diff options
author | Juan Linietsky <reduzio@gmail.com> | 2020-03-12 09:37:40 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2020-03-26 15:49:42 +0100 |
commit | 441f1a5fe9a3bf0e4e5dab578f793500b1ff6e3d (patch) | |
tree | 6421bcc3235e6fdcd726244ac7d455886e17734b /scene | |
parent | 543fb1c4dadd75914d595b089820aef42e691075 (diff) |
Popups are now windows also (broken!)
Diffstat (limited to 'scene')
43 files changed, 1289 insertions, 1249 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp index 2d2da005d0..321f3f2e6f 100644 --- a/scene/2d/canvas_item.cpp +++ b/scene/2d/canvas_item.cpp @@ -34,6 +34,7 @@ #include "core/message_queue.h" #include "core/method_bind_ext.gen.inc" #include "scene/main/canvas_layer.h" +#include "scene/main/viewport.h" #include "scene/main/window.h" #include "scene/resources/font.h" #include "scene/resources/style_box.h" @@ -454,6 +455,21 @@ Transform2D CanvasItem::get_global_transform_with_canvas() const { return get_global_transform(); } +Transform2D CanvasItem::get_screen_transform() const { + ERR_FAIL_COND_V(!is_inside_tree(), Transform2D()); + Transform2D xform = get_global_transform_with_canvas(); + + Window *w = Object::cast_to<Window>(get_viewport()); + if (w) { + Transform2D s; + s.set_origin(w->get_position()); + + xform = s * xform; + } + + return xform; +} + Transform2D CanvasItem::get_global_transform() const { #ifdef DEBUG_ENABLED ERR_FAIL_COND_V(!is_inside_tree(), get_transform()); diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h index 6bfe3cf0c7..3f176e5f60 100644 --- a/scene/2d/canvas_item.h +++ b/scene/2d/canvas_item.h @@ -367,6 +367,7 @@ public: virtual Transform2D get_global_transform() const; virtual Transform2D get_global_transform_with_canvas() const; + virtual Transform2D get_screen_transform() const; CanvasItem *get_toplevel() const; _FORCE_INLINE_ RID get_canvas_item() const { diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index e0bfeac9f7..0da6e0fdfa 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -45,7 +45,7 @@ void BoxContainer::_resort() { Size2i new_size = get_size(); - int sep = get_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); + int sep = get_theme_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); bool first = true; int children_count = 0; @@ -206,7 +206,7 @@ Size2 BoxContainer::get_minimum_size() const { /* Calculate MINIMUM SIZE */ Size2i minimum; - int sep = get_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); + int sep = get_theme_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); bool first = true; @@ -310,7 +310,7 @@ MarginContainer *VBoxContainer::add_margin_child(const String &p_label, Control l->set_text(p_label); add_child(l); MarginContainer *mc = memnew(MarginContainer); - mc->add_constant_override("margin_left", 0); + mc->add_theme_constant_override("margin_left", 0); mc->add_child(p_control); add_child(mc); if (p_expand) diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 784d298bff..f71d322412 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -35,14 +35,14 @@ Size2 Button::get_minimum_size() const { - Size2 minsize = get_font("font")->get_string_size(xl_text); + Size2 minsize = get_theme_font("font")->get_string_size(xl_text); if (clip_text) minsize.width = 0; if (!expand_icon) { Ref<Texture2D> _icon; - if (icon.is_null() && has_icon("icon")) - _icon = Control::get_icon("icon"); + if (icon.is_null() && has_theme_icon("icon")) + _icon = Control::get_theme_icon("icon"); else _icon = icon; @@ -51,11 +51,11 @@ Size2 Button::get_minimum_size() const { minsize.height = MAX(minsize.height, _icon->get_height()); minsize.width += _icon->get_width(); if (xl_text != "") - minsize.width += get_constant("hseparation"); + minsize.width += get_theme_constant("hseparation"); } } - return get_stylebox("normal")->get_minimum_size() + minsize; + return get_theme_stylebox("normal")->get_minimum_size() + minsize; } void Button::_set_internal_margin(Margin p_margin, float p_value) { @@ -79,30 +79,30 @@ void Button::_notification(int p_what) { Color color; Color color_icon(1, 1, 1, 1); - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); switch (get_draw_mode()) { case DRAW_NORMAL: { - style = get_stylebox("normal"); + style = get_theme_stylebox("normal"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - color = get_color("font_color"); - if (has_color("icon_color_normal")) - color_icon = get_color("icon_color_normal"); + color = get_theme_color("font_color"); + if (has_theme_color("icon_color_normal")) + color_icon = get_theme_color("icon_color_normal"); } break; case DRAW_HOVER_PRESSED: { - if (has_stylebox("hover_pressed") && has_stylebox_override("hover_pressed")) { - style = get_stylebox("hover_pressed"); + if (has_theme_stylebox("hover_pressed") && has_theme_stylebox_override("hover_pressed")) { + style = get_theme_stylebox("hover_pressed"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - if (has_color("font_color_hover_pressed")) - color = get_color("font_color_hover_pressed"); + if (has_theme_color("font_color_hover_pressed")) + color = get_theme_color("font_color_hover_pressed"); else - color = get_color("font_color"); - if (has_color("icon_color_hover_pressed")) - color_icon = get_color("icon_color_hover_pressed"); + color = get_theme_color("font_color"); + if (has_theme_color("icon_color_hover_pressed")) + color_icon = get_theme_color("icon_color_hover_pressed"); break; } @@ -110,49 +110,49 @@ void Button::_notification(int p_what) { } case DRAW_PRESSED: { - style = get_stylebox("pressed"); + style = get_theme_stylebox("pressed"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - if (has_color("font_color_pressed")) - color = get_color("font_color_pressed"); + if (has_theme_color("font_color_pressed")) + color = get_theme_color("font_color_pressed"); else - color = get_color("font_color"); - if (has_color("icon_color_pressed")) - color_icon = get_color("icon_color_pressed"); + color = get_theme_color("font_color"); + if (has_theme_color("icon_color_pressed")) + color_icon = get_theme_color("icon_color_pressed"); } break; case DRAW_HOVER: { - style = get_stylebox("hover"); + style = get_theme_stylebox("hover"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - color = get_color("font_color_hover"); - if (has_color("icon_color_hover")) - color_icon = get_color("icon_color_hover"); + color = get_theme_color("font_color_hover"); + if (has_theme_color("icon_color_hover")) + color_icon = get_theme_color("icon_color_hover"); } break; case DRAW_DISABLED: { - style = get_stylebox("disabled"); + style = get_theme_stylebox("disabled"); if (!flat) style->draw(ci, Rect2(Point2(0, 0), size)); - color = get_color("font_color_disabled"); - if (has_color("icon_color_disabled")) - color_icon = get_color("icon_color_disabled"); + color = get_theme_color("font_color_disabled"); + if (has_theme_color("icon_color_disabled")) + color_icon = get_theme_color("icon_color_disabled"); } break; } if (has_focus()) { - Ref<StyleBox> style2 = get_stylebox("focus"); + Ref<StyleBox> style2 = get_theme_stylebox("focus"); style2->draw(ci, Rect2(Point2(), size)); } - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); Ref<Texture2D> _icon; - if (icon.is_null() && has_icon("icon")) - _icon = Control::get_icon("icon"); + if (icon.is_null() && has_theme_icon("icon")) + _icon = Control::get_theme_icon("icon"); else _icon = icon; @@ -166,14 +166,14 @@ void Button::_notification(int p_what) { float icon_ofs_region = 0; if (_internal_margin[MARGIN_LEFT] > 0) { - icon_ofs_region = _internal_margin[MARGIN_LEFT] + get_constant("hseparation"); + icon_ofs_region = _internal_margin[MARGIN_LEFT] + get_theme_constant("hseparation"); } if (expand_icon) { Size2 _size = get_size() - style->get_offset() * 2; - _size.width -= get_constant("hseparation") + icon_ofs_region; + _size.width -= get_theme_constant("hseparation") + icon_ofs_region; if (!clip_text) - _size.width -= get_font("font")->get_string_size(xl_text).width; + _size.width -= get_theme_font("font")->get_string_size(xl_text).width; float icon_width = _icon->get_width() * _size.height / _icon->get_height(); float icon_height = _size.height; @@ -188,13 +188,13 @@ void Button::_notification(int p_what) { } } - Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_constant("hseparation"), 0) : Point2(); + Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant("hseparation"), 0) : Point2(); int text_clip = size.width - style->get_minimum_size().width - icon_ofs.width; if (_internal_margin[MARGIN_LEFT] > 0) { - text_clip -= _internal_margin[MARGIN_LEFT] + get_constant("hseparation"); + text_clip -= _internal_margin[MARGIN_LEFT] + get_theme_constant("hseparation"); } if (_internal_margin[MARGIN_RIGHT] > 0) { - text_clip -= _internal_margin[MARGIN_RIGHT] + get_constant("hseparation"); + text_clip -= _internal_margin[MARGIN_RIGHT] + get_theme_constant("hseparation"); } Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - font->get_string_size(xl_text) - Point2(_internal_margin[MARGIN_RIGHT] - _internal_margin[MARGIN_LEFT], 0)) / 2.0; @@ -202,7 +202,7 @@ void Button::_notification(int p_what) { switch (align) { case ALIGN_LEFT: { if (_internal_margin[MARGIN_LEFT] > 0) { - text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x + _internal_margin[MARGIN_LEFT] + get_constant("hseparation"); + text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x + _internal_margin[MARGIN_LEFT] + get_theme_constant("hseparation"); } else { text_ofs.x = style->get_margin(MARGIN_LEFT) + icon_ofs.x; } @@ -216,7 +216,7 @@ void Button::_notification(int p_what) { } break; case ALIGN_RIGHT: { if (_internal_margin[MARGIN_RIGHT] > 0) { - text_ofs.x = size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size(xl_text).x - _internal_margin[MARGIN_RIGHT] - get_constant("hseparation"); + text_ofs.x = size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size(xl_text).x - _internal_margin[MARGIN_RIGHT] - get_theme_constant("hseparation"); } else { text_ofs.x = size.x - style->get_margin(MARGIN_RIGHT) - font->get_string_size(xl_text).x; } diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index 89bd8ab0dd..d68bd4fe4e 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -33,10 +33,10 @@ #include "servers/visual_server.h" Size2 CheckBox::get_icon_size() const { - Ref<Texture2D> checked = Control::get_icon("checked"); - Ref<Texture2D> unchecked = Control::get_icon("unchecked"); - Ref<Texture2D> radio_checked = Control::get_icon("radio_checked"); - Ref<Texture2D> radio_unchecked = Control::get_icon("radio_unchecked"); + Ref<Texture2D> checked = Control::get_theme_icon("checked"); + Ref<Texture2D> unchecked = Control::get_theme_icon("unchecked"); + Ref<Texture2D> radio_checked = Control::get_theme_icon("radio_checked"); + Ref<Texture2D> radio_unchecked = Control::get_theme_icon("radio_unchecked"); Size2 tex_size = Size2(0, 0); if (!checked.is_null()) @@ -56,9 +56,9 @@ Size2 CheckBox::get_minimum_size() const { Size2 tex_size = get_icon_size(); minsize.width += tex_size.width; if (get_text().length() > 0) { - minsize.width += get_constant("hseparation"); + minsize.width += get_theme_constant("hseparation"); } - Ref<StyleBox> sb = get_stylebox("normal"); + Ref<StyleBox> sb = get_theme_stylebox("normal"); minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM)); return minsize; @@ -73,13 +73,13 @@ void CheckBox::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture2D> on = Control::get_icon(is_radio() ? "radio_checked" : "checked"); - Ref<Texture2D> off = Control::get_icon(is_radio() ? "radio_unchecked" : "unchecked"); - Ref<StyleBox> sb = get_stylebox("normal"); + Ref<Texture2D> on = Control::get_theme_icon(is_radio() ? "radio_checked" : "checked"); + Ref<Texture2D> off = Control::get_theme_icon(is_radio() ? "radio_unchecked" : "unchecked"); + Ref<StyleBox> sb = get_theme_stylebox("normal"); Vector2 ofs; ofs.x = sb->get_margin(MARGIN_LEFT); - ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_constant("check_vadjust"); + ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant("check_vadjust"); if (is_pressed()) on->draw(ci, ofs); diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index 0b093ce850..ac967a128c 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -35,8 +35,8 @@ Size2 CheckButton::get_icon_size() const { - Ref<Texture2D> on = Control::get_icon(is_disabled() ? "on_disabled" : "on"); - Ref<Texture2D> off = Control::get_icon(is_disabled() ? "off_disabled" : "off"); + Ref<Texture2D> on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on"); + Ref<Texture2D> off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off"); Size2 tex_size = Size2(0, 0); if (!on.is_null()) tex_size = Size2(on->get_width(), on->get_height()); @@ -52,8 +52,8 @@ Size2 CheckButton::get_minimum_size() const { Size2 tex_size = get_icon_size(); minsize.width += tex_size.width; if (get_text().length() > 0) - minsize.width += get_constant("hseparation"); - Ref<StyleBox> sb = get_stylebox("normal"); + minsize.width += get_theme_constant("hseparation"); + Ref<StyleBox> sb = get_theme_stylebox("normal"); minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(MARGIN_TOP) + sb->get_margin(MARGIN_BOTTOM)); return minsize; @@ -68,15 +68,15 @@ void CheckButton::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture2D> on = Control::get_icon(is_disabled() ? "on_disabled" : "on"); - Ref<Texture2D> off = Control::get_icon(is_disabled() ? "off_disabled" : "off"); + Ref<Texture2D> on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on"); + Ref<Texture2D> off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off"); - Ref<StyleBox> sb = get_stylebox("normal"); + Ref<StyleBox> sb = get_theme_stylebox("normal"); Vector2 ofs; Size2 tex_size = get_icon_size(); ofs.x = get_size().width - (tex_size.width + sb->get_margin(MARGIN_RIGHT)); - ofs.y = (get_size().height - tex_size.height) / 2 + get_constant("check_vadjust"); + ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant("check_vadjust"); if (is_pressed()) on->draw(ci, ofs); diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 79125cc14b..2a3f7467dc 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -45,15 +45,15 @@ void ColorPicker::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { - btn_pick->set_icon(get_icon("screen_picker", "ColorPicker")); - bt_add_preset->set_icon(get_icon("add_preset")); + btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker")); + bt_add_preset->set_icon(get_theme_icon("add_preset")); _update_controls(); } break; case NOTIFICATION_ENTER_TREE: { - btn_pick->set_icon(get_icon("screen_picker", "ColorPicker")); - bt_add_preset->set_icon(get_icon("add_preset")); + btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker")); + bt_add_preset->set_icon(get_theme_icon("add_preset")); _update_color(); @@ -70,13 +70,13 @@ void ColorPicker::_notification(int p_what) { case NOTIFICATION_PARENTED: { for (int i = 0; i < 4; i++) - set_margin((Margin)i, get_constant("margin")); + set_margin((Margin)i, get_theme_constant("margin")); } break; case NOTIFICATION_VISIBILITY_CHANGED: { Popup *p = Object::cast_to<Popup>(get_parent()); if (p) - p->set_size(Size2(get_combined_minimum_size().width + get_constant("margin") * 2, get_combined_minimum_size().height + get_constant("margin") * 2)); + p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant("margin") * 2, get_combined_minimum_size().height + get_theme_constant("margin") * 2)); } break; case NOTIFICATION_WM_CLOSE_REQUEST: { @@ -267,7 +267,7 @@ void ColorPicker::_text_type_toggled() { text_is_constructor = !text_is_constructor; if (text_is_constructor) { text_type->set_text(""); - text_type->set_icon(get_icon("Script", "EditorIcons")); + text_type->set_icon(get_theme_icon("Script", "EditorIcons")); c_text->set_editable(false); } else { @@ -399,14 +399,14 @@ void ColorPicker::_sample_draw() { const Rect2 r = Rect2(Point2(), Size2(uv_edit->get_size().width, sample->get_size().height * 0.95)); if (color.a < 1.0) { - sample->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), r, true); + sample->draw_texture_rect(get_theme_icon("preset_bg", "ColorPicker"), r, true); } sample->draw_rect(r, color); if (color.r > 1 || color.g > 1 || color.b > 1) { // Draw an indicator to denote that the color is "overbright" and can't be displayed accurately in the preview - sample->draw_texture(get_icon("overbright_indicator", "ColorPicker"), Point2()); + sample->draw_texture(get_theme_icon("overbright_indicator", "ColorPicker"), Point2()); } } @@ -445,7 +445,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) { c->draw_line(Point2(0, y), Point2(c->get_size().x, y), col.inverted()); c->draw_line(Point2(x, y), Point2(x, y), Color(1, 1, 1), 2); } else if (p_which == 1) { - Ref<Texture2D> hue = get_icon("color_hue", "ColorPicker"); + Ref<Texture2D> hue = get_theme_icon("color_hue", "ColorPicker"); c->draw_texture_rect(hue, Rect2(Point2(), c->get_size())); int y = c->get_size().y - c->get_size().y * (1.0 - h); Color col = Color(); @@ -738,12 +738,12 @@ ColorPicker::ColorPicker() : uv_edit->set_mouse_filter(MOUSE_FILTER_PASS); uv_edit->set_h_size_flags(SIZE_EXPAND_FILL); uv_edit->set_v_size_flags(SIZE_EXPAND_FILL); - uv_edit->set_custom_minimum_size(Size2(get_constant("sv_width"), get_constant("sv_height"))); + uv_edit->set_custom_minimum_size(Size2(get_theme_constant("sv_width"), get_theme_constant("sv_height"))); uv_edit->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw), make_binds(0, uv_edit)); w_edit = memnew(Control); hb_edit->add_child(w_edit); - w_edit->set_custom_minimum_size(Size2(get_constant("h_width"), 0)); + w_edit->set_custom_minimum_size(Size2(get_theme_constant("h_width"), 0)); w_edit->set_h_size_flags(SIZE_FILL); w_edit->set_v_size_flags(SIZE_EXPAND_FILL); w_edit->connect("gui_input", callable_mp(this, &ColorPicker::_w_input)); @@ -777,7 +777,7 @@ ColorPicker::ColorPicker() : HBoxContainer *hbc = memnew(HBoxContainer); labels[i] = memnew(Label()); - labels[i]->set_custom_minimum_size(Size2(get_constant("label_width"), 0)); + labels[i]->set_custom_minimum_size(Size2(get_theme_constant("label_width"), 0)); labels[i]->set_v_size_flags(SIZE_SHRINK_CENTER); hbc->add_child(labels[i]); @@ -881,8 +881,8 @@ void ColorPickerButton::_modal_closed() { void ColorPickerButton::pressed() { _update_picker(); - popup->set_position(get_global_position() - picker->get_combined_minimum_size() * get_global_transform().get_scale()); - popup->set_scale(get_global_transform().get_scale()); + popup->set_position(get_screen_position() - picker->get_combined_minimum_size() * get_global_transform().get_scale()); + //popup->set_scale(get_global_transform().get_scale()); popup->popup(); picker->set_focus_on_line_edit(); } @@ -892,14 +892,14 @@ void ColorPickerButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - const Ref<StyleBox> normal = get_stylebox("normal"); + const Ref<StyleBox> normal = get_theme_stylebox("normal"); const Rect2 r = Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()); - draw_texture_rect(Control::get_icon("bg", "ColorPickerButton"), r, true); + draw_texture_rect(Control::get_theme_icon("bg", "ColorPickerButton"), r, true); draw_rect(r, color); if (color.r > 1 || color.g > 1 || color.b > 1) { // Draw an indicator to denote that the color is "overbright" and can't be displayed accurately in the preview - draw_texture(Control::get_icon("overbright_indicator", "ColorPicker"), normal->get_offset()); + draw_texture(Control::get_theme_icon("overbright_indicator", "ColorPicker"), normal->get_offset()); } } break; case NOTIFICATION_WM_CLOSE_REQUEST: { @@ -963,7 +963,7 @@ void ColorPickerButton::_update_picker() { add_child(popup); picker->connect("color_changed", callable_mp(this, &ColorPickerButton::_color_changed)); popup->connect("modal_closed", callable_mp(this, &ColorPickerButton::_modal_closed)); - popup->connect("about_to_show", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); + popup->connect("about_to_popup", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false)); picker->set_pick_color(color); picker->set_edit_alpha(edit_alpha); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 55ef2a6bed..062d15c05b 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -260,22 +260,22 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) { } else { if (name.begins_with("custom_icons/")) { String dname = name.get_slicec('/', 1); - add_icon_override(dname, p_value); + add_theme_icon_override(dname, p_value); } else if (name.begins_with("custom_shaders/")) { String dname = name.get_slicec('/', 1); - add_shader_override(dname, p_value); + add_theme_shader_override(dname, p_value); } else if (name.begins_with("custom_styles/")) { String dname = name.get_slicec('/', 1); - add_style_override(dname, p_value); + add_theme_style_override(dname, p_value); } else if (name.begins_with("custom_fonts/")) { String dname = name.get_slicec('/', 1); - add_font_override(dname, p_value); + add_theme_font_override(dname, p_value); } else if (name.begins_with("custom_colors/")) { String dname = name.get_slicec('/', 1); - add_color_override(dname, p_value); + add_theme_color_override(dname, p_value); } else if (name.begins_with("custom_constants/")) { String dname = name.get_slicec('/', 1); - add_constant_override(dname, p_value); + add_theme_constant_override(dname, p_value); } else return false; } @@ -817,11 +817,11 @@ Size2 Control::get_minimum_size() const { } template <class T> -bool Control::_find_theme_item(T &r_ret, T (Theme::*get_func)(const StringName &, const StringName &) const, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) const { +bool Control::_find_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, T &r_ret, T (Theme::*get_func)(const StringName &, const StringName &) const, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) { // try with custom themes - Control *theme_owner = data.theme_owner; - Window *theme_owner_window = data.theme_owner_window; + Control *theme_owner = p_theme_owner; + Window *theme_owner_window = p_theme_owner_window; while (theme_owner || theme_owner_window) { @@ -863,11 +863,11 @@ bool Control::_find_theme_item(T &r_ret, T (Theme::*get_func)(const StringName & return false; } -bool Control::_has_theme_item(bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) const { +bool Control::_has_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) { // try with custom themes - Control *theme_owner = data.theme_owner; - Window *theme_owner_window = data.theme_owner_window; + Control *theme_owner = p_theme_owner; + Window *theme_owner_window = p_theme_owner_window; while (theme_owner || theme_owner_window) { @@ -907,7 +907,7 @@ bool Control::_has_theme_item(bool (Theme::*has_func)(const StringName &, const return false; } -Ref<Texture2D> Control::get_icon(const StringName &p_name, const StringName &p_type) const { +Ref<Texture2D> Control::get_theme_icon(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { @@ -918,22 +918,28 @@ Ref<Texture2D> Control::get_icon(const StringName &p_name, const StringName &p_t StringName type = p_type ? p_type : get_class_name(); + return get_icons(data.theme_owner, data.theme_owner_window, p_name, type); +} + +Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + Ref<Texture2D> icon; - if (_find_theme_item(icon, &Theme::get_icon, &Theme::has_icon, p_name, type)) { + if (_find_theme_item(p_theme_owner, p_theme_owner_window, icon, &Theme::get_icon, &Theme::has_icon, p_name, p_type)) { return icon; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_icon(p_name, type)) { - return Theme::get_project_default()->get_icon(p_name, type); + if (Theme::get_project_default()->has_icon(p_name, p_type)) { + return Theme::get_project_default()->get_icon(p_name, p_type); } } - return Theme::get_default()->get_icon(p_name, type); + return Theme::get_default()->get_icon(p_name, p_type); } -Ref<Shader> Control::get_shader(const StringName &p_name, const StringName &p_type) const { +Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName &p_type) const { + if (p_type == StringName() || p_type == get_class_name()) { const Ref<Shader> *sdr = data.shader_override.getptr(p_name); @@ -943,22 +949,27 @@ Ref<Shader> Control::get_shader(const StringName &p_name, const StringName &p_ty StringName type = p_type ? p_type : get_class_name(); + return get_shaders(data.theme_owner, data.theme_owner_window, p_name, type); +} + +Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + Ref<Shader> shader; - if (_find_theme_item(shader, &Theme::get_shader, &Theme::has_shader, p_name, type)) { + if (_find_theme_item(p_theme_owner, p_theme_owner_window, shader, &Theme::get_shader, &Theme::has_shader, p_name, p_type)) { return shader; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_shader(p_name, type)) { - return Theme::get_project_default()->get_shader(p_name, type); + if (Theme::get_project_default()->has_shader(p_name, p_type)) { + return Theme::get_project_default()->get_shader(p_name, p_type); } } - return Theme::get_default()->get_shader(p_name, type); + return Theme::get_default()->get_shader(p_name, p_type); } -Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName &p_type) const { +Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { const Ref<StyleBox> *style = data.style_override.getptr(p_name); @@ -968,21 +979,27 @@ Ref<StyleBox> Control::get_stylebox(const StringName &p_name, const StringName & StringName type = p_type ? p_type : get_class_name(); + return get_styleboxs(data.theme_owner, data.theme_owner_window, p_name, type); +} + +Ref<StyleBox> Control::get_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + Ref<StyleBox> stylebox; - if (_find_theme_item(stylebox, &Theme::get_stylebox, &Theme::has_stylebox, p_name, type)) { + if (_find_theme_item(p_theme_owner, p_theme_owner_window, stylebox, &Theme::get_stylebox, &Theme::has_stylebox, p_name, p_type)) { return stylebox; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_stylebox(p_name, type)) { - return Theme::get_project_default()->get_stylebox(p_name, type); + if (Theme::get_project_default()->has_stylebox(p_name, p_type)) { + return Theme::get_project_default()->get_stylebox(p_name, p_type); } } - return Theme::get_default()->get_stylebox(p_name, type); + return Theme::get_default()->get_stylebox(p_name, p_type); } -Ref<Font> Control::get_font(const StringName &p_name, const StringName &p_type) const { + +Ref<Font> Control::get_theme_font(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { const Ref<Font> *font = data.font_override.getptr(p_name); @@ -992,21 +1009,27 @@ Ref<Font> Control::get_font(const StringName &p_name, const StringName &p_type) StringName type = p_type ? p_type : get_class_name(); + return get_fonts(data.theme_owner, data.theme_owner_window, p_name, type); +} + +Ref<Font> Control::get_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + Ref<Font> font; - if (_find_theme_item(font, &Theme::get_font, &Theme::has_font, p_name, type)) { + if (_find_theme_item(p_theme_owner, p_theme_owner_window, font, &Theme::get_font, &Theme::has_font, p_name, p_type)) { return font; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_font(p_name, type)) { - return Theme::get_project_default()->get_font(p_name, type); + if (Theme::get_project_default()->has_font(p_name, p_type)) { + return Theme::get_project_default()->get_font(p_name, p_type); } } - return Theme::get_default()->get_font(p_name, type); + return Theme::get_default()->get_font(p_name, p_type); } -Color Control::get_color(const StringName &p_name, const StringName &p_type) const { + +Color Control::get_theme_color(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { const Color *color = data.color_override.getptr(p_name); @@ -1016,21 +1039,26 @@ Color Control::get_color(const StringName &p_name, const StringName &p_type) con StringName type = p_type ? p_type : get_class_name(); + return get_colors(data.theme_owner, data.theme_owner_window, p_name, type); +} + +Color Control::get_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + Color color; - if (_find_theme_item(color, &Theme::get_color, &Theme::has_color, p_name, type)) { + if (_find_theme_item(p_theme_owner, p_theme_owner_window, color, &Theme::get_color, &Theme::has_color, p_name, p_type)) { return color; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_color(p_name, type)) { - return Theme::get_project_default()->get_color(p_name, type); + if (Theme::get_project_default()->has_color(p_name, p_type)) { + return Theme::get_project_default()->get_color(p_name, p_type); } } - return Theme::get_default()->get_color(p_name, type); + return Theme::get_default()->get_color(p_name, p_type); } -int Control::get_constant(const StringName &p_name, const StringName &p_type) const { +int Control::get_theme_constant(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { const int *constant = data.constant_override.getptr(p_name); @@ -1040,178 +1068,212 @@ int Control::get_constant(const StringName &p_name, const StringName &p_type) co StringName type = p_type ? p_type : get_class_name(); + return get_constants(data.theme_owner, data.theme_owner_window, p_name, type); +} + +int Control::get_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + int constant; - if (_find_theme_item(constant, &Theme::get_constant, &Theme::has_constant, p_name, type)) { + if (_find_theme_item(p_theme_owner, p_theme_owner_window, constant, &Theme::get_constant, &Theme::has_constant, p_name, p_type)) { return constant; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_constant(p_name, type)) { - return Theme::get_project_default()->get_constant(p_name, type); + if (Theme::get_project_default()->has_constant(p_name, p_type)) { + return Theme::get_project_default()->get_constant(p_name, p_type); } } - return Theme::get_default()->get_constant(p_name, type); + return Theme::get_default()->get_constant(p_name, p_type); } -bool Control::has_icon_override(const StringName &p_name) const { +bool Control::has_theme_icon_override(const StringName &p_name) const { const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); return tex != NULL; } -bool Control::has_shader_override(const StringName &p_name) const { +bool Control::has_theme_shader_override(const StringName &p_name) const { const Ref<Shader> *sdr = data.shader_override.getptr(p_name); return sdr != NULL; } -bool Control::has_stylebox_override(const StringName &p_name) const { +bool Control::has_theme_stylebox_override(const StringName &p_name) const { const Ref<StyleBox> *style = data.style_override.getptr(p_name); return style != NULL; } -bool Control::has_font_override(const StringName &p_name) const { +bool Control::has_theme_font_override(const StringName &p_name) const { const Ref<Font> *font = data.font_override.getptr(p_name); return font != NULL; } -bool Control::has_color_override(const StringName &p_name) const { +bool Control::has_theme_color_override(const StringName &p_name) const { const Color *color = data.color_override.getptr(p_name); return color != NULL; } -bool Control::has_constant_override(const StringName &p_name) const { +bool Control::has_theme_constant_override(const StringName &p_name) const { const int *constant = data.constant_override.getptr(p_name); return constant != NULL; } -bool Control::has_icon(const StringName &p_name, const StringName &p_type) const { +bool Control::has_theme_icon(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_icon_override(p_name)) + if (has_theme_icon_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - if (_has_theme_item(&Theme::has_icon, p_name, type)) { + return has_icons(data.theme_owner, data.theme_owner_window, p_name, type); +} + +bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_icon, p_name, p_type)) { return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_color(p_name, type)) { + if (Theme::get_project_default()->has_color(p_name, p_type)) { return true; } } - return Theme::get_default()->has_icon(p_name, type); + return Theme::get_default()->has_icon(p_name, p_type); } -bool Control::has_shader(const StringName &p_name, const StringName &p_type) const { +bool Control::has_theme_shader(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_shader_override(p_name)) + if (has_theme_shader_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - if (_has_theme_item(&Theme::has_shader, p_name, type)) { + return has_shaders(data.theme_owner, data.theme_owner_window, p_name, type); +} +bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_shader, p_name, p_type)) { return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_shader(p_name, type)) { + if (Theme::get_project_default()->has_shader(p_name, p_type)) { return true; } } - return Theme::get_default()->has_shader(p_name, type); + return Theme::get_default()->has_shader(p_name, p_type); } -bool Control::has_stylebox(const StringName &p_name, const StringName &p_type) const { + +bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_stylebox_override(p_name)) + if (has_theme_stylebox_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - if (_has_theme_item(&Theme::has_stylebox, p_name, type)) { + return has_styleboxs(data.theme_owner, data.theme_owner_window, p_name, type); +} + +bool Control::has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_stylebox, p_name, p_type)) { return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_stylebox(p_name, type)) { + if (Theme::get_project_default()->has_stylebox(p_name, p_type)) { return true; } } - return Theme::get_default()->has_stylebox(p_name, type); + return Theme::get_default()->has_stylebox(p_name, p_type); } -bool Control::has_font(const StringName &p_name, const StringName &p_type) const { + +bool Control::has_theme_font(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_font_override(p_name)) + if (has_theme_font_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - if (_has_theme_item(&Theme::has_font, p_name, type)) { + return has_fonts(data.theme_owner, data.theme_owner_window, p_name, type); +} +bool Control::has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_font, p_name, p_type)) { return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_font(p_name, type)) { + if (Theme::get_project_default()->has_font(p_name, p_type)) { return true; } } - return Theme::get_default()->has_font(p_name, type); + return Theme::get_default()->has_font(p_name, p_type); } -bool Control::has_color(const StringName &p_name, const StringName &p_type) const { +bool Control::has_theme_color(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_color_override(p_name)) + if (has_theme_color_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - if (_has_theme_item(&Theme::has_color, p_name, type)) { + return has_colors(data.theme_owner, data.theme_owner_window, p_name, type); +} +bool Control::has_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_color, p_name, p_type)) { return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_color(p_name, type)) { + if (Theme::get_project_default()->has_color(p_name, p_type)) { return true; } } - return Theme::get_default()->has_color(p_name, type); + return Theme::get_default()->has_color(p_name, p_type); } -bool Control::has_constant(const StringName &p_name, const StringName &p_type) const { +bool Control::has_theme_constant(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - if (has_constant_override(p_name)) + if (has_theme_constant_override(p_name)) return true; } StringName type = p_type ? p_type : get_class_name(); - if (_has_theme_item(&Theme::has_constant, p_name, type)) { + return has_constants(data.theme_owner, data.theme_owner_window, p_name, p_type); +} + +bool Control::has_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type) { + + if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_constant, p_name, p_type)) { return true; } if (Theme::get_project_default().is_valid()) { - if (Theme::get_project_default()->has_constant(p_name, type)) { + if (Theme::get_project_default()->has_constant(p_name, p_type)) { return true; } } - return Theme::get_default()->has_constant(p_name, type); + return Theme::get_default()->has_constant(p_name, p_type); } Rect2 Control::get_parent_anchorable_rect() const { @@ -1654,6 +1716,17 @@ Point2 Control::get_global_position() const { return get_global_transform().get_origin(); } +Point2 Control::get_screen_position() const { + ERR_FAIL_COND_V(!is_inside_tree(), Point2()); + Point2 global_pos = get_global_position(); + Window *w = Object::cast_to<Window>(get_viewport()); + if (w) { + global_pos += w->get_position(); + } + + return global_pos; +} + void Control::_set_global_position(const Point2 &p_point) { set_global_position(p_point); } @@ -1748,6 +1821,20 @@ Rect2 Control::get_global_rect() const { return Rect2(get_global_position(), get_size()); } +Rect2 Control::get_screen_rect() const { + + ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); + + Rect2 r(get_global_position(), get_size()); + + Window *w = Object::cast_to<Window>(get_viewport()); + if (w) { + r.position += w->get_position(); + } + + return r; +} + Rect2 Control::get_window_rect() const { ERR_FAIL_COND_V(!is_inside_tree(), Rect2()); Rect2 gr = get_global_rect(); @@ -1765,7 +1852,7 @@ Rect2 Control::get_anchorable_rect() const { return Rect2(Point2(), get_size()); } -void Control::add_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) { +void Control::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) { if (data.icon_override.has(p_name)) { data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); @@ -1783,7 +1870,7 @@ void Control::add_icon_override(const StringName &p_name, const Ref<Texture2D> & notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { +void Control::add_theme_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) { if (data.shader_override.has(p_name)) { data.shader_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); @@ -1800,7 +1887,7 @@ void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p } notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { +void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) { if (data.style_override.has(p_name)) { data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); @@ -1818,7 +1905,7 @@ void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> & notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_font) { +void Control::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) { if (data.font_override.has(p_name)) { data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); @@ -1835,12 +1922,12 @@ void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_fon } notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_color_override(const StringName &p_name, const Color &p_color) { +void Control::add_theme_color_override(const StringName &p_name, const Color &p_color) { data.color_override[p_name] = p_color; notification(NOTIFICATION_THEME_CHANGED); } -void Control::add_constant_override(const StringName &p_name, int p_constant) { +void Control::add_theme_constant_override(const StringName &p_name, int p_constant) { data.constant_override[p_name] = p_constant; notification(NOTIFICATION_THEME_CHANGED); @@ -2797,31 +2884,31 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Control::set_theme); ClassDB::bind_method(D_METHOD("get_theme"), &Control::get_theme); - ClassDB::bind_method(D_METHOD("add_icon_override", "name", "texture"), &Control::add_icon_override); - ClassDB::bind_method(D_METHOD("add_shader_override", "name", "shader"), &Control::add_shader_override); - ClassDB::bind_method(D_METHOD("add_stylebox_override", "name", "stylebox"), &Control::add_style_override); - ClassDB::bind_method(D_METHOD("add_font_override", "name", "font"), &Control::add_font_override); - ClassDB::bind_method(D_METHOD("add_color_override", "name", "color"), &Control::add_color_override); - ClassDB::bind_method(D_METHOD("add_constant_override", "name", "constant"), &Control::add_constant_override); - - ClassDB::bind_method(D_METHOD("get_icon", "name", "type"), &Control::get_icon, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_stylebox", "name", "type"), &Control::get_stylebox, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_font", "name", "type"), &Control::get_font, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_color", "name", "type"), &Control::get_color, DEFVAL("")); - ClassDB::bind_method(D_METHOD("get_constant", "name", "type"), &Control::get_constant, DEFVAL("")); - - ClassDB::bind_method(D_METHOD("has_icon_override", "name"), &Control::has_icon_override); - ClassDB::bind_method(D_METHOD("has_shader_override", "name"), &Control::has_shader_override); - ClassDB::bind_method(D_METHOD("has_stylebox_override", "name"), &Control::has_stylebox_override); - ClassDB::bind_method(D_METHOD("has_font_override", "name"), &Control::has_font_override); - ClassDB::bind_method(D_METHOD("has_color_override", "name"), &Control::has_color_override); - ClassDB::bind_method(D_METHOD("has_constant_override", "name"), &Control::has_constant_override); - - ClassDB::bind_method(D_METHOD("has_icon", "name", "type"), &Control::has_icon, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_stylebox", "name", "type"), &Control::has_stylebox, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_font", "name", "type"), &Control::has_font, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_color", "name", "type"), &Control::has_color, DEFVAL("")); - ClassDB::bind_method(D_METHOD("has_constant", "name", "type"), &Control::has_constant, DEFVAL("")); + ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Control::add_theme_icon_override); + ClassDB::bind_method(D_METHOD("add_theme_shader_override", "name", "shader"), &Control::add_theme_shader_override); + ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Control::add_theme_style_override); + ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Control::add_theme_font_override); + ClassDB::bind_method(D_METHOD("add_theme_color_override", "name", "color"), &Control::add_theme_color_override); + ClassDB::bind_method(D_METHOD("add_theme_constant_override", "name", "constant"), &Control::add_theme_constant_override); + + ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "type"), &Control::get_theme_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "type"), &Control::get_theme_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_font", "name", "type"), &Control::get_theme_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_color", "name", "type"), &Control::get_theme_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "type"), &Control::get_theme_constant, DEFVAL("")); + + ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Control::has_theme_icon_override); + ClassDB::bind_method(D_METHOD("has_theme_shader_override", "name"), &Control::has_theme_shader_override); + ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Control::has_theme_stylebox_override); + ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Control::has_theme_font_override); + ClassDB::bind_method(D_METHOD("has_theme_color_override", "name"), &Control::has_theme_color_override); + ClassDB::bind_method(D_METHOD("has_theme_constant_override", "name"), &Control::has_theme_constant_override); + + ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "type"), &Control::has_theme_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "type"), &Control::has_theme_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_font", "name", "type"), &Control::has_theme_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_color", "name", "type"), &Control::has_theme_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "type"), &Control::has_theme_constant, DEFVAL("")); ClassDB::bind_method(D_METHOD("get_parent_control"), &Control::get_parent_control); diff --git a/scene/gui/control.h b/scene/gui/control.h index 83b9dd7861..22839df712 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -248,9 +248,23 @@ private: static void _propagate_theme_changed(Node *p_at, Control *p_owner, Window *p_owner_window, bool p_assign = true); template <class T> - _FORCE_INLINE_ bool _find_theme_item(T &, T (Theme::*get_func)(const StringName &, const StringName &) const, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) const; + _FORCE_INLINE_ static bool _find_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, T &, T (Theme::*get_func)(const StringName &, const StringName &) const, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type); - _FORCE_INLINE_ bool _has_theme_item(bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type) const; + _FORCE_INLINE_ static bool _has_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_type); + + static Ref<Texture2D> get_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static Ref<Shader> get_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static Ref<StyleBox> get_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static Ref<Font> get_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static Color get_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static int get_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + + static bool has_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_colors(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); + static bool has_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_type = StringName()); protected: virtual void add_child_notify(Node *p_child); @@ -356,12 +370,14 @@ public: void set_global_position(const Point2 &p_point, bool p_keep_margins = false); Point2 get_position() const; Point2 get_global_position() const; + Point2 get_screen_position() const; void set_size(const Size2 &p_size, bool p_keep_margins = false); Size2 get_size() const; Rect2 get_rect() const; Rect2 get_global_rect() const; + Rect2 get_screen_rect() const; Rect2 get_window_rect() const; ///< use with care, as it blocks waiting for the visual server Rect2 get_anchorable_rect() const; @@ -427,33 +443,33 @@ public: /* SKINNING */ - void add_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon); - void add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader); - void add_style_override(const StringName &p_name, const Ref<StyleBox> &p_style); - void add_font_override(const StringName &p_name, const Ref<Font> &p_font); - void add_color_override(const StringName &p_name, const Color &p_color); - void add_constant_override(const StringName &p_name, int p_constant); - - Ref<Texture2D> get_icon(const StringName &p_name, const StringName &p_type = StringName()) const; - Ref<Shader> get_shader(const StringName &p_name, const StringName &p_type = StringName()) const; - Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; - Ref<Font> get_font(const StringName &p_name, const StringName &p_type = StringName()) const; - Color get_color(const StringName &p_name, const StringName &p_type = StringName()) const; - int get_constant(const StringName &p_name, const StringName &p_type = StringName()) const; - - bool has_icon_override(const StringName &p_name) const; - bool has_shader_override(const StringName &p_name) const; - bool has_stylebox_override(const StringName &p_name) const; - bool has_font_override(const StringName &p_name) const; - bool has_color_override(const StringName &p_name) const; - bool has_constant_override(const StringName &p_name) const; - - bool has_icon(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_shader(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_font(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_color(const StringName &p_name, const StringName &p_type = StringName()) const; - bool has_constant(const StringName &p_name, const StringName &p_type = StringName()) const; + void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon); + void add_theme_shader_override(const StringName &p_name, const Ref<Shader> &p_shader); + void add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style); + void add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font); + void add_theme_color_override(const StringName &p_name, const Color &p_color); + void add_theme_constant_override(const StringName &p_name, int p_constant); + + Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<Shader> get_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const; + Color get_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const; + int get_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const; + + bool has_theme_icon_override(const StringName &p_name) const; + bool has_theme_shader_override(const StringName &p_name) const; + bool has_theme_stylebox_override(const StringName &p_name) const; + bool has_theme_font_override(const StringName &p_name) const; + bool has_theme_color_override(const StringName &p_name) const; + bool has_theme_constant_override(const StringName &p_name) const; + + bool has_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const; /* TOOLTIP */ diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 71000847a1..2e87a92969 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -69,15 +69,22 @@ void AcceptDialog::_notification(int p_what) { } else { if (parent_visible) { parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible = nullptr; } } } break; case NOTIFICATION_THEME_CHANGED: { - bg->add_style_override("panel", bg->get_stylebox("panel", "AcceptDialog")); + bg->add_theme_style_override("panel", bg->get_theme_stylebox("panel", "AcceptDialog")); } break; + case NOTIFICATION_EXIT_TREE: { + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused)); + parent_visible = nullptr; + } + } break; case NOTIFICATION_READY: case NOTIFICATION_WM_SIZE_CHANGED: { if (is_visible()) { @@ -167,7 +174,7 @@ void AcceptDialog::_update_child_rects() { if (label->get_text().empty()) { label_size.height = 0; } - int margin = hbc->get_constant("margin", "Dialogs"); + int margin = hbc->get_theme_constant("margin", "Dialogs"); Size2 size = get_size(); Size2 hminsize = hbc->get_combined_minimum_size(); @@ -198,7 +205,7 @@ void AcceptDialog::_update_child_rects() { Size2 AcceptDialog::_get_contents_minimum_size() const { - int margin = hbc->get_constant("margin", "Dialogs"); + int margin = hbc->get_theme_constant("margin", "Dialogs"); Size2 minsize = label->get_combined_minimum_size(); for (int i = 0; i < get_child_count(); i++) { @@ -296,6 +303,7 @@ AcceptDialog::AcceptDialog() { parent_visible = nullptr; + set_wrap_controls(true); set_visible(false); set_transient(true); @@ -304,8 +312,8 @@ AcceptDialog::AcceptDialog() { hbc = memnew(HBoxContainer); - int margin = hbc->get_constant("margin", "Dialogs"); - int button_margin = hbc->get_constant("button_margin", "Dialogs"); + int margin = hbc->get_theme_constant("margin", "Dialogs"); + int button_margin = hbc->get_theme_constant("button_margin", "Dialogs"); label = memnew(Label); label->set_anchor(MARGIN_RIGHT, Control::ANCHOR_END); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 2f7949ea12..a4f0338f00 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -46,21 +46,21 @@ VBoxContainer *FileDialog::get_vbox() { void FileDialog::_theme_changed() { - Color font_color = vbc->get_color("font_color", "ToolButton"); - Color font_color_hover = vbc->get_color("font_color_hover", "ToolButton"); - Color font_color_pressed = vbc->get_color("font_color_pressed", "ToolButton"); + Color font_color = vbc->get_theme_color("font_color", "ToolButton"); + Color font_color_hover = vbc->get_theme_color("font_color_hover", "ToolButton"); + Color font_color_pressed = vbc->get_theme_color("font_color_pressed", "ToolButton"); - dir_up->add_color_override("icon_color_normal", font_color); - dir_up->add_color_override("icon_color_hover", font_color_hover); - dir_up->add_color_override("icon_color_pressed", font_color_pressed); + dir_up->add_theme_color_override("icon_color_normal", font_color); + dir_up->add_theme_color_override("icon_color_hover", font_color_hover); + dir_up->add_theme_color_override("icon_color_pressed", font_color_pressed); - refresh->add_color_override("icon_color_normal", font_color); - refresh->add_color_override("icon_color_hover", font_color_hover); - refresh->add_color_override("icon_color_pressed", font_color_pressed); + refresh->add_theme_color_override("icon_color_normal", font_color); + refresh->add_theme_color_override("icon_color_hover", font_color_hover); + refresh->add_theme_color_override("icon_color_pressed", font_color_pressed); - show_hidden->add_color_override("icon_color_normal", font_color); - show_hidden->add_color_override("icon_color_hover", font_color_hover); - show_hidden->add_color_override("icon_color_pressed", font_color_pressed); + show_hidden->add_theme_color_override("icon_color_normal", font_color); + show_hidden->add_theme_color_override("icon_color_hover", font_color_hover); + show_hidden->add_theme_color_override("icon_color_pressed", font_color_pressed); } void FileDialog::_notification(int p_what) { @@ -73,9 +73,9 @@ void FileDialog::_notification(int p_what) { } if (p_what == NOTIFICATION_ENTER_TREE) { - dir_up->set_icon(vbc->get_icon("parent_folder")); - refresh->set_icon(vbc->get_icon("reload")); - show_hidden->set_icon(vbc->get_icon("toggle_hidden")); + dir_up->set_icon(vbc->get_theme_icon("parent_folder")); + refresh->set_icon(vbc->get_theme_icon("reload")); + show_hidden->set_icon(vbc->get_theme_icon("toggle_hidden")); _theme_changed(); } } @@ -429,8 +429,8 @@ void FileDialog::update_file_list() { dir_access->list_dir_begin(); TreeItem *root = tree->create_item(); - Ref<Texture2D> folder = vbc->get_icon("folder"); - const Color folder_color = vbc->get_color("folder_icon_modulate"); + Ref<Texture2D> folder = vbc->get_theme_icon("folder"); + const Color folder_color = vbc->get_theme_color("folder_icon_modulate"); List<String> files; List<String> dirs; @@ -528,7 +528,7 @@ void FileDialog::update_file_list() { } if (mode == FILE_MODE_OPEN_DIR) { - ti->set_custom_color(0, vbc->get_color("files_disabled")); + ti->set_custom_color(0, vbc->get_theme_color("files_disabled")); ti->set_selectable(0, false); } Dictionary d; diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index 6345bfe562..88107f754c 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -76,15 +76,15 @@ void GradientEdit::_show_color_picker() { if (grabbed == -1) return; picker->set_pick_color(points[grabbed].color); - Size2 minsize = popup->get_combined_minimum_size(); + Size2 minsize = popup->get_contents_minimum_size(); bool show_above = false; if (get_global_position().y + get_size().y + minsize.y > get_viewport_rect().size.y) { show_above = true; } if (show_above) { - popup->set_position(get_global_position() - Vector2(0, minsize.y)); + popup->set_position(get_screen_position() - Vector2(0, minsize.y)); } else { - popup->set_position(get_global_position() + Vector2(0, get_size().y)); + popup->set_position(get_screen_position() + Vector2(0, get_size().y)); } popup->popup(); } diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index ddc80d2726..fd7935b376 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -281,13 +281,13 @@ void GraphEdit::remove_child_notify(Node *p_child) { void GraphEdit::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) { - port_grab_distance_horizontal = get_constant("port_grab_distance_horizontal"); - port_grab_distance_vertical = get_constant("port_grab_distance_vertical"); + port_grab_distance_horizontal = get_theme_constant("port_grab_distance_horizontal"); + port_grab_distance_vertical = get_theme_constant("port_grab_distance_vertical"); - zoom_minus->set_icon(get_icon("minus")); - zoom_reset->set_icon(get_icon("reset")); - zoom_plus->set_icon(get_icon("more")); - snap_button->set_icon(get_icon("snap")); + zoom_minus->set_icon(get_theme_icon("minus")); + zoom_reset->set_icon(get_theme_icon("reset")); + zoom_plus->set_icon(get_theme_icon("more")); + snap_button->set_icon(get_theme_icon("snap")); } if (p_what == NOTIFICATION_READY) { Size2 hmin = h_scroll->get_combined_minimum_size(); @@ -305,7 +305,7 @@ void GraphEdit::_notification(int p_what) { } if (p_what == NOTIFICATION_DRAW) { - draw_style_box(get_stylebox("bg"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox("bg"), Rect2(Point2(), get_size())); if (is_using_snap()) { //draw grid @@ -318,8 +318,8 @@ void GraphEdit::_notification(int p_what) { Point2i from = (offset / float(snap)).floor(); Point2i len = (size / float(snap)).floor() + Vector2(1, 1); - Color grid_minor = get_color("grid_minor"); - Color grid_major = get_color("grid_major"); + Color grid_minor = get_theme_color("grid_minor"); + Color grid_major = get_theme_color("grid_major"); for (int i = from.x; i < from.x + len.x; i++) { @@ -357,7 +357,7 @@ void GraphEdit::_notification(int p_what) { bool GraphEdit::_filter_input(const Point2 &p_point) { - Ref<Texture2D> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -389,7 +389,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseButton> mb = p_ev; if (mb.is_valid() && mb->get_button_index() == BUTTON_LEFT && mb->is_pressed()) { - Ref<Texture2D> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); Vector2 mpos(mb->get_position().x, mb->get_position().y); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -501,7 +501,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { connecting_target = false; top_layer->update(); - Ref<Texture2D> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); Vector2 mpos = mm->get_position(); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -666,8 +666,8 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const //cubic bezier code float diff = p_to.x - p_from.x; float cp_offset; - int cp_len = get_constant("bezier_len_pos"); - int cp_neg_len = get_constant("bezier_len_neg"); + int cp_len = get_theme_constant("bezier_len_pos"); + int cp_neg_len = get_theme_constant("bezier_len_neg"); if (diff > 0) { cp_offset = MIN(cp_len, diff * 0.5); @@ -697,7 +697,7 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const void GraphEdit::_connections_layer_draw() { - Color activity_color = get_color("activity"); + Color activity_color = get_theme_color("activity"); //draw connections List<List<Connection>::Element *> to_erase; for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { @@ -784,8 +784,8 @@ void GraphEdit::_top_layer_draw() { } if (box_selecting) { - top_layer->draw_rect(box_selecting_rect, get_color("selection_fill")); - top_layer->draw_rect(box_selecting_rect, get_color("selection_stroke"), false); + top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_fill")); + top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_stroke"), false); } } diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 82e890395a..c28a60ff87 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -117,8 +117,8 @@ void GraphNode::_get_property_list(List<PropertyInfo> *p_list) const { void GraphNode::_resort() { - int sep = get_constant("separation"); - Ref<StyleBox> sb = get_stylebox("frame"); + int sep = get_theme_constant("separation"); + Ref<StyleBox> sb = get_theme_stylebox("frame"); bool first = true; Size2 minsize; @@ -169,8 +169,8 @@ void GraphNode::_resort() { bool GraphNode::has_point(const Point2 &p_point) const { if (comment) { - Ref<StyleBox> comment = get_stylebox("comment"); - Ref<Texture2D> resizer = get_icon("resizer"); + Ref<StyleBox> comment = get_theme_stylebox("comment"); + Ref<Texture2D> resizer = get_theme_icon("resizer"); if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) { return true; @@ -195,28 +195,28 @@ void GraphNode::_notification(int p_what) { Ref<StyleBox> sb; if (comment) { - sb = get_stylebox(selected ? "commentfocus" : "comment"); + sb = get_theme_stylebox(selected ? "commentfocus" : "comment"); } else { - sb = get_stylebox(selected ? "selectedframe" : "frame"); + sb = get_theme_stylebox(selected ? "selectedframe" : "frame"); } //sb=sb->duplicate(); //sb->call("set_modulate",modulate); - Ref<Texture2D> port = get_icon("port"); - Ref<Texture2D> close = get_icon("close"); - Ref<Texture2D> resizer = get_icon("resizer"); - int close_offset = get_constant("close_offset"); - int close_h_offset = get_constant("close_h_offset"); - Color close_color = get_color("close_color"); - Color resizer_color = get_color("resizer_color"); - Ref<Font> title_font = get_font("title_font"); - int title_offset = get_constant("title_offset"); - int title_h_offset = get_constant("title_h_offset"); - Color title_color = get_color("title_color"); + Ref<Texture2D> port = get_theme_icon("port"); + Ref<Texture2D> close = get_theme_icon("close"); + Ref<Texture2D> resizer = get_theme_icon("resizer"); + int close_offset = get_theme_constant("close_offset"); + int close_h_offset = get_theme_constant("close_h_offset"); + Color close_color = get_theme_color("close_color"); + Color resizer_color = get_theme_color("resizer_color"); + Ref<Font> title_font = get_theme_font("title_font"); + int title_offset = get_theme_constant("title_offset"); + int title_h_offset = get_theme_constant("title_h_offset"); + Color title_color = get_theme_color("title_color"); Point2i icofs = -port->get_size() * 0.5; - int edgeofs = get_constant("port_offset"); + int edgeofs = get_theme_constant("port_offset"); icofs.y += sb->get_margin(MARGIN_TOP); draw_style_box(sb, Rect2(Point2(), get_size())); @@ -227,10 +227,10 @@ void GraphNode::_notification(int p_what) { } break; case OVERLAY_BREAKPOINT: { - draw_style_box(get_stylebox("breakpoint"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox("breakpoint"), Rect2(Point2(), get_size())); } break; case OVERLAY_POSITION: { - draw_style_box(get_stylebox("position"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox("position"), Rect2(Point2(), get_size())); } break; } @@ -370,16 +370,16 @@ Color GraphNode::get_slot_color_right(int p_idx) const { Size2 GraphNode::get_minimum_size() const { - Ref<Font> title_font = get_font("title_font"); + Ref<Font> title_font = get_theme_font("title_font"); - int sep = get_constant("separation"); - Ref<StyleBox> sb = get_stylebox("frame"); + int sep = get_theme_constant("separation"); + Ref<StyleBox> sb = get_theme_stylebox("frame"); bool first = true; Size2 minsize; minsize.x = title_font->get_string_size(title).x; if (show_close) { - Ref<Texture2D> close = get_icon("close"); + Ref<Texture2D> close = get_theme_icon("close"); minsize.x += sep + close->get_width(); } @@ -464,10 +464,10 @@ bool GraphNode::is_close_button_visible() const { void GraphNode::_connpos_update() { - int edgeofs = get_constant("port_offset"); - int sep = get_constant("separation"); + int edgeofs = get_theme_constant("port_offset"); + int sep = get_theme_constant("separation"); - Ref<StyleBox> sb = get_stylebox("frame"); + Ref<StyleBox> sb = get_theme_stylebox("frame"); conn_input_cache.clear(); conn_output_cache.clear(); int vofs = 0; @@ -606,7 +606,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { return; } - Ref<Texture2D> resizer = get_icon("resizer"); + Ref<Texture2D> resizer = get_theme_icon("resizer"); if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) { diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index 0028093a95..16f6fd0111 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -41,8 +41,8 @@ void GridContainer::_notification(int p_what) { Set<int> col_expanded; // Columns which have the SIZE_EXPAND flag set. Set<int> row_expanded; // Rows which have the SIZE_EXPAND flag set. - int hsep = get_constant("hseparation"); - int vsep = get_constant("vseparation"); + int hsep = get_theme_constant("hseparation"); + int vsep = get_theme_constant("vseparation"); int max_col = MIN(get_child_count(), columns); int max_row = ceil((float)get_child_count() / (float)columns); @@ -200,8 +200,8 @@ Size2 GridContainer::get_minimum_size() const { Map<int, int> col_minw; Map<int, int> row_minh; - int hsep = get_constant("hseparation"); - int vsep = get_constant("vseparation"); + int hsep = get_theme_constant("hseparation"); + int vsep = get_theme_constant("vseparation"); int max_row = 0; int max_col = 0; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 5e662b8df0..2db44d0b66 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -495,7 +495,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { search_string = ""; //any mousepress cancels Vector2 pos = mb->get_position(); - Ref<StyleBox> bg = get_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); @@ -820,7 +820,7 @@ void ItemList::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> bg = get_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); int mw = scroll_bar->get_minimum_size().x; scroll_bar->set_anchor_and_margin(MARGIN_LEFT, ANCHOR_END, -mw); @@ -837,18 +837,18 @@ void ItemList::_notification(int p_what) { draw_style_box(bg, Rect2(Point2(), size)); - int hseparation = get_constant("hseparation"); - int vseparation = get_constant("vseparation"); - int icon_margin = get_constant("icon_margin"); - int line_separation = get_constant("line_separation"); + int hseparation = get_theme_constant("hseparation"); + int vseparation = get_theme_constant("vseparation"); + int icon_margin = get_theme_constant("icon_margin"); + int line_separation = get_theme_constant("line_separation"); - Ref<StyleBox> sbsel = has_focus() ? get_stylebox("selected_focus") : get_stylebox("selected"); - Ref<StyleBox> cursor = has_focus() ? get_stylebox("cursor") : get_stylebox("cursor_unfocused"); + Ref<StyleBox> sbsel = has_focus() ? get_theme_stylebox("selected_focus") : get_theme_stylebox("selected"); + Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox("cursor") : get_theme_stylebox("cursor_unfocused"); - Ref<Font> font = get_font("font"); - Color guide_color = get_color("guide_color"); - Color font_color = get_color("font_color"); - Color font_color_selected = get_color("font_color_selected"); + Ref<Font> font = get_theme_font("font"); + Color guide_color = get_theme_color("guide_color"); + Color font_color = get_theme_color("font_color"); + Color font_color_selected = get_theme_color("font_color_selected"); int font_height = font->get_height(); Vector<int> line_size_cache; Vector<int> line_limit_cache; @@ -860,7 +860,7 @@ void ItemList::_notification(int p_what) { if (has_focus()) { VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true); - draw_style_box(get_stylebox("bg_focus"), Rect2(Point2(), size)); + draw_style_box(get_theme_stylebox("bg_focus"), Rect2(Point2(), size)); VisualServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false); } @@ -1251,7 +1251,7 @@ void ItemList::_scroll_changed(double) { int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const { Vector2 pos = p_pos; - Ref<StyleBox> bg = get_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); @@ -1286,7 +1286,7 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const { return true; Vector2 pos = p_pos; - Ref<StyleBox> bg = get_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index c900b35d65..ef1bb958f6 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -65,7 +65,7 @@ bool Label::is_uppercase() const { int Label::get_line_height() const { - return get_font("font")->get_height(); + return get_theme_font("font")->get_height(); } void Label::_notification(int p_what) { @@ -94,14 +94,14 @@ void Label::_notification(int p_what) { Size2 string_size; Size2 size = get_size(); - Ref<StyleBox> style = get_stylebox("normal"); - Ref<Font> font = get_font("font"); - Color font_color = get_color("font_color"); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); - int line_spacing = get_constant("line_spacing"); - Color font_outline_modulate = get_color("font_outline_modulate"); + Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<Font> font = get_theme_font("font"); + Color font_color = get_theme_color("font_color"); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); + int line_spacing = get_theme_constant("line_spacing"); + Color font_outline_modulate = get_theme_color("font_outline_modulate"); style->draw(ci, Rect2(Point2(0, 0), get_size())); @@ -300,7 +300,7 @@ void Label::_notification(int p_what) { Size2 Label::get_minimum_size() const { - Size2 min_style = get_stylebox("normal")->get_minimum_size(); + Size2 min_style = get_theme_stylebox("normal")->get_minimum_size(); // don't want to mutable everything if (word_cache_dirty) { @@ -319,7 +319,7 @@ Size2 Label::get_minimum_size() const { int Label::get_longest_line_width() const { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); real_t max_line_width = 0; real_t line_width = 0; @@ -363,9 +363,9 @@ int Label::get_line_count() const { int Label::get_visible_line_count() const { - int line_spacing = get_constant("line_spacing"); - int font_h = get_font("font")->get_height() + line_spacing; - int lines_visible = (get_size().height - get_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h; + int line_spacing = get_theme_constant("line_spacing"); + int font_h = get_theme_font("font")->get_height() + line_spacing; + int lines_visible = (get_size().height - get_theme_stylebox("normal")->get_minimum_size().height + line_spacing) / font_h; if (lines_visible > line_count) lines_visible = line_count; @@ -387,20 +387,20 @@ void Label::regenerate_word_cache() { int width; if (autowrap) { - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); width = MAX(get_size().width, get_custom_minimum_size().width) - style->get_minimum_size().width; } else { width = get_longest_line_width(); } - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); real_t current_word_size = 0; int word_pos = 0; real_t line_width = 0; int space_count = 0; real_t space_width = font->get_char_size(' ').width; - int line_spacing = get_constant("line_spacing"); + int line_spacing = get_theme_constant("line_spacing"); line_count = 1; total_char_cache = 0; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 0bbb82db91..fd82c33c4e 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -56,7 +56,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (b->is_pressed() && b->get_button_index() == BUTTON_RIGHT && context_menu_enabled) { menu->set_position(get_global_transform().xform(get_local_mouse_position())); menu->set_size(Vector2(1, 1)); - menu->set_scale(get_global_transform().get_scale()); + //menu->set_scale(get_global_transform().get_scale()); menu->popup(); grab_focus(); accept_event(); @@ -552,10 +552,10 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { } break; case KEY_MENU: { if (context_menu_enabled) { - Point2 pos = Point2(get_cursor_pixel_pos(), (get_size().y + get_font("font")->get_height()) / 2); + Point2 pos = Point2(get_cursor_pixel_pos(), (get_size().y + get_theme_font("font")->get_height()) / 2); menu->set_position(get_global_transform().xform(pos)); menu->set_size(Vector2(1, 1)); - menu->set_scale(get_global_transform().get_scale()); + // menu->set_scale(get_global_transform().get_scale()); menu->popup(); menu->grab_focus(); } @@ -629,7 +629,7 @@ void LineEdit::drop_data(const Point2 &p_point, const Variant &p_data) { set_cursor_at_pixel_pos(p_point.x); int selected = selection.end - selection.begin; - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); if (font != NULL) { for (int i = selection.begin; i < selection.end; i++) cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width; @@ -654,8 +654,8 @@ bool LineEdit::_is_over_clear_button(const Point2 &p_pos) const { if (!clear_button_enabled || !has_point(p_pos)) { return false; } - Ref<Texture2D> icon = Control::get_icon("clear"); - int x_ofs = get_stylebox("normal")->get_offset().x; + Ref<Texture2D> icon = Control::get_theme_icon("clear"); + int x_ofs = get_theme_stylebox("normal")->get_offset().x; return p_pos.x > get_size().width - icon->get_width() - x_ofs; } @@ -709,19 +709,19 @@ void LineEdit::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); if (!is_editable()) { - style = get_stylebox("read_only"); + style = get_theme_stylebox("read_only"); draw_caret = false; } - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); style->draw(ci, Rect2(Point2(), size)); if (has_focus()) { - get_stylebox("focus")->draw(ci, Rect2(Point2(), size)); + get_theme_stylebox("focus")->draw(ci, Rect2(Point2(), size)); } int x_ofs = 0; @@ -756,10 +756,10 @@ void LineEdit::_notification(int p_what) { int font_ascent = font->get_ascent(); - Color selection_color = get_color("selection_color"); - Color font_color = is_editable() ? get_color("font_color") : get_color("font_color_uneditable"); - Color font_color_selected = get_color("font_color_selected"); - Color cursor_color = get_color("cursor_color"); + Color selection_color = get_theme_color("selection_color"); + Color font_color = is_editable() ? get_theme_color("font_color") : get_theme_color("font_color_uneditable"); + Color font_color_selected = get_theme_color("font_color_selected"); + Color cursor_color = get_theme_color("cursor_color"); const String &t = using_placeholder ? placeholder_translated : text; // Draw placeholder color. @@ -768,13 +768,13 @@ void LineEdit::_notification(int p_what) { bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; Color color_icon(1, 1, 1, !is_editable() ? .5 * .9 : .9); if (display_clear_icon) { if (clear_button_status.press_attempt && clear_button_status.pressing_inside) { - color_icon = get_color("clear_button_color_pressed"); + color_icon = get_theme_color("clear_button_color_pressed"); } else { - color_icon = get_color("clear_button_color"); + color_icon = get_theme_color("clear_button_color"); } } @@ -1054,13 +1054,13 @@ void LineEdit::shift_selection_check_post(bool p_shift) { void LineEdit::set_cursor_at_pixel_pos(int p_x) { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); int ofs = window_pos; - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); int pixel_ofs = 0; Size2 size = get_size(); bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled; - int r_icon_width = Control::get_icon("clear")->get_width(); + int r_icon_width = Control::get_theme_icon("clear")->get_width(); switch (align) { @@ -1108,13 +1108,13 @@ void LineEdit::set_cursor_at_pixel_pos(int p_x) { int LineEdit::get_cursor_pixel_pos() { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); int ofs = window_pos; - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); int pixel_ofs = 0; Size2 size = get_size(); bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled; - int r_icon_width = Control::get_icon("clear")->get_width(); + int r_icon_width = Control::get_theme_icon("clear")->get_width(); switch (align) { @@ -1201,7 +1201,7 @@ void LineEdit::delete_char() { if ((text.length() <= 0) || (cursor_pos == 0)) return; - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); if (font != NULL) { cached_width -= font->get_char_size(pass ? secret_character[0] : text[cursor_pos - 1]).width; } @@ -1220,7 +1220,7 @@ void LineEdit::delete_char() { void LineEdit::delete_text(int p_from_column, int p_to_column) { if (text.size() > 0) { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); if (font != NULL) { for (int i = p_from_column; i < p_to_column; i++) cached_width -= font->get_char_size(pass ? secret_character[0] : text[i]).width; @@ -1318,8 +1318,8 @@ void LineEdit::set_cursor_position(int p_pos) { return; } - Ref<StyleBox> style = get_stylebox("normal"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<Font> font = get_theme_font("font"); if (cursor_pos <= window_pos) { // Adjust window if cursor goes too much to the left. @@ -1329,7 +1329,7 @@ void LineEdit::set_cursor_position(int p_pos) { int window_width = get_size().width - style->get_minimum_size().width; bool display_clear_icon = !text.empty() && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; window_width -= r_icon->get_width(); } @@ -1404,14 +1404,14 @@ void LineEdit::clear_internal() { Size2 LineEdit::get_minimum_size() const { - Ref<StyleBox> style = get_stylebox("normal"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<Font> font = get_theme_font("font"); Size2 min_size; // Minimum size of text. int space_size = font->get_char_size(' ').x; - min_size.width = get_constant("minimum_spaces") * space_size; + min_size.width = get_theme_constant("minimum_spaces") * space_size; if (expand_to_text_length) { // Add a space because some fonts are too exact, and because cursor needs a bit more when at the end. @@ -1422,8 +1422,8 @@ Size2 LineEdit::get_minimum_size() const { // Take icons into account. if (!text.empty() && is_editable() && clear_button_enabled) { - min_size.width = MAX(min_size.width, Control::get_icon("clear")->get_width()); - min_size.height = MAX(min_size.height, Control::get_icon("clear")->get_height()); + min_size.width = MAX(min_size.width, Control::get_theme_icon("clear")->get_width()); + min_size.height = MAX(min_size.height, Control::get_theme_icon("clear")->get_height()); } if (right_icon.is_valid()) { min_size.width = MAX(min_size.width, right_icon->get_width()); @@ -1702,7 +1702,7 @@ void LineEdit::_emit_text_change() { } void LineEdit::update_cached_width() { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); cached_width = 0; if (font != NULL) { String text = get_text(); @@ -1713,7 +1713,7 @@ void LineEdit::update_cached_width() { } void LineEdit::update_placeholder_width() { - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); cached_placeholder_width = 0; if (font != NULL) { for (int i = 0; i < placeholder_translated.length(); i++) { diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index 4b8054bac6..3dffa06b49 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -54,7 +54,7 @@ LinkButton::UnderlineMode LinkButton::get_underline_mode() const { Size2 LinkButton::get_minimum_size() const { - return get_font("font")->get_string_size(text); + return get_theme_font("font")->get_string_size(text); } void LinkButton::_notification(int p_what) { @@ -72,29 +72,29 @@ void LinkButton::_notification(int p_what) { case DRAW_NORMAL: { - color = get_color("font_color"); + color = get_theme_color("font_color"); do_underline = underline_mode == UNDERLINE_MODE_ALWAYS; } break; case DRAW_HOVER_PRESSED: case DRAW_PRESSED: { - if (has_color("font_color_pressed")) - color = get_color("font_color_pressed"); + if (has_theme_color("font_color_pressed")) + color = get_theme_color("font_color_pressed"); else - color = get_color("font_color"); + color = get_theme_color("font_color"); do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; case DRAW_HOVER: { - color = get_color("font_color_hover"); + color = get_theme_color("font_color_hover"); do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; case DRAW_DISABLED: { - color = get_color("font_color_disabled"); + color = get_theme_color("font_color_disabled"); do_underline = underline_mode == UNDERLINE_MODE_ALWAYS; } break; @@ -102,16 +102,16 @@ void LinkButton::_notification(int p_what) { if (has_focus()) { - Ref<StyleBox> style = get_stylebox("focus"); + Ref<StyleBox> style = get_theme_stylebox("focus"); style->draw(ci, Rect2(Point2(), size)); } - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); draw_string(font, Vector2(0, font->get_ascent()), text, color); if (do_underline) { - int underline_spacing = get_constant("underline_spacing"); + int underline_spacing = get_theme_constant("underline_spacing"); int width = font->get_string_size(text).width; int y = font->get_ascent() + underline_spacing; diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp index 53373fc297..1cd4ff4ff8 100644 --- a/scene/gui/margin_container.cpp +++ b/scene/gui/margin_container.cpp @@ -32,10 +32,10 @@ Size2 MarginContainer::get_minimum_size() const { - int margin_left = get_constant("margin_left"); - int margin_top = get_constant("margin_top"); - int margin_right = get_constant("margin_right"); - int margin_bottom = get_constant("margin_bottom"); + int margin_left = get_theme_constant("margin_left"); + int margin_top = get_theme_constant("margin_top"); + int margin_right = get_theme_constant("margin_right"); + int margin_bottom = get_theme_constant("margin_bottom"); Size2 max; @@ -67,10 +67,10 @@ void MarginContainer::_notification(int p_what) { switch (p_what) { case NOTIFICATION_SORT_CHILDREN: { - int margin_left = get_constant("margin_left"); - int margin_top = get_constant("margin_top"); - int margin_right = get_constant("margin_right"); - int margin_bottom = get_constant("margin_bottom"); + int margin_left = get_theme_constant("margin_left"); + int margin_top = get_theme_constant("margin_top"); + int margin_right = get_theme_constant("margin_right"); + int margin_bottom = get_theme_constant("margin_bottom"); Size2 s = get_size(); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 7f2ea7d3ed..4cae7b8f40 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -52,14 +52,13 @@ void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) { void MenuButton::pressed() { - emit_signal("about_to_show"); + emit_signal("about_to_popup"); Size2 size = get_size(); - Point2 gp = get_global_position(); - popup->set_global_position(gp + Size2(0, size.height * get_global_transform().get_scale().y)); + Point2 gp = get_screen_position(); + popup->set_position(gp + Size2(0, size.height * get_global_transform().get_scale().y)); popup->set_size(Size2(size.width, 0)); - popup->set_scale(get_global_transform().get_scale()); - popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_position()), get_size())); + popup->set_parent_rect(Rect2(Point2(gp - popup->get_position()), get_size())); popup->popup(); } @@ -116,7 +115,7 @@ void MenuButton::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "switch_on_hover"), "set_switch_on_hover", "is_switch_on_hover"); - ADD_SIGNAL(MethodInfo("about_to_show")); + ADD_SIGNAL(MethodInfo("about_to_popup")); } void MenuButton::set_disable_shortcuts(bool p_disabled) { @@ -137,8 +136,7 @@ MenuButton::MenuButton() { popup = memnew(PopupMenu); popup->hide(); add_child(popup); - popup->set_pass_on_modal_close_click(false); - popup->connect("about_to_show", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); // For when switching from another MenuButton. + popup->connect("about_to_popup", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(true)); // For when switching from another MenuButton. popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false)); } diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index c185761beb..30ecd651b1 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -36,12 +36,12 @@ Size2 OptionButton::get_minimum_size() const { Size2 minsize = Button::get_minimum_size(); - if (has_icon("arrow")) { - const Size2 padding = get_stylebox("normal")->get_minimum_size(); - const Size2 arrow_size = Control::get_icon("arrow")->get_size(); + if (has_theme_icon("arrow")) { + const Size2 padding = get_theme_stylebox("normal")->get_minimum_size(); + const Size2 arrow_size = Control::get_theme_icon("arrow")->get_size(); Size2 content_size = minsize - padding; - content_size.width += arrow_size.width + get_constant("hseparation"); + content_size.width += arrow_size.width + get_theme_constant("hseparation"); content_size.height = MAX(content_size.height, arrow_size.height); minsize = content_size + padding; @@ -55,37 +55,37 @@ void OptionButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (!has_icon("arrow")) + if (!has_theme_icon("arrow")) return; RID ci = get_canvas_item(); - Ref<Texture2D> arrow = Control::get_icon("arrow"); + Ref<Texture2D> arrow = Control::get_theme_icon("arrow"); Color clr = Color(1, 1, 1); - if (get_constant("modulate_arrow")) { + if (get_theme_constant("modulate_arrow")) { switch (get_draw_mode()) { case DRAW_PRESSED: - clr = get_color("font_color_pressed"); + clr = get_theme_color("font_color_pressed"); break; case DRAW_HOVER: - clr = get_color("font_color_hover"); + clr = get_theme_color("font_color_hover"); break; case DRAW_DISABLED: - clr = get_color("font_color_disabled"); + clr = get_theme_color("font_color_disabled"); break; default: - clr = get_color("font_color"); + clr = get_theme_color("font_color"); } } Size2 size = get_size(); - Point2 ofs(size.width - arrow->get_width() - get_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2))); + Point2 ofs(size.width - arrow->get_width() - get_theme_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2))); arrow->draw(ci, ofs, clr); } break; case NOTIFICATION_THEME_CHANGED: { - if (has_icon("arrow")) { - _set_internal_margin(MARGIN_RIGHT, Control::get_icon("arrow")->get_width()); + if (has_theme_icon("arrow")) { + _set_internal_margin(MARGIN_RIGHT, Control::get_theme_icon("arrow")->get_width()); } } break; case NOTIFICATION_VISIBILITY_CHANGED: { @@ -109,9 +109,8 @@ void OptionButton::_selected(int p_which) { void OptionButton::pressed() { Size2 size = get_size(); - popup->set_global_position(get_global_position() + Size2(0, size.height * get_global_transform().get_scale().y)); + popup->set_position(get_screen_position() + Size2(0, size.height * get_global_transform().get_scale().y)); popup->set_size(Size2(size.width, 0)); - popup->set_scale(get_global_transform().get_scale()); popup->popup(); } @@ -351,15 +350,15 @@ OptionButton::OptionButton() { set_toggle_mode(true); set_text_align(ALIGN_LEFT); set_action_mode(ACTION_MODE_BUTTON_PRESS); - if (has_icon("arrow")) { - _set_internal_margin(MARGIN_RIGHT, Control::get_icon("arrow")->get_width()); + if (has_theme_icon("arrow")) { + _set_internal_margin(MARGIN_RIGHT, Control::get_theme_icon("arrow")->get_width()); } popup = memnew(PopupMenu); popup->hide(); add_child(popup); - popup->set_pass_on_modal_close_click(false); - popup->set_notify_transform(true); + // popup->set_pass_on_modal_close_click(false); + // popup->set_notify_transform(true); popup->set_allow_search(true); popup->connect("index_pressed", callable_mp(this, &OptionButton::_selected)); popup->connect("id_focused", callable_mp(this, &OptionButton::_focused)); diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index 1957e4f271..ae51463a15 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -36,7 +36,7 @@ void Panel::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { RID ci = get_canvas_item(); - Ref<StyleBox> style = mode == MODE_BACKGROUND ? get_stylebox("panel") : get_stylebox("panel_fg"); + Ref<StyleBox> style = mode == MODE_BACKGROUND ? get_theme_stylebox("panel") : get_theme_stylebox("panel_fg"); style->draw(ci, Rect2(Point2(), get_size())); } } diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp index 6cf23b8a32..dc9daf3c91 100644 --- a/scene/gui/panel_container.cpp +++ b/scene/gui/panel_container.cpp @@ -34,10 +34,10 @@ Size2 PanelContainer::get_minimum_size() const { Ref<StyleBox> style; - if (has_stylebox("panel")) - style = get_stylebox("panel"); + if (has_theme_stylebox("panel")) + style = get_theme_stylebox("panel"); else - style = get_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox("panel", "PanelContainer"); Size2 ms; for (int i = 0; i < get_child_count(); i++) { @@ -65,10 +65,10 @@ void PanelContainer::_notification(int p_what) { RID ci = get_canvas_item(); Ref<StyleBox> style; - if (has_stylebox("panel")) - style = get_stylebox("panel"); + if (has_theme_stylebox("panel")) + style = get_theme_stylebox("panel"); else - style = get_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox("panel", "PanelContainer"); style->draw(ci, Rect2(Point2(), get_size())); } @@ -77,10 +77,10 @@ void PanelContainer::_notification(int p_what) { Ref<StyleBox> style; - if (has_stylebox("panel")) - style = get_stylebox("panel"); + if (has_theme_stylebox("panel")) + style = get_theme_stylebox("panel"); else - style = get_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox("panel", "PanelContainer"); Size2 size = get_size(); Point2 ofs; diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 6896d5d609..4ed87ff42f 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -32,227 +32,100 @@ #include "core/engine.h" #include "core/os/keyboard.h" +#include "scene/gui/panel.h" -void Popup::_gui_input(Ref<InputEvent> p_event) { -} - -void Popup::_notification(int p_what) { - - if (p_what == NOTIFICATION_VISIBILITY_CHANGED) { - if (popped_up && !is_visible_in_tree()) { - popped_up = false; - notification(NOTIFICATION_POPUP_HIDE); - emit_signal("popup_hide"); - } - - update_configuration_warning(); - } - - if (p_what == NOTIFICATION_EXIT_TREE) { - if (popped_up) { - popped_up = false; - notification(NOTIFICATION_POPUP_HIDE); - emit_signal("popup_hide"); - } - } - - if (p_what == NOTIFICATION_ENTER_TREE) { -//small helper to make editing of these easier in editor -#ifdef TOOLS_ENABLED - if (Engine::get_singleton()->is_editor_hint() && get_tree()->get_edited_scene_root() && get_tree()->get_edited_scene_root()->is_a_parent_of(this)) { - //edited on editor - set_as_toplevel(false); - } else -#endif - if (is_visible()) { - hide(); - } +void Popup::_input_from_window(const Ref<InputEvent> &p_event) { + Ref<InputEventKey> key = p_event; + if (key.is_valid() && key->is_pressed() && key->get_keycode() == KEY_ESCAPE) { + _close_pressed(); } } -void Popup::_fix_size() { - - Point2 pos = get_global_position(); - Size2 size = get_size() * get_scale(); - Point2 window_size = get_viewport_rect().size - get_viewport_transform().get_origin(); - - if (pos.x + size.width > window_size.width) - pos.x = window_size.width - size.width; - if (pos.x < 0) - pos.x = 0; - - if (pos.y + size.height > window_size.height) - pos.y = window_size.height - size.height; - if (pos.y < 0) - pos.y = 0; - if (pos != get_position()) - set_global_position(pos); +void Popup::_parent_focused() { + _close_pressed(); } +void Popup::_notification(int p_what) { -void Popup::set_as_minsize() { - - Size2 total_minsize; - - for (int i = 0; i < get_child_count(); i++) { - - Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) - continue; - if (!c->is_visible()) - continue; - - Size2 minsize = c->get_combined_minimum_size(); - - for (int j = 0; j < 2; j++) { - - Margin m_beg = Margin(0 + j); - Margin m_end = Margin(2 + j); - - float margin_begin = c->get_margin(m_beg); - float margin_end = c->get_margin(m_end); - float anchor_begin = c->get_anchor(m_beg); - float anchor_end = c->get_anchor(m_end); - - minsize[j] += margin_begin * (ANCHOR_END - anchor_begin) + margin_end * anchor_end; - } - - total_minsize.width = MAX(total_minsize.width, minsize.width); - total_minsize.height = MAX(total_minsize.height, minsize.height); + switch (p_what) { + case NOTIFICATION_VISIBILITY_CHANGED: { + if (is_visible()) { + + parent_visible = get_parent_visible_window(); + if (parent_visible) { + parent_visible->connect("focus_entered", callable_mp(this, &Popup::_parent_focused)); + } + } else { + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused)); + parent_visible = nullptr; + } + + emit_signal("popup_hide"); + } + + } break; + case NOTIFICATION_EXIT_TREE: { + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused)); + parent_visible = nullptr; + } + } break; + case NOTIFICATION_WM_CLOSE_REQUEST: { + _close_pressed(); + } break; } - - set_size(total_minsize); -} - -void Popup::popup_centered_clamped(const Size2 &p_size, float p_fallback_ratio) { - - Size2 popup_size = p_size; - Size2 window_size = get_viewport_rect().size; - - // clamp popup size in each dimension if window size is too small (using fallback ratio) - popup_size.x = MIN(window_size.x * p_fallback_ratio, popup_size.x); - popup_size.y = MIN(window_size.y * p_fallback_ratio, popup_size.y); - - popup_centered_size(popup_size); -} - -void Popup::popup_centered_minsize(const Size2 &p_minsize) { - - set_custom_minimum_size(p_minsize); - _fix_size(); - popup_centered_size(); -} - -void Popup::popup_centered_size(const Size2 &p_size) { - - Rect2 rect; - Size2 window_size = get_viewport_rect().size; - rect.size = p_size == Size2() ? get_size() : p_size; - rect.position = ((window_size - rect.size) / 2.0).floor(); - - _popup(rect, true); } -void Popup::popup_centered_ratio(float p_screen_ratio) { - - Rect2 rect; - Size2 window_size = get_viewport_rect().size; - rect.size = (window_size * p_screen_ratio).floor(); - rect.position = ((window_size - rect.size) / 2.0).floor(); - - _popup(rect, true); -} - -void Popup::popup(const Rect2 &p_bounds) { - - _popup(p_bounds); -} - -void Popup::_popup(const Rect2 &p_bounds, const bool p_centered) { - - emit_signal("about_to_show"); - show_modal(exclusive); - - // Fit the popup into the optionally provided bounds. - if (!p_bounds.has_no_area()) { - set_size(p_bounds.size); +void Popup::_close_pressed() { - // check if p_bounds.size was using an outdated cached values - if (p_centered && p_bounds.size != get_size()) { - set_position(p_bounds.position - ((get_size() - p_bounds.size) / 2.0).floor()); - } else { - set_position(p_bounds.position); - } + Window *parent_window = parent_visible; + if (parent_visible) { + parent_visible->disconnect("focus_entered", callable_mp(this, &Popup::_parent_focused)); + parent_visible = nullptr; } - _fix_size(); - - Control *focusable = find_next_valid_focus(); - if (focusable) - focusable->grab_focus(); - - _post_popup(); - notification(NOTIFICATION_POST_POPUP); - popped_up = true; -} + call_deferred("hide"); -void Popup::set_exclusive(bool p_exclusive) { + emit_signal("cancelled"); - exclusive = p_exclusive; + if (parent_window) { + //parent_window->grab_focus(); + } } -bool Popup::is_exclusive() const { - - return exclusive; +void Popup::set_as_minsize() { + set_size(get_contents_minimum_size()); } - void Popup::_bind_methods() { - ClassDB::bind_method(D_METHOD("set_as_minsize"), &Popup::set_as_minsize); - ClassDB::bind_method(D_METHOD("popup_centered_size", "size"), &Popup::popup_centered_size, DEFVAL(Size2())); - ClassDB::bind_method(D_METHOD("popup_centered_ratio", "ratio"), &Popup::popup_centered_ratio, DEFVAL(0.75)); - ClassDB::bind_method(D_METHOD("popup_centered_minsize", "minsize"), &Popup::popup_centered_minsize, DEFVAL(Size2())); - ClassDB::bind_method(D_METHOD("popup_centered_clamped", "size", "fallback_ratio"), &Popup::popup_centered_clamped, DEFVAL(Size2()), DEFVAL(0.75)); - ClassDB::bind_method(D_METHOD("popup", "bounds"), &Popup::popup, DEFVAL(Rect2())); - ClassDB::bind_method(D_METHOD("set_exclusive", "enable"), &Popup::set_exclusive); - ClassDB::bind_method(D_METHOD("is_exclusive"), &Popup::is_exclusive); - ADD_SIGNAL(MethodInfo("about_to_show")); ADD_SIGNAL(MethodInfo("popup_hide")); - ADD_GROUP("Popup", "popup_"); - ADD_PROPERTY(PropertyInfo(Variant::BOOL, "popup_exclusive"), "set_exclusive", "is_exclusive"); - - BIND_CONSTANT(NOTIFICATION_POST_POPUP); - BIND_CONSTANT(NOTIFICATION_POPUP_HIDE); } Popup::Popup() { - set_as_toplevel(true); - exclusive = false; - popped_up = false; - hide(); -} + parent_visible = nullptr; -String Popup::get_configuration_warning() const { + set_wrap_controls(true); + set_visible(false); + set_transient(true); + set_flag(FLAG_BORDERLESS, true); + set_flag(FLAG_RESIZE_DISABLED, true); - if (is_visible_in_tree()) { - return TTR("Popups will hide by default unless you call popup() or any of the popup*() functions. Making them visible for editing is fine, but they will hide upon running."); - } - - return String(); + connect("window_input", callable_mp(this, &Popup::_input_from_window)); } Popup::~Popup() { } -Size2 PopupPanel::get_minimum_size() const { +Size2 PopupPanel::_get_contents_minimum_size() const { - Ref<StyleBox> p = get_stylebox("panel"); + Ref<StyleBox> p = get_theme_stylebox("panel", "PopupPanel"); Size2 ms; for (int i = 0; i < get_child_count(); i++) { Control *c = Object::cast_to<Control>(get_child(i)); - if (!c) + if (!c || c == panel) continue; if (c->is_set_as_toplevel()) @@ -268,7 +141,7 @@ Size2 PopupPanel::get_minimum_size() const { void PopupPanel::_update_child_rects() { - Ref<StyleBox> p = get_stylebox("panel"); + Ref<StyleBox> p = get_theme_stylebox("panel", "PopupPanel"); Vector2 cpos(p->get_offset()); Vector2 csize(get_size() - p->get_minimum_size()); @@ -281,24 +154,30 @@ void PopupPanel::_update_child_rects() { if (c->is_set_as_toplevel()) continue; - c->set_position(cpos); - c->set_size(csize); + if (c == panel) { + c->set_position(Vector2()); + c->set_size(get_size()); + } else { + c->set_position(cpos); + c->set_size(csize); + } } } void PopupPanel::_notification(int p_what) { - if (p_what == NOTIFICATION_DRAW) { - - get_stylebox("panel")->draw(get_canvas_item(), Rect2(Point2(), get_size())); - } else if (p_what == NOTIFICATION_READY) { + if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_ENTER_TREE) { + panel->add_theme_style_override("panel", get_theme_stylebox("panel", "PopupPanel")); _update_child_rects(); - } else if (p_what == NOTIFICATION_RESIZED) { + } else if (p_what == NOTIFICATION_WM_SIZE_CHANGED) { _update_child_rects(); } } PopupPanel::PopupPanel() { + + panel = memnew(Panel); + add_child(panel); } diff --git a/scene/gui/popup.h b/scene/gui/popup.h index fc4158d41c..20b355bc18 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -31,44 +31,24 @@ #ifndef POPUP_H #define POPUP_H -#include "scene/gui/control.h" +#include "scene/main/window.h" -class Popup : public Control { +class Popup : public Window { - GDCLASS(Popup, Control); + GDCLASS(Popup, Window); - bool exclusive; - bool popped_up; + Window *parent_visible; -private: - void _popup(const Rect2 &p_bounds = Rect2(), const bool p_centered = false); + void _input_from_window(const Ref<InputEvent> &p_event); + void _parent_focused(); + void _close_pressed(); protected: - virtual void _post_popup() {} - - void _gui_input(Ref<InputEvent> p_event); void _notification(int p_what); - virtual void _fix_size(); static void _bind_methods(); public: - enum { - NOTIFICATION_POST_POPUP = 80, - NOTIFICATION_POPUP_HIDE = 81 - }; - - void set_exclusive(bool p_exclusive); - bool is_exclusive() const; - - void popup_centered_ratio(float p_screen_ratio = 0.75); - void popup_centered_size(const Size2 &p_size = Size2()); - void popup_centered_minsize(const Size2 &p_minsize = Size2()); void set_as_minsize(); - void popup_centered_clamped(const Size2 &p_size = Size2(), float p_fallback_ratio = 0.75); - virtual void popup(const Rect2 &p_bounds = Rect2()); - - virtual String get_configuration_warning() const; - Popup(); ~Popup(); }; @@ -77,13 +57,16 @@ class PopupPanel : public Popup { GDCLASS(PopupPanel, Popup); + Panel *panel; + protected: void _update_child_rects(); void _notification(int p_what); + virtual Size2 _get_contents_minimum_size() const; + public: void set_child_rect(Control *p_child); - virtual Size2 get_minimum_size() const; PopupPanel(); }; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index c45220ea60..6951026dec 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -35,6 +35,7 @@ #include "core/os/os.h" #include "core/print_string.h" #include "core/translation.h" +#include "scene/gui/control.h" String PopupMenu::_get_accel_text(int p_item) const { @@ -47,18 +48,18 @@ String PopupMenu::_get_accel_text(int p_item) const { return String(); } -Size2 PopupMenu::get_minimum_size() const { +Size2 PopupMenu::_get_contents_minimum_size() const { - int vseparation = get_constant("vseparation"); - int hseparation = get_constant("hseparation"); + int vseparation = get_theme_constant("vseparation"); + int hseparation = get_theme_constant("hseparation"); - Size2 minsize = get_stylebox("panel")->get_minimum_size(); - Ref<Font> font = get_font("font"); + Size2 minsize = get_theme_stylebox("panel")->get_minimum_size(); + Ref<Font> font = get_theme_font("font"); float max_w = 0; float icon_w = 0; int font_h = font->get_height(); - int check_w = MAX(get_icon("checked")->get_width(), get_icon("radio_checked")->get_width()) + hseparation; + int check_w = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation; int accel_max_w = 0; bool has_check = false; @@ -93,7 +94,7 @@ Size2 PopupMenu::get_minimum_size() const { } if (items[i].submenu != "") - size.width += get_icon("submenu")->get_width(); + size.width += get_theme_icon("submenu")->get_width(); max_w = MAX(max_w, size.width); @@ -112,15 +113,15 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const { if (p_over.x < 0 || p_over.x >= get_size().width) return -1; - Ref<StyleBox> style = get_stylebox("panel"); + Ref<StyleBox> style = get_theme_stylebox("panel"); Point2 ofs = style->get_offset(); if (ofs.y > p_over.y) return -1; - Ref<Font> font = get_font("font"); - int vseparation = get_constant("vseparation"); + Ref<Font> font = get_theme_font("font"); + int vseparation = get_theme_constant("vseparation"); float font_h = font->get_height(); for (int i = 0; i < items.size(); i++) { @@ -152,27 +153,27 @@ void PopupMenu::_activate_submenu(int over) { ERR_FAIL_COND_MSG(!n, "Item subnode does not exist: " + items[over].submenu + "."); Popup *pm = Object::cast_to<Popup>(n); ERR_FAIL_COND_MSG(!pm, "Item subnode is not a Popup: " + items[over].submenu + "."); - if (pm->is_visible_in_tree()) + if (pm->is_visible()) return; //already visible! - Point2 p = get_global_position(); + Point2 p = get_position(); Rect2 pr(p, get_size()); - Ref<StyleBox> style = get_stylebox("panel"); + Ref<StyleBox> style = get_theme_stylebox("panel"); - Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y) * get_global_transform().get_scale(); + Point2 pos = p + Point2(get_size().width, items[over]._ofs_cache - style->get_offset().y); Size2 size = pm->get_size(); // fix pos - if (pos.x + size.width > get_viewport_rect().size.width) + if (pos.x + size.width > get_screen_rect().size.width) pos.x = p.x - size.width; pm->set_position(pos); - pm->set_scale(get_global_transform().get_scale()); + // pm->set_scale(get_global_transform().get_scale()); pm->popup(); PopupMenu *pum = Object::cast_to<PopupMenu>(pm); if (pum) { - pr.position -= pum->get_global_position(); + pr.position -= pum->get_position(); pum->clear_autohide_areas(); pum->add_autohide_area(Rect2(pr.position.x, pr.position.y, pr.size.x, items[over]._ofs_cache)); if (over < items.size() - 1) { @@ -192,17 +193,17 @@ void PopupMenu::_submenu_timeout() { void PopupMenu::_scroll(float p_factor, const Point2 &p_over) { - int vseparation = get_constant("vseparation"); - Ref<Font> font = get_font("font"); + int vseparation = get_theme_constant("vseparation"); + Ref<Font> font = get_theme_font("font"); - float dy = (vseparation + font->get_height()) * 3 * p_factor * get_global_transform().get_scale().y; + float dy = (vseparation + font->get_height()) * 3 * p_factor; if (dy > 0) { - const float global_top = get_global_position().y; + const float global_top = get_position().y; const float limit = global_top < 0 ? -global_top : 0; dy = MIN(dy, limit); } else if (dy < 0) { - const float global_bottom = get_global_position().y + get_size().y * get_global_transform().get_scale().y; - const float viewport_height = get_viewport_rect().size.y; + const float global_bottom = get_position().y + get_size().y; + const float viewport_height = get_screen_rect().size.y; const float limit = global_bottom > viewport_height ? global_bottom - viewport_height : 0; dy = -MIN(-dy, limit); } @@ -231,8 +232,8 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { mouse_over = i; emit_signal("id_focused", i); - update(); - accept_event(); + control->update(); + set_input_as_handled(); break; } } @@ -251,8 +252,8 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { mouse_over = i; emit_signal("id_focused", i); - update(); - accept_event(); + control->update(); + set_input_as_handled(); break; } } @@ -261,13 +262,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { Node *n = get_parent(); if (n && Object::cast_to<PopupMenu>(n)) { hide(); - accept_event(); + set_input_as_handled(); } } else if (p_event->is_action("ui_right") && p_event->is_pressed()) { if (mouse_over >= 0 && mouse_over < items.size() && !items[mouse_over].separator && items[mouse_over].submenu != "" && submenu_over != mouse_over) { _activate_submenu(mouse_over); - accept_event(); + set_input_as_handled(); } } else if (p_event->is_action("ui_accept") && p_event->is_pressed()) { @@ -278,7 +279,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { } else { activate_item(mouse_over); } - accept_event(); + set_input_as_handled(); } } @@ -294,13 +295,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { case BUTTON_WHEEL_DOWN: { - if (get_global_position().y + get_size().y * get_global_transform().get_scale().y > get_viewport_rect().size.y) { + if (get_position().y + get_size().y > get_screen_rect().size.y) { _scroll(-b->get_factor(), b->get_position()); } } break; case BUTTON_WHEEL_UP: { - if (get_global_position().y < 0) { + if (get_position().y < 0) { _scroll(b->get_factor(), b->get_position()); } } break; @@ -338,7 +339,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { } } - //update(); + //control->update(); } Ref<InputEventMouseMotion> m = p_event; @@ -364,7 +365,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { if (id < 0) { mouse_over = -1; - update(); + control->update(); return; } @@ -375,13 +376,13 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { if (over != mouse_over) { mouse_over = over; - update(); + control->update(); } } Ref<InputEventPanGesture> pan_gesture = p_event; if (pan_gesture.is_valid()) { - if (get_global_position().y + get_size().y > get_viewport_rect().size.y || get_global_position().y < 0) { + if (get_position().y + get_size().y > get_screen_rect().size.y || get_position().y < 0) { _scroll(-pan_gesture->get_delta().y, pan_gesture->get_position()); } } @@ -416,191 +417,174 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { if (items[i].text.findn(search_string) == 0) { mouse_over = i; emit_signal("id_focused", i); - update(); - accept_event(); + control->update(); + set_input_as_handled(); break; } } } } -bool PopupMenu::has_point(const Point2 &p_point) const { +void PopupMenu::_draw() { - if (parent_rect.has_point(p_point)) - return true; - for (const List<Rect2>::Element *E = autohide_areas.front(); E; E = E->next()) { + RID ci = control->get_canvas_item(); + Size2 size = get_size(); - if (E->get().has_point(p_point)) - return true; - } - - return Control::has_point(p_point); -} + Ref<StyleBox> style = get_theme_stylebox("panel"); + Ref<StyleBox> hover = get_theme_stylebox("hover"); + Ref<Font> font = get_theme_font("font"); + // In Item::checkable_type enum order (less the non-checkable member) + Ref<Texture2D> check[] = { get_theme_icon("checked"), get_theme_icon("radio_checked") }; + Ref<Texture2D> uncheck[] = { get_theme_icon("unchecked"), get_theme_icon("radio_unchecked") }; + Ref<Texture2D> submenu = get_theme_icon("submenu"); + Ref<StyleBox> separator = get_theme_stylebox("separator"); + Ref<StyleBox> labeled_separator_left = get_theme_stylebox("labeled_separator_left"); + Ref<StyleBox> labeled_separator_right = get_theme_stylebox("labeled_separator_right"); -void PopupMenu::_notification(int p_what) { + style->draw(ci, Rect2(Point2(), get_size())); + Point2 ofs = style->get_offset(); + int vseparation = get_theme_constant("vseparation"); + int hseparation = get_theme_constant("hseparation"); + Color font_color = get_theme_color("font_color"); + Color font_color_disabled = get_theme_color("font_color_disabled"); + Color font_color_accel = get_theme_color("font_color_accel"); + Color font_color_hover = get_theme_color("font_color_hover"); + float font_h = font->get_height(); - switch (p_what) { + // Add the check and the wider icon to the offset of all items. + float icon_ofs = 0.0; + bool has_check = false; + for (int i = 0; i < items.size(); i++) { - case NOTIFICATION_ENTER_TREE: { + if (!items[i].icon.is_null()) + icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs); - PopupMenu *pm = Object::cast_to<PopupMenu>(get_parent()); - if (pm) { - // Inherit submenu's popup delay time from parent menu - float pm_delay = pm->get_submenu_popup_delay(); - set_submenu_popup_delay(pm_delay); - } - } break; - case NOTIFICATION_TRANSLATION_CHANGED: { + if (items[i].checkable_type) + has_check = true; + } + if (icon_ofs > 0.0) + icon_ofs += hseparation; - for (int i = 0; i < items.size(); i++) { - items.write[i].xl_text = tr(items[i].text); - } + float check_ofs = 0.0; + if (has_check) + check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation; - minimum_size_changed(); - update(); - } break; - case NOTIFICATION_DRAW: { - - RID ci = get_canvas_item(); - Size2 size = get_size(); - - Ref<StyleBox> style = get_stylebox("panel"); - Ref<StyleBox> hover = get_stylebox("hover"); - Ref<Font> font = get_font("font"); - // In Item::checkable_type enum order (less the non-checkable member) - Ref<Texture2D> check[] = { get_icon("checked"), get_icon("radio_checked") }; - Ref<Texture2D> uncheck[] = { get_icon("unchecked"), get_icon("radio_unchecked") }; - Ref<Texture2D> submenu = get_icon("submenu"); - Ref<StyleBox> separator = get_stylebox("separator"); - Ref<StyleBox> labeled_separator_left = get_stylebox("labeled_separator_left"); - Ref<StyleBox> labeled_separator_right = get_stylebox("labeled_separator_right"); - - style->draw(ci, Rect2(Point2(), get_size())); - Point2 ofs = style->get_offset(); - int vseparation = get_constant("vseparation"); - int hseparation = get_constant("hseparation"); - Color font_color = get_color("font_color"); - Color font_color_disabled = get_color("font_color_disabled"); - Color font_color_accel = get_color("font_color_accel"); - Color font_color_hover = get_color("font_color_hover"); - float font_h = font->get_height(); - - // Add the check and the wider icon to the offset of all items. - float icon_ofs = 0.0; - bool has_check = false; - for (int i = 0; i < items.size(); i++) { + for (int i = 0; i < items.size(); i++) { - if (!items[i].icon.is_null()) - icon_ofs = MAX(items[i].icon->get_size().width, icon_ofs); + if (i > 0) + ofs.y += vseparation; + Point2 item_ofs = ofs; + Size2 icon_size; + float h; - if (items[i].checkable_type) - has_check = true; - } - if (icon_ofs > 0.0) - icon_ofs += hseparation; + if (!items[i].icon.is_null()) { - float check_ofs = 0.0; - if (has_check) - check_ofs = MAX(get_icon("checked")->get_width(), get_icon("radio_checked")->get_width()) + hseparation; + icon_size = items[i].icon->get_size(); + h = MAX(icon_size.height, font_h); + } else { - for (int i = 0; i < items.size(); i++) { + h = font_h; + } - if (i > 0) - ofs.y += vseparation; - Point2 item_ofs = ofs; - Size2 icon_size; - float h; + if (i == mouse_over) { - if (!items[i].icon.is_null()) { + hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation))); + } - icon_size = items[i].icon->get_size(); - h = MAX(icon_size.height, font_h); - } else { + String text = items[i].xl_text; - h = font_h; + item_ofs.x += items[i].h_ofs; + if (items[i].separator) { + + int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; + if (text != String()) { + int ss = font->get_string_size(text).width; + int center = (get_size().width) / 2; + int l = center - ss / 2; + int r = center + ss / 2; + if (l > item_ofs.x) { + labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, l - item_ofs.x), sep_h))); } - - if (i == mouse_over) { - - hover->draw(ci, Rect2(item_ofs + Point2(-hseparation, -vseparation / 2), Size2(get_size().width - style->get_minimum_size().width + hseparation * 2, h + vseparation))); + if (r < get_size().width - style->get_margin(MARGIN_RIGHT)) { + labeled_separator_right->draw(ci, Rect2(Point2(r, item_ofs.y + Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, get_size().width - style->get_margin(MARGIN_RIGHT) - r), sep_h))); } + } else { + separator->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(get_size().width - style->get_minimum_size().width, sep_h))); + } + } - String text = items[i].xl_text; + Color icon_color(1, 1, 1, items[i].disabled ? 0.5 : 1); - item_ofs.x += items[i].h_ofs; - if (items[i].separator) { + if (items[i].checkable_type) { + Texture2D *icon = (items[i].checked ? check[items[i].checkable_type - 1] : uncheck[items[i].checkable_type - 1]).ptr(); + icon->draw(ci, item_ofs + Point2(0, Math::floor((h - icon->get_height()) / 2.0)), icon_color); + } - int sep_h = separator->get_center_size().height + separator->get_minimum_size().height; - if (text != String()) { - int ss = font->get_string_size(text).width; - int center = (get_size().width) / 2; - int l = center - ss / 2; - int r = center + ss / 2; - if (l > item_ofs.x) { - labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, l - item_ofs.x), sep_h))); - } - if (r < get_size().width - style->get_margin(MARGIN_RIGHT)) { - labeled_separator_right->draw(ci, Rect2(Point2(r, item_ofs.y + Math::floor((h - sep_h) / 2.0)), Size2(MAX(0, get_size().width - style->get_margin(MARGIN_RIGHT) - r), sep_h))); - } - } else { - separator->draw(ci, Rect2(item_ofs + Point2(0, Math::floor((h - sep_h) / 2.0)), Size2(get_size().width - style->get_minimum_size().width, sep_h))); - } - } + if (!items[i].icon.is_null()) { + items[i].icon->draw(ci, item_ofs + Size2(check_ofs, 0) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color); + } - Color icon_color(1, 1, 1, items[i].disabled ? 0.5 : 1); + if (items[i].submenu != "") { + submenu->draw(ci, Point2(size.width - style->get_margin(MARGIN_RIGHT) - submenu->get_width(), item_ofs.y + Math::floor(h - submenu->get_height()) / 2), icon_color); + } - if (items[i].checkable_type) { - Texture2D *icon = (items[i].checked ? check[items[i].checkable_type - 1] : uncheck[items[i].checkable_type - 1]).ptr(); - icon->draw(ci, item_ofs + Point2(0, Math::floor((h - icon->get_height()) / 2.0)), icon_color); - } + item_ofs.y += font->get_ascent(); + if (items[i].separator) { - if (!items[i].icon.is_null()) { - items[i].icon->draw(ci, item_ofs + Size2(check_ofs, 0) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color); - } + if (text != String()) { + int center = (get_size().width - font->get_string_size(text).width) / 2; + font->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_disabled); + } + } else { - if (items[i].submenu != "") { - submenu->draw(ci, Point2(size.width - style->get_margin(MARGIN_RIGHT) - submenu->get_width(), item_ofs.y + Math::floor(h - submenu->get_height()) / 2), icon_color); - } + item_ofs.x += icon_ofs + check_ofs; + font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color)); + } - item_ofs.y += font->get_ascent(); - if (items[i].separator) { + if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) { + //accelerator + String text2 = _get_accel_text(i); + item_ofs.x = size.width - style->get_margin(MARGIN_RIGHT) - font->get_string_size(text2).width; + font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text2, i == mouse_over ? font_color_hover : font_color_accel); + } - if (text != String()) { - int center = (get_size().width - font->get_string_size(text).width) / 2; - font->draw(ci, Point2(center, item_ofs.y + Math::floor((h - font_h) / 2.0)), text, font_color_disabled); - } - } else { + items.write[i]._ofs_cache = ofs.y; - item_ofs.x += icon_ofs + check_ofs; - font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, items[i].disabled ? font_color_disabled : (i == mouse_over ? font_color_hover : font_color)); - } + ofs.y += h; + } +} - if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) { - //accelerator - String text2 = _get_accel_text(i); - item_ofs.x = size.width - style->get_margin(MARGIN_RIGHT) - font->get_string_size(text2).width; - font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text2, i == mouse_over ? font_color_hover : font_color_accel); - } +void PopupMenu::_notification(int p_what) { - items.write[i]._ofs_cache = ofs.y; + switch (p_what) { + + case NOTIFICATION_ENTER_TREE: { - ofs.y += h; + PopupMenu *pm = Object::cast_to<PopupMenu>(get_parent()); + if (pm) { + // Inherit submenu's popup delay time from parent menu + float pm_delay = pm->get_submenu_popup_delay(); + set_submenu_popup_delay(pm_delay); } } break; - case NOTIFICATION_WM_FOCUS_OUT: { + case NOTIFICATION_TRANSLATION_CHANGED: { - if (hide_on_window_lose_focus) - hide(); + for (int i = 0; i < items.size(); i++) { + items.write[i].xl_text = tr(items[i].text); + } + + child_controls_changed(); + control->update(); } break; - case NOTIFICATION_MOUSE_ENTER: { + case NOTIFICATION_WM_MOUSE_ENTER: { grab_focus(); } break; - case NOTIFICATION_MOUSE_EXIT: { + case NOTIFICATION_WM_MOUSE_EXIT: { if (mouse_over >= 0 && (items[mouse_over].submenu == "" || submenu_over != -1)) { mouse_over = -1; - update(); + control->update(); } } break; case NOTIFICATION_POST_POPUP: { @@ -608,26 +592,28 @@ void PopupMenu::_notification(int p_what) { initial_button_mask = InputFilter::get_singleton()->get_mouse_button_mask(); during_grabbed_click = (bool)initial_button_mask; } break; - case NOTIFICATION_POPUP_HIDE: { + case NOTIFICATION_VISIBILITY_CHANGED: { - if (mouse_over >= 0) { - mouse_over = -1; - update(); - } + if (!is_visible()) { + if (mouse_over >= 0) { + mouse_over = -1; + control->update(); + } - for (int i = 0; i < items.size(); i++) { - if (items[i].submenu == "") - continue; + for (int i = 0; i < items.size(); i++) { + if (items[i].submenu == "") + continue; - Node *n = get_node(items[i].submenu); - if (!n) - continue; + Node *n = get_node(items[i].submenu); + if (!n) + continue; - PopupMenu *pm = Object::cast_to<PopupMenu>(n); - if (!pm || !pm->is_visible()) - continue; + PopupMenu *pm = Object::cast_to<PopupMenu>(n); + if (!pm || !pm->is_visible()) + continue; - pm->hide(); + pm->hide(); + } } } break; } @@ -648,8 +634,8 @@ void PopupMenu::add_item(const String &p_label, int p_id, uint32_t p_accel) { Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { @@ -658,8 +644,8 @@ void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_labe ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.icon = p_icon; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel) { @@ -668,8 +654,8 @@ void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { @@ -679,8 +665,8 @@ void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String & item.icon = p_icon; item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p_accel) { @@ -689,8 +675,8 @@ void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { @@ -700,8 +686,8 @@ void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const St item.icon = p_icon; item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int p_default_state, int p_id, uint32_t p_accel) { @@ -711,8 +697,8 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int item.max_states = p_max_states; item.state = p_default_state; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } #define ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global) \ @@ -729,8 +715,8 @@ void PopupMenu::add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_g Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -739,8 +725,8 @@ void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortC ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.icon = p_icon; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -749,8 +735,8 @@ void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bo ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -760,8 +746,8 @@ void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref< item.icon = p_icon; item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -770,8 +756,8 @@ void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_ ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { @@ -781,8 +767,8 @@ void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, cons item.icon = p_icon; item.checkable_type = Item::CHECKABLE_TYPE_RADIO_BUTTON; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, int p_id) { @@ -793,8 +779,8 @@ void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu, item.id = p_id == -1 ? items.size() : p_id; item.submenu = p_submenu; items.push_back(item); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } #undef ITEM_SETUP_WITH_ACCEL @@ -808,16 +794,16 @@ void PopupMenu::set_item_text(int p_idx, const String &p_text) { items.write[p_idx].text = p_text; items.write[p_idx].xl_text = tr(p_text); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].icon = p_icon; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_checked(int p_idx, bool p_checked) { @@ -825,16 +811,16 @@ void PopupMenu::set_item_checked(int p_idx, bool p_checked) { items.write[p_idx].checked = p_checked; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_id(int p_idx, int p_id) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].id = p_id; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) { @@ -842,40 +828,40 @@ void PopupMenu::set_item_accelerator(int p_idx, uint32_t p_accel) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].accel = p_accel; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_metadata(int p_idx, const Variant &p_meta) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].metadata = p_meta; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_disabled(int p_idx, bool p_disabled) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].disabled = p_disabled; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_submenu(int p_idx, const String &p_submenu) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].submenu = p_submenu; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::toggle_item_checked(int p_idx) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checked = !items[p_idx].checked; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } String PopupMenu::get_item_text(int p_idx) const { @@ -968,7 +954,7 @@ void PopupMenu::set_item_as_separator(int p_idx, bool p_separator) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].separator = p_separator; - update(); + control->update(); } bool PopupMenu::is_item_separator(int p_idx) const { @@ -980,21 +966,21 @@ void PopupMenu::set_item_as_checkable(int p_idx, bool p_checkable) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checkable_type = p_checkable ? Item::CHECKABLE_TYPE_CHECK_BOX : Item::CHECKABLE_TYPE_NONE; - update(); + control->update(); } void PopupMenu::set_item_as_radio_checkable(int p_idx, bool p_radio_checkable) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].checkable_type = p_radio_checkable ? Item::CHECKABLE_TYPE_RADIO_BUTTON : Item::CHECKABLE_TYPE_NONE; - update(); + control->update(); } void PopupMenu::set_item_tooltip(int p_idx, const String &p_tooltip) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].tooltip = p_tooltip; - update(); + control->update(); } void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bool p_global) { @@ -1009,29 +995,29 @@ void PopupMenu::set_item_shortcut(int p_idx, const Ref<ShortCut> &p_shortcut, bo _ref_shortcut(items[p_idx].shortcut); } - update(); + control->update(); } void PopupMenu::set_item_h_offset(int p_idx, int p_offset) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].h_ofs = p_offset; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::set_item_multistate(int p_idx, int p_state) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].state = p_state; - update(); + control->update(); } void PopupMenu::set_item_shortcut_disabled(int p_idx, bool p_disabled) { ERR_FAIL_INDEX(p_idx, items.size()); items.write[p_idx].shortcut_is_disabled = p_disabled; - update(); + control->update(); } void PopupMenu::toggle_item_multistate(int p_idx) { @@ -1045,7 +1031,7 @@ void PopupMenu::toggle_item_multistate(int p_idx) { if (items.write[p_idx].max_states <= items[p_idx].state) items.write[p_idx].state = 0; - update(); + control->update(); } bool PopupMenu::is_item_checkable(int p_idx) const { @@ -1177,8 +1163,8 @@ void PopupMenu::remove_item(int p_idx) { } items.remove(p_idx); - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } void PopupMenu::add_separator(const String &p_text) { @@ -1191,7 +1177,7 @@ void PopupMenu::add_separator(const String &p_text) { sep.xl_text = tr(p_text); } items.push_back(sep); - update(); + control->update(); } void PopupMenu::clear() { @@ -1203,8 +1189,8 @@ void PopupMenu::clear() { } items.clear(); mouse_over = -1; - update(); - minimum_size_changed(); + control->update(); + child_controls_changed(); } Array PopupMenu::_get_items() const { @@ -1345,16 +1331,6 @@ bool PopupMenu::get_allow_search() const { return allow_search; } -void PopupMenu::set_hide_on_window_lose_focus(bool p_enabled) { - - hide_on_window_lose_focus = p_enabled; -} - -bool PopupMenu::is_hide_on_window_lose_focus() const { - - return hide_on_window_lose_focus; -} - String PopupMenu::get_tooltip(const Point2 &p_pos) const { int over = _get_mouse_over(p_pos); @@ -1466,9 +1442,6 @@ void PopupMenu::_bind_methods() { ClassDB::bind_method(D_METHOD("set_submenu_popup_delay", "seconds"), &PopupMenu::set_submenu_popup_delay); ClassDB::bind_method(D_METHOD("get_submenu_popup_delay"), &PopupMenu::get_submenu_popup_delay); - ClassDB::bind_method(D_METHOD("set_hide_on_window_lose_focus", "enable"), &PopupMenu::set_hide_on_window_lose_focus); - ClassDB::bind_method(D_METHOD("is_hide_on_window_lose_focus"), &PopupMenu::is_hide_on_window_lose_focus); - ClassDB::bind_method(D_METHOD("set_allow_search", "allow"), &PopupMenu::set_allow_search); ClassDB::bind_method(D_METHOD("get_allow_search"), &PopupMenu::get_allow_search); @@ -1486,7 +1459,6 @@ void PopupMenu::_bind_methods() { void PopupMenu::popup(const Rect2 &p_bounds) { - grab_click_focus(); moved = Vector2(); invalidated_click = true; Popup::popup(p_bounds); @@ -1494,6 +1466,13 @@ void PopupMenu::popup(const Rect2 &p_bounds) { PopupMenu::PopupMenu() { + control = memnew(Control); + add_child(control); + + control->set_anchors_and_margins_preset(Control::PRESET_WIDE); + control->connect("gui_input", callable_mp(this, &PopupMenu::_gui_input)); + control->connect("draw", callable_mp(this, &PopupMenu::_draw)); + mouse_over = -1; submenu_over = -1; initial_button_mask = 0; @@ -1503,12 +1482,9 @@ PopupMenu::PopupMenu() { search_time_msec = 0; search_string = ""; - set_focus_mode(FOCUS_ALL); - set_as_toplevel(true); set_hide_on_item_selection(true); set_hide_on_checkable_item_selection(true); set_hide_on_multistate_item_selection(false); - set_hide_on_window_lose_focus(true); submenu_timer = memnew(Timer); submenu_timer->set_wait_time(0.3); diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index a3a858cfde..511c630ad2 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -32,6 +32,7 @@ #define POPUP_MENU_H #include "scene/gui/popup.h" +#include "scene/gui/shortcut.h" class PopupMenu : public Popup { @@ -87,7 +88,7 @@ class PopupMenu : public Popup { Rect2 parent_rect; String _get_accel_text(int p_item) const; int _get_mouse_over(const Point2 &p_over) const; - virtual Size2 get_minimum_size() const; + virtual Size2 _get_contents_minimum_size() const; void _scroll(float p_factor, const Point2 &p_over); void _gui_input(const Ref<InputEvent> &p_event); void _activate_submenu(int over); @@ -97,7 +98,6 @@ class PopupMenu : public Popup { bool hide_on_item_selection; bool hide_on_checkable_item_selection; bool hide_on_multistate_item_selection; - bool hide_on_window_lose_focus; Vector2 moved; Array _get_items() const; @@ -112,9 +112,11 @@ class PopupMenu : public Popup { uint64_t search_time_msec; String search_string; -protected: - virtual bool has_point(const Point2 &p_point) const; + Control *control; + + void _draw(); +protected: friend class MenuButton; void _notification(int p_what); static void _bind_methods(); @@ -213,9 +215,6 @@ public: virtual void popup(const Rect2 &p_bounds = Rect2()); - void set_hide_on_window_lose_focus(bool p_enabled); - bool is_hide_on_window_lose_focus() const; - PopupMenu(); ~PopupMenu(); }; diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp index e11295d7e7..362c45453d 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -32,9 +32,9 @@ Size2 ProgressBar::get_minimum_size() const { - Ref<StyleBox> bg = get_stylebox("bg"); - Ref<StyleBox> fg = get_stylebox("fg"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); + Ref<StyleBox> fg = get_theme_stylebox("fg"); + Ref<Font> font = get_theme_font("font"); Size2 minimum_size = bg->get_minimum_size(); minimum_size.height = MAX(minimum_size.height, fg->get_minimum_size().height); @@ -52,10 +52,10 @@ void ProgressBar::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> bg = get_stylebox("bg"); - Ref<StyleBox> fg = get_stylebox("fg"); - Ref<Font> font = get_font("font"); - Color font_color = get_color("font_color"); + Ref<StyleBox> bg = get_theme_stylebox("bg"); + Ref<StyleBox> fg = get_theme_stylebox("fg"); + Ref<Font> font = get_theme_font("font"); + Color font_color = get_theme_color("font_color"); draw_style_box(bg, Rect2(Point2(), get_size())); float r = get_as_ratio(); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 2a21df002c..614d109534 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -143,7 +143,7 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) { } Rect2 RichTextLabel::_get_text_rect() { - Ref<StyleBox> style = get_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox("normal"); return Rect2(style->get_offset(), get_size() - style->get_minimum_size()); } @@ -241,7 +241,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & l.space_caches.push_back(spaces); \ } \ line_wrapped = false; \ - y += line_height + get_constant(SceneStringNames::get_singleton()->line_separation); \ + y += line_height + get_theme_constant(SceneStringNames::get_singleton()->line_separation); \ line_height = 0; \ line_ascent = 0; \ line_descent = 0; \ @@ -306,8 +306,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & Color selection_bg; if (p_mode == PROCESS_DRAW) { - selection_fg = get_color("font_color_selected"); - selection_bg = get_color("selection_color"); + selection_fg = get_theme_color("font_color_selected"); + selection_bg = get_theme_color("selection_color"); } int rchar = 0; @@ -668,13 +668,13 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & lh = 0; ItemTable *table = static_cast<ItemTable *>(it); - int hseparation = get_constant("table_hseparation"); - int vseparation = get_constant("table_vseparation"); + int hseparation = get_theme_constant("table_hseparation"); + int vseparation = get_theme_constant("table_vseparation"); Color ccolor = _find_color(table, p_base_color); Vector2 draw_ofs = Point2(wofs, y); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs2(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs2(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); if (p_mode == PROCESS_CACHE) { @@ -988,11 +988,11 @@ void RichTextLabel::_notification(int p_what) { Size2 size = get_size(); Rect2 text_rect = _get_text_rect(); - draw_style_box(get_stylebox("normal"), Rect2(Point2(), size)); + draw_style_box(get_theme_stylebox("normal"), Rect2(Point2(), size)); if (has_focus()) { VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, true); - draw_style_box(get_stylebox("focus"), Rect2(Point2(), size)); + draw_style_box(get_theme_stylebox("focus"), Rect2(Point2(), size)); VisualServer::get_singleton()->canvas_item_add_clip_ignore(ci, false); } @@ -1013,11 +1013,11 @@ void RichTextLabel::_notification(int p_what) { if (from_line >= main->lines.size()) break; //nothing to draw int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs; - Ref<Font> base_font = get_font("normal_font"); - Color base_color = get_color("default_color"); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); + Ref<Font> base_font = get_theme_font("normal_font"); + Color base_color = get_theme_color("default_color"); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); visible_line_count = 0; while (y < size.height && from_line < main->lines.size()) { @@ -1044,9 +1044,9 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item Rect2 text_rect = _get_text_rect(); int ofs = vscroll->get_value(); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); //todo, change to binary search int from_line = 0; @@ -1062,8 +1062,8 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item return; int y = (p_frame->lines[from_line].height_accum_cache - p_frame->lines[from_line].height_cache) - ofs; - Ref<Font> base_font = get_font("normal_font"); - Color base_color = get_color("default_color"); + Ref<Font> base_font = get_theme_font("normal_font"); + Color base_color = get_theme_color("default_color"); while (y < text_rect.get_size().height && from_line < p_frame->lines.size()) { @@ -1228,14 +1228,14 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { case KEY_UP: { if (vscroll->is_visible_in_tree()) { - vscroll->set_value(vscroll->get_value() - get_font("normal_font")->get_height()); + vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height()); handled = true; } } break; case KEY_DOWN: { if (vscroll->is_visible_in_tree()) { - vscroll->set_value(vscroll->get_value() + get_font("normal_font")->get_height()); + vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height()); handled = true; } } break; @@ -1526,11 +1526,11 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { size.width = fixed_width; } Rect2 text_rect = _get_text_rect(); - Color font_color_shadow = get_color("font_color_shadow"); - bool use_outline = get_constant("shadow_as_outline"); - Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); + Color font_color_shadow = get_theme_color("font_color_shadow"); + bool use_outline = get_theme_constant("shadow_as_outline"); + Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); - Ref<Font> base_font = get_font("normal_font"); + Ref<Font> base_font = get_theme_font("normal_font"); for (int i = p_frame->first_invalid_line; i < p_frame->lines.size(); i++) { @@ -1545,7 +1545,7 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { int total_height = 0; if (p_frame->lines.size()) - total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_stylebox("normal")->get_minimum_size().height; + total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height; main->first_invalid_line = p_frame->lines.size(); @@ -1759,35 +1759,35 @@ void RichTextLabel::push_font(const Ref<Font> &p_font) { } void RichTextLabel::push_normal() { - Ref<Font> normal_font = get_font("normal_font"); + Ref<Font> normal_font = get_theme_font("normal_font"); ERR_FAIL_COND(normal_font.is_null()); push_font(normal_font); } void RichTextLabel::push_bold() { - Ref<Font> bold_font = get_font("bold_font"); + Ref<Font> bold_font = get_theme_font("bold_font"); ERR_FAIL_COND(bold_font.is_null()); push_font(bold_font); } void RichTextLabel::push_bold_italics() { - Ref<Font> bold_italics_font = get_font("bold_italics_font"); + Ref<Font> bold_italics_font = get_theme_font("bold_italics_font"); ERR_FAIL_COND(bold_italics_font.is_null()); push_font(bold_italics_font); } void RichTextLabel::push_italics() { - Ref<Font> italics_font = get_font("italics_font"); + Ref<Font> italics_font = get_theme_font("italics_font"); ERR_FAIL_COND(italics_font.is_null()); push_font(italics_font); } void RichTextLabel::push_mono() { - Ref<Font> mono_font = get_font("mono_font"); + Ref<Font> mono_font = get_theme_font("mono_font"); ERR_FAIL_COND(mono_font.is_null()); push_font(mono_font); @@ -2045,13 +2045,13 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { int pos = 0; List<String> tag_stack; - Ref<Font> normal_font = get_font("normal_font"); - Ref<Font> bold_font = get_font("bold_font"); - Ref<Font> italics_font = get_font("italics_font"); - Ref<Font> bold_italics_font = get_font("bold_italics_font"); - Ref<Font> mono_font = get_font("mono_font"); + Ref<Font> normal_font = get_theme_font("normal_font"); + Ref<Font> bold_font = get_theme_font("bold_font"); + Ref<Font> italics_font = get_theme_font("italics_font"); + Ref<Font> bold_italics_font = get_theme_font("bold_italics_font"); + Ref<Font> mono_font = get_theme_font("mono_font"); - Color base_color = get_color("default_color"); + Color base_color = get_theme_color("default_color"); int indent_level = 0; @@ -2519,7 +2519,7 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p _validate_line_caches(main); - int fh = _find_font(t).is_valid() ? _find_font(t)->get_height() : get_font("normal_font")->get_height(); + int fh = _find_font(t).is_valid() ? _find_font(t)->get_height() : get_theme_font("normal_font")->get_height(); float offset = 0; @@ -2693,7 +2693,7 @@ void RichTextLabel::install_effect(const Variant effect) { int RichTextLabel::get_content_height() { int total_height = 0; if (main->lines.size()) - total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_stylebox("normal")->get_minimum_size().height; + total_height = main->lines[main->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height; return total_height; } diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 7fc83703c3..5e9541730e 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -72,8 +72,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (b->is_pressed()) { double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x; - Ref<Texture2D> decr = get_icon("decrement"); - Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -149,7 +149,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (drag.active) { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> decr = get_theme_icon("decrement"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); ofs -= decr_size; @@ -160,8 +160,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { } else { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture2D> decr = get_icon("decrement"); - Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -234,17 +234,17 @@ void ScrollBar::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_icon("decrement_highlight") : get_icon("decrement"); - Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_icon("increment_highlight") : get_icon("increment"); - Ref<StyleBox> bg = has_focus() ? get_stylebox("scroll_focus") : get_stylebox("scroll"); + Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon("decrement_highlight") : get_theme_icon("decrement"); + Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_theme_icon("increment_highlight") : get_theme_icon("increment"); + Ref<StyleBox> bg = has_focus() ? get_theme_stylebox("scroll_focus") : get_theme_stylebox("scroll"); Ref<StyleBox> grabber; if (drag.active) - grabber = get_stylebox("grabber_pressed"); + grabber = get_theme_stylebox("grabber_pressed"); else if (highlight == HIGHLIGHT_RANGE) - grabber = get_stylebox("grabber_highlight"); + grabber = get_theme_stylebox("grabber_highlight"); else - grabber = get_stylebox("grabber"); + grabber = get_theme_stylebox("grabber"); Point2 ofs; @@ -417,7 +417,7 @@ void ScrollBar::_notification(int p_what) { double ScrollBar::get_grabber_min_size() const { - Ref<StyleBox> grabber = get_stylebox("grabber"); + Ref<StyleBox> grabber = get_theme_stylebox("grabber"); Size2 gminsize = grabber->get_minimum_size() + grabber->get_center_size(); return (orientation == VERTICAL) ? gminsize.height : gminsize.width; } @@ -443,17 +443,17 @@ double ScrollBar::get_area_size() const { switch (orientation) { case VERTICAL: { double area = get_size().height; - area -= get_stylebox("scroll")->get_minimum_size().height; - area -= get_icon("increment")->get_height(); - area -= get_icon("decrement")->get_height(); + area -= get_theme_stylebox("scroll")->get_minimum_size().height; + area -= get_theme_icon("increment")->get_height(); + area -= get_theme_icon("decrement")->get_height(); area -= get_grabber_min_size(); return area; } break; case HORIZONTAL: { double area = get_size().width; - area -= get_stylebox("scroll")->get_minimum_size().width; - area -= get_icon("increment")->get_width(); - area -= get_icon("decrement")->get_width(); + area -= get_theme_stylebox("scroll")->get_minimum_size().width; + area -= get_theme_icon("increment")->get_width(); + area -= get_theme_icon("decrement")->get_width(); area -= get_grabber_min_size(); return area; } break; @@ -469,14 +469,14 @@ double ScrollBar::get_area_offset() const { if (orientation == VERTICAL) { - ofs += get_stylebox("hscroll")->get_margin(MARGIN_TOP); - ofs += get_icon("decrement")->get_height(); + ofs += get_theme_stylebox("hscroll")->get_margin(MARGIN_TOP); + ofs += get_theme_icon("decrement")->get_height(); } if (orientation == HORIZONTAL) { - ofs += get_stylebox("hscroll")->get_margin(MARGIN_LEFT); - ofs += get_icon("decrement")->get_width(); + ofs += get_theme_stylebox("hscroll")->get_margin(MARGIN_LEFT); + ofs += get_theme_icon("decrement")->get_width(); } return ofs; @@ -501,9 +501,9 @@ double ScrollBar::get_grabber_offset() const { Size2 ScrollBar::get_minimum_size() const { - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); - Ref<StyleBox> bg = get_stylebox("scroll"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<StyleBox> bg = get_theme_stylebox("scroll"); Size2 minsize; if (orientation == VERTICAL) { diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 32943e04e0..fb17adf96e 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -39,7 +39,7 @@ bool ScrollContainer::clips_input() const { Size2 ScrollContainer::get_minimum_size() const { - Ref<StyleBox> sb = get_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox("bg"); Size2 min_size; for (int i = 0; i < get_child_count(); i++) { @@ -276,7 +276,7 @@ void ScrollContainer::_notification(int p_what) { Size2 size = get_size(); Point2 ofs; - Ref<StyleBox> sb = get_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox("bg"); size -= sb->get_minimum_size(); ofs += sb->get_offset(); @@ -323,7 +323,7 @@ void ScrollContainer::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> sb = get_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox("bg"); draw_style_box(sb, Rect2(Vector2(), get_size())); update_scrollbars(); @@ -404,7 +404,7 @@ void ScrollContainer::_notification(int p_what) { void ScrollContainer::update_scrollbars() { Size2 size = get_size(); - Ref<StyleBox> sb = get_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox("bg"); size -= sb->get_minimum_size(); Size2 hmin; diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp index 4635efb233..75c4b7cce9 100644 --- a/scene/gui/separator.cpp +++ b/scene/gui/separator.cpp @@ -34,9 +34,9 @@ Size2 Separator::get_minimum_size() const { Size2 ms(3, 3); if (orientation == VERTICAL) { - ms.x = get_constant("separation"); + ms.x = get_theme_constant("separation"); } else { // HORIZONTAL - ms.y = get_constant("separation"); + ms.y = get_theme_constant("separation"); } return ms; } @@ -48,7 +48,7 @@ void Separator::_notification(int p_what) { case NOTIFICATION_DRAW: { Size2i size = get_size(); - Ref<StyleBox> style = get_stylebox("separator"); + Ref<StyleBox> style = get_theme_stylebox("separator"); Size2i ssize = style->get_minimum_size() + style->get_center_size(); if (orientation == VERTICAL) { diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 85887ef7b1..e47e2b869d 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -33,10 +33,10 @@ Size2 Slider::get_minimum_size() const { - Ref<StyleBox> style = get_stylebox("slider"); + Ref<StyleBox> style = get_theme_stylebox("slider"); Size2i ss = style->get_minimum_size() + style->get_center_size(); - Ref<Texture2D> grabber = get_icon("grabber"); + Ref<Texture2D> grabber = get_theme_icon("grabber"); Size2i rs = grabber->get_size(); if (orientation == HORIZONTAL) @@ -57,7 +57,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) { if (mb->get_button_index() == BUTTON_LEFT) { if (mb->is_pressed()) { - Ref<Texture2D> grabber = get_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber"); + Ref<Texture2D> grabber = get_theme_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber"); grab.pos = orientation == VERTICAL ? mb->get_position().y : mb->get_position().x; double grab_width = (double)grabber->get_size().width; @@ -87,7 +87,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) { if (grab.active) { Size2i size = get_size(); - Ref<Texture2D> grabber = get_icon("grabber"); + Ref<Texture2D> grabber = get_theme_icon("grabber"); float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos; if (orientation == VERTICAL) motion = -motion; @@ -165,10 +165,10 @@ void Slider::_notification(int p_what) { case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); Size2i size = get_size(); - Ref<StyleBox> style = get_stylebox("slider"); - Ref<StyleBox> grabber_area = get_stylebox("grabber_area"); - Ref<Texture2D> grabber = get_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled"); - Ref<Texture2D> tick = get_icon("tick"); + Ref<StyleBox> style = get_theme_stylebox("slider"); + Ref<StyleBox> grabber_area = get_theme_stylebox("grabber_area"); + Ref<Texture2D> grabber = get_theme_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled"); + Ref<Texture2D> tick = get_theme_icon("tick"); double ratio = Math::is_nan(get_as_ratio()) ? 0 : get_as_ratio(); if (orientation == VERTICAL) { diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 12b2f39538..ccfa8ebf63 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -196,7 +196,7 @@ void SpinBox::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<Texture2D> updown = get_icon("updown"); + Ref<Texture2D> updown = get_theme_icon("updown"); _adjust_width_for_icon(updown); @@ -210,7 +210,7 @@ void SpinBox::_notification(int p_what) { //_value_changed(0); } else if (p_what == NOTIFICATION_ENTER_TREE) { - _adjust_width_for_icon(get_icon("updown")); + _adjust_width_for_icon(get_theme_icon("updown")); _value_changed(0); } else if (p_what == NOTIFICATION_THEME_CHANGED) { diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 255278be2b..4eb614a9ac 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -74,8 +74,8 @@ void SplitContainer::_resort() { bool second_expanded = (vertical ? second->get_v_size_flags() : second->get_h_size_flags()) & SIZE_EXPAND; // Determine the separation between items - Ref<Texture2D> g = get_icon("grabber"); - int sep = get_constant("separation"); + Ref<Texture2D> g = get_theme_icon("grabber"); + int sep = get_theme_constant("separation"); sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0; // Compute the minimum size @@ -123,8 +123,8 @@ Size2 SplitContainer::get_minimum_size() const { /* Calculate MINIMUM SIZE */ Size2i minimum; - Ref<Texture2D> g = get_icon("grabber"); - int sep = get_constant("separation"); + Ref<Texture2D> g = get_theme_icon("grabber"); + int sep = get_theme_constant("separation"); sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0; for (int i = 0; i < 2; i++) { @@ -167,7 +167,7 @@ void SplitContainer::_notification(int p_what) { case NOTIFICATION_MOUSE_EXIT: { mouse_inside = false; - if (get_constant("autohide")) + if (get_theme_constant("autohide")) update(); } break; case NOTIFICATION_DRAW: { @@ -175,14 +175,14 @@ void SplitContainer::_notification(int p_what) { if (!_getch(0) || !_getch(1)) return; - if (collapsed || (!dragging && !mouse_inside && get_constant("autohide"))) + if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide"))) return; if (dragger_visibility != DRAGGER_VISIBLE) return; - int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0; - Ref<Texture2D> tex = get_icon("grabber"); + int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant("separation") : 0; + Ref<Texture2D> tex = get_theme_icon("grabber"); Size2 size = get_size(); if (vertical) @@ -210,7 +210,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { if (mb->is_pressed()) { - int sep = get_constant("separation"); + int sep = get_theme_constant("separation"); if (vertical) { @@ -242,14 +242,14 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { bool mouse_inside_state = false; if (vertical) - mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_constant("separation"); + mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant("separation"); else - mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_constant("separation"); + mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant("separation"); if (mouse_inside != mouse_inside_state) { mouse_inside = mouse_inside_state; - if (get_constant("autohide")) + if (get_theme_constant("autohide")) update(); } @@ -270,7 +270,7 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) { - int sep = get_constant("separation"); + int sep = get_theme_constant("separation"); if (vertical) { diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 6290d364fc..7cecbf7fa2 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -41,14 +41,14 @@ int TabContainer::_get_top_margin() const { return 0; // Respect the minimum tab height. - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); int tab_height = MAX(MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height), tab_disabled->get_minimum_size().height); // Font height or higher icon wins. - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); int content_height = font->get_height(); Vector<Control *> tabs = _get_tabs(); @@ -81,15 +81,15 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { return; // Handle menu button. - Ref<Texture2D> menu = get_icon("menu"); + Ref<Texture2D> menu = get_theme_icon("menu"); if (popup && pos.x > size.width - menu->get_width()) { emit_signal("pre_popup_pressed"); - Vector2 popup_pos = get_global_position(); - popup_pos.x += size.width * get_global_transform().get_scale().x - popup->get_size().width * popup->get_global_transform().get_scale().x; - popup_pos.y += menu->get_height() * get_global_transform().get_scale().y; + Vector2 popup_pos = get_screen_position(); + popup_pos.x += size.width - popup->get_size().width; + popup_pos.y += menu->get_height(); - popup->set_global_position(popup_pos); + popup->set_position(popup_pos); popup->popup(); return; } @@ -107,8 +107,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { popup_ofs = menu->get_width(); } - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); if (pos.x > size.width - increment->get_width() - popup_ofs) { if (last_tab_cache < tabs.size() - 1) { first_tab_cache += 1; @@ -159,7 +159,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { return; } - Ref<Texture2D> menu = get_icon("menu"); + Ref<Texture2D> menu = get_theme_icon("menu"); if (popup) { if (pos.x >= size.width - menu->get_width()) { @@ -191,8 +191,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { popup_ofs = menu->get_width(); } - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); if (pos.x >= size.width - increment->get_width() - popup_ofs) { if (highlight_arrow != 1) { @@ -224,10 +224,10 @@ void TabContainer::_notification(int p_what) { case NOTIFICATION_RESIZED: { Vector<Control *> tabs = _get_tabs(); - int side_margin = get_constant("side_margin"); - Ref<Texture2D> menu = get_icon("menu"); - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> decrement = get_icon("decrement"); + int side_margin = get_theme_constant("side_margin"); + Ref<Texture2D> menu = get_theme_icon("menu"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); int header_width = get_size().width - side_margin * 2; // Find the width of the header area. @@ -262,28 +262,28 @@ void TabContainer::_notification(int p_what) { Size2 size = get_size(); // Draw only the tab area if the header is hidden. - Ref<StyleBox> panel = get_stylebox("panel"); + Ref<StyleBox> panel = get_theme_stylebox("panel"); if (!tabs_visible) { panel->draw(canvas, Rect2(0, 0, size.width, size.height)); return; } Vector<Control *> tabs = _get_tabs(); - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> increment_hl = get_icon("increment_highlight"); - Ref<Texture2D> decrement = get_icon("decrement"); - Ref<Texture2D> decrement_hl = get_icon("decrement_highlight"); - Ref<Texture2D> menu = get_icon("menu"); - Ref<Texture2D> menu_hl = get_icon("menu_highlight"); - Ref<Font> font = get_font("font"); - Color font_color_fg = get_color("font_color_fg"); - Color font_color_bg = get_color("font_color_bg"); - Color font_color_disabled = get_color("font_color_disabled"); - int side_margin = get_constant("side_margin"); - int icon_text_distance = get_constant("hseparation"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> increment_hl = get_theme_icon("increment_highlight"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); + Ref<Texture2D> decrement_hl = get_theme_icon("decrement_highlight"); + Ref<Texture2D> menu = get_theme_icon("menu"); + Ref<Texture2D> menu_hl = get_theme_icon("menu_highlight"); + Ref<Font> font = get_theme_font("font"); + Color font_color_fg = get_theme_color("font_color_fg"); + Color font_color_bg = get_theme_color("font_color_bg"); + Color font_color_disabled = get_theme_color("font_color_disabled"); + int side_margin = get_theme_constant("side_margin"); + int icon_text_distance = get_theme_constant("hseparation"); // Find out start and width of the header area. int header_x = side_margin; @@ -458,7 +458,7 @@ int TabContainer::_get_tab_width(int p_index) const { return 0; // Get the width of the text displayed on the tab. - Ref<Font> font = get_font("font"); + Ref<Font> font = get_theme_font("font"); String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(control->get_name()); int width = font->get_string_size(text).width; @@ -468,14 +468,14 @@ int TabContainer::_get_tab_width(int p_index) const { if (icon.is_valid()) { width += icon->get_width(); if (text != "") - width += get_constant("hseparation"); + width += get_theme_constant("hseparation"); } } // Respect a minimum size. - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); if (get_tab_disabled(p_index)) { width += tab_disabled->get_minimum_size().width; } else if (p_index == current) { @@ -530,7 +530,7 @@ void TabContainer::add_child_notify(Node *p_child) { c->set_anchors_and_margins_preset(Control::PRESET_WIDE); if (tabs_visible) c->set_margin(MARGIN_TOP, _get_top_margin()); - Ref<StyleBox> sb = get_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox("panel"); c->set_margin(Margin(MARGIN_TOP), c->get_margin(Margin(MARGIN_TOP)) + sb->get_margin(Margin(MARGIN_TOP))); c->set_margin(Margin(MARGIN_LEFT), c->get_margin(Margin(MARGIN_LEFT)) + sb->get_margin(Margin(MARGIN_LEFT))); c->set_margin(Margin(MARGIN_RIGHT), c->get_margin(Margin(MARGIN_RIGHT)) - sb->get_margin(Margin(MARGIN_RIGHT))); @@ -554,7 +554,7 @@ void TabContainer::set_current_tab(int p_current) { int pending_previous = current; current = p_current; - Ref<StyleBox> sb = get_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox("panel"); Vector<Control *> tabs = _get_tabs(); for (int i = 0; i < tabs.size(); i++) { @@ -745,12 +745,12 @@ int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const { int right_ofs = 0; if (popup) { - Ref<Texture2D> menu = get_icon("menu"); + Ref<Texture2D> menu = get_theme_icon("menu"); right_ofs += menu->get_width(); } if (buttons_visible_cache) { - Ref<Texture2D> increment = get_icon("increment"); - Ref<Texture2D> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon("increment"); + Ref<Texture2D> decrement = get_theme_icon("decrement"); right_ofs += increment->get_width() + decrement->get_width(); } if (p_point.x > size.width - right_ofs) { @@ -933,17 +933,17 @@ Size2 TabContainer::get_minimum_size() const { ms.y = MAX(ms.y, cms.y); } - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Font> font = get_theme_font("font"); if (tabs_visible) { ms.y += MAX(MAX(tab_bg->get_minimum_size().y, tab_fg->get_minimum_size().y), tab_disabled->get_minimum_size().y); ms.y += font->get_height(); } - Ref<StyleBox> sb = get_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox("panel"); ms += sb->get_minimum_size(); return ms; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 901408919a..ea6d44e3a7 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -37,10 +37,10 @@ Size2 Tabs::get_minimum_size() const { - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Font> font = get_theme_font("font"); Size2 ms(0, MAX(MAX(tab_bg->get_minimum_size().height, tab_fg->get_minimum_size().height), tab_disabled->get_minimum_size().height) + font->get_height()); @@ -50,7 +50,7 @@ Size2 Tabs::get_minimum_size() const { if (tex.is_valid()) { ms.height = MAX(ms.height, tex->get_size().height); if (tabs[i].text != "") - ms.width += get_constant("hseparation"); + ms.width += get_theme_constant("hseparation"); } ms.width += Math::ceil(font->get_string_size(tabs[i].xl_text).width); @@ -65,15 +65,15 @@ Size2 Tabs::get_minimum_size() const { if (tabs[i].right_button.is_valid()) { Ref<Texture2D> rb = tabs[i].right_button; Size2 bms = rb->get_size(); - bms.width += get_constant("hseparation"); + bms.width += get_theme_constant("hseparation"); ms.width += bms.width; ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<Texture2D> cb = get_icon("close"); + Ref<Texture2D> cb = get_theme_icon("close"); Size2 bms = cb->get_size(); - bms.width += get_constant("hseparation"); + bms.width += get_theme_constant("hseparation"); ms.width += bms.width; ms.height = MAX(bms.height + tab_bg->get_minimum_size().height, ms.height); } @@ -94,8 +94,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { highlight_arrow = -1; if (buttons_visible) { - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); @@ -163,8 +163,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { if (buttons_visible) { - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); @@ -238,14 +238,14 @@ void Tabs::_notification(int p_what) { _update_cache(); RID ci = get_canvas_item(); - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Font> font = get_font("font"); - Color color_fg = get_color("font_color_fg"); - Color color_bg = get_color("font_color_bg"); - Color color_disabled = get_color("font_color_disabled"); - Ref<Texture2D> close = get_icon("close"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Font> font = get_theme_font("font"); + Color color_fg = get_theme_color("font_color_fg"); + Color color_bg = get_theme_color("font_color_bg"); + Color color_disabled = get_theme_color("font_color_disabled"); + Ref<Texture2D> close = get_theme_icon("close"); int h = get_size().height; int w = 0; @@ -267,10 +267,10 @@ void Tabs::_notification(int p_what) { w = 0; } - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); - Ref<Texture2D> incr_hl = get_icon("increment_highlight"); - Ref<Texture2D> decr_hl = get_icon("decrement_highlight"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr_hl = get_theme_icon("increment_highlight"); + Ref<Texture2D> decr_hl = get_theme_icon("decrement_highlight"); int limit = get_size().width - incr->get_size().width - decr->get_size().width; @@ -318,7 +318,7 @@ void Tabs::_notification(int p_what) { icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2)); if (tabs[i].text != "") - w += icon->get_width() + get_constant("hseparation"); + w += icon->get_width() + get_theme_constant("hseparation"); } font->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - font->get_height()) / 2 + font->get_ascent()), tabs[i].xl_text, col, tabs[i].size_text); @@ -327,10 +327,10 @@ void Tabs::_notification(int p_what) { if (tabs[i].right_button.is_valid()) { - Ref<StyleBox> style = get_stylebox("button"); + Ref<StyleBox> style = get_theme_stylebox("button"); Ref<Texture2D> rb = tabs[i].right_button; - w += get_constant("hseparation"); + w += get_theme_constant("hseparation"); Rect2 rb_rect; rb_rect.size = style->get_minimum_size() + rb->get_size(); @@ -339,7 +339,7 @@ void Tabs::_notification(int p_what) { if (rb_hover == i) { if (rb_pressing) - get_stylebox("button_pressed")->draw(ci, rb_rect); + get_theme_stylebox("button_pressed")->draw(ci, rb_rect); else style->draw(ci, rb_rect); } @@ -351,10 +351,10 @@ void Tabs::_notification(int p_what) { if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<StyleBox> style = get_stylebox("button"); + Ref<StyleBox> style = get_theme_stylebox("button"); Ref<Texture2D> cb = close; - w += get_constant("hseparation"); + w += get_theme_constant("hseparation"); Rect2 cb_rect; cb_rect.size = style->get_minimum_size() + cb->get_size(); @@ -363,7 +363,7 @@ void Tabs::_notification(int p_what) { if (!tabs[i].disabled && cb_hover == i) { if (cb_pressing) - get_stylebox("button_pressed")->draw(ci, cb_rect); + get_theme_stylebox("button_pressed")->draw(ci, cb_rect); else style->draw(ci, cb_rect); } @@ -532,12 +532,12 @@ void Tabs::_update_hover() { } void Tabs::_update_cache() { - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<Font> font = get_font("font"); - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<Font> font = get_theme_font("font"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); int w = 0; @@ -577,12 +577,12 @@ void Tabs::_update_cache() { slen = m_width - (sb->get_margin(MARGIN_LEFT) + sb->get_margin(MARGIN_RIGHT)); if (tabs[i].icon.is_valid()) { slen -= tabs[i].icon->get_width(); - slen -= get_constant("hseparation"); + slen -= get_theme_constant("hseparation"); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<Texture2D> cb = get_icon("close"); + Ref<Texture2D> cb = get_theme_icon("close"); slen -= cb->get_width(); - slen -= get_constant("hseparation"); + slen -= get_theme_constant("hseparation"); } slen = MAX(slen, 1); lsize = m_width; @@ -799,10 +799,10 @@ int Tabs::get_tab_width(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, tabs.size(), 0); - Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); - Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); - Ref<StyleBox> tab_disabled = get_stylebox("tab_disabled"); - Ref<Font> font = get_font("font"); + Ref<StyleBox> tab_bg = get_theme_stylebox("tab_bg"); + Ref<StyleBox> tab_fg = get_theme_stylebox("tab_fg"); + Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<Font> font = get_theme_font("font"); int x = 0; @@ -810,7 +810,7 @@ int Tabs::get_tab_width(int p_idx) const { if (tex.is_valid()) { x += tex->get_width(); if (tabs[p_idx].text != "") - x += get_constant("hseparation"); + x += get_theme_constant("hseparation"); } x += Math::ceil(font->get_string_size(tabs[p_idx].xl_text).width); @@ -825,13 +825,13 @@ int Tabs::get_tab_width(int p_idx) const { if (tabs[p_idx].right_button.is_valid()) { Ref<Texture2D> rb = tabs[p_idx].right_button; x += rb->get_width(); - x += get_constant("hseparation"); + x += get_theme_constant("hseparation"); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx == current)) { - Ref<Texture2D> cb = get_icon("close"); + Ref<Texture2D> cb = get_theme_icon("close"); x += cb->get_width(); - x += get_constant("hseparation"); + x += get_theme_constant("hseparation"); } return x; @@ -842,8 +842,8 @@ void Tabs::_ensure_no_over_offset() { if (!is_inside_tree()) return; - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); @@ -885,8 +885,8 @@ void Tabs::ensure_tab_visible(int p_idx) { } int prev_offset = offset; - Ref<Texture2D> incr = get_icon("increment"); - Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); for (int i = offset; i <= p_idx; i++) { if (tabs[i].ofs_cache + tabs[i].size_cache > limit) { diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 7de6a04c54..5bc920b04e 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -1584,11 +1584,11 @@ void TextEdit::_notification(int p_what) { bool completion_below = false; if (completion_active && completion_options.size() > 0) { // Code completion box. - Ref<StyleBox> csb = get_stylebox("completion"); - int maxlines = get_constant("completion_lines"); - int cmax_width = get_constant("completion_max_width") * cache.font->get_char_size('x').x; - int scrollw = get_constant("completion_scroll_width"); - Color scrollc = get_color("completion_scroll_color"); + Ref<StyleBox> csb = get_theme_stylebox("completion"); + int maxlines = get_theme_constant("completion_lines"); + int cmax_width = get_theme_constant("completion_max_width") * cache.font->get_char_size('x').x; + int scrollw = get_theme_constant("completion_scroll_width"); + Color scrollc = get_theme_color("completion_scroll_color"); const int completion_options_size = completion_options.size(); int lines = MIN(completion_options_size, maxlines); @@ -1607,7 +1607,7 @@ void TextEdit::_notification(int p_what) { } // Add space for completion icons. - const int icon_hsep = get_constant("hseparation", "ItemList"); + const int icon_hsep = get_theme_constant("hseparation", "ItemList"); Size2 icon_area_size(get_row_height(), get_row_height()); w += icon_area_size.width + icon_hsep; @@ -1694,9 +1694,9 @@ void TextEdit::_notification(int p_what) { if (show_hint) { - Ref<StyleBox> sb = get_stylebox("panel", "TooltipPanel"); + Ref<StyleBox> sb = get_theme_stylebox("panel", "TooltipPanel"); Ref<Font> font = cache.font; - Color font_color = get_color("font_color", "TooltipLabel"); + Color font_color = get_theme_color("font_color", "TooltipLabel"); int max_w = 0; int sc = completion_hint.get_slice_count("\n"); @@ -2477,9 +2477,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } - menu->set_position(get_global_transform().xform(get_local_mouse_position())); + menu->set_position(get_screen_transform().xform(get_local_mouse_position())); menu->set_size(Vector2(1, 1)); - menu->set_scale(get_global_transform().get_scale()); + // menu->set_scale(get_global_transform().get_scale()); menu->popup(); grab_focus(); } @@ -2634,7 +2634,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (k->get_keycode() == KEY_PAGEUP) { - completion_index -= get_constant("completion_lines"); + completion_index -= get_theme_constant("completion_lines"); if (completion_index < 0) completion_index = 0; completion_current = completion_options[completion_index]; @@ -2645,7 +2645,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (k->get_keycode() == KEY_PAGEDOWN) { - completion_index += get_constant("completion_lines"); + completion_index += get_theme_constant("completion_lines"); if (completion_index >= completion_options.size()) completion_index = completion_options.size() - 1; completion_current = completion_options[completion_index]; @@ -3735,7 +3735,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (context_menu_enabled) { menu->set_position(get_global_transform().xform(_get_cursor_pixel_pos())); menu->set_size(Vector2(1, 1)); - menu->set_scale(get_global_transform().get_scale()); + // menu->set_scale(get_global_transform().get_scale()); menu->popup(); menu->grab_focus(); } @@ -5026,51 +5026,51 @@ void TextEdit::_toggle_draw_caret() { void TextEdit::_update_caches() { - cache.style_normal = get_stylebox("normal"); - cache.style_focus = get_stylebox("focus"); - cache.style_readonly = get_stylebox("read_only"); - cache.completion_background_color = get_color("completion_background_color"); - cache.completion_selected_color = get_color("completion_selected_color"); - cache.completion_existing_color = get_color("completion_existing_color"); - cache.completion_font_color = get_color("completion_font_color"); - cache.font = get_font("font"); - cache.caret_color = get_color("caret_color"); - cache.caret_background_color = get_color("caret_background_color"); - cache.line_number_color = get_color("line_number_color"); - cache.safe_line_number_color = get_color("safe_line_number_color"); - cache.font_color = get_color("font_color"); - cache.font_color_selected = get_color("font_color_selected"); - cache.font_color_readonly = get_color("font_color_readonly"); - cache.keyword_color = get_color("keyword_color"); - cache.function_color = get_color("function_color"); - cache.member_variable_color = get_color("member_variable_color"); - cache.number_color = get_color("number_color"); - cache.selection_color = get_color("selection_color"); - cache.mark_color = get_color("mark_color"); - cache.current_line_color = get_color("current_line_color"); - cache.line_length_guideline_color = get_color("line_length_guideline_color"); - cache.bookmark_color = get_color("bookmark_color"); - cache.breakpoint_color = get_color("breakpoint_color"); - cache.executing_line_color = get_color("executing_line_color"); - cache.code_folding_color = get_color("code_folding_color"); - cache.brace_mismatch_color = get_color("brace_mismatch_color"); - cache.word_highlighted_color = get_color("word_highlighted_color"); - cache.search_result_color = get_color("search_result_color"); - cache.search_result_border_color = get_color("search_result_border_color"); - cache.symbol_color = get_color("symbol_color"); - cache.background_color = get_color("background_color"); + cache.style_normal = get_theme_stylebox("normal"); + cache.style_focus = get_theme_stylebox("focus"); + cache.style_readonly = get_theme_stylebox("read_only"); + cache.completion_background_color = get_theme_color("completion_background_color"); + cache.completion_selected_color = get_theme_color("completion_selected_color"); + cache.completion_existing_color = get_theme_color("completion_existing_color"); + cache.completion_font_color = get_theme_color("completion_font_color"); + cache.font = get_theme_font("font"); + cache.caret_color = get_theme_color("caret_color"); + cache.caret_background_color = get_theme_color("caret_background_color"); + cache.line_number_color = get_theme_color("line_number_color"); + cache.safe_line_number_color = get_theme_color("safe_line_number_color"); + cache.font_color = get_theme_color("font_color"); + cache.font_color_selected = get_theme_color("font_color_selected"); + cache.font_color_readonly = get_theme_color("font_color_readonly"); + cache.keyword_color = get_theme_color("keyword_color"); + cache.function_color = get_theme_color("function_color"); + cache.member_variable_color = get_theme_color("member_variable_color"); + cache.number_color = get_theme_color("number_color"); + cache.selection_color = get_theme_color("selection_color"); + cache.mark_color = get_theme_color("mark_color"); + cache.current_line_color = get_theme_color("current_line_color"); + cache.line_length_guideline_color = get_theme_color("line_length_guideline_color"); + cache.bookmark_color = get_theme_color("bookmark_color"); + cache.breakpoint_color = get_theme_color("breakpoint_color"); + cache.executing_line_color = get_theme_color("executing_line_color"); + cache.code_folding_color = get_theme_color("code_folding_color"); + cache.brace_mismatch_color = get_theme_color("brace_mismatch_color"); + cache.word_highlighted_color = get_theme_color("word_highlighted_color"); + cache.search_result_color = get_theme_color("search_result_color"); + cache.search_result_border_color = get_theme_color("search_result_border_color"); + cache.symbol_color = get_theme_color("symbol_color"); + cache.background_color = get_theme_color("background_color"); #ifdef TOOLS_ENABLED - cache.line_spacing = get_constant("line_spacing") * EDSCALE; + cache.line_spacing = get_theme_constant("line_spacing") * EDSCALE; #else cache.line_spacing = get_constant("line_spacing"); #endif cache.row_height = cache.font->get_height() + cache.line_spacing; - cache.tab_icon = get_icon("tab"); - cache.space_icon = get_icon("space"); - cache.folded_icon = get_icon("folded"); - cache.can_fold_icon = get_icon("fold"); - cache.folded_eol_icon = get_icon("GuiEllipsis", "EditorIcons"); - cache.executing_icon = get_icon("MainPlay", "EditorIcons"); + cache.tab_icon = get_theme_icon("tab"); + cache.space_icon = get_theme_icon("space"); + cache.folded_icon = get_theme_icon("folded"); + cache.can_fold_icon = get_theme_icon("fold"); + cache.folded_eol_icon = get_theme_icon("GuiEllipsis", "EditorIcons"); + cache.executing_icon = get_theme_icon("MainPlay", "EditorIcons"); text.set_font(cache.font); if (syntax_highlighter) { diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 0ac8a9bf94..7bac82bf63 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -952,45 +952,45 @@ TreeItem::~TreeItem() { void Tree::update_cache() { - cache.font = get_font("font"); - cache.tb_font = get_font("title_button_font"); - cache.bg = get_stylebox("bg"); - cache.selected = get_stylebox("selected"); - cache.selected_focus = get_stylebox("selected_focus"); - cache.cursor = get_stylebox("cursor"); - cache.cursor_unfocus = get_stylebox("cursor_unfocused"); - cache.button_pressed = get_stylebox("button_pressed"); - - cache.checked = get_icon("checked"); - cache.unchecked = get_icon("unchecked"); - cache.arrow_collapsed = get_icon("arrow_collapsed"); - cache.arrow = get_icon("arrow"); - cache.select_arrow = get_icon("select_arrow"); - cache.updown = get_icon("updown"); - - cache.custom_button = get_stylebox("custom_button"); - cache.custom_button_hover = get_stylebox("custom_button_hover"); - cache.custom_button_pressed = get_stylebox("custom_button_pressed"); - cache.custom_button_font_highlight = get_color("custom_button_font_highlight"); - - cache.font_color = get_color("font_color"); - cache.font_color_selected = get_color("font_color_selected"); - cache.guide_color = get_color("guide_color"); - cache.drop_position_color = get_color("drop_position_color"); - cache.hseparation = get_constant("hseparation"); - cache.vseparation = get_constant("vseparation"); - cache.item_margin = get_constant("item_margin"); - cache.button_margin = get_constant("button_margin"); - cache.draw_guides = get_constant("draw_guides"); - cache.draw_relationship_lines = get_constant("draw_relationship_lines"); - cache.relationship_line_color = get_color("relationship_line_color"); - cache.scroll_border = get_constant("scroll_border"); - cache.scroll_speed = get_constant("scroll_speed"); - - cache.title_button = get_stylebox("title_button_normal"); - cache.title_button_pressed = get_stylebox("title_button_pressed"); - cache.title_button_hover = get_stylebox("title_button_hover"); - cache.title_button_color = get_color("title_button_color"); + cache.font = get_theme_font("font"); + cache.tb_font = get_theme_font("title_button_font"); + cache.bg = get_theme_stylebox("bg"); + cache.selected = get_theme_stylebox("selected"); + cache.selected_focus = get_theme_stylebox("selected_focus"); + cache.cursor = get_theme_stylebox("cursor"); + cache.cursor_unfocus = get_theme_stylebox("cursor_unfocused"); + cache.button_pressed = get_theme_stylebox("button_pressed"); + + cache.checked = get_theme_icon("checked"); + cache.unchecked = get_theme_icon("unchecked"); + cache.arrow_collapsed = get_theme_icon("arrow_collapsed"); + cache.arrow = get_theme_icon("arrow"); + cache.select_arrow = get_theme_icon("select_arrow"); + cache.updown = get_theme_icon("updown"); + + cache.custom_button = get_theme_stylebox("custom_button"); + cache.custom_button_hover = get_theme_stylebox("custom_button_hover"); + cache.custom_button_pressed = get_theme_stylebox("custom_button_pressed"); + cache.custom_button_font_highlight = get_theme_color("custom_button_font_highlight"); + + cache.font_color = get_theme_color("font_color"); + cache.font_color_selected = get_theme_color("font_color_selected"); + cache.guide_color = get_theme_color("guide_color"); + cache.drop_position_color = get_theme_color("drop_position_color"); + cache.hseparation = get_theme_constant("hseparation"); + cache.vseparation = get_theme_constant("vseparation"); + cache.item_margin = get_theme_constant("item_margin"); + cache.button_margin = get_theme_constant("button_margin"); + cache.draw_guides = get_theme_constant("draw_guides"); + cache.draw_relationship_lines = get_theme_constant("draw_relationship_lines"); + cache.relationship_line_color = get_theme_color("relationship_line_color"); + cache.scroll_border = get_theme_constant("scroll_border"); + cache.scroll_speed = get_theme_constant("scroll_speed"); + + cache.title_button = get_theme_stylebox("title_button_normal"); + cache.title_button_pressed = get_theme_stylebox("title_button_pressed"); + cache.title_button_hover = get_theme_stylebox("title_button_hover"); + cache.title_button_color = get_theme_color("title_button_color"); v_scroll->set_custom_step(cache.font->get_height()); } @@ -1291,7 +1291,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } } - Color col = p_item->cells[i].custom_color ? p_item->cells[i].color : get_color(p_item->cells[i].selected ? "font_color_selected" : "font_color"); + Color col = p_item->cells[i].custom_color ? p_item->cells[i].color : get_theme_color(p_item->cells[i].selected ? "font_color_selected" : "font_color"); Color icon_col = p_item->cells[i].icon_color; Point2i text_pos = item_rect.position; @@ -3011,7 +3011,7 @@ void Tree::_notification(int p_what) { RID ci = get_canvas_item(); Ref<StyleBox> bg = cache.bg; - Ref<StyleBox> bg_focus = get_stylebox("bg_focus"); + Ref<StyleBox> bg_focus = get_theme_stylebox("bg_focus"); Point2 draw_ofs; draw_ofs += bg->get_offset(); @@ -4020,7 +4020,7 @@ Tree::Tree() { popup_menu = memnew(PopupMenu); popup_menu->hide(); add_child(popup_menu); - popup_menu->set_as_toplevel(true); + // popup_menu->set_as_toplevel(true); text_editor = memnew(LineEdit); add_child(text_editor); text_editor->set_as_toplevel(true); diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 4fbb1cb870..50d0520d4b 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -1309,7 +1309,7 @@ Transform2D Viewport::_get_input_pre_xform() const { Transform2D pre_xf; - if (to_screen_rect != Rect2i()) { + if (to_screen_rect.size.x != 0 && to_screen_rect.size.y != 0) { pre_xf.elements[2] = -to_screen_rect.position; pre_xf.scale(size / to_screen_rect.size); @@ -1460,7 +1460,7 @@ void Viewport::_gui_show_tooltip() { gui.tooltip_label = memnew(TooltipLabel); gui.tooltip_popup->add_child(gui.tooltip_label); - Ref<StyleBox> ttp = gui.tooltip_label->get_stylebox("panel", "TooltipPanel"); + Ref<StyleBox> ttp = gui.tooltip_label->get_theme_stylebox("panel", "TooltipPanel"); gui.tooltip_label->set_anchor_and_margin(MARGIN_LEFT, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_LEFT)); gui.tooltip_label->set_anchor_and_margin(MARGIN_TOP, Control::ANCHOR_BEGIN, ttp->get_margin(MARGIN_TOP)); @@ -1995,37 +1995,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { Control *top = gui.modal_stack.back()->get(); if (over != top && !top->is_a_parent_of(over)) { - - PopupMenu *popup_menu = Object::cast_to<PopupMenu>(top); - MenuButton *popup_menu_parent = NULL; - MenuButton *menu_button = Object::cast_to<MenuButton>(over); - - if (popup_menu) { - popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent()); - if (!popup_menu_parent) { - // Go through the parents to see if there's a MenuButton at the end. - while (Object::cast_to<PopupMenu>(popup_menu->get_parent())) { - popup_menu = Object::cast_to<PopupMenu>(popup_menu->get_parent()); - } - popup_menu_parent = Object::cast_to<MenuButton>(popup_menu->get_parent()); - } - } - - // If the mouse is over a menu button, this menu will open automatically - // if there is already a pop-up menu open at the same hierarchical level. - if (popup_menu_parent && menu_button && popup_menu_parent->is_switch_on_hover() && - !menu_button->is_disabled() && menu_button->is_switch_on_hover() && - (popup_menu_parent->get_parent()->is_a_parent_of(menu_button) || - menu_button->get_parent()->is_a_parent_of(popup_menu))) { - - popup_menu->notification(Control::NOTIFICATION_MODAL_CLOSE); - popup_menu->_modal_stack_remove(); - popup_menu->hide(); - - menu_button->pressed(); - } else { - over = NULL; //nothing can be found outside the modal stack - } + over = NULL; //nothing can be found outside the modal stack } } diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 61817f086c..6d61f3f0a8 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -394,7 +394,7 @@ void Window::_make_transient() { if (window) { transient_parent = window; window->transient_children.insert(this); - if (exclusive) { + if (is_inside_tree() && is_visible() && exclusive) { if (transient_parent->exclusive_child == nullptr) { transient_parent->exclusive_child = this; } else if (transient_parent->exclusive_child != this) { @@ -439,9 +439,9 @@ void Window::set_exclusive(bool p_exclusive) { exclusive = p_exclusive; if (transient_parent) { - if (p_exclusive) { + if (p_exclusive && is_inside_tree() && is_visible()) { ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child."); - transient_parent->exclusive_child = nullptr; + transient_parent->exclusive_child = this; } else { if (transient_parent->exclusive_child == this) { transient_parent->exclusive_child = nullptr; @@ -762,8 +762,10 @@ void Window::_window_input(const Ref<InputEvent> &p_ev) { if (exclusive_child != nullptr) { exclusive_child->grab_focus(); + print_line("drop because of exclusive"); return; //has an exclusive child, can't get events until child is closed } + emit_signal(SceneStringNames::get_singleton()->window_input, p_ev); input(p_ev); if (!is_input_handled()) { @@ -897,6 +899,8 @@ void Window::popup_centered_ratio(float p_ratio) { } void Window::popup(const Rect2 &p_screen_rect) { + + emit_signal("about_to_popup"); if (p_screen_rect != Rect2()) { set_position(p_screen_rect.position); set_size(p_screen_rect.size); @@ -908,6 +912,10 @@ void Window::popup(const Rect2 &p_screen_rect) { notification(NOTIFICATION_POST_POPUP); } +Size2 Window::get_contents_minimum_size() const { + return _get_contents_minimum_size(); +} + void Window::grab_focus() { if (window_id != DisplayServer::INVALID_WINDOW_ID) { DisplayServer::get_singleton()->window_move_to_foreground(window_id); @@ -979,6 +987,74 @@ Ref<Theme> Window::get_theme() const { return theme; } +Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_type) const { + return Control::get_icons(theme_owner, theme_owner_window, p_name, p_type); +} +Ref<Shader> Window::get_theme_shader(const StringName &p_name, const StringName &p_type) const { + return Control::get_shaders(theme_owner, theme_owner_window, p_name, p_type); +} +Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const { + return Control::get_styleboxs(theme_owner, theme_owner_window, p_name, p_type); +} +Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_type) const { + return Control::get_fonts(theme_owner, theme_owner_window, p_name, p_type); +} +Color Window::get_theme_color(const StringName &p_name, const StringName &p_type) const { + return Control::get_colors(theme_owner, theme_owner_window, p_name, p_type); +} +int Window::get_theme_constant(const StringName &p_name, const StringName &p_type) const { + return Control::get_constants(theme_owner, theme_owner_window, p_name, p_type); +} + +bool Window::has_theme_icon(const StringName &p_name, const StringName &p_type) const { + return Control::has_icons(theme_owner, theme_owner_window, p_name, p_type); +} +bool Window::has_theme_shader(const StringName &p_name, const StringName &p_type) const { + return Control::has_shaders(theme_owner, theme_owner_window, p_name, p_type); +} +bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const { + return Control::has_styleboxs(theme_owner, theme_owner_window, p_name, p_type); +} +bool Window::has_theme_font(const StringName &p_name, const StringName &p_type) const { + return Control::has_fonts(theme_owner, theme_owner_window, p_name, p_type); +} +bool Window::has_theme_color(const StringName &p_name, const StringName &p_type) const { + return Control::has_colors(theme_owner, theme_owner_window, p_name, p_type); +} +bool Window::has_theme_constant(const StringName &p_name, const StringName &p_type) const { + return Control::has_constants(theme_owner, theme_owner_window, p_name, p_type); +} + +Rect2i Window::get_screen_rect() const { + if (is_embedded()) { + //viewport + return Rect2i(); + } else { + int x = get_position().x; + int closest_dist = 0x7FFFFFFF; + Rect2i closest_rect; + for (int i = 0; i < DisplayServer::get_singleton()->get_screen_count(); i++) { + Rect2i s(DisplayServer::get_singleton()->screen_get_position(i), DisplayServer::get_singleton()->screen_get_size(i)); + int d; + if (x >= s.position.x && x < s.size.x) { + //contained + closest_rect = s; + break; + } else if (x < s.position.x) { + d = s.position.x - x; + } else { + d = x - (s.position.x + s.size.x); + } + + if (d < closest_dist) { + closest_dist = d; + closest_rect = s; + } + } + return closest_rect; + } +} + void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title); @@ -1055,6 +1131,18 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Window::set_theme); ClassDB::bind_method(D_METHOD("get_theme"), &Window::get_theme); + ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "type"), &Window::get_theme_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "type"), &Window::get_theme_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_font", "name", "type"), &Window::get_theme_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_color", "name", "type"), &Window::get_theme_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "type"), &Window::get_theme_constant, DEFVAL("")); + + ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "type"), &Window::has_theme_icon, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "type"), &Window::has_theme_stylebox, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_font", "name", "type"), &Window::has_theme_font, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_color", "name", "type"), &Window::has_theme_color, DEFVAL("")); + ClassDB::bind_method(D_METHOD("has_theme_constant", "name", "type"), &Window::has_theme_constant, DEFVAL("")); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "position"), "set_position", "get_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size"), "set_size", "get_size"); @@ -1080,7 +1168,7 @@ void Window::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); ADD_SIGNAL(MethodInfo("window_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); - ADD_SIGNAL(MethodInfo("files_dropped")); + ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files"))); ADD_SIGNAL(MethodInfo("mouse_entered")); ADD_SIGNAL(MethodInfo("mouse_exited")); ADD_SIGNAL(MethodInfo("focus_entered")); @@ -1088,6 +1176,8 @@ void Window::_bind_methods() { ADD_SIGNAL(MethodInfo("close_requested")); ADD_SIGNAL(MethodInfo("go_back_requested")); ADD_SIGNAL(MethodInfo("visibility_changed")); + ADD_SIGNAL(MethodInfo("files_dropped")); + ADD_SIGNAL(MethodInfo("about_to_popup")); BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED); } diff --git a/scene/main/window.h b/scene/main/window.h index acc3e11fdc..298a611575 100644 --- a/scene/main/window.h +++ b/scene/main/window.h @@ -224,9 +224,27 @@ public: void set_theme(const Ref<Theme> &p_theme); Ref<Theme> get_theme() const; + Size2 get_contents_minimum_size() const; + void grab_focus(); bool has_focus() const; + Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<Shader> get_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; + Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const; + Color get_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const; + int get_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const; + + bool has_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_color(const StringName &p_name, const StringName &p_type = StringName()) const; + bool has_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const; + + Rect2i get_screen_rect() const; + Window(); ~Window(); }; |