]> git.tdb.fi Git - libs/gltk.git/blob - source/geometry.cpp
Refactor filling from Part to Alignment
[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         if(parent.w>geom.w)
40                 geom.w+=static_cast<unsigned>((parent.w-geom.w)*w);
41         if(parent.h>geom.h)
42                 geom.h+=static_cast<unsigned>((parent.h-geom.h)*h);
43
44         geom.x+=static_cast<int>((parent.w-geom.w)*x);
45         geom.y+=static_cast<int>((parent.h-geom.h)*y);
46 }
47
48 void Alignment::apply(Geometry &geom, const Geometry &parent, const Sides &margin) const
49 {
50         if(parent.w>geom.w)
51                 geom.w+=static_cast<unsigned>((parent.w-geom.w)*w);
52         if(parent.h>geom.h)
53                 geom.h+=static_cast<unsigned>((parent.h-geom.h)*h);
54
55         geom.x+=static_cast<int>(margin.left+(parent.w-margin.left-margin.right-geom.w)*x);
56         geom.y+=static_cast<int>(margin.bottom+(parent.h-margin.bottom-margin.top-geom.h)*y);
57 }
58
59 } // namespace GLtk
60 } // namespace Msp