diff options
Diffstat (limited to 'src/input_common/mouse/mouse_input.cpp')
| -rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 25 |
1 files changed, 14 insertions, 11 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index 055924087..b23a7f1cc 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp | |||
| @@ -21,8 +21,11 @@ void Mouse::UpdateThread() { | |||
| 21 | constexpr int update_time = 10; | 21 | constexpr int update_time = 10; |
| 22 | while (update_thread_running) { | 22 | while (update_thread_running) { |
| 23 | for (MouseInfo& info : mouse_info) { | 23 | for (MouseInfo& info : mouse_info) { |
| 24 | Common::Vec3f angular_direction = {-info.tilt_direction.y, 0.0f, | 24 | const Common::Vec3f angular_direction{ |
| 25 | -info.tilt_direction.x}; | 25 | -info.tilt_direction.y, |
| 26 | 0.0f, | ||
| 27 | -info.tilt_direction.x, | ||
| 28 | }; | ||
| 26 | 29 | ||
| 27 | info.motion.SetGyroscope(angular_direction * info.tilt_speed); | 30 | info.motion.SetGyroscope(angular_direction * info.tilt_speed); |
| 28 | info.motion.UpdateRotation(update_time * 1000); | 31 | info.motion.UpdateRotation(update_time * 1000); |
| @@ -46,14 +49,14 @@ void Mouse::UpdateYuzuSettings() { | |||
| 46 | } | 49 | } |
| 47 | 50 | ||
| 48 | void Mouse::PressButton(int x, int y, int button_) { | 51 | void Mouse::PressButton(int x, int y, int button_) { |
| 49 | if (button_ >= static_cast<int>(mouse_info.size())) { | 52 | const auto button_index = static_cast<std::size_t>(button_); |
| 53 | if (button_index >= mouse_info.size()) { | ||
| 50 | return; | 54 | return; |
| 51 | } | 55 | } |
| 52 | 56 | ||
| 53 | int button = 1 << button_; | 57 | const auto button = 1U << button_index; |
| 54 | const auto button_index = static_cast<std::size_t>(button_); | ||
| 55 | buttons |= static_cast<u16>(button); | 58 | buttons |= static_cast<u16>(button); |
| 56 | last_button = static_cast<MouseButton>(button_); | 59 | last_button = static_cast<MouseButton>(button_index); |
| 57 | 60 | ||
| 58 | mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); | 61 | mouse_info[button_index].mouse_origin = Common::MakeVec(x, y); |
| 59 | mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); | 62 | mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y); |
| @@ -63,8 +66,8 @@ void Mouse::PressButton(int x, int y, int button_) { | |||
| 63 | void Mouse::MouseMove(int x, int y) { | 66 | void Mouse::MouseMove(int x, int y) { |
| 64 | for (MouseInfo& info : mouse_info) { | 67 | for (MouseInfo& info : mouse_info) { |
| 65 | if (info.data.pressed) { | 68 | if (info.data.pressed) { |
| 66 | auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; | 69 | const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin; |
| 67 | auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; | 70 | const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position; |
| 68 | info.last_mouse_position = Common::MakeVec(x, y); | 71 | info.last_mouse_position = Common::MakeVec(x, y); |
| 69 | info.data.axis = {mouse_move.x, -mouse_move.y}; | 72 | info.data.axis = {mouse_move.x, -mouse_move.y}; |
| 70 | 73 | ||
| @@ -79,12 +82,12 @@ void Mouse::MouseMove(int x, int y) { | |||
| 79 | } | 82 | } |
| 80 | 83 | ||
| 81 | void Mouse::ReleaseButton(int button_) { | 84 | void Mouse::ReleaseButton(int button_) { |
| 82 | if (button_ >= static_cast<int>(mouse_info.size())) { | 85 | const auto button_index = static_cast<std::size_t>(button_); |
| 86 | if (button_index >= mouse_info.size()) { | ||
| 83 | return; | 87 | return; |
| 84 | } | 88 | } |
| 85 | 89 | ||
| 86 | int button = 1 << button_; | 90 | const auto button = 1U << button_index; |
| 87 | const auto button_index = static_cast<std::size_t>(button_); | ||
| 88 | buttons &= static_cast<u16>(0xFF - button); | 91 | buttons &= static_cast<u16>(0xFF - button); |
| 89 | 92 | ||
| 90 | mouse_info[button_index].tilt_speed = 0; | 93 | mouse_info[button_index].tilt_speed = 0; |