Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!wuarchive!ukma!rutgers!mcnc!ecsgate!ecsvax!utoddl From: utoddl@uncecs.edu (Todd M. Lewis) Newsgroups: comp.sys.amiga.programmer Subject: Re: Clicking on irregular shapes? Message-ID: <1991Apr9.154810.19996@uncecs.edu> Date: 9 Apr 91 15:48:10 GMT References: <1991Ap Organization: UNC Educational Computing Service Lines: 40 In article nj@magnolia.Berkeley.EDU (Narciso Jaramillo) writes: >In article <1991Apr2.083226.28814@jarvis.csri.toronto.edu> edgar@csri.toronto.edu (Edgar LeBel) writes: > > Here's a REALLY cheap way of detecting clicks on irregular shapes: draw the > shapes in different colours, so you can sample the pixel clicked on to > figure out which shape was picked. > >Except that (1) this forces you to click exactly on the shape boundary >for an unfilled shape and (2) it forces every shape to be a different >color. Useful for some applications, not for others. > Here's a similar technique that requires (1) that you click within the shape boundary (on it isn't good enough--helps reduce errors) and (2) all shapes be filled with one of a given set of colors. (Below I've assumed they are all the same color.) Try this. You have irregular shapes with borders, right? The shapes are all plane, and filled with the same pen color, right? Make sure that the only place on screen where that pen is used is in those shapes. Now, when the user clicks on the screen, check the pixel s/he clicked on and make sure it is that pen, and therefore is actually in one of these shapes. If not, ignore the click (or give a message). So far so good. We know a shape was selected, but we don't know which one. Next, flood-fill with a different pen starting at that pixel. If this different pen has a different color then the user can see which shape was selected, but it could be a pen of the same color--just depends on what you want. Now go through your list of irregular shapes and check a single pixel within each one until you find the shape whose color was changed. You'll probably want to flood-fill it again to set the color back to "normal", or not, depending on your needs. Todd M. Lewis, utoddl@ecsvax.uncecs.edu, utoddl@ecsvax.bitnet "It is curious that this many people [...] would assume to know the intent of the author based on the observed behavior of the program." --- Eugene H. Spafford, "Crisis and Aftermath", CACM, (June 1989)