Can I trigger Event on Canvas Object like polygon?

38 views
Skip to first unread message

BLACKBING

unread,
Sep 3, 2008, 10:49:53 PM9/3/08
to google-excanvas
As title, if i create a line or polygon, I want to click it and
trigger an event function. Have any idea?

Adam Maschek

unread,
Sep 4, 2008, 4:40:32 AM9/4/08
to google-excanvas
No, you cant do that. If you need sth like that, you need SVG.

roliveira

unread,
Sep 4, 2008, 4:45:07 AM9/4/08
to google-excanvas
Well as far as i know i think you will have to get the mouse
coordinates on click event and then see if those coordinates belong to
the line.

I say this based on a project made by Ernest Delgado:

http://www.ernestdelgado.com/public-tests/canvasphoto/
http://www.ernestdelgado.com/public-tests/canvasphoto/demo/canvas.html

He had to determine if the user clicks the photo. And to do that he
had to determine mouse coordinates first (see code:
http://code.google.com/p/canvas-photo/source/browse#svn/trunk).



On Sep 4, 3:49 am, BLACKBING <blackb...@gmail.com> wrote:

Ryan Schmidt

unread,
Sep 4, 2008, 5:07:41 AM9/4/08
to google-...@googlegroups.com
On Sep 4, 2008, at 3:40 AM, Adam Maschek wrote:

> On Sep 4, 3:49 am, BLACKBING wrote:
>
>> As title, if i create a line or polygon, I want to click it and
>> trigger an event function. Have any idea?
>

> No, you cant do that. If you need sth like that, you need SVG.

Probably a lot of people like me are using canvas because they find
svg unpalatable.

I'm sure there's a way to do it in canvas, though it won't be
easy! :) You'll have to do all the computations yourself to determine
if the clicked coordinate is inside any line or shape you've drawn.
That means you'll have to keep a record of what you've drawn, because
the canvas just remembers pixels, not what commands you used to draw
them. I'll be looking into this myself soon. If I learn anything
useful I'll post my results. For now, here's an interesting document:

http://alienryderflex.com/polyspline/

Reply all
Reply to author
Forward
0 new messages