diff options
Diffstat (limited to 'core/src/ch/asynk')
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Element.java | 6 | ||||
-rw-r--r-- | core/src/ch/asynk/gdx/boardgame/ui/Sizing.java | 70 |
2 files changed, 41 insertions, 35 deletions
diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Element.java b/core/src/ch/asynk/gdx/boardgame/ui/Element.java index c76346d..9bc7551 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Element.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Element.java @@ -17,7 +17,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch public boolean visible; protected float padding; protected Element parent; - protected Sizing sizing; // sizing policy + protected int sizing; // sizing policy protected Alignment alignment; // where to position itself protected Rectangle rect; // outer drawing coordinates protected Rectangle innerRect; // inner drawing coordinates @@ -66,7 +66,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() + " " + Integer.toHexString(hashCode()); + (int)padding + " " + alignment + " " + Sizing.print(sizing) + " "+ getClass().getName() + " " + Integer.toHexString(hashCode()); if (level < 0) return r; if (parent != null) @@ -145,7 +145,7 @@ public abstract class Element implements Drawable, Paddable, Positionable, Touch taint(); } - public void setSizing(Sizing sizing) + public void setSizing(int sizing) { this.sizing = sizing; taint(); diff --git a/core/src/ch/asynk/gdx/boardgame/ui/Sizing.java b/core/src/ch/asynk/gdx/boardgame/ui/Sizing.java index a8d089c..4f50d96 100644 --- a/core/src/ch/asynk/gdx/boardgame/ui/Sizing.java +++ b/core/src/ch/asynk/gdx/boardgame/ui/Sizing.java @@ -1,47 +1,53 @@ package ch.asynk.gdx.boardgame.ui; -public enum Sizing +public class Sizing { - NONE(0), - // 0x02 - FILL_WIDTH(2), - FILL_HEIGHT(3), - FILL_BOTH(6), - // 0x08 - EXPAND_WIDTH(8), - EXPAND_HEIGHT(9), - EXPAND_BOTH(24); - - private int s; - Sizing(int s) { this.s = s; } - - public boolean fill() - { - return (this.s & 0x2) == 0x2; - } - - public boolean fillWidth() - { - return (this == FILL_WIDTH || this == FILL_BOTH); - } - - public boolean fillHeight() + public static final int NONE = 0; + public static final int FILL_X = 0x1; + public static final int FILL_Y = 0x2; + public static final int FILL_BOTH = FILL_X | FILL_Y; + public static final int EXPAND_X = 0x4; + public static final int EXPAND_Y = 0x8; + public static final int EXPAND_BOTH = EXPAND_X | EXPAND_Y; + + public static boolean contains(int v, int w) { - return (this == FILL_HEIGHT || this == FILL_BOTH); + return ((v & w) == w); } - public boolean expand() + public static boolean fill(int v) { - return (this.s & 0x8) == 0x8; + return contains(v, FILL_X) || contains(v, FILL_Y); } - public boolean expandWidth() + public static boolean expand(int v) { - return (this == EXPAND_WIDTH || this == EXPAND_BOTH); + return contains(v, EXPAND_X) || contains(v, EXPAND_Y); } - public boolean expandHeight() + public static String print(int v) { - return (this == EXPAND_HEIGHT || this == EXPAND_BOTH); + String ret = ""; + if (v == 0) + return "NONE"; + if (fill(v)) { + ret += "FILL_"; + if (contains(v, FILL_BOTH)) + ret += "BOTH "; + else if (contains(v, FILL_X)) + ret += "X "; + else + ret += "Y "; + } + if (expand(v)) { + ret += "EXPAND_"; + if (contains(v, EXPAND_BOTH)) + ret += "BOTH "; + else if (contains(v, EXPAND_X)) + ret += "X "; + else + ret += "Y "; + } + return ret.substring(0, ret.length() - 1); } } |