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

📄 ugldemo.c

📁 S1D13506windml下的驱动程序,支持vxworks5.4 支持tornado2.0 windml2.0
💻 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
--------------------
01e,30nov00,gav  Fixed message length to fit on small screens.
01d,21nov00,gav  Clearscreen corrected (SPR 36009).
01c,16nov00,msr  Fixed SPR #62051
01b,27oct00,rfm  Added func ptr cast to taskSpawn
01a,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.
*
**************************************************************/

#include <vxWorks.h>
#include <taskLib.h>
#include <ugl/ugl.h>
#include <ugl/uglevent.h>
#include <ugl/uglfont.h>
#include <ugl/uglinput.h>
#include <ugl/ugldib.h>
#include <ugl/uglmedia.h>
#include <stdio.h>
#include <stdlib.h>
#include <sysLib.h>

UGL_DEVICE_ID devId;
UGL_GC_ID gc;
static UGL_EVENT_SERVICE_ID eventServiceId;
static UGL_EVENT_HANDLER_ID eventHandlerId;
static UGL_EVENT_Q_ID qId;
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;

static 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_EVENT event;
    UGL_STATUS status;

    do
        {
        status = uglEventGet (qId, &event, sizeof (event), UGL_NO_WAIT);

        if (event.header.type == UGL_EVENT_TYPE_POINTER)
            {
            UGL_INPUT_EVENT *pInputEvent = (UGL_INPUT_EVENT *)&event;
            uglCursorMove(gc->pDriver, pInputEvent->x, pInputEvent->y);
            }

        } while (status != UGL_STATUS_Q_EMPTY);
    }

/**************************************************************************
*
* pause
*
* RETURNS: 0 if 'q' wasn't pressed, -1 if 'q' was pressed.
*
* NOMANUAL
*
*/

static int pause(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_EVENT event;
    UGL_STATUS status;
    int retVal = 0;

    if (mode == 0 && eventServiceId != 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 = uglEventGet (qId, &event, sizeof (event), UGL_WAIT_FOREVER);

	    if (status != UGL_STATUS_Q_EMPTY)
		{
		UGL_INPUT_EVENT * pInputEvent = (UGL_INPUT_EVENT *)&event;
		if (((pInputEvent->type.keyboard.key == 'q') ||
		     (pInputEvent->type.keyboard.key == 'Q')) && 
		    pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) 
		    {
		    retVal = -1;
		    break;
		    }
		else if ((pInputEvent->modifiers & UGL_KEYBOARD_KEYDOWN) || 
			 ((pInputEvent->type.pointer.buttonChange & 
			   pInputEvent->type.pointer.buttonState) != 0))
		    break;
		}
	    }
	}
    else if (mode > 0)
	{
	taskDelay(sysClkRateGet() * mode);
	}

    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 && eventServiceId != 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);

    if (mode >= 0 && eventServiceId != UGL_NULL)
	{
	uglEventCallbackRemove(eventHandlerId, UGL_EVENT_TYPE_POINTER,
			       UGL_EVENT_CATEGORY_INPUT, uglCallbackCursorMove);
	uglMediaDeinit();
	uglEventQDestroy (eventServiceId, qId);
	}

    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
*
*/


void ugldemo (int mode)
    {
    taskSpawn("tWindMLDemo", 110, 0, 10000, (FUNCPTR)windMLDemo,
              mode,1,2,3,4,5,6,7,8,9);
    }

/**************************************************************************
*
* windMLDemo - entry point for the demo
*
* RETURNS: void
*
* ERRNO: N/A
*
* SEE ALSO: N/A
*
* NOMANUAL
*
*/

UGL_LOCAL 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 = "Welcome to WindML 2.0";
    int textWidth, textHeight;
    UGL_FB_INFO fbInfo;
    UGL_RECT rect;

    /* Initialize UGL */

    if (uglInitialize() == UGL_STATUS_ERROR)
	return;

    /* Obtain display device identifier */

    uglDriverFind (UGL_DISPLAY_TYPE, 0, (UGL_UINT32 *)&devId);

    if (mode >= 0)
	{
	/* obtain the input service identifier and create the input queue. */

	if (uglDriverFind (UGL_EVENT_SERVICE_TYPE, 0, (UGL_UINT32 *)&eventServiceId) ==
	    UGL_STATUS_OK)
	    {
	    qId = uglEventQCreate (eventServiceId, 100);

	    /* Attach the auto cursor move callback */

	    uglMediaInit();
	    uglEventHandlerGet (eventServiceId, &eventHandlerId);
	    uglEventCallbackAdd (eventHandlerId, UGL_EVENT_TYPE_POINTER, 
				 UGL_EVENT_CATEGORY_INPUT, uglCallbackCursorMove);
	    }
	else
	    {
	    eventServiceId = UGL_NULL;
	    }
	}
    /* Create a graphics context */

    gc = uglGcCreate(devId);

    /* Create Fonts */

    uglDriverFind (UGL_FONT_ENGINE_TYPE, 0, (UGL_UINT32 *)&fontDrvId);

    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;        
        }

    uglFontFindString(fontDrvId, "familyName=Helvetica; pixelSize = 18", &dialogFontDef);

    if ((fontDialog = uglFontCreate(fontDrvId, &dialogFontDef)) == UGL_NULL)
        {
 	printf("Font not found. Exiting.\n");
	return;       
        }

⌨️ 快捷键说明

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