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

📄 uglgc.c

📁 cpc-1631的BSP包for VxWorks操作系统
💻 C
📖 第 1 页 / 共 3 页
字号:

UGL_STATUS uglDefaultBitmapSet
    (
    UGL_GC_ID gc,			/* graphics context */
    UGL_DDB_ID defaultBitmap		/* new default bitmap setting */
    )
    {
    UGL_DEVICE_ID devId;

    if (UGL_NULL == gc)
        return (UGL_STATUS_ERROR);

    if (UGL_NULL == defaultBitmap) /* UGL_DEFAULT_ID currently == UGL_NULL */
        defaultBitmap = UGL_DISPLAY_ID;
    else if (defaultBitmap != UGL_DISPLAY_ID && defaultBitmap->type != UGL_DDB_TYPE)
        return (UGL_STATUS_ERROR);

    devId = gc->pDriver;

    uglOSLock(gc->lockId);

    if (gc->pDefaultBitmap != defaultBitmap)
        {
        gc->pDefaultBitmap = defaultBitmap;

        if (UGL_DISPLAY_ID == defaultBitmap)
            {
            gc->boundRect.left = gc->boundRect.top = 0;
            gc->boundRect.right = devId->pMode->width - 1;
            gc->boundRect.bottom = devId->pMode->height - 1;
            }
        else
            {
            gc->boundRect.left = gc->boundRect.top = 0;
            gc->boundRect.right = defaultBitmap->width - 1;
            gc->boundRect.bottom = defaultBitmap->height - 1;
            }

        uglViewPortSet(gc, gc->boundRect.left, gc->boundRect.top,
                       gc->boundRect.right, gc->boundRect.bottom);

        gc->changed |= UGL_GC_DEFAULT_BITMAP_CHANGED;
        UGL_GC_CHANGED_SET(gc);

        /* Protect software cursors. */
        if (devId->cursorHide != UGL_NULL &&
            UGL_DISPLAY_ID == gc->pDefaultBitmap && 
            devId->magicNumber == gc->magicNumber &&
            devId->batchCount > 0)
            {
            UGL_RECT hideRect = gc->clipRect;

            hideRect.left += gc->viewPort.left;
            hideRect.right += gc->viewPort.left;
            hideRect.top += gc->viewPort.top;
            hideRect.bottom += gc->viewPort.top;

            uglOSLock (devId->lockId);
            (*devId->cursorHide) (devId, &hideRect);
            uglOSUnlock (devId->lockId);                
            }
        }

    uglOSUnlock (gc->lockId);

    return (UGL_STATUS_OK);
    }
    

/***************************************************************************
*
* uglFillPatternGet - get a graphics context's fill pattern setting
*
* This routine gets the current fill pattern setting of the graphics 
* context <gc>. The fill pattern bitmap identifier is written to 
* <pPatternBitmap>. A NULL value indicates a solid pattern.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglFillPatternSet()
*
*/

UGL_STATUS uglFillPatternGet
    (
    UGL_GC_ID gc,			/* graphics context */
    UGL_MDDB_ID *pPatternBitmap	        /* pattern bitmap ID */
    )
    {

    if (UGL_NULL == gc)
        return (UGL_STATUS_ERROR);

    *pPatternBitmap = gc->pPatternBitmap;

    return (UGL_STATUS_OK);
    }


/****************************************************************************
*
* uglFillPatternSet - sets a graphics context's fill pattern
*
* This routine sets the fill pattern for the  graphics context <gc> to the 
* pattern bitmap specified by the monochrome bitmap <patternBitmap>. A NULL 
* value for <patternBitmap> indicates a solid fill.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglFillPatternGet()
*/

UGL_STATUS uglFillPatternSet
    (
    UGL_GC_ID gc, 			/* graphics context */
    UGL_MDDB_ID patternBitmap		/* new pattern bitmap */
    )
    {

    if (UGL_NULL == gc)
        return (UGL_STATUS_ERROR);

    uglOSLock(gc->lockId);

    if (gc->pPatternBitmap != patternBitmap)
        {
        gc->pPatternBitmap = patternBitmap;
        gc->changed |= UGL_GC_PATTERN_BITMAP_CHANGED;
        UGL_GC_CHANGED_SET(gc);
        }

    uglOSUnlock (gc->lockId);

    return (UGL_STATUS_OK);
    }


/***************************************************************************
*
* uglForegroundColorGet - gets a graphics context's foreground color setting
*
* This routine gets the foreground color of graphics context <gc>. The 
* foreground color is written to the location specified by the parameter 
* <pForegroundColor>.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglForegroundColorSet()
* 
*/

UGL_STATUS uglForegroundColorGet
    (
    UGL_GC_ID gc, 			/* graphics context */
    UGL_COLOR * pForegroundColor	/* forground color setting */
    )
    {

    if (UGL_NULL == gc)
        return (UGL_STATUS_ERROR);

    *pForegroundColor = gc->foregroundColor;
	
    if(colorBit ==16)
	{
*pForegroundColor = SWAP16((UINT16)(*pForegroundColor));
    	}
    return (UGL_STATUS_OK);
    }


/*******************************************************************************
*
* uglForegroundColorSet - sets a graphics context's foreground color
*
* This routine sets the foreground color of the graphics context specified 
* by the parameter <gc> to the color specified by the parameter <color>. The 
* foreground color is used during UGL rendering operations such as drawing 
* lines, outlines for shapes, and text.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglForegroundColorGet()
*/

