diff --git a/common/include/mouse.h b/common/include/mouse.h index 8ec07cf32..47d299e7d 100644 --- a/common/include/mouse.h +++ b/common/include/mouse.h @@ -19,7 +19,6 @@ #include #include "window.h" -struct d_event; struct SDL_MouseButtonEvent; struct SDL_MouseMotionEvent; @@ -61,7 +60,8 @@ void mouse_cursor_autohide(); class d_event_mousebutton : public d_event { public: - int button; + d_event_mousebutton(event_type type, unsigned b); + const unsigned button; }; class d_event_mouse_moved : public d_event diff --git a/similar/arch/sdl/mouse.cpp b/similar/arch/sdl/mouse.cpp index 852f4665e..1380e893f 100644 --- a/similar/arch/sdl/mouse.cpp +++ b/similar/arch/sdl/mouse.cpp @@ -42,6 +42,11 @@ struct mouseinfo : flushable_mouseinfo static mouseinfo Mouse; +d_event_mousebutton::d_event_mousebutton(const event_type type, const unsigned b) : + d_event{type}, button(b) +{ +} + void mouse_init(void) { Mouse = {}; @@ -76,9 +81,7 @@ static void maybe_send_z_move(const unsigned button) static void send_singleclick(const bool pressed, const unsigned button) { - d_event_mousebutton event; - event.type = pressed ? EVENT_MOUSE_BUTTON_DOWN : EVENT_MOUSE_BUTTON_UP; - event.button = button; + const d_event_mousebutton event{pressed ? EVENT_MOUSE_BUTTON_DOWN : EVENT_MOUSE_BUTTON_UP, button}; con_printf(CON_DEBUG, "Sending event %s, button %d, coords %d,%d,%d", pressed ? "EVENT_MOUSE_BUTTON_DOWN" : "EVENT_MOUSE_BUTTON_UP", event.button, Mouse.x, Mouse.y, Mouse.z); event_send(event); @@ -91,9 +94,7 @@ static void maybe_send_doubleclick(const fix64 now, const unsigned button) when = now; if (now > then + F1_0/5) return; - d_event_mousebutton event; - event.type = EVENT_MOUSE_DOUBLE_CLICKED; - event.button = button; + const d_event_mousebutton event{EVENT_MOUSE_DOUBLE_CLICKED, button}; con_printf(CON_DEBUG, "Sending event EVENT_MOUSE_DOUBLE_CLICKED, button %d, coords %d,%d", button, Mouse.x, Mouse.y); event_send(event); }