diff options
Diffstat (limited to 'src/input_common/drivers')
| -rw-r--r-- | src/input_common/drivers/mouse.cpp | 67 | ||||
| -rw-r--r-- | src/input_common/drivers/mouse.h | 38 |
2 files changed, 81 insertions, 24 deletions
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp index faf9cbdc3..da50e0a24 100644 --- a/src/input_common/drivers/mouse.cpp +++ b/src/input_common/drivers/mouse.cpp | |||
| @@ -15,23 +15,39 @@ constexpr int mouse_axis_y = 1; | |||
| 15 | constexpr int wheel_axis_x = 2; | 15 | constexpr int wheel_axis_x = 2; |
| 16 | constexpr int wheel_axis_y = 3; | 16 | constexpr int wheel_axis_y = 3; |
| 17 | constexpr int motion_wheel_y = 4; | 17 | constexpr int motion_wheel_y = 4; |
| 18 | constexpr int touch_axis_x = 10; | ||
| 19 | constexpr int touch_axis_y = 11; | ||
| 20 | constexpr PadIdentifier identifier = { | 18 | constexpr PadIdentifier identifier = { |
| 21 | .guid = Common::UUID{}, | 19 | .guid = Common::UUID{}, |
| 22 | .port = 0, | 20 | .port = 0, |
| 23 | .pad = 0, | 21 | .pad = 0, |
| 24 | }; | 22 | }; |
| 25 | 23 | ||
| 24 | constexpr PadIdentifier real_mouse_identifier = { | ||
| 25 | .guid = Common::UUID{}, | ||
| 26 | .port = 1, | ||
| 27 | .pad = 0, | ||
| 28 | }; | ||
| 29 | |||
| 30 | constexpr PadIdentifier touch_identifier = { | ||
| 31 | .guid = Common::UUID{}, | ||
| 32 | .port = 2, | ||
| 33 | .pad = 0, | ||
| 34 | }; | ||
| 35 | |||
| 26 | Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_)) { | 36 | Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_)) { |
| 27 | PreSetController(identifier); | 37 | PreSetController(identifier); |
| 38 | PreSetController(real_mouse_identifier); | ||
| 39 | PreSetController(touch_identifier); | ||
| 40 | |||
| 41 | // Initialize all mouse axis | ||
| 28 | PreSetAxis(identifier, mouse_axis_x); | 42 | PreSetAxis(identifier, mouse_axis_x); |
| 29 | PreSetAxis(identifier, mouse_axis_y); | 43 | PreSetAxis(identifier, mouse_axis_y); |
| 30 | PreSetAxis(identifier, wheel_axis_x); | 44 | PreSetAxis(identifier, wheel_axis_x); |
| 31 | PreSetAxis(identifier, wheel_axis_y); | 45 | PreSetAxis(identifier, wheel_axis_y); |
| 32 | PreSetAxis(identifier, motion_wheel_y); | 46 | PreSetAxis(identifier, motion_wheel_y); |
| 33 | PreSetAxis(identifier, touch_axis_x); | 47 | PreSetAxis(real_mouse_identifier, mouse_axis_x); |
| 34 | PreSetAxis(identifier, touch_axis_y); | 48 | PreSetAxis(real_mouse_identifier, mouse_axis_y); |
| 49 | PreSetAxis(touch_identifier, mouse_axis_x); | ||
| 50 | PreSetAxis(touch_identifier, mouse_axis_y); | ||
| 35 | update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); }); | 51 | update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); }); |
| 36 | } | 52 | } |
| 37 | 53 | ||
| @@ -39,7 +55,7 @@ void Mouse::UpdateThread(std::stop_token stop_token) { | |||
| 39 | Common::SetCurrentThreadName("Mouse"); | 55 | Common::SetCurrentThreadName("Mouse"); |
| 40 | constexpr int update_time = 10; | 56 | constexpr int update_time = 10; |
| 41 | while (!stop_token.stop_requested()) { | 57 | while (!stop_token.stop_requested()) { |
| 42 | if (Settings::values.mouse_panning && !Settings::values.mouse_enabled) { | 58 | if (Settings::values.mouse_panning) { |
| 43 | // Slow movement by 4% | 59 | // Slow movement by 4% |
| 44 | last_mouse_change *= 0.96f; | 60 | last_mouse_change *= 0.96f; |
| 45 | const float sensitivity = | 61 | const float sensitivity = |
| @@ -57,17 +73,7 @@ void Mouse::UpdateThread(std::stop_token stop_token) { | |||
| 57 | } | 73 | } |
| 58 | } | 74 | } |
| 59 | 75 | ||
| 60 | void Mouse::MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int center_y) { | 76 | void Mouse::Move(int x, int y, int center_x, int center_y) { |
| 61 | // If native mouse is enabled just set the screen coordinates | ||
| 62 | if (Settings::values.mouse_enabled) { | ||
| 63 | SetAxis(identifier, mouse_axis_x, touch_x); | ||
| 64 | SetAxis(identifier, mouse_axis_y, touch_y); | ||
| 65 | return; | ||
| 66 | } | ||
| 67 | |||
| 68 | SetAxis(identifier, touch_axis_x, touch_x); | ||
| 69 | SetAxis(identifier, touch_axis_y, touch_y); | ||
| 70 | |||
| 71 | if (Settings::values.mouse_panning) { | 77 | if (Settings::values.mouse_panning) { |
| 72 | auto mouse_change = | 78 | auto mouse_change = |
| 73 | (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); | 79 | (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>(); |
| @@ -113,20 +119,41 @@ void Mouse::MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int | |||
| 113 | } | 119 | } |
| 114 | } | 120 | } |
| 115 | 121 | ||
| 116 | void Mouse::PressButton(int x, int y, f32 touch_x, f32 touch_y, MouseButton button) { | 122 | void Mouse::MouseMove(f32 touch_x, f32 touch_y) { |
| 117 | SetAxis(identifier, touch_axis_x, touch_x); | 123 | SetAxis(real_mouse_identifier, mouse_axis_x, touch_x); |
| 118 | SetAxis(identifier, touch_axis_y, touch_y); | 124 | SetAxis(real_mouse_identifier, mouse_axis_y, touch_y); |
| 125 | } | ||
| 126 | |||
| 127 | void Mouse::TouchMove(f32 touch_x, f32 touch_y) { | ||
| 128 | SetAxis(touch_identifier, mouse_axis_x, touch_x); | ||
| 129 | SetAxis(touch_identifier, mouse_axis_y, touch_y); | ||
| 130 | } | ||
| 131 | |||
| 132 | void Mouse::PressButton(int x, int y, MouseButton button) { | ||
| 119 | SetButton(identifier, static_cast<int>(button), true); | 133 | SetButton(identifier, static_cast<int>(button), true); |
| 134 | |||
| 120 | // Set initial analog parameters | 135 | // Set initial analog parameters |
| 121 | mouse_origin = {x, y}; | 136 | mouse_origin = {x, y}; |
| 122 | last_mouse_position = {x, y}; | 137 | last_mouse_position = {x, y}; |
| 123 | button_pressed = true; | 138 | button_pressed = true; |
| 124 | } | 139 | } |
| 125 | 140 | ||
| 141 | void Mouse::PressMouseButton(MouseButton button) { | ||
| 142 | SetButton(real_mouse_identifier, static_cast<int>(button), true); | ||
| 143 | } | ||
| 144 | |||
| 145 | void Mouse::PressTouchButton(f32 touch_x, f32 touch_y, MouseButton button) { | ||
| 146 | SetAxis(touch_identifier, mouse_axis_x, touch_x); | ||
| 147 | SetAxis(touch_identifier, mouse_axis_y, touch_y); | ||
| 148 | SetButton(touch_identifier, static_cast<int>(button), true); | ||
| 149 | } | ||
| 150 | |||
| 126 | void Mouse::ReleaseButton(MouseButton button) { | 151 | void Mouse::ReleaseButton(MouseButton button) { |
| 127 | SetButton(identifier, static_cast<int>(button), false); | 152 | SetButton(identifier, static_cast<int>(button), false); |
| 153 | SetButton(real_mouse_identifier, static_cast<int>(button), false); | ||
| 154 | SetButton(touch_identifier, static_cast<int>(button), false); | ||
| 128 | 155 | ||
| 129 | if (!Settings::values.mouse_panning && !Settings::values.mouse_enabled) { | 156 | if (!Settings::values.mouse_panning) { |
| 130 | SetAxis(identifier, mouse_axis_x, 0); | 157 | SetAxis(identifier, mouse_axis_x, 0); |
| 131 | SetAxis(identifier, mouse_axis_y, 0); | 158 | SetAxis(identifier, mouse_axis_y, 0); |
| 132 | } | 159 | } |
diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h index 72073cc23..f3b65bdd1 100644 --- a/src/input_common/drivers/mouse.h +++ b/src/input_common/drivers/mouse.h | |||
| @@ -37,13 +37,43 @@ public: | |||
| 37 | * @param center_x the x-coordinate of the middle of the screen | 37 | * @param center_x the x-coordinate of the middle of the screen |
| 38 | * @param center_y the y-coordinate of the middle of the screen | 38 | * @param center_y the y-coordinate of the middle of the screen |
| 39 | */ | 39 | */ |
| 40 | void MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int center_y); | 40 | void Move(int x, int y, int center_x, int center_y); |
| 41 | 41 | ||
| 42 | /** | 42 | /** |
| 43 | * Sets the status of all buttons bound with the key to pressed | 43 | * Signals that real mouse has moved. |
| 44 | * @param key_code the code of the key to press | 44 | * @param x the absolute position on the touchscreen of the cursor |
| 45 | * @param y the absolute position on the touchscreen of the cursor | ||
| 45 | */ | 46 | */ |
| 46 | void PressButton(int x, int y, f32 touch_x, f32 touch_y, MouseButton button); | 47 | void MouseMove(f32 touch_x, f32 touch_y); |
| 48 | |||
| 49 | /** | ||
| 50 | * Signals that touch finger has moved. | ||
| 51 | * @param x the absolute position on the touchscreen of the cursor | ||
| 52 | * @param y the absolute position on the touchscreen of the cursor | ||
| 53 | */ | ||
| 54 | void TouchMove(f32 touch_x, f32 touch_y); | ||
| 55 | |||
| 56 | /** | ||
| 57 | * Sets the status of a button to pressed | ||
| 58 | * @param x the x-coordinate of the cursor | ||
| 59 | * @param y the y-coordinate of the cursor | ||
| 60 | * @param button the id of the button to press | ||
| 61 | */ | ||
| 62 | void PressButton(int x, int y, MouseButton button); | ||
| 63 | |||
| 64 | /** | ||
| 65 | * Sets the status of a mouse button to pressed | ||
| 66 | * @param button the id of the button to press | ||
| 67 | */ | ||
| 68 | void PressMouseButton(MouseButton button); | ||
| 69 | |||
| 70 | /** | ||
| 71 | * Sets the status of touch finger to pressed | ||
| 72 | * @param x the absolute position on the touchscreen of the cursor | ||
| 73 | * @param y the absolute position on the touchscreen of the cursor | ||
| 74 | * @param button the id of the button to press | ||
| 75 | */ | ||
| 76 | void PressTouchButton(f32 touch_x, f32 touch_y, MouseButton button); | ||
| 47 | 77 | ||
| 48 | /** | 78 | /** |
| 49 | * Sets the status of all buttons bound with the key to released | 79 | * Sets the status of all buttons bound with the key to released |