From c1056a9bfb723d053c3bec9d9f8d84ecdc5e93f9 Mon Sep 17 00:00:00 2001 From: Juan Linietsky Date: Sun, 12 Jun 2016 15:31:38 -0300 Subject: [PATCH] Fixed ancient bug that prevented proper theme editing, closes #4924 --- scene/gui/control.cpp | 45 +++++++++++++++------------------------ scene/resources/theme.cpp | 7 +++--- 2 files changed, 21 insertions(+), 31 deletions(-) diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index bd56369746c..dfad7d1432e 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -223,7 +223,7 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const { String sname=p_name; - if (!sname.begins_with("custom")) + if (!sname.begins_with("custom")) { if (sname.begins_with("margin/")) { String dname = sname.get_slicec('/', 1); if (dname == "left") { @@ -248,6 +248,7 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const { } else { return false; } + } if (sname.begins_with("custom_icons/")) { String name = sname.get_slicec('/',1); @@ -489,6 +490,10 @@ void Control::_notification(int p_notification) { } + if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) { + data.theme_owner=data.parent->data.theme_owner; + notification(NOTIFICATION_THEME_CHANGED); + } } break; case NOTIFICATION_EXIT_CANVAS: { @@ -520,26 +525,9 @@ void Control::_notification(int p_notification) { data.parent=NULL; data.parent_canvas_item=NULL; - - } break; - - - case NOTIFICATION_PARENTED: { - - Control * parent = get_parent()->cast_to(); - - //make children reference them theme - - if (parent && data.theme.is_null() && parent->data.theme_owner) { - _propagate_theme_changed(parent->data.theme_owner); - } - - } break; - case NOTIFICATION_UNPARENTED: { - - //make children unreference the theme - if (data.theme.is_null() && data.theme_owner) { - _propagate_theme_changed(NULL); + if (data.theme_owner && data.theme.is_null()) { + data.theme_owner=NULL; + //notification(NOTIFICATION_THEME_CHANGED); } } break; @@ -785,7 +773,7 @@ Ref 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 data.theme_owner->data.theme->get_icon(p_name, type ); + return theme_owner->data.theme->get_icon(p_name, type ); Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to():NULL; if (parent) @@ -815,7 +803,7 @@ Ref 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 data.theme_owner->data.theme->get_shader(p_name, type ); + return theme_owner->data.theme->get_shader(p_name, type ); Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to():NULL; if (parent) @@ -843,8 +831,9 @@ Ref Control::get_stylebox(const StringName& p_name,const StringName& p while(theme_owner) { - if (theme_owner->data.theme->has_stylebox(p_name, type ) ) - return data.theme_owner->data.theme->get_stylebox(p_name, type ); + if (theme_owner->data.theme->has_stylebox(p_name, type ) ) { + return theme_owner->data.theme->get_stylebox(p_name, type ); + } Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to():NULL; if (parent) @@ -872,7 +861,7 @@ Ref 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 data.theme_owner->data.theme->get_font(p_name, type ); + return theme_owner->data.theme->get_font(p_name, type ); 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():NULL; @@ -902,7 +891,7 @@ 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 data.theme_owner->data.theme->get_color(p_name, type ); + return theme_owner->data.theme->get_color(p_name, type ); Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to():NULL; if (parent) @@ -931,7 +920,7 @@ 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 data.theme_owner->data.theme->get_constant(p_name, type ); + return theme_owner->data.theme->get_constant(p_name, type ); Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to():NULL; if (parent) diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 8d0aedbf93c..2f4d37053e9 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -240,7 +240,7 @@ Ref Theme::get_icon(const StringName& p_name,const StringName& p_type) bool Theme::has_icon(const StringName& p_name,const StringName& p_type) const { - return (icon_map.has(p_type) && icon_map[p_type].has(p_name)); + return (icon_map.has(p_type) && icon_map[p_type].has(p_name) && icon_map[p_type][p_name].is_valid()); } @@ -337,12 +337,13 @@ Ref Theme::get_stylebox(const StringName& p_name,const StringName& p_t return style_map[p_type][p_name]; } else { return default_style; + } } bool Theme::has_stylebox(const StringName& p_name,const StringName& p_type) const { - return (style_map.has(p_type) && style_map[p_type].has(p_name) ); + return (style_map.has(p_type) && style_map[p_type].has(p_name) && style_map[p_type][p_name].is_valid()); } void Theme::clear_stylebox(const StringName& p_name,const StringName& p_type) { @@ -402,7 +403,7 @@ Ref Theme::get_font(const StringName& p_name,const StringName& p_type) con bool Theme::has_font(const StringName& p_name,const StringName& p_type) const { - return (font_map.has(p_type) && font_map[p_type].has(p_name)); + return (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()); } void Theme::clear_font(const StringName& p_name,const StringName& p_type) {