summaryrefslogtreecommitdiff
path: root/scene/gui/control.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui/control.cpp')
-rw-r--r--scene/gui/control.cpp90
1 files changed, 76 insertions, 14 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index dfad7d1432..edc8a8bcb8 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -153,6 +153,9 @@ bool Control::_set(const StringName& p_name, const Variant& p_value) {
update();
} else if (name.begins_with("custom_fonts/")) {
String dname = name.get_slicec('/',1);
+ if (data.font_override.has(dname)) {
+ _unref_font(data.font_override[dname]);
+ }
data.font_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
update();
@@ -437,11 +440,17 @@ void Control::_notification(int p_notification) {
if (is_set_as_toplevel()) {
data.SI=get_viewport()->_gui_add_subwindow_control(this);
+
+ if (data.theme.is_null() && data.parent && data.parent->data.theme_owner) {
+ data.theme_owner=data.parent->data.theme_owner;
+ notification(NOTIFICATION_THEME_CHANGED);
+ }
+
} else {
Node *parent=this; //meh
- Node *parent_control=NULL;
+ Control *parent_control=NULL;
bool subwindow=false;
while(parent) {
@@ -457,8 +466,9 @@ void Control::_notification(int p_notification) {
break;
}
- if (parent->cast_to<Control>()) {
- parent_control=parent->cast_to<Control>();
+ parent_control=parent->cast_to<Control>();
+
+ if (parent_control) {
break;
} else if (ci) {
@@ -470,6 +480,10 @@ void Control::_notification(int p_notification) {
if (parent_control) {
//do nothing, has a parent control
+ if (data.theme.is_null() && parent_control->data.theme_owner) {
+ data.theme_owner=parent_control->data.theme_owner;
+ notification(NOTIFICATION_THEME_CHANGED);
+ }
} else if (subwindow) {
//is a subwindow (process input before other controls for that canvas)
data.SI=get_viewport()->_gui_add_subwindow_control(this);
@@ -1540,7 +1554,15 @@ void Control::add_style_override(const StringName& p_name, const Ref<StyleBox>&
void Control::add_font_override(const StringName& p_name, const Ref<Font>& p_font) {
ERR_FAIL_COND(p_font.is_null());
+ if (data.font_override.has(p_name)) {
+ _unref_font(data.font_override[p_name]);
+ }
data.font_override[p_name]=p_font;
+
+ if (p_font.is_valid()) {
+ _ref_font(p_font);
+ }
+
notification(NOTIFICATION_THEME_CHANGED);
update();
}
@@ -1829,18 +1851,29 @@ void Control::_modal_stack_remove() {
}
-void Control::_propagate_theme_changed(Control *p_owner) {
+void Control::_propagate_theme_changed(CanvasItem *p_at,Control *p_owner) {
- for(int i=0;i<get_child_count();i++) {
+ Control *c = p_at->cast_to<Control>();
+
+ if (c && c!=p_owner && c->data.theme.is_valid()) // has a theme, this can't be propagated
+ return;
+
+ for(int i=0;i<p_at->get_child_count();i++) {
+
+ CanvasItem *child = p_at->get_child(i)->cast_to<CanvasItem>();
+ if (child) {
+ _propagate_theme_changed(child,p_owner);
+ }
- Control *child = get_child(i)->cast_to<Control>();
- if (child && child->data.theme.is_null()) //has no theme, propagate
- child->_propagate_theme_changed(p_owner);
}
- data.theme_owner=p_owner;
- _notification(NOTIFICATION_THEME_CHANGED);
- update();
+
+ if (c) {
+
+ c->data.theme_owner=p_owner;
+ c->_notification(NOTIFICATION_THEME_CHANGED);
+ c->update();
+ }
}
void Control::set_theme(const Ref<Theme>& p_theme) {
@@ -1849,15 +1882,15 @@ void Control::set_theme(const Ref<Theme>& p_theme) {
data.theme=p_theme;
if (!p_theme.is_null()) {
- _propagate_theme_changed(this);
+ _propagate_theme_changed(this,this);
} else {
Control *parent = get_parent()?get_parent()->cast_to<Control>():NULL;
if (parent && parent->data.theme_owner) {
- _propagate_theme_changed(parent->data.theme_owner);
+ _propagate_theme_changed(this,parent->data.theme_owner);
} else {
- _propagate_theme_changed(NULL);
+ _propagate_theme_changed(this,NULL);
}
}
@@ -2222,6 +2255,33 @@ float Control::_get_rotation_deg() const {
WARN_PRINT("Deprecated method Control._get_rotation_deg(): This method was renamed to get_rotation_deg. Please adapt your code accordingly, as the old method will be obsoleted.");
return get_rotation_deg();
}
+//needed to update the control if the font changes..
+void Control::_ref_font( Ref<Font> p_sc) {
+
+ if (!data.font_refcount.has(p_sc)) {
+ data.font_refcount[p_sc]=1;
+ p_sc->connect("changed",this,"_font_changed");
+ } else {
+ data.font_refcount[p_sc]+=1;
+ }
+}
+
+void Control::_unref_font(Ref<Font> p_sc) {
+
+ ERR_FAIL_COND(!data.font_refcount.has(p_sc));
+ data.font_refcount[p_sc]--;
+ if (data.font_refcount[p_sc]==0) {
+ p_sc->disconnect("changed",this,"_font_changed");
+ data.font_refcount.erase(p_sc);
+ }
+}
+
+void Control::_font_changed(){
+
+ update();
+ notification(NOTIFICATION_THEME_CHANGED);
+ minimum_size_changed(); //fonts affect minimum size pretty much almost always
+}
void Control::set_scale(const Vector2& p_scale){
@@ -2374,6 +2434,8 @@ void Control::_bind_methods() {
ObjectTypeDB::bind_method(_MD("minimum_size_changed"), &Control::minimum_size_changed);
+ ObjectTypeDB::bind_method(_MD("_font_changed"), &Control::_font_changed);
+
BIND_VMETHOD(MethodInfo("_input_event",PropertyInfo(Variant::INPUT_EVENT,"event")));
BIND_VMETHOD(MethodInfo(Variant::VECTOR2,"get_minimum_size"));
BIND_VMETHOD(MethodInfo(Variant::OBJECT,"get_drag_data",PropertyInfo(Variant::VECTOR2,"pos")));