summaryrefslogtreecommitdiffstats
path: root/src/input_common/mouse/mouse_input.h
diff options
context:
space:
mode:
authorbunnei <bunneidev@gmail.com>2020-11-30 07:59:50 +0100
committerGitHub <noreply@github.com>2020-11-30 07:59:50 +0100
commit7bc3e80399d62aabe4acbba094d0fff23a187186 (patch)
treeac12ca41f34fdda51992fedfeb55b169dedcfcaf /src/input_common/mouse/mouse_input.h
parentMerge pull request #5005 from ReinUsesLisp/div-ceil (diff)
parentImplement full mouse support (diff)
downloadyuzu-7bc3e80399d62aabe4acbba094d0fff23a187186.tar
yuzu-7bc3e80399d62aabe4acbba094d0fff23a187186.tar.gz
yuzu-7bc3e80399d62aabe4acbba094d0fff23a187186.tar.bz2
yuzu-7bc3e80399d62aabe4acbba094d0fff23a187186.tar.lz
yuzu-7bc3e80399d62aabe4acbba094d0fff23a187186.tar.xz
yuzu-7bc3e80399d62aabe4acbba094d0fff23a187186.tar.zst
yuzu-7bc3e80399d62aabe4acbba094d0fff23a187186.zip
Diffstat (limited to 'src/input_common/mouse/mouse_input.h')
-rw-r--r--src/input_common/mouse/mouse_input.h99
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 @@
+// Copyright 2020 yuzu Emulator Project
+// Licensed under GPLv2 or any later version
+// Refer to the license.txt file included.
+
+#pragma once
+
+#include <algorithm>
+#include <functional>
+#include <mutex>
+#include <thread>
+#include <unordered_map>
+#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<int, 2> 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<MouseStatus>& GetMouseQueue();
+ [[nodiscard]] const Common::SPSCQueue<MouseStatus>& 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<int> mouse_origin;
+ Common::Vec2<int> last_mouse_position;
+ bool is_tilting = false;
+ float sensitivity{0.120f};
+
+ float tilt_speed = 0;
+ Common::Vec2<float> tilt_direction;
+ MouseData data;
+ };
+
+ u16 buttons{};
+ std::thread update_thread;
+ MouseButton last_button{MouseButton::Undefined};
+ std::array<MouseInfo, 5> mouse_info;
+ Common::SPSCQueue<MouseStatus> mouse_queue;
+ bool configuring{false};
+ bool update_thread_running{true};
+};
+} // namespace MouseInput