Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!mips!swrinde!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!pacific.mps.ohio-state.edu!linac!mp.cs.niu.edu!ux1.cso.uiuc.edu!midway!quads.uchicago.edu!jcav From: jcav@quads.uchicago.edu (john cavallino) Newsgroups: comp.sys.mac.programmer Subject: Re: Easy way to draw the rubber band?? Message-ID: <1991May31.151716.5814@midway.uchicago.edu> Date: 31 May 91 15:17:16 GMT References: <30149@hydra.gatech.EDU> <53513@apple.Apple.COM> Sender: news@midway.uchicago.edu (NewsMistress) Organization: University of Chicago Lines: 39 In article <53513@apple.Apple.COM> stevec@Apple.COM (Steve Christensen) writes: >If you just want to track an empty rectangle around, how about doing something >like this: All of the futzing around to create the rectangle from the points can be eliminated if you use the Quickdraw procedure _Pt2Rect (IM I-175). See below: >void RubberBand(Point startPt, Rect *theRect) { > Point lastPt,newPt; > > lastPt.v = startPt.v; // initialize the last mouse location > lastPt.h = startPt.h; // to be the starting mouse location > SetRect(theRect,0,0,0,0); // empty rectangle to start > > PenMode(patXor); // use XOR transfer mode > > while (StillDown()) { > GetMouse(&newPt); // get the mouse's current location > if ((newPt.v != lastPt.v) && (newPt.h != lastPt.h)) { > lastPt.v = newPt.v; // it's moved since last time, so > lastPt.h = newPt.h; // update the last location > > FrameRect(&theRect); // erase the previous rectangle Pt2Rect(&startPt,&newPt,&theRect); // MUCH MUCH simpler > FrameRect(theRect); // draw the new rectangle > } > } > > PenNormal(); // restore the pen mode >} -- John Cavallino | EMail: jcav@midway.uchicago.edu University of Chicago Hospitals | USMail: 5841 S. Maryland Ave, Box 145 Office of Facilities Management | Chicago, IL 60637 B0 f++ w c+ g+ k s(+) e+ h- pv (qv) | Telephone: 312-702-6900