diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-17 06:52:35 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-17 06:52:35 +0200 |
commit | c619ebf333c677e906bc020a62864fbb0e7d44e1 (patch) | |
tree | 50336987b910112e7ac9d0e9b644abda75797d02 /core/src/ch | |
parent | 3ed148e88e425046e9af155393efb33f9a11c050 (diff) | |
download | gdx-boardgame-c619ebf333c677e906bc020a62864fbb0e7d44e1.zip gdx-boardgame-c619ebf333c677e906bc020a62864fbb0e7d44e1.tar.gz |
UI : add damaged flag, a child is dirt
Diffstat (limited to 'core/src/ch')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Container.java | 6 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Element.java | 18 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Root.java | 2 |
3 files changed, 22 insertions, 4 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Container.java b/core/src/ch/asynk/gdx/boardgame/ui/Container.java index 30b5f20..46a013a 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Container.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Container.java @@ -40,9 +40,11 @@ public class Container extends Element @Override public void computeGeometry(Rectangle area, boolean resized) { + if ((dirty || damaged || resized) && children != null) { + children.forEach( c -> c.computeGeometry(area, resized) ); + damaged = false; + } if (dirty || resized) { - if (children != null) - children.forEach( c -> c.computeGeometry(area, resized) ); super.computeGeometry(area, resized); } } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Element.java b/core/src/ch/asynk/gdx/boardgame/ui/Element.java index 89e28a7..c76346d 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Element.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Element.java @@ -23,6 +23,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch protected Rectangle innerRect; // inner drawing coordinates protected float x, y; // given position protected boolean dirty; // geometry must be computed + protected boolean damaged; // child Element is dirty protected Element() { @@ -36,6 +37,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch this.innerRect = new Rectangle(0, 0, 0, 0); this.x = this.y = 0; this.dirty = true; + this.damaged = false; } @Override public final float getX() { return rect.x; } @@ -83,6 +85,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch { if (DEBUG_GEOMETRY) print(" clear"); this.dirty = false; + this.damaged = false; } public void taint() @@ -93,7 +96,18 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch } if (DEBUG_GEOMETRY) print(" taint"); this.dirty = true; - if (parent != null) parent.taint(); + if (parent != null) parent.damage(); + } + + public void damage() + { + if (this.damaged) { + if (DEBUG_GEOMETRY) print(" already damaged"); + return; + } + if (DEBUG_GEOMETRY) print(" damage"); + this.damaged = true; + if (parent != null) parent.damage(); } @Override public void setPosition(float x, float y, float w, float h) @@ -187,6 +201,8 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch computeDimensions(); computePosition(area); clear(); + } else if (damaged) { + damaged = false; } } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Root.java b/core/src/ch/asynk/gdx/boardgame/ui/Root.java index 750f574..9b6da72 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Root.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Root.java @@ -47,7 +47,7 @@ public class Root extends Container @Override public void draw(Batch batch) { - if (dirty || resized) { + if (dirty || damaged || resized) { computeGeometry(null, resized); resized = false; } |