summaryrefslogtreecommitdiffstats
path: root/core/src/ch/asynk/gdx/boardgame/ui/Alignment.java
blob: 3c120877177507f2e75fed92879d1e7d3b0a402e (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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
package ch.asynk.gdx.boardgame.ui;

import com.badlogic.gdx.math.Rectangle;

public enum Alignment
{
    ABSOLUTE,           // Root
    RELATIVE,           // Default
    TOP_LEFT,
    TOP_RIGHT,
    TOP_CENTER,
    MIDDLE_LEFT,
    MIDDLE_RIGHT,
    MIDDLE_CENTER,
    BOTTOM_LEFT,
    BOTTOM_RIGHT,
    BOTTOM_CENTER;

    public Alignment verticalMirror()
    {
        switch(this) {
            case TOP_LEFT:
                return TOP_RIGHT;
            case MIDDLE_LEFT:
                return MIDDLE_RIGHT;
            case BOTTOM_LEFT:
                return BOTTOM_RIGHT;
            case TOP_RIGHT:
                return TOP_LEFT;
            case MIDDLE_RIGHT:
                return MIDDLE_LEFT;
            case BOTTOM_RIGHT:
                return BOTTOM_LEFT;
        }
        return this;
    }

    public Alignment horizontalMirror()
    {
        switch(this) {
            case TOP_LEFT:
                return BOTTOM_LEFT;
            case TOP_CENTER:
                return BOTTOM_CENTER;
            case TOP_RIGHT:
                return BOTTOM_RIGHT;
            case BOTTOM_LEFT:
                return TOP_LEFT;
            case BOTTOM_CENTER:
                return TOP_CENTER;
            case BOTTOM_RIGHT:
                return TOP_RIGHT;
        }
        return this;
    }

    public boolean isTop()
    {
        switch(this) {
            case TOP_LEFT:
            case TOP_CENTER:
            case TOP_RIGHT:
                return true;
        }
        return false;
    }

    public boolean isMiddle()
    {
        boolean r = false;
        switch(this) {
            case MIDDLE_LEFT:
            case MIDDLE_CENTER:
            case MIDDLE_RIGHT:
                return true;
        }
        return false;
    }

    public boolean isBottom()
    {
        boolean r = false;
        switch(this) {
            case BOTTOM_LEFT:
            case BOTTOM_CENTER:
            case BOTTOM_RIGHT:
                return true;
        }
        return false;
    }

    public boolean isLeft()
    {
        boolean r = false;
        switch(this) {
            case TOP_LEFT:
            case MIDDLE_LEFT:
            case BOTTOM_LEFT:
                return true;
        }
        return false;
    }

    public boolean isRight()
    {
        boolean r = false;
        switch(this) {
            case TOP_RIGHT:
            case MIDDLE_RIGHT:
            case BOTTOM_RIGHT:
                return true;
        }
        return false;
    }

    public boolean isCenter()
    {
        switch(this) {
            case TOP_CENTER:
            case MIDDLE_CENTER:
            case BOTTOM_CENTER:
                return true;
        }
        return false;
    }

    public float getX(Rectangle area, float width)
    {
        float x = area.x;
        switch(this) {
            case TOP_LEFT:
            case MIDDLE_LEFT:
            case BOTTOM_LEFT:
                break;
            case TOP_CENTER:
            case MIDDLE_CENTER:
            case BOTTOM_CENTER:
                x += ((area.width - width) / 2);
                break;
            case TOP_RIGHT:
            case MIDDLE_RIGHT:
            case BOTTOM_RIGHT:
                x += (area.width - width);
                break;
        }
        return x;
    }

    public float getY(Rectangle area, float height)
    {
        float y = area.y;
        switch(this) {
            case TOP_LEFT:
            case TOP_CENTER:
            case TOP_RIGHT:
                y += (area.height - height);
                break;
            case MIDDLE_LEFT:
            case MIDDLE_CENTER:
            case MIDDLE_RIGHT:
                y += ((area.height - height) / 2);
                break;
            case BOTTOM_LEFT:
            case BOTTOM_CENTER:
            case BOTTOM_RIGHT:
                break;
        }
        return y;
    }
}