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);
122inline CBofRect::CBofRect() {
127inline CBofRect::CBofRect(
int l,
int t,
int r,
int b) {
134inline CBofRect::CBofRect(
const CBofRect &srcRect) {
137 right = srcRect.right;
138 bottom = srcRect.bottom;
141inline CBofRect::CBofRect(
const CBofPoint &point,
const CBofSize &size) {
142 right = (left = point.x) + size.cx - 1;
143 bottom = (top = point.y) + size.cy - 1;
146inline CBofRect::CBofRect(
const CBofPoint &pttopLeft,
const CBofPoint &ptBottomRight) {
147 setRect(pttopLeft.x, pttopLeft.y, ptBottomRight.x, ptBottomRight.y);
150inline int CBofRect::width()
const {
152 assert(isValidObject(
this));
154 return right - left + 1;
157inline int CBofRect::height()
const {
159 assert(isValidObject(
this));
161 return bottom - top + 1;
164inline CBofSize CBofRect::size()
const {
166 assert(isValidObject(
this));
168 return CBofSize(width(), height());
171inline CBofPoint CBofRect::topLeft()
const {
173 assert(isValidObject(
this));
175 return CBofPoint(left, top);
178inline CBofPoint CBofRect::bottomRight()
const {
180 assert(isValidObject(
this));
182 return CBofPoint(right, bottom);
185inline CBofPoint CBofRect::topRight()
const {
187 assert(isValidObject(
this));
189 return CBofPoint(right, top);
192inline CBofPoint CBofRect::bottomLeft()
const {
194 assert(isValidObject(
this));
196 return CBofPoint(left, bottom);
199inline bool CBofRect::isRectEmpty()
const {
201 assert(isValidObject(
this));
203 return (width() <= 0 || height() <= 0);
206inline bool CBofRect::isRectNull()
const {
208 assert(isValidObject(
this));
210 return (left == 0 && right == 0 && top == 0 && bottom == 0);
213inline 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);
220inline void CBofRect::setRect(
int x1,
int y1,
int x2,
int y2) {
222 assert(isValidObject(
this));
230inline void CBofRect::setRectEmpty() {
232 assert(isValidObject(
this));
238 assert(isRectEmpty());
241inline 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;
253inline 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);
262inline RECT CBofRect::getWinRect() {
263 assert(isValidObject(
this));
269 stRect.right = right + 1;
270 stRect.bottom = bottom + 1;
275inline void CBofRect::setWinRect(
const RECT *pRect) {
276 assert(isValidObject(
this));
278 assert(pRect !=
nullptr);
282 right = pRect->right - 1;
283 bottom = pRect->bottom - 1;
286inline void CBofRect::offsetRect(
int x,
int y) {
288 assert(isValidObject(
this));
296inline void CBofRect::offsetRect(
const CBofPoint &point) {
298 assert(isValidObject(
this));
306inline void CBofRect::offsetRect(
const CBofSize &size) {
308 assert(isValidObject(
this));
316inline 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));
332inline bool CBofRect::intersectRect(
const CBofRect &cRect1,
const CBofRect &cRect2) {
334 assert(isValidObject(
this));
336 return intersectRect(&cRect1, &cRect2);
339inline 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();
355inline void CBofRect::operator=(
const CBofRect &srcRect) {
357 assert(isValidObject(
this));
360 right = srcRect.right;
362 bottom = srcRect.bottom;
365inline 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);
373inline 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);
381inline void CBofRect::operator+=(
const CBofPoint &point) {
383 assert(isValidObject(
this));
388inline void CBofRect::operator-=(
const CBofPoint &point) {
390 assert(isValidObject(
this));
392 offsetRect(-point.x, -point.y);
395inline void CBofRect::operator&=(
const CBofRect &rect) {
397 assert(isValidObject(
this));
399 intersectRect(
this, &rect);
402inline void CBofRect::operator|=(
const CBofRect &rect) {
404 assert(isValidObject(
this));
406 unionRect(
this, &rect);
409inline CBofRect CBofRect::operator+(
const CBofPoint &pt) {
411 assert(isValidObject(
this));
413 CBofRect rect(*
this);
415 rect.offsetRect(pt.x, pt.y);
420inline CBofRect CBofRect::operator-(
const CBofPoint &pt) {
422 assert(isValidObject(
this));
424 CBofRect rect(*
this);
426 rect.offsetRect(-pt.x, -pt.y);
431inline CBofRect CBofRect::operator&(
const CBofRect &rect2) {
433 assert(isValidObject(
this));
437 rect.intersectRect(
this, &rect2);
442inline CBofRect CBofRect::operator|(
const CBofRect &rect2) {
444 assert(isValidObject(
this));
448 rect.unionRect(
this, &rect2);
T MIN(T a, T b)
Definition: util.h:63
T MAX(T a, T b)
Definition: util.h:66
T right
Definition: rect.h:171
T left
Definition: rect.h:170
Definition: minwindef.h:179