From 7ebc4229455521bd1e978c8de2913a9a7763b66f Mon Sep 17 00:00:00 2001 From: Saracen Date: Sun, 22 May 2016 23:54:56 +0100 Subject: [PATCH 1/4] Expose string 'erase' method to script --- core/variant_call.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/variant_call.cpp b/core/variant_call.cpp index 4be763a5112..e9551bb94c9 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -262,7 +262,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM0R(String,basename); VCALL_LOCALMEM1R(String,plus_file); VCALL_LOCALMEM1R(String,ord_at); - //VCALL_LOCALMEM2R(String,erase); + VCALL_LOCALMEM2(String,erase); VCALL_LOCALMEM0R(String,hash); VCALL_LOCALMEM0R(String,md5_text); VCALL_LOCALMEM0R(String,md5_buffer); @@ -1282,7 +1282,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC0(STRING,STRING,String,basename,varray()); ADDFUNC1(STRING,STRING,String,plus_file,STRING,"file",varray()); ADDFUNC1(STRING,STRING,String,ord_at,INT,"at",varray()); -// ADDFUNC2(STRING,String,erase,INT,INT,varray()); + ADDFUNC2(STRING,NIL,String,erase,INT,"pos",INT,"chars", varray()); ADDFUNC0(STRING,INT,String,hash,varray()); ADDFUNC0(STRING,STRING,String,md5_text,varray()); ADDFUNC0(STRING,RAW_ARRAY,String,md5_buffer,varray()); From 445909c1e106a3fd02da313d258d9078632cb745 Mon Sep 17 00:00:00 2001 From: Saracen Date: Sun, 29 May 2016 18:58:31 +0100 Subject: [PATCH 2/4] Exposed remaining PROPERTY_USAGE constants to script --- core/global_constants.cpp | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/core/global_constants.cpp b/core/global_constants.cpp index 3cf4ff8f833..63764383ff7 100644 --- a/core/global_constants.cpp +++ b/core/global_constants.cpp @@ -478,7 +478,21 @@ static _GlobalConstant _global_constants[]={ BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORAGE ), BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_EDITOR ), BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_NETWORK ), + + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_EDITOR_HELPER ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CHECKABLE ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CHECKED ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_INTERNATIONALIZED ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_BUNDLE ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_CATEGORY ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORE_IF_NONZERO ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_STORE_IF_NONONE ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_NO_INSTANCE_STATE ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_RESTART_IF_CHANGED ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_DEFAULT ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_DEFAULT_INTL ), + BIND_GLOBAL_CONSTANT( PROPERTY_USAGE_NOEDITOR ), BIND_GLOBAL_CONSTANT( METHOD_FLAG_NORMAL ), BIND_GLOBAL_CONSTANT( METHOD_FLAG_EDITOR ), From 4bcc60008d7ce346b282652a347b3e1f6184e5f9 Mon Sep 17 00:00:00 2001 From: Saracen Date: Mon, 30 May 2016 02:57:48 +0100 Subject: [PATCH 3/4] Expose Vector2 abs method to scripts --- core/variant_call.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/core/variant_call.cpp b/core/variant_call.cpp index e9551bb94c9..986494b67fe 100644 --- a/core/variant_call.cpp +++ b/core/variant_call.cpp @@ -339,6 +339,7 @@ static void _call_##m_type##_##m_method(Variant& r_ret,Variant& p_self,const Var VCALL_LOCALMEM1R(Vector2,reflect); VCALL_LOCALMEM0R(Vector2,angle); // VCALL_LOCALMEM1R(Vector2,cross); + VCALL_LOCALMEM0R(Vector2,abs); VCALL_LOCALMEM0R(Rect2,get_area); VCALL_LOCALMEM1R(Rect2,intersects); @@ -1333,6 +1334,7 @@ _VariantCall::addfunc(Variant::m_vtype,Variant::m_ret,_SCS(#m_method),VCALL(m_cl ADDFUNC1(VECTOR2,VECTOR2,Vector2,slide,VECTOR2,"vec",varray()); ADDFUNC1(VECTOR2,VECTOR2,Vector2,reflect,VECTOR2,"vec",varray()); //ADDFUNC1(VECTOR2,REAL,Vector2,cross,VECTOR2,"with",varray()); + ADDFUNC0(VECTOR2,VECTOR2,Vector2,abs,varray()); ADDFUNC0(RECT2,REAL,Rect2,get_area,varray()); ADDFUNC1(RECT2,BOOL,Rect2,intersects,RECT2,"b",varray()); From b160a26abd50eb34e8ba982f2c1fd95fdd6d102e Mon Sep 17 00:00:00 2001 From: Saracen Date: Wed, 1 Jun 2016 15:41:25 +0100 Subject: [PATCH 4/4] Expose control theme element and override detection methods to scripting side. --- scene/gui/control.cpp | 116 +++++++++++++++++++++++++++++++----------- scene/gui/control.h | 7 +++ 2 files changed, 94 insertions(+), 29 deletions(-) diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 0522b2efede..03b857f2662 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -770,7 +770,7 @@ Size2 Control::get_minimum_size() const { Ref Control::get_icon(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Ref* tex = data.icon_override.getptr(p_name); if (tex) @@ -800,7 +800,7 @@ Ref Control::get_icon(const StringName& p_name,const StringName& p_type } Ref Control::get_shader(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Ref* sdr = data.shader_override.getptr(p_name); if (sdr) @@ -830,7 +830,7 @@ Ref Control::get_shader(const StringName& p_name,const StringName& p_typ Ref Control::get_stylebox(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Ref* style = data.style_override.getptr(p_name); if (style) return *style; @@ -858,7 +858,7 @@ Ref Control::get_stylebox(const StringName& p_name,const StringName& p } Ref Control::get_font(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Ref* font = data.font_override.getptr(p_name); if (font) return *font; @@ -889,7 +889,7 @@ Ref Control::get_font(const StringName& p_name,const StringName& p_type) c } Color Control::get_color(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const Color* color = data.color_override.getptr(p_name); if (color) return *color; @@ -918,7 +918,7 @@ Color Control::get_color(const StringName& p_name,const StringName& p_type) cons int Control::get_constant(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { + if (p_type==StringName() || p_type=="") { const int* constant = data.constant_override.getptr(p_name); if (constant) return *constant; @@ -946,12 +946,64 @@ int Control::get_constant(const StringName& p_name,const StringName& p_type) con } +bool Control::has_icon_override(const StringName& p_name) const { + + const Ref* tex = data.icon_override.getptr(p_name); + if (tex) + return true; + else + return false; +} + +bool Control::has_shader_override(const StringName &p_name) const { + + const Ref* sdr = data.shader_override.getptr(p_name); + if (sdr) + return true; + else + return false; +} + +bool Control::has_stylebox_override(const StringName& p_name) const { + + const Ref* style = data.style_override.getptr(p_name); + if (style) + return true; + else + return false; +} + +bool Control::has_font_override(const StringName& p_name) const { + + const Ref* font = data.font_override.getptr(p_name); + if (font) + return true; + else + return false; +} + +bool Control::has_color_override(const StringName& p_name) const { + + const Color* color = data.color_override.getptr(p_name); + if (color) + return true; + else + return false; +} + +bool Control::has_constant_override(const StringName& p_name) const { + + const int* constant = data.constant_override.getptr(p_name); + if (constant) + return true; + else + return false; +} bool Control::has_icon(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - const Ref* tex = data.icon_override.getptr(p_name); - if (tex) + if (p_type==StringName() || p_type=="") { + if (has_icon_override(p_name) == true) return true; } @@ -977,11 +1029,10 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const } -bool Control::has_shader(const StringName &p_name, const StringName &p_type) const -{ - if (p_type==StringName()) { - const Ref* sdr = data.shader_override.getptr(p_name); - if (sdr) +bool Control::has_shader(const StringName &p_name, const StringName &p_type) const { + + if (p_type==StringName() || p_type=="") { + if (has_shader_override(p_name)==true) return true; } @@ -1008,10 +1059,8 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_type) con } bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - const Ref* style = data.style_override.getptr(p_name); - - if (style) + if (p_type==StringName() || p_type=="") { + if (has_stylebox_override(p_name)==true) return true; } @@ -1038,9 +1087,8 @@ bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) co } bool Control::has_font(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - const Ref* font = data.font_override.getptr(p_name); - if (font) + if (p_type==StringName() || p_type=="") { + if (has_font_override(p_name)==true) return true; } @@ -1066,11 +1114,11 @@ bool Control::has_font(const StringName& p_name,const StringName& p_type) const return Theme::get_default()->has_font( p_name, type ); } -bool Control::has_color(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - const Color* color = data.color_override.getptr(p_name); - if (color) +bool Control::has_color(const StringName& p_name, const StringName& p_type) const { + + if (p_type==StringName() || p_type=="") { + if (has_color_override(p_name)==true) return true; } @@ -1098,10 +1146,8 @@ bool Control::has_color(const StringName& p_name,const StringName& p_type) const bool Control::has_constant(const StringName& p_name,const StringName& p_type) const { - if (p_type==StringName()) { - - const int* constant = data.constant_override.getptr(p_name); - if (constant) + if (p_type==StringName() || p_type=="") { + if (has_constant_override(p_name) == true) return true; } @@ -2296,6 +2342,17 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_color","name","type"),&Control::get_color,DEFVAL("")); ObjectTypeDB::bind_method(_MD("get_constant","name","type"),&Control::get_constant,DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_icon_override", "name"), &Control::has_icon_override); + ObjectTypeDB::bind_method(_MD("has_stylebox_override", "name"), &Control::has_stylebox_override); + ObjectTypeDB::bind_method(_MD("has_font_override", "name"), &Control::has_font_override); + ObjectTypeDB::bind_method(_MD("has_color_override", "name"), &Control::has_color_override); + ObjectTypeDB::bind_method(_MD("has_constant_override", "name"), &Control::has_constant_override); + + ObjectTypeDB::bind_method(_MD("has_icon", "name", "type"), &Control::has_icon, DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_stylebox", "name", "type"), &Control::has_stylebox, DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_font", "name", "type"), &Control::has_font, DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_color", "name", "type"), &Control::has_color, DEFVAL("")); + ObjectTypeDB::bind_method(_MD("has_constant", "name", "type"), &Control::has_constant, DEFVAL("")); ObjectTypeDB::bind_method(_MD("get_parent_control:Control"),&Control::get_parent_control); @@ -2325,6 +2382,7 @@ void Control::_bind_methods() { ObjectTypeDB::bind_method(_MD("warp_mouse","to_pos"),&Control::warp_mouse); + ObjectTypeDB::bind_method(_MD("minimum_size_changed"), &Control::minimum_size_changed); BIND_VMETHOD(MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"event"))); BIND_VMETHOD(MethodInfo(Variant::VECTOR2,"get_minimum_size")); diff --git a/scene/gui/control.h b/scene/gui/control.h index f720185c9d1..76e4f43d787 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -341,6 +341,13 @@ public: Color get_color(const StringName& p_name,const StringName& p_type=StringName()) const; int get_constant(const StringName& p_name,const StringName& p_type=StringName()) const; + bool has_icon_override(const StringName& p_name) const; + bool has_shader_override(const StringName& p_name) const; + bool has_stylebox_override(const StringName& p_name) const; + bool has_font_override(const StringName& p_name) const; + bool has_color_override(const StringName& p_name) const; + bool has_constant_override(const StringName& p_name) const; + bool has_icon(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_shader(const StringName& p_name,const StringName& p_type=StringName()) const; bool has_stylebox(const StringName& p_name,const StringName& p_type=StringName()) const;