summaryrefslogtreecommitdiff
path: root/scene/resources/theme.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/resources/theme.cpp')
-rw-r--r--scene/resources/theme.cpp72
1 files changed, 63 insertions, 9 deletions
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 2f4d37053e..92a6f0c0b9 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;
@@ -81,13 +107,22 @@ bool Theme::_get(const StringName& p_name,Variant &r_ret) const {
if (type=="icons") {
- r_ret= get_icon(name,node_type);
+ if (!has_icon(name,node_type))
+ r_ret=Ref<Texture>();
+ else
+ r_ret= get_icon(name,node_type);
} else if (type=="styles") {
- r_ret= get_stylebox(name,node_type);
+ if (!has_stylebox(name,node_type))
+ r_ret=Ref<StyleBox>();
+ else
+ r_ret= get_stylebox(name,node_type);
} else if (type=="fonts") {
- r_ret= get_font(name,node_type);
+ if (!has_font(name,node_type))
+ r_ret=Ref<Font>();
+ else
+ r_ret= get_font(name,node_type);
} else if (type=="colors") {
r_ret= get_color(name,node_type);
@@ -116,7 +151,7 @@ void Theme::_get_property_list( List<PropertyInfo> *p_list) const {
while((key2=icon_map[*key].next(key2))) {
- list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/icons/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "Texture" ) );
+ list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/icons/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "Texture",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_STORE_IF_NULL ) );
}
}
@@ -128,7 +163,7 @@ void Theme::_get_property_list( List<PropertyInfo> *p_list) const {
while((key2=style_map[*key].next(key2))) {
- list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/styles/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox" ) );
+ list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/styles/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_STORE_IF_NULL ) );
}
}
@@ -141,7 +176,7 @@ void Theme::_get_property_list( List<PropertyInfo> *p_list) const {
while((key2=font_map[*key].next(key2))) {
- list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/fonts/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "Font" ) );
+ list.push_back( PropertyInfo( Variant::OBJECT, String()+*key+"/fonts/"+*key2, PROPERTY_HINT_RESOURCE_TYPE, "Font",PROPERTY_USAGE_DEFAULT|PROPERTY_USAGE_STORE_IF_NULL ) );
}
}
@@ -217,7 +252,7 @@ void Theme::set_default_font( const Ref<Font>& p_font ) {
void Theme::set_icon(const StringName& p_name,const StringName& p_type,const Ref<Texture>& p_icon) {
- ERR_FAIL_COND(p_icon.is_null());
+// ERR_FAIL_COND(p_icon.is_null());
bool new_value=!icon_map.has(p_type) || !icon_map[p_type].has(p_name);
@@ -317,7 +352,7 @@ void Theme::get_shader_list(const StringName &p_type, List<StringName> *p_list)
void Theme::set_stylebox(const StringName& p_name,const StringName& p_type,const Ref<StyleBox>& p_style) {
- ERR_FAIL_COND(p_style.is_null());
+// ERR_FAIL_COND(p_style.is_null());
bool new_value=!style_map.has(p_type) || !style_map[p_type].has(p_name);
@@ -380,11 +415,21 @@ void Theme::get_stylebox_types(List<StringName> *p_list) const {
void Theme::set_font(const StringName& p_name,const StringName& p_type,const Ref<Font>& p_font) {
- ERR_FAIL_COND(p_font.is_null());
+// 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();;
@@ -411,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();;
@@ -636,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"));