📄 uglgc.c
字号:
/* uglgc.c - graphics context handling functions */
/* Copyright 1999-2000 Wind River Systems, Inc. All Rights Reserved */
/* Copyright 1998 Zinc Software Incorporated. */
/*
modification history
--------------------
01t,08mar02,gav Refgen cleanup
01s,25feb02,wdf Fixed compile problem.
01r,22feb02,wdf Fixed compiler warnings.
01q,28nov01,msr Fixed bug with view port clipping.
01p,23oct00,wdf Changed copyright date.
01o,08feb00,rfm Removed uglFontSet and uglFontGet
01n,03feb00,msr Fixed bug with uglClipRegionSet().
01m,10jan00,msr Added UGL_MODE_INFO request.
01l,03dec99,msr Added support for "changed" bit field in gc structure.
01k,02dec99,msr Fixed warnings generated by Borland compiler.
01j,15nov99,msr Added default GC selection to uglGcDestroy().
01i,13nov99,msr Added gc->boundRect support.
01h,06oct99,jlb Removed driver info function, moved to uglinfo.c
01g,10sep99,msr Changing clip rect to be stored in UGL coordinates.
01f,01aug99,msr Adding clip region support.
01e,01may99,dmm Adding Wind River Systems Copyright
01d,30apr99,msr Writing function header comments.
01c,19mar99,jcs adding device lock when counting fonts in uglInfo.
01b,18mar99,jcs minor changes due to font list becoming part of a device's
data.
01a,30nov98,dmm Adding checks for UGL_NULL function parameters in UGL functions
...
01b,23oct98,ugl added in checks to malloc returns and fix gc copy.
01a,06aug98,ugl written.
*/
/*
DESCRIPTION
This file contains the implementation for the UGL 2D graphics context
manipulation functions. Includes are the functions to create, destroy,
copy, and to modify parameters associated with the graphics context.
NOMANUAL
*/
/* includes */
#include <stdlib.h>
#include <string.h>
#if (CPU == NATSPARCSOLARIS) && defined(__unix__)
# include <strings.h>
#endif
#include <ugl/ugl.h>
UGL_LOCAL UGL_UINT32 magicNumber = 1;
extern int colorBit;
#define SWAP16(x) ((((x) << 8) | ((x) >> 8)) & 0xFFFF)
#define SWAP32(x) \
(((x) << 24) | \
(((x) & 0x0000FF00) << 8) | \
(((x) & 0x00FF0000) >> 8) | \
(((unsigned int)(x)) >> 24))
/***************************************************************************
*
* uglBackgroundColorGet - gets a graphics context's background color setting
*
* This routine returns the background color of graphics context <gc>, and
* places it in the location specified by <pBackgroundColor>.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglBackgroundColorSet()
*
*/
UGL_STATUS uglBackgroundColorGet
(
UGL_GC_ID gc, /* graphics context */
UGL_COLOR * pBackgroundColor /* background color setting */
)
{
if (UGL_NULL == gc)
return (UGL_STATUS_ERROR);
*pBackgroundColor = gc->backgroundColor;
if(colorBit ==16)
{
*pBackgroundColor = SWAP16((UINT16)(*pBackgroundColor));
}
return (UGL_STATUS_OK);
}
/***************************************************************************
*
* uglBackgroundColorSet - sets a graphics context's background color
*
* This routine sets the background color of graphics context <gc> to the
* color specified by <color>. The background color is used for filling the
* interior of shapes, such as rectangles, polygons, and ellipses.
* Additionally, the background color is used for 0 bits in monochrome
* bitmaps.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglBackgroundColorGet()
*/
UGL_STATUS uglBackgroundColorSet
(
UGL_GC_ID gc, /* graphics context */
UGL_COLOR color /* new background color */
)
{
if(colorBit ==16)
{
color = SWAP16((UINT16)color);
}
/*printf("uglBackgroundColorSet:color=0x%x\n",color);*/
if (UGL_NULL == gc)
return (UGL_STATUS_ERROR);
uglOSLock(gc->lockId);
if (gc->backgroundColor != color)
{
gc->backgroundColor = color;
gc->changed |= UGL_GC_BACKGROUND_COLOR_CHANGED;
UGL_GC_CHANGED_SET(gc);
}
uglOSUnlock(gc->lockId);
return (UGL_STATUS_OK);
}
/***************************************************************************
*
* uglClipRectSet - sets a graphics context's clipping rectangle
*
* This routine sets the current clipping rectangle of graphics context <gc>.
* The arguments <left>, <top>, <right>, and <bottom> specify the boundaries
* of the clipping rectangle.
*
* The clipping rectangle is set to the intersection of the specified rectangle,
* the graphics context's view port, and the bounds of the default bitmap.
* Any portion of a drawing operation that extends beyond the bounds of the
* clipping rectangle is not rendered.
*
* The clipping rectangle is inclusive, such that portions of drawing operations
* falling on the right and bottom boundaries are rendered.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglClipRectGet()
*/
UGL_STATUS uglClipRectSet
(
UGL_GC_ID gc, /* graphics context */
UGL_POS left, /* left boundary of clipping rectangle */
UGL_POS top, /* top boundary of clipping rectangle */
UGL_POS right, /* right boundary of clipping rectangle */
UGL_POS bottom /* bottom boundary of clipping rectangle */
)
{
UGL_RECT clip;
UGL_DEVICE_ID devId;
if (UGL_NULL == gc)
return (UGL_STATUS_ERROR);
devId = gc->pDriver;
clip.left = left;
clip.top = top;
clip.right = right;
clip.bottom = bottom;
/* Lock access to GC */
uglOSLock(gc->lockId);
UGL_RECT_MOVE(clip, gc->viewPort.left, gc->viewPort.top);
UGL_RECT_INTERSECT(clip, gc->boundRect, clip);
UGL_RECT_INTERSECT(clip, gc->viewPort, clip);
if (devId->cursorHide != UGL_NULL &&
UGL_DISPLAY_ID == gc->pDefaultBitmap &&
devId->magicNumber == gc->magicNumber &&
devId->batchCount > 0)
{
uglOSLock (devId->lockId);
(*devId->cursorHide) (devId, &clip);
uglOSUnlock (devId->lockId);
}
UGL_RECT_MOVE(clip, -gc->viewPort.left, -gc->viewPort.top);
gc->clipRect = clip;
gc->changed |= UGL_GC_CLIP_RECT_CHANGED;
UGL_GC_CHANGED_SET(gc);
uglOSUnlock (gc->lockId);
return (UGL_STATUS_OK);
}
/***************************************************************************
*
* uglClipRectGet - gets a graphics context's clipping rectangle
*
* This routine gets the current clipping rectangle of graphics context <gc>.
* The arguments <pLeft>, <pTop>, <pRight>, and <pBottom> are output
* parameters representing the boundaries of the clipping rectangle. Any
* portion of a drawing operation that extends beyond the bounds of the
* clipping rectangle is not rendered.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglClipRectSet()
*/
UGL_STATUS uglClipRectGet
(
UGL_GC_ID gc, /* graphics context */
UGL_POS * pLeft, /* left boundary of clipping rectangle */
UGL_POS * pTop, /* top boundary of clipping rectangle */
UGL_POS * pRight, /* right boundary of clipping rectangle */
UGL_POS * pBottom /* bottom boundary of clipping rectangle */
)
{
UGL_DEVICE_ID devId;
if (UGL_NULL == gc)
return (UGL_STATUS_ERROR);
devId = gc->pDriver;
uglOSLock (devId->lockId);
uglOSLock(gc->lockId);
*pLeft = gc->clipRect.left;
*pTop = gc->clipRect.top;
*pRight = gc->clipRect.right;
*pBottom = gc->clipRect.bottom;
uglOSUnlock (gc->lockId);
uglOSUnlock (devId->lockId);
return (UGL_STATUS_OK);
}
/*******************************************************************************
*
* uglClipRegionGet - get the clipping region of a graphics context
*
* This routine gets the clipping region of a specified <gc> and places the
* contents in <pClipRegionId>.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the operation fails.
*/
UGL_STATUS uglClipRegionGet
(
UGL_GC_ID gc, /* graphics context */
UGL_REGION_ID *pClipRegionId /* clip region */
)
{
if (UGL_NULL == gc)
return (UGL_STATUS_ERROR);
uglOSLock(gc->lockId);
*pClipRegionId = gc->clipRegionId;
uglOSUnlock(gc->lockId);
return (UGL_STATUS_OK);
}
/*******************************************************************************
*
* uglClipRegionSet - set the clipping region of a graphics context
*
* This routine sets the clipping region of <gc> to <clipRegionId>. If
* <clipRegionId> is NULL, the clipping region of the gc will be empty.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the operation fails.
*/
UGL_STATUS uglClipRegionSet
(
UGL_GC_ID gc, /* graphics context */
UGL_REGION_ID clipRegionId /* clip region */
)
{
if (UGL_NULL == gc)
return (UGL_STATUS_ERROR);
uglOSLock(gc->lockId);
gc->clipRegionId = clipRegionId;
gc->changed |= UGL_GC_CLIP_REGION_CHANGED;
UGL_GC_CHANGED_SET(gc);
uglOSUnlock (gc->lockId);
return (UGL_STATUS_OK);
}
/***************************************************************************
*
* uglDefaultBitmapGet - gets a graphics context's default bitmap
*
* This routine obtains the current default bitmap for the graphics context,
* specified by <gc> and places it in the parameter <pDefaultBitmap>. A value
* of UGL_DISPLAY_ID for <pDefaultBitmap> specifies the display as the target
* of drawing operations rendered for the graphics context.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglDefaultBitMapSet()
*
*/
UGL_STATUS uglDefaultBitmapGet
(
UGL_GC_ID gc, /* graphics context */
UGL_DDB_ID *pDefaultBitampId /* default bitmap ID */
)
{
if (UGL_NULL == gc)
return (UGL_STATUS_ERROR);
*pDefaultBitampId = gc->pDefaultBitmap;
return (UGL_STATUS_OK);
}
/***************************************************************************
*
* uglDefaultBitmapSet - sets a graphics context's default bitmap
*
* This routine sets the default bitmap for the graphics context <gc> to the
* bitmap identifier <defaultBitmap>. This bitmap becomes the target of
* drawing operations rendered using the graphics context specified by <gc>.
* A value of UGL_DISPLAY_ID for <defaultBitmap> specifies the display as the
* target of drawing operations rendered with <gc>.
*
* RETURNS: UGL_STATUS_OK, or UGL_STATUS_ERROR if the <gc> is null.
*
* ERRNO: N/A
*
* SEE ALSO: uglDefaultBitmapGet()
*
*/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -