📄 ugldemo.c
字号:
/* ugldemo.c - Graphics primitives demonstration program *//* Copyright 1999-2003 Wind River Systems, Inc. All Rights Reserved *//* Copyright 1998 Zinc Software Incorporated. *//*modification history--------------------01r,09may03,jlb Correct version number display format01q,16apr03,jlb Improved comments and program documentation and updated version display01p,02apr03,jlb Correct Diab compile warning01o,01apr03,sts [SPR 86504] Use uglRegistryFind() safely.01n,01aug02,rfm Removed static declaration of windMLDemo01m,26apr02,gav Change banner to display actual version.01l,25feb02,wdf Fixed compiler warnings.01k,22feb02,msr Backward compatibility 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*//*DESCRIPTION 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.*/#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>#include <ioLib.h>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;int fd;void windMLDemo (int mode);/** 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.*/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} };/* * This is the data for a user defined fill pattern that* can be used with various drawing primitives. This data* will be used to create a monochrome DIB (MDIB), which* will be used in turn to create a monochrome "bitmap".* It is the bitmap that is used by the drawing primitives.** Solid fills do not need to have a pattern defined, just* pass an UGL_NULL value in the pattern parameter to* revert (it is the default) to solid fills.*/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 } };/* Label the colors we defined */#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)/* Definition of a smiley face cursor */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 - flush the input message queue and update cursor position** This routine reads from the input message queue until it is empty. If the* message type was a pointer position update, the cursor is repositioned on* the display.** RETURNS: ** ERRNO: N/A** SEE ALSO: ** 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 - wait for input from keyboard or pointer** If the <mode> is "0" and there was an input device configured, this * routine waits for input from the keyboard or the pointer. If the input* was from the pointer and no button was pressed, the cursor position is * updated accordingly. If the input was from the pointer and a button was* pressed or if it was from the keyboard (other than a "q" or "Q" ) then* the routine exits with a value of 0. If a "q" or a "Q" was entered then* the exit value is -1.** If the <mode> was a positive number then the routine will not wait* for input from the input queue but rather delay the number of clock ticks* represented in the operating mode.** RETURNS: -1 when a "q" or "Q" entered; otherwise 0** ERRNO: N/A** SEE ALSO: ** NOMANUAL**/static int pauseDemo ( int mode /* operating 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; char ch; 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); } else if(mode == -1) { ioctl (fd, FIOFLUSH, 0); uglBackgroundColorSet(gc, colorTable[BLACK].uglColor); uglForegroundColorSet(gc, colorTable[LIGHTRED].uglColor);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -