From e46f0e084c73420f8c76c514079952ca0acf1ebe Mon Sep 17 00:00:00 2001 From: german Date: Tue, 17 Nov 2020 22:55:09 -0600 Subject: Implement full mouse support --- src/input_common/mouse/mouse_input.h | 99 ++++++++++++++++++++++++++++++++++++ 1 file changed, 99 insertions(+) create mode 100644 src/input_common/mouse/mouse_input.h (limited to 'src/input_common/mouse/mouse_input.h') diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h new file mode 100644 index 000000000..761663334 --- /dev/null +++ b/src/input_common/mouse/mouse_input.h @@ -0,0 +1,99 @@ +// Copyright 2020 yuzu Emulator Project +// Licensed under GPLv2 or any later version +// Refer to the license.txt file included. + +#pragma once + +#include +#include +#include +#include +#include +#include "common/common_types.h" +#include "common/threadsafe_queue.h" +#include "core/frontend/input.h" +#include "input_common/main.h" +#include "input_common/motion_input.h" + +namespace MouseInput { + +enum class MouseButton { + Left, + Wheel, + Right, + Foward, + Backward, + Undefined, +}; + +struct MouseStatus { + MouseButton button{MouseButton::Undefined}; +}; + +struct MouseData { + bool pressed{}; + std::array axis{}; + Input::MotionStatus motion{}; + Input::TouchStatus touch{}; +}; + +class Mouse { +public: + Mouse(); + ~Mouse(); + + /// Used for polling + void BeginConfiguration(); + void EndConfiguration(); + + /** + * Signals that a button is pressed. + * @param x the x-coordinate of the cursor + * @param y the y-coordinate of the cursor + * @param button the button pressed + */ + void PressButton(int x, int y, int button_); + + /** + * Signals that mouse has moved. + * @param x the x-coordinate of the cursor + * @param y the y-coordinate of the cursor + */ + void MouseMove(int x, int y); + + /** + * Signals that a motion sensor tilt has ended. + */ + void ReleaseButton(int button_); + + [[nodiscard]] Common::SPSCQueue& GetMouseQueue(); + [[nodiscard]] const Common::SPSCQueue& GetMouseQueue() const; + + [[nodiscard]] MouseData& GetMouseState(std::size_t button); + [[nodiscard]] const MouseData& GetMouseState(std::size_t button) const; + +private: + void UpdateThread(); + void UpdateYuzuSettings(); + + struct MouseInfo { + InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f}; + Common::Vec2 mouse_origin; + Common::Vec2 last_mouse_position; + bool is_tilting = false; + float sensitivity{0.120f}; + + float tilt_speed = 0; + Common::Vec2 tilt_direction; + MouseData data; + }; + + u16 buttons{}; + std::thread update_thread; + MouseButton last_button{MouseButton::Undefined}; + std::array mouse_info; + Common::SPSCQueue mouse_queue; + bool configuring{false}; + bool update_thread_running{true}; +}; +} // namespace MouseInput -- cgit v1.2.3 From 774d7eab64108a8537c0d0db02744f8a11fa4618 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Dec 2020 10:25:10 -0500 Subject: mouse_input: Remove unused includes --- src/input_common/mouse/mouse_input.h | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/input_common/mouse/mouse_input.h') diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 761663334..6fc95a49e 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h @@ -4,15 +4,14 @@ #pragma once -#include -#include +#include #include #include -#include + #include "common/common_types.h" #include "common/threadsafe_queue.h" +#include "common/vector_math.h" #include "core/frontend/input.h" -#include "input_common/main.h" #include "input_common/motion_input.h" namespace MouseInput { -- cgit v1.2.3 From 5842a767a99c07317ff6ef7771e129306c347a4c Mon Sep 17 00:00:00 2001 From: Lioncash Date: Thu, 3 Dec 2020 10:26:50 -0500 Subject: mouse_input: Resolve a -Wdocumentation warning --- src/input_common/mouse/mouse_input.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input_common/mouse/mouse_input.h') diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 6fc95a49e..65e64bee7 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h @@ -49,7 +49,7 @@ public: * Signals that a button is pressed. * @param x the x-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_); -- cgit v1.2.3 From a745d87971b2c9795e1b2c587bfe30b849b522fa Mon Sep 17 00:00:00 2001 From: Morph <39850852+Morph1984@users.noreply.github.com> Date: Sat, 2 Jan 2021 09:00:05 -0500 Subject: general: Fix various spelling errors --- src/input_common/mouse/mouse_input.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/input_common/mouse/mouse_input.h') diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 65e64bee7..58803c1bf 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h @@ -20,7 +20,7 @@ enum class MouseButton { Left, Wheel, Right, - Foward, + Forward, Backward, Undefined, }; -- cgit v1.2.3