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