diff --git a/rpcs3/Input/mouse_gyro_state.cpp b/rpcs3/Input/mouse_gyro_state.cpp index 05d9e50421..ed3c2d90cd 100644 --- a/rpcs3/Input/mouse_gyro_state.cpp +++ b/rpcs3/Input/mouse_gyro_state.cpp @@ -1,5 +1,12 @@ #include "mouse_gyro_state.h" +#include +#include +#include +#include + +#include + void mouse_gyro_state::clear() { active = false; @@ -37,6 +44,65 @@ void mouse_gyro_state::set_gyro_y(s32 steps) gyro_y = static_cast(std::clamp(gyro_y + steps, 0, DEFAULT_MOTION_Y * 2 - 1)); } +void mouse_gyro_state::gyro_detect(QEvent* ev, const QWindow& win) +{ + // Hardcoded mouse-based motion input. + // Captures mouse events while the game window is focused. + // Updates motion sensor values via mouse position and mouse wheel while RMB is held. + // Intentionally independent of chosen pad configuration. + switch (ev->type()) + { + case QEvent::MouseButtonPress: + { + auto* e = static_cast(ev); + if (e->button() == Qt::RightButton) + { + // Enable mouse-driven gyro emulation while RMB is held. + set_gyro_active(); + } + break; + } + case QEvent::MouseButtonRelease: + { + auto* e = static_cast(ev); + if (e->button() == Qt::RightButton) + { + // Disable gyro emulation and request a one-shot motion reset. + set_gyro_reset(); + } + break; + } + case QEvent::MouseMove: + { + auto* e = static_cast(ev); + + // Track cursor offset from window center. + const QPoint center(win.width() / 2, win.height() / 2); + const QPoint cur = e->position().toPoint(); + + const s32 off_x = cur.x() - center.x() + DEFAULT_MOTION_X; + const s32 off_y = cur.y() - center.y() + DEFAULT_MOTION_Z; + + // Determine motion from relative mouse position while gyro emulation is active. + set_gyro_xz(off_x, off_y); + + break; + } + case QEvent::Wheel: + { + auto* e = static_cast(ev); + + // Track mouse wheel steps. + const s32 steps = e->angleDelta().y() / 120; + + // Accumulate mouse wheel steps while gyro emulation is active. + set_gyro_y(steps); + + break; + } + } +} + void mouse_gyro_state::gyro_run(const std::shared_ptr& pad) { if (!pad || !pad->is_connected()) diff --git a/rpcs3/Input/mouse_gyro_state.h b/rpcs3/Input/mouse_gyro_state.h index bd4c870ff4..21b52d5b9c 100644 --- a/rpcs3/Input/mouse_gyro_state.h +++ b/rpcs3/Input/mouse_gyro_state.h @@ -3,7 +3,8 @@ #include "util/types.hpp" #include "Emu/Io/pad_types.h" -#include +class QEvent; +class QWindow; // Mouse-based motion sensor emulation state. class mouse_gyro_state @@ -29,5 +30,6 @@ public: void set_gyro_xz(s32 off_x, s32 off_y); void set_gyro_y(s32 steps); + void gyro_detect(QEvent* ev, const QWindow& win); void gyro_run(const std::shared_ptr& pad); }; diff --git a/rpcs3/Input/pad_thread.cpp b/rpcs3/Input/pad_thread.cpp index 27c1d33ee0..7120992b52 100644 --- a/rpcs3/Input/pad_thread.cpp +++ b/rpcs3/Input/pad_thread.cpp @@ -612,7 +612,8 @@ void pad_thread::operator()() // Inject mouse-based motion sensor values into pad sensors for gyro emulation. // Intentionally bound to Player 1 only. - m_mouse_gyro.gyro_run(m_pads[0]); + auto& main_pad = m_pads[0]; + m_mouse_gyro.gyro_run(main_pad); } m_info.now_connect = connected_devices + num_ldd_pad; diff --git a/rpcs3/rpcs3qt/gs_frame.cpp b/rpcs3/rpcs3qt/gs_frame.cpp index 061fb3c6cf..b2d2622394 100644 --- a/rpcs3/rpcs3qt/gs_frame.cpp +++ b/rpcs3/rpcs3qt/gs_frame.cpp @@ -1219,64 +1219,11 @@ bool gs_frame::event(QEvent* ev) } // Hardcoded mouse-based motion input. - // Captures mouse events while the game window is focused. - // Updates motion sensor values via mouse position and mouse wheel while RMB is held. - // Intentionally independent of chosen pad configuration. if (Emu.IsRunning()) { if (auto* pad_thr = pad::get_pad_thread(true)) { - switch (ev->type()) - { - case QEvent::MouseButtonPress: - { - auto* e = static_cast(ev); - if (e->button() == Qt::RightButton) - { - // Enable mouse-driven gyro emulation while RMB is held. - pad_thr->m_mouse_gyro.set_gyro_active(); - } - break; - } - case QEvent::MouseButtonRelease: - { - auto* e = static_cast(ev); - if (e->button() == Qt::RightButton) - { - // Disable gyro emulation and request a one-shot motion reset. - pad_thr->m_mouse_gyro.set_gyro_reset(); - } - break; - } - case QEvent::MouseMove: - { - auto* e = static_cast(ev); - - // Track cursor offset from window center. - const QPoint center(width() / 2, height() / 2); - const QPoint cur = e->position().toPoint(); - - const s32 off_x = cur.x() - center.x() + DEFAULT_MOTION_X; - const s32 off_y = cur.y() - center.y() + DEFAULT_MOTION_Z; - - // Determine motion from relative mouse position while gyro emulation is active. - pad_thr->m_mouse_gyro.set_gyro_xz(off_x, off_y); - - break; - } - case QEvent::Wheel: - { - auto* e = static_cast(ev); - - // Track mouse wheel steps. - const s32 steps = e->angleDelta().y() / 120; - - // Accumulate mouse wheel steps while gyro emulation is active. - pad_thr->m_mouse_gyro.set_gyro_y(steps); - - break; - } - } + pad_thr->m_mouse_gyro.gyro_detect(ev, *this); } }