]> git.localhorst.tv Git - gong.git/blob - src/graphics/align.hpp
code, assets, and other stuff stolen from blank
[gong.git] / src / graphics / align.hpp
1 #ifndef GONG_GRAPHICS_ALIGN_HPP_
2 #define GONG_GRAPHICS_ALIGN_HPP_
3
4 #include "glm.hpp"
5
6
7 namespace gong {
8 namespace graphics {
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.5 * int(get_x(g)) + offset.x,
47                 size.y * 0.5 * int(get_y(g)) + offset.y
48         );
49 }
50
51 }
52 }
53
54 #endif