Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!csd4.milw.wisc.edu!cs.utexas.edu!uunet!microsoft!bradch From: bradch@microsoft.UUCP (Bradford Christian ms1) Newsgroups: comp.sys.amiga.tech Subject: Re: Clicking on Irregular Shapes Message-ID: <6124@microsoft.UUCP> Date: 21 Jun 89 21:34:27 GMT References: <42700015@m.cs.uiuc.edu> Reply-To: bradch@microsoft.UUCP (Bradford Christian ms1) Organization: Microsoft Corp., Redmond WA Lines: 47 In article <42700015@m.cs.uiuc.edu> schwager@m.cs.uiuc.edu writes: >[ ... ] >Given an irregularly shaped object on a Screen, how can one tell if >the mouse button has been pressed inside of it? I don't want a box all >around or inside it; I want the object and exactly the object. Here's >why I ask: I'm going to be drawing a map on the screen (into a Backdrop >window of a workbenchscreen) and I want to be able to select individual >countries. Take something like Italy- if the user selects the toe of >the boot or the top, it should acknowledge either. But I don't want them >to be able to select Italy while they're just a tad into Switzerland. Nor >do I want them to be able to click in a corner of Italy and have them >wondering why the Amiga didn't grab their click. > [ ... ] Easy solution (hack): Make each country a color different than it's neighbors using basic topology rules. Define a rectangle around each country. When the user clicks, get the color of the pixel under the cursor and check all rectangles that contain the cursor. When one of the right color is found, so is your country. I repeat: this is a hack and will only work under ideal conditions. For example, if you label the countries, the user would have to be careful not to click on the label (it would be the wrong color). Better solution (hard): QuickDraw (the Mac graphics library) defines an object called a region which is an arbitrary shape. Internally, it's structure is a set of lines containing start/end column pairs. (E.g. line 1 starts at 10 and continues to 20, line 2 starts at 3 and continues to 15.) You could write your own region package that would include some way of converting your country shapes into regions and a check to see if a point is inside the region. Another solution (memory hog): Create a separate bitmap for each country. When the user clicks, look at each country whose bounding rectangle contains the point and check to see if the point is set in the countrie's bitmap. I believe there is a way to use the last solution in the BOB code, but I've never played with that stuff. It sure would be nice if Commodore would add regions to the graphics library; they are REALLY handy for a number of things (hint for 1.4 ;^) BradCh