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

📄 ugldemo.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
📖 第 1 页 / 共 3 页
字号:
	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);
    }
#else
void showugl (int mode)
    {
    uglOSTaskCreate("tWindMLDemo", (UGL_FPTR)windMLDemo, 110, 0, 10000, 
		    mode,0,0,0,0);
    }
#endif

#define SWAP16(x) ((((x) << 8) | ((x) >> 8)) & 0xFFFF)
#define SWAP32(x)               \
  (((x) << 24) |                \
  (((x) & 0x0000FF00) << 8) |   \
  (((x) & 0x00FF0000) >> 8) |   \
  (((unsigned int)(x)) >> 24))

void fbtestcolor(short color)
{
	int i;
	volatile unsigned short *fb_buffer = (volatile unsigned short *)0xdc000000;
	/*while(1)
	{*/
		for(i=0;i<(640*480);i++)
		{
		fb_buffer[i] = colorTable[color].uglColor;
		}

		taskDelay(1);
	/*}*/
}
/**************************************************************************
*
* 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;
int k;
    /* 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;        
        }

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

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

    uglFontFindString(fontDrvId, "familyName=Courier; pixelSize = 12", &fixedFontDef);

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

    /* Obtain the demensions of the display */

    uglInfo(devId, UGL_FB_INFO_REQ, &fbInfo);
    displayWidth = fbInfo.width;
    displayHeight = fbInfo.height;

    /* Setup random points */

    srand(6);
    numRandomPoints = 2000;
    randomData = (int *)UGL_MALLOC(2 * numRandomPoints * sizeof(int));
    for (i = 0; i < numRandomPoints * 2; i += 2)
	{
	randomData[i] = (rand() % displayWidth);
	randomData[i + 1] = (rand() % displayHeight);
	}

    /* 	Initialize colors. */

    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[CYAN].rgbColor, UGL_NULL,
                  &colorTable[CYAN].uglColor, 1);
    uglColorAlloc(devId, &colorTable[RED].rgbColor, UGL_NULL,
                  &colorTable[RED].uglColor, 1);
    uglColorAlloc(devId, &colorTable[MAGENTA].rgbColor, UGL_NULL,
                  &colorTable[MAGENTA].uglColor, 1);
    uglColorAlloc(devId, &colorTable[BROWN].rgbColor, UGL_NULL,
                  &colorTable[BROWN].uglColor, 1);
    uglColorAlloc(devId, &colorTable[LIGHTGRAY].rgbColor, UGL_NULL,
                  &colorTable[LIGHTGRAY].uglColor, 1);
    uglColorAlloc(devId, &colorTable[DARKGRAY].rgbColor, UGL_NULL,
                  &colorTable[DARKGRAY].uglColor, 1);
    uglColorAlloc(devId, &colorTable[LIGHTBLUE].rgbColor, UGL_NULL,
                  &colorTable[LIGHTBLUE].uglColor, 1);
    uglColorAlloc(devId, &colorTable[LIGHTGREEN].rgbColor, UGL_NULL,
                  &colorTable[LIGHTGREEN].uglColor, 1);
    uglColorAlloc(devId, &colorTable[LIGHTCYAN].rgbColor, UGL_NULL,
                  &colorTable[LIGHTCYAN].uglColor, 1);
    uglColorAlloc(devId, &colorTable[LIGHTRED].rgbColor, UGL_NULL,
                  &colorTable[LIGHTRED].uglColor, 1);
    uglColorAlloc(devId, &colorTable[LIGHTMAGENTA].rgbColor, UGL_NULL,
                  &colorTable[LIGHTMAGENTA].uglColor, 1);
    uglColorAlloc(devId, &colorTable[YELLOW].rgbColor,  UGL_NULL,
                  &colorTable[YELLOW].uglColor, 1);
    uglColorAlloc(devId, &colorTable[WHITE].rgbColor,  UGL_NULL,
                  &colorTable[WHITE].uglColor, 1);
	
printf("displayWidth=%d,displayHeight=%d\n",displayWidth,displayHeight);
#if 0
	for(k=0;k<16;k++)
{
printf("rgbColor=0x%x,uglColor=0x%x\n",colorTable[k].rgbColor,colorTable[k].uglColor);
}
#endif
#if 0
colorTable[BLACK].uglColor = SWAP16((unsigned short)colorTable[BLACK].uglColor);
colorTable[BLUE].uglColor = SWAP16((unsigned short)colorTable[BLUE].uglColor);
colorTable[GREEN].uglColor = SWAP16((unsigned short)colorTable[GREEN].uglColor);
colorTable[CYAN].uglColor = SWAP16((unsigned short)colorTable[CYAN].uglColor);
colorTable[RED].uglColor = SWAP16((unsigned short)colorTable[RED].uglColor);
colorTable[MAGENTA].uglColor = SWAP16((unsigned short)colorTable[MAGENTA].uglColor);
colorTable[BROWN].uglColor = SWAP16((unsigned short)colorTable[BROWN].uglColor);
colorTable[LIGHTGRAY].uglColor = SWAP16((unsigned short)colorTable[LIGHTGRAY].uglColor);
colorTable[DARKGRAY].uglColor = SWAP16((unsigned short)colorTable[DARKGRAY].uglColor);
colorTable[LIGHTBLUE].uglColor = SWAP16((unsigned short)colorTable[LIGHTBLUE].uglColor);
colorTable[LIGHTGREEN].uglColor = SWAP16((unsigned short)colorTable[LIGHTGREEN].uglColor);
colorTable[LIGHTCYAN].uglColor = SWAP16((unsigned short)colorTable[LIGHTCYAN].uglColor);
colorTable[LIGHTRED].uglColor = SWAP16((unsigned short)colorTable[LIGHTRED].uglColor);
colorTable[LIGHTMAGENTA].uglColor = SWAP16((unsigned short)colorTable[LIGHTMAGENTA].uglColor);
colorTable[YELLOW].uglColor = SWAP16((unsigned short)colorTable[YELLOW].uglColor);
colorTable[WHITE].uglColor = SWAP16((unsigned short)colorTable[WHITE].uglColor);
#endif

#if 0
for(k=0;k<16;k++)
{
printf("rgbColor=0x%x,uglColor=0x%x\n",colorTable[k].rgbColor,colorTable[k].uglColor);
}
#endif
    /* Create Region */
#if 1
    regionId = uglRegionCreate ();
    uglBackgroundColorSet(gc, colorTable[YELLOW].uglColor);
    uglForegroundColorSet(gc, colorTable[LIGHTGREEN].uglColor);

    sprintf(regionMessage,"Hello kuangyaowen");

    uglTextSizeGet(fontDialog, &textWidth, &textHeight, 
		   -1, regionMessage);
    uglFontSet(gc, fontDialog);
    uglTextDraw(gc, (displayWidth - textWidth) / 2, 
                    (displayHeight - textHeight) / 3, -1, regionMessage);
	
    rect.left = rect.top = 0;
    rect.right = displayWidth - 1;
    rect.bottom = displayHeight - 1;
    uglRegionRectInclude (regionId, &rect);
    rect.right = ((displayWidth - textWidth) / 2) + textWidth + 5;
    rect.bottom = ((displayHeight - textHeight) / 3) + textHeight + 5;
    rect.left = ((displayWidth - textWidth) / 2) - 6;
    rect.top = ((displayHeight - textHeight) / 3) - 6;
    uglRegionRectExclude (regionId, &rect);
    uglClipRegionSet (gc, regionId);
#endif

