diff options
Diffstat (limited to 'scene/gui')
56 files changed, 837 insertions, 756 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index 6f3d8c61cf..784d298bff 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -40,7 +40,7 @@ Size2 Button::get_minimum_size() const { minsize.width = 0; if (!expand_icon) { - Ref<Texture> _icon; + Ref<Texture2D> _icon; if (icon.is_null() && has_icon("icon")) _icon = Control::get_icon("icon"); else @@ -106,7 +106,7 @@ void Button::_notification(int p_what) { break; } - FALLTHROUGH; + [[fallthrough]]; } case DRAW_PRESSED: { @@ -150,7 +150,7 @@ void Button::_notification(int p_what) { } Ref<Font> font = get_font("font"); - Ref<Texture> _icon; + Ref<Texture2D> _icon; if (icon.is_null() && has_icon("icon")) _icon = Control::get_icon("icon"); else @@ -249,7 +249,7 @@ String Button::get_text() const { return text; } -void Button::set_icon(const Ref<Texture> &p_icon) { +void Button::set_icon(const Ref<Texture2D> &p_icon) { if (icon == p_icon) return; @@ -259,7 +259,7 @@ void Button::set_icon(const Ref<Texture> &p_icon) { minimum_size_changed(); } -Ref<Texture> Button::get_icon() const { +Ref<Texture2D> Button::get_icon() const { return icon; } @@ -331,7 +331,7 @@ void Button::_bind_methods() { BIND_ENUM_CONSTANT(ALIGN_RIGHT); ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_button_icon", "get_button_icon"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_button_icon", "get_button_icon"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flat"), "set_flat", "is_flat"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "get_clip_text"); ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_text_align", "get_text_align"); diff --git a/scene/gui/button.h b/scene/gui/button.h index e975dc52a5..3135b98578 100644 --- a/scene/gui/button.h +++ b/scene/gui/button.h @@ -48,7 +48,7 @@ private: bool flat; String text; String xl_text; - Ref<Texture> icon; + Ref<Texture2D> icon; bool expand_icon; bool clip_text; TextAlign align; @@ -65,8 +65,8 @@ public: void set_text(const String &p_text); String get_text() const; - void set_icon(const Ref<Texture> &p_icon); - Ref<Texture> get_icon() const; + void set_icon(const Ref<Texture2D> &p_icon); + Ref<Texture2D> get_icon() const; void set_expand_icon(bool p_expand_icon); bool is_expand_icon() const; diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index 443121db32..89bd8ab0dd 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<Texture> checked = Control::get_icon("checked"); - Ref<Texture> unchecked = Control::get_icon("unchecked"); - Ref<Texture> radio_checked = Control::get_icon("radio_checked"); - Ref<Texture> radio_unchecked = Control::get_icon("radio_unchecked"); + 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"); Size2 tex_size = Size2(0, 0); if (!checked.is_null()) @@ -73,8 +73,8 @@ void CheckBox::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture> on = Control::get_icon(is_radio() ? "radio_checked" : "checked"); - Ref<Texture> off = Control::get_icon(is_radio() ? "radio_unchecked" : "unchecked"); + 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"); Vector2 ofs; diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index 9d6df94cce..0b093ce850 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -35,8 +35,8 @@ Size2 CheckButton::get_icon_size() const { - Ref<Texture> on = Control::get_icon(is_disabled() ? "on_disabled" : "on"); - Ref<Texture> off = Control::get_icon(is_disabled() ? "off_disabled" : "off"); + Ref<Texture2D> on = Control::get_icon(is_disabled() ? "on_disabled" : "on"); + Ref<Texture2D> off = Control::get_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()); @@ -68,8 +68,8 @@ void CheckButton::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture> on = Control::get_icon(is_disabled() ? "on_disabled" : "on"); - Ref<Texture> off = Control::get_icon(is_disabled() ? "off_disabled" : "off"); + Ref<Texture2D> on = Control::get_icon(is_disabled() ? "on_disabled" : "on"); + Ref<Texture2D> off = Control::get_icon(is_disabled() ? "off_disabled" : "off"); Ref<StyleBox> sb = get_stylebox("normal"); Vector2 ofs; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 01f4070883..cbbad79811 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -59,7 +59,7 @@ void ColorPicker::_notification(int p_what) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { - PoolColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PoolColorArray()); + PackedColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PackedColorArray()); for (int i = 0; i < saved_presets.size(); i++) { add_preset(saved_presets[i]); @@ -295,7 +295,7 @@ void ColorPicker::add_preset(const Color &p_color) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { - PoolColorArray arr_to_save = get_presets(); + PackedColorArray arr_to_save = get_presets(); EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save); } #endif @@ -309,16 +309,16 @@ void ColorPicker::erase_preset(const Color &p_color) { #ifdef TOOLS_ENABLED if (Engine::get_singleton()->is_editor_hint()) { - PoolColorArray arr_to_save = get_presets(); + PackedColorArray arr_to_save = get_presets(); EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save); } #endif } } -PoolColorArray ColorPicker::get_presets() const { +PackedColorArray ColorPicker::get_presets() const { - PoolColorArray arr; + PackedColorArray arr; arr.resize(presets.size()); for (int i = 0; i < presets.size(); i++) { arr.set(i, presets[i]); @@ -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<Texture> hue = get_icon("color_hue", "ColorPicker"); + Ref<Texture2D> hue = get_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(); @@ -593,10 +593,10 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) { Ref<Image> img = r->get_texture()->get_data(); if (img.is_valid() && !img->empty()) { - img->lock(); + Vector2 ofs = mev->get_global_position() - r->get_visible_rect().get_position(); Color c = img->get_pixel(ofs.x, r->get_visible_rect().size.height - ofs.y); - img->unlock(); + set_pick_color(c); } } @@ -615,9 +615,9 @@ void ColorPicker::_screen_pick_pressed() { screen->set_as_toplevel(true); screen->set_anchors_and_margins_preset(Control::PRESET_WIDE); screen->set_default_cursor_shape(CURSOR_POINTING_HAND); - screen->connect("gui_input", this, "_screen_input"); + screen->connect("gui_input", callable_mp(this, &ColorPicker::_screen_input)); // It immediately toggles off in the first press otherwise. - screen->call_deferred("connect", "hide", btn_pick, "set_pressed", varray(false)); + screen->call_deferred("connect", "hide", Callable(btn_pick, "set_pressed"), varray(false)); } screen->raise(); screen->show_modal(); @@ -667,6 +667,7 @@ void ColorPicker::set_presets_visible(bool p_visible) { presets_visible = p_visible; preset_separator->set_visible(p_visible); preset_container->set_visible(p_visible); + preset_container2->set_visible(p_visible); } bool ColorPicker::are_presets_visible() const { @@ -677,9 +678,9 @@ void ColorPicker::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pick_color", "color"), &ColorPicker::set_pick_color); ClassDB::bind_method(D_METHOD("get_pick_color"), &ColorPicker::get_pick_color); - ClassDB::bind_method(D_METHOD("set_hsv_mode", "mode"), &ColorPicker::set_hsv_mode); + ClassDB::bind_method(D_METHOD("set_hsv_mode"), &ColorPicker::set_hsv_mode); ClassDB::bind_method(D_METHOD("is_hsv_mode"), &ColorPicker::is_hsv_mode); - ClassDB::bind_method(D_METHOD("set_raw_mode", "mode"), &ColorPicker::set_raw_mode); + ClassDB::bind_method(D_METHOD("set_raw_mode"), &ColorPicker::set_raw_mode); ClassDB::bind_method(D_METHOD("is_raw_mode"), &ColorPicker::is_raw_mode); ClassDB::bind_method(D_METHOD("set_deferred_mode", "mode"), &ColorPicker::set_deferred_mode); ClassDB::bind_method(D_METHOD("is_deferred_mode"), &ColorPicker::is_deferred_mode); @@ -692,21 +693,6 @@ void ColorPicker::_bind_methods() { ClassDB::bind_method(D_METHOD("add_preset", "color"), &ColorPicker::add_preset); ClassDB::bind_method(D_METHOD("erase_preset", "color"), &ColorPicker::erase_preset); ClassDB::bind_method(D_METHOD("get_presets"), &ColorPicker::get_presets); - ClassDB::bind_method(D_METHOD("_value_changed"), &ColorPicker::_value_changed); - ClassDB::bind_method(D_METHOD("_html_entered"), &ColorPicker::_html_entered); - ClassDB::bind_method(D_METHOD("_text_type_toggled"), &ColorPicker::_text_type_toggled); - ClassDB::bind_method(D_METHOD("_add_preset_pressed"), &ColorPicker::_add_preset_pressed); - ClassDB::bind_method(D_METHOD("_screen_pick_pressed"), &ColorPicker::_screen_pick_pressed); - ClassDB::bind_method(D_METHOD("_sample_draw"), &ColorPicker::_sample_draw); - ClassDB::bind_method(D_METHOD("_update_presets"), &ColorPicker::_update_presets); - ClassDB::bind_method(D_METHOD("_hsv_draw"), &ColorPicker::_hsv_draw); - ClassDB::bind_method(D_METHOD("_uv_input"), &ColorPicker::_uv_input); - ClassDB::bind_method(D_METHOD("_w_input"), &ColorPicker::_w_input); - ClassDB::bind_method(D_METHOD("_preset_input"), &ColorPicker::_preset_input); - ClassDB::bind_method(D_METHOD("_screen_input"), &ColorPicker::_screen_input); - ClassDB::bind_method(D_METHOD("_focus_enter"), &ColorPicker::_focus_enter); - ClassDB::bind_method(D_METHOD("_focus_exit"), &ColorPicker::_focus_exit); - ClassDB::bind_method(D_METHOD("_html_focus_exit"), &ColorPicker::_html_focus_exit); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_pick_color", "get_pick_color"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "edit_alpha"), "set_edit_alpha", "is_editing_alpha"); @@ -741,20 +727,20 @@ ColorPicker::ColorPicker() : uv_edit = memnew(Control); hb_edit->add_child(uv_edit); - uv_edit->connect("gui_input", this, "_uv_input"); + uv_edit->connect("gui_input", callable_mp(this, &ColorPicker::_uv_input)); 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->connect("draw", this, "_hsv_draw", make_binds(0, uv_edit)); + 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_h_size_flags(SIZE_FILL); w_edit->set_v_size_flags(SIZE_EXPAND_FILL); - w_edit->connect("gui_input", this, "_w_input"); - w_edit->connect("draw", this, "_hsv_draw", make_binds(1, w_edit)); + w_edit->connect("gui_input", callable_mp(this, &ColorPicker::_w_input)); + w_edit->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw), make_binds(1, w_edit)); HBoxContainer *hb_smpl = memnew(HBoxContainer); add_child(hb_smpl); @@ -762,13 +748,13 @@ ColorPicker::ColorPicker() : sample = memnew(TextureRect); hb_smpl->add_child(sample); sample->set_h_size_flags(SIZE_EXPAND_FILL); - sample->connect("draw", this, "_sample_draw"); + sample->connect("draw", callable_mp(this, &ColorPicker::_sample_draw)); btn_pick = memnew(ToolButton); hb_smpl->add_child(btn_pick); btn_pick->set_toggle_mode(true); btn_pick->set_tooltip(TTR("Pick a color from the editor window.")); - btn_pick->connect("pressed", this, "_screen_pick_pressed"); + btn_pick->connect("pressed", callable_mp(this, &ColorPicker::_screen_pick_pressed)); VBoxContainer *vbl = memnew(VBoxContainer); add_child(vbl); @@ -796,14 +782,14 @@ ColorPicker::ColorPicker() : values[i] = memnew(SpinBox); scroll[i]->share(values[i]); hbc->add_child(values[i]); - values[i]->get_line_edit()->connect("focus_entered", this, "_focus_enter"); - values[i]->get_line_edit()->connect("focus_exited", this, "_focus_exit"); + values[i]->get_line_edit()->connect("focus_entered", callable_mp(this, &ColorPicker::_focus_enter)); + values[i]->get_line_edit()->connect("focus_exited", callable_mp(this, &ColorPicker::_focus_exit)); scroll[i]->set_min(0); scroll[i]->set_page(0); scroll[i]->set_h_size_flags(SIZE_EXPAND_FILL); - scroll[i]->connect("value_changed", this, "_value_changed"); + scroll[i]->connect("value_changed", callable_mp(this, &ColorPicker::_value_changed)); vbr->add_child(hbc); } @@ -815,12 +801,12 @@ ColorPicker::ColorPicker() : btn_hsv = memnew(CheckButton); hhb->add_child(btn_hsv); btn_hsv->set_text(TTR("HSV")); - btn_hsv->connect("toggled", this, "set_hsv_mode"); + btn_hsv->connect("toggled", callable_mp(this, &ColorPicker::set_hsv_mode)); btn_raw = memnew(CheckButton); hhb->add_child(btn_raw); btn_raw->set_text(TTR("Raw")); - btn_raw->connect("toggled", this, "set_raw_mode"); + btn_raw->connect("toggled", callable_mp(this, &ColorPicker::set_raw_mode)); text_type = memnew(Button); hhb->add_child(text_type); @@ -831,7 +817,7 @@ ColorPicker::ColorPicker() : #ifdef TOOLS_ENABLED text_type->set_custom_minimum_size(Size2(28 * EDSCALE, 0)); // Adjust for the width of the "Script" icon. #endif - text_type->connect("pressed", this, "_text_type_toggled"); + text_type->connect("pressed", callable_mp(this, &ColorPicker::_text_type_toggled)); } else { text_type->set_flat(true); @@ -841,9 +827,9 @@ ColorPicker::ColorPicker() : c_text = memnew(LineEdit); hhb->add_child(c_text); c_text->set_h_size_flags(SIZE_EXPAND_FILL); - c_text->connect("text_entered", this, "_html_entered"); - c_text->connect("focus_entered", this, "_focus_enter"); - c_text->connect("focus_exited", this, "_html_focus_exit"); + c_text->connect("text_entered", callable_mp(this, &ColorPicker::_html_entered)); + c_text->connect("focus_entered", callable_mp(this, &ColorPicker::_focus_enter)); + c_text->connect("focus_exited", callable_mp(this, &ColorPicker::_html_focus_exit)); _update_controls(); updating = false; @@ -859,8 +845,8 @@ ColorPicker::ColorPicker() : preset = memnew(TextureRect); preset_container->add_child(preset); - preset->connect("gui_input", this, "_preset_input"); - preset->connect("draw", this, "_update_presets"); + preset->connect("gui_input", callable_mp(this, &ColorPicker::_preset_input)); + preset->connect("draw", callable_mp(this, &ColorPicker::_update_presets)); preset_container2 = memnew(HBoxContainer); preset_container2->set_h_size_flags(SIZE_EXPAND_FILL); @@ -868,7 +854,7 @@ ColorPicker::ColorPicker() : bt_add_preset = memnew(Button); preset_container2->add_child(bt_add_preset); bt_add_preset->set_tooltip(TTR("Add current color as a preset.")); - bt_add_preset->connect("pressed", this, "_add_preset_pressed"); + bt_add_preset->connect("pressed", callable_mp(this, &ColorPicker::_add_preset_pressed)); } ///////////////// @@ -968,10 +954,10 @@ void ColorPickerButton::_update_picker() { picker = memnew(ColorPicker); popup->add_child(picker); add_child(popup); - picker->connect("color_changed", this, "_color_changed"); - popup->connect("modal_closed", this, "_modal_closed"); - popup->connect("about_to_show", this, "set_pressed", varray(true)); - popup->connect("popup_hide", this, "set_pressed", varray(false)); + 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("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false)); picker->set_pick_color(color); picker->set_edit_alpha(edit_alpha); emit_signal("picker_created"); @@ -986,8 +972,6 @@ void ColorPickerButton::_bind_methods() { ClassDB::bind_method(D_METHOD("get_popup"), &ColorPickerButton::get_popup); ClassDB::bind_method(D_METHOD("set_edit_alpha", "show"), &ColorPickerButton::set_edit_alpha); ClassDB::bind_method(D_METHOD("is_editing_alpha"), &ColorPickerButton::is_editing_alpha); - ClassDB::bind_method(D_METHOD("_color_changed"), &ColorPickerButton::_color_changed); - ClassDB::bind_method(D_METHOD("_modal_closed"), &ColorPickerButton::_modal_closed); ADD_SIGNAL(MethodInfo("color_changed", PropertyInfo(Variant::COLOR, "color"))); ADD_SIGNAL(MethodInfo("popup_closed")); diff --git a/scene/gui/color_picker.h b/scene/gui/color_picker.h index 49d36dfb3a..dde2f37135 100644 --- a/scene/gui/color_picker.h +++ b/scene/gui/color_picker.h @@ -116,7 +116,7 @@ public: void add_preset(const Color &p_color); void erase_preset(const Color &p_color); - PoolColorArray get_presets() const; + PackedColorArray get_presets() const; void set_hsv_mode(bool p_enabled); bool is_hsv_mode() const; diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index b411f563b8..41f33bb719 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -48,9 +48,9 @@ void Container::add_child_notify(Node *p_child) { if (!control) return; - control->connect("size_flags_changed", this, "queue_sort"); - control->connect("minimum_size_changed", this, "_child_minsize_changed"); - control->connect("visibility_changed", this, "_child_minsize_changed"); + control->connect("size_flags_changed", callable_mp(this, &Container::queue_sort)); + control->connect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed)); + control->connect("visibility_changed", callable_mp(this, &Container::_child_minsize_changed)); minimum_size_changed(); queue_sort(); @@ -75,9 +75,9 @@ void Container::remove_child_notify(Node *p_child) { if (!control) return; - control->disconnect("size_flags_changed", this, "queue_sort"); - control->disconnect("minimum_size_changed", this, "_child_minsize_changed"); - control->disconnect("visibility_changed", this, "_child_minsize_changed"); + control->disconnect("size_flags_changed", callable_mp(this, &Container::queue_sort)); + control->disconnect("minimum_size_changed", callable_mp(this, &Container::_child_minsize_changed)); + control->disconnect("visibility_changed", callable_mp(this, &Container::_child_minsize_changed)); minimum_size_changed(); queue_sort(); @@ -185,7 +185,6 @@ String Container::get_configuration_warning() const { void Container::_bind_methods() { ClassDB::bind_method(D_METHOD("_sort_children"), &Container::_sort_children); - ClassDB::bind_method(D_METHOD("_child_minsize_changed"), &Container::_child_minsize_changed); ClassDB::bind_method(D_METHOD("queue_sort"), &Container::queue_sort); ClassDB::bind_method(D_METHOD("fit_child_in_rect", "child", "rect"), &Container::fit_child_in_rect); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 4c70bd1d39..1a231e368b 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -221,28 +221,28 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) { if (name.begins_with("custom_icons/")) { String dname = name.get_slicec('/', 1); if (data.icon_override.has(dname)) { - data.icon_override[dname]->disconnect("changed", this, "_override_changed"); + data.icon_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } data.icon_override.erase(dname); notification(NOTIFICATION_THEME_CHANGED); } else if (name.begins_with("custom_shaders/")) { String dname = name.get_slicec('/', 1); if (data.shader_override.has(dname)) { - data.shader_override[dname]->disconnect("changed", this, "_override_changed"); + data.shader_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } data.shader_override.erase(dname); notification(NOTIFICATION_THEME_CHANGED); } else if (name.begins_with("custom_styles/")) { String dname = name.get_slicec('/', 1); if (data.style_override.has(dname)) { - data.style_override[dname]->disconnect("changed", this, "_override_changed"); + data.style_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } data.style_override.erase(dname); notification(NOTIFICATION_THEME_CHANGED); } else if (name.begins_with("custom_fonts/")) { String dname = name.get_slicec('/', 1); if (data.font_override.has(dname)) { - data.font_override[dname]->disconnect("changed", this, "_override_changed"); + data.font_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } data.font_override.erase(dname); notification(NOTIFICATION_THEME_CHANGED); @@ -358,7 +358,7 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const { if (data.icon_override.has(E->get())) hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED; - p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture", hint)); + p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_icons/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", hint)); } } { @@ -542,10 +542,10 @@ void Control::_notification(int p_notification) { if (data.parent_canvas_item) { - data.parent_canvas_item->connect("item_rect_changed", this, "_size_changed"); + data.parent_canvas_item->connect("item_rect_changed", callable_mp(this, &Control::_size_changed)); } else { //connect viewport - get_viewport()->connect("size_changed", this, "_size_changed"); + get_viewport()->connect("size_changed", callable_mp(this, &Control::_size_changed)); } } @@ -561,11 +561,11 @@ void Control::_notification(int p_notification) { if (data.parent_canvas_item) { - data.parent_canvas_item->disconnect("item_rect_changed", this, "_size_changed"); + data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed)); data.parent_canvas_item = NULL; } else if (!is_set_as_toplevel()) { //disconnect viewport - get_viewport()->disconnect("size_changed", this, "_size_changed"); + get_viewport()->disconnect("size_changed", callable_mp(this, &Control::_size_changed)); } if (data.MI) { @@ -687,9 +687,9 @@ bool Control::has_point(const Point2 &p_point) const { if (get_script_instance()) { Variant v = p_point; const Variant *p = &v; - Variant::CallError ce; + Callable::CallError ce; Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->has_point, &p, 1, ce); - if (ce.error == Variant::CallError::CALL_OK) { + if (ce.error == Callable::CallError::CALL_OK) { return ret; } } @@ -705,12 +705,12 @@ void Control::set_drag_forwarding(Control *p_target) { if (p_target) data.drag_owner = p_target->get_instance_id(); else - data.drag_owner = 0; + data.drag_owner = ObjectID(); } Variant Control::get_drag_data(const Point2 &p_point) { - if (data.drag_owner) { + if (data.drag_owner.is_valid()) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { Control *c = Object::cast_to<Control>(obj); @@ -721,9 +721,9 @@ Variant Control::get_drag_data(const Point2 &p_point) { if (get_script_instance()) { Variant v = p_point; const Variant *p = &v; - Variant::CallError ce; + Callable::CallError ce; Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->get_drag_data, &p, 1, ce); - if (ce.error == Variant::CallError::CALL_OK) + if (ce.error == Callable::CallError::CALL_OK) return ret; } @@ -732,7 +732,7 @@ Variant Control::get_drag_data(const Point2 &p_point) { bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const { - if (data.drag_owner) { + if (data.drag_owner.is_valid()) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { Control *c = Object::cast_to<Control>(obj); @@ -743,9 +743,9 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const if (get_script_instance()) { Variant v = p_point; const Variant *p[2] = { &v, &p_data }; - Variant::CallError ce; + Callable::CallError ce; Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->can_drop_data, p, 2, ce); - if (ce.error == Variant::CallError::CALL_OK) + if (ce.error == Callable::CallError::CALL_OK) return ret; } @@ -753,7 +753,7 @@ bool Control::can_drop_data(const Point2 &p_point, const Variant &p_data) const } void Control::drop_data(const Point2 &p_point, const Variant &p_data) { - if (data.drag_owner) { + if (data.drag_owner.is_valid()) { Object *obj = ObjectDB::get_instance(data.drag_owner); if (obj) { Control *c = Object::cast_to<Control>(obj); @@ -765,9 +765,9 @@ void Control::drop_data(const Point2 &p_point, const Variant &p_data) { if (get_script_instance()) { Variant v = p_point; const Variant *p[2] = { &v, &p_data }; - Variant::CallError ce; + Callable::CallError ce; Variant ret = get_script_instance()->call(SceneStringNames::get_singleton()->drop_data, p, 2, ce); - if (ce.error == Variant::CallError::CALL_OK) + if (ce.error == Callable::CallError::CALL_OK) return; } } @@ -805,19 +805,19 @@ Size2 Control::get_minimum_size() const { ScriptInstance *si = const_cast<Control *>(this)->get_script_instance(); if (si) { - Variant::CallError ce; + Callable::CallError ce; Variant s = si->call(SceneStringNames::get_singleton()->_get_minimum_size, NULL, 0, ce); - if (ce.error == Variant::CallError::CALL_OK) + if (ce.error == Callable::CallError::CALL_OK) return s; } return Size2(); } -Ref<Texture> Control::get_icon(const StringName &p_name, const StringName &p_type) const { +Ref<Texture2D> Control::get_icon(const StringName &p_name, const StringName &p_type) const { if (p_type == StringName() || p_type == get_class_name()) { - const Ref<Texture> *tex = data.icon_override.getptr(p_name); + const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); if (tex) return *tex; } @@ -1063,7 +1063,7 @@ int Control::get_constant(const StringName &p_name, const StringName &p_type) co bool Control::has_icon_override(const StringName &p_name) const { - const Ref<Texture> *tex = data.icon_override.getptr(p_name); + const Ref<Texture2D> *tex = data.icon_override.getptr(p_name); return tex != NULL; } @@ -1880,10 +1880,10 @@ Rect2 Control::get_anchorable_rect() const { return Rect2(Point2(), get_size()); } -void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon) { +void Control::add_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", this, "_override_changed"); + data.icon_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } // clear if "null" is passed instead of a icon @@ -1892,7 +1892,7 @@ void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_ } else { data.icon_override[p_name] = p_icon; if (data.icon_override[p_name].is_valid()) { - data.icon_override[p_name]->connect("changed", this, "_override_changed", Vector<Variant>(), CONNECT_REFERENCE_COUNTED); + data.icon_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED); } } notification(NOTIFICATION_THEME_CHANGED); @@ -1901,7 +1901,7 @@ void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_ void Control::add_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", this, "_override_changed"); + data.shader_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } // clear if "null" is passed instead of a shader @@ -1910,7 +1910,7 @@ void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p } else { data.shader_override[p_name] = p_shader; if (data.shader_override[p_name].is_valid()) { - data.shader_override[p_name]->connect("changed", this, "_override_changed", Vector<Variant>(), CONNECT_REFERENCE_COUNTED); + data.shader_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED); } } notification(NOTIFICATION_THEME_CHANGED); @@ -1918,7 +1918,7 @@ void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p void Control::add_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", this, "_override_changed"); + data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } // clear if "null" is passed instead of a style @@ -1927,7 +1927,7 @@ void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> & } else { data.style_override[p_name] = p_style; if (data.style_override[p_name].is_valid()) { - data.style_override[p_name]->connect("changed", this, "_override_changed", Vector<Variant>(), CONNECT_REFERENCE_COUNTED); + data.style_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED); } } notification(NOTIFICATION_THEME_CHANGED); @@ -1936,7 +1936,7 @@ void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> & void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_font) { if (data.font_override.has(p_name)) { - data.font_override[p_name]->disconnect("changed", this, "_override_changed"); + data.font_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed)); } // clear if "null" is passed instead of a font @@ -1945,7 +1945,7 @@ void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_fon } else { data.font_override[p_name] = p_font; if (data.font_override[p_name].is_valid()) { - data.font_override[p_name]->connect("changed", this, "_override_changed", Vector<Variant>(), CONNECT_REFERENCE_COUNTED); + data.font_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED); } } notification(NOTIFICATION_THEME_CHANGED); @@ -2224,7 +2224,7 @@ void Control::_modal_stack_remove() { get_viewport()->_gui_remove_from_modal_stack(element, data.modal_prev_focus_owner); - data.modal_prev_focus_owner = 0; + data.modal_prev_focus_owner = ObjectID(); } void Control::_propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool p_assign) { @@ -2262,7 +2262,7 @@ void Control::set_theme(const Ref<Theme> &p_theme) { return; if (data.theme.is_valid()) { - data.theme->disconnect("changed", this, "_theme_changed"); + data.theme->disconnect("changed", callable_mp(this, &Control::_theme_changed)); } data.theme = p_theme; @@ -2282,7 +2282,7 @@ void Control::set_theme(const Ref<Theme> &p_theme) { } if (data.theme.is_valid()) { - data.theme->connect("changed", this, "_theme_changed", varray(), CONNECT_DEFERRED); + data.theme->connect("changed", callable_mp(this, &Control::_theme_changed), varray(), CONNECT_DEFERRED); } } @@ -2625,9 +2625,9 @@ bool Control::is_text_field() const { if (get_script_instance()) { Variant v=p_point; const Variant *p[2]={&v,&p_data}; - Variant::CallError ce; + Callable::CallError ce; Variant ret = get_script_instance()->call("is_text_field",p,2,ce); - if (ce.error==Variant::CallError::CALL_OK) + if (ce.error==Callable::CallError::CALL_OK) return ret; } */ @@ -2813,7 +2813,6 @@ Control::GrowDirection Control::get_v_grow_direction() const { void Control::_bind_methods() { //ClassDB::bind_method(D_METHOD("_window_resize_event"),&Control::_window_resize_event); - ClassDB::bind_method(D_METHOD("_size_changed"), &Control::_size_changed); ClassDB::bind_method(D_METHOD("_update_minimum_size"), &Control::_update_minimum_size); ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event); @@ -2942,10 +2941,6 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("minimum_size_changed"), &Control::minimum_size_changed); - ClassDB::bind_method(D_METHOD("_theme_changed"), &Control::_theme_changed); - - ClassDB::bind_method(D_METHOD("_override_changed"), &Control::_override_changed); - BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size")); @@ -2959,10 +2954,10 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::BOOL, "_clips_input")); ADD_GROUP("Anchor", "anchor_"); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", MARGIN_LEFT); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", MARGIN_TOP); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_right", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", MARGIN_RIGHT); - ADD_PROPERTYI(PropertyInfo(Variant::REAL, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", MARGIN_BOTTOM); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", MARGIN_LEFT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", MARGIN_TOP); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_right", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", MARGIN_RIGHT); + ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", MARGIN_BOTTOM); ADD_GROUP("Margin", "margin_"); ADD_PROPERTYI(PropertyInfo(Variant::INT, "margin_left", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_LEFT); @@ -2979,7 +2974,7 @@ void Control::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_global_position", PROPERTY_HINT_NONE, "", 0), "_set_global_position", "get_global_position"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_size", "get_size"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater"), "set_rotation_degrees", "get_rotation_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rect_rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater"), "set_rotation_degrees", "get_rotation_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents"); @@ -3003,7 +2998,7 @@ void Control::_bind_methods() { ADD_GROUP("Size Flags", "size_flags_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags"); ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_stretch_ratio", "get_stretch_ratio"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,128,0.01"), "set_stretch_ratio", "get_stretch_ratio"); ADD_GROUP("Theme", ""); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme"); ADD_GROUP("", ""); @@ -3110,7 +3105,7 @@ Control::Control() { data.rotation = 0; data.parent_canvas_item = NULL; data.scale = Vector2(1, 1); - data.drag_owner = 0; + data.modal_frame = 0; data.block_minimum_size_adjust = false; data.disable_visibility_clip = false; @@ -3125,7 +3120,6 @@ Control::Control() { data.margin[i] = 0; } data.focus_mode = FOCUS_NONE; - data.modal_prev_focus_owner = 0; } Control::~Control() { diff --git a/scene/gui/control.h b/scene/gui/control.h index 357858beb6..67e8ed0d27 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -198,7 +198,7 @@ private: NodePath focus_next; NodePath focus_prev; - HashMap<StringName, Ref<Texture> > icon_override; + HashMap<StringName, Ref<Texture2D> > icon_override; HashMap<StringName, Ref<Shader> > shader_override; HashMap<StringName, Ref<StyleBox> > style_override; HashMap<StringName, Ref<Font> > font_override; @@ -420,14 +420,14 @@ public: /* SKINNING */ - void add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon); + 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<Texture> get_icon(const StringName &p_name, const StringName &p_type = StringName()) const; + 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; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index e0e88e1577..6cadd0a63e 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -247,8 +247,10 @@ void WindowDialog::_notification(int p_what) { } break; case NOTIFICATION_POPUP_HIDE: { - if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton() && !was_editor_dimmed) + if (get_tree() && Engine::get_singleton()->is_editor_hint() && EditorNode::get_singleton() && !was_editor_dimmed) { EditorNode::get_singleton()->dim_editor(false); + set_pass_on_modal_close_click(false); + } } break; #endif } @@ -334,7 +336,6 @@ void WindowDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("get_title"), &WindowDialog::get_title); ClassDB::bind_method(D_METHOD("set_resizable", "resizable"), &WindowDialog::set_resizable); ClassDB::bind_method(D_METHOD("get_resizable"), &WindowDialog::get_resizable); - ClassDB::bind_method(D_METHOD("_closed"), &WindowDialog::_closed); ClassDB::bind_method(D_METHOD("get_close_button"), &WindowDialog::get_close_button); ADD_PROPERTY(PropertyInfo(Variant::STRING, "window_title", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT_INTL), "set_title", "get_title"); @@ -347,7 +348,7 @@ WindowDialog::WindowDialog() { resizable = false; close_button = memnew(TextureButton); add_child(close_button); - close_button->connect("pressed", this, "_closed"); + close_button->connect("pressed", callable_mp(this, &WindowDialog::_closed)); #ifdef TOOLS_ENABLED was_editor_dimmed = false; @@ -395,7 +396,7 @@ void AcceptDialog::_notification(int p_what) { } } -void AcceptDialog::_builtin_text_entered(const String &p_text) { +void AcceptDialog::_text_entered(const String &p_text) { _ok_pressed(); } @@ -407,11 +408,18 @@ void AcceptDialog::_ok_pressed() { ok_pressed(); emit_signal("confirmed"); } + void AcceptDialog::_close_pressed() { cancel_pressed(); } +// FIXME: This is redundant with _closed_pressed, but there's a slight behavior +// change (WindowDialog's _closed() also calls hide()) which should be assessed. +void AcceptDialog::_on_close_pressed() { + _closed(); // From WindowDialog. +} + String AcceptDialog::get_text() const { return label->get_text(); @@ -446,7 +454,7 @@ void AcceptDialog::register_text_enter(Node *p_line_edit) { ERR_FAIL_NULL(p_line_edit); LineEdit *line_edit = Object::cast_to<LineEdit>(p_line_edit); if (line_edit) - line_edit->connect("text_entered", this, "_builtin_text_entered"); + line_edit->connect("text_entered", callable_mp(this, &AcceptDialog::_text_entered)); } void AcceptDialog::_update_child_rects() { @@ -531,7 +539,7 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin } if (p_action != "") { - button->connect("pressed", this, "_custom_action", varray(p_action)); + button->connect("pressed", callable_mp(this, &AcceptDialog::_custom_action), varray(p_action)); } return button; @@ -543,29 +551,26 @@ Button *AcceptDialog::add_cancel(const String &p_cancel) { if (p_cancel == "") c = RTR("Cancel"); Button *b = swap_ok_cancel ? add_button(c, true) : add_button(c); - b->connect("pressed", this, "_closed"); + b->connect("pressed", callable_mp(this, &AcceptDialog::_on_close_pressed)); return b; } void AcceptDialog::_bind_methods() { - ClassDB::bind_method(D_METHOD("_ok"), &AcceptDialog::_ok_pressed); ClassDB::bind_method(D_METHOD("get_ok"), &AcceptDialog::get_ok); ClassDB::bind_method(D_METHOD("get_label"), &AcceptDialog::get_label); ClassDB::bind_method(D_METHOD("set_hide_on_ok", "enabled"), &AcceptDialog::set_hide_on_ok); ClassDB::bind_method(D_METHOD("get_hide_on_ok"), &AcceptDialog::get_hide_on_ok); ClassDB::bind_method(D_METHOD("add_button", "text", "right", "action"), &AcceptDialog::add_button, DEFVAL(false), DEFVAL("")); ClassDB::bind_method(D_METHOD("add_cancel", "name"), &AcceptDialog::add_cancel); - ClassDB::bind_method(D_METHOD("_builtin_text_entered"), &AcceptDialog::_builtin_text_entered); ClassDB::bind_method(D_METHOD("register_text_enter", "line_edit"), &AcceptDialog::register_text_enter); - ClassDB::bind_method(D_METHOD("_custom_action"), &AcceptDialog::_custom_action); ClassDB::bind_method(D_METHOD("set_text", "text"), &AcceptDialog::set_text); ClassDB::bind_method(D_METHOD("get_text"), &AcceptDialog::get_text); ClassDB::bind_method(D_METHOD("set_autowrap", "autowrap"), &AcceptDialog::set_autowrap); ClassDB::bind_method(D_METHOD("has_autowrap"), &AcceptDialog::has_autowrap); ADD_SIGNAL(MethodInfo("confirmed")); - ADD_SIGNAL(MethodInfo("custom_action", PropertyInfo(Variant::STRING, "action"))); + ADD_SIGNAL(MethodInfo("custom_action", PropertyInfo(Variant::STRING_NAME, "action"))); ADD_GROUP("Dialog", "dialog"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "dialog_text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text"); @@ -600,7 +605,7 @@ AcceptDialog::AcceptDialog() { hbc->add_child(ok); hbc->add_spacer(); - ok->connect("pressed", this, "_ok"); + ok->connect("pressed", callable_mp(this, &AcceptDialog::_ok_pressed)); set_as_toplevel(true); hide_on_ok = true; diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h index b6381e98b4..c474f7849d 100644 --- a/scene/gui/dialogs.h +++ b/scene/gui/dialogs.h @@ -64,7 +64,6 @@ class WindowDialog : public Popup { #endif void _gui_input(const Ref<InputEvent> &p_event); - void _closed(); int _drag_hit_test(const Point2 &pos) const; protected: @@ -75,6 +74,9 @@ protected: void _notification(int p_what); static void _bind_methods(); + // Not private since used by derived classes signal. + void _closed(); + public: TextureButton *get_close_button(); @@ -113,9 +115,7 @@ class AcceptDialog : public WindowDialog { bool hide_on_ok; void _custom_action(const String &p_action); - void _ok_pressed(); void _close_pressed(); - void _builtin_text_entered(const String &p_text); void _update_child_rects(); static bool swap_ok_cancel; @@ -128,6 +128,11 @@ protected: virtual void cancel_pressed() {} virtual void custom_action(const String &) {} + // Not private since used by derived classes signal. + void _text_entered(const String &p_text); + void _ok_pressed(); + void _on_close_pressed(); + public: Size2 get_minimum_size() const; diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 2cc9c1a53a..1d813d8081 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -85,7 +85,7 @@ void FileDialog::_unhandled_input(const Ref<InputEvent> &p_event) { bool handled = true; - switch (k->get_scancode()) { + switch (k->get_keycode()) { case KEY_H: { @@ -193,7 +193,7 @@ void FileDialog::_action_pressed() { TreeItem *ti = tree->get_next_selected(NULL); String fbase = dir_access->get_current_dir(); - PoolVector<String> files; + Vector<String> files; while (ti) { files.push_back(fbase.plus_file(ti->get_text(0))); @@ -424,7 +424,7 @@ void FileDialog::update_file_list() { dir_access->list_dir_begin(); TreeItem *root = tree->create_item(); - Ref<Texture> folder = get_icon("folder"); + Ref<Texture2D> folder = get_icon("folder"); const Color folder_color = get_color("folder_icon_modulate"); List<String> files; List<String> dirs; @@ -518,7 +518,7 @@ void FileDialog::update_file_list() { if (get_icon_func) { - Ref<Texture> icon = get_icon_func(base_dir.plus_file(files.front()->get())); + Ref<Texture2D> icon = get_icon_func(base_dir.plus_file(files.front()->get())); ti->set_icon(0, icon); } @@ -805,15 +805,7 @@ void FileDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("_unhandled_input"), &FileDialog::_unhandled_input); - ClassDB::bind_method(D_METHOD("_tree_multi_selected"), &FileDialog::_tree_multi_selected); - ClassDB::bind_method(D_METHOD("_tree_selected"), &FileDialog::_tree_selected); - ClassDB::bind_method(D_METHOD("_tree_item_activated"), &FileDialog::_tree_item_activated); - ClassDB::bind_method(D_METHOD("_dir_entered"), &FileDialog::_dir_entered); - ClassDB::bind_method(D_METHOD("_file_entered"), &FileDialog::_file_entered); - ClassDB::bind_method(D_METHOD("_action_pressed"), &FileDialog::_action_pressed); ClassDB::bind_method(D_METHOD("_cancel_pressed"), &FileDialog::_cancel_pressed); - ClassDB::bind_method(D_METHOD("_filter_selected"), &FileDialog::_filter_selected); - ClassDB::bind_method(D_METHOD("_save_confirm_pressed"), &FileDialog::_save_confirm_pressed); ClassDB::bind_method(D_METHOD("clear_filters"), &FileDialog::clear_filters); ClassDB::bind_method(D_METHOD("add_filter", "filter"), &FileDialog::add_filter); @@ -835,13 +827,9 @@ void FileDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("get_access"), &FileDialog::get_access); ClassDB::bind_method(D_METHOD("set_show_hidden_files", "show"), &FileDialog::set_show_hidden_files); ClassDB::bind_method(D_METHOD("is_showing_hidden_files"), &FileDialog::is_showing_hidden_files); - ClassDB::bind_method(D_METHOD("_select_drive"), &FileDialog::_select_drive); - ClassDB::bind_method(D_METHOD("_make_dir"), &FileDialog::_make_dir); - ClassDB::bind_method(D_METHOD("_make_dir_confirm"), &FileDialog::_make_dir_confirm); ClassDB::bind_method(D_METHOD("_update_file_name"), &FileDialog::update_file_name); - ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list); ClassDB::bind_method(D_METHOD("_update_dir"), &FileDialog::update_dir); - ClassDB::bind_method(D_METHOD("_go_up"), &FileDialog::_go_up); + ClassDB::bind_method(D_METHOD("_update_file_list"), &FileDialog::update_file_list); ClassDB::bind_method(D_METHOD("deselect_items"), &FileDialog::deselect_items); ClassDB::bind_method(D_METHOD("invalidate"), &FileDialog::invalidate); @@ -849,14 +837,14 @@ void FileDialog::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "mode_overrides_title"), "set_mode_overrides_title", "is_mode_overriding_title"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Open File,Open Files,Open Folder,Open Any,Save"), "set_mode", "get_mode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "access", PROPERTY_HINT_ENUM, "Resources,User data,File system"), "set_access", "get_access"); - ADD_PROPERTY(PropertyInfo(Variant::POOL_STRING_ARRAY, "filters"), "set_filters", "get_filters"); + ADD_PROPERTY(PropertyInfo(Variant::PACKED_STRING_ARRAY, "filters"), "set_filters", "get_filters"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "show_hidden_files"), "set_show_hidden_files", "is_showing_hidden_files"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_dir"), "set_current_dir", "get_current_dir"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_file"), "set_current_file", "get_current_file"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "current_path"), "set_current_path", "get_current_path"); ADD_SIGNAL(MethodInfo("file_selected", PropertyInfo(Variant::STRING, "path"))); - ADD_SIGNAL(MethodInfo("files_selected", PropertyInfo(Variant::POOL_STRING_ARRAY, "paths"))); + ADD_SIGNAL(MethodInfo("files_selected", PropertyInfo(Variant::PACKED_STRING_ARRAY, "paths"))); ADD_SIGNAL(MethodInfo("dir_selected", PropertyInfo(Variant::STRING, "dir"))); BIND_ENUM_CONSTANT(MODE_OPEN_FILE); @@ -900,11 +888,11 @@ FileDialog::FileDialog() { dir_up = memnew(ToolButton); dir_up->set_tooltip(RTR("Go to parent folder.")); hbc->add_child(dir_up); - dir_up->connect("pressed", this, "_go_up"); + dir_up->connect("pressed", callable_mp(this, &FileDialog::_go_up)); drives = memnew(OptionButton); hbc->add_child(drives); - drives->connect("item_selected", this, "_select_drive"); + drives->connect("item_selected", callable_mp(this, &FileDialog::_select_drive)); hbc->add_child(memnew(Label(RTR("Path:")))); dir = memnew(LineEdit); @@ -913,19 +901,19 @@ FileDialog::FileDialog() { refresh = memnew(ToolButton); refresh->set_tooltip(RTR("Refresh files.")); - refresh->connect("pressed", this, "_update_file_list"); + refresh->connect("pressed", callable_mp(this, &FileDialog::update_file_list)); hbc->add_child(refresh); show_hidden = memnew(ToolButton); show_hidden->set_toggle_mode(true); show_hidden->set_pressed(is_showing_hidden_files()); show_hidden->set_tooltip(RTR("Toggle the visibility of hidden files.")); - show_hidden->connect("toggled", this, "set_show_hidden_files"); + show_hidden->connect("toggled", callable_mp(this, &FileDialog::set_show_hidden_files)); hbc->add_child(show_hidden); makedir = memnew(Button); makedir->set_text(RTR("Create Folder")); - makedir->connect("pressed", this, "_make_dir"); + makedir->connect("pressed", callable_mp(this, &FileDialog::_make_dir)); hbc->add_child(makedir); vbc->add_child(hbc); @@ -950,20 +938,20 @@ FileDialog::FileDialog() { access = ACCESS_RESOURCES; _update_drives(); - connect("confirmed", this, "_action_pressed"); - tree->connect("multi_selected", this, "_tree_multi_selected", varray(), CONNECT_DEFERRED); - tree->connect("cell_selected", this, "_tree_selected", varray(), CONNECT_DEFERRED); - tree->connect("item_activated", this, "_tree_item_activated", varray()); - tree->connect("nothing_selected", this, "deselect_items"); - dir->connect("text_entered", this, "_dir_entered"); - file->connect("text_entered", this, "_file_entered"); - filter->connect("item_selected", this, "_filter_selected"); + connect("confirmed", callable_mp(this, &FileDialog::_action_pressed)); + tree->connect("multi_selected", callable_mp(this, &FileDialog::_tree_multi_selected), varray(), CONNECT_DEFERRED); + tree->connect("cell_selected", callable_mp(this, &FileDialog::_tree_selected), varray(), CONNECT_DEFERRED); + tree->connect("item_activated", callable_mp(this, &FileDialog::_tree_item_activated), varray()); + tree->connect("nothing_selected", callable_mp(this, &FileDialog::deselect_items)); + dir->connect("text_entered", callable_mp(this, &FileDialog::_dir_entered)); + file->connect("text_entered", callable_mp(this, &FileDialog::_file_entered)); + filter->connect("item_selected", callable_mp(this, &FileDialog::_filter_selected)); confirm_save = memnew(ConfirmationDialog); confirm_save->set_as_toplevel(true); add_child(confirm_save); - confirm_save->connect("confirmed", this, "_save_confirm_pressed"); + confirm_save->connect("confirmed", callable_mp(this, &FileDialog::_save_confirm_pressed)); makedialog = memnew(ConfirmationDialog); makedialog->set_title(RTR("Create Folder")); @@ -974,7 +962,7 @@ FileDialog::FileDialog() { makevb->add_margin_child(RTR("Name:"), makedirname); add_child(makedialog); makedialog->register_text_enter(makedirname); - makedialog->connect("confirmed", this, "_make_dir_confirm"); + makedialog->connect("confirmed", callable_mp(this, &FileDialog::_make_dir_confirm)); mkdirerr = memnew(AcceptDialog); mkdirerr->set_text(RTR("Could not create folder.")); add_child(mkdirerr); @@ -1003,8 +991,6 @@ FileDialog::~FileDialog() { void LineEditFileChooser::_bind_methods() { - ClassDB::bind_method(D_METHOD("_browse"), &LineEditFileChooser::_browse); - ClassDB::bind_method(D_METHOD("_chosen"), &LineEditFileChooser::_chosen); ClassDB::bind_method(D_METHOD("get_button"), &LineEditFileChooser::get_button); ClassDB::bind_method(D_METHOD("get_line_edit"), &LineEditFileChooser::get_line_edit); ClassDB::bind_method(D_METHOD("get_file_dialog"), &LineEditFileChooser::get_file_dialog); @@ -1029,10 +1015,10 @@ LineEditFileChooser::LineEditFileChooser() { button = memnew(Button); button->set_text(" .. "); add_child(button); - button->connect("pressed", this, "_browse"); + button->connect("pressed", callable_mp(this, &LineEditFileChooser::_browse)); dialog = memnew(FileDialog); add_child(dialog); - dialog->connect("file_selected", this, "_chosen"); - dialog->connect("dir_selected", this, "_chosen"); - dialog->connect("files_selected", this, "_chosen"); + dialog->connect("file_selected", callable_mp(this, &LineEditFileChooser::_chosen)); + dialog->connect("dir_selected", callable_mp(this, &LineEditFileChooser::_chosen)); + dialog->connect("files_selected", callable_mp(this, &LineEditFileChooser::_chosen)); } diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index d9ab00e0f2..9f6650c276 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -58,7 +58,7 @@ public: MODE_SAVE_FILE }; - typedef Ref<Texture> (*GetIconFunc)(const String &); + typedef Ref<Texture2D> (*GetIconFunc)(const String &); typedef void (*RegisterFunc)(FileDialog *); static GetIconFunc get_icon_func; diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index 46c59f42fc..6345bfe562 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -54,7 +54,6 @@ GradientEdit::GradientEdit() { checker = Ref<ImageTexture>(memnew(ImageTexture)); Ref<Image> img = memnew(Image(checker_bg_png)); - checker->create_from_image(img, ImageTexture::FLAG_REPEAT); } int GradientEdit::_get_point_from_pos(int x) { @@ -97,7 +96,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { Ref<InputEventKey> k = p_event; - if (k.is_valid() && k->is_pressed() && k->get_scancode() == KEY_DELETE && grabbed != -1) { + if (k.is_valid() && k->is_pressed() && k->get_keycode() == KEY_DELETE && grabbed != -1) { points.remove(grabbed); grabbed = -1; @@ -303,8 +302,8 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { void GradientEdit::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - if (!picker->is_connected("color_changed", this, "_color_changed")) { - picker->connect("color_changed", this, "_color_changed"); + if (!picker->is_connected("color_changed", callable_mp(this, &GradientEdit::_color_changed))) { + picker->connect("color_changed", callable_mp(this, &GradientEdit::_color_changed)); } } if (p_what == NOTIFICATION_DRAW) { @@ -491,6 +490,5 @@ Vector<Gradient::Point> &GradientEdit::get_points() { void GradientEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &GradientEdit::_gui_input); - ClassDB::bind_method(D_METHOD("_color_changed"), &GradientEdit::_color_changed); ADD_SIGNAL(MethodInfo("ramp_changed")); } diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index c09b2414b2..4bc33b220e 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -257,9 +257,9 @@ void GraphEdit::add_child_notify(Node *p_child) { GraphNode *gn = Object::cast_to<GraphNode>(p_child); if (gn) { gn->set_scale(Vector2(zoom, zoom)); - gn->connect("offset_changed", this, "_graph_node_moved", varray(gn)); - gn->connect("raise_request", this, "_graph_node_raised", varray(gn)); - gn->connect("item_rect_changed", connections_layer, "update"); + gn->connect("offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved), varray(gn)); + gn->connect("raise_request", callable_mp(this, &GraphEdit::_graph_node_raised), varray(gn)); + gn->connect("item_rect_changed", callable_mp((CanvasItem *)connections_layer, &CanvasItem::update)); _graph_node_moved(gn); gn->set_mouse_filter(MOUSE_FILTER_PASS); } @@ -273,8 +273,8 @@ void GraphEdit::remove_child_notify(Node *p_child) { } GraphNode *gn = Object::cast_to<GraphNode>(p_child); if (gn) { - gn->disconnect("offset_changed", this, "_graph_node_moved"); - gn->disconnect("raise_request", this, "_graph_node_raised"); + gn->disconnect("offset_changed", callable_mp(this, &GraphEdit::_graph_node_moved)); + gn->disconnect("raise_request", callable_mp(this, &GraphEdit::_graph_node_raised)); } } @@ -357,7 +357,7 @@ void GraphEdit::_notification(int p_what) { bool GraphEdit::_filter_input(const Point2 &p_point) { - Ref<Texture> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_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<Texture> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_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<Texture> port = get_icon("port", "GraphNode"); + Ref<Texture2D> port = get_icon("port", "GraphNode"); Vector2 mpos = mm->get_position(); for (int i = get_child_count() - 1; i >= 0; i--) { @@ -689,9 +689,9 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const colors.push_back(p_to_color); #ifdef TOOLS_ENABLED - p_where->draw_polyline_colors(points, colors, Math::floor(2 * EDSCALE), true); + p_where->draw_polyline_colors(points, colors, Math::floor(2 * EDSCALE)); #else - p_where->draw_polyline_colors(points, colors, 2, true); + p_where->draw_polyline_colors(points, colors, 2); #endif } @@ -1043,22 +1043,22 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { if (k.is_valid()) { - if (k->get_scancode() == KEY_D && k->is_pressed() && k->get_command()) { + if (k->get_keycode() == KEY_D && k->is_pressed() && k->get_command()) { emit_signal("duplicate_nodes_request"); accept_event(); } - if (k->get_scancode() == KEY_C && k->is_pressed() && k->get_command()) { + if (k->get_keycode() == KEY_C && k->is_pressed() && k->get_command()) { emit_signal("copy_nodes_request"); accept_event(); } - if (k->get_scancode() == KEY_V && k->is_pressed() && k->get_command()) { + if (k->get_keycode() == KEY_V && k->is_pressed() && k->get_command()) { emit_signal("paste_nodes_request"); accept_event(); } - if (k->get_scancode() == KEY_DELETE && k->is_pressed()) { + if (k->get_keycode() == KEY_DELETE && k->is_pressed()) { emit_signal("delete_nodes_request"); accept_event(); } @@ -1291,21 +1291,8 @@ void GraphEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_right_disconnects", "enable"), &GraphEdit::set_right_disconnects); ClassDB::bind_method(D_METHOD("is_right_disconnects_enabled"), &GraphEdit::is_right_disconnects_enabled); - ClassDB::bind_method(D_METHOD("_graph_node_moved"), &GraphEdit::_graph_node_moved); - ClassDB::bind_method(D_METHOD("_graph_node_raised"), &GraphEdit::_graph_node_raised); - - ClassDB::bind_method(D_METHOD("_top_layer_input"), &GraphEdit::_top_layer_input); - ClassDB::bind_method(D_METHOD("_top_layer_draw"), &GraphEdit::_top_layer_draw); - ClassDB::bind_method(D_METHOD("_scroll_moved"), &GraphEdit::_scroll_moved); - ClassDB::bind_method(D_METHOD("_zoom_minus"), &GraphEdit::_zoom_minus); - ClassDB::bind_method(D_METHOD("_zoom_reset"), &GraphEdit::_zoom_reset); - ClassDB::bind_method(D_METHOD("_zoom_plus"), &GraphEdit::_zoom_plus); - ClassDB::bind_method(D_METHOD("_snap_toggled"), &GraphEdit::_snap_toggled); - ClassDB::bind_method(D_METHOD("_snap_value_changed"), &GraphEdit::_snap_value_changed); - ClassDB::bind_method(D_METHOD("_gui_input"), &GraphEdit::_gui_input); ClassDB::bind_method(D_METHOD("_update_scroll_offset"), &GraphEdit::_update_scroll_offset); - ClassDB::bind_method(D_METHOD("_connections_layer_draw"), &GraphEdit::_connections_layer_draw); ClassDB::bind_method(D_METHOD("get_zoom_hbox"), &GraphEdit::get_zoom_hbox); @@ -1315,17 +1302,17 @@ void GraphEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scroll_offset"), "set_scroll_ofs", "get_scroll_ofs"); ADD_PROPERTY(PropertyInfo(Variant::INT, "snap_distance"), "set_snap", "get_snap"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_snap"), "set_use_snap", "is_using_snap"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "zoom"), "set_zoom", "get_zoom"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "zoom"), "set_zoom", "get_zoom"); - ADD_SIGNAL(MethodInfo("connection_request", PropertyInfo(Variant::STRING, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::STRING, "to"), PropertyInfo(Variant::INT, "to_slot"))); - ADD_SIGNAL(MethodInfo("disconnection_request", PropertyInfo(Variant::STRING, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::STRING, "to"), PropertyInfo(Variant::INT, "to_slot"))); + ADD_SIGNAL(MethodInfo("connection_request", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"))); + ADD_SIGNAL(MethodInfo("disconnection_request", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"))); ADD_SIGNAL(MethodInfo("popup_request", PropertyInfo(Variant::VECTOR2, "position"))); ADD_SIGNAL(MethodInfo("duplicate_nodes_request")); ADD_SIGNAL(MethodInfo("copy_nodes_request")); ADD_SIGNAL(MethodInfo("paste_nodes_request")); ADD_SIGNAL(MethodInfo("node_selected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node"))); - ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); - ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); + ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); + ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position"))); ADD_SIGNAL(MethodInfo("delete_nodes_request")); ADD_SIGNAL(MethodInfo("_begin_node_move")); ADD_SIGNAL(MethodInfo("_end_node_move")); @@ -1341,12 +1328,12 @@ GraphEdit::GraphEdit() { add_child(top_layer); top_layer->set_mouse_filter(MOUSE_FILTER_PASS); top_layer->set_anchors_and_margins_preset(Control::PRESET_WIDE); - top_layer->connect("draw", this, "_top_layer_draw"); - top_layer->connect("gui_input", this, "_top_layer_input"); + top_layer->connect("draw", callable_mp(this, &GraphEdit::_top_layer_draw)); + top_layer->connect("gui_input", callable_mp(this, &GraphEdit::_top_layer_input)); connections_layer = memnew(Control); add_child(connections_layer); - connections_layer->connect("draw", this, "_connections_layer_draw"); + connections_layer->connect("draw", callable_mp(this, &GraphEdit::_connections_layer_draw)); connections_layer->set_name("CLAYER"); connections_layer->set_disable_visibility_clip(true); // so it can draw freely and be offset connections_layer->set_mouse_filter(MOUSE_FILTER_IGNORE); @@ -1373,8 +1360,8 @@ GraphEdit::GraphEdit() { v_scroll->set_min(-10000); v_scroll->set_max(10000); - h_scroll->connect("value_changed", this, "_scroll_moved"); - v_scroll->connect("value_changed", this, "_scroll_moved"); + h_scroll->connect("value_changed", callable_mp(this, &GraphEdit::_scroll_moved)); + v_scroll->connect("value_changed", callable_mp(this, &GraphEdit::_scroll_moved)); zoom = 1; @@ -1385,25 +1372,25 @@ GraphEdit::GraphEdit() { zoom_minus = memnew(ToolButton); zoom_hb->add_child(zoom_minus); zoom_minus->set_tooltip(RTR("Zoom Out")); - zoom_minus->connect("pressed", this, "_zoom_minus"); + zoom_minus->connect("pressed", callable_mp(this, &GraphEdit::_zoom_minus)); zoom_minus->set_focus_mode(FOCUS_NONE); zoom_reset = memnew(ToolButton); zoom_hb->add_child(zoom_reset); zoom_reset->set_tooltip(RTR("Zoom Reset")); - zoom_reset->connect("pressed", this, "_zoom_reset"); + zoom_reset->connect("pressed", callable_mp(this, &GraphEdit::_zoom_reset)); zoom_reset->set_focus_mode(FOCUS_NONE); zoom_plus = memnew(ToolButton); zoom_hb->add_child(zoom_plus); zoom_plus->set_tooltip(RTR("Zoom In")); - zoom_plus->connect("pressed", this, "_zoom_plus"); + zoom_plus->connect("pressed", callable_mp(this, &GraphEdit::_zoom_plus)); zoom_plus->set_focus_mode(FOCUS_NONE); snap_button = memnew(ToolButton); snap_button->set_toggle_mode(true); snap_button->set_tooltip(RTR("Enable snap and show grid.")); - snap_button->connect("pressed", this, "_snap_toggled"); + snap_button->connect("pressed", callable_mp(this, &GraphEdit::_snap_toggled)); snap_button->set_pressed(true); snap_button->set_focus_mode(FOCUS_NONE); zoom_hb->add_child(snap_button); @@ -1413,7 +1400,7 @@ GraphEdit::GraphEdit() { snap_amount->set_max(100); snap_amount->set_step(1); snap_amount->set_value(20); - snap_amount->connect("value_changed", this, "_snap_value_changed"); + snap_amount->connect("value_changed", callable_mp(this, &GraphEdit::_snap_value_changed)); zoom_hb->add_child(snap_amount); setting_scroll_ofs = false; diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 7b1bfdfdb5..82e890395a 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -170,7 +170,7 @@ bool GraphNode::has_point(const Point2 &p_point) const { if (comment) { Ref<StyleBox> comment = get_stylebox("comment"); - Ref<Texture> resizer = get_icon("resizer"); + Ref<Texture2D> resizer = get_icon("resizer"); if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) { return true; @@ -204,9 +204,9 @@ void GraphNode::_notification(int p_what) { //sb=sb->duplicate(); //sb->call("set_modulate",modulate); - Ref<Texture> port = get_icon("port"); - Ref<Texture> close = get_icon("close"); - Ref<Texture> resizer = get_icon("resizer"); + 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"); @@ -259,14 +259,14 @@ void GraphNode::_notification(int p_what) { const Slot &s = slot_info[E->key()]; //left if (s.enable_left) { - Ref<Texture> p = port; + Ref<Texture2D> p = port; if (s.custom_slot_left.is_valid()) { p = s.custom_slot_left; } p->draw(get_canvas_item(), icofs + Point2(edgeofs, cache_y[E->key()]), s.color_left); } if (s.enable_right) { - Ref<Texture> p = port; + Ref<Texture2D> p = port; if (s.custom_slot_right.is_valid()) { p = s.custom_slot_right; } @@ -291,7 +291,7 @@ void GraphNode::_notification(int p_what) { } } -void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture> &p_custom_left, const Ref<Texture> &p_custom_right) { +void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture2D> &p_custom_left, const Ref<Texture2D> &p_custom_right) { ERR_FAIL_COND(p_idx < 0); @@ -379,7 +379,7 @@ Size2 GraphNode::get_minimum_size() const { Size2 minsize; minsize.x = title_font->get_string_size(title).x; if (show_close) { - Ref<Texture> close = get_icon("close"); + Ref<Texture2D> close = get_icon("close"); minsize.x += sep + close->get_width(); } @@ -606,7 +606,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { return; } - Ref<Texture> resizer = get_icon("resizer"); + Ref<Texture2D> resizer = get_icon("resizer"); if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) { @@ -674,7 +674,7 @@ void GraphNode::_bind_methods() { ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title); ClassDB::bind_method(D_METHOD("_gui_input"), &GraphNode::_gui_input); - ClassDB::bind_method(D_METHOD("set_slot", "idx", "enable_left", "type_left", "color_left", "enable_right", "type_right", "color_right", "custom_left", "custom_right"), &GraphNode::set_slot, DEFVAL(Ref<Texture>()), DEFVAL(Ref<Texture>())); + ClassDB::bind_method(D_METHOD("set_slot", "idx", "enable_left", "type_left", "color_left", "enable_right", "type_right", "color_right", "custom_left", "custom_right"), &GraphNode::set_slot, DEFVAL(Ref<Texture2D>()), DEFVAL(Ref<Texture2D>())); ClassDB::bind_method(D_METHOD("clear_slot", "idx"), &GraphNode::clear_slot); ClassDB::bind_method(D_METHOD("clear_all_slots"), &GraphNode::clear_all_slots); ClassDB::bind_method(D_METHOD("is_slot_enabled_left", "idx"), &GraphNode::is_slot_enabled_left); diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h index e1a81b5f3d..a3eb8ed152 100644 --- a/scene/gui/graph_node.h +++ b/scene/gui/graph_node.h @@ -52,8 +52,8 @@ private: bool enable_right; int type_right; Color color_right; - Ref<Texture> custom_slot_left; - Ref<Texture> custom_slot_right; + Ref<Texture2D> custom_slot_left; + Ref<Texture2D> custom_slot_right; Slot() { enable_left = false; @@ -112,7 +112,7 @@ protected: public: bool has_point(const Point2 &p_point) const; - void set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture> &p_custom_left = Ref<Texture>(), const Ref<Texture> &p_custom_right = Ref<Texture>()); + void set_slot(int p_idx, bool p_enable_left, int p_type_left, const Color &p_color_left, bool p_enable_right, int p_type_right, const Color &p_color_right, const Ref<Texture2D> &p_custom_left = Ref<Texture2D>(), const Ref<Texture2D> &p_custom_right = Ref<Texture2D>()); void clear_slot(int p_idx); void clear_all_slots(); bool is_slot_enabled_left(int p_idx) const; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 526950dbb3..5e662b8df0 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -32,7 +32,7 @@ #include "core/os/os.h" #include "core/project_settings.h" -void ItemList::add_item(const String &p_item, const Ref<Texture> &p_texture, bool p_selectable) { +void ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bool p_selectable) { Item item; item.icon = p_texture; @@ -51,7 +51,7 @@ void ItemList::add_item(const String &p_item, const Ref<Texture> &p_texture, boo shape_changed = true; } -void ItemList::add_icon_item(const Ref<Texture> &p_item, bool p_selectable) { +void ItemList::add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable) { Item item; item.icon = p_item; @@ -110,7 +110,7 @@ String ItemList::get_item_tooltip(int p_idx) const { return items[p_idx].tooltip; } -void ItemList::set_item_icon(int p_idx, const Ref<Texture> &p_icon) { +void ItemList::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) { ERR_FAIL_INDEX(p_idx, items.size()); @@ -119,9 +119,9 @@ void ItemList::set_item_icon(int p_idx, const Ref<Texture> &p_icon) { shape_changed = true; } -Ref<Texture> ItemList::get_item_icon(int p_idx) const { +Ref<Texture2D> ItemList::get_item_icon(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture>()); + ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture2D>()); return items[p_idx].icon; } @@ -201,7 +201,7 @@ Color ItemList::get_item_custom_fg_color(int p_idx) const { return items[p_idx].custom_fg; } -void ItemList::set_item_tag_icon(int p_idx, const Ref<Texture> &p_tag_icon) { +void ItemList::set_item_tag_icon(int p_idx, const Ref<Texture2D> &p_tag_icon) { ERR_FAIL_INDEX(p_idx, items.size()); @@ -209,9 +209,9 @@ void ItemList::set_item_tag_icon(int p_idx, const Ref<Texture> &p_tag_icon) { update(); shape_changed = true; } -Ref<Texture> ItemList::get_item_tag_icon(int p_idx) const { +Ref<Texture2D> ItemList::get_item_tag_icon(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture>()); + ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture2D>()); return items[p_idx].tag_icon; } @@ -1398,7 +1398,7 @@ void ItemList::_set_items(const Array &p_items) { for (int i = 0; i < p_items.size(); i += 3) { String text = p_items[i + 0]; - Ref<Texture> icon = p_items[i + 1]; + Ref<Texture2D> icon = p_items[i + 1]; bool disabled = p_items[i + 2]; int idx = get_item_count(); @@ -1542,7 +1542,6 @@ void ItemList::_bind_methods() { ClassDB::bind_method(D_METHOD("get_v_scroll"), &ItemList::get_v_scroll); - ClassDB::bind_method(D_METHOD("_scroll_changed"), &ItemList::_scroll_changed); ClassDB::bind_method(D_METHOD("_gui_input"), &ItemList::_gui_input); ClassDB::bind_method(D_METHOD("_set_items"), &ItemList::_set_items); @@ -1561,7 +1560,7 @@ void ItemList::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "fixed_column_width", PROPERTY_HINT_RANGE, "0,100,1,or_greater"), "set_fixed_column_width", "get_fixed_column_width"); ADD_GROUP("Icon", ""); ADD_PROPERTY(PropertyInfo(Variant::INT, "icon_mode", PROPERTY_HINT_ENUM, "Top,Left"), "set_icon_mode", "get_icon_mode"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "icon_scale"), "set_icon_scale", "get_icon_scale"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "icon_scale"), "set_icon_scale", "get_icon_scale"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "fixed_icon_size"), "set_fixed_icon_size", "get_fixed_icon_size"); BIND_ENUM_CONSTANT(ICON_MODE_TOP); @@ -1599,7 +1598,7 @@ ItemList::ItemList() { add_child(scroll_bar); shape_changed = true; - scroll_bar->connect("value_changed", this, "_scroll_changed"); + scroll_bar->connect("value_changed", callable_mp(this, &ItemList::_scroll_changed)); set_focus_mode(FOCUS_ALL); current_columns = 1; diff --git a/scene/gui/item_list.h b/scene/gui/item_list.h index d9b510c762..da9851dd7d 100644 --- a/scene/gui/item_list.h +++ b/scene/gui/item_list.h @@ -52,11 +52,11 @@ public: private: struct Item { - Ref<Texture> icon; + Ref<Texture2D> icon; bool icon_transposed; Rect2i icon_region; Color icon_modulate; - Ref<Texture> tag_icon; + Ref<Texture2D> tag_icon; String text; bool selectable; bool selected; @@ -125,14 +125,14 @@ protected: static void _bind_methods(); public: - void add_item(const String &p_item, const Ref<Texture> &p_texture = Ref<Texture>(), bool p_selectable = true); - void add_icon_item(const Ref<Texture> &p_item, bool p_selectable = true); + void add_item(const String &p_item, const Ref<Texture2D> &p_texture = Ref<Texture2D>(), bool p_selectable = true); + void add_icon_item(const Ref<Texture2D> &p_item, bool p_selectable = true); void set_item_text(int p_idx, const String &p_text); String get_item_text(int p_idx) const; - void set_item_icon(int p_idx, const Ref<Texture> &p_icon); - Ref<Texture> get_item_icon(int p_idx) const; + void set_item_icon(int p_idx, const Ref<Texture2D> &p_icon); + Ref<Texture2D> get_item_icon(int p_idx) const; void set_item_icon_transposed(int p_idx, const bool transposed); bool is_item_icon_transposed(int p_idx) const; @@ -152,8 +152,8 @@ public: void set_item_metadata(int p_idx, const Variant &p_metadata); Variant get_item_metadata(int p_idx) const; - void set_item_tag_icon(int p_idx, const Ref<Texture> &p_tag_icon); - Ref<Texture> get_item_tag_icon(int p_idx) const; + void set_item_tag_icon(int p_idx, const Ref<Texture2D> &p_tag_icon); + Ref<Texture2D> get_item_tag_icon(int p_idx) const; void set_item_tooltip_enabled(int p_idx, const bool p_enabled); bool is_item_tooltip_enabled(int p_idx) const; diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 9b542cb179..c900b35d65 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -687,7 +687,7 @@ void Label::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "is_clipping_text"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uppercase"), "set_uppercase", "is_uppercase"); ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1", PROPERTY_USAGE_EDITOR), "set_visible_characters", "get_visible_characters"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible"); ADD_PROPERTY(PropertyInfo(Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE, "0,999,1"), "set_lines_skipped", "get_lines_skipped"); ADD_PROPERTY(PropertyInfo(Variant::INT, "max_lines_visible", PROPERTY_HINT_RANGE, "-1,999,1"), "set_max_lines_visible", "get_max_lines_visible"); } diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 7cc47d351e..fdddf0b5fa 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -165,7 +165,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { #ifdef APPLE_STYLE_KEYS if (k->get_control() && !k->get_shift() && !k->get_alt() && !k->get_command()) { uint32_t remap_key = KEY_UNKNOWN; - switch (k->get_scancode()) { + switch (k->get_keycode()) { case KEY_F: { remap_key = KEY_RIGHT; } break; @@ -184,16 +184,22 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { case KEY_H: { remap_key = KEY_BACKSPACE; } break; + case KEY_A: { + remap_key = KEY_HOME; + } break; + case KEY_E: { + remap_key = KEY_END; + } break; } if (remap_key != KEY_UNKNOWN) { - k->set_scancode(remap_key); + k->set_keycode(remap_key); k->set_control(false); } } #endif - unsigned int code = k->get_scancode(); + unsigned int code = k->get_keycode(); if (k->get_command() && is_shortcut_keys_enabled()) { @@ -349,14 +355,23 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_LEFT: { - #ifndef APPLE_STYLE_KEYS - if (!k->get_alt()) + if (!k->get_alt()) { #endif + if (selection.enabled && !k->get_shift()) { + set_cursor_position(selection.begin); + deselect(); + handled = true; + break; + } + shift_selection_check_pre(k->get_shift()); +#ifndef APPLE_STYLE_KEYS + } +#endif #ifdef APPLE_STYLE_KEYS if (k->get_command()) { @@ -396,11 +411,23 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_RIGHT: { +#ifndef APPLE_STYLE_KEYS + if (!k->get_alt()) { +#endif + if (selection.enabled && !k->get_shift()) { + set_cursor_position(selection.end); + deselect(); + handled = true; + break; + } - shift_selection_check_pre(k->get_shift()); + shift_selection_check_pre(k->get_shift()); +#ifndef APPLE_STYLE_KEYS + } +#endif #ifdef APPLE_STYLE_KEYS if (k->get_command()) { @@ -503,7 +530,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_HOME: { @@ -516,7 +543,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_END: { @@ -544,7 +571,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (handled) { accept_event(); } else if (!k->get_command()) { - if (k->get_unicode() >= 32 && k->get_scancode() != KEY_DELETE) { + if (k->get_unicode() >= 32 && k->get_keycode() != KEY_DELETE) { if (editable) { selection_delete(); @@ -628,7 +655,7 @@ bool LineEdit::_is_over_clear_button(const Point2 &p_pos) const { if (!clear_button_enabled || !has_point(p_pos)) { return false; } - Ref<Texture> icon = Control::get_icon("clear"); + Ref<Texture2D> icon = Control::get_icon("clear"); int x_ofs = get_stylebox("normal")->get_offset().x; return p_pos.x > get_size().width - icon->get_width() - x_ofs; } @@ -642,8 +669,8 @@ void LineEdit::_notification(int p_what) { cursor_set_blink_enabled(EDITOR_DEF("text_editor/cursor/caret_blink", false)); cursor_set_blink_speed(EDITOR_DEF("text_editor/cursor/caret_blink_speed", 0.65)); - if (!EditorSettings::get_singleton()->is_connected("settings_changed", this, "_editor_settings_changed")) { - EditorSettings::get_singleton()->connect("settings_changed", this, "_editor_settings_changed"); + if (!EditorSettings::get_singleton()->is_connected("settings_changed", callable_mp(this, &LineEdit::_editor_settings_changed))) { + EditorSettings::get_singleton()->connect("settings_changed", callable_mp(this, &LineEdit::_editor_settings_changed)); } } } break; @@ -742,7 +769,7 @@ 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<Texture> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_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) { @@ -1303,7 +1330,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<Texture> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_icon("clear") : right_icon; window_width -= r_icon->get_width(); } @@ -1644,7 +1671,7 @@ bool LineEdit::is_selecting_enabled() const { return selecting_enabled; } -void LineEdit::set_right_icon(const Ref<Texture> &p_icon) { +void LineEdit::set_right_icon(const Ref<Texture2D> &p_icon) { if (right_icon == p_icon) { return; } @@ -1653,7 +1680,7 @@ void LineEdit::set_right_icon(const Ref<Texture> &p_icon) { update(); } -Ref<Texture> LineEdit::get_right_icon() { +Ref<Texture2D> LineEdit::get_right_icon() { return right_icon; } @@ -1746,9 +1773,6 @@ void LineEdit::_generate_context_menu() { void LineEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("_text_changed"), &LineEdit::_text_changed); - ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &LineEdit::_toggle_draw_caret); - - ClassDB::bind_method("_editor_settings_changed", &LineEdit::_editor_settings_changed); ClassDB::bind_method(D_METHOD("set_align", "align"), &LineEdit::set_align); ClassDB::bind_method(D_METHOD("get_align"), &LineEdit::get_align); @@ -1826,10 +1850,10 @@ void LineEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "right_icon", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_right_icon", "get_right_icon"); ADD_GROUP("Placeholder", "placeholder_"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "placeholder_text"), "set_placeholder", "get_placeholder"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "placeholder_alpha", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_placeholder_alpha", "get_placeholder_alpha"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "placeholder_alpha", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_placeholder_alpha", "get_placeholder_alpha"); ADD_GROUP("Caret", "caret_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "cursor_set_blink_speed", "cursor_get_blink_speed"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "cursor_set_blink_speed", "cursor_get_blink_speed"); ADD_PROPERTY(PropertyInfo(Variant::INT, "caret_position"), "set_cursor_position", "get_cursor_position"); } @@ -1864,7 +1888,7 @@ LineEdit::LineEdit() { caret_blink_timer = memnew(Timer); add_child(caret_blink_timer); caret_blink_timer->set_wait_time(0.65); - caret_blink_timer->connect("timeout", this, "_toggle_draw_caret"); + caret_blink_timer->connect("timeout", callable_mp(this, &LineEdit::_toggle_draw_caret)); cursor_set_blink_enabled(false); context_menu_enabled = true; @@ -1872,7 +1896,7 @@ LineEdit::LineEdit() { add_child(menu); editable = false; // Initialise to opposite first, so we get past the early-out in set_editable. set_editable(true); - menu->connect("id_pressed", this, "menu_option"); + menu->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); expand_to_text_length = false; } diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 037238d682..938974453a 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -91,7 +91,7 @@ private: bool shortcut_keys_enabled; - Ref<Texture> right_icon; + Ref<Texture2D> right_icon; struct Selection { @@ -232,8 +232,8 @@ public: void set_selecting_enabled(bool p_enabled); bool is_selecting_enabled() const; - void set_right_icon(const Ref<Texture> &p_icon); - Ref<Texture> get_right_icon(); + void set_right_icon(const Ref<Texture2D> &p_icon); + Ref<Texture2D> get_right_icon(); virtual bool is_text_field() const; LineEdit(); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 6e348054e2..2b163187c5 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "menu_button.h" + #include "core/os/keyboard.h" #include "scene/main/viewport.h" @@ -137,8 +138,8 @@ MenuButton::MenuButton() { popup->hide(); add_child(popup); popup->set_pass_on_modal_close_click(false); - popup->connect("about_to_show", this, "set_pressed", varray(true)); // For when switching from another MenuButton. - popup->connect("popup_hide", this, "set_pressed", varray(false)); + popup->connect("about_to_show", 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)); } MenuButton::~MenuButton() { diff --git a/scene/gui/nine_patch_rect.cpp b/scene/gui/nine_patch_rect.cpp index 945d1850d7..0ef1f53006 100644 --- a/scene/gui/nine_patch_rect.cpp +++ b/scene/gui/nine_patch_rect.cpp @@ -70,7 +70,7 @@ void NinePatchRect::_bind_methods() { ADD_SIGNAL(MethodInfo("texture_changed")); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "draw_center"), "set_draw_center", "is_draw_center_enabled"); ADD_PROPERTY(PropertyInfo(Variant::RECT2, "region_rect"), "set_region_rect", "get_region_rect"); @@ -88,7 +88,7 @@ void NinePatchRect::_bind_methods() { BIND_ENUM_CONSTANT(AXIS_STRETCH_MODE_TILE_FIT); } -void NinePatchRect::set_texture(const Ref<Texture> &p_tex) { +void NinePatchRect::set_texture(const Ref<Texture2D> &p_tex) { if (texture == p_tex) return; @@ -103,7 +103,7 @@ void NinePatchRect::set_texture(const Ref<Texture> &p_tex) { _change_notify("texture"); } -Ref<Texture> NinePatchRect::get_texture() const { +Ref<Texture2D> NinePatchRect::get_texture() const { return texture; } diff --git a/scene/gui/nine_patch_rect.h b/scene/gui/nine_patch_rect.h index 3329c0a64c..0ef7f6b299 100644 --- a/scene/gui/nine_patch_rect.h +++ b/scene/gui/nine_patch_rect.h @@ -47,7 +47,7 @@ public: bool draw_center; int margin[4]; Rect2 region_rect; - Ref<Texture> texture; + Ref<Texture2D> texture; AxisStretchMode axis_h, axis_v; @@ -57,8 +57,8 @@ protected: static void _bind_methods(); public: - void set_texture(const Ref<Texture> &p_tex); - Ref<Texture> get_texture() const; + void set_texture(const Ref<Texture2D> &p_tex); + Ref<Texture2D> get_texture() const; void set_patch_margin(Margin p_margin, int p_size); int get_patch_margin(Margin p_margin) const; diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 3f46afa8e8..c185761beb 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "option_button.h" + #include "core/print_string.h" Size2 OptionButton::get_minimum_size() const { @@ -58,7 +59,7 @@ void OptionButton::_notification(int p_what) { return; RID ci = get_canvas_item(); - Ref<Texture> arrow = Control::get_icon("arrow"); + Ref<Texture2D> arrow = Control::get_icon("arrow"); Color clr = Color(1, 1, 1); if (get_constant("modulate_arrow")) { switch (get_draw_mode()) { @@ -114,7 +115,7 @@ void OptionButton::pressed() { popup->popup(); } -void OptionButton::add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_id) { +void OptionButton::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id) { popup->add_icon_radio_check_item(p_icon, p_label, p_id); if (popup->get_item_count() == 1) @@ -134,7 +135,7 @@ void OptionButton::set_item_text(int p_idx, const String &p_text) { if (current == p_idx) set_text(p_text); } -void OptionButton::set_item_icon(int p_idx, const Ref<Texture> &p_icon) { +void OptionButton::set_item_icon(int p_idx, const Ref<Texture2D> &p_icon) { popup->set_item_icon(p_idx, p_icon); @@ -161,7 +162,7 @@ String OptionButton::get_item_text(int p_idx) const { return popup->get_item_text(p_idx); } -Ref<Texture> OptionButton::get_item_icon(int p_idx) const { +Ref<Texture2D> OptionButton::get_item_icon(int p_idx) const { return popup->get_item_icon(p_idx); } @@ -289,7 +290,7 @@ void OptionButton::_set_items(const Array &p_items) { for (int i = 0; i < p_items.size(); i += 5) { String text = p_items[i + 0]; - Ref<Texture> icon = p_items[i + 1]; + Ref<Texture2D> icon = p_items[i + 1]; bool disabled = p_items[i + 2]; int id = p_items[i + 3]; Variant meta = p_items[i + 4]; @@ -309,9 +310,6 @@ void OptionButton::get_translatable_strings(List<String> *p_strings) const { void OptionButton::_bind_methods() { - ClassDB::bind_method(D_METHOD("_selected"), &OptionButton::_selected); - ClassDB::bind_method(D_METHOD("_focused"), &OptionButton::_focused); - ClassDB::bind_method(D_METHOD("add_item", "label", "id"), &OptionButton::add_item, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("add_icon_item", "texture", "label", "id"), &OptionButton::add_icon_item, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("set_item_text", "idx", "text"), &OptionButton::set_item_text); @@ -363,9 +361,9 @@ OptionButton::OptionButton() { popup->set_pass_on_modal_close_click(false); popup->set_notify_transform(true); popup->set_allow_search(true); - popup->connect("index_pressed", this, "_selected"); - popup->connect("id_focused", this, "_focused"); - popup->connect("popup_hide", this, "set_pressed", varray(false)); + popup->connect("index_pressed", callable_mp(this, &OptionButton::_selected)); + popup->connect("id_focused", callable_mp(this, &OptionButton::_focused)); + popup->connect("popup_hide", callable_mp((BaseButton *)this, &BaseButton::set_pressed), varray(false)); } OptionButton::~OptionButton() { diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h index 04bd28fe28..9658e1fea8 100644 --- a/scene/gui/option_button.h +++ b/scene/gui/option_button.h @@ -57,17 +57,17 @@ protected: static void _bind_methods(); public: - void add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1); + void add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id = -1); void add_item(const String &p_label, int p_id = -1); void set_item_text(int p_idx, const String &p_text); - void set_item_icon(int p_idx, const Ref<Texture> &p_icon); + void set_item_icon(int p_idx, const Ref<Texture2D> &p_icon); void set_item_id(int p_idx, int p_id); void set_item_metadata(int p_idx, const Variant &p_metadata); void set_item_disabled(int p_idx, bool p_disabled); String get_item_text(int p_idx) const; - Ref<Texture> get_item_icon(int p_idx) const; + Ref<Texture2D> get_item_icon(int p_idx) const; int get_item_id(int p_idx) const; int get_item_index(int p_id) const; Variant get_item_metadata(int p_idx) const; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 87f17838cf..e75dadd5e0 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -29,6 +29,7 @@ /*************************************************************************/ #include "popup_menu.h" + #include "core/os/input.h" #include "core/os/keyboard.h" #include "core/os/os.h" @@ -467,9 +468,9 @@ void PopupMenu::_notification(int p_what) { Ref<StyleBox> hover = get_stylebox("hover"); Ref<Font> font = get_font("font"); // In Item::checkable_type enum order (less the non-checkable member) - Ref<Texture> check[] = { get_icon("checked"), get_icon("radio_checked") }; - Ref<Texture> uncheck[] = { get_icon("unchecked"), get_icon("radio_unchecked") }; - Ref<Texture> submenu = get_icon("submenu"); + 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"); @@ -549,7 +550,7 @@ void PopupMenu::_notification(int p_what) { Color icon_color(1, 1, 1, items[i].disabled ? 0.5 : 1); if (items[i].checkable_type) { - Texture *icon = (items[i].checked ? check[items[i].checkable_type - 1] : uncheck[items[i].checkable_type - 1]).ptr(); + 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); } @@ -651,7 +652,7 @@ void PopupMenu::add_item(const String &p_label, int p_id, uint32_t p_accel) { minimum_size_changed(); } -void PopupMenu::add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { +void PopupMenu::add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); @@ -671,7 +672,7 @@ void PopupMenu::add_check_item(const String &p_label, int p_id, uint32_t p_accel minimum_size_changed(); } -void PopupMenu::add_icon_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { +void PopupMenu::add_icon_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); @@ -692,7 +693,7 @@ void PopupMenu::add_radio_check_item(const String &p_label, int p_id, uint32_t p minimum_size_changed(); } -void PopupMenu::add_icon_radio_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { +void PopupMenu::add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id, uint32_t p_accel) { Item item; ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel); @@ -732,7 +733,7 @@ void PopupMenu::add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bool p_g minimum_size_changed(); } -void PopupMenu::add_icon_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { +void PopupMenu::add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); @@ -752,7 +753,7 @@ void PopupMenu::add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id, bo minimum_size_changed(); } -void PopupMenu::add_icon_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { +void PopupMenu::add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); @@ -773,7 +774,7 @@ void PopupMenu::add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_ minimum_size_changed(); } -void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { +void PopupMenu::add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id, bool p_global) { Item item; ITEM_SETUP_WITH_SHORTCUT(p_shortcut, p_id, p_global); @@ -810,7 +811,7 @@ void PopupMenu::set_item_text(int p_idx, const String &p_text) { update(); minimum_size_changed(); } -void PopupMenu::set_item_icon(int p_idx, const Ref<Texture> &p_icon) { +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; @@ -893,9 +894,9 @@ int PopupMenu::get_item_idx_from_text(const String &text) const { return -1; } -Ref<Texture> PopupMenu::get_item_icon(int p_idx) const { +Ref<Texture2D> PopupMenu::get_item_icon(int p_idx) const { - ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture>()); + ERR_FAIL_INDEX_V(p_idx, items.size(), Ref<Texture2D>()); return items[p_idx].icon; } @@ -1074,7 +1075,7 @@ bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_fo Ref<InputEventKey> k = p_event; if (k.is_valid()) { - code = k->get_scancode(); + code = k->get_keycode(); if (code == 0) code = k->get_unicode(); if (k->get_control()) @@ -1233,7 +1234,7 @@ void PopupMenu::_ref_shortcut(Ref<ShortCut> p_sc) { if (!shortcut_refcount.has(p_sc)) { shortcut_refcount[p_sc] = 1; - p_sc->connect("changed", this, "update"); + p_sc->connect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update)); } else { shortcut_refcount[p_sc] += 1; } @@ -1244,7 +1245,7 @@ void PopupMenu::_unref_shortcut(Ref<ShortCut> p_sc) { ERR_FAIL_COND(!shortcut_refcount.has(p_sc)); shortcut_refcount[p_sc]--; if (shortcut_refcount[p_sc] == 0) { - p_sc->disconnect("changed", this, "update"); + p_sc->disconnect("changed", callable_mp((CanvasItem *)this, &CanvasItem::update)); shortcut_refcount.erase(p_sc); } } @@ -1257,7 +1258,7 @@ void PopupMenu::_set_items(const Array &p_items) { for (int i = 0; i < p_items.size(); i += 10) { String text = p_items[i + 0]; - Ref<Texture> icon = p_items[i + 1]; + Ref<Texture2D> icon = p_items[i + 1]; // For compatibility, use false/true for no/checkbox and integers for other values bool checkable = p_items[i + 2]; bool radio_checkable = (int)p_items[i + 2] == Item::CHECKABLE_TYPE_RADIO_BUTTON; @@ -1471,13 +1472,11 @@ void PopupMenu::_bind_methods() { 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); - ClassDB::bind_method(D_METHOD("_submenu_timeout"), &PopupMenu::_submenu_timeout); - ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "items", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_items", "_get_items"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_on_item_selection"), "set_hide_on_item_selection", "is_hide_on_item_selection"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_on_checkable_item_selection"), "set_hide_on_checkable_item_selection", "is_hide_on_checkable_item_selection"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hide_on_state_item_selection"), "set_hide_on_state_item_selection", "is_hide_on_state_item_selection"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "submenu_popup_delay"), "set_submenu_popup_delay", "get_submenu_popup_delay"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "submenu_popup_delay"), "set_submenu_popup_delay", "get_submenu_popup_delay"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_search"), "set_allow_search", "get_allow_search"); ADD_SIGNAL(MethodInfo("id_pressed", PropertyInfo(Variant::INT, "id"))); @@ -1514,7 +1513,7 @@ PopupMenu::PopupMenu() { submenu_timer = memnew(Timer); submenu_timer->set_wait_time(0.3); submenu_timer->set_one_shot(true); - submenu_timer->connect("timeout", this, "_submenu_timeout"); + submenu_timer->connect("timeout", callable_mp(this, &PopupMenu::_submenu_timeout)); add_child(submenu_timer); } diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h index f77ede0a8b..a3a858cfde 100644 --- a/scene/gui/popup_menu.h +++ b/scene/gui/popup_menu.h @@ -38,7 +38,7 @@ class PopupMenu : public Popup { GDCLASS(PopupMenu, Popup); struct Item { - Ref<Texture> icon; + Ref<Texture2D> icon; String text; String xl_text; bool checked; @@ -121,25 +121,25 @@ protected: public: void add_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0); - void add_icon_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0); + void add_icon_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0); void add_check_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0); - void add_icon_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0); + void add_icon_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0); void add_radio_check_item(const String &p_label, int p_id = -1, uint32_t p_accel = 0); - void add_icon_radio_check_item(const Ref<Texture> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0); + void add_icon_radio_check_item(const Ref<Texture2D> &p_icon, const String &p_label, int p_id = -1, uint32_t p_accel = 0); void add_multistate_item(const String &p_label, int p_max_states, int p_default_state = 0, int p_id = -1, uint32_t p_accel = 0); void add_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); - void add_icon_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); + void add_icon_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); void add_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); - void add_icon_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); + void add_icon_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); void add_radio_check_shortcut(const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); - void add_icon_radio_check_shortcut(const Ref<Texture> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); + void add_icon_radio_check_shortcut(const Ref<Texture2D> &p_icon, const Ref<ShortCut> &p_shortcut, int p_id = -1, bool p_global = false); void add_submenu_item(const String &p_label, const String &p_submenu, int p_id = -1); void set_item_text(int p_idx, const String &p_text); - void set_item_icon(int p_idx, const Ref<Texture> &p_icon); + void set_item_icon(int p_idx, const Ref<Texture2D> &p_icon); void set_item_checked(int p_idx, bool p_checked); void set_item_id(int p_idx, int p_id); void set_item_accelerator(int p_idx, uint32_t p_accel); @@ -160,7 +160,7 @@ public: String get_item_text(int p_idx) const; int get_item_idx_from_text(const String &text) const; - Ref<Texture> get_item_icon(int p_idx) const; + Ref<Texture2D> get_item_icon(int p_idx) const; bool is_item_checked(int p_idx) const; int get_item_id(int p_idx) const; int get_item_index(int p_id) const; diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index 6b6f5bca93..adc5f81465 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -267,15 +267,15 @@ void Range::_bind_methods() { ClassDB::bind_method(D_METHOD("share", "with"), &Range::_share); ClassDB::bind_method(D_METHOD("unshare"), &Range::unshare); - ADD_SIGNAL(MethodInfo("value_changed", PropertyInfo(Variant::REAL, "value"))); + ADD_SIGNAL(MethodInfo("value_changed", PropertyInfo(Variant::FLOAT, "value"))); ADD_SIGNAL(MethodInfo("changed")); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "min_value"), "set_min", "get_min"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "max_value"), "set_max", "get_max"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "step"), "set_step", "get_step"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "page"), "set_page", "get_page"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "value"), "set_value", "get_value"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "ratio", PROPERTY_HINT_RANGE, "0,1,0.01", 0), "set_as_ratio", "get_as_ratio"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "min_value"), "set_min", "get_min"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "max_value"), "set_max", "get_max"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "step"), "set_step", "get_step"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "page"), "set_page", "get_page"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "value"), "set_value", "get_value"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "ratio", PROPERTY_HINT_RANGE, "0,1,0.01", 0), "set_as_ratio", "get_as_ratio"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "exp_edit"), "set_exp_ratio", "is_ratio_exp"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rounded"), "set_use_rounded_values", "is_using_rounded_values"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "allow_greater"), "set_allow_greater", "is_greater_allowed"); diff --git a/scene/gui/rich_text_effect.cpp b/scene/gui/rich_text_effect.cpp index c5b1685ff9..0f5926ea1c 100644 --- a/scene/gui/rich_text_effect.cpp +++ b/scene/gui/rich_text_effect.cpp @@ -91,7 +91,7 @@ void CharFXTransform::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "relative_index"), "set_relative_index", "get_relative_index"); ADD_PROPERTY(PropertyInfo(Variant::INT, "absolute_index"), "set_absolute_index", "get_absolute_index"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "elapsed_time"), "set_elapsed_time", "get_elapsed_time"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "elapsed_time"), "set_elapsed_time", "get_elapsed_time"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visibility", "is_visible"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color"); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index af5d0e2f45..bc1510d6f6 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -204,6 +204,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & int line_ascent = cfont->get_ascent(); int line_descent = cfont->get_descent(); + int backtrack = 0; // for dynamic hidden content. + int nonblank_line_count = 0; //number of nonblank lines as counted during PROCESS_DRAW Variant meta; @@ -214,6 +216,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & { \ if (p_mode != PROCESS_CACHE) { \ line++; \ + backtrack = 0; \ if (!line_is_blank) { \ nonblank_line_count++; \ } \ @@ -263,7 +266,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & l.maximum_width = MAX(l.maximum_width, MIN(p_width, wofs + m_width)); \ l.minimum_width = MAX(l.minimum_width, m_width); \ } \ - if (wofs + m_width > p_width) { \ + if (wofs - backtrack + m_width > p_width) { \ line_wrapped = true; \ if (p_mode == PROCESS_CACHE) { \ if (spaces > 0) \ @@ -390,6 +393,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & int fw = 0; lh = 0; + if (p_mode != PROCESS_CACHE) { lh = line < l.height_caches.size() ? l.height_caches[line] : 1; line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1; @@ -432,13 +436,12 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & { - int ofs = 0; + int ofs = 0 - backtrack; for (int i = 0; i < end; i++) { int pofs = wofs + ofs; if (p_mode == PROCESS_POINTER && r_click_char && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) { - //int o = (wofs+w)-p_click_pos.x; int cw = font->get_char_size(c[i], c[i + 1]).x; @@ -481,7 +484,10 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & bool visible = visible_characters < 0 || ((p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent)) && faded_visibility > 0.0f); + const bool previously_visible = visible; + for (int j = 0; j < fx_stack.size(); j++) { + ItemFX *item_fx = fx_stack[j]; if (item_fx->type == ITEM_CUSTOMFX && custom_fx_ok) { @@ -575,6 +581,8 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } else { cw = drawer.draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], fx_color); } + } else if (previously_visible) { + backtrack += font->get_char_size(fx_char, c[i + 1]).x; } p_char_count++; @@ -648,6 +656,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & case ITEM_NEWLINE: { lh = 0; + if (p_mode != PROCESS_CACHE) { lh = line < l.height_caches.size() ? l.height_caches[line] : 1; line_is_blank = true; @@ -1199,49 +1208,59 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { if (k.is_valid()) { if (k->is_pressed() && !k->get_alt() && !k->get_shift()) { - bool handled = true; - switch (k->get_scancode()) { + bool handled = false; + switch (k->get_keycode()) { case KEY_PAGEUP: { - if (vscroll->is_visible_in_tree()) + if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_value() - vscroll->get_page()); + handled = true; + } } break; case KEY_PAGEDOWN: { - if (vscroll->is_visible_in_tree()) + if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_value() + vscroll->get_page()); + handled = true; + } } break; case KEY_UP: { - if (vscroll->is_visible_in_tree()) + if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_value() - get_font("normal_font")->get_height()); + handled = true; + } } break; case KEY_DOWN: { - if (vscroll->is_visible_in_tree()) + if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_value() + get_font("normal_font")->get_height()); + handled = true; + } } break; case KEY_HOME: { - if (vscroll->is_visible_in_tree()) + if (vscroll->is_visible_in_tree()) { vscroll->set_value(0); + handled = true; + } } break; case KEY_END: { - if (vscroll->is_visible_in_tree()) + if (vscroll->is_visible_in_tree()) { vscroll->set_value(vscroll->get_max()); + handled = true; + } } break; case KEY_INSERT: case KEY_C: { if (k->get_command()) { selection_copy(); - } else { - handled = false; + handled = true; } } break; - default: handled = false; } if (handled) @@ -1648,7 +1667,7 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub } } -void RichTextLabel::add_image(const Ref<Texture> &p_image, const int p_width, const int p_height) { +void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height) { if (current->type == ITEM_TABLE) return; @@ -2204,7 +2223,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1); - Ref<Texture> texture = ResourceLoader::load(image, "Texture"); + Ref<Texture2D> texture = ResourceLoader::load(image, "Texture2D"); if (texture.is_valid()) add_image(texture); @@ -2230,7 +2249,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { String image = p_bbcode.substr(brk_end + 1, end - brk_end - 1); - Ref<Texture> texture = ResourceLoader::load(image, "Texture"); + Ref<Texture2D> texture = ResourceLoader::load(image, "Texture"); if (texture.is_valid()) add_image(texture, width, height); @@ -2655,7 +2674,7 @@ void RichTextLabel::set_effects(const Vector<Variant> &effects) { Vector<Variant> RichTextLabel::get_effects() { Vector<Variant> r; for (int i = 0; i < custom_effects.size(); i++) { - r.push_back(custom_effects[i].get_ref_ptr()); + r.push_back(custom_effects[i]); } return r; } @@ -2680,7 +2699,6 @@ int RichTextLabel::get_content_height() { void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &RichTextLabel::_gui_input); - ClassDB::bind_method(D_METHOD("_scroll_changed"), &RichTextLabel::_scroll_changed); ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text); ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text); ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text); @@ -2762,7 +2780,7 @@ void RichTextLabel::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::STRING, "bbcode_text", PROPERTY_HINT_MULTILINE_TEXT), "set_bbcode", "get_bbcode"); ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta_underlined"), "set_meta_underline", "is_meta_underlined"); ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_size", PROPERTY_HINT_RANGE, "0,24,1"), "set_tab_size", "get_tab_size"); @@ -2944,7 +2962,7 @@ RichTextLabel::RichTextLabel() { vscroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0); vscroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); vscroll->set_anchor_and_margin(MARGIN_RIGHT, ANCHOR_END, 0); - vscroll->connect("value_changed", this, "_scroll_changed"); + vscroll->connect("value_changed", callable_mp(this, &RichTextLabel::_scroll_changed)); vscroll->set_step(1); vscroll->hide(); current_idx = 1; diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 61ac0bd86c..409aec0ca6 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -147,7 +147,7 @@ private: }; struct ItemImage : public Item { - Ref<Texture> image; + Ref<Texture2D> image; Size2 size; ItemImage() { type = ITEM_IMAGE; } }; @@ -407,7 +407,7 @@ protected: public: String get_text(); void add_text(const String &p_text); - void add_image(const Ref<Texture> &p_image, const int p_width = 0, const int p_height = 0); + void add_image(const Ref<Texture2D> &p_image, const int p_width = 0, const int p_height = 0); void add_newline(); bool remove_line(const int p_line); void push_font(const Ref<Font> &p_font); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 45fa212886..fef5e00984 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -71,8 +71,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<Texture> decr = get_icon("decrement"); - Ref<Texture> incr = get_icon("increment"); + Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_icon("increment"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -148,7 +148,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<Texture> decr = get_icon("decrement"); + Ref<Texture2D> decr = get_icon("decrement"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); ofs -= decr_size; @@ -159,8 +159,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { } else { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture> decr = get_icon("decrement"); - Ref<Texture> incr = get_icon("increment"); + Ref<Texture2D> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_icon("increment"); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -233,8 +233,8 @@ void ScrollBar::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<Texture> decr = highlight == HIGHLIGHT_DECR ? get_icon("decrement_highlight") : get_icon("decrement"); - Ref<Texture> incr = highlight == HIGHLIGHT_INCR ? get_icon("increment_highlight") : get_icon("increment"); + 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<StyleBox> grabber; @@ -296,15 +296,15 @@ void ScrollBar::_notification(int p_what) { } if (drag_node) { - drag_node->connect("gui_input", this, "_drag_node_input"); - drag_node->connect("tree_exiting", this, "_drag_node_exit", varray(), CONNECT_ONESHOT); + drag_node->connect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->connect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit), varray(), CONNECT_ONESHOT); } } if (p_what == NOTIFICATION_EXIT_TREE) { if (drag_node) { - drag_node->disconnect("gui_input", this, "_drag_node_input"); - drag_node->disconnect("tree_exiting", this, "_drag_node_exit"); + drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit)); } drag_node = NULL; @@ -500,8 +500,8 @@ double ScrollBar::get_grabber_offset() const { Size2 ScrollBar::get_minimum_size() const { - Ref<Texture> incr = get_icon("increment"); - Ref<Texture> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_icon("decrement"); Ref<StyleBox> bg = get_stylebox("scroll"); Size2 minsize; @@ -539,7 +539,7 @@ float ScrollBar::get_custom_step() const { void ScrollBar::_drag_node_exit() { if (drag_node) { - drag_node->disconnect("gui_input", this, "_drag_node_input"); + drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); } drag_node = NULL; } @@ -611,8 +611,8 @@ void ScrollBar::set_drag_node(const NodePath &p_path) { if (is_inside_tree()) { if (drag_node) { - drag_node->disconnect("gui_input", this, "_drag_node_input"); - drag_node->disconnect("tree_exiting", this, "_drag_node_exit"); + drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit)); } } @@ -627,8 +627,8 @@ void ScrollBar::set_drag_node(const NodePath &p_path) { } if (drag_node) { - drag_node->connect("gui_input", this, "_drag_node_input"); - drag_node->connect("tree_exiting", this, "_drag_node_exit", varray(), CONNECT_ONESHOT); + drag_node->connect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input)); + drag_node->connect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit), varray(), CONNECT_ONESHOT); } } } @@ -651,12 +651,10 @@ void ScrollBar::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollBar::_gui_input); ClassDB::bind_method(D_METHOD("set_custom_step", "step"), &ScrollBar::set_custom_step); ClassDB::bind_method(D_METHOD("get_custom_step"), &ScrollBar::get_custom_step); - ClassDB::bind_method(D_METHOD("_drag_node_input"), &ScrollBar::_drag_node_input); - ClassDB::bind_method(D_METHOD("_drag_node_exit"), &ScrollBar::_drag_node_exit); ADD_SIGNAL(MethodInfo("scrolling")); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "custom_step", PROPERTY_HINT_RANGE, "-1,4096"), "set_custom_step", "get_custom_step"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "custom_step", PROPERTY_HINT_RANGE, "-1,4096"), "set_custom_step", "get_custom_step"); } ScrollBar::ScrollBar(Orientation p_orientation) { diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 509e6d19f6..c25a6d5a0c 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -267,7 +267,7 @@ void ScrollContainer::_notification(int p_what) { if (p_what == NOTIFICATION_READY) { - get_viewport()->connect("gui_focus_changed", this, "_ensure_focused_visible"); + get_viewport()->connect("gui_focus_changed", callable_mp(this, &ScrollContainer::_ensure_focused_visible)); } if (p_what == NOTIFICATION_SORT_CHILDREN) { @@ -570,14 +570,12 @@ VScrollBar *ScrollContainer::get_v_scrollbar() { void ScrollContainer::_bind_methods() { - ClassDB::bind_method(D_METHOD("_scroll_moved"), &ScrollContainer::_scroll_moved); ClassDB::bind_method(D_METHOD("_gui_input"), &ScrollContainer::_gui_input); ClassDB::bind_method(D_METHOD("set_enable_h_scroll", "enable"), &ScrollContainer::set_enable_h_scroll); ClassDB::bind_method(D_METHOD("is_h_scroll_enabled"), &ScrollContainer::is_h_scroll_enabled); ClassDB::bind_method(D_METHOD("set_enable_v_scroll", "enable"), &ScrollContainer::set_enable_v_scroll); ClassDB::bind_method(D_METHOD("is_v_scroll_enabled"), &ScrollContainer::is_v_scroll_enabled); ClassDB::bind_method(D_METHOD("_update_scrollbar_position"), &ScrollContainer::_update_scrollbar_position); - ClassDB::bind_method(D_METHOD("_ensure_focused_visible"), &ScrollContainer::_ensure_focused_visible); ClassDB::bind_method(D_METHOD("set_h_scroll", "value"), &ScrollContainer::set_h_scroll); ClassDB::bind_method(D_METHOD("get_h_scroll"), &ScrollContainer::get_h_scroll); ClassDB::bind_method(D_METHOD("set_v_scroll", "value"), &ScrollContainer::set_v_scroll); @@ -610,12 +608,12 @@ ScrollContainer::ScrollContainer() { h_scroll = memnew(HScrollBar); h_scroll->set_name("_h_scroll"); add_child(h_scroll); - h_scroll->connect("value_changed", this, "_scroll_moved"); + h_scroll->connect("value_changed", callable_mp(this, &ScrollContainer::_scroll_moved)); v_scroll = memnew(VScrollBar); v_scroll->set_name("_v_scroll"); add_child(v_scroll); - v_scroll->connect("value_changed", this, "_scroll_moved"); + v_scroll->connect("value_changed", callable_mp(this, &ScrollContainer::_scroll_moved)); drag_speed = Vector2(); drag_touching = false; diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 9b3ed35e6e..85887ef7b1 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -36,7 +36,7 @@ Size2 Slider::get_minimum_size() const { Ref<StyleBox> style = get_stylebox("slider"); Size2i ss = style->get_minimum_size() + style->get_center_size(); - Ref<Texture> grabber = get_icon("grabber"); + Ref<Texture2D> grabber = get_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<Texture> grabber = get_icon(mouse_inside || has_focus() ? "grabber_highlight" : "grabber"); + Ref<Texture2D> grabber = get_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<Texture> grabber = get_icon("grabber"); + Ref<Texture2D> grabber = get_icon("grabber"); float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos; if (orientation == VERTICAL) motion = -motion; @@ -167,8 +167,8 @@ void Slider::_notification(int p_what) { Size2i size = get_size(); Ref<StyleBox> style = get_stylebox("slider"); Ref<StyleBox> grabber_area = get_stylebox("grabber_area"); - Ref<Texture> grabber = get_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled"); - Ref<Texture> tick = get_icon("tick"); + Ref<Texture2D> grabber = get_icon(editable ? ((mouse_inside || has_focus()) ? "grabber_highlight" : "grabber") : "grabber_disabled"); + Ref<Texture2D> tick = get_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 92377949f8..576de98a4f 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -182,7 +182,7 @@ void SpinBox::_line_edit_focus_exit() { _text_entered(line_edit->get_text()); } -inline void SpinBox::_adjust_width_for_icon(const Ref<Texture> &icon) { +inline void SpinBox::_adjust_width_for_icon(const Ref<Texture2D> &icon) { int w = icon->get_width(); if (w != last_w) { @@ -195,7 +195,7 @@ void SpinBox::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<Texture> updown = get_icon("updown"); + Ref<Texture2D> updown = get_icon("updown"); _adjust_width_for_icon(updown); @@ -267,7 +267,6 @@ void SpinBox::_bind_methods() { //ClassDB::bind_method(D_METHOD("_value_changed"),&SpinBox::_value_changed); ClassDB::bind_method(D_METHOD("_gui_input"), &SpinBox::_gui_input); - ClassDB::bind_method(D_METHOD("_text_entered"), &SpinBox::_text_entered); ClassDB::bind_method(D_METHOD("set_align", "align"), &SpinBox::set_align); ClassDB::bind_method(D_METHOD("get_align"), &SpinBox::get_align); ClassDB::bind_method(D_METHOD("set_suffix", "suffix"), &SpinBox::set_suffix); @@ -277,10 +276,7 @@ void SpinBox::_bind_methods() { ClassDB::bind_method(D_METHOD("set_editable", "editable"), &SpinBox::set_editable); ClassDB::bind_method(D_METHOD("is_editable"), &SpinBox::is_editable); ClassDB::bind_method(D_METHOD("apply"), &SpinBox::apply); - ClassDB::bind_method(D_METHOD("_line_edit_focus_exit"), &SpinBox::_line_edit_focus_exit); ClassDB::bind_method(D_METHOD("get_line_edit"), &SpinBox::get_line_edit); - ClassDB::bind_method(D_METHOD("_line_edit_input"), &SpinBox::_line_edit_input); - ClassDB::bind_method(D_METHOD("_range_click_timeout"), &SpinBox::_range_click_timeout); ADD_PROPERTY(PropertyInfo(Variant::INT, "align", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_align", "get_align"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "editable"), "set_editable", "is_editable"); @@ -297,12 +293,12 @@ SpinBox::SpinBox() { line_edit->set_anchors_and_margins_preset(Control::PRESET_WIDE); line_edit->set_mouse_filter(MOUSE_FILTER_PASS); //connect("value_changed",this,"_value_changed"); - line_edit->connect("text_entered", this, "_text_entered", Vector<Variant>(), CONNECT_DEFERRED); - line_edit->connect("focus_exited", this, "_line_edit_focus_exit", Vector<Variant>(), CONNECT_DEFERRED); - line_edit->connect("gui_input", this, "_line_edit_input"); + line_edit->connect("text_entered", callable_mp(this, &SpinBox::_text_entered), Vector<Variant>(), CONNECT_DEFERRED); + line_edit->connect("focus_exited", callable_mp(this, &SpinBox::_line_edit_focus_exit), Vector<Variant>(), CONNECT_DEFERRED); + line_edit->connect("gui_input", callable_mp(this, &SpinBox::_line_edit_input)); drag.enabled = false; range_click_timer = memnew(Timer); - range_click_timer->connect("timeout", this, "_range_click_timeout"); + range_click_timer->connect("timeout", callable_mp(this, &SpinBox::_range_click_timeout)); add_child(range_click_timer); } diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h index 04491c8477..d3a3d8fe3d 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -62,7 +62,7 @@ class SpinBox : public Range { void _line_edit_focus_exit(); - inline void _adjust_width_for_icon(const Ref<Texture> &icon); + inline void _adjust_width_for_icon(const Ref<Texture2D> &icon); protected: void _gui_input(const Ref<InputEvent> &p_event); diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 079907db07..255278be2b 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -74,7 +74,7 @@ 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<Texture> g = get_icon("grabber"); + Ref<Texture2D> g = get_icon("grabber"); int sep = get_constant("separation"); sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0; @@ -123,7 +123,7 @@ Size2 SplitContainer::get_minimum_size() const { /* Calculate MINIMUM SIZE */ Size2i minimum; - Ref<Texture> g = get_icon("grabber"); + Ref<Texture2D> g = get_icon("grabber"); int sep = get_constant("separation"); sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0; @@ -182,7 +182,7 @@ void SplitContainer::_notification(int p_what) { return; int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0; - Ref<Texture> tex = get_icon("grabber"); + Ref<Texture2D> tex = get_icon("grabber"); Size2 size = get_size(); if (vertical) diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index b045ff4fe1..6290d364fc 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -58,7 +58,7 @@ int TabContainer::_get_top_margin() const { if (!c->has_meta("_tab_icon")) continue; - Ref<Texture> tex = c->get_meta("_tab_icon"); + Ref<Texture2D> tex = c->get_meta("_tab_icon"); if (!tex.is_valid()) continue; content_height = MAX(content_height, tex->get_size().height); @@ -81,7 +81,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { return; // Handle menu button. - Ref<Texture> menu = get_icon("menu"); + Ref<Texture2D> menu = get_icon("menu"); if (popup && pos.x > size.width - menu->get_width()) { emit_signal("pre_popup_pressed"); @@ -107,8 +107,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { popup_ofs = menu->get_width(); } - Ref<Texture> increment = get_icon("increment"); - Ref<Texture> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_icon("increment"); + Ref<Texture2D> decrement = get_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<Texture> menu = get_icon("menu"); + Ref<Texture2D> menu = get_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<Texture> increment = get_icon("increment"); - Ref<Texture> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_icon("increment"); + Ref<Texture2D> decrement = get_icon("decrement"); if (pos.x >= size.width - increment->get_width() - popup_ofs) { if (highlight_arrow != 1) { @@ -225,9 +225,9 @@ void TabContainer::_notification(int p_what) { Vector<Control *> tabs = _get_tabs(); int side_margin = get_constant("side_margin"); - Ref<Texture> menu = get_icon("menu"); - Ref<Texture> increment = get_icon("increment"); - Ref<Texture> decrement = get_icon("decrement"); + Ref<Texture2D> menu = get_icon("menu"); + Ref<Texture2D> increment = get_icon("increment"); + Ref<Texture2D> decrement = get_icon("decrement"); int header_width = get_size().width - side_margin * 2; // Find the width of the header area. @@ -272,12 +272,12 @@ void TabContainer::_notification(int p_what) { 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<Texture> increment = get_icon("increment"); - Ref<Texture> increment_hl = get_icon("increment_highlight"); - Ref<Texture> decrement = get_icon("decrement"); - Ref<Texture> decrement_hl = get_icon("decrement_highlight"); - Ref<Texture> menu = get_icon("menu"); - Ref<Texture> menu_hl = get_icon("menu_highlight"); + 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"); @@ -383,7 +383,7 @@ void TabContainer::_notification(int p_what) { // Draw the tab icon. if (control->has_meta("_tab_icon")) { - Ref<Texture> icon = control->get_meta("_tab_icon"); + Ref<Texture2D> icon = control->get_meta("_tab_icon"); if (icon.is_valid()) { int y = y_center - (icon->get_height() / 2); icon->draw(canvas, Point2i(x_content, y)); @@ -464,7 +464,7 @@ int TabContainer::_get_tab_width(int p_index) const { // Add space for a tab icon. if (control->has_meta("_tab_icon")) { - Ref<Texture> icon = control->get_meta("_tab_icon"); + Ref<Texture2D> icon = control->get_meta("_tab_icon"); if (icon.is_valid()) { width += icon->get_width(); if (text != "") @@ -537,8 +537,8 @@ void TabContainer::add_child_notify(Node *p_child) { c->set_margin(Margin(MARGIN_BOTTOM), c->get_margin(Margin(MARGIN_BOTTOM)) - sb->get_margin(Margin(MARGIN_BOTTOM))); update(); - p_child->connect("renamed", this, "_child_renamed_callback"); - if (first) + p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback)); + if (first && is_inside_tree()) emit_signal("tab_changed", current); } @@ -620,7 +620,7 @@ void TabContainer::remove_child_notify(Node *p_child) { call_deferred("_update_current_tab"); - p_child->disconnect("renamed", this, "_child_renamed_callback"); + p_child->disconnect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback)); update(); } @@ -648,7 +648,7 @@ Variant TabContainer::get_drag_data(const Point2 &p_point) { HBoxContainer *drag_preview = memnew(HBoxContainer); - Ref<Texture> icon = get_tab_icon(tab_over); + Ref<Texture2D> icon = get_tab_icon(tab_over); if (!icon.is_null()) { TextureRect *tf = memnew(TextureRect); tf->set_texture(icon); @@ -745,12 +745,12 @@ int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const { int right_ofs = 0; if (popup) { - Ref<Texture> menu = get_icon("menu"); + Ref<Texture2D> menu = get_icon("menu"); right_ofs += menu->get_width(); } if (buttons_visible_cache) { - Ref<Texture> increment = get_icon("increment"); - Ref<Texture> decrement = get_icon("decrement"); + Ref<Texture2D> increment = get_icon("increment"); + Ref<Texture2D> decrement = get_icon("decrement"); right_ofs += increment->get_width() + decrement->get_width(); } if (p_point.x > size.width - right_ofs) { @@ -834,21 +834,21 @@ String TabContainer::get_tab_title(int p_tab) const { return child->get_name(); } -void TabContainer::set_tab_icon(int p_tab, const Ref<Texture> &p_icon) { +void TabContainer::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) { Control *child = _get_tab(p_tab); ERR_FAIL_COND(!child); child->set_meta("_tab_icon", p_icon); update(); } -Ref<Texture> TabContainer::get_tab_icon(int p_tab) const { +Ref<Texture2D> TabContainer::get_tab_icon(int p_tab) const { Control *child = _get_tab(p_tab); - ERR_FAIL_COND_V(!child, Ref<Texture>()); + ERR_FAIL_COND_V(!child, Ref<Texture2D>()); if (child->has_meta("_tab_icon")) return child->get_meta("_tab_icon"); else - return Ref<Texture>(); + return Ref<Texture2D>(); } void TabContainer::set_tab_disabled(int p_tab, bool p_disabled) { @@ -1011,9 +1011,7 @@ void TabContainer::_bind_methods() { ClassDB::bind_method(D_METHOD("set_use_hidden_tabs_for_min_size", "enabled"), &TabContainer::set_use_hidden_tabs_for_min_size); ClassDB::bind_method(D_METHOD("get_use_hidden_tabs_for_min_size"), &TabContainer::get_use_hidden_tabs_for_min_size); - ClassDB::bind_method(D_METHOD("_child_renamed_callback"), &TabContainer::_child_renamed_callback); ClassDB::bind_method(D_METHOD("_on_theme_changed"), &TabContainer::_on_theme_changed); - ClassDB::bind_method(D_METHOD("_on_mouse_exited"), &TabContainer::_on_mouse_exited); ClassDB::bind_method(D_METHOD("_update_current_tab"), &TabContainer::_update_current_tab); ADD_SIGNAL(MethodInfo("tab_changed", PropertyInfo(Variant::INT, "tab"))); @@ -1048,5 +1046,5 @@ TabContainer::TabContainer() { tabs_rearrange_group = -1; use_hidden_tabs_for_min_size = false; - connect("mouse_exited", this, "_on_mouse_exited"); + connect("mouse_exited", callable_mp(this, &TabContainer::_on_mouse_exited)); } diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index c5a9045ca6..38c029475c 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -93,8 +93,8 @@ public: void set_tab_title(int p_tab, const String &p_title); String get_tab_title(int p_tab) const; - void set_tab_icon(int p_tab, const Ref<Texture> &p_icon); - Ref<Texture> get_tab_icon(int p_tab) const; + void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon); + Ref<Texture2D> get_tab_icon(int p_tab) const; void set_tab_disabled(int p_tab, bool p_disabled); bool get_tab_disabled(int p_tab) const; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 6cd95e73fc..901408919a 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -46,7 +46,7 @@ Size2 Tabs::get_minimum_size() const { for (int i = 0; i < tabs.size(); i++) { - Ref<Texture> tex = tabs[i].icon; + Ref<Texture2D> tex = tabs[i].icon; if (tex.is_valid()) { ms.height = MAX(ms.height, tex->get_size().height); if (tabs[i].text != "") @@ -63,7 +63,7 @@ Size2 Tabs::get_minimum_size() const { ms.width += tab_bg->get_minimum_size().width; if (tabs[i].right_button.is_valid()) { - Ref<Texture> rb = tabs[i].right_button; + Ref<Texture2D> rb = tabs[i].right_button; Size2 bms = rb->get_size(); bms.width += get_constant("hseparation"); ms.width += bms.width; @@ -71,7 +71,7 @@ Size2 Tabs::get_minimum_size() const { } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<Texture> cb = get_icon("close"); + Ref<Texture2D> cb = get_icon("close"); Size2 bms = cb->get_size(); bms.width += get_constant("hseparation"); ms.width += bms.width; @@ -94,8 +94,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { highlight_arrow = -1; if (buttons_visible) { - Ref<Texture> incr = get_icon("increment"); - Ref<Texture> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_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<Texture> incr = get_icon("increment"); - Ref<Texture> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); @@ -245,7 +245,7 @@ void Tabs::_notification(int p_what) { 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<Texture> close = get_icon("close"); + Ref<Texture2D> close = get_icon("close"); int h = get_size().height; int w = 0; @@ -267,10 +267,10 @@ void Tabs::_notification(int p_what) { w = 0; } - Ref<Texture> incr = get_icon("increment"); - Ref<Texture> decr = get_icon("decrement"); - Ref<Texture> incr_hl = get_icon("increment_highlight"); - Ref<Texture> decr_hl = get_icon("decrement_highlight"); + 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"); int limit = get_size().width - incr->get_size().width - decr->get_size().width; @@ -313,7 +313,7 @@ void Tabs::_notification(int p_what) { w += sb->get_margin(MARGIN_LEFT); Size2i sb_ms = sb->get_minimum_size(); - Ref<Texture> icon = tabs[i].icon; + Ref<Texture2D> icon = tabs[i].icon; if (icon.is_valid()) { icon->draw(ci, Point2i(w, sb->get_margin(MARGIN_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2)); @@ -328,7 +328,7 @@ void Tabs::_notification(int p_what) { if (tabs[i].right_button.is_valid()) { Ref<StyleBox> style = get_stylebox("button"); - Ref<Texture> rb = tabs[i].right_button; + Ref<Texture2D> rb = tabs[i].right_button; w += get_constant("hseparation"); @@ -352,7 +352,7 @@ 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<Texture> cb = close; + Ref<Texture2D> cb = close; w += get_constant("hseparation"); @@ -449,7 +449,7 @@ String Tabs::get_tab_title(int p_tab) const { return tabs[p_tab].text; } -void Tabs::set_tab_icon(int p_tab, const Ref<Texture> &p_icon) { +void Tabs::set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon) { ERR_FAIL_INDEX(p_tab, tabs.size()); tabs.write[p_tab].icon = p_icon; @@ -457,9 +457,9 @@ void Tabs::set_tab_icon(int p_tab, const Ref<Texture> &p_icon) { minimum_size_changed(); } -Ref<Texture> Tabs::get_tab_icon(int p_tab) const { +Ref<Texture2D> Tabs::get_tab_icon(int p_tab) const { - ERR_FAIL_INDEX_V(p_tab, tabs.size(), Ref<Texture>()); + ERR_FAIL_INDEX_V(p_tab, tabs.size(), Ref<Texture2D>()); return tabs[p_tab].icon; } @@ -475,7 +475,7 @@ bool Tabs::get_tab_disabled(int p_tab) const { return tabs[p_tab].disabled; } -void Tabs::set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button) { +void Tabs::set_tab_right_button(int p_tab, const Ref<Texture2D> &p_right_button) { ERR_FAIL_INDEX(p_tab, tabs.size()); tabs.write[p_tab].right_button = p_right_button; @@ -483,9 +483,9 @@ void Tabs::set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button) { update(); minimum_size_changed(); } -Ref<Texture> Tabs::get_tab_right_button(int p_tab) const { +Ref<Texture2D> Tabs::get_tab_right_button(int p_tab) const { - ERR_FAIL_INDEX_V(p_tab, tabs.size(), Ref<Texture>()); + ERR_FAIL_INDEX_V(p_tab, tabs.size(), Ref<Texture2D>()); return tabs[p_tab].right_button; } @@ -536,8 +536,8 @@ void Tabs::_update_cache() { Ref<StyleBox> tab_bg = get_stylebox("tab_bg"); Ref<StyleBox> tab_fg = get_stylebox("tab_fg"); Ref<Font> font = get_font("font"); - Ref<Texture> incr = get_icon("increment"); - Ref<Texture> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_icon("decrement"); int limit = get_size().width - incr->get_width() - decr->get_width(); int w = 0; @@ -580,7 +580,7 @@ void Tabs::_update_cache() { slen -= get_constant("hseparation"); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<Texture> cb = get_icon("close"); + Ref<Texture2D> cb = get_icon("close"); slen -= cb->get_width(); slen -= get_constant("hseparation"); } @@ -604,7 +604,7 @@ void Tabs::_on_mouse_exited() { update(); } -void Tabs::add_tab(const String &p_str, const Ref<Texture> &p_icon) { +void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) { Tab t; t.text = p_str; @@ -806,7 +806,7 @@ int Tabs::get_tab_width(int p_idx) const { int x = 0; - Ref<Texture> tex = tabs[p_idx].icon; + Ref<Texture2D> tex = tabs[p_idx].icon; if (tex.is_valid()) { x += tex->get_width(); if (tabs[p_idx].text != "") @@ -823,13 +823,13 @@ int Tabs::get_tab_width(int p_idx) const { x += tab_bg->get_minimum_size().width; if (tabs[p_idx].right_button.is_valid()) { - Ref<Texture> rb = tabs[p_idx].right_button; + Ref<Texture2D> rb = tabs[p_idx].right_button; x += rb->get_width(); x += get_constant("hseparation"); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx == current)) { - Ref<Texture> cb = get_icon("close"); + Ref<Texture2D> cb = get_icon("close"); x += cb->get_width(); x += get_constant("hseparation"); } @@ -842,8 +842,8 @@ void Tabs::_ensure_no_over_offset() { if (!is_inside_tree()) return; - Ref<Texture> incr = get_icon("increment"); - Ref<Texture> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_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<Texture> incr = get_icon("increment"); - Ref<Texture> decr = get_icon("decrement"); + Ref<Texture2D> incr = get_icon("increment"); + Ref<Texture2D> decr = get_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) { @@ -956,7 +956,6 @@ void Tabs::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &Tabs::_gui_input); ClassDB::bind_method(D_METHOD("_update_hover"), &Tabs::_update_hover); - ClassDB::bind_method(D_METHOD("_on_mouse_exited"), &Tabs::_on_mouse_exited); ClassDB::bind_method(D_METHOD("get_tab_count"), &Tabs::get_tab_count); ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &Tabs::set_current_tab); ClassDB::bind_method(D_METHOD("get_current_tab"), &Tabs::get_current_tab); @@ -967,7 +966,7 @@ void Tabs::_bind_methods() { ClassDB::bind_method(D_METHOD("set_tab_disabled", "tab_idx", "disabled"), &Tabs::set_tab_disabled); ClassDB::bind_method(D_METHOD("get_tab_disabled", "tab_idx"), &Tabs::get_tab_disabled); ClassDB::bind_method(D_METHOD("remove_tab", "tab_idx"), &Tabs::remove_tab); - ClassDB::bind_method(D_METHOD("add_tab", "title", "icon"), &Tabs::add_tab, DEFVAL(""), DEFVAL(Ref<Texture>())); + ClassDB::bind_method(D_METHOD("add_tab", "title", "icon"), &Tabs::add_tab, DEFVAL(""), DEFVAL(Ref<Texture2D>())); ClassDB::bind_method(D_METHOD("set_tab_align", "align"), &Tabs::set_tab_align); ClassDB::bind_method(D_METHOD("get_tab_align"), &Tabs::get_tab_align); ClassDB::bind_method(D_METHOD("get_tab_offset"), &Tabs::get_tab_offset); @@ -1034,5 +1033,5 @@ Tabs::Tabs() { drag_to_rearrange_enabled = false; tabs_rearrange_group = -1; - connect("mouse_exited", this, "_on_mouse_exited"); + connect("mouse_exited", callable_mp(this, &Tabs::_on_mouse_exited)); } diff --git a/scene/gui/tabs.h b/scene/gui/tabs.h index c06e47a54a..3170acb46f 100644 --- a/scene/gui/tabs.h +++ b/scene/gui/tabs.h @@ -59,7 +59,7 @@ private: String text; String xl_text; - Ref<Texture> icon; + Ref<Texture2D> icon; int ofs_cache; bool disabled; int size_cache; @@ -67,7 +67,7 @@ private: int x_cache; int x_size_cache; - Ref<Texture> right_button; + Ref<Texture2D> right_button; Rect2 rb_rect; Rect2 cb_rect; }; @@ -115,19 +115,19 @@ protected: int get_tab_idx_at_point(const Point2 &p_point) const; public: - void add_tab(const String &p_str = "", const Ref<Texture> &p_icon = Ref<Texture>()); + void add_tab(const String &p_str = "", const Ref<Texture2D> &p_icon = Ref<Texture2D>()); void set_tab_title(int p_tab, const String &p_title); String get_tab_title(int p_tab) const; - void set_tab_icon(int p_tab, const Ref<Texture> &p_icon); - Ref<Texture> get_tab_icon(int p_tab) const; + void set_tab_icon(int p_tab, const Ref<Texture2D> &p_icon); + Ref<Texture2D> get_tab_icon(int p_tab) const; void set_tab_disabled(int p_tab, bool p_disabled); bool get_tab_disabled(int p_tab) const; - void set_tab_right_button(int p_tab, const Ref<Texture> &p_right_button); - Ref<Texture> get_tab_right_button(int p_tab) const; + void set_tab_right_button(int p_tab, const Ref<Texture2D> &p_right_button); + Ref<Texture2D> get_tab_right_button(int p_tab) const; void set_tab_align(TabAlign p_align); TabAlign get_tab_align() const; diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 93d0ae080b..5e925bf37f 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -753,10 +753,18 @@ void TextEdit::_notification(int p_what) { } } - if (line_length_guideline) { - int x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_col - cursor.x_ofs; - if (x > xmargin_beg && x < xmargin_end) { - VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(x, 0), Point2(x, size.height), cache.line_length_guideline_color); + if (line_length_guidelines) { + const int hard_x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_hard_col - cursor.x_ofs; + if (hard_x > xmargin_beg && hard_x < xmargin_end) { + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(hard_x, 0), Point2(hard_x, size.height), cache.line_length_guideline_color); + } + + // Draw a "Soft" line length guideline, less visible than the hard line length guideline. + // It's usually set to a lower column compared to the hard line length guideline. + // Only drawn if its column differs from the hard line length guideline. + const int soft_x = xmargin_beg + (int)cache.font->get_char_size('0').width * line_length_guideline_soft_col - cursor.x_ofs; + if (hard_x != soft_x && soft_x > xmargin_beg && soft_x < xmargin_end) { + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(soft_x, 0), Point2(soft_x, size.height), cache.line_length_guideline_color * Color(1, 1, 1, 0.5)); } } @@ -1216,7 +1224,7 @@ void TextEdit::_notification(int p_what) { int horizontal_gap = (cache.info_gutter_width * 30) / 100; int gutter_left = cache.style_normal->get_margin(MARGIN_LEFT) + cache.breakpoint_gutter_width; - Ref<Texture> info_icon = text.get_info_icon(line); + Ref<Texture2D> info_icon = text.get_info_icon(line); // Ensure the icon fits the gutter size. Size2i icon_size = info_icon->get_size(); if (icon_size.width > cache.info_gutter_width - horizontal_gap) { @@ -1645,7 +1653,7 @@ void TextEdit::_notification(int p_what) { Point2 title_pos(completion_rect.position.x, completion_rect.position.y + i * get_row_height() + cache.font->get_ascent() + yofs); // Draw completion icon if it is valid. - Ref<Texture> icon = completion_options[l].icon; + Ref<Texture2D> icon = completion_options[l].icon; Rect2 icon_area(completion_rect.position.x, completion_rect.position.y + i * get_row_height(), icon_area_size.width, icon_area_size.height); if (icon.is_valid()) { const real_t max_scale = 0.7f; @@ -1844,6 +1852,42 @@ void TextEdit::_consume_pair_symbol(CharType ch) { } } + String line = text[cursor.line]; + + bool in_single_quote = false; + bool in_double_quote = false; + + int c = 0; + while (c < line.length()) { + if (line[c] == '\\') { + c++; // Skip quoted anything. + + if (cursor.column == c) { + break; + } + } else { + if (line[c] == '\'' && !in_double_quote) { + in_single_quote = !in_single_quote; + } else if (line[c] == '"' && !in_single_quote) { + in_double_quote = !in_double_quote; + } + } + + c++; + + if (cursor.column == c) { + break; + } + } + + // Disallow inserting duplicated quotes while already in string + if ((in_single_quote || in_double_quote) && (ch == '"' || ch == '\'')) { + insert_text_at_cursor(ch_single); + cursor_set_column(cursor_position_to_move); + + return; + } + insert_text_at_cursor(ch_pair); cursor_set_column(cursor_position_to_move); } @@ -2520,9 +2564,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { k = k->duplicate(); // It will be modified later on. #ifdef OSX_ENABLED - if (k->get_scancode() == KEY_META) { + if (k->get_keycode() == KEY_META) { #else - if (k->get_scancode() == KEY_CONTROL) { + if (k->get_keycode() == KEY_CONTROL) { #endif if (select_identifiers_enabled) { @@ -2553,7 +2597,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (valid) { if (!k->get_alt()) { - if (k->get_scancode() == KEY_UP) { + if (k->get_keycode() == KEY_UP) { if (completion_index > 0) { completion_index--; @@ -2567,7 +2611,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - if (k->get_scancode() == KEY_DOWN) { + if (k->get_keycode() == KEY_DOWN) { if (completion_index < completion_options.size() - 1) { completion_index++; @@ -2581,7 +2625,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - if (k->get_scancode() == KEY_PAGEUP) { + if (k->get_keycode() == KEY_PAGEUP) { completion_index -= get_constant("completion_lines"); if (completion_index < 0) @@ -2592,7 +2636,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - if (k->get_scancode() == KEY_PAGEDOWN) { + if (k->get_keycode() == KEY_PAGEDOWN) { completion_index += get_constant("completion_lines"); if (completion_index >= completion_options.size()) @@ -2603,7 +2647,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - if (k->get_scancode() == KEY_HOME && completion_index > 0) { + if (k->get_keycode() == KEY_HOME && completion_index > 0) { completion_index = 0; completion_current = completion_options[completion_index]; @@ -2612,7 +2656,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - if (k->get_scancode() == KEY_END && completion_index < completion_options.size() - 1) { + if (k->get_keycode() == KEY_END && completion_index < completion_options.size() - 1) { completion_index = completion_options.size() - 1; completion_current = completion_options[completion_index]; @@ -2621,14 +2665,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - if (k->get_scancode() == KEY_KP_ENTER || k->get_scancode() == KEY_ENTER || k->get_scancode() == KEY_TAB) { + if (k->get_keycode() == KEY_KP_ENTER || k->get_keycode() == KEY_ENTER || k->get_keycode() == KEY_TAB) { _confirm_completion(); accept_event(); return; } - if (k->get_scancode() == KEY_BACKSPACE) { + if (k->get_keycode() == KEY_BACKSPACE) { _reset_caret_blink_timer(); @@ -2638,7 +2682,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { return; } - if (k->get_scancode() == KEY_SHIFT) { + if (k->get_keycode() == KEY_SHIFT) { accept_event(); return; } @@ -2682,20 +2726,20 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { /* TEST CONTROL FIRST! */ // Some remaps for duplicate functions. - if (k->get_command() && !k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_scancode() == KEY_INSERT) { + if (k->get_command() && !k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_keycode() == KEY_INSERT) { - k->set_scancode(KEY_C); + k->set_keycode(KEY_C); } - if (!k->get_command() && k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_scancode() == KEY_INSERT) { + if (!k->get_command() && k->get_shift() && !k->get_alt() && !k->get_metakey() && k->get_keycode() == KEY_INSERT) { - k->set_scancode(KEY_V); + k->set_keycode(KEY_V); k->set_command(true); k->set_shift(false); } #ifdef APPLE_STYLE_KEYS if (k->get_control() && !k->get_shift() && !k->get_alt() && !k->get_command()) { uint32_t remap_key = KEY_UNKNOWN; - switch (k->get_scancode()) { + switch (k->get_keycode()) { case KEY_F: { remap_key = KEY_RIGHT; } break; @@ -2717,7 +2761,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } if (remap_key != KEY_UNKNOWN) { - k->set_scancode(remap_key); + k->set_keycode(remap_key); k->set_control(false); } } @@ -2735,7 +2779,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { bool unselect = false; bool dobreak = false; - switch (k->get_scancode()) { + switch (k->get_keycode()) { case KEY_TAB: { if (k->get_shift()) { @@ -2809,11 +2853,11 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { selection.selecting_text = false; - bool scancode_handled = true; + bool keycode_handled = true; - // Special scancode test. + // Special keycode test. - switch (k->get_scancode()) { + switch (k->get_keycode()) { case KEY_KP_ENTER: case KEY_ENTER: { @@ -2935,7 +2979,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { completion_hint = ""; update(); } else { - scancode_handled = false; + keycode_handled = false; } } break; case KEY_TAB: { @@ -3008,7 +3052,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (k->get_alt() && cursor.column > 1) { #else if (k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } else if (k->get_command() && cursor.column > 1) { #endif @@ -3065,10 +3109,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } break; case KEY_KP_4: { if (k->get_unicode() != 0) { - scancode_handled = false; + keycode_handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_LEFT: { @@ -3101,7 +3145,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } else if (k->get_alt()) { #else if (k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } else if (k->get_command()) { #endif @@ -3141,10 +3185,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } break; case KEY_KP_6: { if (k->get_unicode() != 0) { - scancode_handled = false; + keycode_handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_RIGHT: { @@ -3163,7 +3207,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } else if (k->get_alt()) { #else if (k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } else if (k->get_command()) { #endif @@ -3202,15 +3246,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } break; case KEY_KP_8: { if (k->get_unicode() != 0) { - scancode_handled = false; + keycode_handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_UP: { if (k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } #ifndef APPLE_STYLE_KEYS @@ -3255,15 +3299,15 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } break; case KEY_KP_2: { if (k->get_unicode() != 0) { - scancode_handled = false; + keycode_handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_DOWN: { if (k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } #ifndef APPLE_STYLE_KEYS @@ -3323,7 +3367,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (k->get_alt() && cursor.column < curline_len - 1) { #else if (k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } else if (k->get_command() && cursor.column < curline_len - 1) { #endif @@ -3378,10 +3422,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } break; case KEY_KP_7: { if (k->get_unicode() != 0) { - scancode_handled = false; + keycode_handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_HOME: { #ifdef APPLE_STYLE_KEYS @@ -3439,10 +3483,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } break; case KEY_KP_1: { if (k->get_unicode() != 0) { - scancode_handled = false; + keycode_handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_END: { #ifdef APPLE_STYLE_KEYS @@ -3486,10 +3530,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } break; case KEY_KP_9: { if (k->get_unicode() != 0) { - scancode_handled = false; + keycode_handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_PAGEUP: { @@ -3509,10 +3553,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } break; case KEY_KP_3: { if (k->get_unicode() != 0) { - scancode_handled = false; + keycode_handled = false; break; } - FALLTHROUGH; + [[fallthrough]]; } case KEY_PAGEDOWN: { @@ -3534,7 +3578,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { #ifndef APPLE_STYLE_KEYS if (!k->get_control() || k->get_shift() || k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } if (is_shortcut_keys_enabled()) { @@ -3542,7 +3586,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } #else if ((!k->get_command() && !k->get_control())) { - scancode_handled = false; + keycode_handled = false; break; } if (!k->get_shift() && k->get_command() && is_shortcut_keys_enabled()) @@ -3573,7 +3617,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { case KEY_E: { if (!k->get_control() || k->get_command() || k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } @@ -3598,7 +3642,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { break; } if (!k->get_command() || k->get_shift() || k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } if (is_shortcut_keys_enabled()) { @@ -3609,7 +3653,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { case KEY_C: { if (!k->get_command() || k->get_shift() || k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } @@ -3625,7 +3669,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } if (!k->get_command()) { - scancode_handled = false; + keycode_handled = false; break; } @@ -3643,7 +3687,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } if (!k->get_command()) { - scancode_handled = false; + keycode_handled = false; break; } @@ -3656,7 +3700,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { break; } if (!k->get_command() || k->get_shift() || k->get_alt()) { - scancode_handled = false; + keycode_handled = false; break; } @@ -3673,9 +3717,9 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { #endif query_code_comple(); - scancode_handled = true; + keycode_handled = true; } else { - scancode_handled = false; + keycode_handled = false; } } break; @@ -3692,20 +3736,20 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { default: { - scancode_handled = false; + keycode_handled = false; } break; } - if (scancode_handled) + if (keycode_handled) accept_event(); - if (k->get_scancode() == KEY_INSERT) { + if (k->get_keycode() == KEY_INSERT) { set_insert_mode(!insert_mode); accept_event(); return; } - if (!scancode_handled && !k->get_command()) { // For German keyboards. + if (!keycode_handled && !k->get_command()) { // For German keyboards. if (k->get_unicode() >= 32) { @@ -5446,11 +5490,11 @@ int TextEdit::_get_column_pos_of_word(const String &p_key, const String &p_searc return col; } -PoolVector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const { +Vector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const { int col, line; if (search(p_key, p_search_flags, p_from_line, p_from_column, line, col)) { - PoolVector<int> result; + Vector<int> result; result.resize(2); result.set(SEARCH_RESULT_COLUMN, col); result.set(SEARCH_RESULT_LINE, line); @@ -5458,7 +5502,7 @@ PoolVector<int> TextEdit::_search_bind(const String &p_key, uint32_t p_search_fl } else { - return PoolVector<int>(); + return Vector<int>(); } } @@ -5690,7 +5734,7 @@ void TextEdit::remove_breakpoints() { } } -void TextEdit::set_line_info_icon(int p_line, Ref<Texture> p_icon, String p_info) { +void TextEdit::set_line_info_icon(int p_line, Ref<Texture2D> p_icon, String p_info) { ERR_FAIL_INDEX(p_line, text.size()); text.set_info_icon(p_line, p_icon, p_info); update(); @@ -6530,6 +6574,10 @@ void TextEdit::_update_completion_candidates() { Vector<float> sim_cache; bool single_quote = s.begins_with("'"); Vector<ScriptCodeCompletionOption> completion_options_casei; + Vector<ScriptCodeCompletionOption> completion_options_subseq; + Vector<ScriptCodeCompletionOption> completion_options_subseq_casei; + + String s_lower = s.to_lower(); for (List<ScriptCodeCompletionOption>::Element *E = completion_sources.front(); E; E = E->next()) { ScriptCodeCompletionOption &option = E->get(); @@ -6544,31 +6592,68 @@ void TextEdit::_update_completion_candidates() { option.insert_text = option.insert_text.quote(quote); } - if (option.display.begins_with(s)) { + if (option.display.length() == 0) { + continue; + } else if (s.length() == 0) { completion_options.push_back(option); - } else if (option.display.to_lower().begins_with(s.to_lower())) { - completion_options_casei.push_back(option); - } - } + } else { - completion_options.append_array(completion_options_casei); + // This code works the same as: + /* + if (option.display.begins_with(s)) { + completion_options.push_back(option); + } else if (option.display.to_lower().begins_with(s.to_lower())) { + completion_options_casei.push_back(option); + } else if (s.is_subsequence_of(option.display)) { + completion_options_subseq.push_back(option); + } else if (s.is_subsequence_ofi(option.display)) { + completion_options_subseq_casei.push_back(option); + } + */ + // But is more performant due to being inlined and looping over the characters only once - if (completion_options.size() == 0) { - for (int i = 0; i < completion_sources.size(); i++) { - if (s.is_subsequence_of(completion_sources[i].display)) { - completion_options.push_back(completion_sources[i]); + String display_lower = option.display.to_lower(); + + const CharType *ssq = &s[0]; + const CharType *ssq_lower = &s_lower[0]; + + const CharType *tgt = &option.display[0]; + const CharType *tgt_lower = &display_lower[0]; + + const CharType *ssq_last_tgt = NULL; + const CharType *ssq_lower_last_tgt = NULL; + + for (; *tgt; tgt++, tgt_lower++) { + if (*ssq == *tgt) { + ssq++; + ssq_last_tgt = tgt; + } + if (*ssq_lower == *tgt_lower) { + ssq_lower++; + ssq_lower_last_tgt = tgt; + } } - } - } - if (completion_options.size() == 0) { - for (int i = 0; i < completion_sources.size(); i++) { - if (s.is_subsequence_ofi(completion_sources[i].display)) { - completion_options.push_back(completion_sources[i]); + if (!*ssq) { // Matched the whole subsequence in s + if (ssq_last_tgt == &option.display[s.length() - 1]) { // Finished matching in the first s.length() characters + completion_options.push_back(option); + } else { + completion_options_subseq.push_back(option); + } + } else if (!*ssq_lower) { // Matched the whole subsequence in s_lower + if (ssq_lower_last_tgt == &option.display[s.length() - 1]) { // Finished matching in the first s.length() characters + completion_options_casei.push_back(option); + } else { + completion_options_subseq_casei.push_back(option); + } } } } + completion_options.append_array(completion_options_casei); + completion_options.append_array(completion_options_subseq); + completion_options.append_array(completion_options_subseq_casei); + if (completion_options.size() == 0) { // No options to complete, cancel. _cancel_completion(); @@ -6757,13 +6842,18 @@ bool TextEdit::is_show_line_numbers_enabled() const { return line_numbers; } -void TextEdit::set_show_line_length_guideline(bool p_show) { - line_length_guideline = p_show; +void TextEdit::set_show_line_length_guidelines(bool p_show) { + line_length_guidelines = p_show; + update(); +} + +void TextEdit::set_line_length_guideline_soft_column(int p_column) { + line_length_guideline_soft_col = p_column; update(); } -void TextEdit::set_line_length_guideline_column(int p_column) { - line_length_guideline_col = p_column; +void TextEdit::set_line_length_guideline_hard_column(int p_column) { + line_length_guideline_hard_col = p_column; update(); } @@ -6954,13 +7044,8 @@ PopupMenu *TextEdit::get_menu() const { void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("_gui_input"), &TextEdit::_gui_input); - ClassDB::bind_method(D_METHOD("_scroll_moved"), &TextEdit::_scroll_moved); ClassDB::bind_method(D_METHOD("_cursor_changed_emit"), &TextEdit::_cursor_changed_emit); ClassDB::bind_method(D_METHOD("_text_changed_emit"), &TextEdit::_text_changed_emit); - ClassDB::bind_method(D_METHOD("_push_current_op"), &TextEdit::_push_current_op); - ClassDB::bind_method(D_METHOD("_click_selection_held"), &TextEdit::_click_selection_held); - ClassDB::bind_method(D_METHOD("_toggle_draw_caret"), &TextEdit::_toggle_draw_caret); - ClassDB::bind_method(D_METHOD("_v_scroll_input"), &TextEdit::_v_scroll_input); ClassDB::bind_method(D_METHOD("_update_wrap_at"), &TextEdit::_update_wrap_at); BIND_ENUM_CONSTANT(SEARCH_MATCH_CASE); @@ -7106,10 +7191,10 @@ void TextEdit::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::BOOL, "shortcut_keys_enabled"), "set_shortcut_keys_enabled", "is_shortcut_keys_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selecting_enabled"), "set_selecting_enabled", "is_selecting_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "smooth_scrolling"), "set_smooth_scroll_enable", "is_smooth_scroll_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "v_scroll_speed"), "set_v_scroll_speed", "get_v_scroll_speed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "hiding_enabled"), "set_hiding_enabled", "is_hiding_enabled"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "wrap_enabled"), "set_wrap_enabled", "is_wrap_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "scroll_vertical"), "set_v_scroll", "get_v_scroll"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "scroll_vertical"), "set_v_scroll", "get_v_scroll"); ADD_PROPERTY(PropertyInfo(Variant::INT, "scroll_horizontal"), "set_h_scroll", "get_h_scroll"); ADD_GROUP("Minimap", "minimap_"); @@ -7119,7 +7204,7 @@ void TextEdit::_bind_methods() { ADD_GROUP("Caret", "caret_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_block_mode"), "cursor_set_block_mode", "cursor_is_block_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_blink"), "cursor_set_blink_enabled", "cursor_get_blink_enabled"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "cursor_set_blink_speed", "cursor_get_blink_speed"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "caret_blink_speed", PROPERTY_HINT_RANGE, "0.1,10,0.01"), "cursor_set_blink_speed", "cursor_get_blink_speed"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "caret_moving_by_right_click"), "set_right_click_moves_caret", "is_right_click_moving_caret"); ADD_SIGNAL(MethodInfo("cursor_changed")); @@ -7139,7 +7224,7 @@ void TextEdit::_bind_methods() { BIND_ENUM_CONSTANT(MENU_MAX); GLOBAL_DEF("gui/timers/text_edit_idle_detect_sec", 3); - ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/text_edit_idle_detect_sec", PropertyInfo(Variant::REAL, "gui/timers/text_edit_idle_detect_sec", PROPERTY_HINT_RANGE, "0,10,0.01,or_greater")); // No negative numbers. + ProjectSettings::get_singleton()->set_custom_property_info("gui/timers/text_edit_idle_detect_sec", PropertyInfo(Variant::FLOAT, "gui/timers/text_edit_idle_detect_sec", PROPERTY_HINT_RANGE, "0,10,0.01,or_greater")); // No negative numbers. } TextEdit::TextEdit() { @@ -7182,10 +7267,10 @@ TextEdit::TextEdit() { updating_scrolls = false; selection.active = false; - h_scroll->connect("value_changed", this, "_scroll_moved"); - v_scroll->connect("value_changed", this, "_scroll_moved"); + h_scroll->connect("value_changed", callable_mp(this, &TextEdit::_scroll_moved)); + v_scroll->connect("value_changed", callable_mp(this, &TextEdit::_scroll_moved)); - v_scroll->connect("scrolling", this, "_v_scroll_input"); + v_scroll->connect("scrolling", callable_mp(this, &TextEdit::_v_scroll_input)); cursor_changed_dirty = false; text_changed_dirty = false; @@ -7202,7 +7287,7 @@ TextEdit::TextEdit() { caret_blink_timer = memnew(Timer); add_child(caret_blink_timer); caret_blink_timer->set_wait_time(0.65); - caret_blink_timer->connect("timeout", this, "_toggle_draw_caret"); + caret_blink_timer->connect("timeout", callable_mp(this, &TextEdit::_toggle_draw_caret)); cursor_set_blink_enabled(false); right_click_moves_caret = true; @@ -7210,12 +7295,12 @@ TextEdit::TextEdit() { add_child(idle_detect); idle_detect->set_one_shot(true); idle_detect->set_wait_time(GLOBAL_GET("gui/timers/text_edit_idle_detect_sec")); - idle_detect->connect("timeout", this, "_push_current_op"); + idle_detect->connect("timeout", callable_mp(this, &TextEdit::_push_current_op)); click_select_held = memnew(Timer); add_child(click_select_held); click_select_held->set_wait_time(0.05); - click_select_held->connect("timeout", this, "_click_selection_held"); + click_select_held->connect("timeout", callable_mp(this, &TextEdit::_click_selection_held)); current_op.type = TextOperation::TYPE_NONE; undo_enabled = true; @@ -7232,8 +7317,9 @@ TextEdit::TextEdit() { tooltip_obj = NULL; line_numbers = false; line_numbers_zero_padded = false; - line_length_guideline = false; - line_length_guideline_col = 80; + line_length_guidelines = false; + line_length_guideline_soft_col = 80; + line_length_guideline_hard_col = 100; draw_bookmark_gutter = false; draw_breakpoint_gutter = false; draw_fold_gutter = false; @@ -7273,7 +7359,7 @@ TextEdit::TextEdit() { add_child(menu); readonly = true; // Initialise to opposite first, so we get past the early-out in set_readonly. set_readonly(false); - menu->connect("id_pressed", this, "menu_option"); + menu->connect("id_pressed", callable_mp(this, &TextEdit::menu_option)); first_draw = true; executing_line = -1; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index b4e7dcfebb..6e267f5a47 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -85,7 +85,7 @@ public: bool has_info : 1; int wrap_amount_cache : 24; Map<int, ColorRegionInfo> region_info; - Ref<Texture> info_icon; + Ref<Texture2D> info_icon; String info; String data; Line() { @@ -129,7 +129,7 @@ public: bool is_hidden(int p_line) const { return text[p_line].hidden; } void set_safe(int p_line, bool p_safe) { text.write[p_line].safe = p_safe; } bool is_safe(int p_line) const { return text[p_line].safe; } - void set_info_icon(int p_line, Ref<Texture> p_icon, String p_info) { + void set_info_icon(int p_line, Ref<Texture2D> p_icon, String p_info) { if (p_icon.is_null()) { text.write[p_line].has_info = false; return; @@ -139,7 +139,7 @@ public: text.write[p_line].has_info = true; } bool has_info_icon(int p_line) const { return text[p_line].has_info; } - const Ref<Texture> &get_info_icon(int p_line) const { return text[p_line].info_icon; } + const Ref<Texture2D> &get_info_icon(int p_line) const { return text[p_line].info_icon; } const String &get_info(int p_line) const { return text[p_line].info; } void insert(int p_at, const String &p_text); void remove(int p_at); @@ -208,12 +208,12 @@ private: struct Cache { - Ref<Texture> tab_icon; - Ref<Texture> space_icon; - Ref<Texture> can_fold_icon; - Ref<Texture> folded_icon; - Ref<Texture> folded_eol_icon; - Ref<Texture> executing_icon; + Ref<Texture2D> tab_icon; + Ref<Texture2D> space_icon; + Ref<Texture2D> can_fold_icon; + Ref<Texture2D> folded_icon; + Ref<Texture2D> folded_eol_icon; + Ref<Texture2D> executing_icon; Ref<StyleBox> style_normal; Ref<StyleBox> style_focus; Ref<StyleBox> style_readonly; @@ -369,8 +369,9 @@ private: bool undo_enabled; bool line_numbers; bool line_numbers_zero_padded; - bool line_length_guideline; - int line_length_guideline_col; + bool line_length_guidelines; + int line_length_guideline_soft_col; + int line_length_guideline_hard_col; bool draw_bookmark_gutter; bool draw_breakpoint_gutter; int breakpoint_gutter_width; @@ -513,7 +514,7 @@ private: int _get_column_pos_of_word(const String &p_key, const String &p_search, uint32_t p_search_flags, int p_from_column); - PoolVector<int> _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const; + Vector<int> _search_bind(const String &p_key, uint32_t p_search_flags, int p_from_line, int p_from_column) const; PopupMenu *menu; @@ -603,7 +604,7 @@ public: Array get_breakpoints_array() const; void remove_breakpoints(); - void set_line_info_icon(int p_line, Ref<Texture> p_icon, String p_info = ""); + void set_line_info_icon(int p_line, Ref<Texture2D> p_icon, String p_info = ""); void clear_info_icons(); void set_line_as_hidden(int p_line, bool p_hidden); @@ -765,8 +766,9 @@ public: void set_line_numbers_zero_padded(bool p_zero_padded); - void set_show_line_length_guideline(bool p_show); - void set_line_length_guideline_column(int p_column); + void set_show_line_length_guidelines(bool p_show); + void set_line_length_guideline_soft_column(int p_column); + void set_line_length_guideline_hard_column(int p_column); void set_bookmark_gutter_enabled(bool p_draw); bool is_bookmark_gutter_enabled() const; diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 9ffb69037a..5f2e4cf58e 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -122,7 +122,7 @@ void TextureButton::_notification(int p_what) { case NOTIFICATION_DRAW: { DrawMode draw_mode = get_draw_mode(); - Ref<Texture> texdraw; + Ref<Texture2D> texdraw; switch (draw_mode) { case DRAW_NORMAL: { @@ -252,11 +252,11 @@ void TextureButton::_bind_methods() { ClassDB::bind_method(D_METHOD("get_stretch_mode"), &TextureButton::get_stretch_mode); ADD_GROUP("Textures", "texture_"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_normal_texture", "get_normal_texture"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_pressed", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_pressed_texture", "get_pressed_texture"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_hover", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_hover_texture", "get_hover_texture"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_disabled", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_disabled_texture", "get_disabled_texture"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_focused", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_focused_texture", "get_focused_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_normal", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_normal_texture", "get_normal_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_pressed", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_pressed_texture", "get_pressed_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_hover", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_hover_texture", "get_hover_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_disabled", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_disabled_texture", "get_disabled_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_focused", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_focused_texture", "get_focused_texture"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_click_mask", PROPERTY_HINT_RESOURCE_TYPE, "BitMap"), "set_click_mask", "get_click_mask"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand", PROPERTY_HINT_RESOURCE_TYPE, "bool"), "set_expand", "get_expand"); ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode"); @@ -270,24 +270,24 @@ void TextureButton::_bind_methods() { BIND_ENUM_CONSTANT(STRETCH_KEEP_ASPECT_COVERED); } -void TextureButton::set_normal_texture(const Ref<Texture> &p_normal) { +void TextureButton::set_normal_texture(const Ref<Texture2D> &p_normal) { normal = p_normal; update(); minimum_size_changed(); } -void TextureButton::set_pressed_texture(const Ref<Texture> &p_pressed) { +void TextureButton::set_pressed_texture(const Ref<Texture2D> &p_pressed) { pressed = p_pressed; update(); } -void TextureButton::set_hover_texture(const Ref<Texture> &p_hover) { +void TextureButton::set_hover_texture(const Ref<Texture2D> &p_hover) { hover = p_hover; update(); } -void TextureButton::set_disabled_texture(const Ref<Texture> &p_disabled) { +void TextureButton::set_disabled_texture(const Ref<Texture2D> &p_disabled) { disabled = p_disabled; update(); @@ -298,19 +298,19 @@ void TextureButton::set_click_mask(const Ref<BitMap> &p_click_mask) { update(); } -Ref<Texture> TextureButton::get_normal_texture() const { +Ref<Texture2D> TextureButton::get_normal_texture() const { return normal; } -Ref<Texture> TextureButton::get_pressed_texture() const { +Ref<Texture2D> TextureButton::get_pressed_texture() const { return pressed; } -Ref<Texture> TextureButton::get_hover_texture() const { +Ref<Texture2D> TextureButton::get_hover_texture() const { return hover; } -Ref<Texture> TextureButton::get_disabled_texture() const { +Ref<Texture2D> TextureButton::get_disabled_texture() const { return disabled; } @@ -319,12 +319,12 @@ Ref<BitMap> TextureButton::get_click_mask() const { return click_mask; } -Ref<Texture> TextureButton::get_focused_texture() const { +Ref<Texture2D> TextureButton::get_focused_texture() const { return focused; }; -void TextureButton::set_focused_texture(const Ref<Texture> &p_focused) { +void TextureButton::set_focused_texture(const Ref<Texture2D> &p_focused) { focused = p_focused; }; diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h index e39b94abf0..43b10a8e8b 100644 --- a/scene/gui/texture_button.h +++ b/scene/gui/texture_button.h @@ -49,11 +49,11 @@ public: }; private: - Ref<Texture> normal; - Ref<Texture> pressed; - Ref<Texture> hover; - Ref<Texture> disabled; - Ref<Texture> focused; + Ref<Texture2D> normal; + Ref<Texture2D> pressed; + Ref<Texture2D> hover; + Ref<Texture2D> disabled; + Ref<Texture2D> focused; Ref<BitMap> click_mask; bool expand; StretchMode stretch_mode; @@ -69,18 +69,18 @@ protected: static void _bind_methods(); public: - void set_normal_texture(const Ref<Texture> &p_normal); - void set_pressed_texture(const Ref<Texture> &p_pressed); - void set_hover_texture(const Ref<Texture> &p_hover); - void set_disabled_texture(const Ref<Texture> &p_disabled); - void set_focused_texture(const Ref<Texture> &p_focused); + void set_normal_texture(const Ref<Texture2D> &p_normal); + void set_pressed_texture(const Ref<Texture2D> &p_pressed); + void set_hover_texture(const Ref<Texture2D> &p_hover); + void set_disabled_texture(const Ref<Texture2D> &p_disabled); + void set_focused_texture(const Ref<Texture2D> &p_focused); void set_click_mask(const Ref<BitMap> &p_click_mask); - Ref<Texture> get_normal_texture() const; - Ref<Texture> get_pressed_texture() const; - Ref<Texture> get_hover_texture() const; - Ref<Texture> get_disabled_texture() const; - Ref<Texture> get_focused_texture() const; + Ref<Texture2D> get_normal_texture() const; + Ref<Texture2D> get_pressed_texture() const; + Ref<Texture2D> get_hover_texture() const; + Ref<Texture2D> get_disabled_texture() const; + Ref<Texture2D> get_focused_texture() const; Ref<BitMap> get_click_mask() const; bool get_expand() const; diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index 2d30ff7334..abf6b2ed49 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -32,19 +32,19 @@ #include "core/engine.h" -void TextureProgress::set_under_texture(const Ref<Texture> &p_texture) { +void TextureProgress::set_under_texture(const Ref<Texture2D> &p_texture) { under = p_texture; update(); minimum_size_changed(); } -Ref<Texture> TextureProgress::get_under_texture() const { +Ref<Texture2D> TextureProgress::get_under_texture() const { return under; } -void TextureProgress::set_over_texture(const Ref<Texture> &p_texture) { +void TextureProgress::set_over_texture(const Ref<Texture2D> &p_texture) { over = p_texture; update(); @@ -53,7 +53,7 @@ void TextureProgress::set_over_texture(const Ref<Texture> &p_texture) { } } -Ref<Texture> TextureProgress::get_over_texture() const { +Ref<Texture2D> TextureProgress::get_over_texture() const { return over; } @@ -94,14 +94,14 @@ Size2 TextureProgress::get_minimum_size() const { return Size2(1, 1); } -void TextureProgress::set_progress_texture(const Ref<Texture> &p_texture) { +void TextureProgress::set_progress_texture(const Ref<Texture2D> &p_texture) { progress = p_texture; update(); minimum_size_changed(); } -Ref<Texture> TextureProgress::get_progress_texture() const { +Ref<Texture2D> TextureProgress::get_progress_texture() const { return progress; } @@ -201,7 +201,7 @@ Point2 TextureProgress::get_relative_center() { return p; } -void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, FillMode p_mode, double p_ratio, const Color &p_modulate) { +void TextureProgress::draw_nine_patch_stretched(const Ref<Texture2D> &p_texture, FillMode p_mode, double p_ratio, const Color &p_modulate) { Vector2 texture_size = p_texture->get_size(); Vector2 topleft = Vector2(stretch_margin[MARGIN_LEFT], stretch_margin[MARGIN_TOP]); Vector2 bottomright = Vector2(stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_BOTTOM]); @@ -501,17 +501,17 @@ void TextureProgress::_bind_methods() { ClassDB::bind_method(D_METHOD("get_nine_patch_stretch"), &TextureProgress::get_nine_patch_stretch); ADD_GROUP("Textures", "texture_"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_under", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_under_texture", "get_under_texture"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_over", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_over_texture", "get_over_texture"); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_progress", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_progress_texture", "get_progress_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_under", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_under_texture", "get_under_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_over", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_over_texture", "get_over_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_progress", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_progress_texture", "get_progress_texture"); ADD_PROPERTY(PropertyInfo(Variant::INT, "fill_mode", PROPERTY_HINT_ENUM, "Left to Right,Right to Left,Top to Bottom,Bottom to Top,Clockwise,Counter Clockwise,Bilinear (Left and Right),Bilinear (Top and Bottom), Clockwise and Counter Clockwise"), "set_fill_mode", "get_fill_mode"); ADD_GROUP("Tint", "tint_"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_under"), "set_tint_under", "get_tint_under"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_over"), "set_tint_over", "get_tint_over"); ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_progress"), "set_tint_progress", "get_tint_progress"); ADD_GROUP("Radial Fill", "radial_"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "radial_initial_angle", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_radial_initial_angle", "get_radial_initial_angle"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "radial_fill_degrees", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_fill_degrees", "get_fill_degrees"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radial_initial_angle", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_radial_initial_angle", "get_radial_initial_angle"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radial_fill_degrees", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_fill_degrees", "get_fill_degrees"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "radial_center_offset"), "set_radial_center_offset", "get_radial_center_offset"); ADD_GROUP("Stretch", "stretch_"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "nine_patch_stretch"), "set_nine_patch_stretch", "get_nine_patch_stretch"); diff --git a/scene/gui/texture_progress.h b/scene/gui/texture_progress.h index e4a40fd6a3..e05f89aa3e 100644 --- a/scene/gui/texture_progress.h +++ b/scene/gui/texture_progress.h @@ -37,9 +37,9 @@ class TextureProgress : public Range { GDCLASS(TextureProgress, Range); - Ref<Texture> under; - Ref<Texture> progress; - Ref<Texture> over; + Ref<Texture2D> under; + Ref<Texture2D> progress; + Ref<Texture2D> over; protected: static void _bind_methods(); @@ -70,14 +70,14 @@ public: void set_radial_center_offset(const Point2 &p_off); Point2 get_radial_center_offset(); - void set_under_texture(const Ref<Texture> &p_texture); - Ref<Texture> get_under_texture() const; + void set_under_texture(const Ref<Texture2D> &p_texture); + Ref<Texture2D> get_under_texture() const; - void set_progress_texture(const Ref<Texture> &p_texture); - Ref<Texture> get_progress_texture() const; + void set_progress_texture(const Ref<Texture2D> &p_texture); + Ref<Texture2D> get_progress_texture() const; - void set_over_texture(const Ref<Texture> &p_texture); - Ref<Texture> get_over_texture() const; + void set_over_texture(const Ref<Texture2D> &p_texture); + Ref<Texture2D> get_over_texture() const; void set_stretch_margin(Margin p_margin, int p_size); int get_stretch_margin(Margin p_margin) const; @@ -109,7 +109,7 @@ private: Point2 unit_val_to_uv(float val); Point2 get_relative_center(); - void draw_nine_patch_stretched(const Ref<Texture> &p_texture, FillMode p_mode, double p_ratio, const Color &p_modulate); + void draw_nine_patch_stretched(const Ref<Texture2D> &p_texture, FillMode p_mode, double p_ratio, const Color &p_modulate); }; VARIANT_ENUM_CAST(TextureProgress::FillMode); diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp index 514eff358e..6dafd3bf4f 100644 --- a/scene/gui/texture_rect.cpp +++ b/scene/gui/texture_rect.cpp @@ -127,9 +127,8 @@ void TextureRect::_bind_methods() { ClassDB::bind_method(D_METHOD("is_flipped_v"), &TextureRect::is_flipped_v); ClassDB::bind_method(D_METHOD("set_stretch_mode", "stretch_mode"), &TextureRect::set_stretch_mode); ClassDB::bind_method(D_METHOD("get_stretch_mode"), &TextureRect::get_stretch_mode); - ClassDB::bind_method(D_METHOD("_texture_changed"), &TextureRect::_texture_changed); - ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_texture", "get_texture"); + ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_texture", "get_texture"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand"), "set_expand", "has_expand"); ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_mode", PROPERTY_HINT_ENUM, "Scale On Expand (Compat),Scale,Tile,Keep,Keep Centered,Keep Aspect,Keep Aspect Centered,Keep Aspect Covered"), "set_stretch_mode", "get_stretch_mode"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "flip_h"), "set_flip_h", "is_flipped_h"); @@ -153,27 +152,27 @@ void TextureRect::_texture_changed() { } } -void TextureRect::set_texture(const Ref<Texture> &p_tex) { +void TextureRect::set_texture(const Ref<Texture2D> &p_tex) { if (p_tex == texture) { return; } if (texture.is_valid()) { - texture->disconnect(CoreStringNames::get_singleton()->changed, this, "_texture_changed"); + texture->disconnect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TextureRect::_texture_changed)); } texture = p_tex; if (texture.is_valid()) { - texture->connect(CoreStringNames::get_singleton()->changed, this, "_texture_changed"); + texture->connect(CoreStringNames::get_singleton()->changed, callable_mp(this, &TextureRect::_texture_changed)); } update(); minimum_size_changed(); } -Ref<Texture> TextureRect::get_texture() const { +Ref<Texture2D> TextureRect::get_texture() const { return texture; } diff --git a/scene/gui/texture_rect.h b/scene/gui/texture_rect.h index ef970fa051..77a2828fd4 100644 --- a/scene/gui/texture_rect.h +++ b/scene/gui/texture_rect.h @@ -53,7 +53,7 @@ private: bool expand; bool hflip; bool vflip; - Ref<Texture> texture; + Ref<Texture2D> texture; StretchMode stretch_mode; void _texture_changed(); @@ -64,8 +64,8 @@ protected: static void _bind_methods(); public: - void set_texture(const Ref<Texture> &p_tex); - Ref<Texture> get_texture() const; + void set_texture(const Ref<Texture2D> &p_tex); + Ref<Texture2D> get_texture() const; void set_expand(bool p_expand); bool has_expand() const; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 964f376dbd..12b3d56938 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -129,7 +129,7 @@ void TreeItem::set_cell_mode(int p_column, TreeCellMode p_mode) { c.step = 1; c.val = 0; c.checked = false; - c.icon = Ref<Texture>(); + c.icon = Ref<Texture2D>(); c.text = ""; c.icon_max_w = 0; _changed_notify(p_column); @@ -198,16 +198,16 @@ String TreeItem::get_suffix(int p_column) const { return cells[p_column].suffix; } -void TreeItem::set_icon(int p_column, const Ref<Texture> &p_icon) { +void TreeItem::set_icon(int p_column, const Ref<Texture2D> &p_icon) { ERR_FAIL_INDEX(p_column, cells.size()); cells.write[p_column].icon = p_icon; _changed_notify(p_column); } -Ref<Texture> TreeItem::get_icon(int p_column) const { +Ref<Texture2D> TreeItem::get_icon(int p_column) const { - ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<Texture>()); + ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<Texture2D>()); return cells[p_column].icon; } @@ -522,7 +522,7 @@ void TreeItem::deselect(int p_column) { _cell_deselected(p_column); } -void TreeItem::add_button(int p_column, const Ref<Texture> &p_button, int p_id, bool p_disabled, const String &p_tooltip) { +void TreeItem::add_button(int p_column, const Ref<Texture2D> &p_button, int p_id, bool p_disabled, const String &p_tooltip) { ERR_FAIL_INDEX(p_column, cells.size()); ERR_FAIL_COND(!p_button.is_valid()); @@ -542,9 +542,9 @@ int TreeItem::get_button_count(int p_column) const { ERR_FAIL_INDEX_V(p_column, cells.size(), -1); return cells[p_column].buttons.size(); } -Ref<Texture> TreeItem::get_button(int p_column, int p_idx) const { - ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<Texture>()); - ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), Ref<Texture>()); +Ref<Texture2D> TreeItem::get_button(int p_column, int p_idx) const { + ERR_FAIL_INDEX_V(p_column, cells.size(), Ref<Texture2D>()); + ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), Ref<Texture2D>()); return cells[p_column].buttons[p_idx].texture; } String TreeItem::get_button_tooltip(int p_column, int p_idx) const { @@ -577,7 +577,7 @@ int TreeItem::get_button_by_id(int p_column, int p_id) const { return -1; } -void TreeItem::set_button(int p_column, int p_idx, const Ref<Texture> &p_button) { +void TreeItem::set_button(int p_column, int p_idx, const Ref<Texture2D> &p_button) { ERR_FAIL_COND(p_button.is_null()); ERR_FAIL_INDEX(p_column, cells.size()); @@ -729,18 +729,18 @@ bool TreeItem::is_folding_disabled() const { return disable_folding; } -Variant TreeItem::_call_recursive_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error) { +Variant TreeItem::_call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 1) { - r_error.error = Variant::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; + r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; r_error.argument = 0; return Variant(); } - if (p_args[0]->get_type() != Variant::STRING) { - r_error.error = Variant::CallError::CALL_ERROR_INVALID_ARGUMENT; + if (p_args[0]->get_type() != Variant::STRING && p_args[0]->get_type() != Variant::STRING_NAME) { + r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT; r_error.argument = 0; - r_error.expected = Variant::STRING; + r_error.expected = Variant::STRING_NAME; return Variant(); } @@ -750,7 +750,7 @@ Variant TreeItem::_call_recursive_bind(const Variant **p_args, int p_argcount, V return Variant(); } -void recursive_call_aux(TreeItem *p_item, const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { +void recursive_call_aux(TreeItem *p_item, const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (!p_item) { return; } @@ -762,7 +762,7 @@ void recursive_call_aux(TreeItem *p_item, const StringName &p_method, const Vari } } -void TreeItem::call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error) { +void TreeItem::call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error) { recursive_call_aux(this, p_method, p_args, p_argcount, r_error); } @@ -861,7 +861,7 @@ void TreeItem::_bind_methods() { { MethodInfo mi; mi.name = "call_recursive"; - mi.arguments.push_back(PropertyInfo(Variant::STRING, "method")); + mi.arguments.push_back(PropertyInfo(Variant::STRING_NAME, "method")); ClassDB::bind_vararg_method(METHOD_FLAGS_DEFAULT, "call_recursive", &TreeItem::_call_recursive_bind, mi); } @@ -1020,13 +1020,13 @@ int Tree::compute_item_height(TreeItem *p_item) const { int check_icon_h = cache.checked->get_height(); if (height < check_icon_h) height = check_icon_h; - FALLTHROUGH; + [[fallthrough]]; } case TreeItem::CELL_MODE_STRING: case TreeItem::CELL_MODE_CUSTOM: case TreeItem::CELL_MODE_ICON: { - Ref<Texture> icon = p_item->cells[i].icon; + Ref<Texture2D> icon = p_item->cells[i].icon; if (!icon.is_null()) { Size2i s = p_item->cells[i].get_icon_size(); @@ -1121,7 +1121,7 @@ void Tree::draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, co } rect.position.y += Math::floor((rect.size.y - font->get_height()) / 2.0) + font->get_ascent(); - font->draw(ci, rect.position, text, p_color, rect.size.x); + font->draw(ci, rect.position, text, p_color, MAX(0, rect.size.width)); } int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item) { @@ -1190,7 +1190,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 int bw = 0; for (int j = p_item->cells[i].buttons.size() - 1; j >= 0; j--) { - Ref<Texture> b = p_item->cells[i].buttons[j].texture; + Ref<Texture2D> b = p_item->cells[i].buttons[j].texture; Size2 s = b->get_size() + cache.button_pressed->get_minimum_size(); if (s.height < label_h) s.height = label_h; @@ -1305,8 +1305,8 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } break; case TreeItem::CELL_MODE_CHECK: { - Ref<Texture> checked = cache.checked; - Ref<Texture> unchecked = cache.unchecked; + Ref<Texture2D> checked = cache.checked; + Ref<Texture2D> unchecked = cache.unchecked; Point2i check_ofs = item_rect.position; check_ofs.y += Math::floor((real_t)(item_rect.size.y - checked->get_height()) / 2); @@ -1350,7 +1350,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (p_item->cells[i].suffix != String()) s += " " + p_item->cells[i].suffix; - Ref<Texture> downarrow = cache.select_arrow; + Ref<Texture2D> downarrow = cache.select_arrow; font->draw(ci, text_pos, s, col, item_rect.size.x - downarrow->get_width()); @@ -1361,7 +1361,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 downarrow->draw(ci, arrow_pos); } else { - Ref<Texture> updown = cache.updown; + Ref<Texture2D> updown = cache.updown; String valtext = String::num(p_item->cells[i].val, Math::range_step_decimals(p_item->cells[i].step)); @@ -1399,7 +1399,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 } break; case TreeItem::CELL_MODE_CUSTOM: { - if (p_item->cells[i].custom_draw_obj) { + if (p_item->cells[i].custom_draw_obj.is_valid()) { Object *cdo = ObjectDB::get_instance(p_item->cells[i].custom_draw_obj); if (cdo) @@ -1412,7 +1412,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 break; } - Ref<Texture> downarrow = cache.select_arrow; + Ref<Texture2D> downarrow = cache.select_arrow; Rect2i ir = item_rect; @@ -1462,7 +1462,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 if (!p_item->disable_folding && !hide_folding && p_item->children) { //has children, draw the guide box - Ref<Texture> arrow; + Ref<Texture2D> arrow; if (p_item->collapsed) { @@ -1775,7 +1775,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool bool already_cursor = (p_item == selected_item) && col == selected_col; for (int j = c.buttons.size() - 1; j >= 0; j--) { - Ref<Texture> b = c.buttons[j].texture; + Ref<Texture2D> b = c.buttons[j].texture; int w = b->get_size().width + cache.button_pressed->get_minimum_size().width; if (x > col_width - w) { @@ -2439,7 +2439,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { return; } else { - if (k->get_scancode() != KEY_SHIFT) + if (k->get_keycode() != KEY_SHIFT) last_keypress = 0; } } @@ -3630,6 +3630,17 @@ TreeItem *Tree::search_item_text(const String &p_find, int *r_col, bool p_select return _search_item_text(from->get_next_visible(true), p_find, r_col, p_selectable); } +TreeItem *Tree::get_item_with_text(const String &p_find) const { + for (TreeItem *current = root; current; current = current->get_next_visible()) { + for (int i = 0; i < columns.size(); i++) { + if (current->get_text(i) == p_find) { + return current; + } + } + } + return NULL; +} + void Tree::_do_incr_search(const String &p_add) { uint64_t time = OS::get_singleton()->get_ticks_usec() / 1000; // convert to msec @@ -3814,7 +3825,7 @@ String Tree::get_tooltip(const Point2 &p_pos) const { pos.x -= get_column_width(i); for (int j = c.buttons.size() - 1; j >= 0; j--) { - Ref<Texture> b = c.buttons[j].texture; + Ref<Texture2D> b = c.buttons[j].texture; Size2 size = b->get_size() + cache.button_pressed->get_minimum_size(); if (pos.x > col_width - size.width) { String tooltip = c.buttons[j].tooltip; @@ -3903,13 +3914,7 @@ bool Tree::get_allow_reselect() const { void Tree::_bind_methods() { - ClassDB::bind_method(D_METHOD("_range_click_timeout"), &Tree::_range_click_timeout); ClassDB::bind_method(D_METHOD("_gui_input"), &Tree::_gui_input); - ClassDB::bind_method(D_METHOD("_popup_select"), &Tree::popup_select); - ClassDB::bind_method(D_METHOD("_text_editor_enter"), &Tree::text_editor_enter); - ClassDB::bind_method(D_METHOD("_text_editor_modal_close"), &Tree::_text_editor_modal_close); - ClassDB::bind_method(D_METHOD("_value_editor_changed"), &Tree::value_editor_changed); - ClassDB::bind_method(D_METHOD("_scroll_moved"), &Tree::_scroll_moved); ClassDB::bind_method(D_METHOD("clear"), &Tree::clear); ClassDB::bind_method(D_METHOD("create_item", "parent", "idx"), &Tree::_create_item, DEFVAL(Variant()), DEFVAL(-1)); @@ -4032,15 +4037,15 @@ Tree::Tree() { add_child(v_scroll); range_click_timer = memnew(Timer); - range_click_timer->connect("timeout", this, "_range_click_timeout"); + range_click_timer->connect("timeout", callable_mp(this, &Tree::_range_click_timeout)); add_child(range_click_timer); - h_scroll->connect("value_changed", this, "_scroll_moved"); - v_scroll->connect("value_changed", this, "_scroll_moved"); - text_editor->connect("text_entered", this, "_text_editor_enter"); - text_editor->connect("modal_closed", this, "_text_editor_modal_close"); - popup_menu->connect("id_pressed", this, "_popup_select"); - value_editor->connect("value_changed", this, "_value_editor_changed"); + h_scroll->connect("value_changed", callable_mp(this, &Tree::_scroll_moved)); + v_scroll->connect("value_changed", callable_mp(this, &Tree::_scroll_moved)); + text_editor->connect("text_entered", callable_mp(this, &Tree::text_editor_enter)); + text_editor->connect("modal_closed", callable_mp(this, &Tree::_text_editor_modal_close)); + popup_menu->connect("id_pressed", callable_mp(this, &Tree::popup_select)); + value_editor->connect("value_changed", callable_mp(this, &Tree::value_editor_changed)); value_editor->set_as_toplevel(true); text_editor->set_as_toplevel(true); diff --git a/scene/gui/tree.h b/scene/gui/tree.h index d87de6e773..b179c5bcba 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -66,7 +66,7 @@ private: TreeCellMode mode; - Ref<Texture> icon; + Ref<Texture2D> icon; Rect2i icon_region; String text; String suffix; @@ -97,7 +97,7 @@ private: struct Button { int id; bool disabled; - Ref<Texture> texture; + Ref<Texture2D> texture; Color color; String tooltip; Button() { @@ -112,7 +112,7 @@ private: Cell() { - custom_draw_obj = 0; + custom_draw_obj = ObjectID(); custom_button = false; mode = TreeItem::CELL_MODE_STRING; min = 0; @@ -172,7 +172,7 @@ protected: remove_child(Object::cast_to<TreeItem>(p_child)); } - Variant _call_recursive_bind(const Variant **p_args, int p_argcount, Variant::CallError &r_error); + Variant _call_recursive_bind(const Variant **p_args, int p_argcount, Callable::CallError &r_error); public: /* cell mode */ @@ -189,8 +189,8 @@ public: void set_suffix(int p_column, String p_suffix); String get_suffix(int p_column) const; - void set_icon(int p_column, const Ref<Texture> &p_icon); - Ref<Texture> get_icon(int p_column) const; + void set_icon(int p_column, const Ref<Texture2D> &p_icon); + Ref<Texture2D> get_icon(int p_column) const; void set_icon_region(int p_column, const Rect2 &p_icon_region); Rect2 get_icon_region(int p_column) const; @@ -201,14 +201,14 @@ public: void set_icon_max_width(int p_column, int p_max); int get_icon_max_width(int p_column) const; - void add_button(int p_column, const Ref<Texture> &p_button, int p_id = -1, bool p_disabled = false, const String &p_tooltip = ""); + void add_button(int p_column, const Ref<Texture2D> &p_button, int p_id = -1, bool p_disabled = false, const String &p_tooltip = ""); int get_button_count(int p_column) const; String get_button_tooltip(int p_column, int p_idx) const; - Ref<Texture> get_button(int p_column, int p_idx) const; + Ref<Texture2D> get_button(int p_column, int p_idx) const; int get_button_id(int p_column, int p_idx) const; void erase_button(int p_column, int p_idx); int get_button_by_id(int p_column, int p_id) const; - void set_button(int p_column, int p_idx, const Ref<Texture> &p_button); + void set_button(int p_column, int p_idx, const Ref<Texture2D> &p_button); void set_button_color(int p_column, int p_idx, const Color &p_color); void set_button_disabled(int p_column, int p_idx, bool p_disabled); bool is_button_disabled(int p_column, int p_idx) const; @@ -282,7 +282,7 @@ public: void set_disable_folding(bool p_disable); bool is_folding_disabled() const; - void call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Variant::CallError &r_error); + void call_recursive(const StringName &p_method, const Variant **p_args, int p_argcount, Callable::CallError &r_error); ~TreeItem(); }; @@ -374,7 +374,7 @@ private: int compute_item_height(TreeItem *p_item) const; int get_item_height(TreeItem *p_item) const; - //void draw_item_text(String p_text,const Ref<Texture>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color); + //void draw_item_text(String p_text,const Ref<Texture2D>& p_icon,int p_icon_max_w,bool p_tool,Rect2i p_rect,const Color& p_color); void draw_item_rect(const TreeItem::Cell &p_cell, const Rect2i &p_rect, const Color &p_color, const Color &p_icon_color); int draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 &p_draw_size, TreeItem *p_item); void select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_col, TreeItem *p_prev = NULL, bool *r_in_range = NULL, bool p_force_deselect = false); @@ -416,12 +416,12 @@ private: Color title_button_color; - Ref<Texture> checked; - Ref<Texture> unchecked; - Ref<Texture> arrow_collapsed; - Ref<Texture> arrow; - Ref<Texture> select_arrow; - Ref<Texture> updown; + Ref<Texture2D> checked; + Ref<Texture2D> unchecked; + Ref<Texture2D> arrow_collapsed; + Ref<Texture2D> arrow; + Ref<Texture2D> select_arrow; + Ref<Texture2D> updown; Color font_color; Color font_color_selected; @@ -577,7 +577,10 @@ public: Rect2 get_item_rect(TreeItem *p_item, int p_column = -1) const; bool edit_selected(); + // First item that starts with the text, from the current focused item down and wraps around. TreeItem *search_item_text(const String &p_find, int *r_col = NULL, bool p_selectable = false); + // First item that matches the whole text, from the first item down. + TreeItem *get_item_with_text(const String &p_find) const; Point2 get_scroll() const; void scroll_to_item(TreeItem *p_item); diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index 0a693d4023..ac1e4a5629 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -375,12 +375,12 @@ void VideoPlayer::set_stream_position(float p_position) { playback->seek(p_position); } -Ref<Texture> VideoPlayer::get_video_texture() const { +Ref<Texture2D> VideoPlayer::get_video_texture() const { if (playback.is_valid()) return playback->get_texture(); - return Ref<Texture>(); + return Ref<Texture2D>(); } void VideoPlayer::set_autoplay(bool p_enable) { @@ -473,15 +473,15 @@ void VideoPlayer::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::INT, "audio_track", PROPERTY_HINT_RANGE, "0,128,1"), "set_audio_track", "get_audio_track"); ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "VideoStream"), "set_stream", "get_stream"); //ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/loop"), "set_loop", "has_loop") ; - ADD_PROPERTY(PropertyInfo(Variant::REAL, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_volume_db", "get_volume_db"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "volume", PROPERTY_HINT_EXP_RANGE, "0,15,0.01", 0), "set_volume", "get_volume"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_volume_db", "get_volume_db"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume", PROPERTY_HINT_EXP_RANGE, "0,15,0.01", 0), "set_volume", "get_volume"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "has_autoplay"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_paused", "is_paused"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "expand"), "set_expand", "has_expand"); ADD_PROPERTY(PropertyInfo(Variant::INT, "buffering_msec", PROPERTY_HINT_RANGE, "10,1000"), "set_buffering_msec", "get_buffering_msec"); - ADD_PROPERTY(PropertyInfo(Variant::REAL, "stream_position", PROPERTY_HINT_RANGE, "0,1280000,0.1", 0), "set_stream_position", "get_stream_position"); + ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "stream_position", PROPERTY_HINT_RANGE, "0,1280000,0.1", 0), "set_stream_position", "get_stream_position"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus"); + ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "bus", PROPERTY_HINT_ENUM, ""), "set_bus", "get_bus"); } VideoPlayer::VideoPlayer() { diff --git a/scene/gui/video_player.h b/scene/gui/video_player.h index e740e3e4ed..78e7fa05f8 100644 --- a/scene/gui/video_player.h +++ b/scene/gui/video_player.h @@ -86,7 +86,7 @@ public: void set_expand(bool p_expand); bool has_expand() const; - Ref<Texture> get_video_texture() const; + Ref<Texture2D> get_video_texture() const; void set_stream(const Ref<VideoStream> &p_stream); Ref<VideoStream> get_stream() const; diff --git a/scene/gui/viewport_container.cpp b/scene/gui/viewport_container.cpp index 4565b4b538..a76f2924d3 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/viewport_container.cpp @@ -135,9 +135,9 @@ void ViewportContainer::_notification(int p_what) { continue; if (stretch) - draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size() * Size2(1, -1))); + draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size())); else - draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size() * Size2(1, -1))); + draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size())); } } } |