
3.4.3 Active regions
draw-rect function that was defined in Section 3.4.1 on page 31.
;;; This support function draws a rectangle on viewport, around
;;; region.
(defun draw-region-rect (region viewport)
(draw-rect
viewport
(region-origin-x region) (region-origin-y region)
(+ (region-origin-x region) (region-width region))
(+ (region-origin-y region) (region-height region))))
;;; This support function draws a filled inverse rectangle on
;;; viewport, around region.
(defun draw-region-filled-rect (region viewport)
(bitblt
viewport (region-origin-x region) (region-origin-y region)
viewport (region-origin-x region) (region-origin-y region)
(region-width region) (region-height region)
boole-c2))
;;; Draw a string in an active region.
(defun draw-active-region-string
(window string x y &optional (font *default-font*))
(stringblt window (make-position x y) font string)
;; Outline the string region, and account for the string's
;; height offset.
(let ((region
(make-region
:x x
:y (- y (font-height font))
:width (string-width string font)
:height (font-height font))))
;; Make the active region around the string.
(make-active-region
region
:bitmap window
:mouse-documentation "Right: invert active region"
:mouse-enter-region ; Outline the string.
#'(lambda (viewport region event x y)
(declare (ignore event x y))
(draw-region-rect region viewport))
:mouse-exit-region ; Remove the outline.
#'(lambda (viewport region event x y)
(declare (ignore event x y))
(draw-region-rect region viewport))
:mouse-click ; Highlight the string.
#'(lambda (viewport region event x y)
(declare (ignore event x y))
(draw-region-filled-rect region viewport)))))
;; Invoke the function.
(draw-active-region-string *window* "active region" 0 20)
Now move the mouse over the text string"activeregion" in the window. A box appears around the active region when the mouse enters it. If you click the right mouse button, the string appears in reverse video in the active region area. A bitmap can have any number of active regions. The functionbitmap-active-regions returns a list of the active regions associated with a bitmap. If you want to remove an active region from a bitmap, use the function detach-active-region. If you want to remove all of the active regions from a bitmap, use the functionclear-bitmap-active-regions.

Generated with Harlequin WebMaker