From 4825afb0187527d7eaa0ea3d903ad716a3eb9562 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Tue, 17 Nov 2015 00:19:10 +0300 Subject: Convert enum InputType into strong typed. --- src/input/inputactiondata.h | 6 ++++-- src/input/inputactionmap.h | 3 ++- src/input/inputitem.h | 12 ++++++++---- src/input/inputmanager.cpp | 15 ++++++++------- src/input/inputmanager.h | 14 +++++++++----- src/input/inputtype.h | 43 ------------------------------------------- src/input/joystick.cpp | 3 ++- src/input/keyboardconfig.cpp | 3 ++- 8 files changed, 35 insertions(+), 64 deletions(-) delete mode 100644 src/input/inputtype.h (limited to 'src/input') 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(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(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/inputtype.h b/src/input/inputtype.h deleted file mode 100644 index 021b8de46..000000000 --- a/src/input/inputtype.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * The ManaPlus Client - * Copyright (C) 2012-2015 The ManaPlus Developers - * - * This file is part of The ManaPlus Client. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#ifndef INPUT_INPUTTYPE_H -#define INPUT_INPUTTYPE_H - -// hack to avoid conflicts with windows headers. -#ifdef KEYBOARD -#undef KEYBOARD -#endif -#ifdef MOUSE -#undef MOUSE -#endif - -namespace InputType -{ - enum Type - { - UNKNOWN = 0, - KEYBOARD = 1, - MOUSE = 2, - JOYSTICK = 3 - }; -} - -#endif // INPUT_INPUTTYPE_H 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" -- cgit v1.2.3-60-g2f50