Drawing in a Window

In order to draw in a Motif window there are two things you need:

  1. the window itself, type Widget. You can get this either by doing the drawing in a callback for that that window, or in any other function that can get hold of the widget for that window. The easiest way to do the second is to make a callback for the window creation and setting a non-local variable from the widget that is passed. See the examples for how to do this.
  2. a graphics context. These can be created with the following call:

    GC gc = XCreateGC(XtDisplay(w), RootWindowOfScreen(XtScreen(w), 0, NULL);

    where w is a widget (type Widget).

Drawing functions

These are some of the drawing functions available at the lowest level of X; Motif does not provide drawing functions of its own. In the following, the arguments d, w and gc are common. They refer to:

x and y are window pixel coordinates (x increases to the right, y increases downwards)

w and h are width and height, in pixels

XDrawPoint(d, w, gc, x, y)

XDrawLine(d, w, gc, x1, y1, x2, y2)

XDrawRectangle(d, w, gc, x, y, w, h)

XFillRectangle(d, w, gc, x, y, w, h)

XDrawArc(d, w, gc, x, y, w, h, a1, a2)

XFillArc(d, w, gc, x, y, w, h, a1, a2, h)

XDrawString(d, w, gc, x, y, s, l)