diff options
author | Andrei Karas <akaras@inbox.ru> | 2014-03-10 15:29:19 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2014-03-10 16:44:16 +0300 |
commit | 33d1477fb7cf090e5af1860d2ab2ad763400d866 (patch) | |
tree | f6873afb4ba5682eaee6b55bba32ac3bce963606 /src | |
parent | 9105408ba52b7639d8553855e47ec452d2e22e17 (diff) | |
download | plus-33d1477fb7cf090e5af1860d2ab2ad763400d866.tar.gz plus-33d1477fb7cf090e5af1860d2ab2ad763400d866.tar.bz2 plus-33d1477fb7cf090e5af1860d2ab2ad763400d866.tar.xz plus-33d1477fb7cf090e5af1860d2ab2ad763400d866.zip |
Remove duplicate code from inputmanager.
Diffstat (limited to 'src')
-rw-r--r-- | src/input/inputmanager.cpp | 79 | ||||
-rw-r--r-- | src/input/inputmanager.h | 2 |
2 files changed, 30 insertions, 51 deletions
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 5d157f0fa..d611e4790 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -216,69 +216,46 @@ void InputManager::store() const } } -void InputManager::resetKeys() +void InputManager::resetKey(const int i) { - for (int i = 0; i < Input::KEY_TOTAL; i++) + KeyFunction &key = mKey[i]; + for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++) { - KeyFunction &key = mKey[i]; - for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++) - { - KeyItem &ki2 = key.values[i2]; - ki2.type = INPUT_UNKNOWN; - ki2.value = -1; - } - const KeyData &kd = keyData[i]; - KeyItem &val0 = key.values[0]; - val0.type = kd.defaultType1; - KeyItem &val1 = key.values[1]; - val1.type = kd.defaultType2; + KeyItem &ki2 = key.values[i2]; + ki2.type = INPUT_UNKNOWN; + ki2.value = -1; + } + const KeyData &kd = keyData[i]; + KeyItem &val0 = key.values[0]; + val0.type = kd.defaultType1; + KeyItem &val1 = key.values[1]; + val1.type = kd.defaultType2; #ifdef USE_SDL2 - if (kd.defaultType1 == INPUT_KEYBOARD) - val0.value = SDL_GetScancodeFromKey(kd.defaultValue1); - else - val0.value = kd.defaultValue1; - if (kd.defaultType2 == INPUT_KEYBOARD) - val1.value = SDL_GetScancodeFromKey(kd.defaultValue2); - else - val1.value = kd.defaultValue2; -#else + if (kd.defaultType1 == INPUT_KEYBOARD) + val0.value = SDL_GetScancodeFromKey(kd.defaultValue1); + else val0.value = kd.defaultValue1; + if (kd.defaultType2 == INPUT_KEYBOARD) + val1.value = SDL_GetScancodeFromKey(kd.defaultValue2); + else val1.value = kd.defaultValue2; +#else + val0.value = kd.defaultValue1; + val1.value = kd.defaultValue2; #endif - } +} + +void InputManager::resetKeys() +{ + for (int i = 0; i < Input::KEY_TOTAL; i++) + resetKey(i); } void InputManager::makeDefault(const int i) { if (i >= 0 && i < Input::KEY_TOTAL) { - KeyFunction &key = mKey[i]; - for (size_t i2 = 1; i2 < KeyFunctionSize; i2 ++) - { - KeyItem &ki2 = key.values[i2]; - ki2.type = INPUT_UNKNOWN; - ki2.value = -1; - } - const KeyData &kd = keyData[i]; - KeyItem &val0 = key.values[0]; - val0.type = kd.defaultType1; - KeyItem &val1 = key.values[1]; - val1.type = kd.defaultType2; - -#ifdef USE_SDL2 - if (kd.defaultType1 == INPUT_KEYBOARD) - val0.value = SDL_GetScancodeFromKey(kd.defaultValue1); - else - val0.value = kd.defaultValue1; - if (kd.defaultType2 == INPUT_KEYBOARD) - val1.value = SDL_GetScancodeFromKey(kd.defaultValue2); - else - val1.value = kd.defaultValue2; -#else - val0.value = kd.defaultValue1; - val1.value = kd.defaultValue2; -#endif - + resetKey(i); update(); } } diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h index fcd1252c0..bf9e04f34 100644 --- a/src/input/inputmanager.h +++ b/src/input/inputmanager.h @@ -181,6 +181,8 @@ class InputManager final void executeAction(const int keyNum); protected: + void resetKey(const int i); + static bool isActionActive0(const int index) A_WARN_UNUSED; Setup_Input *mSetupInput; /**< Reference to setup window */ |