Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!think.com!snorkelwacker.mit.edu!ira.uka.de!smurf!urlichs From: urlichs@smurf.sub.org (Matthias Urlichs) Newsgroups: comp.sys.mac.programmer Subject: Re: An itsy bitsy question... Message-ID: Date: 7 Jan 91 20:16:29 GMT References: <27725.2787e3d0@kuhub.cc.ukans.edu> Organization: University of Karlsruhe, FRG Lines: 57 In comp.sys.mac.programmer, article <27725.2787e3d0@kuhub.cc.ukans.edu>, mlab2@kuhub.cc.ukans.edu writes: < < When in line-drawing-mode, a mouseDown event in the drawing window should call < a procedure similar to the below: < Modify at will for drawing other shapes, of course... I'd suggest some enhancements: - drawing the rubberbanded line in gray (QD pattern for monochrome Macs, real gray for Color QD) - drawing only when the mouse position has changed - autoscrolling the new endpoint into the window - invalidating the old line rather than simply erasing it; there might be other shapes behind it. This will make the routine slightly more complicated, of course, but all the add-ons should already be present in your program anyway. ;-) < procedure RubberBand; < var < originalPt, lastPt, newPt : Point; < begin < GetMouse(originalPoint); < PenMode(patXOr); PenPat(gray); (* you might also want to make the pen bigger, maybe one point bigger than the line you're drawing, so that it doesn't tend to vanish for near-45 degree angles *) < GetMouse(lastPt); < MoveTo(originalPt.h, originalPt.v); < LineTo(lastPt.h, lastPt.v); < repeat GetMouse(newPt); if newPt <> lastPt then begin < MoveTo(originalPt.h, originalPt.v); < LineTo(lastPt.h, lastPt); < (* GetMouse(newPt); *) ScrollIntoView(newPt); UpdateWindow; < MoveTo(originalPt.h,originalPt.v); < LineTo(newPt.h, newPt.v); < lastPt:=newPt; end; < until (not Button); < PenNormal; PenPat(black); (* reset pen size? *) MoveTo(originalPt.h, originalPt.v); LineTo(lastPt.h, lastPt.v); (* now erase and invalidate the location of the old line as there might have been bits behind it, probably by calling Pt2Rect and InvalRect *) < end; -- Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de /(o\ Humboldtstrasse 7 - 7500 Karlsruhe 1 - FRG -- +49+721+621127(0700-2330) \o)/