| 1 |
// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 2; -*- |
| 2 |
// Rect.hh for Blackbox - an X11 Window manager |
| 3 |
// Copyright (c) 2001 - 2005 Sean 'Shaleh' Perry <[email protected]> |
| 4 |
// Copyright (c) 1997 - 2000, 2002 - 2005 |
| 5 |
// Bradley T Hughes <bhughes at trolltech.com> |
| 6 |
// |
| 7 |
// Permission is hereby granted, free of charge, to any person obtaining a |
| 8 |
// copy of this software and associated documentation files (the "Software"), |
| 9 |
// to deal in the Software without restriction, including without limitation |
| 10 |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 |
// and/or sell copies of the Software, and to permit persons to whom the |
| 12 |
// Software is furnished to do so, subject to the following conditions: |
| 13 |
// |
| 14 |
// The above copyright notice and this permission notice shall be included in |
| 15 |
// all copies or substantial portions of the Software. |
| 16 |
// |
| 17 |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 18 |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 19 |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 20 |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 21 |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 22 |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 23 |
// DEALINGS IN THE SOFTWARE. |
| 24 |
|
| 25 |
#ifndef __Rect_hh |
| 26 |
#define __Rect_hh |
| 27 |
|
| 28 |
namespace bt { |
| 29 |
|
| 30 |
class Rect { |
| 31 |
public: |
| 32 |
inline Rect(void) |
| 33 |
: _x1(0), _y1(0), _x2(0), _y2(0) |
| 34 |
{ } |
| 35 |
inline Rect(int x_, int y_, unsigned int w, unsigned int h) |
| 36 |
: _x1(x_), _y1(y_), _x2(w + x_ - 1), _y2(h + y_ - 1) |
| 37 |
{ } |
| 38 |
|
| 39 |
inline int left(void) const |
| 40 |
{ return _x1; } |
| 41 |
inline int top(void) const |
| 42 |
{ return _y1; } |
| 43 |
inline int right(void) const |
| 44 |
{ return _x2; } |
| 45 |
inline int bottom(void) const |
| 46 |
{ return _y2; } |
| 47 |
|
| 48 |
inline int x(void) const |
| 49 |
{ return _x1; } |
| 50 |
inline int y(void) const |
| 51 |
{ return _y1; } |
| 52 |
void setX(int x_); |
| 53 |
void setY(int y_); |
| 54 |
void setPos(int x_, int y_); |
| 55 |
|
| 56 |
inline unsigned int width(void) const |
| 57 |
{ return _x2 - _x1 + 1; } |
| 58 |
inline unsigned int height(void) const |
| 59 |
{ return _y2 - _y1 + 1; } |
| 60 |
void setWidth(unsigned int w); |
| 61 |
void setHeight(unsigned int h); |
| 62 |
void setSize(unsigned int w, unsigned int h); |
| 63 |
|
| 64 |
void setRect(int x_, int y_, unsigned int w, unsigned int h); |
| 65 |
|
| 66 |
void setCoords(int l, int t, int r, int b); |
| 67 |
|
| 68 |
inline bool operator==(const Rect &a) const |
| 69 |
{ return _x1 == a._x1 && _y1 == a._y1 && _x2 == a._x2 && _y2 == a._y2; } |
| 70 |
inline bool operator!=(const Rect &a) const |
| 71 |
{ return (!operator==(a)); } |
| 72 |
|
| 73 |
Rect operator|(const Rect &a) const; |
| 74 |
Rect operator&(const Rect &a) const; |
| 75 |
inline Rect &operator|=(const Rect &a) |
| 76 |
{ *this = *this | a; return *this; } |
| 77 |
inline Rect &operator&=(const Rect &a) |
| 78 |
{ *this = *this & a; return *this; } |
| 79 |
|
| 80 |
inline bool valid(void) const |
| 81 |
{ return _x2 > _x1 && _y2 > _y1; } |
| 82 |
|
| 83 |
bool intersects(const Rect &a) const; |
| 84 |
bool contains(int x_, int y_) const; |
| 85 |
|
| 86 |
Rect inside(const Rect &a) const; |
| 87 |
|
| 88 |
private: |
| 89 |
int _x1, _y1, _x2, _y2; |
| 90 |
}; |
| 91 |
|
| 92 |
} // namespace bt |
| 93 |
|
| 94 |
#endif // __Rect_hh |