📄 wexdbuf.c
字号:
* 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) { printf("Display not found. Exiting.\n"); uglDeinitialize(); return; } devId = (UGL_DEVICE_ID)pRegistryData->id; /* Obtain the font driver */ pRegistryData = uglRegistryFind (UGL_FONT_ENGINE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { printf("Font engine not found. Exiting.\n"); uglDeinitialize(); return; } fontDrvId = (UGL_FONT_DRIVER_ID)pRegistryData->id; /* Create the font */ uglFontFindString(fontDrvId, "pixelSize=12", &fontDef); if ((font = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL) { printf("Font not found. Exiting.\n"); uglDeinitialize(); return; } /* get the input service */ pRegistryData = uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0, 0); if (pRegistryData == UGL_NULL) { printf("Input service not found. Exiting.\n"); uglDeinitialize(); return; } inputServiceId = (UGL_INPUT_SERVICE_ID)pRegistryData->id; /* * Obtain the dimensions of the display. We will use these * to center some of our objects. */ uglInfo(devId, UGL_MODE_INFO_REQ, &modeInfo); displayWidth = modeInfo.width; displayHeight = modeInfo.height; /* * Create a graphics context. Default values are set during * the creation. */ gc = uglGcCreate(devId); /* Set the font */ uglFontSet(gc, font); /* * 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. * * We have set up for 16 colors, so here we will "allocate" them * within UGL's CLUT (sometimes referred to as a "palette"). Colors * can also be de-allocated, or freed, with uglColorFree. * * 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[GREEN].rgbColor, UGL_NULL, &colorTable[GREEN].uglColor, 1); uglColorAlloc(devId, &colorTable[CYAN].rgbColor, UGL_NULL, &colorTable[CYAN].uglColor, 1); uglColorAlloc(devId, &colorTable[RED].rgbColor, UGL_NULL, &colorTable[RED].uglColor, 1); uglColorAlloc(devId, &colorTable[MAGENTA].rgbColor, UGL_NULL, &colorTable[MAGENTA].uglColor, 1); uglColorAlloc(devId, &colorTable[BROWN].rgbColor, UGL_NULL, &colorTable[BROWN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTGRAY].rgbColor, UGL_NULL, &colorTable[LIGHTGRAY].uglColor, 1); uglColorAlloc(devId, &colorTable[DARKGRAY].rgbColor, UGL_NULL, &colorTable[DARKGRAY].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTBLUE].rgbColor, UGL_NULL, &colorTable[LIGHTBLUE].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTGREEN].rgbColor, UGL_NULL, &colorTable[LIGHTGREEN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTCYAN].rgbColor, UGL_NULL, &colorTable[LIGHTCYAN].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTRED].rgbColor, UGL_NULL, &colorTable[LIGHTRED].uglColor, 1); uglColorAlloc(devId, &colorTable[LIGHTMAGENTA].rgbColor, UGL_NULL, &colorTable[LIGHTMAGENTA].uglColor, 1); uglColorAlloc(devId, &colorTable[YELLOW].rgbColor, UGL_NULL, &colorTable[YELLOW].uglColor, 1); uglColorAlloc(devId, &colorTable[WHITE].rgbColor, UGL_NULL, &colorTable[WHITE].uglColor, 1); /* First check to see if driver supports double buffering */ uglInfo(devId, UGL_FB_INFO_REQ, &fbInfo); if (fbInfo.flags & UGL_FB_PAGING_ENABLED) { int x, y; int xinc = 1, yinc = 1; int pageIndex = 0; int dblBufOn = UGL_TRUE; UGL_POINT m0TextCoordinates; UGL_POINT m1TextCoordinates; UGL_RECT rect; rect.left = displayWidth / 4; rect.top = displayHeight / 4; rect.right = 3 * rect.left; rect.bottom = 3 * rect.top; x = rect.left; y = rect.top; uglTextSizeGet(font, &textWidth, &textHeight, -1, message0); m0TextCoordinates.x = ((displayWidth - textWidth) / 2); m0TextCoordinates.y = ((displayHeight - textHeight) / 4); uglTextSizeGet(font, &textWidth, &textHeight, -1, message1); m1TextCoordinates.x = ((displayWidth - textWidth) / 2); m1TextCoordinates.y = ((displayHeight - textHeight) / 4); page[0] = UGL_PAGE_ZERO_ID; page[1] = uglPageCreate(devId); uglPageDrawSet(devId, page[1]); while (stopWex == UGL_FALSE) { uglBackgroundColorSet(gc, colorTable[GREEN].uglColor); uglForegroundColorSet(gc, colorTable[GREEN].uglColor); uglRectangle(gc, rect.left, rect.top, rect.right, rect.bottom); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[BLACK].uglColor); uglRectangle(gc, rect.left + 15, rect.top + 15, rect.right - 15, rect.bottom - 15); uglBackgroundColorSet(gc, colorTable[BLUE].uglColor); uglForegroundColorSet(gc, colorTable[YELLOW].uglColor); uglEllipse(gc, x, y, x + 32, y + 32, 0, 0, 0, 0); if (x + 32 >= rect.right - 15) { xinc = -1; } else if (x <= rect.left + 15) { xinc = 1; } if (y + 32 >= rect.bottom - 15) { yinc = -1; } else if (y <= rect.top + 15) { yinc = 1; } x += xinc; y += yinc; if (dblBufOn == UGL_TRUE) { uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTGREEN].uglColor); uglTextDraw(gc, m0TextCoordinates.x, m0TextCoordinates.y, -1, message0); if (pageIndex == 0) { uglPageVisibleSet(devId, page[1]); uglPageDrawSet(devId, page[0]); pageIndex = 1; } else { uglPageVisibleSet(devId, page[0]); uglPageDrawSet(devId, page[1]); pageIndex = 0; } } else { uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor); uglTextDraw(gc, m1TextCoordinates.x, m1TextCoordinates.y, -1, message1); uglPageVisibleSet(devId, page[0]); uglPageDrawSet(devId, page[0]); } if (getInput()) { if (dblBufOn == UGL_TRUE) { dblBufOn = UGL_FALSE; } else { dblBufOn = UGL_TRUE; } } } uglPageDrawSet(devId, page[0]); uglPageVisibleSet(devId, page[0]); uglPageDestroy(devId, page[1]); } else { uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor); uglTextSizeGet(font, &textWidth, &textHeight, -1, errorMessage0); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 2 - textHeight, -1, errorMessage0); uglTextSizeGet(font, &textWidth, &textHeight, -1, errorMessage1); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 2, -1, errorMessage1); while(getInput() != 1); } /* Clean Up */ uglFontDestroy(font); uglGcDestroy (gc); uglDeinitialize(); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -