From 1600ca2c0352fd126588ed079f39ace44768f83d Mon Sep 17 00:00:00 2001 From: Megamouse Date: Mon, 20 May 2024 09:58:09 +0200 Subject: [PATCH] input: add horizontal mouse scroll/tilt to mouse handlers --- rpcs3/Emu/Io/MouseHandler.cpp | 17 +++++++++-------- rpcs3/Emu/Io/MouseHandler.h | 4 ++-- rpcs3/Input/basic_mouse_handler.cpp | 13 ++++++++++++- rpcs3/Input/raw_mouse_handler.cpp | 14 ++++++-------- 4 files changed, 29 insertions(+), 19 deletions(-) diff --git a/rpcs3/Emu/Io/MouseHandler.cpp b/rpcs3/Emu/Io/MouseHandler.cpp index 5cc83cd5ab..adb1c479fb 100644 --- a/rpcs3/Emu/Io/MouseHandler.cpp +++ b/rpcs3/Emu/Io/MouseHandler.cpp @@ -68,15 +68,15 @@ void MouseHandlerBase::Button(u32 index, u8 button, bool pressed) else mouse.buttons &= ~button; - MouseData new_data; + MouseData new_data{}; new_data.update = CELL_MOUSE_DATA_UPDATE; new_data.buttons = mouse.buttons; - datalist.push_back(new_data); + datalist.push_back(std::move(new_data)); } } -void MouseHandlerBase::Scroll(u32 index, s32 rotation) +void MouseHandlerBase::Scroll(u32 index, s8 x, s8 y) { std::lock_guard lock(mutex); @@ -95,12 +95,13 @@ void MouseHandlerBase::Scroll(u32 index, s32 rotation) datalist.pop_front(); } - MouseData new_data; + MouseData new_data{}; new_data.update = CELL_MOUSE_DATA_UPDATE; - new_data.wheel = std::clamp(rotation / 120, -128, 127); // 120=event.GetWheelDelta() new_data.buttons = mouse.buttons; + new_data.wheel = y; + new_data.tilt = x; - datalist.push_back(new_data); + datalist.push_back(std::move(new_data)); } } @@ -123,7 +124,7 @@ void MouseHandlerBase::Move(u32 index, s32 x_pos_new, s32 y_pos_new, s32 x_max, datalist.pop_front(); } - MouseData new_data; + MouseData new_data{}; new_data.update = CELL_MOUSE_DATA_UPDATE; new_data.buttons = mouse.buttons; @@ -146,7 +147,7 @@ void MouseHandlerBase::Move(u32 index, s32 x_pos_new, s32 y_pos_new, s32 x_max, //rawdata.data[rawdata.len % CELL_MOUSE_MAX_CODES] = 0; // (TODO) //rawdata.len++; - datalist.push_back(new_data); + datalist.push_back(std::move(new_data)); } } diff --git a/rpcs3/Emu/Io/MouseHandler.h b/rpcs3/Emu/Io/MouseHandler.h index b30ebab56d..3467b821eb 100644 --- a/rpcs3/Emu/Io/MouseHandler.h +++ b/rpcs3/Emu/Io/MouseHandler.h @@ -95,7 +95,7 @@ struct MouseData s8 x_axis = 0; s8 y_axis = 0; s8 wheel = 0; - s8 tilt = 0; // (TODO) + s8 tilt = 0; }; struct MouseTabletData @@ -144,7 +144,7 @@ public: void save(utils::serial& ar); void Button(u32 index, u8 button, bool pressed); - void Scroll(u32 index, s32 rotation); + void Scroll(u32 index, s8 x, s8 y); void Move(u32 index, s32 x_pos_new, s32 y_pos_new, s32 x_max, s32 y_max, const bool is_relative = false, s32 x_delta = 0, s32 y_delta = 0); void SetIntercepted(bool intercepted); diff --git a/rpcs3/Input/basic_mouse_handler.cpp b/rpcs3/Input/basic_mouse_handler.cpp index 03846f59bf..fea4e4cdd8 100644 --- a/rpcs3/Input/basic_mouse_handler.cpp +++ b/rpcs3/Input/basic_mouse_handler.cpp @@ -103,6 +103,8 @@ bool basic_mouse_handler::eventFilter(QObject* target, QEvent* ev) void basic_mouse_handler::MouseButtonDown(QMouseEvent* event) { + if (!event) return; + const int button = event->button(); if (const auto it = std::find_if(m_buttons.cbegin(), m_buttons.cend(), [button](const auto& entry){ return entry.second == button; }); it != m_buttons.cend()) @@ -113,6 +115,8 @@ void basic_mouse_handler::MouseButtonDown(QMouseEvent* event) void basic_mouse_handler::MouseButtonUp(QMouseEvent* event) { + if (!event) return; + const int button = event->button(); if (const auto it = std::find_if(m_buttons.cbegin(), m_buttons.cend(), [button](const auto& entry){ return entry.second == button; }); it != m_buttons.cend()) @@ -123,7 +127,12 @@ void basic_mouse_handler::MouseButtonUp(QMouseEvent* event) void basic_mouse_handler::MouseScroll(QWheelEvent* event) { - MouseHandlerBase::Scroll(0, event->angleDelta().y()); + if (!event) return; + + const QPoint delta = event->angleDelta(); + const s8 x = std::clamp(delta.x() / 120, -128, 127); + const s8 y = std::clamp(delta.y() / 120, -128, 127); + MouseHandlerBase::Scroll(0, x, y); } bool basic_mouse_handler::get_mouse_lock_state() const @@ -148,6 +157,8 @@ int basic_mouse_handler::get_mouse_button(const cfg::string& button) void basic_mouse_handler::MouseMove(QMouseEvent* event) { + if (!event) return; + if (is_time_for_update()) { // get the screen dimensions diff --git a/rpcs3/Input/raw_mouse_handler.cpp b/rpcs3/Input/raw_mouse_handler.cpp index 8dd487e359..38f27894f9 100644 --- a/rpcs3/Input/raw_mouse_handler.cpp +++ b/rpcs3/Input/raw_mouse_handler.cpp @@ -143,17 +143,15 @@ void raw_mouse::update_values(const RAWMOUSE& state) get_button_pressed(CELL_MOUSE_BUTTON_4, state.usButtonFlags); get_button_pressed(CELL_MOUSE_BUTTON_5, state.usButtonFlags); - // Get vertical mouse wheel + // Get mouse wheel if ((state.usButtonFlags & RI_MOUSE_WHEEL)) { - m_handler->Scroll(m_index, static_cast(state.usButtonData)); + m_handler->Scroll(m_index, 0, std::clamp(static_cast(state.usButtonData) / WHEEL_DELTA, -128, 127)); + } + else if ((state.usButtonFlags & RI_MOUSE_HWHEEL)) + { + m_handler->Scroll(m_index, std::clamp(static_cast(state.usButtonData) / WHEEL_DELTA, -128, 127), 0); } - - // Get horizontal mouse wheel. Ignored until needed. - //if ((state.usButtonFlags & RI_MOUSE_HWHEEL)) - //{ - // m_handler->Scroll(m_index, static_cast(state.usButtonData)); - //} // Get mouse movement if ((state.usFlags & MOUSE_MOVE_ABSOLUTE))