package me.hammerle.snuviengine.api; public class FixedWindowView implements WindowView { private final int width; private final int height; private final int fontScale; public FixedWindowView(int width, int height, int fontScale) { this.width = width; this.height = height; this.fontScale = fontScale; } @Override public int getScale(int width, int height) { return Math.max(width / this.width, 1); } @Override public int getFontScale(int width, int height) { return fontScale; } @Override public int getWidth(int newWidth, int newHeight) { return Math.max(getMaxScale(newWidth, newHeight) * width, width); } @Override public int getHeight(int newWidth, int newHeight) { return Math.max(getMaxScale(newWidth, newHeight) * height, height); } private int getMaxScale(int newWidth, int newHeight) { return Math.max(getNearestScale(newWidth, width), getNearestScale(newHeight, height)); } private int getNearestScale(int value, int multiple) { float scale = (float) value / multiple; int roundedScale = (int) scale; if(scale == roundedScale) { return roundedScale; } float diff = scale - roundedScale; roundedScale += diff < 0.5f ? 1 : 0; return roundedScale; } }