diff options
Diffstat (limited to 'scene/gui')
48 files changed, 561 insertions, 344 deletions
diff --git a/scene/gui/SCsub b/scene/gui/SCsub index bf9125be7f..b01e2fd54d 100644 --- a/scene/gui/SCsub +++ b/scene/gui/SCsub @@ -3,5 +3,3 @@ Import('env') env.add_source_files(env.scene_sources, "*.cpp") - -Export('env') diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index d17ae1d84c..71fb97c2c6 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -30,7 +30,7 @@ #include "base_button.h" -#include "os/keyboard.h" +#include "core/os/keyboard.h" #include "scene/main/viewport.h" #include "scene/scene_string_names.h" @@ -315,6 +315,14 @@ void BaseButton::set_disabled(bool p_disabled) { return; status.disabled = p_disabled; + if (p_disabled) { + if (!toggle_mode) { + status.pressed = false; + } + status.press_attempt = false; + status.pressing_inside = false; + status.pressing_button = 0; + } update(); _change_notify("disabled"); } @@ -360,7 +368,9 @@ BaseButton::DrawMode BaseButton::get_draw_mode() const { return DRAW_DISABLED; }; - if (status.press_attempt == false && status.hovering && !status.pressed) { + if (status.press_attempt == false && status.hovering) { + if (status.pressed) + return DRAW_HOVER_PRESSED; return DRAW_HOVER; } else { @@ -536,6 +546,7 @@ void BaseButton::_bind_methods() { BIND_ENUM_CONSTANT(DRAW_PRESSED); BIND_ENUM_CONSTANT(DRAW_HOVER); BIND_ENUM_CONSTANT(DRAW_DISABLED); + BIND_ENUM_CONSTANT(DRAW_HOVER_PRESSED); BIND_ENUM_CONSTANT(ACTION_MODE_BUTTON_PRESS); BIND_ENUM_CONSTANT(ACTION_MODE_BUTTON_RELEASE); diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h index 79638bbcce..176d9fc213 100644 --- a/scene/gui/base_button.h +++ b/scene/gui/base_button.h @@ -85,6 +85,7 @@ public: DRAW_PRESSED, DRAW_HOVER, DRAW_DISABLED, + DRAW_HOVER_PRESSED, }; DrawMode get_draw_mode() const; diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index a34f2f1ad5..2d17fb1391 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -29,8 +29,8 @@ /*************************************************************************/ #include "button.h" +#include "core/translation.h" #include "servers/visual_server.h" -#include "translation.h" Size2 Button::get_minimum_size() const { @@ -88,6 +88,21 @@ void Button::_notification(int p_what) { if (has_color("icon_color_normal")) color_icon = get_color("icon_color_normal"); } break; + case DRAW_HOVER_PRESSED: { + if (has_stylebox("hover_pressed") && has_stylebox_override("hover_pressed")) { + style = get_stylebox("hover_pressed"); + if (!flat) + style->draw(ci, Rect2(Point2(0, 0), size)); + if (has_color("font_color_hover_pressed")) + color = get_color("font_color_hover_pressed"); + else + color = get_color("font_color"); + if (has_color("icon_color_hover_pressed")) + color_icon = get_color("icon_color_hover_pressed"); + + break; + } + } case DRAW_PRESSED: { style = get_stylebox("pressed"); diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index f9ed0ecdbb..fa9538da28 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -30,7 +30,7 @@ #include "check_button.h" -#include "print_string.h" +#include "core/print_string.h" #include "servers/visual_server.h" Size2 CheckButton::get_icon_size() const { diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 8e232c6f46..03eee9c6d8 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -30,9 +30,14 @@ #include "color_picker.h" -#include "os/input.h" -#include "os/keyboard.h" -#include "os/os.h" +#include "core/os/input.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" + +#ifdef TOOLS_ENABLED +#include "editor_settings.h" +#endif + #include "scene/gui/separator.h" #include "scene/main/viewport.h" @@ -52,6 +57,16 @@ void ColorPicker::_notification(int p_what) { bt_add_preset->set_icon(get_icon("add_preset")); _update_color(); + +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + PoolColorArray saved_presets = EditorSettings::get_singleton()->get_project_metadata("color_picker", "presets", PoolColorArray()); + + for (int i = 0; i < saved_presets.size(); i++) { + add_preset(saved_presets[i]); + } + } +#endif } break; case NOTIFICATION_PARENTED: { @@ -186,9 +201,22 @@ void ColorPicker::_update_presets() { preset->draw_texture_rect(get_icon("preset_bg", "ColorPicker"), Rect2(Point2(), preset_size), true); +#ifdef TOOLS_ENABLED + if (Engine::get_singleton()->is_editor_hint()) { + PoolColorArray arr_to_save = PoolColorArray(); + + for (int i = 0; i < presets.size(); i++) { + preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]); + arr_to_save.insert(i, presets[i]); + } + + EditorSettings::get_singleton()->set_project_metadata("color_picker", "presets", arr_to_save); + } +#else for (int i = 0; i < presets.size(); i++) { preset->draw_rect(Rect2(Point2(size.width * i, 0), size), presets[i]); } +#endif } void ColorPicker::_text_type_toggled() { diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp index 7df03bf7c6..d606629041 100644 --- a/scene/gui/container.cpp +++ b/scene/gui/container.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "container.h" -#include "message_queue.h" +#include "core/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 e094a063be..dc18895298 100644 --- a/scene/gui/control.cpp +++ b/scene/gui/control.cpp @@ -29,15 +29,15 @@ /*************************************************************************/ #include "control.h" -#include "project_settings.h" +#include "core/project_settings.h" #include "scene/main/canvas_layer.h" #include "scene/main/viewport.h" #include "servers/visual_server.h" -#include "message_queue.h" -#include "os/keyboard.h" -#include "os/os.h" -#include "print_string.h" +#include "core/message_queue.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" +#include "core/print_string.h" #include "scene/gui/label.h" #include "scene/gui/panel.h" #include "scene/scene_string_names.h" @@ -1993,7 +1993,7 @@ Control *Control::find_prev_valid_focus() const { if (!from) { - ERR_EXPLAIN("Prev focus node is not a control: " + n->get_name()); + ERR_EXPLAIN("Previous focus node is not a control: " + n->get_name()); ERR_FAIL_V(NULL); } } else { @@ -2062,8 +2062,11 @@ void Control::grab_focus() { if (!is_inside_tree()) { ERR_FAIL_COND(!is_inside_tree()); } - if (data.focus_mode == FOCUS_NONE) + + if (data.focus_mode == FOCUS_NONE) { + WARN_PRINT("This control can't grab focus. Use set_focus_mode() to allow a control to get focus."); return; + } get_viewport()->_gui_control_grab_focus(this); } @@ -2874,7 +2877,7 @@ void Control::_bind_methods() { ADD_GROUP("Mouse", "mouse_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter"); - ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,Ibeam,Pointing hand,Cross,Wait,Busy,Drag,Can drop,Forbidden,Vertical resize,Horizontal resize,Secondary diagonal resize,Main diagonal resize,Move,Vertial split,Horizontal split,Help"), "set_default_cursor_shape", "get_default_cursor_shape"); + ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,Ibeam,Pointing hand,Cross,Wait,Busy,Drag,Can drop,Forbidden,Vertical resize,Horizontal resize,Secondary diagonal resize,Main diagonal resize,Move,Vertical split,Horizontal split,Help"), "set_default_cursor_shape", "get_default_cursor_shape"); 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"); @@ -2956,7 +2959,7 @@ void Control::_bind_methods() { BIND_ENUM_CONSTANT(ANCHOR_END); ADD_SIGNAL(MethodInfo("resized")); - ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "ev", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); + ADD_SIGNAL(MethodInfo("gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"))); ADD_SIGNAL(MethodInfo("mouse_entered")); ADD_SIGNAL(MethodInfo("mouse_exited")); ADD_SIGNAL(MethodInfo("focus_entered")); diff --git a/scene/gui/control.h b/scene/gui/control.h index c6bd2f097d..eb39d9ca0f 100644 --- a/scene/gui/control.h +++ b/scene/gui/control.h @@ -31,13 +31,13 @@ #ifndef CONTROL_H #define CONTROL_H -#include "rid.h" +#include "core/math/transform_2d.h" +#include "core/rid.h" #include "scene/2d/canvas_item.h" #include "scene/gui/shortcut.h" #include "scene/main/node.h" #include "scene/main/timer.h" #include "scene/resources/theme.h" -#include "transform_2d.h" /** @author Juan Linietsky <reduzio@gmail.com> */ @@ -76,7 +76,7 @@ public: SIZE_EXPAND = 2, SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL, SIZE_SHRINK_CENTER = 4, //ignored by expand or fill - SIZE_SHRINK_END = 8, //ignored by expand or fil + SIZE_SHRINK_END = 8, //ignored by expand or fill }; diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index d9737fa21a..e3a21eb10d 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -29,9 +29,9 @@ /*************************************************************************/ #include "dialogs.h" +#include "core/print_string.h" +#include "core/translation.h" #include "line_edit.h" -#include "print_string.h" -#include "translation.h" #ifdef TOOLS_ENABLED #include "editor/editor_node.h" diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index 9bddaa7d29..1e9f4df4a3 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -29,8 +29,8 @@ /*************************************************************************/ #include "file_dialog.h" -#include "os/keyboard.h" -#include "print_string.h" +#include "core/os/keyboard.h" +#include "core/print_string.h" #include "scene/gui/label.h" FileDialog::GetIconFunc FileDialog::get_icon_func = NULL; @@ -330,6 +330,10 @@ void FileDialog::deselect_items() { case MODE_OPEN_DIR: get_ok()->set_text(RTR("Select Current Folder")); break; + case MODE_OPEN_ANY: + case MODE_SAVE_FILE: + // FIXME: Implement, or refactor to avoid duplication with set_mode + break; } } } @@ -349,7 +353,7 @@ void FileDialog::_tree_selected() { file->set_text(d["name"]); } else if (mode == MODE_OPEN_DIR) { - get_ok()->set_text(RTR("Select this Folder")); + get_ok()->set_text(RTR("Select This Folder")); } get_ok()->set_disabled(_is_open_should_be_disabled()); diff --git a/scene/gui/file_dialog.h b/scene/gui/file_dialog.h index 3227f1c3a8..8bd15080d3 100644 --- a/scene/gui/file_dialog.h +++ b/scene/gui/file_dialog.h @@ -32,7 +32,7 @@ #define FILE_DIALOG_H #include "box_container.h" -#include "os/dir_access.h" +#include "core/os/dir_access.h" #include "scene/gui/dialogs.h" #include "scene/gui/line_edit.h" #include "scene/gui/option_button.h" diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index e82c0c4ad1..19ffe681ef 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -29,7 +29,10 @@ /*************************************************************************/ #include "gradient_edit.h" -#include "os/keyboard.h" +#include "core/os/keyboard.h" +#include "editor/editor_scale.h" + +#define SPACING (3 * EDSCALE) GradientEdit::GradientEdit() { grabbed = -1; @@ -49,11 +52,15 @@ GradientEdit::GradientEdit() { int GradientEdit::_get_point_from_pos(int x) { int result = -1; - int total_w = get_size().width - get_size().height - 3; + int total_w = get_size().width - get_size().height - SPACING; + float min_distance = 1e20; for (int i = 0; i < points.size(); i++) { //Check if we clicked at point - if (ABS(x - points[i].offset * total_w + 1) < (POINT_WIDTH / 2 + 1)) { + float distance = ABS(x - points[i].offset * total_w); + float min = (POINT_WIDTH / 2 * 1.7); //make it easier to grab + if (distance <= min && distance < min_distance) { result = i; + min_distance = distance; } } return result; @@ -63,7 +70,16 @@ void GradientEdit::_show_color_picker() { if (grabbed == -1) return; picker->set_pick_color(points[grabbed].color); - popup->set_position(get_global_position() - popup->get_combined_minimum_size()); + Size2 minsize = popup->get_combined_minimum_size(); + bool show_above = false; + if (get_global_position().y + get_size().y + minsize.y > get_viewport_rect().size.y) { + show_above = true; + } + if (show_above) { + popup->set_position(get_global_position() - Vector2(0, minsize.y)); + } else { + popup->set_position(get_global_position() + Vector2(0, get_size().y)); + } popup->popup(); } @@ -112,7 +128,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { grabbed = _get_point_from_pos(x); if (grabbed != -1) { - int total_w = get_size().width - get_size().height - 3; + int total_w = get_size().width - get_size().height - SPACING; Gradient::Point newPoint = points[grabbed]; newPoint.offset = CLAMP(x / float(total_w), 0, 1); @@ -130,14 +146,15 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { } } + //select if (mb.is_valid() && mb->get_button_index() == 1 && mb->is_pressed()) { update(); int x = mb->get_position().x; - int total_w = get_size().width - get_size().height - 3; + int total_w = get_size().width - get_size().height - SPACING; //Check if color selector was clicked. - if (x > total_w + 3) { + if (x > total_w + SPACING) { _show_color_picker(); return; } @@ -211,7 +228,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid() && grabbing) { - int total_w = get_size().width - get_size().height - 3; + int total_w = get_size().width - get_size().height - SPACING; int x = mm->get_position().x; @@ -286,7 +303,7 @@ void GradientEdit::_notification(int p_what) { if (w == 0 || h == 0) return; //Safety check. We have division by 'h'. And in any case there is nothing to draw with such size - int total_w = get_size().width - get_size().height - 3; + int total_w = get_size().width - get_size().height - SPACING; //Draw checker pattern for ramp _draw_checker(0, 0, total_w, h); @@ -335,27 +352,36 @@ void GradientEdit::_notification(int p_what) { //Draw point markers for (int i = 0; i < points.size(); i++) { - Color col = i == grabbed ? Color(1, 0.0, 0.0, 0.9) : points[i].color.contrasted(); + Color col = points[i].color.contrasted(); col.a = 0.9; draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col); - draw_rect(Rect2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2, POINT_WIDTH, h / 2), Color(0.6, 0.6, 0.6, i == grabbed ? 0.9 : 0.4)); - draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h - 1), col); - draw_line(Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h - 1), col); - draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h / 2), col); - draw_line(Vector2(points[i].offset * total_w - POINT_WIDTH / 2, h - 1), Vector2(points[i].offset * total_w + POINT_WIDTH / 2, h - 1), col); + Rect2 rect = Rect2(points[i].offset * total_w - POINT_WIDTH / 2, h / 2, POINT_WIDTH, h / 2); + draw_rect(rect, points[i].color, true); + draw_rect(rect, col, false); + if (grabbed == i) { + rect = rect.grow(-1); + if (has_focus()) { + draw_rect(rect, Color(1, 0, 0, 0.9), false); + } else { + draw_rect(rect, Color(0.6, 0, 0, 0.9), false); + } + + rect = rect.grow(-1); + draw_rect(rect, col, false); + } } //Draw "button" for color selector - _draw_checker(total_w + 3, 0, h, h); + _draw_checker(total_w + SPACING, 0, h, h); if (grabbed != -1) { //Draw with selection color - draw_rect(Rect2(total_w + 3, 0, h, h), points[grabbed].color); + draw_rect(Rect2(total_w + SPACING, 0, h, h), points[grabbed].color); } else { //if no color selected draw grey color with 'X' on top. - draw_rect(Rect2(total_w + 3, 0, h, h), Color(0.5, 0.5, 0.5, 1)); - draw_line(Vector2(total_w + 3, 0), Vector2(total_w + 3 + h, h), Color(1, 1, 1, 0.6)); - draw_line(Vector2(total_w + 3, h), Vector2(total_w + 3 + h, 0), Color(1, 1, 1, 0.6)); + draw_rect(Rect2(total_w + SPACING, 0, h, h), Color(0.5, 0.5, 0.5, 1)); + draw_line(Vector2(total_w + SPACING, 0), Vector2(total_w + SPACING + h, h), Color(1, 1, 1, 0.6)); + draw_line(Vector2(total_w + SPACING, h), Vector2(total_w + SPACING + h, 0), Color(1, 1, 1, 0.6)); } //Draw borders around color ramp if in focus diff --git a/scene/gui/gradient_edit.h b/scene/gui/gradient_edit.h index e7834ea0de..f6927ad0b7 100644 --- a/scene/gui/gradient_edit.h +++ b/scene/gui/gradient_edit.h @@ -36,7 +36,7 @@ #include "scene/resources/color_ramp.h" #include "scene/resources/default_theme/theme_data.h" -#define POINT_WIDTH 8 +#define POINT_WIDTH (8 * EDSCALE) class GradientEdit : public Control { diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index a7163adbe6..0ffaac20f6 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -30,8 +30,8 @@ #include "graph_edit.h" -#include "os/input.h" -#include "os/keyboard.h" +#include "core/os/input.h" +#include "core/os/keyboard.h" #include "scene/gui/box_container.h" #define ZOOM_SCALE 1.2 @@ -1279,7 +1279,7 @@ void GraphEdit::_bind_methods() { 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("popup_request", PropertyInfo(Variant::VECTOR2, "p_position"))); ADD_SIGNAL(MethodInfo("duplicate_nodes_request")); - ADD_SIGNAL(MethodInfo("node_selected", PropertyInfo(Variant::OBJECT, "node"))); + 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("delete_nodes_request")); ADD_SIGNAL(MethodInfo("_begin_node_move")); @@ -1304,7 +1304,7 @@ GraphEdit::GraphEdit() { add_child(connections_layer); connections_layer->connect("draw", this, "_connections_layer_draw"); connections_layer->set_name("CLAYER"); - connections_layer->set_disable_visibility_clip(true); // so it can draw freely and be offseted + connections_layer->set_disable_visibility_clip(true); // so it can draw freely and be offset connections_layer->set_mouse_filter(MOUSE_FILTER_IGNORE); h_scroll = memnew(HScrollBar); diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 24857d49fa..b189afd30b 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -29,7 +29,8 @@ /*************************************************************************/ #include "graph_node.h" -#include "method_bind_ext.gen.inc" + +#include "core/method_bind_ext.gen.inc" bool GraphNode::_set(const StringName &p_name, const Variant &p_value) { diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index 9f5c12e87f..0d5fbee9ee 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -29,8 +29,8 @@ /*************************************************************************/ #include "item_list.h" -#include "os/os.h" -#include "project_settings.h" +#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) { diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 0b36e1663c..91dab27930 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -29,9 +29,9 @@ /*************************************************************************/ #include "label.h" -#include "print_string.h" -#include "project_settings.h" -#include "translation.h" +#include "core/print_string.h" +#include "core/project_settings.h" +#include "core/translation.h" void Label::set_autowrap(bool p_autowrap) { @@ -295,14 +295,13 @@ Size2 Label::get_minimum_size() const { Size2 min_style = get_stylebox("normal")->get_minimum_size(); + // don't want to mutable everything + if (word_cache_dirty) + const_cast<Label *>(this)->regenerate_word_cache(); + if (autowrap) return Size2(1, clip ? 1 : minsize.height) + min_style; else { - - // don't want to mutable everything - if (word_cache_dirty) - const_cast<Label *>(this)->regenerate_word_cache(); - Size2 ms = minsize; if (clip) ms.width = 1; diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index 1f3d5e6e13..9c43d5b308 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -29,12 +29,12 @@ /*************************************************************************/ #include "line_edit.h" +#include "core/message_queue.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" +#include "core/print_string.h" +#include "core/translation.h" #include "label.h" -#include "message_queue.h" -#include "os/keyboard.h" -#include "os/os.h" -#include "print_string.h" -#include "translation.h" #ifdef TOOLS_ENABLED #include "editor/editor_scale.h" diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index 8560efdde5..d38a067fef 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -91,6 +91,7 @@ void LinkButton::_notification(int p_what) { do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; + case DRAW_HOVER_PRESSED: break; // Not used in this class case DRAW_DISABLED: { color = get_color("font_color_disabled"); diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp index 87cf4dc334..95ec618c3b 100644 --- a/scene/gui/menu_button.cpp +++ b/scene/gui/menu_button.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "menu_button.h" -#include "os/keyboard.h" +#include "core/os/keyboard.h" #include "scene/main/viewport.h" void MenuButton::_unhandled_key_input(Ref<InputEvent> p_event) { diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index 2901176a69..6b847c6483 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "option_button.h" -#include "print_string.h" +#include "core/print_string.h" Size2 OptionButton::get_minimum_size() const { diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index 4375e03a50..d3b7b72ee1 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "panel.h" -#include "print_string.h" +#include "core/print_string.h" void Panel::_notification(int p_what) { diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 26d01ecc09..bfbe62e1c7 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -30,8 +30,8 @@ #include "popup.h" -#include "engine.h" -#include "os/keyboard.h" +#include "core/engine.h" +#include "core/os/keyboard.h" void Popup::_gui_input(Ref<InputEvent> p_event) { } @@ -234,15 +234,46 @@ String Popup::get_configuration_warning() const { Popup::~Popup() { } -void PopupPanel::set_child_rect(Control *p_child) { - ERR_FAIL_NULL(p_child); +Size2 PopupPanel::get_minimum_size() const { Ref<StyleBox> p = get_stylebox("panel"); - p_child->set_anchors_preset(Control::PRESET_WIDE); - p_child->set_margin(MARGIN_LEFT, p->get_margin(MARGIN_LEFT)); - p_child->set_margin(MARGIN_RIGHT, -p->get_margin(MARGIN_RIGHT)); - p_child->set_margin(MARGIN_TOP, p->get_margin(MARGIN_TOP)); - p_child->set_margin(MARGIN_BOTTOM, -p->get_margin(MARGIN_BOTTOM)); + + Size2 ms; + + for (int i = 0; i < get_child_count(); i++) { + Control *c = Object::cast_to<Control>(get_child(i)); + if (!c) + continue; + + if (c->is_set_as_toplevel()) + continue; + + Size2 cms = c->get_combined_minimum_size(); + ms.x = MAX(cms.x, ms.x); + ms.y = MAX(cms.y, ms.y); + } + + return ms + p->get_minimum_size(); +} + +void PopupPanel::_update_child_rects() { + + Ref<StyleBox> p = get_stylebox("panel"); + + Vector2 cpos(p->get_offset()); + Vector2 csize(get_size() - p->get_minimum_size()); + + for (int i = 0; i < get_child_count(); i++) { + Control *c = Object::cast_to<Control>(get_child(i)); + if (!c) + continue; + + if (c->is_set_as_toplevel()) + continue; + + c->set_position(cpos); + c->set_size(csize); + } } void PopupPanel::_notification(int p_what) { @@ -250,6 +281,12 @@ void PopupPanel::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { get_stylebox("panel")->draw(get_canvas_item(), Rect2(Point2(), get_size())); + } else if (p_what == NOTIFICATION_READY) { + + _update_child_rects(); + } else if (p_what == NOTIFICATION_RESIZED) { + + _update_child_rects(); } } diff --git a/scene/gui/popup.h b/scene/gui/popup.h index 550e803578..5b1ef7d6ca 100644 --- a/scene/gui/popup.h +++ b/scene/gui/popup.h @@ -77,10 +77,12 @@ class PopupPanel : public Popup { GDCLASS(PopupPanel, Popup); protected: + void _update_child_rects(); void _notification(int p_what); public: void set_child_rect(Control *p_child); + virtual Size2 get_minimum_size() const; PopupPanel(); }; diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 436dda41a4..3239641c2f 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -29,10 +29,10 @@ /*************************************************************************/ #include "popup_menu.h" -#include "os/input.h" -#include "os/keyboard.h" -#include "print_string.h" -#include "translation.h" +#include "core/os/input.h" +#include "core/os/keyboard.h" +#include "core/print_string.h" +#include "core/translation.h" String PopupMenu::_get_accel_text(int p_item) const { diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index 09d8664240..e862743934 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -30,6 +30,19 @@ #include "range.h" +String Range::get_configuration_warning() const { + String warning = Control::get_configuration_warning(); + + if (shared->exp_ratio && shared->min <= 0) { + if (warning != String()) { + warning += "\n"; + } + warning += TTR("If exp_edit is true min_value must be > 0."); + } + + return warning; +} + void Range::_value_changed_notify() { _value_changed(shared->val); @@ -66,10 +79,11 @@ void Range::Shared::emit_changed(const char *p_what) { } void Range::set_value(double p_val) { + if (shared->step > 0) + p_val = Math::round(p_val / shared->step) * shared->step; - if (_rounded_values) { + if (_rounded_values) p_val = Math::round(p_val); - } if (!shared->allow_greater && p_val > shared->max - shared->page) p_val = shared->max - shared->page; @@ -90,6 +104,8 @@ void Range::set_min(double p_min) { set_value(shared->val); shared->emit_changed("min"); + + update_configuration_warning(); } void Range::set_max(double p_max) { @@ -277,6 +293,8 @@ bool Range::is_using_rounded_values() const { void Range::set_exp_ratio(bool p_enable) { shared->exp_ratio = p_enable; + + update_configuration_warning(); } bool Range::is_ratio_exp() const { diff --git a/scene/gui/range.h b/scene/gui/range.h index 125f559248..58f15c8aa8 100644 --- a/scene/gui/range.h +++ b/scene/gui/range.h @@ -97,6 +97,8 @@ public: void share(Range *p_range); void unshare(); + virtual String get_configuration_warning() const; + Range(); ~Range(); }; diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp index 74e68598f4..e96e5afb2a 100644 --- a/scene/gui/reference_rect.cpp +++ b/scene/gui/reference_rect.cpp @@ -30,7 +30,7 @@ #include "reference_rect.h" -#include "engine.h" +#include "core/engine.h" void ReferenceRect::_notification(int p_what) { diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index a5f9bea1b1..bb36852cf9 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -29,12 +29,13 @@ /*************************************************************************/ #include "rich_text_label.h" -#include "os/keyboard.h" -#include "os/os.h" + +#include "core/os/keyboard.h" +#include "core/os/os.h" #include "scene/scene_string_names.h" #ifdef TOOLS_ENABLED -#include "editor/editor_node.h" +#include "editor/editor_scale.h" #endif RichTextLabel::Item *RichTextLabel::_get_next_item(Item *p_item, bool p_free) { @@ -319,14 +320,17 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & Color color; Color font_color_shadow; bool underline = false; + bool strikethrough = false; if (p_mode == PROCESS_DRAW) { color = _find_color(text, p_base_color); font_color_shadow = _find_color(text, p_font_color_shadow); - underline = _find_underline(text); - if (_find_meta(text, &meta) && underline_meta) { + if (_find_underline(text) || (_find_meta(text, &meta) && underline_meta)) { underline = true; + } else if (_find_strikethrough(text)) { + + strikethrough = true; } } else if (p_mode == PROCESS_CACHE) { @@ -417,7 +421,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & int cw = 0; - bool visible = visible_characters < 0 || p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent); + bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent)); if (visible) line_is_blank = false; @@ -468,6 +472,15 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & underline_width *= EDSCALE; #endif VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, underline_width); + } else if (strikethrough) { + Color uc = color; + uc.a *= 0.5; + int uy = y + lh / 2 - line_descent + 2; + float strikethrough_width = 1.0; +#ifdef TOOLS_ENABLED + strikethrough_width *= EDSCALE; +#endif + VS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, strikethrough_width); } } @@ -496,7 +509,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int & ENSURE_WIDTH(img->image->get_width()); - bool visible = visible_characters < 0 || p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->image->get_height(), img->image->get_height()); + bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->image->get_height(), img->image->get_height())); if (visible) line_is_blank = false; @@ -834,8 +847,6 @@ void RichTextLabel::_notification(int p_what) { bool use_outline = get_constant("shadow_as_outline"); Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y")); - float x_ofs = 0; - visible_line_count = 0; while (y < size.height && from_line < main->lines.size()) { @@ -853,7 +864,6 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item if (r_click_item) *r_click_item = NULL; - Size2 size = get_size(); Rect2 text_rect = _get_text_rect(); int ofs = vscroll->get_value(); Color font_color_shadow = get_color("font_color_shadow"); @@ -1226,6 +1236,23 @@ bool RichTextLabel::_find_underline(Item *p_item) { return false; } +bool RichTextLabel::_find_strikethrough(Item *p_item) { + + Item *item = p_item; + + while (item) { + + if (item->type == ITEM_STRIKETHROUGH) { + + return true; + } + + item = item->parent; + } + + return false; +} + bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta) { Item *item = p_item; @@ -1423,18 +1450,28 @@ bool RichTextLabel::remove_line(const int p_line) { if (p_line >= current_frame->lines.size() || p_line < 0) return false; - int lines = p_line * 2; + int i = 0; + while (i < current->subitems.size() && current->subitems[i]->line < p_line) { + i++; + } - if (current->subitems[lines]->type != ITEM_NEWLINE) - _remove_item(current->subitems[lines], current->subitems[lines]->line, lines); + bool was_newline = false; + while (i < current->subitems.size()) { + was_newline = current->subitems[i]->type == ITEM_NEWLINE; + _remove_item(current->subitems[i], current->subitems[i]->line, p_line); + if (was_newline) + break; + } - _remove_item(current->subitems[lines], current->subitems[lines]->line, lines); + if (!was_newline) { + current_frame->lines.remove(p_line); + } - if (p_line == 0) { + if (p_line == 0 && current->subitems.size() > 0) main->lines.write[0].from = main; - } main->first_invalid_line = 0; + return true; } @@ -1447,6 +1484,7 @@ void RichTextLabel::push_font(const Ref<Font> &p_font) { item->font = p_font; _add_item(item, true); } + void RichTextLabel::push_color(const Color &p_color) { ERR_FAIL_COND(current->type == ITEM_TABLE); @@ -1455,6 +1493,7 @@ void RichTextLabel::push_color(const Color &p_color) { item->color = p_color; _add_item(item, true); } + void RichTextLabel::push_underline() { ERR_FAIL_COND(current->type == ITEM_TABLE); @@ -1463,6 +1502,14 @@ void RichTextLabel::push_underline() { _add_item(item, true); } +void RichTextLabel::push_strikethrough() { + + ERR_FAIL_COND(current->type == ITEM_TABLE); + ItemStrikethrough *item = memnew(ItemStrikethrough); + + _add_item(item, true); +} + void RichTextLabel::push_align(Align p_align) { ERR_FAIL_COND(current->type == ITEM_TABLE); @@ -1672,7 +1719,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { } if (brk_pos == p_bbcode.length()) - break; //nothing else o add + break; //nothing else to add int brk_end = p_bbcode.find("]", brk_pos + 1); @@ -1738,7 +1785,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { int columns = tag.substr(6, tag.length()).to_int(); if (columns < 1) columns = 1; - //use monospace font + push_table(columns); pos = brk_end + 1; tag_stack.push_front("table"); @@ -1752,7 +1799,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { int ratio = tag.substr(5, tag.length()).to_int(); if (ratio < 1) ratio = 1; - //use monospace font + set_table_column_expand(get_current_table_column(), true, ratio); push_cell(); pos = brk_end + 1; @@ -1765,43 +1812,37 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { tag_stack.push_front(tag); } else if (tag == "s") { - //use strikethrough (not supported underline instead) - push_underline(); + //use strikethrough + push_strikethrough(); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "center") { - //use underline push_align(ALIGN_CENTER); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "fill") { - //use underline push_align(ALIGN_FILL); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "right") { - //use underline push_align(ALIGN_RIGHT); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "ul") { - //use underline push_list(LIST_DOTS); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "ol") { - //use underline push_list(LIST_NUMBERS); pos = brk_end + 1; tag_stack.push_front(tag); } else if (tag == "indent") { - //use underline indent_level++; push_indent(indent_level); pos = brk_end + 1; @@ -1809,7 +1850,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { } else if (tag == "url") { - //use strikethrough (not supported underline instead) int end = p_bbcode.find("[", brk_end); if (end == -1) end = p_bbcode.length(); @@ -1827,7 +1867,6 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { tag_stack.push_front("url"); } else if (tag == "img") { - //use strikethrough (not supported underline instead) int end = p_bbcode.find("[", brk_end); if (end == -1) end = p_bbcode.length(); @@ -2134,6 +2173,7 @@ void RichTextLabel::_bind_methods() { ClassDB::bind_method(D_METHOD("push_list", "type"), &RichTextLabel::push_list); ClassDB::bind_method(D_METHOD("push_meta", "data"), &RichTextLabel::push_meta); ClassDB::bind_method(D_METHOD("push_underline"), &RichTextLabel::push_underline); + ClassDB::bind_method(D_METHOD("push_strikethrough"), &RichTextLabel::push_strikethrough); ClassDB::bind_method(D_METHOD("push_table", "columns"), &RichTextLabel::push_table); ClassDB::bind_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::set_table_column_expand); ClassDB::bind_method(D_METHOD("push_cell"), &RichTextLabel::push_cell); @@ -2194,7 +2234,7 @@ void RichTextLabel::_bind_methods() { 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"); - ADD_PROPERTY(PropertyInfo(Variant::STRING, "text"), "set_text", "get_text"); + ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_active"), "set_scroll_active", "is_scroll_active"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_following"), "set_scroll_follow", "is_scroll_following"); @@ -2222,6 +2262,7 @@ void RichTextLabel::_bind_methods() { BIND_ENUM_CONSTANT(ITEM_FONT); BIND_ENUM_CONSTANT(ITEM_COLOR); BIND_ENUM_CONSTANT(ITEM_UNDERLINE); + BIND_ENUM_CONSTANT(ITEM_STRIKETHROUGH); BIND_ENUM_CONSTANT(ITEM_ALIGN); BIND_ENUM_CONSTANT(ITEM_INDENT); BIND_ENUM_CONSTANT(ITEM_LIST); @@ -2285,7 +2326,7 @@ RichTextLabel::RichTextLabel() { vscroll = memnew(VScrollBar); add_child(vscroll); - vscroll->set_drag_slave(String("..")); + vscroll->set_drag_node(String("..")); vscroll->set_step(1); vscroll->set_anchor_and_margin(MARGIN_TOP, ANCHOR_BEGIN, 0); vscroll->set_anchor_and_margin(MARGIN_BOTTOM, ANCHOR_END, 0); diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h index 06e9b8efe3..c2e5712b9d 100644 --- a/scene/gui/rich_text_label.h +++ b/scene/gui/rich_text_label.h @@ -62,6 +62,7 @@ public: ITEM_FONT, ITEM_COLOR, ITEM_UNDERLINE, + ITEM_STRIKETHROUGH, ITEM_ALIGN, ITEM_INDENT, ITEM_LIST, @@ -164,6 +165,11 @@ private: ItemUnderline() { type = ITEM_UNDERLINE; } }; + struct ItemStrikethrough : public Item { + + ItemStrikethrough() { type = ITEM_STRIKETHROUGH; } + }; + struct ItemMeta : public Item { Variant meta; @@ -277,6 +283,7 @@ private: Align _find_align(Item *p_item); Color _find_color(Item *p_item, const Color &p_default_color); bool _find_underline(Item *p_item); + bool _find_strikethrough(Item *p_item); bool _find_meta(Item *p_item, Variant *r_meta); void _update_scroll(); @@ -307,6 +314,7 @@ public: void push_font(const Ref<Font> &p_font); void push_color(const Color &p_color); void push_underline(); + void push_strikethrough(); void push_align(Align p_align); void push_indent(int p_level); void push_list(ListType p_list); diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index e5bd1c453d..07380f45cc 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -30,9 +30,9 @@ #include "scroll_bar.h" -#include "os/keyboard.h" -#include "os/os.h" -#include "print_string.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" +#include "core/print_string.h" bool ScrollBar::focus_by_default = false; @@ -300,24 +300,24 @@ void ScrollBar::_notification(int p_what) { if (p_what == NOTIFICATION_ENTER_TREE) { - if (has_node(drag_slave_path)) { - Node *n = get_node(drag_slave_path); - drag_slave = Object::cast_to<Control>(n); + if (has_node(drag_node_path)) { + Node *n = get_node(drag_node_path); + drag_node = Object::cast_to<Control>(n); } - if (drag_slave) { - drag_slave->connect("gui_input", this, "_drag_slave_input"); - drag_slave->connect("tree_exiting", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT); + if (drag_node) { + drag_node->connect("gui_input", this, "_drag_node_input"); + drag_node->connect("tree_exiting", this, "_drag_node_exit", varray(), CONNECT_ONESHOT); } } if (p_what == NOTIFICATION_EXIT_TREE) { - if (drag_slave) { - drag_slave->disconnect("gui_input", this, "_drag_slave_input"); - drag_slave->disconnect("tree_exiting", this, "_drag_slave_exit"); + if (drag_node) { + drag_node->disconnect("gui_input", this, "_drag_node_input"); + drag_node->disconnect("tree_exiting", this, "_drag_node_exit"); } - drag_slave = NULL; + drag_node = NULL; } if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) { @@ -337,12 +337,13 @@ void ScrollBar::_notification(int p_what) { scrolling = false; set_physics_process_internal(false); } - } else if (drag_slave_touching) { - if (drag_slave_touching_deaccel) { + } else if (drag_node_touching) { + + if (drag_node_touching_deaccel) { Vector2 pos = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0); - pos += drag_slave_speed * get_physics_process_delta_time(); + pos += drag_node_speed * get_physics_process_delta_time(); bool turnoff = false; @@ -360,15 +361,15 @@ void ScrollBar::_notification(int p_what) { set_value(pos.x); - float sgn_x = drag_slave_speed.x < 0 ? -1 : 1; - float val_x = Math::abs(drag_slave_speed.x); + float sgn_x = drag_node_speed.x < 0 ? -1 : 1; + float val_x = Math::abs(drag_node_speed.x); val_x -= 1000 * get_physics_process_delta_time(); if (val_x < 0) { turnoff = true; } - drag_slave_speed.x = sgn_x * val_x; + drag_node_speed.x = sgn_x * val_x; } else { @@ -384,29 +385,29 @@ void ScrollBar::_notification(int p_what) { set_value(pos.y); - float sgn_y = drag_slave_speed.y < 0 ? -1 : 1; - float val_y = Math::abs(drag_slave_speed.y); + float sgn_y = drag_node_speed.y < 0 ? -1 : 1; + float val_y = Math::abs(drag_node_speed.y); val_y -= 1000 * get_physics_process_delta_time(); if (val_y < 0) { turnoff = true; } - drag_slave_speed.y = sgn_y * val_y; + drag_node_speed.y = sgn_y * val_y; } if (turnoff) { set_physics_process_internal(false); - drag_slave_touching = false; - drag_slave_touching_deaccel = false; + drag_node_touching = false; + drag_node_touching_deaccel = false; } } else { if (time_since_motion == 0 || time_since_motion > 0.1) { - Vector2 diff = drag_slave_accum - last_drag_slave_accum; - last_drag_slave_accum = drag_slave_accum; - drag_slave_speed = diff / get_physics_process_delta_time(); + Vector2 diff = drag_node_accum - last_drag_node_accum; + last_drag_node_accum = drag_node_accum; + drag_node_speed = diff / get_physics_process_delta_time(); } time_since_motion += get_physics_process_delta_time(); @@ -544,15 +545,15 @@ float ScrollBar::get_custom_step() const { return custom_step; } -void ScrollBar::_drag_slave_exit() { +void ScrollBar::_drag_node_exit() { - if (drag_slave) { - drag_slave->disconnect("gui_input", this, "_drag_slave_input"); + if (drag_node) { + drag_node->disconnect("gui_input", this, "_drag_node_input"); } - drag_slave = NULL; + drag_node = NULL; } -void ScrollBar::_drag_slave_input(const Ref<InputEvent> &p_input) { +void ScrollBar::_drag_node_input(const Ref<InputEvent> &p_input) { Ref<InputEventMouseButton> mb = p_input; @@ -563,43 +564,30 @@ void ScrollBar::_drag_slave_input(const Ref<InputEvent> &p_input) { if (mb->is_pressed()) { - if (drag_slave_touching) { - set_physics_process_internal(false); - drag_slave_touching_deaccel = false; - drag_slave_touching = false; - drag_slave_speed = Vector2(); - drag_slave_accum = Vector2(); - last_drag_slave_accum = Vector2(); - drag_slave_from = Vector2(); - } + drag_node_speed = Vector2(); + drag_node_accum = Vector2(); + last_drag_node_accum = Vector2(); + drag_node_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0); - if (true) { - drag_slave_speed = Vector2(); - drag_slave_accum = Vector2(); - last_drag_slave_accum = Vector2(); - //drag_slave_from=Vector2(h_scroll->get_val(),v_scroll->get_val()); - drag_slave_from = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0); + drag_node_touching = OS::get_singleton()->has_touchscreen_ui_hint(); + drag_node_touching_deaccel = false; + time_since_motion = 0; - drag_slave_touching = OS::get_singleton()->has_touchscreen_ui_hint(); - drag_slave_touching_deaccel = false; + if (drag_node_touching) { + set_physics_process_internal(true); time_since_motion = 0; - if (drag_slave_touching) { - set_physics_process_internal(true); - time_since_motion = 0; - } } } else { - if (drag_slave_touching) { + if (drag_node_touching) { - if (drag_slave_speed == Vector2()) { - drag_slave_touching_deaccel = false; - drag_slave_touching = false; + if (drag_node_speed == Vector2()) { + drag_node_touching_deaccel = false; + drag_node_touching = false; set_physics_process_internal(false); } else { - - drag_slave_touching_deaccel = true; + drag_node_touching_deaccel = true; } } } @@ -609,60 +597,54 @@ void ScrollBar::_drag_slave_input(const Ref<InputEvent> &p_input) { if (mm.is_valid()) { - if (drag_slave_touching && !drag_slave_touching_deaccel) { + if (drag_node_touching && !drag_node_touching_deaccel) { Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y); - drag_slave_accum -= motion; - Vector2 diff = drag_slave_from + drag_slave_accum; + drag_node_accum -= motion; + Vector2 diff = drag_node_from + drag_node_accum; if (orientation == HORIZONTAL) set_value(diff.x); - /* - else - drag_slave_accum.x=0; - */ + if (orientation == VERTICAL) set_value(diff.y); - /* - else - drag_slave_accum.y=0; - */ + time_since_motion = 0; } } } -void ScrollBar::set_drag_slave(const NodePath &p_path) { +void ScrollBar::set_drag_node(const NodePath &p_path) { if (is_inside_tree()) { - if (drag_slave) { - drag_slave->disconnect("gui_input", this, "_drag_slave_input"); - drag_slave->disconnect("tree_exiting", this, "_drag_slave_exit"); + if (drag_node) { + drag_node->disconnect("gui_input", this, "_drag_node_input"); + drag_node->disconnect("tree_exiting", this, "_drag_node_exit"); } } - drag_slave = NULL; - drag_slave_path = p_path; + drag_node = NULL; + drag_node_path = p_path; if (is_inside_tree()) { if (has_node(p_path)) { Node *n = get_node(p_path); - drag_slave = Object::cast_to<Control>(n); + drag_node = Object::cast_to<Control>(n); } - if (drag_slave) { - drag_slave->connect("gui_input", this, "_drag_slave_input"); - drag_slave->connect("tree_exiting", this, "_drag_slave_exit", varray(), CONNECT_ONESHOT); + if (drag_node) { + drag_node->connect("gui_input", this, "_drag_node_input"); + drag_node->connect("tree_exiting", this, "_drag_node_exit", varray(), CONNECT_ONESHOT); } } } -NodePath ScrollBar::get_drag_slave() const { +NodePath ScrollBar::get_drag_node() const { - return drag_slave_path; + return drag_node_path; } void ScrollBar::set_smooth_scroll_enabled(bool p_enable) { @@ -678,8 +660,8 @@ 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_slave_input"), &ScrollBar::_drag_slave_input); - ClassDB::bind_method(D_METHOD("_drag_slave_exit"), &ScrollBar::_drag_slave_exit); + 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")); @@ -691,13 +673,13 @@ ScrollBar::ScrollBar(Orientation p_orientation) { orientation = p_orientation; highlight = HIGHLIGHT_NONE; custom_step = -1; - drag_slave = NULL; + drag_node = NULL; drag.active = false; - drag_slave_speed = Vector2(); - drag_slave_touching = false; - drag_slave_touching_deaccel = false; + drag_node_speed = Vector2(); + drag_node_touching = false; + drag_node_touching_deaccel = false; scrolling = false; target_scroll = 0; diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h index 15e037f8bb..cde4120cdb 100644 --- a/scene/gui/scroll_bar.h +++ b/scene/gui/scroll_bar.h @@ -36,6 +36,7 @@ /** @author Juan Linietsky <reduzio@gmail.com> */ + class ScrollBar : public Range { GDCLASS(ScrollBar, Range); @@ -71,25 +72,25 @@ class ScrollBar : public Range { static void set_can_focus_by_default(bool p_can_focus); - Node *drag_slave; - NodePath drag_slave_path; + Node *drag_node; + NodePath drag_node_path; - Vector2 drag_slave_speed; - Vector2 drag_slave_accum; - Vector2 drag_slave_from; - Vector2 last_drag_slave_accum; - float last_drag_slave_time; + Vector2 drag_node_speed; + Vector2 drag_node_accum; + Vector2 drag_node_from; + Vector2 last_drag_node_accum; + float last_drag_node_time; float time_since_motion; - bool drag_slave_touching; - bool drag_slave_touching_deaccel; + bool drag_node_touching; + bool drag_node_touching_deaccel; bool click_handled; bool scrolling; double target_scroll; bool smooth_scroll_enabled; - void _drag_slave_exit(); - void _drag_slave_input(const Ref<InputEvent> &p_input); + void _drag_node_exit(); + void _drag_node_input(const Ref<InputEvent> &p_input); void _gui_input(Ref<InputEvent> p_event); @@ -102,8 +103,8 @@ public: void set_custom_step(float p_custom_step); float get_custom_step() const; - void set_drag_slave(const NodePath &p_path); - NodePath get_drag_slave() const; + void set_drag_node(const NodePath &p_path); + NodePath get_drag_node() const; void set_smooth_scroll_enabled(bool p_enable); bool is_smooth_scroll_enabled() const; diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 495d618930..26da16569a 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -29,7 +29,8 @@ /*************************************************************************/ #include "scroll_container.h" -#include "os/os.h" +#include "core/os/os.h" + bool ScrollContainer::clips_input() const { return true; @@ -170,7 +171,7 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) { Vector2 motion = Vector2(mm->get_relative().x, mm->get_relative().y); drag_accum -= motion; - if (beyond_deadzone || scroll_h && Math::abs(drag_accum.x) > deadzone || scroll_v && Math::abs(drag_accum.y) > deadzone) { + if (beyond_deadzone || (scroll_h && Math::abs(drag_accum.x) > deadzone) || (scroll_v && Math::abs(drag_accum.y) > deadzone)) { if (!beyond_deadzone) { propagate_notification(NOTIFICATION_SCROLL_BEGIN); emit_signal("scroll_started"); diff --git a/scene/gui/shortcut.cpp b/scene/gui/shortcut.cpp index 36490cf254..6fcf96f611 100644 --- a/scene/gui/shortcut.cpp +++ b/scene/gui/shortcut.cpp @@ -30,7 +30,7 @@ #include "shortcut.h" -#include "os/keyboard.h" +#include "core/os/keyboard.h" void ShortCut::set_shortcut(const Ref<InputEvent> &p_shortcut) { diff --git a/scene/gui/shortcut.h b/scene/gui/shortcut.h index f9240642bf..7613a24e43 100644 --- a/scene/gui/shortcut.h +++ b/scene/gui/shortcut.h @@ -31,8 +31,8 @@ #ifndef SHORTCUT_H #define SHORTCUT_H -#include "os/input_event.h" -#include "resource.h" +#include "core/os/input_event.h" +#include "core/resource.h" class ShortCut : public Resource { diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index b820e2eafd..147c0518ec 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "slider.h" -#include "os/keyboard.h" +#include "core/os/keyboard.h" Size2 Slider::get_minimum_size() const { diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 145981d498..f766c0722d 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -29,7 +29,7 @@ /*************************************************************************/ #include "spin_box.h" -#include "os/input.h" +#include "core/os/input.h" Size2 SpinBox::get_minimum_size() const { @@ -217,6 +217,16 @@ void SpinBox::_notification(int p_what) { } } +void SpinBox::set_align(LineEdit::Align p_align) { + + line_edit->set_align(p_align); +} + +LineEdit::Align SpinBox::get_align() const { + + return line_edit->get_align(); +} + void SpinBox::set_suffix(const String &p_suffix) { suffix = p_suffix; @@ -253,6 +263,8 @@ 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); ClassDB::bind_method(D_METHOD("get_suffix"), &SpinBox::get_suffix); ClassDB::bind_method(D_METHOD("set_prefix", "prefix"), &SpinBox::set_prefix); @@ -264,6 +276,7 @@ void SpinBox::_bind_methods() { 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_PROPERTYNZ(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"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "prefix"), "set_prefix", "get_prefix"); ADD_PROPERTY(PropertyInfo(Variant::STRING, "suffix"), "set_suffix", "get_suffix"); diff --git a/scene/gui/spin_box.h b/scene/gui/spin_box.h index 8863f44bef..f1ee26d9f3 100644 --- a/scene/gui/spin_box.h +++ b/scene/gui/spin_box.h @@ -76,6 +76,9 @@ public: virtual Size2 get_minimum_size() const; + void set_align(LineEdit::Align p_align); + LineEdit::Align get_align() const; + void set_editable(bool p_editable); bool is_editable() const; diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index c30fa96327..4c354768fe 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -30,7 +30,7 @@ #include "tab_container.h" -#include "message_queue.h" +#include "core/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/tabs.cpp b/scene/gui/tabs.cpp index 2075f7ce70..c56b7d0f26 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -30,7 +30,7 @@ #include "tabs.h" -#include "message_queue.h" +#include "core/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 ec98b01ced..c390c60a8c 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -30,11 +30,11 @@ #include "text_edit.h" -#include "message_queue.h" -#include "os/input.h" -#include "os/keyboard.h" -#include "os/os.h" -#include "project_settings.h" +#include "core/message_queue.h" +#include "core/os/input.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" +#include "core/project_settings.h" #include "scene/main/viewport.h" #ifdef TOOLS_ENABLED @@ -556,7 +556,6 @@ void TextEdit::_notification(int p_what) { } break; case NOTIFICATION_RESIZED: { - cache.size = get_size(); _update_scrollbars(); update_wrap_at(); } break; @@ -593,6 +592,7 @@ void TextEdit::_notification(int p_what) { } } break; case NOTIFICATION_DRAW: { + Size2 size = get_size(); if ((!has_focus() && !menu->has_focus()) || !window_has_focus) { draw_caret = false; } @@ -634,24 +634,22 @@ void TextEdit::_notification(int p_what) { RID ci = get_canvas_item(); VisualServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true); int xmargin_beg = cache.style_normal->get_margin(MARGIN_LEFT) + cache.line_number_w + cache.breakpoint_gutter_width + cache.fold_gutter_width; - int xmargin_end = cache.size.width - cache.style_normal->get_margin(MARGIN_RIGHT); + int xmargin_end = size.width - cache.style_normal->get_margin(MARGIN_RIGHT); //let's do it easy for now: - cache.style_normal->draw(ci, Rect2(Point2(), cache.size)); + cache.style_normal->draw(ci, Rect2(Point2(), size)); float readonly_alpha = 1.0; // used to set the input text color when in read-only mode if (readonly) { - cache.style_readonly->draw(ci, Rect2(Point2(), cache.size)); + cache.style_readonly->draw(ci, Rect2(Point2(), size)); readonly_alpha = .5; draw_caret = false; } if (has_focus()) - cache.style_focus->draw(ci, Rect2(Point2(), cache.size)); + cache.style_focus->draw(ci, Rect2(Point2(), size)); int ascent = cache.font->get_ascent(); int visible_rows = get_visible_rows() + 1; - int tab_w = cache.font->get_char_size(' ').width * indent_size; - Color color = cache.font_color; color.a *= readonly_alpha; @@ -1261,7 +1259,7 @@ void TextEdit::_notification(int p_what) { if (line_length_guideline) { int x = xmargin_beg + 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, cache.size.height), cache.line_length_guideline_color); + VisualServer::get_singleton()->canvas_item_add_line(ci, Point2(x, 0), Point2(x, size.height), cache.line_length_guideline_color); } } @@ -1942,7 +1940,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { int to_column = get_selection_to_column(); if (row < from_line || row > to_line || (row == from_line && col < from_column) || (row == to_line && col > to_column)) { - // Right click is outside the seleted text + // Right click is outside the selected text deselect(); } } @@ -3119,16 +3117,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (selection.active) { int ini = selection.from_line; int end = selection.to_line; + for (int i = ini; i <= end; i++) { - if (get_line(i).begins_with("#")) - _remove_text(i, 0, i, 1); + _uncomment_line(i); } } else { - if (get_line(cursor.line).begins_with("#")) { - _remove_text(cursor.line, 0, cursor.line, 1); - if (cursor.column >= get_line(cursor.line).length()) { - cursor.column = MAX(0, get_line(cursor.line).length() - 1); - } + _uncomment_line(cursor.line); + if (cursor.column >= get_line(cursor.line).length()) { + cursor.column = MAX(0, get_line(cursor.line).length() - 1); } } update(); @@ -3208,6 +3204,24 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } } +void TextEdit::_uncomment_line(int p_line) { + String line_text = get_line(p_line); + for (int i = 0; i < line_text.length(); i++) { + if (line_text[i] == '#') { + _remove_text(p_line, i, p_line, i + 1); + if (p_line == selection.to_line && selection.to_column > line_text.length() - 1) { + selection.to_column -= 1; + if (selection.to_column >= selection.from_column) { + selection.active = false; + } + } + return; + } else if (line_text[i] != '\t' && line_text[i] != ' ') { + return; + } + } +} + void TextEdit::_scroll_up(real_t p_delta) { if (scrolling && smooth_scroll_enabled && SGN(target_v_scroll - v_scroll->get_value()) != SGN(-p_delta)) @@ -3609,7 +3623,7 @@ Size2 TextEdit::get_minimum_size() const { int TextEdit::get_visible_rows() const { - int total = cache.size.height; + int total = get_size().height; total -= cache.style_normal->get_minimum_size().height; if (h_scroll->is_visible_in_tree()) total -= h_scroll->get_size().height; @@ -3636,7 +3650,7 @@ int TextEdit::get_total_visible_rows() const { void TextEdit::update_wrap_at() { - wrap_at = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - wrap_right_offset; + wrap_at = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width - wrap_right_offset; update_cursor_wrap_offset(); text.clear_wrap_cache(); @@ -3670,7 +3684,7 @@ void TextEdit::adjust_viewport_to_cursor() { set_line_as_last_visible(cur_line, cur_wrap); } - int visible_width = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width; + int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width; if (v_scroll->is_visible_in_tree()) visible_width -= v_scroll->get_combined_minimum_size().width; visible_width -= 20; // give it a little more space @@ -3701,7 +3715,7 @@ void TextEdit::center_viewport_to_cursor() { unfold_line(cursor.line); set_line_as_center_visible(cursor.line, get_cursor_wrap_index()); - int visible_width = cache.size.width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width; + int visible_width = get_size().width - cache.style_normal->get_minimum_size().width - cache.line_number_w - cache.breakpoint_gutter_width - cache.fold_gutter_width; if (v_scroll->is_visible_in_tree()) visible_width -= v_scroll->get_combined_minimum_size().width; visible_width -= 20; // give it a little more space @@ -3780,7 +3794,7 @@ Vector<String> TextEdit::get_wrap_rows_text(int p_line) const { int tab_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width; while (col < line_text.length()) { - char c = line_text[col]; + CharType c = line_text[col]; int w = text.get_char_width(c, line_text[col + 1], px + word_px); int indent_ofs = (cur_wrap_index != 0 ? tab_offset_px : 0); @@ -4158,7 +4172,7 @@ Control::CursorShape TextEdit::get_cursor_shape(const Point2 &p_pos) const { } } - return CURSOR_IBEAM; + return get_default_cursor_shape(); } void TextEdit::set_text(String p_text) { @@ -4386,7 +4400,7 @@ int TextEdit::_is_line_in_region(int p_line) { // if not find the closest line we have int previous_line = p_line - 1; - for (previous_line; previous_line > -1; previous_line--) { + for (; previous_line > -1; previous_line--) { if (color_region_cache.has(p_line)) { break; } @@ -4531,9 +4545,13 @@ void TextEdit::cut() { void TextEdit::copy() { if (!selection.active) { - String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length()); - OS::get_singleton()->set_clipboard(clipboard); - cut_copy_line = clipboard; + + if (text[cursor.line].length() != 0) { + + String clipboard = _base_get_text(cursor.line, 0, cursor.line, text[cursor.line].length()); + OS::get_singleton()->set_clipboard(clipboard); + cut_copy_line = clipboard; + } } else { String clipboard = _base_get_text(selection.from_line, selection.from_column, selection.to_line, selection.to_column); OS::get_singleton()->set_clipboard(clipboard); @@ -4822,28 +4840,27 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l pos = -1; - int pos_from = 0; + int pos_from = (p_search_flags & SEARCH_BACKWARDS) ? text_line.length() : 0; int last_pos = -1; while (true) { - while ((last_pos = (p_search_flags & SEARCH_MATCH_CASE) ? text_line.find(p_key, pos_from) : text_line.findn(p_key, pos_from)) != -1) { - - if (p_search_flags & SEARCH_BACKWARDS) { - - if (last_pos > from_column) + if (p_search_flags & SEARCH_BACKWARDS) { + while ((last_pos = (p_search_flags & SEARCH_MATCH_CASE) ? text_line.rfind(p_key, pos_from) : text_line.rfindn(p_key, pos_from)) != -1) { + if (last_pos <= from_column) { + pos = last_pos; break; - pos = last_pos; - - } else { - + } + pos_from = last_pos - p_key.length(); + } + } else { + while ((last_pos = (p_search_flags & SEARCH_MATCH_CASE) ? text_line.find(p_key, pos_from) : text_line.findn(p_key, pos_from)) != -1) { if (last_pos >= from_column) { pos = last_pos; break; } + pos_from = last_pos + p_key.length(); } - - pos_from = last_pos + p_key.length(); } bool is_match = true; @@ -4856,11 +4873,15 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l is_match = false; } + if (pos_from == -1) { + pos = -1; + } + if (is_match || last_pos == -1 || pos == -1) { break; } - pos_from = pos + 1; + pos_from = (p_search_flags & SEARCH_BACKWARDS) ? pos - 1 : pos + 1; pos = -1; } @@ -5133,7 +5154,7 @@ bool TextEdit::can_fold(int p_line) const { return false; if (p_line + 1 >= text.size()) return false; - if (text[p_line].size() == 0) + if (text[p_line].strip_edges().size() == 0) return false; if (is_folded(p_line)) return false; @@ -5145,7 +5166,7 @@ bool TextEdit::can_fold(int p_line) const { int start_indent = get_indent_level(p_line); for (int i = p_line + 1; i < text.size(); i++) { - if (text[i].size() == 0) + if (text[i].strip_edges().size() == 0) continue; int next_indent = get_indent_level(i); if (is_line_comment(i)) { @@ -5543,7 +5564,7 @@ int TextEdit::get_last_visible_line_wrap_index() const { double TextEdit::get_visible_rows_offset() const { - double total = cache.size.height; + double total = get_size().height; total -= cache.style_normal->get_minimum_size().height; if (h_scroll->is_visible_in_tree()) total -= h_scroll->get_size().height; @@ -5847,7 +5868,7 @@ String TextEdit::get_word_at_pos(const Vector2 &p_pos) const { if (select_word(s, col, beg, end)) { bool inside_quotes = false; - char selected_quote = '\0'; + CharType selected_quote = '\0'; int qbegin = 0, qend = 0; for (int i = 0; i < s.length(); i++) { if (s[i] == '"' || s[i] == '\'') { @@ -5910,6 +5931,9 @@ void TextEdit::set_line(int line, String new_text) { if (cursor.line == line) { cursor.column = MIN(cursor.column, new_text.length()); } + if (is_selection_active() && line == selection.to_line && selection.to_column > text[line].length()) { + selection.to_column = text[line].length(); + } } void TextEdit::insert_at(const String &p_text, int at) { @@ -6227,7 +6251,6 @@ TextEdit::TextEdit() { set_focus_mode(FOCUS_ALL); syntax_highlighter = NULL; _update_caches(); - cache.size = Size2(1, 1); cache.row_height = 1; cache.line_spacing = 1; cache.line_number_w = 1; @@ -6235,6 +6258,7 @@ TextEdit::TextEdit() { breakpoint_gutter_width = 0; cache.fold_gutter_width = 0; fold_gutter_width = 0; + set_default_cursor_shape(CURSOR_IBEAM); indent_size = 4; text.set_indent_size(indent_size); @@ -6400,8 +6424,8 @@ Map<int, TextEdit::HighlighterInfo> TextEdit::_get_line_syntax_highlighting(int is_hex_notation = false; } - // check for dot or underscore or 'x' for hex notation in floating point number - if ((str[j] == '.' || str[j] == 'x' || str[j] == '_' || str[j] == 'f') && !in_word && prev_is_number && !is_number) { + // check for dot or underscore or 'x' for hex notation in floating point number or 'e' for scientific notation + if ((str[j] == '.' || str[j] == 'x' || str[j] == '_' || str[j] == 'f' || str[j] == 'e') && !in_word && prev_is_number && !is_number) { is_number = true; is_symbol = false; is_char = false; diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 19b5d574c6..f0c18ad047 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -193,7 +193,6 @@ private: int line_number_w; int breakpoint_gutter_width; int fold_gutter_width; - Size2 size; } cache; Map<int, int> color_region_cache; @@ -373,6 +372,7 @@ private: void _update_selection_mode_word(); void _update_selection_mode_line(); + void _uncomment_line(int p_line); void _scroll_up(real_t p_delta); void _scroll_down(real_t p_delta); diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp index 6bd3b26280..413f9dbbe6 100644 --- a/scene/gui/texture_button.cpp +++ b/scene/gui/texture_button.cpp @@ -88,6 +88,9 @@ bool TextureButton::has_point(const Point2 &p_point) const { scale.y = min; ofs -= _texture_region.position / min; } break; + default: { + // FIXME: Why a switch if we only handle one enum value? + } } // offset and scale the new point position to adjust it to the bitmask size @@ -147,6 +150,7 @@ void TextureButton::_notification(int p_what) { } else texdraw = hover; } break; + case DRAW_HOVER_PRESSED: break; // Not used in this class case DRAW_DISABLED: { if (disabled.is_null()) { diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp index ff90576c1b..d28b4065fb 100644 --- a/scene/gui/texture_progress.cpp +++ b/scene/gui/texture_progress.cpp @@ -30,7 +30,7 @@ #include "texture_progress.h" -#include "engine.h" +#include "core/engine.h" void TextureProgress::set_under_texture(const Ref<Texture> &p_texture) { @@ -229,6 +229,17 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, F first_section_size = topleft.y; last_section_size = bottomright.y; } break; + case FILL_BILINEAR_LEFT_AND_RIGHT: { + // TODO: Implement + } break; + case FILL_BILINEAR_TOP_AND_BOTTOM: { + // TODO: Implement + } break; + case FILL_CLOCKWISE: + case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: + case FILL_COUNTER_CLOCKWISE: { + // Those modes are circular, not relevant for nine patch + } break; } double width_filled = width_total * p_ratio; @@ -263,6 +274,17 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, F dst_rect.size.y = width_filled; topleft.y = last_section_size; } break; + case FILL_BILINEAR_LEFT_AND_RIGHT: { + // TODO: Implement + } break; + case FILL_BILINEAR_TOP_AND_BOTTOM: { + // TODO: Implement + } break; + case FILL_CLOCKWISE: + case FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE: + case FILL_COUNTER_CLOCKWISE: { + // Those modes are circular, not relevant for nine patch + } break; } } @@ -466,9 +488,9 @@ void TextureProgress::_bind_methods() { ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_progress", PROPERTY_HINT_RESOURCE_TYPE, "Texture"), "set_progress_texture", "get_progress_texture"); ADD_PROPERTYNZ(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", PROPERTY_HINT_COLOR_NO_ALPHA), "set_tint_under", "get_tint_under"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_over", PROPERTY_HINT_COLOR_NO_ALPHA), "set_tint_over", "get_tint_over"); - ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_progress", PROPERTY_HINT_COLOR_NO_ALPHA), "set_tint_progress", "get_tint_progress"); + 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_PROPERTYNZ(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_PROPERTYNZ(PropertyInfo(Variant::REAL, "radial_fill_degrees", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_fill_degrees", "get_fill_degrees"); diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 6f09488b64..3a540d187b 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -31,12 +31,12 @@ #include "tree.h" #include <limits.h> -#include "math_funcs.h" -#include "os/input.h" -#include "os/keyboard.h" -#include "os/os.h" -#include "print_string.h" -#include "project_settings.h" +#include "core/math/math_funcs.h" +#include "core/os/input.h" +#include "core/os/keyboard.h" +#include "core/os/os.h" +#include "core/print_string.h" +#include "core/project_settings.h" #include "scene/main/viewport.h" #ifdef TOOLS_ENABLED @@ -159,7 +159,7 @@ void TreeItem::set_text(int p_column, String p_text) { ERR_FAIL_INDEX(p_column, cells.size()); cells.write[p_column].text = p_text; - if (cells[p_column].mode == TreeItem::CELL_MODE_RANGE || cells[p_column].mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) { + if (cells[p_column].mode == TreeItem::CELL_MODE_RANGE) { Vector<String> strings = p_text.split(","); cells.write[p_column].min = INT_MAX; @@ -791,7 +791,6 @@ void TreeItem::_bind_methods() { BIND_ENUM_CONSTANT(CELL_MODE_STRING); BIND_ENUM_CONSTANT(CELL_MODE_CHECK); BIND_ENUM_CONSTANT(CELL_MODE_RANGE); - BIND_ENUM_CONSTANT(CELL_MODE_RANGE_EXPRESSION); BIND_ENUM_CONSTANT(CELL_MODE_ICON); BIND_ENUM_CONSTANT(CELL_MODE_CUSTOM); @@ -1245,9 +1244,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 //font->draw( ci, text_pos, p_item->cells[i].text, col,item_rect.size.x-check_w ); } break; - case TreeItem::CELL_MODE_RANGE: - case TreeItem::CELL_MODE_RANGE_EXPRESSION: { - + case TreeItem::CELL_MODE_RANGE: { if (p_item->cells[i].text != "") { if (!p_item->cells[i].editable) @@ -1257,13 +1254,13 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 String s = RTR("(Other)"); Vector<String> strings = p_item->cells[i].text.split(","); - for (int i = 0; i < strings.size(); i++) { - int value = i; - if (!strings[i].get_slicec(':', 1).empty()) { - value = strings[i].get_slicec(':', 1).to_int(); + for (int j = 0; j < strings.size(); j++) { + int value = j; + if (!strings[j].get_slicec(':', 1).empty()) { + value = strings[j].get_slicec(':', 1).to_int(); } if (option == value) { - s = strings[i].get_slicec(':', 0); + s = strings[j].get_slicec(':', 0); break; } } @@ -1419,7 +1416,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2 while (c) { - if (cache.draw_relationship_lines == 1) { + if (cache.draw_relationship_lines == 1 && (c->get_parent() != root || !hide_root)) { int root_ofs = children_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); int parent_ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin); Point2i root_pos = Point2i(root_ofs, children_pos.y + label_h / 2) - cache.offset + p_draw_ofs; @@ -1721,7 +1718,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool if (p_button == BUTTON_LEFT || (p_button == BUTTON_RIGHT && allow_rmb_select)) { /* process selection */ - if (p_doubleclick && (!c.editable || c.mode == TreeItem::CELL_MODE_CUSTOM || c.mode == TreeItem::CELL_MODE_ICON /*|| c.mode==TreeItem::CELL_MODE_CHECK*/)) { //it' s confusing for check + if (p_doubleclick && (!c.editable || c.mode == TreeItem::CELL_MODE_CUSTOM || c.mode == TreeItem::CELL_MODE_ICON /*|| c.mode==TreeItem::CELL_MODE_CHECK*/)) { //it's confusing for check emit_signal("item_activated"); incr_search.clear(); @@ -1821,9 +1818,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, bool //p_item->edited_signal.call(col); } break; - case TreeItem::CELL_MODE_RANGE: - case TreeItem::CELL_MODE_RANGE_EXPRESSION: { - + case TreeItem::CELL_MODE_RANGE: { if (c.text != "") { //if (x >= (get_column_width(col)-item_h/2)) { @@ -2010,21 +2005,6 @@ void Tree::text_editor_enter(String p_text) { //popup_edited_item->edited_signal.call( popup_edited_item_col ); } break; - case TreeItem::CELL_MODE_RANGE_EXPRESSION: { - - if (evaluator) - c.val = evaluator->eval(p_text); - else - c.val = p_text.to_double(); - - if (c.step > 0) - c.val = Math::stepify(c.val, c.step); - if (c.val < c.min) - c.val = c.min; - else if (c.val > c.max) - c.val = c.max; - - } break; default: { ERR_FAIL(); } } @@ -2239,13 +2219,13 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { _go_left(); } - } else if (p_event->is_action("ui_up") && p_event->is_pressed()) { + } else if (p_event->is_action("ui_up") && p_event->is_pressed() && !k->get_command()) { if (!cursor_can_exit_tree) accept_event(); _go_up(); - } else if (p_event->is_action("ui_down") && p_event->is_pressed()) { + } else if (p_event->is_action("ui_down") && p_event->is_pressed() && !k->get_command()) { if (!cursor_can_exit_tree) accept_event(); @@ -2453,7 +2433,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { update(); } - if (pressing_for_editor && popup_edited_item && (popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE || popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE_EXPRESSION)) { + if (pressing_for_editor && popup_edited_item && (popup_edited_item->get_cell_mode(popup_edited_item_col) == TreeItem::CELL_MODE_RANGE)) { //range drag if (!range_drag_enabled) { @@ -2697,7 +2677,7 @@ bool Tree::edit_selected() { item_edited(col, s); return true; - } else if ((c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) && c.text != "") { + } else if (c.mode == TreeItem::CELL_MODE_RANGE && c.text != "") { popup_menu->clear(); for (int i = 0; i < c.text.get_slice_count(","); i++) { @@ -2713,7 +2693,7 @@ bool Tree::edit_selected() { popup_edited_item_col = col; return true; - } else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) { + } else if (c.mode == TreeItem::CELL_MODE_STRING || c.mode == TreeItem::CELL_MODE_RANGE) { Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2); Point2i textedpos = get_global_position() + rect.position - ofs; @@ -2723,7 +2703,7 @@ bool Tree::edit_selected() { text_editor->set_text(c.mode == TreeItem::CELL_MODE_STRING ? c.text : String::num(c.val, Math::step_decimals(c.step))); text_editor->select_all(); - if (c.mode == TreeItem::CELL_MODE_RANGE || c.mode == TreeItem::CELL_MODE_RANGE_EXPRESSION) { + if (c.mode == TreeItem::CELL_MODE_RANGE) { value_editor->set_position(textedpos + Point2i(0, text_editor->get_size().height)); value_editor->set_size(Size2(rect.size.width, 1)); @@ -3713,10 +3693,6 @@ bool Tree::is_folding_hidden() const { return hide_folding; } -void Tree::set_value_evaluator(ValueEvaluator *p_evaluator) { - evaluator = p_evaluator; -} - void Tree::set_drop_mode_flags(int p_flags) { if (drop_mode_flags == p_flags) return; @@ -3831,16 +3807,16 @@ void Tree::_bind_methods() { ADD_SIGNAL(MethodInfo("item_selected")); ADD_SIGNAL(MethodInfo("cell_selected")); - ADD_SIGNAL(MethodInfo("multi_selected", PropertyInfo(Variant::OBJECT, "item"), PropertyInfo(Variant::INT, "column"), PropertyInfo(Variant::BOOL, "selected"))); + ADD_SIGNAL(MethodInfo("multi_selected", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "TreeItem"), PropertyInfo(Variant::INT, "column"), PropertyInfo(Variant::BOOL, "selected"))); ADD_SIGNAL(MethodInfo("item_rmb_selected", PropertyInfo(Variant::VECTOR2, "position"))); ADD_SIGNAL(MethodInfo("empty_tree_rmb_selected", PropertyInfo(Variant::VECTOR2, "position"))); ADD_SIGNAL(MethodInfo("item_edited")); ADD_SIGNAL(MethodInfo("item_rmb_edited")); ADD_SIGNAL(MethodInfo("item_custom_button_pressed")); ADD_SIGNAL(MethodInfo("item_double_clicked")); - ADD_SIGNAL(MethodInfo("item_collapsed", PropertyInfo(Variant::OBJECT, "item"))); + ADD_SIGNAL(MethodInfo("item_collapsed", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "TreeItem"))); //ADD_SIGNAL( MethodInfo("item_doubleclicked" ) ); - ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::OBJECT, "item"), PropertyInfo(Variant::INT, "column"), PropertyInfo(Variant::INT, "id"))); + ADD_SIGNAL(MethodInfo("button_pressed", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "TreeItem"), PropertyInfo(Variant::INT, "column"), PropertyInfo(Variant::INT, "id"))); ADD_SIGNAL(MethodInfo("custom_popup_edited", PropertyInfo(Variant::BOOL, "arrow_clicked"))); ADD_SIGNAL(MethodInfo("item_activated")); ADD_SIGNAL(MethodInfo("column_title_pressed", PropertyInfo(Variant::INT, "column"))); @@ -3934,8 +3910,6 @@ Tree::Tree() { hide_folding = false; - evaluator = NULL; - drop_mode_flags = 0; drop_mode_over = NULL; drop_mode_section = 0; diff --git a/scene/gui/tree.h b/scene/gui/tree.h index 5af66c5faa..34138acb85 100644 --- a/scene/gui/tree.h +++ b/scene/gui/tree.h @@ -31,7 +31,6 @@ #ifndef TREE_H #define TREE_H -#include "core/helper/value_evaluator.h" #include "scene/gui/control.h" #include "scene/gui/line_edit.h" #include "scene/gui/popup_menu.h" @@ -54,7 +53,6 @@ public: CELL_MODE_STRING, ///< just a string CELL_MODE_CHECK, ///< string + check CELL_MODE_RANGE, ///< Contains a range - CELL_MODE_RANGE_EXPRESSION, ///< Contains a range CELL_MODE_ICON, ///< Contains an icon, not editable CELL_MODE_CUSTOM, ///< Contains a custom value, show a string, and an edit button }; @@ -504,8 +502,6 @@ private: bool hide_folding; - ValueEvaluator *evaluator; - int _count_selected_items(TreeItem *p_from) const; void _go_left(); void _go_right(); @@ -516,7 +512,7 @@ protected: static void _bind_methods(); //bind helpers - Object *_create_item(Object *p_parent, int p_idx = -1) { + TreeItem *_create_item(Object *p_parent, int p_idx = -1) { return create_item(Object::cast_to<TreeItem>(p_parent), p_idx); } @@ -601,8 +597,6 @@ public: void set_allow_reselect(bool p_allow); bool get_allow_reselect() const; - void set_value_evaluator(ValueEvaluator *p_evaluator); - Tree(); ~Tree(); }; diff --git a/scene/gui/video_player.cpp b/scene/gui/video_player.cpp index 88e1847533..39e7c73390 100644 --- a/scene/gui/video_player.cpp +++ b/scene/gui/video_player.cpp @@ -31,7 +31,7 @@ #include "video_player.h" #include "scene/scene_string_names.h" -#include "os/os.h" +#include "core/os/os.h" #include "servers/audio_server.h" int VideoPlayer::sp_get_channel_count() const { @@ -102,6 +102,10 @@ void VideoPlayer::_mix_audio() { } } break; + case AudioServer::SPEAKER_SURROUND_31: { + + // FIXME: Implement + } break; case AudioServer::SPEAKER_SURROUND_51: { AudioFrame *targets[2] = { |