diff options
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/control.cpp | 45 | ||||
-rw-r--r-- | scene/gui/item_list.cpp | 110 | ||||
-rw-r--r-- | scene/gui/item_list.h | 12 | ||||
-rw-r--r-- | scene/resources/packed_scene.cpp | 16 | ||||
-rw-r--r-- | scene/resources/theme.cpp | 7 |
5 files changed, 81 insertions, 109 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index bd56369746..dfad7d1432 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<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); + if (data.theme_owner && data.theme.is_null()) { + data.theme_owner=NULL; + //notification(NOTIFICATION_THEME_CHANGED); } } break; @@ -785,7 +773,7 @@ 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 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; if (parent) @@ -815,7 +803,7 @@ 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 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; if (parent) @@ -843,8 +831,9 @@ 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 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<Control>():NULL; if (parent) @@ -872,7 +861,7 @@ 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 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<Control>():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<Control>():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<Control>():NULL; if (parent) diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index fc4ab5f8ca..66e8fe10ff 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -384,27 +384,16 @@ ItemList::IconMode ItemList::get_icon_mode() const{ return icon_mode; } -void ItemList::set_min_icon_size(const Size2& p_size) { - min_icon_size=p_size; - update(); -} - -Size2 ItemList::get_min_icon_size() const { - - return min_icon_size; -} +void ItemList::set_fixed_icon_size(const Size2& p_size) { - -void ItemList::set_max_icon_size(const Size2& p_size) { - - max_icon_size=p_size; + fixed_icon_size=p_size; update(); } -Size2 ItemList::get_max_icon_size() const { +Size2 ItemList::get_fixed_icon_size() const { - return max_icon_size; + return fixed_icon_size; } Size2 ItemList::Item::get_icon_size() const { @@ -732,51 +721,21 @@ void ItemList::ensure_current_is_visible() { update(); } -static Size2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) { - - if (p_max_size.x<=0) - p_max_size.x=1e20; - if (p_max_size.y<=0) - p_max_size.y=1e20; - +static Rect2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) { - Size2 new_size; + Size2 size=p_max_size; + int tex_width = p_size.width * size.height / p_size.height; + int tex_height = size.height; - if (p_size.x > p_max_size.x) { - - new_size.width=p_max_size.x; - new_size.height=p_size.height * p_max_size.width / p_size.width; - - if (new_size.height > p_max_size.height) { - new_size=Size2(); //invalid - } + if (tex_width>size.width) { + tex_width=size.width; + tex_height=p_size.height * tex_width / p_size.width; } + int ofs_x=(size.width - tex_width)/2; + int ofs_y=(size.height - tex_height)/2; - if (p_size.y > p_max_size.y) { - - Size2 new_size2; - new_size2.height=p_max_size.y; - new_size2.width=p_size.width * p_max_size.height / p_size.height; - - if (new_size2.width < p_max_size.width) { - - if (new_size!=Size2()) { - - if (new_size2.x*new_size2.y > new_size.x*new_size.y) { - new_size=new_size2; - } - } else { - new_size=new_size2; - } - } - - } - - if (new_size==Size2()) - return p_size; - else - return new_size; + return Rect2(ofs_x,ofs_y,tex_width,tex_height); } @@ -845,7 +804,11 @@ void ItemList::_notification(int p_what) { Size2 minsize; if (items[i].icon.is_valid()) { - minsize=_adjust_to_max_size(items[i].get_icon_size(),max_icon_size) * icon_scale; + if (fixed_icon_size.x>0 && fixed_icon_size.y>0) { + minsize=fixed_icon_size* icon_scale; + } else { + minsize=items[i].get_icon_size() *icon_scale; + } if (items[i].text!="") { if (icon_mode==ICON_MODE_TOP) { @@ -1001,13 +964,18 @@ void ItemList::_notification(int p_what) { Vector2 text_ofs; if (items[i].icon.is_valid()) { - Size2 icon_size = _adjust_to_max_size(items[i].get_icon_size(),max_icon_size) * icon_scale; + Size2 icon_size; + //= _adjust_to_max_size(items[i].get_icon_size(),fixed_icon_size) * icon_scale; + + if (fixed_icon_size.x>0 && fixed_icon_size.y>0) { + icon_size=fixed_icon_size* icon_scale; + } else { + icon_size=items[i].get_icon_size() *icon_scale; - Vector2 icon_ofs; - if (min_icon_size!=Vector2()) { - icon_ofs = (min_icon_size - icon_size)/2; } + Vector2 icon_ofs; + Point2 pos = items[i].rect_cache.pos + icon_ofs + base_ofs; if (icon_mode==ICON_MODE_TOP) { @@ -1017,18 +985,26 @@ void ItemList::_notification(int p_what) { Math::floor((items[i].rect_cache.size.height - icon_size.height)/2), items[i].rect_cache.size.height - items[i].min_rect_cache.size.height ); - text_ofs.y = MAX(icon_size.height, min_icon_size.y) + icon_margin; + text_ofs.y = icon_size.height + icon_margin; text_ofs.y += items[i].rect_cache.size.height - items[i].min_rect_cache.size.height; } else { pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height)/2); - text_ofs.x = MAX(icon_size.width, min_icon_size.x) + icon_margin; + text_ofs.x = icon_size.width + icon_margin; + } + + Rect2 draw_rect=Rect2(pos,icon_size); + + if (fixed_icon_size.x>0 && fixed_icon_size.y>0) { + Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale,icon_size); + draw_rect.pos+=adj.pos; + draw_rect.size=adj.size; } if (items[i].icon_region.has_no_area()) - draw_texture_rect(items[i].icon, Rect2(pos,icon_size) ); + draw_texture_rect(items[i].icon, draw_rect ); else - draw_texture_rect_region(items[i].icon, Rect2(pos, icon_size), items[i].icon_region); + draw_texture_rect_region(items[i].icon, draw_rect, items[i].icon_region); } @@ -1298,11 +1274,9 @@ void ItemList::_bind_methods(){ ObjectTypeDB::bind_method(_MD("set_icon_mode","mode"),&ItemList::set_icon_mode); ObjectTypeDB::bind_method(_MD("get_icon_mode"),&ItemList::get_icon_mode); - ObjectTypeDB::bind_method(_MD("set_min_icon_size","size"),&ItemList::set_min_icon_size); - ObjectTypeDB::bind_method(_MD("get_min_icon_size"),&ItemList::get_min_icon_size); - ObjectTypeDB::bind_method(_MD("set_max_icon_size","size"),&ItemList::set_max_icon_size); - ObjectTypeDB::bind_method(_MD("get_max_icon_size"),&ItemList::get_max_icon_size); + ObjectTypeDB::bind_method(_MD("set_fixed_icon_size","size"),&ItemList::set_fixed_icon_size); + ObjectTypeDB::bind_method(_MD("get_fixed_icon_size"),&ItemList::get_fixed_icon_size); ObjectTypeDB::bind_method(_MD("set_icon_scale","scale"),&ItemList::set_icon_scale); ObjectTypeDB::bind_method(_MD("get_icon_scale"),&ItemList::get_icon_scale); diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index 087c585128..a4909205ef 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -62,8 +62,7 @@ private: int max_text_lines; int max_columns; - Size2 min_icon_size; - Size2 max_icon_size; + Size2 fixed_icon_size; Size2 max_item_size_cache; @@ -75,6 +74,8 @@ private: void _scroll_changed(double); void _input_event(const InputEvent& p_event); + + protected: void _notification(int p_what); @@ -144,11 +145,8 @@ public: void set_icon_mode(IconMode p_mode); IconMode get_icon_mode() const; - void set_min_icon_size(const Size2& p_size); - Size2 get_min_icon_size() const; - - void set_max_icon_size(const Size2& p_size); - Size2 get_max_icon_size() const; + void set_fixed_icon_size(const Size2& p_size); + Size2 get_fixed_icon_size() const; void set_allow_rmb_select(bool p_allow); bool get_allow_rmb_select() const; diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp index 5df22ba8cc..5ac7946391 100644 --- a/scene/resources/packed_scene.cpp +++ b/scene/resources/packed_scene.cpp @@ -545,9 +545,19 @@ https://github.com/godotengine/godot/issues/3127 } #endif - if (exists && bool(Variant::evaluate(Variant::OP_EQUAL,value,original))) { - //exists and did not change - continue; + if (exists) { + + //check if already exists and did not change + if (value.get_type()==Variant::REAL && original.get_type()==Variant::REAL) { + //this must be done because, as some scenes save as text, there might be a tiny difference in floats due to numerical error + float a = value; + float b = original; + + if (Math::abs(a-b)<CMP_EPSILON) + continue; + } else if (bool(Variant::evaluate(Variant::OP_EQUAL,value,original))) { + continue; + } } if (!exists && isdefault) { diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 8d0aedbf93..2f4d37053e 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -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 { - 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]; } 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<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 { - 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) { |