You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Henric Rosvall <he...@swipnet.se> on 2006/04/11 17:15:35 UTC

MouseEvnts in scrolled Canvas

Hi!
 
I have a class that inherits from JSVGCanvas, encapsulated in a
JSVGScrollPane. When I click somewhere in the canvas, I get a DOMMouseEvent
that reports the clientX and Y-coordinates, and this works great - if the
JSVGScrollPane isn't scolled. If I scroll down, it will still report the
same coordinate as when it's not scrolled at all, which causes a problem
when trying to select an object.
 
So, how do I convert the ClientX and ClientY-coordinates into
canvas-coordinates? (so a click at position 200, 300 with a JSVGScrollPane
scrolled down 500 px becomes 200, 1000)
 
Regards
Henric Rosvall

Re: MouseEvnts in scrolled Canvas

Posted by th...@kodak.com.
Hi Henric,

"Henric Rosvall" <he...@swipnet.se> wrote on 04/11/2006 11:15:35 
AM:

> So, how do I convert the ClientX and ClientY-coordinates into canvas-
> coordinates? (so a click at position 200, 300 with a JSVGScrollPane 
scrolled 
> down 500 px becomes 200, 1000)

   I presume you mean 200,800.  The short answer is getScreenCTM().
If you look at the recent message from Selva, there is a good example
of how to use this in the 'localPt' function.  For all of SVG it is 
important to have a clear idea of what coordinate system you are working
in.  For updating the X/Y coordinates of an element they are defined in
the 'local' coordinate system of the element (which is often but not 
always
the same as the parent's coordinate system, if the element has a 
'transform'
attribute then it is likely not the same).

> I have a class that inherits from JSVGCanvas, encapsulated in a 
> JSVGScrollPane. When I click somewhere in the canvas, I get a 
DOMMouseEvent 
> that reports the clientX and Y-coordinates, and this works great - if 
the 
> JSVGScrollPane isn't scrolled. If I scroll down, it will still report 
the same 
> coordinate as when it's not scrolled at all, which causes a problem when 

> trying to select an object.

   BTW you should check if you can use the 'target' that is already in the
MouseEvent as that is the element the mouse is over when the event was 
created.
For most uses this is exactly what you want.


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org