diff options
Diffstat (limited to 'src/input_common')
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 48 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_input.h | 7 | ||||
| -rw-r--r-- | src/input_common/mouse/mouse_poller.cpp | 3 | ||||
| -rw-r--r-- | src/input_common/sdl/sdl_impl.cpp | 7 | ||||
| -rw-r--r-- | src/input_common/settings.h | 1 |
5 files changed, 63 insertions, 3 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; |
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 { |
diff --git a/src/input_common/sdl/sdl_impl.cpp b/src/input_common/sdl/sdl_impl.cpp index f67de37e3..a88ae452f 100644 --- a/src/input_common/sdl/sdl_impl.cpp +++ b/src/input_common/sdl/sdl_impl.cpp | |||
| @@ -717,6 +717,13 @@ SDLState::SDLState() { | |||
| 717 | if (SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1") == SDL_FALSE) { | 717 | if (SDL_SetHint(SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS, "1") == SDL_FALSE) { |
| 718 | LOG_ERROR(Input, "Failed to set hint for background events with: {}", SDL_GetError()); | 718 | LOG_ERROR(Input, "Failed to set hint for background events with: {}", SDL_GetError()); |
| 719 | } | 719 | } |
| 720 | // these hints are only defined on sdl2.0.9 or higher | ||
| 721 | #if SDL_VERSION_ATLEAST(2, 0, 9) | ||
| 722 | #if !SDL_VERSION_ATLEAST(2, 0, 12) | ||
| 723 | // There are also hints to toggle the individual drivers if needed. | ||
| 724 | SDL_SetHint(SDL_HINT_JOYSTICK_HIDAPI, "0"); | ||
| 725 | #endif | ||
| 726 | #endif | ||
| 720 | 727 | ||
| 721 | SDL_AddEventWatch(&SDLEventWatcher, this); | 728 | SDL_AddEventWatch(&SDLEventWatcher, this); |
| 722 | 729 | ||
diff --git a/src/input_common/settings.h b/src/input_common/settings.h index 75486554b..a59f5d461 100644 --- a/src/input_common/settings.h +++ b/src/input_common/settings.h | |||
| @@ -340,6 +340,7 @@ enum class ControllerType { | |||
| 340 | LeftJoycon, | 340 | LeftJoycon, |
| 341 | RightJoycon, | 341 | RightJoycon, |
| 342 | Handheld, | 342 | Handheld, |
| 343 | GameCube, | ||
| 343 | }; | 344 | }; |
| 344 | 345 | ||
| 345 | struct PlayerInput { | 346 | struct PlayerInput { |