summaryrefslogtreecommitdiff
path: root/src/input_common/mouse/mouse_input.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/mouse/mouse_input.h')
-rw-r--r--src/input_common/mouse/mouse_input.h98
1 files changed, 98 insertions, 0 deletions
diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h
new file mode 100644
index 000000000..58803c1bf
--- /dev/null
+++ b/src/input_common/mouse/mouse_input.h
@@ -0,0 +1,98 @@
1// Copyright 2020 yuzu Emulator Project
2// Licensed under GPLv2 or any later version
3// Refer to the license.txt file included.
4
5#pragma once
6
7#include <array>
8#include <mutex>
9#include <thread>
10
11#include "common/common_types.h"
12#include "common/threadsafe_queue.h"
13#include "common/vector_math.h"
14#include "core/frontend/input.h"
15#include "input_common/motion_input.h"
16
17namespace MouseInput {
18
19enum class MouseButton {
20 Left,
21 Wheel,
22 Right,
23 Forward,
24 Backward,
25 Undefined,
26};
27
28struct MouseStatus {
29 MouseButton button{MouseButton::Undefined};
30};
31
32struct MouseData {
33 bool pressed{};
34 std::array<int, 2> axis{};
35 Input::MotionStatus motion{};
36 Input::TouchStatus touch{};
37};
38
39class Mouse {
40public:
41 Mouse();
42 ~Mouse();
43
44 /// Used for polling
45 void BeginConfiguration();
46 void EndConfiguration();
47
48 /**
49 * Signals that a button is pressed.
50 * @param x the x-coordinate of the cursor
51 * @param y the y-coordinate of the cursor
52 * @param button_ the button pressed
53 */
54 void PressButton(int x, int y, int button_);
55
56 /**
57 * Signals that mouse has moved.
58 * @param x the x-coordinate of the cursor
59 * @param y the y-coordinate of the cursor
60 */
61 void MouseMove(int x, int y);
62
63 /**
64 * Signals that a motion sensor tilt has ended.
65 */
66 void ReleaseButton(int button_);
67
68 [[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue();
69 [[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const;
70
71 [[nodiscard]] MouseData& GetMouseState(std::size_t button);
72 [[nodiscard]] const MouseData& GetMouseState(std::size_t button) const;
73
74private:
75 void UpdateThread();
76 void UpdateYuzuSettings();
77
78 struct MouseInfo {
79 InputCommon::MotionInput motion{0.0f, 0.0f, 0.0f};
80 Common::Vec2<int> mouse_origin;
81 Common::Vec2<int> last_mouse_position;
82 bool is_tilting = false;
83 float sensitivity{0.120f};
84
85 float tilt_speed = 0;
86 Common::Vec2<float> tilt_direction;
87 MouseData data;
88 };
89
90 u16 buttons{};
91 std::thread update_thread;
92 MouseButton last_button{MouseButton::Undefined};
93 std::array<MouseInfo, 5> mouse_info;
94 Common::SPSCQueue<MouseStatus> mouse_queue;
95 bool configuring{false};
96 bool update_thread_running{true};
97};
98} // namespace MouseInput