23 #ifndef BAGEL_BOFLIB_RECT_H 24 #define BAGEL_BOFLIB_RECT_H 26 #include "common/rect.h" 27 #include "bagel/boflib/stdinc.h" 28 #include "bagel/boflib/object.h" 29 #include "bagel/boflib/point.h" 30 #include "bagel/boflib/size.h" 41 CBofRect(
int l,
int t,
int r,
int b);
56 bool isRectEmpty()
const;
57 bool isRectNull()
const;
58 bool ptInRect(
const CBofPoint &point)
const;
62 inline void setRect(
int x1,
int y1,
int x2,
int y2);
64 void copyRect(
const CBofRect &cRect);
65 bool equalRect(
const CBofRect &cRect);
74 void setWinRect(
const RECT *pRect);
77 void operator=(
const RECT &srcRect) {
81 operator const RECT() {
85 void offsetRect(
int x,
int y);
86 void offsetRect(
const CBofSize &size);
95 void operator=(
const CBofRect &srcRect);
96 bool operator==(
const CBofRect &rect);
97 bool operator!=(
const CBofRect &rect);
100 void operator&=(
const CBofRect &rect);
101 void operator|=(
const CBofRect &rect);
115 inline CBofRect::CBofRect() {
120 inline CBofRect::CBofRect(
int l,
int t,
int r,
int b) {
127 inline CBofRect::CBofRect(
const CBofRect &srcRect) {
130 right = srcRect.right;
131 bottom = srcRect.bottom;
135 right = (left = point.x) + size.cx - 1;
136 bottom = (top = point.y) + size.cy - 1;
139 inline CBofRect::CBofRect(
const CBofPoint &pttopLeft,
const CBofPoint &ptBottomRight) {
140 setRect(pttopLeft.x, pttopLeft.y, ptBottomRight.x, ptBottomRight.y);
143 inline int CBofRect::width()
const {
145 assert(isValidObject(
this));
147 return right - left + 1;
150 inline int CBofRect::height()
const {
152 assert(isValidObject(
this));
154 return bottom - top + 1;
157 inline CBofSize CBofRect::size()
const {
159 assert(isValidObject(
this));
164 inline CBofPoint CBofRect::topLeft()
const {
166 assert(isValidObject(
this));
171 inline CBofPoint CBofRect::bottomRight()
const {
173 assert(isValidObject(
this));
178 inline CBofPoint CBofRect::topRight()
const {
180 assert(isValidObject(
this));
185 inline CBofPoint CBofRect::bottomLeft()
const {
187 assert(isValidObject(
this));
192 inline bool CBofRect::isRectEmpty()
const {
194 assert(isValidObject(
this));
196 return (width() <= 0 || height() <= 0);
199 inline bool CBofRect::isRectNull()
const {
201 assert(isValidObject(
this));
203 return (left == 0 && right == 0 && top == 0 && bottom == 0);
206 inline bool CBofRect::ptInRect(
const CBofPoint &point)
const {
208 assert(isValidObject(
this));
210 return (point.x >= left && point.x <= right && point.y >= top && point.y <= bottom);
213 inline void CBofRect::setRect(
int x1,
int y1,
int x2,
int y2) {
215 assert(isValidObject(
this));
223 inline void CBofRect::setRectEmpty() {
225 assert(isValidObject(
this));
231 assert(isRectEmpty());
234 inline void CBofRect::copyRect(
const CBofRect &cSrcRect) {
236 assert(isValidObject(
this));
238 assert(isValidObject(&cSrcRect));
240 left = cSrcRect.left;
241 right = cSrcRect.right;
243 bottom = cSrcRect.bottom;
246 inline bool CBofRect::equalRect(
const CBofRect &cRect) {
248 assert(isValidObject(
this));
250 assert(isValidObject(&cRect));
252 return (left == cRect.left && right == cRect.right && top == cRect.top && bottom == cRect.bottom);
255 inline RECT CBofRect::getWinRect() {
256 assert(isValidObject(
this));
262 stRect.
right = right + 1;
263 stRect.bottom = bottom + 1;
268 inline void CBofRect::setWinRect(
const RECT *pRect) {
269 assert(isValidObject(
this));
271 assert(pRect !=
nullptr);
275 right = pRect->
right - 1;
276 bottom = pRect->bottom - 1;
279 inline void CBofRect::offsetRect(
int x,
int y) {
281 assert(isValidObject(
this));
289 inline void CBofRect::offsetRect(
const CBofPoint &point) {
291 assert(isValidObject(
this));
299 inline void CBofRect::offsetRect(
const CBofSize &size) {
301 assert(isValidObject(
this));
309 inline bool CBofRect::intersectRect(
const CBofRect *pRect1,
const CBofRect *pRect2) {
311 assert(isValidObject(
this));
314 assert(pRect1 !=
nullptr);
315 assert(pRect2 !=
nullptr);
317 left =
MAX(pRect1->left, pRect2->left);
318 top =
MAX(pRect1->top, pRect2->top);
319 right =
MIN(pRect1->right, pRect2->right);
320 bottom =
MIN(pRect1->bottom, pRect2->bottom);
322 return ((width() > 0) && (height() > 0));
325 inline bool CBofRect::intersectRect(
const CBofRect &cRect1,
const CBofRect &cRect2) {
327 assert(isValidObject(
this));
329 return intersectRect(&cRect1, &cRect2);
332 inline bool CBofRect::unionRect(
const CBofRect *pRect1,
const CBofRect *pRect2) {
334 assert(isValidObject(
this));
337 assert(pRect1 !=
nullptr);
338 assert(pRect2 !=
nullptr);
340 left =
MIN(pRect1->left, pRect2->left);
341 top =
MIN(pRect1->top, pRect2->top);
342 right =
MAX(pRect1->right, pRect2->right);
343 bottom =
MAX(pRect1->bottom, pRect2->bottom);
345 return isRectEmpty();
348 inline void CBofRect::operator=(
const CBofRect &srcRect) {
350 assert(isValidObject(
this));
353 right = srcRect.right;
355 bottom = srcRect.bottom;
358 inline bool CBofRect::operator==(
const CBofRect &rect) {
360 assert(isValidObject(
this));
362 return (left == rect.left && right == rect.right &&
363 top == rect.top && bottom == rect.bottom);
366 inline bool CBofRect::operator!=(
const CBofRect &rect) {
368 assert(isValidObject(
this));
370 return (left != rect.left || right != rect.right ||
371 top != rect.top || bottom != rect.bottom);
374 inline void CBofRect::operator+=(
const CBofPoint &point) {
376 assert(isValidObject(
this));
381 inline void CBofRect::operator-=(
const CBofPoint &point) {
383 assert(isValidObject(
this));
385 offsetRect(-point.x, -point.y);
388 inline void CBofRect::operator&=(
const CBofRect &rect) {
390 assert(isValidObject(
this));
392 intersectRect(
this, &rect);
395 inline void CBofRect::operator|=(
const CBofRect &rect) {
397 assert(isValidObject(
this));
399 unionRect(
this, &rect);
404 assert(isValidObject(
this));
408 rect.offsetRect(pt.x, pt.y);
415 assert(isValidObject(
this));
419 rect.offsetRect(-pt.x, -pt.y);
426 assert(isValidObject(
this));
430 rect.intersectRect(
this, &rect2);
437 assert(isValidObject(
this));
441 rect.unionRect(
this, &rect2);
446 #define CRect CBofRect
int16 right
Definition: rect.h:146
int16 left
Definition: rect.h:145
T MIN(T a, T b)
Definition: util.h:59
T MAX(T a, T b)
Definition: util.h:62