Merge pull request #5366 from Morph1984/button-press
input_interpreter: Add method to check for a button press state
This commit is contained in:
commit
ff2b7cc0d3
|
@ -25,6 +25,10 @@ void InputInterpreter::PollInput() {
|
||||||
button_states[current_index] = button_state;
|
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 {
|
bool InputInterpreter::IsButtonPressedOnce(HIDButton button) const {
|
||||||
const bool current_press =
|
const bool current_press =
|
||||||
(button_states[current_index] & (1U << static_cast<u8>(button))) != 0;
|
(button_states[current_index] & (1U << static_cast<u8>(button))) != 0;
|
||||||
|
|
|
@ -66,6 +66,27 @@ public:
|
||||||
/// Gets a button state from HID and inserts it into the array of button states.
|
/// Gets a button state from HID and inserts it into the array of button states.
|
||||||
void PollInput();
|
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
|
* The specified button is considered to be pressed once
|
||||||
* if it is currently pressed and not pressed previously.
|
* if it is currently pressed and not pressed previously.
|
||||||
|
|
Reference in New Issue