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 aKIv <me...@gmx.net> on 2010/07/16 11:32:28 UTC

getBBox problem with SVGElements

I have got a problem in case of using the method getBBox. For Example my SVG
Document have got two circle elements. Now i am trying to get the element
from the canvas on click. The problem here is, that i only can click on the
lastChild of my circle element. Also the program is now assigning all circle
elements. 

the part of the program: 

	if (n instanceof SVGCircleElement) {
			SVGCircleElement svgElement = (SVGCircleElement) n;

			if (e.getPoint().x >= svgElement.getBBox().getX()
					&& e.getPoint().x <= (svgElement.getBBox().getX() + svgElement
							.getBBox().getWidth())
					&& e.getPoint().y >= svgElement.getBBox().getY()
					&& e.getPoint().y <= (svgElement.getBBox().getY() + svgElement
							.getBBox().getHeight())) {
				System.out.println("circle");
				svgElement.setAttribute("fill", "red");

			} else {
				svgElement.removeAttribute("fill");
			}

-- 
View this message in context: http://old.nabble.com/getBBox-problem-with-SVGElements-tp29181765p29181765.html
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: getBBox problem with SVGElements

Posted by aKIv <me...@gmx.net>.
at first thank you for your answer... 
you have to know, that i go recursive in a for loop through the elements. so
that means, i response all elements. 
-- 
View this message in context: http://old.nabble.com/getBBox-problem-with-SVGElements-tp29181765p29182481.html
Sent from the Batik - Users mailing list archive at Nabble.com.


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


Re: getBBox problem with SVGElements

Posted by th...@kodak.com.
Hi aKIv,

aKIv <me...@gmx.net> wrote on 07/16/2010 05:32:28 AM:

> I have got a problem in case of using the method getBBox. For Example my 
SVG
> Document have got two circle elements. Now i am trying to get the 
element
> from the canvas on click. The problem here is, that i only can click on 
the
> lastChild of my circle element. Also the program is now assigning all 
circle
> elements. 

    I'm fairly certain that this is a problem with coordinate systems.

        e.getPoint is the click location in a screen coordinate system.
svgElement.getBBox() is the bounding box in the local coordinate system
of 'svgElement'.  In your document I'm guessing that for the 'last child'
the screen and local coordinate system happen to be the same, and since
you aren't accounting for the transform on your other circle elements they
all thing they were clicked when the last child is clicked.

        What you need to do is transform the event point by the inverse of 

the getScreenCTM affine transform you get from each of your circle 
elements.