diff options
Diffstat (limited to 'src/input_common/mouse')
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 32 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_input.h | 7 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_poller.cpp | 3 |
3 files changed, 39 insertions, 3 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index 10786a541..67a584d53 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp | |||
| @@ -2,6 +2,7 @@ | |||
| 2 | // Licensed under GPLv2+ | 2 | // Licensed under GPLv2+ |
| 3 | // Refer to the license.txt file included. | 3 | // Refer to the license.txt file included. |
| 4 | 4 | ||
| 5 | #include "core/settings.h" | ||
| 5 | #include "input_common/mouse/mouse_input.h" | 6 | #include "input_common/mouse/mouse_input.h" |
| 6 | 7 | ||
| 7 | namespace MouseInput { | 8 | namespace MouseInput { |
| @@ -36,6 +37,9 @@ void Mouse::UpdateThread() { | |||
| 36 | if (configuring) { | 37 | if (configuring) { |
| 37 | UpdateYuzuSettings(); | 38 | UpdateYuzuSettings(); |
| 38 | } | 39 | } |
| 40 | if (mouse_panning_timout++ > 8) { | ||
| 41 | StopPanning(); | ||
| 42 | } | ||
| 39 | std::this_thread::sleep_for(std::chrono::milliseconds(update_time)); | 43 | std::this_thread::sleep_for(std::chrono::milliseconds(update_time)); |
| 40 | } | 44 | } |
| 41 | } | 45 | } |
| @@ -65,8 +69,34 @@ void Mouse::PressButton(int x, int y, int button_) { | |||
| 65 | mouse_info[button_index].data.pressed = true; | 69 | mouse_info[button_index].data.pressed = true; |
| 66 | } | 70 | } |
| 67 | 71 | ||
| 68 | void Mouse::MouseMove(int x, int y) { | 72 | void Mouse::StopPanning() { |
| 73 | for (MouseInfo& info : mouse_info) { | ||
| 74 | if (Settings::values.mouse_panning) { | ||
| 75 | info.data.axis = {}; | ||
| 76 | info.tilt_speed = 0; | ||
| 77 | info.last_mouse_change = {}; | ||
| 78 | } | ||
| 79 | } | ||
| 80 | } | ||
| 81 | |||
| 82 | void Mouse::MouseMove(int x, int y, int center_x, int center_y) { | ||
| 69 | for (MouseInfo& info : mouse_info) { | 83 | for (MouseInfo& info : mouse_info) { |
| 84 | if (Settings::values.mouse_panning) { | ||
| 85 | const auto mouse_change = Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y); | ||
| 86 | mouse_panning_timout = 0; | ||
| 87 | |||
| 88 | if (mouse_change.y == 0 && mouse_change.x == 0) { | ||
| 89 | continue; | ||
| 90 | } | ||
| 91 | |||
| 92 | info.last_mouse_change = (info.last_mouse_change * 0.8f) + (mouse_change * 0.2f); | ||
| 93 | info.data.axis = {static_cast<int>(16 * info.last_mouse_change.x), | ||
| 94 | static_cast<int>(16 * -info.last_mouse_change.y)}; | ||
| 95 | info.tilt_direction = info.last_mouse_change; | ||
| 96 | info.tilt_speed = info.tilt_direction.Normalize() * info.sensitivity; | ||
| 97 | continue; | ||
| 98 | } | ||
| 99 | |||
| 70 | if (info.data.pressed) { | 100 | if (info.data.pressed) { |
| 71 | const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; | 101 | const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; |
| 72 | const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; | 102 | const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; |
diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 58803c1bf..46aa676c1 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h | |||
| @@ -57,8 +57,10 @@ public: | |||
| 57 | * Signals that mouse has moved. | 57 | * Signals that mouse has moved. |
| 58 | * @param x the x-coordinate of the cursor | 58 | * @param x the x-coordinate of the cursor |
| 59 | * @param y the y-coordinate of the cursor | 59 | * @param y the y-coordinate of the cursor |
| 60 | * @param center_x the x-coordinate of the middle of the screen | ||
| 61 | * @param center_y the y-coordinate of the middle of the screen | ||
| 60 | */ | 62 | */ |
| 61 | void MouseMove(int x, int y); | 63 | void MouseMove(int x, int y, int center_x, int center_y); |
| 62 | 64 | ||
| 63 | /** | 65 | /** |
| 64 | * Signals that a motion sensor tilt has ended. | 66 | * Signals that a motion sensor tilt has ended. |
| @@ -74,11 +76,13 @@ public: | |||
| 74 | private: | 76 | private: |
| 75 | void UpdateThread(); | 77 | void UpdateThread(); |
| 76 | void UpdateYuzuSettings(); | 78 | void UpdateYuzuSettings(); |
| 79 | void StopPanning(); | ||
| 77 | 80 | ||
| 78 | struct MouseInfo { | 81 | struct MouseInfo { |
| 79 | InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f}; | 82 | InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f}; |
| 80 | Common::Vec2<int> mouse_origin; | 83 | Common::Vec2<int> mouse_origin; |
| 81 | Common::Vec2<int> last_mouse_position; | 84 | Common::Vec2<int> last_mouse_position; |
| 85 | Common::Vec2<float> last_mouse_change; | ||
| 82 | bool is_tilting = false; | 86 | bool is_tilting = false; |
| 83 | float sensitivity{0.120f}; | 87 | float sensitivity{0.120f}; |
| 84 | 88 | ||
| @@ -94,5 +98,6 @@ private: | |||
| 94 | Common::SPSCQueue<MouseStatus> mouse_queue; | 98 | Common::SPSCQueue<MouseStatus> mouse_queue; |
| 95 | bool configuring{false}; | 99 | bool configuring{false}; |
| 96 | bool update_thread_running{true}; | 100 | bool update_thread_running{true}; |
| 101 | int mouse_panning_timout{}; | ||
| 97 | }; | 102 | }; |
| 98 | } // namespace MouseInput | 103 | } // namespace MouseInput |
diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp index 3d799b293..bb56787ee 100644 --- a/src/input_common/mouse/mouse_poller.cpp +++ b/src/input_common/mouse/mouse_poller.cpp | |||
| @@ -6,6 +6,7 @@ | |||
| 6 | #include <utility> | 6 | #include <utility> |
| 7 | 7 | ||
| 8 | #include "common/threadsafe_queue.h" | 8 | #include "common/threadsafe_queue.h" |
| 9 | #include "core/settings.h" | ||
| 9 | #include "input_common/mouse/mouse_input.h" | 10 | #include "input_common/mouse/mouse_input.h" |
| 10 | #include "input_common/mouse/mouse_poller.h" | 11 | #include "input_common/mouse/mouse_poller.h" |
| 11 | 12 | ||
| @@ -71,7 +72,7 @@ public: | |||
| 71 | std::lock_guard lock{mutex}; | 72 | std::lock_guard lock{mutex}; |
| 72 | const auto axis_value = | 73 | const auto axis_value = |
| 73 | static_cast<float>(mouse_input->GetMouseState(button).axis.at(axis)); | 74 | static_cast<float>(mouse_input->GetMouseState(button).axis.at(axis)); |
| 74 | return axis_value / (100.0f * range); | 75 | return axis_value * Settings::values.mouse_panning_sensitivity / (100.0f * range); |
| 75 | } | 76 | } |
| 76 | 77 | ||
| 77 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { | 78 | std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const { |