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 "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil> on 2005/10/25 22:57:26 UTC

Weird problem using translations.

I sure hope I can describe this one without pictures.  I've started to
use the "translate" attribute to move elements around the JSVGCanvas.  I
have a DragStatus object that keeps track of what I'm dragging.  Here is
what my code is doing:

 

MouseDown:

            Set DragStatus.dragStatus to DRAG_DOWN.

Capture the Element I pressed the mouse on and save it as the
DragStatus.selectedElement.

Capture the coordinates of where the mouse was pressed and save it as
the DragStatus.dragDownPoint.

 

MouseMove:

            Capture the current DOMMouseEvent coordinates as an
SVGOMPoint and convert from screen coordinates.

            Run a MoveRunnable Runnable in the UpdateManager, sending
the SVGOMPoint and the DragStatus.selectedElement.

 

MoveRunnable(Element element, SVGOMPoint location):

            Create an instance of WhiteboardElement(element) which is
what I use to "wrap" elements.  Subclasses (RectangleElement,
EllipseElement, etc.) know how to generate color information,
transforms, etc. for the wrapped Element.

 

            Set the new "translate" piece of the "transform" attribute
as follows:

 

// Set the "new" translation coordinates as [current element translate
coordinates] + [current mouse coordinates] - [mouse coordinates of mouse
press].

float translateX = (whiteboardElement.getTranslateX().floatValue() +
location.getX() - DragStatus.getDragDownPoint().getX());

float translateY = (whiteboardElement.getTranslateY().floatValue() +
location.getY() - DragStatus.getDragDownPoint().getY());

 

// Set class variables for X and Y translations.

whiteboardElement.setTranslateX(new Double(translateX));

whiteboardElement.setTranslateY(new Double(translateY));

 

// Set the "transform" attribute of the actual Element (triggering the
change to the document I think.

whiteboardElement.addTransform();

 

All of this "sort of" works.  With slow mouse moving, you get kind of
jerky motion across the canvas.  Any sudden mouse movements cause the
element to "fly off" the canvas on its own.  It's especially apparent
with lines and polylines.  I *think* the trigger is moving the mouse far
enough to register a "mouse moved" event when the mouse is "off" the
element you're dragging.

 

Any suggestions?  Smoother motion would be nice; the element seems to
"wobble" when you move it, but stopping it from flying off the canvas
entirely would be very helpful.  I've been pulling my hair out for the
better part of the afternoon...:-)

 

Michael Bishop