xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Selva <selvakumar_...@yahoo.co.in>
Subject move shapes in the Canvas
Date Mon, 10 Apr 2006 07:01:50 GMT
Hi All,

I am trying to move the rectangle element in JSVGcanvas. But it is not moving 
properly when i move the mouse faster. i have referred 
http://wiki.apache.org/xmlgraphics-batik/DragTutorial. But still i couldn't 
able to move the elements properly. 

This is code i used in mouse move handler.

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));
} else {

     float cW = Float.parseFloat(((Element)actionNode).getAttribute("width"));
     float cH = Float.parseFloat(((Element)actionNode).getAttribute("height"));
     float ar = cW / cH;
     float nW = nowToX - dx;
     float nH = nowToY - dy;
     if (nW / nH < ar) {
         nW = ar * nH; } else {
         nH = nW / ar; }
         ((Element)actionNode).setAttribute("width", "" + nW);
         ((Element)actionNode).setAttribute("height", "" + nH);
}

Please give the suggestions to handle this situation.

Thanks,
Selva


---------------------------------------------------------------------
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