Next: Colour Up: Xlib and Motif Previous: Writing Your Own Event Handler


If a window has been obscured then we will have to redraw the window when it gets reexposed.

This means that we may have to go through all the drawing function calls that have previously been used to render our drawing. This will be cumbersome and may involve some complicated storage methods.

Fortunately, X provides a mechanism that overcomes this (and other) problem.

A Pixmap is an off-screen Drawable area.

We can draw to Pixmap in the same way as we draw to a Window.

However no immediate display effect will occur in our window. To do this we must copy the Pixmap to a Window.

The program draw2.c draws to pixmaps instead of the window. NOTE: the effect of an exposure on draw.c and draw2.c.

To create a Pixmap use the XCreatePixmap() function. This function takes 5 arguments and returns a Pixmap structure:

- a pointer to the Display associated with Pixmap.
- the screen on which to place Pixmap.
Width, Height
- the dimensions of the Pixmap.
- the number of bits of each pixel. Usually 8 by default. A Pixmap of depth 1 is usually called a bitmap and are used for icons and special bitmap files.

When you have finished using a Pixmap it is a good idea to free the memory in which it has been stored by calling:

XFreePixmap(Display*, Pixmap).

If you want to clear a Pixmap (not done automatically) use XFillRectangle().

To copy a Pixmap onto another Pixmap or a Window use:

XCopyArea(Display *display, Drawable source, 
      Drawable destination, GC gc, 
      int src_x, src_y, 
      int width, int height, 
      int dest_x, int dest_y)

where (src_x, src_y) specify the coordinates in the source pixmap where copy starts, width and height specify dimensions of copied area and (dest_x, dest_y) are the start coordinates in the destination where pixels are placed.
Tue May 24 16:52:56 BST 1994