2.2 Displaying bitmaps on the screen
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-pointreturns 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 *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))When doing graphics output, you might want to draw a number of points or lines in sequence. The functions
(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)
draw-polylineallow 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)If at any time you wish to clear all the bits in a bitmap, use the function
(draw-polyline *window* (list (make-position 10 10) (make-position 90 10) (make-position 10 90) (make-position 90 90)) :width 2)
(clear-bitmap *window*)You can send text to a bitmap directly by using the functions
stringblt. This operation is not the same as using the Common Lisp functions
stringblt, you must specify the exact location of the character or string; with
format, 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!")
Generated with Harlequin WebMaker