
3.4.3 Active regions
You should clear all the active regions in your experimental window before you try another example in the same window to prevent the resulting active regions from overlapping:
(clear-bitmap-active-regions *window*) (clear-bitmap *window*)In this next example, two smaller squares are drawn inside a larger rectangle. Each of these three rectangles describes an active region on the window. A click in any of the smaller rectangles should reverse the shade of that active region but should not reverse the shade of the larger square. A click in the larger rectangle should reverse its shade. The location of the mouse event determines when a rectangle's shade is reversed. This example uses the previously defined functions
draw-rect,draw-region-rect, anddraw-region-filled-rect.
(defun squares (window)
(let ((square1 (make-region :x 30 :y 60 :width 15 :height 15))
(square2 (make-region :x 55 :y 60 :width 15 :height 15))
(big-square (make-region :x 20 :y 40
:width 60 :height 50)))
(draw-region-rect square1 window)
(draw-region-rect square2 window)
(draw-region-rect big-square window)
(make-active-region ; Draw a small rectangle.
square1
:bitmap window
:mouse-documentation "Click: invert square color"
:mouse-click
#'(lambda (viewport region event x y)
(declare (ignore event x y))
(draw-region-filled-rect region viewport)))
(make-active-region ; Draw a second small rectangle.
square2
:bitmap window
:mouse-documentation "Click: invert square color"
:mouse-click
#'(lambda (viewport region event x y)
(declare (ignore event))
(draw-region-filled-rect region viewport)))
(make-active-region ; Draw a large rectangle.
big-square
:bitmap window
:mouse-documentation "Click: invert square color"
:mouse-click
#'(lambda (viewport region event x y)
(declare (ignore event))
;; If the click was really in one of the small squares,
;; ignore it.
(unless (or (region-contains-point-p square1 x y)
(region-contains-point-p square2 x y))
(draw-region-filled-rect region viewport))))))
;; Invoke the function.
(squares *window*)

Generated with Harlequin WebMaker