⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 wextext.c

📁 2410/vxworks/tornado下的基本实验包括 serial,ramdrv,interrupt,multi-FTP,TCP,UDP-Under the basic experimental
💻 C
📖 第 1 页 / 共 2 页
字号:
** wexPause - wait for input from keyboard** This routine waits for input from the keyboard and then calls the textEcho()* function to echo the entered key.** This function enters an infinite loop collecting keyboard input and echoing* the key that was depressed.  To break out of the loop the textioStop() * function needs to be invoked from the shell.* * RETURNS: ** ERRNO: N/A** SEE ALSO:  ** NOMANUAL*/UGL_LOCAL void wexPause (void)    {    UGL_MSG msg;    char ch;    /* 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 0        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);                }            }        #endif        #if 1       while((read(fd, &ch, 1) > 0) && (stopWex == 0))       	{      	textEcho((UGL_UINT16)ch, (UGL_UINT16)ch);      	}	  #endif        /* Stop if we get a signal from textioStop. */	  if(stopWex == 1)       break;        }    }#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 [])    {    windMLExampleTextIO();    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);    windMLExampleTextIO();    return (0);    }#else/**************************************************************************** wextext - demonstrate text input/output handling** This routine demonstrates the manner to read from the keyboard and display* the received data.  ** This example program demonstrates how to:**\ml *\m Initialize WindML*\m Identify the graphics device and input devices*\m Determine the resolution of the display*\m Create a graphics context*\m Allocate colors*\m Create the fonts that are to be used*\m Read input from the keyboard*\m Decode the received key, of it is printable then echo the character*\m For keys that are not printable, print a description*\m Releasing all resources and terminating a WindML application.*\me** NOTE:* Test is rendered 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.** SEE ALSO: wextextStop() **/void wextext (void)    {    stopWex = 0;    fd = open("/tyCo/0", 2, 0644);    ioctl (fd, FIOSETOPTIONS, OPT_ECHO | OPT_CRMOD | OPT_TANDEM | \			 OPT_MON_TRAP | OPT_7_BIT | OPT_ABORT );	    printf("To stop wextext, type 'wextextStop'\n");    uglOSTaskCreate("tWindMLtxt", (UGL_FPTR)windMLExampleTextIO, 110, 		    0, 10240, 0,0,0,0,0);    }#endif/**************************************************************************** wextextStop - stop the text input/output example program** This routine stops the text input/output example program.** RETURNS: ** ERRNO: N/A** SEE ALSO: wextext() **/void wextextStop (void)    {    stopWex = 1;    }/**************************************************************************** windMLExampleTextIO - set up demo program and echo keyboard input** This routine initializes the graphics and input devices and then* starts to echo keyboard input.** RETURNS: ** ERRNO: N/A** SEE ALSO:  ** NOMANUAL*/int windMLExampleTextIO (void)    {    /* For registry lookups. */    UGL_REG_DATA *pRegistryData;   /*   * 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 */    pRegistryData = uglRegistryFind (UGL_DISPLAY_TYPE, 0, 0, 0);    if (pRegistryData == UGL_NULL)        {        printf("Display not found. Exiting.\n");	uglDeinitialize();	return(0);	}    devId = (UGL_DEVICE_ID)pRegistryData->id;    /*    * Obtain the input service identifier.  Typically there is only one    * input service, but there can be more than one.    */    pRegistryData = uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0, 0);    if (pRegistryData == UGL_NULL)        {        printf("Input service not found. Exiting.\n");        uglDeinitialize();        return(0);        }    inputServiceId = (UGL_INPUT_SERVICE_ID)pRegistryData->id;    /*    * Obtain the device identifier for the font engine.    */    pRegistryData = uglRegistryFind (UGL_FONT_ENGINE_TYPE, 0, 0, 0);    if (pRegistryData == UGL_NULL)        {        printf("Font engine not found. Exiting.\n");        uglDeinitialize();        return(0);        }    fontDrvId = (UGL_FONT_DRIVER_ID)pRegistryData->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 + -