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/05/03 19:26:04 UTC

Zoom In/Zoom Out problem for glass pane

Hi All,

I have added glass pane in my SVGApplication to smoothen the mouse move
events. But while Zoom In/Zoom Out the SVGCanvas, it not zooming in/Zooming
out the glass pane to whole view port. So elements in SVGCanvas not able to
move in entire SVGCavas. So anybody please help me to resolve this problem.

My glass pane code snippet:
Element rect = _document.createElementNS(SVGGraphView.svgNS, "rect");
rect.setAttributeNS(null, "id", "bgrectangle");
rect.setAttributeNS(null, "x", "0");
rect.setAttributeNS(null, "y", "0");
rect.setAttributeNS(null, "width", "100%");
rect.setAttributeNS(null, "height", "100%");
rect.setAttributeNS(null, "pointer-events", "fill");
rect.setAttributeNS(null, "style", "fill:none;stroke:none");

Thanks,
Selva

--
View this message in context: http://www.nabble.com/Zoom-In-Zoom-Out-problem-for-glass-pane-t1551519.html#a4214771
Sent from the Batik - Users forum 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: Zoom In/Zoom Out problem for glass pane

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

news <ne...@sea.gmane.org> wrote on 05/05/2006 07:00:47 AM:

> >    What are you calling viewport?
> 
> The Area which is used to display SVG Elements. 

   This isn't sufficiently precise to be useful.  Please read
all or part of Chapter 7 of the SVG specification:

        http://www.w3.org/TR/SVG11/coords.html#Introduction

   Per that chapter the viewport === the visible area of
of the JSVGCanvas (Batik implements this). In this context
you have been asking that what is visible always be what
is visible - which is simple. 

   Obviously you want something different please explain 
using terminology/references to that chapter...

> <svg xmlns='http://www.w3.org/2000/svg' width="200px" height="400px" 
> version="1.1">


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


Re: Zoom In/Zoom Out problem for glass pane

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>    What are you calling viewport?

The Area which is used to display SVG Elements. 

<svg xmlns='http://www.w3.org/2000/svg' width="200px" height="400px" 
version="1.1">

Thanks,
Selva



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


Re: Zoom In/Zoom Out problem for glass pane

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

news <ne...@sea.gmane.org> wrote on 05/05/2006 06:44:20 AM:

> Actually my requirement is that viewport should cover entire SVGCanvas, 
> whenever user zoom in/zoom out.

   What are you calling viewport?


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


Re: Zoom In/Zoom Out problem for glass pane

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>    What you are requesting doesn't make any sense to me so I'm guessing
> that I don't understand what you really want.

Actually my requirement is that viewport should cover entire SVGCanvas, 
whenever user zoom in/zoom out. It should be independent to the position where 
it is clicked for zoom in/zoom out.

Thanks,
Selva



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


Re: Zoom In/Zoom Out problem for glass pane

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

news <ne...@sea.gmane.org> wrote on 05/04/2006 10:50:44 AM:

> >    Correct typically on zoom out the upper left of the canvas 
> > will be negative X/Y. 
> 
> In my case, When user zoom out the upper left corner or any place in 
view 
> port, my viewport's upper left corner must be equal to SVGCanvas's upper 
left 
> corner. Is there anyway to do like this?

   What you are requesting doesn't make any sense to me so I'm guessing
that I don't understand what you really want.

> >    You can change the viewBox on the root SVG element if you want but
> > this is a _very_ expensive operation as we rebuild the entire graphics
> > tree when the width/height of this changes so that element's using '%' 

> > units are sized correctly...
> 
> Since glass pane is within the viewport, setting the X, Y, width and 
height 
> values in "%" not affecting viewport's position. 

    Sure but what you wanted was a way to cover the viewport with the
glass pane, using % can help with this.

> So can you please specify how to set the viewport's x, y, height and 
width in "%"?

   You can't set the viewport in % since the viewport defines the meaning 
of
percentages.


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


Re: Zoom In/Zoom Out problem for glass pane

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>    Correct typically on zoom out the upper left of the canvas 
> will be negative X/Y.  

In my case, When user zoom out the upper left corner or any place in view 
port, my viewport's upper left corner must be equal to SVGCanvas's upper left 
corner. Is there anyway to do like this?

>    You can change the viewBox on the root SVG element if you want but
> this is a _very_ expensive operation as we rebuild the entire graphics
> tree when the width/height of this changes so that element's using '%' 
> units are sized correctly...

Since glass pane is within the viewport, setting the X, Y, width and height 
values in "%" not affecting viewport's position. So can you please specify how 
to set the viewport's x, y, height and width in "%"?

Thanks,
Selva


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


Re: Zoom In/Zoom Out problem for glass pane

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

news <ne...@sea.gmane.org> wrote on 05/04/2006 02:59:27 AM:

> > I added a component listener to the JSVGCanvas to catch resize events
> > so I can adjust the background to exactly fill the window.   You can
> > probably use the same code to adjust your transparent glass pane:
> 
> I have added your code in UpdateManagerListener's updateCompleted(). 
Because i 
> should resize the glass pane while doing zoom in/zoom out. But doing 
zoom in 
> glass pane resized properly. But in zoom out, viewport is not in left 
corner 
> of the SVGCanvas, it means Xmin and Ymin value is not (0,0).

   Correct typically on zoom out the upper left of the canvas 