UGL_STATUS uglForegroundColorSet
    (
    UGL_GC_ID gc,	/* graphics context */
    UGL_COLOR color	/* new foreground color */
    )
    {
    if(colorBit ==16)
	{
	color = SWAP16((UINT16)color);
	}
	/*printf("uglForegroundColorSet:color=0x%x\n",color);*/

    if (UGL_NULL == gc)
        return (UGL_STATUS_ERROR);

    uglOSLock(gc->lockId);

    if (gc->foregroundColor != color)
        {
        gc->foregroundColor = color;
        gc->changed |= UGL_GC_FOREGROUND_COLOR_CHANGED;
        UGL_GC_CHANGED_SET(gc);
        }

    uglOSUnlock (gc->lockId);

    return (UGL_STATUS_OK);
    }


/*******************************************************************************
*
* uglGcCopy - copies a graphics context
*
* This routine copies the contents of a graphics context <srcGc> to another
* graphics context <dstGc>.  Both the source and destination graphics contexts
* must previously exist.  After the copy operation the <dstGc> is identical
* to the <srcGc> with the exception that each graphics context will have 
* its own lock identifier.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <srcGc> or <dstGc> are null.
*
* ERRNO: N/A
*
* SEE ALSO: uglGcCreate()
*
* INTERNAL
*
* The copy operation copies all fields of the GC from the source to the
* destination except that the magicNumber and the GC lock are preserved.
*
*/

UGL_STATUS uglGcCopy
    (
    UGL_GC_ID srcGc,	/* source graphics context */
    UGL_GC_ID dstGc     /* destination graphics context */
    )
    {
    UGL_LOCK_ID lockId;
    UGL_UINT32 magicNumber;

    if ((srcGc == UGL_NULL) || (dstGc == UGL_NULL)) 
        return (UGL_STATUS_ERROR);

    /* Lock access to the graphics contexts */
    uglOSLock(srcGc->lockId);
    uglOSLock(dstGc->lockId);

    /* Save items that are preserved */
    lockId = dstGc->lockId;
    magicNumber = dstGc->magicNumber;

    /* Copy the graphics context */
    bcopy((char *)srcGc, (char *)dstGc, sizeof(UGL_GC));

    /* Restore preserved items */
    dstGc->lockId = lockId;
    dstGc->magicNumber = magicNumber;

    dstGc->changed = 0xFFFFFFFF;
    UGL_GC_CHANGED_SET(dstGc);

    /* Unlock access to the graphics contexts */
    uglOSUnlock(srcGc->lockId);
    uglOSUnlock(dstGc->lockId);

    return (UGL_STATUS_OK);
    }


/*******************************************************************************
*
* uglGcCreate - creates a graphics context
*
* This routine creates a graphics context for use in subsequent rendering
* operations. The graphics context (GC) defines the manner in which a graphics
* rendering operation is performed.  For instance, the uglLine() operation uses 
* the <defaultBitmap>, <clipRect>, <rasterOp>, <foregroundColor>, <lineStyle>, 
* and <lineWidth> portions of the gc to render a line.
*
* The created graphics context is directly associated with the specified
* graphics device.  The graphics context provides definitions on:
*
*\is
*\i clipping region and rectangle
*\i view port rectangle
*\i background and foreground color
*\i line style and width 
*\i fill patterns
*\i default bitmap
*\i font for text rendering
*\i current raster operation
*\ie
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> or <devId> are 
*          null.
*
* ERRNO: N/A
*
* SEE ALSO: 
*
*/

UGL_GC_ID uglGcCreate
    (
    UGL_DEVICE_ID devId     /* Output device ID */
    ) 
    {
    UGL_GC_ID gc;
    UGL_MODE_INFO modeInfo;

    if (devId == UGL_NULL)
	return UGL_NULL;

    /* Lock the device */
    uglOSLock (devId->lockId);

    (*devId->info) (devId, UGL_MODE_INFO_REQ, &modeInfo);
    gc = (*devId->gcCreate) (devId);

    uglOSUnlock (devId->lockId);

    if (UGL_NULL != gc)
	{
	memset (gc, 0, sizeof(UGL_GC));

        gc->boundRect.left = gc->boundRect.top = 0;
        gc->boundRect.right = modeInfo.width - 1;
        gc->boundRect.bottom = modeInfo.height - 1;
        gc->magicNumber = magicNumber++;
	gc->pDriver = devId;
	gc->lineWidth = 1;
        gc->pDefaultBitmap = UGL_DISPLAY_ID;
        gc->viewPort = gc->clipRect = gc->boundRect;
	gc->rasterOp = UGL_RASTER_OP_COPY;
	gc->lineStyle = UGL_LINE_STYLE_SOLID;
        gc->changed = 0xFFFFFFFF;

        gc->lockId = uglOSLockCreate ();
	}

    return (gc);
    }


/***************************************************************************
*
* uglGcDestroy - destroys a graphics context
*
* This routine destroys the graphics context <gc>. All memory resources and
* GC locks associated with the graphics context are freed. Once the <gc> has
* been destroyed, it cannot be used in any future rendering operations.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglGcCreate()
*/

UGL_STATUS uglGcDestroy
    (
    UGL_GC_ID gc	/* graphics context */
    )
    {
    UGL_STATUS status;
    UGL_DEVICE_ID devId;

    if (UGL_NULL == gc)
        return (UGL_STATUS_ERROR);

⌨️ 快捷键说明

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