diff options
Diffstat (limited to 'core/src/ch/asynk/gdx')
-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; } |