Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!spool.mu.edu!mips!apple!stevec From: stevec@Apple.COM (Steve Christensen) Newsgroups: comp.sys.mac.programmer Subject: Re: Easy way to draw the rubber band?? Message-ID: <53513@apple.Apple.COM> Date: 31 May 91 04:59:58 GMT References: <30149@hydra.gatech.EDU> Organization: Apple Computer Inc., Cupertino, CA Lines: 63 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: 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 if (lastPt.v > startPt.v) { // make sure the bottom of the theRect->top = startPt.v; // rectangle is below the top theRect->bottom = lastPt.v; } else { theRect->top = lastPt.v; theRect->bottom = startPt.v; } if (lastPt.h > startPt.h ) { // ditto with the left and right theRect->left = startPt.h; theRect->right = lastPt.h; } else { theRect->left = lastPt.h; theRect->right = startPt.h; } FrameRect(theRect); // draw the new rectangle } } PenNormal(); // restore the pen mode } Note that startPt should be in local coordinates. This means you've done a SetPort() to the appropriate port followed by GlobalToLocal(&startPt). If you'd like a gray rubber band instead of a black one, you could also do a PenPat(&qd.gray) (MPW) or PenPat(gray) (Think) right after the PenMode call. steve -- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Steve Christensen Never hit a man with glasses. stevec@apple.com Hit him with a baseball bat.