]> Dogcows Code - chaz/openbox/blob - otk/rect.cc
blef
[chaz/openbox] / otk / rect.cc
1 // -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*-
2
3 #ifdef HAVE_CONFIG_H
4 # include "../config.h"
5 #endif
6
7 #include "rect.hh"
8
9 namespace otk {
10
11 void Rect::setX(int x)
12 {
13 _x2 += x - _x1;
14 _x1 = x;
15 }
16
17
18 void Rect::setY(int y)
19 {
20 _y2 += y - _y1;
21 _y1 = y;
22 }
23
24
25 void Rect::setPos(const Point &location)
26 {
27 _x2 += location.x() - _x1;
28 _x1 = location.x();
29 _y2 += location.y() - _y1;
30 _y1 = location.y();
31 }
32
33
34 void Rect::setPos(int x, int y)
35 {
36 _x2 += x - _x1;
37 _x1 = x;
38 _y2 += y - _y1;
39 _y1 = y;
40 }
41
42
43 void Rect::setWidth(int w)
44 {
45 _x2 = w + _x1 - 1;
46 }
47
48
49 void Rect::setHeight(int h)
50 {
51 _y2 = h + _y1 - 1;
52 }
53
54
55 void Rect::setSize(int w, int h)
56 {
57 _x2 = w + _x1 - 1;
58 _y2 = h + _y1 - 1;
59 }
60
61
62 void Rect::setSize(const Point &size)
63 {
64 _x2 = size.x() + _x1 - 1;
65 _y2 = size.y() + _y1 - 1;
66 }
67
68
69 void Rect::setRect(int x, int y, int w, int h)
70 {
71 *this = Rect(x, y, w, h);
72 }
73
74
75 void Rect::setRect(const Point &location, const Point &size)
76 {
77 *this = Rect(location, size);
78 }
79
80
81 void Rect::setCoords(int l, int t, int r, int b)
82 {
83 _x1 = l;
84 _y1 = t;
85 _x2 = r;
86 _y2 = b;
87 }
88
89
90 void Rect::setCoords(const Point &tl, const Point &br)
91 {
92 _x1 = tl.x();
93 _y1 = tl.y();
94 _x2 = br.x();
95 _y2 = br.y();
96 }
97
98
99 Rect Rect::operator|(const Rect &a) const
100 {
101 Rect b;
102
103 b._x1 = std::min(_x1, a._x1);
104 b._y1 = std::min(_y1, a._y1);
105 b._x2 = std::max(_x2, a._x2);
106 b._y2 = std::max(_y2, a._y2);
107
108 return b;
109 }
110
111
112 Rect Rect::operator&(const Rect &a) const
113 {
114 Rect b;
115
116 b._x1 = std::max(_x1, a._x1);
117 b._y1 = std::max(_y1, a._y1);
118 b._x2 = std::min(_x2, a._x2);
119 b._y2 = std::min(_y2, a._y2);
120
121 return b;
122 }
123
124
125 bool Rect::intersects(const Rect &a) const
126 {
127 return std::max(_x1, a._x1) <= std::min(_x2, a._x2) &&
128 std::max(_y1, a._y1) <= std::min(_y2, a._y2);
129 }
130
131
132 bool Rect::contains(int x, int y) const
133 {
134 return x >= _x1 && x <= _x2 &&
135 y >= _y1 && y <= _y2;
136 }
137
138
139 bool Rect::contains(const Point &p) const
140 {
141 return contains(p.x(), p.y());
142 }
143
144
145 bool Rect::contains(const Rect& a) const
146 {
147 return a._x1 >= _x1 && a._x2 <= _x2 &&
148 a._y1 >= _y1 && a._y2 <= _y2;
149 }
150
151 }
This page took 0.037828 seconds and 4 git commands to generate.