summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/button.cpp6
-rw-r--r--scene/gui/color_picker.cpp2
-rw-r--r--scene/gui/container.cpp13
-rw-r--r--scene/gui/container.h2
-rw-r--r--scene/gui/control.cpp91
-rw-r--r--scene/gui/control.h5
-rw-r--r--scene/gui/file_dialog.cpp3
-rw-r--r--scene/gui/gradient_edit.h2
-rw-r--r--scene/gui/graph_edit.cpp31
-rw-r--r--scene/gui/graph_node.cpp6
-rw-r--r--scene/gui/item_list.cpp12
-rw-r--r--scene/gui/line_edit.cpp14
-rw-r--r--scene/gui/link_button.h2
-rw-r--r--scene/gui/option_button.cpp7
-rw-r--r--scene/gui/option_button.h1
-rw-r--r--scene/gui/popup.cpp35
-rw-r--r--scene/gui/popup_menu.cpp10
-rw-r--r--scene/gui/progress_bar.cpp9
-rw-r--r--scene/gui/rich_text_label.cpp35
-rw-r--r--scene/gui/rich_text_label.h2
-rw-r--r--scene/gui/scroll_container.cpp6
-rw-r--r--scene/gui/split_container.cpp41
-rw-r--r--scene/gui/text_edit.cpp155
-rw-r--r--scene/gui/text_edit.h1
-rw-r--r--scene/gui/texture_button.cpp13
-rw-r--r--scene/gui/texture_button.h2
-rw-r--r--scene/gui/texture_progress.cpp17
-rw-r--r--scene/gui/tree.cpp34
28 files changed, 285 insertions, 272 deletions
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index b77b57ddd4..65e9cccd05 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "button.h"
+
#include "core/translation.h"
#include "servers/visual_server.h"
@@ -102,6 +103,7 @@ void Button::_notification(int p_what) {
break;
}
+ FALLTHROUGH;
}
case DRAW_PRESSED: {
@@ -140,8 +142,8 @@ void Button::_notification(int p_what) {
if (has_focus()) {
- Ref<StyleBox> style = get_stylebox("focus");
- style->draw(ci, Rect2(Point2(), size));
+ Ref<StyleBox> style2 = get_stylebox("focus");
+ style2->draw(ci, Rect2(Point2(), size));
}
Ref<Font> font = get_font("font");
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 4b1c7b3db7..7aca6acd00 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -737,7 +737,7 @@ ColorPicker::ColorPicker() :
bt_add_preset = memnew(Button);
bbc->add_child(bt_add_preset);
- bt_add_preset->set_tooltip(TTR("Add current color as a preset"));
+ bt_add_preset->set_tooltip(TTR("Add current color as a preset."));
bt_add_preset->connect("pressed", this, "_add_preset_pressed");
}
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index 2579321773..7f1ca58d58 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -169,6 +169,19 @@ void Container::_notification(int p_what) {
}
}
+String Container::get_configuration_warning() const {
+
+ String warning = Control::get_configuration_warning();
+
+ if (get_class() == "Container" && get_script().is_null()) {
+ if (warning != String()) {
+ warning += "\n";
+ }
+ warning += TTR("Container by itself serves no purpose unless a script configures it's children placement behavior.\nIf you dont't intend to add a script, then please use a plain 'Control' node instead.");
+ }
+ return warning;
+}
+
void Container::_bind_methods() {
ClassDB::bind_method(D_METHOD("_sort_children"), &Container::_sort_children);
diff --git a/scene/gui/container.h b/scene/gui/container.h
index 0b014137f4..80d3f6ee5d 100644
--- a/scene/gui/container.h
+++ b/scene/gui/container.h
@@ -57,6 +57,8 @@ public:
void fit_child_in_rect(Control *p_child, const Rect2 &p_rect);
+ virtual String get_configuration_warning() const;
+
Container();
};
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index 513befb8f3..c7cd2bb6d8 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -206,65 +206,62 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
if (name.begins_with("custom_icons/")) {
String dname = name.get_slicec('/', 1);
+ if (data.icon_override.has(dname)) {
+ data.icon_override[dname]->disconnect("changed", this, "_override_changed");
+ }
data.icon_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- update();
} else if (name.begins_with("custom_shaders/")) {
String dname = name.get_slicec('/', 1);
+ if (data.shader_override.has(dname)) {
+ data.shader_override[dname]->disconnect("changed", this, "_override_changed");
+ }
data.shader_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- update();
} else if (name.begins_with("custom_styles/")) {
String dname = name.get_slicec('/', 1);
+ if (data.style_override.has(dname)) {
+ data.style_override[dname]->disconnect("changed", this, "_override_changed");
+ }
data.style_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- update();
} else if (name.begins_with("custom_fonts/")) {
String dname = name.get_slicec('/', 1);
if (data.font_override.has(dname)) {
- _unref_font(data.font_override[dname]);
+ data.font_override[dname]->disconnect("changed", this, "_override_changed");
}
data.font_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- update();
} else if (name.begins_with("custom_colors/")) {
String dname = name.get_slicec('/', 1);
data.color_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- update();
} else if (name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
data.constant_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- update();
} else
return false;
} else {
if (name.begins_with("custom_icons/")) {
String dname = name.get_slicec('/', 1);
- notification(NOTIFICATION_THEME_CHANGED);
add_icon_override(dname, p_value);
} else if (name.begins_with("custom_shaders/")) {
String dname = name.get_slicec('/', 1);
add_shader_override(dname, p_value);
- notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_styles/")) {
String dname = name.get_slicec('/', 1);
add_style_override(dname, p_value);
- notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_fonts/")) {
String dname = name.get_slicec('/', 1);
add_font_override(dname, p_value);
- notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_colors/")) {
String dname = name.get_slicec('/', 1);
add_color_override(dname, p_value);
- notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_constants/")) {
String dname = name.get_slicec('/', 1);
add_constant_override(dname, p_value);
- notification(NOTIFICATION_THEME_CHANGED);
} else
return false;
}
@@ -1391,7 +1388,10 @@ void Control::set_anchor(Margin p_margin, float p_anchor, bool p_keep_margin, bo
}
update();
- _change_notify("anchor");
+ _change_notify("anchor_left");
+ _change_notify("anchor_right");
+ _change_notify("anchor_top");
+ _change_notify("anchor_bottom");
}
void Control::_set_anchor(Margin p_margin, float p_anchor) {
@@ -1800,51 +1800,63 @@ Rect2 Control::get_anchorable_rect() const {
void Control::add_icon_override(const StringName &p_name, const Ref<Texture> &p_icon) {
ERR_FAIL_COND(p_icon.is_null());
+ if (data.icon_override.has(p_name)) {
+ data.icon_override[p_name]->disconnect("changed", this, "_override_changed");
+ }
data.icon_override[p_name] = p_icon;
+ if (data.icon_override[p_name].is_valid()) {
+ data.icon_override[p_name]->connect("changed", this, "_override_changed", Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
+ }
notification(NOTIFICATION_THEME_CHANGED);
- update();
}
void Control::add_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) {
ERR_FAIL_COND(p_shader.is_null());
+ if (data.shader_override.has(p_name)) {
+ data.shader_override[p_name]->disconnect("changed", this, "_override_changed");
+ }
data.shader_override[p_name] = p_shader;
+ if (data.shader_override[p_name].is_valid()) {
+ data.shader_override[p_name]->connect("changed", this, "_override_changed", Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
+ }
notification(NOTIFICATION_THEME_CHANGED);
- update();
}
void Control::add_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
ERR_FAIL_COND(p_style.is_null());
+ if (data.style_override.has(p_name)) {
+ data.style_override[p_name]->disconnect("changed", this, "_override_changed");
+ }
data.style_override[p_name] = p_style;
+ if (data.style_override[p_name].is_valid()) {
+ data.style_override[p_name]->connect("changed", this, "_override_changed", Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
+ }
+
notification(NOTIFICATION_THEME_CHANGED);
- update();
}
void Control::add_font_override(const StringName &p_name, const Ref<Font> &p_font) {
ERR_FAIL_COND(p_font.is_null());
if (data.font_override.has(p_name)) {
- _unref_font(data.font_override[p_name]);
+ data.font_override[p_name]->disconnect("changed", this, "_override_changed");
}
data.font_override[p_name] = p_font;
-
- if (p_font.is_valid()) {
- _ref_font(p_font);
+ if (data.font_override[p_name].is_valid()) {
+ data.font_override[p_name]->connect("changed", this, "_override_changed", Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
}
notification(NOTIFICATION_THEME_CHANGED);
- update();
}
void Control::add_color_override(const StringName &p_name, const Color &p_color) {
data.color_override[p_name] = p_color;
notification(NOTIFICATION_THEME_CHANGED);
- update();
}
void Control::add_constant_override(const StringName &p_name, int p_constant) {
data.constant_override[p_name] = p_constant;
notification(NOTIFICATION_THEME_CHANGED);
- update();
}
void Control::set_focus_mode(FocusMode p_focus_mode) {
@@ -2143,7 +2155,6 @@ void Control::_propagate_theme_changed(CanvasItem *p_at, Control *p_owner, bool
c->data.theme_owner = p_owner;
}
c->notification(NOTIFICATION_THEME_CHANGED);
- c->update();
}
}
@@ -2550,32 +2561,10 @@ float Control::get_rotation_degrees() const {
return Math::rad2deg(get_rotation());
}
-//needed to update the control if the font changes..
-void Control::_ref_font(Ref<Font> p_sc) {
+void Control::_override_changed() {
- if (!data.font_refcount.has(p_sc)) {
- data.font_refcount[p_sc] = 1;
- p_sc->connect("changed", this, "_font_changed");
- } else {
- data.font_refcount[p_sc] += 1;
- }
-}
-
-void Control::_unref_font(Ref<Font> p_sc) {
-
- ERR_FAIL_COND(!data.font_refcount.has(p_sc));
- data.font_refcount[p_sc]--;
- if (data.font_refcount[p_sc] == 0) {
- p_sc->disconnect("changed", this, "_font_changed");
- data.font_refcount.erase(p_sc);
- }
-}
-
-void Control::_font_changed() {
-
- update();
notification(NOTIFICATION_THEME_CHANGED);
- minimum_size_changed(); //fonts affect minimum size pretty much almost always
+ minimum_size_changed(); // overrides are likely to affect minimum size
}
void Control::set_pivot_offset(const Vector2 &p_pivot) {
@@ -2735,7 +2724,7 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_scale"), &Control::get_scale);
ClassDB::bind_method(D_METHOD("get_pivot_offset"), &Control::get_pivot_offset);
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_parent_area_size"), &Control::get_parent_area_size);
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);
@@ -2829,7 +2818,7 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("_theme_changed"), &Control::_theme_changed);
- ClassDB::bind_method(D_METHOD("_font_changed"), &Control::_font_changed);
+ ClassDB::bind_method(D_METHOD("_override_changed"), &Control::_override_changed);
BIND_VMETHOD(MethodInfo("_gui_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
BIND_VMETHOD(MethodInfo(Variant::VECTOR2, "_get_minimum_size"));
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 0812457bd2..5e33f6ba43 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -207,7 +207,6 @@ private:
HashMap<StringName, Ref<Font> > font_override;
HashMap<StringName, Color> color_override;
HashMap<StringName, int> constant_override;
- Map<Ref<Font>, int> font_refcount;
} data;
@@ -234,9 +233,7 @@ private:
void _size_changed();
String _get_tooltip() const;
- void _ref_font(Ref<Font> p_sc);
- void _unref_font(Ref<Font> p_sc);
- void _font_changed();
+ void _override_changed();
void _update_canvas_item_transform();
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index 5599c64daa..059e59ea21 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -861,7 +861,7 @@ FileDialog::FileDialog() {
HBoxContainer *hbc = memnew(HBoxContainer);
dir_up = memnew(ToolButton);
- dir_up->set_tooltip(RTR("Go to parent folder"));
+ dir_up->set_tooltip(RTR("Go to parent folder."));
hbc->add_child(dir_up);
dir_up->connect("pressed", this, "_go_up");
@@ -871,6 +871,7 @@ FileDialog::FileDialog() {
dir->set_h_size_flags(SIZE_EXPAND_FILL);
refresh = memnew(ToolButton);
+ refresh->set_tooltip(RTR("Refresh"));
refresh->connect("pressed", this, "_update_file_list");
hbc->add_child(refresh);
diff --git a/scene/gui/gradient_edit.h b/scene/gui/gradient_edit.h
index fd340b3f6c..662278a17b 100644
--- a/scene/gui/gradient_edit.h
+++ b/scene/gui/gradient_edit.h
@@ -33,8 +33,8 @@
#include "scene/gui/color_picker.h"
#include "scene/gui/popup.h"
-#include "scene/resources/color_ramp.h"
#include "scene/resources/default_theme/theme_data.h"
+#include "scene/resources/gradient.h"
#define POINT_WIDTH (8 * EDSCALE)
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 94c65b3e64..30ad81bb2e 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -221,8 +221,8 @@ void GraphEdit::_graph_node_raised(Node *p_gn) {
}
int first_not_comment = 0;
for (int i = 0; i < get_child_count(); i++) {
- GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (gn && !gn->is_comment()) {
+ GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
+ if (gn2 && !gn2->is_comment()) {
first_not_comment = i;
break;
}
@@ -261,8 +261,9 @@ void GraphEdit::add_child_notify(Node *p_child) {
void GraphEdit::remove_child_notify(Node *p_child) {
Control::remove_child_notify(p_child);
-
- top_layer->call_deferred("raise"); //top layer always on top!
+ if (is_inside_tree()) {
+ top_layer->call_deferred("raise"); //top layer always on top!
+ }
GraphNode *gn = Object::cast_to<GraphNode>(p_child);
if (gn) {
gn->disconnect("offset_changed", this, "_graph_node_moved");
@@ -769,7 +770,9 @@ void GraphEdit::_top_layer_draw() {
}
if (box_selecting)
- top_layer->draw_rect(box_selecting_rect, Color(0.7, 0.7, 1.0, 0.3));
+ top_layer->draw_rect(
+ box_selecting_rect,
+ get_color("accent_color", "Editor") * Color(1, 1, 1, 0.375));
}
void GraphEdit::set_selected(Node *p_child) {
@@ -958,33 +961,33 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn || !gn->is_selected())
+ GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
+ if (!gn2 || !gn2->is_selected())
continue;
- previus_selected.push_back(gn);
+ previus_selected.push_back(gn2);
}
} else if (b->get_shift()) {
box_selection_mode_aditive = false;
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn || !gn->is_selected())
+ GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
+ if (!gn2 || !gn2->is_selected())
continue;
- previus_selected.push_back(gn);
+ previus_selected.push_back(gn2);
}
} else {
box_selection_mode_aditive = true;
previus_selected.clear();
for (int i = get_child_count() - 1; i >= 0; i--) {
- GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
- if (!gn)
+ GraphNode *gn2 = Object::cast_to<GraphNode>(get_child(i));
+ if (!gn2)
continue;
- gn->set_selected(false);
+ gn2->set_selected(false);
}
}
}
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 8c588109d6..e8692d56d2 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -164,7 +164,6 @@ void GraphNode::_resort() {
vofs += size.y;
}
- _change_notify();
update();
connpos_dirty = true;
}
@@ -409,9 +408,12 @@ Size2 GraphNode::get_minimum_size() const {
void GraphNode::set_title(const String &p_title) {
+ if (title == p_title)
+ return;
title = p_title;
- minimum_size_changed();
update();
+ _change_notify("title");
+ minimum_size_changed();
}
String GraphNode::get_title() const {
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index efe452305b..026374ded1 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -1094,7 +1094,7 @@ void ItemList::_notification(int p_what) {
if (items[i].disabled)
modulate.a *= 0.5;
- // If the icon is transposed, we have to swith the size so that it is drawn correctly
+ // If the icon is transposed, we have to switch the size so that it is drawn correctly
if (items[i].icon_transposed) {
Size2 size_tmp = draw_rect.size;
draw_rect.size.x = size_tmp.y;
@@ -1114,13 +1114,13 @@ void ItemList::_notification(int p_what) {
int max_len = -1;
- Vector2 size = font->get_string_size(items[i].text);
+ Vector2 size2 = font->get_string_size(items[i].text);
if (fixed_column_width)
max_len = fixed_column_width;
else if (same_column_width)
max_len = items[i].rect_cache.size.x;
else
- max_len = size.x;
+ max_len = size2.x;
Color modulate = items[i].selected ? font_color_selected : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color);
if (items[i].disabled)
@@ -1170,12 +1170,12 @@ void ItemList::_notification(int p_what) {
} else {
if (fixed_column_width > 0)
- size.x = MIN(size.x, fixed_column_width);
+ size2.x = MIN(size2.x, fixed_column_width);
if (icon_mode == ICON_MODE_TOP) {
- text_ofs.x += (items[i].rect_cache.size.width - size.x) / 2;
+ text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2;
} else {
- text_ofs.y += (items[i].rect_cache.size.height - size.y) / 2;
+ text_ofs.y += (items[i].rect_cache.size.height - size2.y) / 2;
}
text_ofs.y += font->get_ascent();
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 4a2bb3dad1..0c5dc39273 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "line_edit.h"
+
#include "core/message_queue.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
@@ -320,7 +321,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
handled = false;
break;
}
- // numlock disabled. fallthrough to key_left
+ FALLTHROUGH;
}
case KEY_LEFT: {
@@ -367,7 +368,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
handled = false;
break;
}
- // numlock disabled. fallthrough to key_right
+ FALLTHROUGH;
}
case KEY_RIGHT: {
@@ -474,7 +475,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
handled = false;
break;
}
- // numlock disabled. fallthrough to key_home
+ FALLTHROUGH;
}
case KEY_HOME: {
@@ -487,7 +488,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
handled = false;
break;
}
- // numlock disabled. fallthrough to key_end
+ FALLTHROUGH;
}
case KEY_END: {
@@ -1154,9 +1155,7 @@ void LineEdit::set_cursor_position(int p_pos) {
if (cursor_pos <= window_pos) {
/* Adjust window if cursor goes too much to the left */
- if (window_pos > 0)
- set_window_pos(window_pos - 1);
-
+ set_window_pos(MAX(0, cursor_pos - 1));
} else if (cursor_pos > window_pos) {
/* Adjust window if cursor goes too much to the right */
int window_width = get_size().width - style->get_minimum_size().width;
@@ -1225,6 +1224,7 @@ void LineEdit::append_at_cursor(String p_text) {
void LineEdit::clear_internal() {
+ deselect();
_clear_undo_stack();
cached_width = 0;
cursor_pos = 0;
diff --git a/scene/gui/link_button.h b/scene/gui/link_button.h
index ffe248ac5e..17c4bca67b 100644
--- a/scene/gui/link_button.h
+++ b/scene/gui/link_button.h
@@ -32,7 +32,7 @@
#define LINKBUTTON_H
#include "scene/gui/base_button.h"
-#include "scene/resources/bit_mask.h"
+#include "scene/resources/bit_map.h"
class LinkButton : public BaseButton {
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 98f427cc07..b9b270ce0c 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -160,6 +160,12 @@ int OptionButton::get_item_id(int p_idx) const {
return popup->get_item_id(p_idx);
}
+
+int OptionButton::get_item_index(int p_id) const {
+
+ return popup->get_item_index(p_id);
+}
+
Variant OptionButton::get_item_metadata(int p_idx) const {
return popup->get_item_metadata(p_idx);
@@ -306,6 +312,7 @@ void OptionButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_item_text", "idx"), &OptionButton::get_item_text);
ClassDB::bind_method(D_METHOD("get_item_icon", "idx"), &OptionButton::get_item_icon);
ClassDB::bind_method(D_METHOD("get_item_id", "idx"), &OptionButton::get_item_id);
+ ClassDB::bind_method(D_METHOD("get_item_index", "id"), &OptionButton::get_item_index);
ClassDB::bind_method(D_METHOD("get_item_metadata", "idx"), &OptionButton::get_item_metadata);
ClassDB::bind_method(D_METHOD("is_item_disabled", "idx"), &OptionButton::is_item_disabled);
ClassDB::bind_method(D_METHOD("get_item_count"), &OptionButton::get_item_count);
diff --git a/scene/gui/option_button.h b/scene/gui/option_button.h
index 121b4c002d..63b451377a 100644
--- a/scene/gui/option_button.h
+++ b/scene/gui/option_button.h
@@ -71,6 +71,7 @@ public:
String get_item_text(int p_idx) const;
Ref<Texture> get_item_icon(int p_idx) const;
int get_item_id(int p_idx) const;
+ int get_item_index(int p_id) const;
Variant get_item_metadata(int p_idx) const;
bool is_item_disabled(int p_idx) const;
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 2d2c54594a..80ec7049fc 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -124,49 +124,22 @@ void Popup::popup_centered_minsize(const Size2 &p_minsize) {
void Popup::popup_centered(const Size2 &p_size) {
- Point2 window_size = get_viewport_rect().size;
-
- emit_signal("about_to_show");
Rect2 rect;
+ Size2 window_size = get_viewport_rect().size;
rect.size = p_size == Size2() ? get_size() : p_size;
-
rect.position = ((window_size - rect.size) / 2.0).floor();
- set_position(rect.position);
- set_size(rect.size);
-
- show_modal(exclusive);
- _fix_size();
- Control *focusable = find_next_valid_focus();
- if (focusable)
- focusable->grab_focus();
-
- _post_popup();
- notification(NOTIFICATION_POST_POPUP);
- popped_up = true;
+ popup(rect);
}
void Popup::popup_centered_ratio(float p_screen_ratio) {
- emit_signal("about_to_show");
-
Rect2 rect;
- Point2 window_size = get_viewport_rect().size;
+ Size2 window_size = get_viewport_rect().size;
rect.size = (window_size * p_screen_ratio).floor();
rect.position = ((window_size - rect.size) / 2.0).floor();
- set_position(rect.position);
- set_size(rect.size);
- show_modal(exclusive);
- _fix_size();
-
- Control *focusable = find_next_valid_focus();
- if (focusable)
- focusable->grab_focus();
-
- _post_popup();
- notification(NOTIFICATION_POST_POPUP);
- popped_up = true;
+ popup(rect);
}
void Popup::popup(const Rect2 &p_bounds) {
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index ac94ac63ec..94c73b2e42 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -519,9 +519,9 @@ void PopupMenu::_notification(int p_what) {
if (items[i].accel || (items[i].shortcut.is_valid() && items[i].shortcut->is_valid())) {
//accelerator
- String text = _get_accel_text(i);
- item_ofs.x = size.width - style->get_margin(MARGIN_RIGHT) - font->get_string_size(text).width;
- font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text, i == mouse_over ? font_color_hover : font_color_accel);
+ String text2 = _get_accel_text(i);
+ item_ofs.x = size.width - style->get_margin(MARGIN_RIGHT) - font->get_string_size(text2).width;
+ font->draw(ci, item_ofs + Point2(0, Math::floor((h - font_h) / 2.0)), text2, i == mouse_over ? font_color_hover : font_color_accel);
}
items.write[i]._ofs_cache = ofs.y;
@@ -594,7 +594,7 @@ void PopupMenu::add_item(const String &p_label, int p_ID, uint32_t p_accel) {
item.text = p_label;
item.xl_text = tr(p_label);
item.accel = p_accel;
- item.ID = p_ID;
+ item.ID = p_ID == -1 ? items.size() : p_ID;
items.push_back(item);
update();
minimum_size_changed();
@@ -632,7 +632,7 @@ void PopupMenu::add_check_item(const String &p_label, int p_ID, uint32_t p_accel
item.text = p_label;
item.xl_text = tr(p_label);
item.accel = p_accel;
- item.ID = p_ID;
+ item.ID = p_ID == -1 ? items.size() : p_ID;
item.checkable_type = Item::CHECKABLE_TYPE_CHECK_BOX;
items.push_back(item);
update();
diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp
index 2195ec9778..264eda4035 100644
--- a/scene/gui/progress_bar.cpp
+++ b/scene/gui/progress_bar.cpp
@@ -39,9 +39,12 @@ Size2 ProgressBar::get_minimum_size() const {
Size2 minimum_size = bg->get_minimum_size();
minimum_size.height = MAX(minimum_size.height, fg->get_minimum_size().height);
minimum_size.width = MAX(minimum_size.width, fg->get_minimum_size().width);
- //if (percent_visible) { this is needed, else the progressbar will collapse
- minimum_size.height = MAX(minimum_size.height, bg->get_minimum_size().height + font->get_height());
- //}
+ if (percent_visible) {
+ minimum_size.height = MAX(minimum_size.height, bg->get_minimum_size().height + font->get_height());
+ } else { // this is needed, else the progressbar will collapse
+ minimum_size.width = MAX(minimum_size.width, 1);
+ minimum_size.height = MAX(minimum_size.height, 1);
+ }
return minimum_size;
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 2e466fd582..00d6ac3b94 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -544,7 +544,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
Vector2 draw_ofs = Point2(wofs, y);
Color font_color_shadow = get_color("font_color_shadow");
bool use_outline = get_constant("shadow_as_outline");
- Point2 shadow_ofs(get_constant("shadow_offset_x"), get_constant("shadow_offset_y"));
+ Point2 shadow_ofs2(get_constant("shadow_offset_x"), get_constant("shadow_offset_y"));
if (p_mode == PROCESS_CACHE) {
@@ -568,7 +568,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
for (int i = 0; i < frame->lines.size(); i++) {
- _process_line(frame, Point2(), ly, available_width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs);
+ _process_line(frame, Point2(), ly, available_width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs2);
table->columns.write[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].minimum_width);
table->columns.write[column].max_width = MAX(table->columns[column].max_width, frame->lines[i].maximum_width);
}
@@ -641,7 +641,7 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
for (int i = 0; i < frame->lines.size(); i++) {
int ly = 0;
- _process_line(frame, Point2(), ly, table->columns[column].width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs);
+ _process_line(frame, Point2(), ly, table->columns[column].width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs2);
frame->lines.write[i].height_cache = ly; //actual height
frame->lines.write[i].height_accum_cache = ly; //actual height
}
@@ -674,9 +674,9 @@ int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &
if (visible) {
if (p_mode == PROCESS_DRAW) {
- nonblank_line_count += _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_DRAW, cfont, ccolor, font_color_shadow, use_outline, shadow_ofs);
+ nonblank_line_count += _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_DRAW, cfont, ccolor, font_color_shadow, use_outline, shadow_ofs2);
} else if (p_mode == PROCESS_POINTER) {
- _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_POINTER, cfont, ccolor, font_color_shadow, use_outline, shadow_ofs, p_click_pos, r_click_item, r_click_char, r_outside);
+ _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_POINTER, cfont, ccolor, font_color_shadow, use_outline, shadow_ofs2, p_click_pos, r_click_item, r_click_char, r_outside);
if (r_click_item && *r_click_item) {
RETURN; // exit early
}
@@ -900,21 +900,13 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const {
- if (!underline_meta || selection.click)
+ if (selection.click)
return CURSOR_ARROW;
if (main->first_invalid_line < main->lines.size())
return CURSOR_ARROW; //invalid
- int line = 0;
- Item *item = NULL;
-
- ((RichTextLabel *)(this))->_find_click(main, p_pos, &item, &line);
-
- if (item && ((RichTextLabel *)(this))->_find_meta(item, NULL))
- return CURSOR_POINTING_HAND;
-
- return CURSOR_ARROW;
+ return get_default_cursor_shape();
}
void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
@@ -1133,18 +1125,19 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
Variant meta;
- if (item && !outside && _find_meta(item, &meta)) {
- if (meta_hovering != item) {
+ ItemMeta *item_meta;
+ if (item && !outside && _find_meta(item, &meta, &item_meta)) {
+ if (meta_hovering != item_meta) {
if (meta_hovering) {
emit_signal("meta_hover_ended", current_meta);
}
- meta_hovering = static_cast<ItemMeta *>(item);
+ meta_hovering = item_meta;
current_meta = meta;
emit_signal("meta_hover_started", meta);
}
} else if (meta_hovering) {
- emit_signal("meta_hover_ended", current_meta);
meta_hovering = NULL;
+ emit_signal("meta_hover_ended", current_meta);
current_meta = false;
}
}
@@ -1269,7 +1262,7 @@ bool RichTextLabel::_find_strikethrough(Item *p_item) {
return false;
}
-bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta) {
+bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item) {
Item *item = p_item;
@@ -1280,6 +1273,8 @@ bool RichTextLabel::_find_meta(Item *p_item, Variant *r_meta) {
ItemMeta *meta = static_cast<ItemMeta *>(item);
if (r_meta)
*r_meta = meta->meta;
+ if (r_item)
+ *r_item = meta;
return true;
}
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index bec2c5ac02..114c6103e2 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -285,7 +285,7 @@ private:
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);
+ bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = NULL);
void _update_scroll();
void _scroll_changed(double);
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 28292309b9..e50a71b0ff 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -368,8 +368,10 @@ void ScrollContainer::update_scrollbars() {
Ref<StyleBox> sb = get_stylebox("bg");
size -= sb->get_minimum_size();
- Size2 hmin = h_scroll->get_combined_minimum_size();
- Size2 vmin = v_scroll->get_combined_minimum_size();
+ Size2 hmin;
+ Size2 vmin;
+ if (scroll_h) hmin = h_scroll->get_combined_minimum_size();
+ if (scroll_v) vmin = v_scroll->get_combined_minimum_size();
Size2 min = child_max_size;
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index d6a93238b2..e5d1844d39 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -164,34 +164,31 @@ void SplitContainer::_notification(int p_what) {
_resort();
} break;
- case NOTIFICATION_MOUSE_ENTER: {
-
- mouse_inside = true;
- update();
- } break;
case NOTIFICATION_MOUSE_EXIT: {
mouse_inside = false;
- update();
+ if (get_constant("autohide"))
+ update();
} break;
case NOTIFICATION_DRAW: {
if (!_getch(0) || !_getch(1))
return;
- if (collapsed || (!mouse_inside && get_constant("autohide")))
+ if (collapsed || (!dragging && !mouse_inside && get_constant("autohide")))
+ return;
+
+ if (dragger_visibility != DRAGGER_VISIBLE)
return;
int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_constant("separation") : 0;
Ref<Texture> tex = get_icon("grabber");
Size2 size = get_size();
- if (dragger_visibility == DRAGGER_VISIBLE) {
- if (vertical)
- draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
- else
- draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
- }
+ if (vertical)
+ draw_texture(tex, Point2i((size.x - tex->get_width()) / 2, middle_sep + (sep - tex->get_height()) / 2));
+ else
+ draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
} break;
case NOTIFICATION_THEME_CHANGED: {
@@ -241,7 +238,23 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseMotion> mm = p_event;
- if (mm.is_valid() && dragging) {
+ if (mm.is_valid()) {
+
+ bool mouse_inside_state = false;
+ if (vertical)
+ mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_constant("separation");
+ else
+ mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_constant("separation");
+
+ if (mouse_inside != mouse_inside_state) {
+
+ mouse_inside = mouse_inside_state;
+ if (get_constant("autohide"))
+ update();
+ }
+
+ if (!dragging)
+ return;
split_offset = drag_ofs + ((vertical ? mm->get_position().y : mm->get_position().x) - drag_from);
should_clamp_split_offset = true;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 09fbb39866..9acf8d40c9 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -666,7 +666,7 @@ void TextEdit::_notification(int p_what) {
bool brace_close_matching = false;
bool brace_close_mismatch = false;
- if (brace_matching_enabled) {
+ if (brace_matching_enabled && cursor.line >= 0 && cursor.line < text.size() && cursor.column >= 0) {
if (cursor.column < text[cursor.line].length()) {
//check for open
@@ -861,6 +861,9 @@ void TextEdit::_notification(int p_what) {
const String &str = wrap_rows[line_wrap_index];
int indent_px = line_wrap_index != 0 ? get_indent_level(line) * cache.font->get_char_size(' ').width : 0;
+ if (indent_px >= wrap_at) {
+ indent_px = 0;
+ }
if (line_wrap_index > 0)
last_wrap_column += wrap_rows[line_wrap_index - 1].length();
@@ -1381,8 +1384,8 @@ void TextEdit::_notification(int p_what) {
}
}
- Size2 size = Size2(max_w, sc * font->get_height() + spacing);
- Size2 minsize = size + sb->get_minimum_size();
+ Size2 size2 = Size2(max_w, sc * font->get_height() + spacing);
+ Size2 minsize = size2 + sb->get_minimum_size();
if (completion_hint_offset == -0xFFFF) {
completion_hint_offset = cursor_pos.x - offset;
@@ -1714,10 +1717,10 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
col = get_char_pos_for_line(colx, row, wrap_index);
if (is_wrap_enabled() && wrap_index < times_line_wraps(row)) {
// move back one if we are at the end of the row
- Vector<String> rows = get_wrap_rows_text(row);
+ Vector<String> rows2 = get_wrap_rows_text(row);
int row_end_col = 0;
for (int i = 0; i < wrap_index + 1; i++) {
- row_end_col += rows[i].length();
+ row_end_col += rows2[i].length();
}
if (col >= row_end_col)
col -= 1;
@@ -2202,10 +2205,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
bool had_selection = selection.active;
// stuff to do when selection is active..
- if (selection.active) {
-
- if (readonly)
- return;
+ if (!readonly && selection.active) {
bool clear = false;
bool unselect = false;
@@ -2517,7 +2517,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
scancode_handled = false;
break;
}
- // numlock disabled. fallthrough to key_left
+ FALLTHROUGH;
}
case KEY_LEFT: {
@@ -2580,7 +2580,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
scancode_handled = false;
break;
}
- // numlock disabled. fallthrough to key_right
+ FALLTHROUGH;
}
case KEY_RIGHT: {
@@ -2641,28 +2641,30 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
scancode_handled = false;
break;
}
- // numlock disabled. fallthrough to key_up
+ FALLTHROUGH;
}
case KEY_UP: {
- if (k->get_shift())
- _pre_shift_selection();
if (k->get_alt()) {
scancode_handled = false;
break;
}
#ifndef APPLE_STYLE_KEYS
if (k->get_command()) {
- _scroll_lines_up();
- break;
- }
#else
if (k->get_command() && k->get_alt()) {
+#endif
_scroll_lines_up();
break;
}
+ if (k->get_shift()) {
+ _pre_shift_selection();
+ }
+
+#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
+
cursor_set_line(0);
} else
#endif
@@ -2692,28 +2694,28 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
scancode_handled = false;
break;
}
- // numlock disabled. fallthrough to key_down
+ FALLTHROUGH;
}
case KEY_DOWN: {
- if (k->get_shift())
- _pre_shift_selection();
if (k->get_alt()) {
scancode_handled = false;
break;
}
#ifndef APPLE_STYLE_KEYS
if (k->get_command()) {
- _scroll_lines_down();
- break;
- }
-
#else
if (k->get_command() && k->get_alt()) {
+#endif
_scroll_lines_down();
break;
}
+ if (k->get_shift()) {
+ _pre_shift_selection();
+ }
+
+#ifdef APPLE_STYLE_KEYS
if (k->get_command()) {
cursor_set_line(get_last_unhidden_line(), true, false, 9999);
} else
@@ -2815,11 +2817,10 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
scancode_handled = false;
break;
}
- // numlock disabled. fallthrough to key_home
+ FALLTHROUGH;
}
-#ifdef APPLE_STYLE_KEYS
case KEY_HOME: {
-
+#ifdef APPLE_STYLE_KEYS
if (k->get_shift())
_pre_shift_selection();
@@ -2829,11 +2830,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_post_shift_selection();
else if (k->get_command() || k->get_control())
deselect();
-
- } break;
#else
- case KEY_HOME: {
-
if (k->get_shift())
_pre_shift_selection();
@@ -2874,19 +2871,17 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
deselect();
_cancel_completion();
completion_hint = "";
-
- } break;
#endif
+ } break;
case KEY_KP_1: {
if (k->get_unicode() != 0) {
scancode_handled = false;
break;
}
- // numlock disabled. fallthrough to key_end
+ FALLTHROUGH;
}
-#ifdef APPLE_STYLE_KEYS
case KEY_END: {
-
+#ifdef APPLE_STYLE_KEYS
if (k->get_shift())
_pre_shift_selection();
@@ -2896,11 +2891,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_post_shift_selection();
else if (k->get_command() || k->get_control())
deselect();
-
- } break;
#else
- case KEY_END: {
-
if (k->get_shift())
_pre_shift_selection();
@@ -2927,15 +2918,14 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
_cancel_completion();
completion_hint = "";
-
- } break;
#endif
+ } break;
case KEY_KP_9: {
if (k->get_unicode() != 0) {
scancode_handled = false;
break;
}
- // numlock disabled. fallthrough to key_pageup
+ FALLTHROUGH;
}
case KEY_PAGEUP: {
@@ -2958,7 +2948,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
scancode_handled = false;
break;
}
- // numlock disabled. fallthrough to key_pagedown
+ FALLTHROUGH;
}
case KEY_PAGEDOWN: {
@@ -3137,21 +3127,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
if (scancode_handled)
accept_event();
- /*
- if (!scancode_handled && !k->get_command() && !k->get_alt()) {
-
- if (k->get_unicode()>=32) {
-
- if (readonly)
- break;
-
- accept_event();
- } else {
- break;
- }
- }
-*/
if (k->get_scancode() == KEY_INSERT) {
set_insert_mode(!insert_mode);
accept_event();
@@ -3194,7 +3170,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) {
end_complex_operation();
}
accept_event();
- } else {
}
}
@@ -3373,20 +3348,20 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i
String preinsert_text = text[p_line].substr(0, p_char);
String postinsert_text = text[p_line].substr(p_char, text[p_line].size());
- for (int i = 0; i < substrings.size(); i++) {
+ for (int j = 0; j < substrings.size(); j++) {
//insert the substrings
- if (i == 0) {
+ if (j == 0) {
- text.set(p_line, preinsert_text + substrings[i]);
+ text.set(p_line, preinsert_text + substrings[j]);
} else {
- text.insert(p_line + i, substrings[i]);
+ text.insert(p_line + j, substrings[j]);
}
- if (i == substrings.size() - 1) {
+ if (j == substrings.size() - 1) {
- text.set(p_line + i, text[p_line + i] + postinsert_text);
+ text.set(p_line + j, text[p_line + j] + postinsert_text);
}
}
@@ -3789,6 +3764,9 @@ Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
int cur_wrap_index = 0;
int tab_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width;
+ if (tab_offset_px >= wrap_at) {
+ tab_offset_px = 0;
+ }
while (col < line_text.length()) {
CharType c = line_text[col];
@@ -3796,29 +3774,36 @@ Vector<String> TextEdit::get_wrap_rows_text(int p_line) const {
int indent_ofs = (cur_wrap_index != 0 ? tab_offset_px : 0);
- word_str += c;
- word_px += w;
- if (c == ' ') {
- // end of a word; add this word to the substring
+ if (indent_ofs + word_px + w > wrap_at) {
+ // not enough space to add this char; start next line
wrap_substring += word_str;
- px += word_px;
- word_str = "";
- word_px = 0;
- }
+ lines.push_back(wrap_substring);
+ cur_wrap_index++;
+ wrap_substring = "";
+ px = 0;
- if ((indent_ofs + px + word_px) > wrap_at) {
- // do not want to add this word
- if (indent_ofs + word_px > wrap_at) {
- // not enough space; add it anyway
+ word_str = "";
+ word_str += c;
+ word_px = w;
+ } else {
+ word_str += c;
+ word_px += w;
+ if (c == ' ') {
+ // end of a word; add this word to the substring
wrap_substring += word_str;
+ px += word_px;
word_str = "";
word_px = 0;
}
- lines.push_back(wrap_substring);
- // reset for next wrap
- cur_wrap_index++;
- wrap_substring = "";
- px = 0;
+
+ if (indent_ofs + px + word_px > wrap_at) {
+ // this word will be moved to the next line
+ lines.push_back(wrap_substring);
+ // reset for next wrap
+ cur_wrap_index++;
+ wrap_substring = "";
+ px = 0;
+ }
}
col++;
}
@@ -4031,6 +4016,9 @@ int TextEdit::get_char_pos_for_line(int p_px, int p_line, int p_wrap_index) cons
int line_wrap_amount = times_line_wraps(p_line);
int wrap_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width;
+ if (wrap_offset_px >= wrap_at) {
+ wrap_offset_px = 0;
+ }
if (p_wrap_index > line_wrap_amount)
p_wrap_index = line_wrap_amount;
if (p_wrap_index > 0)
@@ -4072,6 +4060,9 @@ int TextEdit::get_column_x_offset_for_line(int p_char, int p_line) const {
int px = get_column_x_offset(n_char, rows[wrap_index]);
int wrap_offset_px = get_indent_level(p_line) * cache.font->get_char_size(' ').width;
+ if (wrap_offset_px >= wrap_at) {
+ wrap_offset_px = 0;
+ }
if (wrap_index != 0)
px += wrap_offset_px;
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index 95f1fbbee5..33f0a3f45d 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -683,6 +683,7 @@ protected:
TextEdit *text_editor;
public:
+ virtual ~SyntaxHighlighter() {}
virtual void _update_cache() = 0;
virtual Map<int, TextEdit::HighlighterInfo> _get_line_syntax_highlighting(int p_line) = 0;
diff --git a/scene/gui/texture_button.cpp b/scene/gui/texture_button.cpp
index 95aab95253..795b25cce0 100644
--- a/scene/gui/texture_button.cpp
+++ b/scene/gui/texture_button.cpp
@@ -64,7 +64,9 @@ bool TextureButton::has_point(const Point2 &p_point) const {
Rect2 rect = Rect2();
Size2 mask_size = click_mask->get_size();
- if (_tile) {
+ if (_position_rect.no_area()) {
+ rect.size = mask_size;
+ } else if (_tile) {
// if the stretch mode is tile we offset the point to keep it inside the mask size
rect.size = mask_size;
if (_position_rect.has_point(point)) {
@@ -206,8 +208,8 @@ void TextureButton::_notification(int p_what) {
Size2 scaleSize(size.width / tex_size.width, size.height / tex_size.height);
float scale = scaleSize.width > scaleSize.height ? scaleSize.width : scaleSize.height;
Size2 scaledTexSize = tex_size * scale;
- Point2 ofs = ((scaledTexSize - size) / scale).abs() / 2.0f;
- _texture_region = Rect2(ofs, size / scale);
+ Point2 ofs2 = ((scaledTexSize - size) / scale).abs() / 2.0f;
+ _texture_region = Rect2(ofs2, size / scale);
} break;
}
}
@@ -216,11 +218,12 @@ void TextureButton::_notification(int p_what) {
draw_texture_rect(texdraw, _position_rect, _tile);
else
draw_texture_rect_region(texdraw, _position_rect, _texture_region);
+ } else {
+ _position_rect = Rect2();
}
if (has_focus() && focused.is_valid()) {
- Rect2 drect(Point2(), get_size());
- draw_texture_rect(focused, drect, false);
+ draw_texture_rect(focused, _position_rect, false);
};
} break;
}
diff --git a/scene/gui/texture_button.h b/scene/gui/texture_button.h
index 4dc0de5358..d9224de686 100644
--- a/scene/gui/texture_button.h
+++ b/scene/gui/texture_button.h
@@ -32,7 +32,7 @@
#define TEXTURE_BUTTON_H
#include "scene/gui/base_button.h"
-#include "scene/resources/bit_mask.h"
+#include "scene/resources/bit_map.h"
class TextureButton : public BaseButton {
GDCLASS(TextureButton, BaseButton);
diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress.cpp
index 778d86d546..c534df5cbe 100644
--- a/scene/gui/texture_progress.cpp
+++ b/scene/gui/texture_progress.cpp
@@ -160,23 +160,27 @@ Point2 TextureProgress::unit_val_to_uv(float val) {
if (edge == 0) {
if (dir.x > 0)
continue;
- cp = -dir.x;
cq = -(edgeLeft - p.x);
+ dir.x *= 2.0 * cq;
+ cp = -dir.x;
} else if (edge == 1) {
if (dir.x < 0)
continue;
- cp = dir.x;
cq = (edgeRight - p.x);
+ dir.x *= 2.0 * cq;
+ cp = dir.x;
} else if (edge == 2) {
if (dir.y > 0)
continue;
- cp = -dir.y;
cq = -(edgeBottom - p.y);
+ dir.y *= 2.0 * cq;
+ cp = -dir.y;
} else if (edge == 3) {
if (dir.y < 0)
continue;
- cp = dir.y;
cq = (edgeTop - p.y);
+ dir.y *= 2.0 * cq;
+ cp = dir.y;
}
cr = cq / cp;
if (cr >= 0 && cr < t1)
@@ -247,12 +251,14 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, F
middle_section_size *= MIN(1.0, (MAX(0.0, width_filled - first_section_size) / MAX(1.0, width_total - first_section_size - last_section_size)));
last_section_size = MAX(0.0, last_section_size - (width_total - width_filled));
+ first_section_size = MIN(first_section_size, width_filled);
width_texture = MIN(width_texture, first_section_size + middle_section_size + last_section_size);
switch (mode) {
case FILL_LEFT_TO_RIGHT: {
src_rect.size.x = width_texture;
dst_rect.size.x = width_filled;
+ topleft.x = first_section_size;
bottomright.x = last_section_size;
} break;
case FILL_RIGHT_TO_LEFT: {
@@ -261,11 +267,13 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, F
dst_rect.position.x += width_total - width_filled;
dst_rect.size.x = width_filled;
topleft.x = last_section_size;
+ bottomright.x = first_section_size;
} break;
case FILL_TOP_TO_BOTTOM: {
src_rect.size.y = width_texture;
dst_rect.size.y = width_filled;
bottomright.y = last_section_size;
+ topleft.y = first_section_size;
} break;
case FILL_BOTTOM_TO_TOP: {
src_rect.position.y += src_rect.size.y - width_texture;
@@ -273,6 +281,7 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture> &p_texture, F
dst_rect.position.y += width_total - width_filled;
dst_rect.size.y = width_filled;
topleft.y = last_section_size;
+ bottomright.y = first_section_size;
} break;
case FILL_BILINEAR_LEFT_AND_RIGHT: {
// TODO: Implement
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 514be00227..679b752fa3 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -29,7 +29,6 @@
/*************************************************************************/
#include "tree.h"
-#include <limits.h>
#include "core/math/math_funcs.h"
#include "core/os/input.h"
@@ -43,6 +42,8 @@
#include "editor/editor_node.h"
#endif
+#include <limits.h>
+
void TreeItem::move_to_top() {
if (!parent || parent->children == this)
@@ -940,6 +941,7 @@ int Tree::compute_item_height(TreeItem *p_item) const {
int check_icon_h = cache.checked->get_height();
if (height < check_icon_h)
height = check_icon_h;
+ FALLTHROUGH;
}
case TreeItem::CELL_MODE_STRING:
case TreeItem::CELL_MODE_CUSTOM:
@@ -1071,11 +1073,11 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
int font_ascent = font->get_ascent();
int ofs = p_pos.x + ((p_item->disable_folding || hide_folding) ? cache.hseparation : cache.item_margin);
- int skip = 0;
+ int skip2 = 0;
for (int i = 0; i < columns.size(); i++) {
- if (skip) {
- skip--;
+ if (skip2) {
+ skip2--;
continue;
}
@@ -1102,7 +1104,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
while (i + plus < columns.size() && !p_item->cells[i + plus].editable && p_item->cells[i + plus].mode == TreeItem::CELL_MODE_STRING && p_item->cells[i + plus].text == "" && p_item->cells[i + plus].icon.is_null()) {
w += get_column_width(i + plus);
plus++;
- skip++;
+ skip2++;
}
}
@@ -1165,8 +1167,8 @@ 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()) {
- Vector2 ofs(0, (text_editor->get_size().height - r.size.height) / 2);
- text_editor->set_position(get_global_position() + r.position - ofs);
+ Vector2 ofs2(0, (text_editor->get_size().height - r.size.height) / 2);
+ text_editor->set_position(get_global_position() + r.position - ofs2);
}
}
@@ -1416,12 +1418,15 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
TreeItem *c = p_item->children;
+ int prev_ofs = children_pos.y - cache.offset.y + p_draw_ofs.y;
+
while (c) {
if (cache.draw_relationship_lines > 0 && (!hide_root || c->parent != 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;
+
if (c->get_children() != NULL)
root_pos -= Point2i(cache.arrow->get_width(), 0);
@@ -1434,12 +1439,13 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
if (root_pos.y + line_width >= 0) {
VisualServer::get_singleton()->canvas_item_add_line(ci, root_pos, Point2i(parent_pos.x - Math::floor(line_width / 2), root_pos.y), cache.relationship_line_color, line_width);
- VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), parent_pos, cache.relationship_line_color, line_width);
+ VisualServer::get_singleton()->canvas_item_add_line(ci, Point2i(parent_pos.x, root_pos.y), Point2i(parent_pos.x, prev_ofs), cache.relationship_line_color, line_width);
}
if (htotal < 0) {
return -1;
}
+ prev_ofs = root_pos.y;
}
if (htotal >= 0) {
@@ -1601,7 +1607,7 @@ void Tree::_range_click_timeout() {
mb.instance();
;
- propagate_mouse_activated = false; //done from outside, so signal handler cant clear the tree in the middle of emit(which is a common case)
+ propagate_mouse_activated = false; // done from outside, so signal handler can't clear the tree in the middle of emit (which is a common case)
blocked++;
propagate_mouse_event(pos + cache.offset, 0, 0, false, root, BUTTON_LEFT, mb);
blocked--;
@@ -2698,8 +2704,8 @@ bool Tree::edit_selected() {
popup_menu->clear();
for (int i = 0; i < c.text.get_slice_count(","); i++) {
- String s = c.text.get_slicec(',', i);
- popup_menu->add_item(s.get_slicec(':', 0), s.get_slicec(':', 1).empty() ? i : s.get_slicec(':', 1).to_int());
+ String s2 = c.text.get_slicec(',', i);
+ popup_menu->add_item(s2.get_slicec(':', 0), s2.get_slicec(':', 1).empty() ? i : s2.get_slicec(':', 1).to_int());
}
popup_menu->set_size(Size2(rect.size.width, 0));
@@ -2951,14 +2957,14 @@ void Tree::_notification(int p_what) {
if (show_column_titles) {
//title buttons
- int ofs = cache.bg->get_margin(MARGIN_LEFT);
+ int ofs2 = cache.bg->get_margin(MARGIN_LEFT);
for (int i = 0; i < columns.size(); i++) {
Ref<StyleBox> sb = (cache.click_type == Cache::CLICK_TITLE && cache.click_index == i) ? cache.title_button_pressed : ((cache.hover_type == Cache::CLICK_TITLE && cache.hover_index == i) ? cache.title_button_hover : cache.title_button);
Ref<Font> f = cache.tb_font;
- Rect2 tbrect = Rect2(ofs - cache.offset.x, bg->get_margin(MARGIN_TOP), get_column_width(i), tbh);
+ Rect2 tbrect = Rect2(ofs2 - cache.offset.x, bg->get_margin(MARGIN_TOP), get_column_width(i), tbh);
sb->draw(ci, tbrect);
- ofs += tbrect.size.width;
+ ofs2 += tbrect.size.width;
//text
int clip_w = tbrect.size.width - sb->get_minimum_size().width;
f->draw_halign(ci, tbrect.position + Point2i(sb->get_offset().x, (tbrect.size.height - f->get_height()) / 2 + f->get_ascent()), HALIGN_CENTER, clip_w, columns[i].title, cache.title_button_color);