summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorNao Pross <naopross@thearcway.org>2018-11-24 17:12:53 +0100
committerNao Pross <naopross@thearcway.org>2018-11-24 17:12:53 +0100
commitaf50267fd73925d00ac6cfb0370083c72e71412f (patch)
tree6bd8e3dda8f826f52356f8111d9ac678bca60678 /src
parentAdd simple widget.Clickable interface with example Button (diff)
downloadSubconscious-java-af50267fd73925d00ac6cfb0370083c72e71412f.tar.gz
Subconscious-java-af50267fd73925d00ac6cfb0370083c72e71412f.zip
Update MapScene size members on window resize
Diffstat (limited to 'src')
-rw-r--r--src/subconscious/graphics/MapScene.java14
-rw-r--r--src/subconscious/graphics/Scene.java2
2 files changed, 15 insertions, 1 deletions
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;
@@ -223,6 +224,19 @@ public abstract class MapScene extends Scene {
}
@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