Next: XEvents Up: Xlib and Motif Previous: Graphics Contexts

Two Dimensional Graphics

Xlib provides a whole range of 2D Graphics functions. See draw.c for examples.

Most are fairly easy to understand and use. The functions basically draw a specific graphical primitive (point, line, polygon, arc, circle etc.) to a display according to a specific GC.

Probably the simplest function is XDrawPoint(Display *d, Drawable dr, GC gc, int x, int y) which draws to a given Drawable on a Display a point at position (x, y).

The function XDrawPoints(Display *d, Drawable dr, GC gc, XPoint *pts, int n, int mode) is similar except that an n element array of XPoints is drawn. The modeis either CoordModeOrigin or CoordModePrevious which either draws all points relative to the origin or the the last point.

XDrawLine(Display *d, Drawable dr, GC gc, int x1, int y1, int x2, int y2) draws a line between (x1, y1) and (x2, y2).

XDrawLines(Display *d, Drawable dr, GC gc, XPoint *pts, int n, int mode) draws a series of connected lines - taking pairs of coordinates in the list. mode as before.

XDrawRectangle(Display *d, Drawable dr, GC gc, int x, int y, int width, heigth) draws a rectangle with top left hand corner coordinate (x, y) and of width and height.

XFillRectangle(Display *d, Drawable dr, GC gc, int x, int y, int width, int height) fills (shades interior) a rectangle. The fill_style controls what shading takes place.

XFillPolygon(Display *d, Drawable dr, GC gc, XPoint *pts, int n, int mode, int mode) fills a polygon whose outline is defined by the *pts array.

This function behaves much like XDrawLines().

The shape parameter is either Complex, Nonconvex or Convex and controls how the server may configure the shading operation.

XDrawArc(Display *d, Drawable dr, GC gc, int x, int y, int width, int height, int angle1, int angle2) and

XFillArc(Display *d, Drawable dr, GC gc, int x, int y, int width, int height, int angle1, int angle2) draw/fill an arc.

The x, y, width and height define a bounding box for the arc. The arc is drawn from the centre of the box. The angle1 and angle2 define the start and end points of the arc. The angles specify th degree steps measured anticlockwise. The angle1 is relative to the 3 o'clock position and angle2 is relative to angle1.

So to draw a whole circle set the width and height equal (to diameter) and angle1 = 0, angle2 = 360*64 = 23040.

There are other Xlib Drawing functions.



Next: XEvents Up: Xlib and Motif Previous: Graphics Contexts


Dave.Marshall@cm.cf.ac.uk
Tue May 24 16:52:56 BST 1994