📄 wexdbuf.c
字号:
/* wexdbuf.c - WindML double buffering example program *//* Copyright 2000 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01j,22feb02,msr Backward compatability for input API.01i,05nov01,gav Fixed misnamed devIds01h,05nov01,gav Change to new registry01g,05nov01,gav Change to new registry01f,09oct01,msr Ported to new UGL_Q_EVENT architecture.01e,30nov00,gav Made message to fit on small screens.01d,16nov00,msr Fixed SPR #6205101c,27oct00,rfm Added stdio usage01b,26oct00,rfm Modified entry point01a,25oct00,rfm Fixed restart problem*//*************************************************************** WindML Example - Double Buffering using the WindML Page API ** This example program demonstrates how to perform simple* double buffering.** To start the example:** -> ld < wexdbuf_ugl.o* -> wexdbuf ** Press a key or mouse button to cause the test to toggle * between double buffering on or double buffering off.** To shut down the double buffering test program, type the * following:** -> wexdbufStop***************************************************************//* This is included for VxWorks taskDelay and taskSpawn. */#include <vxWorks.h>#include <sysLib.h>/* This is included for a printf prototype. */#include <stdio.h>/* 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/uglMsg.h>#include <ugl/uglfont.h>#include <ugl/uglinput.h>/* A forward declaration for this program. */UGL_LOCAL void windMLExampleDBuf ();/* Global variables *//* Control variable to signal when to stop program */UGL_LOCAL volatile UGL_BOOL stopWex;/* Some graphics environment information */UGL_LOCAL int displayHeight, displayWidth;UGL_LOCAL UGL_GC_ID gc;UGL_LOCAL UGL_FONT_ID font;UGL_LOCAL UGL_INPUT_SERVICE_ID inputServiceId;/** 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_ARGB(0xff, 0, 0, 0), 0}, /* The color table uses ARGB's */ { UGL_MAKE_ARGB(0xff, 0, 0, 168), 0}, /* (see uglColorAlloc). */ { UGL_MAKE_ARGB(0xff, 0, 168, 0), 0}, /* Initialize alpha to 255 for */ { UGL_MAKE_ARGB(0xff, 0, 168, 168), 0},/* now (opaque). */ { UGL_MAKE_RGB(168, 0, 0), 0}, /* UGL_MAKE_RGB takes care of */ { UGL_MAKE_RGB(168, 0, 168), 0}, /* the alpha for us. */ { UGL_MAKE_RGB(168, 84, 0), 0}, { UGL_MAKE_RGB(168, 168, 168), 0}, { UGL_MAKE_RGB(84, 84, 84), 0}, { UGL_MAKE_RGB(84, 84, 255), 0}, { UGL_MAKE_RGB(84, 255, 84), 0}, { UGL_MAKE_RGB(84, 255, 255), 0}, { UGL_MAKE_RGB(255, 84, 84), 0}, { UGL_MAKE_RGB(255, 84, 255), 0}, { UGL_MAKE_RGB(255, 255, 84), 0}, { UGL_MAKE_RGB(255, 255, 255), 0} };#define BLACK (0)#define BLUE (1)#define GREEN (2)#define CYAN (3)#define RED (4)#define MAGENTA (5)#define BROWN (6)#define LIGHTGRAY (7)#define DARKGRAY (8)#define LIGHTBLUE (9)#define LIGHTGREEN (10)#define LIGHTCYAN (11)#define LIGHTRED (12)#define LIGHTMAGENTA (13)#define YELLOW (14)#define WHITE (15)UGL_LOCAL int getKeyboard(void) { UGL_MSG msg; UGL_STATUS status; int retVal = 0; status = uglInputMsgGet (inputServiceId, &msg, UGL_NO_WAIT); while (status != UGL_STATUS_Q_EMPTY) { if ((msg.type == MSG_KEYBOARD && (msg.data.keyboard.modifiers & UGL_KBD_KEYDOWN)) || (msg.type == MSG_POINTER && (msg.data.pointer.buttonChange & msg.data.pointer.buttonState))) retVal = 1; status = uglInputMsgGet (inputServiceId, &msg, UGL_NO_WAIT); } return(retVal); }/** Start the example program. This function and the bitmapStop function* can be invoked from the host shell in order to control the program.*/void wexdbuf (void) { stopWex = UGL_FALSE; printf("To stop wexdbuf, type 'wexdbufStop'\n"); uglOSTaskCreate("tWindMLDBuf", (UGL_FPTR)windMLExampleDBuf, 110, 0, 10240, 0,0,0,0,0); }/* Stop the example program */void wexdbufStop (void) { stopWex = UGL_TRUE; }/* The main function */UGL_LOCAL void windMLExampleDBuf (void) { UGL_FONT_DRIVER_ID fontDrvId; UGL_FONT_DEF fontDef; UGL_PAGE_ID page[2]; UGL_FB_INFO fbInfo; int textWidth, textHeight; char * message0 = "Double Buffering ON. Press any key or mouse button to turn off."; char * message1 = "Double Buffering Off. Press any key or mouse button to turn on."; char * errorMessage0 = "Double Buffering not supported by this"; char * errorMessage1 = "driver. Press any key or mouse button."; /* * 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 */ devId = (UGL_DEVICE_ID)uglRegistryFind (UGL_DISPLAY_TYPE, 0, 0,0)->id; /* Obtain the font driver */ fontDrvId = (UGL_FONT_DRIVER_ID)uglRegistryFind (UGL_FONT_ENGINE_TYPE, 0, 0,0)->id; /* Create the font */ uglFontFindString(fontDrvId, "pixelSize=12", &fontDef); if ((font = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL) { printf("Font not found. Exiting.\n"); return; } /* get the input service */ inputServiceId = (UGL_INPUT_SERVICE_ID)uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0,0)->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 (getKeyboard()) { 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(getKeyboard() != 1); } /* Clean Up */ uglFontDestroy(font); uglGcDestroy (gc); uglDeinitialize(); return; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -