From bb258f09a0b50f6382be2ff36637191a8b103c3f Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Sun, 8 Apr 2012 21:05:01 +0300 Subject: Move some more code from keyboardconfig to inputmanager. --- src/keyboardconfig.cpp | 59 ++++++-------------------------------------------- 1 file changed, 7 insertions(+), 52 deletions(-) (limited to 'src/keyboardconfig.cpp') diff --git a/src/keyboardconfig.cpp b/src/keyboardconfig.cpp index a56f2cfa6..4dfab8852 100644 --- a/src/keyboardconfig.cpp +++ b/src/keyboardconfig.cpp @@ -35,27 +35,11 @@ #include -#include - #include "debug.h" -class KeyFunctor -{ - public: - bool operator() (int key1, int key2) - { - return keys[key1].priority >= keys[key2].priority; - } - - const KeyData *keys; - -} keySorter; - void KeyboardConfig::init() { mEnabled = true; - - updateKeyActionMap(); } int KeyboardConfig::getKeyValueFromEvent(const SDL_Event &event) const @@ -120,34 +104,6 @@ SDLKey KeyboardConfig::getKeyFromEvent(const SDL_Event &event) const return event.key.keysym.sym; } -void KeyboardConfig::updateKeyActionMap() -{ - mKeyToAction.clear(); - - for (size_t i = 0; i < Input::KEY_TOTAL; i ++) - { - if (keyData[i].action) - { - KeyFunction &key = inputManager.getKey(i); - for (size_t i2 = 0; i2 < KeyFunctionSize; i2 ++) - { - if (key.values[i2].type == INPUT_KEYBOARD) - mKeyToAction[key.values[i2].value].push_back(i); - } - } - } - - keySorter.keys = &keyData[0]; - KeyToActionMapIter it = mKeyToAction.begin(); - KeyToActionMapIter it_end = mKeyToAction.end(); - for (; it != it_end; ++ it) - { - KeysVector *keys = &it->second; - if (keys->size() > 1) - sort(keys->begin(), keys->end(), keySorter); - } -} - bool KeyboardConfig::triggerAction(const SDL_Event &event) { const int i = getKeyValueFromEvent(event); @@ -167,14 +123,8 @@ bool KeyboardConfig::triggerAction(const SDL_Event &event) if (keyNum < 0 || keyNum >= Input::KEY_TOTAL) continue; - if (inputManager.checkKey(&keyData[keyNum], mask)) - { - InputEvent evt(keyNum, mask); - if ((*(keyData[keyNum].action))(evt)) - { - return true; - } - } + if (inputManager.invokeKey(&keyData[keyNum], keyNum, mask)) + return true; } } return false; @@ -193,3 +143,8 @@ bool KeyboardConfig::isActionActive(int index) const } return false; } + +void KeyboardConfig::update() +{ + inputManager.updateKeyActionMap(mKeyToAction, INPUT_KEYBOARD); +} -- cgit v1.2.3-70-g09d2