📄 ugldemo.c
字号:
uglFontSet(gc, fontSystem); uglTextSizeGet(fontSystem, &textWidth, &textHeight, -1, message); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 2 - textHeight, -1, message); uglTextSizeGet(fontSystem, &textWidth, &textHeight, -1, message2); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 2, -1, message2); /* no input device and check the console port input, if input q or Q, exit */ while(read(fd, &ch, 1) > 0) { if((ch == 'q') || (ch == 'Q')) { retVal = -1; break; } break; } } return(retVal); }/**************************************************************************** ClearScreen - clear the screen** This routine clears the screen by drawing a black rectangle to the display.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL*/static void ClearScreen ( UGL_GC_ID gc /* Graphics context */ ) { uglBackgroundColorSet(gc, colorTable [BLACK].uglColor); uglForegroundColorSet(gc, colorTable [BLACK].uglColor); uglLineStyleSet(gc, UGL_LINE_STYLE_SOLID); uglLineWidthSet(gc, 1); uglRectangle(gc, 0, 0, displayWidth - 1, displayHeight - 1); }/**************************************************************************** cleanUp - cleans up all resources prior to termination** This routine releases all system resources prior to termination.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL*/static void cleanUp ( int mode /* Operating mode */ ) { if (mode >= 0 && inputServiceId != UGL_NULL) { uglCursorBitmapDestroy (devId, cursorDdb); uglCursorDeinit (devId); } uglTransBitmapDestroy (devId, transDdb); uglBitmapDestroy(devId, stdDdb); UGL_FREE(colorData); uglMonoBitmapDestroy (devId, patternDdb); uglRegionDestroy(regionId); UGL_FREE (randomData); uglFontDestroy (fontFixed); uglFontDestroy (fontDialog); uglFontDestroy (fontSystem); uglGcDestroy (gc); uglDeinitialize(); }#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 []) { int mode = 0; if (argc > 1) mode = atoi (argv [1]); windMLDemo (mode); 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); windMLDemo(0); return (0); }#else/**************************************************************************** ugldemo - demonstrate miscellaneous features of WindML** This routine demonstrates the various WindML graphics primitives. This routine* can be invoked from the shell to control the program. If the <mode> parameter * is positive the demo will wait <mode> number of seconds before moving to the * next graphics primitive. A value of zero assumes that a mouse or keyboard is * present and the user must press a key or mouse button to continue to the next* graphics primitive. A negative value causes the program to immediately proceed* to next graphics primitive.** When the <mode> specifies a pause waiting for operator input (<mode> = 0), the* operator can select a 'q' or 'Q' to immediately terminate the program. Any * other key entered or depressing any pointer button causes the program to proceed* on to the next graphics primitive demonstration.** This example program demonstrates how to:**\ml *\m Initialize WindML*\m Identify the graphics device and input devices*\m Create fonts *\m Determine the resolution of the display*\m Create a graphics context*\m Allocate colors*\m Create a clipping region*\m Create various bitmaps (color, monochrome, and transparent*\m Create a cursor and position the cursor based on pointer movement reports*\m Write bitmaps to the display*\m Blt color bitmaps to the display*\m Blt transparent bitmaps to the display*\m Draw lines (thin solid, thin dashed, wide solid, and wide dashed)*\m Draw filled rectangles*\m Draw rectangles filled with a pattern*\m Draw filled polygons*\m Draw polygons filled with a pattern*\m Draw text*\m Draw filled ellipses*\m Draw filled pie shapes*\m Blt with a image stretch*\m Releasing all resources and terminating a WindML application.*\me** RETURNS: ** ERRNO: N/A** SEE ALSO: wexbasicStop() **/void ugldemo ( int mode /* Operating mode */ ) { fd = open("/tyCo/0", 2, 0644); ioctl (fd, FIOSETOPTIONS, OPT_ECHO | OPT_CRMOD | OPT_TANDEM | \ OPT_MON_TRAP | OPT_7_BIT | OPT_ABORT ); uglOSTaskCreate("tWindMLDemo", (UGL_FPTR)windMLDemo, 110, 0, 10000, mode,0,0,0,0); }#endif/**************************************************************************** windMLDemo - entry point for the demo** This routine performs a basic test of the drawing primitives. The <mode> * when greater than 0 is the number of seconds to wait between tests. If * <mode> is 0, a keyboard or pointer is assumed to be present and will wait* for a key press or pointer button click to move to the next tests. If <mode>* is less than 0, the demo will run with no delay in between tests with no * input required.** RETURNS: void** ERRNO: N/A** SEE ALSO: N/A** NOMANUAL**/void windMLDemo ( int mode /* Operating mode */ ) { UGL_REG_DATA *pRegistryData; UGL_DIB transDib; UGL_MDIB transMdib; UGL_MDIB patternDib; UGL_CDIB cursorDib; UGL_FONT_DEF systemFontDef; UGL_FONT_DEF dialogFontDef; UGL_FONT_DEF fixedFontDef; UGL_ORD textOrigin = UGL_FONT_TEXT_UPPER_LEFT; int numRandomPoints; int i, index, y, textpage, tmp; char *fontTestText = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; char regionMessage[23]; int textWidth, textHeight; UGL_FB_INFO fbInfo; UGL_RECT rect; /* Initialize UGL */ if (uglInitialize() == UGL_STATUS_ERROR) return; /* Obtain display device identifier */ 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; if (mode >= 0) { /* obtain the input service identifier. */ 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; } /* Create a graphics context */ gc = uglGcCreate(devId); /* Create Fonts */ 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; uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin); uglFontFindString(fontDrvId, "familyName=Lucida; pixelSize = 12", &systemFontDef); if ((fontSystem = uglFontCreate(fontDrvId, &systemFontDef)) == UGL_NULL) { printf("Font not found. Exiting.\n"); return; } uglFontFindString(fontDrvId, "familyName=Helvetica; pixelSize = 18", &dialogFontDef); if ((fontDialog = uglFontCreate(fontDrvId, &dialogFontDef)) == UGL_NULL) { printf("Font not found. Exiting.\n"); return; } uglFontFindString(fontDrvId, "familyName=Courier; pixelSize = 12", &fixedFontDef); if ((fontFixed = uglFontCreate(fontDrvId, &fixedFontDef)) == UGL_NULL) { printf("Font not found. Exiting.\n"); return; } /* Obtain the dimensions of the display */ uglInfo(devId, UGL_FB_INFO_REQ, &fbInfo); displayWidth = fbInfo.width; displayHeight = fbInfo.height; /* Setup random points */ srand(6); numRandomPoints = 2000; randomData = (int *)UGL_MALLOC(2 * numRandomPoints * sizeof(int)); for (i = 0; i < numRandomPoints * 2; i += 2) { randomData[i] = (rand() % displayWidth); randomData[i + 1] = (rand() % displayHeight); } /* Initialize colors. */ 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); /* Create Region */ regionId = uglRegionCreate (); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTGREEN].uglColor); sprintf(regionMessage,"Welcome to WindML %d.%d.%d", uglVersionMajor,uglVersionMinor, uglVersionPatch); uglTextSizeGet(fontDialog, &textWidth, &textHeight, -1, regionMessage); uglFontSet(gc, fontDialog); uglTextDraw(gc, (displayWidth - textWidth) / 2, (displayHeight - textHeight) / 3, -1, regionMessage); rect.left = rect.top = 0; rect.right = displayWidth - 1; rect.bottom = displayHeight - 1; uglRegionRectInclude (regionId, &rect); rect.right = ((displayWidth - textWidth) / 2) + textWidth + 5; rect.bottom = ((displayHeight - textHeight) / 3) + textHeight + 5; rect.left = ((displayWidth - textWidth) / 2) - 6; rect.top = ((displayHeight - textHeight) / 3) - 6; uglRegionRectExclude (regionId, &rect); uglClipRegionSet (gc, regionId); /* Create the brick pattern */ patternDib.width = patternDib.stride = patternData.width; patternDib.height = patternData.height; patternDib.pImage = patternData.data; patternDdb = uglMonoBitmapCreate(devId, &patternDib, UGL_DIB_INIT_DATA, 0, UGL_NULL); /* Create standard and transparent DDBs */ colorData = (UGL_COLOR *)UGL_MALLOC(32 * 32 * sizeof(UGL_COLOR)); for (i = 0; i < 32 * 32; i++) colorData[i] = colorTable[transparentData[i]].uglColor; transDib.pImage = (void *)colorData; transDib.colorFormat = UGL_DEVICE_COLOR_32; transDib.clutSize = 0; transDib.pClut = UGL_NULL; transDib.imageFormat = UGL_DIRECT; transDib.width = transDib.height = transDib.stride = 32; stdDdb = uglBitmapCreate(devId, &transDib, UGL_DIB_INIT_DATA, 0, UGL_NULL); transMdib.width = transMdib.stride = transMdib.height = 32; transMdib.pImage = transparentMask; transDdb = uglTransBitmapCreate(devId, &transDib, &transMdib, UGL_DIB_INIT_DATA, 0, UGL_NULL); /* Create the cursor */ if (mode >= 0 && inputServiceId != UGL_NULL) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -