Department of Engineering

IT Services

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.
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.


LineSolid, LineDoubleDash, LineOnOffDash

CapNotLast, CapButt, CapRound, CapProjecting

JoinMiter, JoinRound, JoinBevel

FillSolid,FillTiled, FillOpaqueStippled

EvenOddRule, WindingRule (rules determining how to fill a complex polygon.

ArcPieSlice, ArcChord (rules determining how to fill an arc).

This is a bitmap for use in shading operations.

ts_x_origin, ts_y_origin:-
These are the offsets for tile/stipple operations.

ClipByChildren, IncludeInferiors

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

   GC src,dest                             



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;

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                             
XSetArcMode       (display,gc,arc_mode)
XSetSubwindowMode (display,gc,subwindowmode);
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.