XCreateGC(3X) XCreateGC(3X)NAME XCreateGC, XCopyGC, XChangeGC, XGetGCValues, XFreeGC, XGContextFromGC, XGCValues - create and free graphic contexts and manipulate the GCValues structure SYNOPSIS GC XCreateGC(display, d, valuemask-create, values) Display *display; Drawable d; unsigned long valuemask-create; XGCValues *values; XCopyGC(display, src, valuemask-copy, dest) Display *display; GC src, dest; unsigned long valuemask-copy; XChangeGC(display, gc, valuemask-change, values) Display *display; GC gc; unsigned long valuemask-change; XGCValues *values; Status XGetGCValues(display, gc, valuemask-get, values- return) Display *display; GC gc; unsigned long valuemask-get; XGCValues *values-return; XFreeGC(display, gc) Display *display; GC gc; GContext XGContextFromGC(gc) GC gc; DESCRIPTION The XCreateGC function creates a graphic context and returns a GC. The GC can be used with any destination drawable hav- ing the same root and depth as the specified drawable. Use with other drawables results in a BadMatch error. The XCopyGC function copies the specified components from the source graphic context to the destination graphic con- text. The source and destination graphic context must have the same root and depth, or a BadMatch error results. The valuemask-copy specifies which component to copy, as for XCreateGC. The XChangeGC function changes the components specified by valuemask-change for the specified graphic context. The November, 1990 1
XCreateGC(3X) XCreateGC(3X)values argument contains the values to be set. The values and restrictions are the same as for XCreateGC. Changing clip_mask overrides any previous XSetClipRectangles request on the context. Changing the dash_offset or dashes members of the XGCValues structure overrides any previous XSetDashes request on the context. The order in which components are verified and altered is server-dependent. If an error is generated, a subset of the components may have been altered. The XGetGCValues function returns the components specified by valuemask-get for the specified graphic context. Note that clip_mask and dashes (represented by the GCClipMask and GCDashList bits, respectively, in valuemask-get) cannot be requested. If valuemask-get contains a valid set of graphic context mask bits (GCFunction, GCPlaneMask, GCForeground, GCBackground, GCLineWidth, GCLineStyle, GCCapStyle, GCJoin- Style, GCFillStyle, GCFillRule, GCTile, GCStipple, GCTileStipXOrigin, GCTileStipYOrigin, GCFont, GCSubwin- dowMode, GCGraphicsExposures, GCClipXOrigin, GCCLipYOrigin, GCDashOffset, or GCArcMode) and no error occurs, XGetGCValues sets the requested com- ponents in values-return and returns a nonzero status. Oth- erwise, it returns a 0 status. The XFreeGC function destroys the specified graphic context as well as the associated storage. Arguments These functions accept the following arguments: d Specifies the drawable. dest Specifies the destination graphic context. display Specifies the connection to the X server. gc Specifies the graphic context. src Specifies the components of the source graphic con- text. valuemask-change Specifies the components in the graphic context that are to be changed using information in the XGCValues structure. This argument is the bitwise inclusive OR of one or more of the valid graphic context com- ponent mask bits. valuemask-copy Specifies components in the graphic context that are to be copied to the destination graphic context. This argument is the bitwise inclusive OR of one or 2 November, 1990
XCreateGC(3X) XCreateGC(3X)more of the valid graphic context component masks. valuemask-create Specifies the components in the graphic context that are to be set using information in the XGCValues structure. This argument is the bitwise inclusive OR of one or more of the valid graphic context com- ponent masks. valuemask-get Specifies the components in the graphic context that are to be returned using information in the XGCValues structure. This argument is the bitwise inclusive OR of one or more of the valid graphic context component masks. values Specifies a pointer to the XGCValues structure. values-return Returns the graphic context values in the specified XGCValues structure. Structures The XGCValues structure is defined as follows. #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 */ typedef struct { int function; /* logical operation */ unsigned long plane_mask;/* plane mask */ November, 1990 3
XCreateGC(3X) XCreateGC(3X)unsigned long foreground;/* foreground pixel */ unsigned long background;/* background pixel */ int line_width; /* line width (in pixels) */ int line_style; /* LineSolid, */ /* LineOnOffDash, */ /* LineDoubleDash */ int cap_style; /* CapNotLast, CapButt, */ /* CapRound, CapProjecting */ int join_style; /* JoinMiter, JoinRound, */ /* JoinBevel */ int fill_style; /* FillSolid, FillTiled, */ /* FillStippled, */ /* FillOpaqueStippled*/ int fill_rule; /* EvenOddRule, */ /* WindingRule */ int arc_mode; /* ArcChord, ArcPieSlice */ Pixmap tile; /* tile pixmap for */ /* tiling operations */ Pixmap stipple; /* stipple 1 plane */ /* pixmap for stippling */ 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 of a graphic context is used when you update a section of a drawable (the destination) with bits from some- where else (the source). The value of function 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 works on a color display, but special applications may use other functions, particularly in con- cert with particular planes of a color display. The 16 pos- sible values of Function, as defined in <X11/X.h>, are: Function Name Hex CodeOperation GXclear 0x0 0 GXand 0x1 src AND dst GXandReverse 0x2src AND NOT dst 4 November, 1990
XCreateGC(3X) XCreateGC(3X)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 0xcNOT 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 graphic context. The planes_mask is of type long, and it specifies which planes of the destination are to be modified, one bit per plane. A monochrome display has only one plane and will be the least-significant bit of the word. As planes are added to the display hardware, they will occupy more significant bits in the plane_mask. In graphics operations, given a source and destination pix- el, the result is computed bitwise on corresponding bits of the pixels. That is, a Boolean operation is performed in each bit plane. The plane_mask restricts the operation to a subset of planes. A macro constant AllPlanes can be used to refer to all planes of the screen simultaneously. The result is computed by the following: ((src FUNC dst) AND plane-mask) OR (dst AND (NOT plane- mask)) Range checking is not performed on the values for fore- ground, background, or plane_mask. They are simply truncat- ed to the appropriate number of bits. The line_width is measured in pixels and either can be greater than or equal to 1 (wide line) or can be the special value 0 (thin line). Wide lines are drawn centered on the path described by the graphics request. Unless otherwise specified by 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 in- side the bounding box (which is viewed as having infinitely November, 1990 5
XCreateGC(3X) XCreateGC(3X)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 in- terior 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 (line_width of 0) are one-pixel-wide lines drawn using an unspecified, device-dependent algorithm. There are only two constraints 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 0 may differ from a line-width of 1 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 1. However, because of their different drawing algorithms, thin lines may not mix well aesthetical- ly with wide lines. If it is desirable to obtain precise and uniform results across all displays, a client should al- ways use a line-width of 1 rather than a line-width of 0. The line_style member defines which sections of a line are drawn: LineDoubleDash The full path of the line is drawn, but the even dashes are filled differently than the odd dashes with CapButt style used where even and odd dashes meet. LineOnOffDash 6 November, 1990
XCreateGC(3X) XCreateGC(3X)Only the even dashes are drawn, and cap_style ap- plies to all internal ends of the individual dashes, except CapNotLast is treated as CapButt. LineSolid The full path of the line is drawn. The cap_style member defines how the endpoints of a path are drawn: CapButt except that for a line_width of 0 the final endpoint is not drawn. CapButt The line is square at the endpoint (perpendicular to the slope of the line) with no projection beyond. November, 1990 7
XCreateGC(3X) XCreateGC(3X)CapNotLast This is equivalent to CapButt except that for a line-width of 0, the final endpoint is not drawn. CapProjecting The line is square at the end, but the path contin- ues beyond the endpoint for a distance equal to half the value of line_width. (This is equivalent to CapButt for a line_width of 0). CapRound The line has a circular arc with the diameter equal to line_width, centered on the endpoint. (This is equivalent to CapButt for a line_width of 0). The join_style member defines how corners are drawn for wide lines and can be one of: JoinBevel The corner has CapButt endpoint styles with the tri- angular notch filled. JoinMiter The outer edges of two lines extend to meet at an angle. However, if the angle is less than 11 de- grees, JoinBevel is used instead. JoinRound The corner is a circular arc with the diameter equal to line_width, centered on the join point. For a line with coincident endpoints (x1=x2, y1=y2), when cap_style is applied to both endpoints, the semantics depends on the value of line_width and cap_style: CapButt(thin) The results are device-dependent, but the desired effect is that a single pixel is drawn. CapButt(wide) Nothing is drawn. CapNotLast(thin) The results are device-dependent, but the desired effect is that nothing is drawn. CapProjecting(thin) The results are the same as for Butt(thin). CapProjecting(wide) The closed path is a square, aligned with the coor- 8 November, 1990
XCreateGC(3X) XCreateGC(3X)dinate axes, centered at the endpoint, and with the sides equal to the line-width. CapRound(thin) The results are the same as for CapButt(thin). CapRound(wide) The closed path is a circle, centered at the end- point, and with the diameter equal to the line- width. For a line with coincident endpoints (x1=x2, y1=y2), when the specified join style is applied at one or both end- points, the effect is as if the line was removed from the overall path. However, if the total path consists of or is reduced to a single point joined with itself, the effect is the same as when cap_style is applied at both endpoints. The tile, stipple, clip_x_origin, and clip_y_origin members are interpreted relative to the origin of whatever destina- tion drawable is specified in a graphics request. The tile pixel map must have the same root and depth as the graphic context, or a BadMatch error results. The stipple pixel map must have depth 1 and must have the same root as the graphic context, or a BadMatch error results. For stipple operations where fill_style is FillStippled but not FillOpaqueStippled, the stipple pattern is tiled in a single plane and is used as an additional clip mask in an AND operation with clip_mask. Although some sizes may be faster to use than others, any size pixel map can be used for tiling or stippling. The fill_style member defines the contents of the source for line, text, and fill requests. For all text and fill re- quests (for example, XDrawText, XDrawText16, XFillRectangle, XFillPolygon, and XFillArc); for line requests with a line_style of 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: FillOpaqueStippled A tile with the same width and height as stipple, but with background everywhere stipple has a 0 and with foreground everywhere stipple has a 1. FillSolid Foreground. FillStippled A foreground masked by stipple. November, 1990 9
XCreateGC(3X) XCreateGC(3X)FillTiled Tile. 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 A background masked by stipple. Storing a pixel map in a graphic context might or might not result in a copy being made. If the pixel map is later used as the destination for a graphics request, the change might or might not be reflected in the graphic context. If the pixel map is used simultaneously in a graphics request both as a destination and as a tile or stipple, the results are undefined. For optimum performance, you should draw as much as possible with the same graphic context (without changing its com- ponents). The costs of changing graphics components rela- tive to using different graphic contexts depend upon the display hardware and the server implementation. It is quite likely that some amount of graphic context information will be cached in display hardware and that such hardware can only cache a small number of graphic contexts. The dashes member is actually a simplified form of the more general patterns that can be set with XSetDashes. Specify- ing a value of N is equivalent to specifying the two-element list [N, N] in XSetDashes. The value must be nonzero, or a BadValue error results. The clip_mask member restricts writes to the destination drawable. If clip_mask is set to a pixel map, it must have a depth of 1 and have the same root as the graphic context, or a BadMatch error results. If clip_mask is set to None, the pixels are always drawn regardless of the clip origin. The clip_mask member also can be set by calling the XSetClipRec- tangles or XSetRegion functions. Only pixels where clip_mask has a bit set to 1 are drawn. Pixels are not drawn outside the area covered by clip_mask or where clip_mask has a bit set to 0. The clip_mask member affects all graphic 10 November, 1990
XCreateGC(3X) XCreateGC(3X)requests but does mask does not clip sources. The origin of clip_mask is interpreted relative to the origin of whatever destination drawable is specified in a graphics request. You can set the subwindow-mode member to ClipByChildren or IncludeInferiors. For ClipByChildren, both source and destination windows are ad- ditionally clipped by all viewable InputOutput children. For IncludeInferiors, neither source nor destination window is clipped by inferiors. This will result in including subwin- dow contents in the source and drawing through subwindow boundaries of the destination. The use of IncludeInferiors on a window of depth 1 with mapped inferiors of differing depth is not illegal, but the semantics are undefined by the core protocol. The fill_rule member 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 in- side if an infinite ray with the point as origin crosses the path an odd number of times. For WindingRule, a point is in- side if an infinite ray with the point as origin crosses an unequal number of clockwise and counterclockwise directed path segments. A clockwise directed path segment is one that crosses the ray from left to right as observed from the point. A counterclockwise segment 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 boundary. If the center point is on the boundary, the pixel is inside if and only if the po- lygon 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 inte- rior is immediately below (y increasing direction). The arc_mode member controls filling in the XFillArcs func- tion 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 member controls GraphicsExpose event generation for XCopyArea and XCopyPlane requests (and any similar requests defined by extensions). November, 1990 11
XCreateGC(3X) XCreateGC(3X)ERRORS BadAlloc The server failed to allocate the requested resource or server memory. BadDrawable A value for a Drawable argument does not name a de- fined window or pixel map. BadFont A value for a Font or GC argument does not name a defined Font. BadGC A value for a GC argument does not name a defined graphic context. BadMatch An InputOnly window is used as a drawable; or an ar- gument or pair of arguments has the correct type and range but fails to match in some other required way. BadPixmap A value for a Pixmap argument does not name a de- fined pixel map. BadValue Some numeric value falls outside the range of values accepted by the request. Unless a range is speci- fied for an argument, the full range defined by the argument's type is accepted. Any argument defined as a set of alternatives can generate this error. The XCreateGC function can generate BadAlloc, BadDrawable, BadFont, BadMatch, BadPixmap, and BadValue er- rors. The XCopyGC function can generate BadAlloc, BadGC, and Bad- Match errors. The XChangeGC function can generate BadAlloc, BadFont, BadGC, BadMatch, BadPixmap, and BadValue errors. The XFreeGC function can generate a BadGC error. SEE ALSO AllPlanes(3X), XCopyArea(3X), XCreateRegion(3X), XDrawArc(3X), XDrawLine(3X), XDrawRectangle(3X), XDrawText(3X), XFillRectangle(3X), XQueryBestSize(3X), XSetArcMode(3X), XSetClipOrigin(3X), XSetFillStyle(3X), XSetFont(3X), XSetLineAttributes(3X), XSetState(3X), XSetTile(3X)Xlib - C Language Interface12 November, 1990