[Scummvm-cvs-logs] SF.net SVN: scummvm:[35966] scummvm/trunk/backends/vkeybd

fingolfin at users.sourceforge.net fingolfin at users.sourceforge.net
Wed Jan 21 00:19:43 CET 2009


Revision: 35966
          http://scummvm.svn.sourceforge.net/scummvm/?rev=35966&view=rev
Author:   fingolfin
Date:     2009-01-20 23:19:42 +0000 (Tue, 20 Jan 2009)

Log Message:
-----------
some code cleanup

Modified Paths:
--------------
    scummvm/trunk/backends/vkeybd/image-map.cpp
    scummvm/trunk/backends/vkeybd/image-map.h
    scummvm/trunk/backends/vkeybd/polygon.h
    scummvm/trunk/backends/vkeybd/virtual-keyboard-gui.cpp
    scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp
    scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.h
    scummvm/trunk/backends/vkeybd/virtual-keyboard.h

Modified: scummvm/trunk/backends/vkeybd/image-map.cpp
===================================================================
--- scummvm/trunk/backends/vkeybd/image-map.cpp	2009-01-20 22:52:29 UTC (rev 35965)
+++ scummvm/trunk/backends/vkeybd/image-map.cpp	2009-01-20 23:19:42 UTC (rev 35966)
@@ -26,6 +26,7 @@
 #ifdef ENABLE_VKEYBD
 
 #include "backends/vkeybd/image-map.h"
+#include "backends/vkeybd/polygon.h"
 
 namespace Common {
 
@@ -64,7 +65,7 @@
 		if (it->_value->contains(x, y))
 			return it->_key;
 	}
-	return "";
+	return String();
 }
 
 

Modified: scummvm/trunk/backends/vkeybd/image-map.h
===================================================================
--- scummvm/trunk/backends/vkeybd/image-map.h	2009-01-20 22:52:29 UTC (rev 35965)
+++ scummvm/trunk/backends/vkeybd/image-map.h	2009-01-20 23:19:42 UTC (rev 35966)
@@ -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 @@
 	String findMapArea(int16 x, int16 y);
 
 protected:
-	HashMap<String, Polygon*> _areas;
+	HashMap<String, Polygon *> _areas;
 };
 
 

Modified: scummvm/trunk/backends/vkeybd/polygon.h
===================================================================
--- scummvm/trunk/backends/vkeybd/polygon.h	2009-01-20 22:52:29 UTC (rev 35965)
+++ scummvm/trunk/backends/vkeybd/polygon.h	2009-01-20 23:19:42 UTC (rev 35966)
@@ -36,13 +36,9 @@
 
 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 @@
 			addPoint(p[i]);
 		}
 	}
-	virtual ~Polygon() {}
 
 	void addPoint(const Point& p) {
 		_points.push_back(p);
@@ -66,36 +61,36 @@
 		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;
+	bool contains(int16 x, int16 y) const;
 
-	/*!	@brief 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
+	/**
+	 * 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 @@
 		}
 	}
 
-	virtual Rect getBoundingRect() const {
+	Rect getBoundingRect() const {
 		return _bound;
 	}
 

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard-gui.cpp
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard-gui.cpp	2009-01-20 22:52:29 UTC (rev 35965)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard-gui.cpp	2009-01-20 23:19:42 UTC (rev 35966)
@@ -96,13 +96,14 @@
 }
 
 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);

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp	2009-01-20 22:52:29 UTC (rev 35965)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.cpp	2009-01-20 23:19:42 UTC (rev 35966)
@@ -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 @@
 			delete _mode->image;
 			_mode->image = 0;
 			_mode->imageMap.removeAllAreas();
-			delete _mode->displayArea;
-			_mode->displayArea = 0;
+			_mode->displayArea = Rect();
 		}
 	}
 
@@ -298,16 +298,16 @@
 	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 @@
 	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 @@
 		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;
 }
 

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.h
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.h	2009-01-20 22:52:29 UTC (rev 35965)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard-parser.h	2009-01-20 23:19:42 UTC (rev 35966)
@@ -260,9 +260,9 @@
 
 	/** 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

Modified: scummvm/trunk/backends/vkeybd/virtual-keyboard.h
===================================================================
--- scummvm/trunk/backends/vkeybd/virtual-keyboard.h	2009-01-20 22:52:29 UTC (rev 35965)
+++ scummvm/trunk/backends/vkeybd/virtual-keyboard.h	2009-01-20 23:19:42 UTC (rev 35966)
@@ -116,11 +116,11 @@
 		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;


This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.




More information about the Scummvm-git-logs mailing list