summaryrefslogtreecommitdiff
path: root/src/input/inputmanager.cpp
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2014-03-10 15:29:19 +0300
committerAndrei Karas <akaras@inbox.ru>2014-03-10 16:44:16 +0300
commit33d1477fb7cf090e5af1860d2ab2ad763400d866 (patch)
treef6873afb4ba5682eaee6b55bba32ac3bce963606 /src/input/inputmanager.cpp
parent9105408ba52b7639d8553855e47ec452d2e22e17 (diff)
downloadmv-33d1477fb7cf090e5af1860d2ab2ad763400d866.tar.gz
mv-33d1477fb7cf090e5af1860d2ab2ad763400d866.tar.bz2
mv-33d1477fb7cf090e5af1860d2ab2ad763400d866.tar.xz
mv-33d1477fb7cf090e5af1860d2ab2ad763400d866.zip
Remove duplicate code from inputmanager.
Diffstat (limited to 'src/input/inputmanager.cpp')
-rw-r--r--src/input/inputmanager.cpp79
1 files changed, 28 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();
}
}