|
[XML-DEV Mailing List Archive Home] [By Thread] [By Date] [Recent Entries] [Reply To This Message] SVG: Retrieving mouse event co-ordinates in transformed co-ordinate spac
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@x...&BODY=unsubscribe%20xml-dev List archives are available at http://xml.org/archives/xml-dev/ ***************************************************************************
|
PURCHASE STYLUS STUDIO ONLINE TODAY!Purchasing Stylus Studio from our online shop is Easy, Secure and Value Priced! Download The World's Best XML IDE!Accelerate XML development with our award-winning XML IDE - Download a free trial today! Subscribe in XML format
|
|||||||||

Cart








