2.2 Displaying bitmaps on the screen

2.2.2 Making a viewport

The function make-viewport creates a viewport of the specified dimensions:

(setq *viewport2*
      (make-viewport :width 100 :height 100 
                     :screen-x 50 :screen-y 0))
Notice that*viewport1*, created in Section 2.2.1 on page 16, is partially blank because the newly created*viewport2* has occluded part of it.

Since a viewport creates an associated bitmap by default,*viewport2* has its own bitmap. You can perform graphics operations directly to the viewport's bitmap by using the variable that contains the viewport in place of the bitmap argument of an output function:

(draw-line *viewport2* (make-position 0 0)
           (make-position 100 0) :width 10)

You now see a thick line from the top-left corner of the viewport to the top-right corner of the viewport.

You can also copy from one bitmap to another by using*bitmap* from the previous example:

(bitblt *bitmap* 0 0 *viewport2* 0 0 100 100 boole-1)
Notice that*viewport2* shows the image of*bitmap* in addition to the thick line that was originally drawn on*viewport2*.

Viewports are not limited to displaying bitmaps of the same size as their screen clipping region; they can display bitmaps that are larger. When creating a viewport with a bitmap that is larger than the viewport, you can specify the keyword arguments :bitmap-x and :bitmap-y. These arguments define the positions in the bitmap that are displayed at the top-left corner. If you do not supply these arguments, they receive the value 0 by default.

Try this example:

(setq *viewport3*
      (make-viewport :width 50 :height 50
                     :bitmap *bitmap*
                     :bitmap-x 50 :bitmap-y 25
                     :screen-x 100 :screen-y 0))

A new viewport, half the width and height of*viewport2*, now displays a partial image of the bitmap. The bit at location (50,25) in*bitmap* corresponds to the pixel at the location (0,0) in*viewport3*.

The function deactivate-viewport removes a viewport or window from the screen. Any windows that were occluded before the window was removed are now visible. Deactivating a viewport or window does not remove the window from the window system, only from the screen; the window can be displayed again on the screen with the function activate-viewport:

(deactivate-viewport *viewport3*)
Notice that*viewport3* is no longer on the screen. To bring it back, type the following expression:

(activate-viewport *viewport3*)

The Window Tool Kit - 9 SEP 1996

Generated with Harlequin WebMaker