diff options
author | german77 <juangerman-13@hotmail.com> | 2021-03-06 20:27:02 +0100 |
---|---|---|
committer | german77 <juangerman-13@hotmail.com> | 2021-03-06 20:27:02 +0100 |
commit | 41e94b7b99f83a45633d555160b31b50f021c350 (patch) | |
tree | 3383b74713144712144eeb5cb6a247ba4be9da42 /src/input_common/mouse | |
parent | Add toggle button option for normal buttons (diff) | |
download | yuzu-41e94b7b99f83a45633d555160b31b50f021c350.tar yuzu-41e94b7b99f83a45633d555160b31b50f021c350.tar.gz yuzu-41e94b7b99f83a45633d555160b31b50f021c350.tar.bz2 yuzu-41e94b7b99f83a45633d555160b31b50f021c350.tar.lz yuzu-41e94b7b99f83a45633d555160b31b50f021c350.tar.xz yuzu-41e94b7b99f83a45633d555160b31b50f021c350.tar.zst yuzu-41e94b7b99f83a45633d555160b31b50f021c350.zip |
Diffstat (limited to '')
-rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 36 | ||||
-rw-r--r-- | src/input_common/mouse/mouse_input.h | 5 | ||||
-rw-r--r-- | src/input_common/mouse/mouse_poller.cpp | 20 |
3 files changed, 56 insertions, 5 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index b864d26f2..6818d5eee 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp @@ -157,6 +157,42 @@ void Mouse::EndConfiguration() { configuring = false; } +bool Mouse::ToggleButton(std::size_t button_) { + if (button_ >= mouse_info.size()) { + return false; + } + const auto button = 1U << button_; + const bool button_state = (toggle_buttons & button) != 0; + const bool button_lock = (lock_buttons & button) != 0; + + if (button_lock) { + return button_state; + } + + lock_buttons |= static_cast<u16>(button); + + if (button_state) { + toggle_buttons &= static_cast<u16>(0xFF - button); + } else { + toggle_buttons |= static_cast<u16>(button); + } + + return !button_state; +} + +bool Mouse::UnlockButton(std::size_t button_) { + if (button_ >= mouse_info.size()) { + return false; + } + + const auto button = 1U << button_; + const bool button_state = (toggle_buttons & button) != 0; + + lock_buttons &= static_cast<u16>(0xFF - button); + + return button_state; +} + Common::SPSCQueue<MouseStatus>& Mouse::GetMouseQueue() { return mouse_queue; } diff --git a/src/input_common/mouse/mouse_input.h b/src/input_common/mouse/mouse_input.h index 46aa676c1..a75f0ecb5 100644 --- a/src/input_common/mouse/mouse_input.h +++ b/src/input_common/mouse/mouse_input.h @@ -67,6 +67,9 @@ public: */ void ReleaseButton(int button_); + [[nodiscard]] bool ToggleButton(std::size_t button_); + [[nodiscard]] bool UnlockButton(std::size_t button_); + [[nodiscard]] Common::SPSCQueue<MouseStatus>& GetMouseQueue(); [[nodiscard]] const Common::SPSCQueue<MouseStatus>& GetMouseQueue() const; @@ -92,6 +95,8 @@ private: }; u16 buttons{}; + u16 toggle_buttons{}; + u16 lock_buttons{}; std::thread update_thread; MouseButton last_button{MouseButton::Undefined}; std::array<MouseInfo, 5> mouse_info; diff --git a/src/input_common/mouse/mouse_poller.cpp b/src/input_common/mouse/mouse_poller.cpp index bb56787ee..0e1db54fb 100644 --- a/src/input_common/mouse/mouse_poller.cpp +++ b/src/input_common/mouse/mouse_poller.cpp @@ -14,16 +14,25 @@ namespace InputCommon { class MouseButton final : public Input::ButtonDevice { public: - explicit MouseButton(u32 button_, const MouseInput::Mouse* mouse_input_) - : button(button_), mouse_input(mouse_input_) {} + explicit MouseButton(u32 button_, bool toggle_, MouseInput::Mouse* mouse_input_) + : button(button_), toggle(toggle_), mouse_input(mouse_input_) {} bool GetStatus() const override { - return mouse_input->GetMouseState(button).pressed; + const bool button_state = mouse_input->GetMouseState(button).pressed; + if (!toggle) { + return button_state; + } + + if (button_state) { + return mouse_input->ToggleButton(button); + } + return mouse_input->UnlockButton(button); } private: const u32 button; - const MouseInput::Mouse* mouse_input; + const bool toggle; + MouseInput::Mouse* mouse_input; }; MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_input_) @@ -32,8 +41,9 @@ MouseButtonFactory::MouseButtonFactory(std::shared_ptr<MouseInput::Mouse> mouse_ std::unique_ptr<Input::ButtonDevice> MouseButtonFactory::Create( const Common::ParamPackage& params) { const auto button_id = params.Get("button", 0); + const auto toggle = params.Get("toggle", false); - return std::make_unique<MouseButton>(button_id, mouse_input.get()); + return std::make_unique<MouseButton>(button_id, toggle, mouse_input.get()); } Common::ParamPackage MouseButtonFactory::GetNextInput() const { |