New topic: 

mouse down on canvas or how is it done?

<http://forums.realsoftware.com/viewtopic.php?t=31408>

       Page 1 of 1
   [ 3 posts ]                 Previous topic | Next topic         Author  
Message       DukeUK           Post subject: mouse down on canvas or how is it 
done?Posted: Thu Dec 03, 2009 5:32 pm                        
Joined: Wed Jul 22, 2009 3:17 pm
Posts: 7              Don't know whether anyone can point me in the right 
direction with this.

I have a window with an image on a canvas (its actually a map).  

What I would like is to assign a value to a variable depending on where the 
user clicks on the canvas.

I thought maybe I could overlay more canvases with mouse down events depending 
on which one was clicked, but the areas are very irregular so this would be 
very difficult to do without having hundreds of canvases.  

I then thought maybe there was a way to work out the co-ordinates of the click 
and then feed the values into some equations to get the value.  Again that 
would be almost impossible because of the shape of the areas.

I am just wondering how this is normally done ?

Ta for any help   
                            Top                timhare           Post subject: 
Re: mouse down on canvas or how is it done?Posted: Thu Dec 03, 2009 6:35 pm     
                   
Joined: Fri Jan 06, 2006 3:21 pm
Posts: 6882
Location: Portland, OR  USA              Create a second image where each 
country is a unique solid color.  Take the X,Y coords from the mouseclick and 
check the pixel color on the second image.   
                            Top               kendoll           Post subject: 
Re: mouse down on canvas or how is it done?Posted: Thu Dec 03, 2009 6:37 pm     
                          
Joined: Mon Jul 17, 2006 10:39 am
Posts: 1542              You can get the location of a click in a canvas by 
using a MouseDown event.  The X and Y parameters passed to that event are 
relative to the top-left corner of the canvas itself.

As for collision-testing with polygonal shapes (I'm assuming this is what 
you're dealing with), there are ways of doing it, but such things are usually 
more math-related than REALbasic-related.  
http://en.wikipedia.org/wiki/Point_in_polygon should give you a starting point 
to work from.  Tim's method is probably simpler, assuming you can draw your 
shape, but does require more memory.     
_________________
Kenneth McCleary
[email protected]  
                            Top           Display posts from previous: All 
posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost 
timeSubject AscendingDescending          Page 1 of 1
   [ 3 posts ]     
-- 
Over 1500 classes with 29000 functions in one REALbasic plug-in collection. 
The Monkeybread Software Realbasic Plugin v9.3. 
http://www.monkeybreadsoftware.de/realbasic/plugins.shtml

[email protected]

Reply via email to