fix(io): auto-scale GUI text with window size, consistent with the map
Body text/HUD font now derives from a window-relative auto-scale (starting at uiScale, growing as the window grows) and is re-applied on resize, so the text tracks the window like the map does. Ctrl +/- zoom still multiplies on top of both. Removes the resize hiccup where only the map reacted. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user