next up previous contents
Next: Drawing Text in a Up: X Windows Version 11.5 Previous: Graphics Context

Rectangles, lines, dots, arcs and text

First, some elemental structures.

typedef struct 
{
    short x, y; 
} XPoint;

typedef struct 
{
    short x1, y1,x2,y2;
} XSegment;

typedef struct 
{
    short x, y;
    unsigned short width, height;
} XRectangle;

typedef struct  
{
    short x, y; 
    unsigned short width, height;
    short angle1,angle2;
} XArc;
The following routines make extensive use of the GC (refer to the manual for further information on exactly which components are relevant). Lines of width 0 come out with a thickness of 1 drawn using a different, faster, algorithm.

They write to drawables (pixmaps or windows that can accept graphic input).

XDrawPoint(display,d,gc,x,y)
XDrawPoints(display,d,gc,points,npoints,mode)
     int mode; /* CoordModeOrigin or CoordModePrevious */

XDrawLine(display,d,gc,x1, y1, x2, y2)
XDrawLines(display,d,gc,points.npoints,mode)
     int mode; /* CoordModeOrigin or CoordModePrevious */

XDrawSegments(display,d,gc,segments,nsegments)

XDrawRectangle(display,d,gc,x,y,width,height)  
XDrawRectangles(display,d,gc,rectangles,nrectangles) 

XDrawArc(display,d,gc,x,y,width,height,angle1,angle2)
    unsigned int width,height /*major and minor axes of arc*/
    int angle1 /*start of arc, clockwise from 3 o'clock,scaled by 64 */   
    int angle2 /*path and extent of arc, relative to angle1, scaled by 64*/
XDrawArcs(display,d,gc,arcs,narcs)                           

XFillRectangle(display,d,gc,x,y,width,height)                
XFillRectangles(display,d,gc,rectangles,nrectangles)
The last 2 routines fill rectangles that are 1 pixel shorter and narrower than the XDrawRectangle routines.

XFillPolygon(display,d,gc,points,npoints,shape,mode)         
    int shape /*Complex,Convex,NonConvex ;
               helps select best fill algorithm */
    int mode; /* CoordModeOrigin or CoordModePrevious */
XFillArc(display,d,gc,x,y,width,height,angle1,angle2)
XFillArcs(display,d,gc,arcs,narcs)  

XMoveArea(display, w, srcX, srcY, dstX, dstY, width, height)
    int srcX, srcY;    /* position of top LH corner of area    */
    int dstX, dstY;    /* where top LH corner must end up      */
    int width, length; /* size of area to be moved             */

XCopyArea(display,src,dest,gc,src_x, src_y,width, height, dest_x,dest_y)
    Drawable src_x, src_y;    /* position of top LH corner of area    */
    int src_x,src_y,dest_x, dest_y; /* where top LH corner must end up */
    unsigned int width, height; /* size of area being copied            */
             /* The depth of the source and destination must be the same. */

XCopyPlane(display,src,dest,gc,src_x,src_y,width,height,dest_x,dest_y,plane)
             /* src and dest are drawables with the same root */
    unsigned int width,height;
    unsigned long plane;

XClearArea(display,w,x,y,width,height,exposures)
    int width, height;/* if width=0 then width is set to window_width-x 
                         and similarly for y */
    Bool exposures;   /* if True then exposure events generated */

XClearWindow(display,w) /* clears the window */




Tim Love
Mon Mar 11 17:03:18 GMT 1996