summaryrefslogtreecommitdiff
path: root/src/input
diff options
context:
space:
mode:
authorAndrei Karas <akaras@inbox.ru>2017-06-06 23:34:34 +0300
committerAndrei Karas <akaras@inbox.ru>2017-06-07 19:23:40 +0300
commit36ba43d6ea38062b17f7e63ef659962bfc51c64d (patch)
tree190156cb88b13a38a6d13c69ee0742cc078065a1 /src/input
parentf1518dd8476c968a43fa57cfb06198e290a4f77a (diff)
downloadmanaverse-36ba43d6ea38062b17f7e63ef659962bfc51c64d.tar.gz
manaverse-36ba43d6ea38062b17f7e63ef659962bfc51c64d.tar.bz2
manaverse-36ba43d6ea38062b17f7e63ef659962bfc51c64d.tar.xz
manaverse-36ba43d6ea38062b17f7e63ef659962bfc51c64d.zip
Fix clang-tidy check readability-implicit-bool-cast.
Diffstat (limited to 'src/input')
-rw-r--r--src/input/inputmanager.cpp70
-rw-r--r--src/input/joystick.cpp16
-rw-r--r--src/input/joystick.h8
-rw-r--r--src/input/keyboardconfig.cpp18
-rw-r--r--src/input/keyboardconfig.h2
-rw-r--r--src/input/touch/touchactions.cpp4
-rw-r--r--src/input/touch/touchmanager.cpp45
7 files changed, 83 insertions, 80 deletions
diff --git a/src/input/inputmanager.cpp b/src/input/inputmanager.cpp
index 40397e91f..13298f2e3 100644
--- a/src/input/inputmanager.cpp
+++ b/src/input/inputmanager.cpp
@@ -110,7 +110,7 @@ void InputManager::init() restrict2
void InputManager::update()
{
keyboard.update();
- if (joystick)
+ if (joystick != nullptr)
joystick->update();
}
@@ -306,7 +306,7 @@ bool InputManager::hasConflicts(InputActionT &restrict key1,
for (int i = 0; i < CAST_S32(InputAction::TOTAL); i++)
{
const InputActionData &restrict kdi = inputActionData[i];
- if (!*kdi.configField)
+ if (*kdi.configField == 0)
continue;
const InputFunction &restrict ki = mKey[i];
@@ -320,7 +320,7 @@ bool InputManager::hasConflicts(InputActionT &restrict key1,
for (j = i, j++; j < CAST_S32(InputAction::TOTAL); j++)
{
if ((kdi.grp & inputActionData[j].grp) == 0
- || !*kdi.configField)
+ || (*kdi.configField == 0))
{
continue;
}
@@ -370,7 +370,7 @@ bool InputManager::isActionActive0(const InputActionT index)
{
if (keyboard.isActionActive(index))
return true;
- if (joystick && joystick->isActionActive(index))
+ if ((joystick != nullptr) && joystick->isActionActive(index))
return true;
return touchManager.isActionActive(index);
}
@@ -539,7 +539,7 @@ void InputManager::setNewKey(const SDL_Event &event,
int val = -1;
if (type == InputType::KEYBOARD)
val = KeyboardConfig::getKeyValueFromEvent(event);
- else if (type == InputType::JOYSTICK && joystick)
+ else if (type == InputType::JOYSTICK && (joystick != nullptr))
val = joystick->getButtonFromEvent(event);
if (val != -1)
@@ -566,7 +566,7 @@ void InputManager::unassignKey() restrict2
bool InputManager::handleAssignKey(const SDL_Event &restrict event,
const InputTypeT type) restrict2
{
- if (setupWindow && setupWindow->isWindowVisible() &&
+ if ((setupWindow != nullptr) && setupWindow->isWindowVisible() &&
getNewKeyIndex() > InputAction::NO_VALUE)
{
setNewKey(event, type);
@@ -603,11 +603,11 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
keyboard.handleActivateKey(event);
// send straight to gui for certain windows
#ifndef DYECMD
- if (quitDialog || TextDialog::isActive())
+ if ((quitDialog != nullptr) || TextDialog::isActive())
{
- if (guiInput)
+ if (guiInput != nullptr)
guiInput->pushInput(event);
- if (gui)
+ if (gui != nullptr)
gui->handleInput();
BLOCK_END("InputManager::handleEvent")
return true;
@@ -660,9 +660,9 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
break;
}
- if (guiInput)
+ if (guiInput != nullptr)
guiInput->pushInput(event);
- if (gui)
+ if (gui != nullptr)
{
const bool res = gui->handleInput();
if (res && event.type == SDL_KEYDOWN)
@@ -683,7 +683,7 @@ bool InputManager::handleEvent(const SDL_Event &restrict event) restrict2
break;
case SDL_JOYBUTTONDOWN:
- if (joystick && joystick->validate())
+ if ((joystick != nullptr) && joystick->validate())
{
if (triggerAction(joystick->getActionVector(event)))
{
@@ -713,7 +713,7 @@ void InputManager::handleRepeat()
{
const int time = tick_time;
keyboard.handleRepeat(time);
- if (joystick)
+ if (joystick != nullptr)
joystick->handleRepeat(time);
}
@@ -723,17 +723,17 @@ void InputManager::updateConditionMask() restrict2
if (keyboard.isEnabled())
mMask |= InputCondition::ENABLED;
#ifndef DYECMD
- if ((!chatWindow || !chatWindow->isInputFocused()) &&
+ if (((chatWindow == nullptr) || !chatWindow->isInputFocused()) &&
!NpcDialog::isAnyInputFocused() &&
!InventoryWindow::isAnyInputFocused() &&
- (!tradeWindow || !tradeWindow->isInpupFocused()))
+ ((tradeWindow == nullptr) || !tradeWindow->isInpupFocused()))
{
- if (gui)
+ if (gui != nullptr)
{
FocusHandler *restrict const focus = gui->getFocusHandler();
- if (focus)
+ if (focus != nullptr)
{
- if (!dynamic_cast<TextField*>(focus->getFocused()))
+ if (dynamic_cast<TextField*>(focus->getFocused()) == nullptr)
mMask |= InputCondition::NOINPUT;
}
else
@@ -756,24 +756,24 @@ void InputManager::updateConditionMask() restrict2
mMask |= InputCondition::NOROOM;
const NpcDialog *restrict const dialog = NpcDialog::getActive();
- if (!dialog || !dialog->isTextInputFocused())
+ if ((dialog == nullptr) || !dialog->isTextInputFocused())
mMask |= InputCondition::NONPCINPUT;
- if (!dialog || dialog->isCloseState())
+ if ((dialog == nullptr) || (dialog->isCloseState() != 0))
{
mMask |= InputCondition::NONPCDIALOG;
if (!InventoryWindow::isStorageActive())
mMask |= InputCondition::NOTALKING;
}
- if (!setupWindow || !setupWindow->isWindowVisible())
+ if ((setupWindow == nullptr) || !setupWindow->isWindowVisible())
mMask |= InputCondition::NOSETUP;
- if (Game::instance() && Game::instance()->getValidSpeed())
+ if ((Game::instance() != nullptr) && Game::instance()->getValidSpeed())
mMask |= InputCondition::VALIDSPEED;
- if (Game::instance())
+ if (Game::instance() != nullptr)
mMask |= InputCondition::INGAME;
- if (localPlayer)
+ if (localPlayer != nullptr)
{
if (localPlayer->getFollow().empty())
mMask |= InputCondition::NOFOLLOW;
@@ -794,7 +794,7 @@ void InputManager::updateConditionMask() restrict2
if (!settings.awayMode)
mMask |= InputCondition::NOAWAY;
- if (gui && !gui->getFocusHandler()->getModalFocused())
+ if (gui != nullptr && gui->getFocusHandler()->getModalFocused() == nullptr)
mMask |= InputCondition::NOMODAL;
if (!settings.disableGameModifiers)
@@ -811,7 +811,7 @@ bool InputManager::checkKey(const InputActionData *restrict const key) const
restrict2
{
// logger->log("checkKey mask=%d, condition=%d", mMask, key->condition);
- if (!key || (key->condition & mMask) != key->condition)
+ if ((key == nullptr) || (key->condition & mMask) != key->condition)
return false;
return (key->modKeyIndex == InputAction::NO_VALUE
@@ -828,7 +828,7 @@ bool InputManager::invokeKey(const InputActionData *restrict const key,
InputEvent evt(keyNum, mMask);
ActionFuncPtr func = *(inputActionData[
CAST_SIZE(keyNum)].action);
- if (func && func(evt))
+ if ((func != nullptr) && func(evt))
return true;
}
return false;
@@ -842,7 +842,7 @@ void InputManager::executeAction(const InputActionT keyNum) restrict2
InputEvent evt(keyNum, mMask);
ActionFuncPtr func = *(inputActionData[CAST_SIZE(
keyNum)].action);
- if (func)
+ if (func != nullptr)
func(evt);
}
@@ -854,7 +854,7 @@ bool InputManager::executeChatCommand(const std::string &restrict cmd,
if (it != mChatMap.end())
{
ActionFuncPtr func = *(inputActionData[(*it).second].action);
- if (func)
+ if (func != nullptr)
{
InputEvent evt(args, tab, mMask);
func(evt);
@@ -882,7 +882,7 @@ bool InputManager::executeRemoteChatCommand(const std::string &restrict cmd,
if (data.isProtected == Protected_true)
return false;
ActionFuncPtr func = *(data.action);
- if (func)
+ if (func != nullptr)
{
InputEvent evt(args, tab, mMask);
func(evt);
@@ -900,7 +900,7 @@ bool InputManager::executeChatCommand(const InputActionT keyNum,
return false;
ActionFuncPtr func = *(inputActionData[CAST_SIZE(
keyNum)].action);
- if (func)
+ if (func != nullptr)
{
InputEvent evt(args, tab, mMask);
func(evt);
@@ -921,7 +921,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &restrict actionMap,
{
const InputFunction &restrict key = mKey[i];
const InputActionData &restrict kd = inputActionData[i];
- if (kd.action)
+ if (kd.action != nullptr)
{
for (size_t i2 = 0; i2 < inputFunctionSize; i2 ++)
{
@@ -933,7 +933,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &restrict actionMap,
}
}
}
- if (kd.configField && (kd.grp & Input::GRP_GUICHAN))
+ if (kd.configField != nullptr && (kd.grp & Input::GRP_GUICHAN) != 0)
{
for (size_t i2 = 0; i2 < inputFunctionSize; i2 ++)
{
@@ -942,7 +942,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &restrict actionMap,
idMap[ki.value] = static_cast<InputActionT>(i);
}
}
- if (kd.configField && (kd.grp & Input::GRP_REPEAT))
+ if (kd.configField != nullptr && (kd.grp & Input::GRP_REPEAT) != 0)
{
for (size_t i2 = 0; i2 < inputFunctionSize; i2 ++)
{
@@ -965,7 +965,7 @@ void InputManager::updateKeyActionMap(KeyToActionMap &restrict actionMap,
bool InputManager::triggerAction(const KeysVector *restrict const ptrs)
restrict2
{
- if (!ptrs)
+ if (ptrs == nullptr)
return false;
// logger->log("ptrs: %d", (int)ptrs.size());
diff --git a/src/input/joystick.cpp b/src/input/joystick.cpp
index 480d2b493..3ec317c8d 100644
--- a/src/input/joystick.cpp
+++ b/src/input/joystick.cpp
@@ -97,7 +97,7 @@ bool Joystick::open()
mJoystick = SDL_JoystickOpen(mNumber);
- if (!mJoystick)
+ if (mJoystick == nullptr)
{
logger->log("Couldn't open joystick: %s", SDL_GetError());
return false;
@@ -129,7 +129,7 @@ bool Joystick::open()
void Joystick::close()
{
logger->log("close joystick %d", mNumber);
- if (mJoystick)
+ if (mJoystick != nullptr)
{
SDL_JoystickClose(mJoystick);
mJoystick = nullptr;
@@ -144,7 +144,7 @@ void Joystick::reload()
void Joystick::setNumber(const int n)
{
- if (mJoystick)
+ if (mJoystick != nullptr)
{
SDL_JoystickClose(mJoystick);
mNumber = n;
@@ -200,17 +200,17 @@ void Joystick::logic()
logger->log("axis 4 pos: %d", SDL_JoystickGetAxis(mJoystick, 4));
#endif // DEBUG_JOYSTICK
- if (!mDirection && mHaveHats)
+ if ((mDirection == 0u) && mHaveHats)
{
// reading only hat 0
const uint8_t hat = SDL_JoystickGetHat(mJoystick, 0);
- if (hat & SDL_HAT_RIGHT)
+ if ((hat & SDL_HAT_RIGHT) != 0)
mDirection |= RIGHT;
- else if (hat & SDL_HAT_LEFT)
+ else if ((hat & SDL_HAT_LEFT) != 0)
mDirection |= LEFT;
- if (hat & SDL_HAT_UP)
+ if ((hat & SDL_HAT_UP) != 0)
mDirection |= UP;
- else if (hat & SDL_HAT_DOWN)
+ else if ((hat & SDL_HAT_DOWN) != 0)
mDirection |= DOWN;
}
diff --git a/src/input/joystick.h b/src/input/joystick.h
index 0238285aa..4088cc84c 100644
--- a/src/input/joystick.h
+++ b/src/input/joystick.h
@@ -99,16 +99,16 @@ class Joystick final
bool buttonPressed(const unsigned char no) const A_WARN_UNUSED;
bool isUp() const noexcept2 A_WARN_UNUSED
- { return mEnabled && (mDirection & UP); }
+ { return mEnabled && ((mDirection & UP) != 0); }
bool isDown() const noexcept2 A_WARN_UNUSED
- { return mEnabled && (mDirection & DOWN); }
+ { return mEnabled && ((mDirection & DOWN) != 0); }
bool isLeft() const noexcept2 A_WARN_UNUSED
- { return mEnabled && (mDirection & LEFT); }
+ { return mEnabled && ((mDirection & LEFT) != 0); }
bool isRight() const noexcept2 A_WARN_UNUSED
- { return mEnabled && (mDirection & RIGHT); }
+ { return mEnabled && ((mDirection & RIGHT) != 0); }
int getNumber() const noexcept2 A_WARN_UNUSED
{ return mNumber; }
diff --git a/src/input/keyboardconfig.cpp b/src/input/keyboardconfig.cpp
index 9ed3d2a58..794d4d377 100644
--- a/src/input/keyboardconfig.cpp
+++ b/src/input/keyboardconfig.cpp
@@ -163,7 +163,7 @@ InputActionT KeyboardConfig::getActionId(const SDL_Event &event)
bool KeyboardConfig::isActionActive(const InputActionT index) const
{
- if (!mActiveKeys || !mActiveKeys2)
+ if ((mActiveKeys == nullptr) || (mActiveKeys2 == nullptr))
return false;
const InputFunction &key = inputManager.getKey(index);
@@ -176,12 +176,12 @@ bool KeyboardConfig::isActionActive(const InputActionT index) const
const int value = val.value;
if (value >= 0)
{
- if (mActiveKeys[value])
+ if (mActiveKeys[value] != 0u)
return true;
}
else if (value < -1 && value > -500)
{
- if (mActiveKeys2[-value])
+ if (mActiveKeys2[-value] != 0u)
return true;
}
}
@@ -196,7 +196,7 @@ void KeyboardConfig::update()
void KeyboardConfig::handleActivateKey(const SDL_Event &event)
{
- if (!mActiveKeys2)
+ if (mActiveKeys2 == nullptr)
return;
const int key = getKeyValueFromEvent(event);
if (key < -1 && key > -500)
@@ -206,7 +206,7 @@ void KeyboardConfig::handleActivateKey(const SDL_Event &event)
void KeyboardConfig::handleActivateKey(const int key)
{
- if (!mActiveKeys2)
+ if (mActiveKeys2 == nullptr)
return;
if (key < -1 && key > -500)
mActiveKeys2[-key] = 1;
@@ -215,7 +215,7 @@ void KeyboardConfig::handleActivateKey(const int key)
void KeyboardConfig::handleDeActicateKey(const SDL_Event &event)
{
- if (!mActiveKeys2)
+ if (mActiveKeys2 == nullptr)
return;
const int key = getKeyValueFromEvent(event);
if (key < -1 && key > -500)
@@ -225,7 +225,7 @@ void KeyboardConfig::handleDeActicateKey(const SDL_Event &event)
void KeyboardConfig::handleDeActicateKey(const int key)
{
- if (!mActiveKeys2)
+ if (mActiveKeys2 == nullptr)
return;
if (key < -1 && key > -500)
mActiveKeys2[-key] = 0;
@@ -241,12 +241,12 @@ void KeyboardConfig::handleRepeat(const int time)
const int key = (*it).first;
if (key >= 0)
{
- if (mActiveKeys && mActiveKeys[key])
+ if ((mActiveKeys != nullptr) && (mActiveKeys[key] != 0u))
repeat = true;
}
else if (key < -1 && key > -500)
{
- if (mActiveKeys2 && mActiveKeys2[-key])
+ if ((mActiveKeys2 != nullptr) && (mActiveKeys2[-key] != 0u))
repeat = true;
}
if (repeat)
diff --git a/src/input/keyboardconfig.h b/src/input/keyboardconfig.h
index 259fb650e..789f8b4ef 100644
--- a/src/input/keyboardconfig.h
+++ b/src/input/keyboardconfig.h
@@ -89,7 +89,7 @@ class KeyboardConfig final
return event.key.keysym.scancode;
#else // USE_SDL2
- if (event.key.keysym.sym)
+ if (event.key.keysym.sym != 0u)
return CAST_S32(event.key.keysym.sym);
else if (event.key.keysym.scancode > 1)
return -event.key.keysym.scancode;
diff --git a/src/input/touch/touchactions.cpp b/src/input/touch/touchactions.cpp
index 40fa8bf3d..ae79dd182 100644
--- a/src/input/touch/touchactions.cpp
+++ b/src/input/touch/touchactions.cpp
@@ -58,12 +58,12 @@ static void moveChar(int x, int y)
const int y2 = abs(y);
if (x2 > y2)
{
- if (y2 && x2 * 10 / y2 > diff)
+ if ((y2 != 0) && x2 * 10 / y2 > diff)
y = 0;
}
else
{
- if (x2 && y2 * 10 / x2 > diff)
+ if ((x2 != 0) && y2 * 10 / x2 > diff)
x = 0;
}
diff --git a/src/input/touch/touchmanager.cpp b/src/input/touch/touchmanager.cpp
index add16a929..e9c378ef7 100644
--- a/src/input/touch/touchmanager.cpp
+++ b/src/input/touch/touchmanager.cpp
@@ -130,7 +130,7 @@ void TouchManager::loadTouchItem(TouchItem **restrict item,
const TouchFuncPtr fOut) restrict2
{
*item = nullptr;
- if (!theme)
+ if (theme == nullptr)
return;
ImageRect *images = new ImageRect;
for (int f = 0; f < 9; f ++)
@@ -143,10 +143,10 @@ void TouchManager::loadTouchItem(TouchItem **restrict item,
icon = Theme::getImageFromThemeXml(imageName, "");
Skin *const skin = theme->loadSkinRect(*images, name, "");
- if (skin)
+ if (skin != nullptr)
{
Image *const image = images->grid[0];
- if (image)
+ if (image != nullptr)
{
if (x == -1)
x = skin->getOption("x", 10);
@@ -208,13 +208,13 @@ void TouchManager::draw() restrict2
FOR_EACH (TouchItemVectorCIter, it, mObjects)
{
const TouchItem *const item = *it;
- if (item && item->images && (mShow ||
+ if ((item != nullptr) && (item->images != nullptr) && (mShow ||
(item == mKeyboard && mShowKeyboard)))
{
mainGraphics->calcWindow(mVertexes, item->x, item->y,
item->width, item->height, *item->images);
const Image *const icon = item->icon;
- if (icon)
+ if (icon != nullptr)
{
mainGraphics->calcTileCollection(mVertexes, icon,
item->x + (item->width - icon->mBounds.w) / 2,
@@ -233,13 +233,13 @@ void TouchManager::safeDraw() restrict2
FOR_EACH (TouchItemVectorCIter, it, mObjects)
{
const TouchItem *const item = *it;
- if (item && item->images && (mShow ||
+ if ((item != nullptr) && (item->images != nullptr) && (mShow ||
(item == mKeyboard && mShowKeyboard)))
{
mainGraphics->drawImageRect(item->x, item->y,
item->width, item->height, *item->images);
const Image *const icon = item->icon;
- if (icon)
+ if (icon != nullptr)
{
mainGraphics->drawImage(icon,
item->x + (item->width - icon->mBounds.w) / 2,
@@ -252,7 +252,7 @@ void TouchManager::safeDraw() restrict2
void TouchManager::drawText() restrict2
{
- if (!gui)
+ if (gui == nullptr)
return;
Font *const font = boldFont;
@@ -262,7 +262,7 @@ void TouchManager::drawText() restrict2
FOR_EACH (TouchItemVectorCIter, it, mObjects)
{
const TouchItem *const item = *it;
- if (item && mShow && !item->text.empty())
+ if ((item != nullptr) && mShow && !item->text.empty())
{
const std::string str = item->text;
const int textX = (item->rect.width - font->getWidth(str))
@@ -285,15 +285,18 @@ bool TouchManager::processEvent(const MouseInput &mouseInput) restrict2
FOR_EACH (TouchItemVectorCIter, it, mObjects)
{
const TouchItem *const item = *it;
- if (!item || (!mShow && (item != mKeyboard || !mShowKeyboard)))
+ if (item == nullptr ||
+ (!mShow && (item != mKeyboard || !mShowKeyboard)))
+ {
continue;
+ }
const Rect &rect = item->rect;
if (rect.isPointInRect(x, y))
{
MouseInput event = mouseInput;
event.setX(event.getTouchX() - item->x);
event.setY(event.getTouchY() - item->y);
- if (item->funcAll)
+ if (item->funcAll != nullptr)
item->funcAll(event);
switch (mouseInput.getType())
@@ -301,13 +304,13 @@ bool TouchManager::processEvent(const MouseInput &mouseInput) restrict2
case MouseEventType::PRESSED:
if (!item->eventPressed.empty())
executeAction(item->eventPressed);
- else if (item->funcPressed)
+ else if (item->funcPressed != nullptr)
item->funcPressed(event);
break;
case MouseEventType::RELEASED:
if (!item->eventReleased.empty())
executeAction(item->eventReleased);
- else if (item->funcReleased)
+ else if (item->funcReleased != nullptr)
item->funcReleased(event);
break;
default:
@@ -323,7 +326,7 @@ bool TouchManager::processEvent(const MouseInput &mouseInput) restrict2
}
return true;
}
- else if (item->funcOut)
+ else if (item->funcOut != nullptr)
{
item->funcOut(mouseInput);
}
@@ -350,7 +353,7 @@ void TouchManager::resize(const int width, const int height) restrict2
FOR_EACH (TouchItemVectorCIter, it, mObjects)
{
TouchItem *const item = *it;
- if (!item)
+ if (item == nullptr)
continue;
switch (item->type)
@@ -381,13 +384,13 @@ void TouchManager::resize(const int width, const int height) restrict2
void TouchManager::unload(TouchItem *restrict const item)
{
- if (item)
+ if (item != nullptr)
{
- if (item->images)
+ if (item->images != nullptr)
{
Theme::unloadRect(*item->images);
delete2(item->images);
- if (item->icon)
+ if (item->icon != nullptr)
{
item->icon->decRef();
item->icon = nullptr;
@@ -402,7 +405,7 @@ void TouchManager::unloadTouchItem(TouchItem *restrict *unloadItem) restrict2
FOR_EACH (TouchItemVectorIter, it, mObjects)
{
TouchItem *item = *it;
- if (item && *unloadItem == item)
+ if ((item != nullptr) && *unloadItem == item)
{
mObjects.erase(it);
unload(item);
@@ -421,11 +424,11 @@ void TouchManager::loadPad() restrict2
void TouchManager::loadButtons() restrict2
{
const int sz = (mButtonsSize + 1) * 50;
- if (!theme)
+ if (theme == nullptr)
return;
Skin *const skin = theme->load("dbutton.xml", "");
- if (skin)
+ if (skin != nullptr)
{
const int x = skin->getOption("x", 10);
const int y = skin->getOption("y", 10);