zoomGroup.getChildren().add(content); setContent(contentGroup); scaleTransform = new Scale(scaleValue, scaleValue, 0, 0); zoomGroup.getTransforms().add(scaleTransform);
/** * Creates a {@link Canvas} with the specified display unit size. */ public Canvas createCanvas (float width, float height) { return createCanvasImpl(scale, scale.scaledCeil(width), scale.scaledCeil(height)); }
@Override public void initialize(URL location, ResourceBundle resources) { anchorpane.setOnScroll(event -> { double zoom_fac = 1.05; if(delta_y < 0) { zoom_fac = 2.0 - zoom_fac; } Scale newScale = new Scale(); newScale.setPivotX(event.getX); newScale.setPivotY(event.getY); newScale.setX( content_group.getScaleX() * zoom_fac ); newScale.setY( content_group.getScaleY() * zoom_fac ); content_group.getTransforms().add(newScale); event.consume(); }); }
/** * Sizes or resizes the root element that contains the game view. This is specified in pixels as * understood by page elements. If the page is actually being dispalyed on a HiDPI (Retina) * device, the actual framebuffer may be 2x (or larger) the specified size. */ public void setSize (int width, int height) { rootElement.getStyle().setWidth(width, Unit.PX); rootElement.getStyle().setHeight(height, Unit.PX); // the frame buffer may be larger (or smaller) than the logical size, depending on whether // we're on a HiDPI display, or how the game has configured things (maybe they're scaling down // from native resolution to improve performance) Scale fbScale = new Scale(frameBufferPixelRatio); canvas.setWidth(fbScale.scaledCeil(width)); canvas.setHeight(fbScale.scaledCeil(height)); // set the canvas's CSS size to the logical size; the browser works in logical pixels canvas.getStyle().setWidth(width, Style.Unit.PX); canvas.getStyle().setHeight(height, Style.Unit.PX); viewportChanged(canvas.getWidth(), canvas.getHeight()); }
/** * Returns an ordered series of scaled resources to try when loading an asset. The highest * (presumably native) resolution will be tried first, then that will be stepped down to all * whole integers less than the native resolution. Often this is simply {@code 2, 1}, but on a * Retina iPad, it could be {@code 4, 3, 2, 1}, and on Android devices it may often be something * like {@code 3, 2, 1} or {@code 2.5, 2, 1}. */ public List<ScaledResource> getScaledResources(String path) { List<ScaledResource> rsrcs = new ArrayList<ScaledResource>(); rsrcs.add(new ScaledResource(this, computePath(path, factor))); for (float rscale = MathUtil.ifloor(factor); rscale > 1; rscale -= 1) { if (rscale != factor) rsrcs.add( new ScaledResource(new Scale(rscale), computePath(path, rscale))); } rsrcs.add(new ScaledResource(ONE, path)); return rsrcs; }
public void start(Stage primaryStage) { Pane pane = new Pane(); Scale scale = new Scale(); scale.setX(1); scale.setY(-1); scale.pivotYProperty().bind(Bindings.createDoubleBinding(() -> pane.getBoundsInLocal().getMinY() + pane.getBoundsInLocal().getHeight() /2, pane.boundsInLocalProperty()));
@Override public Image getImage (String path) { Scale assetScale = (this.assetScale == null) ? Scale.ONE : this.assetScale; List<Scale.ScaledResource> rsrcs = assetScale.getScaledResources(path); return getImage(rsrcs.get(0).path, rsrcs.get(0).scale); }
/** * Informs the graphics system that the main framebuffer size has changed. The supplied size * should be in physical pixels. */ protected void viewportChanged (int pixelWidth, int pixelHeight) { viewPixelWidth = pixelWidth; viewPixelHeight = pixelHeight; viewSizeM.width = scale.invScaled(pixelWidth); viewSizeM.height = scale.invScaled(pixelHeight); plat.log().info("viewPortChanged " + pixelWidth + "x" + pixelHeight + " / " + scale.factor + " -> " + viewSize); }
/** Returns the supplied length scaled by our scale factor and rounded up. */ public int scaledCeil(float length) { return MathUtil.iceil(scaled(length)); }
/** * Sizes or resizes the root element that contains the game view. This is specified in pixels as * understood by page elements. If the page is actually being dispalyed on a HiDPI (Retina) * device, the actual framebuffer may be 2x (or larger) the specified size. */ public void setSize (int width, int height) { rootElement.getStyle().setWidth(width, Unit.PX); rootElement.getStyle().setHeight(height, Unit.PX); // the frame buffer may be larger (or smaller) than the logical size, depending on whether // we're on a HiDPI display, or how the game has configured things (maybe they're scaling down // from native resolution to improve performance) Scale fbScale = new Scale(frameBufferPixelRatio); canvas.setWidth(fbScale.scaledCeil(width)); canvas.setHeight(fbScale.scaledCeil(height)); // set the canvas's CSS size to the logical size; the browser works in logical pixels canvas.getStyle().setWidth(width, Style.Unit.PX); canvas.getStyle().setHeight(height, Style.Unit.PX); viewportChanged(canvas.getWidth(), canvas.getHeight()); }
/** * Returns an ordered series of scaled resources to try when loading an asset. The native * resolution will be tried first, then that will be rounded up to the nearest whole integer and * stepped down through all whole integers to {@code 1}. If the native scale factor is {@code 2}, * this will yield {@code 2, 1}. If the native scale factor is {@code 4}, this will yield * {@code 4, 3, 2, 1}. Android devices often have fractional scale factors, which demonstrates * the rounding up then back down approach: a native scale factor of {@code 2.5} would yield * {@code 2.5, 3, 2, 1}. */ public List<ScaledResource> getScaledResources(String path) { List<ScaledResource> rsrcs = new ArrayList<ScaledResource>(); rsrcs.add(new ScaledResource(this, computePath(path, factor))); for (float rscale = MathUtil.iceil(factor); rscale > 1; rscale -= 1) { if (rscale != factor) rsrcs.add( new ScaledResource(new Scale(rscale), computePath(path, rscale))); } rsrcs.add(new ScaledResource(ONE, path)); return rsrcs; }
@Override public Image getImage (String path) { Scale assetScale = (this.assetScale == null) ? Scale.ONE : this.assetScale; List<Scale.ScaledResource> rsrcs = assetScale.getScaledResources(path); return getImage(rsrcs.get(0).path, rsrcs.get(0).scale); }
/** * Informs the graphics system that the main framebuffer size has changed. The supplied size * should be in physical pixels. */ protected void viewportChanged (int pixelWidth, int pixelHeight) { viewPixelWidth = pixelWidth; viewPixelHeight = pixelHeight; viewSizeM.width = scale.invScaled(pixelWidth); viewSizeM.height = scale.invScaled(pixelHeight); plat.log().info("viewPortChanged " + pixelWidth + "x" + pixelHeight + " / " + scale.factor + " -> " + viewSize); }
/** Returns the supplied length scaled by our scale factor and rounded down. */ public int scaledFloor(float length) { return MathUtil.ifloor(scaled(length)); }
/** * Configures the default scale to use for assets. This allows one to specify an intermediate * graphics scale (like 1.5) and scale the 2x imagery down to 1.5x instead of scaling the 1.5x * imagery up (or displaying nothing at all). */ public void setAssetScale(float scaleFactor) { this.assetScale = new Scale(scaleFactor); }
/** * Creates a {@link Canvas} with the specified display unit size. */ public Canvas createCanvas (float width, float height) { return createCanvasImpl(scale, scale.scaledCeil(width), scale.scaledCeil(height)); }