diff options
| author | bunnei <bunneidev@gmail.com> | 2021-01-16 13:00:54 -0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-16 13:00:54 -0800 |
| commit | f4e62240cd8b4f836fae3f9adb534dd1e994ce12 (patch) | |
| tree | bef1999d57e5106a379fc9ac19acb01d84913085 /src | |
| parent | 74cee15619a992c7cf4371eb336be2cf9209b8cd (diff) | |
| parent | 989694f182326aa1426c77e3dd3bcb847c831612 (diff) | |
Merge pull request #5366 from Morph1984/button-press
input_interpreter: Add method to check for a button press state
Diffstat (limited to 'src')
| -rw-r--r-- | src/core/frontend/input_interpreter.cpp | 4 | ||||
| -rw-r--r-- | src/core/frontend/input_interpreter.h | 21 |
2 files changed, 25 insertions, 0 deletions
diff --git a/src/core/frontend/input_interpreter.cpp b/src/core/frontend/input_interpreter.cpp index 66ae506cd3..ec5fe660ed 100644 --- a/src/core/frontend/input_interpreter.cpp +++ b/src/core/frontend/input_interpreter.cpp @@ -25,6 +25,10 @@ void InputInterpreter::PollInput() { button_states[current_index] = button_state; } +bool InputInterpreter::IsButtonPressed(HIDButton button) const { + return (button_states[current_index] & (1U << static_cast<u8>(button))) != 0; +} + bool InputInterpreter::IsButtonPressedOnce(HIDButton button) const { const bool current_press = (button_states[current_index] & (1U << static_cast<u8>(button))) != 0; diff --git a/src/core/frontend/input_interpreter.h b/src/core/frontend/input_interpreter.h index fea9aebe67..36a92a6b67 100644 --- a/src/core/frontend/input_interpreter.h +++ b/src/core/frontend/input_interpreter.h @@ -67,6 +67,27 @@ public: void PollInput(); /** + * Checks whether the button is pressed. + * + * @param button The button to check. + * + * @returns True when the button is pressed. + */ + [[nodiscard]] bool IsButtonPressed(HIDButton button) const; + + /** + * Checks whether any of the buttons in the parameter list is pressed. + * + * @tparam HIDButton The buttons to check. + * + * @returns True when at least one of the buttons is pressed. + */ + template <HIDButton... T> + [[nodiscard]] bool IsAnyButtonPressed() { + return (IsButtonPressed(T) || ...); + } + + /** * The specified button is considered to be pressed once * if it is currently pressed and not pressed previously. * |
