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
|
#ifdef ENABLE_VKEYBD
|
||||||
|
|
||||||
#include "backends/vkeybd/image-map.h"
|
#include "backends/vkeybd/image-map.h"
|
||||||
|
#include "backends/vkeybd/polygon.h"
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
@ -64,7 +65,7 @@ String ImageMap::findMapArea(int16 x, int16 y) {
|
||||||
if (it->_value->contains(x, y))
|
if (it->_value->contains(x, y))
|
||||||
return it->_key;
|
return it->_key;
|
||||||
}
|
}
|
||||||
return "";
|
return String();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -31,10 +31,11 @@
|
||||||
#include "common/scummsys.h"
|
#include "common/scummsys.h"
|
||||||
#include "common/hashmap.h"
|
#include "common/hashmap.h"
|
||||||
#include "common/hash-str.h"
|
#include "common/hash-str.h"
|
||||||
#include "backends/vkeybd/polygon.h"
|
|
||||||
|
|
||||||
namespace Common {
|
namespace Common {
|
||||||
|
|
||||||
|
struct Polygon;
|
||||||
|
|
||||||
class ImageMap {
|
class ImageMap {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
@ -47,7 +48,7 @@ public:
|
||||||
String findMapArea(int16 x, int16 y);
|
String findMapArea(int16 x, int16 y);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
HashMap<String, Polygon*> _areas;
|
HashMap<String, Polygon *> _areas;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -36,13 +36,9 @@ namespace Common {
|
||||||
|
|
||||||
struct Polygon {
|
struct Polygon {
|
||||||
|
|
||||||
|
|
||||||
Polygon() {}
|
Polygon() {}
|
||||||
Polygon(const Polygon& p) : _points(p._points), _bound(p._bound) {}
|
|
||||||
Polygon(Array<Point> p) : _points(p) {
|
Polygon(Array<Point> p) : _points(p) {
|
||||||
if (p.empty()) return;
|
for (uint i = 0; i < p.size(); i++) {
|
||||||
_bound = Rect(p[0].x, p[0].y, p[0].x, p[0].y);
|
|
||||||
for (uint i = 1; i < p.size(); i++) {
|
|
||||||
_bound.extend(Rect(p[i].x, p[i].y, p[i].x, p[i].y));
|
_bound.extend(Rect(p[i].x, p[i].y, p[i].x, p[i].y));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -51,7 +47,6 @@ struct Polygon {
|
||||||
addPoint(p[i]);
|
addPoint(p[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
virtual ~Polygon() {}
|
|
||||||
|
|
||||||
void addPoint(const Point& p) {
|
void addPoint(const Point& p) {
|
||||||
_points.push_back(p);
|
_points.push_back(p);
|
||||||
|
@ -66,36 +61,36 @@ struct Polygon {
|
||||||
return _points.size();
|
return _points.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*! @brief check if given position is inside this polygon
|
/**
|
||||||
|
* Check if given position is inside this polygon.
|
||||||
@param x the horizontal position to check
|
*
|
||||||
@param y the vertical position to check
|
* @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
|
* @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
|
/**
|
||||||
|
* Check if given point is inside this polygon.
|
||||||
@param p the point to check
|
*
|
||||||
|
* @param p the point to check
|
||||||
@return true if the given point is inside this polygon, false otherwise
|
* @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);
|
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 dx = x - ((_bound.right + _bound.left) / 2);
|
||||||
int16 dy = y - ((_bound.bottom + _bound.top) / 2);
|
int16 dy = y - ((_bound.bottom + _bound.top) / 2);
|
||||||
translate(dx, dy);
|
translate(dx, dy);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void moveTo(const Point &p) {
|
void moveTo(const Point &p) {
|
||||||
moveTo(p.x, p.y);
|
moveTo(p.x, p.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void translate(int16 dx, int16 dy) {
|
void translate(int16 dx, int16 dy) {
|
||||||
Array<Point>::iterator it;
|
Array<Point>::iterator it;
|
||||||
for (it = _points.begin(); it != _points.end(); it++) {
|
for (it = _points.begin(); it != _points.end(); it++) {
|
||||||
it->x += dx;
|
it->x += dx;
|
||||||
|
@ -103,7 +98,7 @@ struct Polygon {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual Rect getBoundingRect() const {
|
Rect getBoundingRect() const {
|
||||||
return _bound;
|
return _bound;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,13 +96,14 @@ VirtualKeyboardGUI::~VirtualKeyboardGUI() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void VirtualKeyboardGUI::initMode(VirtualKeyboard::Mode *mode) {
|
void VirtualKeyboardGUI::initMode(VirtualKeyboard::Mode *mode) {
|
||||||
|
assert(mode->image);
|
||||||
|
|
||||||
_kbdSurface = mode->image;
|
_kbdSurface = mode->image;
|
||||||
_kbdTransparentColor = mode->transparentColor;
|
_kbdTransparentColor = mode->transparentColor;
|
||||||
_kbdBound.setWidth(_kbdSurface->w);
|
_kbdBound.setWidth(_kbdSurface->w);
|
||||||
_kbdBound.setHeight(_kbdSurface->h);
|
_kbdBound.setHeight(_kbdSurface->h);
|
||||||
|
|
||||||
if (mode->displayArea)
|
setupDisplayArea(mode->displayArea, mode->displayFontColor);
|
||||||
setupDisplayArea(*(mode->displayArea), mode->displayFontColor);
|
|
||||||
|
|
||||||
if (_displaying) {
|
if (_displaying) {
|
||||||
extendDirtyRect(_kbdBound);
|
extendDirtyRect(_kbdBound);
|
||||||
|
|
|
@ -27,6 +27,7 @@
|
||||||
#ifdef ENABLE_VKEYBD
|
#ifdef ENABLE_VKEYBD
|
||||||
|
|
||||||
#include "backends/vkeybd/virtual-keyboard-parser.h"
|
#include "backends/vkeybd/virtual-keyboard-parser.h"
|
||||||
|
#include "backends/vkeybd/polygon.h"
|
||||||
|
|
||||||
#include "common/keyboard.h"
|
#include "common/keyboard.h"
|
||||||
#include "common/util.h"
|
#include "common/util.h"
|
||||||
|
@ -156,8 +157,7 @@ bool VirtualKeyboardParser::parserCallback_mode(ParserNode *node) {
|
||||||
delete _mode->image;
|
delete _mode->image;
|
||||||
_mode->image = 0;
|
_mode->image = 0;
|
||||||
_mode->imageMap.removeAllAreas();
|
_mode->imageMap.removeAllAreas();
|
||||||
delete _mode->displayArea;
|
_mode->displayArea = Rect();
|
||||||
_mode->displayArea = 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,16 +298,16 @@ bool VirtualKeyboardParser::parserCallback_area(ParserNode *node) {
|
||||||
String& coords = node->values["coords"];
|
String& coords = node->values["coords"];
|
||||||
|
|
||||||
if (target.equalsIgnoreCase("display_area")) {
|
if (target.equalsIgnoreCase("display_area")) {
|
||||||
if (! shape.equalsIgnoreCase("rect"))
|
if (!shape.equalsIgnoreCase("rect"))
|
||||||
return parserError("display_area must be a rect area");
|
return parserError("display_area must be a rect area");
|
||||||
_mode->displayArea = new Rect();
|
_mode->displayArea = Rect();
|
||||||
return parseRect(_mode->displayArea, coords);
|
return parseRect(_mode->displayArea, coords);
|
||||||
} else if (shape.equalsIgnoreCase("rect")) {
|
} else if (shape.equalsIgnoreCase("rect")) {
|
||||||
Polygon *poly = _mode->imageMap.createArea(target);
|
Polygon *poly = _mode->imageMap.createArea(target);
|
||||||
return parseRectAsPolygon(poly, coords);
|
return parseRectAsPolygon(*poly, coords);
|
||||||
} else if (shape.equalsIgnoreCase("poly")) {
|
} else if (shape.equalsIgnoreCase("poly")) {
|
||||||
Polygon *poly = _mode->imageMap.createArea(target);
|
Polygon *poly = _mode->imageMap.createArea(target);
|
||||||
return parsePolygon(poly, coords);
|
return parsePolygon(*poly, coords);
|
||||||
}
|
}
|
||||||
return parserError("Area shape '%s' not known", shape.c_str());
|
return parserError("Area shape '%s' not known", shape.c_str());
|
||||||
}
|
}
|
||||||
|
@ -329,18 +329,21 @@ byte VirtualKeyboardParser::parseFlags(const String& flags) {
|
||||||
return val;
|
return val;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualKeyboardParser::parseRect(Rect *rect, const String& coords) {
|
bool VirtualKeyboardParser::parseRect(Rect &rect, const String& coords) {
|
||||||
int x1, y1, x2, y2;
|
int x1, y1, x2, y2;
|
||||||
if (!parseIntegerKey(coords.c_str(), 4, &x1, &y1, &x2, &y2))
|
if (!parseIntegerKey(coords.c_str(), 4, &x1, &y1, &x2, &y2))
|
||||||
return parserError("Invalid coords for rect area");
|
return parserError("Invalid coords for rect area");
|
||||||
rect->left = x1; rect->top = y1; rect->right = x2; rect->bottom = y2;
|
rect.left = x1;
|
||||||
if (!rect->isValidRect())
|
rect.top = y1;
|
||||||
|
rect.right = x2;
|
||||||
|
rect.bottom = y2;
|
||||||
|
if (!rect.isValidRect())
|
||||||
return parserError("Rect area is not a valid rectangle");
|
return parserError("Rect area is not a valid rectangle");
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualKeyboardParser::parsePolygon(Polygon *poly, const String& coords) {
|
bool VirtualKeyboardParser::parsePolygon(Polygon &poly, const String& coords) {
|
||||||
StringTokenizer tok (coords, ", ");
|
StringTokenizer tok(coords, ", ");
|
||||||
for (String st = tok.nextToken(); !st.empty(); st = tok.nextToken()) {
|
for (String st = tok.nextToken(); !st.empty(); st = tok.nextToken()) {
|
||||||
int x, y;
|
int x, y;
|
||||||
if (sscanf(st.c_str(), "%d", &x) != 1)
|
if (sscanf(st.c_str(), "%d", &x) != 1)
|
||||||
|
@ -348,22 +351,22 @@ bool VirtualKeyboardParser::parsePolygon(Polygon *poly, const String& coords) {
|
||||||
st = tok.nextToken();
|
st = tok.nextToken();
|
||||||
if (sscanf(st.c_str(), "%d", &y) != 1)
|
if (sscanf(st.c_str(), "%d", &y) != 1)
|
||||||
return parserError("Invalid coords for polygon area");
|
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 parserError("Invalid coords for polygon area");
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool VirtualKeyboardParser::parseRectAsPolygon(Polygon *poly, const String& coords) {
|
bool VirtualKeyboardParser::parseRectAsPolygon(Polygon &poly, const String& coords) {
|
||||||
Rect rect;
|
Rect rect;
|
||||||
if (!parseRect(&rect, coords))
|
if (!parseRect(rect, coords))
|
||||||
return false;
|
return false;
|
||||||
poly->addPoint(rect.left, rect.top);
|
poly.addPoint(rect.left, rect.top);
|
||||||
poly->addPoint(rect.right, rect.top);
|
poly.addPoint(rect.right, rect.top);
|
||||||
poly->addPoint(rect.right, rect.bottom);
|
poly.addPoint(rect.right, rect.bottom);
|
||||||
poly->addPoint(rect.left, rect.bottom);
|
poly.addPoint(rect.left, rect.bottom);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -260,9 +260,9 @@ protected:
|
||||||
|
|
||||||
/** Parse helper functions */
|
/** Parse helper functions */
|
||||||
byte parseFlags(const String& flags);
|
byte parseFlags(const String& flags);
|
||||||
bool parseRect(Rect *rect, const String& coords);
|
bool parseRect(Rect &rect, const String& coords);
|
||||||
bool parsePolygon(Polygon *poly, const String& coords);
|
bool parsePolygon(Polygon &poly, const String& coords);
|
||||||
bool parseRectAsPolygon(Polygon *poly, const String& coords);
|
bool parseRectAsPolygon(Polygon &poly, const String& coords);
|
||||||
};
|
};
|
||||||
|
|
||||||
} // end of namespace GUI
|
} // end of namespace GUI
|
||||||
|
|
|
@ -116,11 +116,11 @@ protected:
|
||||||
OverlayColor transparentColor;
|
OverlayColor transparentColor;
|
||||||
ImageMap imageMap;
|
ImageMap imageMap;
|
||||||
VKEventMap events;
|
VKEventMap events;
|
||||||
Rect *displayArea;
|
Rect displayArea;
|
||||||
OverlayColor displayFontColor;
|
OverlayColor displayFontColor;
|
||||||
|
|
||||||
Mode() : image(0), displayArea(0) {}
|
Mode() : image(0) {}
|
||||||
~Mode() { delete image; delete displayArea; }
|
~Mode() { delete image; }
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef HashMap<String, Mode, IgnoreCase_Hash, IgnoreCase_EqualTo> ModeMap;
|
typedef HashMap<String, Mode, IgnoreCase_Hash, IgnoreCase_EqualTo> ModeMap;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue