diff options
author | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-14 15:32:28 +0200 |
---|---|---|
committer | Jérémy Zurcher <jeremy@asynk.ch> | 2020-05-14 15:32:28 +0200 |
commit | 639f146d92e0e2503f4360e40f79b885db6d1ba5 (patch) | |
tree | 7ca0df15a9b86a18ff0aaaf89c613bcfae0658b7 | |
parent | bb280894c14b9dbf7747a97fcd78714628100fd8 (diff) | |
download | gdx-boardgame-639f146d92e0e2503f4360e40f79b885db6d1ba5.zip gdx-boardgame-639f146d92e0e2503f4360e40f79b885db6d1ba5.tar.gz |
UI : introduce abstract Element.drawReal(batch)
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Bg.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Button.java | 8 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Container.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Element.java | 19 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Label.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/List.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Menu.java | 10 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Patch.java | 4 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java | 3 | ||||
-rw-r--r-- | test/src/ch/asynk/gdx/boardgame/test/UiScreen.java | 8 |
10 files changed, 29 insertions, 39 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Bg.java b/core/src/ch/asynk/gdx/boardgame/ui/Bg.java index ba0385e..e7519b8 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Bg.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Bg.java @@ -13,10 +13,8 @@ public class Bg extends Element rect.set(0, 0, region.getRegionWidth(), region.getRegionHeight()); } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; - 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 6798ea6..46232ba 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Button.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Button.java @@ -55,12 +55,10 @@ public class Button extends Patch label.computePosition(); } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; - if (dirty) computeGeometry(); - super.draw(batch); - label.draw(batch); + super.drawReal(batch); + label.drawReal(batch); } @Override public void drawDebug(ShapeRenderer shapeRenderer) diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Container.java b/core/src/ch/asynk/gdx/boardgame/ui/Container.java index 8225d1e..ab6b781 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Container.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Container.java @@ -44,10 +44,8 @@ public class Container extends Element children.forEach( c -> c.drip() ); } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; - 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 6d6fad1..b7604f6 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Element.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Element.java @@ -1,5 +1,6 @@ package ch.asynk.gdx.boardgame.ui; +import com.badlogic.gdx.graphics.g2d.Batch; import com.badlogic.gdx.graphics.glutils.ShapeRenderer; import com.badlogic.gdx.math.Rectangle; @@ -197,13 +198,19 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch if (DEBUG_GEOMETRY) System.err.println(" pos " + print(-1)); } - public final void computeGeometry() + public abstract void drawReal(Batch batch); + + @Override public void draw(Batch batch) { - if (DEBUG_GEOMETRY) { print("[Geometry"); System.err.println(" --> " + print(-1)); } - computeDimensions(); - computePosition(); - clear(); - if (DEBUG_GEOMETRY) System.err.println("Geometry]"); + if (!visible) return; + if (dirty) { + if (DEBUG_GEOMETRY) { print("[Geometry"); System.err.println(" --> " + print(-1)); } + computeDimensions(); + computePosition(); + clear(); + if (DEBUG_GEOMETRY) System.err.println("Geometry]"); + } + drawReal(batch); } @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 779554b..4ff4789 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Label.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Label.java @@ -59,10 +59,8 @@ public class Label extends Element if (DEBUG_GEOMETRY) System.err.println(" dim " + print(-1)); } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; - 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 16a6aef..2d84a94 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/List.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/List.java @@ -84,10 +84,8 @@ public class List extends Element if (DEBUG_GEOMETRY) System.err.println(" pos " + print(-1)); } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; - 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 be14951..2c0c429 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Menu.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Menu.java @@ -116,14 +116,12 @@ public class Menu extends Patch return null; } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; - if (dirty) computeGeometry(); - super.draw(batch); - title.draw(batch); + super.drawReal(batch); + title.drawReal(batch); for (Label label : entries) { - label.draw(batch); + label.drawReal(batch); } } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Patch.java b/core/src/ch/asynk/gdx/boardgame/ui/Patch.java index cd71bb9..9cd4f56 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Patch.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Patch.java @@ -14,10 +14,8 @@ public class Patch extends Element setPosition(0, 0, patch.getTotalWidth(), patch.getTotalHeight()); } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; - if (dirty) computeGeometry(); patch.draw(batch, getX(), getY(), getWidth(), getHeight()); } } diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java b/core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java index abc0e27..b5f55f4 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Scrollable.java @@ -97,9 +97,8 @@ public class Scrollable extends Element scissorIdx = Scissors.compute(scissorIdx, clip); } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; batch.flush(); Rectangle scissor = Scissors.get(scissorIdx, clip); HdpiUtils.glScissor((int)scissor.x, (int)scissor.y, (int)scissor.width, (int)scissor.height); diff --git a/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java b/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java index ef153aa..58ad764 100644 --- a/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java +++ b/test/src/ch/asynk/gdx/boardgame/test/UiScreen.java @@ -222,12 +222,10 @@ class MyList extends Patch return scrollable.drag(x, y, dx, dy); } - @Override public void draw(Batch batch) + @Override public void drawReal(Batch batch) { - if (!visible) return; - if (dirty) computeGeometry(); - super.draw(batch); - title.draw(batch); + super.drawReal(batch); + title.drawReal(batch); scrollable.draw(batch); } |