diff --git a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java index 3fab999..86b9b53 100644 --- a/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java +++ b/Semesterprojekt/src/main/java/thb/jeanluc/adventure/io/SwingIO.java @@ -120,6 +120,7 @@ public class SwingIO implements GameIO { @Override public void componentResized(ComponentEvent e) { updateSideWidth(); + applyFonts(); } }); @@ -178,10 +179,21 @@ public class SwingIO implements GameIO { map.repaint(); } - /** Re-derives and applies all component fonts from the current scale and zoom. */ + /** + * Auto-scale derived from the window size relative to the design size + * (900x600). At the initial size this equals {@link #uiScale}; growing the + * window grows the text, mirroring how the map fits its panel. + */ + private float frameScale() { + double s = Math.min(frame.getWidth() / 900.0, frame.getHeight() / 600.0); + return (float) Math.max(0.6, Math.min(2.6, s)); + } + + /** Re-derives and applies all component fonts from the window auto-scale and zoom. */ private void applyFonts() { - float main = BASE_SIZE * uiScale * zoom; - float small = SMALL_SIZE * uiScale * zoom; + float auto = frameScale(); + float main = BASE_SIZE * auto * zoom; + float small = SMALL_SIZE * auto * zoom; output.setFont(baseFont.deriveFont(main)); input.setFont(baseFont.deriveFont(main)); hud.setFont(baseFont.deriveFont(small));