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