]> icculus.org git repositories - mikachu/openbox.git/blob - otk/rect.cc
move Rect and PointerAssassin into the toolkit
[mikachu/openbox.git] / otk / rect.cc
1 #include "rect.hh"
2
3 namespace otk {
4
5 void Rect::setX(int x) {
6   _x2 += x - _x1;
7   _x1 = x;
8 }
9
10
11 void Rect::setY(int y)
12 {
13   _y2 += y - _y1;
14   _y1 = y;
15 }
16
17
18 void Rect::setPos(int x, int y) {
19   _x2 += x - _x1;
20   _x1 = x;
21   _y2 += y - _y1;
22   _y1 = y;
23 }
24
25
26 void Rect::setWidth(unsigned int w) {
27   _x2 = w + _x1 - 1;
28 }
29
30
31 void Rect::setHeight(unsigned int h) {
32   _y2 = h + _y1 - 1;
33 }
34
35
36 void Rect::setSize(unsigned int w, unsigned int h) {
37   _x2 = w + _x1 - 1;
38   _y2 = h + _y1 - 1;
39 }
40
41
42 void Rect::setRect(int x, int y, unsigned int w, unsigned int h) {
43   *this = Rect(x, y, w, h);
44 }
45
46
47 void Rect::setCoords(int l, int t, int r, int b) {
48   _x1 = l;
49   _y1 = t;
50   _x2 = r;
51   _y2 = b;
52 }
53
54
55 Rect Rect::operator|(const Rect &a) const {
56   Rect b;
57
58   b._x1 = std::min(_x1, a._x1);
59   b._y1 = std::min(_y1, a._y1);
60   b._x2 = std::max(_x2, a._x2);
61   b._y2 = std::max(_y2, a._y2);
62
63   return b;
64 }
65
66
67 Rect Rect::operator&(const Rect &a) const {
68   Rect b;
69
70   b._x1 = std::max(_x1, a._x1);
71   b._y1 = std::max(_y1, a._y1);
72   b._x2 = std::min(_x2, a._x2);
73   b._y2 = std::min(_y2, a._y2);
74
75   return b;
76 }
77
78
79 bool Rect::intersects(const Rect &a) const {
80   return std::max(_x1, a._x1) <= std::min(_x2, a._x2) &&
81          std::max(_y1, a._y1) <= std::min(_y2, a._y2);
82 }
83
84
85 bool Rect::contains(int x, int y) const {
86   return x >= _x1 && x <= _x2 &&
87          y >= _y1 && y <= _y2;
88 }
89
90
91 bool Rect::contains(const Rect& a) const {
92   return a._x1 >= _x1 && a._x2 <= _x2 &&
93          a._y1 >= _y1 && a._y2 <= _y2;
94 }
95
96 }