diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/control.cpp | 4 | ||||
-rw-r--r-- | scene/gui/dialogs.cpp | 1 | ||||
-rw-r--r-- | scene/gui/file_dialog.cpp | 66 | ||||
-rw-r--r-- | scene/gui/file_dialog.h | 22 | ||||
-rw-r--r-- | scene/gui/rich_text_label.cpp | 10 | ||||
-rw-r--r-- | scene/gui/subviewport_container.cpp (renamed from scene/gui/viewport_container.cpp) | 36 | ||||
-rw-r--r-- | scene/gui/subviewport_container.h (renamed from scene/gui/viewport_container.h) | 8 | ||||
-rw-r--r-- | scene/gui/tabs.cpp | 30 | ||||
-rw-r--r-- | scene/gui/texture_rect.cpp | 9 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 7 |
10 files changed, 62 insertions, 131 deletions
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 775f863a4f..b4dc37c74f 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -1893,7 +1893,7 @@ static Control *_next_control(Control *p_from) { return nullptr; } - int next = p_from->get_position_in_parent(); + int next = p_from->get_index(); ERR_FAIL_INDEX_V(next, parent->get_child_count(), nullptr); for (int i = (next + 1); i < parent->get_child_count(); i++) { @@ -2032,7 +2032,7 @@ Control *Control::find_prev_valid_focus() const { } else { - for (int i = (from->get_position_in_parent() - 1); i >= 0; i--) { + for (int i = (from->get_index() - 1); i >= 0; i--) { Control *c = Object::cast_to<Control>(from->get_parent()->get_child(i)); diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 2e87a92969..5654219a3e 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -322,7 +322,6 @@ AcceptDialog::AcceptDialog() { label->set_end(Point2(-margin, -button_margin - 10)); add_child(label); - hbc = memnew(HBoxContainer); add_child(hbc); hbc->add_spacer(); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 6be74d8d29..89d13ecd7f 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -46,9 +46,9 @@ VBoxContainer *FileDialog::get_vbox() { void FileDialog::_theme_changed() { - Color font_color = vbc->get_theme_color("font_color", "ToolButton"); - Color font_color_hover = vbc->get_theme_color("font_color_hover", "ToolButton"); - Color font_color_pressed = vbc->get_theme_color("font_color_pressed", "ToolButton"); + Color font_color = vbox->get_theme_color("font_color", "ToolButton"); + Color font_color_hover = vbox->get_theme_color("font_color_hover", "ToolButton"); + Color font_color_pressed = vbox->get_theme_color("font_color_pressed", "ToolButton"); dir_up->add_theme_color_override("icon_color_normal", font_color); dir_up->add_theme_color_override("icon_color_hover", font_color_hover); @@ -73,9 +73,9 @@ void FileDialog::_notification(int p_what) { } if (p_what == NOTIFICATION_ENTER_TREE) { - dir_up->set_icon(vbc->get_theme_icon("parent_folder")); - refresh->set_icon(vbc->get_theme_icon("reload")); - show_hidden->set_icon(vbc->get_theme_icon("toggle_hidden")); + dir_up->set_icon(vbox->get_theme_icon("parent_folder", "FileDialog")); + refresh->set_icon(vbox->get_theme_icon("reload", "FileDialog")); + show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden", "FileDialog")); _theme_changed(); } } @@ -429,8 +429,8 @@ void FileDialog::update_file_list() { dir_access->list_dir_begin(); TreeItem *root = tree->create_item(); - Ref<Texture2D> folder = vbc->get_theme_icon("folder"); - const Color folder_color = vbc->get_theme_color("folder_icon_modulate"); + Ref<Texture2D> folder = vbox->get_theme_icon("folder", "FileDialog"); + const Color folder_color = vbox->get_theme_color("folder_icon_modulate", "FileDialog"); List<String> files; List<String> dirs; @@ -528,7 +528,7 @@ void FileDialog::update_file_list() { } if (mode == FILE_MODE_OPEN_DIR) { - ti->set_custom_color(0, vbc->get_theme_color("files_disabled")); + ti->set_custom_color(0, vbox->get_theme_color("files_disabled", "FileDialog")); ti->set_selectable(0, false); } Dictionary d; @@ -888,9 +888,9 @@ FileDialog::FileDialog() { mode_overrides_title = true; - vbc = memnew(VBoxContainer); - add_child(vbc); - vbc->connect("theme_changed", callable_mp(this, &FileDialog::_theme_changed)); + vbox = memnew(VBoxContainer); + add_child(vbox); + vbox->connect("theme_changed", callable_mp(this, &FileDialog::_theme_changed)); mode = FILE_MODE_SAVE_FILE; set_title(RTR("Save a File")); @@ -909,6 +909,7 @@ FileDialog::FileDialog() { drives = memnew(OptionButton); drives->connect("item_selected", callable_mp(this, &FileDialog::_select_drive)); + hbc->add_child(drives); dir = memnew(LineEdit); hbc->add_child(dir); @@ -933,11 +934,11 @@ FileDialog::FileDialog() { makedir->set_text(RTR("Create Folder")); makedir->connect("pressed", callable_mp(this, &FileDialog::_make_dir)); hbc->add_child(makedir); - vbc->add_child(hbc); + vbox->add_child(hbc); tree = memnew(Tree); tree->set_hide_root(true); - vbc->add_margin_child(RTR("Directories & Files:"), tree, true); + vbox->add_margin_child(RTR("Directories & Files:"), tree, true); file_box = memnew(HBoxContainer); file_box->add_child(memnew(Label(RTR("File:")))); @@ -950,7 +951,7 @@ FileDialog::FileDialog() { filter->set_h_size_flags(Control::SIZE_EXPAND_FILL); filter->set_clip_text(true); // too many extensions overflows it file_box->add_child(filter); - vbc->add_child(file_box); + vbox->add_child(file_box); dir_access = DirAccess::create(DirAccess::ACCESS_RESOURCES); access = ACCESS_RESOURCES; @@ -993,7 +994,6 @@ FileDialog::FileDialog() { update_dir(); set_hide_on_ok(false); - vbox = vbc; invalidated = true; if (register_func) @@ -1006,37 +1006,3 @@ FileDialog::~FileDialog() { unregister_func(this); memdelete(dir_access); } - -void LineEditFileChooser::_bind_methods() { - - 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); -} - -void LineEditFileChooser::_chosen(const String &p_text) { - - line_edit->set_text(p_text); - line_edit->emit_signal("text_entered", p_text); -} - -void LineEditFileChooser::_browse() { - - dialog->popup_centered_ratio(); -} - -LineEditFileChooser::LineEditFileChooser() { - - line_edit = memnew(LineEdit); - add_child(line_edit); - line_edit->set_h_size_flags(Control::SIZE_EXPAND_FILL); - button = memnew(Button); - button->set_text(" .. "); - add_child(button); - button->connect("pressed", callable_mp(this, &LineEditFileChooser::_browse)); - dialog = memnew(FileDialog); - add_child(dialog); - 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 295ae023d1..ac0e733abc 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -70,7 +70,6 @@ private: ConfirmationDialog *makedialog; LineEdit *makedirname; - VBoxContainer *vbc; Button *makedir; Access access; //Button *action; @@ -178,27 +177,6 @@ public: ~FileDialog(); }; -class LineEditFileChooser : public HBoxContainer { - - GDCLASS(LineEditFileChooser, HBoxContainer); - Button *button; - LineEdit *line_edit; - FileDialog *dialog; - - void _chosen(const String &p_text); - void _browse(); - -protected: - static void _bind_methods(); - -public: - Button *get_button() { return button; } - LineEdit *get_line_edit() { return line_edit; } - FileDialog *get_file_dialog() { return dialog; } - - LineEditFileChooser(); -}; - VARIANT_ENUM_CAST(FileDialog::FileMode); VARIANT_ENUM_CAST(FileDialog::Access); diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index 5fb2243aff..0b314d57c5 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -411,7 +411,6 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & break; //don't allow lines longer than assigned width } - w += cw; fw += cw; end++; @@ -552,8 +551,10 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } } - if (visible) + if (visible) { line_is_blank = false; + w += font->get_char_size(c[i], c[i + 1]).x; + } if (c[i] == '\t') visible = false; @@ -582,13 +583,14 @@ 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) { + } else if (previously_visible && c[i] != '\t') { backtrack += font->get_char_size(fx_char, c[i + 1]).x; } p_char_count++; if (c[i] == '\t') { cw = tab_size * font->get_char_size(' ').width; + backtrack = MAX(0, backtrack - cw); } ofs += cw; @@ -607,7 +609,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & } else if (strikethrough) { Color uc = color; uc.a *= 0.5; - int uy = y + lh / 2 - line_descent + 2; + int uy = y + lh - (line_ascent + line_descent) / 2; float strikethrough_width = 1.0; #ifdef TOOLS_ENABLED strikethrough_width *= EDSCALE; diff --git a/scene/gui/viewport_container.cpp b/scene/gui/subviewport_container.cpp index 7ce1d9e551..50f468741d 100644 --- a/scene/gui/viewport_container.cpp +++ b/scene/gui/subviewport_container.cpp @@ -1,5 +1,5 @@ /*************************************************************************/ -/* viewport_container.cpp */ +/* subviewport_container.cpp */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -28,12 +28,12 @@ /* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ /*************************************************************************/ -#include "viewport_container.h" +#include "subviewport_container.h" #include "core/engine.h" #include "scene/main/viewport.h" -Size2 ViewportContainer::get_minimum_size() const { +Size2 SubViewportContainer::get_minimum_size() const { if (stretch) return Size2(); @@ -52,19 +52,19 @@ Size2 ViewportContainer::get_minimum_size() const { return ms; } -void ViewportContainer::set_stretch(bool p_enable) { +void SubViewportContainer::set_stretch(bool p_enable) { stretch = p_enable; queue_sort(); update(); } -bool ViewportContainer::is_stretch_enabled() const { +bool SubViewportContainer::is_stretch_enabled() const { return stretch; } -void ViewportContainer::set_stretch_shrink(int p_shrink) { +void SubViewportContainer::set_stretch_shrink(int p_shrink) { ERR_FAIL_COND(p_shrink < 1); if (shrink == p_shrink) @@ -87,12 +87,12 @@ void ViewportContainer::set_stretch_shrink(int p_shrink) { update(); } -int ViewportContainer::get_stretch_shrink() const { +int SubViewportContainer::get_stretch_shrink() const { return shrink; } -void ViewportContainer::_notification(int p_what) { +void SubViewportContainer::_notification(int p_what) { if (p_what == NOTIFICATION_RESIZED) { @@ -142,7 +142,7 @@ void ViewportContainer::_notification(int p_what) { } } -void ViewportContainer::_input(const Ref<InputEvent> &p_event) { +void SubViewportContainer::_input(const Ref<InputEvent> &p_event) { if (Engine::get_singleton()->is_editor_hint()) return; @@ -167,7 +167,7 @@ void ViewportContainer::_input(const Ref<InputEvent> &p_event) { } } -void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) { +void SubViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) { if (Engine::get_singleton()->is_editor_hint()) return; @@ -192,21 +192,21 @@ void ViewportContainer::_unhandled_input(const Ref<InputEvent> &p_event) { } } -void ViewportContainer::_bind_methods() { +void SubViewportContainer::_bind_methods() { - ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &ViewportContainer::_unhandled_input); - ClassDB::bind_method(D_METHOD("_input", "event"), &ViewportContainer::_input); - ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &ViewportContainer::set_stretch); - ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &ViewportContainer::is_stretch_enabled); + ClassDB::bind_method(D_METHOD("_unhandled_input", "event"), &SubViewportContainer::_unhandled_input); + ClassDB::bind_method(D_METHOD("_input", "event"), &SubViewportContainer::_input); + ClassDB::bind_method(D_METHOD("set_stretch", "enable"), &SubViewportContainer::set_stretch); + ClassDB::bind_method(D_METHOD("is_stretch_enabled"), &SubViewportContainer::is_stretch_enabled); - ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &ViewportContainer::set_stretch_shrink); - ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &ViewportContainer::get_stretch_shrink); + ClassDB::bind_method(D_METHOD("set_stretch_shrink", "amount"), &SubViewportContainer::set_stretch_shrink); + ClassDB::bind_method(D_METHOD("get_stretch_shrink"), &SubViewportContainer::get_stretch_shrink); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "stretch"), "set_stretch", "is_stretch_enabled"); ADD_PROPERTY(PropertyInfo(Variant::INT, "stretch_shrink"), "set_stretch_shrink", "get_stretch_shrink"); } -ViewportContainer::ViewportContainer() { +SubViewportContainer::SubViewportContainer() { stretch = false; shrink = 1; diff --git a/scene/gui/viewport_container.h b/scene/gui/subviewport_container.h index 8597444426..6ff3d188e2 100644 --- a/scene/gui/viewport_container.h +++ b/scene/gui/subviewport_container.h @@ -1,5 +1,5 @@ /*************************************************************************/ -/* viewport_container.h */ +/* subviewport_container.h */ /*************************************************************************/ /* This file is part of: */ /* GODOT ENGINE */ @@ -33,9 +33,9 @@ #include "scene/gui/container.h" -class ViewportContainer : public Container { +class SubViewportContainer : public Container { - GDCLASS(ViewportContainer, Container); + GDCLASS(SubViewportContainer, Container); bool stretch; int shrink; @@ -55,7 +55,7 @@ public: virtual Size2 get_minimum_size() const; - ViewportContainer(); + SubViewportContainer(); }; #endif // VIEWPORTCONTAINER_H diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index ea6d44e3a7..1a3b53f489 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -184,10 +184,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { } int found = -1; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { if (tabs[i].rb_rect.has_point(pos)) { rb_pressing = true; @@ -276,10 +273,7 @@ void Tabs::_notification(int p_what) { missing_right = false; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { tabs.write[i].ofs_cache = w; @@ -499,10 +493,7 @@ void Tabs::_update_hover() { // test hovering to display right or close button int hover_now = -1; int hover_buttons = -1; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { Rect2 rect = get_tab_rect(i); if (rect.has_point(pos)) { @@ -559,9 +550,8 @@ void Tabs::_update_cache() { if (count_resize > 0) { m_width = MAX((limit - size_fixed) / count_resize, min_width); } - for (int i = 0; i < tabs.size(); i++) { - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { + Ref<StyleBox> sb; if (tabs[i].disabled) { sb = tab_disabled; @@ -753,10 +743,7 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) { int Tabs::get_tab_idx_at_point(const Point2 &p_point) const { int hover_now = -1; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset) - continue; + for (int i = offset; i < tabs.size(); i++) { Rect2 rect = get_tab_rect(i); if (rect.has_point(p_point)) { @@ -850,10 +837,7 @@ void Tabs::_ensure_no_over_offset() { while (offset > 0) { int total_w = 0; - for (int i = 0; i < tabs.size(); i++) { - - if (i < offset - 1) - continue; + for (int i = offset - 1; i < tabs.size(); i++) { total_w += tabs[i].size_cache; } diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp index baa138847f..92f3c5b5d9 100644 --- a/scene/gui/texture_rect.cpp +++ b/scene/gui/texture_rect.cpp @@ -95,6 +95,15 @@ void TextureRect::_notification(int p_what) { } break; } + Ref<AtlasTexture> p_atlas = texture; + + if (p_atlas.is_valid() && region.has_no_area()) { + Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height()); + + offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0; + offset.height += vflip ? p_atlas->get_margin().get_position().height * scale_size.height * 2 : 0; + } + size.width *= hflip ? -1.0f : 1.0f; size.height *= vflip ? -1.0f : 1.0f; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index a7acaae8df..509a52d36a 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -3045,13 +3045,6 @@ void Tree::_notification(int p_what) { draw_item(Point2(), draw_ofs, draw_size, root); } - int ofs = 0; - - for (int i = 0; i < (columns.size() - 1 - 1); i++) { - - ofs += get_column_width(i); - } - if (show_column_titles) { //title buttons |