diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2018-09-14 18:06:11 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-09-14 18:06:11 +0200 |
commit | c9df3fbfdb03d9d9fd6ba4740dcbd800e39a3e04 (patch) | |
tree | 574ca52551caa8a453c3cf74fd36b8e68c568187 /core/os | |
parent | e099fea259d85a44f533821c5337cdb0f91c00cc (diff) | |
parent | bf16f89a302239ea1abc4dd767eda01f61cb9feb (diff) |
Merge pull request #21954 from isaacremnant/fix_inputs
Fix is_action_pressed for InputEventActions
Diffstat (limited to 'core/os')
-rw-r--r-- | core/os/input_event.cpp | 16 | ||||
-rw-r--r-- | core/os/input_event.h | 2 |
2 files changed, 18 insertions, 0 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index cc359ef2ac..5bbdd7efb2 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -962,6 +962,22 @@ bool InputEventAction::is_action(const StringName &p_action) const { return action == p_action; } +bool InputEventAction::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const { + + Ref<InputEventAction> act = p_event; + if (act.is_null()) + return false; + + bool match = action == act->action; + if (match) { + if (p_pressed != NULL) + *p_pressed = act->pressed; + if (p_strength != NULL) + *p_strength = (*p_pressed) ? 1.0f : 0.0f; + } + return match; +} + String InputEventAction::as_text() const { return "InputEventAction : action=" + action + ", pressed=(" + (pressed ? "true" : "false"); diff --git a/core/os/input_event.h b/core/os/input_event.h index cb61e61e7c..789d19c5b2 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -481,6 +481,8 @@ public: virtual bool is_action(const StringName &p_action) const; + virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float p_deadzone) const; + virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const { return true; } virtual String as_text() const; |