]> git.tdb.fi Git - libs/gltk.git/blob - source/geometry.h
9945fabcd8645a63e093ce8de5b6939e87c2fd80
[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         };
34
35         unsigned top;
36         unsigned right;
37         unsigned bottom;
38         unsigned left;
39
40         Sides();
41         Sides(unsigned);
42         Sides(unsigned, unsigned);
43         Sides(unsigned, unsigned, unsigned);
44         Sides(unsigned, unsigned, unsigned, unsigned);
45 };
46
47
48 /**
49 Performs alignment of nested geometries, such as widgets and their parts.
50 */
51 struct Alignment
52 {
53         float x, y;
54         float w, h;
55
56         Alignment(): x(0), y(0), w(1), h(1) { }
57         void apply(Geometry &, const Geometry &) const;
58         void apply(Geometry &, const Geometry &, const Sides &) const;
59 };
60
61 } // namespace GLtk
62 } // namespace Msp
63
64 #endif