aboutsummaryrefslogtreecommitdiff
path: root/backends/common/keymap.cpp
diff options
context:
space:
mode:
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);
}