aboutsummaryrefslogtreecommitdiff
path: root/backends/common/keymap.cpp
diff options
context:
space:
mode:
authorStephen Kennedy2008-07-24 10:00:56 +0000
committerStephen Kennedy2008-07-24 10:00:56 +0000
commitdfcdbb0d335128c99d13ba017a4e36f2338f7736 (patch)
tree727f48a0e5e589229788b0c42b0a73cafd31b39e /backends/common/keymap.cpp
parent2f064da1021344f28c9106285475c72930638390 (diff)
downloadscummvm-rg350-dfcdbb0d335128c99d13ba017a4e36f2338f7736.tar.gz
scummvm-rg350-dfcdbb0d335128c99d13ba017a4e36f2338f7736.tar.bz2
scummvm-rg350-dfcdbb0d335128c99d13ba017a4e36f2338f7736.zip
KeymapManager - implemented loading/saving of keymaps
- Refactoring of code to map a key to a UserAction - now we call a method on UserAction to do it (and it then tells the Keymap class) - General cleanup of code svn-id: r33262
Diffstat (limited to 'backends/common/keymap.cpp')
-rw-r--r--backends/common/keymap.cpp41
1 files changed, 16 insertions, 25 deletions
diff --git a/backends/common/keymap.cpp b/backends/common/keymap.cpp
index 770e308fbc..639b03f78f 100644
--- a/backends/common/keymap.cpp
+++ b/backends/common/keymap.cpp
@@ -1,12 +1,14 @@
#include "backends/common/keymap.h"
+#include "backends/common/hardware-key.h"
namespace Common {
Keymap::Keymap(const Keymap& km) : _actions(km._actions), _keymap() {
init();
for (uint i = 0; i < _actions.size(); i++) {
- if (_actions[i].hwKey) {
- _keymap[_actions[i].hwKey->key] = &_actions[i];
+ const HardwareKey *hwKey = _actions[i].getMappedKey();
+ if (hwKey) {
+ _keymap[hwKey->key] = &_actions[i];
}
}
}
@@ -15,41 +17,30 @@ void Keymap::init() {
_actions.reserve(20);
}
-void Keymap::addAction(const UserAction& action) {
+void Keymap::addAction(UserAction& action) {
if (findUserAction(action.id))
- error("UserAction with id %d already in KeyMap!\n", action.id);
+ error("UserAction with id %d already in KeyMap!", action.id);
+ action.setParent(this);
_actions.push_back(action);
- _actions[_actions.size()-1].hwKey = 0;
}
-void Keymap::mapKeyToAction(UserAction *action, HardwareKey *key) {
- for (uint i = 0; i < _actions.size(); i++) {
- if (&_actions[i] == action) {
- internalMapKey(action, key);
- return;
- }
- }
- error("UserAction not contained in KeyMap\n");
-}
-
-void Keymap::mapKeyToAction(int32 id, HardwareKey *key) {
- UserAction *act = findUserAction(id);
- if (act)
- internalMapKey(act, key);
-}
-
-void Keymap::internalMapKey(UserAction *action, HardwareKey *hwKey) {
+void Keymap::registerMapping(UserAction *action, const HardwareKey *hwKey) {
HashMap<KeyState, UserAction*>::iterator it;
it = _keymap.find(hwKey->key);
// if key is already mapped to an action then un-map it
if (it != _keymap.end())
- it->_value->hwKey = 0;
+ it->_value->mapKey(0);
- action->hwKey = hwKey;
_keymap[hwKey->key] = action;
}
-const UserAction *Keymap::getUserAction(int32 id) const {
+void Keymap::unregisterMapping(UserAction *action) {
+ const HardwareKey *hwKey = action->getMappedKey();
+ if (hwKey)
+ _keymap[hwKey->key] = 0;
+}
+
+UserAction *Keymap::getUserAction(int32 id) {
return findUserAction(id);
}