mirror of
https://git.suyu.dev/suyu/suyu
synced 2024-11-01 04:47:53 +00:00
Merge pull request #5059 from lioncash/mouse
mouse_input/mouse_poller: Minor cleanup
This commit is contained in:
commit
843ef8f2ec
3 changed files with 28 additions and 29 deletions
|
@ -2,9 +2,6 @@
|
||||||
// Licensed under GPLv2+
|
// Licensed under GPLv2+
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include "common/logging/log.h"
|
|
||||||
#include "common/math_util.h"
|
|
||||||
#include "common/param_package.h"
|
|
||||||
#include "input_common/mouse/mouse_input.h"
|
#include "input_common/mouse/mouse_input.h"
|
||||||
|
|
||||||
namespace MouseInput {
|
namespace MouseInput {
|
||||||
|
@ -24,8 +21,11 @@ void Mouse::UpdateThread() {
|
||||||
constexpr int update_time = 10;
|
constexpr int update_time = 10;
|
||||||
while (update_thread_running) {
|
while (update_thread_running) {
|
||||||
for (MouseInfo& info : mouse_info) {
|
for (MouseInfo& info : mouse_info) {
|
||||||
Common::Vec3f angular_direction = {-info.tilt_direction.y, 0.0f,
|
const Common::Vec3f angular_direction{
|
||||||
-info.tilt_direction.x};
|
-info.tilt_direction.y,
|
||||||
|
0.0f,
|
||||||
|
-info.tilt_direction.x,
|
||||||
|
};
|
||||||
|
|
||||||
info.motion.SetGyroscope(angular_direction * info.tilt_speed);
|
info.motion.SetGyroscope(angular_direction * info.tilt_speed);
|
||||||
info.motion.UpdateRotation(update_time * 1000);
|
info.motion.UpdateRotation(update_time * 1000);
|
||||||
|
@ -41,22 +41,24 @@ void Mouse::UpdateThread() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse::UpdateYuzuSettings() {
|
void Mouse::UpdateYuzuSettings() {
|
||||||
MouseStatus pad_status{};
|
if (buttons == 0) {
|
||||||
if (buttons != 0) {
|
|
||||||
pad_status.button = last_button;
|
|
||||||
mouse_queue.Push(pad_status);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void Mouse::PressButton(int x, int y, int button_) {
|
|
||||||
if (button_ >= static_cast<int>(mouse_info.size())) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int button = 1 << button_;
|
mouse_queue.Push(MouseStatus{
|
||||||
|
.button = last_button,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mouse::PressButton(int x, int y, int button_) {
|
||||||
const auto button_index = static_cast<std::size_t>(button_);
|
const auto button_index = static_cast<std::size_t>(button_);
|
||||||
|
if (button_index >= mouse_info.size()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto button = 1U << button_index;
|
||||||
buttons |= static_cast<u16>(button);
|
buttons |= static_cast<u16>(button);
|
||||||
last_button = static_cast<MouseButton>(button_);
|
last_button = static_cast<MouseButton>(button_index);
|
||||||
|
|
||||||
mouse_info[button_index].mouse_origin = Common::MakeVec(x, y);
|
mouse_info[button_index].mouse_origin = Common::MakeVec(x, y);
|
||||||
mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y);
|
mouse_info[button_index].last_mouse_position = Common::MakeVec(x, y);
|
||||||
|
@ -66,8 +68,8 @@ void Mouse::PressButton(int x, int y, int button_) {
|
||||||
void Mouse::MouseMove(int x, int y) {
|
void Mouse::MouseMove(int x, int y) {
|
||||||
for (MouseInfo& info : mouse_info) {
|
for (MouseInfo& info : mouse_info) {
|
||||||
if (info.data.pressed) {
|
if (info.data.pressed) {
|
||||||
auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin;
|
const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin;
|
||||||
auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position;
|
const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position;
|
||||||
info.last_mouse_position = Common::MakeVec(x, y);
|
info.last_mouse_position = Common::MakeVec(x, y);
|
||||||
info.data.axis = {mouse_move.x, -mouse_move.y};
|
info.data.axis = {mouse_move.x, -mouse_move.y};
|
||||||
|
|
||||||
|
@ -82,12 +84,12 @@ void Mouse::MouseMove(int x, int y) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Mouse::ReleaseButton(int button_) {
|
void Mouse::ReleaseButton(int button_) {
|
||||||
if (button_ >= static_cast<int>(mouse_info.size())) {
|
const auto button_index = static_cast<std::size_t>(button_);
|
||||||
|
if (button_index >= mouse_info.size()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
int button = 1 << button_;
|
const auto button = 1U << button_index;
|
||||||
const auto button_index = static_cast<std::size_t>(button_);
|
|
||||||
buttons &= static_cast<u16>(0xFF - button);
|
buttons &= static_cast<u16>(0xFF - button);
|
||||||
|
|
||||||
mouse_info[button_index].tilt_speed = 0;
|
mouse_info[button_index].tilt_speed = 0;
|
||||||
|
|
|
@ -4,15 +4,14 @@
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <algorithm>
|
#include <array>
|
||||||
#include <functional>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <thread>
|
#include <thread>
|
||||||
#include <unordered_map>
|
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
#include "common/threadsafe_queue.h"
|
#include "common/threadsafe_queue.h"
|
||||||
|
#include "common/vector_math.h"
|
||||||
#include "core/frontend/input.h"
|
#include "core/frontend/input.h"
|
||||||
#include "input_common/main.h"
|
|
||||||
#include "input_common/motion_input.h"
|
#include "input_common/motion_input.h"
|
||||||
|
|
||||||
namespace MouseInput {
|
namespace MouseInput {
|
||||||
|
@ -50,7 +49,7 @@ public:
|
||||||
* Signals that a button is pressed.
|
* Signals that a button is pressed.
|
||||||
* @param x the x-coordinate of the cursor
|
* @param x the x-coordinate of the cursor
|
||||||
* @param y the y-coordinate of the cursor
|
* @param y the y-coordinate of the cursor
|
||||||
* @param button the button pressed
|
* @param button_ the button pressed
|
||||||
*/
|
*/
|
||||||
void PressButton(int x, int y, int button_);
|
void PressButton(int x, int y, int button_);
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,9 @@
|
||||||
// Licensed under GPLv2 or any later version
|
// Licensed under GPLv2 or any later version
|
||||||
// Refer to the license.txt file included.
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
#include <atomic>
|
|
||||||
#include <list>
|
|
||||||
#include <mutex>
|
#include <mutex>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include "common/assert.h"
|
|
||||||
#include "common/threadsafe_queue.h"
|
#include "common/threadsafe_queue.h"
|
||||||
#include "input_common/mouse/mouse_input.h"
|
#include "input_common/mouse/mouse_input.h"
|
||||||
#include "input_common/mouse/mouse_poller.h"
|
#include "input_common/mouse/mouse_poller.h"
|
||||||
|
|
Loading…
Reference in a new issue