📄 wextext.c
字号:
/* wextext.c - WindML Text I/O example program *//* Copyright 2000-2003 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01t,16apr03,jlb Improved comments and program documentation01s,01apr03,sts [SPR 86504] Use uglRegistryFind() safely.01r,26jun02,gav Remove date from banner.01q,13jun02,gav Fixed DIAB compile crash and warning.01p,25feb02,wdf Fixed compiler warnings.01o,22feb02,msr Backward compatibility for input API.01n,29jan02,rbp Addition of support for Native Unix.01m,23jan02,msr Added "keyCode" to raw keyboard event data.01l,05nov01,gav Fixed misnamed devIds01k,05nov01,gav Change to new registry01j,05nov01,gav Change to new registry01i,09oct01,msr Ported to new UGL_Q_EVENT architecture.01h,19dec00,gav Entry point identical to filename w/o extension.01g,06dec00,rfm Choose a pixel size for the Banner font01f,28nov00,gav Added special key identification.01e,21nov00,gav Added font name, etc. to banner display.01d,16nov00,msr Fixed SPR #6205101c,27oct00,rfm Added stdio usage01b,26oct00,rfm Modified entry point01a,25oct00,rfm Added modification history*//*DESCRIPTION This example program demonstrates how to echo characters input from a keyboard to the screen. This example requires a keyboard. To start the example: -> ld < wextext_ugl.o -> wextext To stop the example: -> wextextStop**************************************************************/#include <ugl/uglucode.h>/* This is included for a printf prototype. */#include <stdio.h>/** Include the UGL header file to use UGL functions, etc.*/#include <ugl/ugl.h>#include <ugl/uglos.h>/** Include header file for the input features of WindML. WindML's input* API provide the access to a pointing device and keyboard if they are * present and supported by a driver.*/#include <ugl/uglinput.h>/** Messages in WindML allow the application to work independently from the* input processing, while still having access to the input messages.*/#include <ugl/uglMsg.h>/** The Font API in WindML provides access to the font engine and fonts* for rendering the fonts to a bitmap (or screen).*/#include <ugl/uglfont.h>/** Include the standard I/O for printf's (errors to the host* console).*/#include <stdio.h>#include <ioLib.h>/* A forward declaration for this program. */int windMLExampleTextIO (void);/* Defines */#define BLACK (0)#define BLUE (1)#define GREEN (2)#define YELLOW (3)#define WHITE (4)/* Global variables *//* Control variable to signal when to stop program */UGL_LOCAL volatile UGL_BOOL stopWex;/* input service */UGL_INPUT_SERVICE_ID inputServiceId;/* Some graphics environment information */UGL_LOCAL int displayHeight, displayWidth;/* * We want to protect the banner at the top of the screen from being* overwritten so keep track of its height. All subsequent rendering* will be done below this.*/UGL_LOCAL int bannerHeight;/** The x and y coordinates of the "cursor". Not really a cursor, but simply* the place on the screen where the next text output will be rendered.*/UGL_LOCAL int x,y;/* * The UGL Graphics Context (GC) is an important concept in UGL.* The GC contains data that various UGL functions can use.* If there were no such thing as a GC, most function calls* would require several more parameters to communicate that* information.*/UGL_LOCAL UGL_GC_ID gc;/** UGL supports multiple fonts to be active at once. Each font that is* "created" requires an identifier. For this example we will use two* fonts.*/UGL_LOCAL UGL_FONT_ID fontEcho;UGL_LOCAL UGL_FONT_ID fontBanner;/** 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_RGB(0, 0, 0), 0}, /* Black */ { UGL_MAKE_RGB(0, 0, 168), 0}, /* Blue */ { UGL_MAKE_RGB(0, 255, 0), 0}, /* Green */ { UGL_MAKE_RGB(255, 255, 84), 0}, /* Yellow */ { UGL_MAKE_RGB(255, 255, 255), 0} /* White */ };int fd;/**************************************************************************** specialKey - identify the special key entered** This function displays a notification that a special key was depressed* the is represented by <scanCode> and <key>.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL*/UGL_LOCAL UGL_BOOL specialKey ( UGL_UINT16 scanCode, /* scan code of key */ UGL_WCHAR key /* Unicode value of key */ ) { /* restrict the keys to the Unicode range of values. */ UGL_WCHAR nomodkey = (UGL_WCHAR)(key & 0xffff); UGL_CHAR keyText[30]; UGL_BOOL retCode = UGL_TRUE; int textWidth, textHeight; /* * Initialize the keyText to something valid for the size function * that may be called later. */ sprintf(keyText, "UGL"); /* If the key is not mapped at all, say so. */ if (key == 0) { sprintf(keyText,"Un-mapped key: scanCode %d\n",scanCode); retCode = UGL_TRUE; } else switch (nomodkey) /* The key is mapped, so see if it is one of the non-printable ones. */ { case UGL_UNI_BACKSPACE: sprintf(keyText,"UGL_UNI_BACKSPACE\n"); break; case UGL_UNI_DELETE: sprintf(keyText,"UGL_UNI_DELETE\n"); break; case UGL_UNI_F1: sprintf(keyText,"UGL_UNI_F1\n"); break; case UGL_UNI_F2: sprintf(keyText,"UGL_UNI_F2\n"); break; case UGL_UNI_F3: sprintf(keyText,"UGL_UNI_F3\n"); break; case UGL_UNI_F4: sprintf(keyText,"UGL_UNI_F4\n"); break; case UGL_UNI_F5: sprintf(keyText,"UGL_UNI_F5\n"); break; case UGL_UNI_F6: sprintf(keyText,"UGL_UNI_F6\n"); break; case UGL_UNI_F7: sprintf(keyText,"UGL_UNI_F7\n"); break; case UGL_UNI_F8: sprintf(keyText,"UGL_UNI_F8\n"); break; case UGL_UNI_F9: sprintf(keyText,"UGL_UNI_F9\n"); break; case UGL_UNI_F10: sprintf(keyText,"UGL_UNI_F10\n"); break; case UGL_UNI_F11: sprintf(keyText,"UGL_UNI_F11\n"); break; case UGL_UNI_F12: sprintf(keyText,"UGL_UNI_F12\n"); break; case UGL_UNI_HOME: sprintf(keyText,"UGL_UNI_HOME\n"); break; case UGL_UNI_END: sprintf(keyText,"UGL_UNI_END\n"); break; case UGL_UNI_INSERT: sprintf(keyText,"UGL_UNI_INSERT\n"); break; case UGL_UNI_PAGE_UP: sprintf(keyText,"UGL_UNI_PAGE_UP\n"); break; case UGL_UNI_PAGE_DOWN: sprintf(keyText,"UGL_UNI_PAGE_DOWN\n"); break; case UGL_UNI_LEFT_ARROW: sprintf(keyText,"UGL_UNI_LEFT_ARROW\n"); break; case UGL_UNI_RIGHT_ARROW: sprintf(keyText,"UGL_UNI_RIGHT_ARROW\n"); break; case UGL_UNI_UP_ARROW: sprintf(keyText,"UGL_UNI_UP_ARROW\n"); break; case UGL_UNI_DOWN_ARROW: sprintf(keyText,"UGL_UNI_DOWN_ARROW\n"); break; case UGL_UNI_PRINT_SCREEN: sprintf(keyText,"UGL_UNI_PRINT_SCREEN\n"); break; case UGL_UNI_PAUSE: sprintf(keyText,"UGL_UNI_PAUSE\n"); break; case UGL_UNI_CAPS_LOCK: sprintf(keyText,"UGL_UNI_CAPS_LOCK\n"); break; case UGL_UNI_NUM_LOCK: sprintf(keyText,"UGL_UNI_NUM_LOCK\n"); break; case UGL_UNI_SCROLL_LOCK: sprintf(keyText,"UGL_UNI_SCROLL_LOCK\n"); break; case UGL_UNI_LEFT_SHIFT: sprintf(keyText,"UGL_UNI_LEFT_SHIFT\n"); break; case UGL_UNI_RIGHT_SHIFT: sprintf(keyText,"UGL_UNI_RIGHT_SHIFT\n"); break; case UGL_UNI_LEFT_CTRL: sprintf(keyText,"UGL_UNI_LEFT_CTRL\n"); break; case UGL_UNI_RIGHT_CTRL: sprintf(keyText,"UGL_UNI_RIGHT_CTRL\n"); break; case UGL_UNI_LEFT_ALT: sprintf(keyText,"UGL_UNI_LEFT_ALT\n"); break; case UGL_UNI_RIGHT_ALT: sprintf(keyText,"UGL_UNI_RIGHT_ALT\n"); break; case UGL_UNI_PROGRAM: sprintf(keyText,"UGL_UNI_PROGRAM\n"); break; default: retCode = UGL_FALSE; } /* Use the font we selected for the banner text. */ uglFontSet(gc, fontBanner); uglTextSizeGet(fontBanner, &textWidth, &textHeight, -1, keyText); /* Clear the text area for a new text line. */ uglForegroundColorSet(gc,colorTable[BLACK].uglColor); uglBackgroundColorSet(gc,colorTable[BLACK].uglColor); uglRectangle(gc, 3 * displayWidth / 4, 0, displayWidth, textHeight); /* If the code is not printable, print its description on the banner. */ if (retCode == UGL_TRUE) { uglForegroundColorSet(gc,colorTable[GREEN].uglColor); uglBackgroundColorSet(gc,colorTable[BLACK].uglColor); uglTextDraw(gc, 3 * displayWidth / 4, 0, -1, keyText); } /* * The return code will control whether or not an attempt will be made to * print the character's glyph. No attempt is made for the characters * identified in this function. */ return (retCode); }/**************************************************************************** textEcho - echo the value represented by depressed key** This function renders text in a simple "echo" fashion. It supports wrapping * at the line ends and the bottom of the screen. It also recognizes the * carriage return key, and tab key. The backspace key is not implemented and * treated as a non-printable glyph.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** NOMANUAL*/UGL_LOCAL void textEcho ( UGL_UINT16 scanCode, /* Scan code of entered key */ UGL_WCHAR key /* Unicode value of entered key */ ) { /* These are used to position the text correctly on the screen. */ int textWidth, textHeight; /* UGL outputs a string so we create a one character string here. */ UGL_CHAR output[] = { 0, 0 }; output [0] = (UGL_CHAR) key; /* * Check to see if the key is printable or not. If it is not printable, * then don't try to print it. */ if (!specialKey(scanCode, key)) { /* Use the font we selected for echoing text. */ uglFontSet(gc, fontEcho); /* * Get the size of this particular output string, using the * currently selected font. */ uglTextSizeGet(fontEcho, &textWidth, &textHeight, -1, output); /* * If this was a special key (typically not printable), give it * special treatment. */ /* 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; } }/**************************************************************************
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -