]> git.tdb.fi Git - libs/gltk.git/blob - source/geometry.h
Add various constructors to Sides (semantics inspired by CSS margins)
[libs/gltk.git] / source / geometry.h
1 /* $Id$
2
3 This file is part of libmspgltk
4 Copyright © 2007, 2011  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/objectloader.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         bool is_inside_relative(int, int) const;
28 };
29
30
31 /**
32 Specifies margins on the sides of an element.
33 */
34 struct Sides
35 {
36         class Loader: public DataFile::ObjectLoader<Sides>
37         {
38         public:
39                 Loader(Sides &);
40         };
41
42         unsigned top;
43         unsigned right;
44         unsigned bottom;
45         unsigned left;
46
47         Sides();
48         Sides(unsigned);
49         Sides(unsigned, unsigned);
50         Sides(unsigned, unsigned, unsigned);
51         Sides(unsigned, unsigned, unsigned, unsigned);
52 };
53
54
55 /**
56 Performs alignment of nested geometries, such as widgets and their parts.
57 */
58 struct Alignment
59 {
60         float x, y;
61         float w, h;
62
63         Alignment(): x(0), y(0), w(1), h(1) { }
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