From e6fb0cf970639d70d8207bf888eaf02681ac159a Mon Sep 17 00:00:00 2001 From: Jaguar Date: Tue, 23 Jun 2015 16:24:48 -0400 Subject: [PATCH] Added helper methods to InputEvent --- core/os/input_event.cpp | 10 ++++++++++ core/os/input_event.h | 2 ++ core/variant_call.cpp | 4 ++++ 3 files changed, 16 insertions(+) diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index fc230122815..2bd62927b03 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -173,6 +173,16 @@ bool InputEvent::is_action(const String& p_action) const { return InputMap::get_singleton()->event_is_action(*this,p_action); } +bool InputEvent::is_action_pressed(const String& p_action) const { + + return is_action(p_action) && is_pressed() && !is_echo(); +} + +bool InputEvent::is_action_released(const String& p_action) const { + + return is_action(p_action) && !is_pressed(); +} + uint32_t InputEventKey::get_scancode_with_modifiers() const { uint32_t sc=scancode; diff --git a/core/os/input_event.h b/core/os/input_event.h index 811d5504d5c..4bb122ebc1a 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -287,6 +287,8 @@ struct InputEvent { bool is_pressed() const; bool is_action(const String& p_action) const; + bool is_action_pressed(const String& p_action) const; + bool is_action_released(const String& p_action) const; bool is_echo() const; void set_as_action(const String& p_action, bool p_pressed); diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 7dd0eb8a0c5..4cca3420a10 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -715,6 +715,8 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_PTR0R( InputEvent, is_pressed ); VCALL_PTR1R( InputEvent, is_action ); + VCALL_PTR1R( InputEvent, is_action_pressed ); + VCALL_PTR1R( InputEvent, is_action_released ); VCALL_PTR0R( InputEvent, is_echo ); VCALL_PTR2( InputEvent, set_as_action ); @@ -1540,6 +1542,8 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(INPUT_EVENT,BOOL,InputEvent,is_pressed,varray()); ADDFUNC1(INPUT_EVENT,BOOL,InputEvent,is_action,STRING,"action",varray()); + ADDFUNC1(INPUT_EVENT,BOOL,InputEvent,is_action_pressed,STRING,"is_action_pressed",varray()); + ADDFUNC1(INPUT_EVENT,BOOL,InputEvent,is_action_released,STRING,"is_action_released",varray()); ADDFUNC0(INPUT_EVENT,BOOL,InputEvent,is_echo,varray()); ADDFUNC2(INPUT_EVENT,NIL,InputEvent,set_as_action,STRING,"action",BOOL,"pressed",varray());