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 @@ // Licensed under GPLv2+ // Refer to the license.txt file included. +#include "core/settings.h" #include "input_common/mouse/mouse_input.h" namespace MouseInput { @@ -32,10 +33,18 @@ void Mouse::UpdateThread() { info.motion.UpdateOrientation(update_time * 1000); info.tilt_speed = 0; info.data.motion = info.motion.GetMotion(); + if (Settings::values.mouse_panning) { + info.last_mouse_change *= 0.96f; + info.data.axis = {static_cast<int>(16 * info.last_mouse_change.x), + static_cast<int>(16 * -info.last_mouse_change.y)}; + } } if (configuring) { UpdateYuzuSettings(); } + if (mouse_panning_timout++ > 20) { + StopPanning(); + } std::this_thread::sleep_for(std::chrono::milliseconds(update_time)); } } @@ -50,7 +59,7 @@ void Mouse::UpdateYuzuSettings() { }); } -void Mouse::PressButton(int x, int y, int button_) { +void Mouse::PressButton(int x, int y, MouseButton button_) { const auto button_index = static_cast<std::size_t>(button_); if (button_index >= mouse_info.size()) { return; @@ -58,15 +67,52 @@ void Mouse::PressButton(int x, int y, int button_) { const auto button = 1U << button_index; buttons |= static_cast<u16>(button); - last_button = static_cast<MouseButton>(button_index); + last_button = button_; mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); mouse_info[button_index].data.pressed = true; } -void Mouse::MouseMove(int x, int y) { +void Mouse::StopPanning() { for (MouseInfo& info : mouse_info) { + if (Settings::values.mouse_panning) { + info.data.axis = {}; + info.tilt_speed = 0; + info.last_mouse_change = {}; + } + } +} + +void Mouse::MouseMove(int x, int y, int center_x, int center_y) { + for (MouseInfo& info : mouse_info) { + if (Settings::values.mouse_panning) { + auto mouse_change = + (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); + mouse_panning_timout = 0; + + if (mouse_change.y == 0 && mouse_change.x == 0) { + continue; + } + const auto mouse_change_length = mouse_change.Length(); + if (mouse_change_length < 3.0f) { + mouse_change /= mouse_change_length / 3.0f; + } + + info.last_mouse_change = (info.last_mouse_change * 0.91f) + (mouse_change * 0.09f); + + const auto last_mouse_change_length = info.last_mouse_change.Length(); + if (last_mouse_change_length > 8.0f) { + info.last_mouse_change /= last_mouse_change_length / 8.0f; + } else if (last_mouse_change_length < 1.0f) { + info.last_mouse_change = mouse_change / mouse_change.Length(); + } + + info.tilt_direction = info.last_mouse_change; + info.tilt_speed = info.tilt_direction.Normalize() * info.sensitivity; + continue; + } + if (info.data.pressed) { const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; @@ -83,7 +129,7 @@ void Mouse::MouseMove(int x, int y) { } } -void Mouse::ReleaseButton(int button_) { +void Mouse::ReleaseButton(MouseButton button_) { const auto button_index = static_cast<std::size_t>(button_); if (button_index >= mouse_info.size()) { return; @@ -106,11 +152,52 @@ void Mouse::BeginConfiguration() { void Mouse::EndConfiguration() { buttons = 0; + for (MouseInfo& info : mouse_info) { + info.tilt_speed = 0; + info.data.pressed = false; + info.data.axis = {0, 0}; + } last_button = MouseButton::Undefined; mouse_queue.Clear(); configuring = false; } +bool Mouse::ToggleButton(std::size_t button_) { + if (button_ >= mouse_info.size()) { + return false; + } + const auto button = 1U << button_; + const bool button_state = (toggle_buttons & button) != 0; + const bool button_lock = (lock_buttons & button) != 0; + + if (button_lock) { + return button_state; + } + + lock_buttons |= static_cast<u16>(button); + + if (button_state) { + toggle_buttons &= static_cast<u16>(0xFF - button); + } else { + toggle_buttons |= static_cast<u16>(button); + } + + return !button_state; +} + +bool Mouse::UnlockButton(std::size_t button_) { + if (button_ >= mouse_info.size()) { + return false; + } + + const auto button = 1U << button_; + const bool button_state = (toggle_buttons & button) != 0; + + lock_buttons &= static_cast<u16>(0xFF - button); + + return button_state; +} + Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() { return mouse_queue; } |