summaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2015-05-31 00:19:18 +0300
committerAndrei Karas <akaras@inbox.ru>2015-05-31 00:19:18 +0300
commit694e07d193e7c5758a7d672b45668651b034003d (patch)
tree20a4aec8dee2b3b5475db9f3667e797fb43c603b /src/input
parentc9a84749b3b71d4df6cc3b9b488d60dc4a013a20 (diff)
downloadmanaverse-694e07d193e7c5758a7d672b45668651b034003d.tar.gz
manaverse-694e07d193e7c5758a7d672b45668651b034003d.tar.bz2
manaverse-694e07d193e7c5758a7d672b45668651b034003d.tar.xz
manaverse-694e07d193e7c5758a7d672b45668651b034003d.zip
Convert InputAction enum into strong typed enum.
Diffstat (limited to 'src/input')
-rw-r--r--src/input/inputactiondata.h4
-rw-r--r--src/input/inputactionmap.h9
-rw-r--r--src/input/inputactionoperators.cpp32
-rw-r--r--src/input/inputactionoperators.h31
-rw-r--r--src/input/inputactionsortfunctor.h6
-rw-r--r--src/input/inputmanager.cpp126
-rw-r--r--src/input/inputmanager.h52
-rw-r--r--src/input/joystick.cpp2
-rw-r--r--src/input/joystick.h2
-rw-r--r--src/input/keyboardconfig.cpp14
-rw-r--r--src/input/keyboardconfig.h10
-rw-r--r--src/input/keyinput.h10
12 files changed, 195 insertions, 103 deletions
diff --git a/src/input/inputactiondata.h b/src/input/inputactiondata.h
index c0a2b975b..f25a5a7f7 100644
--- a/src/input/inputactiondata.h
+++ b/src/input/inputactiondata.h
@@ -25,6 +25,8 @@
#include "actions/actionfuncptr.h"
+#include "enums/input/inputaction.h"
+
#include "enums/simpletypes/useargs.h"
struct InputActionData final
@@ -36,7 +38,7 @@ struct InputActionData final
const int defaultValue2;
const int grp;
const ActionFuncPtr action;
- const int modKeyIndex;
+ const InputActionT modKeyIndex;
const int priority;
const int condition;
const std::string chatCommand;
diff --git a/src/input/inputactionmap.h b/src/input/inputactionmap.h
index cd57e47a7..b96a187f8 100644
--- a/src/input/inputactionmap.h
+++ b/src/input/inputactionmap.h
@@ -43,18 +43,19 @@
#include "localconsts.h"
#define defaultAction(name) \
- InputType::UNKNOWN, InputAction::NO_VALUE, \
- InputType::UNKNOWN, InputAction::NO_VALUE, \
+ InputType::UNKNOWN, -1, \
+ InputType::UNKNOWN, -1, \
Input::GRP_DEFAULT, \
name, \
InputAction::NO_VALUE, 50
#define addKey(name) InputType::KEYBOARD, name
-#define emptyKey InputType::UNKNOWN, InputAction::NO_VALUE
+#define emptyKey InputType::UNKNOWN, -1
#define joystickButton(num) InputType::JOYSTICK, num
// keyData must be in same order as enum keyAction.
-static const InputActionData inputActionData[InputAction::TOTAL] = {
+static const InputActionData inputActionData
+ [static_cast<size_t>(InputAction::TOTAL)] = {
{"keyMoveUp",
addKey(SDLK_UP),
emptyKey,
diff --git a/src/input/inputactionoperators.cpp b/src/input/inputactionoperators.cpp
new file mode 100644
index 000000000..a2c0eb496
--- /dev/null
+++ b/src/input/inputactionoperators.cpp
@@ -0,0 +1,32 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 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 <http://www.gnu.org/licenses/>.
+ */
+
+#include "input/inputactionoperators.h"
+
+InputActionT operator+(InputActionT action, const int& i)
+{
+ action = static_cast<InputActionT>(static_cast<int>(action) + i);
+ return action;
+}
+
+int operator-(const InputActionT &action1, const InputActionT &action2)
+{
+ return static_cast<int>(action1) - static_cast<int>(action2);
+}
diff --git a/src/input/inputactionoperators.h b/src/input/inputactionoperators.h
new file mode 100644
index 000000000..2a5244c46
--- /dev/null
+++ b/src/input/inputactionoperators.h
@@ -0,0 +1,31 @@
+/*
+ * The ManaPlus Client
+ * Copyright (C) 2007 Joshua Langley <joshlangley@optusnet.com.au>
+ * Copyright (C) 2009-2010 The Mana Developers
+ * Copyright (C) 2011-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 <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef INPUT_INPUTACTIONOPERATORS_H
+#define INPUT_INPUTACTIONOPERATORS_H
+
+#include "enums/input/inputaction.h"
+
+InputActionT operator+(InputActionT action, const int& i);
+int operator-(const InputActionT &action1, const InputActionT &action2);
+
+#endif // INPUT_INPUTACTIONOPERATORS_H
diff --git a/src/input/inputactionsortfunctor.h b/src/input/inputactionsortfunctor.h
index 9582d70e0..fbd9b79f3 100644
--- a/src/input/inputactionsortfunctor.h
+++ b/src/input/inputactionsortfunctor.h
@@ -28,9 +28,11 @@
class InputActionSortFunctor final
{
public:
- bool operator() (const int key1, const int key2) const
+ bool operator() (const InputActionT key1,
+ const InputActionT key2) const
{
- return keys[key1].priority >= keys[key2].priority;
+ return keys[static_cast<size_t>(key1)].priority
+ >= keys[static_cast<size_t>(key2)].priority;
}
const InputActionData *keys;
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index 8b5cb97e2..12c28c806 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -83,7 +83,9 @@ InputManager::InputManager() :
void InputManager::init()
{
- for (unsigned int i = 0; i < InputAction::TOTAL; i++)
+ for (unsigned int i = 0;
+ i < static_cast<unsigned int>(InputAction::TOTAL);
+ i ++)
{
InputFunction &kf = mKey[i];
for (unsigned int f = 0; f < inputFunctionSize; f ++)
@@ -110,7 +112,7 @@ void InputManager::update()
void InputManager::retrieve()
{
- for (int i = 0; i < InputAction::TOTAL; i++)
+ for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i ++)
{
const std::string &cmd = inputActionData[i].chatCommand;
if (!cmd.empty())
@@ -128,7 +130,7 @@ void InputManager::retrieve()
#endif
if (!cf.empty())
{
- mNameMap[cf] = i;
+ mNameMap[cf] = static_cast<InputActionT>(i);
InputFunction &kf = mKey[i];
const std::string keyStr = config.getValue(cf, "");
const size_t keyStrSize = keyStr.size();
@@ -174,7 +176,7 @@ void InputManager::retrieve()
void InputManager::store() const
{
- for (int i = 0; i < InputAction::TOTAL; i++)
+ for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i ++)
{
#ifdef USE_SDL2
const std::string cf = std::string("sdl2")
@@ -226,16 +228,16 @@ void InputManager::store() const
}
}
-void InputManager::resetKey(const int i)
+void InputManager::resetKey(const InputActionT i)
{
- InputFunction &key = mKey[i];
+ InputFunction &key = mKey[static_cast<size_t>(i)];
for (size_t i2 = 1; i2 < inputFunctionSize; i2 ++)
{
InputItem &ki2 = key.values[i2];
ki2.type = InputType::UNKNOWN;
ki2.value = -1;
}
- const InputActionData &kd = inputActionData[i];
+ const InputActionData &kd = inputActionData[static_cast<size_t>(i)];
InputItem &val0 = key.values[0];
val0.type = kd.defaultType1;
InputItem &val1 = key.values[1];
@@ -257,26 +259,27 @@ void InputManager::resetKey(const int i)
void InputManager::resetKeys()
{
- for (int i = 0; i < InputAction::TOTAL; i++)
- resetKey(i);
+ for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i++)
+ resetKey(static_cast<InputActionT>(i));
}
-void InputManager::makeDefault(const int i)
+void InputManager::makeDefault(const InputActionT i)
{
- if (i >= 0 && i < InputAction::TOTAL)
+ if (i > InputAction::NO_VALUE && i < InputAction::TOTAL)
{
resetKey(i);
update();
}
}
-bool InputManager::hasConflicts(int &restrict key1, int &restrict key2) const
+bool InputManager::hasConflicts(InputActionT &restrict key1,
+ InputActionT &restrict key2) const
{
/**
* No need to parse the square matrix: only check one triangle
* that's enough to detect conflicts
*/
- for (int i = 0; i < InputAction::TOTAL; i++)
+ for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i++)
{
const InputActionData &kdi = inputActionData[i];
if (!*kdi.configField)
@@ -286,11 +289,11 @@ bool InputManager::hasConflicts(int &restrict key1, int &restrict key2) const
for (size_t i2 = 0; i2 < inputFunctionSize; i2 ++)
{
const InputItem &vali2 = ki.values[i2];
- if (vali2.value == InputAction::NO_VALUE)
+ if (vali2.value == -1)
continue;
size_t j;
- for (j = i, j++; j < InputAction::TOTAL; j++)
+ for (j = i, j++; j < static_cast<int>(InputAction::TOTAL); j++)
{
if ((kdi.grp & inputActionData[j].grp) == 0
|| !*kdi.configField)
@@ -307,8 +310,8 @@ bool InputManager::hasConflicts(int &restrict key1, int &restrict key2) const
&& vali2.value == valj2.value
&& vali2.type == valj2.type)
{
- key1 = static_cast<int>(i);
- key2 = static_cast<int>(j);
+ key1 = static_cast<InputActionT>(i);
+ key2 = static_cast<InputActionT>(j);
return true;
}
}
@@ -323,12 +326,12 @@ void InputManager::callbackNewKey()
mSetupInput->newKeyCallback(mNewKeyIndex);
}
-bool InputManager::isActionActive(const int index) const
+bool InputManager::isActionActive(const InputActionT index) const
{
if (!isActionActive0(index))
return false;
- const InputActionData &key = inputActionData[index];
+ const InputActionData &key = inputActionData[static_cast<size_t>(index)];
// logger->log("isActionActive mask=%d, condition=%d, index=%d",
// mMask, key.condition, index);
if ((key.condition & mMask) != key.condition)
@@ -336,7 +339,7 @@ bool InputManager::isActionActive(const int index) const
return true;
}
-bool InputManager::isActionActive0(const int index)
+bool InputManager::isActionActive0(const InputActionT index)
{
if (keyboard.isActionActive(index))
return true;
@@ -345,17 +348,17 @@ bool InputManager::isActionActive0(const int index)
return touchManager.isActionActive(index);
}
-InputFunction &InputManager::getKey(int index)
+InputFunction &InputManager::getKey(InputActionT index)
{
- if (index < 0 || index >= InputAction::TOTAL)
- index = 0;
- return mKey[index];
+ if (static_cast<int>(index) < 0 || index >= InputAction::TOTAL)
+ index = InputAction::MOVE_UP;
+ return mKey[static_cast<size_t>(index)];
}
-std::string InputManager::getKeyStringLong(const int index) const
+std::string InputManager::getKeyStringLong(const InputActionT index) const
{
std::string keyStr;
- const InputFunction &ki = mKey[index];
+ const InputFunction &ki = mKey[static_cast<size_t>(index)];
for (size_t i = 0; i < inputFunctionSize; i ++)
{
@@ -395,10 +398,10 @@ std::string InputManager::getKeyStringLong(const int index) const
return keyStr;
}
-std::string InputManager::getKeyValueString(const int index) const
+std::string InputManager::getKeyValueString(const InputActionT index) const
{
std::string keyStr;
- const InputFunction &ki = mKey[index];
+ const InputFunction &ki = mKey[static_cast<size_t>(index)];
for (size_t i = 0; i < inputFunctionSize; i ++)
{
@@ -441,7 +444,7 @@ std::string InputManager::getKeyValueString(const int index) const
std::string InputManager::getKeyValueByName(const std::string &keyName)
{
- const StringIntMapCIter it = mNameMap.find(keyName);
+ const StringInpActionMapCIter it = mNameMap.find(keyName);
if (it == mNameMap.end())
return std::string();
@@ -450,21 +453,22 @@ std::string InputManager::getKeyValueByName(const std::string &keyName)
std::string InputManager::getKeyValueByNameLong(const std::string &keyName)
{
- const StringIntMapCIter it = mNameMap.find(keyName);
+ const StringInpActionMapCIter it = mNameMap.find(keyName);
if (it == mNameMap.end())
return std::string();
return getKeyStringLong((*it).second);
}
-void InputManager::addActionKey(const int action, const int type,
+void InputManager::addActionKey(const InputActionT action,
+ const int type,
const int val)
{
- if (action < 0 || action >= InputAction::TOTAL)
+ if (static_cast<int>(action) < 0 || action >= InputAction::TOTAL)
return;
int idx = -1;
- InputFunction &key = mKey[action];
+ InputFunction &key = mKey[static_cast<size_t>(action)];
for (size_t i = 0; i < inputFunctionSize; i ++)
{
const InputItem &val2 = key.values[i];
@@ -507,7 +511,7 @@ void InputManager::setNewKey(const SDL_Event &event, const int type)
void InputManager::unassignKey()
{
- InputFunction &key = mKey[mNewKeyIndex];
+ InputFunction &key = mKey[static_cast<size_t>(mNewKeyIndex)];
for (size_t i = 0; i < inputFunctionSize; i ++)
{
InputItem &val = key.values[i];
@@ -747,27 +751,29 @@ bool InputManager::checkKey(const InputActionData *const key) const
}
bool InputManager::invokeKey(const InputActionData *const key,
- const int keyNum)
+ const InputActionT keyNum)
{
// no validation to keyNum because it validated in caller
if (checkKey(key))
{
InputEvent evt(keyNum, mMask);
- ActionFuncPtr func = *(inputActionData[keyNum].action);
+ ActionFuncPtr func = *(inputActionData[
+ static_cast<size_t>(keyNum)].action);
if (func && func(evt))
return true;
}
return false;
}
-void InputManager::executeAction(const int keyNum)
+void InputManager::executeAction(const InputActionT keyNum)
{
- if (keyNum < 0 || keyNum >= InputAction::TOTAL)
+ if (keyNum < InputAction::MOVE_UP || keyNum >= InputAction::TOTAL)
return;
InputEvent evt(keyNum, mMask);
- ActionFuncPtr func = *(inputActionData[keyNum].action);
+ ActionFuncPtr func = *(inputActionData[static_cast<size_t>(
+ keyNum)].action);
if (func)
func(evt);
}
@@ -790,13 +796,14 @@ bool InputManager::executeChatCommand(const std::string &cmd,
return false;
}
-bool InputManager::executeChatCommand(const int keyNum,
+bool InputManager::executeChatCommand(const InputActionT keyNum,
const std::string &args,
ChatTab *const tab)
{
- if (keyNum < 0 || keyNum >= InputAction::TOTAL)
+ if (static_cast<int>(keyNum) < 0 || keyNum >= InputAction::TOTAL)
return false;
- ActionFuncPtr func = *(inputActionData[keyNum].action);
+ ActionFuncPtr func = *(inputActionData[static_cast<size_t>(
+ keyNum)].action);
if (func)
{
InputEvent evt(args, tab, mMask);
@@ -814,7 +821,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &actionMap,
actionMap.clear();
keyTimeMap.clear();
- for (size_t i = 0; i < InputAction::TOTAL; i ++)
+ for (size_t i = 0; i < static_cast<size_t>(InputAction::TOTAL); i ++)
{
const InputFunction &key = mKey[i];
const InputActionData &kd = inputActionData[i];
@@ -824,7 +831,10 @@ void InputManager::updateKeyActionMap(KeyToActionMap &actionMap,
{
const InputItem &ki = key.values[i2];
if (ki.type == type && ki.value != -1)
- actionMap[ki.value].push_back(static_cast<int>(i));
+ {
+ actionMap[ki.value].push_back(
+ static_cast<InputActionT>(i));
+ }
}
}
if (kd.configField && (kd.grp & Input::GRP_GUICHAN))
@@ -833,7 +843,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &actionMap,
{
const InputItem &ki = key.values[i2];
if (ki.type == type && ki.value != -1)
- idMap[ki.value] = static_cast<int>(i);
+ idMap[ki.value] = static_cast<InputActionT>(i);
}
}
if (kd.configField && (kd.grp & Input::GRP_REPEAT))
@@ -865,20 +875,21 @@ bool InputManager::triggerAction(const KeysVector *const ptrs)
FOR_EACHP (KeysVectorCIter, it, ptrs)
{
- const int keyNum = *it;
- if (keyNum < 0 || keyNum >= InputAction::TOTAL)
+ const InputActionT keyNum = *it;
+ if (static_cast<int>(keyNum) < 0 || keyNum >= InputAction::TOTAL)
continue;
- if (invokeKey(&inputActionData[keyNum], keyNum))
+ if (invokeKey(&inputActionData[static_cast<size_t>(keyNum)], keyNum))
return true;
}
return false;
}
-int InputManager::getKeyIndex(const int value, const int grp,
- const int type) const
+InputActionT InputManager::getKeyIndex(const int value,
+ const int grp,
+ const int type) const
{
- for (size_t i = 0; i < InputAction::TOTAL; i++)
+ for (size_t i = 0; i < static_cast<size_t>(InputAction::TOTAL); i++)
{
const InputFunction &key = mKey[i];
const InputActionData &kd = inputActionData[i];
@@ -888,28 +899,31 @@ int InputManager::getKeyIndex(const int value, const int grp,
if (value == vali2.value && (grp & kd.grp) != 0
&& vali2.type == type)
{
- return static_cast<int>(i);
+ return static_cast<InputActionT>(i);
}
}
}
return InputAction::NO_VALUE;
}
-int InputManager::getActionByKey(const SDL_Event &event) const
+InputActionT InputManager::getActionByKey(const SDL_Event &event) const
{
// for now support only keyboard events
if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP)
{
- const int idx = keyboard.getActionId(event);
- if (idx >= 0 && checkKey(&inputActionData[idx]))
+ const InputActionT idx = keyboard.getActionId(event);
+ if (static_cast<int>(idx) >= 0 &&
+ checkKey(&inputActionData[static_cast<size_t>(idx)]))
+ {
return idx;
+ }
}
return InputAction::NO_VALUE;
}
void InputManager::addChatCommands(std::list<std::string> &arr)
{
- for (int i = 0; i < InputAction::TOTAL; i++)
+ for (int i = 0; i < static_cast<int>(InputAction::TOTAL); i++)
{
const InputActionData &ad = inputActionData[i];
std::string cmd = ad.chatCommand;
diff --git a/src/input/inputmanager.h b/src/input/inputmanager.h
index 9526e8cdd..79a197799 100644
--- a/src/input/inputmanager.h
+++ b/src/input/inputmanager.h
@@ -37,6 +37,9 @@ class Setup_Input;
struct InputActionData;
+typedef std::map<std::string, InputActionT> StringInpActionMap;
+typedef StringInpActionMap::const_iterator StringInpActionMapCIter;
+
class InputManager final
{
public:
@@ -56,35 +59,37 @@ class InputManager final
void resetKeys();
- void makeDefault(const int i);
+ void makeDefault(const InputActionT i);
- bool hasConflicts(int &restrict key1,
- int &restrict key2) const A_WARN_UNUSED;
+ bool hasConflicts(InputActionT &restrict key1,
+ InputActionT &restrict key2) const A_WARN_UNUSED;
void callbackNewKey();
- InputFunction &getKey(int index) A_WARN_UNUSED;
+ InputFunction &getKey(InputActionT index) A_WARN_UNUSED;
- std::string getKeyValueString(const int index) const A_WARN_UNUSED;
+ std::string getKeyValueString(const InputActionT index) const A_WARN_UNUSED;
- std::string getKeyStringLong(const int index) const A_WARN_UNUSED;
+ std::string getKeyStringLong(const InputActionT index) const A_WARN_UNUSED;
std::string getKeyValueByName(const std::string &keyName);
std::string getKeyValueByNameLong(const std::string &keyName);
- void addActionKey(const int action, const int type, const int val);
+ void addActionKey(const InputActionT action,
+ const int type,
+ const int val);
void setNewKey(const SDL_Event &event, const int type);
void unassignKey();
- bool isActionActive(const int index) const A_WARN_UNUSED;
+ bool isActionActive(const InputActionT index) const A_WARN_UNUSED;
/**
* Set the index of the new key to be assigned.
*/
- void setNewKeyIndex(const int value)
+ void setNewKeyIndex(const InputActionT value)
{ mNewKeyIndex = value; }
/**
@@ -96,14 +101,15 @@ class InputManager final
/**
* Get the index of the new key to be assigned.
*/
- int getNewKeyIndex() const A_WARN_UNUSED
+ InputActionT getNewKeyIndex() const A_WARN_UNUSED
{ return mNewKeyIndex; }
void updateKeyActionMap(KeyToActionMap &actionMap,
KeyToIdMap &idMap, KeyTimeMap &keyTimeMap,
const int type) const;
- bool invokeKey(const InputActionData *const key, const int keyNum);
+ bool invokeKey(const InputActionData *const key,
+ const InputActionT keyNum);
bool handleAssignKey(const SDL_Event &event, const int type);
@@ -111,42 +117,44 @@ class InputManager final
bool triggerAction(const KeysVector *const ptrs);
- int getKeyIndex(const int value, const int grp,
- const int type) const A_WARN_UNUSED;
+ InputActionT getKeyIndex(const int value,
+ const int grp,
+ const int type) const A_WARN_UNUSED;
static void update();
void updateConditionMask();
- int getActionByKey(const SDL_Event &event) const A_WARN_UNUSED;
+ InputActionT getActionByKey(const SDL_Event &event)
+ const A_WARN_UNUSED;
- void executeAction(const int keyNum);
+ void executeAction(const InputActionT keyNum);
bool executeChatCommand(const std::string &cmd,
const std::string &args,
ChatTab *const tab);
- bool executeChatCommand(const int keyNum,
+ bool executeChatCommand(const InputActionT keyNum,
const std::string &args,
ChatTab *const tab);
void addChatCommands(std::list<std::string> &arr);
protected:
- void resetKey(const int i);
+ void resetKey(const InputActionT i);
- static bool isActionActive0(const int index) A_WARN_UNUSED;
+ static bool isActionActive0(const InputActionT index) A_WARN_UNUSED;
- Setup_Input *mSetupInput; /**< Reference to setup window */
+ Setup_Input *mSetupInput; /**< Reference to setup window */
- int mNewKeyIndex; /**< Index of new key to be assigned */
+ InputActionT mNewKeyIndex; /**< Index of new key to be assigned */
int mMask;
- StringIntMap mNameMap;
+ StringInpActionMap mNameMap;
StringIntMap mChatMap;
- InputFunction mKey[InputAction::TOTAL];
+ InputFunction mKey[static_cast<size_t>(InputAction::TOTAL)];
};
extern InputManager inputManager;
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp
index e54347907..9e674a263 100644
--- a/src/input/joystick.cpp
+++ b/src/input/joystick.cpp
@@ -320,7 +320,7 @@ int Joystick::getButtonFromEvent(const SDL_Event &event) const
return event.jbutton.button;
}
-bool Joystick::isActionActive(const int index) const
+bool Joystick::isActionActive(const InputActionT index) const
{
if (!validate())
return false;
diff --git a/src/input/joystick.h b/src/input/joystick.h
index 01937c829..d5f31798a 100644
--- a/src/input/joystick.h
+++ b/src/input/joystick.h
@@ -124,7 +124,7 @@ class Joystick final
int getButtonFromEvent(const SDL_Event &event) const A_WARN_UNUSED;
- bool isActionActive(const int index) const A_WARN_UNUSED;
+ bool isActionActive(const InputActionT index) const A_WARN_UNUSED;
bool validate() const A_WARN_UNUSED;
diff --git a/src/input/keyboardconfig.cpp b/src/input/keyboardconfig.cpp
index 9229d4184..80ad2fcd9 100644
--- a/src/input/keyboardconfig.cpp
+++ b/src/input/keyboardconfig.cpp
@@ -73,7 +73,7 @@ int KeyboardConfig::getKeyValueFromEvent(const SDL_Event &event)
#endif
}
-int KeyboardConfig::getKeyIndex(const SDL_Event &event, const int grp)
+InputActionT KeyboardConfig::getKeyIndex(const SDL_Event &event, const int grp)
{
const int keyValue = getKeyValueFromEvent(event);
return inputManager.getKeyIndex(keyValue, grp, InputType::KEYBOARD);
@@ -86,9 +86,9 @@ void KeyboardConfig::refreshActiveKeys()
std::string KeyboardConfig::getKeyName(const int key)
{
- if (key == InputAction::NO_VALUE)
+ if (key == -1)
return "";
- if (key >= 0)
+ if (key > -1)
{
#ifdef USE_SDL2
return SDL_GetKeyName(SDL_GetKeyFromScancode(
@@ -99,7 +99,7 @@ std::string KeyboardConfig::getKeyName(const int key)
}
// TRANSLATORS: long key name, should be short
- return strprintf(_("key_%d"), key);
+ return strprintf(_("key_%d"), static_cast<int>(key));
}
std::string KeyboardConfig::getKeyShortString(const std::string &key)
@@ -174,16 +174,16 @@ KeysVector *KeyboardConfig::getActionVectorByKey(const int i)
return nullptr;
}
-int KeyboardConfig::getActionId(const SDL_Event &event)
+InputActionT KeyboardConfig::getActionId(const SDL_Event &event)
{
const int i = getKeyValueFromEvent(event);
// logger->log("getActionId: %d", i);
if (i != 0 && i < SDLK_LAST && mKeyToId.find(i) != mKeyToId.end())
return mKeyToId[i];
- return -1;
+ return InputAction::NO_VALUE;
}
-bool KeyboardConfig::isActionActive(const int index) const
+bool KeyboardConfig::isActionActive(const InputActionT index) const
{
if (!mActiveKeys)
return false;
diff --git a/src/input/keyboardconfig.h b/src/input/keyboardconfig.h
index 7b1d09e33..5b36fd65c 100644
--- a/src/input/keyboardconfig.h
+++ b/src/input/keyboardconfig.h
@@ -54,8 +54,8 @@ class KeyboardConfig final
/**
* Get the key function index by providing the keys value.
*/
- static int getKeyIndex(const SDL_Event &event,
- const int grp = 1) A_WARN_UNUSED;
+ static InputActionT getKeyIndex(const SDL_Event &event,
+ const int grp = 1) A_WARN_UNUSED;
/**
* Set the enable flag, which will stop the user from doing actions.
@@ -79,9 +79,9 @@ class KeyboardConfig final
KeysVector *getActionVectorByKey(const int i) A_WARN_UNUSED;
- static std::string getKeyName(const int key)A_WARN_UNUSED;
+ static std::string getKeyName(const int key) A_WARN_UNUSED;
- bool isActionActive(const int index) const A_WARN_UNUSED;
+ bool isActionActive(const InputActionT index) const A_WARN_UNUSED;
void update();
@@ -93,7 +93,7 @@ class KeyboardConfig final
void handleDeActicateKey(const int key);
- int getActionId(const SDL_Event &event) A_WARN_UNUSED;
+ InputActionT getActionId(const SDL_Event &event) A_WARN_UNUSED;
void handleRepeat(const int time);
diff --git a/src/input/keyinput.h b/src/input/keyinput.h
index 8555d8bbb..229b4d212 100644
--- a/src/input/keyinput.h
+++ b/src/input/keyinput.h
@@ -66,6 +66,8 @@
#include "enums/events/keyeventtype.h"
+#include "enums/input/inputaction.h"
+
#include "input/key.h"
#include "localconsts.h"
@@ -79,7 +81,7 @@ class KeyInput final
#ifdef USE_SDL2
mText(),
#endif
- mActionId(-2)
+ mActionId(InputAction::UNDEFINED_VALUE)
{ }
~KeyInput()
@@ -105,12 +107,12 @@ class KeyInput final
return mKey;
}
- void setActionId(const int n)
+ void setActionId(const InputActionT n)
{
mActionId = n;
}
- int getActionId() const A_WARN_UNUSED
+ InputActionT getActionId() const A_WARN_UNUSED
{
return mActionId;
}
@@ -142,7 +144,7 @@ class KeyInput final
std::string mText;
#endif
- int mActionId;
+ InputActionT mActionId;
};
#endif // INPUT_KEYINPUT_H