Is there any trick to determine if user clicks on given element rendered in canvas? For example I'm displaying rhombus from .png file with transparent background and i want to know if user click inside or outside that figure (like mouse-element collision).
+1
A:
There is no concept of individual elements in a canvas - it is simple just an area that you're drawing pixels onto. SVG on the other hand is made up of elements which you can then bind events to. However are a few approaches you can take to add click events to canvas:
Position an html element that overlays the area on the canvas you want to be clickable. A for a rectangular area or an image map for something more irregular.
Use separate canvases for each element that you want to be clickable.
CAKE - I haven't used this myself, but it's description is "SVG sans the XML". This may cover your needs. Demos here http://glimr.rubyforge.org/cake/canvas.html#EditableCurve
Castrohenge
2010-07-09 16:40:52
You could also just check the coordinates of the mouse click vs. the coordinates of the object. A little more intensive, but not terribly difficult.
Ryan Kinal
2010-07-09 16:43:02