23 #ifndef BAGEL_BOFLIB_RECT_H 24 #define BAGEL_BOFLIB_RECT_H 26 #include "common/rect.h" 27 #include "bagel/afxwin.h" 28 #include "bagel/boflib/stdinc.h" 29 #include "bagel/boflib/object.h" 30 #include "bagel/boflib/point.h" 31 #include "bagel/boflib/size.h" 39 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 const RECT r = { srcRect.
left, srcRect.top, srcRect.
right, srcRect.bottom };
85 operator const RECT() {
92 void offsetRect(
int x,
int y);
93 void offsetRect(
const CBofSize &size);
102 void operator=(
const CBofRect &srcRect);
103 bool operator==(
const CBofRect &rect);
104 bool operator!=(
const CBofRect &rect);
107 void operator&=(
const CBofRect &rect);
108 void operator|=(
const CBofRect &rect);
122 inline CBofRect::CBofRect() {
127 inline CBofRect::CBofRect(
int l,
int t,
int r,
int b) {
134 inline CBofRect::CBofRect(
const CBofRect &srcRect) {
137 right = srcRect.right;
138 bottom = srcRect.bottom;
142 right = (left = point.x) + size.cx - 1;
143 bottom = (top = point.y) + size.cy - 1;
146 inline CBofRect::CBofRect(
const CBofPoint &pttopLeft,
const CBofPoint &ptBottomRight) {
147 setRect(pttopLeft.x, pttopLeft.y, ptBottomRight.x, ptBottomRight.y);
150 inline int CBofRect::width()
const {
152 assert(isValidObject(
this));
154 return right - left + 1;
157 inline int CBofRect::height()
const {
159 assert(isValidObject(
this));
161 return bottom - top + 1;
164 inline CBofSize CBofRect::size()
const {
166 assert(isValidObject(
this));
171 inline CBofPoint CBofRect::topLeft()
const {
173 assert(isValidObject(
this));
178 inline CBofPoint CBofRect::bottomRight()
const {
180 assert(isValidObject(
this));
185 inline CBofPoint CBofRect::topRight()
const {
187 assert(isValidObject(
this));
192 inline CBofPoint CBofRect::bottomLeft()
const {
194 assert(isValidObject(
this));
199 inline bool CBofRect::isRectEmpty()
const {
201 assert(isValidObject(
this));
203 return (width() <= 0 || height() <= 0);
206 inline bool CBofRect::isRectNull()
const {
208 assert(isValidObject(
this));
210 return (left == 0 && right == 0 && top == 0 && bottom == 0);
213 inline bool CBofRect::ptInRect(
const CBofPoint &point)
const {
215 assert(isValidObject(
this));
217 return (point.x >= left && point.x <= right && point.y >= top && point.y <= bottom);
220 inline void CBofRect::setRect(
int x1,
int y1,
int x2,
int y2) {
222 assert(isValidObject(
this));
230 inline void CBofRect::setRectEmpty() {
232 assert(isValidObject(
this));
238 assert(isRectEmpty());
241 inline void CBofRect::copyRect(
const CBofRect &cSrcRect) {
243 assert(isValidObject(
this));
245 assert(isValidObject(&cSrcRect));
247 left = cSrcRect.left;
248 right = cSrcRect.right;
250 bottom = cSrcRect.bottom;
253 inline bool CBofRect::equalRect(
const CBofRect &cRect) {
255 assert(isValidObject(
this));
257 assert(isValidObject(&cRect));
259 return (left == cRect.left && right == cRect.right && top == cRect.top && bottom == cRect.bottom);
262 inline RECT CBofRect::getWinRect() {
263 assert(isValidObject(
this));
269 stRect.right = right + 1;
270 stRect.bottom = bottom + 1;
275 inline void CBofRect::setWinRect(
const RECT *pRect) {
276 assert(isValidObject(
this));
278 assert(pRect !=
nullptr);
282 right = pRect->right - 1;
283 bottom = pRect->bottom - 1;
286 inline void CBofRect::offsetRect(
int x,
int y) {
288 assert(isValidObject(
this));
296 inline void CBofRect::offsetRect(
const CBofPoint &point) {
298 assert(isValidObject(
this));
306 inline void CBofRect::offsetRect(
const CBofSize &size) {
308 assert(isValidObject(
this));
316 inline bool CBofRect::intersectRect(
const CBofRect *pRect1,
const CBofRect *pRect2) {
318 assert(isValidObject(
this));
321 assert(pRect1 !=
nullptr);
322 assert(pRect2 !=
nullptr);
324 left =
MAX(pRect1->left, pRect2->left);
325 top =
MAX(pRect1->top, pRect2->top);
326 right =
MIN(pRect1->right, pRect2->right);
327 bottom =
MIN(pRect1->bottom, pRect2->bottom);
329 return ((width() > 0) && (height() > 0));
332 inline bool CBofRect::intersectRect(
const CBofRect &cRect1,
const CBofRect &cRect2) {
334 assert(isValidObject(
this));
336 return intersectRect(&cRect1, &cRect2);
339 inline bool CBofRect::unionRect(
const CBofRect *pRect1,
const CBofRect *pRect2) {
341 assert(isValidObject(
this));
344 assert(pRect1 !=
nullptr);
345 assert(pRect2 !=
nullptr);
347 left =
MIN(pRect1->left, pRect2->left);
348 top =
MIN(pRect1->top, pRect2->top);
349 right =
MAX(pRect1->right, pRect2->right);
350 bottom =
MAX(pRect1->bottom, pRect2->bottom);
352 return isRectEmpty();
355 inline void CBofRect::operator=(
const CBofRect &srcRect) {
357 assert(isValidObject(
this));
360 right = srcRect.right;
362 bottom = srcRect.bottom;
365 inline bool CBofRect::operator==(
const CBofRect &rect) {
367 assert(isValidObject(
this));
369 return (left == rect.left && right == rect.right &&
370 top == rect.top && bottom == rect.bottom);
373 inline bool CBofRect::operator!=(
const CBofRect &rect) {
375 assert(isValidObject(
this));
377 return (left != rect.left || right != rect.right ||
378 top != rect.top || bottom != rect.bottom);
381 inline void CBofRect::operator+=(
const CBofPoint &point) {
383 assert(isValidObject(
this));
388 inline void CBofRect::operator-=(
const CBofPoint &point) {
390 assert(isValidObject(
this));
392 offsetRect(-point.x, -point.y);
395 inline void CBofRect::operator&=(
const CBofRect &rect) {
397 assert(isValidObject(
this));
399 intersectRect(
this, &rect);
402 inline void CBofRect::operator|=(
const CBofRect &rect) {
404 assert(isValidObject(
this));
406 unionRect(
this, &rect);
411 assert(isValidObject(
this));
415 rect.offsetRect(pt.x, pt.y);
422 assert(isValidObject(
this));
426 rect.offsetRect(-pt.x, -pt.y);
433 assert(isValidObject(
this));
437 rect.intersectRect(
this, &rect2);
444 assert(isValidObject(
this));
448 rect.unionRect(
this, &rect2);
T left
Definition: rect.h:170
T right
Definition: rect.h:171
Definition: minwindef.h:179
T MIN(T a, T b)
Definition: util.h:61
T MAX(T a, T b)
Definition: util.h:64