diff options
Diffstat (limited to 'scene/gui')
-rw-r--r-- | scene/gui/color_picker.cpp | 2 | ||||
-rw-r--r-- | scene/gui/color_ramp_edit.cpp | 2 | ||||
-rw-r--r-- | scene/gui/container.cpp | 2 | ||||
-rw-r--r-- | scene/gui/control.cpp | 34 | ||||
-rw-r--r-- | scene/gui/control.h | 8 | ||||
-rw-r--r-- | scene/gui/dialogs.cpp | 71 | ||||
-rw-r--r-- | scene/gui/graph_edit.cpp | 20 | ||||
-rw-r--r-- | scene/gui/line_edit.cpp | 2 | ||||
-rw-r--r-- | scene/gui/menu_button.cpp | 6 | ||||
-rw-r--r-- | scene/gui/option_button.cpp | 2 | ||||
-rw-r--r-- | scene/gui/popup.cpp | 16 | ||||
-rw-r--r-- | scene/gui/popup_menu.cpp | 18 | ||||
-rw-r--r-- | scene/gui/tab_container.cpp | 4 | ||||
-rw-r--r-- | scene/gui/text_edit.cpp | 144 | ||||
-rw-r--r-- | scene/gui/text_edit.h | 14 | ||||
-rw-r--r-- | scene/gui/tree.cpp | 24 |
16 files changed, 232 insertions, 137 deletions
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 8a94d4918f..adb5e2f0b6 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -591,7 +591,7 @@ void ColorPickerButton::_color_changed(const Color &p_color) { void ColorPickerButton::pressed() { Size2 ms = Size2(300, picker->get_combined_minimum_size().height + 10); - popup->set_pos(get_global_pos() - Size2(0, ms.height)); + popup->set_position(get_global_position() - Size2(0, ms.height)); popup->set_size(ms); popup->popup(); picker->set_focus_on_line_edit(); diff --git a/scene/gui/color_ramp_edit.cpp b/scene/gui/color_ramp_edit.cpp index 0bc9205175..c6f73fe6e6 100644 --- a/scene/gui/color_ramp_edit.cpp +++ b/scene/gui/color_ramp_edit.cpp @@ -62,7 +62,7 @@ void ColorRampEdit::_show_color_picker() { return; Size2 ms = Size2(350, picker->get_combined_minimum_size().height + 10); picker->set_pick_color(points[grabbed].color); - popup->set_pos(get_global_pos() - Vector2(ms.width - get_size().width, ms.height)); + popup->set_position(get_global_position() - Vector2(ms.width - get_size().width, ms.height)); popup->set_size(ms); popup->popup(); } diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index d3096d7806..c428d524a4 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -107,7 +107,7 @@ void Container::fit_child_in_rect(Control *p_child, const Rect2 &p_rect) { for (int i = 0; i < 4; i++) p_child->set_anchor(Margin(i), ANCHOR_BEGIN); - p_child->set_pos(r.pos); + p_child->set_position(r.pos); p_child->set_size(r.size); p_child->set_rotation(0); p_child->set_scale(Vector2(1, 1)); diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp index bda54181c7..e62a993651 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -58,7 +58,7 @@ void Control::edit_set_state(const Variant &p_state) { Dictionary s = p_state; Rect2 state = s["rect"]; - set_pos(state.pos); + set_position(state.pos); set_size(state.size); set_rotation(s["rot"]); set_scale(s["scale"]); @@ -96,13 +96,13 @@ void Control::edit_set_rect(const Rect2 &p_edit_rect) { postxf.set_rotation_and_scale(data.rotation, data.scale); Vector2 new_pos = postxf.xform(p_edit_rect.pos); - Vector2 pos = get_pos() + new_pos; + Vector2 pos = get_position() + new_pos; Rect2 new_rect = get_rect(); new_rect.pos = pos.snapped(Vector2(1, 1)); new_rect.size = p_edit_rect.size.snapped(Vector2(1, 1)); - set_pos(new_rect.pos); + set_position(new_rect.pos); set_size(new_rect.size); } @@ -353,7 +353,7 @@ void Control::remove_child_notify(Node *p_child) { void Control::_update_canvas_item_transform() { - Transform2D xform = Transform2D(data.rotation, get_pos()); + Transform2D xform = Transform2D(data.rotation, get_position()); xform.scale_basis(data.scale); VisualServer::get_singleton()->canvas_item_set_transform(get_canvas_item(), xform); } @@ -1390,12 +1390,12 @@ Size2 Control::get_end() const { return Size2(data.margin[2], data.margin[3]); } -Point2 Control::get_global_pos() const { +Point2 Control::get_global_position() const { return get_global_transform().get_origin(); } -void Control::set_global_pos(const Point2 &p_point) { +void Control::set_global_position(const Point2 &p_point) { Transform2D inv; @@ -1404,10 +1404,10 @@ void Control::set_global_pos(const Point2 &p_point) { inv = data.parent_canvas_item->get_global_transform().affine_inverse(); } - set_pos(inv.xform(p_point)); + set_position(inv.xform(p_point)); } -void Control::set_pos(const Size2 &p_point) { +void Control::set_position(const Size2 &p_point) { float pw = _get_parent_range(0); float ph = _get_parent_range(1); @@ -1459,7 +1459,7 @@ void Control::set_size(const Size2 &p_size) { _size_changed(); } -Size2 Control::get_pos() const { +Size2 Control::get_position() const { return data.pos_cache; } @@ -1471,7 +1471,7 @@ Size2 Control::get_size() const { Rect2 Control::get_global_rect() const { - return Rect2(get_global_pos(), get_size()); + return Rect2(get_global_position(), get_size()); } Rect2 Control::get_window_rect() const { @@ -1483,7 +1483,7 @@ Rect2 Control::get_window_rect() const { Rect2 Control::get_rect() const { - return Rect2(get_pos(), get_size()); + return Rect2(get_position(), get_size()); } Rect2 Control::get_item_rect() const { @@ -1886,7 +1886,7 @@ Control::CursorShape Control::get_cursor_shape(const Point2 &p_pos) const { Transform2D Control::get_transform() const { - Transform2D xform = Transform2D(data.rotation, get_pos()); + Transform2D xform = Transform2D(data.rotation, get_position()); xform.scale_basis(data.scale); return xform; } @@ -2315,10 +2315,10 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("set_anchor_and_margin", "margin", "anchor_mode", "offset"), &Control::set_anchor_and_margin); ClassDB::bind_method(D_METHOD("set_begin", "pos"), &Control::set_begin); ClassDB::bind_method(D_METHOD("set_end", "pos"), &Control::set_end); - ClassDB::bind_method(D_METHOD("set_pos", "pos"), &Control::set_pos); + ClassDB::bind_method(D_METHOD("set_position", "pos"), &Control::set_position); ClassDB::bind_method(D_METHOD("set_size", "size"), &Control::set_size); ClassDB::bind_method(D_METHOD("set_custom_minimum_size", "size"), &Control::set_custom_minimum_size); - ClassDB::bind_method(D_METHOD("set_global_pos", "pos"), &Control::set_global_pos); + ClassDB::bind_method(D_METHOD("set_global_position", "pos"), &Control::set_global_position); ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation); ClassDB::bind_method(D_METHOD("set_rotation_deg", "degrees"), &Control::set_rotation_deg); // TODO: Obsolete this method (old name) properly (GH-4397) @@ -2327,7 +2327,7 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_margin", "margin"), &Control::get_margin); ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin); ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end); - ClassDB::bind_method(D_METHOD("get_pos"), &Control::get_pos); + ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position); ClassDB::bind_method(D_METHOD("get_size"), &Control::get_size); ClassDB::bind_method(D_METHOD("get_rotation"), &Control::get_rotation); ClassDB::bind_method(D_METHOD("get_rotation_deg"), &Control::get_rotation_deg); @@ -2336,7 +2336,7 @@ void Control::_bind_methods() { ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale); ClassDB::bind_method(D_METHOD("get_custom_minimum_size"), &Control::get_custom_minimum_size); ClassDB::bind_method(D_METHOD("get_parent_area_size"), &Control::get_size); - ClassDB::bind_method(D_METHOD("get_global_pos"), &Control::get_global_pos); + ClassDB::bind_method(D_METHOD("get_global_position"), &Control::get_global_position); ClassDB::bind_method(D_METHOD("get_rect"), &Control::get_rect); ClassDB::bind_method(D_METHOD("get_global_rect"), &Control::get_global_rect); ClassDB::bind_method(D_METHOD("set_area_as_parent_rect", "margin"), &Control::set_area_as_parent_rect, DEFVAL(0)); @@ -2438,7 +2438,7 @@ void Control::_bind_methods() { ADD_PROPERTYINZ(PropertyInfo(Variant::INT, "margin_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_margin", "get_margin", MARGIN_BOTTOM); ADD_GROUP("Rect", "rect_"); - ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_pos", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_pos", "get_pos"); + ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_position", "get_position"); ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "set_size", "get_size"); ADD_PROPERTYNZ(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size"); ADD_PROPERTYNZ(PropertyInfo(Variant::REAL, "rect_rotation", PROPERTY_HINT_RANGE, "-1080,1080,0.01"), "set_rotation_deg", "get_rotation_deg"); diff --git a/scene/gui/control.h b/scene/gui/control.h index 9075c5a6ed..5834d1550a 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -277,12 +277,12 @@ public: Point2 get_begin() const; Point2 get_end() const; - void set_pos(const Point2 &p_point); + void set_position(const Point2 &p_point); void set_size(const Size2 &p_size); - void set_global_pos(const Point2 &p_point); + void set_global_position(const Point2 &p_point); - Point2 get_pos() const; - Point2 get_global_pos() const; + Point2 get_position() const; + Point2 get_global_position() const; Size2 get_size() const; Rect2 get_rect() const; Rect2 get_global_rect() const; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index c53b2bdb21..835775e13b 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -36,6 +36,8 @@ #include "editor/editor_node.h" #endif +// WindowDialog + void WindowDialog::_post_popup() { drag_type = DRAG_NONE; // just in case @@ -46,20 +48,20 @@ void WindowDialog::_fix_size() { // Perhaps this should be called when the viewport resizes as well or windows go out of bounds... // Ensure the whole window is visible. - Point2i pos = get_global_pos(); + Point2i pos = get_global_position(); Size2i size = get_size(); Size2i viewport_size = get_viewport_rect().size; // Windows require additional padding to keep the window chrome visible. - Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); - float top = panel->get_margin(MARGIN_TOP); - float left = panel->get_margin(MARGIN_LEFT); - float bottom = panel->get_margin(MARGIN_BOTTOM); - float right = panel->get_margin(MARGIN_RIGHT); + Ref<StyleBoxTexture> panel = get_stylebox("panel", "WindowDialog"); + float top = panel->get_expand_margin_size(MARGIN_TOP); + float left = panel->get_expand_margin_size(MARGIN_LEFT); + float bottom = panel->get_expand_margin_size(MARGIN_BOTTOM); + float right = panel->get_expand_margin_size(MARGIN_RIGHT); pos.x = MAX(left, MIN(pos.x, viewport_size.x - size.x - right)); pos.y = MAX(top, MIN(pos.y, viewport_size.y - size.y - bottom)); - set_global_pos(pos); + set_global_position(pos); // Also resize the window to fit if a resize should be possible at all. if (resizable) { @@ -74,9 +76,9 @@ bool WindowDialog::has_point(const Point2 &p_point) const { Rect2 r(Point2(), get_size()); // Enlarge upwards for title bar. - int titlebar_height = get_constant("titlebar_height", "WindowDialog"); - r.pos.y -= titlebar_height; - r.size.y += titlebar_height; + int title_height = get_constant("title_height", "WindowDialog"); + r.pos.y -= title_height; + r.size.y += title_height; // Inflate by the resizable border thickness. if (resizable) { @@ -98,8 +100,8 @@ void WindowDialog::_gui_input(const InputEvent &p_event) { // Begin a possible dragging operation. drag_type = _drag_hit_test(Point2(p_event.mouse_button.x, p_event.mouse_button.y)); if (drag_type != DRAG_NONE) - drag_offset = get_global_mouse_pos() - get_pos(); - drag_offset_far = get_pos() + get_size() - get_global_mouse_pos(); + drag_offset = get_global_mouse_position() - get_position(); + drag_offset_far = get_position() + get_size() - get_global_mouse_position(); } else if (drag_type != DRAG_NONE && !p_event.mouse_button.pressed) { // End a dragging operation. drag_type = DRAG_NONE; @@ -136,7 +138,7 @@ void WindowDialog::_gui_input(const InputEvent &p_event) { set_default_cursor_shape(cursor); } else { // Update while in a dragging operation. - Point2 global_pos = get_global_mouse_pos(); + Point2 global_pos = get_global_mouse_position(); global_pos.y = MAX(global_pos.y, 0); // Ensure title bar stays visible. Rect2 rect = get_rect(); @@ -164,7 +166,7 @@ void WindowDialog::_gui_input(const InputEvent &p_event) { } set_size(rect.size); - set_pos(rect.pos); + set_position(rect.pos); } } } @@ -173,30 +175,21 @@ void WindowDialog::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - RID canvas = get_canvas_item(); - Size2 size = get_size(); + // Draw the background. Ref<StyleBox> panel = get_stylebox("panel", "WindowDialog"); - int margin_left = static_cast<int>(panel->get_margin(MARGIN_LEFT)); - int margin_top = static_cast<int>(panel->get_margin(MARGIN_TOP)); - int margin_right = static_cast<int>(panel->get_margin(MARGIN_RIGHT)); - int margin_bottom = static_cast<int>(panel->get_margin(MARGIN_BOTTOM)); - - Rect2 rect; - rect.pos.x = -margin_left; - rect.pos.y = -margin_top; - rect.size.width = size.width + margin_left + margin_right; - rect.size.height = size.height + margin_top + margin_bottom; - - panel->draw(canvas, rect); + Size2 size = get_size(); + panel->draw(canvas, Rect2(0, 0, size.x, size.y)); - int title_height = get_constant("title_height", "WindowDialog"); + // Draw the title bar text. + Ref<Font> title_font = get_font("title_font", "WindowDialog"); Color title_color = get_color("title_color", "WindowDialog"); - Ref<Font> font = get_font("title_font", "WindowDialog"); - int ofs = (size.width - font->get_string_size(title).width) / 2; - draw_string(font, Point2(ofs, -title_height + font->get_ascent()), title, title_color, size.width - panel->get_minimum_size().width); - + int title_height = get_constant("title_height", "WindowDialog"); + int font_height = title_font->get_height() - title_font->get_descent() * 2; + int x = (size.x - title_font->get_string_size(title).x) / 2; + int y = (-title_height + font_height) / 2; + title_font->draw(canvas, Point2(x, y), title, title_color, size.x - panel->get_minimum_size().x); } break; case NOTIFICATION_THEME_CHANGED: @@ -238,12 +231,12 @@ int WindowDialog::_drag_hit_test(const Point2 &pos) const { int drag_type = DRAG_NONE; if (resizable) { - int titlebar_height = get_constant("titlebar_height", "WindowDialog"); + int title_height = get_constant("title_height", "WindowDialog"); int scaleborder_size = get_constant("scaleborder_size", "WindowDialog"); Rect2 rect = get_rect(); - if (pos.y < (-titlebar_height + scaleborder_size)) + if (pos.y < (-title_height + scaleborder_size)) drag_type = DRAG_RESIZE_TOP; else if (pos.y >= (rect.size.height - scaleborder_size)) drag_type = DRAG_RESIZE_BOTTOM; @@ -317,6 +310,8 @@ WindowDialog::WindowDialog() { WindowDialog::~WindowDialog() { } +// PopupDialog + void PopupDialog::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { @@ -416,14 +411,14 @@ void AcceptDialog::_update_child_rects() { if (c == hbc || c == label || c == get_close_button() || c->is_set_as_toplevel()) continue; - c->set_pos(cpos); + c->set_position(cpos); c->set_size(csize); } cpos.y += csize.y + margin; csize.y = hminsize.y; - hbc->set_pos(cpos); + hbc->set_position(cpos); hbc->set_size(csize); } @@ -554,6 +549,8 @@ AcceptDialog::AcceptDialog() { AcceptDialog::~AcceptDialog() { } +// ConfirmationDialog + void ConfirmationDialog::_bind_methods() { ClassDB::bind_method(D_METHOD("get_cancel:Button"), &ConfirmationDialog::get_cancel); diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 76baf20526..0c092a4e17 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -140,13 +140,13 @@ void GraphEdit::_update_scroll_offset() { Point2 pos = gn->get_offset() * zoom; pos -= Point2(h_scroll->get_value(), v_scroll->get_value()); - gn->set_pos(pos); + gn->set_position(pos); if (gn->get_scale() != Vector2(zoom, zoom)) { gn->set_scale(Vector2(zoom, zoom)); } } - connections_layer->set_pos(-Point2(h_scroll->get_value(), v_scroll->get_value())); + connections_layer->set_position(-Point2(h_scroll->get_value(), v_scroll->get_value())); set_block_minimum_size_adjust(false); awaiting_scroll_offset_update = false; } @@ -350,14 +350,14 @@ bool GraphEdit::_filter_input(const Point2 &p_point) { for (int j = 0; j < gn->get_connection_output_count(); j++) { - Vector2 pos = gn->get_connection_output_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_output_pos(j) + gn->get_position(); if (pos.distance_to(p_point) < grab_r) return true; } for (int j = 0; j < gn->get_connection_input_count(); j++) { - Vector2 pos = gn->get_connection_input_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_input_pos(j) + gn->get_position(); if (pos.distance_to(p_point) < grab_r) { return true; } @@ -383,7 +383,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) { for (int j = 0; j < gn->get_connection_output_count(); j++) { - Vector2 pos = gn->get_connection_output_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_output_pos(j) + gn->get_position(); if (pos.distance_to(mpos) < grab_r) { if (valid_left_disconnect_types.has(gn->get_connection_output_type(j))) { @@ -430,7 +430,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) { for (int j = 0; j < gn->get_connection_input_count(); j++) { - Vector2 pos = gn->get_connection_input_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_input_pos(j) + gn->get_position(); if (pos.distance_to(mpos) < grab_r) { @@ -497,7 +497,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) { if (!connecting_out) { for (int j = 0; j < gn->get_connection_output_count(); j++) { - Vector2 pos = gn->get_connection_output_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_output_pos(j) + gn->get_position(); int type = gn->get_connection_output_type(j); if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && pos.distance_to(mpos) < grab_r) { @@ -512,7 +512,7 @@ void GraphEdit::_top_layer_input(const InputEvent &p_ev) { for (int j = 0; j < gn->get_connection_input_count(); j++) { - Vector2 pos = gn->get_connection_input_pos(j) + gn->get_pos(); + Vector2 pos = gn->get_connection_input_pos(j) + gn->get_position(); int type = gn->get_connection_input_type(j); if ((type == connecting_type || valid_connection_types.has(ConnType(type, connecting_type))) && pos.distance_to(mpos) < grab_r) { connecting_target = true; @@ -704,7 +704,7 @@ void GraphEdit::_top_layer_draw() { pos = from->get_connection_output_pos(connecting_index); else pos = from->get_connection_input_pos(connecting_index); - pos += from->get_pos(); + pos += from->get_position(); Vector2 topos; topos = connecting_to; @@ -1229,7 +1229,7 @@ GraphEdit::GraphEdit() { HBoxContainer *zoom_hb = memnew(HBoxContainer); top_layer->add_child(zoom_hb); - zoom_hb->set_pos(Vector2(10, 10)); + zoom_hb->set_position(Vector2(10, 10)); zoom_minus = memnew(ToolButton); zoom_hb->add_child(zoom_minus); diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 30bc4d1663..9abf9649c0 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -51,7 +51,7 @@ void LineEdit::_gui_input(InputEvent p_event) { const InputEventMouseButton &b = p_event.mouse_button; if (b.pressed && b.button_index == BUTTON_RIGHT) { - menu->set_pos(get_global_transform().xform(get_local_mouse_pos())); + menu->set_position(get_global_transform().xform(get_local_mouse_pos())); menu->set_size(Vector2(1, 1)); menu->popup(); grab_focus(); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 16277ed0d0..cf468f2257 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -50,10 +50,10 @@ void MenuButton::pressed() { emit_signal("about_to_show"); Size2 size = get_size(); - Point2 gp = get_global_pos(); - popup->set_global_pos(gp + Size2(0, size.height)); + Point2 gp = get_global_position(); + popup->set_global_position(gp + Size2(0, size.height)); popup->set_size(Size2(size.width, 0)); - popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_pos()), get_size())); + popup->set_parent_rect(Rect2(Point2(gp - popup->get_global_position()), get_size())); popup->popup(); popup->call_deferred("grab_click_focus"); popup->set_invalidate_click_until_motion(); diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 0bb68e7fa1..0806d35d48 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -87,7 +87,7 @@ void OptionButton::_selected(int p_which) { void OptionButton::pressed() { Size2 size = get_size(); - popup->set_global_pos(get_global_pos() + Size2(0, size.height)); + popup->set_global_position(get_global_position() + Size2(0, size.height)); popup->set_size(Size2(size.width, 0)); popup->popup(); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 523633166c..7d0b91a366 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -58,12 +58,12 @@ void Popup::_notification(int p_what) { void Popup::_fix_size() { #if 0 - Point2 pos = get_pos(); + Point2 pos = get_position(); Size2 size = get_size(); Point2 window_size = window==this ? get_parent_area_size() :window->get_size(); #else - Point2 pos = get_global_pos(); + Point2 pos = get_global_position(); Size2 size = get_size(); Point2 window_size = get_viewport_rect().size; @@ -79,10 +79,10 @@ void Popup::_fix_size() { pos.y = 0; #if 0 if (pos!=get_pos()) - set_pos(pos); + set_position(pos); #else - if (pos != get_pos()) - set_global_pos(pos); + if (pos != get_position()) + set_global_position(pos); #endif } @@ -171,7 +171,7 @@ void Popup::popup_centered(const Size2 &p_size) { rect.size = p_size == Size2() ? get_size() : p_size; rect.pos = ((window_size - rect.size) / 2.0).floor(); - set_pos(rect.pos); + set_position(rect.pos); set_size(rect.size); show_modal(exclusive); @@ -194,7 +194,7 @@ void Popup::popup_centered_ratio(float p_screen_ratio) { Point2 window_size = get_viewport_rect().size; rect.size = (window_size * p_screen_ratio).floor(); rect.pos = ((window_size - rect.size) / 2.0).floor(); - set_pos(rect.pos); + set_position(rect.pos); set_size(rect.size); show_modal(exclusive); @@ -216,7 +216,7 @@ void Popup::popup(const Rect2 &bounds) { // Fit the popup into the optionally provided bounds. if (!bounds.has_no_area()) { - set_pos(bounds.pos); + set_position(bounds.pos); set_size(bounds.size); } _fix_size(); diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index de16f3c525..6ac6eac655 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -169,7 +169,7 @@ void PopupMenu::_activate_submenu(int over) { if (pm->is_visible_in_tree()) return; //already visible! - Point2 p = get_global_pos(); + Point2 p = get_global_position(); Rect2 pr(p, get_size()); Ref<StyleBox> style = get_stylebox("panel"); @@ -179,13 +179,13 @@ void PopupMenu::_activate_submenu(int over) { if (pos.x + size.width > get_viewport_rect().size.width) pos.x = p.x - size.width; - pm->set_pos(pos); + pm->set_position(pos); pm->popup(); PopupMenu *pum = pm->cast_to<PopupMenu>(); if (pum) { - pr.pos -= pum->get_global_pos(); + pr.pos -= pum->get_global_position(); pum->clear_autohide_areas(); pum->add_autohide_area(Rect2(pr.pos.x, pr.pos.y, pr.size.x, items[over]._ofs_cache)); if (over < items.size() - 1) { @@ -266,15 +266,15 @@ void PopupMenu::_gui_input(const InputEvent &p_event) { case BUTTON_WHEEL_DOWN: { - if (get_global_pos().y + get_size().y > get_viewport_rect().size.y) { + if (get_global_position().y + get_size().y > get_viewport_rect().size.y) { int vseparation = get_constant("vseparation"); Ref<Font> font = get_font("font"); - Point2 pos = get_pos(); + Point2 pos = get_position(); int s = (vseparation + font->get_height()) * 3; pos.y -= s; - set_pos(pos); + set_position(pos); //update hover InputEvent ie; @@ -286,15 +286,15 @@ void PopupMenu::_gui_input(const InputEvent &p_event) { } break; case BUTTON_WHEEL_UP: { - if (get_global_pos().y < 0) { + if (get_global_position().y < 0) { int vseparation = get_constant("vseparation"); Ref<Font> font = get_font("font"); - Point2 pos = get_pos(); + Point2 pos = get_position(); int s = (vseparation + font->get_height()) * 3; pos.y += s; - set_pos(pos); + set_position(pos); //update hover InputEvent ie; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 0ef6fbdebd..0c7a58dc16 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -79,11 +79,11 @@ void TabContainer::_gui_input(const InputEvent &p_event) { if (popup && pos.x > size.width - menu->get_width()) { emit_signal("pre_popup_pressed"); - Vector2 popup_pos = get_global_pos(); + Vector2 popup_pos = get_global_position(); popup_pos.x += size.width - popup->get_size().width; popup_pos.y += menu->get_height(); - popup->set_global_pos(popup_pos); + popup->set_global_position(popup_pos); popup->popup(); return; } diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 8cbd6675f0..3c8545bd75 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -101,15 +101,15 @@ void TextEdit::Text::set_font(const Ref<Font> &p_font) { font = p_font; } -void TextEdit::Text::set_tab_size(int p_tab_size) { +void TextEdit::Text::set_indent_size(int p_indent_size) { - tab_size = p_tab_size; + indent_size = p_indent_size; } void TextEdit::Text::_update_line_cache(int p_line) const { int w = 0; - int tab_w = font->get_char_size(' ').width * tab_size; + int tab_w = font->get_char_size(' ').width * indent_size; int len = text[p_line].data.length(); const CharType *str = text[p_line].data.c_str(); @@ -360,7 +360,7 @@ void TextEdit::_click_selection_held() { if (Input::get_singleton()->is_mouse_button_pressed(BUTTON_LEFT) && selection.selecting_mode != Selection::MODE_NONE) { - Point2 mp = Input::get_singleton()->get_mouse_pos() - get_global_pos(); + Point2 mp = Input::get_singleton()->get_mouse_position() - get_global_position(); int row, col; _get_mouse_pos(Point2i(mp.x, mp.y), row, col); @@ -456,7 +456,7 @@ void TextEdit::_notification(int p_what) { int visible_rows = get_visible_rows(); - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; Color color = cache.font_color; int in_region = -1; @@ -1305,7 +1305,38 @@ void TextEdit::backspace_at_cursor() { _is_pair_left_symbol(text[cursor.line][cursor.column - 1])) { _consume_backspace_for_pair_symbol(prev_line, prev_column); } else { - _remove_text(prev_line, prev_column, cursor.line, cursor.column); + // handle space indentation + if (cursor.column - indent_size >= 0 && indent_using_spaces) { + + // if there is enough spaces to count as a tab + bool unindent = true; + for (int i = 1; i <= indent_size; i++) { + if (text[cursor.line][cursor.column - i] != ' ') { + unindent = false; + break; + } + } + + // and it is before the first character + int i = 0; + while (i < cursor.column && i < text[cursor.line].length()) { + if (text[cursor.line][i] != ' ' && text[cursor.line][i] != '\t') { + unindent = false; + break; + } + i++; + } + + // then we can remove it as a single character. + if (unindent) { + _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column); + prev_column = cursor.column - indent_size; + } else { + _remove_text(prev_line, prev_column, cursor.line, cursor.column); + } + } else { + _remove_text(prev_line, prev_column, cursor.line, cursor.column); + } } cursor_set_line(prev_line); @@ -1328,7 +1359,11 @@ void TextEdit::indent_selection_right() { for (int i = start_line; i <= end_line; i++) { String line_text = get_line(i); - line_text = '\t' + line_text; + if (indent_using_spaces) { + line_text = space_indent + line_text; + } else { + line_text = '\t' + line_text; + } set_line(i, line_text); } @@ -1359,8 +1394,8 @@ void TextEdit::indent_selection_left() { if (line_text.begins_with("\t")) { line_text = line_text.substr(1, line_text.length()); set_line(i, line_text); - } else if (line_text.begins_with(" ")) { - line_text = line_text.substr(4, line_text.length()); + } else if (line_text.begins_with(space_indent)) { + line_text = line_text.substr(indent_size, line_text.length()); set_line(i, line_text); } } @@ -1586,7 +1621,7 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) { if (mb.button_index == BUTTON_RIGHT && context_menu_enabled) { - menu->set_pos(get_global_transform().xform(get_local_mouse_pos())); + menu->set_position(get_global_transform().xform(get_local_mouse_pos())); menu->set_size(Vector2(1, 1)); menu->popup(); grab_focus(); @@ -1931,17 +1966,39 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) { String ins = "\n"; //keep indentation + int space_count = 0; for (int i = 0; i < text[cursor.line].length(); i++) { - if (text[cursor.line][i] == '\t') - ins += "\t"; - else + if (text[cursor.line][i] == '\t') { + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } + space_count = 0; + } else if (text[cursor.line][i] == ' ') { + space_count++; + + if (space_count == indent_size) { + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } + space_count = 0; + } + } else { break; + } } if (auto_indent) { // indent once again if previous line will end with ':' // (i.e. colon precedes current cursor position) if (cursor.column > 0 && text[cursor.line][cursor.column - 1] == ':') { - ins += "\t"; + if (indent_using_spaces) { + ins += space_indent; + } else { + ins += "\t"; + } } } @@ -1987,15 +2044,36 @@ void TextEdit::_gui_input(const InputEvent &p_gui_input) { } else { if (k.mod.shift) { + //simple unindent int cc = cursor.column; - if (cc > 0 && cc <= text[cursor.line].length() && text[cursor.line][cursor.column - 1] == '\t') { - //simple unindent + if (cc > 0 && cc <= text[cursor.line].length()) { + if (text[cursor.line][cursor.column - 1] == '\t') { + backspace_at_cursor(); + } else { + if (cursor.column - indent_size >= 0) { + + bool unindent = true; + for (int i = 1; i <= indent_size; i++) { + if (text[cursor.line][cursor.column - i] != ' ') { + unindent = false; + break; + } + } - backspace_at_cursor(); + if (unindent) { + _remove_text(cursor.line, cursor.column - indent_size, cursor.line, cursor.column); + cursor_set_column(cursor.column - indent_size); + } + } + } } } else { //simple indent - _insert_text_at_cursor("\t"); + if (indent_using_spaces) { + _insert_text_at_cursor(space_indent); + } else { + _insert_text_at_cursor("\t"); + } } } @@ -3103,7 +3181,7 @@ int TextEdit::get_char_pos_for(int p_px, String p_str) const { int px = 0; int c = 0; - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; while (c < p_str.length()) { @@ -3135,7 +3213,7 @@ int TextEdit::get_column_x_offset(int p_char, String p_str) { int px = 0; - int tab_w = cache.font->get_char_size(' ').width * tab_size; + int tab_w = cache.font->get_char_size(' ').width * indent_size; for (int i = 0; i < p_char; i++) { @@ -3952,10 +4030,24 @@ void TextEdit::_push_current_op() { current_op.chain_forward = false; } -void TextEdit::set_tab_size(const int p_size) { +void TextEdit::set_indent_using_spaces(const bool p_use_spaces) { + indent_using_spaces = p_use_spaces; +} + +bool TextEdit::is_indent_using_spaces() const { + return indent_using_spaces; +} + +void TextEdit::set_indent_size(const int p_size) { ERR_FAIL_COND(p_size <= 0); - tab_size = p_size; - text.set_tab_size(p_size); + indent_size = p_size; + text.set_indent_size(p_size); + + space_indent = ""; + for (int i = 0; i < p_size; i++) { + space_indent += " "; + } + update(); } @@ -4542,8 +4634,8 @@ TextEdit::TextEdit() { cache.breakpoint_gutter_width = 0; breakpoint_gutter_width = 0; - tab_size = 4; - text.set_tab_size(tab_size); + indent_size = 4; + text.set_indent_size(indent_size); text.clear(); //text.insert(1,"Mongolia.."); //text.insert(2,"PAIS GENEROSO!!"); @@ -4631,6 +4723,8 @@ TextEdit::TextEdit() { auto_brace_completion_enabled = false; brace_matching_enabled = false; highlight_all_occurrences = false; + indent_using_spaces = false; + space_indent = " "; auto_indent = false; insert_mode = false; window_has_focus = true; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index d5fe2950f4..905ea46bd7 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -141,12 +141,12 @@ class TextEdit : public Control { const Vector<ColorRegion> *color_regions; mutable Vector<Line> text; Ref<Font> font; - int tab_size; + int indent_size; void _update_line_cache(int p_line) const; public: - void set_tab_size(int p_tab_size); + void set_indent_size(int p_indent_size); void set_font(const Ref<Font> &p_font); void set_color_regions(const Vector<ColorRegion> *p_regions) { color_regions = p_regions; } int get_line_width(int p_line) const; @@ -163,7 +163,7 @@ class TextEdit : public Control { void clear(); void clear_caches(); _FORCE_INLINE_ const String &operator[](int p_line) const { return text[p_line].data; } - Text() { tab_size = 4; } + Text() { indent_size = 4; } }; struct TextOperation { @@ -221,7 +221,9 @@ class TextEdit : public Control { int max_chars; bool readonly; bool syntax_coloring; - int tab_size; + bool indent_using_spaces; + int indent_size; + String space_indent; Timer *caret_blink_timer; bool caret_blink_enabled; @@ -461,7 +463,9 @@ public: void redo(); void clear_undo_history(); - void set_tab_size(const int p_size); + void set_indent_using_spaces(const bool p_use_spaces); + bool is_indent_using_spaces() const; + void set_indent_size(const int p_size); void set_draw_tabs(bool p_draw); bool is_drawing_tabs() const; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 1cfaa58b92..bc7b7485d8 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -1041,7 +1041,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 cache.selected->draw(ci, r); } if (text_editor->is_visible_in_tree()) { - text_editor->set_pos(get_global_pos() + r.pos); + text_editor->set_position(get_global_position() + r.pos); } } @@ -1503,7 +1503,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool cache.click_id = c.buttons[j].id; cache.click_item = p_item; cache.click_column = col; - cache.click_pos = get_global_mouse_pos() - get_global_pos(); + cache.click_pos = get_global_mouse_position() - get_global_position(); update(); //emit_signal("button_pressed"); return -1; @@ -1627,7 +1627,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool } popup_menu->set_size(Size2(col_width, 0)); - popup_menu->set_pos(get_global_pos() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h) - cache.offset); + popup_menu->set_position(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h) - cache.offset); popup_menu->popup(); popup_edited_item = p_item; popup_edited_item_col = col; @@ -1693,7 +1693,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool case TreeItem::CELL_MODE_CUSTOM: { edited_item = p_item; edited_col = col; - custom_popup_rect = Rect2i(get_global_pos() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h)); + custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h)); emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2)))); bring_up_editor = false; @@ -1710,7 +1710,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool popup_edited_item = p_item; popup_edited_item_col = col; - pressing_item_rect = Rect2(get_global_pos() + Point2i(col_ofs, _get_title_button_height() + y_ofs) - cache.offset, Size2(col_width, item_h)); + pressing_item_rect = Rect2(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs) - cache.offset, Size2(col_width, item_h)); pressing_for_editor_text = editor_text; pressing_for_editor = true; @@ -2379,7 +2379,7 @@ bool Tree::edit_selected() { edited_item = s; edited_col = col; - custom_popup_rect = Rect2i(get_global_pos() + rect.pos, rect.size); + custom_popup_rect = Rect2i(get_global_position() + rect.pos, rect.size); emit_signal("custom_popup_edited", false); item_edited(col, s); @@ -2394,7 +2394,7 @@ bool Tree::edit_selected() { } popup_menu->set_size(Size2(rect.size.width, 0)); - popup_menu->set_pos(get_global_pos() + rect.pos + Point2i(0, rect.size.height)); + popup_menu->set_position(get_global_position() + rect.pos + Point2i(0, rect.size.height)); popup_menu->popup(); popup_edited_item = s; popup_edited_item_col = col; @@ -2402,8 +2402,8 @@ bool Tree::edit_selected() { } else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) { - Point2i textedpos = get_global_pos() + rect.pos; - text_editor->set_pos(textedpos); + Point2i textedpos = get_global_position() + rect.pos; + text_editor->set_position(textedpos); text_editor->set_size(rect.size); text_editor->clear(); text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::step_decimals(c.step))); @@ -2411,7 +2411,7 @@ bool Tree::edit_selected() { if (c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) { - value_editor->set_pos(textedpos + Point2i(0, text_editor->get_size().height)); + value_editor->set_position(textedpos + Point2i(0, text_editor->get_size().height)); value_editor->set_size(Size2(rect.size.width, 1)); value_editor->show_modal(); updating_value_editor = true; @@ -2529,7 +2529,7 @@ void Tree::_notification(int p_what) { if (p_what == NOTIFICATION_DRAG_BEGIN) { single_select_defer = NULL; - if (cache.scroll_speed > 0 && get_rect().has_point(get_viewport()->get_mouse_pos() - get_global_pos())) { + if (cache.scroll_speed > 0 && get_rect().has_point(get_viewport()->get_mouse_position() - get_global_position())) { scrolling = true; set_fixed_process(true); } @@ -2577,7 +2577,7 @@ void Tree::_notification(int p_what) { } if (scrolling) { - Point2 point = get_viewport()->get_mouse_pos() - get_global_pos(); + Point2 point = get_viewport()->get_mouse_position() - get_global_position(); if (point.x < cache.scroll_border) { point.x -= cache.scroll_border; } else if (point.x > get_size().width - cache.scroll_border) { |