some code cleanup
svn-id: r35966
This commit is contained in:
parent
c210b71876
commit
299736c9e1
7 changed files with 54 additions and 53 deletions
|
@ -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();
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -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;
|
||||
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 @@ struct Polygon {
|
|||
}
|
||||
}
|
||||
|
||||
virtual Rect getBoundingRect() const {
|
||||
Rect getBoundingRect() const {
|
||||
return _bound;
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue