summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2016-07-18 16:41:28 -0300
committerJuan Linietsky <reduzio@gmail.com>2016-07-18 16:41:59 -0300
commitf10bd217a26487f097bc4609c02302126d36ae41 (patch)
treeafc02337035501e3cdf1f073cec5bddc747d0362
parent4f9dea3aed8a0a15df6dfde65fc5f2bd5e8a0b06 (diff)
properly fixed notificaitons for theme changed, closes #5774
-rw-r--r--scene/gui/control.cpp26
-rw-r--r--scene/gui/control.h4
-rw-r--r--scene/resources/theme.cpp15
3 files changed, 42 insertions, 3 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index fc27c0d24f..c176e50cee 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -1865,7 +1865,7 @@ void Control::_modal_stack_remove() {
}
-void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner) {
+void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner,bool p_assign) {
Control *c = p_at->cast_to<Control>();
@@ -1884,15 +1884,30 @@ void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner) {
if (c) {
- c->data.theme_owner=p_owner;
+ if (p_assign) {
+ c->data.theme_owner=p_owner;
+ }
c->_notification(NOTIFICATION_THEME_CHANGED);
c->update();
}
}
+
+void Control::_theme_changed() {
+
+ _propagate_theme_changed(this,this,false);
+}
+
void Control::set_theme(const Ref<Theme>& p_theme) {
+ if (data.theme==p_theme)
+ return;
+
+ if (data.theme.is_valid()) {
+ data.theme->disconnect("changed",this,"_theme_changed");
+ }
+
data.theme=p_theme;
if (!p_theme.is_null()) {
@@ -1909,6 +1924,9 @@ void Control::set_theme(const Ref<Theme>& p_theme) {
}
+ if (data.theme.is_valid()) {
+ data.theme->connect("changed",this,"_theme_changed");
+ }
}
@@ -2448,6 +2466,10 @@ void Control::_bind_methods() {
ObjectTypeDB::bind_method(_MD("minimum_size_changed"), &Control::minimum_size_changed);
+ ObjectTypeDB::bind_method(_MD("_theme_changed"), &Control::_theme_changed);
+
+
+
ObjectTypeDB::bind_method(_MD("_font_changed"), &Control::_font_changed);
BIND_VMETHOD(MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"event")));
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 830ebd1620..1337cbc4b9 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -172,7 +172,9 @@ private:
float _get_range(int p_idx) const;
float _s2a(float p_val, AnchorType p_anchor,float p_range) const;
float _a2s(float p_val, AnchorType p_anchor,float p_range) const;
- void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner);
+ void _propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign=true);
+ void _theme_changed();
+
void _change_notify_margins();
void _update_minimum_size();
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index 92a6f0c0b9..b351167e10 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -219,7 +219,22 @@ Ref<Theme> Theme::get_default() {
void Theme::set_default_theme_font( const Ref<Font>& p_default_font ) {
+ if (default_theme_font==p_default_font)
+ return;
+
+ if (default_theme_font.is_valid()) {
+ _unref_font(default_theme_font);
+ }
+
default_theme_font=p_default_font;
+
+ if (default_theme_font.is_valid()) {
+ _ref_font(default_theme_font);
+ }
+
+ _change_notify();
+ emit_changed();;
+
}
Ref<Font> Theme::get_default_theme_font() const {