summaryrefslogtreecommitdiff
path: root/src/input_common/mouse/mouse_input.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/mouse/mouse_input.cpp')
-rw-r--r--src/input_common/mouse/mouse_input.cpp38
1 files changed, 20 insertions, 18 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp
index d0ee64ad7..10786a541 100644
--- a/src/input_common/mouse/mouse_input.cpp
+++ b/src/input_common/mouse/mouse_input.cpp
@@ -2,9 +2,6 @@
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 "common/logging/log.h"
6#include "common/math_util.h"
7#include "common/param_package.h"
8#include "input_common/mouse/mouse_input.h" 5#include "input_common/mouse/mouse_input.h"
9 6
10namespace MouseInput { 7namespace MouseInput {
@@ -24,8 +21,11 @@ void Mouse::UpdateThread() {
24 constexpr int update_time = 10; 21 constexpr int update_time = 10;
25 while (update_thread_running) { 22 while (update_thread_running) {
26 for (MouseInfo& info : mouse_info) { 23 for (MouseInfo& info : mouse_info) {
27 Common::Vec3f angular_direction = {-info.tilt_direction.y, 0.0f, 24 const Common::Vec3f angular_direction{
28 -info.tilt_direction.x}; 25 -info.tilt_direction.y,
26 0.0f,
27 -info.tilt_direction.x,
28 };
29 29
30 info.motion.SetGyroscope(angular_direction * info.tilt_speed); 30 info.motion.SetGyroscope(angular_direction * info.tilt_speed);
31 info.motion.UpdateRotation(update_time * 1000); 31 info.motion.UpdateRotation(update_time * 1000);
@@ -41,22 +41,24 @@ void Mouse::UpdateThread() {
41} 41}
42 42
43void Mouse::UpdateYuzuSettings() { 43void Mouse::UpdateYuzuSettings() {
44 MouseStatus pad_status{}; 44 if (buttons == 0) {
45 if (buttons != 0) { 45 return;
46 pad_status.button = last_button;
47 mouse_queue.Push(pad_status);
48 } 46 }
47
48 mouse_queue.Push(MouseStatus{
49 .button = last_button,
50 });
49} 51}
50 52
51void Mouse::PressButton(int x, int y, int button_) { 53void Mouse::PressButton(int x, int y, int button_) {
52 if (button_ >= static_cast<int>(mouse_info.size())) { 54 const auto button_index = static_cast<std::size_t>(button_);
55 if (button_index >= mouse_info.size()) {
53 return; 56 return;
54 } 57 }
55 58
56 int button = 1 << button_; 59 const auto button = 1U << button_index;
57 const auto button_index = static_cast<std::size_t>(button_);
58 buttons |= static_cast<u16>(button); 60 buttons |= static_cast<u16>(button);
59 last_button = static_cast<MouseButton>(button_); 61 last_button = static_cast<MouseButton>(button_index);
60 62
61 mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); 63 mouse_info[button_index].mouse_origin = Common::MakeVec(x, y);
62 mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); 64 mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y);
@@ -66,8 +68,8 @@ void Mouse::PressButton(int x, int y, int button_) {
66void Mouse::MouseMove(int x, int y) { 68void Mouse::MouseMove(int x, int y) {
67 for (MouseInfo& info : mouse_info) { 69 for (MouseInfo& info : mouse_info) {
68 if (info.data.pressed) { 70 if (info.data.pressed) {
69 auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; 71 const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin;
70 auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; 72 const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position;
71 info.last_mouse_position = Common::MakeVec(x, y); 73 info.last_mouse_position = Common::MakeVec(x, y);
72 info.data.axis = {mouse_move.x, -mouse_move.y}; 74 info.data.axis = {mouse_move.x, -mouse_move.y};
73 75
@@ -82,12 +84,12 @@ void Mouse::MouseMove(int x, int y) {
82} 84}
83 85
84void Mouse::ReleaseButton(int button_) { 86void Mouse::ReleaseButton(int button_) {
85 if (button_ >= static_cast<int>(mouse_info.size())) { 87 const auto button_index = static_cast<std::size_t>(button_);
88 if (button_index >= mouse_info.size()) {
86 return; 89 return;
87 } 90 }
88 91
89 int button = 1 << button_; 92 const auto button = 1U << button_index;
90 const auto button_index = static_cast<std::size_t>(button_);
91 buttons &= static_cast<u16>(0xFF - button); 93 buttons &= static_cast<u16>(0xFF - button);
92 94
93 mouse_info[button_index].tilt_speed = 0; 95 mouse_info[button_index].tilt_speed = 0;