ScummVM API documentation
point.h
1 
2 /* ScummVM - Graphic Adventure Engine
3  *
4  * ScummVM is the legal property of its developers, whose names
5  * are too numerous to list here. Please refer to the COPYRIGHT
6  * file distributed with this source distribution.
7  *
8  * This program is free software: you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License as published by
10  * the Free Software Foundation, either version 3 of the License, or
11  * (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program. If not, see <http://www.gnu.org/licenses/>.
20  *
21  */
22 
23 #ifndef BAGEL_BOFLIB_POINT_H
24 #define BAGEL_BOFLIB_POINT_H
25 
26 #include "common/rect.h"
27 #include "bagel/boflib/stdinc.h"
28 #include "bagel/boflib/object.h"
29 
30 namespace Bagel {
31 
32 typedef Common::Point POINT;
33 
34 class CBofPoint : public StPoint, public CBofObject {
35 public:
36  // Constructors
37  CBofPoint();
38  CBofPoint(int initX, int initY);
39  CBofPoint(StPoint stPoint);
40  CBofPoint(const CBofPoint &cPoint);
41  CBofPoint(const StSize &stSize);
42 
43  CBofPoint(const POINT &stPoint) {
44  setWinPoint(&stPoint);
45  }
46 
47  void setWinPoint(const POINT *pPoint);
48  POINT GetWinPoint() const;
49 
50  void operator=(const POINT &stPoint) {
51  setWinPoint(&stPoint);
52  }
53 
54  operator const POINT() {
55  return GetWinPoint();
56  }
57 
58 
59  // Operations
60  void offset(int xOffset, int yOffset);
61  void offset(StPoint point);
62  void offset(StSize size);
63  void operator=(const StPoint &point);
64  void operator=(const CBofPoint &point);
65  bool operator==(StPoint point) const;
66  bool operator!=(StPoint point) const;
67  void operator+=(StSize size);
68  void operator-=(StSize size);
69  void operator+=(StPoint point);
70  void operator-=(StPoint point);
71 
72  // Operators returning CBofPoint values
73  CBofPoint operator+(StSize size) const;
74  CBofPoint operator+(StPoint point) const;
75  CBofPoint operator-(StSize size) const;
76  CBofPoint operator-(StPoint point) const;
77  CBofPoint operator-() const;
78 };
79 
80 // CBofPoint
81 inline CBofPoint::CBofPoint() {
82  x = 0;
83  y = 0;
84 }
85 
86 inline CBofPoint::CBofPoint(const int initX, const int initY) {
87  x = initX;
88  y = initY;
89 }
90 
91 inline CBofPoint::CBofPoint(const StPoint stPoint) {
92  x = stPoint.x;
93  y = stPoint.y;
94 }
95 
96 inline CBofPoint::CBofPoint(const StSize &stSize) {
97  x = stSize.cx;
98  y = stSize.cy;
99 }
100 
101 inline CBofPoint::CBofPoint(const CBofPoint &cPoint) {
102  x = cPoint.x;
103  y = cPoint.y;
104 }
105 
106 inline void CBofPoint::setWinPoint(const POINT *pPoint) {
107  assert(pPoint != nullptr);
108  assert(isValidObject(this));
109 
110  x = pPoint->x;
111  y = pPoint->y;
112 }
113 
114 inline POINT CBofPoint::GetWinPoint() const {
115  assert(isValidObject(this));
116 
117  POINT stPoint;
118 
119  stPoint.x = x;
120  stPoint.y = y;
121 
122  return stPoint;
123 }
124 
125 inline void CBofPoint::offset(int xOffset, int yOffset) {
126  // Make sure object is not used after it is destructed
127  assert(isValidObject(this));
128 
129  x += xOffset;
130  y += yOffset;
131 }
132 
133 inline void CBofPoint::offset(StPoint point) {
134  // Make sure object is not used after it is destructed
135  assert(isValidObject(this));
136 
137  x += point.x;
138  y += point.y;
139 }
140 
141 inline void CBofPoint::offset(StSize size) {
142  // Make sure object is not used after it is destructed
143  assert(isValidObject(this));
144 
145  x += size.cx;
146  y += size.cy;
147 }
148 
149 inline void CBofPoint::operator=(const StPoint &point) {
150  // Make sure object is not used after it is destructed
151  assert(isValidObject(this));
152 
153  x = point.x;
154  y = point.y;
155 }
156 
157 inline void CBofPoint::operator=(const CBofPoint &point) {
158  // Make sure object is not used after it is destructed
159  assert(isValidObject(this));
160 
161  x = point.x;
162  y = point.y;
163 }
164 
165 inline bool CBofPoint::operator==(StPoint point) const {
166  // Make sure object is not used after it is destructed
167  assert(isValidObject(this));
168 
169  return (x == point.x && y == point.y);
170 }
171 
172 inline bool CBofPoint::operator!=(StPoint point) const {
173  // Make sure object is not used after it is destructed
174  assert(isValidObject(this));
175 
176  return (x != point.x || y != point.y);
177 }
178 
179 inline void CBofPoint::operator+=(StSize size) {
180  // Make sure object is not used after it is destructed
181  assert(isValidObject(this));
182 
183  x += size.cx;
184  y += size.cy;
185 }
186 
187 inline void CBofPoint::operator+=(StPoint point) {
188  // Make sure object is not used after it is destructed
189  assert(isValidObject(this));
190 
191  x += point.x;
192  y += point.y;
193 }
194 
195 inline void CBofPoint::operator-=(StPoint point) {
196  // Make sure object is not used after it is destructed
197  assert(isValidObject(this));
198 
199  x -= point.x;
200  y -= point.y;
201 }
202 
203 inline void CBofPoint::operator-=(StSize size) {
204  // Make sure object is not used after it is destructed
205  assert(isValidObject(this));
206 
207  x -= size.cx;
208  y -= size.cy;
209 }
210 
211 inline CBofPoint CBofPoint::operator+(StSize size) const {
212  // Make sure object is not used after it is destructed
213  assert(isValidObject(this));
214 
215  return CBofPoint(x + size.cx, y + size.cy);
216 }
217 
218 inline CBofPoint CBofPoint::operator+(StPoint point) const {
219  // Make sure object is not used after it is destructed
220  assert(isValidObject(this));
221 
222  return CBofPoint(x + point.x, y + point.y);
223 }
224 
225 inline CBofPoint CBofPoint::operator-(StSize size) const {
226  // Make sure object is not used after it is destructed
227  assert(isValidObject(this));
228 
229  return CBofPoint(x - size.cx, y - size.cy);
230 }
231 
232 inline CBofPoint CBofPoint::operator-(StPoint point) const {
233  // Make sure object is not used after it is destructed
234  assert(isValidObject(this));
235 
236  return CBofPoint(x - point.x, y - point.y);
237 }
238 
239 inline CBofPoint CBofPoint::operator-() const {
240  // Make sure object is not used after it is destructed
241  assert(isValidObject(this));
242 
243  return CBofPoint(-x, -y);
244 }
245 
246 #define CPoint CBofPoint
247 
248 } // namespace Bagel
249 
250 #endif
Definition: object.h:28
Definition: stdinc.h:40
Definition: rect.h:45
Definition: bagel.h:31
Definition: point.h:34
int16 x
Definition: rect.h:46
int16 y
Definition: rect.h:47
Definition: stdinc.h:45