summaryrefslogtreecommitdiff
path: root/scene/gui
diff options
context:
space:
mode:
Diffstat (limited to 'scene/gui')
-rw-r--r--scene/gui/base_button.cpp20
-rw-r--r--scene/gui/base_button.h2
-rw-r--r--scene/gui/button.cpp10
-rw-r--r--scene/gui/code_edit.cpp8
-rw-r--r--scene/gui/code_edit.h4
-rw-r--r--scene/gui/control.cpp35
-rw-r--r--scene/gui/control.h16
-rw-r--r--scene/gui/graph_edit.cpp115
-rw-r--r--scene/gui/graph_edit.h23
-rw-r--r--scene/gui/grid_container.cpp25
-rw-r--r--scene/gui/option_button.cpp2
-rw-r--r--scene/gui/popup.cpp16
-rw-r--r--scene/gui/popup.h4
-rw-r--r--scene/gui/range.cpp8
-rw-r--r--scene/gui/range.h2
-rw-r--r--scene/gui/rich_text_label.cpp832
-rw-r--r--scene/gui/rich_text_label.h50
-rw-r--r--scene/gui/text_edit.cpp14
-rw-r--r--scene/gui/texture_progress_bar.cpp4
-rw-r--r--scene/gui/tree.cpp110
-rw-r--r--scene/gui/tree.h2
-rw-r--r--scene/gui/video_stream_player.cpp2
22 files changed, 829 insertions, 475 deletions
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index 595f0cbea7..776623f7ce 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -43,12 +43,12 @@ void BaseButton::_unpress_group() {
status.pressed = true;
}
- for (RBSet<BaseButton *>::Element *E = button_group->buttons.front(); E; E = E->next()) {
- if (E->get() == this) {
+ for (BaseButton *E : button_group->buttons) {
+ if (E == this) {
continue;
}
- E->get()->set_pressed(false);
+ E->set_pressed(false);
}
}
@@ -485,24 +485,24 @@ BaseButton::~BaseButton() {
}
void ButtonGroup::get_buttons(List<BaseButton *> *r_buttons) {
- for (RBSet<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
- r_buttons->push_back(E->get());
+ for (BaseButton *E : buttons) {
+ r_buttons->push_back(E);
}
}
Array ButtonGroup::_get_buttons() {
Array btns;
- for (RBSet<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
- btns.push_back(E->get());
+ for (const BaseButton *E : buttons) {
+ btns.push_back(E);
}
return btns;
}
BaseButton *ButtonGroup::get_pressed_button() {
- for (RBSet<BaseButton *>::Element *E = buttons.front(); E; E = E->next()) {
- if (E->get()->is_pressed()) {
- return E->get();
+ for (BaseButton *E : buttons) {
+ if (E->is_pressed()) {
+ return E;
}
}
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 0b70d285ee..ba3852ec98 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -143,7 +143,7 @@ VARIANT_ENUM_CAST(BaseButton::ActionMode)
class ButtonGroup : public Resource {
GDCLASS(ButtonGroup, Resource);
friend class BaseButton;
- RBSet<BaseButton *> buttons;
+ HashSet<BaseButton *> buttons;
protected:
static void _bind_methods();
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index ff194f979d..c54897035a 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -60,11 +60,11 @@ Size2 Button::get_minimum_size() const {
}
}
}
-
- Ref<Font> font = get_theme_font(SNAME("font"));
- float font_height = font->get_height(get_theme_font_size(SNAME("font_size")));
-
- minsize.height = MAX(font_height, minsize.height);
+ if (!xl_text.is_empty()) {
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ float font_height = font->get_height(get_theme_font_size(SNAME("font_size")));
+ minsize.height = MAX(font_height, minsize.height);
+ }
return get_theme_stylebox(SNAME("normal"))->get_minimum_size() + minsize;
}
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 197c9005c3..22e9763929 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -740,8 +740,8 @@ void CodeEdit::set_auto_indent_prefixes(const TypedArray<String> &p_prefixes) {
TypedArray<String> CodeEdit::get_auto_indent_prefixes() const {
TypedArray<String> prefixes;
- for (const RBSet<char32_t>::Element *E = auto_indent_prefixes.front(); E; E = E->next()) {
- prefixes.push_back(String::chr(E->get()));
+ for (const char32_t &E : auto_indent_prefixes) {
+ prefixes.push_back(String::chr(E));
}
return prefixes;
}
@@ -1752,8 +1752,8 @@ void CodeEdit::set_code_completion_prefixes(const TypedArray<String> &p_prefixes
TypedArray<String> CodeEdit::get_code_completion_prefixes() const {
TypedArray<String> prefixes;
- for (const RBSet<char32_t>::Element *E = code_completion_prefixes.front(); E; E = E->next()) {
- prefixes.push_back(String::chr(E->get()));
+ for (const char32_t &E : code_completion_prefixes) {
+ prefixes.push_back(String::chr(E));
}
return prefixes;
}
diff --git a/scene/gui/code_edit.h b/scene/gui/code_edit.h
index 0b00735f46..ccf046c612 100644
--- a/scene/gui/code_edit.h
+++ b/scene/gui/code_edit.h
@@ -58,7 +58,7 @@ private:
String indent_text = "\t";
bool auto_indent = false;
- RBSet<char32_t> auto_indent_prefixes;
+ HashSet<char32_t> auto_indent_prefixes;
bool indent_using_spaces = false;
int _calculate_spaces_till_next_left_indent(int p_column) const;
@@ -214,7 +214,7 @@ private:
int code_completion_longest_line = 0;
Rect2i code_completion_rect;
- RBSet<char32_t> code_completion_prefixes;
+ HashSet<char32_t> code_completion_prefixes;
List<ScriptLanguage::CodeCompletionOption> code_completion_option_submitted;
List<ScriptLanguage::CodeCompletionOption> code_completion_option_sources;
String code_completion_base;
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index a0104387c9..db78b4adb6 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -471,6 +471,13 @@ void Control::_validate_property(PropertyInfo &property) const {
property.hint_string = hint_string;
}
+ if (property.name == "mouse_force_pass_scroll_events") {
+ // Disable force pass if the control is not stopping the event.
+ if (data.mouse_filter != MOUSE_FILTER_STOP) {
+ property.usage |= PROPERTY_USAGE_READ_ONLY;
+ }
+ }
+
// Validate which positioning properties should be displayed depending on the parent and the layout mode.
Node *parent_node = get_parent_control();
if (!parent_node) {
@@ -829,6 +836,7 @@ void Control::_notification(int p_notification) {
}
} else {
data.minimum_size_valid = false;
+ _update_minimum_size();
_size_changed();
}
} break;
@@ -2921,6 +2929,7 @@ int Control::get_v_size_flags() const {
void Control::set_mouse_filter(MouseFilter p_filter) {
ERR_FAIL_INDEX(p_filter, 3);
data.mouse_filter = p_filter;
+ notify_property_list_changed();
update_configuration_warnings();
}
@@ -2928,6 +2937,14 @@ Control::MouseFilter Control::get_mouse_filter() const {
return data.mouse_filter;
}
+void Control::set_force_pass_scroll_events(bool p_force_pass_scroll_events) {
+ data.force_pass_scroll_events = p_force_pass_scroll_events;
+}
+
+bool Control::is_force_pass_scroll_events() const {
+ return data.force_pass_scroll_events;
+}
+
void Control::warp_mouse(const Point2 &p_position) {
ERR_FAIL_COND(!is_inside_tree());
get_viewport()->warp_mouse(get_global_transform_with_canvas().xform(p_position));
@@ -3240,6 +3257,9 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_mouse_filter", "filter"), &Control::set_mouse_filter);
ClassDB::bind_method(D_METHOD("get_mouse_filter"), &Control::get_mouse_filter);
+ ClassDB::bind_method(D_METHOD("set_force_pass_scroll_events", "force_pass_scroll_events"), &Control::set_force_pass_scroll_events);
+ ClassDB::bind_method(D_METHOD("is_force_pass_scroll_events"), &Control::is_force_pass_scroll_events);
+
ClassDB::bind_method(D_METHOD("set_clip_contents", "enable"), &Control::set_clip_contents);
ClassDB::bind_method(D_METHOD("is_clipping_contents"), &Control::is_clipping_contents);
@@ -3282,19 +3302,19 @@ void Control::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_BOTTOM);
ADD_SUBGROUP_INDENT("Anchor Offsets", "offset_", 1);
- ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_left", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_LEFT);
- ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_top", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_TOP);
- ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_right", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_RIGHT);
- ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_BOTTOM);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_left", PROPERTY_HINT_RANGE, "-4096,4096,suffix:px"), "set_offset", "get_offset", SIDE_LEFT);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_top", PROPERTY_HINT_RANGE, "-4096,4096,suffix:px"), "set_offset", "get_offset", SIDE_TOP);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_right", PROPERTY_HINT_RANGE, "-4096,4096,suffix:px"), "set_offset", "get_offset", SIDE_RIGHT);
+ ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_bottom", PROPERTY_HINT_RANGE, "-4096,4096,suffix:px"), "set_offset", "get_offset", SIDE_BOTTOM);
ADD_SUBGROUP_INDENT("Grow Direction", "grow_", 1);
ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Left,Right,Both"), "set_h_grow_direction", "get_h_grow_direction");
ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Top,Bottom,Both"), "set_v_grow_direction", "get_v_grow_direction");
ADD_SUBGROUP("Transform", "");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_size", "get_size");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_position", "get_position");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_global_position", "get_global_position");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_EDITOR), "_set_size", "get_size");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "position", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_EDITOR), "_set_position", "get_position");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "global_position", PROPERTY_HINT_NONE, "suffix:px", PROPERTY_USAGE_NONE), "_set_global_position", "get_global_position");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater,radians"), "set_rotation", "get_rotation");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "scale"), "set_scale", "get_scale");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "pivot_offset"), "set_pivot_offset", "get_pivot_offset");
@@ -3321,6 +3341,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::BOOL, "mouse_force_pass_scroll_events"), "set_force_pass_scroll_events", "is_force_pass_scroll_events");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,I-Beam,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("Theme", "theme_");
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 65b71d74f8..f18dd99bff 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -190,6 +190,7 @@ private:
Point2 custom_minimum_size;
MouseFilter mouse_filter = MOUSE_FILTER_STOP;
+ bool force_pass_scroll_events = true;
bool clip_contents = false;
@@ -216,12 +217,12 @@ private:
NodePath focus_prev;
bool bulk_theme_override = false;
- HashMap<StringName, Ref<Texture2D>> icon_override;
- HashMap<StringName, Ref<StyleBox>> style_override;
- HashMap<StringName, Ref<Font>> font_override;
- HashMap<StringName, int> font_size_override;
- HashMap<StringName, Color> color_override;
- HashMap<StringName, int> constant_override;
+ Theme::ThemeIconMap icon_override;
+ Theme::ThemeStyleMap style_override;
+ Theme::ThemeFontMap font_override;
+ Theme::ThemeFontSizeMap font_size_override;
+ Theme::ThemeColorMap color_override;
+ Theme::ThemeConstantMap constant_override;
} data;
@@ -468,6 +469,9 @@ public:
void set_mouse_filter(MouseFilter p_filter);
MouseFilter get_mouse_filter() const;
+ void set_force_pass_scroll_events(bool p_force_pass_scroll_events);
+ bool is_force_pass_scroll_events() const;
+
/* SKINNING */
void begin_bulk_theme_override();
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 6f3a361e82..fdff6a88a9 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -1343,7 +1343,19 @@ void GraphEdit::gui_input(const Ref<InputEvent> &p_ev) {
emit_signal(SNAME("paste_nodes_request"));
accept_event();
} else if (p_ev->is_action("ui_graph_delete")) {
- emit_signal(SNAME("delete_nodes_request"));
+ TypedArray<StringName> nodes;
+
+ for (int i = 0; i < get_child_count(); i++) {
+ GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
+ if (!gn) {
+ continue;
+ }
+ if (gn->is_selected() && gn->is_close_button_visible()) {
+ nodes.push_back(gn->get_name());
+ }
+ }
+
+ emit_signal(SNAME("delete_nodes_request"), nodes);
accept_event();
}
}
@@ -1684,11 +1696,11 @@ void GraphEdit::set_warped_panning(bool p_warped) {
warped_panning = p_warped;
}
-int GraphEdit::_set_operations(SET_OPERATIONS p_operation, RBSet<StringName> &r_u, const RBSet<StringName> &r_v) {
+int GraphEdit::_set_operations(SET_OPERATIONS p_operation, HashSet<StringName> &r_u, const HashSet<StringName> &r_v) {
switch (p_operation) {
case GraphEdit::IS_EQUAL: {
- for (RBSet<StringName>::Element *E = r_u.front(); E; E = E->next()) {
- if (!r_v.has(E->get())) {
+ for (const StringName &E : r_u) {
+ if (!r_v.has(E)) {
return 0;
}
}
@@ -1698,25 +1710,28 @@ int GraphEdit::_set_operations(SET_OPERATIONS p_operation, RBSet<StringName> &r_
if (r_u.size() == r_v.size() && !r_u.size()) {
return 1;
}
- for (RBSet<StringName>::Element *E = r_u.front(); E; E = E->next()) {
- if (!r_v.has(E->get())) {
+ for (const StringName &E : r_u) {
+ if (!r_v.has(E)) {
return 0;
}
}
return 1;
} break;
case GraphEdit::DIFFERENCE: {
- for (RBSet<StringName>::Element *E = r_u.front(); E; E = E->next()) {
- if (r_v.has(E->get())) {
- r_u.erase(E->get());
+ for (HashSet<StringName>::Iterator E = r_u.begin(); E;) {
+ HashSet<StringName>::Iterator N = E;
+ ++N;
+ if (r_v.has(*E)) {
+ r_u.remove(E);
}
+ E = N;
}
return r_u.size();
} break;
case GraphEdit::UNION: {
- for (RBSet<StringName>::Element *E = r_v.front(); E; E = E->next()) {
- if (!r_u.has(E->get())) {
- r_u.insert(E->get());
+ for (const StringName &E : r_v) {
+ if (!r_u.has(E)) {
+ r_u.insert(E);
}
}
return r_u.size();
@@ -1727,28 +1742,28 @@ int GraphEdit::_set_operations(SET_OPERATIONS p_operation, RBSet<StringName> &r_
return -1;
}
-HashMap<int, Vector<StringName>> GraphEdit::_layering(const RBSet<StringName> &r_selected_nodes, const HashMap<StringName, RBSet<StringName>> &r_upper_neighbours) {
+HashMap<int, Vector<StringName>> GraphEdit::_layering(const HashSet<StringName> &r_selected_nodes, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours) {
HashMap<int, Vector<StringName>> l;
- RBSet<StringName> p = r_selected_nodes, q = r_selected_nodes, u, z;
+ HashSet<StringName> p = r_selected_nodes, q = r_selected_nodes, u, z;
int current_layer = 0;
bool selected = false;
while (!_set_operations(GraphEdit::IS_EQUAL, q, u)) {
_set_operations(GraphEdit::DIFFERENCE, p, u);
- for (const RBSet<StringName>::Element *E = p.front(); E; E = E->next()) {
- RBSet<StringName> n = r_upper_neighbours[E->get()];
+ for (const StringName &E : p) {
+ HashSet<StringName> n = r_upper_neighbours[E];
if (_set_operations(GraphEdit::IS_SUBSET, n, z)) {
Vector<StringName> t;
- t.push_back(E->get());
+ t.push_back(E);
if (!l.has(current_layer)) {
l.insert(current_layer, Vector<StringName>{});
}
selected = true;
t.append_array(l[current_layer]);
l.insert(current_layer, t);
- RBSet<StringName> V;
- V.insert(E->get());
+ HashSet<StringName> V;
+ V.insert(E);
_set_operations(GraphEdit::UNION, u, V);
}
}
@@ -1789,10 +1804,10 @@ Vector<StringName> GraphEdit::_split(const Vector<StringName> &r_layer, const Ha
return left;
}
-void GraphEdit::_horizontal_alignment(Dictionary &r_root, Dictionary &r_align, const HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, RBSet<StringName>> &r_upper_neighbours, const RBSet<StringName> &r_selected_nodes) {
- for (const RBSet<StringName>::Element *E = r_selected_nodes.front(); E; E = E->next()) {
- r_root[E->get()] = E->get();
- r_align[E->get()] = E->get();
+void GraphEdit::_horizontal_alignment(Dictionary &r_root, Dictionary &r_align, const HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours, const HashSet<StringName> &r_selected_nodes) {
+ for (const StringName &E : r_selected_nodes) {
+ r_root[E] = E;
+ r_align[E] = E;
}
if (r_layers.size() == 1) {
@@ -1829,7 +1844,7 @@ void GraphEdit::_horizontal_alignment(Dictionary &r_root, Dictionary &r_align, c
}
}
-void GraphEdit::_crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, RBSet<StringName>> &r_upper_neighbours) {
+void GraphEdit::_crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours) {
if (r_layers.size() == 1) {
return;
}
@@ -1867,10 +1882,10 @@ void GraphEdit::_crossing_minimisation(HashMap<int, Vector<StringName>> &r_layer
}
}
-void GraphEdit::_calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictionary &r_root, const Dictionary &r_node_names, const Dictionary &r_align, const RBSet<StringName> &r_block_heads, const HashMap<StringName, Pair<int, int>> &r_port_info) {
- for (const RBSet<StringName>::Element *E = r_block_heads.front(); E; E = E->next()) {
+void GraphEdit::_calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictionary &r_root, const Dictionary &r_node_names, const Dictionary &r_align, const HashSet<StringName> &r_block_heads, const HashMap<StringName, Pair<int, int>> &r_port_info) {
+ for (const StringName &E : r_block_heads) {
real_t left = 0;
- StringName u = E->get();
+ StringName u = E;
StringName v = r_align[u];
while (u != v && (StringName)r_root[u] != v) {
String _connection = String(u) + " " + String(v);
@@ -1891,11 +1906,11 @@ void GraphEdit::_calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictio
v = (StringName)r_align[v];
}
- u = E->get();
+ u = E;
do {
r_inner_shifts[u] = (real_t)r_inner_shifts[u] - left;
u = (StringName)r_align[u];
- } while (u != E->get());
+ } while (u != E);
}
}
@@ -2040,7 +2055,7 @@ void GraphEdit::arrange_nodes() {
}
Dictionary node_names;
- RBSet<StringName> selected_nodes;
+ HashSet<StringName> selected_nodes;
for (int i = get_child_count() - 1; i >= 0; i--) {
GraphNode *gn = Object::cast_to<GraphNode>(get_child(i));
@@ -2051,7 +2066,7 @@ void GraphEdit::arrange_nodes() {
node_names[gn->get_name()] = gn;
}
- HashMap<StringName, RBSet<StringName>> upper_neighbours;
+ HashMap<StringName, HashSet<StringName>> upper_neighbours;
HashMap<StringName, Pair<int, int>> port_info;
Vector2 origin(FLT_MAX, FLT_MAX);
@@ -2066,7 +2081,7 @@ void GraphEdit::arrange_nodes() {
if (gn->is_selected()) {
selected_nodes.insert(gn->get_name());
- RBSet<StringName> s;
+ HashSet<StringName> s;
for (List<Connection>::Element *E = connections.front(); E; E = E->next()) {
GraphNode *p_from = Object::cast_to<GraphNode>(node_names[E->get().from]);
if (E->get().to == gn->get_name() && p_from->is_selected()) {
@@ -2103,35 +2118,35 @@ void GraphEdit::arrange_nodes() {
HashMap<StringName, Vector2> new_positions;
Vector2 default_position(FLT_MAX, FLT_MAX);
Dictionary inner_shift;
- RBSet<StringName> block_heads;
+ HashSet<StringName> block_heads;
- for (const RBSet<StringName>::Element *E = selected_nodes.front(); E; E = E->next()) {
- inner_shift[E->get()] = 0.0f;
- sink[E->get()] = E->get();
- shift[E->get()] = FLT_MAX;
- new_positions.insert(E->get(), default_position);
- if ((StringName)root[E->get()] == E->get()) {
- block_heads.insert(E->get());
+ for (const StringName &E : selected_nodes) {
+ inner_shift[E] = 0.0f;
+ sink[E] = E;
+ shift[E] = FLT_MAX;
+ new_positions.insert(E, default_position);
+ if ((StringName)root[E] == E) {
+ block_heads.insert(E);
}
}
_calculate_inner_shifts(inner_shift, root, node_names, align, block_heads, port_info);
- for (const RBSet<StringName>::Element *E = block_heads.front(); E; E = E->next()) {
- _place_block(E->get(), gap_v, layers, root, align, node_names, inner_shift, sink, shift, new_positions);
+ for (const StringName &E : block_heads) {
+ _place_block(E, gap_v, layers, root, align, node_names, inner_shift, sink, shift, new_positions);
}
origin.y = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().y - (new_positions[layers[0][0]].y + (float)inner_shift[layers[0][0]]);
origin.x = Object::cast_to<GraphNode>(node_names[layers[0][0]])->get_position_offset().x;
- for (const RBSet<StringName>::Element *E = block_heads.front(); E; E = E->next()) {
- StringName u = E->get();
- float start_from = origin.y + new_positions[E->get()].y;
+ for (const StringName &E : block_heads) {
+ StringName u = E;
+ float start_from = origin.y + new_positions[E].y;
do {
Vector2 cal_pos;
cal_pos.y = start_from + (real_t)inner_shift[u];
new_positions.insert(u, cal_pos);
u = align[u];
- } while (u != E->get());
+ } while (u != E);
}
// Compute horizontal coordinates individually for layers to get uniform gap.
@@ -2169,10 +2184,10 @@ void GraphEdit::arrange_nodes() {
}
emit_signal(SNAME("begin_node_move"));
- for (const RBSet<StringName>::Element *E = selected_nodes.front(); E; E = E->next()) {
- GraphNode *gn = Object::cast_to<GraphNode>(node_names[E->get()]);
+ for (const StringName &E : selected_nodes) {
+ GraphNode *gn = Object::cast_to<GraphNode>(node_names[E]);
gn->set_drag(true);
- Vector2 pos = (new_positions[E->get()]);
+ Vector2 pos = (new_positions[E]);
if (is_using_snap()) {
const int snap = get_snap();
@@ -2290,7 +2305,7 @@ void GraphEdit::_bind_methods() {
ADD_SIGNAL(MethodInfo("node_deselected", PropertyInfo(Variant::OBJECT, "node", PROPERTY_HINT_RESOURCE_TYPE, "Node")));
ADD_SIGNAL(MethodInfo("connection_to_empty", PropertyInfo(Variant::STRING_NAME, "from"), PropertyInfo(Variant::INT, "from_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
ADD_SIGNAL(MethodInfo("connection_from_empty", PropertyInfo(Variant::STRING_NAME, "to"), PropertyInfo(Variant::INT, "to_slot"), PropertyInfo(Variant::VECTOR2, "release_position")));
- ADD_SIGNAL(MethodInfo("delete_nodes_request"));
+ ADD_SIGNAL(MethodInfo("delete_nodes_request", PropertyInfo(Variant::ARRAY, "nodes", PROPERTY_HINT_ARRAY_TYPE, "StringName")));
ADD_SIGNAL(MethodInfo("begin_node_move"));
ADD_SIGNAL(MethodInfo("end_node_move"));
ADD_SIGNAL(MethodInfo("scroll_offset_changed", PropertyInfo(Variant::VECTOR2, "offset")));
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index 9e34d5528f..5484a2317c 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -218,8 +218,11 @@ private:
uint64_t key = 0;
};
- bool operator<(const ConnType &p_type) const {
- return key < p_type.key;
+ static uint32_t hash(const ConnType &p_conn) {
+ return hash_one_uint64(p_conn.key);
+ }
+ bool operator==(const ConnType &p_type) const {
+ return key == p_type.key;
}
ConnType(uint32_t a = 0, uint32_t b = 0) {
@@ -228,9 +231,9 @@ private:
}
};
- RBSet<ConnType> valid_connection_types;
- RBSet<int> valid_left_disconnect_types;
- RBSet<int> valid_right_disconnect_types;
+ HashSet<ConnType, ConnType> valid_connection_types;
+ HashSet<int> valid_left_disconnect_types;
+ HashSet<int> valid_right_disconnect_types;
HashMap<StringName, Vector<GraphNode *>> comment_enclosed_nodes;
void _update_comment_enclosed_nodes_list(GraphNode *p_node, HashMap<StringName, Vector<GraphNode *>> &p_comment_enclosed_nodes);
@@ -258,12 +261,12 @@ private:
UNION,
};
- int _set_operations(SET_OPERATIONS p_operation, RBSet<StringName> &r_u, const RBSet<StringName> &r_v);
- HashMap<int, Vector<StringName>> _layering(const RBSet<StringName> &r_selected_nodes, const HashMap<StringName, RBSet<StringName>> &r_upper_neighbours);
+ int _set_operations(SET_OPERATIONS p_operation, HashSet<StringName> &r_u, const HashSet<StringName> &r_v);
+ HashMap<int, Vector<StringName>> _layering(const HashSet<StringName> &r_selected_nodes, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours);
Vector<StringName> _split(const Vector<StringName> &r_layer, const HashMap<StringName, Dictionary> &r_crossings);
- void _horizontal_alignment(Dictionary &r_root, Dictionary &r_align, const HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, RBSet<StringName>> &r_upper_neighbours, const RBSet<StringName> &r_selected_nodes);
- void _crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, RBSet<StringName>> &r_upper_neighbours);
- void _calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictionary &r_root, const Dictionary &r_node_names, const Dictionary &r_align, const RBSet<StringName> &r_block_heads, const HashMap<StringName, Pair<int, int>> &r_port_info);
+ void _horizontal_alignment(Dictionary &r_root, Dictionary &r_align, const HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours, const HashSet<StringName> &r_selected_nodes);
+ void _crossing_minimisation(HashMap<int, Vector<StringName>> &r_layers, const HashMap<StringName, HashSet<StringName>> &r_upper_neighbours);
+ void _calculate_inner_shifts(Dictionary &r_inner_shifts, const Dictionary &r_root, const Dictionary &r_node_names, const Dictionary &r_align, const HashSet<StringName> &r_block_heads, const HashMap<StringName, Pair<int, int>> &r_port_info);
float _calculate_threshold(StringName p_v, StringName p_w, const Dictionary &r_node_names, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_inner_shift, real_t p_current_threshold, const HashMap<StringName, Vector2> &r_node_positions);
void _place_block(StringName p_v, float p_delta, const HashMap<int, Vector<StringName>> &r_layers, const Dictionary &r_root, const Dictionary &r_align, const Dictionary &r_node_name, const Dictionary &r_inner_shift, Dictionary &r_sink, Dictionary &r_shift, HashMap<StringName, Vector2> &r_node_positions);
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index ec33018da0..6f8518a7b0 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -29,12 +29,13 @@
/*************************************************************************/
#include "grid_container.h"
+#include "core/templates/rb_set.h"
void GridContainer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
- HashMap<int, int> col_minw; // Max of min_width of all controls in each col (indexed by col).
- HashMap<int, int> row_minh; // Max of min_height of all controls in each row (indexed by row).
+ RBMap<int, int> col_minw; // Max of min_width of all controls in each col (indexed by col).
+ RBMap<int, int> row_minh; // Max of min_height of all controls in each row (indexed by row).
RBSet<int> col_expanded; // Columns which have the SIZE_EXPAND flag set.
RBSet<int> row_expanded; // Rows which have the SIZE_EXPAND flag set.
@@ -104,11 +105,11 @@ void GridContainer::_notification(int p_what) {
// Check if all minwidth constraints are OK if we use the remaining space.
can_fit = true;
int max_index = col_expanded.front()->get();
- for (RBSet<int>::Element *E = col_expanded.front(); E; E = E->next()) {
- if (col_minw[E->get()] > col_minw[max_index]) {
- max_index = E->get();
+ for (const int &E : col_expanded) {
+ if (col_minw[E] > col_minw[max_index]) {
+ max_index = E;
}
- if (can_fit && (remaining_space.width / col_expanded.size()) < col_minw[E->get()]) {
+ if (can_fit && (remaining_space.width / col_expanded.size()) < col_minw[E]) {
can_fit = false;
}
}
@@ -125,11 +126,11 @@ void GridContainer::_notification(int p_what) {
// Check if all minheight constraints are OK if we use the remaining space.
can_fit = true;
int max_index = row_expanded.front()->get();
- for (RBSet<int>::Element *E = row_expanded.front(); E; E = E->next()) {
- if (row_minh[E->get()] > row_minh[max_index]) {
- max_index = E->get();
+ for (const int &E : row_expanded) {
+ if (row_minh[E] > row_minh[max_index]) {
+ max_index = E;
}
- if (can_fit && (remaining_space.height / row_expanded.size()) < row_minh[E->get()]) {
+ if (can_fit && (remaining_space.height / row_expanded.size()) < row_minh[E]) {
can_fit = false;
}
}
@@ -261,8 +262,8 @@ void GridContainer::_bind_methods() {
}
Size2 GridContainer::get_minimum_size() const {
- HashMap<int, int> col_minw;
- HashMap<int, int> row_minh;
+ RBMap<int, int> col_minw;
+ RBMap<int, int> row_minh;
int hsep = get_theme_constant(SNAME("h_separation"));
int vsep = get_theme_constant(SNAME("v_separation"));
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 4b79d79846..a86f2bdbc1 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -320,7 +320,7 @@ int OptionButton::get_selectable_item(bool p_from_last) const {
}
}
} else {
- for (int i = get_item_count() - 1; i >= 0; i++) {
+ for (int i = get_item_count() - 1; i >= 0; i--) {
if (!is_item_disabled(i) && !is_item_separator(i)) {
return i;
}
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index b9e3e7814e..6532fc5934 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -108,11 +108,25 @@ void Popup::_close_pressed() {
_deinitialize_visible_parents();
- call_deferred(SNAME("hide"));
+ // Hide after returning to process events, but only if we don't
+ // get popped up in the interim.
+ call_deferred(SNAME("_popup_conditional_hide"));
+}
+
+void Popup::_post_popup() {
+ Window::_post_popup();
+ popped_up = true;
+}
+
+void Popup::_popup_conditional_hide() {
+ if (!popped_up) {
+ hide();
+ }
}
void Popup::_bind_methods() {
ADD_SIGNAL(MethodInfo("popup_hide"));
+ ClassDB::bind_method(D_METHOD("_popup_conditional_hide"), &Popup::_popup_conditional_hide);
}
Rect2i Popup::_popup_adjust_rect() const {
diff --git a/scene/gui/popup.h b/scene/gui/popup.h
index 6211af4d20..27f46d4a97 100644
--- a/scene/gui/popup.h
+++ b/scene/gui/popup.h
@@ -57,6 +57,10 @@ protected:
void _notification(int p_what);
static void _bind_methods();
+ void _popup_conditional_hide();
+
+ virtual void _post_popup() override;
+
public:
Popup();
~Popup();
diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp
index 73f19a8eda..fae6688452 100644
--- a/scene/gui/range.cpp
+++ b/scene/gui/range.cpp
@@ -50,8 +50,8 @@ void Range::_value_changed_notify() {
}
void Range::Shared::emit_value_changed() {
- for (RBSet<Range *>::Element *E = owners.front(); E; E = E->next()) {
- Range *r = E->get();
+ for (Range *E : owners) {
+ Range *r = E;
if (!r->is_inside_tree()) {
continue;
}
@@ -70,8 +70,8 @@ void Range::_validate_values() {
}
void Range::Shared::emit_changed(const char *p_what) {
- for (RBSet<Range *>::Element *E = owners.front(); E; E = E->next()) {
- Range *r = E->get();
+ for (Range *E : owners) {
+ Range *r = E;
if (!r->is_inside_tree()) {
continue;
}
diff --git a/scene/gui/range.h b/scene/gui/range.h
index a59bfa9677..1274821bd1 100644
--- a/scene/gui/range.h
+++ b/scene/gui/range.h
@@ -45,7 +45,7 @@ class Range : public Control {
bool exp_ratio = false;
bool allow_greater = false;
bool allow_lesser = false;
- RBSet<Range *> owners;
+ HashSet<Range *> owners;
void emit_value_changed();
void emit_changed(const char *p_what = "");
};
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index fa0c2ce12c..94c2a9e64b 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -209,9 +209,10 @@ String RichTextLabel::_letters(int p_num, bool p_capitalize) const {
void RichTextLabel::_update_line_font(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size) {
ERR_FAIL_COND(p_frame == nullptr);
- ERR_FAIL_COND(p_line < 0 || p_line >= p_frame->lines.size());
+ ERR_FAIL_COND(p_line < 0 || p_line >= (int)p_frame->lines.size());
- Line &l = p_frame->lines.write[p_line];
+ Line &l = p_frame->lines[p_line];
+ MutexLock lock(l.text_buf->get_mutex());
RID t = l.text_buf->get_rid();
int spans = TS->shaped_get_span_count(t);
@@ -231,7 +232,7 @@ void RichTextLabel::_update_line_font(ItemFrame *p_frame, int p_line, const Ref<
}
}
- Item *it_to = (p_line + 1 < p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
+ Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
switch (it->type) {
case ITEM_TABLE: {
@@ -239,7 +240,7 @@ void RichTextLabel::_update_line_font(ItemFrame *p_frame, int p_line, const Ref<
for (Item *E : table->subitems) {
ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
ItemFrame *frame = static_cast<ItemFrame *>(E);
- for (int i = 0; i < frame->lines.size(); i++) {
+ for (int i = 0; i < (int)frame->lines.size(); i++) {
_update_line_font(frame, i, p_base_font, p_base_font_size);
}
}
@@ -250,11 +251,12 @@ void RichTextLabel::_update_line_font(ItemFrame *p_frame, int p_line, const Ref<
}
}
-void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width) {
- ERR_FAIL_COND(p_frame == nullptr);
- ERR_FAIL_COND(p_line < 0 || p_line >= p_frame->lines.size());
+float RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, float p_h) {
+ ERR_FAIL_COND_V(p_frame == nullptr, p_h);
+ ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), p_h);
- Line &l = p_frame->lines.write[p_line];
+ Line &l = p_frame->lines[p_line];
+ MutexLock lock(l.text_buf->get_mutex());
l.offset.x = _find_margin(l.from, p_base_font, p_base_font_size);
l.text_buf->set_width(p_width - l.offset.x);
@@ -265,7 +267,7 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
l.text_buf->tab_align(tabs);
}
- Item *it_to = (p_line + 1 < p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
+ Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
switch (it->type) {
case ITEM_TABLE: {
@@ -275,16 +277,18 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
int col_count = table->columns.size();
for (int i = 0; i < col_count; i++) {
- table->columns.write[i].width = 0;
+ table->columns[i].width = 0;
}
int idx = 0;
for (Item *E : table->subitems) {
ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
ItemFrame *frame = static_cast<ItemFrame *>(E);
- for (int i = 0; i < frame->lines.size(); i++) {
+ float prev_h = 0;
+ for (int i = 0; i < (int)frame->lines.size(); i++) {
+ MutexLock sub_lock(frame->lines[i].text_buf->get_mutex());
int w = _find_margin(frame->lines[i].from, p_base_font, p_base_font_size) + 1;
- _resize_line(frame, i, p_base_font, p_base_font_size, w);
+ prev_h = _resize_line(frame, i, p_base_font, p_base_font_size, w, prev_h);
}
idx++;
}
@@ -300,7 +304,7 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
for (int i = 0; i < col_count; i++) {
remaining_width -= table->columns[i].min_width;
if (table->columns[i].max_width > table->columns[i].min_width) {
- table->columns.write[i].expand = true;
+ table->columns[i].expand = true;
}
if (table->columns[i].expand) {
total_ratio += table->columns[i].expand_ratio;
@@ -309,9 +313,9 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
// Assign actual widths.
for (int i = 0; i < col_count; i++) {
- table->columns.write[i].width = table->columns[i].min_width;
+ table->columns[i].width = table->columns[i].min_width;
if (table->columns[i].expand && total_ratio > 0 && remaining_width > 0) {
- table->columns.write[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
+ table->columns[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
}
table->total_width += table->columns[i].width + hseparation;
}
@@ -328,7 +332,7 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
int dif = table->columns[i].width - table->columns[i].max_width;
if (dif > 0) {
table_need_fit = true;
- table->columns.write[i].width = table->columns[i].max_width;
+ table->columns[i].width = table->columns[i].max_width;
table->total_width -= dif;
total_ratio -= table->columns[i].expand_ratio;
}
@@ -342,7 +346,7 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
if (dif > 0) {
int slice = table->columns[i].expand_ratio * remaining_width / total_ratio;
int incr = MIN(dif, slice);
- table->columns.write[i].width += incr;
+ table->columns[i].width += incr;
table->total_width += incr;
}
}
@@ -366,16 +370,14 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
offset.x += frame->padding.position.x;
float yofs = frame->padding.position.y;
- for (int i = 0; i < frame->lines.size(); i++) {
- frame->lines.write[i].text_buf->set_width(table->columns[column].width);
- table->columns.write[column].width = MAX(table->columns.write[column].width, ceil(frame->lines[i].text_buf->get_size().x));
+ float prev_h = 0;
+ for (int i = 0; i < (int)frame->lines.size(); i++) {
+ MutexLock sub_lock(frame->lines[i].text_buf->get_mutex());
+ frame->lines[i].text_buf->set_width(table->columns[column].width);
+ table->columns[column].width = MAX(table->columns[column].width, ceil(frame->lines[i].text_buf->get_size().x));
- if (i > 0) {
- frame->lines.write[i].offset.y = frame->lines[i - 1].offset.y + frame->lines[i - 1].text_buf->get_size().y + frame->lines[i - 1].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
- } else {
- frame->lines.write[i].offset.y = 0;
- }
- frame->lines.write[i].offset += offset;
+ frame->lines[i].offset.y = prev_h;
+ frame->lines[i].offset += offset;
float h = frame->lines[i].text_buf->get_size().y + (frame->lines[i].text_buf->get_line_count() - 1) * get_theme_constant(SNAME("line_separation"));
if (i > 0) {
@@ -388,6 +390,7 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
h = MIN(h, frame->max_size_over.y);
}
yofs += h;
+ prev_h = frame->lines[i].offset.y + frame->lines[i].text_buf->get_size().y + frame->lines[i].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
}
yofs += frame->padding.size.y;
offset.x += table->columns[column].width + hseparation + frame->padding.size.x;
@@ -410,18 +413,16 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font>
}
}
- if (p_line > 0) {
- l.offset.y = p_frame->lines[p_line - 1].offset.y + p_frame->lines[p_line - 1].text_buf->get_size().y + p_frame->lines[p_line - 1].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
- } else {
- l.offset.y = 0;
- }
+ l.offset.y = p_h;
+ return l.offset.y + l.text_buf->get_size().y + l.text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
}
-void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, int *r_char_offset) {
- ERR_FAIL_COND(p_frame == nullptr);
- ERR_FAIL_COND(p_line < 0 || p_line >= p_frame->lines.size());
+float RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, float p_h, int *r_char_offset) {
+ ERR_FAIL_COND_V(p_frame == nullptr, p_h);
+ ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), p_h);
- Line &l = p_frame->lines.write[p_line];
+ Line &l = p_frame->lines[p_line];
+ MutexLock lock(l.text_buf->get_mutex());
uint16_t autowrap_flags = TextServer::BREAK_MANDATORY;
switch (autowrap_mode) {
@@ -458,7 +459,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
// Shape current paragraph.
String text;
- Item *it_to = (p_line + 1 < p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
+ Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
int remaining_characters = visible_characters - l.char_offset;
for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING && visible_characters >= 0 && remaining_characters <= 0) {
@@ -524,9 +525,9 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
int t_char_count = 0;
// Set minimums to zero.
for (int i = 0; i < col_count; i++) {
- table->columns.write[i].min_width = 0;
- table->columns.write[i].max_width = 0;
- table->columns.write[i].width = 0;
+ table->columns[i].min_width = 0;
+ table->columns[i].max_width = 0;
+ table->columns[i].width = 0;
}
// Compute minimum width for each cell.
const int available_width = p_width - hseparation * (col_count - 1);
@@ -537,17 +538,20 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
ItemFrame *frame = static_cast<ItemFrame *>(E);
int column = idx % col_count;
- for (int i = 0; i < frame->lines.size(); i++) {
+ float prev_h = 0;
+ for (int i = 0; i < (int)frame->lines.size(); i++) {
+ MutexLock sub_lock(frame->lines[i].text_buf->get_mutex());
+
int char_offset = l.char_offset + l.char_count;
int w = _find_margin(frame->lines[i].from, p_base_font, p_base_font_size) + 1;
- _shape_line(frame, i, p_base_font, p_base_font_size, w, &char_offset);
+ prev_h = _shape_line(frame, i, p_base_font, p_base_font_size, w, prev_h, &char_offset);
int cell_ch = (char_offset - (l.char_offset + l.char_count));
l.char_count += cell_ch;
t_char_count += cell_ch;
remaining_characters -= cell_ch;
- table->columns.write[column].min_width = MAX(table->columns[column].min_width, ceil(frame->lines[i].text_buf->get_size().x));
- table->columns.write[column].max_width = MAX(table->columns[column].max_width, ceil(frame->lines[i].text_buf->get_non_wrapped_size().x));
+ table->columns[column].min_width = MAX(table->columns[column].min_width, ceil(frame->lines[i].text_buf->get_size().x));
+ table->columns[column].max_width = MAX(table->columns[column].max_width, ceil(frame->lines[i].text_buf->get_non_wrapped_size().x));
}
idx++;
}
@@ -560,7 +564,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
for (int i = 0; i < col_count; i++) {
remaining_width -= table->columns[i].min_width;
if (table->columns[i].max_width > table->columns[i].min_width) {
- table->columns.write[i].expand = true;
+ table->columns[i].expand = true;
}
if (table->columns[i].expand) {
total_ratio += table->columns[i].expand_ratio;
@@ -569,9 +573,9 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
// Assign actual widths.
for (int i = 0; i < col_count; i++) {
- table->columns.write[i].width = table->columns[i].min_width;
+ table->columns[i].width = table->columns[i].min_width;
if (table->columns[i].expand && total_ratio > 0 && remaining_width > 0) {
- table->columns.write[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
+ table->columns[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
}
table->total_width += table->columns[i].width + hseparation;
}
@@ -588,7 +592,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
int dif = table->columns[i].width - table->columns[i].max_width;
if (dif > 0) {
table_need_fit = true;
- table->columns.write[i].width = table->columns[i].max_width;
+ table->columns[i].width = table->columns[i].max_width;
table->total_width -= dif;
total_ratio -= table->columns[i].expand_ratio;
}
@@ -602,7 +606,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
if (dif > 0) {
int slice = table->columns[i].expand_ratio * remaining_width / total_ratio;
int incr = MIN(dif, slice);
- table->columns.write[i].width += incr;
+ table->columns[i].width += incr;
table->total_width += incr;
}
}
@@ -626,16 +630,15 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
offset.x += frame->padding.position.x;
float yofs = frame->padding.position.y;
- for (int i = 0; i < frame->lines.size(); i++) {
- frame->lines.write[i].text_buf->set_width(table->columns[column].width);
- table->columns.write[column].width = MAX(table->columns.write[column].width, ceil(frame->lines[i].text_buf->get_size().x));
+ float prev_h = 0;
+ for (int i = 0; i < (int)frame->lines.size(); i++) {
+ MutexLock sub_lock(frame->lines[i].text_buf->get_mutex());
- if (i > 0) {
- frame->lines.write[i].offset.y = frame->lines[i - 1].offset.y + frame->lines[i - 1].text_buf->get_size().y + frame->lines[i - 1].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
- } else {
- frame->lines.write[i].offset.y = 0;
- }
- frame->lines.write[i].offset += offset;
+ frame->lines[i].text_buf->set_width(table->columns[column].width);
+ table->columns[column].width = MAX(table->columns[column].width, ceil(frame->lines[i].text_buf->get_size().x));
+
+ frame->lines[i].offset.y = prev_h;
+ frame->lines[i].offset += offset;
float h = frame->lines[i].text_buf->get_size().y + (frame->lines[i].text_buf->get_line_count() - 1) * get_theme_constant(SNAME("line_separation"));
if (i > 0) {
@@ -648,6 +651,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
h = MIN(h, frame->max_size_over.y);
}
yofs += h;
+ prev_h = frame->lines[i].offset.y + frame->lines[i].text_buf->get_size().y + frame->lines[i].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
}
yofs += frame->padding.size.y;
offset.x += table->columns[column].width + hseparation + frame->padding.size.x;
@@ -678,24 +682,22 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
*r_char_offset = l.char_offset + l.char_count;
- if (p_line > 0) {
- l.offset.y = p_frame->lines[p_line - 1].offset.y + p_frame->lines[p_line - 1].text_buf->get_size().y + p_frame->lines[p_line - 1].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
- } else {
- l.offset.y = 0;
- }
+ l.offset.y = p_h;
+ return l.offset.y + l.text_buf->get_size().y + l.text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
}
int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_ofs, int p_width, const Color &p_base_color, int p_outline_size, const Color &p_outline_color, const Color &p_font_shadow_color, int p_shadow_outline_size, const Point2 &p_shadow_ofs, int &r_processed_glyphs) {
ERR_FAIL_COND_V(p_frame == nullptr, 0);
- ERR_FAIL_COND_V(p_line < 0 || p_line >= p_frame->lines.size(), 0);
+ ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), 0);
Vector2 off;
int line_spacing = get_theme_constant(SNAME("line_separation"));
- Line &l = p_frame->lines.write[p_line];
+ Line &l = p_frame->lines[p_line];
+ MutexLock lock(l.text_buf->get_mutex());
Item *it_from = l.from;
- Item *it_to = (p_line + 1 < p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
+ Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
if (it_from == nullptr) {
return 0;
@@ -877,7 +879,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position, Size2(table->columns[col].width + hseparation + frame->padding.position.x + frame->padding.size.x, table->rows[row])), (frame->border != Color(0, 0, 0, 0) ? frame->border : border), false);
}
- for (int j = 0; j < frame->lines.size(); j++) {
+ for (int j = 0; j < (int)frame->lines.size(); j++) {
_draw_line(frame, j, p_ofs + rect.position + off + Vector2(0, frame->lines[j].offset.y), rect.size.x, p_base_color, p_outline_size, p_outline_color, p_font_shadow_color, p_shadow_outline_size, p_shadow_ofs, r_processed_glyphs);
}
idx++;
@@ -1299,22 +1301,12 @@ void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item
int vofs = vscroll->get_value();
// Search for the first line.
- int from_line = 0;
-
- //TODO, change to binary search ?
- while (from_line < main->lines.size()) {
- if (main->lines[from_line].offset.y + main->lines[from_line].text_buf->get_size().y + main->lines[from_line].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation")) >= vofs) {
- break;
- }
- from_line++;
- }
-
- if (from_line >= main->lines.size()) {
- return;
- }
+ int to_line = main->first_invalid_line.load();
+ int from_line = _find_first_line(0, to_line, vofs);
Point2 ofs = text_rect.get_position() + Vector2(0, main->lines[from_line].offset.y - vofs);
- while (ofs.y < size.height && from_line < main->lines.size()) {
+ while (ofs.y < size.height && from_line < to_line) {
+ MutexLock lock(main->lines[from_line].text_buf->get_mutex());
_find_click_in_line(p_frame, from_line, ofs, text_rect.size.x, p_click, r_click_frame, r_click_line, r_click_item, r_click_char);
ofs.y += main->lines[from_line].text_buf->get_size().y + main->lines[from_line].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
if (((r_click_item != nullptr) && ((*r_click_item) != nullptr)) || ((r_click_frame != nullptr) && ((*r_click_frame) != nullptr))) {
@@ -1331,7 +1323,9 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
Vector2 off;
int char_pos = -1;
- Line &l = p_frame->lines.write[p_line];
+ Line &l = p_frame->lines[p_line];
+ MutexLock lock(l.text_buf->get_mutex());
+
bool rtl = (l.text_buf->get_direction() == TextServer::DIRECTION_RTL);
bool lrtl = is_layout_rtl();
@@ -1420,14 +1414,14 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
}
}
if (crect.has_point(p_click)) {
- for (int j = 0; j < frame->lines.size(); j++) {
+ for (int j = 0; j < (int)frame->lines.size(); j++) {
_find_click_in_line(frame, j, rect.position + Vector2(0, frame->lines[j].offset.y), rect.size.x, p_click, &table_click_frame, &table_click_line, &table_click_item, &table_click_char, true);
if (table_click_frame && table_click_item) {
// Save cell detected cell hit data.
table_range = Vector2i(INT32_MAX, 0);
for (Item *F : table->subitems) {
ItemFrame *sub_frame = static_cast<ItemFrame *>(F);
- for (int k = 0; k < sub_frame->lines.size(); k++) {
+ for (int k = 0; k < (int)sub_frame->lines.size(); k++) {
table_range.x = MIN(table_range.x, sub_frame->lines[k].char_offset);
table_range.y = MAX(table_range.y, sub_frame->lines[k].char_offset + sub_frame->lines[k].char_count);
}
@@ -1484,7 +1478,7 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V
// Find item.
if (r_click_item != nullptr) {
Item *it = p_frame->lines[p_line].from;
- Item *it_to = (p_line + 1 < p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
+ Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
if (char_pos == p_frame->lines[p_line].char_count) {
// Selection after the end of line, select last item.
if (it_to != nullptr) {
@@ -1532,28 +1526,6 @@ void RichTextLabel::_scroll_changed(double) {
update();
}
-void RichTextLabel::_update_scroll() {
- int total_height = get_content_height();
-
- bool exceeds = total_height > get_size().height && scroll_active;
-
- if (exceeds != scroll_visible) {
- if (exceeds) {
- scroll_visible = true;
- scroll_w = vscroll->get_combined_minimum_size().width;
- vscroll->show();
- vscroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -scroll_w);
- } else {
- scroll_visible = false;
- scroll_w = 0;
- vscroll->hide();
- }
-
- main->first_resized_line = 0; //invalidate ALL
- _validate_line_caches(main);
- }
-}
-
void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, double p_delta_time) {
Item *it = p_frame;
while (it) {
@@ -1588,6 +1560,22 @@ void RichTextLabel::_update_fx(RichTextLabel::ItemFrame *p_frame, double p_delta
}
}
+int RichTextLabel::_find_first_line(int p_from, int p_to, int p_vofs) const {
+ int l = p_from;
+ int r = p_to;
+ while (l < r) {
+ int m = Math::floor(double(l + r) / 2.0);
+ MutexLock lock(main->lines[m].text_buf->get_mutex());
+ int ofs = main->lines[m].offset.y + main->lines[m].text_buf->get_size().y + main->lines[m].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
+ if (ofs < p_vofs) {
+ l = m + 1;
+ } else {
+ r = m;
+ }
+ }
+ return l;
+}
+
void RichTextLabel::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_MOUSE_EXIT: {
@@ -1600,38 +1588,45 @@ void RichTextLabel::_notification(int p_what) {
} break;
case NOTIFICATION_RESIZED: {
- main->first_resized_line = 0; //invalidate ALL
+ _stop_thread();
+ main->first_resized_line.store(0); //invalidate ALL
update();
} break;
case NOTIFICATION_THEME_CHANGED: {
- main->first_invalid_font_line = 0; //invalidate ALL
+ _stop_thread();
+ main->first_invalid_font_line.store(0); //invalidate ALL
update();
} break;
case NOTIFICATION_ENTER_TREE: {
+ _stop_thread();
if (!text.is_empty()) {
set_text(text);
}
- main->first_invalid_line = 0; //invalidate ALL
+ main->first_invalid_line.store(0); //invalidate ALL
update();
} break;
+ case NOTIFICATION_EXIT_TREE: {
+ _stop_thread();
+ } break;
+
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
- main->first_invalid_line = 0; //invalidate ALL
+ _stop_thread();
+ main->first_invalid_line.store(0); //invalidate ALL
update();
} break;
- case NOTIFICATION_DRAW: {
- _validate_line_caches(main);
- _update_scroll();
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ update();
+ } break;
+ case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
-
Size2 size = get_size();
- Rect2 text_rect = _get_text_rect();
draw_style_box(get_theme_stylebox(SNAME("normal")), Rect2(Point2(), size));
@@ -1641,22 +1636,42 @@ void RichTextLabel::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
}
+ // Start text shaping.
+ if (_validate_line_caches()) {
+ set_physics_process_internal(false); // Disable auto refresh, if text is fully processed.
+ } else {
+ // Draw loading progress bar.
+ if ((progress_delay > 0) && (OS::get_singleton()->get_ticks_msec() - loading_started >= (uint64_t)progress_delay)) {
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"), SNAME("ProgressBar"));
+ Ref<StyleBox> fg = get_theme_stylebox(SNAME("fg"), SNAME("ProgressBar"));
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
+
+ Vector2 p_size = Vector2(size.width - (style->get_offset().x + vscroll->get_combined_minimum_size().width) * 2, vscroll->get_combined_minimum_size().width);
+ Vector2 p_pos = Vector2(style->get_offset().x, size.height - style->get_offset().y - vscroll->get_combined_minimum_size().width);
+
+ draw_style_box(bg, Rect2(p_pos, p_size));
+
+ bool right_to_left = is_layout_rtl();
+ double r = loaded.load();
+ int mp = fg->get_minimum_size().width;
+ int p = round(r * (p_size.width - mp));
+ if (right_to_left) {
+ int p_remaining = round((1.0 - r) * (p_size.width - mp));
+ draw_style_box(fg, Rect2(p_pos + Point2(p_remaining, 0), Size2(p + fg->get_minimum_size().width, p_size.height)));
+ } else {
+ draw_style_box(fg, Rect2(p_pos, Size2(p + fg->get_minimum_size().width, p_size.height)));
+ }
+ }
+ }
+
+ // Draw main text.
+ Rect2 text_rect = _get_text_rect();
float vofs = vscroll->get_value();
// Search for the first line.
- int from_line = 0;
+ int to_line = main->first_invalid_line.load();
+ int from_line = _find_first_line(0, to_line, vofs);
- //TODO, change to binary search ?
- while (from_line < main->lines.size()) {
- if (main->lines[from_line].offset.y + main->lines[from_line].text_buf->get_size().y + main->lines[from_line].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation")) >= vofs) {
- break;
- }
- from_line++;
- }
-
- if (from_line >= main->lines.size()) {
- break; //nothing to draw
- }
Ref<Font> base_font = get_theme_font(SNAME("normal_font"));
Color base_color = get_theme_color(SNAME("default_color"));
Color outline_color = get_theme_color(SNAME("font_outline_color"));
@@ -1671,7 +1686,9 @@ void RichTextLabel::_notification(int p_what) {
// New cache draw.
Point2 ofs = text_rect.get_position() + Vector2(0, main->lines[from_line].offset.y - vofs);
int processed_glyphs = 0;
- while (ofs.y < size.height && from_line < main->lines.size()) {
+ while (ofs.y < size.height && from_line < to_line) {
+ MutexLock lock(main->lines[from_line].text_buf->get_mutex());
+
visible_paragraph_count++;
visible_line_count += _draw_line(main, from_line, ofs, text_rect.size.x, base_color, outline_size, outline_color, font_shadow_color, shadow_outline_size, shadow_ofs, processed_glyphs);
ofs.y += main->lines[from_line].text_buf->get_size().y + main->lines[from_line].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
@@ -1681,6 +1698,9 @@ void RichTextLabel::_notification(int p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
if (is_visible_in_tree()) {
+ if (!is_ready()) {
+ return;
+ }
double dt = get_process_delta_time();
_update_fx(main, dt);
update();
@@ -1708,18 +1728,6 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const
return CURSOR_IBEAM;
}
- if (main->first_invalid_line < main->lines.size()) {
- return get_default_cursor_shape(); //invalid
- }
-
- if (main->first_invalid_font_line < main->lines.size()) {
- return get_default_cursor_shape(); //invalid
- }
-
- if (main->first_resized_line < main->lines.size()) {
- return get_default_cursor_shape(); //invalid
- }
-
Item *item = nullptr;
bool outside = true;
const_cast<RichTextLabel *>(this)->_find_click(main, p_pos, nullptr, nullptr, &item, nullptr, &outside);
@@ -1727,7 +1735,6 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const
if (item && !outside && const_cast<RichTextLabel *>(this)->_find_meta(item, nullptr)) {
return CURSOR_POINTING_HAND;
}
-
return get_default_cursor_shape();
}
@@ -1737,16 +1744,6 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
Ref<InputEventMouseButton> b = p_event;
if (b.is_valid()) {
- if (main->first_invalid_line < main->lines.size()) {
- return;
- }
- if (main->first_invalid_font_line < main->lines.size()) {
- return;
- }
- if (main->first_resized_line < main->lines.size()) {
- return;
- }
-
if (b->get_button_index() == MouseButton::LEFT) {
if (b->is_pressed() && !b->is_double_click()) {
scroll_updated = false;
@@ -1800,6 +1797,7 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
if (c_frame) {
const Line &l = c_frame->lines[c_line];
+ MutexLock lock(l.text_buf->get_mutex());
PackedInt32Array words = TS->shaped_text_get_word_breaks(l.text_buf->get_rid());
for (int i = 0; i < words.size(); i = i + 2) {
if (c_index >= words[i] && c_index < words[i + 1]) {
@@ -1841,8 +1839,7 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
deselect();
}
}
-
- if (!b->is_double_click() && !scroll_updated) {
+ if (!b->is_double_click() && !scroll_updated && !selection.active) {
Item *c_item = nullptr;
bool outside = true;
@@ -1945,18 +1942,7 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
}
Ref<InputEventMouseMotion> m = p_event;
-
if (m.is_valid()) {
- if (main->first_invalid_line < main->lines.size()) {
- return;
- }
- if (main->first_invalid_font_line < main->lines.size()) {
- return;
- }
- if (main->first_resized_line < main->lines.size()) {
- return;
- }
-
ItemFrame *c_frame = nullptr;
int c_line = 0;
Item *c_item = nullptr;
@@ -2434,93 +2420,215 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
return false;
}
-void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
- if (p_frame->first_invalid_line == p_frame->lines.size()) {
+void RichTextLabel::_thread_function(void *self) {
+ RichTextLabel *rtl = reinterpret_cast<RichTextLabel *>(self);
+ rtl->_process_line_caches();
+ rtl->updating.store(false);
+ rtl->call_deferred(SNAME("update"));
+}
+
+void RichTextLabel::_stop_thread() {
+ if (threaded) {
+ stop_thread.store(true);
+ thread.wait_to_finish();
+ }
+}
+
+bool RichTextLabel::is_ready() const {
+ if (updating.load()) {
+ return false;
+ }
+ return (main->first_invalid_line.load() == (int)main->lines.size() && main->first_resized_line.load() == (int)main->lines.size() && main->first_invalid_font_line.load() == (int)main->lines.size());
+}
+
+void RichTextLabel::set_threaded(bool p_threaded) {
+ if (threaded != p_threaded) {
+ _stop_thread();
+ threaded = p_threaded;
+ update();
+ }
+}
+
+bool RichTextLabel::is_threaded() const {
+ return threaded;
+}
+
+void RichTextLabel::set_progress_bar_delay(int p_delay_ms) {
+ progress_delay = p_delay_ms;
+}
+
+int RichTextLabel::get_progress_bar_delay() const {
+ return progress_delay;
+}
+
+bool RichTextLabel::_validate_line_caches() {
+ if (updating.load()) {
+ return false;
+ }
+ if (main->first_invalid_line.load() == (int)main->lines.size()) {
+ MutexLock data_lock(data_mutex);
+ Rect2 text_rect = _get_text_rect();
+
Ref<Font> base_font = get_theme_font(SNAME("normal_font"));
int base_font_size = get_theme_font_size(SNAME("normal_font_size"));
+ int ctrl_height = get_size().height;
// Update fonts.
- if (p_frame->first_invalid_font_line != p_frame->lines.size()) {
- for (int i = p_frame->first_invalid_font_line; i < p_frame->lines.size(); i++) {
- _update_line_font(p_frame, i, base_font, base_font_size);
+ if (main->first_invalid_font_line.load() != (int)main->lines.size()) {
+ for (int i = main->first_invalid_font_line.load(); i < (int)main->lines.size(); i++) {
+ _update_line_font(main, i, base_font, base_font_size);
}
- p_frame->first_resized_line = p_frame->first_invalid_font_line;
- p_frame->first_invalid_font_line = p_frame->lines.size();
+ main->first_resized_line.store(main->first_invalid_font_line.load());
+ main->first_invalid_font_line.store(main->lines.size());
}
- if (p_frame->first_resized_line == p_frame->lines.size()) {
- return;
+ if (main->first_resized_line.load() == (int)main->lines.size()) {
+ return true;
}
// Resize lines without reshaping.
- Rect2 text_rect = _get_text_rect();
+ int fi = main->first_resized_line.load();
+
+ float total_height = 0;
+ for (int i = fi; i < (int)main->lines.size(); i++) {
+ total_height = _resize_line(main, i, base_font, base_font_size, text_rect.get_size().width - scroll_w, total_height);
+
+ updating_scroll = true;
+ bool exceeds = total_height > ctrl_height && scroll_active;
+ if (exceeds != scroll_visible) {
+ if (exceeds) {
+ scroll_visible = true;
+ scroll_w = vscroll->get_combined_minimum_size().width;
+ vscroll->show();
+ vscroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -scroll_w);
+ } else {
+ scroll_visible = false;
+ scroll_w = 0;
+ vscroll->hide();
+ }
- for (int i = p_frame->first_resized_line; i < p_frame->lines.size(); i++) {
- _resize_line(p_frame, i, base_font, base_font_size, text_rect.get_size().width - scroll_w);
- }
+ main->first_resized_line.store(0);
- int total_height = 0;
- if (p_frame->lines.size()) {
- total_height = p_frame->lines[p_frame->lines.size() - 1].offset.y + p_frame->lines[p_frame->lines.size() - 1].text_buf->get_size().y + p_frame->lines[p_frame->lines.size() - 1].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
- }
+ total_height = 0;
+ for (int j = 0; j <= i; j++) {
+ total_height = _resize_line(main, j, base_font, base_font_size, text_rect.get_size().width - scroll_w, total_height);
- p_frame->first_resized_line = p_frame->lines.size();
+ main->first_resized_line.store(j);
+ }
+ }
- updating_scroll = true;
- vscroll->set_max(total_height);
- vscroll->set_page(text_rect.size.height);
- if (scroll_follow && scroll_following) {
- vscroll->set_value(total_height);
+ vscroll->set_max(total_height);
+ vscroll->set_page(text_rect.size.height);
+ if (scroll_follow && scroll_following) {
+ vscroll->set_value(total_height);
+ }
+ updating_scroll = false;
+
+ main->first_resized_line.store(i);
}
- updating_scroll = false;
+
+ main->first_resized_line.store(main->lines.size());
if (fit_content_height) {
update_minimum_size();
}
- return;
+ return true;
}
+ stop_thread.store(false);
+ if (threaded) {
+ updating.store(true);
+ loaded.store(true);
+ thread.start(RichTextLabel::_thread_function, reinterpret_cast<void *>(this));
+ loading_started = OS::get_singleton()->get_ticks_msec();
+ set_physics_process_internal(true);
+ return false;
+ } else {
+ _process_line_caches();
+ update();
+ return true;
+ }
+}
+void RichTextLabel::_process_line_caches() {
// Shape invalid lines.
+ MutexLock data_lock(data_mutex);
Rect2 text_rect = _get_text_rect();
Ref<Font> base_font = get_theme_font(SNAME("normal_font"));
int base_font_size = get_theme_font_size(SNAME("normal_font_size"));
+ int ctrl_height = get_size().height;
+ int fi = main->first_invalid_line.load();
+ int total_chars = (fi == 0) ? 0 : (main->lines[fi].char_offset + main->lines[fi].char_count);
- int total_chars = (p_frame->first_invalid_line == 0) ? 0 : (p_frame->lines[p_frame->first_invalid_line].char_offset + p_frame->lines[p_frame->first_invalid_line].char_count);
- for (int i = p_frame->first_invalid_line; i < p_frame->lines.size(); i++) {
- _shape_line(p_frame, i, base_font, base_font_size, text_rect.get_size().width - scroll_w, &total_chars);
- }
+ float total_height = 0;
+ for (int i = fi; i < (int)main->lines.size(); i++) {
+ total_height = _shape_line(main, i, base_font, base_font_size, text_rect.get_size().width - scroll_w, total_height, &total_chars);
- int total_height = 0;
- if (p_frame->lines.size()) {
- total_height = p_frame->lines[p_frame->lines.size() - 1].offset.y + p_frame->lines[p_frame->lines.size() - 1].text_buf->get_size().y + p_frame->lines[p_frame->lines.size() - 1].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
- }
+ updating_scroll = true;
+ bool exceeds = total_height > ctrl_height && scroll_active;
+ if (exceeds != scroll_visible) {
+ if (exceeds) {
+ scroll_visible = true;
+ scroll_w = vscroll->get_combined_minimum_size().width;
+ vscroll->show();
+ vscroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -scroll_w);
+ } else {
+ scroll_visible = false;
+ scroll_w = 0;
+ vscroll->hide();
+ }
- p_frame->first_invalid_line = p_frame->lines.size();
- p_frame->first_resized_line = p_frame->lines.size();
- p_frame->first_invalid_font_line = p_frame->lines.size();
+ main->first_invalid_line.store(0);
+ main->first_resized_line.store(0);
+ main->first_invalid_font_line.store(0);
- updating_scroll = true;
- vscroll->set_max(total_height);
- vscroll->set_page(text_rect.size.height);
- if (scroll_follow && scroll_following) {
- vscroll->set_value(total_height);
+ total_height = 0;
+ for (int j = 0; j <= i; j++) {
+ total_height = _resize_line(main, j, base_font, base_font_size, text_rect.get_size().width - scroll_w, total_height);
+
+ main->first_invalid_line.store(j);
+ main->first_resized_line.store(j);
+ main->first_invalid_font_line.store(j);
+ }
+ }
+
+ vscroll->set_max(total_height);
+ vscroll->set_page(text_rect.size.height);
+ if (scroll_follow && scroll_following) {
+ vscroll->set_value(total_height);
+ }
+ updating_scroll = false;
+
+ main->first_invalid_line.store(i);
+ main->first_resized_line.store(i);
+ main->first_invalid_font_line.store(i);
+
+ if (stop_thread.load()) {
+ return;
+ }
+ loaded.store(double(i) / double(main->lines.size()));
}
- updating_scroll = false;
+
+ main->first_invalid_line.store(main->lines.size());
+ main->first_resized_line.store(main->lines.size());
+ main->first_invalid_font_line.store(main->lines.size());
if (fit_content_height) {
update_minimum_size();
}
+ emit_signal(SNAME("finished"));
}
void RichTextLabel::_invalidate_current_line(ItemFrame *p_frame) {
- if (p_frame->lines.size() - 1 <= p_frame->first_invalid_line) {
- p_frame->first_invalid_line = p_frame->lines.size() - 1;
- update();
+ if ((int)p_frame->lines.size() - 1 <= p_frame->first_invalid_line) {
+ p_frame->first_invalid_line = (int)p_frame->lines.size() - 1;
}
}
void RichTextLabel::add_text(const String &p_text) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
if (current->type == ITEM_TABLE) {
return; //can't add anything here
}
@@ -2564,13 +2672,14 @@ void RichTextLabel::add_text(const String &p_text) {
_add_item(item, false);
current_frame->lines.resize(current_frame->lines.size() + 1);
if (item->type != ITEM_NEWLINE) {
- current_frame->lines.write[current_frame->lines.size() - 1].from = item;
+ current_frame->lines[current_frame->lines.size() - 1].from = item;
}
_invalidate_current_line(current_frame);
}
pos = end + 1;
}
+ update();
}
void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline) {
@@ -2599,7 +2708,7 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline)
}
if (current_frame->lines[current_frame->lines.size() - 1].from == nullptr) {
- current_frame->lines.write[current_frame->lines.size() - 1].from = p_item;
+ current_frame->lines[current_frame->lines.size() - 1].from = p_item;
}
p_item->line = current_frame->lines.size() - 1;
@@ -2608,6 +2717,7 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline)
if (fixed_width != -1) {
update_minimum_size();
}
+ update();
}
void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_subitem_line) {
@@ -2635,6 +2745,9 @@ void RichTextLabel::_remove_item(Item *p_item, const int p_line, const int p_sub
}
void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color, InlineAlignment p_alignment) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
if (current->type == ITEM_TABLE) {
return;
}
@@ -2674,6 +2787,9 @@ void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width,
}
void RichTextLabel::add_newline() {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
if (current->type == ITEM_TABLE) {
return;
}
@@ -2682,10 +2798,14 @@ void RichTextLabel::add_newline() {
_add_item(item, false);
current_frame->lines.resize(current_frame->lines.size() + 1);
_invalidate_current_line(current_frame);
+ update();
}
bool RichTextLabel::remove_line(const int p_line) {
- if (p_line >= current_frame->lines.size() || p_line < 0) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
+ if (p_line >= (int)current_frame->lines.size() || p_line < 0) {
return false;
}
@@ -2713,16 +2833,19 @@ bool RichTextLabel::remove_line(const int p_line) {
}
if (p_line == 0 && current->subitems.size() > 0) {
- main->lines.write[0].from = main;
+ main->lines[0].from = main;
}
- main->first_invalid_line = 0; // p_line ???
+ main->first_invalid_line.store(0);
update();
return true;
}
void RichTextLabel::push_dropcap(const String &p_string, const Ref<Font> &p_font, int p_size, const Rect2 &p_dropcap_margins, const Color &p_color, int p_ol_size, const Color &p_ol_color) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ERR_FAIL_COND(p_string.is_empty());
ERR_FAIL_COND(p_font.is_null());
@@ -2741,6 +2864,9 @@ void RichTextLabel::push_dropcap(const String &p_string, const Ref<Font> &p_font
}
void RichTextLabel::push_font(const Ref<Font> &p_font) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ERR_FAIL_COND(p_font.is_null());
ItemFont *item = memnew(ItemFont);
@@ -2785,6 +2911,9 @@ void RichTextLabel::push_mono() {
}
void RichTextLabel::push_font_size(int p_font_size) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemFontSize *item = memnew(ItemFontSize);
@@ -2793,6 +2922,9 @@ void RichTextLabel::push_font_size(int p_font_size) {
}
void RichTextLabel::push_font_features(const Dictionary &p_features) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemFontFeatures *item = memnew(ItemFontFeatures);
@@ -2801,6 +2933,9 @@ void RichTextLabel::push_font_features(const Dictionary &p_features) {
}
void RichTextLabel::push_outline_size(int p_font_size) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemOutlineSize *item = memnew(ItemOutlineSize);
@@ -2809,6 +2944,9 @@ void RichTextLabel::push_outline_size(int p_font_size) {
}
void RichTextLabel::push_color(const Color &p_color) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemColor *item = memnew(ItemColor);
@@ -2817,6 +2955,9 @@ void RichTextLabel::push_color(const Color &p_color) {
}
void RichTextLabel::push_outline_color(const Color &p_color) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemOutlineColor *item = memnew(ItemOutlineColor);
@@ -2825,6 +2966,9 @@ void RichTextLabel::push_outline_color(const Color &p_color) {
}
void RichTextLabel::push_underline() {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemUnderline *item = memnew(ItemUnderline);
@@ -2832,6 +2976,9 @@ void RichTextLabel::push_underline() {
}
void RichTextLabel::push_strikethrough() {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemStrikethrough *item = memnew(ItemStrikethrough);
@@ -2839,6 +2986,9 @@ void RichTextLabel::push_strikethrough() {
}
void RichTextLabel::push_paragraph(HorizontalAlignment p_alignment, Control::TextDirection p_direction, const String &p_language, TextServer::StructuredTextParser p_st_parser) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemParagraph *item = memnew(ItemParagraph);
@@ -2850,6 +3000,9 @@ void RichTextLabel::push_paragraph(HorizontalAlignment p_alignment, Control::Tex
}
void RichTextLabel::push_indent(int p_level) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ERR_FAIL_COND(p_level < 0);
@@ -2859,6 +3012,9 @@ void RichTextLabel::push_indent(int p_level) {
}
void RichTextLabel::push_list(int p_level, ListType p_list, bool p_capitalize) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ERR_FAIL_COND(p_level < 0);
@@ -2871,6 +3027,9 @@ void RichTextLabel::push_list(int p_level, ListType p_list, bool p_capitalize) {
}
void RichTextLabel::push_meta(const Variant &p_meta) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemMeta *item = memnew(ItemMeta);
@@ -2879,6 +3038,9 @@ void RichTextLabel::push_meta(const Variant &p_meta) {
}
void RichTextLabel::push_hint(const String &p_string) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemHint *item = memnew(ItemHint);
@@ -2887,20 +3049,26 @@ void RichTextLabel::push_hint(const String &p_string) {
}
void RichTextLabel::push_table(int p_columns, InlineAlignment p_alignment) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(p_columns < 1);
ItemTable *item = memnew(ItemTable);
item->columns.resize(p_columns);
item->total_width = 0;
item->inline_align = p_alignment;
- for (int i = 0; i < item->columns.size(); i++) {
- item->columns.write[i].expand = false;
- item->columns.write[i].expand_ratio = 1;
+ for (int i = 0; i < (int)item->columns.size(); i++) {
+ item->columns[i].expand = false;
+ item->columns[i].expand_ratio = 1;
}
_add_item(item, true, false);
}
void RichTextLabel::push_fade(int p_start_index, int p_length) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ItemFade *item = memnew(ItemFade);
item->starting_index = p_start_index;
item->length = p_length;
@@ -2908,6 +3076,9 @@ void RichTextLabel::push_fade(int p_start_index, int p_length) {
}
void RichTextLabel::push_shake(int p_strength = 10, float p_rate = 24.0f) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ItemShake *item = memnew(ItemShake);
item->strength = p_strength;
item->rate = p_rate;
@@ -2915,6 +3086,9 @@ void RichTextLabel::push_shake(int p_strength = 10, float p_rate = 24.0f) {
}
void RichTextLabel::push_wave(float p_frequency = 1.0f, float p_amplitude = 10.0f) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ItemWave *item = memnew(ItemWave);
item->frequency = p_frequency;
item->amplitude = p_amplitude;
@@ -2922,6 +3096,9 @@ void RichTextLabel::push_wave(float p_frequency = 1.0f, float p_amplitude = 10.0
}
void RichTextLabel::push_tornado(float p_frequency = 1.0f, float p_radius = 10.0f) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ItemTornado *item = memnew(ItemTornado);
item->frequency = p_frequency;
item->radius = p_radius;
@@ -2929,6 +3106,9 @@ void RichTextLabel::push_tornado(float p_frequency = 1.0f, float p_radius = 10.0
}
void RichTextLabel::push_rainbow(float p_saturation, float p_value, float p_frequency) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ItemRainbow *item = memnew(ItemRainbow);
item->frequency = p_frequency;
item->saturation = p_saturation;
@@ -2937,6 +3117,9 @@ void RichTextLabel::push_rainbow(float p_saturation, float p_value, float p_freq
}
void RichTextLabel::push_bgcolor(const Color &p_color) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemBGColor *item = memnew(ItemBGColor);
@@ -2945,6 +3128,9 @@ void RichTextLabel::push_bgcolor(const Color &p_color) {
}
void RichTextLabel::push_fgcolor(const Color &p_color) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemFGColor *item = memnew(ItemFGColor);
@@ -2953,6 +3139,9 @@ void RichTextLabel::push_fgcolor(const Color &p_color) {
}
void RichTextLabel::push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionary p_environment) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ItemCustomFX *item = memnew(ItemCustomFX);
item->custom_effect = p_custom_effect;
item->char_fx_transform->environment = p_environment;
@@ -2960,15 +3149,23 @@ void RichTextLabel::push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionar
}
void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_ratio) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type != ITEM_TABLE);
+
ItemTable *table = static_cast<ItemTable *>(current);
- ERR_FAIL_INDEX(p_column, table->columns.size());
- table->columns.write[p_column].expand = p_expand;
- table->columns.write[p_column].expand_ratio = p_ratio;
+ ERR_FAIL_INDEX(p_column, (int)table->columns.size());
+ table->columns[p_column].expand = p_expand;
+ table->columns[p_column].expand_ratio = p_ratio;
}
void RichTextLabel::set_cell_row_background_color(const Color &p_odd_row_bg, const Color &p_even_row_bg) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type != ITEM_FRAME);
+
ItemFrame *cell = static_cast<ItemFrame *>(current);
ERR_FAIL_COND(!cell->cell);
cell->odd_row_bg = p_odd_row_bg;
@@ -2976,14 +3173,22 @@ void RichTextLabel::set_cell_row_background_color(const Color &p_odd_row_bg, con
}
void RichTextLabel::set_cell_border_color(const Color &p_color) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type != ITEM_FRAME);
+
ItemFrame *cell = static_cast<ItemFrame *>(current);
ERR_FAIL_COND(!cell->cell);
cell->border = p_color;
}
void RichTextLabel::set_cell_size_override(const Size2 &p_min_size, const Size2 &p_max_size) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type != ITEM_FRAME);
+
ItemFrame *cell = static_cast<ItemFrame *>(current);
ERR_FAIL_COND(!cell->cell);
cell->min_size_over = p_min_size;
@@ -2991,13 +3196,20 @@ void RichTextLabel::set_cell_size_override(const Size2 &p_min_size, const Size2
}
void RichTextLabel::set_cell_padding(const Rect2 &p_padding) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type != ITEM_FRAME);
+
ItemFrame *cell = static_cast<ItemFrame *>(current);
ERR_FAIL_COND(!cell->cell);
cell->padding = p_padding;
}
void RichTextLabel::push_cell() {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(current->type != ITEM_TABLE);
ItemFrame *item = memnew(ItemFrame);
@@ -3006,20 +3218,23 @@ void RichTextLabel::push_cell() {
current_frame = item;
item->cell = true;
item->lines.resize(1);
- item->lines.write[0].from = nullptr;
- item->first_invalid_line = 0; // parent frame last line ???
+ item->lines[0].from = nullptr;
+ item->first_invalid_line.store(0); // parent frame last line ???
}
int RichTextLabel::get_current_table_column() const {
ERR_FAIL_COND_V(current->type != ITEM_TABLE, -1);
ItemTable *table = static_cast<ItemTable *>(current);
-
return table->subitems.size() % table->columns.size();
}
void RichTextLabel::pop() {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
ERR_FAIL_COND(!current->parent);
+
if (current->type == ITEM_FRAME) {
current_frame = static_cast<ItemFrame *>(current)->parent_frame;
}
@@ -3027,12 +3242,15 @@ void RichTextLabel::pop() {
}
void RichTextLabel::clear() {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
main->_clear_children();
current = main;
current_frame = main;
main->lines.clear();
main->lines.resize(1);
- main->first_invalid_line = 0;
+ main->first_invalid_line.store(0);
selection.click_frame = nullptr;
selection.click_item = nullptr;
@@ -3050,8 +3268,10 @@ void RichTextLabel::clear() {
}
void RichTextLabel::set_tab_size(int p_spaces) {
+ _stop_thread();
+
tab_size = p_spaces;
- main->first_resized_line = 0;
+ main->first_resized_line.store(0);
update();
}
@@ -3131,6 +3351,9 @@ void RichTextLabel::parse_bbcode(const String &p_bbcode) {
}
void RichTextLabel::append_text(const String &p_bbcode) {
+ _stop_thread();
+ MutexLock data_lock(data_mutex);
+
int pos = 0;
List<String> tag_stack;
@@ -3871,9 +4094,13 @@ void RichTextLabel::append_text(const String &p_bbcode) {
}
void RichTextLabel::scroll_to_paragraph(int p_paragraph) {
- ERR_FAIL_INDEX(p_paragraph, main->lines.size());
- _validate_line_caches(main);
- vscroll->set_value(main->lines[p_paragraph].offset.y);
+ if (p_paragraph <= 0) {
+ vscroll->set_value(0);
+ } else if (p_paragraph >= main->first_invalid_line.load()) {
+ vscroll->set_value(vscroll->get_max());
+ } else {
+ vscroll->set_value(main->lines[p_paragraph].offset.y);
+ }
}
int RichTextLabel::get_paragraph_count() const {
@@ -3888,10 +4115,14 @@ int RichTextLabel::get_visible_paragraph_count() const {
}
void RichTextLabel::scroll_to_line(int p_line) {
- _validate_line_caches(main);
-
+ if (p_line <= 0) {
+ vscroll->set_value(0);
+ return;
+ }
int line_count = 0;
- for (int i = 0; i < main->lines.size(); i++) {
+ int to_line = main->first_invalid_line.load();
+ for (int i = 0; i < to_line; i++) {
+ MutexLock lock(main->lines[i].text_buf->get_mutex());
if ((line_count <= p_line) && (line_count + main->lines[i].text_buf->get_line_count() >= p_line)) {
float line_offset = 0.f;
for (int j = 0; j < p_line - line_count; j++) {
@@ -3902,11 +4133,14 @@ void RichTextLabel::scroll_to_line(int p_line) {
}
line_count += main->lines[i].text_buf->get_line_count();
}
+ vscroll->set_value(vscroll->get_max());
}
float RichTextLabel::get_line_offset(int p_line) {
int line_count = 0;
- for (int i = 0; i < main->lines.size(); i++) {
+ int to_line = main->first_invalid_line.load();
+ for (int i = 0; i < to_line; i++) {
+ MutexLock lock(main->lines[i].text_buf->get_mutex());
if ((line_count <= p_line) && (p_line <= line_count + main->lines[i].text_buf->get_line_count())) {
float line_offset = 0.f;
for (int j = 0; j < p_line - line_count; j++) {
@@ -3920,7 +4154,8 @@ float RichTextLabel::get_line_offset(int p_line) {
}
float RichTextLabel::get_paragraph_offset(int p_paragraph) {
- if (0 <= p_paragraph && p_paragraph < main->lines.size()) {
+ int to_line = main->first_invalid_line.load();
+ if (0 <= p_paragraph && p_paragraph < to_line) {
return main->lines[p_paragraph].offset.y;
}
return 0;
@@ -3928,7 +4163,9 @@ float RichTextLabel::get_paragraph_offset(int p_paragraph) {
int RichTextLabel::get_line_count() const {
int line_count = 0;
- for (int i = 0; i < main->lines.size(); i++) {
+ int to_line = main->first_invalid_line.load();
+ for (int i = 0; i < to_line; i++) {
+ MutexLock lock(main->lines[i].text_buf->get_mutex());
line_count += main->lines[i].text_buf->get_line_count();
}
return line_count;
@@ -3989,13 +4226,13 @@ bool RichTextLabel::_search_table(ItemTable *p_table, List<Item *>::Element *p_f
ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
ItemFrame *frame = static_cast<ItemFrame *>(E->get());
if (p_reverse_search) {
- for (int i = frame->lines.size() - 1; i >= 0; i--) {
+ for (int i = (int)frame->lines.size() - 1; i >= 0; i--) {
if (_search_line(frame, i, p_string, -1, p_reverse_search)) {
return true;
}
}
} else {
- for (int i = 0; i < frame->lines.size(); i++) {
+ for (int i = 0; i < (int)frame->lines.size(); i++) {
if (_search_line(frame, i, p_string, 0, p_reverse_search)) {
return true;
}
@@ -4008,12 +4245,12 @@ bool RichTextLabel::_search_table(ItemTable *p_table, List<Item *>::Element *p_f
bool RichTextLabel::_search_line(ItemFrame *p_frame, int p_line, const String &p_string, int p_char_idx, bool p_reverse_search) {
ERR_FAIL_COND_V(p_frame == nullptr, false);
- ERR_FAIL_COND_V(p_line < 0 || p_line >= p_frame->lines.size(), false);
+ ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), false);
- Line &l = p_frame->lines.write[p_line];
+ Line &l = p_frame->lines[p_line];
String text;
- Item *it_to = (p_line + 1 < p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
+ Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
switch (it->type) {
case ITEM_NEWLINE: {
@@ -4071,7 +4308,8 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
int char_idx = p_search_previous ? -1 : 0;
int current_line = 0;
- int ending_line = main->lines.size() - 1;
+ int to_line = main->first_invalid_line.load();
+ int ending_line = to_line - 1;
if (p_from_selection && selection.active) {
// First check to see if other results exist in current line
char_idx = p_search_previous ? selection.from_char - 1 : selection.to_char;
@@ -4120,8 +4358,8 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
while (current_line != ending_line) {
// Wrap around
if (current_line < 0) {
- current_line = main->lines.size() - 1;
- } else if (current_line >= main->lines.size()) {
+ current_line = to_line - 1;
+ } else if (current_line >= to_line) {
current_line = 0;
}
@@ -4143,12 +4381,13 @@ bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p
String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p_selection) const {
String text;
+
ERR_FAIL_COND_V(p_frame == nullptr, text);
- ERR_FAIL_COND_V(p_line < 0 || p_line >= p_frame->lines.size(), text);
+ ERR_FAIL_COND_V(p_line < 0 || p_line >= (int)p_frame->lines.size(), text);
- Line &l = p_frame->lines.write[p_line];
+ Line &l = p_frame->lines[p_line];
- Item *it_to = (p_line + 1 < p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
+ Item *it_to = (p_line + 1 < (int)p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
int end_idx = 0;
if (it_to != nullptr) {
end_idx = it_to->index;
@@ -4163,7 +4402,7 @@ String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p
for (Item *E : table->subitems) {
ERR_CONTINUE(E->type != ITEM_FRAME); // Children should all be frames.
ItemFrame *frame = static_cast<ItemFrame *>(E);
- for (int i = 0; i < frame->lines.size(); i++) {
+ for (int i = 0; i < (int)frame->lines.size(); i++) {
text += _get_line_text(frame, i, p_selection);
}
}
@@ -4227,7 +4466,8 @@ String RichTextLabel::get_selected_text() const {
}
String text;
- for (int i = 0; i < main->lines.size(); i++) {
+ int to_line = main->first_invalid_line.load();
+ for (int i = 0; i < to_line; i++) {
text += _get_line_text(main, i, selection);
}
return text;
@@ -4368,19 +4608,23 @@ String RichTextLabel::get_parsed_text() const {
void RichTextLabel::set_text_direction(Control::TextDirection p_text_direction) {
ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
+ _stop_thread();
+
if (text_direction != p_text_direction) {
text_direction = p_text_direction;
- main->first_invalid_line = 0; //invalidate ALL
- _validate_line_caches(main);
+ main->first_invalid_line.store(0); //invalidate ALL
+ _validate_line_caches();
update();
}
}
void RichTextLabel::set_structured_text_bidi_override(TextServer::StructuredTextParser p_parser) {
if (st_parser != p_parser) {
+ _stop_thread();
+
st_parser = p_parser;
- main->first_invalid_line = 0; //invalidate ALL
- _validate_line_caches(main);
+ main->first_invalid_line.store(0); //invalidate ALL
+ _validate_line_caches();
update();
}
}
@@ -4390,10 +4634,14 @@ TextServer::StructuredTextParser RichTextLabel::get_structured_text_bidi_overrid
}
void RichTextLabel::set_structured_text_bidi_override_options(Array p_args) {
- st_args = p_args;
- main->first_invalid_line = 0; //invalidate ALL
- _validate_line_caches(main);
- update();
+ if (st_args != p_args) {
+ _stop_thread();
+
+ st_args = p_args;
+ main->first_invalid_line.store(0); //invalidate ALL
+ _validate_line_caches();
+ update();
+ }
}
Array RichTextLabel::get_structured_text_bidi_override_options() const {
@@ -4406,9 +4654,11 @@ Control::TextDirection RichTextLabel::get_text_direction() const {
void RichTextLabel::set_language(const String &p_language) {
if (language != p_language) {
+ _stop_thread();
+
language = p_language;
- main->first_invalid_line = 0; //invalidate ALL
- _validate_line_caches(main);
+ main->first_invalid_line.store(0); //invalidate ALL
+ _validate_line_caches();
update();
}
}
@@ -4419,9 +4669,11 @@ String RichTextLabel::get_language() const {
void RichTextLabel::set_autowrap_mode(RichTextLabel::AutowrapMode p_mode) {
if (autowrap_mode != p_mode) {
+ _stop_thread();
+
autowrap_mode = p_mode;
main->first_invalid_line = 0; //invalidate ALL
- _validate_line_caches(main);
+ _validate_line_caches();
update();
}
}
@@ -4432,6 +4684,8 @@ RichTextLabel::AutowrapMode RichTextLabel::get_autowrap_mode() const {
void RichTextLabel::set_percent_visible(float p_percent) {
if (percent_visible != p_percent) {
+ _stop_thread();
+
if (p_percent < 0 || p_percent >= 1) {
visible_characters = -1;
percent_visible = 1;
@@ -4440,8 +4694,8 @@ void RichTextLabel::set_percent_visible(float p_percent) {
percent_visible = p_percent;
}
if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING) {
- main->first_invalid_line = 0; //invalidate ALL
- _validate_line_caches(main);
+ main->first_invalid_line.store(0); //invalidate ALL
+ _validate_line_caches();
}
update();
}
@@ -4476,15 +4730,19 @@ void RichTextLabel::install_effect(const Variant effect) {
int RichTextLabel::get_content_height() const {
int total_height = 0;
- if (main->lines.size()) {
- total_height = main->lines[main->lines.size() - 1].offset.y + main->lines[main->lines.size() - 1].text_buf->get_size().y + main->lines[main->lines.size() - 1].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
+ int to_line = main->first_invalid_line.load();
+ if (to_line) {
+ MutexLock lock(main->lines[to_line - 1].text_buf->get_mutex());
+ total_height = main->lines[to_line - 1].offset.y + main->lines[to_line - 1].text_buf->get_size().y + main->lines[to_line - 1].text_buf->get_line_count() * get_theme_constant(SNAME("line_separation"));
}
return total_height;
}
int RichTextLabel::get_content_width() const {
int total_width = 0;
- for (int i = 0; i < main->lines.size(); i++) {
+ int to_line = main->first_invalid_line.load();
+ for (int i = 0; i < to_line; i++) {
+ MutexLock lock(main->lines[i].text_buf->get_mutex());
total_width = MAX(total_width, main->lines[i].offset.x + main->lines[i].text_buf->get_size().x);
}
return total_width;
@@ -4603,6 +4861,14 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text);
+ ClassDB::bind_method(D_METHOD("is_ready"), &RichTextLabel::is_ready);
+
+ ClassDB::bind_method(D_METHOD("set_threaded", "threaded"), &RichTextLabel::set_threaded);
+ ClassDB::bind_method(D_METHOD("is_threaded"), &RichTextLabel::is_threaded);
+
+ ClassDB::bind_method(D_METHOD("set_progress_bar_delay", "delay_ms"), &RichTextLabel::set_progress_bar_delay);
+ ClassDB::bind_method(D_METHOD("get_progress_bar_delay"), &RichTextLabel::get_progress_bar_delay);
+
ClassDB::bind_method(D_METHOD("set_visible_characters", "amount"), &RichTextLabel::set_visible_characters);
ClassDB::bind_method(D_METHOD("get_visible_characters"), &RichTextLabel::get_visible_characters);
@@ -4643,6 +4909,9 @@ void RichTextLabel::_bind_methods() {
// Note: set "bbcode_enabled" first, to avoid unnecessary "text" resets.
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "threaded"), "set_threaded", "is_threaded");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "progress_bar_delay"), "set_progress_bar_delay", "get_progress_bar_delay");
+
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", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fit_content_height"), "set_fit_content_height", "is_fit_content_height_enabled");
@@ -4676,6 +4945,8 @@ void RichTextLabel::_bind_methods() {
ADD_SIGNAL(MethodInfo("meta_hover_started", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
ADD_SIGNAL(MethodInfo("meta_hover_ended", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
+ ADD_SIGNAL(MethodInfo("finished"));
+
BIND_ENUM_CONSTANT(AUTOWRAP_OFF);
BIND_ENUM_CONSTANT(AUTOWRAP_ARBITRARY);
BIND_ENUM_CONSTANT(AUTOWRAP_WORD);
@@ -4727,15 +4998,19 @@ RichTextLabel::VisibleCharactersBehavior RichTextLabel::get_visible_characters_b
void RichTextLabel::set_visible_characters_behavior(RichTextLabel::VisibleCharactersBehavior p_behavior) {
if (visible_chars_behavior != p_behavior) {
+ _stop_thread();
+
visible_chars_behavior = p_behavior;
- main->first_invalid_line = 0; //invalidate ALL
- _validate_line_caches(main);
+ main->first_invalid_line.store(0); //invalidate ALL
+ _validate_line_caches();
update();
}
}
void RichTextLabel::set_visible_characters(int p_visible) {
if (visible_characters != p_visible) {
+ _stop_thread();
+
visible_characters = p_visible;
if (p_visible == -1) {
percent_visible = 1;
@@ -4746,8 +5021,8 @@ void RichTextLabel::set_visible_characters(int p_visible) {
}
}
if (visible_chars_behavior == VC_CHARS_BEFORE_SHAPING) {
- main->first_invalid_line = 0; //invalidate ALL
- _validate_line_caches(main);
+ main->first_invalid_line.store(0); //invalidate ALL
+ _validate_line_caches();
}
update();
}
@@ -4759,7 +5034,9 @@ int RichTextLabel::get_visible_characters() const {
int RichTextLabel::get_character_line(int p_char) {
int line_count = 0;
- for (int i = 0; i < main->lines.size(); i++) {
+ int to_line = main->first_invalid_line.load();
+ for (int i = 0; i < to_line; i++) {
+ MutexLock lock(main->lines[i].text_buf->get_mutex());
if (main->lines[i].char_offset < p_char && p_char <= main->lines[i].char_offset + main->lines[i].char_count) {
for (int j = 0; j < main->lines[i].text_buf->get_line_count(); j++) {
Vector2i range = main->lines[i].text_buf->get_line_range(j);
@@ -4777,7 +5054,8 @@ int RichTextLabel::get_character_line(int p_char) {
int RichTextLabel::get_character_paragraph(int p_char) {
int para_count = 0;
- for (int i = 0; i < main->lines.size(); i++) {
+ int to_line = main->first_invalid_line.load();
+ for (int i = 0; i < to_line; i++) {
if (main->lines[i].char_offset < p_char && p_char <= main->lines[i].char_offset + main->lines[i].char_count) {
return para_count;
} else {
@@ -4802,7 +5080,6 @@ int RichTextLabel::get_total_character_count() const {
}
it = _get_next_item(it, true);
}
-
return tc;
}
@@ -4812,7 +5089,8 @@ int RichTextLabel::get_total_glyph_count() const {
while (it) {
if (it->type == ITEM_FRAME) {
ItemFrame *f = static_cast<ItemFrame *>(it);
- for (int i = 0; i < f->lines.size(); i++) {
+ for (int i = 0; i < (int)f->lines.size(); i++) {
+ MutexLock lock(f->lines[i].text_buf->get_mutex());
tg += TS->shaped_text_get_glyph_count(f->lines[i].text_buf->get_rid());
}
}
@@ -4836,7 +5114,6 @@ Size2 RichTextLabel::get_minimum_size() const {
}
if (fit_content_height) {
- const_cast<RichTextLabel *>(this)->_validate_line_caches(main);
size.y += get_content_height();
}
@@ -5034,10 +5311,10 @@ RichTextLabel::RichTextLabel(const String &p_text) {
main->index = 0;
current = main;
main->lines.resize(1);
- main->lines.write[0].from = main;
- main->first_invalid_line = 0;
- main->first_resized_line = 0;
- main->first_invalid_font_line = 0;
+ main->lines[0].from = main;
+ main->first_invalid_line.store(0);
+ main->first_resized_line.store(0);
+ main->first_invalid_font_line.store(0);
current_frame = main;
vscroll = memnew(VScrollBar);
@@ -5052,10 +5329,13 @@ RichTextLabel::RichTextLabel(const String &p_text) {
vscroll->hide();
set_text(p_text);
+ updating.store(false);
+ stop_thread.store(false);
set_clip_contents(true);
}
RichTextLabel::~RichTextLabel() {
+ _stop_thread();
memdelete(main);
}
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index c6d0d0875d..7fbd5f1745 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -141,10 +141,10 @@ private:
struct ItemFrame : public Item {
bool cell = false;
- Vector<Line> lines;
- int first_invalid_line = 0;
- int first_invalid_font_line = 0;
- int first_resized_line = 0;
+ LocalVector<Line> lines;
+ std::atomic<int> first_invalid_line;
+ std::atomic<int> first_invalid_font_line;
+ std::atomic<int> first_resized_line;
ItemFrame *parent_frame = nullptr;
@@ -155,7 +155,12 @@ private:
Size2 max_size_over = Size2(-1, -1);
Rect2 padding;
- ItemFrame() { type = ITEM_FRAME; }
+ ItemFrame() {
+ type = ITEM_FRAME;
+ first_invalid_line.store(0);
+ first_invalid_font_line.store(0);
+ first_resized_line.store(0);
+ }
};
struct ItemText : public Item {
@@ -263,8 +268,8 @@ private:
int width = 0;
};
- Vector<Column> columns;
- Vector<float> rows;
+ LocalVector<Column> columns;
+ LocalVector<float> rows;
int total_width = 0;
int total_height = 0;
@@ -363,6 +368,16 @@ private:
Item *current = nullptr;
ItemFrame *current_frame = nullptr;
+ Thread thread;
+ Mutex data_mutex;
+ bool threaded = false;
+ std::atomic<bool> stop_thread;
+ std::atomic<bool> updating;
+ std::atomic<double> loaded;
+
+ uint64_t loading_started = 0;
+ int progress_delay = 1000;
+
VScrollBar *vscroll = nullptr;
AutowrapMode autowrap_mode = AUTOWRAP_WORD_SMART;
@@ -392,7 +407,11 @@ private:
Array custom_effects;
void _invalidate_current_line(ItemFrame *p_frame);
- void _validate_line_caches(ItemFrame *p_frame);
+
+ static void _thread_function(void *self);
+ void _stop_thread();
+ bool _validate_line_caches();
+ void _process_line_caches();
void _add_item(Item *p_item, bool p_enter = false, bool p_ensure_newline = false);
void _remove_item(Item *p_item, const int p_line, const int p_subitem_line);
@@ -446,8 +465,9 @@ private:
bool _search_line(ItemFrame *p_frame, int p_line, const String &p_string, int p_char_idx, bool p_reverse_search);
bool _search_table(ItemTable *p_table, List<Item *>::Element *p_from, const String &p_string, bool p_reverse_search);
- void _shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, int *r_char_offset);
- void _resize_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width);
+ float _shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, float p_h, int *r_char_offset);
+ float _resize_line(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size, int p_width, float p_h);
+
void _update_line_font(ItemFrame *p_frame, int p_line, const Ref<Font> &p_base_font, int p_base_font_size);
int _draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_ofs, int p_width, const Color &p_base_color, int p_outline_size, const Color &p_outline_color, const Color &p_font_shadow_color, int p_shadow_outline_size, const Point2 &p_shadow_ofs, int &r_processed_glyphs);
float _find_click_in_line(ItemFrame *p_frame, int p_line, const Vector2 &p_ofs, int p_width, const Point2i &p_click, ItemFrame **r_click_frame = nullptr, int *r_click_line = nullptr, Item **r_click_item = nullptr, int *r_click_char = nullptr, bool p_table = false);
@@ -480,9 +500,9 @@ private:
bool _find_layout_subitem(Item *from, Item *to);
void _fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack);
- void _update_scroll();
void _update_fx(ItemFrame *p_frame, double p_delta_time);
void _scroll_changed(double);
+ int _find_first_line(int p_from, int p_to, int p_vofs) const;
virtual void gui_input(const Ref<InputEvent> &p_event) override;
virtual String get_tooltip(const Point2 &p_pos) const override;
@@ -611,6 +631,14 @@ public:
bool is_deselect_on_focus_loss_enabled() const;
void deselect();
+ bool is_ready() const;
+
+ void set_threaded(bool p_threaded);
+ bool is_threaded() const;
+
+ void set_progress_bar_delay(int p_delay_ms);
+ int get_progress_bar_delay() const;
+
// Context menu.
PopupMenu *get_menu() const;
bool is_menu_visible() const;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 315ffbd419..0f74c9c357 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -2452,17 +2452,17 @@ void TextEdit::_do_backspace(bool p_word, bool p_all_to_left) {
if (p_word) {
int column = caret.column;
// Check for the case "<word><space><caret>" and ignore the space.
- // No need to check for column being 0 since it is cheked above.
+ // No need to check for column being 0 since it is checked above.
if (is_whitespace(text[caret.line][caret.column - 1])) {
column -= 1;
}
// Get a list with the indices of the word bounds of the given text line.
const PackedInt32Array words = TS->shaped_text_get_word_breaks(text.get_line_data(caret.line)->get_rid());
if (words.is_empty() || column <= words[0]) {
- // If "words" is empty, meaning no words are left, we can remove everything until the begining of the line.
+ // If "words" is empty, meaning no words are left, we can remove everything until the beginning of the line.
column = 0;
} else {
- // Otherwise search for the first word break that is smaller than the index from we're currentlu deleteing
+ // Otherwise search for the first word break that is smaller than the index from which we're currently deleting.
for (int i = words.size() - 2; i >= 0; i = i - 2) {
if (words[i] < column) {
column = words[i];
@@ -4756,9 +4756,7 @@ void TextEdit::add_gutter(int p_at) {
gutters.insert(p_at, GutterInfo());
}
- for (int i = 0; i < text.size() + 1; i++) {
- text.add_gutter(p_at);
- }
+ text.add_gutter(p_at);
emit_signal(SNAME("gutter_added"));
update();
}
@@ -4768,9 +4766,7 @@ void TextEdit::remove_gutter(int p_gutter) {
gutters.remove_at(p_gutter);
- for (int i = 0; i < text.size() + 1; i++) {
- text.remove_gutter(p_gutter);
- }
+ text.remove_gutter(p_gutter);
emit_signal(SNAME("gutter_removed"));
update();
}
diff --git a/scene/gui/texture_progress_bar.cpp b/scene/gui/texture_progress_bar.cpp
index f79c68671c..081d065efe 100644
--- a/scene/gui/texture_progress_bar.cpp
+++ b/scene/gui/texture_progress_bar.cpp
@@ -650,8 +650,8 @@ void TextureProgressBar::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "tint_progress"), "set_tint_progress", "get_tint_progress");
ADD_GROUP("Radial Fill", "radial_");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radial_initial_angle", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_radial_initial_angle", "get_radial_initial_angle");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radial_fill_degrees", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider"), "set_fill_degrees", "get_fill_degrees");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radial_initial_angle", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider,degrees"), "set_radial_initial_angle", "get_radial_initial_angle");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radial_fill_degrees", PROPERTY_HINT_RANGE, "0.0,360.0,0.1,slider,degrees"), "set_fill_degrees", "get_fill_degrees");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "radial_center_offset"), "set_radial_center_offset", "get_radial_center_offset");
BIND_ENUM_CONSTANT(FILL_LEFT_TO_RIGHT);
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 72254b85bd..4d18bc91c4 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -2561,7 +2561,6 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
cache.click_column = col;
cache.click_pos = click_pos;
update();
- //emit_signal(SNAME("button_pressed"));
return -1;
}
@@ -2583,9 +2582,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
if (!c.selected || p_button == MouseButton::RIGHT) {
p_item->select(col);
emit_signal(SNAME("multi_selected"), p_item, col, true);
- if (p_button == MouseButton::RIGHT) {
- emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position());
- }
+ emit_signal(SNAME("item_mouse_selected"), get_local_mouse_position(), p_button);
//p_item->selected_signal.call(col);
} else {
@@ -2600,9 +2597,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
bool inrange = false;
select_single_item(p_item, root, col, selected_item, &inrange);
- if (p_button == MouseButton::RIGHT) {
- emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position());
- }
+ emit_signal(SNAME("item_mouse_selected"), get_local_mouse_position(), p_button);
} else {
int icount = _count_selected_items(root);
@@ -2614,9 +2609,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
select_single_item(p_item, root, col);
}
- if (p_button == MouseButton::RIGHT) {
- emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position());
- }
+ emit_signal(SNAME("item_mouse_selected"), get_local_mouse_position(), p_button);
}
}
@@ -2653,11 +2646,11 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
if (force_edit_checkbox_only_on_checkbox) {
if (x < cache.checked->get_width()) {
p_item->set_checked(col, !c.checked);
- item_edited(col, p_item);
+ item_edited(col, p_item, p_button);
}
} else {
p_item->set_checked(col, !c.checked);
- item_edited(col, p_item);
+ item_edited(col, p_item, p_button);
}
click_handled = true;
//p_item->edited_signal.call(col);
@@ -2699,17 +2692,17 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
p_item->set_range(col, c.val + (up ? 1.0 : -1.0) * c.step);
- item_edited(col, p_item);
+ item_edited(col, p_item, p_button);
} else if (p_button == MouseButton::RIGHT) {
p_item->set_range(col, (up ? c.max : c.min));
- item_edited(col, p_item);
+ item_edited(col, p_item, p_button);
} else if (p_button == MouseButton::WHEEL_UP) {
p_item->set_range(col, c.val + c.step);
- item_edited(col, p_item);
+ item_edited(col, p_item, p_button);
} else if (p_button == MouseButton::WHEEL_DOWN) {
p_item->set_range(col, c.val - c.step);
- item_edited(col, p_item);
+ item_edited(col, p_item, p_button);
}
//p_item->edited_signal.call(col);
@@ -2740,7 +2733,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
}
if (!p_item->cells[col].custom_button || !on_arrow) {
- item_edited(col, p_item, p_button == MouseButton::LEFT);
+ item_edited(col, p_item, p_button);
}
click_handled = true;
return -1;
@@ -2787,8 +2780,8 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int
item_h += child_h;
}
}
- if (p_item == root && p_button == MouseButton::RIGHT) {
- emit_signal(SNAME("empty_rmb"), get_local_mouse_position());
+ if (p_item == root) {
+ emit_signal(SNAME("empty_clicked"), get_local_mouse_position(), p_button);
}
}
@@ -3196,7 +3189,6 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
}
Ref<InputEventMouseMotion> mm = p_event;
-
if (mm.is_valid()) {
if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff
update_cache();
@@ -3326,18 +3318,17 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
}
}
- Ref<InputEventMouseButton> b = p_event;
-
- if (b.is_valid()) {
+ Ref<InputEventMouseButton> mb = p_event;
+ if (mb.is_valid()) {
if (cache.font.is_null()) { // avoid a strange case that may corrupt stuff
update_cache();
}
bool rtl = is_layout_rtl();
- if (!b->is_pressed()) {
- if (b->get_button_index() == MouseButton::LEFT) {
- Point2 pos = b->get_position();
+ if (!mb->is_pressed()) {
+ if (mb->get_button_index() == MouseButton::LEFT) {
+ Point2 pos = mb->get_position();
if (rtl) {
pos.x = get_size().width - pos.x;
}
@@ -3372,7 +3363,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
warp_mouse(range_drag_capture_pos);
} else {
Rect2 rect = get_selected()->get_meta("__focus_rect");
- Point2 mpos = b->get_position();
+ Point2 mpos = mb->get_position();
int icon_size_x = 0;
Ref<Texture2D> icon = get_selected()->get_icon(selected_col);
if (icon.is_valid()) {
@@ -3400,17 +3391,6 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
pressing_for_editor = false;
}
- if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr) {
- // make sure in case of wrong reference after reconstructing whole TreeItems
- cache.click_item = get_item_at_position(cache.click_pos);
- emit_signal(SNAME("button_pressed"), cache.click_item, cache.click_column, cache.click_id);
- }
- cache.click_type = Cache::CLICK_NONE;
- cache.click_index = -1;
- cache.click_id = -1;
- cache.click_item = nullptr;
- cache.click_column = 0;
-
if (drag_touching) {
if (drag_speed == 0) {
drag_touching_deaccel = false;
@@ -3420,8 +3400,20 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
drag_touching_deaccel = true;
}
}
- update();
}
+
+ if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr) {
+ // make sure in case of wrong reference after reconstructing whole TreeItems
+ cache.click_item = get_item_at_position(cache.click_pos);
+ emit_signal("button_clicked", cache.click_item, cache.click_column, cache.click_id, mb->get_button_index());
+ }
+
+ cache.click_type = Cache::CLICK_NONE;
+ cache.click_index = -1;
+ cache.click_id = -1;
+ cache.click_item = nullptr;
+ cache.click_column = 0;
+ update();
return;
}
@@ -3429,12 +3421,12 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
return;
}
- switch (b->get_button_index()) {
+ switch (mb->get_button_index()) {
case MouseButton::RIGHT:
case MouseButton::LEFT: {
Ref<StyleBox> bg = cache.bg;
- Point2 pos = b->get_position();
+ Point2 pos = mb->get_position();
if (rtl) {
pos.x = get_size().width - pos.x;
}
@@ -3444,7 +3436,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
pos.y -= _get_title_button_height();
if (pos.y < 0) {
- if (b->get_button_index() == MouseButton::LEFT) {
+ if (mb->get_button_index() == MouseButton::LEFT) {
pos.x += cache.offset.x;
int len = 0;
for (int i = 0; i < columns.size(); i++) {
@@ -3461,10 +3453,8 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
break;
}
}
+
if (!root || (!root->get_first_child() && hide_root)) {
- if (b->get_button_index() == MouseButton::RIGHT && allow_rmb_select) {
- emit_signal(SNAME("empty_tree_rmb_selected"), get_local_mouse_position());
- }
break;
}
@@ -3479,17 +3469,17 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
cache.rtl = is_layout_rtl();
blocked++;
- propagate_mouse_event(pos + cache.offset, 0, 0, x_limit + cache.offset.width, b->is_double_click(), root, b->get_button_index(), b);
+ propagate_mouse_event(pos + cache.offset, 0, 0, x_limit + cache.offset.width, mb->is_double_click(), root, mb->get_button_index(), mb);
blocked--;
if (pressing_for_editor) {
- pressing_pos = b->get_position();
+ pressing_pos = mb->get_position();
if (rtl) {
pressing_pos.x = get_size().width - pressing_pos.x;
}
}
- if (b->get_button_index() == MouseButton::RIGHT) {
+ if (mb->get_button_index() == MouseButton::RIGHT) {
break;
}
@@ -3512,8 +3502,8 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
set_physics_process_internal(true);
}
- if (b->get_button_index() == MouseButton::LEFT) {
- if (get_item_at_position(b->get_position()) == nullptr && !b->is_shift_pressed() && !b->is_ctrl_pressed() && !b->is_command_pressed()) {
+ if (mb->get_button_index() == MouseButton::LEFT) {
+ if (get_item_at_position(mb->get_position()) == nullptr && !mb->is_shift_pressed() && !mb->is_ctrl_pressed() && !mb->is_command_pressed()) {
emit_signal(SNAME("nothing_selected"));
}
}
@@ -3527,7 +3517,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
} break;
case MouseButton::WHEEL_UP: {
double prev_value = v_scroll->get_value();
- v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8);
+ v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * mb->get_factor() / 8);
if (v_scroll->get_value() != prev_value) {
accept_event();
}
@@ -3535,7 +3525,7 @@ void Tree::gui_input(const Ref<InputEvent> &p_event) {
} break;
case MouseButton::WHEEL_DOWN: {
double prev_value = v_scroll->get_value();
- v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8);
+ v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * mb->get_factor() / 8);
if (v_scroll->get_value() != prev_value) {
accept_event();
}
@@ -3981,16 +3971,16 @@ TreeItem *Tree::get_last_item() const {
return last;
}
-void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) {
+void Tree::item_edited(int p_column, TreeItem *p_item, MouseButton p_mouse_index) {
edited_item = p_item;
edited_col = p_column;
if (p_item != nullptr && p_column >= 0 && p_column < p_item->cells.size()) {
edited_item->cells.write[p_column].dirty = true;
}
- if (p_lmb) {
+ if (p_mouse_index == MouseButton::NONE) {
emit_signal(SNAME("item_edited"));
} else {
- emit_signal(SNAME("item_rmb_edited"));
+ emit_signal(SNAME("custom_item_clicked"), p_mouse_index);
}
}
@@ -5035,17 +5025,15 @@ void Tree::_bind_methods() {
ADD_SIGNAL(MethodInfo("item_selected"));
ADD_SIGNAL(MethodInfo("cell_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_rmb", PropertyInfo(Variant::VECTOR2, "position")));
- ADD_SIGNAL(MethodInfo("empty_tree_rmb_selected", PropertyInfo(Variant::VECTOR2, "position")));
+ ADD_SIGNAL(MethodInfo("item_mouse_selected", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::INT, "mouse_button_index")));
+ ADD_SIGNAL(MethodInfo("empty_clicked", PropertyInfo(Variant::VECTOR2, "position"), PropertyInfo(Variant::INT, "mouse_button_index")));
ADD_SIGNAL(MethodInfo("item_edited"));
- ADD_SIGNAL(MethodInfo("item_rmb_edited"));
+ ADD_SIGNAL(MethodInfo("custom_item_clicked", PropertyInfo(Variant::INT, "mouse_button_index")));
ADD_SIGNAL(MethodInfo("item_custom_button_pressed"));
ADD_SIGNAL(MethodInfo("item_double_clicked"));
ADD_SIGNAL(MethodInfo("item_collapsed", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "TreeItem")));
ADD_SIGNAL(MethodInfo("check_propagated_to_item", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "TreeItem"), PropertyInfo(Variant::INT, "column")));
- //ADD_SIGNAL( MethodInfo("item_double_clicked" ) );
- 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("button_clicked", PropertyInfo(Variant::OBJECT, "item", PROPERTY_HINT_RESOURCE_TYPE, "TreeItem"), PropertyInfo(Variant::INT, "column"), PropertyInfo(Variant::INT, "id"), PropertyInfo(Variant::INT, "mouse_button_index")));
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")));
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index dbf492e9aa..a70f24cb62 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -474,7 +474,7 @@ private:
void _notification(int p_what);
- void item_edited(int p_column, TreeItem *p_item, bool p_lmb = true);
+ void item_edited(int p_column, TreeItem *p_item, MouseButton p_mouse_index = MouseButton::NONE);
void item_changed(int p_column, TreeItem *p_item);
void item_selected(int p_column, TreeItem *p_item);
void item_deselected(int p_column, TreeItem *p_item);
diff --git a/scene/gui/video_stream_player.cpp b/scene/gui/video_stream_player.cpp
index ca2dad71af..20bc9a1028 100644
--- a/scene/gui/video_stream_player.cpp
+++ b/scene/gui/video_stream_player.cpp
@@ -443,7 +443,7 @@ void VideoStreamPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "audio_track", PROPERTY_HINT_RANGE, "0,128,1"), "set_audio_track", "get_audio_track");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "VideoStream"), "set_stream", "get_stream");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_volume_db", "get_volume_db");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01,suffix:dB"), "set_volume_db", "get_volume_db");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume", PROPERTY_HINT_RANGE, "0,15,0.01,exp", PROPERTY_USAGE_NONE), "set_volume", "get_volume");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "has_autoplay");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "paused"), "set_paused", "is_paused");