From af50267fd73925d00ac6cfb0370083c72e71412f Mon Sep 17 00:00:00 2001 From: Nao Pross Date: Sat, 24 Nov 2018 17:12:53 +0100 Subject: Update MapScene size members on window resize --- src/subconscious/graphics/MapScene.java | 14 ++++++++++++++ src/subconscious/graphics/Scene.java | 2 +- 2 files changed, 15 insertions(+), 1 deletion(-) (limited to 'src') diff --git a/src/subconscious/graphics/MapScene.java b/src/subconscious/graphics/MapScene.java index e17a933..149d03d 100644 --- a/src/subconscious/graphics/MapScene.java +++ b/src/subconscious/graphics/MapScene.java @@ -9,6 +9,7 @@ import java.awt.Canvas; import java.awt.Point; import java.awt.Graphics2D; import java.awt.BasicStroke; +import java.awt.Dimension; import java.awt.event.KeyEvent; import java.awt.event.MouseEvent; @@ -222,6 +223,19 @@ public abstract class MapScene extends Scene { g.transform(this.undoZoomTx); } + @Override + public synchronized void updateCanvasSize(Dimension newSize) { + super.updateCanvasSize(newSize); + + if (this.canvasSize.width < this.canvasSize.height) { + this.shorterCanvasLenght = this.canvasSize.width; + } else { + this.shorterCanvasLenght = this.canvasSize.height; + } + + this.tileSize = this.shorterCanvasLenght / 10; + } + @Override public void keyPressed(KeyEvent e) { super.keyPressed(e); diff --git a/src/subconscious/graphics/Scene.java b/src/subconscious/graphics/Scene.java index cfbdc87..a6ac018 100644 --- a/src/subconscious/graphics/Scene.java +++ b/src/subconscious/graphics/Scene.java @@ -251,7 +251,7 @@ public abstract class Scene extends JPanel // WARNING: does not always work // TODO: why doesn't this always work? public synchronized void updateCanvasSize() { - this.canvasSize = this.getParent().getParent().getSize(); + this.updateCanvasSize(this.getParent().getSize()); } // this one always works -- cgit v1.2.1