Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site ut-dillo.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!gatech!ut-sally!ut-ngp!ut-dillo!darin From: darin@ut-dillo.UUCP (Darin Adler) Newsgroups: net.micro.mac Subject: Re: Grow Regions Message-ID: <225@ut-dillo.UUCP> Date: Fri, 6-Dec-85 14:29:56 EST Article-I.D.: ut-dillo.225 Posted: Fri Dec 6 14:29:56 1985 Date-Received: Sat, 7-Dec-85 20:55:46 EST References: <8512060411.AA13585@kim> Organization: UTexas Computation Center, Austin, Texas Lines: 74 > Attention, Real Hackers. Here's a tough one for you: When the mouse is > held down in the Grow box of a window and dragged, a gray outline of > the window follows it around. Likewise, in MacPaint or the Finder, you can > use a rectangle, which also appears in blinking gray, to select. Now, this > has got to be a non-trivial operation, saving the bits under the outline, > writing the outline, then restoring the saved bits after the outline moves. > Do we mortals have access to some semi-highlevel routine which does this for > us? Or am I going to have to kludge something ... This is an old trick for making ephemeral, ghostlike images on a bit-map display. By drawing the outline in exclusive-or mode, all the ToolBox has to do is re-draw the same outline again to completely undo the effects of the first draw. To do this just like the Finder, you also need to know a trick or two about timing to avoid an inordinate amount of flicker. Here is some sample code (in Lisa Pascal, easy to convert to C) that has all the necessary "magic": PROCEDURE Boxer(startPoint: Point; VAR endPoint: Point;); {This is a general purpose "boxing" routine, similar to the one used } {by the Finder. It works in the current port (it is often useful to } {set a ClipRect first). The endPoint is the location of the mouse-up } {event (or the last known position of the mouse, if no mouse-up event } {is available. Both startPoint and endPoint are in local coordinates.} CONST noFlickTicks = 2; {number of ticks between re-drawing} VAR box, oldBox: Rect; {for tracking the mouse} boxTick: LongInt; {for delay to avoid flicker} penSave: PenStatus; {saved status of the pen} upEvent: EventRecord; {for mouse-up event} BEGIN SetRect(oldBox, 0, 0, 0, 0); GetPenState(penSave); {save pen} PenSize(1,1); {set up the pen so that the box works} PenPat(gray); PenMode(notPatXor); FrameRect(oldBox); {framing an empty rectangle, but ...} boxTick := TickCount; WHILE StillDown DO BEGIN GetMouse(endPoint); {track that mouse} Pt2Rect(startPoint, endPoint, box); IF NOT EqualRect(oldBox, box) THEN IF TickCount >= boxTick + noFlickTicks THEN BEGIN {redraw the box...} FrameRect(oldBox); {erase the old box} FramRect(box); {draw the new box} oldBox := box; boxTick := TickCount; END; END; FrameRect(oldBox); {erase remnants of dragging} SetPenState(penSave); {restore pen} IF EventAvail(mUpMask, upEvent) THEN BEGIN {get endpoint from mouse-up event} endPoint := upEvent.where; GlobalToLocal(endPoint); END; END; -- Darin Adler {gatech,harvard,ihnp4,seismo}!ut-sally!ut-dillo!darin