Up: Using DrawingAreas in Practice
Previous: draw_input.c - Input to a DrawingArea
One problem the draw_input.c program has is that if the window was
covered and then exposed the picture would not redraw itself.
Indeed since it is an interactive process it would be very difficult to redraw
the picture unless we used Pixmaps to store the drawing data and then map
a pixmap to the window.
When an expose event is detected all we need to do is remap the pixmap to the
The draw_input2.c program does exactly the same task as draw_input.c but draws to a pixmap which can be remapped to the window upon
The major differences between the programs are:
- A Pixmap is created with the XCreatePixmap() function. The
Pixmap is made the same size as the DrawingArea and is assigned to
default Screen and DepthOfScreen values.
- We still draw some things to the DrawingArea only. The dashed boxes
which only serve to indicate the current rectangle size do not need to be
permanently stored and are unlikely to be drawn, covered and reexposed in
between another mouse motion or the mouse up event.
- We draw the filled colour rectangle to both DrawingArea and Pixmap
so that we get an immediate effect of drawing and we have the Pixmap backup
- Upon an expose event we use XCopyArea() to copy the Pixmap to the