aboutsummaryrefslogtreecommitdiff
path: root/common
diff options
context:
space:
mode:
Diffstat (limited to 'common')
-rw-r--r--common/image-map.cpp49
-rw-r--r--common/image-map.h20
2 files changed, 55 insertions, 14 deletions
diff --git a/common/image-map.cpp b/common/image-map.cpp
index 4e8df6cc50..54b4858dd5 100644
--- a/common/image-map.cpp
+++ b/common/image-map.cpp
@@ -27,6 +27,41 @@
namespace Common {
+ImageMap::~ImageMap() {
+ HashMap<String, Shape*>::iterator it;
+ for (it = _areas.begin(); it != _areas.end(); it++) {
+ delete it->_value;
+ }
+}
+
+Rect *ImageMap::createRectArea(const String& id) {
+ if (_areas.contains(id)) {
+ warning("Image map already contains an area with target of '%s'");
+ return 0;
+ }
+ Rect *r = new Rect();
+ _areas[id] = r;
+ return r;
+}
+
+Polygon *ImageMap::createPolygonArea(const String& id) {
+ if (_areas.contains(id)) {
+ warning("Image map already contains an area with target of '%s'");
+ return 0;
+ }
+ Polygon *p = new Polygon();
+ _areas[id] = p;
+ return p;
+}
+
+/*
+void ImageMap::addMapArea(Shape *shape, const String& target) {
+ if (_areas.contains(target)) {
+ warning("Image map already contains an area with target of '%s'");
+ return;
+ }
+ _areas[target] = shape;
+}
void ImageMap::addRectMapArea(const Rect& rect, const String& target) {
areas.push_back(MapArea(rect, target));
}
@@ -34,14 +69,14 @@ void ImageMap::addRectMapArea(const Rect& rect, const String& target) {
void ImageMap::addPolygonMapArea(const Polygon& poly, const String& target) {
areas.push_back(MapArea(poly, target));
}
-
-MapArea *ImageMap::findMapArea(int16 x, int16 y) {
- Array<MapArea>::iterator it;
- for (it = areas.begin(); it != areas.end(); it++) {
- if (it->contains(x, y))
- return it;
+*/
+String ImageMap::findMapArea(int16 x, int16 y) {
+ HashMap<String, Shape*>::iterator it;
+ for (it = _areas.begin(); it != _areas.end(); it++) {
+ if (it->_value->contains(x, y))
+ return it->_key;
}
- return 0;
+ return "";
}
diff --git a/common/image-map.h b/common/image-map.h
index b6a1ad36f4..eabc54adf3 100644
--- a/common/image-map.h
+++ b/common/image-map.h
@@ -26,7 +26,8 @@
#ifndef COMMON_IMAGEMAP_H
#define COMMON_IMAGEMAP_H
-#include "common/array.h"
+#include "common/hashmap.h"
+#include "common/hash-str.h"
#include "common/rect.h"
#include "common/polygon.h"
@@ -54,8 +55,7 @@ public:
protected:
/* shape defining the MapArea's boundary */
Shape *_shape;
- /* generalised flags for the area
- * TODO: change this */
+ /* string describing the target of MapArea */
String _target;
};
@@ -63,13 +63,19 @@ class ImageMap {
public:
- void addRectMapArea(const Rect& rect, const String& target);
- void addPolygonMapArea(const Polygon& poly, const String& target);
+ ~ImageMap();
+
+ Rect *createRectArea(const String& id);
+ Polygon *createPolygonArea(const String& id);
- MapArea *findMapArea(int16 x, int16 y);
+ //void addMapArea(Shape *shape, const String& target);
+ /*void addRectMapArea(const Rect& rect, const String& target);
+ void addPolygonMapArea(const Polygon& poly, const String& target);
+*/
+ String findMapArea(int16 x, int16 y);
protected:
- Array<MapArea> areas;
+ HashMap<String, Shape*> _areas;
};