aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--backends/common/virtual-keyboard-parser.cpp84
-rw-r--r--backends/common/virtual-keyboard-parser.h17
-rw-r--r--backends/common/virtual-keyboard.cpp21
-rw-r--r--backends/common/virtual-keyboard.h2
-rw-r--r--common/image-map.cpp28
-rw-r--r--common/image-map.h28
6 files changed, 101 insertions, 79 deletions
diff --git a/backends/common/virtual-keyboard-parser.cpp b/backends/common/virtual-keyboard-parser.cpp
index e1eef3505c..f282ecd85d 100644
--- a/backends/common/virtual-keyboard-parser.cpp
+++ b/backends/common/virtual-keyboard-parser.cpp
@@ -45,6 +45,16 @@ VirtualKeyboardParser::VirtualKeyboardParser(VirtualKeyboard *kbd) : XMLParser()
_closedCallbacks["mode"] = &VirtualKeyboardParser::parserCallback_ModeClosed;
}
+void VirtualKeyboardParser::cleanup() {
+ _mode = 0;
+ _kbdParsed = false;
+ _initialModeName.clear();
+ if (_parseMode == kParseFull) {
+ // reset keyboard to remove existing config
+ _keyboard->reset();
+ }
+}
+
bool VirtualKeyboardParser::keyCallback(Common::String keyName) {
if (!_callbacks.contains(_activeKey.top()->name))
return parserError("%s is not a valid key name.", keyName.c_str());
@@ -70,6 +80,10 @@ bool VirtualKeyboardParser::parserCallback_Keyboard() {
if (_kbdParsed)
return parserError("Only a single keyboard element is allowed");
+ // if not full parse then we're done
+ if (_parseMode == kParseCheckResolutions)
+ return true;
+
if (!kbdNode->values.contains("initial_mode"))
return parserError("Keyboard element must contain initial_mode attribute");
@@ -118,47 +132,67 @@ bool VirtualKeyboardParser::parserCallback_Mode() {
Common::String name = modeNode->values["name"];
- if (_keyboard->_modes.contains(name))
- return parserError("Mode '%s' has already been defined", name.c_str());
+ if (_parseMode == kParseFull) {
+ // if full parse then add new mode to keyboard
- // create new mode
- VirtualKeyboard::Mode mode;
- mode.name = name;
- _keyboard->_modes[name] = mode;
- _mode = &(_keyboard->_modes[name]);
-
- // if this is the keyboard's initial mode
- // then set it to be the current mode
- if (name == _initialModeName)
- _keyboard->_initialMode = _mode;
+ if (_keyboard->_modes.contains(name))
+ return parserError("Mode '%s' has already been defined", name.c_str());
+
+ VirtualKeyboard::Mode mode;
+ mode.name = name;
+ _keyboard->_modes[name] = mode;
+ _mode = &(_keyboard->_modes[name]);
+
+ // if this is the keyboard's initial mode
+ // then set it to be the current mode
+ if (name == _initialModeName)
+ _keyboard->_initialMode = _mode;
+ } else
+ _mode = &(_keyboard->_modes[name]);
Common::String resolutions = modeNode->values["resolutions"];
- Common::StringTokenizer tok(resolutions, " ,");
+ Common::StringTokenizer tok (resolutions, " ,");
- uint16 scrX = g_system->getOverlayWidth(), scrY = g_system->getOverlayHeight();
+ uint16 scrW = _keyboard->_screenWidth, scrH = _keyboard->_screenHeight;
uint32 diff = 0xFFFFFFFF;
-
+ Common::String newResolution;
for (Common::String res = tok.nextToken(); res.size() > 0; res = tok.nextToken()) {
- int resX, resY;
- if (sscanf(res.c_str(), "%dx%d", &resX, &resY) != 2) {
- parserError("Invalid resolution specification");
+ // TODO: improve the resolution selection
+ int resW, resH;
+ if (sscanf(res.c_str(), "%dx%d", &resW, &resH) != 2) {
+ return parserError("Invalid resolution specification");
} else {
- if (resX == scrX && resY == scrY) {
- _mode->resolution = res;
+ if (resW == scrW && resH == scrH) {
+ newResolution = res;
break;
} else {
- uint16 newDiff = ABS(scrX - resX) + ABS(scrY - resY);
+ uint16 newDiff = ABS(scrW - resW) + ABS(scrH - resH);
if (newDiff < diff) {
diff = newDiff;
- _mode->resolution = res;
+ newResolution = res;
}
}
}
}
- if (_mode->resolution.empty())
+ if (newResolution.empty())
return parserError("No acceptable resolution was found");
+ if (_parseMode == kParseCheckResolutions) {
+ if (_mode->resolution == newResolution) {
+ modeNode->ignore = true;
+ return true;
+ } else {
+ // remove data relating to old resolution
+ ImageMan.unregisterSurface(_mode->bitmapName);
+ _mode->bitmapName.clear();
+ _mode->image = 0;
+ _mode->imageMap.removeAllAreas();
+ }
+ }
+
+ _mode->resolution = newResolution;
+
return true;
}
@@ -181,6 +215,10 @@ bool VirtualKeyboardParser::parserCallback_Event() {
assert(_mode);
+ // if just checking resolutions we're done
+ if (_parseMode == kParseCheckResolutions)
+ return true;
+
Common::String name = evtNode->values["name"];
if (_mode->events.contains(name))
return parserError("Event '%s' has already been defined", name.c_str());
diff --git a/backends/common/virtual-keyboard-parser.h b/backends/common/virtual-keyboard-parser.h
index 98ec5cd0b7..c716d27733 100644
--- a/backends/common/virtual-keyboard-parser.h
+++ b/backends/common/virtual-keyboard-parser.h
@@ -31,30 +31,35 @@
namespace Common {
+enum ParseMode {
+ kParseFull, // when loading keyboard pack for first time
+ kParseCheckResolutions // when re-parsing following a change in screen size
+};
+
class VirtualKeyboardParser : public Common::XMLParser {
typedef bool (VirtualKeyboardParser::*ParserCallback)();
public:
+
VirtualKeyboardParser(VirtualKeyboard *kbd);
+ void setParseMode(ParseMode m) {
+ _parseMode = m;
+ }
protected:
VirtualKeyboard *_keyboard;
/** internal state variables of parser */
+ ParseMode _parseMode;
VirtualKeyboard::Mode *_mode; // pointer to mode currently being parsed
- bool _modeParsed;
Common::String _initialModeName; // name of initial keyboard mode
bool _kbdParsed;
bool keyCallback(Common::String keyName);
bool closedKeyCallback(Common::String keyName);
- void cleanup() {
- _mode = 0;
- _kbdParsed = _modeParsed = false;
- _initialModeName.clear();
- }
+ void cleanup();
bool parserCallback_Keyboard();
bool parserCallback_Mode();
diff --git a/backends/common/virtual-keyboard.cpp b/backends/common/virtual-keyboard.cpp
index 610e6affa4..5ddf5c00d2 100644
--- a/backends/common/virtual-keyboard.cpp
+++ b/backends/common/virtual-keyboard.cpp
@@ -65,8 +65,6 @@ void VirtualKeyboard::reset() {
}
bool VirtualKeyboard::loadKeyboardPack(Common::String packName) {
- // reset to default settings
- reset();
if (ConfMan.hasKey("extrapath"))
Common::File::addDefaultDirectoryRecursive(ConfMan.get("extrapath"));
@@ -108,6 +106,7 @@ bool VirtualKeyboard::loadKeyboardPack(Common::String packName) {
return false;
}
+ _parser->setParseMode(kParseFull);
_loaded = _parser->parse();
if (_loaded)
printf("Keyboard pack '%s' loaded successfully!\n", packName.c_str());
@@ -148,11 +147,11 @@ void VirtualKeyboard::setDefaultPosition()
_kbdBound.moveTo(posX, posY);
}
-void VirtualKeyboard::checkResolution()
+bool VirtualKeyboard::checkModeResolutions()
{
- // check if there is a more suitable resolution
- // in the keyboard pack than the current one
- // based on the _screenWidth & _screenHeight
+ _parser->setParseMode(kParseCheckResolutions);
+ _loaded = _parser->parse();
+ return _loaded;
}
void VirtualKeyboard::move(int16 x, int16 y) {
@@ -215,9 +214,14 @@ void VirtualKeyboard::switchMode(const Common::String& newMode) {
}
void VirtualKeyboard::show() {
+ if (!_loaded) {
+ warning("Keyboard not loaded therefore can't be shown");
+ return;
+ }
if (_screenWidth != _system->getOverlayWidth() || _screenHeight != _system->getOverlayHeight()) {
_screenWidth = _system->getOverlayWidth();
_screenHeight = _system->getOverlayHeight();
+ if (!checkModeResolutions()) return;
}
switchMode(_initialMode);
_displaying = true;
@@ -272,7 +276,8 @@ void VirtualKeyboard::runLoop() {
case Common::EVENT_SCREEN_CHANGED:
_screenWidth = _system->getOverlayWidth();
_screenHeight = _system->getOverlayHeight();
- checkResolution();
+ if (!checkModeResolutions())
+ _displaying = false;
break;
case Common::EVENT_QUIT:
_system->quit();
@@ -280,6 +285,8 @@ void VirtualKeyboard::runLoop() {
default:
break;
}
+ // TODO - remove this line ?
+ if (!_displaying) break;
}
}
// clear keyboard from overlay
diff --git a/backends/common/virtual-keyboard.h b/backends/common/virtual-keyboard.h
index a3585296f9..b98511d464 100644
--- a/backends/common/virtual-keyboard.h
+++ b/backends/common/virtual-keyboard.h
@@ -114,7 +114,7 @@ protected:
// TODO : sort order of all this stuff
void reset();
- void checkResolution();
+ bool checkModeResolutions();
void setDefaultPosition();
void move(int16 x, int16 y);
void switchMode(Mode *newMode);
diff --git a/common/image-map.cpp b/common/image-map.cpp
index 54b4858dd5..f9201618a4 100644
--- a/common/image-map.cpp
+++ b/common/image-map.cpp
@@ -28,10 +28,7 @@
namespace Common {
ImageMap::~ImageMap() {
- HashMap<String, Shape*>::iterator it;
- for (it = _areas.begin(); it != _areas.end(); it++) {
- delete it->_value;
- }
+ removeAllAreas();
}
Rect *ImageMap::createRectArea(const String& id) {
@@ -54,22 +51,21 @@ Polygon *ImageMap::createPolygonArea(const String& id) {
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'");
+void ImageMap::removeArea(const String& id) {
+ if (!_areas.contains(id))
return;
- }
- _areas[target] = shape;
-}
-void ImageMap::addRectMapArea(const Rect& rect, const String& target) {
- areas.push_back(MapArea(rect, target));
+ delete _areas[id];
+ _areas.erase(id);
}
-void ImageMap::addPolygonMapArea(const Polygon& poly, const String& target) {
- areas.push_back(MapArea(poly, target));
+void ImageMap::removeAllAreas() {
+ HashMap<String, Shape*>::iterator it;
+ for (it = _areas.begin(); it != _areas.end(); it++) {
+ delete it->_value;
+ }
+ _areas.clear();
}
-*/
+
String ImageMap::findMapArea(int16 x, int16 y) {
HashMap<String, Shape*>::iterator it;
for (it = _areas.begin(); it != _areas.end(); it++) {
diff --git a/common/image-map.h b/common/image-map.h
index eabc54adf3..1148d96764 100644
--- a/common/image-map.h
+++ b/common/image-map.h
@@ -33,32 +33,6 @@
namespace Common {
-class MapArea {
-public:
- MapArea() : _shape(0), _target() {}
- MapArea(const Rect& r, const String& t) : _target(t) {
- _shape = new Rect(r);
- }
- MapArea(const Polygon& p, const String& t) : _target(t) {
- _shape = new Polygon(p);
- }
- virtual ~MapArea() {
- delete _shape;
- }
-
- virtual bool contains(int x, int y) {
- return _shape->contains(x, y);
- }
-
- String getTarget() { return _target; }
-
-protected:
- /* shape defining the MapArea's boundary */
- Shape *_shape;
- /* string describing the target of MapArea */
- String _target;
-};
-
class ImageMap {
public:
@@ -67,6 +41,8 @@ public:
Rect *createRectArea(const String& id);
Polygon *createPolygonArea(const String& id);
+ void removeArea(const String& id);
+ void removeAllAreas();
//void addMapArea(Shape *shape, const String& target);
/*void addRectMapArea(const Rect& rect, const String& target);