summaryrefslogtreecommitdiff
path: root/src/inputmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2012-04-18 02:58:23 +0300
committerAndrei Karas <akaras@inbox.ru>2012-04-18 02:58:23 +0300
commit23f87c10db7e6b149e9e1f351e1a82516c545df7 (patch)
treea64be1829568f16108c0a39c4a9a5e3957466831 /src/inputmanager.cpp
parent0f82a8b4a599fbeb2663680deb406bbc15a67576 (diff)
downloadmv-23f87c10db7e6b149e9e1f351e1a82516c545df7.tar.gz
mv-23f87c10db7e6b149e9e1f351e1a82516c545df7.tar.bz2
mv-23f87c10db7e6b149e9e1f351e1a82516c545df7.tar.xz
mv-23f87c10db7e6b149e9e1f351e1a82516c545df7.zip
First step for dehardcode input handling in widgets.
Now widgets can check for input event.
Diffstat (limited to 'src/inputmanager.cpp')
-rw-r--r--src/inputmanager.cpp26
1 files changed, 24 insertions, 2 deletions
diff --git a/src/inputmanager.cpp b/src/inputmanager.cpp
index 283b07d6c..fcb40d4ea 100644
--- a/src/inputmanager.cpp
+++ b/src/inputmanager.cpp
@@ -590,15 +590,16 @@ bool InputManager::invokeKey(const KeyData *key, int keyNum)
return false;
}
-void InputManager::updateKeyActionMap(KeyToActionMap &actionMap, int type)
+void InputManager::updateKeyActionMap(KeyToActionMap &actionMap,
+ KeyToIdMap &idMap, int type)
{
actionMap.clear();
for (size_t i = 0; i < Input::KEY_TOTAL; i ++)
{
+ KeyFunction &key = mKey[i];
if (keyData[i].action)
{
- KeyFunction &key = mKey[i];
for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
{
const KeyItem &ki = key.values[i2];
@@ -606,6 +607,15 @@ void InputManager::updateKeyActionMap(KeyToActionMap &actionMap, int type)
actionMap[ki.value].push_back(i);
}
}
+ if (keyData[i].configField && (keyData[i].grp & Input::GRP_GUI))
+ {
+ for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++)
+ {
+ const KeyItem &ki = key.values[i2];
+ if (ki.type == type && ki.value != -1)
+ idMap[ki.value] = i;
+ }
+ }
}
keySorter.keys = &keyData[0];
@@ -657,3 +667,15 @@ int InputManager::getKeyIndex(int value, int grp, int type) const
}
return Input::KEY_NO_VALUE;
}
+
+int InputManager::getActionByKey(const SDL_Event &event)
+{
+ // for now support only keyboard events
+ if (event.type == SDL_KEYDOWN)
+ {
+ int idx = keyboard.getActionId(event);
+ if (idx >= 0 && checkKey(&keyData[idx]))
+ return idx;
+ }
+ return -1;
+}