]> git.tdb.fi Git - libs/gltk.git/blob - source/geometry.h
Style and comment updates
[libs/gltk.git] / source / geometry.h
1 #ifndef MSP_GLTK_GEOMETRY_H_
2 #define MSP_GLTK_GEOMETRY_H_
3
4 #include <msp/datafile/objectloader.h>
5 #include "mspgltk_api.h"
6
7 namespace Msp {
8 namespace GLtk {
9
10 /**
11 Specifies the position and size of a widget or graphic.
12 */
13 struct MSPGLTK_API Geometry
14 {
15         int x = 0;
16         int y = 0;
17         unsigned w = 1;
18         unsigned h = 1;
19
20         Geometry() = default;
21         Geometry(int x_, int y_, unsigned w_, unsigned h_): x(x_), y(y_), w(w_), h(h_) { }
22
23         bool is_inside(int, int) const;
24         bool is_inside_relative(int, int) const;
25 };
26
27
28 /**
29 Specifies margins on the sides of an element.
30 */
31 struct MSPGLTK_API Sides
32 {
33         class Loader: public DataFile::ObjectLoader<Sides>
34         {
35         public:
36                 Loader(Sides &);
37         private:
38                 void horizontal(unsigned);
39                 void vertical(unsigned);
40         };
41
42         unsigned top = 0;
43         unsigned right = 0;
44         unsigned bottom = 0;
45         unsigned left = 0;
46
47         Sides() = default;
48         Sides(unsigned);
49         Sides(unsigned, unsigned);
50         Sides(unsigned, unsigned, unsigned);
51         Sides(unsigned, unsigned, unsigned, unsigned);
52 };
53
54
55 /**
56 Performs alignment of nested geometries, such as widgets and their parts.
57 */
58 struct MSPGLTK_API Alignment
59 {
60         float x = 0.0f;
61         float y = 0.0f;
62         float w = 1.0f;
63         float h = 1.0f;
64
65         void apply(Geometry &, const Geometry &) const;
66         void apply(Geometry &, const Geometry &, const Sides &) const;
67 };
68
69 } // namespace GLtk
70 } // namespace Msp
71
72 #endif