summaryrefslogtreecommitdiff
path: root/src/input_common/drivers/mouse.h
diff options
context:
space:
mode:
Diffstat (limited to 'src/input_common/drivers/mouse.h')
-rw-r--r--src/input_common/drivers/mouse.h77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/input_common/drivers/mouse.h b/src/input_common/drivers/mouse.h
new file mode 100644
index 000000000..e8355751a
--- /dev/null
+++ b/src/input_common/drivers/mouse.h
@@ -0,0 +1,77 @@
1// Copyright 2021 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 <stop_token>
8#include <thread>
9
10#include "common/vector_math.h"
11#include "input_common/input_engine.h"
12
13namespace InputCommon {
14
15enum class MouseButton {
16 Left,
17 Right,
18 Wheel,
19 Backward,
20 Forward,
21 Task,
22 Extra,
23 Undefined,
24};
25
26/**
27 * A button device factory representing a keyboard. It receives keyboard events and forward them
28 * to all button devices it created.
29 */
30class Mouse final : public InputCommon::InputEngine {
31public:
32 explicit Mouse(const std::string input_engine_);
33
34 /**
35 * Signals that mouse has moved.
36 * @param x the x-coordinate of the cursor
37 * @param y the y-coordinate of the cursor
38 * @param center_x the x-coordinate of the middle of the screen
39 * @param center_y the y-coordinate of the middle of the screen
40 */
41 void MouseMove(int x, int y, f32 touch_x, f32 touch_y, int center_x, int center_y);
42
43 /**
44 * Sets the status of all buttons bound with the key to pressed
45 * @param key_code the code of the key to press
46 */
47 void PressButton(int x, int y, f32 touch_x, f32 touch_y, MouseButton button);
48
49 /**
50 * Sets the status of all buttons bound with the key to released
51 * @param key_code the code of the key to release
52 */
53 void ReleaseButton(MouseButton button);
54
55 void ReleaseAllButtons();
56
57 std::vector<Common::ParamPackage> GetInputDevices() const override;
58 std::string GetUIName(const Common::ParamPackage& params) const override;
59
60private:
61 void UpdateThread(std::stop_token stop_token);
62 void StopPanning();
63
64 const PadIdentifier identifier = {
65 .guid = Common::UUID{""},
66 .port = 0,
67 .pad = 0,
68 };
69 Common::Vec2<int> mouse_origin;
70 Common::Vec2<int> last_mouse_position;
71 Common::Vec2<float> last_mouse_change;
72 bool button_pressed;
73 int mouse_panning_timout{};
74 std::jthread update_thread;
75};
76
77} // namespace InputCommon