Browse Source

Merge pull request #4977 from SaracenOne/scripting_expose

Expose extra methods and constants to scripts
Juan Linietsky 9 years ago
parent
commit
736b65e566
4 changed files with 112 additions and 31 deletions
  1. 14 0
      core/global_constants.cpp
  2. 4 2
      core/variant_call.cpp
  3. 87 29
      scene/gui/control.cpp
  4. 7 0
      scene/gui/control.h

+ 14 - 0
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 ),

+ 4 - 2
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);
@@ -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);
@@ -1285,7 +1286,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());
@@ -1336,6 +1337,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());

+ 87 - 29
scene/gui/control.cpp

@@ -770,7 +770,7 @@ Size2 Control::get_minimum_size() const {
 
 Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type) const {
 
-	if (p_type==StringName()) {
+	if (p_type==StringName() || p_type=="") {
 
 		const Ref<Texture>* tex = data.icon_override.getptr(p_name);
 		if (tex)
@@ -800,7 +800,7 @@ Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type
 }
 
 Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_type) const {
-	if (p_type==StringName()) {
+	if (p_type==StringName() || p_type=="") {
 
 		const Ref<Shader>* sdr = data.shader_override.getptr(p_name);
 		if (sdr)
@@ -830,7 +830,7 @@ Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_typ
 
 Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p_type) const {
 
-	if (p_type==StringName()) {
+	if (p_type==StringName() || p_type=="") {
 		const Ref<StyleBox>* style = data.style_override.getptr(p_name);
 		if (style)
 			return *style;
@@ -858,7 +858,7 @@ Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p
 }
 Ref<Font> 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>* font = data.font_override.getptr(p_name);
 		if (font)
 			return *font;
@@ -889,7 +889,7 @@ Ref<Font> 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<Texture>* 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<Shader>* 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<StyleBox>* 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>* 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<Texture>* 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<Shader>* 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<StyleBox>* 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>* 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;
 	}
 
@@ -2297,6 +2343,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);
 
@@ -2326,6 +2383,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"));

+ 7 - 0
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;