📄 wexcursr.c
字号:
} } else { /* Someplace to hold a WindML message when we get it. */ UGL_MSG msg; /* * This is a counter to keep the flash of color (rectangle) on the * screen for a moment before we erase it and wait for another * button press. */ UGL_UINT16 delayCount = 0; /* Continue until end signal */ UGL_FOREVER { /* * We can wait/pend on an message or return after some time. Since * we can also stop via cursorStop, we cannot pend indefinitely. */ UGL_STATUS uStat = uglInputMsgGet (inputServiceId, &msg, 140); /* * If the message queue is empty then begin counting the delay time. */ if (uStat == UGL_STATUS_Q_EMPTY) { /* * If the delay time has elapsed (5 * 140 mSec), erase the * screen. */ if (delayCount == 5) { uglForegroundColorSet(gc,colorTable[BLACK].uglColor); uglBackgroundColorSet(gc,colorTable[BLACK].uglColor); uglRectangle(gc, 0, 0, displayWidth, displayHeight); delayCount = 0; } else delayCount++; /* Still waiting, increment the counter. */ } else { /* * If there is an message, process it instead of the delayCount. * * There can be all sorts of messages, but here we are only * interested in input pointer messages. We could check the * message's category before this check, but doing so provides * no benefit here. */ if (msg.type == MSG_POINTER) { /* * There are more than 3 button modifiers, but most mice * have no more than 3, so that's all we'll check for here. */ if (msg.data.pointer.buttonState & UGL_PTR_BUTTON1) { uglForegroundColorSet(gc,colorTable[RED].uglColor); uglBackgroundColorSet(gc,colorTable[RED].uglColor); uglRectangle(gc, 0, 0, displayWidth / 3, displayHeight); } else if (msg.data.pointer.buttonState & UGL_PTR_BUTTON3) { uglForegroundColorSet(gc,colorTable[WHITE].uglColor); uglBackgroundColorSet(gc,colorTable[WHITE].uglColor); uglRectangle(gc, displayWidth / 3, 0, 2 * displayWidth / 3, displayHeight); } else if (msg.data.pointer.buttonState & UGL_PTR_BUTTON2) { uglForegroundColorSet(gc,colorTable[BLUE].uglColor); uglBackgroundColorSet(gc,colorTable[BLUE].uglColor); uglRectangle(gc, 2 * displayWidth / 3, 0, displayWidth, displayHeight); } /* * Whether it was a cursor movement or not , calling * uglCursorMove will not be a problem because the current * position will be in the message's coordinates. This will * also allow the cursor to move while a button is pressed. */ uglCursorMove(devId, msg.data.pointer.position.x, msg.data.pointer.position.y); } } /* Stop if we get a signal from cursorStop. */ if (stopWex) break; } } }/**************************************************************************** windMLExampleCursor - main cursor test function** This routine initializes the cursor and starts the test.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL**/int windMLExampleCursor ( int mode /* 0 when move based on message, otherwise time delay between moves */ ) { /* * For registry lookups. */ UGL_REG_DATA *pRegistryData; /* * Type of pointer device. */ UGL_INT32 pdType; /* * We are using a WindML input message stack in this example. The first * layer in the stack is the input device. This UGL_INPUT_DEV_ID * type variable allows us to use WindML functions that access a * particular input device like the keyboard or mouse. */ UGL_INPUT_DEV_ID pointerDevId; /* * The next layer on the stack is the input service. The input service * collects messages from the input devices (and other places) and queues * them for applications to read. */ /* * It is possible to constrain the pointer to a certain screen area. * This rectangle will define the area when passed to the pointer input * device's info function. */ UGL_RECT conRect; /* The cursor DIB is a unique variation of the normal DIB. It * has limited colors, the ability to designate transparent, and * inverting regions, and a "hot spot" (a way to locate it without * having to use the upper left corner of the DIB). From the cursor * DIB we can create a cursor bitmap. Notice that the cursor bitmap * has attributes of a transparent bitmap, but with the special DIB, * a monochrome DIB was not needed to create it. Once the cursor * bitmap is created, the DIB may be discarded. The bitmap, though, * must remain intact while it is being used by a cursor. */ UGL_CDIB cursorDib; UGL_CDDB_ID cursorBitmap; /* * This structure is filled in with data about the frame buffer * by the uglInfo() function. */ UGL_MODE_INFO modeInfo; /* * The device ID is critical to the operation of UGL. It * identifies individual "devices" (display adapter, keyboard, * font engine, etc.) to functions that may be able to work * with more than one device. */ UGL_DEVICE_ID devId; /* * Initialize UGL. Must do this before trying to do anything * else within UGL/WindML. */ uglInitialize(); /* Obtain the device identifier for the display */ pRegistryData = uglRegistryFind (UGL_DISPLAY_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return (UGL_STATUS_ERROR); } devId = (UGL_DEVICE_ID)pRegistryData->id; /* * Obtain the input service identifier. Typically there is only one * input service, but there can be more than one. */ pRegistryData = uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return (UGL_STATUS_ERROR); } inputServiceId = (UGL_INPUT_SERVICE_ID)pRegistryData->id; /* * Obtain the device identifier for the pointer device. */ pRegistryData = uglRegistryFind (UGL_PTR_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { uglDeinitialize(); return (UGL_STATUS_ERROR); } pointerDevId = (UGL_INPUT_DEV_ID)pRegistryData->id; /* Just FYI, find out what kind of pointer we have. */ uglInputDevControl (pointerDevId, ICR_GET_PTR_TYPE, (void *)&pdType); if(pdType == UGL_PTR_TYPE_MOUSE) printf("A mouse type pointing device detected.\n"); else if(pdType == UGL_PTR_TYPE_TOUCH_SCREEN) printf("A touch screen type pointing device detected.\n"); else if(pdType == UGL_PTR_TYPE_PEN_TABLET) printf("A pen tablet type pointing device detected.\n"); else { mode = 1; printf("Unknown pointing device type: 0x%x\n", (int)pdType); } /* * Obtain the dimensions of the display. We will use these * to center some of an object. */ uglInfo(devId, UGL_MODE_INFO_REQ, &modeInfo); displayWidth = modeInfo.width; displayHeight = modeInfo.height; /* * Set up the constraint rectangle to cover the middle half of the * screen. */ conRect.left = modeInfo.width / 4; conRect.right = 3 * modeInfo.width / 4; conRect.top = 0; conRect.bottom = 3 * modeInfo.height / 4; uglInputDevControl (pointerDevId, ICR_SET_PTR_CONSTRAINT, (void *)&conRect); /* * Create a graphics context. Default values are set during * the creation. */ gc = uglGcCreate(devId); /* * Initialize colors. UGL maintains a Color Look-Up Table (CLUT) * for devices that do not represent colors directly. Essentially * some hardware is only able to represent a subset of colors at * any given time. To manage which colors will be available for * rendering, UGL uses color allocation. If the hardware is able * to represent colors directly, then the uglColorAlloc() function * still works, but it is then essentially a no-op. * * In this example we will only allocate what we need. We "allocate" * colors within UGL's CLUT (sometimes referred to as a "palette"). * Colors can also be de-allocated, or freed, with uglColorFree. * * We explicitly use blue and lightgrey, but black is good to have * defined as well since the frame buffer will be often contain zero * index entries which are typically "black". * * Since the ARGB's are intermingled with the UGL_COLORs in * the colorTable, we must allocate each color individually. * If the ARGB's had a contiguous array of ARGBs, and likewise for * the UGL_COLORs, a single uglColorAlloc call could be made. * (see the windows example). */ uglColorAlloc (devId, &colorTable[BLACK].rgbColor, UGL_NULL, &colorTable[BLACK].uglColor, 1); uglColorAlloc(devId, &colorTable[BLUE].rgbColor, UGL_NULL, &colorTable[BLUE].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTGRAY].rgbColor, UGL_NULL, &colorTable[LIGHTGRAY].uglColor, 1); uglColorAlloc(devId, &colorTable[RED].rgbColor, UGL_NULL, &colorTable[RED].uglColor, 1); uglColorAlloc(devId, &colorTable[YELLOW].rgbColor, UGL_NULL, &colorTable[YELLOW].uglColor, 1); uglColorAlloc(devId, &colorTable[WHITE].rgbColor, UGL_NULL, &colorTable[WHITE].uglColor, 1); /* Assemble a cursor DIB (CDIB). Note that hardware cursors often have * a limitation on their dimensions, and other characteristics. * We are centering the "hot spot" on the cursor image. This means that * when the cursor is moved to x,y the pixel at 16,16 in the cursor * image is located at x,y. */ cursorDib.width = cursorDib.height = cursorDib.stride = 32; cursorDib.hotSpot.x = cursorDib.hotSpot.y = 16; cursorDib.pImage = cursorData; cursorDib.clutSize = 2; cursorDib.pClut = cursorClut; /* Initialize the cursor. Set its max size and initial position. */ uglCursorInit (devId, 32, 32, displayWidth / 2, displayHeight / 2); /* Use the DIB to create a cursor type bitmap. */ cursorBitmap = uglCursorBitmapCreate(devId, &cursorDib); /* Set the cursor type bitmap, cursorBitmap, as the cursor's bitmap. * By changing the image to different images the cursor can be * animated. Do not free a bitmap that is being used by the cursor. * So, if animating, select the next image bitmap into the cursor, and * then free the old one. */ uglCursorImageSet (devId, cursorBitmap); /* * O.k. all of the preparation is done, now we can actually turn the * thing on. */ uglCursorOn(devId); /* * More than just pausing. This wexPause function is also the message loop * for the program. */ wexPause(devId, mode); /* Clean Up */ uglCursorDeinit (devId); uglCursorBitmapDestroy (devId, cursorBitmap); uglGcDestroy (gc); uglDeinitialize(); return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -