summaryrefslogtreecommitdiff
path: root/src/inputmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-08 21:05:01 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-08 21:05:01 +0300
commitbb258f09a0b50f6382be2ff36637191a8b103c3f (patch)
tree419eb77c8c1502968e89fddff7f1e7c167d86a11 /src/inputmanager.cpp
parent30ef016b0a14f36dc480284e2d775295b5501dd4 (diff)
downloadmanaplus-bb258f09a0b50f6382be2ff36637191a8b103c3f.tar.gz
manaplus-bb258f09a0b50f6382be2ff36637191a8b103c3f.tar.bz2
manaplus-bb258f09a0b50f6382be2ff36637191a8b103c3f.tar.xz
manaplus-bb258f09a0b50f6382be2ff36637191a8b103c3f.zip
Move some more code from keyboardconfig to inputmanager.
Diffstat (limited to 'src/inputmanager.cpp')
-rw-r--r--src/inputmanager.cpp60
1 files changed, 57 insertions, 3 deletions
diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp
index 3a0b22f3e..cc45a79cf 100644
--- a/src/inputmanager.cpp
+++ b/src/inputmanager.cpp
@@ -39,12 +39,27 @@
#include <guichan/exception.hpp>
#include <guichan/focushandler.hpp>
+#include <algorithm>
+
#include "debug.h"
InputManager inputManager;
extern QuitDialog *quitDialog;
+class KeyFunctor
+{
+ public:
+ bool operator() (int key1, int key2)
+ {
+ return keys[key1].priority >= keys[key2].priority;
+ }
+
+ const KeyData *keys;
+
+} keySorter;
+
+
InputManager::InputManager() :
mSetupKey(nullptr),
mNewKeyIndex(Input::KEY_NO_VALUE)
@@ -66,7 +81,7 @@ void InputManager::init()
makeDefault();
retrieve();
- keyboard.updateKeyActionMap();
+ keyboard.update();
}
void InputManager::retrieve()
@@ -332,7 +347,7 @@ void InputManager::setNewKey(const SDL_Event &event)
addActionKey(mNewKeyIndex, INPUT_KEYBOARD, val);
- keyboard.updateKeyActionMap();
+ keyboard.update();
}
void InputManager::unassignKey()
@@ -343,7 +358,7 @@ void InputManager::unassignKey()
key.values[i].type = INPUT_UNKNOWN;
key.values[i].value = -1;
}
- keyboard.updateKeyActionMap();
+ keyboard.update();
}
bool InputManager::handleEvent(const SDL_Event &event)
@@ -459,3 +474,42 @@ bool InputManager::checkKey(const KeyData *key, int mask)
return (key->modKeyIndex == Input::KEY_NO_VALUE
|| isActionActive(key->modKeyIndex));
}
+
+bool InputManager::invokeKey(const KeyData *key, int keyNum, int mask)
+{
+ if (checkKey(key, mask))
+ {
+ InputEvent evt(keyNum, mask);
+ if ((*(keyData[keyNum].action))(evt))
+ return true;
+ }
+ return false;
+}
+
+void InputManager::updateKeyActionMap(KeyToActionMap &actionMap, int type)
+{
+ actionMap.clear();
+
+ for (size_t i = 0; i < Input::KEY_TOTAL; i ++)
+ {
+ if (keyData[i].action)
+ {
+ KeyFunction &key = mKey[i];
+ for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
+ {
+ if (key.values[i2].type == INPUT_KEYBOARD)
+ actionMap[key.values[i2].value].push_back(i);
+ }
+ }
+ }
+
+ keySorter.keys = &keyData[0];
+ KeyToActionMapIter it = actionMap.begin();
+ KeyToActionMapIter it_end = actionMap.end();
+ for (; it != it_end; ++ it)
+ {
+ KeysVector *keys = &it->second;
+ if (keys->size() > 1)
+ sort(keys->begin(), keys->end(), keySorter);
+ }
+}