GUIScript: Make LoadSymbol return an object.
[gemrb.git] / gemrb / core / Region.cpp
blob0ab46be6bbb24a1f349d291c985e664e8c22ccc3
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 "Region.h"
23 /*************** point ****************************/
24 Point::Point(void)
26 x = y = 0;
27 //memset(this, 0, sizeof(*this));
30 Point::~Point(void)
34 Point::Point(const Point& pnt)
36 x=pnt.x;
37 y=pnt.y;
38 //memcpy(this, &pnt, sizeof(*this));
41 Point& Point::operator=(const Point& pnt)
43 x = pnt.x;
44 y = pnt.y;
45 //memcpy(this, &pnt, sizeof(*this));
46 return *this;
49 bool Point::operator==(const Point& pnt)
51 if (( x == pnt.x ) && ( y == pnt.y )) {
52 return true;
54 return false;
55 //return !memcmp( this, &pnt, sizeof(*this));
58 bool Point::operator!=(const Point& pnt)
60 if (( x == pnt.x ) && ( y == pnt.y )) {
61 return false;
63 return true;
66 Point::Point(short x, short y)
68 this->x = x;
69 this->y = y;
72 ieDword Point::asDword() const
74 return ((y & 0xFFFF) << 16) | (x & 0xFFFF);
77 void Point::fromDword(ieDword val)
79 x = val & 0xFFFF;
80 y = val >> 16;
83 bool Point::isnull() const
85 if (x==0 && y==0) {
86 return true;
88 return false;
91 bool Point::isempty() const
93 if (x==-1 && y==-1) {
94 return true;
96 return false;
99 bool Point::PointInside(const Point &p) const
101 if (( p.x < 0 ) || ( p.x > x )) {
102 return false;
104 if (( p.y < 0 ) || ( p.y > y )) {
105 return false;
107 return true;
110 /*************** region ****************************/
111 Region::Region(void)
113 x = y = w = h = 0;
116 Region::~Region(void)
120 Region::Region(const Region& rgn)
122 x = rgn.x;
123 y = rgn.y;
124 w = rgn.w;
125 h = rgn.h;
128 Region& Region::operator=(const Region& rgn)
130 x = rgn.x;
131 y = rgn.y;
132 w = rgn.w;
133 h = rgn.h;
134 return *this;
137 bool Region::operator==(const Region& rgn)
139 if (( x == rgn.x ) && ( y == rgn.y ) && ( w == rgn.w ) && ( h == rgn.h )) {
140 return true;
142 return false;
145 bool Region::operator!=(const Region& rgn)
147 if (( x != rgn.x ) || ( y != rgn.y ) || ( w != rgn.w ) || ( h != rgn.h )) {
148 return true;
150 return false;
153 Region::Region(int x, int y, int w, int h)
155 this->x = x;
156 this->y = y;
157 this->w = w;
158 this->h = h;
161 Region::Region(const Point &p, int w, int h)
163 this->x = p.x;
164 this->y = p.y;
165 this->w = w;
166 this->h = h;
169 bool Region::PointInside(const Point &p) const
171 if (( p.x < x ) || ( p.x > ( x + w ) )) {
172 return false;
174 if (( p.y < y ) || ( p.y > ( y + h ) )) {
175 return false;
177 return true;
180 bool Region::PointInside(unsigned short XPos, unsigned short YPos) const
182 if (( XPos < x ) || ( XPos > ( x + w ) )) {
183 return false;
185 if (( YPos < y ) || ( YPos > ( y + h ) )) {
186 return false;
188 return true;
191 bool Region::InsideRegion(const Region& rgn) const
193 if (x > ( rgn.x + rgn.w )) {
194 return false;
196 if (( x + w ) < rgn.x) {
197 return false;
199 if (y > ( rgn.y + rgn.h )) {
200 return false;
202 if (( y + h ) < rgn.y) {
203 return false;
205 return true;
208 void Region::Normalize()
210 if (x > w) {
211 int tmp = x;
212 x = w;
213 w = tmp - x;
214 } else {
215 w -= x;
217 if (y > h) {
218 int tmp = y;
219 y = h;
220 h = tmp - y;
221 } else {
222 h -= y;