diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-14 14:34:58 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-14 14:34:58 +0200 |
commit | bb280894c14b9dbf7747a97fcd78714628100fd8 (patch) | |
tree | c2706f043ac97916759d6ae161576bab93e1912a /core/src/ch/asynk/gdx/boardgame | |
parent | c93fd2cf018184a1d2fc83977a84a29319af0dd1 (diff) | |
download | gdx-boardgame-bb280894c14b9dbf7747a97fcd78714628100fd8.zip gdx-boardgame-bb280894c14b9dbf7747a97fcd78714628100fd8.tar.gz |
UI : tainted -> dirty + audit clean up all
Diffstat (limited to 'core/src/ch/asynk/gdx/boardgame')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Bg.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Button.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Container.java | 9 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Element.java | 46 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Label.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/List.java | 3 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Menu.java | 7 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Patch.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Root.java | 2 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java | 2 |
10 files changed, 57 insertions, 20 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Bg.java b/core/src/ch/asynk/gdx/boardgame/ui/Bg.java index 18cfa7c..ba0385e 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Bg.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Bg.java @@ -16,7 +16,7 @@ public class Bg extends Element @Override public void draw(Batch batch) { if (!visible) return; - if (tainted) computeGeometry(); + if (dirty) computeGeometry(); batch.draw(region, rect.x, rect.y, rect.width, rect.height); } } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Button.java b/core/src/ch/asynk/gdx/boardgame/ui/Button.java index 69bec27..6798ea6 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Button.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Button.java @@ -58,7 +58,7 @@ public class Button extends Patch @Override public void draw(Batch batch) { if (!visible) return; - if (tainted) computeGeometry(); + if (dirty) computeGeometry(); super.draw(batch); label.draw(batch); } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Container.java b/core/src/ch/asynk/gdx/boardgame/ui/Container.java index 79e0c45..8225d1e 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Container.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Container.java @@ -24,6 +24,7 @@ public class Container extends Element if (children.add(e)) { e.setParent(this); } + taint(); } public void remove(Element e) @@ -32,19 +33,21 @@ public class Container extends Element if (children.remove(e)) { e.setParent(null); } + taint(); } } - public void taintChildren() + @Override public void drip() { + super.drip(); if (children != null) - children.forEach( c -> c.taint() ); + children.forEach( c -> c.drip() ); } @Override public void draw(Batch batch) { if (!visible) return; - if (tainted) computeGeometry(); + if (dirty) computeGeometry(); if (children != null) children.forEach( c -> c.draw(batch) ); } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Element.java b/core/src/ch/asynk/gdx/boardgame/ui/Element.java index 13b1d42..6d6fad1 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Element.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Element.java @@ -20,7 +20,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch protected Alignment alignment; // where to position itself protected Rectangle rect; // outer drawing coordinates protected float x, y; // given position - protected boolean tainted; // geometry must be computed + protected boolean dirty; // geometry must be computed protected Element() { @@ -61,7 +61,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch String r = suffix; r += " : " + (int)x + " " + (int)y + " [" + (int)rect.x + " " + (int)rect.y + " " + (int)rect.width + " " + (int)rect.height + "] +" + - (int)padding + " " + alignment + " " + sizing + " "+ getClass().getName(); + (int)padding + " " + alignment + " " + sizing + " "+ getClass().getName() + " " + Integer.toHexString(hashCode()); if (level < 0) return r; if (parent != null) @@ -71,10 +71,34 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch return r; } + protected void print(String msg) + { + System.err.println(msg + " : " + getClass().getName() + " " + Integer.toHexString(hashCode())); + } + + public void clear() + { + if (DEBUG_GEOMETRY) print(" clear"); + this.dirty = false; + } + + public void mark() + { + if (DEBUG_GEOMETRY) print(" mark"); + this.dirty = true; + } + + public void drip() + { + if (DEBUG_GEOMETRY) print(" drip"); + this.dirty = true; + } + public void taint() { - this.tainted = true; - if (parent != null) parent.taint(); + if (DEBUG_GEOMETRY) print(" taint"); + mark(); + if (parent != null) parent.mark(); } @Override public void setPosition(float x, float y, float w, float h) @@ -86,6 +110,14 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch taint(); } + public final void setPositionClear(float x, float y) + { + this.x = x; + this.y = y; + computePosition(); + clear(); + } + public void setParent(Element parent) { setParent(parent, null); @@ -167,11 +199,11 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch public final void computeGeometry() { - if (DEBUG_GEOMETRY) System.err.println("[Geometry " + print(-1)); + if (DEBUG_GEOMETRY) { print("[Geometry"); System.err.println(" --> " + print(-1)); } computeDimensions(); computePosition(); - if (DEBUG_GEOMETRY) System.err.println("Geometry]" + print(-1)); - this.tainted = false; + clear(); + if (DEBUG_GEOMETRY) System.err.println("Geometry]"); } @Override public void drawDebug(ShapeRenderer shapeRenderer) diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Label.java b/core/src/ch/asynk/gdx/boardgame/ui/Label.java index 4eb1de6..779554b 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Label.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Label.java @@ -62,7 +62,7 @@ public class Label extends Element @Override public void draw(Batch batch) { if (!visible) return; - if (tainted) computeGeometry(); + if (dirty) computeGeometry(); font.draw(batch, layout, getInnerX(), getInnerY() + layout.height); } } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/List.java b/core/src/ch/asynk/gdx/boardgame/ui/List.java index da1c33f..16a6aef 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/List.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/List.java @@ -81,12 +81,13 @@ public class List extends Element { super.computePosition(); selected.computePosition(); + if (DEBUG_GEOMETRY) System.err.println(" pos " + print(-1)); } @Override public void draw(Batch batch) { if (!visible) return; - if (tainted) computeGeometry(); + if (dirty) computeGeometry(); float x = getInnerX(); float y = getInnerTop(); for (Item e : items) { diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Menu.java b/core/src/ch/asynk/gdx/boardgame/ui/Menu.java index e851175..be14951 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Menu.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Menu.java @@ -87,12 +87,13 @@ public class Menu extends Patch super.computePosition(); float y = getInnerHeight() - title.getHeight(); - title.setPosition(0, y); + title.setPositionClear(0, y); y -= titleSpacing; for (Label l : entries) { - l.setPosition(x + entriesOffset, y - l.getHeight()); + l.setPositionClear(x + entriesOffset, y - l.getHeight()); y -= (l.getHeight() + entriesSpacing); } + if (DEBUG_GEOMETRY) System.err.println(" pos " + print(-1)); } public int touched() @@ -118,7 +119,7 @@ public class Menu extends Patch @Override public void draw(Batch batch) { if (!visible) return; - if (tainted) computeGeometry(); + if (dirty) computeGeometry(); super.draw(batch); title.draw(batch); for (Label label : entries) { diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Patch.java b/core/src/ch/asynk/gdx/boardgame/ui/Patch.java index df2cc06..cd71bb9 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Patch.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Patch.java @@ -17,7 +17,7 @@ public class Patch extends Element @Override public void draw(Batch batch) { if (!visible) return; - if (tainted) computeGeometry(); + if (dirty) computeGeometry(); patch.draw(batch, getX(), getY(), getWidth(), getHeight()); } } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Root.java b/core/src/ch/asynk/gdx/boardgame/ui/Root.java index dfa8e04..f11a617 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Root.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Root.java @@ -28,7 +28,7 @@ public class Root extends Container public void resize(float x, float y, float width, float height) { setPosition(x, y, width, height); - taintChildren(); + drip(); } public Element touched() diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java b/core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java index d07b3c7..abc0e27 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java @@ -93,7 +93,7 @@ public class Scrollable extends Element { rect.set(x, y, w, h); clip.set((x + padding), (y + padding), (w - 2 * padding), (h - 2 * padding)); - child.setPosition(clip.x, clip.y - (child.rect.height - clip.height)); + child.setPositionClear(clip.x, clip.y - (child.rect.height - clip.height)); scissorIdx = Scissors.compute(scissorIdx, clip); } |