]> git.tdb.fi Git - libs/gltk.git/blob - source/geometry.h
6fa8e7f1287ffd1f39942979f1f046889bc97ecc
[libs/gltk.git] / source / geometry.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007  Mikko Rasa, Mikkosoft Productions
5 Distributed under the LGPL
6 */
7
8 #ifndef MSP_GLTK_GEOMETRY_H_
9 #define MSP_GLTK_GEOMETRY_H_
10
11 #include <msp/datafile/loader.h>
12
13 namespace Msp {
14 namespace GLtk {
15
16 /**
17 Specifies the position and size of a widget or graphic.
18 */
19 struct Geometry
20 {
21         int x, y;
22         unsigned w, h;
23
24         Geometry(): x(0), y(0), w(1), h(1) { }
25         Geometry(int x_, int y_, unsigned w_, unsigned h_): x(x_), y(y_), w(w_), h(h_) { }
26         bool is_inside(int, int) const;
27 };
28
29
30 /**
31 Specifies margins on the sides of an element.
32 */
33 struct Sides
34 {
35         class Loader: public DataFile::Loader
36         {
37         public:
38                 Loader(Sides &);
39                 Sides &get_object() { return sides; }
40         private:
41                 Sides &sides;
42         };
43
44         unsigned top;
45         unsigned right;
46         unsigned bottom;
47         unsigned left;
48
49         Sides();
50 };
51
52
53 /**
54 Performs alignment of nested geometries, such as widgets and their parts.
55 */
56 struct Alignment
57 {
58         float x, y;
59         float w, h;
60
61         Alignment(): x(0), y(0), w(1), h(1) { }
62         void apply(Geometry &, const Geometry &) const;
63         void apply(Geometry &, const Geometry &, const Sides &) const;
64 };
65
66 } // namespace GLtk
67 } // namespace Msp
68
69 #endif