will be negative X/Y.  Some of the stuff in Roger's code to
calculate the view port looks a little off to me.  First I would
have used the rectangle returned by canvas.getRenderRect().  IIRC
there are some problems with getVisibleRect().

   Second the code uses:
        final float width = (float)coords[6];
        final float height = (float)coords[7];

   I think this should be:
        final float width  = (float)(coords[6]-coords[4]);
        final float height = (float)(coords[7]-coords[5]);


   Finally for a glass pane it more or less doesn't 'cost' you
anything to make it _huge_ so often I'll just set it's bounds ridiculously
large and not worry about it:
        <rext visibility="hidden" pointer-events="fill" fill="none"
              x="-1000%" y="-1000%" width="3000%" height="3000%"/>

   Heck use 10,000% if you want (comma included for readability you can't 
do
that in the real attribute).

> it's coming center of the SVGCanvas. Can you please explain why it is 
> happening like this?
> 
> also is it possible to change the ViewPort's size and position 
dynamically?

   You can change the viewBox on the root SVG element if you want but
this is a _very_ expensive operation as we rebuild the entire graphics
tree when the width/height of this changes so that element's using '%' 
units are sized correctly...


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


Re: Zoom In/Zoom Out problem for glass pane

Posted by Selva <se...@yahoo.co.in>.
Hi Roger,

> I added a component listener to the JSVGCanvas to catch resize events
> so I can adjust the background to exactly fill the window.   You can
> probably use the same code to adjust your transparent glass pane:

I have added your code in UpdateManagerListener's updateCompleted(). Because i 
should resize the glass pane while doing zoom in/zoom out. But doing zoom in 
glass pane resized properly. But in zoom out, viewport is not in left corner 
of the SVGCanvas, it means Xmin and Ymin value is not (0,0). it's coming 
center of the SVGCanvas. Can you please explain why it is happening like this?

also is it possible to change the ViewPort's size and position dynamically?

Thanks,
Selva


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


Re: Zoom In/Zoom Out problem for glass pane

Posted by Roger Critchlow <re...@elf.org>.
Hi Selva --

I did the opposite, I put a background rectangle into the document and
run the mouse move handler off that.

I added a component listener to the JSVGCanvas to catch resize events
so I can adjust the background to exactly fill the window.   You can
probably use the same code to adjust your transparent glass pane:

        svgCanvas.addComponentListener(new ComponentAdapter() {
        	public void componentResized(ComponentEvent e) {
	       		if (svgDoc != null) {
        			final SVGRectElement bkgd =
(SVGRectElement)getElementById("background");
    				final GraphViewport view = getViewport();
        			if (bkgd != null && view != null) {
        				runInUpdateThread(new Runnable() {
        					public void run() {
        						bkgd.setAttributeNS(null, "x", Float.toString(view.getOriginX()));
        						bkgd.setAttributeNS(null, "y", Float.toString(view.getOriginY()));
        						bkgd.setAttributeNS(null, "width",
Float.toString(view.getWidth()));
        						bkgd.setAttributeNS(null, "height",
Float.toString(view.getHeight()));
        					}
        				});
        			}
        		}
        	}
        });

I compute the viewport like this:

	public GraphViewport getViewport() {
		// take the viewing transform, invert and apply to the screen rectangle,
		// this should be the screen rectangle in the SVG coordinates.
		final Rectangle2D r = svgCanvas.getVisibleRect();
		try {
			AffineTransform v = svgCanvas.getViewingTransform().createInverse();
			double coords[] = { r.getX(), r.getY(), r.getX()+r.getWidth(),
r.getY()+r.getHeight(),
					0, 0, 0, 0 };
			v.inverseTransform(coords, 0, coords, 4, 4);
			final float x = (float)coords[4];
			final float y = (float)coords[5];
			final float width = (float)coords[6];
			final float height = (float)coords[7];
			// System.err.println("viewport: "+x+", "+y+", "+width+", "+height);
			return new GraphViewport() {
				public float getOriginX() { return x; }
				public float getOriginY() { return y; }
				public float getWidth() { return width; }
				public float getHeight() { return height; }
			};
		} catch(Exception e) {
			return new GraphViewport() {
				public float getOriginX() { return (float)r.getX(); }
				public float getOriginY() { return (float)r.getY(); }
				public float getWidth() { return (float)r.getWidth(); }
				public float getHeight() { return (float)r.getHeight(); }
			};
		}
	}

-- rec --

On 5/3/06, Selva <se...@yahoo.co.in> wrote:
>
> Hi All,
>
> I have added glass pane in my SVGApplication to smoothen the mouse move
> events. But while Zoom In/Zoom Out the SVGCanvas, it not zooming in/Zooming
> out the glass pane to whole view port. So elements in SVGCanvas not able to
> move in entire SVGCavas. So anybody please help me to resolve this problem.
>
> My glass pane code snippet:
> Element rect = _document.createElementNS(SVGGraphView.svgNS, "rect");
> rect.setAttributeNS(null, "id", "bgrectangle");
> rect.setAttributeNS(null, "x", "0");
> rect.setAttributeNS(null, "y", "0");
> rect.setAttributeNS(null, "width", "100%");
> rect.setAttributeNS(null, "height", "100%");
> rect.setAttributeNS(null, "pointer-events", "fill");
> rect.setAttributeNS(null, "style", "fill:none;stroke:none");
>
> Thanks,
> Selva
>
> --
> View this message in context: http://www.nabble.com/Zoom-In-Zoom-Out-problem-for-glass-pane-t1551519.html#a4214771
> Sent from the Batik - Users forum at Nabble.com.
>
>
> ---------------------------------------------------------------------
> 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