diff options
author | Stephen Kennedy | 2008-08-22 10:36:12 +0000 |
---|---|---|
committer | Stephen Kennedy | 2008-08-22 10:36:12 +0000 |
commit | 2d52f129bb1312d1914c00a8204aded9d872bb1e (patch) | |
tree | ad8f2cbba4d1753dff05f5a2589da84d37df8746 /backends | |
parent | 34518951897d5b90d4d345f7f7465b4f86a67ed8 (diff) | |
download | scummvm-rg350-2d52f129bb1312d1914c00a8204aded9d872bb1e.tar.gz scummvm-rg350-2d52f129bb1312d1914c00a8204aded9d872bb1e.tar.bz2 scummvm-rg350-2d52f129bb1312d1914c00a8204aded9d872bb1e.zip |
Fix for key repeat bug
svn-id: r34094
Diffstat (limited to 'backends')
-rw-r--r-- | backends/keymapper/keymapper.cpp | 48 | ||||
-rw-r--r-- | backends/keymapper/keymapper.h | 8 |
2 files changed, 40 insertions, 16 deletions
diff --git a/backends/keymapper/keymapper.cpp b/backends/keymapper/keymapper.cpp index d453a875cc..9f4b42658b 100644 --- a/backends/keymapper/keymapper.cpp +++ b/backends/keymapper/keymapper.cpp @@ -127,6 +127,12 @@ bool Keymapper::pushKeymap(const String& name, bool inherit) { } void Keymapper::pushKeymap(Keymap *newMap, bool inherit, bool global) { + List<KeyState>::iterator it; + for (it = _keysDown.begin(); it != _keysDown.end(); ++it) { + Action *action = getAction(*it); + if (action) executeAction(action, false); + } + _keysDown.clear(); MapRecord mr = {newMap, inherit, global}; _activeMaps.push(mr); } @@ -144,54 +150,68 @@ bool Keymapper::mapKeyUp(const KeyState& key) { return mapKey(key, false); } -bool Keymapper::mapKey(const KeyState& key, bool isKeyDown) { +bool Keymapper::mapKey(const KeyState& key, bool keyDown) { if (!_enabled) return false; if (_activeMaps.empty()) return false; + Action *action = getAction(key); + if (!action) return false; + + if (keyDown) + _keysDown.push_back(key); + else + _keysDown.remove(key); + + executeAction(action, keyDown); + return true; +} + +Action *Keymapper::getAction(const KeyState& key) { Action *action = 0; - for (int i = _activeMaps.size() - 1; !action && i >= 0; --i) { + for (int i = _activeMaps.size() - 1; i >= 0; --i) { MapRecord mr = _activeMaps[i]; action = mr.keymap->getMappedAction(key); - if (mr.inherit == false) break; + if (action || mr.inherit == false) break; } - if (!action) return false; + return action; +} +void Keymapper::executeAction(const Action *action, bool keyDown) { List<Event>::iterator it; for (it = action->events.begin(); it != action->events.end(); ++it) { Event evt = *it; switch (evt.type) { case EVENT_KEYDOWN: - if (!isKeyDown) evt.type = EVENT_KEYUP; + if (!keyDown) evt.type = EVENT_KEYUP; break; case EVENT_KEYUP: - if (isKeyDown) evt.type = EVENT_KEYDOWN; + if (keyDown) evt.type = EVENT_KEYDOWN; break; case EVENT_LBUTTONDOWN: - if (!isKeyDown) evt.type = EVENT_LBUTTONUP; + if (!keyDown) evt.type = EVENT_LBUTTONUP; break; case EVENT_LBUTTONUP: - if (isKeyDown) evt.type = EVENT_LBUTTONDOWN; + if (keyDown) evt.type = EVENT_LBUTTONDOWN; break; case EVENT_RBUTTONDOWN: - if (!isKeyDown) evt.type = EVENT_RBUTTONUP; + if (!keyDown) evt.type = EVENT_RBUTTONUP; break; case EVENT_RBUTTONUP: - if (isKeyDown) evt.type = EVENT_RBUTTONDOWN; + if (keyDown) evt.type = EVENT_RBUTTONDOWN; break; case EVENT_MBUTTONDOWN: - if (!isKeyDown) evt.type = EVENT_MBUTTONUP; + if (!keyDown) evt.type = EVENT_MBUTTONUP; break; case EVENT_MBUTTONUP: - if (isKeyDown) evt.type = EVENT_MBUTTONDOWN; + if (keyDown) evt.type = EVENT_MBUTTONDOWN; break; default: // don't deliver other events on key up - if (!isKeyDown) continue; + if (!keyDown) continue; } evt.mouse = _eventMan->getMousePos(); _eventMan->pushEvent(evt); } - return true; } const HardwareKey *Keymapper::getHardwareKey(const KeyState& key) { diff --git a/backends/keymapper/keymapper.h b/backends/keymapper/keymapper.h index 78ab2d2203..d6ba89288d 100644 --- a/backends/keymapper/keymapper.h +++ b/backends/keymapper/keymapper.h @@ -141,10 +141,10 @@ public: * If the active keymap contains a Action mapped to the given key, then * the Action's events are pushed into the EventManager's event queue. * @param key key that was pressed - * @param isKeyDown true for key down, false for key up + * @param keyDown true for key down, false for key up * @return true if key was mapped */ - bool mapKey(const KeyState& key, bool isKeyDown); + bool mapKey(const KeyState& key, bool keyDown); /** * @brief Map a key down event. @@ -183,6 +183,9 @@ private: HardwareKeySet *_hardwareKeys; void pushKeymap(Keymap *newMap, bool inherit, bool global); + + Action *getAction(const KeyState& key); + void executeAction(const Action *act, bool keyDown); typedef List<HardwareKey*>::iterator Iterator; @@ -191,6 +194,7 @@ private: bool _enabled; Stack<MapRecord> _activeMaps; + List<KeyState> _keysDown; }; |