Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!nstn.ns.ca!news.cs.indiana.edu!spool.mu.edu!rex!wuarchive!zazen!schaefer.math.wisc.edu!dickie From: dickie@schaefer.math.wisc.edu (Garth Dickie) Newsgroups: comp.sys.mac.programmer Subject: Re: Easy way to draw the rubber band?? Message-ID: <1991May31.181020.1025@schaefer.math.wisc.edu> Date: 31 May 91 18:10:20 GMT References: <30149@hydra.gatech.EDU> <53513@apple.Apple.COM> Reply-To: dickie@math.wisc.edu (Garth Dickie) Organization: Univ. of Wisconsin Dept. of Mathematics Lines: 59 In article <53513@apple.Apple.COM> stevec@Apple.COM (Steve Christensen) writes: >gt4586c@prism.gatech.EDU (WILLETT,THOMAS CARTER) writes: >>i'm trying to draw the nifty rubber band we all know and love, the one that >>is a rectangle defined by the mouse location at the time of button down as >>the anchor point and the current mouse location (still with button down) as >>the other corner. i've got the mouse location and drawing the rectangle >>alright, but it blanks out my drawing as it goes because i'm calling >>EraseRect do blank out the rectangles outline as the mouse moves. what's >>the right way to do it? thanks for any help > >If you just want to track an empty rectangle around, how about doing something >like this: > > [ code for tracking a rectangle ] It also pays to play with regions, so that the old rectangle is erased at the same time the new one is drawn. It takes a little more time per step, but it *looks* faster, since there is no flicker. The Finder now does this, when you drag an icon, although DragGrayRgn still does it the old way. So, PenPat( gray ); PenMode( notPatXor ); // so we look black, not white, on desktop oldframe = NewRgn(); newframe = NewRgn(); insidebox = NewRgn(); [ whenever the cursor changes ] { Pt2Rect( oldwhere, newwhere, &bounds ); oldwhere = newhere; RectRgn( newframe, &bounds ); // compute a region for a one InsetRect( &bounds, 1, 1 ); // pixel wide frame inside the RectRgn( insidebox, &newrect ); // rectangle. XorRgn( insidebox, newframe, newframe ); XorRgn( newframe, oldframe, oldframe ); // compute the difference PaintRgn( oldframe ); // xor the difference temp = oldframe; // save the current rectangle oldframe = newframe; // as oldframe. newframe = temp; } PaintRgn( oldframe ); // erase the rectangle Somebody was asking about doing color hilighting under the inverted rectangle, like the Finder appears to do. The trick is that the Finder does the hiliting just before it draws over the hilited icon. So, (as far as I can tell), at each step, you: figure out the new rectangle. hilite anything which is now included, but wasn't before. draw the difference between the frames. dehilite anything now not included, which was before. -- Garth Dickie -- Math Graduate Student? -- dickie@math.wisc.edu