diff options
author | german77 <juangerman-13@hotmail.com> | 2021-03-06 13:27:02 -0600 |
---|---|---|
committer | german77 <juangerman-13@hotmail.com> | 2021-03-06 13:27:02 -0600 |
commit | 41e94b7b99f83a45633d555160b31b50f021c350 (patch) | |
tree | 3383b74713144712144eeb5cb6a247ba4be9da42 /src/input_common/mouse/mouse_input.cpp | |
parent | 4bcc5bacffb21e1f6c2859ba26faf865aaea8855 (diff) |
Enable mouse toggle buttons
Diffstat (limited to 'src/input_common/mouse/mouse_input.cpp')
-rw-r--r-- | src/input_common/mouse/mouse_input.cpp | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/src/input_common/mouse/mouse_input.cpp b/src/input_common/mouse/mouse_input.cpp index b864d26f26..6818d5eee1 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; } |