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