📄 wexcursr.c
字号:
/* wexcursr.c - WindML cursor example program *//* Copyright 2000 - 2003 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01q,08may03,jlb Remove UGL_LOCAL on function prototype01p,18apr03,jlb Improved comments and program documentation01o,01apr03,sts [SPR 86504] Use uglRegistryFind() safely.01n,22feb02,msr Backward compatibility for input API.01m,29jan02,rbp Addition of support for Native Unix.01l,05nov01,gav Fixed misnamed devIds01k,05nov01,gav Change to new registry01j,05nov01,gav Change to new registry01i,09oct01,msr Ported to new UGL_Q_EVENT architecture.01h,19dec00,gav Entry point identical to filename w/o extension.01g,18dec00,msr Added color allocation for yellow.01f,27nov00,gav Add pointing device button test.01e,27oct00,rfm Added stdio usage01d,26oct00,rfm Modified entry point01c,25oct00,rfm Changed comments01b,25oct00,jlb Fixed exit crash, added instructions, WRS coding stds01a,11sep00,gav written*//*DESCRIPTIONThis example program demonstrates how to create a cursor, reposition thecursor on the display, and messages processed from the pointer device. To start the example: -> ld < wexcursr_ugl.o -> wexcursr To stop the example: -> wexcursrStop *//** Include the UGL header file to use UGL functions, etc.* The DIB header has defines specific to the use of DIBs.*/#include <ugl/ugl.h>#include <ugl/uglos.h>#include <ugl/ugldib.h>/** Include header file for the input features of WindML. WindML's input* API provide the access to a pointing device and keyboard if they are * present and supported by a driver.*/#include <ugl/uglinput.h>/** Messages in WindML allow the application to work independently from the* input processing, while still having access to the input messages.*/#include <ugl/uglMsg.h>/** Include the standard I/O for printf's (of the type of pointing* device detected from the driver).*/#include <stdio.h>/* Defines */#define BLACK (0)#define BLUE (1)#define LIGHTGRAY (2)#define RED (3)#define YELLOW (4)#define WHITE (5)/* Global variables *//* A forward declaration for this program. */int windMLExampleCursor (int mode);/* Control variable to signal when to stop program */UGL_LOCAL volatile UGL_BOOL stopWex;/* input service */UGL_INPUT_SERVICE_ID inputServiceId;/* Some graphics environment information */UGL_LOCAL int displayHeight, displayWidth;/* * The UGL Graphics Context (GC) is an important concept in UGL.* The GC contains data that various UGL functions can use.* If there were no such thing as a GC, most function calls* would require several more parameters to communicate that* information.*/UGL_GC_ID gc;/** The color table is where we define the colors we want* to have available. The format is an array of* ARGB values paired with their allocated uglColor. As* of this writing, we don't need to worry about Alpha* ("A") values unless we are using video.*/UGL_LOCAL struct _colorStruct { UGL_ARGB rgbColor; UGL_COLOR uglColor; }colorTable[] = { { UGL_MAKE_RGB(0, 0, 0), 0}, /* black */ { UGL_MAKE_RGB(0, 0, 168), 0}, /* blue */ { UGL_MAKE_RGB(168, 168, 168), 0}, /* lightgrey */ { UGL_MAKE_RGB(255, 0, 0), 0}, /* red */ { UGL_MAKE_RGB(255, 255, 84), 0}, /* yellow */ { UGL_MAKE_RGB(255, 255, 255), 0} /* white */ };/** The cursor DIB is defined to use an 8-bit indexed palette with two* reserved indices for transparency and inversion. The format is an array* of ARGB values. Typically, the alpha would not be implemented.** Each indexed color DIB can have its own CLUT. There is only one CLUT for* the display screen, though. With a software cursor, the cursor and the* other displayed data must share the same CLUT. Hardware cursors, though,* may use their own CLUTs or other color mechanisms independent of the frame* buffers CLUT.*/UGL_LOCAL UGL_ARGB cursorClut[] = { UGL_MAKE_RGB(0, 0, 0), /* black */ UGL_MAKE_RGB(255, 255, 84) /* yellow */ };/** The actual image data for the cursor. This could be set up* as an array of numbers, or the like, but a more graphical* representation can be had using the #defines.*/UGL_LOCAL UGL_UINT8 cursorData[] = {#define B 0,#define Y 1,#define T 255,#define I 254, T T T T T T T T T T T T Y Y Y Y Y Y Y Y T T T T T T T T T T T T T T T T T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T T T T T T T T T T T T Y Y Y Y T T T Y Y I I I I Y Y Y Y Y T T T T T T T T T T T T T Y Y Y T T T T T Y Y I I I I I I Y Y Y Y T T T T T T T T T T T Y Y Y T T T T T T Y Y I I I I I I I I I Y Y T T T T T T T T T Y Y T T T T T T T B Y Y B I I I I I I I I Y Y Y T T T T T T T Y Y T T T T T T B B B Y Y B B B I I I I I I I I Y Y T T T T T Y Y Y T T T T T B B B T Y Y I B B B I I I I I I I Y Y Y T T T T Y Y T T T T T B B T T T Y Y I I I B B I I I I I I I Y Y T T T Y Y T T T T T B B T T T T Y Y I I I I B B I I I I I I I Y Y T T Y Y T T T T B B T T T T T Y Y I I I I I B B I I I I I I Y Y T T Y Y T T T T B B T T T T T Y Y I I I I I B B I I I I I I I Y Y Y Y T T T T B B T T T T T T Y Y I I I I I I B B I I I I I I Y Y Y Y T T T T B B T T T T T T Y Y I I I I I I B B I I I I I I Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y I I I I B B I I I I I I Y Y T T T T T T B B T T T T T T Y Y Y Y I I I I B B I I I I I I Y Y T T T T T T B B T T T T T Y Y Y Y Y Y I I I I B B I I I I I Y Y T T T T T B B T T T T T T Y Y Y Y Y Y I I I I B B I I I I I Y Y T T T T T B B T T T T T T Y Y Y T Y Y I I I I I B B I I I I Y Y T T T T B B T T T T T T T Y Y T T Y Y I I I I I B B B B I I Y Y T T B B B T T T T T T T Y Y Y T T Y Y Y I I I I I I B B B B Y Y B B B B T T T T T T T T Y Y Y T T T Y Y I I I I I I I I B B Y Y B B T T T T T T T T T Y Y Y T T T T Y Y Y I I I I I I I I I Y Y T T T T T T T T T T T Y Y Y T T T T T Y Y Y I I I I I I I I Y Y T T T T T T T T T T Y Y Y T T T T T T T Y Y Y I I I I I I I Y Y T T T T T T T T T Y Y Y T T T T T T T T T Y Y Y I I I I I I Y Y T T T T T T T T Y Y Y T T T T T T T T T T T Y Y Y Y I I I I Y Y T T T T T T T Y Y Y T T T T T T T T T T T T T Y Y Y Y Y I I Y Y Y T T T Y Y Y Y Y T T T T T T T T T T T T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T T T T T T T T T T T T T T T T T Y Y Y Y Y Y Y Y T T T T T T T T T T T T#undef B#undef Y#undef T#undef I };#if defined(WINDML_NATIVE) && defined(__unix__)/**************************************************************************** main - start of demo program for unix native simulator** Start the example program. ** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL**/int main (int argc, char *argv []) { windMLExampleCursor(0); return (0); }#elif defined(WINDML_NATIVE) && defined(_WIN32)/**************************************************************************** WinMain - start of demo program for windows native simulator** Start the example program. ** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL**/int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { uglWin32Parameters(hInstance, hPrevInstance, lpCmdLine, nShowCmd); windMLExampleCursor(0); return (0); }#else/**************************************************************************** wexcursr - demonstrate cursor handling** This routine demonstrates the methods to handle cursors and the pointer device.** This example program demonstrates how to:**\ml *\m Initialize WindML*\m Identify the graphics device and input devices*\m Identify the pointing device type*\m Setup up a constraining rectangle for the cursor movement*\m Determine the resolution of the display*\m Create a graphics context for the cursor image*\m Allocate colors to be used for the cursor image*\m Initialize the cursor*\m Create a cursor bitmap*\m Assign the cursor an image*\m Turn on the cursor*\m Accept pointer events, decode the pointer events for movement and button clicks*\m Reposition the cursor on the display*\m Release resources and terminate the WindML application.*\me*** RETURNS: ** ERRNO: N/A** SEE ALSO: wexcursrStop() **/void wexcursr ( int mode /* 0 when move based on message, otherwise time delay between moves */ ) { stopWex = 0; printf("To stop wexcursr, type 'wexcursrStop'\n"); uglOSTaskCreate("tWindMLCurs", (UGL_FPTR)windMLExampleCursor, 110, 0, 10240, mode,0,0,0,0); }#endif/**************************************************************************** wexcursrStop - stop the cursor example program** This routine stops the cursor example program.** RETURNS: ** ERRNO: N/A** SEE ALSO: wexcursr() **/void wexcursrStop (void) { stopWex = 1; }/**************************************************************************** wexPause - move the cursor and check for input** Wait for the signal to stop. ** Now that we are accepting input from the pointing device, we can use the* buttons (if the pointing device has them) to signal a stop. Otherwise,* the cursorStop function will work.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL*/UGL_LOCAL void wexPause ( UGL_DEVICE_ID devId, /* device specifier */ int mode /* mode = 0 wait for input, otherwise move based on delay */ ) { if (mode != 0) { /* Set up some coordinates to keep track of the cursor position. */ UGL_POS x = displayWidth / 2,y = displayHeight / 2, a =1,b=1; /* Continue until we get a signal to stop from cursorStop. */ while (!stopWex) { uglCursorMove(devId, x, y); /* Calculate a new position to which to move the cursor. */ x += a; y += b; /* * Keep the cursor where we can see it. The 16 offset is * to account for the width and height from the hot spot. */ if ((x < 16) || (x > displayWidth - 16)) a *= -1; if ((y < 16) || (y > displayHeight - 16)) b *= -1; /* Delay to slow the cursor movement. */ uglOSTaskDelay (mode);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -