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

📄 ugldemo.c

📁 S1D13506windml下的驱动程序,支持vxworks5.4 支持tornado2.0 windml2.0
💻 C
📖 第 1 页 / 共 2 页
字号:

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

    /* Create Region */

    regionId = uglRegionCreate ();
    uglBackgroundColorSet(gc, colorTable[BLACK].uglColor);
    uglForegroundColorSet(gc, colorTable[LIGHTGREEN].uglColor);
    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 - 1;
    rect.bottom = ((displayHeight - textHeight) / 3) + textHeight - 1;
    rect.left = ((displayWidth - textWidth) / 2 + 1);
    rect.top = ((displayHeight - textHeight) / 3 + 1);
    uglRegionRectExclude (regionId, &rect);
    uglClipRegionSet (gc, regionId);

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

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

    /* Initialization finished, drawing begins */

    ClearScreen(gc);

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

    /* BitmapWrite test */

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

    if(pause(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(pause(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(pause(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(pause(mode) < 0)
	{
	cleanUp(mode);
	return;
	}

    /* Dashed lines */

    ClearScreen(gc);

    uglBatchStart(gc);

    uglLineStyleSet(gc, UGL_LINE_STYLE_DASHED);
    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(pause(mode) < 0)
	{
	cleanUp(mode);
	return;
	}

    /* Wide solid lines */
    
    ClearScreen(gc);

    uglBatchStart(gc);

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

    uglBatchEnd(gc);

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

    /* Wide dashed lines */

    ClearScreen(gc);

    uglBatchStart(gc);

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

    uglBatchEnd(gc);

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

    /* Filled rectangles */

    ClearScreen(gc);

    uglBatchStart(gc);

    index = 0;
    for (i = 0; i < numRandomPoints / 2; i++)
	{
	int left = min(randomData[index], randomData[index + 2]);
	int right = max(randomData[index], randomData[index + 2]);
	int top = min(randomData[index + 1], randomData[index + 3]);
	int bottom = max(randomData[index + 1], randomData[index + 3]);
	uglForegroundColorSet(gc, colorTable[ i % 15 + 1].uglColor);
	uglBackgroundColorSet(gc, colorTable[ 15 - (i % 15)].uglColor);
	uglLineWidthSet(gc, (i % 6) + 1);
	uglRectangle(gc, left, top , right, bottom);
	index += 4;
	}

    uglBatchEnd(gc);

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

    /* Rectangles filled with a pattern */

    ClearScreen(gc);

    uglBatchStart(gc);

    uglFillPatternSet(gc, patternDdb);

    index = 0;
    for (i = 0; i < numRandomPoints / 15; i++)
	{
	int left = min(randomData[index], randomData[index + 2]);
	int right = max(randomData[index], randomData[index + 2]);
	int top = min(randomData[index + 1], randomData[index + 3]);
	int bottom = max(randomData[index + 1], randomData[index + 3]);
	uglForegroundColorSet(gc, colorTable[ i % 15 + 1].uglColor);
	uglBackgroundColorSet(gc, colorTable[ 15 - (i % 15)].uglColor);
	uglLineWidthSet(gc, i % 6 + 1);
	uglRectangle(gc, left, top , right, bottom);
	index += 4;
	}

    uglFillPatternSet(gc, 0);
    uglBatchEnd(gc);

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

    /* Filled polygons */

    ClearScreen(gc);

    uglBatchStart(gc);

    index = 0;
    for (i = 0; i < numRandomPoints / 10; i++)
	{
	uglForegroundColorSet(gc, colorTable[ i % 15 + 1].uglColor);
	uglBackgroundColorSet(gc, colorTable[ 15 - (i % 15)].uglColor);
	randomData[index + 18] = randomData[index];
	randomData[index + 19] = randomData[index + 1];
	uglPolygon(gc, 10, &randomData[index]);
	index += 20;
	}

    uglBatchEnd(gc);

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

    /* Polygons filled with a pattern */

    ClearScreen(gc);

    uglBatchStart(gc);

    uglFillPatternSet(gc, patternDdb);

    index = 0;
    for (i = 0; i < numRandomPoints / 22; i++)
	{
	uglForegroundColorSet(gc, colorTable[ i % 15 + 1].uglColor);
	uglBackgroundColorSet(gc, colorTable[ 15 - (i % 15)].uglColor);
	uglLineWidthSet(gc, i % 4 + 1);
	randomData[index + 18] = randomData[index];
	randomData[index + 19] = randomData[index + 1];
	uglPolygon(gc, 10, &randomData[index]);
	index += 20;
	}

    uglFillPatternSet(gc, 0);
    uglBatchEnd(gc);

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

    /* Text */

    ClearScreen(gc);

    uglBatchStart(gc);

    y = 0;
    textpage = 0;

    for (i = 0; i < 1000; i++)
	{
	uglForegroundColorSet(gc, colorTable[ i % 15 + 1].uglColor);
	uglBackgroundColorSet(gc, colorTable[ 15 - (i % 15)].uglColor);

	switch (i % 3)
	    {
	    case 0:
		uglFontSet(gc, fontSystem);
		uglTextSizeGet(fontSystem, UGL_NULL, &tmp, -1, fontTestText);
		break;

	    case 1:
		uglFontSet(gc, fontDialog);
		uglTextSizeGet(fontDialog, UGL_NULL, &tmp, -1, fontTestText);
		break;

	    case 2:
		uglFontSet(gc, fontFixed);
		uglTextSizeGet(fontFixed, UGL_NULL, &tmp, -1, fontTestText);
		break;

	    }

	uglTextDraw(gc, 0, y, -1, fontTestText);
	y += tmp;

	if (y >= displayHeight)
	    {
	    y = 0;
	    textpage++;
	    }
	}

    uglBatchEnd(gc);

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

    /* Filled Ellipses */

    ClearScreen(gc);

    uglBatchStart(gc);

    index = 0;
    for (i = 0; i < numRandomPoints / 2; i++)
	{
	int left = min(randomData[index], randomData[index + 2]);
	int right = max(randomData[index], randomData[index + 2]);
	int top = min(randomData[index + 1], randomData[index + 3]);
	int bottom = max(randomData[index + 1], randomData[index + 3]);
	uglForegroundColorSet(gc, colorTable[ i % 16].uglColor);
	uglBackgroundColorSet(gc, colorTable[ 15 - (i % 15)].uglColor);
	uglEllipse(gc, left, top, right, bottom, 0, 0, 0, 0);
	index += 4;
	}
    uglBatchEnd(gc);

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

    /* Pie Shapes */

    ClearScreen(gc);

    uglBatchStart(gc);

    index = 0;
    for (i = 0; i < numRandomPoints / 4; i++)
	{
	int left = min(randomData[index], randomData[index + 2]);
	int right = max(randomData[index], randomData[index + 2]);
	int top = min(randomData[index + 1], randomData[index + 3]);
	int bottom = max(randomData[index + 1], randomData[index + 3]);
	uglForegroundColorSet(gc, colorTable[ i % 16].uglColor);
	uglBackgroundColorSet(gc, colorTable[ 15 - (i % 15)].uglColor);
	uglEllipse(gc, left, top, right, bottom,
		       randomData[index + 4], randomData[index + 5],
		       randomData[index + 6], randomData[index + 7]);
	index += 8;
	}
    uglBatchEnd(gc);

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

    /* Stretch Blits */

    ClearScreen(gc);

    uglBitmapStretchBlt(gc,stdDdb,0,0,31,31,UGL_NULL,100,100,200,150);
	
    if(pause(mode) < 0)
	{
	cleanUp(mode);
	return;
	}

    ClearScreen(gc);

    uglBitmapStretchBlt(gc,stdDdb,0,0,31,31,UGL_NULL,100,100,150,200);
	
    if(pause(mode) < 0)
	{
	cleanUp(mode);
	return;
	}

    ClearScreen(gc);

    uglBitmapStretchBlt(gc,stdDdb,0,0,31,31,UGL_NULL,0,0,
			 displayWidth-1, displayHeight-1);

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

    ClearScreen(gc);

    /* Clean Up */
    cleanUp(mode);

    return;
    }

⌨️ 快捷键说明

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