I'm using this snippet from
http://xmlgraphics.apache.org/batik/javaScripting.html to transform
the client coordinates from the mouse event into the svg coordinates.
Until I did this, my mouse tended to move further than the rectangle
was being dragged, now they track each other just fine.
SVGMatrix mat = elem.getScreenCTM();
SVGMatrix imat = mat.inverse();
SVGPoint cPt = document.getRootElement().createSVGPoint();
cPt.setX(uiEvt.clientX);
cPt.setY(uiEvt.clientY);
cPt = cPt.matrixTransform(imat);
I made a few changes: I use the getScreenCTM from the root element of
the document and I call getClientX() and getClientY() on the event.
So, do this and then use cPt.getX() and cPt.getY() to update the
dragged rectangle x and y attributes.
-- rec --
On 4/10/06, Selva <[EMAIL PROTECTED]> wrote:
> Hi All,
>
> I am trying to drag the Rectangle in SVGCanvas. If I do it slowly, it is
> working smoothly. But in case of faster dragging, it is not moving properly. I
> have also referred http://wiki.apache.org/xmlgraphics-batik/DragTutorial for
> mouse dragging. But it is not working. I have attached my sample code for your
> reference.
>
> private class OnMoveAction implements EventListener {
> public void handleEvent(Event evt) {
>
> if (actionNode == null)return;
> dragged = true;
> DOMMouseEvent elEvt = (DOMMouseEvent)evt;
>
> int nowToX = elEvt.getClientX();
> int nowToY = elEvt.getClientY();
> SVGDocument svgDocument = svgCanvas.getSVGDocument();
> SVGPoint trans = svgDocument.getRootElement().getCurrentTranslate();
> float scale = svgDocument.getRootElement().getCurrentScale();
> nowToX = (int)((nowToX - trans.getX()) / scale);
> nowToY = (int)((nowToY - trans.getY()) / scale);
> if (action == DRAG) {
> ((Element)actionNode).setAttribute("x", "" + (nowToX - dx));
> ((Element)actionNode).setAttribute("y", "" + (nowToY - dy));
> }
> }
>
>
> Please give me the better solution for dragging the SVG elements in SVGCanvas.
>
> Thanks,
> Selva
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]