]> git.tdb.fi Git - libs/gltk.git/blob - source/geometry.h
fac3bbc7a506ea9cde32a37fad8a5e50618d562a
[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         bool is_inside(int, int) const;
23         bool is_inside_relative(int, int) const;
24 };
25
26
27 /**
28 Specifies margins on the sides of an element.
29 */
30 struct MSPGLTK_API Sides
31 {
32         class Loader: public DataFile::ObjectLoader<Sides>
33         {
34         public:
35                 Loader(Sides &);
36         private:
37                 void horizontal(unsigned);
38                 void vertical(unsigned);
39         };
40
41         unsigned top = 0;
42         unsigned right = 0;
43         unsigned bottom = 0;
44         unsigned left = 0;
45
46         Sides() = default;
47         Sides(unsigned);
48         Sides(unsigned, unsigned);
49         Sides(unsigned, unsigned, unsigned);
50         Sides(unsigned, unsigned, unsigned, unsigned);
51 };
52
53
54 /**
55 Performs alignment of nested geometries, such as widgets and their parts.
56 */
57 struct MSPGLTK_API Alignment
58 {
59         float x = 0.0f;
60         float y = 0.0f;
61         float w = 1.0f;
62         float h = 1.0f;
63
64         void apply(Geometry &, const Geometry &) const;
65         void apply(Geometry &, const Geometry &, const Sides &) const;
66 };
67
68 } // namespace GLtk
69 } // namespace Msp
70
71 #endif