Drawing in a Window
In order to draw in a Motif window there are two things you need:
- 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.
- 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:
- d is the display. This can be set by:
Display* display = XtDisplay(w)
- w is the window of the widget. This can set by using XtWindow(w)
- gc is the gaphics context, set as above
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)
- draw a single pixel at (x, y) with the current foreground color
XDrawLine(d, w, gc, x1, y1, x2, y2)
- draw a line with the current foreground color from (x1, y1) to (x2, y2)
XDrawRectangle(d, w, gc, x, y, w, h)
- draw an empty rectangle with the current foreground color with width w and height h pixesl, and with upper-left corner at (x, y)
XFillRectangle(d, w, gc, x, y, w, h)
- draw a filled rectangle (with current foreground color) as XDrawRectangle
XDrawArc(d, w, gc, x, y, w, h, a1, a2)
- draw an arc of an ellipse in a rectangle with width w and height h. a1 and a2 are starting and ending angles of the arc in 64ths of a degree. zero degrees starts at the three o'clock position and degrees increase counter-clockwise as expected. The circle or ellipse fills the specified rectangle, and will be complete if you draw from zero degrees to 360*64)
XFillArc(d, w, gc, x, y, w, h, a1, a2, h)
- as XDrawArc, except that the arc is filled with the current foreground color
XDrawString(d, w, gc, x, y, s, l)
- draw a text string s in the current font starting at (x, y) and extending for length l characters