几种GUI中的图形上下文比较
发布:much | 发布时间: 2009年12月15日
今天晚上看了看几个GUI下的图形上下文(GC,graphics context),的使用方法,发现在应用上没有太大的区别,区别只是在于在不同的GUI中其内容不同而已。在网上搜索了一下,发现还有的GUI中将图形上下文定义为类,如Symbian系统中。而在手头上有的有的这几个gui中,都是定义为结构体了,在不同的GUI中对图形上下文又有不同的定义和使用方法。比如:在windml和microwindows中,是作为函数的参数进行传递的,而在UCGUI中,却是作为全局变量使用的。
这样做,各有利弊,从我个人的使用角度出发,我认为做为参数传递是比较方便的。
在这里,将手头上现有的gui中的图像上下文列举出来。如果对其他GUI的图形上下文有兴趣,请自行查找,在这里,much就不一一列举了。
WINDML
typedef struct ugl_gc
{
struct ugl_ugi_driver *pDriver; /* driver associated with gc */
UGL_DDB * pDefaultBitmap; /* output bitmap for rendering */
UGL_RECT boundRect; /* bounding rect of output bitmap */
UGL_RECT viewPort; /* view port */
UGL_RECT clipRect; /* clipping rectangle */
UGL_REGION_ID clipRegionId; /* clipping region */
UGL_COLOR foregroundColor; /* foreground color */
UGL_COLOR backgroundColor; /* background color */
UGL_RASTER_OP rasterOp; /* raster operation */
UGL_SIZE lineWidth; /* line width */
UGL_LINE_STYLE lineStyle; /* line style */
UGL_MDDB * pPatternBitmap; /* fill pattern bitmap */
struct ugl_font * pFont; /* active font */
UGL_UINT32 changed; /* hanged status bit field */
void * extension; /* optional driver extensions */
UGL_UINT32 magicNumber; /* GC id plus changed status. */
UGL_LOCK_ID lockId; /* Id of mutex semaphore. */
} UGL_GC;
microwindows
typedef struct _mwscreendevice {
MWCOORD xres; /* X screen res (real) */
MWCOORD yres; /* Y screen res (real) */
MWCOORD xvirtres; /* X drawing res (will be flipped in portrait mode) */
MWCOORD yvirtres; /* Y drawing res (will be flipped in portrait mode) */
int planes; /* # planes*/
int bpp; /* # bpp*/
int linelen; /* line length in bytes for bpp 1,2,4,8*/
/* line length in pixels for bpp 16, 24, 32*/
int size; /* size of memory allocated*/
long ncolors; /* # screen colors*/
int pixtype; /* format of pixel value*/
int flags; /* device flags*/
void * addr; /* address of memory allocated (memdc or fb)*/
PSD (*Open)(PSD psd);
void (*Close)(PSD psd);
void (*GetScreenInfo)(PSD psd,PMWSCREENINFO psi);
void (*SetPalette)(PSD psd,int first,int count,MWPALENTRY *pal);
void (*DrawPixel)(PSD psd,MWCOORD x,MWCOORD y,MWPIXELVAL c);
MWPIXELVAL (*ReadPixel)(PSD psd,MWCOORD x,MWCOORD y);
void (*DrawHorzLine)(PSD psd,MWCOORD x1,MWCOORD x2,MWCOORD y,
MWPIXELVAL c);
void (*DrawVertLine)(PSD psd,MWCOORD x,MWCOORD y1,MWCOORD y2,
MWPIXELVAL c);
void (*FillRect)(PSD psd,MWCOORD x1,MWCOORD y1,MWCOORD x2,MWCOORD y2, MWPIXELVAL c);
PMWCOREFONT builtin_fonts;
/* *void (*DrawText)(PSD psd,MWCOORD x,MWCOORD y,const MWUCHAR *str,
int count, MWPIXELVAL fg, PMWFONT pfont);***/
void (*Blit)(PSD destpsd,MWCOORD destx,MWCOORD desty,MWCOORD w,
MWCOORD h,PSD srcpsd,MWCOORD srcx,MWCOORD srcy,long op);
void (*PreSelect)(PSD psd);
void (*DrawArea)(PSD psd, driver_gc_t *gc, int op);
int (*SetIOPermissions)(PSD psd);
PSD (*AllocateMemGC)(PSD psd);
MWBOOL(*MapMemGC)(PSD mempsd,MWCOORD w,MWCOORD h,int planes,int bpp,
int linelen,int size,void *addr);
void (*FreeMemGC)(PSD mempsd);
void (*StretchBlit)(PSD destpsd,MWCOORD destx,MWCOORD desty,
MWCOORD destw,MWCOORD desth,PSD srcpsd,MWCOORD srcx,
MWCOORD srcy,MWCOORD srcw,MWCOORD srch,long op);
void (*SetPortrait)(PSD psd,int portraitmode);
int portrait; /* screen portrait mode*/
PSUBDRIVER orgsubdriver; /* original subdriver for portrait modes*/
void (*StretchBlitEx) (PSD dstpsd, PSD srcpsd,
MWCOORD dest_x_start, MWCOORD dest_y_start,
MWCOORD width, MWCOORD height,
int x_denominator, int y_denominator,
int src_x_fraction, int src_y_fraction,
int x_step_fraction, int y_step_fraction,
long op);
} SCREENDEVICE;
UCGUI
struct GUI_Context_struct {
/* Variables in LCD module */
LCD_COLORINDEX_UNION LCD;
LCD_RECT ClipRect;
const tLCD_HL_APIList* pLCD_HL;
U8 DrawMode;
/* Variables in GL module */
GUI_RECT* pClipRect_HL;
U8 PenSize;
U8 PenShape;
U8 LineStyle;
U8 FillStyle;
/* Variables in GUICHAR module */
const GUI_FONT* pAFont;
I16P LBorder;
I16P DispPosX, DispPosY;
I16P DrawPosX, DrawPosY;
I16P TextMode;
I16P TextAlign;
/* Variables in WM module */
#if GUI_WINSUPPORT
const GUI_RECT* WM__pUserClipRect;
GUI_HWIN hAWin;
#endif
/* Variables in MEMDEV module (with memory devices only) */
#if GUI_SUPPORT_MEMDEV
const tLCDDEV_APIList* pDeviceAPI; /* function pointers only */
GUI_HMEM hDevData;
GUI_RECT ClipRectPrev;
#endif
/* Variables Anitaliasing module */
U8 AA_Factor;
U8 AA_HiResEnable;
};
等等不一而足。
上述列举出的图形上下文的结构体中,有许多的相同之处,例如:线宽、字体、颜色等信息。在具体的使用过程中,如果能够灵活使用图形上下文,是可以解决一些采用常规手段无法解决的问题的!
- 相关文章:
发表评论
◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。





