3.4.3 Active regions

3.4.3.4 Restricting mouse actions in active regions

When active regions overlap, the mouse actions whose x- and y-location is inside more than one active region are given to all of the overlapping active regions in an arbitrary order. Code can be executed by all of the active regions that handle the specified mouse input. If you want some overlapping active regions to exclusively handle certain kinds of mouse actions, you must restrict execution of code under those circumstances.

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 functionsdraw-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*)


The Window Tool Kit - 9 SEP 1996

Generated with Harlequin WebMaker