OASIS Mailing List ArchivesView the OASIS mailing list archive below
or browse/search using MarkMail.

 


Help: OASIS Mailing Lists Help | MarkMail Help

 


 

   SVG: Retrieving mouse event co-ordinates in transformed co-ordinate spac

[ Lists Home | Date Index | Thread Index ]
  • From: Alan Kennedy <Alank@Widelearning.com>
  • To: "'xml-dev@xml.org'" <xml-dev@xml.org>
  • Date: Mon, 13 Mar 2000 13:10:08 -0000

Hi,

Is this something missing from SVG? Or something missing from DOM2?

Hope this explanation isn't too long.

All pixel-addressable display screens have a maximum width (max-width) and
height (max-height), and I can address pixels on such displays using a
co-ordinate system where the x value ranges from 0 to max-width and the y
value ranges from 0 to max-height. Let's call this co-ordinate space SYSTEM.

When I define a SVG document, if I don't define any co-ordinate system, I
get the "initial user co-ordinate system", which is set by the user agent.
Let's call this co-ordinate space S.

<svg width="640px" height="480px">
	<!-- This rectangle will fill the visible portion of S.	-->
	<rect x="0" y="0" width="640" height="480" style="fill:red;"/>
</svg>

However, I can also define a transformation on S, using the "viewBox"
attribute, to change the mapping of co-ordinates into a new co-ordinate
space more suitable for my purposes. Let's call this transformed co-ordinate
space ST.

<svg width="640" height="480" viewBox="0 0 100 100"
preserveAspectRatio="none">
	<!-- This rectangle will fill the visible portion of ST.	-->
	<rect x="0" y="0" width="100" height="100" style="fill:red;"
onmouse="handleSTevents(event)"/>
</svg>

Next, I register event listeners on an object in ST, listening for all mouse
events, e.g. mouseover, mouseup, mousedown, etc. I do this in order to be
able to make the objects interactive, e.g. draggable.

When the event (a DOM2 UIEvent) is received by my event handler
(handleSTevents), it has four attributes on it to tell me the location of
the mouse at the time the event occurred. They are, along with definitions
given in the DOM2 spec
(http://www.w3.org/TR/DOM-Level-2/events.html#Events-UIEvent), 

screenX - The horizontal coordinate at which the event occurred relative to
the origin of the screen coordinate system.
screenY- The vertical coordinate at which the event occurred relative to the
origin of the screen coordinate system.
clientX - The horizontal coordinate at which the event occurred relative to
the DOM implementation's client area.
clientY- The vertical coordinate at which the event occurred relative to the
DOM implementation's client area.

The problem is that there seems to be no way of determining what were the
co-ordinates of the mouse event in the transformed space ST. If I want to
find out where in my graphical object the event occurred, or if I want to
change the location of my object to a new location *in space ST*, then I
cannot do so, since I can't find the location of the event in space ST.

The "screenX" and "screenY" attributes tell me the co-ordinates of the event
in the SYSTEM co-ordinate space, and the "clientX" and "clientY" attributes
tell me the co-ordinates of the event in the user agent's S co-ordinate
space.

If I want to work out the co-ordinates of the event in the space ST, then I
have to calculate them by finding all co-ordinate system transformations
that result in the formation of ST, by searching the ancestors of the
element in the document, and process "clientX" and "clientY" through them.

Or am I missing something?

Alan Kennedy.


***************************************************************************
This is xml-dev, the mailing list for XML developers.
To unsubscribe, mailto:majordomo@xml.org&BODY=unsubscribe%20xml-dev
List archives are available at http://xml.org/archives/xml-dev/
***************************************************************************




 

News | XML in Industry | Calendar | XML Registry
Marketplace | Resources | MyXML.org | Sponsors | Privacy Statement

Copyright 2001 XML.org. This site is hosted by OASIS