Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » GEF » How can i set the initial zoom factor to the InfiniteCanvas?
How can i set the initial zoom factor to the InfiniteCanvas? [message #1795513] Mon, 24 September 2018 15:13 Go to next message
Frank Benoit is currently offline Frank BenoitFriend
Messages: 179
Registered: July 2009
Senior Member
Hello

i see i can set the scroll position with

InfiniteCanvas c = (InfiniteCanvas) viewer.getCanvas();
c.setVerticalScrollOffset(50);
c.setHorizontalScrollOffset(150);


For setting the zoom level, i tried to use setScaleX/Y but the behavior is then strange when resizing the window.

Is there an API for this?

BR
Frank
Re: How can i set the initial zoom factor to the InfiniteCanvas? [message #1802132 is a reply to message #1795513] Fri, 01 February 2019 17:27 Go to previous message
Matthias Wienand is currently offline Matthias WienandFriend
Messages: 230
Registered: March 2015
Senior Member
Hi Frank,

you can use the fitToSize() method and pass-in the absolute zoom level you want to achieve.

scaleX/Y are the default JavaFX properties. Therefore, the whole canvas is scaled using these properties.

Alternatively, you can manipulate the content transform to achieve the desired result. For this, I would recommend to get inspiration from fitToSize():

		// compute content center
		double cx = contentBounds.getMinX() + contentBounds.getWidth() / 2;
		double cy = contentBounds.getMinY() + contentBounds.getHeight() / 2;

		// compute visible area center
		double vx = getWidth() / 2;
		double vy = getHeight() / 2;

		// scroll to center position
		setHorizontalScrollOffset(getHorizontalScrollOffset() + vx - cx);
		setVerticalScrollOffset(getVerticalScrollOffset() + vy - cy);

		// compute pivot point for zoom within content coordinates
		Point2D pivot = getContentGroup().sceneToLocal(vx, vy);

		// restrict zoom factor to [zoomMin, zoomMax] range
		AffineTransform contentTransform = FX2Geometry
				.toAffineTransform(getContentTransform());
		double realZoomFactor = contentTransform.getScaleX() * zf;
		if (realZoomFactor > zoomMax) {
			zf = zoomMax / contentTransform.getScaleX();
		}
		if (realZoomFactor < zoomMin) {
			zf = zoomMin / contentTransform.getScaleX();
		}

		// compute scale transformation (around visible center)
		AffineTransform scaleTransform = new AffineTransform()
				.translate(pivot.getX(), pivot.getY()).scale(zf, zf)
				.translate(-pivot.getX(), -pivot.getY());

		// concatenate old transformation and scale transformation to yield the
		// new transformation
		AffineTransform newTransform = contentTransform
				.concatenate(scaleTransform);
		setContentTransform(Geometry2FX.toFXAffine(newTransform));

Permalink: https://github.com/eclipse/gef/blob/5135440577a6c3381e139591b3dd88dd79c43871/org.eclipse.gef.fx/src/org/eclipse/gef/fx/nodes/InfiniteCanvas.java#L728

Best regards,
Matthias
Previous Topic:Hover outline is having gap on right+bottom side
Next Topic:ViewportPolicy fitToSize method reloads css
Goto Forum:
  


Current Time: Fri Apr 19 20:17:14 GMT 2024

Powered by FUDForum. Page generated in 0.02945 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top