@Test public void testToScreenCoordinates() { viewport.onResize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT); final Vector2 coordinates = new Vector2(); coordinates.set(1f, 1f); viewport.toScreenCoordinates(coordinates); Assert.assertEquals(1f, coordinates.x, 0.001f); Assert.assertEquals(1f, coordinates.y, 0.001f); viewport.onResize(MathUtils.round(VIEWPORT_WIDTH * 1.5f), MathUtils.round(VIEWPORT_HEIGHT * 1.5f)); coordinates.set(1f, 1f); viewport.toScreenCoordinates(coordinates); Assert.assertEquals(1.5f, coordinates.x, 0.001f); Assert.assertEquals(1.5f, coordinates.y, 0.001f); viewport.onResize(VIEWPORT_WIDTH * 2, VIEWPORT_HEIGHT * 2); coordinates.set(1f, 1f); viewport.toScreenCoordinates(coordinates); Assert.assertEquals(2f, coordinates.x, 0.001f); Assert.assertEquals(2f, coordinates.y, 0.001f); viewport.onResize(VIEWPORT_WIDTH * 2, VIEWPORT_HEIGHT); coordinates.set(1f, 1f); viewport.toScreenCoordinates(coordinates); Assert.assertEquals(1f, coordinates.x, 0.001f); Assert.assertEquals(1f, coordinates.y, 0.001f); viewport.onResize(VIEWPORT_WIDTH, VIEWPORT_HEIGHT * 2); coordinates.set(1f, 1f); viewport.toScreenCoordinates(coordinates); Assert.assertEquals(1f, coordinates.x, 0.001f); Assert.assertEquals(1f, coordinates.y, 0.001f); }
@Override public void onResize(int width, int height) { float worldWidth = minWorldWidth; float worldHeight = minWorldHeight; Scaling.FIT.apply(size, scale, powerOfTwo, worldWidth, worldHeight, width, height); int viewportWidth = Math.round(size.x); int viewportHeight = Math.round(size.y); if (viewportWidth < width) { float toViewportSpace = viewportHeight / worldHeight; float toWorldSpace = worldHeight / viewportHeight; float lengthen = (width - viewportWidth) * toWorldSpace; if (maxWorldWidth > 0) lengthen = Math.min(lengthen, maxWorldWidth - minWorldWidth); worldWidth += lengthen; viewportWidth += Math.round(lengthen * toViewportSpace); } if (viewportHeight < height) { float toViewportSpace = viewportWidth / worldWidth; float toWorldSpace = worldWidth / viewportWidth; float lengthen = (height - viewportHeight) * toWorldSpace; if (maxWorldHeight > 0) lengthen = Math.min(lengthen, maxWorldHeight - minWorldHeight); worldHeight += lengthen; viewportHeight += Math.round(lengthen * toViewportSpace); } setBounds((width - viewportWidth) / MathUtils.round(2 * scale.x), (height - viewportHeight) / MathUtils.round(2 * scale.y), MathUtils.round(worldWidth), MathUtils.round(worldHeight), scale.x, scale.y); }
ExtendViewport extends Viewport { @Override public void onResize(int width, int height) { float worldWidth = minWorldWidth; float worldHeight = minWorldHeight; Scaling.FIT.apply(size, scale, powerOfTwo, worldWidth, worldHeight, width, height); int viewportWidth = Math.round(size.x); int viewportHeight = Math.round(size.y); if (viewportWidth < width) { float toViewportSpace = viewportHeight / worldHeight; float toWorldSpace = worldHeight / viewportHeight; float lengthen = (width - viewportWidth) * toWorldSpace; if (maxWorldWidth > 0) lengthen = Math.min(lengthen, maxWorldWidth - minWorldWidth); worldWidth += lengthen; viewportWidth += Math.round(lengthen * toViewportSpace); } if (viewportHeight < height) { float toViewportSpace = viewportWidth / worldWidth; float toWorldSpace = worldWidth / viewportWidth; float lengthen = (height - viewportHeight) * toWorldSpace; if (maxWorldHeight > 0) lengthen = Math.min(lengthen, maxWorldHeight - minWorldHeight); worldHeight += lengthen; viewportHeight += Math.round(lengthen * toViewportSpace); } setBounds((width - viewportWidth) / MathUtils.round(2 * scale.x), (height - viewportHeight) / MathUtils.round(2 * scale.y), MathUtils.round(worldWidth), MathUtils.round(worldHeight), scale.x, scale.y); } }
ExtendViewport extends Viewport { @Override public void onResize(int width, int height) { float worldWidth = minWorldWidth; float worldHeight = minWorldHeight; Scaling.FIT.apply(size, scale, powerOfTwo, worldWidth, worldHeight, width, height); int viewportWidth = Math.round(size.x); int viewportHeight = Math.round(size.y); if (viewportWidth < width) { float toViewportSpace = viewportHeight / worldHeight; float toWorldSpace = worldHeight / viewportHeight; float lengthen = (width - viewportWidth) * toWorldSpace; if (maxWorldWidth > 0) lengthen = Math.min(lengthen, maxWorldWidth - minWorldWidth); worldWidth += lengthen; viewportWidth += Math.round(lengthen * toViewportSpace); } if (viewportHeight < height) { float toViewportSpace = viewportWidth / worldWidth; float toWorldSpace = worldWidth / viewportWidth; float lengthen = (height - viewportHeight) * toWorldSpace; if (maxWorldHeight > 0) lengthen = Math.min(lengthen, maxWorldHeight - minWorldHeight); worldHeight += lengthen; viewportHeight += Math.round(lengthen * toViewportSpace); } setBounds((width - viewportWidth) / MathUtils.round(2 * scale.x), (height - viewportHeight) / MathUtils.round(2 * scale.y), MathUtils.round(worldWidth), MathUtils.round(worldHeight), scale.x, scale.y); } ExtendViewport(float minWorldWidth, float minWorldHeight);  ExtendViewport(float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight);  ExtendViewport(boolean powerOfTwo, float minWorldWidth, float minWorldHeight);  ExtendViewport(boolean powerOfTwo, float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight); }
ExtendViewport extends Viewport { @Override public void onResize(int width, int height) { float worldWidth = minWorldWidth; float worldHeight = minWorldHeight; Scaling.FIT.apply(size, scale, powerOfTwo, worldWidth, worldHeight, width, height); int viewportWidth = Math.round(size.x); int viewportHeight = Math.round(size.y); if (viewportWidth < width) { float toViewportSpace = viewportHeight / worldHeight; float toWorldSpace = worldHeight / viewportHeight; float lengthen = (width - viewportWidth) * toWorldSpace; if (maxWorldWidth > 0) lengthen = Math.min(lengthen, maxWorldWidth - minWorldWidth); worldWidth += lengthen; viewportWidth += Math.round(lengthen * toViewportSpace); } if (viewportHeight < height) { float toViewportSpace = viewportWidth / worldWidth; float toWorldSpace = worldWidth / viewportWidth; float lengthen = (height - viewportHeight) * toWorldSpace; if (maxWorldHeight > 0) lengthen = Math.min(lengthen, maxWorldHeight - minWorldHeight); worldHeight += lengthen; viewportHeight += Math.round(lengthen * toViewportSpace); } setBounds((width - viewportWidth) / MathUtils.round(2 * scale.x), (height - viewportHeight) / MathUtils.round(2 * scale.y), MathUtils.round(worldWidth), MathUtils.round(worldHeight), scale.x, scale.y); } ExtendViewport(float minWorldWidth, float minWorldHeight);  ExtendViewport(float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight);  ExtendViewport(boolean powerOfTwo, float minWorldWidth, float minWorldHeight);  ExtendViewport(boolean powerOfTwo, float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight); @Override void onResize(int width, int height); float getMinWorldWidth(); void setMinWorldWidth(float minWorldWidth); float getMinWorldHeight(); void setMinWorldHeight(float minWorldHeight); float getMaxWorldWidth(); void setMaxWorldWidth(float maxWorldWidth); float getMaxWorldHeight(); void setMaxWorldHeight(float maxWorldHeight); boolean isPowerOfTwo(); void setPowerOfTwo(boolean powerOfTwo); }
ExtendViewport extends Viewport { @Override public void onResize(int width, int height) { float worldWidth = minWorldWidth; float worldHeight = minWorldHeight; Scaling.FIT.apply(size, scale, powerOfTwo, worldWidth, worldHeight, width, height); int viewportWidth = Math.round(size.x); int viewportHeight = Math.round(size.y); if (viewportWidth < width) { float toViewportSpace = viewportHeight / worldHeight; float toWorldSpace = worldHeight / viewportHeight; float lengthen = (width - viewportWidth) * toWorldSpace; if (maxWorldWidth > 0) lengthen = Math.min(lengthen, maxWorldWidth - minWorldWidth); worldWidth += lengthen; viewportWidth += Math.round(lengthen * toViewportSpace); } if (viewportHeight < height) { float toViewportSpace = viewportWidth / worldWidth; float toWorldSpace = worldWidth / viewportWidth; float lengthen = (height - viewportHeight) * toWorldSpace; if (maxWorldHeight > 0) lengthen = Math.min(lengthen, maxWorldHeight - minWorldHeight); worldHeight += lengthen; viewportHeight += Math.round(lengthen * toViewportSpace); } setBounds((width - viewportWidth) / MathUtils.round(2 * scale.x), (height - viewportHeight) / MathUtils.round(2 * scale.y), MathUtils.round(worldWidth), MathUtils.round(worldHeight), scale.x, scale.y); } ExtendViewport(float minWorldWidth, float minWorldHeight);  ExtendViewport(float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight);  ExtendViewport(boolean powerOfTwo, float minWorldWidth, float minWorldHeight);  ExtendViewport(boolean powerOfTwo, float minWorldWidth, float minWorldHeight, float maxWorldWidth, float maxWorldHeight); @Override void onResize(int width, int height); float getMinWorldWidth(); void setMinWorldWidth(float minWorldWidth); float getMinWorldHeight(); void setMinWorldHeight(float minWorldHeight); float getMaxWorldWidth(); void setMaxWorldWidth(float maxWorldWidth); float getMaxWorldHeight(); void setMaxWorldHeight(float maxWorldHeight); boolean isPowerOfTwo(); void setPowerOfTwo(boolean powerOfTwo);  }