📄 wexbasic.c
字号:
/* wexbasic.c - WindML Basic Graphics Primitive example program *//* Copyright 2000 Wind River Systems, Inc. All Rights Reserved *//*modification history--------------------01k,22feb02,msr Backward compatability for input API.01j,29jan02,rbp Addition of support for Native Unix.01i,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,19dec00,gav Entry point identical to filename w/o extension.01d,20nov00,gav Relative object positioning.01c,27oct00,rfm Added stdio usage01b,26oct00,rfm Modified entry point01a,25oct00,rfm Added modification history*//*************************************************************** WindML Example - Basic Graphics Primitives** This example program demonstrates how to draw basic primitives* to the screen.** To start the example:** -> ld < wexbasic_ugl.o* -> wexbasic** To stop the example:** -> wexbasicStop***************************************************************//* 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 <ugl/uglinput.h>/* A forward declaration for this program. */UGL_LOCAL int windMLExampleBasic (void);/* Global variables *//* Control variable to signal when to stop program */UGL_LOCAL volatile UGL_BOOL stopWex;/* Some graphics environment information */UGL_LOCAL int displayHeight, displayWidth;/* input service */UGL_LOCAL UGL_INPUT_SERVICE_ID inputServiceId;/** 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_ARGB(0xff, 0, 0, 0), 0}, /* The color table uses ARGB's */ { UGL_MAKE_ARGB(0xff, 0, 0, 168), 0}, /* (see uglColorAlloc). */ { UGL_MAKE_ARGB(0xff, 0, 168, 0), 0}, /* Initialize alpha to 255 for */ { UGL_MAKE_ARGB(0xff, 0, 168, 168), 0},/* now (opaque). */ { UGL_MAKE_RGB(168, 0, 0), 0}, /* UGL_MAKE_RGB takes care of */ { UGL_MAKE_RGB(168, 0, 168), 0}, /* the alpha for us. */ { 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} };/* 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)/* * 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.*/UGL_LOCAL struct { int width; int height; unsigned char data[32]; } patternData = { 16, 16, { 0xFF, 0xFF, /* a brick pattern */ 0x00, 0x01, 0x00, 0x01, /* 8 pixels per byte */ 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 } };/* Use this to make sure the frame buffer is clear */UGL_LOCAL 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); }/** Wait for the signal to stop. This is the last function* called before freeing resources and de-initializing UGL.*/UGL_LOCAL void wexPause(void) { while (!stopWex) { UGL_MSG msg; if ((uglInputMsgGet (inputServiceId, &msg, 140) != UGL_STATUS_Q_EMPTY) && msg.type == MSG_KEYBOARD) stopWex = UGL_TRUE; } }/** Start the example program. This function and the basicStop function* can be invoked from the host shell in order to control the program.*/#if defined(WINDML_NATIVE) && defined(__unix__)int main (int argc, char *argv []) { windMLExampleBasic(); return (0); }#elif defined(WINDML_NATIVE) && defined(_WIN32)int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd) { uglWin32Parameters(hInstance, hPrevInstance, lpCmdLine, nShowCmd); windMLExampleBasic(); return (0); }#elsevoid wexbasic (void) { stopWex = UGL_FALSE; printf("To stop wexbasic, type 'wexbasicStop'\n"); uglOSTaskCreate("tWindMLbas", (UGL_FPTR)windMLExampleBasic, 110, 0, 10240,0,0,0,0,0); }#endif/* Stop the example program; by signalling the wexPause function. */void wexbasicStop (void) { stopWex = UGL_TRUE; }/* The main function */UGL_LOCAL int windMLExampleBasic (void) { /* An int for miscellaneous counters,etc. */ int i; /* * 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_GC_ID gc; /* * 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; /* * As mentioned in the comments to patternData, the fill pattern * is defined as a monochrome bitmap for certain drawing primitives. * To create the bitmap (UGL_MDDB_ID), a Device Independent Bitmap * (DIB) is used; in particular a monochrome DIB (UGL_MDIB). The * "DDB" in UGL_MDDB_ID stands for Device Dependent Bitmap. Often * the DDB is simply referred to as a "bitmap" and the DIB is * called a "dib" (it's easier to pronounce dib than ddb). */ UGL_MDIB patternDib; UGL_MDDB_ID patternBitmap; /* * Initialize UGL. Must do this before trying to do anything * else within UGL/WindML. */ uglInitialize(); /* Obtain the device identifier for the display */ devId = (UGL_DEVICE_ID)uglRegistryFind (UGL_DISPLAY_TYPE, 0, 0,0)->id; inputServiceId = (UGL_INPUT_SERVICE_ID)uglRegistryFind (UGL_INPUT_SERVICE_TYPE, 0, 0,0)->id; /* * Obtain the dimensions of the display. We will use these * to center some of our objects. */ 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); /* * 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. * * We have set up for 16 colors, so here we will "allocate" them * 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).
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -