xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Selva <selvakumar_...@yahoo.co.in>
Subject Translation problem for group element
Date Tue, 11 Apr 2006 13:00:50 GMT
Hi All,

I have created <g> element with 2 rectangles. I tried to move the group 
element using translate. but it is not moving properly. Each time it is going 
to initial position, which had before moving the element. I have attached my 
sample code for your reference.
 
OnMouseDownAction 

DOMMouseEvent elEvt = (DOMMouseEvent)evt;
actionNode = elEvt.getTarget();
action = DRAG;
Node n = ((Element)elEvt.getTarget()).getParentNode();
startPt = localPt((Element)n, elEvt.getClientX(), elEvt.getClientY());
dragged = false;


OnMouseMoveAction  

if (action == DRAG) {
Element ee = (Element)((Element)actionNode).getParentNode();
   SVGPoint pt = localPt(ee, elEvt.getClientX(), elEvt.getClientY());
   float dx = pt.getX() - startPt.getX();
   float dy = pt.getY() - startPt.getY();
   ee.setAttribute("transform", "translate(" + dx + ", " + dy + ")");
}

private SVGPoint localPt(Element elem, int x, int y) {
   SVGDocument svgDocument = svgCanvas.getSVGDocument();
   SVGMatrix mat = ((SVGLocatable)elem).getScreenCTM();
   SVGMatrix imat = mat.inverse();
   SVGPoint cPt = svgDocument.getRootElement().createSVGPoint();
   cPt.setX(x);
   cPt.setY(y);
   cPt = cPt.matrixTransform(imat);
   return cPt;
}

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


Mime
View raw message