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

📄 ugldemo.c

📁 VxWorks源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* ugldemo.c - Graphics primitives demonstration program *//* Copyright 1999-2000 Wind River Systems, Inc. All Rights Reserved *//* Copyright 1998 Zinc Software Incorporated. *//*modification history--------------------01n,01aug02,rfm  Removed static declartion of windMLDemo01m,26apr02,gav  Change banner to display actual version.01l,25feb02,wdf  Fixed compiler warnings.01k,22feb02,msr  Backward compatability for input API.01j,29jan02,rbp  Addition of support for Native Unix.01i,28aug01,rbp  Fix for __unix__ macro.01h,23jul01,c_s  Change NATIVE to WINDML_NATIVE (less chance of collision)01g,16jun01,c_s  Allow argv [1] to set mode.01f,15jun01,c_s  Add native support01i,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  Fixed message length to fit on small screens.01d,21nov00,gav  Clearscreen corrected (SPR 36009).01c,16nov00,msr  Fixed SPR #6205101b,27oct00,rfm  Added func ptr cast to taskSpawn01a,25oct00,rfm  Added taskSpawn*//***************************************************************  WindML Example - Demo of primitives** This example program demonstrates basic drawing primitives.** To start the example:** -> ld < ugldemo_ugl.o* -> ugldemo <mode>** If the <mode> parameter is positive, no input devices are * assumed to be present and the demo will wait <mode> number* of seconds before moving to the next test. 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* test. A negative value assumes no input devices are present* and no delay between tests.** To shut down the double buffering test program, either press* 'q' on the keyboard or wait for the test to complete.***************************************************************/#if !defined(WINDML_NATIVE)#include <vxWorks.h>#elif defined(__unix__)#include <unistd.h>#endif#include <ugl/ugl.h>#include <ugl/uglos.h>#include <ugl/uglMsg.h>#include <ugl/uglfont.h>#include <ugl/uglinput.h>#include <ugl/ugldib.h>#include <stdio.h>#include <stdlib.h>extern const unsigned int uglVersionMinor;extern const unsigned int uglVersionMajor;UGL_DEVICE_ID devId;UGL_GC_ID gc;static UGL_INPUT_SERVICE_ID inputServiceId;static UGL_REGION_ID regionId;static UGL_FONT_ID fontDialog;static UGL_FONT_ID fontSystem;static UGL_FONT_ID fontFixed;static UGL_FONT_DRIVER_ID fontDrvId;static UGL_DDB_ID stdDdb;static UGL_MDDB_ID patternDdb;static UGL_CDDB_ID cursorDdb;static UGL_TDDB_ID transDdb;static int *randomData;static UGL_COLOR * colorData;static int displayHeight, displayWidth;void windMLDemo (int mode);struct _colorStruct    {    UGL_RGB rgbColor;    UGL_COLOR uglColor;    }colorTable[] =    {    { UGL_MAKE_RGB(0, 0, 0), 0},    { UGL_MAKE_RGB(0, 0, 168), 0},    { UGL_MAKE_RGB(0, 168, 0), 0},    { UGL_MAKE_RGB(0, 168, 168), 0},    { UGL_MAKE_RGB(168, 0, 0), 0},    { UGL_MAKE_RGB(168, 0, 168), 0},    { 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}    };struct    {    int width;    int height;    unsigned char data[32];    } patternData =    {    16, 16,        {         0xFF, 0xFF,         0x00, 0x01,        0x00, 0x01,        0x00, 0x01,        0x00, 0x01,        0x00, 0x01,        0x00, 0x01,        0x00, 0x01,        0xFF, 0xFF,         0x01, 0x00,        0x01, 0x00,        0x01, 0x00,        0x01, 0x00,        0x01, 0x00,        0x01, 0x00,        0x01, 0x00        }    };#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)#define TRANS			(255)#define INVERT			(254)UGL_ARGB cursorClut[] =    {    UGL_MAKE_RGB(0, 0, 0),    UGL_MAKE_RGB(255, 255, 84),    };UGL_UINT8 cursorData[] =    {#define B 0,#define Y 1,#define T 255,#define I 254,    T T T T T T T T T T T T Y Y Y Y Y Y Y Y T T T T T T T T T T T T    T T T T T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T T T T T    T T T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T T T    T T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T T    T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T    T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T    T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T    T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T    T T Y Y Y Y Y Y Y T T T Y Y Y Y Y Y Y Y I I I Y Y Y Y Y Y Y T T    T Y Y Y Y Y Y Y T T T T T Y Y Y Y Y Y I I I I I Y Y Y Y Y Y Y T    T Y Y Y Y Y Y Y T T T T T Y Y Y Y Y Y I I I I I Y Y Y Y Y Y Y T    T Y Y Y Y Y Y Y T T T T T Y Y Y Y Y Y I I I I I Y Y Y Y Y Y Y T    Y Y Y Y Y Y Y Y Y T T T Y Y Y Y Y Y Y Y I I I Y Y Y Y Y Y Y Y Y    Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y    Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y    Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y    Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y    Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y    Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y    Y Y Y Y Y B B Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y B B Y Y Y Y Y    T Y Y Y Y B B Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y B B Y Y Y Y T    T Y Y Y Y B B B Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y B B B Y Y Y Y T    T Y Y Y Y Y B B Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y B B Y Y Y Y Y T    T T Y Y Y Y B B B Y Y Y Y Y Y Y Y Y Y Y Y Y Y B B B Y Y Y Y T T    T T Y Y Y Y Y B B B B Y Y Y Y Y Y Y Y Y Y B B B B Y Y Y Y Y T T    T T T Y Y Y Y Y B B B B B B Y Y Y Y Y B B B B B Y Y Y Y Y T T T    T T T T Y Y Y Y Y Y B B B B B B B B B B B B Y Y Y Y Y Y T T T T    T T T T T Y Y Y Y Y Y Y Y B B B B B B Y Y Y Y Y Y Y Y T T T T T    T T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T T    T T T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T T T    T T T T T T T T T Y Y Y Y Y Y Y Y Y Y Y Y Y Y T T T T T T T T T    T T T T T T T T T T T T Y Y Y Y Y Y Y Y T T T T T T T T T T T T#undef B#undef Y#undef T#undef I    };UGL_UINT8 transparentData[] =    {#define O BLACK,#define _ BLACK,#define I YELLOW,    O O O O O O O O O O O O I I I I I I I I O O O O O O O O O O O O    O O O O O O O O O I I I I I I I I I I I I I I O O O O O O O O O    O O O O O O O I I I I I I I I I I I I I I I I I I O O O O O O O    O O O O O O I I I I I I I I I I I I I I I I I I I I O O O O O O    O O O O O I I I I I I I I I I I I I I I I I I I I I I O O O O O    O O O O I I I I I I I I I I I I I I I I I I I I I I I I O O O O    O O O I I I I I I I I I I I I I I I I I I I I I I I I I I O O O    O O I I I I I I I I I I I I I I I I I I I I I I I I I I I I O O    O O I I I I I I I _ _ _ I I I I I I I I _ _ _ I I I I I I I O O    O I I I I I I I _ _ _ _ _ I I I I I I _ _ _ _ _ I I I I I I I O    O I I I I I I I _ _ _ _ _ I I I I I I _ _ _ _ _ I I I I I I I O    O I I I I I I I _ _ _ _ _ I I I I I I _ _ _ _ _ I I I I I I I O    I I I I I I I I I _ _ _ I I I I I I I I _ _ _ I I I I I I I I I    I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I    I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I    I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I    I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I    I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I    I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I I    I I I I I _ _ I I I I I I I I I I I I I I I I I I _ _ I I I I I    O I I I I _ _ I I I I I I I I I I I I I I I I I I _ _ I I I I O    O I I I I _ _ _ I I I I I I I I I I I I I I I I _ _ _ I I I I O    O I I I I I _ _ I I I I I I I I I I I I I I I I _ _ I I I I I O    O O I I I I _ _ _ I I I I I I I I I I I I I I _ _ _ I I I I O O    O O I I I I I _ _ _ _ I I I I I I I I I I _ _ _ _ I I I I I O O    O O O I I I I I _ _ _ _ _ _ I I I I I _ _ _ _ _ I I I I I O O O    O O O O I I I I I I _ _ _ _ _ _ _ _ _ _ _ _ I I I I I I O O O O    O O O O O I I I I I I I I _ _ _ _ _ _ I I I I I I I I O O O O O    O O O O O O I I I I I I I I I I I I I I I I I I I I O O O O O O    O O O O O O O I I I I I I I I I I I I I I I I I I O O O O O O O    O O O O O O O O O I I I I I I I I I I I I I I O O O O O O O O O    O O O O O O O O O O O O I I I I I I I I O O O O O O O O O O O O#undef _#undef O#undef I    };UGL_UINT8 transparentMask[] =    {    0x00, 0x0F, 0xF0, 0x00,    0x00, 0x7F, 0xFE, 0x00,    0x01, 0xFF, 0xFF, 0x80,    0x03, 0xFF, 0xFF, 0xC0,    0x07, 0xFF, 0xFF, 0xE0,    0x0F, 0xFF, 0xFF, 0xF0,    0x1F, 0xFF, 0xFF, 0xF8,    0x3F, 0xFF, 0xFF, 0xFC,    0x3F, 0xFF, 0xFF, 0xFC,    0x7F, 0xFF, 0xFF, 0xFE,    0x7F, 0xFF, 0xFF, 0xFE,    0x7F, 0xFF, 0xFF, 0xFE,    0xFF, 0xFF, 0xFF, 0xFF,    0xFF, 0xFF, 0xFF, 0xFF,    0xFF, 0xFF, 0xFF, 0xFF,    0xFF, 0xFF, 0xFF, 0xFF,    0xFF, 0xFF, 0xFF, 0xFF,    0xFF, 0xFF, 0xFF, 0xFF,    0xFF, 0xFF, 0xFF, 0xFF,    0xFF, 0xFF, 0xFF, 0xFF,    0x7F, 0xFF, 0xFF, 0xFE,    0x7F, 0xFF, 0xFF, 0xFE,    0x7F, 0xFF, 0xFF, 0xFE,    0x3F, 0xFF, 0xFF, 0xFC,    0x3F, 0xFF, 0xFF, 0xFC,    0x1F, 0xFF, 0xFF, 0xF8,    0x0F, 0xFF, 0xFF, 0xF0,    0x07, 0xFF, 0xFF, 0xE0,    0x03, 0xFF, 0xFF, 0xC0,    0x01, 0xFF, 0xFF, 0x80,    0x00, 0x7F, 0xFE, 0x00,    0x00, 0x0F, 0xF0, 0x00    };/**************************************************************************** flushQ** RETURNS: void** NOMANUAL**/static void flushQ(void)    {    UGL_MSG msg;    UGL_STATUS status;    do        {        status = uglInputMsgGet (inputServiceId, &msg, UGL_NO_WAIT);	if (msg.type == MSG_POINTER)	    {	    uglCursorMove(devId,			  msg.data.pointer.position.x,			  msg.data.pointer.position.y);	    }        } while (status != UGL_STATUS_Q_EMPTY);    }/**************************************************************************** pauseDemo** RETURNS: 0 if 'q' wasn't pressed, -1 if 'q' was pressed.** NOMANUAL**/static int pauseDemo(int mode)    {    static UGL_CHAR * message = "Press 'q' to quit or any other";    static UGL_CHAR * message2= "key (or mouse button) to continue.";    int textWidth, textHeight;    UGL_MSG msg;    UGL_STATUS status;    int retVal = 0;    if (mode == 0 && inputServiceId != UGL_NULL)	{	uglBackgroundColorSet(gc, colorTable[BLACK].uglColor);	uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor);	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);	flushQ();	UGL_FOREVER	    {	    status = uglInputMsgGet (inputServiceId, &msg, UGL_WAIT_FOREVER);            if (msg.type == MSG_KEYBOARD)                {                if (msg.data.keyboard.modifiers & UGL_KBD_KEYDOWN)                     {                    if (msg.data.keyboard.key == 'q' ||                        msg.data.keyboard.key == 'Q')                        retVal = -1;                    break;                    }                }            else if (msg.type == MSG_POINTER)                {                uglCursorMove (devId, msg.data.pointer.position.x,                               msg.data.pointer.position.y);                if ((msg.data.pointer.buttonChange &                      msg.data.pointer.buttonState) != 0)                    break;                }	    }	}    else if (mode > 0)	{	uglOSTaskDelay (mode * 1000);	}    return(retVal);    }/**************************************************************************** ClearScreen** RETURNS: void** NOMANUAL**/static void ClearScreen(UGL_GC_ID gc)    {    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** RETURNS: void** NOMANUAL**/static void cleanUp(int 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();    }/**************************************************************************** ugldemo - entry point for the demo** This routine performs a basic test of the drawing primitives. <mode> is* the number of seconds to wait between tests if no keyboard is present.* If <mode> is 0, a keyboard is assumed to be present and will wait for * a key press in between 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**/#if defined(WINDML_NATIVE) && defined(__unix__)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)int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance,                   LPSTR lpCmdLine, int nShowCmd)    {    uglWin32Parameters(hInstance, hPrevInstance, lpCmdLine, nShowCmd);    windMLDemo(0);    return (0);    }#elsevoid ugldemo (int mode)    {    uglOSTaskCreate("tWindMLDemo", (UGL_FPTR)windMLDemo, 110, 0, 10000, 		    mode,0,0,0,0);    }#endif/**************************************************************************** windMLDemo - entry point for the demo** RETURNS: void** ERRNO: N/A** SEE ALSO: N/A** NOMANUAL**/void windMLDemo (int mode)    {    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 */    devId = (UGL_DEVICE_ID)uglRegistryFind (UGL_DISPLAY_TYPE,  0, 0,0)->id;    if (mode >= 0)	{	/* obtain the input service identifier. */	inputServiceId = (UGL_INPUT_SERVICE_ID)uglRegistryFind (UGL_INPUT_SERVICE_TYPE,  0, 0,0)->id;	}    /* Create a graphics context */    gc = uglGcCreate(devId);    /* Create Fonts */    fontDrvId =  (UGL_FONT_DRIVER_ID)uglRegistryFind (UGL_FONT_ENGINE_TYPE,  0, 0,0)->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;                }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -