diff options
author | Max Horn | 2009-01-20 23:19:42 +0000 |
---|---|---|
committer | Max Horn | 2009-01-20 23:19:42 +0000 |
commit | 299736c9e11dfb84d84ba942e7b9982acc02cb14 (patch) | |
tree | 67a440df1b48812116297d40a771f914b2cc1fec /backends/vkeybd | |
parent | c210b7187618111ee71c1f3d8404dc6ef23042e2 (diff) | |
download | scummvm-rg350-299736c9e11dfb84d84ba942e7b9982acc02cb14.tar.gz scummvm-rg350-299736c9e11dfb84d84ba942e7b9982acc02cb14.tar.bz2 scummvm-rg350-299736c9e11dfb84d84ba942e7b9982acc02cb14.zip |
some code cleanup
svn-id: r35966
Diffstat (limited to 'backends/vkeybd')
-rw-r--r-- | backends/vkeybd/image-map.cpp | 3 | ||||
-rw-r--r-- | backends/vkeybd/image-map.h | 5 | ||||
-rw-r--r-- | backends/vkeybd/polygon.h | 41 | ||||
-rw-r--r-- | backends/vkeybd/virtual-keyboard-gui.cpp | 5 | ||||
-rw-r--r-- | backends/vkeybd/virtual-keyboard-parser.cpp | 41 | ||||
-rw-r--r-- | backends/vkeybd/virtual-keyboard-parser.h | 6 | ||||
-rw-r--r-- | backends/vkeybd/virtual-keyboard.h | 6 |
7 files changed, 54 insertions, 53 deletions
diff --git a/backends/vkeybd/image-map.cpp b/backends/vkeybd/image-map.cpp index edb3087ee0..b0aa42ba22 100644 --- a/backends/vkeybd/image-map.cpp +++ b/backends/vkeybd/image-map.cpp @@ -26,6 +26,7 @@ #ifdef ENABLE_VKEYBD #include "backends/vkeybd/image-map.h" +#include "backends/vkeybd/polygon.h" namespace Common { @@ -64,7 +65,7 @@ String ImageMap::findMapArea(int16 x, int16 y) { if (it->_value->contains(x, y)) return it->_key; } - return ""; + return String(); } diff --git a/backends/vkeybd/image-map.h b/backends/vkeybd/image-map.h index 9401fa037d..6e31720abb 100644 --- a/backends/vkeybd/image-map.h +++ b/backends/vkeybd/image-map.h @@ -31,10 +31,11 @@ #include "common/scummsys.h" #include "common/hashmap.h" #include "common/hash-str.h" -#include "backends/vkeybd/polygon.h" namespace Common { +struct Polygon; + class ImageMap { public: @@ -47,7 +48,7 @@ public: String findMapArea(int16 x, int16 y); protected: - HashMap<String, Polygon*> _areas; + HashMap<String, Polygon *> _areas; }; diff --git a/backends/vkeybd/polygon.h b/backends/vkeybd/polygon.h index e16133a050..a93e1ff8ac 100644 --- a/backends/vkeybd/polygon.h +++ b/backends/vkeybd/polygon.h @@ -36,13 +36,9 @@ namespace Common { struct Polygon { - Polygon() {} - 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); - for (uint i = 1; i < p.size(); i++) { + for (uint i = 0; i < p.size(); i++) { _bound.extend(Rect(p[i].x, p[i].y, p[i].x, p[i].y)); } } @@ -51,7 +47,6 @@ struct Polygon { addPoint(p[i]); } } - virtual ~Polygon() {} void addPoint(const Point& p) { _points.push_back(p); @@ -66,36 +61,36 @@ struct Polygon { return _points.size(); } - /*! @brief check if given position is inside this polygon - - @param x the horizontal position to check - @param y the vertical position to check - - @return true if the given position is inside this polygon, false otherwise + /** + * Check if given position is inside this polygon. + * + * @param x the horizontal position to check + * @param y the vertical position to check + * @return true if the given position is inside this polygon, false otherwise */ - virtual bool contains(int16 x, int16 y) const; - - /*! @brief check if given point is inside this polygon - - @param p the point to check + bool contains(int16 x, int16 y) const; - @return true if the given point is inside this polygon, false otherwise + /** + * Check if given point is inside this polygon. + * + * @param p the point to check + * @return true if the given point is inside this polygon, false otherwise */ - virtual bool contains(const Point &p) const { + bool contains(const Point &p) const { return contains(p.x, p.y); } - virtual void moveTo(int16 x, int16 y) { + void moveTo(int16 x, int16 y) { int16 dx = x - ((_bound.right + _bound.left) / 2); int16 dy = y - ((_bound.bottom + _bound.top) / 2); translate(dx, dy); } - virtual void moveTo(const Point &p) { + void moveTo(const Point &p) { moveTo(p.x, p.y); } - virtual void translate(int16 dx, int16 dy) { + void translate(int16 dx, int16 dy) { Array<Point>::iterator it; for (it = _points.begin(); it != _points.end(); it++) { it->x += dx; @@ -103,7 +98,7 @@ struct Polygon { } } - virtual Rect getBoundingRect() const { + Rect getBoundingRect() const { return _bound; } diff --git a/backends/vkeybd/virtual-keyboard-gui.cpp b/backends/vkeybd/virtual-keyboard-gui.cpp index 37a88761aa..b26b34068a 100644 --- a/backends/vkeybd/virtual-keyboard-gui.cpp +++ b/backends/vkeybd/virtual-keyboard-gui.cpp @@ -96,13 +96,14 @@ VirtualKeyboardGUI::~VirtualKeyboardGUI() { } void VirtualKeyboardGUI::initMode(VirtualKeyboard::Mode *mode) { + assert(mode->image); + _kbdSurface = mode->image; _kbdTransparentColor = mode->transparentColor; _kbdBound.setWidth(_kbdSurface->w); _kbdBound.setHeight(_kbdSurface->h); - if (mode->displayArea) - setupDisplayArea(*(mode->displayArea), mode->displayFontColor); + setupDisplayArea(mode->displayArea, mode->displayFontColor); if (_displaying) { extendDirtyRect(_kbdBound); diff --git a/backends/vkeybd/virtual-keyboard-parser.cpp b/backends/vkeybd/virtual-keyboard-parser.cpp index 74bf82947c..e643161333 100644 --- a/backends/vkeybd/virtual-keyboard-parser.cpp +++ b/backends/vkeybd/virtual-keyboard-parser.cpp @@ -27,6 +27,7 @@ #ifdef ENABLE_VKEYBD #include "backends/vkeybd/virtual-keyboard-parser.h" +#include "backends/vkeybd/polygon.h" #include "common/keyboard.h" #include "common/util.h" @@ -156,8 +157,7 @@ bool VirtualKeyboardParser::parserCallback_mode(ParserNode *node) { delete _mode->image; _mode->image = 0; _mode->imageMap.removeAllAreas(); - delete _mode->displayArea; - _mode->displayArea = 0; + _mode->displayArea = Rect(); } } @@ -298,16 +298,16 @@ bool VirtualKeyboardParser::parserCallback_area(ParserNode *node) { String& coords = node->values["coords"]; if (target.equalsIgnoreCase("display_area")) { - if (! shape.equalsIgnoreCase("rect")) + if (!shape.equalsIgnoreCase("rect")) return parserError("display_area must be a rect area"); - _mode->displayArea = new Rect(); + _mode->displayArea = Rect(); return parseRect(_mode->displayArea, coords); } else if (shape.equalsIgnoreCase("rect")) { Polygon *poly = _mode->imageMap.createArea(target); - return parseRectAsPolygon(poly, coords); + return parseRectAsPolygon(*poly, coords); } else if (shape.equalsIgnoreCase("poly")) { Polygon *poly = _mode->imageMap.createArea(target); - return parsePolygon(poly, coords); + return parsePolygon(*poly, coords); } return parserError("Area shape '%s' not known", shape.c_str()); } @@ -329,18 +329,21 @@ byte VirtualKeyboardParser::parseFlags(const String& flags) { return val; } -bool VirtualKeyboardParser::parseRect(Rect *rect, const String& coords) { +bool VirtualKeyboardParser::parseRect(Rect &rect, const String& coords) { int x1, y1, x2, y2; if (!parseIntegerKey(coords.c_str(), 4, &x1, &y1, &x2, &y2)) return parserError("Invalid coords for rect area"); - rect->left = x1; rect->top = y1; rect->right = x2; rect->bottom = y2; - if (!rect->isValidRect()) + rect.left = x1; + rect.top = y1; + rect.right = x2; + rect.bottom = y2; + if (!rect.isValidRect()) return parserError("Rect area is not a valid rectangle"); return true; } -bool VirtualKeyboardParser::parsePolygon(Polygon *poly, const String& coords) { - StringTokenizer tok (coords, ", "); +bool VirtualKeyboardParser::parsePolygon(Polygon &poly, const String& coords) { + StringTokenizer tok(coords, ", "); for (String st = tok.nextToken(); !st.empty(); st = tok.nextToken()) { int x, y; if (sscanf(st.c_str(), "%d", &x) != 1) @@ -348,22 +351,22 @@ bool VirtualKeyboardParser::parsePolygon(Polygon *poly, const String& coords) { st = tok.nextToken(); if (sscanf(st.c_str(), "%d", &y) != 1) return parserError("Invalid coords for polygon area"); - poly->addPoint(x, y); + poly.addPoint(x, y); } - if (poly->getPointCount() < 3) + if (poly.getPointCount() < 3) return parserError("Invalid coords for polygon area"); return true; } -bool VirtualKeyboardParser::parseRectAsPolygon(Polygon *poly, const String& coords) { +bool VirtualKeyboardParser::parseRectAsPolygon(Polygon &poly, const String& coords) { Rect rect; - if (!parseRect(&rect, coords)) + if (!parseRect(rect, coords)) return false; - poly->addPoint(rect.left, rect.top); - poly->addPoint(rect.right, rect.top); - poly->addPoint(rect.right, rect.bottom); - poly->addPoint(rect.left, rect.bottom); + poly.addPoint(rect.left, rect.top); + poly.addPoint(rect.right, rect.top); + poly.addPoint(rect.right, rect.bottom); + poly.addPoint(rect.left, rect.bottom); return true; } diff --git a/backends/vkeybd/virtual-keyboard-parser.h b/backends/vkeybd/virtual-keyboard-parser.h index 201f184193..12adcd61c2 100644 --- a/backends/vkeybd/virtual-keyboard-parser.h +++ b/backends/vkeybd/virtual-keyboard-parser.h @@ -260,9 +260,9 @@ protected: /** Parse helper functions */ byte parseFlags(const String& flags); - bool parseRect(Rect *rect, const String& coords); - bool parsePolygon(Polygon *poly, const String& coords); - bool parseRectAsPolygon(Polygon *poly, const String& coords); + bool parseRect(Rect &rect, const String& coords); + bool parsePolygon(Polygon &poly, const String& coords); + bool parseRectAsPolygon(Polygon &poly, const String& coords); }; } // end of namespace GUI diff --git a/backends/vkeybd/virtual-keyboard.h b/backends/vkeybd/virtual-keyboard.h index 30e1f0cbcd..4fdcb8b453 100644 --- a/backends/vkeybd/virtual-keyboard.h +++ b/backends/vkeybd/virtual-keyboard.h @@ -116,11 +116,11 @@ protected: OverlayColor transparentColor; ImageMap imageMap; VKEventMap events; - Rect *displayArea; + Rect displayArea; OverlayColor displayFontColor; - Mode() : image(0), displayArea(0) {} - ~Mode() { delete image; delete displayArea; } + Mode() : image(0) {} + ~Mode() { delete image; } }; typedef HashMap<String, Mode, IgnoreCase_Hash, IgnoreCase_EqualTo> ModeMap; |