summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/mouse.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/drivers/mouse.cpp')
-rw-r--r--src/input_common/drivers/mouse.cpp67
1 files changed, 47 insertions, 20 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;
15constexpr int wheel_axis_x = 2; 15constexpr int wheel_axis_x = 2;
16constexpr int wheel_axis_y = 3; 16constexpr int wheel_axis_y = 3;
17constexpr int motion_wheel_y = 4; 17constexpr int motion_wheel_y = 4;
18constexpr int touch_axis_x = 10;
19constexpr int touch_axis_y = 11;
20constexpr PadIdentifier identifier = { 18constexpr 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
24constexpr PadIdentifier real_mouse_identifier = {
25 .guid = Common::UUID{},
26 .port = 1,
27 .pad = 0,
28};
29
30constexpr PadIdentifier touch_identifier = {
31 .guid = Common::UUID{},
32 .port = 2,
33 .pad = 0,
34};
35
26Mouse::Mouse(std::string input_engine_) : InputEngine(std::move(input_engine_)) { 36Mouse::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
60void Mouse::MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int center_y) { 76void 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
116void Mouse::PressButton(int x, int y, f32 touch_x, f32 touch_y, MouseButton button) { 122void 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
127void 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
132void 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
141void Mouse::PressMouseButton(MouseButton button) {
142 SetButton(real_mouse_identifier, static_cast<int>(button), true);
143}
144
145void 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
126void Mouse::ReleaseButton(MouseButton button) { 151void 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 }