Constificiation.
[gemrb.git] / gemrb / core / Region.cpp
blobac1e32e5ac5ae55f10e15ee0b7b5bd379f9f8e7e
1 /* GemRB - Infinity Engine Emulator
2 * Copyright (C) 2003 The GemRB Project
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License
6 * as published by the Free Software Foundation; either version 2
7 * of the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
21 #include "win32def.h"
22 #include "Region.h"
24 /*************** point ****************************/
25 Point::Point(void)
27 x = y = 0;
28 //memset(this, 0, sizeof(*this));
31 Point::~Point(void)
35 Point::Point(const Point& pnt)
37 x=pnt.x;
38 y=pnt.y;
39 //memcpy(this, &pnt, sizeof(*this));
42 Point& Point::operator=(const Point& pnt)
44 x = pnt.x;
45 y = pnt.y;
46 //memcpy(this, &pnt, sizeof(*this));
47 return *this;
50 bool Point::operator==(const Point& pnt)
52 if (( x == pnt.x ) && ( y == pnt.y )) {
53 return true;
55 return false;
56 //return !memcmp( this, &pnt, sizeof(*this));
59 bool Point::operator!=(const Point& pnt)
61 if (( x == pnt.x ) && ( y == pnt.y )) {
62 return false;
64 return true;
67 Point::Point(short x, short y)
69 this->x = x;
70 this->y = y;
73 ieDword Point::asDword() const
75 return ((y & 0xFFFF) << 16) | (x & 0xFFFF);
78 void Point::fromDword(ieDword val)
80 x = val & 0xFFFF;
81 y = val >> 16;
84 bool Point::isnull() const
86 if (x==0 && y==0) {
87 return true;
89 return false;
92 bool Point::isempty() const
94 if (x==-1 && y==-1) {
95 return true;
97 return false;
100 bool Point::PointInside(const Point &p) const
102 if (( p.x < 0 ) || ( p.x > x )) {
103 return false;
105 if (( p.y < 0 ) || ( p.y > y )) {
106 return false;
108 return true;
111 /*************** region ****************************/
112 Region::Region(void)
114 x = y = w = h = 0;
117 Region::~Region(void)
121 Region::Region(const Region& rgn)
123 x = rgn.x;
124 y = rgn.y;
125 w = rgn.w;
126 h = rgn.h;
129 Region& Region::operator=(const Region& rgn)
131 x = rgn.x;
132 y = rgn.y;
133 w = rgn.w;
134 h = rgn.h;
135 return *this;
138 bool Region::operator==(const Region& rgn)
140 if (( x == rgn.x ) && ( y == rgn.y ) && ( w == rgn.w ) && ( h == rgn.h )) {
141 return true;
143 return false;
146 bool Region::operator!=(const Region& rgn)
148 if (( x != rgn.x ) || ( y != rgn.y ) || ( w != rgn.w ) || ( h != rgn.h )) {
149 return true;
151 return false;
154 Region::Region(int x, int y, int w, int h)
156 this->x = x;
157 this->y = y;
158 this->w = w;
159 this->h = h;
162 Region::Region(const Point &p, int w, int h)
164 this->x = p.x;
165 this->y = p.y;
166 this->w = w;
167 this->h = h;
170 bool Region::PointInside(const Point &p) const
172 if (( p.x < x ) || ( p.x > ( x + w ) )) {
173 return false;
175 if (( p.y < y ) || ( p.y > ( y + h ) )) {
176 return false;
178 return true;
181 bool Region::PointInside(unsigned short XPos, unsigned short YPos) const
183 if (( XPos < x ) || ( XPos > ( x + w ) )) {
184 return false;
186 if (( YPos < y ) || ( YPos > ( y + h ) )) {
187 return false;
189 return true;
192 bool Region::InsideRegion(const Region& rgn) const
194 if (x > ( rgn.x + rgn.w )) {
195 return false;
197 if (( x + w ) < rgn.x) {
198 return false;
200 if (y > ( rgn.y + rgn.h )) {
201 return false;
203 if (( y + h ) < rgn.y) {
204 return false;
206 return true;
209 void Region::Normalize()
211 if (x > w) {
212 int tmp = x;
213 x = w;
214 w = tmp - x;
215 } else {
216 w -= x;
218 if (y > h) {
219 int tmp = y;
220 y = h;
221 h = tmp - y;
222 } else {
223 h -= y;