aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephen Kennedy2008-08-17 12:11:34 +0000
committerStephen Kennedy2008-08-17 12:11:34 +0000
commit63c4a61032bd97b478de9cbf82510f461d08f653 (patch)
tree50763830be3ee133b6374046edf6001fdeaf9f5f
parent8c2340d323dcf7d404e05da147f4e964d0d10133 (diff)
downloadscummvm-rg350-63c4a61032bd97b478de9cbf82510f461d08f653.tar.gz
scummvm-rg350-63c4a61032bd97b478de9cbf82510f461d08f653.tar.bz2
scummvm-rg350-63c4a61032bd97b478de9cbf82510f461d08f653.zip
Various virtual keyboard bug fixes
svn-id: r33969
-rw-r--r--backends/events/default/default-events.cpp16
-rw-r--r--backends/vkeybd/virtual-keyboard-gui.cpp22
-rw-r--r--backends/vkeybd/virtual-keyboard-gui.h1
-rw-r--r--backends/vkeybd/virtual-keyboard-parser.cpp12
-rw-r--r--backends/vkeybd/virtual-keyboard.cpp30
-rw-r--r--backends/vkeybd/virtual-keyboard.h2
6 files changed, 54 insertions, 29 deletions
diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp
index aad8fee4fc..282d8251b5 100644
--- a/backends/events/default/default-events.cpp
+++ b/backends/events/default/default-events.cpp
@@ -423,11 +423,17 @@ bool DefaultEventManager::pollEvent(Common::Event &event) {
if (_vk->isDisplaying()) {
_vk->close(true);
} else {
- bool isPaused = (g_engine) ? g_engine->isPaused() : true;
- if (!isPaused) g_engine->pauseEngine(true);
- _vk->show();
- if (!isPaused) g_engine->pauseEngine(false);
- result = false;
+ static bool enabled = true;
+ if (enabled && _vk->isLoaded() == false) {
+ enabled = _vk->loadKeyboardPack("vkeybd");
+ }
+ if (enabled) {
+ bool isPaused = (g_engine) ? g_engine->isPaused() : true;
+ if (!isPaused) g_engine->pauseEngine(true);
+ _vk->show();
+ if (!isPaused) g_engine->pauseEngine(false);
+ result = false;
+ }
}
} else if (event.kbd.keycode == Common::KEYCODE_F7 && event.kbd.flags == 0) {
if (!_remap) {
diff --git a/backends/vkeybd/virtual-keyboard-gui.cpp b/backends/vkeybd/virtual-keyboard-gui.cpp
index 812190cfda..d46dc695f6 100644
--- a/backends/vkeybd/virtual-keyboard-gui.cpp
+++ b/backends/vkeybd/virtual-keyboard-gui.cpp
@@ -54,8 +54,6 @@ void VirtualKeyboardGUI::initMode(VirtualKeyboard::Mode *mode) {
_kbdBound.setWidth(_kbdSurface->w);
_kbdBound.setHeight(_kbdSurface->h);
- _dispSurface.free();
- _displayEnabled = false;
if (mode->displayArea)
setupDisplayArea(*(mode->displayArea), mode->displayFontColor);
@@ -66,12 +64,14 @@ void VirtualKeyboardGUI::initMode(VirtualKeyboard::Mode *mode) {
}
void VirtualKeyboardGUI::setupDisplayArea(Rect& r, OverlayColor forecolor) {
- // choose font
+
_dispFont = FontMan.getFontByUsage(Graphics::FontManager::kBigGUIFont);
if (!fontIsSuitable(_dispFont, r)) {
_dispFont = FontMan.getFontByUsage(Graphics::FontManager::kGUIFont);
- if (!fontIsSuitable(_dispFont, r))
+ if (!fontIsSuitable(_dispFont, r)) {
+ _displayEnabled = false;
return;
+ }
}
_dispX = _kbdBound.left + r.left;
_dispY = _kbdBound.top + r.top + (r.height() - _dispFont->getFontHeight()) / 2;
@@ -79,7 +79,7 @@ void VirtualKeyboardGUI::setupDisplayArea(Rect& r, OverlayColor forecolor) {
_dispForeColor = forecolor;
_dispBackColor = _dispForeColor + 0xFF;
_dispSurface.create(r.width(), _dispFont->getFontHeight(), sizeof(OverlayColor));
- _dispSurface.fillRect(r, _dispBackColor);
+ _dispSurface.fillRect(Rect(_dispSurface.w, _dispSurface.h), _dispBackColor);
_displayEnabled = true;
}
@@ -88,11 +88,12 @@ bool VirtualKeyboardGUI::fontIsSuitable(const Graphics::Font *font, const Rect&
font->getFontHeight() < rect.height());
}
-void VirtualKeyboardGUI::run() {
+void VirtualKeyboardGUI::checkScreenChanged() {
if (_lastScreenChanged != _system->getScreenChangeID())
- screenChanged();
+ screenChanged();
+}
- // TODO: set default position if position is somehow invalid (ie. after screen change)
+void VirtualKeyboardGUI::run() {
if (_firstRun) {
_firstRun = false;
moveToDefaultPosition();
@@ -195,8 +196,11 @@ void VirtualKeyboardGUI::move(int16 x, int16 y) {
void VirtualKeyboardGUI::screenChanged() {
_lastScreenChanged = _system->getScreenChangeID();
- if (!_kbd->checkModeResolutions())
+ if (!_kbd->checkModeResolutions()) {
_displaying = false;
+ return;
+ }
+ moveToDefaultPosition();
}
diff --git a/backends/vkeybd/virtual-keyboard-gui.h b/backends/vkeybd/virtual-keyboard-gui.h
index 6d05a24142..8171f166f1 100644
--- a/backends/vkeybd/virtual-keyboard-gui.h
+++ b/backends/vkeybd/virtual-keyboard-gui.h
@@ -42,6 +42,7 @@ public:
~VirtualKeyboardGUI();
void initMode(VirtualKeyboard::Mode *mode);
+ void checkScreenChanged();
void run();
void close();
bool isDisplaying() { return _displaying; }
diff --git a/backends/vkeybd/virtual-keyboard-parser.cpp b/backends/vkeybd/virtual-keyboard-parser.cpp
index 971b0c2bd7..bb575d64c1 100644
--- a/backends/vkeybd/virtual-keyboard-parser.cpp
+++ b/backends/vkeybd/virtual-keyboard-parser.cpp
@@ -134,19 +134,17 @@ bool VirtualKeyboardParser::parserCallback_Mode() {
if (_parseMode == kParseFull) {
// if full parse then add new mode to keyboard
-
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 (name == _initialModeName)
- _keyboard->_initialMode = _mode;
- } else
- _mode = &(_keyboard->_modes[name]);
+ _mode = &(_keyboard->_modes[name]);
+ if (name == _initialModeName)
+ _keyboard->_initialMode = _mode;
String resolutions = modeNode->values["resolutions"];
StringTokenizer tok (resolutions, " ,");
@@ -189,6 +187,8 @@ bool VirtualKeyboardParser::parserCallback_Mode() {
_mode->bitmapName.clear();
_mode->image = 0;
_mode->imageMap.removeAllAreas();
+ delete _mode->displayArea;
+ _mode->displayArea = 0;
}
}
diff --git a/backends/vkeybd/virtual-keyboard.cpp b/backends/vkeybd/virtual-keyboard.cpp
index bb3c365a6c..3a66c75091 100644
--- a/backends/vkeybd/virtual-keyboard.cpp
+++ b/backends/vkeybd/virtual-keyboard.cpp
@@ -27,6 +27,8 @@
#include "backends/vkeybd/virtual-keyboard-gui.h"
#include "backends/vkeybd/virtual-keyboard-parser.h"
#include "backends/vkeybd/keycode-descriptions.h"
+#include "common/config-manager.h"
+#include "common/fs.h"
#include "graphics/imageman.h"
#define KEY_START_CHAR ('[')
@@ -73,12 +75,25 @@ void VirtualKeyboard::reset() {
}
bool VirtualKeyboard::loadKeyboardPack(Common::String packName) {
- if (Common::File::exists(packName + ".xml")) {
+ FilesystemNode *vkDir = 0;
+ if (ConfMan.hasKey("vkeybdpath")) {
+ vkDir = new FilesystemNode(ConfMan.get("vkeybdpath"));
+ } else if (ConfMan.hasKey("extrapath")) {
+ vkDir = new FilesystemNode(ConfMan.get("extrapath"));
+ } else { // use current directory
+ vkDir = new FilesystemNode(".");
+ }
+
+ // TODO - make parser support FilesystemNode's
+ File::addDefaultDirectory(vkDir->getPath());
+
+ if (vkDir->getChild(packName + ".xml").exists()) {
// uncompressed keyboard pack
+
if (!_parser->loadFile(packName + ".xml"))
return false;
- } else if (Common::File::exists(packName + ".zip")) {
+ } else if (vkDir->getChild(packName + ".zip").exists()) {
// compressed keyboard pack
#ifdef USE_ZLIB
unzFile zipFile = unzOpen((packName + ".zip").c_str());
@@ -123,6 +138,7 @@ bool VirtualKeyboard::checkModeResolutions()
{
_parser->setParseMode(kParseCheckResolutions);
_loaded = _parser->parse();
+ _kbdGUI->initMode(_currentMode);
return _loaded;
}
@@ -197,15 +213,13 @@ void VirtualKeyboard::handleMouseUp(int16 x, int16 y) {
}
void VirtualKeyboard::show() {
+ if (_loaded) _kbdGUI->checkScreenChanged();
if (!_loaded) {
- // if not loaded then load default "vkeybd" pack
- if (!loadKeyboardPack("vkeybd")) {
- warning("Keyboard not loaded therefore can't be shown");
- return;
- }
+ warning("Virtual keyboard not loaded!");
+ return;
}
- switchMode(_initialMode);
+ switchMode(_initialMode);
_kbdGUI->run();
if (_submitKeys) {
diff --git a/backends/vkeybd/virtual-keyboard.h b/backends/vkeybd/virtual-keyboard.h
index f5e9a76642..2325b4b251 100644
--- a/backends/vkeybd/virtual-keyboard.h
+++ b/backends/vkeybd/virtual-keyboard.h
@@ -80,7 +80,7 @@ protected:
OverlayColor displayFontColor;
Mode() : image(0), displayArea(0) {}
- ~Mode() { if (displayArea) delete displayArea; }
+ ~Mode() { delete displayArea; }
};
typedef Common::HashMap<Common::String, Mode, Common::IgnoreCase_Hash, Common::IgnoreCase_EqualTo> ModeMap;