📄 wextext.c
字号:
*/ /* Set the colors of the text and its background. */ uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[GREEN].uglColor); /* Draw the text to the screen (which is the GC's current bitmap). */ uglTextDraw(gc, x, y, -1, output); /* Signal a stop if the key was Escape. */ if (key == 27 /* escape */) stopWex = 1; if (key == 9 /* tab */) x += 60; /* Just advance by some number to keep tab simple. */ else /* * For a normal character, advance the position by * the width of the character. */ x += textWidth; /* Protect against backspacing past the left edge. */ if (x < 0) x = 0; /* * Wrap the rendering to the left edge if we reach the right edge, or * if the Carriage Return is pressed. Also descend one line. */ if ((x >= displayWidth - textWidth) || (key == 13)) { y += textHeight; x = 0; } /* Wrap the text to the top of the screen if it goes past the bottom. */ if (y >= displayHeight - textHeight) y = bannerHeight << 1; } }/** Wait for the signal to stop. This is the last function called before* freeing resources and de-initializing UGL.** The program is message driven. So we have an infinite loop that* processes messages. Since we are accepting input from the keyboard, we* can use it to signal a stop for the program. Alternatively, the textioStop* function can be used.*/UGL_LOCAL void wexPause(void) { UGL_MSG msg; /* A gratuitous plug for UGL. for(;;) */ UGL_FOREVER { /* * We can wait/pend on an message or return after some time. Since * we can also stop via textioStop, we cannot pend indefinitely. */ if (uglInputMsgGet (inputServiceId, &msg, 140 /* mSec */) != UGL_STATUS_Q_EMPTY) { /* * There can be all sorts of messages, but here we are only * interested in keyboard messages. We could check the * message's category before this check, but doing so provides * no benefit here. */ if (msg.type == MSG_KEYBOARD) { /* * Keyboard and pointer messages use the "modifiers" field * to pass information. Here we see if a key is being * pressed down. The keyboard type field contains the * keyboard scan code and ASCII key code. */ if (msg.type == MSG_KEYBOARD && msg.data.keyboard.modifiers & UGL_KBD_KEYDOWN) textEcho((UGL_UINT16)msg.data.keyboard.rawKbd.value.scanCode, msg.data.keyboard.key); } } /* Stop if we get a signal from textioStop. */ if (stopWex) break; } }/** Start the example program. This function and the textioStop function* can be invoked from the host shell in order to control the program.*/#if defined(WINDML_NATIVE) && defined(__unix__)int main (int argc, char *argv []) { windMLExampleTextIO(); return 0; }#elif defined(WINDML_NATIVE) && defined(_WIN32)int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { uglWin32Parameters(hInstance, hPrevInstance, lpCmdLine, nShowCmd); windMLExampleTextIO(); return (0); }#elsevoid wextext (void) { stopWex = 0; printf("To stop wextext, type 'wextextStop'\n"); uglOSTaskCreate("tWindMLtxt", (UGL_FPTR)windMLExampleTextIO, 110, 0, 10240, 0,0,0,0,0); }#endif/* Stop the example program; by signalling the wexPause function. */void wextextStop (void) { stopWex = 1; }/* The main function */int windMLExampleTextIO (void) { /* * Various font drivers which may use different font "engines" (such as * BMF and AGFA) can be configured into UGL. In order to access a * particular driver an identifier is used. This is required to do * practically anything with the font API. */ UGL_FONT_DRIVER_ID fontDrvId; /* Use this variable to specify a particular font for UGL to "create". */ UGL_FONT_DEF fontDef; /* * A variable to hold the data sent to and returned from * uglFontDriverInfo. In this example we are going to pass * data to the function related to the positioning of the * rendered text. */ UGL_ORD textOrigin; /* Text for our banner that will be printed at the top of the screen. */ char *text = "WindML text input and output example. Wind River Systems."; char fontInfoText[80]; /* * 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; /* * The font metric contains various information about a font. * The metric is loaded with a font's information using the * uglFontMetricsGet() function. We are only going to use * the font face name and pixel size for display on the banner. */ UGL_FONT_METRICS metric; /* * 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 input service identifier. Typically there is only one * input service, but there can be more than one. */ inputServiceId = (UGL_INPUT_SERVICE_ID)uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0,0)->id; /* * Obtain the device identifier for the font engine. */ fontDrvId = (UGL_FONT_DRIVER_ID)uglRegistryFind (UGL_FONT_ENGINE_TYPE, 0, 0,0)->id; /* * Right about here we could get the device identifier for the keyboard * if there was anything that we wanted to do with it. The keyboard is * already to go after uglInitialize, so we will not have to do any more * with it, though. */ /* * 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; /* * Create a graphics context. Default values are set during * the creation. */ gc = uglGcCreate(devId); /* * UGL will render fonts using different origins. Somewhat like the * "hot spot" in the cursor. Here we are setting the origin of the font * rendering to be at the upper left corner of the text. * uglFontDriverInfo is a general purpose function that can return * information. It also can be used to affect configuration data, as * we are doing here. */ textOrigin = UGL_FONT_TEXT_UPPER_LEFT; uglFontDriverInfo(fontDrvId, UGL_FONT_TEXT_ORIGIN, &textOrigin); /* * This function allows us to find a font from the set of available * fonts. A search parameter string is used to specify the font we * want. Incomplete specifications leave the function to make the * choice. Here we specify Lucida, but haven't specified a size, so * the font function will choose one for us. There are several para- * meters that can be used. They are semicolon delimited. */ uglFontFindString(fontDrvId, "familyName=Lucida; pixelSize=14", &fontDef); /* * Now that we have found a font and it is specified in fontDef, * we can "create" the font. What is accomplished here is dependent * up upon the specific font engine being used. This step could * include conversion of the font data from a platform independent * format to a platform dependent format; similar to a DIB being used * to create a DDB. For the BMF font engine a glyph cache and other * resources are configured. */ if ((fontBanner = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL) { printf("Font not found. Exiting.\n"); return(0); } /* Find another font for the echo text. Use a big one if available. */ uglFontFindString(fontDrvId, "pixelSize=24", &fontDef); if ((fontEcho = uglFontCreate(fontDrvId, &fontDef)) == UGL_NULL) { printf("Font not found. Exiting.\n"); return(0); } /* * 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. * * 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[YELLOW].rgbColor, UGL_NULL, &colorTable[YELLOW].uglColor, 1); uglColorAlloc(devId, &colorTable[WHITE].rgbColor, UGL_NULL, &colorTable[WHITE].uglColor, 1); /* Set some obnoxious color combination for the banner. */ uglForegroundColorSet(gc, colorTable[YELLOW].uglColor); uglBackgroundColorSet(gc, colorTable[BLUE].uglColor); /* Set the font we acquired earlier for the banner. */ uglFontSet(gc, fontBanner); /* * We pass the text string into this function to find out what size * the rendering of the text will occupy in the bitmap. We only need * the height, so pass a null for the width. The size is font dependent * so we pass that to the function too. */ uglTextSizeGet(fontBanner, UGL_NULL, &bannerHeight, -1, text); /* * Initialize the print location (upper left corner of screen, * but below the banner). */ y = bannerHeight; x = 0; /* * Draw the text! The GC contains the bitmap that we want to render to. * In this case it will be the frame buffer. We are locating the text * at the upper left corner of the screen (0,0). */ uglTextDraw(gc, 0, 0, -1, text); /* Get the metric information for the echo font. */ if (uglFontMetricsGet(fontEcho, &metric) != 0) { printf("uglFontMetricsGet failed.\n"); sprintf(fontInfoText," < font information unavailable >"); } else sprintf(fontInfoText,"%s %d",metric.faceName, metric.pixelSize); /* Draw the metric information on the screen. */ uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglTextDraw(gc, 0, y, -1, fontInfoText); y += bannerHeight; /* * More than just pausing. This wexPause function is also the message loop * for the program. This function calls textEcho to put characters on * the screen. */ wexPause(); /* Clean Up */ uglFontDestroy (fontBanner); uglFontDestroy (fontEcho); uglGcDestroy (gc); uglDeinitialize(); return(0); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -