structure
SYNTAX
GC XCreateGC(Display *display, Drawable d, unsigned long valuemask,
XGCValues *values);
int XCopyGC(Display *display, GC src, GC dest, unsigned long value-
mask);
int XChangeGC(Display *display, GC gc, unsigned long valuemask, XGCVal-
ues *values);
Status XGetGCValues(Display *display, GC gc, unsigned long valuemask,
XGCValues *values_return);
int XFreeGC(Display *display, GC gc);
GContext XGContextFromGC(GC gc);
ARGUMENTS
d Specifies the drawable.
dest Specifies the destination GC.
display Specifies the connection to the X server.
gc Specifies the GC.
src Specifies the components of the source GC.
valuemask Specifies which components in the GC are to be set, copied,
changed, or returned . This argument is the bitwise inclu-
sive OR of zero or more of the valid GC component mask bits.
values Specifies any values as specified by the valuemask.
values_return
Returns the GC values in the specified XGCValues structure.
DESCRIPTION
The XCreateGC function creates a graphics context and returns a GC.
The GC can be used with any destination drawable having the same root
and depth as the specified drawable. Use with other drawables results
in a BadMatch error.
XCreateGC can generate BadAlloc, BadDrawable, BadFont, BadMatch, Bad-
Pixmap, and BadValue errors.
The XCopyGC function copies the specified components from the source GC
to the destination GC. The source and destination GCs must have the
same root and depth, or a BadMatch error results. The valuemask speci-
fies which component to copy, as for XCreateGC.
The XGetGCValues function returns the components specified by valuemask
for the specified GC. If the valuemask contains a valid set of GC mask
bits (GCFunction, GCPlaneMask, GCForeground, GCBackground, GCLineWidth,
GCLineStyle, GCCapStyle, GCJoinStyle, GCFillStyle, GCFillRule, GCTile,
GCStipple, GCTileStipXOrigin, GCTileStipYOrigin, GCFont, GCSubwindow-
Mode, GCGraphicsExposures, GCClipXOrigin, GCCLipYOrigin, GCDashOffset,
or GCArcMode) and no error occurs, XGetGCValues sets the requested com-
ponents in values_return and returns a nonzero status. Otherwise, it
returns a zero status. Note that the clip-mask and dash-list (repre-
sented by the GCClipMask and GCDashList bits, respectively, in the val-
uemask) cannot be requested. Also note that an invalid resource ID
(with one or more of the three most significant bits set to 1) will be
returned for GCFont, GCTile, and GCStipple if the component has never
been explicitly set by the client.
The XFreeGC function destroys the specified GC as well as all the asso-
ciated storage.
XFreeGC can generate a BadGC error.
STRUCTURES
The XGCValues structure contains:
/* GC attribute value mask bits */
#define GCFunction (1L<<0)
#define GCPlaneMask (1L<<1)
#define GCForeground (1L<<2)
#define GCBackground (1L<<3)
#define GCLineWidth (1L<<4)
#define GCLineStyle (1L<<5)
#define GCCapStyle (1L<<6)
#define GCJoinStyle (1L<<7)
#define GCFillStyle (1L<<8)
#define GCFillRule (1L<<9)
#define GCTile (1L<<10)
#define GCStipple (1L<<11)
#define GCTileStipXOrigin (1L<<12)
#define GCTileStipYOrigin (1L<<13)
#define GCFont (1L<<14)
#define GCSubwindowMode (1L<<15)
#define GCGraphicsExposures (1L<<16)
#define GCClipXOrigin (1L<<17)
#define GCClipYOrigin (1L<<18)
#define GCClipMask (1L<<19)
#define GCDashOffset (1L<<20)
#define GCDashList (1L<<21)
#define GCArcMode (1L<<22)
/* Values */
int ts_x_origin; /* offset for tile or stipple operations */
int ts_y_origin;
Font font; /* default text font for text operations */
int subwindow_mode; /* ClipByChildren, IncludeInferiors */
Bool graphics_exposures; /* boolean, should exposures be generated */
int clip_x_origin; /* origin for clipping */
int clip_y_origin;
Pixmap clip_mask; /* bitmap clipping; other calls for rects */
int dash_offset; /* patterned/dashed line information */
char dashes;
} XGCValues;
The function attributes of a GC are used when you update a section of a
drawable (the destination) with bits from somewhere else (the source).
The function in a GC defines how the new destination bits are to be
computed from the source bits and the old destination bits. GXcopy is
typically the most useful because it will work on a color display, but
special applications may use other functions, particularly in concert
with particular planes of a color display. The 16 GC functions,
defined in <X11/X.h>, are:
-----------------------------------------------
Function Name Value Operation
-----------------------------------------------
() ()
GXclear 0x0 0
GXand 0x1 src AND dst
GXandReverse 0x2 src AND NOT dst
GXcopy 0x3 src
GXandInverted 0x4 (NOT src) AND dst
GXnoop 0x5 dst
GXxor 0x6 src XOR dst
GXor 0x7 src OR dst
GXnor 0x8 (NOT src) AND (NOT
dst)
GXequiv 0x9 (NOT src) XOR dst
GXinvert 0xa NOT dst
GXorReverse 0xb src OR (NOT dst)
GXcopyInverted 0xc NOT src
GXorInverted 0xd (NOT src) OR dst
GXnand 0xe (NOT src) OR (NOT
dst)
GXset 0xf 1
-----------------------------------------------
Many graphics operations depend on either pixel values or planes in a
Range checking is not performed on the values for foreground, back-
ground, or plane_mask. They are simply truncated to the appropriate
number of bits. The line-width is measured in pixels and either can be
greater than or equal to one (wide line) or can be the special value
zero (thin line).
Wide lines are drawn centered on the path described by the graphics
request. Unless otherwise specified by the join-style or cap-style,
the bounding box of a wide line with endpoints [x1, y1], [x2, y2] and
width w is a rectangle with vertices at the following real coordinates:
[x1-(w*sn/2), y1+(w*cs/2)], [x1+(w*sn/2), y1-(w*cs/2)],
[x2-(w*sn/2), y2+(w*cs/2)], [x2+(w*sn/2), y2-(w*cs/2)]
Here sn is the sine of the angle of the line, and cs is the cosine of
the angle of the line. A pixel is part of the line and so is drawn if
the center of the pixel is fully inside the bounding box (which is
viewed as having infinitely thin edges). If the center of the pixel is
exactly on the bounding box, it is part of the line if and only if the
interior is immediately to its right (x increasing direction). Pixels
with centers on a horizontal edge are a special case and are part of
the line if and only if the interior or the boundary is immediately
below (y increasing direction) and the interior or the boundary is
immediately to the right (x increasing direction).
Thin lines (zero line-width) are one-pixel-wide lines drawn using an
unspecified, device-dependent algorithm. There are only two con-
straints on this algorithm.
1. If a line is drawn unclipped from [x1,y1] to [x2,y2] and if
another line is drawn unclipped from [x1+dx,y1+dy] to
[x2+dx,y2+dy], a point [x,y] is touched by drawing the first line
if and only if the point [x+dx,y+dy] is touched by drawing the
second line.
2. The effective set of points comprising a line cannot be affected
by clipping. That is, a point is touched in a clipped line if and
only if the point lies inside the clipping region and the point
would be touched by the line when drawn unclipped.
A wide line drawn from [x1,y1] to [x2,y2] always draws the same pixels
as a wide line drawn from [x2,y2] to [x1,y1], not counting cap-style
and join-style. It is recommended that this property be true for thin
lines, but this is not required. A line-width of zero may differ from
a line-width of one in which pixels are drawn. This permits the use of
many manufacturers' line drawing hardware, which may run many times
faster than the more precisely specified wide lines.
In general, drawing a thin line will be faster than drawing a wide line
of width one. However, because of their different drawing algorithms,
thin lines may not mix well aesthetically with wide lines. If it is
ual dashes, except CapNotLast is treated as
CapButt.
The cap-style defines how the endpoints of a path are drawn:
CapNotLast This is equivalent to CapButt except that for
a line-width of zero the final endpoint is
not drawn.
CapButt The line is square at the endpoint (perpen-
dicular to the slope of the line) with no
projection beyond.
CapRound The line has a circular arc with the diameter
equal to the line-width, centered on the end-
point. (This is equivalent to CapButt for
line-width of zero).
CapProjecting The line is square at the end, but the path
continues beyond the endpoint for a distance
equal to half the line-width. (This is
equivalent to CapButt for line-width of
zero).
The join-style defines how corners are drawn for wide lines:
JoinMiter The outer edges of two lines extend to meet
at an angle. However, if the angle is less
than 11 degrees, then a JoinBevel join-style
is used instead.
JoinRound The corner is a circular arc with the diame-
ter equal to the line-width, centered on the
joinpoint.
JoinBevel The corner has CapButt endpoint styles with
the triangular notch filled.
For a line with coincident endpoints (x1=x2, y1=y2), when the cap-style
is applied to both endpoints, the semantics depends on the line-width
and the cap-style:
CapNotLast thin The results are device dependent, but
the desired effect is that nothing is
drawn.
CapButt thin The results are device dependent, but
the desired effect is that a single
pixel is drawn.
CapRound thin The results are the same as for Cap-
Butt/thin.
CapProjecting thin The results are the same as for Cap-
Butt/thin.
CapButt wide Nothing is drawn.
CapRound wide The closed path is a circle, centered at
the endpoint, and with the diameter
equal to the line-width.
CapProjecting wide The closed path is a square, aligned
within the drawable specified by the tile/stipple origin. The
tile/stipple and clip origins are interpreted relative to the origin of
whatever destination drawable is specified in a graphics request. The
tile pixmap must have the same root and depth as the GC, or a BadMatch
error results. The stipple pixmap must have depth one and must have
the same root as the GC, or a BadMatch error results. For stipple
operations where the fill-style is FillStippled but not FillOpaqueStip-
pled, the stipple pattern is tiled in a single plane and acts as an
additional clip mask to be ANDed with the clip-mask. Although some
sizes may be faster to use than others, any size pixmap can be used for
tiling or stippling.
The fill-style defines the contents of the source for line, text, and
fill requests. For all text and fill requests (for example, XDrawText,
XDrawText16, XFillRectangle, XFillPolygon, and XFillArc); for line
requests with line-style LineSolid (for example, XDrawLine, XDrawSeg-
ments, XDrawRectangle, XDrawArc); and for the even dashes for line
requests with line-style LineOnOffDash or LineDoubleDash, the following
apply:
FillSolid Foreground
FillTiled Tile
FillOpaqueStippled A tile with the same width and height as
stipple, but with background everywhere
stipple has a zero and with foreground
everywhere stipple has a one
FillStippled Foreground masked by stipple
When drawing lines with line-style LineDoubleDash, the odd dashes are
controlled by the fill-style in the following manner:
FillSolid Background
FillTiled Same as for even dashes
FillOpaqueStippled Same as for even dashes
FillStippled Background masked by stipple
Storing a pixmap in a GC might or might not result in a copy being
made. If the pixmap is later used as the destination for a graphics
request, the change might or might not be reflected in the GC. If the
pixmap is used simultaneously in a graphics request both as a destina-
tion and as a tile or stipple, the results are undefined.
For optimum performance, you should draw as much as possible with the
same GC (without changing its components). The costs of changing GC
components relative to using different GCs depend on the display hard-
ware and the server implementation. It is quite likely that some
amount of GC information will be cached in display hardware and that
such hardware can only cache a small number of GCs.
The dashes value is actually a simplified form of the more general pat-
terns that can be set with XSetDashes. Specifying a value of N is
equivalent to specifying the two-element list [N, N] in XSetDashes.
You can set the subwindow-mode to ClipByChildren or IncludeInferiors.
For ClipByChildren, both source and destination windows are addition-
ally clipped by all viewable InputOutput children. For IncludeInferi-
ors, neither source nor destination window is clipped by inferiors.
This will result in including subwindow contents in the source and
drawing through subwindow boundaries of the destination. The use of
IncludeInferiors on a window of one depth with mapped inferiors of dif-
fering depth is not illegal, but the semantics are undefined by the
core protocol.
The fill-rule defines what pixels are inside (drawn) for paths given in
XFillPolygon requests and can be set to EvenOddRule or WindingRule.
For EvenOddRule, a point is inside if an infinite ray with the point as
origin crosses the path an odd number of times. For WindingRule, a
point is inside if an infinite ray with the point as origin crosses an
unequal number of clockwise and counterclockwise directed path seg-
ments. A clockwise directed path segment is one that crosses the ray
from left to right as observed from the point. A counterclockwise seg-
ment is one that crosses the ray from right to left as observed from
the point. The case where a directed line segment is coincident with
the ray is uninteresting because you can simply choose a different ray
that is not coincident with a segment.
For both EvenOddRule and WindingRule, a point is infinitely small, and
the path is an infinitely thin line. A pixel is inside if the center
point of the pixel is inside and the center point is not on the bound-
ary. If the center point is on the boundary, the pixel is inside if
and only if the polygon interior is immediately to its right (x
increasing direction). Pixels with centers on a horizontal edge are a
special case and are inside if and only if the polygon interior is
immediately below (y increasing direction).
The arc-mode controls filling in the XFillArcs function and can be set
to ArcPieSlice or ArcChord. For ArcPieSlice, the arcs are pie-slice
filled. For ArcChord, the arcs are chord filled.
The graphics-exposure flag controls GraphicsExpose event generation for
XCopyArea and XCopyPlane requests (and any similar requests defined by
extensions).
DIAGNOSTICS
BadAlloc The server failed to allocate the requested resource or
server memory.
BadDrawable
A value for a Drawable argument does not name a defined Win-
dow or Pixmap.
BadFont A value for a Font or GContext argument does not name a
defined Font.
BadGC A value for a GContext argument does not name a defined GCon-
generate this error.
SEE ALSO
AllPlanes(3X11), XCopyArea(3X11), XCreateRegion(3X11), XDrawArc(3X11),
XDrawLine(3X11), XDrawRectangle(3X11), XDrawText(3X11), XFillRectan-
gle(3X11), XQueryBestSize(3X11), XSetArcMode(3X11), XSetClipOri-
gin(3X11), XSetFillStyle(3X11), XSetFont(3X11), XSetLineAt-
tributes(3X11), XSetState(3X11), XSetTile(3X11)
Xlib - C Language X Interface
()
Man(1) output converted with
man2html
|