diff --git a/cpp/src/user_input.cpp b/cpp/src/user_input.cpp index fc98968..59dd83b 100644 --- a/cpp/src/user_input.cpp +++ b/cpp/src/user_input.cpp @@ -59,16 +59,18 @@ const std::vector &UserInput::GetActions() { } } else if (event.type == SDL_EVENT_MOUSE_BUTTON_DOWN) { SDL_MouseButtonEvent mouse_event = event.button; - if (mouse_event.button == 1) { + MouseButton button = static_cast(mouse_event.button); + if (button == MouseButton::LEFT) { LOG_DEBUG("Mouse down: ", mouse_event.x, ", ", mouse_event.y); m_Actions.emplace_back(UserAction::Type::SET_MOVE_TARGET, WindowPos{mouse_event.x, mouse_event.y}); - } else if (mouse_event.button == 2) { + } else if (button == MouseButton::MIDDLE) { mouse_pan = true; } } else if (event.type == SDL_EVENT_MOUSE_BUTTON_UP) { SDL_MouseButtonEvent mouse_event = event.button; - if (mouse_event.button == 2) { + MouseButton button = static_cast(mouse_event.button); + if (button == MouseButton::MIDDLE) { mouse_pan = false; } } else if (event.type == SDL_EVENT_MOUSE_MOTION) { diff --git a/cpp/src/user_input.hpp b/cpp/src/user_input.hpp index 62631e5..48a2457 100644 --- a/cpp/src/user_input.hpp +++ b/cpp/src/user_input.hpp @@ -7,6 +7,9 @@ #include "log.hpp" #include "math.hpp" +// Seems like SDL doesn't have named constants for mouse button +enum class MouseButton { LEFT = 1, MIDDLE, RIGHT }; + class UserAction { public: enum class Type { NONE, EXIT, SET_MOVE_TARGET, SELECT_PATHFINDER, CAMERA_PAN, CAMERA_ZOOM };