How I can detect a click on the border of a canvas, not its conte开发者_JAVA百科nts?.
I am aware that I can validate ranges event.mouseX (Y), but my canvas has rounded corners and in some cases appears to be a circle, is there any way of knowing if the border of the canvas is under the pointer?
I have:
Canvas.setStyle ("borderColor", 0xFF0000);
Canvas.setStyle ("borderStyle", "solid");
Canvas.setStyle ("BorderThickness", 10);
Judging by a 10px thickness what is the real problem if the user clicks on the border or the canvas? Do you have event listeners that are being invoked when the canvas is clicked on? If so, maybe you should refine those listeners to tune into the events dispatched from the contents of the canvas rather than the canvas itself.
I don't know much about this particular topic, but have you thought about setting up some sort of picking mechanism?
You can have a graphics buffer that you never display, but draw everything to. Each thing you'd like to distinguish you draw in a different color. That way you can, for any mouse event, figure out what the mouse was over, including the border which would be drawn in its own color, and pass the appropriate event to that object.
Probably only useful as a last resort, if you can't find any other way of doing it.
How about having one canvas that is 10px larger than the one in front of it with your actual content. Then that back canvas register for a click and the front one with your actual content not.
精彩评论