summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/ui/Sizing.java
blob: 4f50d9648b6924c700f59303a3093a612294d1af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package ch.asynk.gdx.boardgame.ui;

public class Sizing
{
    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 ((v & w) == w);
    }

    public static boolean fill(int v)
    {
        return contains(v, FILL_X) || contains(v, FILL_Y);
    }

    public static boolean expand(int v)
    {
        return contains(v, EXPAND_X) || contains(v, EXPAND_Y);
    }

    public static String print(int v)
    {
        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);
    }
}