aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/image-map.cpp16
-rw-r--r--common/image-map.h6
-rw-r--r--common/polygon.h5
-rw-r--r--common/rect.h57
-rw-r--r--common/shape.h105
5 files changed, 50 insertions, 139 deletions
diff --git a/common/image-map.cpp b/common/image-map.cpp
index 393417315d..84b22b4f1f 100644
--- a/common/image-map.cpp
+++ b/common/image-map.cpp
@@ -31,17 +31,7 @@ ImageMap::~ImageMap() {
removeAllAreas();
}
-Rect *ImageMap::createRectArea(const String& id) {
- if (_areas.contains(id)) {
- warning("Image map already contains an area with target of '%s'", id.c_str());
- return 0;
- }
- Rect *r = new Rect();
- _areas[id] = r;
- return r;
-}
-
-Polygon *ImageMap::createPolygonArea(const String& id) {
+Polygon *ImageMap::createArea(const String& id) {
if (_areas.contains(id)) {
warning("Image map already contains an area with target of '%s'", id.c_str());
return 0;
@@ -59,7 +49,7 @@ void ImageMap::removeArea(const String& id) {
}
void ImageMap::removeAllAreas() {
- HashMap<String, Shape*>::iterator it;
+ HashMap<String, Polygon*>::iterator it;
for (it = _areas.begin(); it != _areas.end(); it++) {
delete it->_value;
}
@@ -67,7 +57,7 @@ void ImageMap::removeAllAreas() {
}
String ImageMap::findMapArea(int16 x, int16 y) {
- HashMap<String, Shape*>::iterator it;
+ HashMap<String, Polygon*>::iterator it;
for (it = _areas.begin(); it != _areas.end(); it++) {
if (it->_value->contains(x, y))
return it->_key;
diff --git a/common/image-map.h b/common/image-map.h
index eaf803178d..ee64d96ba1 100644
--- a/common/image-map.h
+++ b/common/image-map.h
@@ -28,7 +28,6 @@
#include "common/hashmap.h"
#include "common/hash-str.h"
-#include "common/rect.h"
#include "common/polygon.h"
namespace Common {
@@ -39,14 +38,13 @@ public:
~ImageMap();
- Rect *createRectArea(const String& id);
- Polygon *createPolygonArea(const String& id);
+ Polygon *createArea(const String& id);
void removeArea(const String& id);
void removeAllAreas();
String findMapArea(int16 x, int16 y);
protected:
- HashMap<String, Shape*> _areas;
+ HashMap<String, Polygon*> _areas;
};
diff --git a/common/polygon.h b/common/polygon.h
index e4a518193e..69df2c0ca3 100644
--- a/common/polygon.h
+++ b/common/polygon.h
@@ -28,15 +28,14 @@
#include "common/array.h"
#include "common/rect.h"
-#include "common/shape.h"
namespace Common {
-struct Polygon : public Shape {
+struct Polygon {
Polygon() {}
- Polygon(const Polygon& p) : Shape(), _points(p._points), _bound(p._bound) {}
+ Polygon(const Polygon& p) : _points(p._points), _bound(p._bound) {}
Polygon(Array<Point> p) : _points(p) {
if (p.empty()) return;
_bound = Rect(p[0].x, p[0].y, p[0].x, p[0].y);
diff --git a/common/rect.h b/common/rect.h
index d6badb1efd..dcf1c8b421 100644
--- a/common/rect.h
+++ b/common/rect.h
@@ -26,10 +26,45 @@
#ifndef COMMON_RECT_H
#define COMMON_RECT_H
-#include "common/shape.h"
+#include "common/scummsys.h"
+#include "common/util.h"
namespace Common {
+/*! @brief simple class for handling both 2D position and size
+
+ This small class is an helper for position and size values.
+*/
+struct Point {
+ int16 x; //!< The horizontal part of the point
+ int16 y; //!< The vertical part of the point
+
+ Point() : x(0), y(0) {}
+ Point(const Point &p) : x(p.x), y(p.y) {}
+ explicit Point(int16 x1, int16 y1) : x(x1), y(y1) {}
+ Point & operator=(const Point & p) { x = p.x; y = p.y; return *this; };
+ bool operator==(const Point & p) const { return x == p.x && y == p.y; };
+ bool operator!=(const Point & p) const { return x != p.x || y != p.y; };
+
+ /**
+ * Return the square of the distance between this point and the point p.
+ *
+ * @param p the other point
+ * @return the distance between this and p
+ */
+ uint sqrDist(const Point & p) const {
+ int diffx = ABS(p.x - x);
+ if (diffx >= 0x1000)
+ return 0xFFFFFF;
+
+ int diffy = ABS(p.y - y);
+ if (diffy >= 0x1000)
+ return 0xFFFFFF;
+
+ return uint(diffx*diffx + diffy*diffy);
+ }
+};
+
/*! @brief simple class for handling a rectangular zone.
This small class is an helper for rectangles.
@@ -40,7 +75,7 @@ namespace Common {
Another very wide spread approach to rectangle classes treats (bottom,right)
also as a part of the rectangle.
- Conceptually, both are sound, but the approach we use saves many intermediate
+ Coneptually, both are sound, but the approach we use saves many intermediate
computations (like computing the height in our case is done by doing this:
height = bottom - top;
while in the alternate system, it would be
@@ -48,7 +83,7 @@ namespace Common {
When writing code using our Rect class, always keep this principle in mind!
*/
-struct Rect : public Shape {
+struct Rect {
int16 top, left; //!< The point at the top left of the rectangle (part of the rect).
int16 bottom, right; //!< The point at the bottom right of the rectangle (not part of the rect).
@@ -57,8 +92,6 @@ struct Rect : public Shape {
Rect(int16 x1, int16 y1, int16 x2, int16 y2) : top(y1), left(x1), bottom(y2), right(x2) {
assert(isValidRect());
}
- virtual ~Rect() {}
-
int16 width() const { return right - left; }
int16 height() const { return bottom - top; }
@@ -77,7 +110,7 @@ struct Rect : public Shape {
@return true if the given position is inside this rectangle, false otherwise
*/
- virtual bool contains(int16 x, int16 y) const {
+ bool contains(int16 x, int16 y) const {
return (left <= x) && (x < right) && (top <= y) && (y < bottom);
}
@@ -87,7 +120,7 @@ struct Rect : public Shape {
@return true if the given point is inside this rectangle, false otherwise
*/
- virtual bool contains(const Point &p) const {
+ bool contains(const Point &p) const {
return contains(p.x, p.y);
}
@@ -152,19 +185,19 @@ struct Rect : public Shape {
return (left <= right && top <= bottom);
}
- virtual void moveTo(int16 x, int16 y) {
+ void moveTo(int16 x, int16 y) {
bottom += y - top;
right += x - left;
top = y;
left = x;
}
- virtual void translate(int16 dx, int16 dy) {
+ void translate(int16 dx, int16 dy) {
left += dx; right += dx;
top += dy; bottom += dy;
}
- virtual void moveTo(const Point &p) {
+ void moveTo(const Point &p) {
moveTo(p.x, p.y);
}
@@ -178,10 +211,6 @@ struct Rect : public Shape {
h /= 2;
return Rect(cx - w, cy - h, cx + w, cy + h);
}
-
- virtual Rect getBoundingRect() const {
- return *this;
- }
};
} // End of namespace Common
diff --git a/common/shape.h b/common/shape.h
deleted file mode 100644
index 2cce365bfc..0000000000
--- a/common/shape.h
+++ /dev/null
@@ -1,105 +0,0 @@
-/* ScummVM - Graphic Adventure Engine
- *
- * ScummVM is the legal property of its developers, whose names
- * are too numerous to list here. Please refer to the COPYRIGHT
- * file distributed with this source distribution.
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
- *
- * $URL$
- * $Id$
- *
- */
-
-#ifndef COMMON_SHAPE_H
-#define COMMON_SHAPE_H
-
-#include "common/scummsys.h"
-#include "common/util.h"
-
-namespace Common {
-
-struct Rect;
-
-/*! @brief simple class for handling both 2D position and size
-
- This small class is an helper for position and size values.
-*/
-struct Point {
- int16 x; //!< The horizontal part of the point
- int16 y; //!< The vertical part of the point
-
- Point() : x(0), y(0) {}
- Point(const Point &p) : x(p.x), y(p.y) {}
- explicit Point(int16 x1, int16 y1) : x(x1), y(y1) {}
- Point & operator=(const Point & p) { x = p.x; y = p.y; return *this; };
- bool operator==(const Point & p) const { return x == p.x && y == p.y; };
- bool operator!=(const Point & p) const { return x != p.x || y != p.y; };
-
- /**
- * Return the square of the distance between this point and the point p.
- *
- * @param p the other point
- * @return the distance between this and p
- */
- uint sqrDist(const Point & p) const {
- int diffx = ABS(p.x - x);
- if (diffx >= 0x1000)
- return 0xFFFFFF;
-
- int diffy = ABS(p.y - y);
- if (diffy >= 0x1000)
- return 0xFFFFFF;
-
- return uint(diffx*diffx + diffy*diffy);
- }
-};
-
-/*! @brief simple interface that provides common methods for 2D shapes
-
-*/
-struct Shape {
-
- virtual ~Shape() {}
- /*! @brief check if given position is inside this shape
-
- @param x the horizontal position to check
- @param y the vertical position to check
-
- @return true if the given position is inside this shape, false otherwise
- */
- virtual bool contains(int16 x, int16 y) const = 0;
-
- /*! @brief check if given point is inside this shape
-
- @param p the point to check
-
- @return true if the given point is inside this shape, false otherwise
- */
- virtual bool contains(const Point &p) const = 0;
-
- virtual void moveTo(int16 x, int16 y) = 0;
-
- virtual void moveTo(const Point &p) = 0;
-
- virtual void translate(int16 dx, int16 dy) = 0;
-
- virtual Rect getBoundingRect() const = 0;
-
-};
-
-} // end of namespace Common
-
-#endif