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 15:00:50 UTC
Translation problem for group element
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
Re: Translation problem for group element
Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,
Now it's working fine. Thanks for your immediate response.
Thanks,
Selva
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Translation problem for group element
Posted by th...@kodak.com.
Hi Selva,
news <ne...@sea.gmane.org> wrote on 04/11/2006 09:00:50 AM:
> 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.
That is because your localPt function includes the transform you just
set. You need to pass ee's parent because that is really the coordinate
system
you are moving in (by adjusting the transform on the group).
> if (action == DRAG) {
> Element ee = (Element)((Element)actionNode).getParentNode();
> SVGPoint pt = localPt(ee, elEvt.getClientX(), elEvt.getClientY());
Change this line to:
SVGPoint pt = localPt((Element)(ee.getParenNode()),
elEvt.getClientX(), elEvt.getClientY());
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org