#if 1
    /* Create the brick pattern */

    patternDib.width = patternDib.stride = patternData.width;
    patternDib.height = patternData.height;
    patternDib.pImage = patternData.data;
    patternDdb = uglMonoBitmapCreate(devId, &patternDib, 
                                        UGL_DIB_INIT_DATA, 0, UGL_NULL);

    /* Create standard and transparent DDBs */

    colorData = (UGL_COLOR *)UGL_MALLOC(32 * 32 * sizeof(UGL_COLOR));

if(colorBit = 16)
{
    for (i = 0; i < 32 * 32; i++)
	colorData[i] = SWAP16(colorTable[transparentData[i]].uglColor);
}
else
{
    for (i = 0; i < 32 * 32; i++)
	colorData[i] = colorTable[transparentData[i]].uglColor;

}


    (UGL_COLOR *)transDib.pImage = colorData;
    transDib.colorFormat = UGL_DEVICE_COLOR_32;
    transDib.clutSize = 0;
    transDib.pClut = UGL_NULL;
    transDib.imageFormat = UGL_DIRECT;
    transDib.width = transDib.height = transDib.stride = 32;

    stdDdb = uglBitmapCreate(devId, &transDib, UGL_DIB_INIT_DATA, 0,
                                 UGL_NULL);

    transMdib.width = transMdib.stride = transMdib.height = 32;
    transMdib.pImage = transparentMask;

    transDdb = uglTransBitmapCreate(devId, &transDib, &transMdib,
                                        UGL_DIB_INIT_DATA, 0, UGL_NULL);

    /* Create the cursor */

    if (mode >= 0 && inputServiceId != UGL_NULL)
	{
	uglCursorInit (devId, 32, 32, displayWidth / 2, displayHeight / 2);
	cursorDib.width = cursorDib.height = cursorDib.stride = 32;
	cursorDib.hotSpot.x = cursorDib.hotSpot.y = 16;
	cursorDib.pImage = cursorData;
	cursorDib.clutSize = 2;
	cursorDib.pClut = cursorClut;
	cursorDdb = uglCursorBitmapCreate(devId, &cursorDib);
	uglCursorImageSet (devId, cursorDdb);

	uglCursorOn(devId);
	}
	
#endif

#if 1
    /* Initialization finished, drawing begins */

    ClearScreen(gc);

    if(pauseDemo(mode) < 0)
	{
	cleanUp(mode);
	return;
	}


    /* BitmapWrite test */

    uglBitmapWrite(devId, &transDib, 0,0,31,31,UGL_DISPLAY_ID,100,100);

    if(pauseDemo(mode) < 0)
	{
	cleanUp(mode);
	return;
	}

    /* DDB blt */

    ClearScreen(gc);

    uglBatchStart(gc);

    for (i = 0; i < 1000; i++)
	uglBitmapBlt(gc, stdDdb,0,0,31,31,UGL_DEFAULT_ID, randomData[i],randomData[i+1]);

    uglBatchEnd(gc);

    if(pauseDemo(mode) < 0)
	{
	cleanUp(mode);
	return;
	}

	
    /* TDDB blt */

    ClearScreen(gc);

    uglBatchStart(gc);

    for (i = 0; i < 1000; i++)
	uglBitmapBlt(gc, transDdb,0,0,31,31,UGL_DEFAULT_ID, randomData[i],randomData[i+1]);

    uglBatchEnd(gc);

    if(pauseDemo(mode) < 0)
	{
	cleanUp(mode);
	return;
	}
	
	

    /* Simple lines */

    ClearScreen(gc);

    uglBatchStart(gc);

    index = 0;
    for (i = 0; i < numRandomPoints / 2; i++)
	{
	uglForegroundColorSet(gc, colorTable[ i % 16].uglColor);
	uglLine(gc, randomData[index], randomData[index + 1],
		    randomData[index + 2], randomData[index + 3]);
	index += 4;
	}

    uglBatchEnd(gc);

    if(pauseDemo(mode) < 0)
	{
	cleanUp(mode);
	return;
	}

    /* Dashed lines */

    ClearScreen(gc);

⌨️ 快捷键说明

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