diff options
Diffstat (limited to 'src/input_common/mouse/mouse_input.cpp')
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 48 |
1 files changed, 47 insertions, 1 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index 10786a541..b864d26f2 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 { |
| @@ -32,10 +33,18 @@ void Mouse::UpdateThread() { | |||
| 32 | info.motion.UpdateOrientation(update_time * 1000); | 33 | info.motion.UpdateOrientation(update_time * 1000); |
| 33 | info.tilt_speed = 0; | 34 | info.tilt_speed = 0; |
| 34 | info.data.motion = info.motion.GetMotion(); | 35 | info.data.motion = info.motion.GetMotion(); |
| 36 | if (Settings::values.mouse_panning) { | ||
| 37 | info.last_mouse_change *= 0.96f; | ||
| 38 | info.data.axis = {static_cast<int>(16 * info.last_mouse_change.x), | ||
| 39 | static_cast<int>(16 * -info.last_mouse_change.y)}; | ||
| 40 | } | ||
| 35 | } | 41 | } |
| 36 | if (configuring) { | 42 | if (configuring) { |
| 37 | UpdateYuzuSettings(); | 43 | UpdateYuzuSettings(); |
| 38 | } | 44 | } |
| 45 | if (mouse_panning_timout++ > 20) { | ||
| 46 | StopPanning(); | ||
| 47 | } | ||
| 39 | std::this_thread::sleep_for(std::chrono::milliseconds(update_time)); | 48 | std::this_thread::sleep_for(std::chrono::milliseconds(update_time)); |
| 40 | } | 49 | } |
| 41 | } | 50 | } |
| @@ -65,8 +74,45 @@ void Mouse::PressButton(int x, int y, int button_) { | |||
| 65 | mouse_info[button_index].data.pressed = true; | 74 | mouse_info[button_index].data.pressed = true; |
| 66 | } | 75 | } |
| 67 | 76 | ||
| 68 | void Mouse::MouseMove(int x, int y) { | 77 | void Mouse::StopPanning() { |
| 69 | for (MouseInfo& info : mouse_info) { | 78 | for (MouseInfo& info : mouse_info) { |
| 79 | if (Settings::values.mouse_panning) { | ||
| 80 | info.data.axis = {}; | ||
| 81 | info.tilt_speed = 0; | ||
| 82 | info.last_mouse_change = {}; | ||
| 83 | } | ||
| 84 | } | ||
| 85 | } | ||
| 86 | |||
| 87 | void Mouse::MouseMove(int x, int y, int center_x, int center_y) { | ||
| 88 | for (MouseInfo& info : mouse_info) { | ||
| 89 | if (Settings::values.mouse_panning) { | ||
| 90 | auto mouse_change = | ||
| 91 | (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); | ||
| 92 | mouse_panning_timout = 0; | ||
| 93 | |||
| 94 | if (mouse_change.y == 0 && mouse_change.x == 0) { | ||
| 95 | continue; | ||
| 96 | } | ||
| 97 | const auto mouse_change_length = mouse_change.Length(); | ||
| 98 | if (mouse_change_length < 3.0f) { | ||
| 99 | mouse_change /= mouse_change_length / 3.0f; | ||
| 100 | } | ||
| 101 | |||
| 102 | info.last_mouse_change = (info.last_mouse_change * 0.91f) + (mouse_change * 0.09f); | ||
| 103 | |||
| 104 | const auto last_mouse_change_length = info.last_mouse_change.Length(); | ||
| 105 | if (last_mouse_change_length > 8.0f) { | ||
| 106 | info.last_mouse_change /= last_mouse_change_length / 8.0f; | ||
| 107 | } else if (last_mouse_change_length < 1.0f) { | ||
| 108 | info.last_mouse_change = mouse_change / mouse_change.Length(); | ||
| 109 | } | ||
| 110 | |||
| 111 | info.tilt_direction = info.last_mouse_change; | ||
| 112 | info.tilt_speed = info.tilt_direction.Normalize() * info.sensitivity; | ||
| 113 | continue; | ||
| 114 | } | ||
| 115 | |||
| 70 | if (info.data.pressed) { | 116 | if (info.data.pressed) { |
| 71 | const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; | 117 | const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; |
| 72 | const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; | 118 | const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; |