3 #include "ParaMargins.h" 19 QRect() : x1(0), y1(0), x2(-1), y2(-1) {}
22 QRect(int32 left, int32 top, int32 width, int32 height);
23 QRect(
const RECT& r) :x1(r.left), y1(r.top), x2(r.right-1), y2(r.bottom-1) {}
26 inline operator RECT()
const{
27 RECT r = { x1, y1, x1 + width(), y1 + height() };
31 inline bool isNull()
const;
32 inline bool isEmpty()
const;
33 inline bool isValid()
const;
35 inline int32 left()
const;
36 inline int32 top()
const;
37 inline int32 right()
const;
38 inline int32 bottom()
const;
39 QRect normalized()
const;
41 inline int32 x()
const;
42 inline int32 y()
const;
43 inline void setLeft(int32 pos);
44 inline void setTop(int32 pos);
45 inline void setRight(int32 pos);
46 inline void setBottom(int32 pos);
47 inline void setX(int32 x);
48 inline void setY(int32 y);
50 inline void setTopLeft(
const QPoint &p);
51 inline void setBottomRight(
const QPoint &p);
52 inline void setTopRight(
const QPoint &p);
53 inline void setBottomLeft(
const QPoint &p);
55 inline QPoint topLeft()
const;
56 inline QPoint bottomRight()
const;
57 inline QPoint topRight()
const;
58 inline QPoint bottomLeft()
const;
59 inline QPoint center()
const;
61 inline void moveLeft(int32 pos);
62 inline void moveTop(int32 pos);
63 inline void moveRight(int32 pos);
64 inline void moveBottom(int32 pos);
65 inline void moveTopLeft(
const QPoint &p);
66 inline void moveBottomRight(
const QPoint &p);
67 inline void moveTopRight(
const QPoint &p);
68 inline void moveBottomLeft(
const QPoint &p);
69 inline void moveCenter(
const QPoint &p);
71 inline void translate(int32 dx, int32 dy);
72 inline void translate(
const QPoint &p);
73 inline QRect translated(int32 dx, int32 dy)
const;
76 inline void moveTo(int32 x, int32 t);
77 inline void moveTo(
const QPoint &p);
79 inline void setRect(int32 x, int32 y, int32 w, int32 h);
80 inline void getRect(int32 *x, int32 *y, int32 *w, int32 *h)
const;
82 inline void setCoords(int32 x1, int32 y1, int32 x2, int32 y2);
83 inline void getCoords(int32 *x1, int32 *y1, int32 *x2, int32 *y2)
const;
85 inline void adjust(int32 x1, int32 y1, int32 x2, int32 y2);
86 inline QRect adjusted(int32 x1, int32 y1, int32 x2, int32 y2)
const;
88 inline QSize size()
const;
89 inline int32 width()
const;
90 inline int32 height()
const;
91 inline void setWidth(int32 w);
92 inline void setHeight(int32 h);
93 inline void setSize(
const QSize &s);
100 bool contains(
const QRect &r,
bool proper =
false)
const;
101 bool contains(
const QPoint &p,
bool proper =
false)
const;
102 inline bool contains(int32 x, int32 y)
const;
103 inline bool contains(int32 x, int32 y,
bool proper)
const;
105 inline QRect intersected(
const QRect &other)
const;
106 bool intersects(
const QRect &r)
const;
114 friend inline bool operator==(
const QRect &,
const QRect &);
115 friend inline bool operator!=(
const QRect &,
const QRect &);
123 inline bool operator==(
const QRect &,
const QRect &);
124 inline bool operator!=(
const QRect &,
const QRect &);
130 inline QRect::QRect(int32 aleft, int32 atop, int32 awidth, int32 aheight)
131 : x1(aleft), y1(atop), x2(aleft + awidth - 1), y2(atop + aheight - 1) {}
133 inline QRect::QRect(
const QPoint &atopLeft,
const QPoint &abottomRight)
134 : x1(atopLeft.x()), y1(atopLeft.y()), x2(abottomRight.x()), y2(abottomRight.y()) {}
136 inline QRect::QRect(
const QPoint &atopLeft,
const QSize &asize)
137 : x1(atopLeft.x()), y1(atopLeft.y()), x2(atopLeft.x() + asize.width() - 1), y2(atopLeft.y() + asize.height() - 1) {}
139 inline bool QRect::isNull()
const 141 return x2 == x1 - 1 && y2 == y1 - 1;
144 inline bool QRect::isEmpty()
const 146 return x1 > x2 || y1 > y2;
149 inline bool QRect::isValid()
const 151 return x1 <= x2 && y1 <= y2;
154 inline int32 QRect::left()
const 159 inline int32 QRect::top()
const 164 inline int32 QRect::right()
const 169 inline int32 QRect::bottom()
const 174 inline int32 QRect::x()
const 179 inline int32 QRect::y()
const 184 inline void QRect::setLeft(int32 pos)
189 inline void QRect::setTop(int32 pos)
194 inline void QRect::setRight(int32 pos)
199 inline void QRect::setBottom(int32 pos)
204 inline void QRect::setTopLeft(
const QPoint &p)
206 x1 = p.x(); y1 = p.y();
209 inline void QRect::setBottomRight(
const QPoint &p)
211 x2 = p.x(); y2 = p.y();
214 inline void QRect::setTopRight(
const QPoint &p)
216 x2 = p.x(); y1 = p.y();
219 inline void QRect::setBottomLeft(
const QPoint &p)
221 x1 = p.x(); y2 = p.y();
224 inline void QRect::setX(int32 ax)
229 inline void QRect::setY(int32 ay)
234 inline QPoint QRect::topLeft()
const 239 inline QPoint QRect::bottomRight()
const 244 inline QPoint QRect::topRight()
const 249 inline QPoint QRect::bottomLeft()
const 254 inline QPoint QRect::center()
const 256 return QPoint((x1 + x2) / 2, (y1 + y2) / 2);
259 inline int32 QRect::width()
const 264 inline int32 QRect::height()
const 269 inline QSize QRect::size()
const 271 return QSize(width(), height());
274 inline void QRect::translate(int32 dx, int32 dy)
282 inline void QRect::translate(
const QPoint &p)
290 inline QRect QRect::translated(int32 dx, int32 dy)
const 295 inline QRect QRect::translated(
const QPoint &p)
const 300 inline void QRect::moveTo(int32 ax, int32 ay)
308 inline void QRect::moveTo(
const QPoint &p)
316 inline void QRect::moveLeft(int32 pos)
318 x2 += (pos - x1); x1 = pos;
321 inline void QRect::moveTop(int32 pos)
323 y2 += (pos - y1); y1 = pos;
326 inline void QRect::moveRight(int32 pos)
332 inline void QRect::moveBottom(int32 pos)
338 inline void QRect::moveTopLeft(
const QPoint &p)
344 inline void QRect::moveBottomRight(
const QPoint &p)
350 inline void QRect::moveTopRight(
const QPoint &p)
356 inline void QRect::moveBottomLeft(
const QPoint &p)
362 inline void QRect::moveCenter(
const QPoint &p)
372 inline void QRect::getRect(int32 *ax, int32 *ay, int32 *aw, int32 *ah)
const 380 inline void QRect::setRect(int32 ax, int32 ay, int32 aw, int32 ah)
388 inline void QRect::getCoords(int32 *xp1, int32 *yp1, int32 *xp2, int32 *yp2)
const 396 inline void QRect::setCoords(int32 xp1, int32 yp1, int32 xp2, int32 yp2)
404 inline QRect QRect::adjusted(int32 xp1, int32 yp1, int32 xp2, int32 yp2)
const 409 inline void QRect::adjust(int32 dx1, int32 dy1, int32 dx2, int32 dy2)
417 inline void QRect::setWidth(int32 w)
422 inline void QRect::setHeight(int32 h)
427 inline void QRect::setSize(
const QSize &s)
429 x2 = (s.width() + x1 - 1);
430 y2 = (s.height() + y1 - 1);
433 inline bool QRect::contains(int32 ax, int32 ay,
bool aproper)
const 435 return contains(
QPoint(ax, ay), aproper);
438 inline bool QRect::contains(int32 ax, int32 ay)
const 440 return contains(
QPoint(ax, ay),
false);
443 inline QRect& QRect::operator|=(
const QRect &r)
449 inline QRect& QRect::operator&=(
const QRect &r)
457 return *
this & other;
460 inline QRect QRect::united(
const QRect &r)
const 465 inline bool operator==(
const QRect &r1,
const QRect &r2)
467 return r1.x1 == r2.x1 && r1.x2 == r2.x2 && r1.y1 == r2.y1 && r1.y2 == r2.y2;
470 inline bool operator!=(
const QRect &r1,
const QRect &r2)
472 return r1.x1 != r2.x1 || r1.x2 != r2.x2 || r1.y1 != r2.y1 || r1.y2 != r2.y2;
477 return QRect(
QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
478 QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
483 return QRect(
QPoint(rectangle.left() - margins.left(), rectangle.top() - margins.top()),
484 QPoint(rectangle.right() + margins.right(), rectangle.bottom() + margins.bottom()));
489 return QRect(
QPoint(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
490 QPoint(lhs.right() - rhs.right(), lhs.bottom() - rhs.bottom()));
493 inline QRect QRect::marginsAdded(
const QMargins &margins)
const 495 return QRect(
QPoint(x1 - margins.left(), y1 - margins.top()),
496 QPoint(x2 + margins.right(), y2 + margins.bottom()));
499 inline QRect QRect::marginsRemoved(
const QMargins &margins)
const 501 return QRect(
QPoint(x1 + margins.left(), y1 + margins.top()),
502 QPoint(x2 - margins.right(), y2 - margins.bottom()));
507 *
this = marginsAdded(margins);
513 *
this = marginsRemoved(margins);
520 QRectF() : xp(0.), yp(0.), w(0.), h(0.) {}
523 QRectF(
float left,
float top,
float width,
float height);
525 inline explicit QRectF(
const RECT& r) :xp((
float)r.left), yp((
float)r.top), w((
float)(r.right - r.left)), h((
float)(r.bottom - r.top)) {}
527 inline operator RECT()
const{
528 RECT r = { (int)x(), (int)y(), (int)right(), (int)bottom() };
532 inline bool isNull()
const;
533 inline bool isEmpty()
const;
534 inline bool isValid()
const;
535 QRectF normalized()
const;
537 inline float left()
const {
return xp; }
538 inline float top()
const {
return yp; }
539 inline float right()
const {
return xp + w; }
540 inline float bottom()
const {
return yp + h; }
542 inline float x()
const;
543 inline float y()
const;
544 inline void setLeft(
float pos);
545 inline void setTop(
float pos);
546 inline void setRight(
float pos);
547 inline void setBottom(
float pos);
548 inline void setX(
float pos) { setLeft(pos); }
549 inline void setY(
float pos) { setTop(pos); }
552 inline QPointF bottomRight()
const {
return QPointF(xp + w, yp + h); }
557 inline void setTopLeft(
const QPointF &p);
558 inline void setBottomRight(
const QPointF &p);
559 inline void setTopRight(
const QPointF &p);
560 inline void setBottomLeft(
const QPointF &p);
562 inline void moveLeft(
float pos);
563 inline void moveTop(
float pos);
564 inline void moveRight(
float pos);
565 inline void moveBottom(
float pos);
566 inline void moveTopLeft(
const QPointF &p);
567 inline void moveBottomRight(
const QPointF &p);
568 inline void moveTopRight(
const QPointF &p);
569 inline void moveBottomLeft(
const QPointF &p);
570 inline void moveCenter(
const QPointF &p);
572 inline void translate(
float dx,
float dy);
573 inline void translate(
const QPointF &p);
575 inline QRectF translated(
float dx,
float dy)
const;
578 inline void moveTo(
float x,
float y);
579 inline void moveTo(
const QPointF &p);
581 inline void setRect(
float x,
float y,
float w,
float h);
582 inline void getRect(
float *x,
float *y,
float *w,
float *h)
const;
584 inline void setCoords(
float x1,
float y1,
float x2,
float y2);
585 inline void getCoords(
float *x1,
float *y1,
float *x2,
float *y2)
const;
587 inline void adjust(
float x1,
float y1,
float x2,
float y2);
588 inline QRectF adjusted(
float x1,
float y1,
float x2,
float y2)
const;
590 inline QSizeF size()
const;
591 inline float width()
const;
592 inline float height()
const;
593 inline void setWidth(
float w);
594 inline void setHeight(
float h);
595 inline void setSize(
const QSizeF &s);
602 bool contains(
const QRectF &r)
const;
603 bool contains(
const QPointF &p)
const;
604 inline bool contains(
float x,
float y)
const;
607 bool intersects(
const QRectF &r)
const;
614 friend inline bool operator==(
const QRectF &,
const QRectF &);
615 friend inline bool operator!=(
const QRectF &,
const QRectF &);
617 inline QRect toRect()
const;
618 QRect toAlignedRect()
const;
634 inline QRectF::QRectF(
float aleft,
float atop,
float awidth,
float aheight)
635 : xp(aleft), yp(atop), w(awidth), h(aheight)
639 inline QRectF::QRectF(
const QPointF &atopLeft,
const QSizeF &asize)
640 : xp(atopLeft.x()), yp(atopLeft.y()), w(asize.width()), h(asize.height())
645 inline QRectF::QRectF(
const QPointF &atopLeft,
const QPointF &abottomRight)
646 : xp(atopLeft.x()), yp(atopLeft.y()), w(abottomRight.x() - atopLeft.x()), h(abottomRight.y() - atopLeft.y())
650 inline QRectF::QRectF(
const QRect &r)
651 : xp((
float)r.x()), yp((
float)r.y()), w((
float)r.width()), h((
float)r.height())
655 inline bool QRectF::isNull()
const 657 return w == 0. && h == 0.;
660 inline bool QRectF::isEmpty()
const 662 return w <= 0. || h <= 0.;
665 inline bool QRectF::isValid()
const 667 return w > 0. && h > 0.;
670 inline float QRectF::x()
const 675 inline float QRectF::y()
const 680 inline void QRectF::setLeft(
float pos) {
float diff = pos - xp; xp += diff; w -= diff; }
682 inline void QRectF::setRight(
float pos) { w = pos - xp; }
684 inline void QRectF::setTop(
float pos) {
float diff = pos - yp; yp += diff; h -= diff; }
686 inline void QRectF::setBottom(
float pos) { h = pos - yp; }
688 inline void QRectF::setTopLeft(
const QPointF &p) { setLeft(p.x()); setTop(p.y()); }
690 inline void QRectF::setTopRight(
const QPointF &p) { setRight(p.x()); setTop(p.y()); }
692 inline void QRectF::setBottomLeft(
const QPointF &p) { setLeft(p.x()); setBottom(p.y()); }
694 inline void QRectF::setBottomRight(
const QPointF &p) { setRight(p.x()); setBottom(p.y()); }
696 inline QPointF QRectF::center()
const 698 return QPointF(xp + w / 2, yp + h / 2);
701 inline void QRectF::moveLeft(
float pos) { xp = pos; }
703 inline void QRectF::moveTop(
float pos) { yp = pos; }
705 inline void QRectF::moveRight(
float pos) { xp = pos - w; }
707 inline void QRectF::moveBottom(
float pos) { yp = pos - h; }
709 inline void QRectF::moveTopLeft(
const QPointF &p) { moveLeft(p.x()); moveTop(p.y()); }
711 inline void QRectF::moveTopRight(
const QPointF &p) { moveRight(p.x()); moveTop(p.y()); }
713 inline void QRectF::moveBottomLeft(
const QPointF &p) { moveLeft(p.x()); moveBottom(p.y()); }
715 inline void QRectF::moveBottomRight(
const QPointF &p) { moveRight(p.x()); moveBottom(p.y()); }
717 inline void QRectF::moveCenter(
const QPointF &p) { xp = p.x() - w / 2; yp = p.y() - h / 2; }
719 inline float QRectF::width()
const 724 inline float QRectF::height()
const 729 inline QSizeF QRectF::size()
const 734 inline void QRectF::translate(
float dx,
float dy)
740 inline void QRectF::translate(
const QPointF &p)
746 inline void QRectF::moveTo(
float ax,
float ay)
752 inline void QRectF::moveTo(
const QPointF &p)
758 inline QRectF QRectF::translated(
float dx,
float dy)
const 760 return QRectF(xp + dx, yp + dy, w, h);
765 return QRectF(xp + p.x(), yp + p.y(), w, h);
768 inline void QRectF::getRect(
float *ax,
float *ay,
float *aaw,
float *aah)
const 776 inline void QRectF::setRect(
float ax,
float ay,
float aaw,
float aah)
784 inline void QRectF::getCoords(
float *xp1,
float *yp1,
float *xp2,
float *yp2)
const 792 inline void QRectF::setCoords(
float xp1,
float yp1,
float xp2,
float yp2)
800 inline void QRectF::adjust(
float xp1,
float yp1,
float xp2,
float yp2)
802 xp += xp1; yp += yp1; w += xp2 - xp1; h += yp2 - yp1;
805 inline QRectF QRectF::adjusted(
float xp1,
float yp1,
float xp2,
float yp2)
const 807 return QRectF(xp + xp1, yp + yp1, w + xp2 - xp1, h + yp2 - yp1);
810 inline void QRectF::setWidth(
float aw)
815 inline void QRectF::setHeight(
float ah)
820 inline void QRectF::setSize(
const QSizeF &s)
828 return contains(
QPointF(ax, ay));
843 inline QRectF QRectF::intersected(
const QRectF &r)
const 853 inline bool operator==(
const QRectF &r1,
const QRectF &r2)
855 return Math::FuzzyCompare(r1.xp, r2.xp) && Math::FuzzyCompare(r1.yp, r2.yp)
856 && Math::FuzzyCompare(r1.w, r2.w) && Math::FuzzyCompare(r1.h, r2.h);
859 inline bool operator!=(
const QRectF &r1,
const QRectF &r2)
861 return !Math::FuzzyCompare(r1.xp, r2.xp) || !Math::FuzzyCompare(r1.yp, r2.yp)
862 || !Math::FuzzyCompare(r1.w, r2.w) || !Math::FuzzyCompare(r1.h, r2.h);
865 inline QRect QRectF::toRect()
const 872 return QRectF(
QPointF(lhs.left() - rhs.left(), lhs.top() - rhs.top()),
873 QSizeF(lhs.width() + rhs.left() + rhs.right(), lhs.height() + rhs.top() + rhs.bottom()));
878 return QRectF(
QPointF(rhs.left() - lhs.left(), rhs.top() - lhs.top()),
879 QSizeF(rhs.width() + lhs.left() + lhs.right(), rhs.height() + lhs.top() + lhs.bottom()));
884 return QRectF(
QPointF(lhs.left() + rhs.left(), lhs.top() + rhs.top()),
885 QSizeF(lhs.width() - rhs.left() - rhs.right(), lhs.height() - rhs.top() - rhs.bottom()));
890 return QRectF(
QPointF(xp - margins.left(), yp - margins.top()),
891 QSizeF(w + margins.left() + margins.right(), h + margins.top() + margins.bottom()));
896 return QRectF(
QPointF(xp + margins.left(), yp + margins.top()),
897 QSizeF(w - margins.left() - margins.right(), h - margins.top() - margins.bottom()));
902 *
this = marginsAdded(margins);
908 *
this = marginsRemoved(margins);
static int Round(float fValue)
get the closest integer near the specified float number.
Definition: ParaMath.h:609
Definition: ParaPoint.h:203
Definition: ParaSize.h:195
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: ManagedDef.h:18
Definition: ParaRect.h:517
when concerting QRect with QRectF and RECT, we ensure that their left, top and width, height are the same.
Definition: ParaRect.h:16
Definition: ParaMargins.h:5
Definition: ParaMargins.h:242
Definition: ParaPoint.h:5
bool contains(const QRectF &r) const
Definition: ParaRect.cpp:360
QRect operator|(const QRect &r) const
Definition: ParaRect.cpp:139
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: ParaSize.h:9