From 6cfcb7b4f389d42c32fe282035f8ea07dc56d1d5 Mon Sep 17 00:00:00 2001 From: MSuih Date: Sun, 29 Dec 2019 09:33:15 +0200 Subject: [PATCH] Add support for mousewheel movement --- rpcs3/Input/keyboard_pad_handler.cpp | 69 +++++++++++++++++++++++++++ rpcs3/Input/keyboard_pad_handler.h | 24 ++++++++-- rpcs3/rpcs3qt/pad_settings_dialog.cpp | 55 +++++++++++++++++++++ rpcs3/rpcs3qt/pad_settings_dialog.h | 1 + 4 files changed, 145 insertions(+), 4 deletions(-) diff --git a/rpcs3/Input/keyboard_pad_handler.cpp b/rpcs3/Input/keyboard_pad_handler.cpp index 5ce01d7e69..9fe90bf064 100644 --- a/rpcs3/Input/keyboard_pad_handler.cpp +++ b/rpcs3/Input/keyboard_pad_handler.cpp @@ -156,6 +156,9 @@ bool keyboard_pad_handler::eventFilter(QObject* target, QEvent* ev) case QEvent::MouseMove: mouseMoveEvent(static_cast(ev)); break; + case QEvent::Wheel: + mouseWheelEvent(static_cast(ev)); + break; default: break; } @@ -378,6 +381,46 @@ void keyboard_pad_handler::mouseMoveEvent(QMouseEvent* event) event->ignore(); } +void keyboard_pad_handler::mouseWheelEvent(QWheelEvent* event) +{ + QPoint direction = event->angleDelta(); + + if (direction.isNull()) + { + // Scrolling started/ended event, no direction given + return; + } + + if (const int x = direction.x()) + { + bool to_left = event->inverted() ? x < 0 : x > 0; + if (to_left) + { + Key(mouse::wheel_left, true); + m_last_wheel_move_left = std::chrono::steady_clock::now(); + } + else + { + Key(mouse::wheel_right, true); + m_last_wheel_move_right = std::chrono::steady_clock::now(); + } + } + if (const int y = direction.y()) + { + bool to_up = event->inverted() ? y < 0 : y > 0; + if (to_up) + { + Key(mouse::wheel_up, true); + m_last_wheel_move_up = std::chrono::steady_clock::now(); + } + else + { + Key(mouse::wheel_down, true); + m_last_wheel_move_down = std::chrono::steady_clock::now(); + } + } +} + std::vector keyboard_pad_handler::ListDevices() { std::vector list_devices; @@ -659,4 +702,30 @@ void keyboard_pad_handler::ThreadProc() } } } + + // Releases the wheel buttons 0,1 sec after they've been triggered + // Next activation is set to distant future to avoid activating this on every proc + std::chrono::steady_clock::time_point now = std::chrono::steady_clock::now(); + const auto update_treshold = std::chrono::milliseconds(100); + const auto delay = std::chrono::hours(24); + if (now >= m_last_wheel_move_up + update_treshold) + { + Key(mouse::wheel_up, false); + m_last_wheel_move_up = now + delay; + } + if (now >= m_last_wheel_move_down + update_treshold) + { + Key(mouse::wheel_down, false); + m_last_wheel_move_down = now + delay; + } + if (now >= m_last_wheel_move_left + update_treshold) + { + Key(mouse::wheel_left, false); + m_last_wheel_move_left = now + delay; + } + if (now >= m_last_wheel_move_right + update_treshold) + { + Key(mouse::wheel_right, false); + m_last_wheel_move_right = now + delay; + } } diff --git a/rpcs3/Input/keyboard_pad_handler.h b/rpcs3/Input/keyboard_pad_handler.h index 295ab82c59..870bc1c099 100644 --- a/rpcs3/Input/keyboard_pad_handler.h +++ b/rpcs3/Input/keyboard_pad_handler.h @@ -8,10 +8,14 @@ enum mouse { - move_left = 0x05555550, - move_right = 0x05555551, - move_up = 0x05555552, - move_down = 0x05555553 + move_left = 0x05555550, + move_right = 0x05555551, + move_up = 0x05555552, + move_down = 0x05555553, + wheel_up = 0x05555554, + wheel_down = 0x05555555, + wheel_left = 0x05555556, + wheel_right = 0x05555557 }; class keyboard_pad_handler final : public QObject, public PadHandlerBase @@ -52,6 +56,11 @@ class keyboard_pad_handler final : public QObject, public PadHandlerBase { mouse::move_right , "Mouse MRight" }, { mouse::move_up , "Mouse MUp" }, { mouse::move_down , "Mouse MDown" }, + + { mouse::wheel_up , "Wheel Up" }, + { mouse::wheel_down , "Wheel Down" }, + { mouse::wheel_left , "Wheel Left" }, + { mouse::wheel_right , "Wheel Right" }, }; public: @@ -66,6 +75,7 @@ public: void mousePressEvent(QMouseEvent* event); void mouseReleaseEvent(QMouseEvent* event); void mouseMoveEvent(QMouseEvent* event); + void mouseWheelEvent(QWheelEvent* event); bool eventFilter(QObject* obj, QEvent* ev) override; @@ -108,4 +118,10 @@ private: int m_deadzone_y = 60; double m_multi_x = 2; double m_multi_y = 2.5; + + // Mousewheel + std::chrono::steady_clock::time_point m_last_wheel_move_up; + std::chrono::steady_clock::time_point m_last_wheel_move_down; + std::chrono::steady_clock::time_point m_last_wheel_move_left; + std::chrono::steady_clock::time_point m_last_wheel_move_right; }; diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.cpp b/rpcs3/rpcs3qt/pad_settings_dialog.cpp index c39159ea14..69f8f52d1e 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.cpp +++ b/rpcs3/rpcs3qt/pad_settings_dialog.cpp @@ -692,6 +692,61 @@ void pad_settings_dialog::mouseReleaseEvent(QMouseEvent* event) ReactivateButtons(); } +void pad_settings_dialog::wheelEvent(QWheelEvent *event) +{ + if (m_handler->m_type != pad_handler::keyboard) + { + return; + } + + if (m_button_id == button_ids::id_pad_begin) + { + return; + } + + if (m_button_id <= button_ids::id_pad_begin || m_button_id >= button_ids::id_pad_end) + { + LOG_NOTICE(HLE, "Pad Settings: Handler Type: %d, Unknown button ID: %d", static_cast(m_handler->m_type), m_button_id); + return; + } + + QPoint direction = event->angleDelta(); + if (direction.isNull()) + { + // Scrolling started/ended event, no direction given + return; + } + + u32 key; + if (const int x = direction.x()) + { + bool to_left = event->inverted() ? x < 0 : x > 0; + if (to_left) + { + key = mouse::wheel_left; + } + else + { + key = mouse::wheel_right; + } + } + if (const int y = direction.y()) + { + bool to_up = event->inverted() ? y < 0 : y > 0; + if (to_up) + { + key = mouse::wheel_up; + } + else + { + key = mouse::wheel_down; + } + } + m_cfg_entries[m_button_id].key = (static_cast(m_handler.get()))->GetMouseName(key); + m_cfg_entries[m_button_id].text = qstr(m_cfg_entries[m_button_id].key); + ReactivateButtons(); +} + void pad_settings_dialog::mouseMoveEvent(QMouseEvent* /*event*/) { if (m_handler->m_type != pad_handler::keyboard) diff --git a/rpcs3/rpcs3qt/pad_settings_dialog.h b/rpcs3/rpcs3qt/pad_settings_dialog.h index be89377f54..18e62e33a3 100644 --- a/rpcs3/rpcs3qt/pad_settings_dialog.h +++ b/rpcs3/rpcs3qt/pad_settings_dialog.h @@ -180,5 +180,6 @@ protected: void keyPressEvent(QKeyEvent *keyEvent) override; void mouseReleaseEvent(QMouseEvent *event) override; void mouseMoveEvent(QMouseEvent *event) override; + void wheelEvent(QWheelEvent *event) override; bool eventFilter(QObject* object, QEvent* event) override; };