diff options
| author | Juan Linietsky | 2016-06-17 16:00:27 -0300 |
|---|---|---|
| committer | Juan Linietsky | 2016-06-17 16:01:30 -0300 |
| commit | 55b83157e70a34a933a2a73f14a0052a832d0287 (patch) | |
| tree | f81cff6a24c42a3fae5fbfaa20e5e60efaeecb39 /scene/resources/theme.cpp | |
| parent | ebbd705b63d44d6f25949f6fda9bacf8d974c8bd (diff) | |
| download | godot-55b83157e70a34a933a2a73f14a0052a832d0287.tar.gz godot-55b83157e70a34a933a2a73f14a0052a832d0287.tar.zst godot-55b83157e70a34a933a2a73f14a0052a832d0287.zip | |
Diffstat (limited to 'scene/resources/theme.cpp')
| -rw-r--r-- | scene/resources/theme.cpp | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp index 6725f73ad..92a6f0c0b 100644 --- a/scene/resources/theme.cpp +++ b/scene/resources/theme.cpp @@ -34,6 +34,32 @@ Ref<Theme> Theme::default_theme; +void Theme::_emit_theme_changed() { + + emit_changed(); +} + +void Theme::_ref_font( Ref<Font> p_sc) { + + if (!font_refcount.has(p_sc)) { + font_refcount[p_sc]=1; + p_sc->connect("changed",this,"_emit_theme_changed"); + } else { + font_refcount[p_sc]+=1; + } +} + +void Theme::_unref_font(Ref<Font> p_sc) { + + ERR_FAIL_COND(!font_refcount.has(p_sc)); + font_refcount[p_sc]--; + if (font_refcount[p_sc]==0) { + p_sc->disconnect("changed",this,"_emit_theme_changed"); + font_refcount.erase(p_sc); + } +} + + bool Theme::_set(const StringName& p_name, const Variant& p_value) { String sname=p_name; @@ -392,8 +418,18 @@ void Theme::set_font(const StringName& p_name,const StringName& p_type,const Ref // ERR_FAIL_COND(p_font.is_null()); bool new_value=!font_map.has(p_type) || !font_map[p_type].has(p_name); + + if (!new_value) { + if (font_map[p_type][p_name].is_valid()) { + _unref_font(font_map[p_type][p_name]); + } + } font_map[p_type][p_name]=p_font; + if (p_font.is_valid()) { + _ref_font(p_font); + } + if (new_value) { _change_notify(); emit_changed();; @@ -420,6 +456,10 @@ void Theme::clear_font(const StringName& p_name,const StringName& p_type) { ERR_FAIL_COND(!font_map.has(p_type)); ERR_FAIL_COND(!font_map[p_type].has(p_name)); + if (font_map.has(p_type) && font_map[p_type].has(p_name) && font_map[p_type][p_name].is_valid()) { + _unref_font(font_map[p_type][p_name]); + } + font_map[p_type].erase(p_name); _change_notify(); emit_changed();; @@ -645,6 +685,11 @@ void Theme::_bind_methods() { ObjectTypeDB::bind_method(_MD("get_type_list","type"),&Theme::_get_type_list); + ObjectTypeDB::bind_method(_MD("_emit_theme_changed"),&Theme::_emit_theme_changed); + + + + ObjectTypeDB::bind_method("copy_default_theme",&Theme::copy_default_theme); ADD_PROPERTY(PropertyInfo(Variant::OBJECT,"default_font",PROPERTY_HINT_RESOURCE_TYPE,"Font"),_SCS("set_default_font"),_SCS("get_default_font")); |
