diff options
Diffstat (limited to 'scene/gui')
30 files changed, 169 insertions, 117 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index e400801b66..e86ad09aa6 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -30,7 +30,7 @@ #include "button.h" -#include "core/translation.h" +#include "core/string/translation.h" #include "servers/rendering_server.h" Size2 Button::get_minimum_size() const { diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index 1ddc730dd1..790faeb4fd 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -30,7 +30,7 @@ #include "check_button.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #include "servers/rendering_server.h" Size2 CheckButton::get_icon_size() const { diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index 1eb45d7fc6..f6f52fbf55 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -341,7 +341,10 @@ void CodeEdit::_gutter_clicked(int p_line, int p_gutter) { } if (p_gutter == line_number_gutter) { - cursor_set_line(p_line); + set_selection_mode(TextEdit::SelectionMode::SELECTION_MODE_LINE, p_line, 0); + select(p_line, 0, p_line + 1, 0); + cursor_set_line(p_line + 1); + cursor_set_column(0); return; } diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index 470a7db2dc..5643110b89 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "container.h" -#include "core/message_queue.h" +#include "core/object/message_queue.h" #include "scene/scene_string_names.h" void Container::_child_minsize_changed() { diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index 476dccab7e..3414b04978 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -30,12 +30,12 @@ #include "control.h" +#include "core/config/project_settings.h" #include "core/math/geometry_2d.h" -#include "core/message_queue.h" +#include "core/object/message_queue.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/print_string.h" -#include "core/project_settings.h" +#include "core/string/print_string.h" #include "scene/gui/label.h" #include "scene/gui/panel.h" #include "scene/main/canvas_layer.h" @@ -2738,7 +2738,9 @@ void Control::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::BOOL, "can_drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data"))); BIND_VMETHOD(MethodInfo("drop_data", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::NIL, "data"))); - BIND_VMETHOD(MethodInfo(Variant::OBJECT, "_make_custom_tooltip", PropertyInfo(Variant::STRING, "for_text"))); + BIND_VMETHOD(MethodInfo( + PropertyInfo(Variant::OBJECT, "control", PROPERTY_HINT_RESOURCE_TYPE, "Control"), + "_make_custom_tooltip", PropertyInfo(Variant::STRING, "for_text"))); BIND_VMETHOD(MethodInfo(Variant::BOOL, "_clips_input")); ADD_GROUP("Anchor", "anchor_"); diff --git a/scene/gui/control.h b/scene/gui/control.h index 83e79f908f..f2f558cf4f 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -32,7 +32,7 @@ #define CONTROL_H #include "core/math/transform_2d.h" -#include "core/rid.h" +#include "core/templates/rid.h" #include "scene/gui/shortcut.h" #include "scene/main/canvas_item.h" #include "scene/main/node.h" diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 430e98d50e..4f59f4a36a 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -31,8 +31,8 @@ #include "dialogs.h" #include "core/os/keyboard.h" -#include "core/print_string.h" -#include "core/translation.h" +#include "core/string/print_string.h" +#include "core/string/translation.h" #include "line_edit.h" #ifdef TOOLS_ENABLED diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 2da61bdde7..7ce4e90f28 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -31,7 +31,7 @@ #include "file_dialog.h" #include "core/os/keyboard.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #include "scene/gui/label.h" FileDialog::GetIconFunc FileDialog::get_icon_func = nullptr; diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index ecd4ad17ea..53d7ead548 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -357,7 +357,7 @@ void GradientEdit::_notification(int p_what) { //Draw point markers for (int i = 0; i < points.size(); i++) { - Color col = points[i].color.contrasted(); + Color col = points[i].color.inverted(); col.a = 0.9; draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col); diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 54150d130d..6708b18e0a 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -29,8 +29,8 @@ /*************************************************************************/ #include "item_list.h" +#include "core/config/project_settings.h" #include "core/os/os.h" -#include "core/project_settings.h" void ItemList::add_item(const String &p_item, const Ref<Texture2D> &p_texture, bool p_selectable) { Item item; diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 9e3418a5c9..9df63a3c71 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -30,9 +30,9 @@ #include "label.h" -#include "core/print_string.h" -#include "core/project_settings.h" -#include "core/translation.h" +#include "core/config/project_settings.h" +#include "core/string/print_string.h" +#include "core/string/translation.h" void Label::set_autowrap(bool p_autowrap) { if (autowrap == p_autowrap) { diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index ca0d25263c..649f5a5f66 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -30,11 +30,11 @@ #include "line_edit.h" -#include "core/message_queue.h" +#include "core/object/message_queue.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/print_string.h" -#include "core/translation.h" +#include "core/string/print_string.h" +#include "core/string/translation.h" #include "label.h" #include "servers/display_server.h" #ifdef TOOLS_ENABLED diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 5780cc5e71..f0e69a94a4 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -30,7 +30,7 @@ #include "option_button.h" -#include "core/print_string.h" +#include "core/string/print_string.h" Size2 OptionButton::get_minimum_size() const { Size2 minsize = Button::get_minimum_size(); diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index d8d9beca2b..acbb6d7ab5 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -30,7 +30,7 @@ #include "panel.h" -#include "core/print_string.h" +#include "core/string/print_string.h" void Panel::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index de866fa956..49ddd5c3ee 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -30,7 +30,7 @@ #include "popup.h" -#include "core/engine.h" +#include "core/config/engine.h" #include "core/os/keyboard.h" #include "scene/gui/panel.h" diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 3e5b89ccf3..44577811ff 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -33,7 +33,7 @@ #include "scene/main/window.h" -#include "core/local_vector.h" +#include "core/templates/local_vector.h" class Popup : public Window { GDCLASS(Popup, Window); diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 578d8a96e8..0a469d8373 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -33,8 +33,8 @@ #include "core/input/input.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/print_string.h" -#include "core/translation.h" +#include "core/string/print_string.h" +#include "core/string/translation.h" String PopupMenu::_get_accel_text(int p_item) const { ERR_FAIL_INDEX_V(p_item, items.size(), String()); diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp index 32ec0049f0..773acb2713 100644 --- a/scene/gui/reference_rect.cpp +++ b/scene/gui/reference_rect.cpp @@ -30,7 +30,7 @@ #include "reference_rect.h" -#include "core/engine.h" +#include "core/config/engine.h" void ReferenceRect::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { diff --git a/scene/gui/rich_text_effect.cpp b/scene/gui/rich_text_effect.cpp index 2628e5ab0f..76ca8abcc7 100644 --- a/scene/gui/rich_text_effect.cpp +++ b/scene/gui/rich_text_effect.cpp @@ -30,7 +30,7 @@ #include "rich_text_effect.h" -#include "core/script_language.h" +#include "core/object/script_language.h" void RichTextEffect::_bind_methods() { BIND_VMETHOD(MethodInfo(Variant::BOOL, "_process_custom_fx", PropertyInfo(Variant::OBJECT, "char_fx", PROPERTY_HINT_RESOURCE_TYPE, "CharFXTransform"))); diff --git a/scene/gui/rich_text_effect.h b/scene/gui/rich_text_effect.h index a5401f7eaa..e6b9f09e4d 100644 --- a/scene/gui/rich_text_effect.h +++ b/scene/gui/rich_text_effect.h @@ -31,7 +31,7 @@ #ifndef RICH_TEXT_EFFECT_H #define RICH_TEXT_EFFECT_H -#include "core/resource.h" +#include "core/io/resource.h" class RichTextEffect : public Resource { GDCLASS(RichTextEffect, Resource); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 0e9ef71892..9340d98ede 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -32,7 +32,7 @@ #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/print_string.h" +#include "core/string/print_string.h" #include "scene/main/window.h" bool ScrollBar::focus_by_default = false; diff --git a/scene/gui/shortcut.h b/scene/gui/shortcut.h index 0d7809e5cf..176958b397 100644 --- a/scene/gui/shortcut.h +++ b/scene/gui/shortcut.h @@ -32,7 +32,7 @@ #define SHORTCUT_H #include "core/input/input_event.h" -#include "core/resource.h" +#include "core/io/resource.h" class Shortcut : public Resource { GDCLASS(Shortcut, Resource); diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp index 4e1ad2ae05..c5f56fe8e2 100644 --- a/scene/gui/subviewport_container.cpp +++ b/scene/gui/subviewport_container.cpp @@ -30,7 +30,7 @@ #include "subviewport_container.h" -#include "core/engine.h" +#include "core/config/engine.h" #include "scene/main/viewport.h" Size2 SubViewportContainer::get_minimum_size() const { diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index a1f93094c4..d92f41af2d 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -30,7 +30,7 @@ #include "tab_container.h" -#include "core/message_queue.h" +#include "core/object/message_queue.h" #include "scene/gui/box_container.h" #include "scene/gui/label.h" #include "scene/gui/texture_rect.h" @@ -282,7 +282,6 @@ void TabContainer::_notification(int p_what) { Color font_color_bg = get_theme_color("font_color_bg"); Color font_color_disabled = get_theme_color("font_color_disabled"); int side_margin = get_theme_constant("side_margin"); - int icon_text_distance = get_theme_constant("icon_separation"); // Find out start and width of the header area. int header_x = side_margin; @@ -348,61 +347,35 @@ void TabContainer::_notification(int p_what) { break; } - // Draw the tab area. - panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height)); - - // Draw all visible tabs. + // Draw unselected tabs in back int x = 0; + int x_current = 0; for (int i = 0; i < tab_widths.size(); i++) { if (get_tab_hidden(i)) { continue; } - Ref<StyleBox> tab_style; - Color font_color; + + int tab_width = tab_widths[i]; if (get_tab_disabled(i + first_tab_cache)) { - tab_style = tab_disabled; - font_color = font_color_disabled; + _draw_tab(tab_disabled, font_color_disabled, i, tabs_ofs_cache + x); } else if (i + first_tab_cache == current) { - tab_style = tab_fg; - font_color = font_color_fg; + x_current = x; } else { - tab_style = tab_bg; - font_color = font_color_bg; - } - - // Draw the tab background. - int tab_width = tab_widths[i]; - Rect2 tab_rect(tabs_ofs_cache + x, 0, tab_width, header_height); - tab_style->draw(canvas, tab_rect); - - // Draw the tab contents. - Control *control = Object::cast_to<Control>(tabs[i + first_tab_cache]); - String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); - - int x_content = tab_rect.position.x + tab_style->get_margin(MARGIN_LEFT); - int top_margin = tab_style->get_margin(MARGIN_TOP); - int y_center = top_margin + (tab_rect.size.y - tab_style->get_minimum_size().y) / 2; - - // Draw the tab icon. - if (control->has_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)); - if (text != "") { - x_content += icon->get_width() + icon_text_distance; - } - } + _draw_tab(tab_bg, font_color_bg, i, tabs_ofs_cache + x); } - // Draw the tab text. - Point2i text_pos(x_content, y_center - (font->get_height() / 2) + font->get_ascent()); - font->draw(canvas, text_pos, text, font_color); - x += tab_width; last_tab_cache = i + first_tab_cache; } + // Draw the tab area. + panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height)); + + // Draw selected tab in front. Need to check tabs.size() in case of no contents at all. + if (tabs.size() > 0) { + _draw_tab(tab_fg, font_color_fg, current, tabs_ofs_cache + x_current); + } + // Draw the popup menu. x = get_size().width; if (popup) { @@ -438,6 +411,43 @@ void TabContainer::_notification(int p_what) { } } +void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x) { + Vector<Control *> tabs = _get_tabs(); + RID canvas = get_canvas_item(); + Ref<Font> font = get_theme_font("font"); + int icon_text_distance = get_theme_constant("icon_separation"); + int tab_width = _get_tab_width(p_index); + int header_height = _get_top_margin(); + + // Draw the tab background. + Rect2 tab_rect(p_x, 0, tab_width, header_height); + p_tab_style->draw(canvas, tab_rect); + + // Draw the tab contents. + Control *control = Object::cast_to<Control>(tabs[p_index + first_tab_cache]); + String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); + + int x_content = tab_rect.position.x + p_tab_style->get_margin(MARGIN_LEFT); + int top_margin = p_tab_style->get_margin(MARGIN_TOP); + int y_center = top_margin + (tab_rect.size.y - p_tab_style->get_minimum_size().y) / 2; + + // Draw the tab icon. + if (control->has_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)); + if (text != "") { + x_content += icon->get_width() + icon_text_distance; + } + } + } + + // Draw the tab text. + Point2i text_pos(x_content, y_center - (font->get_height() / 2) + font->get_ascent()); + font->draw(canvas, text_pos, text, p_font_color); +} + void TabContainer::_on_theme_changed() { if (get_tab_count() > 0) { _repaint(); diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h index 7ea667d60f..6ac07b5845 100644 --- a/scene/gui/tab_container.h +++ b/scene/gui/tab_container.h @@ -68,6 +68,7 @@ private: void _repaint(); void _on_mouse_exited(); void _update_current_tab(); + void _draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x); protected: void _child_renamed_callback(); diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index d47f771d1d..eefe8cc3bc 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -30,7 +30,7 @@ #include "tabs.h" -#include "core/message_queue.h" +#include "core/object/message_queue.h" #include "scene/gui/box_container.h" #include "scene/gui/label.h" #include "scene/gui/texture_rect.h" diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index c87f639193..cbe6c6bdb9 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -30,12 +30,12 @@ #include "text_edit.h" +#include "core/config/project_settings.h" #include "core/input/input.h" -#include "core/message_queue.h" +#include "core/object/message_queue.h" +#include "core/object/script_language.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/project_settings.h" -#include "core/script_language.h" #include "scene/main/window.h" #ifdef TOOLS_ENABLED @@ -318,15 +318,15 @@ void TextEdit::_click_selection_held() { // Warning: is_mouse_button_pressed(BUTTON_LEFT) returns false for double+ clicks, so this doesn't work for MODE_WORD // and MODE_LINE. However, moving the mouse triggers _gui_input, which calls these functions too, so that's not a huge problem. // I'm unsure if there's an actual fix that doesn't have a ton of side effects. - if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) { + if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != SelectionMode::SELECTION_MODE_NONE) { switch (selection.selecting_mode) { - case Selection::MODE_POINTER: { + case SelectionMode::SELECTION_MODE_POINTER: { _update_selection_mode_pointer(); } break; - case Selection::MODE_WORD: { + case SelectionMode::SELECTION_MODE_WORD: { _update_selection_mode_word(); } break; - case Selection::MODE_LINE: { + case SelectionMode::SELECTION_MODE_LINE: { _update_selection_mode_line(); } break; default: { @@ -1367,10 +1367,6 @@ void TextEdit::_notification(int p_what) { int scrollw = get_theme_constant("completion_scroll_width"); Color scrollc = get_theme_color("completion_scroll_color"); -#ifdef TOOLS_ENABLED - scrollw *= EDSCALE; -#endif - const int completion_options_size = completion_options.size(); int lines = MIN(completion_options_size, maxlines); int w = 0; @@ -2165,7 +2161,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (mb->get_shift() && (cursor.column != prev_col || cursor.line != prev_line)) { if (!selection.active) { selection.active = true; - selection.selecting_mode = Selection::MODE_POINTER; + selection.selecting_mode = SelectionMode::SELECTION_MODE_POINTER; selection.from_column = prev_col; selection.from_line = prev_line; selection.to_column = cursor.column; @@ -2209,19 +2205,19 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } else { selection.active = false; - selection.selecting_mode = Selection::MODE_POINTER; + selection.selecting_mode = SelectionMode::SELECTION_MODE_POINTER; selection.selecting_line = row; selection.selecting_column = col; } if (!mb->is_doubleclick() && (OS::get_singleton()->get_ticks_msec() - last_dblclk) < 600 && cursor.line == prev_line) { // Triple-click select line. - selection.selecting_mode = Selection::MODE_LINE; + selection.selecting_mode = SelectionMode::SELECTION_MODE_LINE; _update_selection_mode_line(); last_dblclk = 0; } else if (mb->is_doubleclick() && text[cursor.line].length()) { // Double-click select word. - selection.selecting_mode = Selection::MODE_WORD; + selection.selecting_mode = SelectionMode::SELECTION_MODE_WORD; _update_selection_mode_word(); last_dblclk = OS::get_singleton()->get_ticks_msec(); } @@ -2321,13 +2317,13 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (!dragging_minimap) { switch (selection.selecting_mode) { - case Selection::MODE_POINTER: { + case SelectionMode::SELECTION_MODE_POINTER: { _update_selection_mode_pointer(); } break; - case Selection::MODE_WORD: { + case SelectionMode::SELECTION_MODE_WORD: { _update_selection_mode_word(); } break; - case Selection::MODE_LINE: { + case SelectionMode::SELECTION_MODE_LINE: { _update_selection_mode_line(); } break; default: { @@ -2604,7 +2600,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (unselect) { selection.active = false; - selection.selecting_mode = Selection::MODE_NONE; + selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE; update(); } if (clear) { @@ -3632,17 +3628,17 @@ void TextEdit::_scroll_down(real_t p_delta) { } void TextEdit::_pre_shift_selection() { - if (!selection.active || selection.selecting_mode == Selection::MODE_NONE) { + if (!selection.active || selection.selecting_mode == SelectionMode::SELECTION_MODE_NONE) { selection.selecting_line = cursor.line; selection.selecting_column = cursor.column; selection.active = true; } - selection.selecting_mode = Selection::MODE_SHIFT; + selection.selecting_mode = SelectionMode::SELECTION_MODE_SHIFT; } void TextEdit::_post_shift_selection() { - if (selection.active && selection.selecting_mode == Selection::MODE_SHIFT) { + if (selection.active && selection.selecting_mode == SelectionMode::SELECTION_MODE_SHIFT) { select(selection.selecting_line, selection.selecting_column, cursor.line, cursor.column); update(); } @@ -4352,6 +4348,30 @@ bool TextEdit::is_right_click_moving_caret() const { return right_click_moves_caret; } +TextEdit::SelectionMode TextEdit::get_selection_mode() const { + return selection.selecting_mode; +} + +void TextEdit::set_selection_mode(SelectionMode p_mode, int p_line, int p_column) { + selection.selecting_mode = p_mode; + if (p_line >= 0) { + ERR_FAIL_INDEX(p_line, text.size()); + selection.selecting_line = p_line; + } + if (p_column >= 0) { + ERR_FAIL_INDEX(p_line, text[selection.selecting_line].length()); + selection.selecting_column = p_column; + } +} + +int TextEdit::get_selection_line() const { + return selection.selecting_line; +}; + +int TextEdit::get_selection_column() const { + return selection.selecting_column; +}; + void TextEdit::_v_scroll_input() { scrolling = false; minimap_clicked = false; @@ -4495,7 +4515,7 @@ void TextEdit::insert_text_at_cursor(const String &p_text) { _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); selection.active = false; - selection.selecting_mode = Selection::MODE_NONE; + selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE; } _insert_text_at_cursor(p_text); @@ -5004,7 +5024,7 @@ void TextEdit::cut() { cursor_set_column(selection.from_column); selection.active = false; - selection.selecting_mode = Selection::MODE_NONE; + selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE; update(); cut_copy_line = ""; } @@ -5030,7 +5050,7 @@ void TextEdit::paste() { begin_complex_operation(); if (selection.active) { selection.active = false; - selection.selecting_mode = Selection::MODE_NONE; + selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE; _remove_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); cursor_set_line(selection.from_line); cursor_set_column(selection.from_column); @@ -5062,7 +5082,7 @@ void TextEdit::select_all() { selection.selecting_column = 0; selection.to_line = text.size() - 1; selection.to_column = text[selection.to_line].length(); - selection.selecting_mode = Selection::MODE_SHIFT; + selection.selecting_mode = SelectionMode::SELECTION_MODE_SHIFT; selection.shiftclick_left = true; cursor_set_line(selection.to_line, false); cursor_set_column(selection.to_column, false); @@ -6613,6 +6633,12 @@ void TextEdit::_bind_methods() { BIND_ENUM_CONSTANT(SEARCH_WHOLE_WORDS); BIND_ENUM_CONSTANT(SEARCH_BACKWARDS); + BIND_ENUM_CONSTANT(SELECTION_MODE_NONE); + BIND_ENUM_CONSTANT(SELECTION_MODE_SHIFT); + BIND_ENUM_CONSTANT(SELECTION_MODE_POINTER); + BIND_ENUM_CONSTANT(SELECTION_MODE_WORD); + BIND_ENUM_CONSTANT(SELECTION_MODE_LINE); + /* ClassDB::bind_method(D_METHOD("delete_char"),&TextEdit::delete_char); ClassDB::bind_method(D_METHOD("delete_line"),&TextEdit::delete_line); @@ -6642,6 +6668,11 @@ void TextEdit::_bind_methods() { ClassDB::bind_method(D_METHOD("set_right_click_moves_caret", "enable"), &TextEdit::set_right_click_moves_caret); ClassDB::bind_method(D_METHOD("is_right_click_moving_caret"), &TextEdit::is_right_click_moving_caret); + ClassDB::bind_method(D_METHOD("get_selection_mode"), &TextEdit::get_selection_mode); + ClassDB::bind_method(D_METHOD("set_selection_mode", "mode", "line", "column"), &TextEdit::set_selection_mode, DEFVAL(-1), DEFVAL(-1)); + ClassDB::bind_method(D_METHOD("get_selection_line"), &TextEdit::get_selection_line); + ClassDB::bind_method(D_METHOD("get_selection_column"), &TextEdit::get_selection_column); + ClassDB::bind_method(D_METHOD("set_readonly", "enable"), &TextEdit::set_readonly); ClassDB::bind_method(D_METHOD("is_readonly"), &TextEdit::is_readonly); @@ -6850,7 +6881,7 @@ TextEdit::TextEdit() { cursor_changed_dirty = false; text_changed_dirty = false; - selection.selecting_mode = Selection::MODE_NONE; + selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE; selection.selecting_line = 0; selection.selecting_column = 0; selection.selecting_text = false; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 562f4768ae..5cfa70bc55 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -47,6 +47,14 @@ public: GUTTER_TPYE_CUSTOM }; + enum SelectionMode { + SELECTION_MODE_NONE, + SELECTION_MODE_SHIFT, + SELECTION_MODE_POINTER, + SELECTION_MODE_WORD, + SELECTION_MODE_LINE + }; + private: struct GutterInfo { GutterType type = GutterType::GUTTER_TYPE_STRING; @@ -157,16 +165,7 @@ private: } cursor; struct Selection { - enum Mode { - - MODE_NONE, - MODE_SHIFT, - MODE_POINTER, - MODE_WORD, - MODE_LINE - }; - - Mode selecting_mode; + SelectionMode selecting_mode; int selecting_line, selecting_column; int selected_word_beg, selected_word_end, selected_word_origin; bool selecting_text; @@ -178,7 +177,7 @@ private: bool shiftclick_left; Selection() { - selecting_mode = MODE_NONE; + selecting_mode = SelectionMode::SELECTION_MODE_NONE; selecting_line = 0; selecting_column = 0; selected_word_beg = 0; @@ -636,6 +635,11 @@ public: void set_right_click_moves_caret(bool p_enable); bool is_right_click_moving_caret() const; + SelectionMode get_selection_mode() const; + void set_selection_mode(SelectionMode p_mode, int p_line = -1, int p_column = -1); + int get_selection_line() const; + int get_selection_column() const; + void set_readonly(bool p_readonly); bool is_readonly() const; @@ -761,6 +765,7 @@ public: }; VARIANT_ENUM_CAST(TextEdit::GutterType); +VARIANT_ENUM_CAST(TextEdit::SelectionMode); VARIANT_ENUM_CAST(TextEdit::MenuItems); VARIANT_ENUM_CAST(TextEdit::SearchFlags); diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index 484b14d11c..e0d98d1c22 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -30,7 +30,7 @@ #include "texture_progress.h" -#include "core/engine.h" +#include "core/config/engine.h" void TextureProgress::set_under_texture(const Ref<Texture2D> &p_texture) { under = p_texture; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 318496df70..bcb375d786 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -30,12 +30,12 @@ #include "tree.h" +#include "core/config/project_settings.h" #include "core/input/input.h" #include "core/math/math_funcs.h" #include "core/os/keyboard.h" #include "core/os/os.h" -#include "core/print_string.h" -#include "core/project_settings.h" +#include "core/string/print_string.h" #include "scene/main/window.h" #include "box_container.h" |