Path: utzoo!utgpu!news-server.csri.toronto.edu!bonnie.concordia.ca!uunet!mcsun!ukc!edcastle!hwcs!sfleming From: sfleming@cs.hw.ac.uk (Stewart T. Fleming) Newsgroups: comp.sys.mac.programmer Subject: Re: An itsy bitsy question... Message-ID: <1929@odin.cs.hw.ac.uk> Date: 9 Jan 91 19:57:16 GMT References: <27725.2787e3d0@kuhub.cc.ukans.edu> Sender: news@cs.hw.ac.uk Reply-To: sfleming@cs.hw.ac.uk (Stewart T. Fleming) Organization: Dept. Of Computer Science, Heriot-Watt University, Edinburgh Lines: 73 In article , urlichs@smurf.sub.org (Matthias Urlichs) writes: |> 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 |> Modify at will for drawing other shapes, of course... |> If you simply extend this procedure to do other shapes, then you will likely get horrific flicker problems. True/False ? Drawing and erasing the whole shape is fairly obvious to the user. Drawing lines with this method is fine, but for other shapes : Procedure TrackShape(Var currPt, prevPt, startPt: Point); Var currRect, prevRect: Rect; prevRgn, dRgn: RgnHandle; Begin {Draw if mouse moves or is outside the window frame (autoscroll)} If NeedToScroll(currPt) Or Not EqualPt(currPt, prevPt) Then Begin GetWindowFrame(currRect); {Pin point in frame} PinInRect(currRect, currPt); Pt2Rect(startPt, currPt, currRect); {Make shapes} Pt2Rect(startPt, prevPt, prevRect); dRgn := OutlineRgn(currRect); {Outline shapes} prevRgn := OutlineRgn(prevRect); XorRgn(dRgn, prevRgn, gUtilRgn); {Find bits changed} DisposeRgn(prevRgn); DisposeRgn(dRgn); PenMode(patXor); {Draw bits changed} PaintRgn(gUtilRgn); End; End; Function OutlineRgn (theRect: Rect): RgnHandle; Var outRgn, inRgn: RgnHandle; Begin outRgn := NewRgn; inRgn := NewRgn; RectRgn(outRgn, theRect); { Construct region consisting of a } CopyRgn(outRgn, inRgn); { one pixel thick outline of } InsetRgn(inRgn, 1, 1); { the previous selection rect } DiffRgn(outRgn, inRgn, outRgn); OutlineRgn := outRgn; DisposeRgn(inRgn); End; I wrote this as a mouse task for Think Pascal with OOP. It works, but I don't think it's too pretty. Feel free to take it apart :-) Here, I just use rectangles, but any shape could be done in the same way by changing OutlineRgn. NeedToScroll checks if the point is outside the frame; if so, it calls ScrollRect. |> I'd suggest some enhancements: > - invalidating the old line rather than simply erasing it; |> there might be other shapes behind it. Do you need to do this after every move ? Or not until the user releases the mouse ? |> Matthias Urlichs -- urlichs@smurf.sub.org -- urlichs@smurf.ira.uka.de Stewart -- sfleming@cs.hw.ac.uk ...ukc!cs.hw.ac.uk!sfleming "Before starting any programming project, try explaining it to your cat."