Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!usc!snorkelwacker!bloom-beacon!eru!luth!sunic!tut!santra!kampi.hut.fi!jmunkki From: jmunkki@kampi.hut.fi (Juri Munkki) Newsgroups: comp.sys.mac.programmer Subject: Re: Line selection algorithims.. Message-ID: <1989Dec17.104221.23095@santra.uucp> Date: 17 Dec 89 10:42:21 GMT References: <8912160053.AA00720@cadman.nyu.edu> Sender: news@santra.uucp (Cnews - USENET news system) Reply-To: jmunkki@kampi.hut.fi (Juri Munkki) Organization: Helsinki University of Technology, Finland Lines: 31 In article <8912160053.AA00720@cadman.nyu.edu> deragon@CADMAN.NYU.EDU (John Deragon) writes: > I was wondering how the current applications like >MacDraw, MacDraft...etc etc do the line selection. For example in >MacDraw you click on the line and it becomes selected? How does it >do this? What is it testing on mouseDown? I think I read that MacDraw uses QuickDraw to do this. You need a grafport with a single pixel (or many pixels, if your pointer should not be with single pixel resolution). Then draw all objects with a black penpat. Check the pixel after every object and stop when it is black. The last object you drew was hit. You have to draw the objects from front to back. I also recommend that you create a "select next object" menu item that resumes the last selection check. You also have to set up the grafport so that the single pixel (or group of pixels) have the coordinates of the mousedown. I wrote a very simple Bezier curve program and used my own window as the checking grafport. This causes a pixel to blink and you have to update that pixel after this routine, so I recommend that you use an offscreen bitmap. Offscreen bitmaps have the benefit that you can just a look at the bitmap contents without having to call GetPixel. This algorithm is surprisingly fast. I guess QuickDraw clips so well that discards most objects without even considering them. Most of the overhead probably still comes from trap dispatches. _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._ | Juri Munkki jmunkki@hut.fi jmunkki@fingate.bitnet I Want Ne | | Helsinki University of Technology Computing Centre My Own XT | ^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^~^