Add mouse button type

This commit is contained in:
Jan Mrna 2025-10-05 12:16:53 +02:00
parent 9757675513
commit 8aeb9c8435
2 changed files with 8 additions and 3 deletions

View File

@ -59,16 +59,18 @@ const std::vector<UserAction> &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<MouseButton>(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<MouseButton>(mouse_event.button);
if (button == MouseButton::MIDDLE) {
mouse_pan = false;
}
} else if (event.type == SDL_EVENT_MOUSE_MOTION) {

View File

@ -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 };