2.2 Displaying bitmaps on the screen

2.2.4 Sending graphics output to bitmaps

The Window Tool Kit provides many functions that alter bits on bitmaps to produce graphics output on the display. This section presents examples that send different kinds of output to bitmaps.

For the following examples, you need a bitmap that is currently mapped onto the screen display. If you do not have a bitmap, viewport, or window from a previous section, create a window as follows:

(setq *window* (make-window :width 100 :height 100))
Note: It is often useful when learning about the window system to be able to locate the exposed viewport or window at a given location relative to the root viewport. The function viewport-at-point returns the viewport or window of the exposed viewport at any given location.

You can determine the value of any bit on a bitmap by giving the name of the bitmap and the coordinates of the location to the function bitmap-value:

(bitmap-value *window* 5 5)
Recall that the values of a bitmap's bits are 0, or turned off, by default. You can change the value of any bit on a bitmap as follows:

(setf (bitmap-value *window* 5 5) 1)
If you look carefully you can see that*window* has a bit set, or black, at pixel location (5,5).

Draw some lines and circles on*window*. Notice that you can vary the width of the line or circle by supplying different values for the:width keyword argument.

(draw-line *window* (make-position 0 0) 
                    (make-position 100 100))

(draw-line *window* (make-position 0 100) (make-position 100 0))

(draw-line *window* (make-position 0 50) (make-position 100 50) :width 5)

(draw-line *window* (make-position 50 0) (make-position 50 100) :width 5)

(draw-circle *window* (make-position 50 50) 50 :width 5)

(draw-circle *window* (make-position 50 50) 25)

(draw-circle *window* (make-position 50 50) 10 :width 10)

When doing graphics output, you might want to draw a number of points or lines in sequence. The functions draw-polypoint and draw-polyline allow you to specify a list of positions as either a polypoint or polyline respectively, as the following example demonstrates:

(draw-polypoint *window*
  (list (make-position 10 10) (make-position 90 10)
        (make-position 10 90) (make-position 90 90))
  :width 5)

(draw-polyline *window* (list (make-position 10 10) (make-position 90 10) (make-position 10 90) (make-position 90 90)) :width 2)

If at any time you wish to clear all the bits in a bitmap, use the functionclear-bitmap:

(clear-bitmap *window*)
You can send text to a bitmap directly by using the functionscharblt and stringblt. This operation is not the same as using the Common Lisp functionsformat orprint with a bitmap output stream. Withcharblt orstringblt, you must specify the exact location of the character or string; withformat, the window's output stream position determines where the text is located.

(charblt *window* (make-position 45 20) *default-font* \#\\A)
(stringblt *window* (make-position 30 50) *default-font* "Hello!")

The Window Tool Kit - 9 SEP 1996

Generated with Harlequin WebMaker