headers/bsd: Add sys/queue.h.
[haiku.git] / src / servers / app / IntRect.h
blobf273bb8172d55078c7c41bb8ead62c78c0b2b638
1 /*
2 * Copyright 2001-2006, Haiku, Inc. All Rights Reserved.
3 * Distributed under the terms of the MIT License.
5 * Authors:
6 * Frans van Nispen
7 * Stephan Aßmus <superstippi@gmx.de>
8 */
10 #ifndef INT_RECT_H
11 #define INT_RECT_H
14 #include <Region.h>
16 #include "IntPoint.h"
18 class IntRect {
19 public:
20 int32 left;
21 int32 top;
22 int32 right;
23 int32 bottom;
25 IntRect();
26 IntRect(const IntRect& r);
27 IntRect(const BRect& r);
28 IntRect(int32 l, int32 t, int32 r, int32 b);
29 IntRect(const IntPoint& lt,
30 const IntPoint& rb);
32 IntRect& operator=(const IntRect &r);
33 void Set(int32 l, int32 t, int32 r, int32 b);
35 void PrintToStream() const;
37 IntPoint LeftTop() const;
38 IntPoint RightBottom() const;
39 IntPoint LeftBottom() const;
40 IntPoint RightTop() const;
42 void SetLeftTop(const IntPoint& p);
43 void SetRightBottom(const IntPoint& p);
44 void SetLeftBottom(const IntPoint& p);
45 void SetRightTop(const IntPoint& p);
47 // transformation
48 void InsetBy(const IntPoint& p);
49 void InsetBy(int32 dx, int32 dy);
50 void OffsetBy(const IntPoint& p);
51 void OffsetBy(int32 dx, int32 dy);
52 void OffsetTo(const IntPoint& p);
53 void OffsetTo(int32 x, int32 y);
55 // expression transformations
56 IntRect& InsetBySelf(const IntPoint& p);
57 IntRect& InsetBySelf(int32 dx, int32 dy);
58 IntRect InsetByCopy(const IntPoint& p);
59 IntRect InsetByCopy(int32 dx, int32 dy);
60 IntRect& OffsetBySelf(const IntPoint& p);
61 IntRect& OffsetBySelf(int32 dx, int32 dy);
62 IntRect OffsetByCopy(const IntPoint& p);
63 IntRect OffsetByCopy(int32 dx, int32 dy);
64 IntRect& OffsetToSelf(const IntPoint& p);
65 IntRect& OffsetToSelf(int32 dx, int32 dy);
66 IntRect OffsetToCopy(const IntPoint& p);
67 IntRect OffsetToCopy(int32 dx, int32 dy);
69 // comparison
70 bool operator==(const IntRect& r) const;
71 bool operator!=(const IntRect& r) const;
73 // intersection and union
74 IntRect operator&(const IntRect& r) const;
75 IntRect operator|(const IntRect& r) const;
77 // conversion to BRect and clipping_rect
78 operator clipping_rect() const;
79 operator BRect() const
80 { return BRect(left, top,
81 right, bottom); }
83 bool Intersects(const IntRect& r) const;
84 bool IsValid() const;
85 int32 Width() const;
86 int32 IntegerWidth() const;
87 int32 Height() const;
88 int32 IntegerHeight() const;
89 bool Contains(const IntPoint& p) const;
90 bool Contains(const IntRect& r) const;
94 // inline definitions ----------------------------------------------------------
96 inline IntPoint
97 IntRect::LeftTop() const
99 return *(const IntPoint*)&left;
103 inline IntPoint
104 IntRect::RightBottom() const
106 return *(const IntPoint*)&right;
110 inline IntPoint
111 IntRect::LeftBottom() const
113 return IntPoint(left, bottom);
117 inline IntPoint
118 IntRect::RightTop() const
120 return IntPoint(right, top);
124 inline
125 IntRect::IntRect()
127 top = left = 0;
128 bottom = right = -1;
132 inline
133 IntRect::IntRect(int32 l, int32 t, int32 r, int32 b)
135 left = l;
136 top = t;
137 right = r;
138 bottom = b;
142 inline
143 IntRect::IntRect(const IntRect &r)
145 left = r.left;
146 top = r.top;
147 right = r.right;
148 bottom = r.bottom;
152 inline
153 IntRect::IntRect(const BRect &r)
155 left = (int32)r.left;
156 top = (int32)r.top;
157 right = (int32)r.right;
158 bottom = (int32)r.bottom;
162 inline
163 IntRect::IntRect(const IntPoint& leftTop, const IntPoint& rightBottom)
165 left = leftTop.x;
166 top = leftTop.y;
167 right = rightBottom.x;
168 bottom = rightBottom.y;
172 inline IntRect &
173 IntRect::operator=(const IntRect& from)
175 left = from.left;
176 top = from.top;
177 right = from.right;
178 bottom = from.bottom;
179 return *this;
183 inline void
184 IntRect::Set(int32 l, int32 t, int32 r, int32 b)
186 left = l;
187 top = t;
188 right = r;
189 bottom = b;
193 inline bool
194 IntRect::IsValid() const
196 return left <= right && top <= bottom;
200 inline int32
201 IntRect::IntegerWidth() const
203 return right - left;
207 inline int32
208 IntRect::Width() const
210 return right - left;
214 inline int32
215 IntRect::IntegerHeight() const
217 return bottom - top;
221 inline int32
222 IntRect::Height() const
224 return bottom - top;
227 inline
228 IntRect::operator clipping_rect() const
230 clipping_rect r;
231 r.left = left;
232 r.top = top;
233 r.right = right;
234 r.bottom = bottom;
235 return r;
239 #endif // INT_RECT_H