summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-01-11 18:29:59 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-01-11 18:29:59 -0300
commitf698e2be4f52415b329d9cfeac59b7582abbe3bd (patch)
tree3232aebb55303240cab69a84a96fc1469d6c85cd
parenta29f942c6b08fe6e20fb8cd9b160096cf57c8ef3 (diff)
Proper inheritance checking when requesting theem resources
-rw-r--r--core/object_type_db.cpp14
-rw-r--r--core/object_type_db.h1
-rw-r--r--scene/gui/control.cpp137
3 files changed, 127 insertions, 25 deletions
diff --git a/core/object_type_db.cpp b/core/object_type_db.cpp
index 7432c09563..f3bb37421f 100644
--- a/core/object_type_db.cpp
+++ b/core/object_type_db.cpp
@@ -258,12 +258,23 @@ void ClassDB::get_inheriters_from_class( const StringName& p_class,List<StringNa
}
+StringName ClassDB::get_parent_class_nocheck(const StringName& p_class) {
+
+ OBJTYPE_RLOCK;
+
+ ClassInfo *ti = classes.getptr(p_class);
+ if (!ti)
+ return StringName();
+ return ti->inherits;
+
+}
+
StringName ClassDB::get_parent_class(const StringName& p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
- ERR_FAIL_COND_V(!ti,"");
+ ERR_FAIL_COND_V(!ti,StringName());
return ti->inherits;
}
@@ -272,6 +283,7 @@ ClassDB::APIType ClassDB::get_api_type(const StringName &p_class) {
OBJTYPE_RLOCK;
ClassInfo *ti = classes.getptr(p_class);
+
ERR_FAIL_COND_V(!ti,API_NONE);
return ti->api;
}
diff --git a/core/object_type_db.h b/core/object_type_db.h
index 158a4dae23..f745e3d5fd 100644
--- a/core/object_type_db.h
+++ b/core/object_type_db.h
@@ -239,6 +239,7 @@ public:
static void get_class_list( List<StringName> *p_classes);
static void get_inheriters_from_class( const StringName& p_class,List<StringName> *p_classes);
+ static StringName get_parent_class_nocheck(const StringName& p_class);
static StringName get_parent_class(const StringName& p_class);
static bool class_exists(const StringName &p_class);
static bool is_parent_class(const StringName &p_class,const StringName& p_inherits);
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index b3d86f85ea..437fbba0e9 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -754,8 +754,16 @@ Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type
while(theme_owner) {
- if (theme_owner->data.theme->has_icon(p_name, type ) )
- return theme_owner->data.theme->get_icon(p_name, type );
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_icon(p_name, class_name ) ) {
+ return theme_owner->data.theme->get_icon(p_name, class_name );
+ }
+
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -784,8 +792,16 @@ Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_typ
while(theme_owner) {
- if (theme_owner->data.theme->has_shader(p_name, type))
- return theme_owner->data.theme->get_shader(p_name, type );
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_shader(p_name, class_name ) ) {
+ return theme_owner->data.theme->get_shader(p_name, class_name );
+ }
+
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -813,9 +829,16 @@ Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p
while(theme_owner) {
- if (theme_owner->data.theme->has_stylebox(p_name, type ) ) {
- return theme_owner->data.theme->get_stylebox(p_name, type );
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_stylebox(p_name, class_name ) ) {
+ return theme_owner->data.theme->get_stylebox(p_name, class_name );
+ }
+
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
}
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -842,8 +865,16 @@ Ref<Font> Control::get_font(const StringName& p_name,const StringName& p_type) c
while(theme_owner) {
- if (theme_owner->data.theme->has_font(p_name, type ) )
- return theme_owner->data.theme->get_font(p_name, type );
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_font(p_name, class_name ) ) {
+ return theme_owner->data.theme->get_font(p_name, class_name );
+ }
+
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
if (theme_owner->data.theme->get_default_theme_font().is_valid())
return theme_owner->data.theme->get_default_theme_font();
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
@@ -872,8 +903,16 @@ Color Control::get_color(const StringName& p_name,const StringName& p_type) cons
while(theme_owner) {
- if (theme_owner->data.theme->has_color(p_name, type ) )
- return theme_owner->data.theme->get_color(p_name, type );
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_color(p_name, class_name ) ) {
+ return theme_owner->data.theme->get_color(p_name, class_name );
+ }
+
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -901,8 +940,16 @@ int Control::get_constant(const StringName& p_name,const StringName& p_type) con
while(theme_owner) {
- if (theme_owner->data.theme->has_constant(p_name, type ) )
- return theme_owner->data.theme->get_constant(p_name, type );
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_constant(p_name, class_name ) ) {
+ return theme_owner->data.theme->get_constant(p_name, class_name );
+ }
+
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -985,8 +1032,15 @@ bool Control::has_icon(const StringName& p_name,const StringName& p_type) const
while(theme_owner) {
- if (theme_owner->data.theme->has_icon(p_name, type ) )
- return true;
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_icon(p_name, class_name ) ) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -1014,8 +1068,15 @@ bool Control::has_shader(const StringName &p_name, const StringName &p_type) con
while(theme_owner) {
- if (theme_owner->data.theme->has_shader(p_name, type))
- return true;
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_shader(p_name, class_name ) ) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -1042,8 +1103,15 @@ bool Control::has_stylebox(const StringName& p_name,const StringName& p_type) co
while(theme_owner) {
- if (theme_owner->data.theme->has_stylebox(p_name, type ) )
- return true;
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_stylebox(p_name, class_name ) ) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -1071,8 +1139,15 @@ bool Control::has_font(const StringName& p_name,const StringName& p_type) const
while(theme_owner) {
- if (theme_owner->data.theme->has_font(p_name, type ) )
- return true;
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_font(p_name, class_name ) ) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -1100,8 +1175,15 @@ bool Control::has_color(const StringName& p_name, const StringName& p_type) cons
while(theme_owner) {
- if (theme_owner->data.theme->has_color(p_name, type ) )
- return true;
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_color(p_name, class_name ) ) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)
@@ -1130,8 +1212,15 @@ bool Control::has_constant(const StringName& p_name,const StringName& p_type) co
while(theme_owner) {
- if (theme_owner->data.theme->has_constant(p_name, type ) )
- return true;
+ StringName class_name = type;
+
+ while(class_name!=StringName()) {
+ if (theme_owner->data.theme->has_constant(p_name, class_name ) ) {
+ return true;
+ }
+ class_name = ClassDB::get_parent_class_nocheck(class_name);
+ }
+
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent)