?? wexcursr.c
字號:
/* wexcursr.c - WindML cursor example program *//* Copyright 2000 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01n,22feb02,msr Backward compatability 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*//*************************************************************** DESCRIPTION** WindML Example - Cursor graphics and Mouse input** This example program demonstrates how a cursor is created,* repositioned on the display, and messages processed from the * pointer. This program also tests the buttons (right, middle,* left) on the cursor.** To start the example:** -> ld < wexcursr_ugl.o* -> wexcursr <mode>** Cursor program is spawned and the cursor can now be moved. The* <mode> parameter identifies how the program is to be executed.* When it is absent or set to 0, then the cursor movement is* handled by received mouse messages. When set to a positive * number the cursor movement is updated at the rate specified by* the parameter.* * To shut down the cursor test program, the following is * performed:** -> 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. */UGL_LOCAL 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 };/**************************************************************************** wexcursr - start of program** This routine starts the cursor test.** RETURNS: ** ERRNO: N/A** SEE ALSO: **/#if defined(WINDML_NATIVE) && defined(__unix__)int main (int argc, char *argv []) { windMLExampleCursor(0); return (0); }#elif defined(WINDML_NATIVE) && defined(_WIN32)int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { uglWin32Parameters(hInstance, hPrevInstance, lpCmdLine, nShowCmd); windMLExampleCursor(0); return (0); }#elsevoid 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 of program** This routine causes the program to terminate.** RETURNS: ** ERRNO: N/A** SEE ALSO: **/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 an stop. Otherwise,* the cursorStop function will work.** RETURNS: ** ERRNO: N/A** SEE ALSO: **/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 offest 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); } } else { /* Someplace to hold a WindML message when we get it. */ UGL_MSG msg; /*
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -