]> Dogcows Code - chaz/openbox/blob - otk/rect.hh
a11f3a25e202ec2c9ae638c5588dc6858a61efd5
[chaz/openbox] / otk / rect.hh
1 // -*- mode: C++; indent-tabs-mode: nil; -*-
2 #ifndef __rect_hh
3 #define __rect_hh
4
5 extern "C" {
6 #include <X11/Xlib.h>
7 }
8
9 #include <vector>
10
11 namespace otk {
12
13 class Rect {
14 public:
15 inline Rect(void) : _x1(0), _y1(0), _x2(0), _y2(0) { }
16 inline Rect(int __x, int __y, unsigned int __w, unsigned int __h)
17 : _x1(__x), _y1(__y), _x2(__w + __x - 1), _y2(__h + __y - 1) { }
18 inline explicit Rect(const XRectangle& xrect)
19 : _x1(xrect.x), _y1(xrect.y), _x2(xrect.width + xrect.x - 1),
20 _y2(xrect.height + xrect.y - 1) { }
21
22 inline int left(void) const { return _x1; }
23 inline int top(void) const { return _y1; }
24 inline int right(void) const { return _x2; }
25 inline int bottom(void) const { return _y2; }
26
27 inline int x(void) const { return _x1; }
28 inline int y(void) const { return _y1; }
29 void setX(int __x);
30 void setY(int __y);
31 void setPos(int __x, int __y);
32
33 inline unsigned int width(void) const { return _x2 - _x1 + 1; }
34 inline unsigned int height(void) const { return _y2 - _y1 + 1; }
35 void setWidth(unsigned int __w);
36 void setHeight(unsigned int __h);
37 void setSize(unsigned int __w, unsigned int __h);
38
39 void setRect(int __x, int __y, unsigned int __w, unsigned int __h);
40
41 void setCoords(int __l, int __t, int __r, int __b);
42
43 inline bool operator==(const Rect &a)
44 { return _x1 == a._x1 && _y1 == a._y1 && _x2 == a._x2 && _y2 == a._y2; }
45 inline bool operator!=(const Rect &a) { return ! operator==(a); }
46
47 Rect operator|(const Rect &a) const;
48 Rect operator&(const Rect &a) const;
49 inline Rect &operator|=(const Rect &a) { *this = *this | a; return *this; }
50 inline Rect &operator&=(const Rect &a) { *this = *this & a; return *this; }
51
52 inline bool valid(void) const { return _x2 > _x1 && _y2 > _y1; }
53
54 bool intersects(const Rect &a) const;
55 bool contains(int __x, int __y) const;
56 bool contains(const Rect &a) const;
57
58 private:
59 int _x1, _y1, _x2, _y2;
60 };
61
62 typedef std::vector<Rect> RectList;
63
64 }
65
66 #endif // __rect_hh
This page took 0.035835 seconds and 4 git commands to generate.