summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/mouse.cpp
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input_common/drivers/mouse.cpp31
1 files changed, 25 insertions, 6 deletions
diff --git a/src/input_common/drivers/mouse.cpp b/src/input_common/drivers/mouse.cpp
index afa92b458..478737db2 100644
--- a/src/input_common/drivers/mouse.cpp
+++ b/src/input_common/drivers/mouse.cpp
@@ -12,6 +12,10 @@
12#include "input_common/drivers/mouse.h" 12#include "input_common/drivers/mouse.h"
13 13
14namespace InputCommon { 14namespace InputCommon {
15constexpr int mouse_axis_x = 0;
16constexpr int mouse_axis_y = 1;
17constexpr int wheel_axis_x = 2;
18constexpr int wheel_axis_y = 3;
15constexpr int touch_axis_x = 10; 19constexpr int touch_axis_x = 10;
16constexpr int touch_axis_y = 11; 20constexpr int touch_axis_y = 11;
17constexpr PadIdentifier identifier = { 21constexpr PadIdentifier identifier = {
@@ -22,6 +26,12 @@ constexpr PadIdentifier identifier = {
22 26
23Mouse::Mouse(const std::string input_engine_) : InputEngine(input_engine_) { 27Mouse::Mouse(const std::string input_engine_) : InputEngine(input_engine_) {
24 PreSetController(identifier); 28 PreSetController(identifier);
29 PreSetAxis(identifier, mouse_axis_x);
30 PreSetAxis(identifier, mouse_axis_y);
31 PreSetAxis(identifier, wheel_axis_x);
32 PreSetAxis(identifier, wheel_axis_y);
33 PreSetAxis(identifier, touch_axis_x);
34 PreSetAxis(identifier, touch_axis_x);
25 update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); }); 35 update_thread = std::jthread([this](std::stop_token stop_token) { UpdateThread(stop_token); });
26} 36}
27 37
@@ -34,14 +44,18 @@ void Mouse::UpdateThread(std::stop_token stop_token) {
34 last_mouse_change *= 0.96f; 44 last_mouse_change *= 0.96f;
35 const float sensitivity = 45 const float sensitivity =
36 Settings::values.mouse_panning_sensitivity.GetValue() * 0.022f; 46 Settings::values.mouse_panning_sensitivity.GetValue() * 0.022f;
37 SetAxis(identifier, 0, last_mouse_change.x * sensitivity); 47 SetAxis(identifier, mouse_axis_x, last_mouse_change.x * sensitivity);
38 SetAxis(identifier, 1, -last_mouse_change.y * sensitivity); 48 SetAxis(identifier, mouse_axis_y, -last_mouse_change.y * sensitivity);
39 } 49 }
40 50
41 if (mouse_panning_timout++ > 20) { 51 if (mouse_panning_timout++ > 20) {
42 StopPanning(); 52 StopPanning();
43 } 53 }
44 std::this_thread::sleep_for(std::chrono::milliseconds(update_time)); 54 std::this_thread::sleep_for(std::chrono::milliseconds(update_time));
55
56 // Reset wheel position
57 SetAxis(identifier, wheel_axis_x, 0);
58 SetAxis(identifier, wheel_axis_y, 0);
45 } 59 }
46} 60}
47 61
@@ -89,8 +103,8 @@ void Mouse::MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int
89 if (button_pressed) { 103 if (button_pressed) {
90 const auto mouse_move = Common::MakeVec<int>(x, y) - mouse_origin; 104 const auto mouse_move = Common::MakeVec<int>(x, y) - mouse_origin;
91 const float sensitivity = Settings::values.mouse_panning_sensitivity.GetValue() * 0.0012f; 105 const float sensitivity = Settings::values.mouse_panning_sensitivity.GetValue() * 0.0012f;
92 SetAxis(identifier, 0, static_cast<float>(mouse_move.x) * sensitivity); 106 SetAxis(identifier, mouse_axis_x, static_cast<float>(mouse_move.x) * sensitivity);
93 SetAxis(identifier, 1, static_cast<float>(-mouse_move.y) * sensitivity); 107 SetAxis(identifier, mouse_axis_y, static_cast<float>(-mouse_move.y) * sensitivity);
94 } 108 }
95} 109}
96 110
@@ -108,12 +122,17 @@ void Mouse::ReleaseButton(MouseButton button) {
108 SetButton(identifier, static_cast<int>(button), false); 122 SetButton(identifier, static_cast<int>(button), false);
109 123
110 if (!Settings::values.mouse_panning) { 124 if (!Settings::values.mouse_panning) {
111 SetAxis(identifier, 0, 0); 125 SetAxis(identifier, mouse_axis_x, 0);
112 SetAxis(identifier, 1, 0); 126 SetAxis(identifier, mouse_axis_y, 0);
113 } 127 }
114 button_pressed = false; 128 button_pressed = false;
115} 129}
116 130
131void Mouse::MouseWheelChange(int x, int y) {
132 SetAxis(identifier, wheel_axis_x, static_cast<f32>(x));
133 SetAxis(identifier, wheel_axis_y, static_cast<f32>(y));
134}
135
117void Mouse::ReleaseAllButtons() { 136void Mouse::ReleaseAllButtons() {
118 ResetButtonState(); 137 ResetButtonState();
119 button_pressed = false; 138 button_pressed = false;