]> git.tdb.fi Git - libs/gltk.git/blob - source/geometry.cpp
81efcd05bad2e69d22325eb3e7df851f638d3644
[libs/gltk.git] / source / geometry.cpp
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 #include "geometry.h"
9
10 namespace Msp {
11 namespace GLtk {
12
13 bool Geometry::is_inside(int x_, int y_) const
14 {
15         return (x_>=x && x_<x+static_cast<int>(w) && y_>=y && y_<y+static_cast<int>(h));
16 }
17
18
19 Sides::Sides():
20         top(0),
21         right(0),
22         bottom(0),
23         left(0)
24 { }
25
26
27 Sides::Loader::Loader(Sides &s):
28         sides(s)
29 {
30         add("top",    &Sides::top);
31         add("right",  &Sides::right);
32         add("bottom", &Sides::bottom);
33         add("left",   &Sides::left);
34 }
35
36
37 void Alignment::apply(Geometry &geom, const Geometry &parent) const
38 {
39         geom.x+=static_cast<int>((parent.w-geom.w)*x);
40         geom.y+=static_cast<int>((parent.h-geom.h)*y);
41 }
42
43 void Alignment::apply(Geometry &geom, const Geometry &parent, const Sides &margin) const
44 {
45         geom.x+=static_cast<int>(margin.left+(parent.w-margin.left-margin.right-geom.w)*x);
46         geom.y+=static_cast<int>(margin.bottom+(parent.h-margin.bottom-margin.top-geom.h)*y);
47 }
48
49 } // namespace GLtk
50 } // namespace Msp