From fca5a0ad340da0fd0fd86d00f2c4cedbfd7a3ab8 Mon Sep 17 00:00:00 2001 From: Stephen Kennedy Date: Fri, 15 Aug 2008 01:21:29 +0000 Subject: Virtual Keyboard: * added support for submit, cancel, backspace, and cursor movement commands * minor API modifications svn-id: r33887 --- backends/events/default/default-events.cpp | 2 +- backends/vkeybd/virtual-keyboard-gui.cpp | 2 +- backends/vkeybd/virtual-keyboard-gui.h | 2 +- backends/vkeybd/virtual-keyboard-parser.cpp | 38 +++++++++++----- backends/vkeybd/virtual-keyboard.cpp | 68 ++++++++++++++-------------- backends/vkeybd/virtual-keyboard.h | 65 +++++++++++++------------- backends/vkeybd/vkeybd.zip | Bin 335613 -> 335616 bytes 7 files changed, 96 insertions(+), 81 deletions(-) diff --git a/backends/events/default/default-events.cpp b/backends/events/default/default-events.cpp index af8f9fa231..aad8fee4fc 100644 --- a/backends/events/default/default-events.cpp +++ b/backends/events/default/default-events.cpp @@ -421,7 +421,7 @@ bool DefaultEventManager::pollEvent(Common::Event &event) { // HACK to show/hide keyboard (keyboard is not shown if gui is active) if (event.kbd.keycode == Common::KEYCODE_F6 && event.kbd.flags == 0) { if (_vk->isDisplaying()) { - _vk->hide(); + _vk->close(true); } else { bool isPaused = (g_engine) ? g_engine->isPaused() : true; if (!isPaused) g_engine->pauseEngine(true); diff --git a/backends/vkeybd/virtual-keyboard-gui.cpp b/backends/vkeybd/virtual-keyboard-gui.cpp index 7ef07735f7..87db58d06d 100644 --- a/backends/vkeybd/virtual-keyboard-gui.cpp +++ b/backends/vkeybd/virtual-keyboard-gui.cpp @@ -114,7 +114,7 @@ void VirtualKeyboardGUI::run() { _dispSurface.free(); } -void VirtualKeyboardGUI::hide() { +void VirtualKeyboardGUI::close() { _displaying = false; } diff --git a/backends/vkeybd/virtual-keyboard-gui.h b/backends/vkeybd/virtual-keyboard-gui.h index ba3025f3b6..f1ad92a067 100644 --- a/backends/vkeybd/virtual-keyboard-gui.h +++ b/backends/vkeybd/virtual-keyboard-gui.h @@ -43,7 +43,7 @@ public: void initMode(VirtualKeyboard::Mode *mode); void run(); - void hide(); + void close(); bool isDisplaying() { return _displaying; } void reset(); void startDrag(int16 x, int16 y); diff --git a/backends/vkeybd/virtual-keyboard-parser.cpp b/backends/vkeybd/virtual-keyboard-parser.cpp index f3d71057b7..b35dac277f 100644 --- a/backends/vkeybd/virtual-keyboard-parser.cpp +++ b/backends/vkeybd/virtual-keyboard-parser.cpp @@ -235,17 +235,15 @@ bool VirtualKeyboardParser::parserCallback_Event() { delete evt; return parserError("Key event element must contain code and ascii attributes"); } - evt->type = VirtualKeyboard::kEventKey; - KeyCode code = (KeyCode)atoi(evtNode->values["code"].c_str()); - uint16 ascii = atoi(evtNode->values["ascii"].c_str()); - - byte flags = 0; + KeyState *ks = (KeyState*) malloc(sizeof(KeyState)); + ks->keycode = (KeyCode)atoi(evtNode->values["code"].c_str()); + ks->ascii = atoi(evtNode->values["ascii"].c_str()); + ks->flags = 0; if (evtNode->values.contains("modifiers")) - flags = parseFlags(evtNode->values["modifiers"]); - - evt->data = new KeyState(code, ascii, flags); + ks->flags = parseFlags(evtNode->values["modifiers"]); + evt->data = ks; } else if (type == "modifier") { if (!evtNode->values.contains("modifiers")) { @@ -254,7 +252,7 @@ bool VirtualKeyboardParser::parserCallback_Event() { } evt->type = VirtualKeyboard::kEventModifier; - byte *flags = new byte; + byte *flags = (byte*) malloc(sizeof(byte)); *(flags) = parseFlags(evtNode->values["modifiers"]); evt->data = flags; @@ -265,9 +263,25 @@ bool VirtualKeyboardParser::parserCallback_Event() { } evt->type = VirtualKeyboard::kEventSwitchMode; - evt->data = new String(evtNode->values["mode"]); - } else if (type == "close") { - evt->type = VirtualKeyboard::kEventClose; + String& mode = evtNode->values["mode"]; + char *str = (char*) malloc(sizeof(char) * mode.size() + 1); + memcpy(str, mode.c_str(), sizeof(char) * mode.size()); + str[mode.size()] = 0; + evt->data = str; + } else if (type == "submit") { + evt->type = VirtualKeyboard::kEventSubmit; + evt->data = 0; + } else if (type == "cancel") { + evt->type = VirtualKeyboard::kEventCancel; + evt->data = 0; + } else if (type == "delete") { + evt->type = VirtualKeyboard::kEventDelete; + evt->data = 0; + } else if (type == "move_left") { + evt->type = VirtualKeyboard::kEventMoveLeft; + evt->data = 0; + } else if (type == "move_right") { + evt->type = VirtualKeyboard::kEventMoveRight; evt->data = 0; } else { delete evt; diff --git a/backends/vkeybd/virtual-keyboard.cpp b/backends/vkeybd/virtual-keyboard.cpp index 67bae7783f..ba41cc4686 100644 --- a/backends/vkeybd/virtual-keyboard.cpp +++ b/backends/vkeybd/virtual-keyboard.cpp @@ -36,7 +36,7 @@ VirtualKeyboard::VirtualKeyboard() : _currentMode(0) { _parser = new VirtualKeyboardParser(this); _kbdGUI = new VirtualKeyboardGUI(this); - _loaded = false; + _submitKeys = _loaded = false; } VirtualKeyboard::~VirtualKeyboard() { @@ -139,12 +139,23 @@ void VirtualKeyboard::processAreaClick(const Common::String& area) { break; case kEventSwitchMode: // switch to new mode - switchMode(*(Common::String *)evt->data); + switchMode((char *)evt->data); _keyQueue.clearFlags(); break; - case kEventClose: - // close virtual keyboard - _kbdGUI->hide(); + case kEventSubmit: + close(true); + break; + case kEventCancel: + close(false); + break; + case kEventDelete: + _keyQueue.deleteKey(); + break; + case kEventMoveLeft: + _keyQueue.moveLeft(); + break; + case kEventMoveRight: + _keyQueue.moveRight(); break; } } @@ -188,23 +199,28 @@ void VirtualKeyboard::show() { _kbdGUI->run(); - EventManager *eventMan = _system->getEventManager(); - assert(eventMan); - - // push keydown & keyup events into the event manager - Common::Event evt; - evt.synthetic = false; - while (!_keyQueue.empty()) { - evt.kbd = _keyQueue.pop(); - evt.type = Common::EVENT_KEYDOWN; - eventMan->pushEvent(evt); - evt.type = Common::EVENT_KEYUP; - eventMan->pushEvent(evt); + if (_submitKeys) { + EventManager *eventMan = _system->getEventManager(); + assert(eventMan); + + // push keydown & keyup events into the event manager + Common::Event evt; + evt.synthetic = false; + while (!_keyQueue.empty()) { + evt.kbd = _keyQueue.pop(); + evt.type = Common::EVENT_KEYDOWN; + eventMan->pushEvent(evt); + evt.type = Common::EVENT_KEYUP; + eventMan->pushEvent(evt); + } + } else { + _keyQueue.clear(); } } -void VirtualKeyboard::hide() { - _kbdGUI->hide(); +void VirtualKeyboard::close(bool submit) { + _submitKeys = submit; + _kbdGUI->close(); } bool VirtualKeyboard::isDisplaying() { @@ -230,20 +246,6 @@ void VirtualKeyboard::KeyPressQueue::clearFlags() { void VirtualKeyboard::KeyPressQueue::insertKey(KeyState key) { _strChanged = true; - switch (key.keycode) { - case KEYCODE_LEFT: - moveLeft(); - return; - case KEYCODE_RIGHT: - moveRight(); - return; - case KEYCODE_BACKSPACE: - deleteKey(); - return; - default: - ; - } - key.flags ^= _keyFlags; if ((key.keycode >= Common::KEYCODE_a) && (key.keycode <= Common::KEYCODE_z)) key.ascii = (key.flags & Common::KBD_SHIFT) ? key.keycode - 32 : key.keycode; diff --git a/backends/vkeybd/virtual-keyboard.h b/backends/vkeybd/virtual-keyboard.h index f15eb4aece..71f718a9b2 100644 --- a/backends/vkeybd/virtual-keyboard.h +++ b/backends/vkeybd/virtual-keyboard.h @@ -47,7 +47,11 @@ protected: kEventKey, kEventModifier, kEventSwitchMode, - kEventClose + kEventSubmit, + kEventCancel, + kEventDelete, + kEventMoveLeft, + kEventMoveRight }; struct Event { @@ -57,21 +61,7 @@ protected: Event() : data(0) {} ~Event() { - if (data) { - switch (type) { - case kEventKey: - delete (KeyState*)data; - break; - case kEventModifier: - delete (byte*)data; - break; - case kEventSwitchMode: - delete (String*)data; - break; - case kEventClose: - break; - } - } + if (data) free(data); } }; @@ -144,34 +134,41 @@ public: virtual ~VirtualKeyboard(); /** - * Loads the keyboard pack with the given name. - * The system first looks for an uncompressed keyboard pack by searching - * for packName.xml in the filesystem, if this does not exist then it - * searches for a compressed keyboard pack by looking for packName.zip. - * @param packName name of the keyboard pack - */ + * Loads the keyboard pack with the given name. + * The system first looks for an uncompressed keyboard pack by searching + * for packName.xml in the filesystem, if this does not exist then it + * searches for a compressed keyboard pack by looking for packName.zip. + * @param packName name of the keyboard pack + */ bool loadKeyboardPack(Common::String packName); /** - * Shows the keyboard, starting an event loop that will intercept all - * user input (like a modal GUI dialog). - * It is assumed that the game has been paused, before this is called - */ + * Shows the keyboard, starting an event loop that will intercept all + * user input (like a modal GUI dialog). + * It is assumed that the game has been paused, before this is called + */ void show(); /** - * Hides the keyboard, ending the event loop. - */ - void hide(); + * Hides the keyboard, ending the event loop. + * @param submit if true all accumulated key presses are submitted to + * the event manager + */ + void close(bool submit); /** - * Returns true if the keyboard is currently being shown - */ + * Hides the keyboard, submiting any key presses to the event manager + */ + void submit(); + + /** + * Returns true if the keyboard is currently being shown + */ bool isDisplaying(); /** - * Returns true if the keyboard is loaded and ready to be shown - */ + * Returns true if the keyboard is loaded and ready to be shown + */ bool isLoaded() { return _loaded; } @@ -209,6 +206,8 @@ protected: // TODO : clean up all this stuff String _areaDown; + bool _submitKeys; + }; diff --git a/backends/vkeybd/vkeybd.zip b/backends/vkeybd/vkeybd.zip index e62498cc3d..8c0c778aef 100644 Binary files a/backends/vkeybd/vkeybd.zip and b/backends/vkeybd/vkeybd.zip differ -- cgit v1.2.3