xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Roger Critchlow" <...@elf.org>
Subject Re: Mouse drag not working smoothly for Rectangle
Date Tue, 11 Apr 2006 05:50:15 GMT
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 <selvakumar_k79@yahoo.co.in> 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: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>

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


Mime
View raw message