diff options
Diffstat (limited to 'src/input_common/mouse/mouse_input.cpp')
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 95 |
1 files changed, 91 insertions, 4 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index 10786a541..329e416c7 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 | } |
| @@ -50,7 +59,7 @@ void Mouse::UpdateYuzuSettings() { | |||
| 50 | }); | 59 | }); |
| 51 | } | 60 | } |
| 52 | 61 | ||
| 53 | void Mouse::PressButton(int x, int y, int button_) { | 62 | void Mouse::PressButton(int x, int y, MouseButton button_) { |
| 54 | const auto button_index = static_cast<std::size_t>(button_); | 63 | const auto button_index = static_cast<std::size_t>(button_); |
| 55 | if (button_index >= mouse_info.size()) { | 64 | if (button_index >= mouse_info.size()) { |
| 56 | return; | 65 | return; |
| @@ -58,15 +67,52 @@ void Mouse::PressButton(int x, int y, int button_) { | |||
| 58 | 67 | ||
| 59 | const auto button = 1U << button_index; | 68 | const auto button = 1U << button_index; |
| 60 | buttons |= static_cast<u16>(button); | 69 | buttons |= static_cast<u16>(button); |
| 61 | last_button = static_cast<MouseButton>(button_index); | 70 | last_button = button_; |
| 62 | 71 | ||
| 63 | mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); | 72 | mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); |
| 64 | mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); | 73 | mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); |
| 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; |
| @@ -83,7 +129,7 @@ void Mouse::MouseMove(int x, int y) { | |||
| 83 | } | 129 | } |
| 84 | } | 130 | } |
| 85 | 131 | ||
| 86 | void Mouse::ReleaseButton(int button_) { | 132 | void Mouse::ReleaseButton(MouseButton button_) { |
| 87 | const auto button_index = static_cast<std::size_t>(button_); | 133 | const auto button_index = static_cast<std::size_t>(button_); |
| 88 | if (button_index >= mouse_info.size()) { | 134 | if (button_index >= mouse_info.size()) { |
| 89 | return; | 135 | return; |
| @@ -106,11 +152,52 @@ void Mouse::BeginConfiguration() { | |||
| 106 | 152 | ||
| 107 | void Mouse::EndConfiguration() { | 153 | void Mouse::EndConfiguration() { |
| 108 | buttons = 0; | 154 | buttons = 0; |
| 155 | for (MouseInfo& info : mouse_info) { | ||
| 156 | info.tilt_speed = 0; | ||
| 157 | info.data.pressed = false; | ||
| 158 | info.data.axis = {0, 0}; | ||
| 159 | } | ||
| 109 | last_button = MouseButton::Undefined; | 160 | last_button = MouseButton::Undefined; |
| 110 | mouse_queue.Clear(); | 161 | mouse_queue.Clear(); |
| 111 | configuring = false; | 162 | configuring = false; |
| 112 | } | 163 | } |
| 113 | 164 | ||
| 165 | bool Mouse::ToggleButton(std::size_t button_) { | ||
| 166 | if (button_ >= mouse_info.size()) { | ||
| 167 | return false; | ||
| 168 | } | ||
| 169 | const auto button = 1U << button_; | ||
| 170 | const bool button_state = (toggle_buttons & button) != 0; | ||
| 171 | const bool button_lock = (lock_buttons & button) != 0; | ||
| 172 | |||
| 173 | if (button_lock) { | ||
| 174 | return button_state; | ||
| 175 | } | ||
| 176 | |||
| 177 | lock_buttons |= static_cast<u16>(button); | ||
| 178 | |||
| 179 | if (button_state) { | ||
| 180 | toggle_buttons &= static_cast<u16>(0xFF - button); | ||
| 181 | } else { | ||
| 182 | toggle_buttons |= static_cast<u16>(button); | ||
| 183 | } | ||
| 184 | |||
| 185 | return !button_state; | ||
| 186 | } | ||
| 187 | |||
| 188 | bool Mouse::UnlockButton(std::size_t button_) { | ||
| 189 | if (button_ >= mouse_info.size()) { | ||
| 190 | return false; | ||
| 191 | } | ||
| 192 | |||
| 193 | const auto button = 1U << button_; | ||
| 194 | const bool button_state = (toggle_buttons & button) != 0; | ||
| 195 | |||
| 196 | lock_buttons &= static_cast<u16>(0xFF - button); | ||
| 197 | |||
| 198 | return button_state; | ||
| 199 | } | ||
| 200 | |||
| 114 | Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() { | 201 | Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() { |
| 115 | return mouse_queue; | 202 | return mouse_queue; |
| 116 | } | 203 | } |