[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Another highlighting questi
- To: "Rodney Daughtrey" <rodney%proact@uunet.UU.NET>, "MCL list" <info-mcl@cambridge.apple.com>
- Subject: Re: Another highlighting questi
- From: bill@cambridge.apple.com (Bill St. Clair)
- Date: Thu, 5 May 1994 09:45:58 -0400
At 7:44 PM 5/4/94 -0600, Rodney Daughtrey wrote:
>Subject: Another highlighting question
>Thanks again to Bill St. Clair for answering my first question.
>
>Now another: I'm trying to add highlighting/selection behavior to some views
>which inherit from ccl:view. I've gotten the code to work when the highlighting
>color is black (using ccl:invert-rect, etc), but I'm having problems with other
>colors where you don't want to invert the (usually black) text. I've written a
>simple mixin (see below) for the highlighting colors other than black that
>works, but it has the disadvantage of having to redraw the view each time the
>view is selected/deselected. In the simple example below the redraw is hardly
>noticeable, but for more complex views it flickers. What I'd really like is a
>version which, when a view is selected/deselected, draws/undraws the colored
>selection rectangle over the view without disturbing the foreground pixels of
>the text or graphics. I've tried using the :pator pen pattern in conjunction w/
>ccl:paint-rect, etc, but could not get this to work. Also, using dialog items
>and their colorable parts aren't applicable for our needs.
>
>The example below illustrates the behavior I'm after, minus the need to
>redisplay each time. Does anyone have any suggestions/code that implements something
>like this? Are there Macintosh traps that implement some/all of this for me?
MCL's inspector does what you want, and you've got source to look at.
Basically, you keep a highlight region and use #_InvertRgn along with
a magical low-memory global to use the highlight color. Here is the relevant
code from "ccl:library;inspector;inspector-window.lisp". I didn't include
source for highlight-selection as its details would obscure my point.
(Basically, it computes what the highlighted region should be,
stores it with (setf (highlight-region inspector-view) rgn), then calls
%invert-region).
----------------------------------------------------------------------------
(in-package :inspector)
(defun unhighlight-selection (inspector-view)
(let ((rgn (highlight-region inspector-view)))
(when (and (handlep rgn) (not (#_EmptyRgn :ptr rgn :boolean)))
(with-focused-view inspector-view
(%invert-region rgn)
(#_SetEmptyRgn :ptr rgn)))))
; Invert a region using the highlight color (see Inside Mac V-62).
(defun %invert-region (rgn)
(with-macptrs ((hiliteMode (%int-to-ptr #$HiliteMode)))
(%put-byte hiliteMode
(logand (lognot (ash 1 #$hiliteBit)) (%get-byte hiliteMode))))
(#_InvertRgn :ptr rgn))