diff options
| author | bunnei <bunneidev@gmail.com> | 2021-03-11 11:00:44 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-03-11 11:00:44 -0800 |
| commit | d0933e20e079ebef2226eb5343007532f65688c8 (patch) | |
| tree | 99955e9f688581d6850c2b6c968d1ccff9fc9672 /src/input_common/mouse/mouse_input.cpp | |
| parent | 1f0cb72f406ba2865991ca9c6791226cf36c46af (diff) | |
| parent | 9c42c9e1644f0340a919952cea7c36e8b8e39b58 (diff) | |
Merge pull request #6040 from german77/toggleKeyboard
Enable toggle buttons for keyboard and mouse
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 d81e790eef..329e416c7e 100644 --- a/src/input_common/mouse/mouse_input.cpp +++ b/src/input_common/mouse/mouse_input.cpp @@ -162,6 +162,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; } |
