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 Selva <se...@yahoo.co.in> on 2006/04/11 06:29:32 UTC
Mouse drag not working smoothly for Rectangle
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
Re: Mouse drag not working smoothly for Rectangle
Posted by Roger Critchlow <re...@elf.org>.
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 <se...@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
Re: Mouse drag not working smoothly for Rectangle
Posted by Tonny Kohar <to...@kiyut.com>.
Hi,
On Tue, 2006-04-11 at 04:29 +0000, Selva 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.
For performance reason, you may be want to update the svg element only
at the end of dragging, so svg only updated only one time. And you could
draw outline / rect during dragging / moving operation.
Regards
Tonny Kohar
--
Sketsa
SVG Graphics Editor
http://www.kiyut.com
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org