Fixed ancient bug that prevented proper theme editing, closes #4924

(cherry picked from commit c1056a9bfb)
This commit is contained in:
Juan Linietsky 2016-06-12 15:31:38 -03:00 committed by Rémi Verschelde
parent c54744ce4d
commit 6525e0017c
2 changed files with 19 additions and 30 deletions

View File

@ -409,6 +409,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; } break;
case NOTIFICATION_EXIT_CANVAS: { case NOTIFICATION_EXIT_CANVAS: {
@ -440,26 +444,9 @@ void Control::_notification(int p_notification) {
data.parent=NULL; data.parent=NULL;
data.parent_canvas_item=NULL; data.parent_canvas_item=NULL;
if (data.theme_owner && data.theme.is_null()) {
} break; data.theme_owner=NULL;
//notification(NOTIFICATION_THEME_CHANGED);
case NOTIFICATION_PARENTED: {
Control * parent = get_parent()->cast_to<Control>();
//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);
} }
} break; } break;
@ -673,7 +660,7 @@ Ref<Texture> Control::get_icon(const StringName& p_name,const StringName& p_type
while(theme_owner) { while(theme_owner) {
if (theme_owner->data.theme->has_icon(p_name, type ) ) 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<Control>():NULL; Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent) if (parent)
@ -703,7 +690,7 @@ Ref<Shader> Control::get_shader(const StringName& p_name,const StringName& p_typ
while(theme_owner) { while(theme_owner) {
if (theme_owner->data.theme->has_shader(p_name, type)) 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<Control>():NULL; Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent) if (parent)
@ -731,8 +718,9 @@ Ref<StyleBox> Control::get_stylebox(const StringName& p_name,const StringName& p
while(theme_owner) { while(theme_owner) {
if (theme_owner->data.theme->has_stylebox(p_name, type ) ) if (theme_owner->data.theme->has_stylebox(p_name, type ) ) {
return data.theme_owner->data.theme->get_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<Control>():NULL; Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent) if (parent)
@ -760,7 +748,7 @@ Ref<Font> Control::get_font(const StringName& p_name,const StringName& p_type) c
while(theme_owner) { while(theme_owner) {
if (theme_owner->data.theme->has_font(p_name, type ) ) 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()) if (theme_owner->data.theme->get_default_theme_font().is_valid())
return theme_owner->data.theme->get_default_theme_font(); return theme_owner->data.theme->get_default_theme_font();
Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL; Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
@ -790,7 +778,7 @@ Color Control::get_color(const StringName& p_name,const StringName& p_type) cons
while(theme_owner) { while(theme_owner) {
if (theme_owner->data.theme->has_color(p_name, type ) ) 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<Control>():NULL; Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent) if (parent)
@ -819,7 +807,7 @@ int Control::get_constant(const StringName& p_name,const StringName& p_type) con
while(theme_owner) { while(theme_owner) {
if (theme_owner->data.theme->has_constant(p_name, type ) ) 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<Control>():NULL; Control *parent = theme_owner->get_parent()?theme_owner->get_parent()->cast_to<Control>():NULL;
if (parent) if (parent)

View File

@ -240,7 +240,7 @@ Ref<Texture> Theme::get_icon(const StringName& p_name,const StringName& p_type)
bool Theme::has_icon(const StringName& p_name,const StringName& p_type) const { 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<StyleBox> Theme::get_stylebox(const StringName& p_name,const StringName& p_t
return style_map[p_type][p_name]; return style_map[p_type][p_name];
} else { } else {
return default_style; return default_style;
} }
} }
bool Theme::has_stylebox(const StringName& p_name,const StringName& p_type) const { 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) { void Theme::clear_stylebox(const StringName& p_name,const StringName& p_type) {
@ -396,7 +397,7 @@ Ref<Font> 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 { 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) { void Theme::clear_font(const StringName& p_name,const StringName& p_type) {