summaryrefslogtreecommitdiffstats
path: root/src/input_common/mouse
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/input_common/mouse/mouse_input.cpp95
-rw-r--r--src/input_common/mouse/mouse_input.h24
-rw-r--r--src/input_common/mouse/mouse_poller.cpp33
3 files changed, 136 insertions, 16 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp
index 10786a541..329e416c7 100644
--- a/src/input_common/mouse/mouse_input.cpp
+++ b/src/input_common/mouse/mouse_input.cpp
@@ -2,6 +2,7 @@
// Licensed under GPLv2+
// Refer to the license.txt file included.
+#include "core/settings.h"
#include "input_common/mouse/mouse_input.h"
namespace MouseInput {
@@ -32,10 +33,18 @@ void Mouse::UpdateThread() {
info.motion.UpdateOrientation(update_time * 1000);
info.tilt_speed = 0;
info.data.motion = info.motion.GetMotion();
+ if (Settings::values.mouse_panning) {
+ info.last_mouse_change *= 0.96f;
+ info.data.axis = {static_cast<int>(16 * info.last_mouse_change.x),
+ static_cast<int>(16 * -info.last_mouse_change.y)};
+ }
}
if (configuring) {
UpdateYuzuSettings();
}
+ if (mouse_panning_timout++ > 20) {
+ StopPanning();
+ }
std::this_thread::sleep_for(std::chrono::milliseconds(update_time));
}
}
@@ -50,7 +59,7 @@ void Mouse::UpdateYuzuSettings() {
});
}
-void Mouse::PressButton(int x, int y, int button_) {
+void Mouse::PressButton(int x, int y, MouseButton button_) {
const auto button_index = static_cast<std::size_t>(button_);
if (button_index >= mouse_info.size()) {
return;
@@ -58,15 +67,52 @@ void Mouse::PressButton(int x, int y, int button_) {
const auto button = 1U << button_index;
buttons |= static_cast<u16>(button);
- last_button = static_cast<MouseButton>(button_index);
+ last_button = button_;
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].data.pressed = true;
}
-void Mouse::MouseMove(int x, int y) {
+void Mouse::StopPanning() {
for (MouseInfo& info : mouse_info) {
+ if (Settings::values.mouse_panning) {
+ info.data.axis = {};
+ info.tilt_speed = 0;
+ info.last_mouse_change = {};
+ }
+ }
+}
+
+void Mouse::MouseMove(int x, int y, int center_x, int center_y) {
+ for (MouseInfo& info : mouse_info) {
+ if (Settings::values.mouse_panning) {
+ auto mouse_change =
+ (Common::MakeVec(x, y) - Common::MakeVec(center_x, center_y)).Cast<float>();
+ mouse_panning_timout = 0;
+
+ if (mouse_change.y == 0 && mouse_change.x == 0) {
+ continue;
+ }
+ const auto mouse_change_length = mouse_change.Length();
+ if (mouse_change_length < 3.0f) {
+ mouse_change /= mouse_change_length / 3.0f;
+ }
+
+ info.last_mouse_change = (info.last_mouse_change * 0.91f) + (mouse_change * 0.09f);
+
+ const auto last_mouse_change_length = info.last_mouse_change.Length();
+ if (last_mouse_change_length > 8.0f) {
+ info.last_mouse_change /= last_mouse_change_length / 8.0f;
+ } else if (last_mouse_change_length < 1.0f) {
+ info.last_mouse_change = mouse_change / mouse_change.Length();
+ }
+
+ info.tilt_direction = info.last_mouse_change;
+ info.tilt_speed = info.tilt_direction.Normalize() * info.sensitivity;
+ continue;
+ }
+
if (info.data.pressed) {
const auto mouse_move = Common::MakeVec(x, y) - info.mouse_origin;
const auto mouse_change = Common::MakeVec(x, y) - info.last_mouse_position;
@@ -83,7 +129,7 @@ void Mouse::MouseMove(int x, int y) {
}
}
-void Mouse::ReleaseButton(int button_) {
+void Mouse::ReleaseButton(MouseButton button_) {
const auto button_index = static_cast<std::size_t>(button_);
if (button_index >= mouse_info.size()) {
return;
@@ -106,11 +152,52 @@ void Mouse::BeginConfiguration() {
void Mouse::EndConfiguration() {
buttons = 0;
+ for (MouseInfo& info : mouse_info) {
+ info.tilt_speed = 0;
+ info.data.pressed = false;
+ info.data.axis = {0, 0};
+ }
last_button = MouseButton::Undefined;
mouse_queue.Clear();
configuring = false;
}
+bool Mouse::ToggleButton(std::size_t button_) {
+ if (button_ >= mouse_info.size()) {
+ return false;
+ }
+ const auto button = 1U << button_;
+ const bool button_state = (toggle_buttons & button) != 0;
+ const bool button_lock = (lock_buttons & button) != 0;
+
+ if (button_lock) {
+ return button_state;
+ }
+
+ lock_buttons |= static_cast<u16>(button);
+
+ if (button_state) {
+ toggle_buttons &= static_cast<u16>(0xFF - button);
+ } else {
+ toggle_buttons |= static_cast<u16>(button);
+ }
+
+ return !button_state;
+}
+
+bool Mouse::UnlockButton(std::size_t button_) {
+ if (button_ >= mouse_info.size()) {
+ return false;
+ }
+
+ const auto button = 1U << button_;
+ const bool button_state = (toggle_buttons & button) != 0;
+
+ lock_buttons &= static_cast<u16>(0xFF - button);
+
+ return button_state;
+}
+
Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() {
return mouse_queue;
}
diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h
index 58803c1bf..750d9b011 100644
--- a/src/input_common/mouse/mouse_input.h
+++ b/src/input_common/mouse/mouse_input.h
@@ -18,10 +18,12 @@ namespace MouseInput {
enum class MouseButton {
Left,
- Wheel,
Right,
- Forward,
+ Wheel,
Backward,
+ Forward,
+ Task,
+ Extra,
Undefined,
};
@@ -51,19 +53,24 @@ public:
* @param y the y-coordinate of the cursor
* @param button_ the button pressed
*/
- void PressButton(int x, int y, int button_);
+ void PressButton(int x, int y, MouseButton button_);
/**
* Signals that mouse has moved.
* @param x the x-coordinate of the cursor
* @param y the y-coordinate of the cursor
+ * @param center_x the x-coordinate of the middle of the screen
+ * @param center_y the y-coordinate of the middle of the screen
*/
- void MouseMove(int x, int y);
+ void MouseMove(int x, int y, int center_x, int center_y);
/**
* Signals that a motion sensor tilt has ended.
*/
- void ReleaseButton(int button_);
+ void ReleaseButton(MouseButton button_);
+
+ [[nodiscard]] bool ToggleButton(std::size_t button_);
+ [[nodiscard]] bool UnlockButton(std::size_t button_);
[[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue();
[[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const;
@@ -74,11 +81,13 @@ public:
private:
void UpdateThread();
void UpdateYuzuSettings();
+ void StopPanning();
struct MouseInfo {
InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f};
Common::Vec2<int> mouse_origin;
Common::Vec2<int> last_mouse_position;
+ Common::Vec2<float> last_mouse_change;
bool is_tilting = false;
float sensitivity{0.120f};
@@ -88,11 +97,14 @@ private:
};
u16 buttons{};
+ u16 toggle_buttons{};
+ u16 lock_buttons{};
std::thread update_thread;
MouseButton last_button{MouseButton::Undefined};
- std::array<MouseInfo, 5> mouse_info;
+ std::array<MouseInfo, 7> mouse_info;
Common::SPSCQueue<MouseStatus> mouse_queue;
bool configuring{false};
bool update_thread_running{true};
+ int mouse_panning_timout{};
};
} // namespace MouseInput
diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp
index 508eb0c7d..0e1db54fb 100644
--- a/src/input_common/mouse/mouse_poller.cpp
+++ b/src/input_common/mouse/mouse_poller.cpp
@@ -6,6 +6,7 @@
#include <utility>
#include "common/threadsafe_queue.h"
+#include "core/settings.h"
#include "input_common/mouse/mouse_input.h"
#include "input_common/mouse/mouse_poller.h"
@@ -13,16 +14,25 @@ namespace InputCommon {
class MouseButton final : public Input::ButtonDevice {
public:
- explicit MouseButton(u32 button_, const MouseInput::Mouse* mouse_input_)
- : button(button_), mouse_input(mouse_input_) {}
+ explicit MouseButton(u32 button_, bool toggle_, MouseInput::Mouse* mouse_input_)
+ : button(button_), toggle(toggle_), mouse_input(mouse_input_) {}
bool GetStatus() const override {
- return mouse_input->GetMouseState(button).pressed;
+ const bool button_state = mouse_input->GetMouseState(button).pressed;
+ if (!toggle) {
+ return button_state;
+ }
+
+ if (button_state) {
+ return mouse_input->ToggleButton(button);
+ }
+ return mouse_input->UnlockButton(button);
}
private:
const u32 button;
- const MouseInput::Mouse* mouse_input;
+ const bool toggle;
+ MouseInput::Mouse* mouse_input;
};
MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_input_)
@@ -31,8 +41,9 @@ MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_
std::unique_ptr<Input::ButtonDevice> MouseButtonFactory::Create(
const Common::ParamPackage& params) {
const auto button_id = params.Get("button", 0);
+ const auto toggle = params.Get("toggle", false);
- return std::make_unique<MouseButton>(button_id, mouse_input.get());
+ return std::make_unique<MouseButton>(button_id, toggle, mouse_input.get());
}
Common::ParamPackage MouseButtonFactory::GetNextInput() const {
@@ -71,7 +82,7 @@ public:
std::lock_guard lock{mutex};
const auto axis_value =
static_cast<float>(mouse_input->GetMouseState(button).axis.at(axis));
- return axis_value / (100.0f * range);
+ return axis_value * Settings::values.mouse_panning_sensitivity / (100.0f * range);
}
std::pair<float, float> GetAnalog(u32 analog_axis_x, u32 analog_axis_y) const {
@@ -106,6 +117,16 @@ public:
return {0.0f, 0.0f};
}
+ std::tuple<float, float> GetRawStatus() const override {
+ const float x = GetAxis(axis_x);
+ const float y = GetAxis(axis_y);
+ return {x, y};
+ }
+
+ Input::AnalogProperties GetAnalogProperties() const override {
+ return {deadzone, range, 0.5f};
+ }
+
private:
const u32 button;
const u32 axis_x;