Graphics Context
Text and Graphics output routines operate within a graphics context (GC); a structure containing current settings (foreground color, font, etc) for drawing operations. This not only reduces the number of arguments that these routines require, but also (since the GC is held in the server) reduces traffic. .
typedef struct {
/*DEFAULTS*/ /*MASKS*/
int function; GXcopy GCFunction
unsigned long plane_mask; ~0 GCPlaneMask
unsigned long foreground; 0 GCForeground
unsigned long background; 1 GCBackground
int line_width; 0 GCLineWidth
int line_style; LineSolid GCLineStyle
int cap_style; CapButt GCCapStyle
int join_style; JoinMiter GCJoinStyle
int fill_style; FillSolid GCFillStyle
int fill_rule; EvenOddRule GCFillRule
int arc_mode; ArcPieSlice GCArcMode
Pixmap tile; a pixmap in the fg color GCTile
Pixmap stipple; a pixmap of 1's GCStipple
int ts_x_origin; 0 GCTileStipXOrigin
int ts_y_origin; 0 GCTileStipYOrigin
Font font; GCFont
int subwindow_mode; ClipByChildren GCSubwindowMode
Bool graphics_exposures; True GCGraphicsExposures
int clip_x_origin; 0 GCClipXOrigin
int clip_y_origin; 0 GCClipYOrigin
Pixmap clip_mask; None GCClipMask
int dash_offset; 0 GCDashOffset
char dashes; 4 GCDashList
} XGCValues;
These components are quite involved.
- function:-
-
When something is drawn on the screen the machine takes the pixel value
being drawn and combines it with the pixel which is already on the screen
using a display function. The display function produces an output pixel
value which becomes the new pixel for that particular point on the screen.
If the old pixel value on the screen is "dst" and the pixel being drawn is
"src" the following table lists the effects of the various display
functions available.
- line_style:-
-
LineSolid, LineDoubleDash, LineOnOffDash
- cap_style:-
-
CapNotLast, CapButt, CapRound, CapProjecting
- join_style:-
-
JoinMiter, JoinRound, JoinBevel
- fill_style:-
-
FillSolid,FillTiled, FillOpaqueStippled
- fill_rule:-
-
EvenOddRule, WindingRule (rules determining how to fill a
complex polygon.
- arc_mode:-
-
ArcPieSlice, ArcChord (rules determining how to fill an arc).
- stipple:-
-
This is a bitmap for use in shading operations.
- ts_x_origin, ts_y_origin:-
-
These are the offsets for tile/stipple operations.
- subwindow_mode:-
-
ClipByChildren, IncludeInferiors
- graphics_exposures:-
-
A Boolean; should expose events be generated if an attempt is made to draw to a
hidden area?
To create a GC use
GC XCreateGC(display,d,valuemask,values) XGCValues *values
Note that although you need to provide a drawable, that doesn't mean that the GC can only be used for operations in that drawable - you can use it for any drawable that's on the same screen and has the same depth as the original drawable.
To change or free GC's, use
XCopyGC(display,src,valuemask,dest) GC src,dest XChangeGC(display,gc,valuemask,values) XFreeGC(display,gc)
The GC contents can be changed singley or en masse using these routines
XSetState (display,gc,foreground,background,function,planemask) This is a packaging of the following 4 routines; XSetForeground(display,gc,foreground) XSetBackground(display,gc,background) XSetFunction(display,gc,function) XSetPlaneMask(display,gc,planemask) XSetLineAttributes(display,gc,line_width,linestyle,cap_style,join_style) XSetDashes (display,gc,dash_offset,dash_list,n) XSetFillStyle (display,gc,fill_style) XSetFillRule (display,gc,fill_rule) XQueryBestSize (display,class,d,width,height,rwidth,rheight) XQueryBestTile (display,gc,d,width,height,rwidth,rheight) XQueryBestStipple (display,gc,d,width,height,rwidth,rheight) XSetTile (display,gc,tile) XSetStipple (display,gc,stipple) XSetFont (display,gc,font) XSetClipOrigin (display,gc,clip_x_origin,clip_y_origin) XSetClipMask (display,gc,pixmap XSetClipRectangles(display,gc,clip_x_origin,clip_y_origin,rectangles,n,ordering) XSetArcMode (display,gc,arc_mode) XSetSubwindowMode (display,gc,subwindowmode); XSetGraphicsExposures(display,gc,graphics_exposures); XSetRegion(display, gc, r);
Many of these routines you might never use. See the manpages if you're interested.
Xlib caches the contents of the GC. The values in the cache can be requested using
Status XGetGCValues(display, gc, valuemask, values_return) XGCValues *values_return;
but note :-
- The values in the cache may not quite be the currently installed values.
- Unless the default values for CFont, GCTile, and GCStipple have been overridden, their values cannot be returned.
- The clip mask and dash list values cannot be returned.
