ScummVM API documentation
rect32.h
1 /* ScummVM - Graphic Adventure Engine
2  *
3  * ScummVM is the legal property of its developers, whose names
4  * are too numerous to list here. Please refer to the COPYRIGHT
5  * file distributed with this source distribution.
6  *
7  * This program is free software: you can redistribute it and/or modify
8  * it under the terms of the GNU General Public License as published by
9  * the Free Software Foundation, either version 3 of the License, or
10  * (at your option) any later version.
11  *
12  * This program is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with this program. If not, see <http://www.gnu.org/licenses/>.
19  *
20  */
21 
22 #ifndef WINTERMUTE_RECT32_H
23 #define WINTERMUTE_RECT32_H
24 
25 #include "common/system.h"
26 #include "engines/wintermute/math/floatpoint.h"
27 #include "common/rect.h"
28 
29 namespace Wintermute {
30 
31 struct Point32 {
32  int32 x;
33  int32 y;
34  Point32() : x(0), y(0) {}
35  Point32(int32 x1, int32 y1) : x(x1), y(y1) {}
36  bool operator==(const Point32 &p) const { return x == p.x && y == p.y; }
37  bool operator!=(const Point32 &p) const { return x != p.x || y != p.y; }
38  Point32 operator+(const Point32 &delta) const { return Point32(x + delta.x, y + delta.y); }
39  Point32 operator-(const Point32 &delta) const { return Point32(x - delta.x, y - delta.y); }
40 
41  Point32 &operator+=(const Point32 &delta) {
42  x += delta.x;
43  y += delta.y;
44  return *this;
45  }
46 
47  Point32 &operator-=(const Point32 &delta) {
48  x -= delta.x;
49  y -= delta.y;
50  return *this;
51  }
52 
53  operator FloatPoint() {
54  return FloatPoint(x,y);
55  }
56 
57 
58 };
59 
60 struct Rect32 {
61  int32 top, left;
62  int32 bottom, right;
63 
64  Rect32() : top(0), left(0), bottom(0), right(0) {}
65  Rect32(int32 w, int32 h) : top(0), left(0), bottom(h), right(w) {}
66  Rect32(const Common::Rect &rect) : top(rect.top), left(rect.left), bottom(rect.bottom), right(rect.right) {}
67  Rect32(int32 x1, int32 y1, int32 x2, int32 y2) : top(y1), left(x1), bottom(y2), right(x2) {
68  assert(isValidRect());
69  }
70  bool operator==(const Rect32 &rhs) const {
71  return equals(rhs);
72  }
73  bool operator!=(const Rect32 &rhs) const {
74  return !equals(rhs);
75  }
76 
77  int32 width() const {
78  return right - left;
79  }
80  int32 height() const {
81  return bottom - top;
82  }
83 
84  void setWidth(int32 aWidth) {
85  right = left + aWidth;
86  }
87 
88  void setHeight(int32 aHeight) {
89  bottom = top + aHeight;
90  }
91 
92  void setEmpty() {
93  left = right = top = bottom = 0;
94  }
95 
96  bool isRectEmpty() const {
97  return (left >= right) || (top >= bottom);
98  }
99 
100  void offsetRect(int dx, int dy) {
101  left += dx;
102  top += dy;
103  right += dx;
104  bottom += dy;
105  }
106 
107  void setRect(int32 newLeft, int32 newTop, int32 newRight, int32 newBottom) {
108  this->left = newLeft;
109  this->top = newTop;
110  this->right = newRight;
111  this->bottom = newBottom;
112  }
113 
121  bool equals(const Rect32 &r) const {
122  return (left == r.left) && (right == r.right) && (top == r.top) && (bottom == r.bottom);
123  }
124 
125  bool isValidRect() const {
126  return (left <= right && top <= bottom);
127  }
128 };
129 
130 } // End of namespace Wintermute
131 
132 #endif
Definition: floatpoint.h:27
int32 left
The point at the top left of the rectangle (part of the rect).
Definition: rect32.h:61
int16 right
Definition: rect.h:146
Definition: rect32.h:31
Definition: rect.h:144
Definition: rect32.h:60
int16 left
Definition: rect.h:145
int32 right
The point at the bottom right of the rectangle (not part of the rect).
Definition: rect32.h:62
bool equals(const Rect32 &r) const
Definition: rect32.h:121
Definition: achievements_tables.h:27