summaryrefslogtreecommitdiffstats
path: root/core
diff options
context:
space:
mode:
Diffstat (limited to 'core')
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Assembly.java15
-rw-r--r--core/src/ch/asynk/gdx/boardgame/ui/Element.java21
2 files changed, 21 insertions, 15 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java b/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
index 866c3dd..28a7597 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Assembly.java
@@ -7,7 +7,6 @@ import ch.asynk.gdx.boardgame.utils.IterableSet;
public abstract class Assembly extends Element
{
- protected IterableSet<Element> children;
private Element touched;
public Assembly(int c)
@@ -15,20 +14,6 @@ public abstract class Assembly extends Element
this.children = new IterableSet<Element>(c);
}
- public void add(Element e)
- {
- if (children.add(e)) {
- e.setParent(this);
- }
- }
-
- public void remove(Element e)
- {
- if (children.remove(e)) {
- e.setParent(null);
- }
- }
-
public void taintChildren()
{
children.forEach( c -> c.taint() );
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Element.java b/core/src/ch/asynk/gdx/boardgame/ui/Element.java
index 9885b59..73d068f 100644
--- a/core/src/ch/asynk/gdx/boardgame/ui/Element.java
+++ b/core/src/ch/asynk/gdx/boardgame/ui/Element.java
@@ -7,10 +7,12 @@ import ch.asynk.gdx.boardgame.Drawable;
import ch.asynk.gdx.boardgame.Paddable;
import ch.asynk.gdx.boardgame.Positionable;
import ch.asynk.gdx.boardgame.Touchable;
+import ch.asynk.gdx.boardgame.utils.IterableSet;
public abstract class Element implements Drawable, Paddable, Positionable, Touchable
{
public static boolean DEBUG_GEOMETRY = false;
+ public static int DEFAULT_CHILD_COUNT = 2;
public boolean blocked;
public boolean visible;
@@ -23,6 +25,8 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
protected boolean tainted; // geometry must be computed
public boolean taintParent; // propagate tainted state up the tree
+ protected IterableSet<Element> children;
+
protected Element()
{
this(false);
@@ -40,6 +44,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
this.x = this.y = 0;
this.tainted = true;
this.taintParent = taintParent;
+ this.children = null;
}
@Override public final float getX() { return rect.x; }
@@ -78,6 +83,22 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch
return r;
}
+ public void add(Element e)
+ {
+ if (children == null)
+ children = new IterableSet<Element>(DEFAULT_CHILD_COUNT);
+ if (children.add(e)) {
+ e.setParent(this);
+ }
+ }
+
+ public void remove(Element e)
+ {
+ if (children.remove(e)) {
+ e.setParent(null);
+ }
+ }
+
@Override public void drawDebug(ShapeRenderer shapeRenderer)
{
shapeRenderer.rect(getX(), getY(), getWidth(), getHeight());