diff --git a/include/Util/Input.hpp b/include/Util/Input.hpp index cf4db53f..e000b924 100644 --- a/include/Util/Input.hpp +++ b/include/Util/Input.hpp @@ -15,7 +15,7 @@ namespace Util { * @brief The Input class provides access to keyboard and mouse input. * @note This class is a singleton and constructable. Use is as follows: \n `Util::Input::IsKeyPressed(Keycode::A)`, - `Util::Input::IsLButtonPressed()`, etc. + `Util::Input::IsLButtonDown()`, etc. */ class Input { public: @@ -67,27 +67,27 @@ class Input { static bool IsKeyPressed(const Keycode &key); /** - * \brief Checks if the left mouse button is currently pressed. + * \brief Checks if the left mouse button is currently down. * - * \return true if the left mouse button is currently pressed, false + * \return true if the left mouse button is currently down, false * otherwise.r * */ - static bool IsLButtonPressed(); + static bool IsLButtonDown(); /** - * @brief Checks if the right mouse button is currently pressed. - * @return true if the right mouse button is currently pressed, false + * @brief Checks if the right mouse button is currently down. + * @return true if the right mouse button is currently down, false * otherwise. */ - static bool IsRButtonPressed(); + static bool IsRButtonDown(); /** - * @brief Checks if the middle mouse button is currently pressed. - * @return true if the middle mouse button is currently pressed, false + * @brief Checks if the middle mouse button is currently down. + * @return true if the middle mouse button is currently down, false * otherwise. */ - static bool IsMButtonPressed(); + static bool IsMButtonDown(); /** * @brief Checks if the mouse wheel is currently being scrolled. diff --git a/src/App.cpp b/src/App.cpp index bc9af65a..2d3a7bf2 100644 --- a/src/App.cpp +++ b/src/App.cpp @@ -21,14 +21,14 @@ void App::Start() { } void App::Update() { - if (Util::Input::IsLButtonPressed()) { - LOG_DEBUG("Left button pressed"); + if (Util::Input::IsLButtonDown()) { + LOG_DEBUG("Left button down"); } - if (Util::Input::IsRButtonPressed()) { - LOG_DEBUG("Right button pressed"); + if (Util::Input::IsRButtonDown()) { + LOG_DEBUG("Right button down"); } - if (Util::Input::IsMButtonPressed()) { - LOG_DEBUG("Middle button pressed"); + if (Util::Input::IsMButtonDown()) { + LOG_DEBUG("Middle button down"); } if (Util::Input::IfScroll()) { auto delta = Util::Input::GetScrollDistance(); diff --git a/src/Util/Input.cpp b/src/Util/Input.cpp index cadd3e19..d99ba6ed 100644 --- a/src/Util/Input.cpp +++ b/src/Util/Input.cpp @@ -1,7 +1,7 @@ #include "Util/Input.hpp" -#include // for SDL_Event #include "config.hpp" +#include // for SDL_Event namespace Util { @@ -22,13 +22,13 @@ bool Input::IsKeyPressed(const Keycode &key) { return s_KeyState[temp] != 0; } -bool Input::IsLButtonPressed() { +bool Input::IsLButtonDown() { return s_LBPressed; } -bool Input::IsRButtonPressed() { +bool Input::IsRButtonDown() { return s_RBPressed; } -bool Input::IsMButtonPressed() { +bool Input::IsMButtonDown() { return s_MBPressed; } bool Input::IsMouseMoving() { @@ -57,19 +57,38 @@ void Input::Update() { s_CursorPosition.y = -(s_CursorPosition.y - static_cast(WINDOW_HEIGHT) / 2); - s_LBPressed = s_RBPressed = s_MBPressed = s_Scroll = s_MouseMoving = false; + s_Scroll = s_MouseMoving = false; while (SDL_PollEvent(&s_Event) != 0) { - s_LBPressed = (s_Event.type == SDL_MOUSEBUTTONDOWN && - s_Event.button.button == SDL_BUTTON_LEFT) || - s_LBPressed; - s_RBPressed = (s_Event.type == SDL_MOUSEBUTTONDOWN && - s_Event.button.button == SDL_BUTTON_RIGHT) || - s_RBPressed; - s_MBPressed = (s_Event.type == SDL_MOUSEBUTTONDOWN && - s_Event.button.button == SDL_BUTTON_MIDDLE) || - s_MBPressed; + if (s_Event.type == SDL_MOUSEBUTTONUP && + s_Event.button.button == SDL_BUTTON_LEFT) { + s_LBPressed = false; + } + if (s_Event.type == SDL_MOUSEBUTTONDOWN && + s_Event.button.button == SDL_BUTTON_LEFT) { + s_LBPressed = true; + } + + if (s_Event.type == SDL_MOUSEBUTTONUP && + s_Event.button.button == SDL_BUTTON_RIGHT) { + s_RBPressed = false; + } + if (s_Event.type == SDL_MOUSEBUTTONDOWN && + s_Event.button.button == SDL_BUTTON_RIGHT) { + s_RBPressed = true; + } + + if (s_Event.type == SDL_MOUSEBUTTONUP && + s_Event.button.button == SDL_BUTTON_MIDDLE) { + s_MBPressed = false; + } + if (s_Event.type == SDL_MOUSEBUTTONDOWN && + s_Event.button.button == SDL_BUTTON_MIDDLE) { + s_MBPressed = true; + } + s_Scroll = s_Event.type == SDL_MOUSEWHEEL || s_Scroll; + if (s_Scroll) { s_ScrollDistance.x = static_cast(s_Event.wheel.x); s_ScrollDistance.y = static_cast(s_Event.wheel.y);