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.
To create a GC use
GC XCreateGC(display,d,valuemask,values) XGCValues *valuesNote 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 :-