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

This commit is contained in:
Juan Linietsky 2016-06-12 15:31:38 -03:00
parent 4bb93c976c
commit c1056a9bfb
2 changed files with 21 additions and 31 deletions

View file

@ -223,7 +223,7 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const {
String sname=p_name; String sname=p_name;
if (!sname.begins_with("custom")) if (!sname.begins_with("custom")) {
if (sname.begins_with("margin/")) { if (sname.begins_with("margin/")) {
String dname = sname.get_slicec('/', 1); String dname = sname.get_slicec('/', 1);
if (dname == "left") { if (dname == "left") {
@ -248,6 +248,7 @@ bool Control::_get(const StringName& p_name,Variant &r_ret) const {
} else { } else {
return false; return false;
} }
}
if (sname.begins_with("custom_icons/")) { if (sname.begins_with("custom_icons/")) {
String name = sname.get_slicec('/',1); 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; } break;
case NOTIFICATION_EXIT_CANVAS: { case NOTIFICATION_EXIT_CANVAS: {
@ -520,26 +525,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;
@ -785,7 +773,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)
@ -815,7 +803,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)
@ -843,8 +831,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)
@ -872,7 +861,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;
@ -902,7 +891,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)
@ -931,7 +920,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) {
@ -402,7 +403,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) {