]> git.localhorst.tv Git - blobs.git/blob - src/ui/align.hpp
randomize creature properties a bit
[blobs.git] / src / ui / align.hpp
1 #ifndef BLOBS_UI_ALIGN_HPP_
2 #define BLOBS_UI_ALIGN_HPP_
3
4 #include "../math/glm.hpp"
5
6
7 namespace blobs {
8 namespace ui {
9
10 enum class Align {
11         BEGIN,
12         MIDDLE,
13         END,
14 };
15
16 enum class Gravity {
17         NORTH_WEST,
18         NORTH,
19         NORTH_EAST,
20         WEST,
21         CENTER,
22         EAST,
23         SOUTH_WEST,
24         SOUTH,
25         SOUTH_EAST,
26 };
27
28 inline Align get_x(Gravity g) noexcept {
29         return Align(int(g) % 3);
30 }
31
32 inline Align get_y(Gravity g) noexcept {
33         return Align(int(g) / 3);
34 }
35
36 inline Gravity get_gravity(Align x, Align y) noexcept {
37         return Gravity(int(y) * 3 + int(x));
38 }
39
40 inline glm::vec2 align(
41         Gravity g,
42         const glm::vec2 &size,
43         const glm::vec2 &offset = glm::vec2(0.0f, 0.0f)
44 ) {
45         return glm::vec2(
46                 size.x * 0.5f * (1 - int(get_x(g))) + offset.x,
47                 size.y * 0.5f * (1 - int(get_y(g))) + offset.y
48         );
49 }
50
51 inline glm::vec3 align(
52         Gravity g,
53         const glm::vec2 &size,
54         const glm::vec3 &offset
55 ) {
56         return glm::vec3(
57                 size.x * 0.5f * (1 - int(get_x(g))) + offset.x,
58                 size.y * 0.5f * (1 - int(get_y(g))) + offset.y,
59                 offset.z
60         );
61 }
62
63 }
64 }
65
66 #endif