diff options
author | Andrei Karas <akaras@inbox.ru> | 2015-11-17 00:19:10 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2015-11-17 00:19:10 +0300 |
commit | 4825afb0187527d7eaa0ea3d903ad716a3eb9562 (patch) | |
tree | e516623a908eb6a8a4d053bbc39a36ff81aa4141 /src | |
parent | b3d17866a3c5700b52c2b0b954fce132a52c1dbf (diff) | |
download | manaverse-4825afb0187527d7eaa0ea3d903ad716a3eb9562.tar.gz manaverse-4825afb0187527d7eaa0ea3d903ad716a3eb9562.tar.bz2 manaverse-4825afb0187527d7eaa0ea3d903ad716a3eb9562.tar.xz manaverse-4825afb0187527d7eaa0ea3d903ad716a3eb9562.zip |
Convert enum InputType into strong typed.
Diffstat (limited to 'src')
-rw-r--r-- | src/enums/input/inputtype.h (renamed from src/input/inputtype.h) | 22 | ||||
-rw-r--r-- | src/input/inputactiondata.h | 6 | ||||
-rw-r--r-- | src/input/inputactionmap.h | 3 | ||||
-rw-r--r-- | src/input/inputitem.h | 12 | ||||
-rw-r--r-- | src/input/inputmanager.cpp | 15 | ||||
-rw-r--r-- | src/input/inputmanager.h | 14 | ||||
-rw-r--r-- | src/input/joystick.cpp | 3 | ||||
-rw-r--r-- | src/input/keyboardconfig.cpp | 3 |
8 files changed, 46 insertions, 32 deletions
diff --git a/src/input/inputtype.h b/src/enums/input/inputtype.h index 021b8de46..7db34d8a5 100644 --- a/src/input/inputtype.h +++ b/src/enums/input/inputtype.h @@ -18,8 +18,10 @@ * along with this program. If not, see <http://www.gnu.org/licenses/>. */ -#ifndef INPUT_INPUTTYPE_H -#define INPUT_INPUTTYPE_H +#ifndef ENUMS_INPUT_INPUTTYPE_H +#define ENUMS_INPUT_INPUTTYPE_H + +#include "enums/simpletypes/enumdefines.h" // hack to avoid conflicts with windows headers. #ifdef KEYBOARD @@ -29,15 +31,13 @@ #undef MOUSE #endif -namespace InputType +enumStart(InputType) { - enum Type - { - UNKNOWN = 0, - KEYBOARD = 1, - MOUSE = 2, - JOYSTICK = 3 - }; + UNKNOWN = 0, + KEYBOARD = 1, + MOUSE = 2, + JOYSTICK = 3 } +enumEnd(InputType); -#endif // INPUT_INPUTTYPE_H +#endif // ENUMS_INPUT_INPUTTYPE_H diff --git a/src/input/inputactiondata.h b/src/input/inputactiondata.h index 0feb8567b..5acef08ac 100644 --- a/src/input/inputactiondata.h +++ b/src/input/inputactiondata.h @@ -25,15 +25,17 @@ #include "actions/actionfuncptr.h" +#include "enums/input/inputtype.h" + #include "enums/simpletypes/useargs.h" #include "enums/simpletypes/protected.h" struct InputActionData final { const char *const configField; - const int defaultType1; + const InputTypeT defaultType1; const int defaultValue1; - const int defaultType2; + const InputTypeT defaultType2; const int defaultValue2; const int grp; const ActionFuncPtr action; diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h index 703913227..3496732aa 100644 --- a/src/input/inputactionmap.h +++ b/src/input/inputactionmap.h @@ -35,10 +35,11 @@ #include "actions/target.h" #include "actions/windows.h" +#include "enums/input/inputtype.h" + #include "input/inputactiondata.h" #include "input/inputcondition.h" #include "input/inputmanager.h" -#include "input/inputtype.h" #include "localconsts.h" diff --git a/src/input/inputitem.h b/src/input/inputitem.h index 5abe34ad1..c3260ff03 100644 --- a/src/input/inputitem.h +++ b/src/input/inputitem.h @@ -21,20 +21,24 @@ #ifndef INPUT_INPUTITEM_H #define INPUT_INPUTITEM_H +#include "enums/input/inputtype.h" + #include "localconsts.h" struct InputItem final { InputItem() : - type(-1), + type(InputType::UNKNOWN), value(-1) { } - InputItem(const int type0, const int value0) : - type(type0), value(value0) + InputItem(const InputTypeT type0, + const int value0) : + type(type0), + value(value0) { } - int type; + InputTypeT type; int value; }; diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp index 59fd1ff2d..8fe1e80de 100644 --- a/src/input/inputmanager.cpp +++ b/src/input/inputmanager.cpp @@ -146,7 +146,7 @@ void InputManager::retrieve() std::string keyStr2 = *it; if (keyStrSize < 2) continue; - int type = InputType::KEYBOARD; + InputTypeT type = InputType::KEYBOARD; if ((keyStr2[0] < '0' || keyStr2[0] > '9') && keyStr2[0] != '-') { @@ -463,7 +463,7 @@ std::string InputManager::getKeyValueByNameLong(const std::string &keyName) } void InputManager::addActionKey(const InputActionT action, - const int type, + const InputTypeT type, const int val) { if (static_cast<int>(action) < 0 || action >= InputAction::TOTAL) @@ -496,7 +496,8 @@ void InputManager::addActionKey(const InputActionT action, key.values[idx] = InputItem(type, val); } -void InputManager::setNewKey(const SDL_Event &event, const int type) +void InputManager::setNewKey(const SDL_Event &event, + const InputTypeT type) { int val = -1; if (type == InputType::KEYBOARD) @@ -525,7 +526,7 @@ void InputManager::unassignKey() #ifndef DYECMD bool InputManager::handleAssignKey(const SDL_Event &event, - const int type) + const InputTypeT type) { if (setupWindow && setupWindow->isWindowVisible() && getNewKeyIndex() > InputAction::NO_VALUE) @@ -539,7 +540,7 @@ bool InputManager::handleAssignKey(const SDL_Event &event, } #else bool InputManager::handleAssignKey(const SDL_Event &event A_UNUSED, - const int type A_UNUSED) + const InputTypeT type A_UNUSED) { return false; } @@ -863,7 +864,7 @@ bool InputManager::executeChatCommand(const InputActionT keyNum, void InputManager::updateKeyActionMap(KeyToActionMap &actionMap, KeyToIdMap &idMap, KeyTimeMap &keyTimeMap, - const int type) const + const InputType type) const { actionMap.clear(); keyTimeMap.clear(); @@ -934,7 +935,7 @@ bool InputManager::triggerAction(const KeysVector *const ptrs) InputActionT InputManager::getKeyIndex(const int value, const int grp, - const int type) const + const InputTypeT type) const { for (size_t i = 0; i < static_cast<size_t>(InputAction::TOTAL); i++) { diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h index cc571c372..df759cacc 100644 --- a/src/input/inputmanager.h +++ b/src/input/inputmanager.h @@ -23,6 +23,8 @@ #include "input/inputfunction.h" +#include "enums/input/inputtype.h" + #include "events/inputevent.h" #include "utils/stringmap.h" @@ -77,10 +79,11 @@ class InputManager final std::string getKeyValueByNameLong(const std::string &keyName); void addActionKey(const InputActionT action, - const int type, + const InputTypeT type, const int val); - void setNewKey(const SDL_Event &event, const int type); + void setNewKey(const SDL_Event &event, + const InputTypeT type); void unassignKey(); @@ -106,12 +109,13 @@ class InputManager final void updateKeyActionMap(KeyToActionMap &actionMap, KeyToIdMap &idMap, KeyTimeMap &keyTimeMap, - const int type) const; + const InputType type) const; bool invokeKey(const InputActionData *const key, const InputActionT keyNum); - bool handleAssignKey(const SDL_Event &event, const int type); + bool handleAssignKey(const SDL_Event &event, + const InputTypeT type); static void handleRepeat(); @@ -119,7 +123,7 @@ class InputManager final InputActionT getKeyIndex(const int value, const int grp, - const int type) const A_WARN_UNUSED; + const InputTypeT type) const A_WARN_UNUSED; static void update(); diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp index 9e674a263..f1c0660f2 100644 --- a/src/input/joystick.cpp +++ b/src/input/joystick.cpp @@ -27,8 +27,9 @@ #include "settings.h" #include "sdlshared.h" +#include "enums/input/inputtype.h" + #include "input/inputmanager.h" -#include "input/inputtype.h" #include "utils/timer.h" diff --git a/src/input/keyboardconfig.cpp b/src/input/keyboardconfig.cpp index 80ad2fcd9..d2497e175 100644 --- a/src/input/keyboardconfig.cpp +++ b/src/input/keyboardconfig.cpp @@ -24,8 +24,9 @@ #include "configuration.h" +#include "enums/input/inputtype.h" + #include "input/inputmanager.h" -#include "input/inputtype.h" #include "utils/gettext.h" |