summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/line_builder.cpp33
-rw-r--r--scene/3d/area_3d.cpp10
-rw-r--r--scene/3d/area_3d.h4
-rw-r--r--scene/3d/audio_stream_player_3d.cpp5
-rw-r--r--scene/3d/path_3d.cpp6
-rw-r--r--scene/3d/physics_joint_3d.cpp13
-rw-r--r--scene/3d/physics_joint_3d.h7
-rw-r--r--scene/3d/sprite_3d.cpp4
-rw-r--r--scene/gui/color_picker.cpp2
-rw-r--r--scene/gui/control.cpp107
-rw-r--r--scene/gui/control.h8
-rw-r--r--scene/gui/dialogs.cpp14
-rw-r--r--scene/gui/dialogs.h6
-rw-r--r--scene/gui/file_dialog.cpp20
-rw-r--r--scene/gui/line_edit.cpp8
-rw-r--r--scene/gui/popup_menu.cpp39
-rw-r--r--scene/gui/rich_text_effect.cpp31
-rw-r--r--scene/gui/rich_text_effect.h29
-rw-r--r--scene/gui/rich_text_label.cpp2730
-rw-r--r--scene/gui/rich_text_label.h269
-rw-r--r--scene/gui/scroll_bar.cpp12
-rw-r--r--scene/gui/scroll_bar.h1
-rw-r--r--scene/gui/tab_container.cpp29
-rw-r--r--scene/gui/tab_container.h4
-rw-r--r--scene/gui/text_edit.cpp12
-rw-r--r--scene/gui/text_edit.h2
-rw-r--r--scene/gui/texture_progress_bar.cpp (renamed from scene/gui/texture_progress.cpp)114
-rw-r--r--scene/gui/texture_progress_bar.h (renamed from scene/gui/texture_progress.h)16
-rw-r--r--scene/gui/tree.cpp10
-rw-r--r--scene/gui/tree.h2
-rw-r--r--scene/main/node.h5
-rw-r--r--scene/main/viewport.cpp2
-rw-r--r--scene/main/viewport.h2
-rw-r--r--scene/main/window.cpp10
-rw-r--r--scene/main/window.h2
-rw-r--r--scene/register_scene_types.cpp24
-rw-r--r--scene/resources/animation.cpp6
-rw-r--r--scene/resources/animation.h2
-rw-r--r--scene/resources/default_theme/default_theme.cpp10
-rw-r--r--scene/resources/environment.cpp2
-rw-r--r--scene/resources/font.cpp127
-rw-r--r--scene/resources/font.h20
-rw-r--r--scene/resources/mesh.cpp10
-rw-r--r--scene/resources/mesh.h13
-rw-r--r--scene/resources/packed_scene.cpp10
-rw-r--r--scene/resources/packed_scene.h1
-rw-r--r--scene/resources/resource_format_text.cpp1
-rw-r--r--scene/resources/sky_material.cpp2
-rw-r--r--scene/resources/style_box.cpp10
-rw-r--r--scene/resources/style_box.h1
-rw-r--r--scene/resources/surface_tool.cpp357
-rw-r--r--scene/resources/surface_tool.h28
-rw-r--r--scene/resources/theme.cpp48
-rw-r--r--scene/resources/theme.h8
54 files changed, 2626 insertions, 1622 deletions
diff --git a/scene/2d/line_builder.cpp b/scene/2d/line_builder.cpp
index f1522dbaeb..e0116d9bad 100644
--- a/scene/2d/line_builder.cpp
+++ b/scene/2d/line_builder.cpp
@@ -459,39 +459,6 @@ void LineBuilder::strip_begin(Vector2 up, Vector2 down, Color color, float uvx)
_last_index[DOWN] = vi + 1;
}
-void LineBuilder::strip_new_quad(Vector2 up, Vector2 down, Color color, float uvx) {
- int vi = vertices.size();
-
- vertices.push_back(vertices[_last_index[UP]]);
- vertices.push_back(vertices[_last_index[DOWN]]);
- vertices.push_back(up);
- vertices.push_back(down);
-
- if (_interpolate_color) {
- colors.push_back(color);
- colors.push_back(color);
- colors.push_back(color);
- colors.push_back(color);
- }
-
- if (texture_mode != Line2D::LINE_TEXTURE_NONE) {
- uvs.push_back(uvs[_last_index[UP]]);
- uvs.push_back(uvs[_last_index[DOWN]]);
- uvs.push_back(Vector2(uvx, UP));
- uvs.push_back(Vector2(uvx, DOWN));
- }
-
- indices.push_back(vi);
- indices.push_back(vi + 3);
- indices.push_back(vi + 1);
- indices.push_back(vi);
- indices.push_back(vi + 2);
- indices.push_back(vi + 3);
-
- _last_index[UP] = vi + 2;
- _last_index[DOWN] = vi + 3;
-}
-
void LineBuilder::strip_add_quad(Vector2 up, Vector2 down, Color color, float uvx) {
int vi = vertices.size();
diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp
index b1ffe76662..b1adb0e88e 100644
--- a/scene/3d/area_3d.cpp
+++ b/scene/3d/area_3d.cpp
@@ -505,11 +505,11 @@ bool Area3D::is_overriding_audio_bus() const {
return audio_bus_override;
}
-void Area3D::set_audio_bus(const StringName &p_audio_bus) {
+void Area3D::set_audio_bus_name(const StringName &p_audio_bus) {
audio_bus = p_audio_bus;
}
-StringName Area3D::get_audio_bus() const {
+StringName Area3D::get_audio_bus_name() const {
for (int i = 0; i < AudioServer::get_singleton()->get_bus_count(); i++) {
if (AudioServer::get_singleton()->get_bus_name(i) == audio_bus) {
return audio_bus;
@@ -625,8 +625,8 @@ void Area3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_audio_bus_override", "enable"), &Area3D::set_audio_bus_override);
ClassDB::bind_method(D_METHOD("is_overriding_audio_bus"), &Area3D::is_overriding_audio_bus);
- ClassDB::bind_method(D_METHOD("set_audio_bus", "name"), &Area3D::set_audio_bus);
- ClassDB::bind_method(D_METHOD("get_audio_bus"), &Area3D::get_audio_bus);
+ ClassDB::bind_method(D_METHOD("set_audio_bus_name", "name"), &Area3D::set_audio_bus_name);
+ ClassDB::bind_method(D_METHOD("get_audio_bus_name"), &Area3D::get_audio_bus_name);
ClassDB::bind_method(D_METHOD("set_use_reverb_bus", "enable"), &Area3D::set_use_reverb_bus);
ClassDB::bind_method(D_METHOD("is_using_reverb_bus"), &Area3D::is_using_reverb_bus);
@@ -665,7 +665,7 @@ void Area3D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "collision_mask", PROPERTY_HINT_LAYERS_3D_PHYSICS), "set_collision_mask", "get_collision_mask");
ADD_GROUP("Audio Bus", "audio_bus_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "audio_bus_override"), "set_audio_bus_override", "is_overriding_audio_bus");
- ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "audio_bus_name", PROPERTY_HINT_ENUM, ""), "set_audio_bus", "get_audio_bus");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "audio_bus_name", PROPERTY_HINT_ENUM, ""), "set_audio_bus_name", "get_audio_bus_name");
ADD_GROUP("Reverb Bus", "reverb_bus_");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "reverb_bus_enable"), "set_use_reverb_bus", "is_using_reverb_bus");
ADD_PROPERTY(PropertyInfo(Variant::STRING_NAME, "reverb_bus_name", PROPERTY_HINT_ENUM, ""), "set_reverb_bus", "get_reverb_bus");
diff --git a/scene/3d/area_3d.h b/scene/3d/area_3d.h
index 7d1f030baf..51f6317517 100644
--- a/scene/3d/area_3d.h
+++ b/scene/3d/area_3d.h
@@ -190,8 +190,8 @@ public:
void set_audio_bus_override(bool p_override);
bool is_overriding_audio_bus() const;
- void set_audio_bus(const StringName &p_audio_bus);
- StringName get_audio_bus() const;
+ void set_audio_bus_name(const StringName &p_audio_bus);
+ StringName get_audio_bus_name() const;
void set_use_reverb_bus(bool p_enable);
bool is_using_reverb_bus() const;
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index b093788d75..2907eb3c7e 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -327,9 +327,6 @@ float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
return att;
}
-void _update_sound() {
-}
-
void AudioStreamPlayer3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
velocity_tracker->reset(get_global_transform().origin);
@@ -487,7 +484,7 @@ void AudioStreamPlayer3D::_notification(int p_what) {
if (area) {
if (area->is_overriding_audio_bus()) {
//override audio bus
- StringName bus_name = area->get_audio_bus();
+ StringName bus_name = area->get_audio_bus_name();
output.bus_index = AudioServer::get_singleton()->thread_find_bus_index(bus_name);
}
diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp
index f25a64c567..ae6bbad8bf 100644
--- a/scene/3d/path_3d.cpp
+++ b/scene/3d/path_3d.cpp
@@ -94,10 +94,6 @@ void PathFollow3D::_update_transform(bool p_update_xyz_rot) {
return;
}
- if (delta_offset == 0) {
- return;
- }
-
float bl = c->get_baked_length();
if (bl == 0.0) {
return;
@@ -156,7 +152,7 @@ void PathFollow3D::_update_transform(bool p_update_xyz_rot) {
t.origin = pos;
- if (p_update_xyz_rot) { // Only update rotation if some parameter has changed - i.e. not on addition to scene tree
+ if (p_update_xyz_rot && delta_offset != 0) { // Only update rotation if some parameter has changed - i.e. not on addition to scene tree.
Vector3 t_prev = (pos - c->interpolate_baked(offset - delta_offset, cubic)).normalized();
Vector3 t_cur = (c->interpolate_baked(offset + delta_offset, cubic) - pos).normalized();
diff --git a/scene/3d/physics_joint_3d.cpp b/scene/3d/physics_joint_3d.cpp
index ab9cdb9fd8..06de5ad0ae 100644
--- a/scene/3d/physics_joint_3d.cpp
+++ b/scene/3d/physics_joint_3d.cpp
@@ -710,9 +710,6 @@ void Generic6DOFJoint3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_flag_z", "flag", "value"), &Generic6DOFJoint3D::set_flag_z);
ClassDB::bind_method(D_METHOD("get_flag_z", "flag"), &Generic6DOFJoint3D::get_flag_z);
- ClassDB::bind_method(D_METHOD("set_precision", "precision"), &Generic6DOFJoint3D::set_precision);
- ClassDB::bind_method(D_METHOD("get_precision"), &Generic6DOFJoint3D::get_precision);
-
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "linear_limit_x/enabled"), "set_flag_x", "get_flag_x", FLAG_ENABLE_LINEAR_LIMIT);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/upper_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_UPPER_LIMIT);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "linear_limit_x/lower_distance"), "set_param_x", "get_param_x", PARAM_LINEAR_LOWER_LIMIT);
@@ -801,8 +798,6 @@ void Generic6DOFJoint3D::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_z/damping"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_DAMPING);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "angular_spring_z/equilibrium_point"), "set_param_z", "get_param_z", PARAM_ANGULAR_SPRING_EQUILIBRIUM_POINT);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "precision", PROPERTY_HINT_RANGE, "1,99999,1"), "set_precision", "get_precision");
-
BIND_ENUM_CONSTANT(PARAM_LINEAR_LOWER_LIMIT);
BIND_ENUM_CONSTANT(PARAM_LINEAR_UPPER_LIMIT);
BIND_ENUM_CONSTANT(PARAM_LINEAR_LIMIT_SOFTNESS);
@@ -921,14 +916,6 @@ bool Generic6DOFJoint3D::get_flag_z(Flag p_flag) const {
return flags_z[p_flag];
}
-void Generic6DOFJoint3D::set_precision(int p_precision) {
- precision = p_precision;
-
- PhysicsServer3D::get_singleton()->generic_6dof_joint_set_precision(
- get_joint(),
- precision);
-}
-
RID Generic6DOFJoint3D::_configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) {
Transform gt = get_global_transform();
//Vector3 cone_twistpos = gt.origin;
diff --git a/scene/3d/physics_joint_3d.h b/scene/3d/physics_joint_3d.h
index a65f6db3bf..250ae8bf52 100644
--- a/scene/3d/physics_joint_3d.h
+++ b/scene/3d/physics_joint_3d.h
@@ -300,8 +300,6 @@ protected:
float params_z[PARAM_MAX];
bool flags_z[FLAG_MAX];
- int precision = 1;
-
virtual RID _configure_joint(PhysicsBody3D *body_a, PhysicsBody3D *body_b) override;
static void _bind_methods();
@@ -324,11 +322,6 @@ public:
void set_flag_z(Flag p_flag, bool p_enabled);
bool get_flag_z(Flag p_flag) const;
- void set_precision(int p_precision);
- int get_precision() const {
- return precision;
- }
-
Generic6DOFJoint3D();
};
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index b6999beff4..1d20a9cd3b 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -486,7 +486,7 @@ void Sprite3D::_draw() {
RS::get_singleton()->immediate_normal(immediate, normal);
RS::get_singleton()->immediate_tangent(immediate, tangent);
RS::get_singleton()->immediate_color(immediate, color);
- RS::get_singleton()->immediate_uv(immediate, uvs[i]);
+ RS::get_singleton()->immediate_uv(immediate, uvs[index[i]]);
Vector3 vtx;
vtx[x_axis] = vertices[index[i]][0];
@@ -815,7 +815,7 @@ void AnimatedSprite3D::_draw() {
RS::get_singleton()->immediate_normal(immediate, normal);
RS::get_singleton()->immediate_tangent(immediate, tangent);
RS::get_singleton()->immediate_color(immediate, color);
- RS::get_singleton()->immediate_uv(immediate, uvs[i]);
+ RS::get_singleton()->immediate_uv(immediate, uvs[indices[i]]);
Vector3 vtx;
vtx[x_axis] = vertices[indices[i]][0];
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index f8a67d154b..6ebd1011e9 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -615,7 +615,7 @@ void ColorPicker::_screen_pick_pressed() {
screen->set_default_cursor_shape(CURSOR_POINTING_HAND);
screen->connect("gui_input", callable_mp(this, &ColorPicker::_screen_input));
// It immediately toggles off in the first press otherwise.
- screen->call_deferred("connect", "hide", Callable(btn_pick, "set_pressed"), varray(false));
+ screen->call_deferred("connect", "hidden", Callable(btn_pick, "set_pressed"), varray(false));
}
screen->raise();
#ifndef _MSC_VER
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index f9b7d828f4..b471bb9d4e 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -223,13 +223,6 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
}
data.icon_override.erase(dname);
notification(NOTIFICATION_THEME_CHANGED);
- } else if (name.begins_with("custom_shaders/")) {
- String dname = name.get_slicec('/', 1);
- if (data.shader_override.has(dname)) {
- data.shader_override[dname]->disconnect("changed", callable_mp(this, &Control::_override_changed));
- }
- data.shader_override.erase(dname);
- notification(NOTIFICATION_THEME_CHANGED);
} else if (name.begins_with("custom_styles/")) {
String dname = name.get_slicec('/', 1);
if (data.style_override.has(dname)) {
@@ -264,9 +257,6 @@ bool Control::_set(const StringName &p_name, const Variant &p_value) {
if (name.begins_with("custom_icons/")) {
String dname = name.get_slicec('/', 1);
add_theme_icon_override(dname, p_value);
- } else if (name.begins_with("custom_shaders/")) {
- String dname = name.get_slicec('/', 1);
- add_theme_shader_override(dname, p_value);
} else if (name.begins_with("custom_styles/")) {
String dname = name.get_slicec('/', 1);
add_theme_style_override(dname, p_value);
@@ -318,9 +308,6 @@ bool Control::_get(const StringName &p_name, Variant &r_ret) const {
if (sname.begins_with("custom_icons/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.icon_override.has(name) ? Variant(data.icon_override[name]) : Variant();
- } else if (sname.begins_with("custom_shaders/")) {
- String name = sname.get_slicec('/', 1);
- r_ret = data.shader_override.has(name) ? Variant(data.shader_override[name]) : Variant();
} else if (sname.begins_with("custom_styles/")) {
String name = sname.get_slicec('/', 1);
r_ret = data.style_override.has(name) ? Variant(data.style_override[name]) : Variant();
@@ -368,18 +355,6 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
}
{
List<StringName> names;
- theme->get_shader_list(get_class_name(), &names);
- for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
- uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
- if (data.shader_override.has(E->get())) {
- hint |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
- }
-
- p_list->push_back(PropertyInfo(Variant::OBJECT, "custom_shaders/" + E->get(), PROPERTY_HINT_RESOURCE_TYPE, "Shader,VisualShader", hint));
- }
- }
- {
- List<StringName> names;
theme->get_stylebox_list(get_class_name(), &names);
for (List<StringName>::Element *E = names.front(); E; E = E->next()) {
uint32_t hint = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
@@ -481,10 +456,6 @@ bool Control::is_layout_rtl() const {
}
}
-void Control::_resize(const Size2 &p_size) {
- _size_changed();
-}
-
//moved theme configuration here, so controls can set up even if still not inside active scene
void Control::add_child_notify(Node *p_child) {
@@ -901,35 +872,6 @@ Ref<Texture2D> Control::get_icons(Control *p_theme_owner, Window *p_theme_owner_
return Theme::get_default()->get_icon(p_name, p_node_type);
}
-Ref<Shader> Control::get_theme_shader(const StringName &p_name, const StringName &p_node_type) const {
- if (p_node_type == StringName() || p_node_type == get_class_name()) {
- const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
- if (sdr) {
- return *sdr;
- }
- }
-
- StringName type = p_node_type ? p_node_type : get_class_name();
-
- return get_shaders(data.theme_owner, data.theme_owner_window, p_name, type);
-}
-
-Ref<Shader> Control::get_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type) {
- Ref<Shader> shader;
-
- if (_find_theme_item(p_theme_owner, p_theme_owner_window, shader, &Theme::get_shader, &Theme::has_shader, p_name, p_node_type)) {
- return shader;
- }
-
- if (Theme::get_project_default().is_valid()) {
- if (Theme::get_project_default()->has_shader(p_name, p_node_type)) {
- return Theme::get_project_default()->get_shader(p_name, p_node_type);
- }
- }
-
- return Theme::get_default()->get_shader(p_name, p_node_type);
-}
-
Ref<StyleBox> Control::get_theme_stylebox(const StringName &p_name, const StringName &p_node_type) const {
if (p_node_type == StringName() || p_node_type == get_class_name()) {
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
@@ -1078,11 +1020,6 @@ bool Control::has_theme_icon_override(const StringName &p_name) const {
return tex != nullptr;
}
-bool Control::has_theme_shader_override(const StringName &p_name) const {
- const Ref<Shader> *sdr = data.shader_override.getptr(p_name);
- return sdr != nullptr;
-}
-
bool Control::has_theme_stylebox_override(const StringName &p_name) const {
const Ref<StyleBox> *style = data.style_override.getptr(p_name);
return style != nullptr;
@@ -1133,31 +1070,6 @@ bool Control::has_icons(Control *p_theme_owner, Window *p_theme_owner_window, co
return Theme::get_default()->has_icon(p_name, p_node_type);
}
-bool Control::has_theme_shader(const StringName &p_name, const StringName &p_node_type) const {
- if (p_node_type == StringName() || p_node_type == get_class_name()) {
- if (has_theme_shader_override(p_name)) {
- return true;
- }
- }
-
- StringName type = p_node_type ? p_node_type : get_class_name();
-
- return has_shaders(data.theme_owner, data.theme_owner_window, p_name, type);
-}
-
-bool Control::has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type) {
- if (_has_theme_item(p_theme_owner, p_theme_owner_window, &Theme::has_shader, p_name, p_node_type)) {
- return true;
- }
-
- if (Theme::get_project_default().is_valid()) {
- if (Theme::get_project_default()->has_shader(p_name, p_node_type)) {
- return true;
- }
- }
- return Theme::get_default()->has_shader(p_name, p_node_type);
-}
-
bool Control::has_theme_stylebox(const StringName &p_name, const StringName &p_node_type) const {
if (p_node_type == StringName() || p_node_type == get_class_name()) {
if (has_theme_stylebox_override(p_name)) {
@@ -1891,23 +1803,6 @@ void Control::add_theme_icon_override(const StringName &p_name, const Ref<Textur
notification(NOTIFICATION_THEME_CHANGED);
}
-void Control::add_theme_shader_override(const StringName &p_name, const Ref<Shader> &p_shader) {
- if (data.shader_override.has(p_name)) {
- data.shader_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
- }
-
- // clear if "null" is passed instead of a shader
- if (p_shader.is_null()) {
- data.shader_override.erase(p_name);
- } else {
- data.shader_override[p_name] = p_shader;
- if (data.shader_override[p_name].is_valid()) {
- data.shader_override[p_name]->connect("changed", callable_mp(this, &Control::_override_changed), Vector<Variant>(), CONNECT_REFERENCE_COUNTED);
- }
- }
- notification(NOTIFICATION_THEME_CHANGED);
-}
-
void Control::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
if (data.style_override.has(p_name)) {
data.style_override[p_name]->disconnect("changed", callable_mp(this, &Control::_override_changed));
@@ -2905,7 +2800,6 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_theme"), &Control::get_theme);
ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Control::add_theme_icon_override);
- ClassDB::bind_method(D_METHOD("add_theme_shader_override", "name", "shader"), &Control::add_theme_shader_override);
ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Control::add_theme_style_override);
ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Control::add_theme_font_override);
ClassDB::bind_method(D_METHOD("add_theme_font_size_override", "name", "font_size"), &Control::add_theme_font_size_override);
@@ -2920,7 +2814,6 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "node_type"), &Control::get_theme_constant, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Control::has_theme_icon_override);
- ClassDB::bind_method(D_METHOD("has_theme_shader_override", "name"), &Control::has_theme_shader_override);
ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Control::has_theme_stylebox_override);
ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Control::has_theme_font_override);
ClassDB::bind_method(D_METHOD("has_theme_font_size_override", "name"), &Control::has_theme_font_size_override);
diff --git a/scene/gui/control.h b/scene/gui/control.h
index e1f05dfe64..8496729f05 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -212,7 +212,6 @@ private:
NodePath focus_prev;
HashMap<StringName, Ref<Texture2D>> icon_override;
- HashMap<StringName, Ref<Shader>> shader_override;
HashMap<StringName, Ref<StyleBox>> style_override;
HashMap<StringName, Ref<Font>> font_override;
HashMap<StringName, int> font_size_override;
@@ -238,7 +237,6 @@ private:
void _update_minimum_size();
void _update_scroll();
- void _resize(const Size2 &p_size);
void _compute_margins(Rect2 p_rect, const float p_anchors[4], float (&r_margins)[4]);
void _compute_anchors(Rect2 p_rect, const float p_margins[4], float (&r_anchors)[4]);
@@ -264,7 +262,6 @@ private:
_FORCE_INLINE_ static bool _has_theme_item(Control *p_theme_owner, Window *p_theme_owner_window, bool (Theme::*has_func)(const StringName &, const StringName &) const, const StringName &p_name, const StringName &p_node_type);
static Ref<Texture2D> get_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
- static Ref<Shader> get_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
static Ref<StyleBox> get_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
static Ref<Font> get_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
static int get_font_sizes(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
@@ -272,7 +269,6 @@ private:
static int get_constants(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
static bool has_icons(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
- static bool has_shaders(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
static bool has_styleboxs(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
static bool has_fonts(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
static bool has_font_sizes(Control *p_theme_owner, Window *p_theme_owner_window, const StringName &p_name, const StringName &p_node_type = StringName());
@@ -456,7 +452,6 @@ public:
/* SKINNING */
void add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon);
- void add_theme_shader_override(const StringName &p_name, const Ref<Shader> &p_shader);
void add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style);
void add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font);
void add_theme_font_size_override(const StringName &p_name, int p_font_size);
@@ -464,7 +459,6 @@ public:
void add_theme_constant_override(const StringName &p_name, int p_constant);
Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_node_type = StringName()) const;
- Ref<Shader> get_theme_shader(const StringName &p_name, const StringName &p_node_type = StringName()) const;
Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_node_type = StringName()) const;
Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_node_type = StringName()) const;
int get_theme_font_size(const StringName &p_name, const StringName &p_node_type = StringName()) const;
@@ -472,7 +466,6 @@ public:
int get_theme_constant(const StringName &p_name, const StringName &p_node_type = StringName()) const;
bool has_theme_icon_override(const StringName &p_name) const;
- bool has_theme_shader_override(const StringName &p_name) const;
bool has_theme_stylebox_override(const StringName &p_name) const;
bool has_theme_font_override(const StringName &p_name) const;
bool has_theme_font_size_override(const StringName &p_name) const;
@@ -480,7 +473,6 @@ public:
bool has_theme_constant_override(const StringName &p_name) const;
bool has_theme_icon(const StringName &p_name, const StringName &p_node_type = StringName()) const;
- bool has_theme_shader(const StringName &p_name, const StringName &p_node_type = StringName()) const;
bool has_theme_stylebox(const StringName &p_name, const StringName &p_node_type = StringName()) const;
bool has_theme_font(const StringName &p_name, const StringName &p_node_type = StringName()) const;
bool has_theme_font_size(const StringName &p_name, const StringName &p_node_type = StringName()) const;
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 4f59f4a36a..4e80498108 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -60,7 +60,7 @@ void AcceptDialog::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
- get_ok()->grab_focus();
+ get_ok_button()->grab_focus();
_update_child_rects();
parent_visible = get_parent_visible_window();
if (parent_visible) {
@@ -253,7 +253,7 @@ Button *AcceptDialog::add_button(const String &p_text, bool p_right, const Strin
return button;
}
-Button *AcceptDialog::add_cancel(const String &p_cancel) {
+Button *AcceptDialog::add_cancel_button(const String &p_cancel) {
String c = p_cancel;
if (p_cancel == "") {
c = RTR("Cancel");
@@ -264,12 +264,12 @@ Button *AcceptDialog::add_cancel(const String &p_cancel) {
}
void AcceptDialog::_bind_methods() {
- ClassDB::bind_method(D_METHOD("get_ok"), &AcceptDialog::get_ok);
+ ClassDB::bind_method(D_METHOD("get_ok_button"), &AcceptDialog::get_ok_button);
ClassDB::bind_method(D_METHOD("get_label"), &AcceptDialog::get_label);
ClassDB::bind_method(D_METHOD("set_hide_on_ok", "enabled"), &AcceptDialog::set_hide_on_ok);
ClassDB::bind_method(D_METHOD("get_hide_on_ok"), &AcceptDialog::get_hide_on_ok);
ClassDB::bind_method(D_METHOD("add_button", "text", "right", "action"), &AcceptDialog::add_button, DEFVAL(false), DEFVAL(""));
- ClassDB::bind_method(D_METHOD("add_cancel", "name"), &AcceptDialog::add_cancel);
+ ClassDB::bind_method(D_METHOD("add_cancel_button", "name"), &AcceptDialog::add_cancel_button);
ClassDB::bind_method(D_METHOD("register_text_enter", "line_edit"), &AcceptDialog::register_text_enter);
ClassDB::bind_method(D_METHOD("set_text", "text"), &AcceptDialog::set_text);
ClassDB::bind_method(D_METHOD("get_text"), &AcceptDialog::get_text);
@@ -337,10 +337,10 @@ AcceptDialog::~AcceptDialog() {
// ConfirmationDialog
void ConfirmationDialog::_bind_methods() {
- ClassDB::bind_method(D_METHOD("get_cancel"), &ConfirmationDialog::get_cancel);
+ ClassDB::bind_method(D_METHOD("get_cancel_button"), &ConfirmationDialog::get_cancel_button);
}
-Button *ConfirmationDialog::get_cancel() {
+Button *ConfirmationDialog::get_cancel_button() {
return cancel;
}
@@ -349,5 +349,5 @@ ConfirmationDialog::ConfirmationDialog() {
#ifdef TOOLS_ENABLED
set_min_size(Size2(200, 70) * EDSCALE);
#endif
- cancel = add_cancel();
+ cancel = add_cancel_button();
}
diff --git a/scene/gui/dialogs.h b/scene/gui/dialogs.h
index de08685ce2..8f6e0e86f9 100644
--- a/scene/gui/dialogs.h
+++ b/scene/gui/dialogs.h
@@ -79,9 +79,9 @@ public:
void register_text_enter(Node *p_line_edit);
- Button *get_ok() { return ok; }
+ Button *get_ok_button() { return ok; }
Button *add_button(const String &p_text, bool p_right = false, const String &p_action = "");
- Button *add_cancel(const String &p_cancel = "");
+ Button *add_cancel_button(const String &p_cancel = "");
void set_hide_on_ok(bool p_hide);
bool get_hide_on_ok() const;
@@ -104,7 +104,7 @@ protected:
static void _bind_methods();
public:
- Button *get_cancel();
+ Button *get_cancel_button();
ConfirmationDialog();
};
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index eb3d5d5c6d..041b8ef174 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -324,15 +324,15 @@ void FileDialog::deselect_items() {
// And change get_ok title.
if (!tree->is_anything_selected()) {
- get_ok()->set_disabled(_is_open_should_be_disabled());
+ get_ok_button()->set_disabled(_is_open_should_be_disabled());
switch (mode) {
case FILE_MODE_OPEN_FILE:
case FILE_MODE_OPEN_FILES:
- get_ok()->set_text(RTR("Open"));
+ get_ok_button()->set_text(RTR("Open"));
break;
case FILE_MODE_OPEN_DIR:
- get_ok()->set_text(RTR("Select Current Folder"));
+ get_ok_button()->set_text(RTR("Select Current Folder"));
break;
case FILE_MODE_OPEN_ANY:
case FILE_MODE_SAVE_FILE:
@@ -356,10 +356,10 @@ void FileDialog::_tree_selected() {
if (!d["dir"]) {
file->set_text(d["name"]);
} else if (mode == FILE_MODE_OPEN_DIR) {
- get_ok()->set_text(RTR("Select This Folder"));
+ get_ok_button()->set_text(RTR("Select This Folder"));
}
- get_ok()->set_disabled(_is_open_should_be_disabled());
+ get_ok_button()->set_disabled(_is_open_should_be_disabled());
}
void FileDialog::_tree_item_activated() {
@@ -646,35 +646,35 @@ void FileDialog::set_file_mode(FileMode p_mode) {
mode = p_mode;
switch (mode) {
case FILE_MODE_OPEN_FILE:
- get_ok()->set_text(RTR("Open"));
+ get_ok_button()->set_text(RTR("Open"));
if (mode_overrides_title) {
set_title(RTR("Open a File"));
}
makedir->hide();
break;
case FILE_MODE_OPEN_FILES:
- get_ok()->set_text(RTR("Open"));
+ get_ok_button()->set_text(RTR("Open"));
if (mode_overrides_title) {
set_title(RTR("Open File(s)"));
}
makedir->hide();
break;
case FILE_MODE_OPEN_DIR:
- get_ok()->set_text(RTR("Select Current Folder"));
+ get_ok_button()->set_text(RTR("Select Current Folder"));
if (mode_overrides_title) {
set_title(RTR("Open a Directory"));
}
makedir->show();
break;
case FILE_MODE_OPEN_ANY:
- get_ok()->set_text(RTR("Open"));
+ get_ok_button()->set_text(RTR("Open"));
if (mode_overrides_title) {
set_title(RTR("Open a File or Directory"));
}
makedir->show();
break;
case FILE_MODE_SAVE_FILE:
- get_ok()->set_text(RTR("Save"));
+ get_ok_button()->set_text(RTR("Save"));
if (mode_overrides_title) {
set_title(RTR("Save a File"));
}
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index d06bdaad91..9f8b944f4c 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -228,6 +228,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
+ case (KEY_Y): // PASTE (Yank for unix users).
case (KEY_V): { // PASTE.
if (editable) {
@@ -258,13 +259,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) {
} break;
- case (KEY_Y): { // PASTE (Yank for unix users).
-
- if (editable) {
- paste_text();
- }
-
- } break;
case (KEY_K): { // Delete from cursor_pos to end.
if (editable) {
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 6dbf005f73..07f03ad40e 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -232,12 +232,13 @@ void PopupMenu::_submenu_timeout() {
}
void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
- if (p_event->is_action("ui_down") && p_event->is_pressed() && mouse_over != items.size() - 1) {
+ if (p_event->is_action("ui_down") && p_event->is_pressed()) {
int search_from = mouse_over + 1;
if (search_from >= items.size()) {
search_from = 0;
}
+ bool match_found = false;
for (int i = search_from; i < items.size(); i++) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
@@ -245,15 +246,31 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
_scroll_to_item(i);
control->update();
set_input_as_handled();
+ match_found = true;
break;
}
}
- } else if (p_event->is_action("ui_up") && p_event->is_pressed() && mouse_over != 0) {
+
+ if (!match_found) {
+ // If the last item is not selectable, try re-searching from the start.
+ for (int i = 0; i < search_from; i++) {
+ if (!items[i].separator && !items[i].disabled) {
+ mouse_over = i;
+ emit_signal("id_focused", i);
+ _scroll_to_item(i);
+ control->update();
+ set_input_as_handled();
+ break;
+ }
+ }
+ }
+ } else if (p_event->is_action("ui_up") && p_event->is_pressed()) {
int search_from = mouse_over - 1;
if (search_from < 0) {
search_from = items.size() - 1;
}
+ bool match_found = false;
for (int i = search_from; i >= 0; i--) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
@@ -261,9 +278,24 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) {
_scroll_to_item(i);
control->update();
set_input_as_handled();
+ match_found = true;
break;
}
}
+
+ if (!match_found) {
+ // If the first item is not selectable, try re-searching from the end.
+ for (int i = items.size() - 1; i >= search_from; i--) {
+ if (!items[i].separator && !items[i].disabled) {
+ mouse_over = i;
+ emit_signal("id_focused", i);
+ _scroll_to_item(i);
+ control->update();
+ set_input_as_handled();
+ break;
+ }
+ }
+ }
} else if (p_event->is_action("ui_left") && p_event->is_pressed()) {
Node *n = get_parent();
if (n && Object::cast_to<PopupMenu>(n)) {
@@ -446,6 +478,7 @@ void PopupMenu::_draw_items() {
Color font_color_disabled = get_theme_color("font_color_disabled");
Color font_color_accel = get_theme_color("font_color_accel");
Color font_color_hover = get_theme_color("font_color_hover");
+ Color font_color_separator = get_theme_color("font_color_separator");
float scroll_width = scroll_container->get_v_scrollbar()->is_visible_in_tree() ? scroll_container->get_v_scrollbar()->get_size().width : 0;
float display_width = control->get_size().width - scroll_width;
@@ -548,7 +581,7 @@ void PopupMenu::_draw_items() {
if (items[i].separator) {
if (text != String()) {
int center = (display_width - items[i].text_buf->get_size().width) / 2;
- items[i].text_buf->draw(ci, Point2(center, item_ofs.y + Math::floor((h - items[i].text_buf->get_size().y) / 2.0)), font_color_disabled);
+ items[i].text_buf->draw(ci, Point2(center, item_ofs.y + Math::floor((h - items[i].text_buf->get_size().y) / 2.0)), font_color_separator);
}
} else {
item_ofs.x += icon_ofs + check_ofs;
diff --git a/scene/gui/rich_text_effect.cpp b/scene/gui/rich_text_effect.cpp
index 76ca8abcc7..5b201f45d3 100644
--- a/scene/gui/rich_text_effect.cpp
+++ b/scene/gui/rich_text_effect.cpp
@@ -64,11 +64,8 @@ RichTextEffect::RichTextEffect() {
}
void CharFXTransform::_bind_methods() {
- ClassDB::bind_method(D_METHOD("get_relative_index"), &CharFXTransform::get_relative_index);
- ClassDB::bind_method(D_METHOD("set_relative_index", "index"), &CharFXTransform::set_relative_index);
-
- ClassDB::bind_method(D_METHOD("get_absolute_index"), &CharFXTransform::get_absolute_index);
- ClassDB::bind_method(D_METHOD("set_absolute_index", "index"), &CharFXTransform::set_absolute_index);
+ ClassDB::bind_method(D_METHOD("get_range"), &CharFXTransform::get_range);
+ ClassDB::bind_method(D_METHOD("set_range", "range"), &CharFXTransform::set_range);
ClassDB::bind_method(D_METHOD("get_elapsed_time"), &CharFXTransform::get_elapsed_time);
ClassDB::bind_method(D_METHOD("set_elapsed_time", "time"), &CharFXTransform::set_elapsed_time);
@@ -76,6 +73,9 @@ void CharFXTransform::_bind_methods() {
ClassDB::bind_method(D_METHOD("is_visible"), &CharFXTransform::is_visible);
ClassDB::bind_method(D_METHOD("set_visibility", "visibility"), &CharFXTransform::set_visibility);
+ ClassDB::bind_method(D_METHOD("is_outline"), &CharFXTransform::is_outline);
+ ClassDB::bind_method(D_METHOD("set_outline", "outline"), &CharFXTransform::set_outline);
+
ClassDB::bind_method(D_METHOD("get_offset"), &CharFXTransform::get_offset);
ClassDB::bind_method(D_METHOD("set_offset", "offset"), &CharFXTransform::set_offset);
@@ -85,27 +85,24 @@ void CharFXTransform::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_environment"), &CharFXTransform::get_environment);
ClassDB::bind_method(D_METHOD("set_environment", "environment"), &CharFXTransform::set_environment);
- ClassDB::bind_method(D_METHOD("get_character"), &CharFXTransform::get_character);
- ClassDB::bind_method(D_METHOD("set_character", "character"), &CharFXTransform::set_character);
+ ClassDB::bind_method(D_METHOD("get_glyph_index"), &CharFXTransform::get_glyph_index);
+ ClassDB::bind_method(D_METHOD("set_glyph_index", "glyph_index"), &CharFXTransform::set_glyph_index);
+
+ ClassDB::bind_method(D_METHOD("get_font"), &CharFXTransform::get_font);
+ ClassDB::bind_method(D_METHOD("set_font", "font"), &CharFXTransform::set_font);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "relative_index"), "set_relative_index", "get_relative_index");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "absolute_index"), "set_absolute_index", "get_absolute_index");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "range"), "set_range", "get_range");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "elapsed_time"), "set_elapsed_time", "get_elapsed_time");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visibility", "is_visible");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "outline"), "set_outline", "is_outline");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "offset"), "set_offset", "get_offset");
ADD_PROPERTY(PropertyInfo(Variant::COLOR, "color"), "set_color", "get_color");
ADD_PROPERTY(PropertyInfo(Variant::DICTIONARY, "env"), "set_environment", "get_environment");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "character"), "set_character", "get_character");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "glyph_index"), "set_glyph_index", "get_glyph_index");
+ ADD_PROPERTY(PropertyInfo(Variant::RID, "font"), "set_font", "get_font");
}
CharFXTransform::CharFXTransform() {
- relative_index = 0;
- absolute_index = 0;
- visibility = true;
- offset = Point2();
- color = Color();
- character = 0;
- elapsed_time = 0.0f;
}
CharFXTransform::~CharFXTransform() {
diff --git a/scene/gui/rich_text_effect.h b/scene/gui/rich_text_effect.h
index e6b9f09e4d..1aa62c1c83 100644
--- a/scene/gui/rich_text_effect.h
+++ b/scene/gui/rich_text_effect.h
@@ -54,32 +54,37 @@ protected:
static void _bind_methods();
public:
- uint64_t relative_index;
- uint64_t absolute_index;
- bool visibility;
+ Vector2i range;
+ bool visibility = true;
+ bool outline = false;
Point2 offset;
Color color;
- char32_t character;
- float elapsed_time;
+ float elapsed_time = 0.0f;
Dictionary environment;
+ uint32_t glpyh_index = 0;
+ RID font;
CharFXTransform();
~CharFXTransform();
- uint64_t get_relative_index() { return relative_index; }
- void set_relative_index(uint64_t p_index) { relative_index = p_index; }
- uint64_t get_absolute_index() { return absolute_index; }
- void set_absolute_index(uint64_t p_index) { absolute_index = p_index; }
+ Vector2i get_range() { return range; }
+ void set_range(const Vector2i &p_range) { range = p_range; }
float get_elapsed_time() { return elapsed_time; }
void set_elapsed_time(float p_elapsed_time) { elapsed_time = p_elapsed_time; }
bool is_visible() { return visibility; }
- void set_visibility(bool p_vis) { visibility = p_vis; }
+ void set_visibility(bool p_visibility) { visibility = p_visibility; }
+ bool is_outline() { return outline; }
+ void set_outline(bool p_outline) { outline = p_outline; }
Point2 get_offset() { return offset; }
void set_offset(Point2 p_offset) { offset = p_offset; }
Color get_color() { return color; }
void set_color(Color p_color) { color = p_color; }
- int get_character() { return (int)character; }
- void set_character(int p_char) { character = (char32_t)p_char; }
+
+ uint32_t get_glyph_index() const { return glpyh_index; };
+ void set_glyph_index(uint32_t p_glpyh_index) { glpyh_index = p_glpyh_index; };
+ RID get_font() const { return font; };
+ void set_font(RID p_font) { font = p_font; };
+
Dictionary get_environment() { return environment; }
void set_environment(Dictionary p_environment) { environment = p_environment; }
};
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 08214b958e..244d90ca6b 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -140,741 +140,1088 @@ Rect2 RichTextLabel::_get_text_rect() {
return Rect2(style->get_offset(), get_size() - style->get_minimum_size());
}
-int RichTextLabel::_process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos, Item **r_click_item, int *r_click_char, bool *r_outside, int p_char_count) {
- ERR_FAIL_INDEX_V((int)p_mode, 3, 0);
-
- RID ci;
- if (r_outside) {
- *r_outside = false;
+RichTextLabel::Item *RichTextLabel::_get_item_at_pos(RichTextLabel::Item *p_item_from, RichTextLabel::Item *p_item_to, int p_position) {
+ int offset = 0;
+ for (Item *it = p_item_from; it && it != p_item_to; it = _get_next_item(it)) {
+ switch (it->type) {
+ case ITEM_TEXT: {
+ ItemText *t = (ItemText *)it;
+ offset += t->text.length();
+ if (offset > p_position) {
+ return it;
+ }
+ } break;
+ case ITEM_NEWLINE:
+ case ITEM_IMAGE:
+ case ITEM_TABLE: {
+ offset += 1;
+ } break;
+ default:
+ break;
+ }
}
- if (p_mode == PROCESS_DRAW) {
- ci = get_canvas_item();
+ return p_item_from;
+}
- if (r_click_item) {
- *r_click_item = nullptr;
- }
+String RichTextLabel::_roman(int p_num, bool p_capitalize) const {
+ if (p_num > 3999) {
+ return "ERR";
+ };
+ String s;
+ if (p_capitalize) {
+ String M[] = { "", "M", "MM", "MMM" };
+ String C[] = { "", "C", "CC", "CCC", "CD", "D", "DC", "DCC", "DCCC", "CM" };
+ String X[] = { "", "X", "XX", "XXX", "XL", "L", "LX", "LXX", "LXXX", "XC" };
+ String I[] = { "", "I", "II", "III", "IV", "V", "VI", "VII", "VIII", "IX" };
+ s = M[p_num / 1000] + C[(p_num % 1000) / 100] + X[(p_num % 100) / 10] + I[p_num % 10];
+ } else {
+ String M[] = { "", "m", "mm", "mmm" };
+ String C[] = { "", "c", "cc", "ccc", "cd", "d", "dc", "dcc", "dccc", "cm" };
+ String X[] = { "", "x", "xx", "xxx", "xl", "l", "lx", "lxx", "lxxx", "xc" };
+ String I[] = { "", "i", "ii", "iii", "iv", "v", "vi", "vii", "viii", "ix" };
+ s = M[p_num / 1000] + C[(p_num % 1000) / 100] + X[(p_num % 100) / 10] + I[p_num % 10];
}
- Line &l = p_frame->lines.write[p_line];
- Item *it = l.from;
+ return s;
+}
- int line_ofs = 0;
- int margin = _find_margin(it, p_base_font);
- Align align = _find_align(it);
- int line = 0;
- int spaces = 0;
+String RichTextLabel::_letters(int p_num, bool p_capitalize) const {
+ int64_t n = p_num;
- int height = get_size().y;
+ int chars = 0;
+ do {
+ n /= 24;
+ chars++;
+ } while (n);
- if (p_mode != PROCESS_CACHE) {
- ERR_FAIL_INDEX_V(line, l.offset_caches.size(), 0);
- line_ofs = l.offset_caches[line];
- }
+ String s;
+ s.resize(chars + 1);
+ char32_t *c = s.ptrw();
+ c[chars] = 0;
+ n = p_num;
+ do {
+ int mod = ABS(n % 24);
+ char a = (p_capitalize ? 'A' : 'a');
+ c[--chars] = a + mod - 1;
- if (p_mode == PROCESS_CACHE) {
- l.offset_caches.clear();
- l.height_caches.clear();
- l.ascent_caches.clear();
- l.descent_caches.clear();
- l.char_count = 0;
- l.minimum_width = 0;
- l.maximum_width = 0;
- }
+ n /= 24;
+ } while (n);
- int wofs = margin;
- int spaces_size = 0;
- int align_ofs = 0;
+ return s;
+}
- if (p_mode != PROCESS_CACHE && align != ALIGN_FILL) {
- wofs += line_ofs;
- }
+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());
+
+ Line &l = p_frame->lines.write[p_line];
- int begin = margin;
+ l.offset.x = _find_margin(l.from, p_base_font, p_base_font_size);
+ l.text_buf->set_width(p_width - l.offset.x);
- Ref<Font> cfont = _find_font(it);
- if (cfont.is_null()) {
- cfont = p_base_font;
+ if (tab_size > 0) { // Align inline tabs.
+ Vector<float> tabs;
+ tabs.push_back(tab_size * p_base_font->get_char_size('m', 0, p_base_font_size).width);
+ l.text_buf->tab_align(tabs);
}
- //line height should be the font height for the first time, this ensures that an empty line will never have zero height and successive newlines are displayed
- int line_height = cfont->get_height();
- int line_ascent = cfont->get_ascent();
- int line_descent = cfont->get_descent();
+ Item *it_to = (p_line + 1 < 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: {
+ ItemTable *table = static_cast<ItemTable *>(it);
+ int hseparation = get_theme_constant("table_hseparation");
+ int vseparation = get_theme_constant("table_vseparation");
+ int col_count = table->columns.size();
- int backtrack = 0; // for dynamic hidden content.
+ for (int i = 0; i < col_count; i++) {
+ table->columns.write[i].width = 0;
+ }
- int nonblank_line_count = 0; //number of nonblank lines as counted during PROCESS_DRAW
+ int idx = 0;
+ for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ for (int i = 0; i < frame->lines.size(); i++) {
+ _resize_line(frame, i, p_base_font, p_base_font_size, 1);
+ }
+ idx++;
+ }
- Variant meta;
+ // Compute minimum width for each cell.
+ const int available_width = p_width - hseparation * (col_count - 1);
-#define RETURN return nonblank_line_count
-
-#define NEW_LINE \
- { \
- if (p_mode != PROCESS_CACHE) { \
- line++; \
- backtrack = 0; \
- if (!line_is_blank) { \
- nonblank_line_count++; \
- } \
- line_is_blank = true; \
- if (line < l.offset_caches.size()) \
- line_ofs = l.offset_caches[line]; \
- wofs = margin; \
- if (align != ALIGN_FILL) \
- wofs += line_ofs; \
- } else { \
- int used = wofs - margin; \
- switch (align) { \
- case ALIGN_LEFT: \
- l.offset_caches.push_back(0); \
- break; \
- case ALIGN_CENTER: \
- l.offset_caches.push_back(((p_width - margin) - used) / 2); \
- break; \
- case ALIGN_RIGHT: \
- l.offset_caches.push_back(((p_width - margin) - used)); \
- break; \
- case ALIGN_FILL: \
- l.offset_caches.push_back(line_wrapped ? ((p_width - margin) - used) : 0); \
- break; \
- } \
- l.height_caches.push_back(line_height); \
- l.ascent_caches.push_back(line_ascent); \
- l.descent_caches.push_back(line_descent); \
- l.space_caches.push_back(spaces); \
- } \
- line_wrapped = false; \
- y += line_height + get_theme_constant(SceneStringNames::get_singleton()->line_separation); \
- line_height = 0; \
- line_ascent = 0; \
- line_descent = 0; \
- spaces = 0; \
- spaces_size = 0; \
- wofs = begin; \
- align_ofs = 0; \
- if (p_mode != PROCESS_CACHE) { \
- lh = line < l.height_caches.size() ? l.height_caches[line] : 1; \
- line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1; \
- line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1; \
- if (align != ALIGN_FILL) { \
- if (line < l.offset_caches.size()) { \
- wofs = l.offset_caches[line]; \
- } \
- } \
- } \
- if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && p_click_pos.x < p_ofs.x + wofs) { \
- if (r_outside) \
- *r_outside = true; \
- *r_click_item = it; \
- *r_click_char = rchar; \
- RETURN; \
- } \
- }
-
-#define ENSURE_WIDTH(m_width) \
- if (p_mode == PROCESS_CACHE) { \
- l.maximum_width = MAX(l.maximum_width, MIN(p_width, wofs + m_width)); \
- l.minimum_width = MAX(l.minimum_width, m_width); \
- } \
- if (wofs - backtrack + m_width > p_width) { \
- line_wrapped = true; \
- if (p_mode == PROCESS_CACHE) { \
- if (spaces > 0) \
- spaces -= 1; \
- } \
- const bool x_in_range = (p_click_pos.x > p_ofs.x + wofs) && (!p_frame->cell || p_click_pos.x < p_ofs.x + p_width); \
- if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && x_in_range) { \
- if (r_outside) \
- *r_outside = true; \
- *r_click_item = it; \
- *r_click_char = rchar; \
- RETURN; \
- } \
- NEW_LINE \
- }
-
-#define ADVANCE(m_width) \
- { \
- if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh && p_click_pos.x >= p_ofs.x + wofs && p_click_pos.x < p_ofs.x + wofs + m_width) { \
- if (r_outside) \
- *r_outside = false; \
- *r_click_item = it; \
- *r_click_char = rchar; \
- RETURN; \
- } \
- wofs += m_width; \
- }
-
-#define CHECK_HEIGHT(m_height) \
- if (m_height > line_height) { \
- line_height = m_height; \
- }
-
-#define YRANGE_VISIBLE(m_top, m_height) \
- (m_height > 0 && ((m_top >= 0 && m_top < height) || ((m_top + m_height - 1) >= 0 && (m_top + m_height - 1) < height)))
-
- Color selection_fg;
- Color selection_bg;
-
- if (p_mode == PROCESS_DRAW) {
- selection_fg = get_theme_color("font_color_selected");
- selection_bg = get_theme_color("selection_color");
- }
-
- int rchar = 0;
- int lh = 0;
- bool line_is_blank = true;
- bool line_wrapped = false;
- int fh = 0;
+ // Compute available width and total ratio (for expanders).
+ int total_ratio = 0;
+ int remaining_width = available_width;
+ table->total_width = hseparation;
- while (it) {
- switch (it->type) {
- case ITEM_ALIGN: {
- ItemAlign *align_it = static_cast<ItemAlign *>(it);
+ 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;
+ }
+ if (table->columns[i].expand) {
+ total_ratio += table->columns[i].expand_ratio;
+ }
+ }
- align = align_it->align;
+ // Assign actual widths.
+ for (int i = 0; i < col_count; i++) {
+ table->columns.write[i].width = table->columns[i].min_width;
+ if (table->columns[i].expand && total_ratio > 0) {
+ table->columns.write[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
+ }
+ table->total_width += table->columns[i].width + hseparation;
+ }
- } break;
- case ITEM_INDENT: {
- if (it != l.from) {
- ItemIndent *indent_it = static_cast<ItemIndent *>(it);
-
- int indent = indent_it->level * tab_size * cfont->get_char_size(' ').width;
- margin += indent;
- begin += indent;
- wofs += indent;
+ // Resize to max_width if needed and distribute the remaining space.
+ bool table_need_fit = true;
+ while (table_need_fit) {
+ table_need_fit = false;
+ // Fit slim.
+ for (int i = 0; i < col_count; i++) {
+ if (!table->columns[i].expand) {
+ continue;
+ }
+ 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->total_width -= dif;
+ total_ratio -= table->columns[i].expand_ratio;
+ }
+ }
+ // Grow.
+ remaining_width = available_width - table->total_width;
+ if (remaining_width > 0 && total_ratio > 0) {
+ for (int i = 0; i < col_count; i++) {
+ if (table->columns[i].expand) {
+ int dif = table->columns[i].max_width - table->columns[i].width;
+ 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->total_width += incr;
+ }
+ }
+ }
+ }
}
+ // Update line width and get total height.
+ idx = 0;
+ table->total_height = 0;
+ table->rows.clear();
+
+ Vector2 offset;
+ float row_height = 0;
+
+ for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+
+ int column = idx % col_count;
+
+ 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));
+
+ if (i > 0) {
+ frame->lines.write[i].offset.y = frame->lines[i - 1].offset.y + frame->lines[i - 1].text_buf->get_size().y;
+ } else {
+ frame->lines.write[i].offset.y = 0;
+ }
+ frame->lines.write[i].offset += Vector2(offset.x, offset.y);
+
+ float h = frame->lines[i].text_buf->get_size().y;
+ if (frame->min_size_over.y > 0) {
+ h = MAX(h, frame->min_size_over.y);
+ }
+ if (frame->max_size_over.y > 0) {
+ h = MIN(h, frame->max_size_over.y);
+ }
+ yofs += h;
+ }
+ yofs += frame->padding.size.y;
+ offset.x += table->columns[column].width + hseparation + frame->padding.size.x;
+
+ row_height = MAX(yofs, row_height);
+ if (column == col_count - 1) {
+ offset.x = 0;
+ row_height += vseparation;
+ table->total_height += row_height;
+ offset.y += row_height;
+ table->rows.push_back(row_height);
+ row_height = 0;
+ }
+ idx++;
+ }
+ l.text_buf->resize_object((uint64_t)it, Size2(table->total_width, table->total_height), table->inline_align);
} break;
- case ITEM_TEXT: {
- ItemText *text = static_cast<ItemText *>(it);
+ default:
+ break;
+ }
+ }
+ 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;
+ } else {
+ l.offset.y = 0;
+ }
+}
+
+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());
+
+ Line &l = p_frame->lines.write[p_line];
+
+ // Clear cache.
+ l.text_buf->clear();
+ l.text_buf->set_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::JUSTIFICATION_KASHIDA | TextServer::JUSTIFICATION_WORD_BOUND | TextServer::JUSTIFICATION_TRIM_EDGE_SPACES);
+ l.char_offset = *r_char_offset;
+ l.char_count = 0;
+
+ // Add indent.
+ l.offset.x = _find_margin(l.from, p_base_font, p_base_font_size);
+ l.text_buf->set_width(p_width - l.offset.x);
+ l.text_buf->set_align((HAlign)_find_align(l.from));
+ l.text_buf->set_direction(_find_direction(l.from));
+
+ if (tab_size > 0) { // Align inline tabs.
+ Vector<float> tabs;
+ tabs.push_back(tab_size * p_base_font->get_char_size('m', 0, p_base_font_size).width);
+ l.text_buf->tab_align(tabs);
+ }
+
+ // Shape current paragraph.
+ String text;
+ Item *it_to = (p_line + 1 < 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)) {
+ if (visible_characters >= 0 && l.char_offset + l.char_count > visible_characters) {
+ break;
+ }
+ switch (it->type) {
+ case ITEM_NEWLINE: {
Ref<Font> font = _find_font(it);
if (font.is_null()) {
font = p_base_font;
}
+ int font_size = _find_font_size(it);
+ if (font_size == -1) {
+ font_size = p_base_font_size;
+ }
+ l.text_buf->add_string("\n", font, font_size, Dictionary(), "");
+ text += "\n";
+ l.char_count += 1;
+ } break;
+ case ITEM_TEXT: {
+ ItemText *t = (ItemText *)it;
+ Ref<Font> font = _find_font(it);
+ if (font.is_null()) {
+ font = p_base_font;
+ }
+ int font_size = _find_font_size(it);
+ if (font_size == -1) {
+ font_size = p_base_font_size;
+ }
+ Dictionary font_ftr = _find_font_features(it);
+ String lang = _find_language(it);
+ String tx = t->text;
+ if (visible_characters >= 0 && l.char_offset + l.char_count + tx.length() > visible_characters) {
+ tx = tx.substr(0, l.char_offset + l.char_count + tx.length() - visible_characters);
+ }
- const char32_t *c = text->text.get_data();
- const char32_t *cf = c;
- int ascent = font->get_ascent();
- int descent = font->get_descent();
-
- Color color;
- Color font_color_shadow;
- bool underline = false;
- bool strikethrough = false;
- ItemFade *fade = nullptr;
- int it_char_start = p_char_count;
-
- Vector<ItemFX *> fx_stack = Vector<ItemFX *>();
- _fetch_item_fx_stack(text, fx_stack);
- bool custom_fx_ok = true;
-
- if (p_mode == PROCESS_DRAW) {
- color = _find_color(text, p_base_color);
- font_color_shadow = _find_color(text, p_font_color_shadow);
- if (_find_underline(text) || (_find_meta(text, &meta) && underline_meta)) {
- underline = true;
- } else if (_find_strikethrough(text)) {
- strikethrough = true;
- }
+ l.text_buf->add_string(tx, font, font_size, font_ftr, lang);
+ text += tx;
+ l.char_count += tx.length();
+ } break;
+ case ITEM_IMAGE: {
+ ItemImage *img = (ItemImage *)it;
+ l.text_buf->add_object((uint64_t)it, img->image->get_size(), img->inline_align, 1);
+ text += String::chr(0xfffc);
+ } break;
+ case ITEM_TABLE: {
+ ItemTable *table = static_cast<ItemTable *>(it);
+ int hseparation = get_theme_constant("table_hseparation");
+ int vseparation = get_theme_constant("table_vseparation");
+ int col_count = table->columns.size();
+ 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;
+ }
+ // Compute minimum width for each cell.
+ const int available_width = p_width - hseparation * (col_count - 1);
- Item *fade_item = it;
- while (fade_item) {
- if (fade_item->type == ITEM_FADE) {
- fade = static_cast<ItemFade *>(fade_item);
- break;
- }
- fade_item = fade_item->parent;
- }
+ int idx = 0;
+ for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E->get());
- } else if (p_mode == PROCESS_CACHE) {
- l.char_count += text->text.length();
+ int column = idx % col_count;
+ for (int i = 0; i < frame->lines.size(); i++) {
+ int char_offset = l.char_offset + l.char_count;
+ _shape_line(frame, i, p_base_font, p_base_font_size, 1, &char_offset);
+ int cell_ch = (char_offset - (l.char_offset + l.char_count));
+ l.char_count += cell_ch;
+ t_char_count += 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_wraped_size().x));
+ }
+ idx++;
}
- rchar = 0;
- //FontDrawer drawer(font, Color(1, 1, 1));
- while (*c) {
- int end = 0;
- int w = 0;
- int fw = 0;
+ // Compute available width and total ratio (for expanders).
+ int total_ratio = 0;
+ int remaining_width = available_width;
+ table->total_width = hseparation;
- lh = 0;
+ 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;
+ }
+ if (table->columns[i].expand) {
+ total_ratio += table->columns[i].expand_ratio;
+ }
+ }
- if (p_mode != PROCESS_CACHE) {
- lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
- line_ascent = line < l.ascent_caches.size() ? l.ascent_caches[line] : 1;
- line_descent = line < l.descent_caches.size() ? l.descent_caches[line] : 1;
+ // Assign actual widths.
+ for (int i = 0; i < col_count; i++) {
+ table->columns.write[i].width = table->columns[i].min_width;
+ if (table->columns[i].expand && total_ratio > 0) {
+ table->columns.write[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
}
- while (c[end] != 0 && !(end && c[end - 1] == ' ' && c[end] != ' ')) {
- int cw = font->get_char_size(c[end], c[end + 1]).width;
- if (c[end] == '\t') {
- cw = tab_size * font->get_char_size(' ').width;
- }
+ table->total_width += table->columns[i].width + hseparation;
+ }
- if (end > 0 && fw + cw + begin > p_width) {
- break; //don't allow lines longer than assigned width
+ // Resize to max_width if needed and distribute the remaining space.
+ bool table_need_fit = true;
+ while (table_need_fit) {
+ table_need_fit = false;
+ // Fit slim.
+ for (int i = 0; i < col_count; i++) {
+ if (!table->columns[i].expand) {
+ continue;
+ }
+ 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->total_width -= dif;
+ total_ratio -= table->columns[i].expand_ratio;
}
-
- fw += cw;
-
- end++;
}
- CHECK_HEIGHT(fh);
- ENSURE_WIDTH(fw);
-
- line_ascent = MAX(line_ascent, ascent);
- line_descent = MAX(line_descent, descent);
- fh = line_ascent + line_descent;
-
- if (end && c[end - 1] == ' ') {
- if (p_mode == PROCESS_CACHE) {
- spaces_size += font->get_char_size(' ').width;
- } else if (align == ALIGN_FILL) {
- int ln = MIN(l.offset_caches.size() - 1, line);
- if (l.space_caches[ln]) {
- align_ofs = spaces * l.offset_caches[ln] / l.space_caches[ln];
+ // Grow.
+ remaining_width = available_width - table->total_width;
+ if (remaining_width > 0 && total_ratio > 0) {
+ for (int i = 0; i < col_count; i++) {
+ if (table->columns[i].expand) {
+ int dif = table->columns[i].max_width - table->columns[i].width;
+ 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->total_width += incr;
+ }
}
}
- spaces++;
}
+ }
- {
- int ofs = 0 - backtrack;
+ // Update line width and get total height.
+ idx = 0;
+ table->total_height = 0;
+ table->rows.clear();
- for (int i = 0; i < end; i++) {
- int pofs = wofs + ofs;
+ Vector2 offset;
+ float row_height = 0;
- if (p_mode == PROCESS_POINTER && r_click_char && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) {
- int cw = font->get_char_size(c[i], c[i + 1]).x;
+ for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E->get());
- if (c[i] == '\t') {
- cw = tab_size * font->get_char_size(' ').width;
- }
+ int column = idx % col_count;
- if (p_click_pos.x - cw / 2 > p_ofs.x + align_ofs + pofs) {
- rchar = int((&c[i]) - cf);
- }
+ 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));
- ofs += cw;
- } else if (p_mode == PROCESS_DRAW) {
- bool selected = false;
- Color fx_color = Color(color);
- Point2 fx_offset;
- char32_t fx_char = c[i];
-
- if (selection.active) {
- int cofs = (&c[i]) - cf;
- if ((text->index > selection.from->index || (text->index == selection.from->index && cofs >= selection.from_char)) && (text->index < selection.to->index || (text->index == selection.to->index && cofs <= selection.to_char))) {
- selected = true;
- }
- }
+ if (i > 0) {
+ frame->lines.write[i].offset.y = frame->lines[i - 1].offset.y + frame->lines[i - 1].text_buf->get_size().y;
+ } else {
+ frame->lines.write[i].offset.y = 0;
+ }
+ frame->lines.write[i].offset += Vector2(offset.x, offset.y);
- int cw = 0;
- int c_item_offset = p_char_count - it_char_start;
+ float h = frame->lines[i].text_buf->get_size().y;
+ if (frame->min_size_over.y > 0) {
+ h = MAX(h, frame->min_size_over.y);
+ }
+ if (frame->max_size_over.y > 0) {
+ h = MIN(h, frame->max_size_over.y);
+ }
+ yofs += h;
+ }
+ yofs += frame->padding.size.y;
+ offset.x += table->columns[column].width + hseparation + frame->padding.size.x;
- float faded_visibility = 1.0f;
- if (fade) {
- if (c_item_offset >= fade->starting_index) {
- faded_visibility -= (float)(c_item_offset - fade->starting_index) / (float)fade->length;
- faded_visibility = faded_visibility < 0.0f ? 0.0f : faded_visibility;
- }
- fx_color.a = faded_visibility;
- }
+ row_height = MAX(yofs, row_height);
+ if (column == col_count - 1) {
+ offset.x = 0;
+ row_height += vseparation;
+ table->total_height += row_height;
+ offset.y += row_height;
+ table->rows.push_back(row_height);
+ row_height = 0;
+ }
+ idx++;
+ }
+
+ l.text_buf->add_object((uint64_t)it, Size2(table->total_width, table->total_height), table->inline_align, t_char_count);
+ text += String::chr(0xfffc).repeat(t_char_count);
+ } break;
+ default:
+ break;
+ }
+ }
- bool visible = visible_characters < 0 || ((p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - line_descent - line_ascent, line_ascent + line_descent)) &&
- faded_visibility > 0.0f);
+ //Apply BiDi override.
+ l.text_buf->set_bidi_override(structured_text_parser(_find_stt(l.from), st_args, text));
- const bool previously_visible = visible;
+ *r_char_offset = l.char_offset + l.char_count;
- for (int j = 0; j < fx_stack.size(); j++) {
- ItemFX *item_fx = fx_stack[j];
+ 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;
+ } else {
+ l.offset.y = 0;
+ }
+}
- if (item_fx->type == ITEM_CUSTOMFX && custom_fx_ok) {
- ItemCustomFX *item_custom = static_cast<ItemCustomFX *>(item_fx);
+float 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_color_shadow, bool p_shadow_as_outline, const Point2 &p_shadow_ofs) {
+ Vector2 off;
- Ref<CharFXTransform> charfx = item_custom->char_fx_transform;
- Ref<RichTextEffect> custom_effect = item_custom->custom_effect;
+ ERR_FAIL_COND_V(p_frame == nullptr, off.y);
+ ERR_FAIL_COND_V(p_line < 0 || p_line >= p_frame->lines.size(), off.y);
- if (!custom_effect.is_null()) {
- charfx->elapsed_time = item_custom->elapsed_time;
- charfx->relative_index = c_item_offset;
- charfx->absolute_index = p_char_count;
- charfx->visibility = visible;
- charfx->offset = fx_offset;
- charfx->color = fx_color;
- charfx->character = fx_char;
+ Line &l = p_frame->lines.write[p_line];
- bool effect_status = custom_effect->_process_effect_impl(charfx);
- custom_fx_ok = effect_status;
+ Item *it_from = l.from;
+ Item *it_to = (p_line + 1 < p_frame->lines.size()) ? p_frame->lines[p_line + 1].from : nullptr;
+ Variant meta;
- fx_offset += charfx->offset;
- fx_color = charfx->color;
- visible &= charfx->visibility;
- fx_char = charfx->character;
- }
- } else if (item_fx->type == ITEM_SHAKE) {
- ItemShake *item_shake = static_cast<ItemShake *>(item_fx);
-
- uint64_t char_current_rand = item_shake->offset_random(c_item_offset);
- uint64_t char_previous_rand = item_shake->offset_previous_random(c_item_offset);
- uint64_t max_rand = 2147483647;
- double current_offset = Math::range_lerp(char_current_rand % max_rand, 0, max_rand, 0.0f, 2.f * (float)Math_PI);
- double previous_offset = Math::range_lerp(char_previous_rand % max_rand, 0, max_rand, 0.0f, 2.f * (float)Math_PI);
- double n_time = (double)(item_shake->elapsed_time / (0.5f / item_shake->rate));
- n_time = (n_time > 1.0) ? 1.0 : n_time;
- fx_offset += Point2(Math::lerp(Math::sin(previous_offset),
- Math::sin(current_offset),
- n_time),
- Math::lerp(Math::cos(previous_offset),
- Math::cos(current_offset),
- n_time)) *
- (float)item_shake->strength / 10.0f;
- } else if (item_fx->type == ITEM_WAVE) {
- ItemWave *item_wave = static_cast<ItemWave *>(item_fx);
-
- double value = Math::sin(item_wave->frequency * item_wave->elapsed_time + ((p_ofs.x + pofs) / 50)) * (item_wave->amplitude / 10.0f);
- fx_offset += Point2(0, 1) * value;
- } else if (item_fx->type == ITEM_TORNADO) {
- ItemTornado *item_tornado = static_cast<ItemTornado *>(item_fx);
-
- double torn_x = Math::sin(item_tornado->frequency * item_tornado->elapsed_time + ((p_ofs.x + pofs) / 50)) * (item_tornado->radius);
- double torn_y = Math::cos(item_tornado->frequency * item_tornado->elapsed_time + ((p_ofs.x + pofs) / 50)) * (item_tornado->radius);
- fx_offset += Point2(torn_x, torn_y);
- } else if (item_fx->type == ITEM_RAINBOW) {
- ItemRainbow *item_rainbow = static_cast<ItemRainbow *>(item_fx);
-
- fx_color = fx_color.from_hsv(item_rainbow->frequency * (item_rainbow->elapsed_time + ((p_ofs.x + pofs) / 50)),
- item_rainbow->saturation,
- item_rainbow->value,
- fx_color.a);
- }
- }
+ if (it_from == nullptr) {
+ return off.y;
+ }
- if (visible) {
- line_is_blank = false;
- w += font->get_char_size(c[i], c[i + 1]).x;
- }
+ RID ci = get_canvas_item();
+ bool rtl = (l.text_buf->get_direction() == TextServer::DIRECTION_RTL);
+ bool lrtl = is_layout_rtl();
- if (c[i] == '\t') {
- visible = false;
- }
+ Vector<int> list_index;
+ Vector<ItemList *> list_items;
+ _find_list(l.from, list_index, list_items);
- if (visible) {
- if (selected) {
- cw = font->get_char_size(fx_char, c[i + 1]).x;
- draw_rect(Rect2(p_ofs.x + pofs, p_ofs.y + y, cw, lh), selection_bg);
- }
+ String prefix;
+ for (int i = 0; i < list_index.size(); i++) {
+ if (rtl) {
+ prefix = prefix + ".";
+ } else {
+ prefix = "." + prefix;
+ }
+ String segment;
+ if (list_items[i]->list_type == LIST_DOTS) {
+ static const char32_t _prefix[2] = { 0x25CF, 0 };
+ prefix = _prefix;
+ break;
+ } else if (list_items[i]->list_type == LIST_NUMBERS) {
+ segment = TS->format_number(itos(list_index[i]), _find_language(l.from));
+ } else if (list_items[i]->list_type == LIST_LETTERS) {
+ segment = _letters(list_index[i], list_items[i]->capitalize);
+ } else if (list_items[i]->list_type == LIST_ROMAN) {
+ segment = _roman(list_index[i], list_items[i]->capitalize);
+ }
+ if (rtl) {
+ prefix = prefix + segment;
+ } else {
+ prefix = segment + prefix;
+ }
+ }
+ if (prefix != "") {
+ Ref<Font> font = _find_font(l.from);
+ if (font.is_null()) {
+ font = get_theme_font("normal_font");
+ }
+ int font_size = _find_font_size(l.from);
+ if (font_size == -1) {
+ font_size = get_theme_font_size("normal_font_size");
+ }
+ if (rtl) {
+ float offx = 0.0f;
+ if (!lrtl && p_frame == main) { // Skip Scrollbar.
+ offx -= scroll_w;
+ }
+ font->draw_string(ci, p_ofs + Vector2(p_width - l.offset.x + offx, l.text_buf->get_line_ascent(0)), " " + prefix, HALIGN_LEFT, l.offset.x, font_size, _find_color(l.from, p_base_color));
+ } else {
+ float offx = 0.0f;
+ if (lrtl && p_frame == main) { // Skip Scrollbar.
+ offx += scroll_w;
+ }
+ font->draw_string(ci, p_ofs + Vector2(offx, l.text_buf->get_line_ascent(0)), prefix + " ", HALIGN_RIGHT, l.offset.x, font_size, _find_color(l.from, p_base_color));
+ }
+ }
- if (p_font_color_shadow.a > 0) {
- float x_ofs_shadow = align_ofs + pofs;
- float y_ofs_shadow = y + lh - line_descent;
- font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + shadow_ofs + fx_offset, fx_char, c[i + 1], -1, p_font_color_shadow);
+ // Draw text.
+ for (int line = 0; line < l.text_buf->get_line_count(); line++) {
+ RID rid = l.text_buf->get_line_rid(line);
- if (p_shadow_as_outline) {
- font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, shadow_ofs.y) + fx_offset, fx_char, c[i + 1], -1, p_font_color_shadow);
- font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(shadow_ofs.x, -shadow_ofs.y) + fx_offset, fx_char, c[i + 1], -1, p_font_color_shadow);
- font->draw_char(ci, Point2(x_ofs_shadow, y_ofs_shadow) + Vector2(-shadow_ofs.x, -shadow_ofs.y) + fx_offset, fx_char, c[i + 1], -1, p_font_color_shadow);
- }
- }
+ float width = l.text_buf->get_width();
+ float length = TS->shaped_text_get_width(rid);
- if (selected) {
- font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent), fx_char, c[i + 1], -1, override_selected_font_color ? selection_fg : fx_color);
- } else {
- cw = font->draw_char(ci, p_ofs + Point2(align_ofs + pofs, y + lh - line_descent) + fx_offset, fx_char, c[i + 1], -1, fx_color);
- }
- } else if (previously_visible && c[i] != '\t') {
- backtrack += font->get_char_size(fx_char, c[i + 1]).x;
- }
+ // Draw line.
- p_char_count++;
- if (c[i] == '\t') {
- cw = tab_size * font->get_char_size(' ').width;
- backtrack = MAX(0, backtrack - cw);
+ if (rtl) {
+ off.x = p_width - l.offset.x - width;
+ if (!lrtl && p_frame == main) { // Skip Scrollbar.
+ off.x -= scroll_w;
+ }
+ } else {
+ off.x = l.offset.x;
+ if (lrtl && p_frame == main) { // Skip Scrollbar.
+ off.x += scroll_w;
+ }
+ }
+
+ // Draw text.
+ switch (l.text_buf->get_align()) {
+ case HALIGN_FILL:
+ case HALIGN_LEFT: {
+ if (rtl) {
+ off.x += width - length;
+ }
+ } break;
+ case HALIGN_CENTER: {
+ off.x += Math::floor((width - length) / 2.0);
+ } break;
+ case HALIGN_RIGHT: {
+ if (!rtl) {
+ off.x += width - length;
+ }
+ } break;
+ }
+
+ //draw_rect(Rect2(p_ofs + off, TS->shaped_text_get_size(rid)), Color(1,0,0), false, 2); //DEBUG_RECTS
+
+ off.y += TS->shaped_text_get_ascent(rid);
+ // Draw inlined objects.
+ Array objects = TS->shaped_text_get_objects(rid);
+ for (int i = 0; i < objects.size(); i++) {
+ Item *it = (Item *)(uint64_t)objects[i];
+ if (it != nullptr) {
+ Rect2 rect = TS->shaped_text_get_object_rect(rid, objects[i]);
+ //draw_rect(rect, Color(1,0,0), false, 2); //DEBUG_RECTS
+ switch (it->type) {
+ case ITEM_IMAGE: {
+ ItemImage *img = static_cast<ItemImage *>(it);
+ img->image->draw_rect(ci, Rect2(p_ofs + rect.position + off, rect.size), false, img->color);
+ } break;
+ case ITEM_TABLE: {
+ ItemTable *table = static_cast<ItemTable *>(it);
+ Color odd_row_bg = get_theme_color("table_odd_row_bg");
+ Color even_row_bg = get_theme_color("table_even_row_bg");
+ Color border = get_theme_color("table_border");
+ int col_count = table->columns.size();
+ int row_count = table->rows.size();
+
+ int idx = 0;
+ for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+
+ int col = idx % col_count;
+ int row = idx / col_count;
+
+ if (frame->lines.size() != 0 && row < row_count) {
+ Vector2 coff = frame->lines[0].offset;
+ if (rtl) {
+ coff.x = rect.size.width - table->columns[col].width - coff.x;
+ }
+ if (row % 2 == 0) {
+ draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position, Size2(table->columns[col].width, table->rows[row])), (frame->odd_row_bg != Color(0, 0, 0, 0) ? frame->odd_row_bg : odd_row_bg), true);
+ } else {
+ draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position, Size2(table->columns[col].width, table->rows[row])), (frame->even_row_bg != Color(0, 0, 0, 0) ? frame->even_row_bg : even_row_bg), true);
}
+ draw_rect(Rect2(p_ofs + rect.position + off + coff - frame->padding.position, Size2(table->columns[col].width, table->rows[row])), (frame->border != Color(0, 0, 0, 0) ? frame->border : border), false);
+ }
- ofs += cw;
+ for (int j = 0; j < 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_color_shadow, p_shadow_as_outline, p_shadow_ofs);
}
+ idx++;
}
+ } break;
+ default:
+ break;
+ }
+ }
+ }
- if (underline) {
- Color uc = color;
- uc.a *= 0.5;
- int uy = y + lh - line_descent + font->get_underline_position();
- float underline_width = font->get_underline_thickness();
-#ifdef TOOLS_ENABLED
- underline_width *= EDSCALE;
-#endif
- RS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, underline_width);
- } else if (strikethrough) {
- Color uc = color;
- uc.a *= 0.5;
- int uy = y + lh - (line_ascent + line_descent) / 2;
- float strikethrough_width = font->get_underline_thickness();
-#ifdef TOOLS_ENABLED
- strikethrough_width *= EDSCALE;
-#endif
- RS::get_singleton()->canvas_item_add_line(ci, p_ofs + Point2(align_ofs + wofs, uy), p_ofs + Point2(align_ofs + wofs + w, uy), uc, strikethrough_width);
- }
- }
+ const Vector<TextServer::Glyph> visual = TS->shaped_text_get_glyphs(rid);
+ const TextServer::Glyph *glyphs = visual.ptr();
+ int gl_size = visual.size();
- ADVANCE(fw);
- CHECK_HEIGHT(fh); //must be done somewhere
- c = &c[end];
- }
+ Vector2 gloff = off;
+ // Draw oulines and shadow.
+ for (int i = 0; i < gl_size; i++) {
+ Item *it = _get_item_at_pos(it_from, it_to, glyphs[i].start);
+ int size = _find_outline_size(it);
+ Color font_color = _find_outline_color(it, Color(0, 0, 0, 0));
+ if (size <= 0) {
+ gloff.x += glyphs[i].advance;
+ continue;
+ }
- } break;
- case ITEM_IMAGE: {
- lh = 0;
- if (p_mode != PROCESS_CACHE) {
- lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
- } else {
- l.char_count += 1; //images count as chars too
+ // Get FX.
+ ItemFade *fade = nullptr;
+ Item *fade_item = it;
+ while (fade_item) {
+ if (fade_item->type == ITEM_FADE) {
+ fade = static_cast<ItemFade *>(fade_item);
+ break;
}
+ fade_item = fade_item->parent;
+ }
- ItemImage *img = static_cast<ItemImage *>(it);
+ Vector<ItemFX *> fx_stack;
+ _fetch_item_fx_stack(it, fx_stack);
+ bool custom_fx_ok = true;
- Ref<Font> font = _find_font(it);
- if (font.is_null()) {
- font = p_base_font;
+ Point2 fx_offset = Vector2(glyphs[i].x_off, glyphs[i].y_off);
+ RID frid = glyphs[i].font_rid;
+ uint32_t gl = glyphs[i].index;
+
+ //Apply fx.
+ float faded_visibility = 1.0f;
+ if (fade) {
+ if (glyphs[i].start >= fade->starting_index) {
+ faded_visibility -= (float)(glyphs[i].start - fade->starting_index) / (float)fade->length;
+ faded_visibility = faded_visibility < 0.0f ? 0.0f : faded_visibility;
}
+ font_color.a = faded_visibility;
+ }
- if (p_mode == PROCESS_POINTER && r_click_char) {
- *r_click_char = 0;
+ bool visible = (font_color.a != 0);
+
+ for (int j = 0; j < fx_stack.size(); j++) {
+ ItemFX *item_fx = fx_stack[j];
+ if (item_fx->type == ITEM_CUSTOMFX && custom_fx_ok) {
+ ItemCustomFX *item_custom = static_cast<ItemCustomFX *>(item_fx);
+
+ Ref<CharFXTransform> charfx = item_custom->char_fx_transform;
+ Ref<RichTextEffect> custom_effect = item_custom->custom_effect;
+
+ if (!custom_effect.is_null()) {
+ charfx->elapsed_time = item_custom->elapsed_time;
+ charfx->range = Vector2i(l.char_offset + glyphs[i].start, l.char_offset + glyphs[i].end);
+ charfx->visibility = visible;
+ charfx->outline = true;
+ charfx->font = frid;
+ charfx->glpyh_index = gl;
+ charfx->offset = fx_offset;
+ charfx->color = font_color;
+
+ bool effect_status = custom_effect->_process_effect_impl(charfx);
+ custom_fx_ok = effect_status;
+
+ fx_offset += charfx->offset;
+ font_color = charfx->color;
+ frid = charfx->font;
+ gl = charfx->glpyh_index;
+ visible &= charfx->visibility;
+ }
+ } else if (item_fx->type == ITEM_SHAKE) {
+ ItemShake *item_shake = static_cast<ItemShake *>(item_fx);
+
+ uint64_t char_current_rand = item_shake->offset_random(glyphs[i].start);
+ uint64_t char_previous_rand = item_shake->offset_previous_random(glyphs[i].start);
+ uint64_t max_rand = 2147483647;
+ double current_offset = Math::range_lerp(char_current_rand % max_rand, 0, max_rand, 0.0f, 2.f * (float)Math_PI);
+ double previous_offset = Math::range_lerp(char_previous_rand % max_rand, 0, max_rand, 0.0f, 2.f * (float)Math_PI);
+ double n_time = (double)(item_shake->elapsed_time / (0.5f / item_shake->rate));
+ n_time = (n_time > 1.0) ? 1.0 : n_time;
+ fx_offset += Point2(Math::lerp(Math::sin(previous_offset), Math::sin(current_offset), n_time), Math::lerp(Math::cos(previous_offset), Math::cos(current_offset), n_time)) * (float)item_shake->strength / 10.0f;
+ } else if (item_fx->type == ITEM_WAVE) {
+ ItemWave *item_wave = static_cast<ItemWave *>(item_fx);
+
+ double value = Math::sin(item_wave->frequency * item_wave->elapsed_time + ((p_ofs.x + off.x) / 50)) * (item_wave->amplitude / 10.0f);
+ fx_offset += Point2(0, 1) * value;
+ } else if (item_fx->type == ITEM_TORNADO) {
+ ItemTornado *item_tornado = static_cast<ItemTornado *>(item_fx);
+
+ double torn_x = Math::sin(item_tornado->frequency * item_tornado->elapsed_time + ((p_ofs.x + gloff.x) / 50)) * (item_tornado->radius);
+ double torn_y = Math::cos(item_tornado->frequency * item_tornado->elapsed_time + ((p_ofs.x + gloff.x) / 50)) * (item_tornado->radius);
+ fx_offset += Point2(torn_x, torn_y);
+ } else if (item_fx->type == ITEM_RAINBOW) {
+ ItemRainbow *item_rainbow = static_cast<ItemRainbow *>(item_fx);
+
+ font_color = font_color.from_hsv(item_rainbow->frequency * (item_rainbow->elapsed_time + ((p_ofs.x + gloff.x) / 50)), item_rainbow->saturation, item_rainbow->value, font_color.a);
}
+ }
- ENSURE_WIDTH(img->size.width);
+ Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
- bool visible = visible_characters < 0 || (p_char_count < visible_characters && YRANGE_VISIBLE(y + lh - font->get_descent() - img->size.height, img->size.height));
+ // Draw glyph outlines.
+ for (int j = 0; j < glyphs[i].repeat; j++) {
if (visible) {
- line_is_blank = false;
- }
-
- if (p_mode == PROCESS_DRAW && visible) {
- img->image->draw_rect(ci, Rect2(p_ofs + Point2(align_ofs + wofs, y + lh - font->get_descent() - img->size.height), img->size), false, img->color);
+ if (frid != RID()) {
+ if (p_shadow_as_outline) {
+ TS->font_draw_glyph_outline(frid, ci, glyphs[i].font_size, size, p_ofs + fx_offset + gloff + Vector2(-shadow_ofs.x, shadow_ofs.y), gl, p_font_color_shadow);
+ TS->font_draw_glyph_outline(frid, ci, glyphs[i].font_size, size, p_ofs + fx_offset + gloff + Vector2(shadow_ofs.x, -shadow_ofs.y), gl, p_font_color_shadow);
+ TS->font_draw_glyph_outline(frid, ci, glyphs[i].font_size, size, p_ofs + fx_offset + gloff + Vector2(-shadow_ofs.x, -shadow_ofs.y), gl, p_font_color_shadow);
+ }
+ TS->font_draw_glyph_outline(frid, ci, glyphs[i].font_size, size, p_ofs + fx_offset + gloff, gl, font_color);
+ }
}
- p_char_count++;
-
- ADVANCE(img->size.width);
- CHECK_HEIGHT((img->size.height + font->get_descent()));
+ gloff.x += glyphs[i].advance;
+ }
+ }
- } break;
- case ITEM_NEWLINE: {
- lh = 0;
+ // Draw main text.
+ Color selection_fg = get_theme_color("font_color_selected");
+ Color selection_bg = get_theme_color("selection_color");
- if (p_mode != PROCESS_CACHE) {
- lh = line < l.height_caches.size() ? l.height_caches[line] : 1;
- line_is_blank = true;
- }
+ int sel_start = -1;
+ int sel_end = -1;
- } break;
- case ITEM_TABLE: {
- lh = 0;
- ItemTable *table = static_cast<ItemTable *>(it);
- int hseparation = get_theme_constant("table_hseparation");
- int vseparation = get_theme_constant("table_vseparation");
- Color ccolor = _find_color(table, p_base_color);
- Vector2 draw_ofs = Point2(wofs, y);
- Color font_color_shadow = get_theme_color("font_color_shadow");
- bool use_outline = get_theme_constant("shadow_as_outline");
- Point2 shadow_ofs2(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
-
- if (p_mode == PROCESS_CACHE) {
- int idx = 0;
- //set minimums to zero
- for (int i = 0; i < table->columns.size(); i++) {
- table->columns.write[i].min_width = 0;
- table->columns.write[i].max_width = 0;
- table->columns.write[i].width = 0;
- }
- //compute minimum width for each cell
- const int available_width = p_width - hseparation * (table->columns.size() - 1) - wofs;
+ if (selection.active && (selection.from_frame->lines[selection.from_line].char_offset + selection.from_char) <= (l.char_offset + TS->shaped_text_get_range(rid).y) && (selection.to_frame->lines[selection.to_line].char_offset + selection.to_char) >= (l.char_offset + TS->shaped_text_get_range(rid).x)) {
+ sel_start = MAX(TS->shaped_text_get_range(rid).x, (selection.from_frame->lines[selection.from_line].char_offset + selection.from_char) - l.char_offset);
+ sel_end = MIN(TS->shaped_text_get_range(rid).y, (selection.to_frame->lines[selection.to_line].char_offset + selection.to_char) - l.char_offset);
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); //children should all be frames
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ Vector<Vector2> sel = TS->shaped_text_get_selection(rid, sel_start, sel_end);
+ for (int i = 0; i < sel.size(); i++) {
+ Rect2 rect = Rect2(sel[i].x + p_ofs.x + off.x, p_ofs.y + off.y - TS->shaped_text_get_ascent(rid), sel[i].y - sel[i].x, TS->shaped_text_get_size(rid).y);
+ RenderingServer::get_singleton()->canvas_item_add_rect(ci, rect, selection_bg);
+ }
+ }
- int column = idx % table->columns.size();
+ for (int i = 0; i < gl_size; i++) {
+ bool selected = selection.active && (sel_start != -1) && (glyphs[i].start >= sel_start) && (glyphs[i].end <= sel_end);
+ Item *it = _get_item_at_pos(it_from, it_to, glyphs[i].start);
+ Color font_color = _find_color(it, p_base_color);
+ if (_find_underline(it) || (_find_meta(it, &meta) && underline_meta)) {
+ Color uc = font_color;
+ uc.a *= 0.5;
+ float y_off = TS->shaped_text_get_underline_position(rid);
+ float underline_width = TS->shaped_text_get_underline_thickness(rid);
+#ifdef TOOLS_ENABLED
+ underline_width *= EDSCALE;
+#endif
+ draw_line(p_ofs + Vector2(off.x, off.y + y_off), p_ofs + Vector2(off.x + glyphs[i].advance * glyphs[i].repeat, off.y + y_off), uc, underline_width);
+ } else if (_find_strikethrough(it)) {
+ Color uc = font_color;
+ uc.a *= 0.5;
+ float y_off = -TS->shaped_text_get_ascent(rid) + TS->shaped_text_get_size(rid).y / 2;
+ float underline_width = TS->shaped_text_get_underline_thickness(rid);
+#ifdef TOOLS_ENABLED
+ underline_width *= EDSCALE;
+#endif
+ draw_line(p_ofs + Vector2(off.x, off.y + y_off), p_ofs + Vector2(off.x + glyphs[i].advance * glyphs[i].repeat, off.y + y_off), uc, underline_width);
+ }
- int ly = 0;
+ // Get FX.
+ ItemFade *fade = nullptr;
+ Item *fade_item = it;
+ while (fade_item) {
+ if (fade_item->type == ITEM_FADE) {
+ fade = static_cast<ItemFade *>(fade_item);
+ break;
+ }
+ fade_item = fade_item->parent;
+ }
- for (int i = 0; i < frame->lines.size(); i++) {
- _process_line(frame, Point2(), ly, available_width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs2);
- table->columns.write[column].min_width = MAX(table->columns[column].min_width, frame->lines[i].minimum_width);
- table->columns.write[column].max_width = MAX(table->columns[column].max_width, frame->lines[i].maximum_width);
- }
- idx++;
- }
+ Vector<ItemFX *> fx_stack;
+ _fetch_item_fx_stack(it, fx_stack);
+ bool custom_fx_ok = true;
- //compute available width and total ratio (for expanders)
+ Point2 fx_offset = Vector2(glyphs[i].x_off, glyphs[i].y_off);
+ RID frid = glyphs[i].font_rid;
+ uint32_t gl = glyphs[i].index;
- int total_ratio = 0;
- int remaining_width = available_width;
- table->total_width = hseparation;
+ //Apply fx.
+ float faded_visibility = 1.0f;
+ if (fade) {
+ if (glyphs[i].start >= fade->starting_index) {
+ faded_visibility -= (float)(glyphs[i].start - fade->starting_index) / (float)fade->length;
+ faded_visibility = faded_visibility < 0.0f ? 0.0f : faded_visibility;
+ }
+ font_color.a = faded_visibility;
+ }
- for (int i = 0; i < table->columns.size(); 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;
- }
- if (table->columns[i].expand) {
- total_ratio += table->columns[i].expand_ratio;
- }
+ bool visible = (font_color.a != 0);
+
+ for (int j = 0; j < fx_stack.size(); j++) {
+ ItemFX *item_fx = fx_stack[j];
+ if (item_fx->type == ITEM_CUSTOMFX && custom_fx_ok) {
+ ItemCustomFX *item_custom = static_cast<ItemCustomFX *>(item_fx);
+
+ Ref<CharFXTransform> charfx = item_custom->char_fx_transform;
+ Ref<RichTextEffect> custom_effect = item_custom->custom_effect;
+
+ if (!custom_effect.is_null()) {
+ charfx->elapsed_time = item_custom->elapsed_time;
+ charfx->range = Vector2i(l.char_offset + glyphs[i].start, l.char_offset + glyphs[i].end);
+ charfx->visibility = visible;
+ charfx->outline = false;
+ charfx->font = frid;
+ charfx->glpyh_index = gl;
+ charfx->offset = fx_offset;
+ charfx->color = font_color;
+
+ bool effect_status = custom_effect->_process_effect_impl(charfx);
+ custom_fx_ok = effect_status;
+
+ fx_offset += charfx->offset;
+ font_color = charfx->color;
+ frid = charfx->font;
+ gl = charfx->glpyh_index;
+ visible &= charfx->visibility;
}
+ } else if (item_fx->type == ITEM_SHAKE) {
+ ItemShake *item_shake = static_cast<ItemShake *>(item_fx);
+
+ uint64_t char_current_rand = item_shake->offset_random(glyphs[i].start);
+ uint64_t char_previous_rand = item_shake->offset_previous_random(glyphs[i].start);
+ uint64_t max_rand = 2147483647;
+ double current_offset = Math::range_lerp(char_current_rand % max_rand, 0, max_rand, 0.0f, 2.f * (float)Math_PI);
+ double previous_offset = Math::range_lerp(char_previous_rand % max_rand, 0, max_rand, 0.0f, 2.f * (float)Math_PI);
+ double n_time = (double)(item_shake->elapsed_time / (0.5f / item_shake->rate));
+ n_time = (n_time > 1.0) ? 1.0 : n_time;
+ fx_offset += Point2(Math::lerp(Math::sin(previous_offset), Math::sin(current_offset), n_time), Math::lerp(Math::cos(previous_offset), Math::cos(current_offset), n_time)) * (float)item_shake->strength / 10.0f;
+ } else if (item_fx->type == ITEM_WAVE) {
+ ItemWave *item_wave = static_cast<ItemWave *>(item_fx);
+
+ double value = Math::sin(item_wave->frequency * item_wave->elapsed_time + ((p_ofs.x + off.x) / 50)) * (item_wave->amplitude / 10.0f);
+ fx_offset += Point2(0, 1) * value;
+ } else if (item_fx->type == ITEM_TORNADO) {
+ ItemTornado *item_tornado = static_cast<ItemTornado *>(item_fx);
+
+ double torn_x = Math::sin(item_tornado->frequency * item_tornado->elapsed_time + ((p_ofs.x + off.x) / 50)) * (item_tornado->radius);
+ double torn_y = Math::cos(item_tornado->frequency * item_tornado->elapsed_time + ((p_ofs.x + off.x) / 50)) * (item_tornado->radius);
+ fx_offset += Point2(torn_x, torn_y);
+ } else if (item_fx->type == ITEM_RAINBOW) {
+ ItemRainbow *item_rainbow = static_cast<ItemRainbow *>(item_fx);
+
+ font_color = font_color.from_hsv(item_rainbow->frequency * (item_rainbow->elapsed_time + ((p_ofs.x + off.x) / 50)), item_rainbow->saturation, item_rainbow->value, font_color.a);
+ }
+ }
- //assign actual widths
- for (int i = 0; i < table->columns.size(); i++) {
- table->columns.write[i].width = table->columns[i].min_width;
- if (table->columns[i].expand && total_ratio > 0) {
- table->columns.write[i].width += table->columns[i].expand_ratio * remaining_width / total_ratio;
- }
- table->total_width += table->columns[i].width + hseparation;
- }
+ if (selected) {
+ font_color = override_selected_font_color ? selection_fg : font_color;
+ }
- //resize to max_width if needed and distribute the remaining space
- bool table_need_fit = true;
- while (table_need_fit) {
- table_need_fit = false;
- //fit slim
- for (int i = 0; i < table->columns.size(); i++) {
- if (!table->columns[i].expand) {
- continue;
- }
- 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->total_width -= dif;
- total_ratio -= table->columns[i].expand_ratio;
- }
- }
- //grow
- remaining_width = available_width - table->total_width;
- if (remaining_width > 0 && total_ratio > 0) {
- for (int i = 0; i < table->columns.size(); i++) {
- if (table->columns[i].expand) {
- int dif = table->columns[i].max_width - table->columns[i].width;
- 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->total_width += incr;
- }
- }
- }
- }
+ // Draw glyphs.
+ for (int j = 0; j < glyphs[i].repeat; j++) {
+ if (visible) {
+ if (frid != RID()) {
+ TS->font_draw_glyph(frid, ci, glyphs[i].font_size, p_ofs + fx_offset + off, gl, selected ? selection_fg : font_color);
+ } else if ((glyphs[i].flags & TextServer::GRAPHEME_IS_VIRTUAL) != TextServer::GRAPHEME_IS_VIRTUAL) {
+ TS->draw_hex_code_box(ci, glyphs[i].font_size, p_ofs + fx_offset + off, gl, selected ? selection_fg : font_color);
}
+ }
+ off.x += glyphs[i].advance;
+ }
+ }
+ off.y += TS->shaped_text_get_descent(rid);
+ }
- //compute caches properly again with the right width
- idx = 0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); //children should all be frames
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ return off.y;
+}
- int column = idx % table->columns.size();
+void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, ItemFrame **r_click_frame, int *r_click_line, Item **r_click_item, int *r_click_char, bool *r_outside) {
+ if (r_click_item) {
+ *r_click_item = nullptr;
+ }
+ if (r_click_char != nullptr) {
+ *r_click_char = 0;
+ }
+ if (r_outside != nullptr) {
+ *r_outside = true;
+ }
- for (int i = 0; i < frame->lines.size(); i++) {
- int ly = 0;
- _process_line(frame, Point2(), ly, table->columns[column].width, i, PROCESS_CACHE, cfont, Color(), font_color_shadow, use_outline, shadow_ofs2);
- frame->lines.write[i].height_cache = ly; //actual height
- frame->lines.write[i].height_accum_cache = ly; //actual height
- }
- idx++;
- }
- }
+ Size2 size = get_size();
+ Rect2 text_rect = _get_text_rect();
- Point2 offset(align_ofs + hseparation, vseparation);
+ int vofs = vscroll->get_value();
- int row_height = 0;
- //draw using computed caches
- int idx = 0;
- for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
- ERR_CONTINUE(E->get()->type != ITEM_FRAME); //children should all be frames
- ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ // Search for the first line.
+ int from_line = 0;
- int column = idx % table->columns.size();
+ //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 + _get_text_rect().get_position().y >= vofs) {
+ break;
+ }
+ from_line++;
+ }
- int ly = 0;
- int yofs = 0;
+ if (from_line >= main->lines.size()) {
+ return;
+ }
- int lines_h = frame->lines[frame->lines.size() - 1].height_accum_cache - (frame->lines[0].height_accum_cache - frame->lines[0].height_cache);
- int lines_ofs = p_ofs.y + offset.y + draw_ofs.y;
+ 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()) {
+ ofs.y += _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);
+ if (((r_click_item != nullptr) && ((*r_click_item) != nullptr)) || ((r_click_frame != nullptr) && ((*r_click_frame) != nullptr))) {
+ if (r_outside != nullptr) {
+ *r_outside = false;
+ }
+ return;
+ }
+ from_line++;
+ }
+}
- bool visible = lines_ofs < get_size().height && lines_ofs + lines_h >= 0;
- if (visible) {
- line_is_blank = false;
- }
+float RichTextLabel::_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, int *r_click_line, Item **r_click_item, int *r_click_char) {
+ Vector2 off;
- for (int i = 0; i < frame->lines.size(); i++) {
- if (visible) {
- if (p_mode == PROCESS_DRAW) {
- nonblank_line_count += _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_DRAW, cfont, ccolor, font_color_shadow, use_outline, shadow_ofs2);
- } else if (p_mode == PROCESS_POINTER) {
- _process_line(frame, p_ofs + offset + draw_ofs + Vector2(0, yofs), ly, table->columns[column].width, i, PROCESS_POINTER, cfont, ccolor, font_color_shadow, use_outline, shadow_ofs2, p_click_pos, r_click_item, r_click_char, r_outside);
- if (r_click_item && *r_click_item) {
- RETURN; // exit early
- }
- }
- }
+ int char_pos = -1;
+ Line &l = p_frame->lines.write[p_line];
+ bool rtl = (l.text_buf->get_direction() == TextServer::DIRECTION_RTL);
+ bool lrtl = is_layout_rtl();
+ bool table_hit = false;
- yofs += frame->lines[i].height_cache;
- if (p_mode == PROCESS_CACHE) {
- frame->lines.write[i].height_accum_cache = offset.y + draw_ofs.y + frame->lines[i].height_cache;
- }
- }
+ for (int line = 0; line < l.text_buf->get_line_count(); line++) {
+ RID rid = l.text_buf->get_line_rid(line);
- row_height = MAX(yofs, row_height);
- offset.x += table->columns[column].width + hseparation;
+ float width = l.text_buf->get_width();
+ float length = TS->shaped_text_get_width(rid);
- if (column == table->columns.size() - 1) {
- offset.y += row_height + vseparation;
- offset.x = hseparation;
- row_height = 0;
- }
- idx++;
- }
+ if (rtl) {
+ off.x = p_width - l.offset.x - width;
+ if (!lrtl && p_frame == main) { // Skip Scrollbar.
+ off.x -= scroll_w;
+ }
+ } else {
+ off.x = l.offset.x;
+ if (lrtl && p_frame == main) { // Skip Scrollbar.
+ off.x += scroll_w;
+ }
+ }
- int total_height = offset.y;
- if (row_height) {
- total_height = row_height + vseparation;
+ switch (l.text_buf->get_align()) {
+ case HALIGN_FILL:
+ case HALIGN_LEFT: {
+ if (rtl) {
+ off.x += width - length;
}
+ } break;
+ case HALIGN_CENTER: {
+ off.x += Math::floor((width - length) / 2.0);
+ } break;
+ case HALIGN_RIGHT: {
+ if (!rtl) {
+ off.x += width - length;
+ }
+ } break;
+ }
- ADVANCE(table->total_width);
- CHECK_HEIGHT(total_height);
+ off.y += TS->shaped_text_get_ascent(rid);
- } break;
+ Array objects = TS->shaped_text_get_objects(rid);
+ for (int i = 0; i < objects.size(); i++) {
+ Item *it = (Item *)(uint64_t)objects[i];
+ if (it != nullptr) {
+ Rect2 rect = TS->shaped_text_get_object_rect(rid, objects[i]);
+ if (rect.has_point(p_click - p_ofs - off)) {
+ switch (it->type) {
+ case ITEM_TABLE: {
+ int hseparation = get_theme_constant("table_hseparation");
+ int vseparation = get_theme_constant("table_vseparation");
- default: {
- }
- }
+ ItemTable *table = static_cast<ItemTable *>(it);
- Item *itp = it;
+ table_hit = true;
- it = _get_next_item(it);
+ int idx = 0;
+ int col_count = table->columns.size();
+ int row_count = table->rows.size();
- if (it && (p_line + 1 < p_frame->lines.size()) && p_frame->lines[p_line + 1].from == it) {
- if (p_mode == PROCESS_POINTER && r_click_item && p_click_pos.y >= p_ofs.y + y && p_click_pos.y <= p_ofs.y + y + lh) {
- //went to next line, but pointer was on the previous one
- if (r_outside) {
- *r_outside = true;
+ for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+
+ int col = idx % col_count;
+ int row = idx / col_count;
+
+ if (frame->lines.size() != 0 && row < row_count) {
+ Vector2 coff = frame->lines[0].offset;
+ if (rtl) {
+ coff.x = rect.size.width - table->columns[col].width - coff.x;
+ }
+ Rect2 crect = Rect2(p_ofs + off + rect.position + coff - frame->padding.position, Size2(table->columns[col].width + hseparation, table->rows[row] + vseparation) + frame->padding.position + frame->padding.size);
+ if (col == col_count - 1) {
+ if (rtl) {
+ crect.size.x = crect.position.x + crect.size.x;
+ crect.position.x = 0;
+ } else {
+ crect.size.x = get_size().x;
+ }
+ }
+ if (crect.has_point(p_click)) {
+ for (int j = 0; j < frame->lines.size(); j++) {
+ _find_click_in_line(frame, j, p_ofs + off + rect.position + Vector2(0, frame->lines[j].offset.y), rect.size.x, p_click, r_click_frame, r_click_line, r_click_item, r_click_char);
+ if (((r_click_item != nullptr) && ((*r_click_item) != nullptr)) || ((r_click_frame != nullptr) && ((*r_click_frame) != nullptr))) {
+ return off.y;
+ }
+ }
+ }
+ }
+ idx++;
+ }
+ } break;
+ default:
+ break;
+ }
}
- *r_click_item = itp;
- *r_click_char = rchar;
- RETURN;
}
+ }
+ Rect2 rect = Rect2(p_ofs + off - Vector2(0, TS->shaped_text_get_ascent(rid)), Size2(get_size().x, TS->shaped_text_get_size(rid).y));
- break;
+ if (rect.has_point(p_click) && !table_hit) {
+ char_pos = TS->shaped_text_hit_test_position(rid, p_click.x - rect.position.x);
}
+ off.y += TS->shaped_text_get_descent(rid);
}
- NEW_LINE;
- RETURN;
+ if (char_pos >= 0) {
+ // 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;
+ it = _get_item_at_pos(it, it_to, char_pos);
+ *r_click_item = it;
+ }
+
+ if (r_click_frame != nullptr) {
+ *r_click_frame = p_frame;
+ }
+
+ if (r_click_line != nullptr) {
+ *r_click_line = p_line;
+ }
+
+ if (r_click_char != nullptr) {
+ *r_click_char = char_pos;
+ }
+ }
-#undef RETURN
-#undef NEW_LINE
-#undef ENSURE_WIDTH
-#undef ADVANCE
-#undef CHECK_HEIGHT
+ return off.y;
}
void RichTextLabel::_scroll_changed(double) {
@@ -910,7 +1257,7 @@ void RichTextLabel::_update_scroll() {
vscroll->hide();
}
- main->first_invalid_line = 0; //invalidate ALL
+ main->first_resized_line = 0; //invalidate ALL
_validate_line_caches(main);
}
}
@@ -960,10 +1307,11 @@ void RichTextLabel::_notification(int p_what) {
}
} break;
case NOTIFICATION_RESIZED: {
- main->first_invalid_line = 0; //invalidate ALL
+ main->first_resized_line = 0; //invalidate ALL
update();
} break;
+ case NOTIFICATION_THEME_CHANGED:
case NOTIFICATION_ENTER_TREE: {
if (bbcode != "") {
set_bbcode(bbcode);
@@ -971,11 +1319,11 @@ void RichTextLabel::_notification(int p_what) {
main->first_invalid_line = 0; //invalidate ALL
update();
-
} break;
- case NOTIFICATION_THEME_CHANGED: {
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ main->first_invalid_line = 0; //invalidate ALL
update();
-
} break;
case NOTIFICATION_DRAW: {
_validate_line_caches(main);
@@ -994,36 +1342,37 @@ void RichTextLabel::_notification(int p_what) {
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
}
- int ofs = vscroll->get_value();
-
- //todo, change to binary search
+ float vofs = vscroll->get_value();
+ // Search for the first line.
int from_line = 0;
- int total_chars = 0;
+
+ //TODO, change to binary search ?
while (from_line < main->lines.size()) {
- if (main->lines[from_line].height_accum_cache + _get_text_rect().get_position().y >= ofs) {
+ if (main->lines[from_line].offset.y + main->lines[from_line].text_buf->get_size().y + _get_text_rect().get_position().y >= vofs) {
break;
}
- total_chars += main->lines[from_line].char_count;
from_line++;
}
if (from_line >= main->lines.size()) {
break; //nothing to draw
}
- int y = (main->lines[from_line].height_accum_cache - main->lines[from_line].height_cache) - ofs;
Ref<Font> base_font = get_theme_font("normal_font");
Color base_color = get_theme_color("default_color");
+ Color outline_color = get_theme_color("outline_color");
+ int outline_size = get_theme_constant("outline_size");
Color font_color_shadow = get_theme_color("font_color_shadow");
bool use_outline = get_theme_constant("shadow_as_outline");
Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
visible_line_count = 0;
- while (y < size.height && from_line < main->lines.size()) {
- visible_line_count++;
- _process_line(main, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_DRAW, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, Point2i(), nullptr, nullptr, nullptr, total_chars);
- total_chars += main->lines[from_line].char_count;
+ // New cache draw.
+ 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()) {
+ visible_line_count++;
+ ofs.y += _draw_line(main, from_line, ofs, text_rect.size.x, base_color, outline_size, outline_color, font_color_shadow, use_outline, shadow_ofs);
from_line++;
}
} break;
@@ -1036,50 +1385,12 @@ void RichTextLabel::_notification(int p_what) {
}
}
-void RichTextLabel::_find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item, int *r_click_char, bool *r_outside) {
- if (r_click_item) {
- *r_click_item = nullptr;
- }
-
- Rect2 text_rect = _get_text_rect();
- int ofs = vscroll->get_value();
- Color font_color_shadow = get_theme_color("font_color_shadow");
- bool use_outline = get_theme_constant("shadow_as_outline");
- Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
-
- //todo, change to binary search
- int from_line = 0;
-
- while (from_line < p_frame->lines.size()) {
- if (p_frame->lines[from_line].height_accum_cache >= ofs) {
- break;
- }
- from_line++;
- }
-
- if (from_line >= p_frame->lines.size()) {
- return;
- }
-
- int y = (p_frame->lines[from_line].height_accum_cache - p_frame->lines[from_line].height_cache) - ofs;
- Ref<Font> base_font = get_theme_font("normal_font");
- Color base_color = get_theme_color("default_color");
-
- while (y < text_rect.get_size().height && from_line < p_frame->lines.size()) {
- _process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, from_line, PROCESS_POINTER, base_font, base_color, font_color_shadow, use_outline, shadow_ofs, p_click, r_click_item, r_click_char, r_outside);
- if (r_click_item && *r_click_item) {
- return;
- }
- from_line++;
- }
-}
-
Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const {
if (!underline_meta) {
return CURSOR_ARROW;
}
- if (selection.click) {
+ if (selection.click_item) {
return CURSOR_IBEAM;
}
@@ -1087,10 +1398,13 @@ Control::CursorShape RichTextLabel::get_cursor_shape(const Point2 &p_pos) const
return CURSOR_ARROW; //invalid
}
- int line = 0;
+ if (main->first_resized_line < main->lines.size()) {
+ return CURSOR_ARROW; //invalid
+ }
+
Item *item = nullptr;
- bool outside;
- ((RichTextLabel *)(this))->_find_click(main, p_pos, &item, &line, &outside);
+ bool outside = true;
+ ((RichTextLabel *)(this))->_find_click(main, p_pos, nullptr, nullptr, &item, nullptr, &outside);
if (item && !outside && ((RichTextLabel *)(this))->_find_meta(item, nullptr)) {
return CURSOR_POINTING_HAND;
@@ -1106,27 +1420,37 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
if (main->first_invalid_line < main->lines.size()) {
return;
}
+ if (main->first_resized_line < main->lines.size()) {
+ return;
+ }
if (b->get_button_index() == BUTTON_LEFT) {
if (b->is_pressed() && !b->is_doubleclick()) {
scroll_updated = false;
- int line = 0;
- Item *item = nullptr;
-
+ ItemFrame *c_frame = nullptr;
+ int c_line = 0;
+ Item *c_item = nullptr;
+ int c_index = 0;
bool outside;
- _find_click(main, b->get_position(), &item, &line, &outside);
- if (item) {
+ _find_click(main, b->get_position(), &c_frame, &c_line, &c_item, &c_index, &outside);
+ if (c_item != nullptr) {
if (selection.enabled) {
- selection.click = item;
- selection.click_char = line;
+ selection.click_frame = c_frame;
+ selection.click_item = c_item;
+ selection.click_line = c_line;
+ selection.click_char = c_index;
// Erase previous selection.
if (selection.active) {
- selection.from = nullptr;
- selection.from_char = '\0';
- selection.to = nullptr;
- selection.to_char = '\0';
+ selection.from_frame = nullptr;
+ selection.from_line = 0;
+ selection.from_item = nullptr;
+ selection.from_char = 0;
+ selection.to_frame = nullptr;
+ selection.to_line = 0;
+ selection.to_item = nullptr;
+ selection.to_char = 0;
selection.active = false;
update();
@@ -1135,44 +1459,49 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
} else if (b->is_pressed() && b->is_doubleclick() && selection.enabled) {
//doubleclick: select word
- int line = 0;
- Item *item = nullptr;
+
+ ItemFrame *c_frame = nullptr;
+ int c_line = 0;
+ Item *c_item = nullptr;
+ int c_index = 0;
bool outside;
- _find_click(main, b->get_position(), &item, &line, &outside);
+ _find_click(main, b->get_position(), &c_frame, &c_line, &c_item, &c_index, &outside);
- while (item && item->type != ITEM_TEXT) {
- item = _get_next_item(item, true);
- }
+ if (c_frame) {
+ const Line &l = c_frame->lines[c_line];
+ Vector<Vector2i> words = TS->shaped_text_get_word_breaks(l.text_buf->get_rid());
+ for (int i = 0; i < words.size(); i++) {
+ if (c_index >= words[i].x && c_index < words[i].y) {
+ selection.from_frame = c_frame;
+ selection.from_line = c_line;
+ selection.from_item = c_item;
+ selection.from_char = words[i].x;
+
+ selection.to_frame = c_frame;
+ selection.to_line = c_line;
+ selection.to_item = c_item;
+ selection.to_char = words[i].y;
- if (item && item->type == ITEM_TEXT) {
- String itext = static_cast<ItemText *>(item)->text;
-
- int beg, end;
- if (select_word(itext, line, beg, end)) {
- selection.from = item;
- selection.to = item;
- selection.from_char = beg;
- selection.to_char = end - 1;
- selection.active = true;
- update();
+ selection.active = true;
+ update();
+ break;
+ }
}
}
} else if (!b->is_pressed()) {
- selection.click = nullptr;
+ selection.click_item = nullptr;
if (!b->is_doubleclick() && !scroll_updated) {
- int line = 0;
- Item *item = nullptr;
+ Item *c_item = nullptr;
- bool outside;
- _find_click(main, b->get_position(), &item, &line, &outside);
+ bool outside = true;
+ _find_click(main, b->get_position(), nullptr, nullptr, &c_item, nullptr, &outside);
- if (item) {
+ if (c_item) {
Variant meta;
- if (!outside && _find_meta(item, &meta)) {
+ if (!outside && _find_meta(c_item, &meta)) {
//meta clicked
-
emit_signal("meta_clicked", meta);
}
}
@@ -1221,13 +1550,13 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
} break;
case KEY_UP: {
if (vscroll->is_visible_in_tree()) {
- vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height());
+ vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size")));
handled = true;
}
} break;
case KEY_DOWN: {
if (vscroll->is_visible_in_tree()) {
- vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height());
+ vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size")));
handled = true;
}
} break;
@@ -1265,27 +1594,32 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
if (main->first_invalid_line < main->lines.size()) {
return;
}
+ if (main->first_resized_line < main->lines.size()) {
+ return;
+ }
- int line = 0;
- Item *item = nullptr;
+ ItemFrame *c_frame = nullptr;
+ int c_line = 0;
+ Item *c_item = nullptr;
+ int c_index = 0;
bool outside;
- _find_click(main, m->get_position(), &item, &line, &outside);
- if (selection.click) {
- if (!item) {
- return; // do not update
- }
-
- selection.from = selection.click;
+ _find_click(main, m->get_position(), &c_frame, &c_line, &c_item, &c_index, &outside);
+ if (selection.click_item && c_item) {
+ selection.from_frame = selection.click_frame;
+ selection.from_line = selection.click_line;
+ selection.from_item = selection.click_item;
selection.from_char = selection.click_char;
- selection.to = item;
- selection.to_char = line;
+ selection.to_frame = c_frame;
+ selection.to_line = c_line;
+ selection.to_item = c_item;
+ selection.to_char = c_index;
bool swap = false;
- if (selection.from->index > selection.to->index) {
+ if (selection.from_item->index > selection.to_item->index) {
swap = true;
- } else if (selection.from->index == selection.to->index) {
+ } else if (selection.from_item->index == selection.to_item->index) {
if (selection.from_char > selection.to_char) {
swap = true;
} else if (selection.from_char == selection.to_char) {
@@ -1295,7 +1629,9 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
if (swap) {
- SWAP(selection.from, selection.to);
+ SWAP(selection.from_frame, selection.to_frame);
+ SWAP(selection.from_line, selection.to_line);
+ SWAP(selection.from_item, selection.to_item);
SWAP(selection.from_char, selection.to_char);
}
@@ -1305,7 +1641,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
Variant meta;
ItemMeta *item_meta;
- if (item && !outside && _find_meta(item, &meta, &item_meta)) {
+ if (c_item && !outside && _find_meta(c_item, &meta, &item_meta)) {
if (meta_hovering != item_meta) {
if (meta_hovering) {
emit_signal("meta_hover_ended", current_meta);
@@ -1322,6 +1658,31 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) {
}
}
+void RichTextLabel::_find_frame(Item *p_item, ItemFrame **r_frame, int *r_line) {
+ if (r_frame != nullptr) {
+ *r_frame = nullptr;
+ }
+ if (r_line != nullptr) {
+ *r_line = 0;
+ }
+
+ Item *item = p_item;
+
+ while (item) {
+ if (item->parent != nullptr && item->parent->type == ITEM_FRAME) {
+ if (r_frame != nullptr) {
+ *r_frame = (ItemFrame *)item->parent;
+ }
+ if (r_line != nullptr) {
+ *r_line = item->line;
+ }
+ return;
+ }
+
+ item = item->parent;
+ }
+}
+
Ref<Font> RichTextLabel::_find_font(Item *p_item) {
Item *fontitem = p_item;
@@ -1337,10 +1698,103 @@ Ref<Font> RichTextLabel::_find_font(Item *p_item) {
return Ref<Font>();
}
-int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
+int RichTextLabel::_find_font_size(Item *p_item) {
+ Item *sizeitem = p_item;
+
+ while (sizeitem) {
+ if (sizeitem->type == ITEM_FONT_SIZE) {
+ ItemFontSize *fi = static_cast<ItemFontSize *>(sizeitem);
+ return fi->font_size;
+ }
+
+ sizeitem = sizeitem->parent;
+ }
+
+ return -1;
+}
+
+int RichTextLabel::_find_outline_size(Item *p_item) {
+ Item *sizeitem = p_item;
+
+ while (sizeitem) {
+ if (sizeitem->type == ITEM_OUTLINE_SIZE) {
+ ItemOutlineSize *fi = static_cast<ItemOutlineSize *>(sizeitem);
+ return fi->outline_size;
+ }
+
+ sizeitem = sizeitem->parent;
+ }
+
+ return 0;
+}
+
+Dictionary RichTextLabel::_find_font_features(Item *p_item) {
+ Item *ffitem = p_item;
+
+ while (ffitem) {
+ if (ffitem->type == ITEM_FONT_FEATURES) {
+ ItemFontFeatures *fi = static_cast<ItemFontFeatures *>(ffitem);
+ return fi->opentype_features;
+ }
+
+ ffitem = ffitem->parent;
+ }
+
+ return Dictionary();
+}
+
+RichTextLabel::ItemList *RichTextLabel::_find_list_item(Item *p_item) {
Item *item = p_item;
- int margin = 0;
+ while (item) {
+ if (item->type == ITEM_LIST) {
+ return static_cast<ItemList *>(item);
+ }
+ item = item->parent;
+ }
+
+ return nullptr;
+}
+
+int RichTextLabel::_find_list(Item *p_item, Vector<int> &r_index, Vector<ItemList *> &r_list) {
+ Item *item = p_item;
+ Item *prev_item = p_item;
+
+ int level = 0;
+
+ while (item) {
+ if (item->type == ITEM_LIST) {
+ ItemList *list = static_cast<ItemList *>(item);
+
+ ItemFrame *frame = nullptr;
+ int line = -1;
+ _find_frame(list, &frame, &line);
+
+ int index = 1;
+ if (frame != nullptr) {
+ for (int i = list->line + 1; i <= prev_item->line; i++) {
+ if (_find_list_item(frame->lines[i].from) == list) {
+ index++;
+ }
+ }
+ }
+
+ r_index.push_back(index);
+ r_list.push_back(list);
+
+ prev_item = item;
+ }
+ level++;
+ item = item->parent;
+ }
+
+ return level;
+}
+
+int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font, int p_base_font_size) {
+ Item *item = p_item;
+
+ float margin = 0;
while (item) {
if (item->type == ITEM_INDENT) {
@@ -1348,16 +1802,22 @@ int RichTextLabel::_find_margin(Item *p_item, const Ref<Font> &p_base_font) {
if (font.is_null()) {
font = p_base_font;
}
-
- ItemIndent *indent = static_cast<ItemIndent *>(item);
-
- margin += indent->level * tab_size * font->get_char_size(' ').width;
+ int font_size = _find_font_size(item);
+ if (font_size == -1) {
+ font_size = p_base_font_size;
+ }
+ margin += tab_size * font->get_char_size('m', 0, font_size).width;
} else if (item->type == ITEM_LIST) {
Ref<Font> font = _find_font(item);
if (font.is_null()) {
font = p_base_font;
}
+ int font_size = _find_font_size(item);
+ if (font_size == -1) {
+ font_size = p_base_font_size;
+ }
+ margin += tab_size * font->get_char_size('m', 0, font_size).width;
}
item = item->parent;
@@ -1370,9 +1830,9 @@ RichTextLabel::Align RichTextLabel::_find_align(Item *p_item) {
Item *item = p_item;
while (item) {
- if (item->type == ITEM_ALIGN) {
- ItemAlign *align = static_cast<ItemAlign *>(item);
- return align->align;
+ if (item->type == ITEM_PARAGRAPH) {
+ ItemParagraph *p = static_cast<ItemParagraph *>(item);
+ return p->align;
}
item = item->parent;
@@ -1381,6 +1841,57 @@ RichTextLabel::Align RichTextLabel::_find_align(Item *p_item) {
return default_align;
}
+TextServer::Direction RichTextLabel::_find_direction(Item *p_item) {
+ Item *item = p_item;
+
+ while (item) {
+ if (item->type == ITEM_PARAGRAPH) {
+ ItemParagraph *p = static_cast<ItemParagraph *>(item);
+ if (p->direction != Control::TEXT_DIRECTION_INHERITED) {
+ return (TextServer::Direction)p->direction;
+ }
+ }
+
+ item = item->parent;
+ }
+
+ if (text_direction == Control::TEXT_DIRECTION_INHERITED) {
+ return is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR;
+ } else {
+ return (TextServer::Direction)text_direction;
+ }
+}
+
+Control::StructuredTextParser RichTextLabel::_find_stt(Item *p_item) {
+ Item *item = p_item;
+
+ while (item) {
+ if (item->type == ITEM_PARAGRAPH) {
+ ItemParagraph *p = static_cast<ItemParagraph *>(item);
+ return p->st_parser;
+ }
+
+ item = item->parent;
+ }
+
+ return st_parser;
+}
+
+String RichTextLabel::_find_language(Item *p_item) {
+ Item *item = p_item;
+
+ while (item) {
+ if (item->type == ITEM_PARAGRAPH) {
+ ItemParagraph *p = static_cast<ItemParagraph *>(item);
+ return p->language;
+ }
+
+ item = item->parent;
+ }
+
+ return language;
+}
+
Color RichTextLabel::_find_color(Item *p_item, const Color &p_default_color) {
Item *item = p_item;
@@ -1396,25 +1907,26 @@ Color RichTextLabel::_find_color(Item *p_item, const Color &p_default_color) {
return p_default_color;
}
-bool RichTextLabel::_find_underline(Item *p_item) {
+Color RichTextLabel::_find_outline_color(Item *p_item, const Color &p_default_color) {
Item *item = p_item;
while (item) {
- if (item->type == ITEM_UNDERLINE) {
- return true;
+ if (item->type == ITEM_OUTLINE_COLOR) {
+ ItemOutlineColor *color = static_cast<ItemOutlineColor *>(item);
+ return color->color;
}
item = item->parent;
}
- return false;
+ return p_default_color;
}
-bool RichTextLabel::_find_strikethrough(Item *p_item) {
+bool RichTextLabel::_find_underline(Item *p_item) {
Item *item = p_item;
while (item) {
- if (item->type == ITEM_STRIKETHROUGH) {
+ if (item->type == ITEM_UNDERLINE) {
return true;
}
@@ -1424,17 +1936,17 @@ bool RichTextLabel::_find_strikethrough(Item *p_item) {
return false;
}
-bool RichTextLabel::_find_by_type(Item *p_item, ItemType p_type) {
- ERR_FAIL_INDEX_V((int)p_type, 19, false);
-
+bool RichTextLabel::_find_strikethrough(Item *p_item) {
Item *item = p_item;
while (item) {
- if (item->type == p_type) {
+ if (item->type == ITEM_STRIKETHROUGH) {
return true;
}
+
item = item->parent;
}
+
return false;
}
@@ -1530,38 +2042,67 @@ bool RichTextLabel::_find_layout_subitem(Item *from, Item *to) {
void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
if (p_frame->first_invalid_line == p_frame->lines.size()) {
+ if (p_frame->first_resized_line == p_frame->lines.size()) {
+ return;
+ }
+
+ // Resize lines without reshaping.
+ Size2 size = get_size();
+ if (fixed_width != -1) {
+ size.width = fixed_width;
+ }
+ Rect2 text_rect = _get_text_rect();
+
+ Ref<Font> base_font = get_theme_font("normal_font");
+ int base_font_size = get_theme_font_size("normal_font_size");
+
+ 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);
+ }
+
+ 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 + get_theme_stylebox("normal")->get_minimum_size().height;
+ }
+
+ p_frame->first_resized_line = p_frame->lines.size();
+
+ updating_scroll = true;
+ vscroll->set_max(total_height);
+ vscroll->set_page(size.height);
+ if (scroll_follow && scroll_following) {
+ vscroll->set_value(total_height - size.height);
+ }
+ updating_scroll = false;
+
+ if (fit_content_height) {
+ minimum_size_changed();
+ }
return;
}
- //validate invalid lines
+ // Shape invalid lines.
Size2 size = get_size();
if (fixed_width != -1) {
size.width = fixed_width;
}
Rect2 text_rect = _get_text_rect();
- Color font_color_shadow = get_theme_color("font_color_shadow");
- bool use_outline = get_theme_constant("shadow_as_outline");
- Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y"));
Ref<Font> base_font = get_theme_font("normal_font");
+ int base_font_size = get_theme_font_size("normal_font_size");
+ 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++) {
- int y = 0;
- _process_line(p_frame, text_rect.get_position(), y, text_rect.get_size().width - scroll_w, i, PROCESS_CACHE, base_font, Color(), font_color_shadow, use_outline, shadow_ofs);
- p_frame->lines.write[i].height_cache = y;
- p_frame->lines.write[i].height_accum_cache = y;
-
- if (i > 0) {
- p_frame->lines.write[i].height_accum_cache += p_frame->lines[i - 1].height_accum_cache;
- }
+ _shape_line(p_frame, i, base_font, base_font_size, text_rect.get_size().width - scroll_w, &total_chars);
}
int total_height = 0;
if (p_frame->lines.size()) {
- total_height = p_frame->lines[p_frame->lines.size() - 1].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height;
+ 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 + get_theme_stylebox("normal")->get_minimum_size().height;
}
- main->first_invalid_line = p_frame->lines.size();
+ p_frame->first_invalid_line = p_frame->lines.size();
+ p_frame->first_resized_line = p_frame->lines.size();
updating_scroll = true;
vscroll->set_max(total_height);
@@ -1569,7 +2110,6 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) {
if (scroll_follow && scroll_following) {
vscroll->set_value(total_height - size.height);
}
-
updating_scroll = false;
if (fit_content_height) {
@@ -1641,6 +2181,13 @@ void RichTextLabel::_add_item(Item *p_item, bool p_enter, bool p_ensure_newline)
p_item->parent = current;
p_item->E = current->subitems.push_back(p_item);
p_item->index = current_idx++;
+ p_item->char_ofs = current_char_ofs;
+ if (p_item->type == ITEM_TEXT) {
+ ItemText *t = (ItemText *)p_item;
+ current_char_ofs += t->text.length();
+ } else if (p_item->type == ITEM_IMAGE) {
+ current_char_ofs++;
+ }
if (p_enter) {
current = p_item;
@@ -1686,7 +2233,7 @@ 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) {
+void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width, const int p_height, const Color &p_color, VAlign p_align) {
if (current->type == ITEM_TABLE) {
return;
}
@@ -1696,6 +2243,7 @@ void RichTextLabel::add_image(const Ref<Texture2D> &p_image, const int p_width,
item->image = p_image;
item->color = p_color;
+ item->inline_align = p_align;
if (p_width > 0) {
// custom width
@@ -1764,7 +2312,7 @@ bool RichTextLabel::remove_line(const int p_line) {
main->lines.write[0].from = main;
}
- main->first_invalid_line = 0;
+ main->first_invalid_line = 0; // p_line ???
return true;
}
@@ -1813,6 +2361,30 @@ void RichTextLabel::push_mono() {
push_font(mono_font);
}
+void RichTextLabel::push_font_size(int p_font_size) {
+ ERR_FAIL_COND(current->type == ITEM_TABLE);
+ ItemFontSize *item = memnew(ItemFontSize);
+
+ item->font_size = p_font_size;
+ _add_item(item, true);
+}
+
+void RichTextLabel::push_font_features(const Dictionary &p_features) {
+ ERR_FAIL_COND(current->type == ITEM_TABLE);
+ ItemFontFeatures *item = memnew(ItemFontFeatures);
+
+ item->opentype_features = p_features;
+ _add_item(item, true);
+}
+
+void RichTextLabel::push_outline_size(int p_font_size) {
+ ERR_FAIL_COND(current->type == ITEM_TABLE);
+ ItemOutlineSize *item = memnew(ItemOutlineSize);
+
+ item->outline_size = p_font_size;
+ _add_item(item, true);
+}
+
void RichTextLabel::push_color(const Color &p_color) {
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemColor *item = memnew(ItemColor);
@@ -1821,6 +2393,14 @@ void RichTextLabel::push_color(const Color &p_color) {
_add_item(item, true);
}
+void RichTextLabel::push_outline_color(const Color &p_color) {
+ ERR_FAIL_COND(current->type == ITEM_TABLE);
+ ItemOutlineColor *item = memnew(ItemOutlineColor);
+
+ item->color = p_color;
+ _add_item(item, true);
+}
+
void RichTextLabel::push_underline() {
ERR_FAIL_COND(current->type == ITEM_TABLE);
ItemUnderline *item = memnew(ItemUnderline);
@@ -1835,11 +2415,14 @@ void RichTextLabel::push_strikethrough() {
_add_item(item, true);
}
-void RichTextLabel::push_align(Align p_align) {
+void RichTextLabel::push_paragraph(Align p_align, Control::TextDirection p_direction, const String &p_language, Control::StructuredTextParser p_st_parser) {
ERR_FAIL_COND(current->type == ITEM_TABLE);
- ItemAlign *item = memnew(ItemAlign);
+ ItemParagraph *item = memnew(ItemParagraph);
item->align = p_align;
+ item->direction = p_direction;
+ item->language = p_language;
+ item->st_parser = p_st_parser;
_add_item(item, true, true);
}
@@ -1852,13 +2435,15 @@ void RichTextLabel::push_indent(int p_level) {
_add_item(item, true, true);
}
-void RichTextLabel::push_list(ListType p_list) {
+void RichTextLabel::push_list(int p_level, ListType p_list, bool p_capitalize) {
ERR_FAIL_COND(current->type == ITEM_TABLE);
- ERR_FAIL_INDEX(p_list, 3);
+ ERR_FAIL_COND(p_level < 0);
ItemList *item = memnew(ItemList);
item->list_type = p_list;
+ item->level = p_level;
+ item->capitalize = p_capitalize;
_add_item(item, true, true);
}
@@ -1870,17 +2455,18 @@ void RichTextLabel::push_meta(const Variant &p_meta) {
_add_item(item, true);
}
-void RichTextLabel::push_table(int p_columns) {
+void RichTextLabel::push_table(int p_columns, VAlign p_align) {
ERR_FAIL_COND(p_columns < 1);
ItemTable *item = memnew(ItemTable);
item->columns.resize(p_columns);
item->total_width = 0;
+ item->inline_align = p_align;
for (int i = 0; i < item->columns.size(); i++) {
item->columns.write[i].expand = false;
item->columns.write[i].expand_ratio = 1;
}
- _add_item(item, true, true);
+ _add_item(item, true, false);
}
void RichTextLabel::push_fade(int p_start_index, int p_length) {
@@ -1934,6 +2520,36 @@ void RichTextLabel::set_table_column_expand(int p_column, bool p_expand, int p_r
table->columns.write[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) {
+ 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;
+ cell->even_row_bg = p_even_row_bg;
+}
+
+void RichTextLabel::set_cell_border_color(const Color &p_color) {
+ 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) {
+ 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;
+ cell->max_size_over = p_max_size;
+}
+
+void RichTextLabel::set_cell_padding(const Rect2 &p_padding) {
+ 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() {
ERR_FAIL_COND(current->type != ITEM_TABLE);
@@ -1942,10 +2558,9 @@ void RichTextLabel::push_cell() {
_add_item(item, true);
current_frame = item;
item->cell = true;
- item->parent_line = item->parent_frame->lines.size() - 1;
item->lines.resize(1);
item->lines.write[0].from = nullptr;
- item->first_invalid_line = 0;
+ item->first_invalid_line = 0; // parent frame last line ???
}
int RichTextLabel::get_current_table_column() const {
@@ -1972,9 +2587,13 @@ void RichTextLabel::clear() {
main->lines.resize(1);
main->first_invalid_line = 0;
update();
- selection.click = nullptr;
+
+ selection.click_frame = nullptr;
+ selection.click_item = nullptr;
selection.active = false;
+
current_idx = 1;
+ current_char_ofs = 0;
if (scroll_follow) {
scroll_following = true;
}
@@ -1986,7 +2605,7 @@ void RichTextLabel::clear() {
void RichTextLabel::set_tab_size(int p_spaces) {
tab_size = p_spaces;
- main->first_invalid_line = 0;
+ main->first_resized_line = 0;
update();
}
@@ -2135,7 +2754,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
if (tag_stack.front()->get() == "i") {
in_italics = false;
}
- if (tag_stack.front()->get() == "indent") {
+ if ((tag_stack.front()->get() == "indent") || (tag_stack.front()->get() == "ol") || (tag_stack.front()->get() == "ul")) {
indent_level--;
}
@@ -2177,12 +2796,24 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag.begins_with("table=")) {
- int columns = tag.substr(6, tag.length()).to_int();
+ Vector<String> subtag = tag.substr(6, tag.length()).split(",");
+ int columns = subtag[0].to_int();
if (columns < 1) {
columns = 1;
}
- push_table(columns);
+ VAlign align = VALIGN_TOP;
+ if (subtag.size() > 1) {
+ if (subtag[1] == "top" || subtag[1] == "t") {
+ align = VALIGN_TOP;
+ } else if (subtag[1] == "center" || subtag[1] == "c") {
+ align = VALIGN_CENTER;
+ } else if (subtag[1] == "bottom" || subtag[1] == "b") {
+ align = VALIGN_BOTTOM;
+ }
+ }
+
+ push_table(columns, align);
pos = brk_end + 1;
tag_stack.push_front("table");
} else if (tag == "cell") {
@@ -2197,6 +2828,42 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
set_table_column_expand(get_current_table_column(), true, ratio);
push_cell();
+
+ pos = brk_end + 1;
+ tag_stack.push_front("cell");
+ } else if (tag.begins_with("cell ")) {
+ Vector<String> subtag = tag.substr(5, tag.length()).split(" ");
+
+ for (int i = 0; i < subtag.size(); i++) {
+ Vector<String> subtag_a = subtag[i].split("=");
+ if (subtag_a.size() == 2) {
+ if (subtag_a[0] == "expand") {
+ int ratio = subtag_a[1].to_int();
+ if (ratio < 1) {
+ ratio = 1;
+ }
+ set_table_column_expand(get_current_table_column(), true, ratio);
+ }
+ }
+ }
+ push_cell();
+ for (int i = 0; i < subtag.size(); i++) {
+ Vector<String> subtag_a = subtag[i].split("=");
+ if (subtag_a.size() == 2) {
+ if (subtag_a[0] == "border") {
+ Color color = _get_color_from_string(subtag_a[1], Color(0, 0, 0, 0));
+ set_cell_border_color(color);
+ } else if (subtag_a[0] == "bg") {
+ Vector<String> subtag_b = subtag_a[1].split(",");
+ if (subtag_b.size() == 2) {
+ Color color1 = _get_color_from_string(subtag_b[0], Color(0, 0, 0, 0));
+ Color color2 = _get_color_from_string(subtag_b[1], Color(0, 0, 0, 0));
+ set_cell_row_background_color(color1, color2);
+ }
+ }
+ }
+ }
+
pos = brk_end + 1;
tag_stack.push_front("cell");
} else if (tag == "u") {
@@ -2209,32 +2876,156 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
push_strikethrough();
pos = brk_end + 1;
tag_stack.push_front(tag);
+ } else if (tag == "lrm") {
+ add_text(String::chr(0x200E));
+ pos = brk_end + 1;
+ } else if (tag == "rlm") {
+ add_text(String::chr(0x200F));
+ pos = brk_end + 1;
+ } else if (tag == "lre") {
+ add_text(String::chr(0x202A));
+ pos = brk_end + 1;
+ } else if (tag == "rle") {
+ add_text(String::chr(0x202B));
+ pos = brk_end + 1;
+ } else if (tag == "lro") {
+ add_text(String::chr(0x202D));
+ pos = brk_end + 1;
+ } else if (tag == "rlo") {
+ add_text(String::chr(0x202E));
+ pos = brk_end + 1;
+ } else if (tag == "pdf") {
+ add_text(String::chr(0x202C));
+ pos = brk_end + 1;
+ } else if (tag == "alm") {
+ add_text(String::chr(0x061c));
+ pos = brk_end + 1;
+ } else if (tag == "lri") {
+ add_text(String::chr(0x2066));
+ pos = brk_end + 1;
+ } else if (tag == "rli") {
+ add_text(String::chr(0x2027));
+ pos = brk_end + 1;
+ } else if (tag == "fsi") {
+ add_text(String::chr(0x2068));
+ pos = brk_end + 1;
+ } else if (tag == "pdi") {
+ add_text(String::chr(0x2069));
+ pos = brk_end + 1;
+ } else if (tag == "zwj") {
+ add_text(String::chr(0x200D));
+ pos = brk_end + 1;
+ } else if (tag == "zwnj") {
+ add_text(String::chr(0x200C));
+ pos = brk_end + 1;
+ } else if (tag == "wj") {
+ add_text(String::chr(0x2060));
+ pos = brk_end + 1;
+ } else if (tag == "shy") {
+ add_text(String::chr(0x00AD));
+ pos = brk_end + 1;
} else if (tag == "center") {
- push_align(ALIGN_CENTER);
+ push_paragraph(ALIGN_CENTER);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "fill") {
- push_align(ALIGN_FILL);
+ push_paragraph(ALIGN_FILL);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "right") {
- push_align(ALIGN_RIGHT);
+ push_paragraph(ALIGN_RIGHT);
pos = brk_end + 1;
tag_stack.push_front(tag);
} else if (tag == "ul") {
- push_list(LIST_DOTS);
+ indent_level++;
+ push_list(indent_level, LIST_DOTS, false);
pos = brk_end + 1;
tag_stack.push_front(tag);
- } else if (tag == "ol") {
- push_list(LIST_NUMBERS);
+ } else if ((tag == "ol") || (tag == "ol type=1")) {
+ indent_level++;
+ push_list(indent_level, LIST_NUMBERS, false);
pos = brk_end + 1;
tag_stack.push_front(tag);
+ } else if (tag == "ol type=a") {
+ indent_level++;
+ push_list(indent_level, LIST_LETTERS, false);
+ pos = brk_end + 1;
+ tag_stack.push_front("ol");
+ } else if (tag == "ol type=A") {
+ indent_level++;
+ push_list(indent_level, LIST_LETTERS, true);
+ pos = brk_end + 1;
+ tag_stack.push_front("ol");
+ } else if (tag == "ol type=i") {
+ indent_level++;
+ push_list(indent_level, LIST_ROMAN, false);
+ pos = brk_end + 1;
+ tag_stack.push_front("ol");
+ } else if (tag == "ol type=I") {
+ indent_level++;
+ push_list(indent_level, LIST_ROMAN, true);
+ pos = brk_end + 1;
+ tag_stack.push_front("ol");
} else if (tag == "indent") {
indent_level++;
push_indent(indent_level);
pos = brk_end + 1;
tag_stack.push_front(tag);
-
+ } else if (tag == "p") {
+ push_paragraph(ALIGN_LEFT);
+ pos = brk_end + 1;
+ tag_stack.push_front("p");
+ } else if (tag.begins_with("p ")) {
+ Vector<String> subtag = tag.substr(2, tag.length()).split(" ");
+ Align align = ALIGN_LEFT;
+ Control::TextDirection dir = Control::TEXT_DIRECTION_INHERITED;
+ String lang;
+ Control::StructuredTextParser st_parser = STRUCTURED_TEXT_DEFAULT;
+ for (int i = 0; i < subtag.size(); i++) {
+ Vector<String> subtag_a = subtag[i].split("=");
+ if (subtag_a.size() == 2) {
+ if (subtag_a[0] == "align") {
+ if (subtag_a[1] == "l" || subtag_a[1] == "left") {
+ align = ALIGN_LEFT;
+ } else if (subtag_a[1] == "c" || subtag_a[1] == "center") {
+ align = ALIGN_CENTER;
+ } else if (subtag_a[1] == "r" || subtag_a[1] == "right") {
+ align = ALIGN_RIGHT;
+ } else if (subtag_a[1] == "f" || subtag_a[1] == "fill") {
+ align = ALIGN_FILL;
+ }
+ } else if (subtag_a[0] == "dir" || subtag_a[0] == "direction") {
+ if (subtag_a[1] == "a" || subtag_a[1] == "auto") {
+ dir = Control::TEXT_DIRECTION_AUTO;
+ } else if (subtag_a[1] == "l" || subtag_a[1] == "ltr") {
+ dir = Control::TEXT_DIRECTION_LTR;
+ } else if (subtag_a[1] == "r" || subtag_a[1] == "rtl") {
+ dir = Control::TEXT_DIRECTION_RTL;
+ }
+ } else if (subtag_a[0] == "lang" || subtag_a[0] == "language") {
+ lang = subtag_a[1];
+ } else if (subtag_a[0] == "st" || subtag_a[0] == "bidi_override") {
+ if (subtag_a[1] == "d" || subtag_a[1] == "default") {
+ st_parser = STRUCTURED_TEXT_DEFAULT;
+ } else if (subtag_a[1] == "u" || subtag_a[1] == "uri") {
+ st_parser = STRUCTURED_TEXT_URI;
+ } else if (subtag_a[1] == "f" || subtag_a[1] == "file") {
+ st_parser = STRUCTURED_TEXT_FILE;
+ } else if (subtag_a[1] == "e" || subtag_a[1] == "email") {
+ st_parser = STRUCTURED_TEXT_EMAIL;
+ } else if (subtag_a[1] == "l" || subtag_a[1] == "list") {
+ st_parser = STRUCTURED_TEXT_LIST;
+ } else if (subtag_a[1] == "n" || subtag_a[1] == "none") {
+ st_parser = STRUCTURED_TEXT_NONE;
+ } else if (subtag_a[1] == "c" || subtag_a[1] == "custom") {
+ st_parser = STRUCTURED_TEXT_CUSTOM;
+ }
+ }
+ }
+ }
+ push_paragraph(align, dir, lang, st_parser);
+ pos = brk_end + 1;
+ tag_stack.push_front("p");
} else if (tag == "url") {
int end = p_bbcode.find("[", brk_end);
if (end == -1) {
@@ -2251,7 +3042,19 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
push_meta(url);
pos = brk_end + 1;
tag_stack.push_front("url");
- } else if (bbcode_name == "img") {
+ } else if (tag.begins_with("img")) {
+ VAlign align = VALIGN_TOP;
+ if (tag.begins_with("img=")) {
+ String al = tag.substr(4, tag.length());
+ if (al == "top" || al == "t") {
+ align = VALIGN_TOP;
+ } else if (al == "center" || al == "c") {
+ align = VALIGN_CENTER;
+ } else if (al == "bottom" || al == "b") {
+ align = VALIGN_BOTTOM;
+ }
+ }
+
int end = p_bbcode.find("[", brk_end);
if (end == -1) {
end = p_bbcode.length();
@@ -2289,7 +3092,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
}
}
- add_image(texture, width, height, color);
+ add_image(texture, width, height, color, align);
}
pos = end;
@@ -2301,6 +3104,13 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
pos = brk_end + 1;
tag_stack.push_front("color");
+ } else if (tag.begins_with("outline_color=")) {
+ String color_str = tag.substr(14, tag.length());
+ Color color = _get_color_from_string(color_str, base_color);
+ push_outline_color(color);
+ pos = brk_end + 1;
+ tag_stack.push_front("outline_color");
+
} else if (tag.begins_with("font=")) {
String fnt = tag.substr(5, tag.length());
@@ -2313,6 +3123,54 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
pos = brk_end + 1;
tag_stack.push_front("font");
+ } else if (tag.begins_with("font_size=")) {
+ int fnt_size = tag.substr(10, tag.length()).to_int();
+ push_font_size(fnt_size);
+ pos = brk_end + 1;
+ tag_stack.push_front("font_size");
+ } else if (tag.begins_with("opentype_features=")) {
+ String fnt_ftr = tag.substr(18, tag.length());
+ Vector<String> subtag = fnt_ftr.split(",");
+ Dictionary ftrs;
+ for (int i = 0; i < subtag.size(); i++) {
+ Vector<String> subtag_a = subtag[i].split("=");
+ if (subtag_a.size() == 2) {
+ ftrs[TS->name_to_tag(subtag_a[0])] = subtag_a[1].to_int();
+ } else if (subtag_a.size() == 1) {
+ ftrs[TS->name_to_tag(subtag_a[0])] = 1;
+ }
+ }
+ push_font_features(ftrs);
+ pos = brk_end + 1;
+ tag_stack.push_front("opentype_features");
+ } else if (tag.begins_with("font ")) {
+ Vector<String> subtag = tag.substr(2, tag.length()).split(" ");
+
+ for (int i = 1; i < subtag.size(); i++) {
+ Vector<String> subtag_a = subtag[i].split("=", true, 2);
+ if (subtag_a.size() == 2) {
+ if (subtag_a[0] == "name" || subtag_a[0] == "n") {
+ String fnt = subtag_a[1];
+ Ref<Font> font = ResourceLoader::load(fnt, "Font");
+ if (font.is_valid()) {
+ push_font(font);
+ } else {
+ push_font(normal_font);
+ }
+ } else if (subtag_a[0] == "size" || subtag_a[0] == "s") {
+ int fnt_size = subtag_a[1].to_int();
+ push_font_size(fnt_size);
+ }
+ }
+ }
+
+ pos = brk_end + 1;
+ tag_stack.push_front("font");
+ } else if (tag.begins_with("outline_size=")) {
+ int fnt_size = tag.substr(13, tag.length()).to_int();
+ push_outline_size(fnt_size);
+ pos = brk_end + 1;
+ tag_stack.push_front("outline_size");
} else if (bbcode_name == "fade") {
int start_index = 0;
@@ -2445,7 +3303,7 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) {
void RichTextLabel::scroll_to_line(int p_line) {
ERR_FAIL_INDEX(p_line, main->lines.size());
_validate_line_caches(main);
- vscroll->set_value(main->lines[p_line].height_accum_cache - main->lines[p_line].height_cache);
+ vscroll->set_value(main->lines[p_line].offset.y);
}
int RichTextLabel::get_line_count() const {
@@ -2472,95 +3330,160 @@ void RichTextLabel::set_selection_enabled(bool p_enabled) {
}
}
-bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p_search_previous) {
- ERR_FAIL_COND_V(!selection.enabled, false);
- Item *it = main;
- int charidx = 0;
-
- if (p_from_selection && selection.active) {
- it = selection.to;
- charidx = selection.to_char + 1;
- }
-
- while (it) {
- if (it->type == ITEM_TEXT) {
- ItemText *t = static_cast<ItemText *>(it);
- int sp = t->text.findn(p_string, charidx);
- if (sp != -1) {
- selection.from = it;
- selection.from_char = sp;
- selection.to = it;
- selection.to_char = sp + p_string.length() - 1;
- selection.active = true;
- update();
-
- _validate_line_caches(main);
+bool RichTextLabel::_search_line(ItemFrame *p_frame, int p_line, const String &p_string, Item *p_from, Item *p_to) {
+ ERR_FAIL_COND_V(p_frame == nullptr, false);
+ ERR_FAIL_COND_V(p_line < 0 || p_line >= p_frame->lines.size(), false);
- int fh = _find_font(t).is_valid() ? _find_font(t)->get_height() : get_theme_font("normal_font")->get_height();
+ Line &l = p_frame->lines.write[p_line];
- float offset = 0;
+ String text;
+ Item *it_to = (p_line + 1 < 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: {
+ text += "\n";
+ } break;
+ case ITEM_TEXT: {
+ ItemText *t = (ItemText *)it;
+ text += t->text;
+ } break;
+ case ITEM_IMAGE: {
+ text += " ";
+ } break;
+ case ITEM_TABLE: {
+ ItemTable *table = static_cast<ItemTable *>(it);
+ int idx = 0;
+ for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E->get());
- int line = t->line;
- Item *item = t;
- while (item) {
- if (item->type == ITEM_FRAME) {
- ItemFrame *frame = static_cast<ItemFrame *>(item);
- if (line >= 0 && line < frame->lines.size()) {
- offset += frame->lines[line].height_accum_cache - frame->lines[line].height_cache;
- line = frame->line;
+ for (int i = 0; i < frame->lines.size(); i++) {
+ if (_search_line(frame, i, p_string, p_from, p_to)) {
+ return true;
}
}
- item = item->parent;
+ idx++;
}
- vscroll->set_value(offset - fh);
+ } break;
+ default:
+ break;
+ }
+ }
+ int sp = text.findn(p_string, 0);
+ if (sp != -1) {
+ selection.from_frame = p_frame;
+ selection.from_line = p_line;
+ selection.from_item = _get_item_at_pos(l.from, it_to, sp);
+ selection.from_char = sp;
+ selection.to_frame = p_frame;
+ selection.to_line = p_line;
+ selection.to_item = _get_item_at_pos(l.from, it_to, sp + p_string.length() - 1);
+ selection.to_char = sp + p_string.length() - 1;
+ selection.active = true;
+ return true;
+ }
+
+ return false;
+}
+bool RichTextLabel::search(const String &p_string, bool p_from_selection, bool p_search_previous) {
+ ERR_FAIL_COND_V(!selection.enabled, false);
+
+ if (p_from_selection && selection.active) {
+ for (int i = 0; i < main->lines.size(); i++) {
+ if (_search_line(main, i, p_string, selection.from_item, selection.to_item)) {
+ update();
return true;
}
}
-
- if (p_search_previous) {
- it = _get_prev_item(it, true);
- } else {
- it = _get_next_item(it, true);
+ } else {
+ for (int i = 0; i < main->lines.size(); i++) {
+ if (_search_line(main, i, p_string, nullptr, nullptr)) {
+ update();
+ return true;
+ }
}
- charidx = 0;
}
return false;
}
-String RichTextLabel::get_selected_text() {
- if (!selection.active || !selection.enabled) {
- return "";
- }
-
+String RichTextLabel::_get_line_text(ItemFrame *p_frame, int p_line, Selection p_selection) {
String text;
+ ERR_FAIL_COND_V(p_frame == nullptr, text);
+ ERR_FAIL_COND_V(p_line < 0 || p_line >= p_frame->lines.size(), text);
- RichTextLabel::Item *item = selection.from;
-
- while (item) {
- if (item->type == ITEM_TEXT) {
- String itext = static_cast<ItemText *>(item)->text;
- if (item == selection.from && item == selection.to) {
- text += itext.substr(selection.from_char, selection.to_char - selection.from_char + 1);
- } else if (item == selection.from) {
- text += itext.substr(selection.from_char, itext.size());
- } else if (item == selection.to) {
- text += itext.substr(0, selection.to_char + 1);
- } else {
- text += itext;
- }
+ Line &l = p_frame->lines.write[p_line];
- } else if (item->type == ITEM_NEWLINE) {
- text += "\n";
+ Item *it_to = (p_line + 1 < 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;
+ } else {
+ for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
+ end_idx = it->index + 1;
+ }
+ }
+ for (Item *it = l.from; it && it != it_to; it = _get_next_item(it)) {
+ if ((p_selection.to_item != nullptr) && (p_selection.to_item->index < l.from->index)) {
+ break;
}
- if (item == selection.to) {
+ if ((p_selection.from_item != nullptr) && (p_selection.from_item->index >= end_idx)) {
break;
}
+ switch (it->type) {
+ case ITEM_NEWLINE: {
+ text += "\n";
+ } break;
+ case ITEM_TEXT: {
+ ItemText *t = (ItemText *)it;
+ text += t->text;
+ } break;
+ case ITEM_IMAGE: {
+ text += " ";
+ } break;
+ case ITEM_TABLE: {
+ ItemTable *table = static_cast<ItemTable *>(it);
+ int idx = 0;
+ int col_count = table->columns.size();
+ for (List<Item *>::Element *E = table->subitems.front(); E; E = E->next()) {
+ ERR_CONTINUE(E->get()->type != ITEM_FRAME); // Children should all be frames.
+ ItemFrame *frame = static_cast<ItemFrame *>(E->get());
+ int column = idx % col_count;
+
+ for (int i = 0; i < frame->lines.size(); i++) {
+ text += _get_line_text(frame, i, p_selection);
+ }
+ if (column == col_count - 1) {
+ text += "\n";
+ } else {
+ text += " ";
+ }
+ idx++;
+ }
+ } break;
+ default:
+ break;
+ }
+ }
+ if ((l.from != nullptr) && (p_frame == p_selection.to_frame) && (p_selection.to_item != nullptr) && (p_selection.to_item->index >= l.from->index) && (p_selection.to_item->index < end_idx)) {
+ text = text.substr(0, p_selection.to_char);
+ }
+ if ((l.from != nullptr) && (p_frame == p_selection.from_frame) && (p_selection.from_item != nullptr) && (p_selection.from_item->index >= l.from->index) && (p_selection.from_item->index < end_idx)) {
+ text = text.substr(p_selection.from_char, -1);
+ }
+ return text;
+}
- item = _get_next_item(item, true);
+String RichTextLabel::get_selected_text() {
+ if (!selection.active || !selection.enabled) {
+ return "";
}
+ String text;
+ for (int i = 0; i < main->lines.size(); i++) {
+ text += _get_line_text(main, i, selection);
+ }
return text;
}
@@ -2611,7 +3534,7 @@ String RichTextLabel::get_text() {
text += t->text;
} else if (it->type == ITEM_NEWLINE) {
text += "\n";
- } else if (it->type == ITEM_INDENT) {
+ } else if (it->type == ITEM_INDENT || it->type == ITEM_LIST) {
text += "\t";
}
it = _get_next_item(it, true);
@@ -2624,18 +3547,73 @@ void RichTextLabel::set_text(const String &p_string) {
add_text(p_string);
}
-void RichTextLabel::set_percent_visible(float p_percent) {
- if (p_percent < 0 || p_percent >= 1) {
- visible_characters = -1;
- percent_visible = 1;
+void RichTextLabel::set_text_direction(Control::TextDirection p_text_direction) {
+ ERR_FAIL_COND((int)p_text_direction < -1 || (int)p_text_direction > 3);
+ if (text_direction != p_text_direction) {
+ text_direction = p_text_direction;
+ main->first_invalid_line = 0; //invalidate ALL
+ _validate_line_caches(main);
+ update();
+ }
+}
- } else {
- visible_characters = get_total_character_count() * p_percent;
- percent_visible = p_percent;
+void RichTextLabel::set_structured_text_bidi_override(Control::StructuredTextParser p_parser) {
+ if (st_parser != p_parser) {
+ st_parser = p_parser;
+ main->first_invalid_line = 0; //invalidate ALL
+ _validate_line_caches(main);
+ update();
}
+}
+
+Control::StructuredTextParser RichTextLabel::get_structured_text_bidi_override() const {
+ return st_parser;
+}
+
+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();
}
+Array RichTextLabel::get_structured_text_bidi_override_options() const {
+ return st_args;
+}
+
+Control::TextDirection RichTextLabel::get_text_direction() const {
+ return text_direction;
+}
+
+void RichTextLabel::set_language(const String &p_language) {
+ if (language != p_language) {
+ language = p_language;
+ main->first_invalid_line = 0; //invalidate ALL
+ _validate_line_caches(main);
+ update();
+ }
+}
+
+String RichTextLabel::get_language() const {
+ return language;
+}
+
+void RichTextLabel::set_percent_visible(float p_percent) {
+ if (percent_visible != p_percent) {
+ if (p_percent < 0 || p_percent >= 1) {
+ visible_characters = -1;
+ percent_visible = 1;
+
+ } else {
+ visible_characters = get_total_character_count() * p_percent;
+ percent_visible = p_percent;
+ }
+ main->first_invalid_line = 0; //invalidate ALL
+ _validate_line_caches(main);
+ update();
+ }
+}
+
float RichTextLabel::get_percent_visible() const {
return percent_visible;
}
@@ -2671,7 +3649,7 @@ 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].height_accum_cache + get_theme_stylebox("normal")->get_minimum_size().height;
+ total_height = main->lines[main->lines.size() - 1].offset.y + main->lines[main->lines.size() - 1].text_buf->get_size().y + get_theme_stylebox("normal")->get_minimum_size().height;
}
return total_height;
}
@@ -2681,29 +3659,46 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_text"), &RichTextLabel::get_text);
ClassDB::bind_method(D_METHOD("add_text", "text"), &RichTextLabel::add_text);
ClassDB::bind_method(D_METHOD("set_text", "text"), &RichTextLabel::set_text);
- ClassDB::bind_method(D_METHOD("add_image", "image", "width", "height", "color"), &RichTextLabel::add_image, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)));
+ ClassDB::bind_method(D_METHOD("add_image", "image", "width", "height", "color", "inline_align"), &RichTextLabel::add_image, DEFVAL(0), DEFVAL(0), DEFVAL(Color(1.0, 1.0, 1.0)), DEFVAL(VALIGN_TOP));
ClassDB::bind_method(D_METHOD("newline"), &RichTextLabel::add_newline);
ClassDB::bind_method(D_METHOD("remove_line", "line"), &RichTextLabel::remove_line);
ClassDB::bind_method(D_METHOD("push_font", "font"), &RichTextLabel::push_font);
+ ClassDB::bind_method(D_METHOD("push_font_size", "font_size"), &RichTextLabel::push_font_size);
+ ClassDB::bind_method(D_METHOD("push_font_features", "opentype_features"), &RichTextLabel::push_font_features);
ClassDB::bind_method(D_METHOD("push_normal"), &RichTextLabel::push_normal);
ClassDB::bind_method(D_METHOD("push_bold"), &RichTextLabel::push_bold);
ClassDB::bind_method(D_METHOD("push_bold_italics"), &RichTextLabel::push_bold_italics);
ClassDB::bind_method(D_METHOD("push_italics"), &RichTextLabel::push_italics);
ClassDB::bind_method(D_METHOD("push_mono"), &RichTextLabel::push_mono);
ClassDB::bind_method(D_METHOD("push_color", "color"), &RichTextLabel::push_color);
- ClassDB::bind_method(D_METHOD("push_align", "align"), &RichTextLabel::push_align);
+ ClassDB::bind_method(D_METHOD("push_outline_size", "outline_size"), &RichTextLabel::push_outline_size);
+ ClassDB::bind_method(D_METHOD("push_outline_color", "color"), &RichTextLabel::push_outline_color);
+ ClassDB::bind_method(D_METHOD("push_paragraph", "align", "base_direction", "language", "st_parser"), &RichTextLabel::push_paragraph, DEFVAL(TextServer::DIRECTION_AUTO), DEFVAL(""), DEFVAL(STRUCTURED_TEXT_DEFAULT));
ClassDB::bind_method(D_METHOD("push_indent", "level"), &RichTextLabel::push_indent);
- ClassDB::bind_method(D_METHOD("push_list", "type"), &RichTextLabel::push_list);
+ ClassDB::bind_method(D_METHOD("push_list", "level", "type", "capitalize"), &RichTextLabel::push_list);
ClassDB::bind_method(D_METHOD("push_meta", "data"), &RichTextLabel::push_meta);
ClassDB::bind_method(D_METHOD("push_underline"), &RichTextLabel::push_underline);
ClassDB::bind_method(D_METHOD("push_strikethrough"), &RichTextLabel::push_strikethrough);
- ClassDB::bind_method(D_METHOD("push_table", "columns"), &RichTextLabel::push_table);
+ ClassDB::bind_method(D_METHOD("push_table", "columns", "inline_align"), &RichTextLabel::push_table, DEFVAL(VALIGN_TOP));
ClassDB::bind_method(D_METHOD("set_table_column_expand", "column", "expand", "ratio"), &RichTextLabel::set_table_column_expand);
+ ClassDB::bind_method(D_METHOD("set_cell_row_background_color", "odd_row_bg", "even_row_bg"), &RichTextLabel::set_cell_row_background_color);
+ ClassDB::bind_method(D_METHOD("set_cell_border_color", "color"), &RichTextLabel::set_cell_border_color);
+ ClassDB::bind_method(D_METHOD("set_cell_size_override", "min_size", "max_size"), &RichTextLabel::set_cell_size_override);
+ ClassDB::bind_method(D_METHOD("set_cell_padding", "padding"), &RichTextLabel::set_cell_padding);
ClassDB::bind_method(D_METHOD("push_cell"), &RichTextLabel::push_cell);
ClassDB::bind_method(D_METHOD("pop"), &RichTextLabel::pop);
ClassDB::bind_method(D_METHOD("clear"), &RichTextLabel::clear);
+ ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override", "parser"), &RichTextLabel::set_structured_text_bidi_override);
+ ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override"), &RichTextLabel::get_structured_text_bidi_override);
+ ClassDB::bind_method(D_METHOD("set_structured_text_bidi_override_options", "args"), &RichTextLabel::set_structured_text_bidi_override_options);
+ ClassDB::bind_method(D_METHOD("get_structured_text_bidi_override_options"), &RichTextLabel::get_structured_text_bidi_override_options);
+ ClassDB::bind_method(D_METHOD("set_text_direction", "direction"), &RichTextLabel::set_text_direction);
+ ClassDB::bind_method(D_METHOD("get_text_direction"), &RichTextLabel::get_text_direction);
+ ClassDB::bind_method(D_METHOD("set_language", "language"), &RichTextLabel::set_language);
+ ClassDB::bind_method(D_METHOD("get_language"), &RichTextLabel::get_language);
+
ClassDB::bind_method(D_METHOD("set_meta_underline", "enable"), &RichTextLabel::set_meta_underline);
ClassDB::bind_method(D_METHOD("is_meta_underlined"), &RichTextLabel::is_meta_underlined);
@@ -2778,6 +3773,13 @@ void RichTextLabel::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_ARRAY_TYPE, "RichTextEffect", (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE)), "set_effects", "get_effects");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,LTR,RTL,Inherited"), "set_text_direction", "get_text_direction");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "language"), "set_language", "get_language");
+
+ ADD_GROUP("Structured Text", "structured_text_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "structured_text_bidi_override", PROPERTY_HINT_ENUM, "Default,URI,File,Email,List,None,Custom"), "set_structured_text_bidi_override", "get_structured_text_bidi_override");
+ ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "structured_text_bidi_override_options"), "set_structured_text_bidi_override_options", "get_structured_text_bidi_override_options");
+
ADD_SIGNAL(MethodInfo("meta_clicked", PropertyInfo(Variant::NIL, "meta", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NIL_IS_VARIANT)));
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)));
@@ -2789,6 +3791,7 @@ void RichTextLabel::_bind_methods() {
BIND_ENUM_CONSTANT(LIST_NUMBERS);
BIND_ENUM_CONSTANT(LIST_LETTERS);
+ BIND_ENUM_CONSTANT(LIST_ROMAN);
BIND_ENUM_CONSTANT(LIST_DOTS);
BIND_ENUM_CONSTANT(ITEM_FRAME);
@@ -2796,10 +3799,14 @@ void RichTextLabel::_bind_methods() {
BIND_ENUM_CONSTANT(ITEM_IMAGE);
BIND_ENUM_CONSTANT(ITEM_NEWLINE);
BIND_ENUM_CONSTANT(ITEM_FONT);
+ BIND_ENUM_CONSTANT(ITEM_FONT_SIZE);
+ BIND_ENUM_CONSTANT(ITEM_FONT_FEATURES);
BIND_ENUM_CONSTANT(ITEM_COLOR);
+ BIND_ENUM_CONSTANT(ITEM_OUTLINE_SIZE);
+ BIND_ENUM_CONSTANT(ITEM_OUTLINE_COLOR);
BIND_ENUM_CONSTANT(ITEM_UNDERLINE);
BIND_ENUM_CONSTANT(ITEM_STRIKETHROUGH);
- BIND_ENUM_CONSTANT(ITEM_ALIGN);
+ BIND_ENUM_CONSTANT(ITEM_PARAGRAPH);
BIND_ENUM_CONSTANT(ITEM_INDENT);
BIND_ENUM_CONSTANT(ITEM_LIST);
BIND_ENUM_CONSTANT(ITEM_TABLE);
@@ -2929,6 +3936,7 @@ RichTextLabel::RichTextLabel() {
main->lines.resize(1);
main->lines.write[0].from = main;
main->first_invalid_line = 0;
+ main->first_resized_line = 0;
current_frame = main;
tab_size = 4;
default_align = ALIGN_LEFT;
@@ -2954,10 +3962,10 @@ RichTextLabel::RichTextLabel() {
vscroll->connect("value_changed", callable_mp(this, &RichTextLabel::_scroll_changed));
vscroll->set_step(1);
vscroll->hide();
- current_idx = 1;
use_bbcode = false;
- selection.click = nullptr;
+ selection.click_frame = nullptr;
+ selection.click_item = nullptr;
selection.active = false;
selection.enabled = false;
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index 67a3f466a6..93e48dd449 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -33,6 +33,7 @@
#include "rich_text_effect.h"
#include "scene/gui/scroll_bar.h"
+#include "scene/resources/text_paragraph.h"
class RichTextLabel : public Control {
GDCLASS(RichTextLabel, Control);
@@ -48,6 +49,7 @@ public:
enum ListType {
LIST_NUMBERS,
LIST_LETTERS,
+ LIST_ROMAN,
LIST_DOTS
};
@@ -57,10 +59,14 @@ public:
ITEM_IMAGE,
ITEM_NEWLINE,
ITEM_FONT,
+ ITEM_FONT_SIZE,
+ ITEM_FONT_FEATURES,
ITEM_COLOR,
+ ITEM_OUTLINE_SIZE,
+ ITEM_OUTLINE_COLOR,
ITEM_UNDERLINE,
ITEM_STRIKETHROUGH,
- ITEM_ALIGN,
+ ITEM_PARAGRAPH,
ITEM_INDENT,
ITEM_LIST,
ITEM_TABLE,
@@ -80,31 +86,25 @@ private:
struct Item;
struct Line {
- Item *from;
- Vector<int> offset_caches;
- Vector<int> height_caches;
- Vector<int> ascent_caches;
- Vector<int> descent_caches;
- Vector<int> space_caches;
- int height_cache;
- int height_accum_cache;
- int char_count;
- int minimum_width;
- int maximum_width;
-
- Line() {
- from = nullptr;
- char_count = 0;
- }
+ Item *from = nullptr;
+
+ Ref<TextParagraph> text_buf;
+
+ Vector2 offset;
+ int char_offset = 0;
+ int char_count = 0;
+
+ Line() { text_buf.instance(); }
};
struct Item {
- int index;
- Item *parent;
- ItemType type;
+ int index = 0;
+ int char_ofs = 0;
+ Item *parent = nullptr;
+ ItemType type = ITEM_FRAME;
List<Item *> subitems;
- List<Item *>::Element *E;
- int line;
+ List<Item *>::Element *E = nullptr;
+ int line = 0;
void _clear_children() {
while (subitems.size()) {
@@ -113,29 +113,26 @@ private:
}
}
- Item() {
- parent = nullptr;
- E = nullptr;
- line = 0;
- index = 0;
- type = ITEM_FRAME;
- }
virtual ~Item() { _clear_children(); }
};
struct ItemFrame : public Item {
- int parent_line;
- bool cell;
+ bool cell = false;
+
Vector<Line> lines;
- int first_invalid_line;
- ItemFrame *parent_frame;
-
- ItemFrame() {
- type = ITEM_FRAME;
- parent_frame = nullptr;
- cell = false;
- parent_line = 0;
- }
+ int first_invalid_line = 0;
+ int first_resized_line = 0;
+
+ ItemFrame *parent_frame = nullptr;
+
+ Color odd_row_bg = Color(0, 0, 0, 0);
+ Color even_row_bg = Color(0, 0, 0, 0);
+ Color border = Color(0, 0, 0, 0);
+ Size2 min_size_over = Size2(-1, -1);
+ Size2 max_size_over = Size2(-1, -1);
+ Rect2 padding;
+
+ ItemFrame() { type = ITEM_FRAME; }
};
struct ItemText : public Item {
@@ -145,6 +142,7 @@ private:
struct ItemImage : public Item {
Ref<Texture2D> image;
+ VAlign inline_align = VALIGN_TOP;
Size2 size;
Color color;
ItemImage() { type = ITEM_IMAGE; }
@@ -155,11 +153,31 @@ private:
ItemFont() { type = ITEM_FONT; }
};
+ struct ItemFontSize : public Item {
+ int font_size = 16;
+ ItemFontSize() { type = ITEM_FONT_SIZE; }
+ };
+
+ struct ItemFontFeatures : public Item {
+ Dictionary opentype_features;
+ ItemFontFeatures() { type = ITEM_FONT_FEATURES; }
+ };
+
struct ItemColor : public Item {
Color color;
ItemColor() { type = ITEM_COLOR; }
};
+ struct ItemOutlineSize : public Item {
+ int outline_size = 0;
+ ItemOutlineSize() { type = ITEM_OUTLINE_SIZE; }
+ };
+
+ struct ItemOutlineColor : public Item {
+ Color color;
+ ItemOutlineColor() { type = ITEM_OUTLINE_COLOR; }
+ };
+
struct ItemUnderline : public Item {
ItemUnderline() { type = ITEM_UNDERLINE; }
};
@@ -173,18 +191,23 @@ private:
ItemMeta() { type = ITEM_META; }
};
- struct ItemAlign : public Item {
- Align align;
- ItemAlign() { type = ITEM_ALIGN; }
+ struct ItemParagraph : public Item {
+ Align align = ALIGN_LEFT;
+ String language;
+ Control::TextDirection direction = Control::TEXT_DIRECTION_AUTO;
+ Control::StructuredTextParser st_parser = STRUCTURED_TEXT_DEFAULT;
+ ItemParagraph() { type = ITEM_PARAGRAPH; }
};
struct ItemIndent : public Item {
- int level;
+ int level = 0;
ItemIndent() { type = ITEM_INDENT; }
};
struct ItemList : public Item {
- ListType list_type;
+ ListType list_type = LIST_DOTS;
+ bool capitalize = false;
+ int level = 0;
ItemList() { type = ITEM_LIST; }
};
@@ -202,37 +225,32 @@ private:
};
Vector<Column> columns;
- int total_width;
+ Vector<float> rows;
+
+ int total_width = 0;
+ int total_height = 0;
+ VAlign inline_align = VALIGN_TOP;
ItemTable() { type = ITEM_TABLE; }
};
struct ItemFade : public Item {
- int starting_index;
- int length;
+ int starting_index = 0;
+ int length = 0;
ItemFade() { type = ITEM_FADE; }
};
struct ItemFX : public Item {
- float elapsed_time;
-
- ItemFX() {
- elapsed_time = 0.0f;
- }
+ float elapsed_time = 0.f;
};
struct ItemShake : public ItemFX {
- int strength;
- float rate;
- uint64_t _current_rng;
- uint64_t _previous_rng;
-
- ItemShake() {
- strength = 0;
- rate = 0.0f;
- _current_rng = 0;
- type = ITEM_SHAKE;
- }
+ int strength = 0;
+ float rate = 0.0f;
+ uint64_t _current_rng = 0;
+ uint64_t _previous_rng = 0;
+
+ ItemShake() { type = ITEM_SHAKE; }
void reroll_random() {
_previous_rng = _current_rng;
@@ -251,38 +269,25 @@ private:
};
struct ItemWave : public ItemFX {
- float frequency;
- float amplitude;
+ float frequency = 1.0f;
+ float amplitude = 1.0f;
- ItemWave() {
- frequency = 1.0f;
- amplitude = 1.0f;
- type = ITEM_WAVE;
- }
+ ItemWave() { type = ITEM_WAVE; }
};
struct ItemTornado : public ItemFX {
- float radius;
- float frequency;
+ float radius = 1.0f;
+ float frequency = 1.0f;
- ItemTornado() {
- radius = 1.0f;
- frequency = 1.0f;
- type = ITEM_TORNADO;
- }
+ ItemTornado() { type = ITEM_TORNADO; }
};
struct ItemRainbow : public ItemFX {
- float saturation;
- float value;
- float frequency;
-
- ItemRainbow() {
- saturation = 0.8f;
- value = 0.8f;
- frequency = 1.0f;
- type = ITEM_RAINBOW;
- }
+ float saturation = 0.8f;
+ float value = 0.8f;
+ float frequency = 1.0f;
+
+ ItemRainbow() { type = ITEM_RAINBOW; }
};
struct ItemCustomFX : public ItemFX {
@@ -291,7 +296,6 @@ private:
ItemCustomFX() {
type = ITEM_CUSTOMFX;
-
char_fx_transform.instance();
}
@@ -316,7 +320,8 @@ private:
int scroll_w;
bool scroll_updated;
bool updating_scroll;
- int current_idx;
+ int current_idx = 1;
+ int current_char_ofs = 0;
int visible_line_count;
int tab_size;
@@ -336,23 +341,25 @@ private:
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);
- struct ProcessState {
- int line_width;
- };
-
- enum ProcessMode {
- PROCESS_CACHE,
- PROCESS_DRAW,
- PROCESS_POINTER
- };
+ String language;
+ TextDirection text_direction = TEXT_DIRECTION_AUTO;
+ Control::StructuredTextParser st_parser = STRUCTURED_TEXT_DEFAULT;
+ Array st_args;
struct Selection {
- Item *click;
+ ItemFrame *click_frame;
+ int click_line;
+ Item *click_item;
int click_char;
- Item *from;
+ ItemFrame *from_frame;
+ int from_line;
+ Item *from_item;
int from_char;
- Item *to;
+
+ ItemFrame *to_frame;
+ int to_line;
+ Item *to_item;
int to_char;
bool active; // anything selected? i.e. from, to, etc. valid?
@@ -364,18 +371,38 @@ private:
int visible_characters;
float percent_visible;
- int _process_line(ItemFrame *p_frame, const Vector2 &p_ofs, int &y, int p_width, int p_line, ProcessMode p_mode, const Ref<Font> &p_base_font, const Color &p_base_color, const Color &p_font_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs, const Point2i &p_click_pos = Point2i(), Item **r_click_item = nullptr, int *r_click_char = nullptr, bool *r_outside = nullptr, int p_char_count = 0);
- void _find_click(ItemFrame *p_frame, const Point2i &p_click, Item **r_click_item = nullptr, int *r_click_char = nullptr, bool *r_outside = nullptr);
+ void _find_click(ItemFrame *p_frame, 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 *r_outside = nullptr);
+
+ String _get_line_text(ItemFrame *p_frame, int p_line, Selection p_sel);
+ bool _search_line(ItemFrame *p_frame, int p_line, const String &p_string, Item *p_from, Item *p_to);
+
+ 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 _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_color_shadow, bool p_shadow_as_outline, const Point2 &shadow_ofs);
+ 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);
+
+ String _roman(int p_num, bool p_capitalize) const;
+ String _letters(int p_num, bool p_capitalize) const;
+ Item *_get_item_at_pos(Item *p_item_from, Item *p_item_to, int p_position);
+ void _find_frame(Item *p_item, ItemFrame **r_frame, int *r_line);
Ref<Font> _find_font(Item *p_item);
- int _find_margin(Item *p_item, const Ref<Font> &p_base_font);
+ int _find_font_size(Item *p_item);
+ Dictionary _find_font_features(Item *p_item);
+ int _find_outline_size(Item *p_item);
+ ItemList *_find_list_item(Item *p_item);
+ int _find_list(Item *p_item, Vector<int> &r_index, Vector<ItemList *> &r_list);
+ int _find_margin(Item *p_item, const Ref<Font> &p_base_font, int p_base_font_size);
Align _find_align(Item *p_item);
+ TextServer::Direction _find_direction(Item *p_item);
+ Control::StructuredTextParser _find_stt(Item *p_item);
+ String _find_language(Item *p_item);
Color _find_color(Item *p_item, const Color &p_default_color);
+ Color _find_outline_color(Item *p_item, const Color &p_default_color);
bool _find_underline(Item *p_item);
bool _find_strikethrough(Item *p_item);
bool _find_meta(Item *p_item, Variant *r_meta, ItemMeta **r_item = nullptr);
bool _find_layout_subitem(Item *from, Item *to);
- bool _find_by_type(Item *p_item, ItemType p_type);
void _fetch_item_fx_stack(Item *p_item, Vector<ItemFX *> &r_stack);
static Color _get_color_from_string(const String &p_color_str, const Color &p_default_color);
@@ -395,8 +422,6 @@ private:
bool use_bbcode;
String bbcode;
- void _update_all_lines();
-
int fixed_width;
bool fit_content_height;
@@ -407,23 +432,27 @@ protected:
public:
String get_text();
void add_text(const String &p_text);
- void add_image(const Ref<Texture2D> &p_image, const int p_width = 0, const int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0));
+ void add_image(const Ref<Texture2D> &p_image, const int p_width = 0, const int p_height = 0, const Color &p_color = Color(1.0, 1.0, 1.0), VAlign p_align = VALIGN_TOP);
void add_newline();
bool remove_line(const int p_line);
void push_font(const Ref<Font> &p_font);
+ void push_font_size(int p_font_size);
+ void push_font_features(const Dictionary &p_features);
+ void push_outline_size(int p_font_size);
void push_normal();
void push_bold();
void push_bold_italics();
void push_italics();
void push_mono();
void push_color(const Color &p_color);
+ void push_outline_color(const Color &p_color);
void push_underline();
void push_strikethrough();
- void push_align(Align p_align);
+ void push_paragraph(Align p_align, Control::TextDirection p_direction = Control::TEXT_DIRECTION_INHERITED, const String &p_language = "", Control::StructuredTextParser p_st_parser = STRUCTURED_TEXT_DEFAULT);
void push_indent(int p_level);
- void push_list(ListType p_list);
+ void push_list(int p_level, ListType p_list, bool p_capitalize);
void push_meta(const Variant &p_meta);
- void push_table(int p_columns);
+ void push_table(int p_columns, VAlign p_align = VALIGN_TOP);
void push_fade(int p_start_index, int p_length);
void push_shake(int p_strength, float p_rate);
void push_wave(float p_frequency, float p_amplitude);
@@ -431,6 +460,10 @@ public:
void push_rainbow(float p_saturation, float p_value, float p_frequency);
void push_customfx(Ref<RichTextEffect> p_custom_effect, Dictionary p_environment);
void set_table_column_expand(int p_column, bool p_expand, int p_ratio = 1);
+ void set_cell_row_background_color(const Color &p_odd_row_bg, const Color &p_even_row_bg);
+ void set_cell_border_color(const Color &p_color);
+ void set_cell_size_override(const Size2 &p_min_size, const Size2 &p_max_size);
+ void set_cell_padding(const Rect2 &p_padding);
int get_current_table_column() const;
void push_cell();
void pop();
@@ -485,6 +518,18 @@ public:
void set_text(const String &p_string);
+ void set_text_direction(TextDirection p_text_direction);
+ TextDirection get_text_direction() const;
+
+ void set_language(const String &p_language);
+ String get_language() const;
+
+ void set_structured_text_bidi_override(Control::StructuredTextParser p_parser);
+ Control::StructuredTextParser get_structured_text_bidi_override() const;
+
+ void set_structured_text_bidi_override_options(Array p_args);
+ Array get_structured_text_bidi_override_options() const;
+
void set_visible_characters(int p_visible);
int get_visible_characters() const;
int get_total_character_count() const;
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index 9340d98ede..70de63fd40 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -449,18 +449,6 @@ double ScrollBar::get_area_offset() const {
return ofs;
}
-double ScrollBar::get_click_pos(const Point2 &p_pos) const {
- float pos = (orientation == VERTICAL) ? p_pos.y : p_pos.x;
- pos -= get_area_offset();
-
- float area = get_area_size();
- if (area == 0) {
- return 0;
- } else {
- return pos / area;
- }
-}
-
double ScrollBar::get_grabber_offset() const {
return (get_area_size()) * get_as_ratio();
}
diff --git a/scene/gui/scroll_bar.h b/scene/gui/scroll_bar.h
index 75f5ad1647..358ed74965 100644
--- a/scene/gui/scroll_bar.h
+++ b/scene/gui/scroll_bar.h
@@ -61,7 +61,6 @@ class ScrollBar : public Range {
double get_grabber_min_size() const;
double get_area_size() const;
double get_area_offset() const;
- double get_click_pos(const Point2 &p_pos) const;
double get_grabber_offset() const;
static void set_can_focus_by_default(bool p_can_focus);
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index d7ca2f66ea..01c1a15b79 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -415,6 +415,11 @@ void TabContainer::_notification(int p_what) {
break;
}
+ if (all_tabs_in_front) {
+ // Draw the tab area.
+ panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
+ }
+
// Draw unselected tabs in back
int x = 0;
int x_current = 0;
@@ -446,8 +451,10 @@ void TabContainer::_notification(int p_what) {
last_tab_cache = index;
}
- // Draw the tab area.
- panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
+ if (!all_tabs_in_front) {
+ // Draw the tab area.
+ panel->draw(canvas, Rect2(0, header_height, size.width, size.height - header_height));
+ }
// Draw selected tab in front. only draw selected tab when it's in visible range.
if (tabs.size() > 0 && current - first_tab_cache < tab_widths.size() && current >= first_tab_cache) {
@@ -1017,6 +1024,20 @@ bool TabContainer::are_tabs_visible() const {
return tabs_visible;
}
+void TabContainer::set_all_tabs_in_front(bool p_in_front) {
+ if (p_in_front == all_tabs_in_front) {
+ return;
+ }
+
+ all_tabs_in_front = p_in_front;
+
+ update();
+}
+
+bool TabContainer::is_all_tabs_in_front() const {
+ return all_tabs_in_front;
+}
+
Control *TabContainer::_get_tab(int p_idx) const {
return get_tab_control(p_idx);
}
@@ -1208,6 +1229,8 @@ void TabContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tab_align"), &TabContainer::get_tab_align);
ClassDB::bind_method(D_METHOD("set_tabs_visible", "visible"), &TabContainer::set_tabs_visible);
ClassDB::bind_method(D_METHOD("are_tabs_visible"), &TabContainer::are_tabs_visible);
+ ClassDB::bind_method(D_METHOD("set_all_tabs_in_front", "is_front"), &TabContainer::set_all_tabs_in_front);
+ ClassDB::bind_method(D_METHOD("is_all_tabs_in_front"), &TabContainer::is_all_tabs_in_front);
ClassDB::bind_method(D_METHOD("set_tab_title", "tab_idx", "title"), &TabContainer::set_tab_title);
ClassDB::bind_method(D_METHOD("get_tab_title", "tab_idx"), &TabContainer::get_tab_title);
ClassDB::bind_method(D_METHOD("set_tab_icon", "tab_idx", "icon"), &TabContainer::set_tab_icon);
@@ -1234,6 +1257,7 @@ void TabContainer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_align", PROPERTY_HINT_ENUM, "Left,Center,Right"), "set_tab_align", "get_tab_align");
ADD_PROPERTY(PropertyInfo(Variant::INT, "current_tab", PROPERTY_HINT_RANGE, "-1,4096,1", PROPERTY_USAGE_EDITOR), "set_current_tab", "get_current_tab");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "tabs_visible"), "set_tabs_visible", "are_tabs_visible");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "all_tabs_in_front"), "set_all_tabs_in_front", "is_all_tabs_in_front");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "drag_to_rearrange_enabled"), "set_drag_to_rearrange_enabled", "get_drag_to_rearrange_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "use_hidden_tabs_for_min_size"), "set_use_hidden_tabs_for_min_size", "get_use_hidden_tabs_for_min_size");
@@ -1253,6 +1277,7 @@ TabContainer::TabContainer() {
previous = 0;
align = ALIGN_CENTER;
tabs_visible = true;
+ all_tabs_in_front = false;
drag_to_rearrange_enabled = false;
tabs_rearrange_group = -1;
use_hidden_tabs_for_min_size = false;
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index 2fef606551..91153e5fc3 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -52,6 +52,7 @@ private:
int current;
int previous;
bool tabs_visible;
+ bool all_tabs_in_front;
bool buttons_visible_cache;
bool menu_hovered;
int highlight_arrow;
@@ -94,6 +95,9 @@ public:
void set_tabs_visible(bool p_visible);
bool are_tabs_visible() const;
+ void set_all_tabs_in_front(bool p_is_front);
+ bool is_all_tabs_in_front() const;
+
void set_tab_title(int p_tab, const String &p_title);
String get_tab_title(int p_tab) const;
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index 906dd94fff..1d65abc95f 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -1650,7 +1650,7 @@ void TextEdit::_notification(int p_what) {
if (get_viewport()->get_window_id() != DisplayServer::INVALID_WINDOW_ID) {
DisplayServer::get_singleton()->window_set_ime_active(true, get_viewport()->get_window_id());
- DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + _get_cursor_pixel_pos(), get_viewport()->get_window_id());
+ DisplayServer::get_singleton()->window_set_ime_position(get_global_position() + _get_cursor_pixel_pos(false), get_viewport()->get_window_id());
}
if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) {
@@ -2072,8 +2072,10 @@ void TextEdit::_get_mouse_pos(const Point2i &p_mouse, int &r_row, int &r_col) co
r_col = col;
}
-Vector2i TextEdit::_get_cursor_pixel_pos() {
- adjust_viewport_to_cursor();
+Vector2i TextEdit::_get_cursor_pixel_pos(bool p_adjust_viewport) {
+ if (p_adjust_viewport) {
+ adjust_viewport_to_cursor();
+ }
int row = 1;
for (int i = get_first_visible_line(); i < cursor.line; i++) {
if (!is_line_hidden(i)) {
@@ -6619,8 +6621,8 @@ void TextEdit::set_line_length_guideline_hard_column(int p_column) {
}
void TextEdit::set_draw_minimap(bool p_draw) {
- draw_minimap = p_draw;
if (draw_minimap != p_draw) {
+ draw_minimap = p_draw;
_update_wrap_at();
}
update();
@@ -6631,8 +6633,8 @@ bool TextEdit::is_drawing_minimap() const {
}
void TextEdit::set_minimap_width(int p_minimap_width) {
- minimap_width = p_minimap_width;
if (minimap_width != p_minimap_width) {
+ minimap_width = p_minimap_width;
_update_wrap_at();
}
update();
diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h
index c2fe4afec5..3f16ed1366 100644
--- a/scene/gui/text_edit.h
+++ b/scene/gui/text_edit.h
@@ -700,7 +700,7 @@ public:
int cursor_get_column() const;
int cursor_get_line() const;
- Vector2i _get_cursor_pixel_pos();
+ Vector2i _get_cursor_pixel_pos(bool p_adjust_viewport = true);
bool cursor_get_blink_enabled() const;
void cursor_set_blink_enabled(const bool p_enabled);
diff --git a/scene/gui/texture_progress.cpp b/scene/gui/texture_progress_bar.cpp
index e0d98d1c22..b5115690ac 100644
--- a/scene/gui/texture_progress.cpp
+++ b/scene/gui/texture_progress_bar.cpp
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* texture_progress.cpp */
+/* texture_progress_bar.cpp */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,21 +28,21 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "texture_progress.h"
+#include "texture_progress_bar.h"
#include "core/config/engine.h"
-void TextureProgress::set_under_texture(const Ref<Texture2D> &p_texture) {
+void TextureProgressBar::set_under_texture(const Ref<Texture2D> &p_texture) {
under = p_texture;
update();
minimum_size_changed();
}
-Ref<Texture2D> TextureProgress::get_under_texture() const {
+Ref<Texture2D> TextureProgressBar::get_under_texture() const {
return under;
}
-void TextureProgress::set_over_texture(const Ref<Texture2D> &p_texture) {
+void TextureProgressBar::set_over_texture(const Ref<Texture2D> &p_texture) {
over = p_texture;
update();
if (under.is_null()) {
@@ -50,33 +50,33 @@ void TextureProgress::set_over_texture(const Ref<Texture2D> &p_texture) {
}
}
-Ref<Texture2D> TextureProgress::get_over_texture() const {
+Ref<Texture2D> TextureProgressBar::get_over_texture() const {
return over;
}
-void TextureProgress::set_stretch_margin(Margin p_margin, int p_size) {
+void TextureProgressBar::set_stretch_margin(Margin p_margin, int p_size) {
ERR_FAIL_INDEX((int)p_margin, 4);
stretch_margin[p_margin] = p_size;
update();
minimum_size_changed();
}
-int TextureProgress::get_stretch_margin(Margin p_margin) const {
+int TextureProgressBar::get_stretch_margin(Margin p_margin) const {
ERR_FAIL_INDEX_V((int)p_margin, 4, 0);
return stretch_margin[p_margin];
}
-void TextureProgress::set_nine_patch_stretch(bool p_stretch) {
+void TextureProgressBar::set_nine_patch_stretch(bool p_stretch) {
nine_patch_stretch = p_stretch;
update();
minimum_size_changed();
}
-bool TextureProgress::get_nine_patch_stretch() const {
+bool TextureProgressBar::get_nine_patch_stretch() const {
return nine_patch_stretch;
}
-Size2 TextureProgress::get_minimum_size() const {
+Size2 TextureProgressBar::get_minimum_size() const {
if (nine_patch_stretch) {
return Size2(stretch_margin[MARGIN_LEFT] + stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_TOP] + stretch_margin[MARGIN_BOTTOM]);
} else if (under.is_valid()) {
@@ -90,44 +90,44 @@ Size2 TextureProgress::get_minimum_size() const {
return Size2(1, 1);
}
-void TextureProgress::set_progress_texture(const Ref<Texture2D> &p_texture) {
+void TextureProgressBar::set_progress_texture(const Ref<Texture2D> &p_texture) {
progress = p_texture;
update();
minimum_size_changed();
}
-Ref<Texture2D> TextureProgress::get_progress_texture() const {
+Ref<Texture2D> TextureProgressBar::get_progress_texture() const {
return progress;
}
-void TextureProgress::set_tint_under(const Color &p_tint) {
+void TextureProgressBar::set_tint_under(const Color &p_tint) {
tint_under = p_tint;
update();
}
-Color TextureProgress::get_tint_under() const {
+Color TextureProgressBar::get_tint_under() const {
return tint_under;
}
-void TextureProgress::set_tint_progress(const Color &p_tint) {
+void TextureProgressBar::set_tint_progress(const Color &p_tint) {
tint_progress = p_tint;
update();
}
-Color TextureProgress::get_tint_progress() const {
+Color TextureProgressBar::get_tint_progress() const {
return tint_progress;
}
-void TextureProgress::set_tint_over(const Color &p_tint) {
+void TextureProgressBar::set_tint_over(const Color &p_tint) {
tint_over = p_tint;
update();
}
-Color TextureProgress::get_tint_over() const {
+Color TextureProgressBar::get_tint_over() const {
return tint_over;
}
-Point2 TextureProgress::unit_val_to_uv(float val) {
+Point2 TextureProgressBar::unit_val_to_uv(float val) {
if (progress.is_null()) {
return Point2();
}
@@ -191,7 +191,7 @@ Point2 TextureProgress::unit_val_to_uv(float val) {
return (p + t1 * dir);
}
-Point2 TextureProgress::get_relative_center() {
+Point2 TextureProgressBar::get_relative_center() {
if (progress.is_null()) {
return Point2();
}
@@ -204,7 +204,7 @@ Point2 TextureProgress::get_relative_center() {
return p;
}
-void TextureProgress::draw_nine_patch_stretched(const Ref<Texture2D> &p_texture, FillMode p_mode, double p_ratio, const Color &p_modulate) {
+void TextureProgressBar::draw_nine_patch_stretched(const Ref<Texture2D> &p_texture, FillMode p_mode, double p_ratio, const Color &p_modulate) {
Vector2 texture_size = p_texture->get_size();
Vector2 topleft = Vector2(stretch_margin[MARGIN_LEFT], stretch_margin[MARGIN_TOP]);
Vector2 bottomright = Vector2(stretch_margin[MARGIN_RIGHT], stretch_margin[MARGIN_BOTTOM]);
@@ -306,7 +306,7 @@ void TextureProgress::draw_nine_patch_stretched(const Ref<Texture2D> &p_texture,
RS::get_singleton()->canvas_item_add_nine_patch(ci, dst_rect, src_rect, p_texture->get_rid(), topleft, bottomright, RS::NINE_PATCH_STRETCH, RS::NINE_PATCH_STRETCH, true, p_modulate);
}
-void TextureProgress::_notification(int p_what) {
+void TextureProgressBar::_notification(int p_what) {
const float corners[12] = { -0.125, -0.375, -0.625, -0.875, 0.125, 0.375, 0.625, 0.875, 1.125, 1.375, 1.625, 1.875 };
switch (p_what) {
case NOTIFICATION_DRAW: {
@@ -428,17 +428,17 @@ void TextureProgress::_notification(int p_what) {
}
}
-void TextureProgress::set_fill_mode(int p_fill) {
+void TextureProgressBar::set_fill_mode(int p_fill) {
ERR_FAIL_INDEX(p_fill, 9);
mode = (FillMode)p_fill;
update();
}
-int TextureProgress::get_fill_mode() {
+int TextureProgressBar::get_fill_mode() {
return mode;
}
-void TextureProgress::set_radial_initial_angle(float p_angle) {
+void TextureProgressBar::set_radial_initial_angle(float p_angle) {
while (p_angle > 360) {
p_angle -= 360;
}
@@ -449,64 +449,64 @@ void TextureProgress::set_radial_initial_angle(float p_angle) {
update();
}
-float TextureProgress::get_radial_initial_angle() {
+float TextureProgressBar::get_radial_initial_angle() {
return rad_init_angle;
}
-void TextureProgress::set_fill_degrees(float p_angle) {
+void TextureProgressBar::set_fill_degrees(float p_angle) {
rad_max_degrees = CLAMP(p_angle, 0, 360);
update();
}
-float TextureProgress::get_fill_degrees() {
+float TextureProgressBar::get_fill_degrees() {
return rad_max_degrees;
}
-void TextureProgress::set_radial_center_offset(const Point2 &p_off) {
+void TextureProgressBar::set_radial_center_offset(const Point2 &p_off) {
rad_center_off = p_off;
update();
}
-Point2 TextureProgress::get_radial_center_offset() {
+Point2 TextureProgressBar::get_radial_center_offset() {
return rad_center_off;
}
-void TextureProgress::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_under_texture", "tex"), &TextureProgress::set_under_texture);
- ClassDB::bind_method(D_METHOD("get_under_texture"), &TextureProgress::get_under_texture);
+void TextureProgressBar::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_under_texture", "tex"), &TextureProgressBar::set_under_texture);
+ ClassDB::bind_method(D_METHOD("get_under_texture"), &TextureProgressBar::get_under_texture);
- ClassDB::bind_method(D_METHOD("set_progress_texture", "tex"), &TextureProgress::set_progress_texture);
- ClassDB::bind_method(D_METHOD("get_progress_texture"), &TextureProgress::get_progress_texture);
+ ClassDB::bind_method(D_METHOD("set_progress_texture", "tex"), &TextureProgressBar::set_progress_texture);
+ ClassDB::bind_method(D_METHOD("get_progress_texture"), &TextureProgressBar::get_progress_texture);
- ClassDB::bind_method(D_METHOD("set_over_texture", "tex"), &TextureProgress::set_over_texture);
- ClassDB::bind_method(D_METHOD("get_over_texture"), &TextureProgress::get_over_texture);
+ ClassDB::bind_method(D_METHOD("set_over_texture", "tex"), &TextureProgressBar::set_over_texture);
+ ClassDB::bind_method(D_METHOD("get_over_texture"), &TextureProgressBar::get_over_texture);
- ClassDB::bind_method(D_METHOD("set_fill_mode", "mode"), &TextureProgress::set_fill_mode);
- ClassDB::bind_method(D_METHOD("get_fill_mode"), &TextureProgress::get_fill_mode);
+ ClassDB::bind_method(D_METHOD("set_fill_mode", "mode"), &TextureProgressBar::set_fill_mode);
+ ClassDB::bind_method(D_METHOD("get_fill_mode"), &TextureProgressBar::get_fill_mode);
- ClassDB::bind_method(D_METHOD("set_tint_under", "tint"), &TextureProgress::set_tint_under);
- ClassDB::bind_method(D_METHOD("get_tint_under"), &TextureProgress::get_tint_under);
+ ClassDB::bind_method(D_METHOD("set_tint_under", "tint"), &TextureProgressBar::set_tint_under);
+ ClassDB::bind_method(D_METHOD("get_tint_under"), &TextureProgressBar::get_tint_under);
- ClassDB::bind_method(D_METHOD("set_tint_progress", "tint"), &TextureProgress::set_tint_progress);
- ClassDB::bind_method(D_METHOD("get_tint_progress"), &TextureProgress::get_tint_progress);
+ ClassDB::bind_method(D_METHOD("set_tint_progress", "tint"), &TextureProgressBar::set_tint_progress);
+ ClassDB::bind_method(D_METHOD("get_tint_progress"), &TextureProgressBar::get_tint_progress);
- ClassDB::bind_method(D_METHOD("set_tint_over", "tint"), &TextureProgress::set_tint_over);
- ClassDB::bind_method(D_METHOD("get_tint_over"), &TextureProgress::get_tint_over);
+ ClassDB::bind_method(D_METHOD("set_tint_over", "tint"), &TextureProgressBar::set_tint_over);
+ ClassDB::bind_method(D_METHOD("get_tint_over"), &TextureProgressBar::get_tint_over);
- ClassDB::bind_method(D_METHOD("set_radial_initial_angle", "mode"), &TextureProgress::set_radial_initial_angle);
- ClassDB::bind_method(D_METHOD("get_radial_initial_angle"), &TextureProgress::get_radial_initial_angle);
+ ClassDB::bind_method(D_METHOD("set_radial_initial_angle", "mode"), &TextureProgressBar::set_radial_initial_angle);
+ ClassDB::bind_method(D_METHOD("get_radial_initial_angle"), &TextureProgressBar::get_radial_initial_angle);
- ClassDB::bind_method(D_METHOD("set_radial_center_offset", "mode"), &TextureProgress::set_radial_center_offset);
- ClassDB::bind_method(D_METHOD("get_radial_center_offset"), &TextureProgress::get_radial_center_offset);
+ ClassDB::bind_method(D_METHOD("set_radial_center_offset", "mode"), &TextureProgressBar::set_radial_center_offset);
+ ClassDB::bind_method(D_METHOD("get_radial_center_offset"), &TextureProgressBar::get_radial_center_offset);
- ClassDB::bind_method(D_METHOD("set_fill_degrees", "mode"), &TextureProgress::set_fill_degrees);
- ClassDB::bind_method(D_METHOD("get_fill_degrees"), &TextureProgress::get_fill_degrees);
+ ClassDB::bind_method(D_METHOD("set_fill_degrees", "mode"), &TextureProgressBar::set_fill_degrees);
+ ClassDB::bind_method(D_METHOD("get_fill_degrees"), &TextureProgressBar::get_fill_degrees);
- ClassDB::bind_method(D_METHOD("set_stretch_margin", "margin", "value"), &TextureProgress::set_stretch_margin);
- ClassDB::bind_method(D_METHOD("get_stretch_margin", "margin"), &TextureProgress::get_stretch_margin);
+ ClassDB::bind_method(D_METHOD("set_stretch_margin", "margin", "value"), &TextureProgressBar::set_stretch_margin);
+ ClassDB::bind_method(D_METHOD("get_stretch_margin", "margin"), &TextureProgressBar::get_stretch_margin);
- ClassDB::bind_method(D_METHOD("set_nine_patch_stretch", "stretch"), &TextureProgress::set_nine_patch_stretch);
- ClassDB::bind_method(D_METHOD("get_nine_patch_stretch"), &TextureProgress::get_nine_patch_stretch);
+ ClassDB::bind_method(D_METHOD("set_nine_patch_stretch", "stretch"), &TextureProgressBar::set_nine_patch_stretch);
+ ClassDB::bind_method(D_METHOD("get_nine_patch_stretch"), &TextureProgressBar::get_nine_patch_stretch);
ADD_GROUP("Textures", "texture_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "texture_under", PROPERTY_HINT_RESOURCE_TYPE, "Texture2D"), "set_under_texture", "get_under_texture");
@@ -539,7 +539,7 @@ void TextureProgress::_bind_methods() {
BIND_ENUM_CONSTANT(FILL_CLOCKWISE_AND_COUNTER_CLOCKWISE);
}
-TextureProgress::TextureProgress() {
+TextureProgressBar::TextureProgressBar() {
mode = FILL_LEFT_TO_RIGHT;
rad_init_angle = 0;
rad_center_off = Point2();
diff --git a/scene/gui/texture_progress.h b/scene/gui/texture_progress_bar.h
index 5e29fca21f..342e719a59 100644
--- a/scene/gui/texture_progress.h
+++ b/scene/gui/texture_progress_bar.h
@@ -1,5 +1,5 @@
/*************************************************************************/
-/* texture_progress.h */
+/* texture_progress_bar.h */
/*************************************************************************/
/* This file is part of: */
/* GODOT ENGINE */
@@ -28,13 +28,13 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#ifndef TEXTURE_PROGRESS_H
-#define TEXTURE_PROGRESS_H
+#ifndef TEXTURE_PROGRESS_BAR_H
+#define TEXTURE_PROGRESS_BAR_H
#include "scene/gui/range.h"
-class TextureProgress : public Range {
- GDCLASS(TextureProgress, Range);
+class TextureProgressBar : public Range {
+ GDCLASS(TextureProgressBar, Range);
Ref<Texture2D> under;
Ref<Texture2D> progress;
@@ -95,7 +95,7 @@ public:
Size2 get_minimum_size() const override;
- TextureProgress();
+ TextureProgressBar();
private:
FillMode mode;
@@ -111,6 +111,6 @@ private:
void draw_nine_patch_stretched(const Ref<Texture2D> &p_texture, FillMode p_mode, double p_ratio, const Color &p_modulate);
};
-VARIANT_ENUM_CAST(TextureProgress::FillMode);
+VARIANT_ENUM_CAST(TextureProgressBar::FillMode);
-#endif // TEXTURE_PROGRESS_H
+#endif // TEXTURE_PROGRESS_BAR_H
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index 6bd8003ef0..063a5e7ac1 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -597,12 +597,6 @@ String TreeItem::get_button_tooltip(int p_column, int p_idx) const {
return cells[p_column].buttons[p_idx].tooltip;
}
-int TreeItem::get_button_id(int p_column, int p_idx) const {
- ERR_FAIL_INDEX_V(p_column, cells.size(), -1);
- ERR_FAIL_INDEX_V(p_idx, cells[p_column].buttons.size(), -1);
- return cells[p_column].buttons[p_idx].id;
-}
-
void TreeItem::erase_button(int p_column, int p_idx) {
ERR_FAIL_INDEX(p_column, cells.size());
ERR_FAIL_INDEX(p_idx, cells[p_column].buttons.size());
@@ -4081,10 +4075,6 @@ void Tree::set_cursor_can_exit_tree(bool p_enable) {
cursor_can_exit_tree = p_enable;
}
-bool Tree::can_cursor_exit_tree() const {
- return cursor_can_exit_tree;
-}
-
void Tree::set_hide_folding(bool p_hide) {
hide_folding = p_hide;
update();
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index 4c3d03c91a..82422b8be3 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -227,7 +227,6 @@ public:
int get_button_count(int p_column) const;
String get_button_tooltip(int p_column, int p_idx) const;
Ref<Texture2D> get_button(int p_column, int p_idx) const;
- int get_button_id(int p_column, int p_idx) const;
void erase_button(int p_column, int p_idx);
int get_button_by_id(int p_column, int p_id) const;
void set_button(int p_column, int p_idx, const Ref<Texture2D> &p_button);
@@ -633,7 +632,6 @@ public:
void scroll_to_item(TreeItem *p_item);
void set_cursor_can_exit_tree(bool p_enable);
- bool can_cursor_exit_tree() const;
VScrollBar *get_vscroll_bar() { return v_scroll; }
diff --git a/scene/main/node.h b/scene/main/node.h
index 873c27bc13..024d036fd3 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -74,9 +74,8 @@ public:
private:
struct GroupData {
- bool persistent;
- SceneTree::Group *group;
- GroupData() { persistent = false; }
+ bool persistent = false;
+ SceneTree::Group *group = nullptr;
};
struct NetData {
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 6350777a3d..e496748b2d 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -3824,7 +3824,7 @@ void SubViewport::_bind_methods() {
BIND_ENUM_CONSTANT(CLEAR_MODE_ALWAYS);
BIND_ENUM_CONSTANT(CLEAR_MODE_NEVER);
- BIND_ENUM_CONSTANT(CLEAR_MODE_ONLY_NEXT_FRAME);
+ BIND_ENUM_CONSTANT(CLEAR_MODE_ONCE);
BIND_ENUM_CONSTANT(UPDATE_DISABLED);
BIND_ENUM_CONSTANT(UPDATE_ONCE);
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 7ce202d27c..f08f255dde 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -624,7 +624,7 @@ public:
enum ClearMode {
CLEAR_MODE_ALWAYS,
CLEAR_MODE_NEVER,
- CLEAR_MODE_ONLY_NEXT_FRAME
+ CLEAR_MODE_ONCE
};
enum UpdateMode {
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index d88c8fb3af..ad87139332 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1167,11 +1167,6 @@ Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName
return Control::get_icons(theme_owner, theme_owner_window, p_name, type);
}
-Ref<Shader> Window::get_theme_shader(const StringName &p_name, const StringName &p_type) const {
- StringName type = p_type ? p_type : get_class_name();
- return Control::get_shaders(theme_owner, theme_owner_window, p_name, type);
-}
-
Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
StringName type = p_type ? p_type : get_class_name();
return Control::get_styleboxs(theme_owner, theme_owner_window, p_name, type);
@@ -1202,11 +1197,6 @@ bool Window::has_theme_icon(const StringName &p_name, const StringName &p_type)
return Control::has_icons(theme_owner, theme_owner_window, p_name, type);
}
-bool Window::has_theme_shader(const StringName &p_name, const StringName &p_type) const {
- StringName type = p_type ? p_type : get_class_name();
- return Control::has_shaders(theme_owner, theme_owner_window, p_name, type);
-}
-
bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_type) const {
StringName type = p_type ? p_type : get_class_name();
return Control::has_styleboxs(theme_owner, theme_owner_window, p_name, type);
diff --git a/scene/main/window.h b/scene/main/window.h
index a9a17ab9ba..20f8309952 100644
--- a/scene/main/window.h
+++ b/scene/main/window.h
@@ -253,7 +253,6 @@ public:
Rect2i get_usable_parent_rect() const;
Ref<Texture2D> get_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const;
- Ref<Shader> get_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const;
Ref<StyleBox> get_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const;
Ref<Font> get_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const;
int get_theme_font_size(const StringName &p_name, const StringName &p_type = StringName()) const;
@@ -261,7 +260,6 @@ public:
int get_theme_constant(const StringName &p_name, const StringName &p_type = StringName()) const;
bool has_theme_icon(const StringName &p_name, const StringName &p_type = StringName()) const;
- bool has_theme_shader(const StringName &p_name, const StringName &p_type = StringName()) const;
bool has_theme_stylebox(const StringName &p_name, const StringName &p_type = StringName()) const;
bool has_theme_font(const StringName &p_name, const StringName &p_type = StringName()) const;
bool has_theme_font_size(const StringName &p_name, const StringName &p_type = StringName()) const;
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index a711d28c76..30077aa642 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -118,7 +118,7 @@
#include "scene/gui/tabs.h"
#include "scene/gui/text_edit.h"
#include "scene/gui/texture_button.h"
-#include "scene/gui/texture_progress.h"
+#include "scene/gui/texture_progress_bar.h"
#include "scene/gui/texture_rect.h"
#include "scene/gui/tree.h"
#include "scene/gui/video_player.h"
@@ -234,6 +234,10 @@ static Ref<ResourceFormatLoaderText> resource_loader_text;
static Ref<ResourceFormatLoaderFont> resource_loader_font;
+#ifndef DISABLE_DEPRECATED
+static Ref<ResourceFormatLoaderCompatFont> resource_loader_compat_font;
+#endif /* DISABLE_DEPRECATED */
+
static Ref<ResourceFormatLoaderStreamTexture2D> resource_loader_stream_texture;
static Ref<ResourceFormatLoaderStreamTextureLayered> resource_loader_texture_layered;
static Ref<ResourceFormatLoaderStreamTexture3D> resource_loader_texture_3d;
@@ -251,6 +255,11 @@ void register_scene_types() {
resource_loader_font.instance();
ResourceLoader::add_resource_format_loader(resource_loader_font);
+#ifndef DISABLE_DEPRECATED
+ resource_loader_compat_font.instance();
+ ResourceLoader::add_resource_format_loader(resource_loader_compat_font);
+#endif /* DISABLE_DEPRECATED */
+
resource_loader_stream_texture.instance();
ResourceLoader::add_resource_format_loader(resource_loader_stream_texture);
@@ -340,7 +349,7 @@ void register_scene_types() {
OS::get_singleton()->yield(); //may take time to init
- ClassDB::register_class<TextureProgress>();
+ ClassDB::register_class<TextureProgressBar>();
ClassDB::register_class<ItemList>();
ClassDB::register_class<LineEdit>();
@@ -799,6 +808,9 @@ void register_scene_types() {
#ifndef DISABLE_DEPRECATED
// Dropped in 4.0, near approximation.
ClassDB::add_compatibility_class("AnimationTreePlayer", "AnimationTree");
+ ClassDB::add_compatibility_class("BitmapFont", "Font");
+ ClassDB::add_compatibility_class("DynamicFont", "Font");
+ ClassDB::add_compatibility_class("DynamicFontData", "FontData");
ClassDB::add_compatibility_class("ToolButton", "Button");
// Renamed in 4.0.
@@ -903,6 +915,7 @@ void register_scene_types() {
ClassDB::add_compatibility_class("SpringArm", "SpringArm3D");
ClassDB::add_compatibility_class("Sprite", "Sprite2D");
ClassDB::add_compatibility_class("StaticBody", "StaticBody3D");
+ ClassDB::add_compatibility_class("TextureProgress", "TextureProgressBar");
ClassDB::add_compatibility_class("VehicleBody", "VehicleBody3D");
ClassDB::add_compatibility_class("VehicleWheel", "VehicleWheel3D");
ClassDB::add_compatibility_class("ViewportContainer", "SubViewportContainer");
@@ -918,7 +931,7 @@ void register_scene_types() {
ClassDB::add_compatibility_class("StreamTexture", "StreamTexture2D");
ClassDB::add_compatibility_class("Light2D", "PointLight2D");
-#endif
+#endif /* DISABLE_DEPRECATED */
OS::get_singleton()->yield(); //may take time to init
@@ -970,6 +983,11 @@ void unregister_scene_types() {
ResourceLoader::remove_resource_format_loader(resource_loader_font);
resource_loader_font.unref();
+#ifndef DISABLE_DEPRECATED
+ ResourceLoader::remove_resource_format_loader(resource_loader_compat_font);
+ resource_loader_compat_font.unref();
+#endif /* DISABLE_DEPRECATED */
+
ResourceLoader::remove_resource_format_loader(resource_loader_texture_layered);
resource_loader_texture_layered.unref();
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index b2aad97d3b..a7a02361a9 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -810,8 +810,8 @@ int Animation::transform_track_insert_key(int p_track, float p_time, const Vecto
return ret;
}
-void Animation::track_remove_key_at_position(int p_track, float p_pos) {
- int idx = track_find_key(p_track, p_pos, true);
+void Animation::track_remove_key_at_time(int p_track, float p_time) {
+ int idx = track_find_key(p_track, p_time, true);
ERR_FAIL_COND(idx < 0);
track_remove_key(p_track, idx);
}
@@ -2608,7 +2608,7 @@ void Animation::_bind_methods() {
ClassDB::bind_method(D_METHOD("transform_track_insert_key", "track_idx", "time", "location", "rotation", "scale"), &Animation::transform_track_insert_key);
ClassDB::bind_method(D_METHOD("track_insert_key", "track_idx", "time", "key", "transition"), &Animation::track_insert_key, DEFVAL(1));
ClassDB::bind_method(D_METHOD("track_remove_key", "track_idx", "key_idx"), &Animation::track_remove_key);
- ClassDB::bind_method(D_METHOD("track_remove_key_at_position", "track_idx", "position"), &Animation::track_remove_key_at_position);
+ ClassDB::bind_method(D_METHOD("track_remove_key_at_time", "track_idx", "time"), &Animation::track_remove_key_at_time);
ClassDB::bind_method(D_METHOD("track_set_key_value", "track_idx", "key", "value"), &Animation::track_set_key_value);
ClassDB::bind_method(D_METHOD("track_set_key_transition", "track_idx", "key_idx", "transition"), &Animation::track_set_key_transition);
ClassDB::bind_method(D_METHOD("track_set_key_time", "track_idx", "key_idx", "time"), &Animation::track_set_key_time);
diff --git a/scene/resources/animation.h b/scene/resources/animation.h
index c52431f5f6..060d1fe2d9 100644
--- a/scene/resources/animation.h
+++ b/scene/resources/animation.h
@@ -293,7 +293,7 @@ public:
void track_set_key_time(int p_track, int p_key_idx, float p_time);
int track_find_key(int p_track, float p_time, bool p_exact = false) const;
void track_remove_key(int p_track, int p_idx);
- void track_remove_key_at_position(int p_track, float p_pos);
+ void track_remove_key_at_time(int p_track, float p_time);
int track_get_key_count(int p_track) const;
Variant track_get_key_value(int p_track, int p_key_idx) const;
float track_get_key_time(int p_track, int p_key_idx) const;
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 1d92ed4830..82f6a8ef57 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -571,6 +571,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_color("font_color_accel", "PopupMenu", Color(0.7, 0.7, 0.7, 0.8));
theme->set_color("font_color_disabled", "PopupMenu", Color(0.4, 0.4, 0.4, 0.8));
theme->set_color("font_color_hover", "PopupMenu", control_font_color);
+ theme->set_color("font_color_separator", "PopupMenu", control_font_color);
theme->set_constant("hseparation", "PopupMenu", 4 * scale);
theme->set_constant("vseparation", "PopupMenu", 4 * scale);
@@ -802,6 +803,12 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_font("bold_italics_font", "RichTextLabel", Ref<Font>());
theme->set_font("mono_font", "RichTextLabel", Ref<Font>());
+ theme->set_font_size("normal_font_size", "RichTextLabel", -1);
+ theme->set_font_size("bold_font_size", "RichTextLabel", -1);
+ theme->set_font_size("italics_font_size", "RichTextLabel", -1);
+ theme->set_font_size("bold_italics_font_size", "RichTextLabel", -1);
+ theme->set_font_size("mono_font_size", "RichTextLabel", -1);
+
theme->set_color("default_color", "RichTextLabel", Color(1, 1, 1));
theme->set_color("font_color_selected", "RichTextLabel", font_color_selection);
theme->set_color("selection_color", "RichTextLabel", Color(0.1, 0.1, 1, 0.8));
@@ -816,6 +823,9 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, const
theme->set_constant("table_hseparation", "RichTextLabel", 3 * scale);
theme->set_constant("table_vseparation", "RichTextLabel", 3 * scale);
+ theme->set_color("table_odd_row_bg", "RichTextLabel", Color(0, 0, 0, 0));
+ theme->set_color("table_even_row_bg", "RichTextLabel", Color(0, 0, 0, 0));
+ theme->set_color("table_border", "RichTextLabel", Color(0, 0, 0, 0));
// Containers
theme->set_stylebox("bg", "VSplitContainer", make_stylebox(vsplit_bg_png, 1, 1, 1, 1));
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index 2ed5953b8f..1eb78a3679 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -591,7 +591,7 @@ void Environment::set_glow_level(int p_level, float p_intensity) {
}
float Environment::get_glow_level(int p_level) const {
- ERR_FAIL_INDEX_V(p_level, RS::MAX_GLOW_LEVELS, false);
+ ERR_FAIL_INDEX_V(p_level, RS::MAX_GLOW_LEVELS, 0.0);
return glow_levels[p_level];
}
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index f88082c665..fab8642c20 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -53,6 +53,11 @@ void FontData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_antialiased", "antialiased"), &FontData::set_antialiased);
ClassDB::bind_method(D_METHOD("get_antialiased"), &FontData::get_antialiased);
+ ClassDB::bind_method(D_METHOD("get_variation_list"), &FontData::get_variation_list);
+
+ ClassDB::bind_method(D_METHOD("set_variation", "tag", "value"), &FontData::set_variation);
+ ClassDB::bind_method(D_METHOD("get_variation", "tag"), &FontData::get_variation);
+
ClassDB::bind_method(D_METHOD("set_hinting", "hinting"), &FontData::set_hinting);
ClassDB::bind_method(D_METHOD("get_hinting"), &FontData::get_hinting);
@@ -115,6 +120,11 @@ bool FontData::_set(const StringName &p_name, const Variant &p_value) {
set_script_support_override(scr, p_value);
return true;
}
+ if (str.begins_with("variation/")) {
+ String name = str.get_slicec('/', 1);
+ set_variation(name, p_value);
+ return true;
+ }
return false;
}
@@ -137,6 +147,12 @@ bool FontData::_get(const StringName &p_name, Variant &r_ret) const {
r_ret = get_script_support_override(scr);
return true;
}
+ if (str.begins_with("variation/")) {
+ String name = str.get_slicec('/', 1);
+
+ r_ret = get_variation(name);
+ return true;
+ }
return false;
}
@@ -153,6 +169,12 @@ void FontData::_get_property_list(List<PropertyInfo> *p_list) const {
p_list->push_back(PropertyInfo(Variant::BOOL, "script_support_override/" + scr_over[i], PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE));
}
p_list->push_back(PropertyInfo(Variant::NIL, "script_support_override/_new", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR));
+
+ Dictionary variations = get_variation_list();
+ for (const Variant *ftr = variations.next(nullptr); ftr != nullptr; ftr = variations.next(ftr)) {
+ Vector3i v = variations[*ftr];
+ p_list->push_back(PropertyInfo(Variant::FLOAT, "variation/" + TS->tag_to_name(*ftr), PROPERTY_HINT_RANGE, itos(v.x) + "," + itos(v.y), PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_STORAGE));
+ }
}
RID FontData::get_rid() const {
@@ -239,6 +261,26 @@ float FontData::get_underline_thickness(int p_size) const {
return TS->font_get_underline_thickness(rid, (p_size < 0) ? base_size : p_size);
}
+Dictionary FontData::get_variation_list() const {
+ if (rid == RID()) {
+ return Dictionary();
+ }
+ return TS->font_get_variation_list(rid);
+}
+
+void FontData::set_variation(const String &p_name, double p_value) {
+ ERR_FAIL_COND(rid == RID());
+ TS->font_set_variation(rid, p_name, p_value);
+ emit_changed();
+}
+
+double FontData::get_variation(const String &p_name) const {
+ if (rid == RID()) {
+ return 0;
+ }
+ return TS->font_get_variation(rid, p_name);
+}
+
void FontData::set_antialiased(bool p_antialiased) {
ERR_FAIL_COND(rid == RID());
TS->font_set_antialiased(rid, p_antialiased);
@@ -472,6 +514,32 @@ void Font::_data_changed() {
bool Font::_set(const StringName &p_name, const Variant &p_value) {
String str = p_name;
+#ifndef DISABLE_DEPRECATED
+ if (str == "font_data") { // Compatibility, DynamicFont main data
+ Ref<FontData> fd = p_value;
+ if (fd.is_valid()) {
+ add_data(fd);
+ return true;
+ }
+ return false;
+ } else if (str.begins_with("fallback/")) { // Compatibility, DynamicFont fallback data
+ Ref<FontData> fd = p_value;
+ if (fd.is_valid()) {
+ add_data(fd);
+ return true;
+ }
+ return false;
+ } else if (str == "fallback") { // Compatibility, BitmapFont fallback
+ Ref<Font> f = p_value;
+ if (f.is_valid()) {
+ for (int i = 0; i < f->get_data_count(); i++) {
+ add_data(f->get_data(i));
+ }
+ return true;
+ }
+ return false;
+ }
+#endif /* DISABLE_DEPRECATED */
if (str.begins_with("data/")) {
int idx = str.get_slicec('/', 1).to_int();
Ref<FontData> fd = p_value;
@@ -899,6 +967,23 @@ RES ResourceFormatLoaderFont::load(const String &p_path, const String &p_origina
return dfont;
}
+void ResourceFormatLoaderFont::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
+#ifndef DISABLE_DEPRECATED
+ if (p_type == "DynacmicFontData") {
+ p_extensions->push_back("ttf");
+ p_extensions->push_back("otf");
+ p_extensions->push_back("woff");
+ return;
+ }
+ if (p_type == "BitmapFont") { // BitmapFont (*.font, *fnt) is handled by ResourceFormatLoaderCompatFont
+ return;
+ }
+#endif /* DISABLE_DEPRECATED */
+ if (p_type == "" || handles_type(p_type)) {
+ get_recognized_extensions(p_extensions);
+ }
+}
+
void ResourceFormatLoaderFont::get_recognized_extensions(List<String> *p_extensions) const {
p_extensions->push_back("ttf");
p_extensions->push_back("otf");
@@ -918,3 +1003,45 @@ String ResourceFormatLoaderFont::get_resource_type(const String &p_path) const {
}
return "";
}
+
+#ifndef DISABLE_DEPRECATED
+
+RES ResourceFormatLoaderCompatFont::load(const String &p_path, const String &p_original_path, Error *r_error, bool p_use_sub_threads, float *r_progress, bool p_no_cache) {
+ if (r_error) {
+ *r_error = ERR_FILE_CANT_OPEN;
+ }
+
+ Ref<FontData> dfont;
+ dfont.instance();
+ dfont->load_resource(p_path);
+
+ Ref<Font> font;
+ font.instance();
+ font->add_data(dfont);
+
+ if (r_error) {
+ *r_error = OK;
+ }
+
+ return font;
+}
+
+void ResourceFormatLoaderCompatFont::get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const {
+ if (p_type == "BitmapFont") {
+ p_extensions->push_back("font");
+ p_extensions->push_back("fnt");
+ }
+}
+
+void ResourceFormatLoaderCompatFont::get_recognized_extensions(List<String> *p_extensions) const {
+}
+
+bool ResourceFormatLoaderCompatFont::handles_type(const String &p_type) const {
+ return (p_type == "Font");
+}
+
+String ResourceFormatLoaderCompatFont::get_resource_type(const String &p_path) const {
+ return "";
+}
+
+#endif /* DISABLE_DEPRECATED */
diff --git a/scene/resources/font.h b/scene/resources/font.h
index 226979c4a0..fe28e1aea5 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -68,6 +68,10 @@ public:
float get_descent(int p_size) const;
Dictionary get_feature_list() const;
+ Dictionary get_variation_list() const;
+
+ void set_variation(const String &p_name, double p_value);
+ double get_variation(const String &p_name) const;
float get_underline_position(int p_size) const;
float get_underline_thickness(int p_size) const;
@@ -198,9 +202,23 @@ VARIANT_ENUM_CAST(Font::SpacingType);
class ResourceFormatLoaderFont : public ResourceFormatLoader {
public:
virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
+ virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
+ virtual void get_recognized_extensions(List<String> *p_extensions) const;
+ virtual bool handles_type(const String &p_type) const;
+ virtual String get_resource_type(const String &p_path) const;
+};
+
+#ifndef DISABLE_DEPRECATED
+
+class ResourceFormatLoaderCompatFont : public ResourceFormatLoader {
+public:
+ virtual RES load(const String &p_path, const String &p_original_path = "", Error *r_error = nullptr, bool p_use_sub_threads = false, float *r_progress = nullptr, bool p_no_cache = false);
+ virtual void get_recognized_extensions_for_type(const String &p_type, List<String> *p_extensions) const;
virtual void get_recognized_extensions(List<String> *p_extensions) const;
virtual bool handles_type(const String &p_type) const;
virtual String get_resource_type(const String &p_path) const;
};
-#endif
+#endif /* DISABLE_DEPRECATED */
+
+#endif /* FONT_H */
diff --git a/scene/resources/mesh.cpp b/scene/resources/mesh.cpp
index c6815c8ecc..287ec55560 100644
--- a/scene/resources/mesh.cpp
+++ b/scene/resources/mesh.cpp
@@ -533,6 +533,9 @@ void Mesh::_bind_methods() {
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_2D_VERTICES);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_DYNAMIC_UPDATE);
BIND_ENUM_CONSTANT(ARRAY_FLAG_USE_8_BONE_WEIGHTS);
+
+ BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED);
+ BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE);
}
void Mesh::clear_cache() const {
@@ -1384,7 +1387,7 @@ bool (*array_mesh_lightmap_unwrap_callback)(float p_texel_size, const float *p_v
struct ArrayMeshLightmapSurface {
Ref<Material> material;
- Vector<SurfaceTool::Vertex> vertices;
+ LocalVector<SurfaceTool::Vertex> vertices;
Mesh::PrimitiveType primitive;
uint32_t format;
};
@@ -1425,7 +1428,7 @@ Error ArrayMesh::lightmap_unwrap_cached(int *&r_cache_data, unsigned int &r_cach
Array arrays = surface_get_arrays(i);
s.material = surface_get_material(i);
- s.vertices = SurfaceTool::create_vertex_array_from_triangle_arrays(arrays);
+ SurfaceTool::create_vertex_array_from_triangle_arrays(arrays, s.vertices);
Vector<Vector3> rvertices = arrays[Mesh::ARRAY_VERTEX];
int vc = rvertices.size();
@@ -1612,9 +1615,6 @@ void ArrayMesh::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "_surfaces", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NOEDITOR | PROPERTY_USAGE_INTERNAL), "_set_surfaces", "_get_surfaces");
ADD_PROPERTY(PropertyInfo(Variant::INT, "blend_shape_mode", PROPERTY_HINT_ENUM, "Normalized,Relative"), "set_blend_shape_mode", "get_blend_shape_mode");
ADD_PROPERTY(PropertyInfo(Variant::AABB, "custom_aabb", PROPERTY_HINT_NONE, ""), "set_custom_aabb", "get_custom_aabb");
-
- BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_NORMALIZED);
- BIND_ENUM_CONSTANT(BLEND_SHAPE_MODE_RELATIVE);
}
void ArrayMesh::reload_from_file() {
diff --git a/scene/resources/mesh.h b/scene/resources/mesh.h
index ae2139a0cf..586bb2f802 100644
--- a/scene/resources/mesh.h
+++ b/scene/resources/mesh.h
@@ -53,7 +53,10 @@ public:
NO_INDEX_ARRAY = RenderingServer::NO_INDEX_ARRAY,
ARRAY_WEIGHTS_SIZE = RenderingServer::ARRAY_WEIGHTS_SIZE
};
-
+ enum BlendShapeMode {
+ BLEND_SHAPE_MODE_NORMALIZED = RS::BLEND_SHAPE_MODE_NORMALIZED,
+ BLEND_SHAPE_MODE_RELATIVE = RS::BLEND_SHAPE_MODE_RELATIVE,
+ };
enum ArrayType {
ARRAY_VERTEX = RenderingServer::ARRAY_VERTEX,
ARRAY_NORMAL = RenderingServer::ARRAY_NORMAL,
@@ -171,12 +174,6 @@ class ArrayMesh : public Mesh {
Array _get_surfaces() const;
void _set_surfaces(const Array &p_data);
-public:
- enum BlendShapeMode {
- BLEND_SHAPE_MODE_NORMALIZED = RS::BLEND_SHAPE_MODE_NORMALIZED,
- BLEND_SHAPE_MODE_RELATIVE = RS::BLEND_SHAPE_MODE_RELATIVE,
- };
-
private:
struct Surface {
uint32_t format;
@@ -268,6 +265,6 @@ VARIANT_ENUM_CAST(Mesh::ArrayType);
VARIANT_ENUM_CAST(Mesh::ArrayFormat);
VARIANT_ENUM_CAST(Mesh::ArrayCustomFormat);
VARIANT_ENUM_CAST(Mesh::PrimitiveType);
-VARIANT_ENUM_CAST(ArrayMesh::BlendShapeMode);
+VARIANT_ENUM_CAST(Mesh::BlendShapeMode);
#endif
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index 5ce253f970..09674f3465 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -1481,16 +1481,6 @@ int SceneState::add_name(const StringName &p_name) {
return names.size() - 1;
}
-int SceneState::find_name(const StringName &p_name) const {
- for (int i = 0; i < names.size(); i++) {
- if (names[i] == p_name) {
- return i;
- }
- }
-
- return -1;
-}
-
int SceneState::add_value(const Variant &p_value) {
variants.push_back(p_value);
return variants.size() - 1;
diff --git a/scene/resources/packed_scene.h b/scene/resources/packed_scene.h
index b8b3f84ecc..fce3891507 100644
--- a/scene/resources/packed_scene.h
+++ b/scene/resources/packed_scene.h
@@ -172,7 +172,6 @@ public:
//build API
int add_name(const StringName &p_name);
- int find_name(const StringName &p_name) const;
int add_value(const Variant &p_value);
int add_node_path(const NodePath &p_path);
int add_node(int p_parent, int p_owner, int p_type, int p_name, int p_instance, int p_index);
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index cf8be8fe15..58645dbe65 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -704,7 +704,6 @@ ResourceLoaderText::ResourceLoaderText() {
resources_total = 0;
resource_current = 0;
- use_sub_threads = false;
progress = nullptr;
lines = false;
diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp
index 69e8e0b5bd..05bb13a1e0 100644
--- a/scene/resources/sky_material.cpp
+++ b/scene/resources/sky_material.cpp
@@ -568,7 +568,7 @@ PhysicalSkyMaterial::PhysicalSkyMaterial() {
code += "\tCOLOR = pow(color, vec3(1.0 / (1.2 + (1.2 * sun_fade))));\n";
code += "\tCOLOR *= exposure;\n";
code += "\t// Make optional, eliminates banding\n";
- code += "\tCOLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.008 * dither_strength;\n";
+ code += "\tCOLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.016 * dither_strength;\n";
code += "}\n";
shader = RS::get_singleton()->shader_create();
diff --git a/scene/resources/style_box.cpp b/scene/resources/style_box.cpp
index a8bf44c5c0..14197c6c68 100644
--- a/scene/resources/style_box.cpp
+++ b/scene/resources/style_box.cpp
@@ -404,16 +404,6 @@ void StyleBoxFlat::set_corner_radius_individual(const int radius_top_left, const
emit_changed();
}
-int StyleBoxFlat::get_corner_radius_min() const {
- int smallest = corner_radius[0];
- for (int i = 1; i < 4; i++) {
- if (smallest > corner_radius[i]) {
- smallest = corner_radius[i];
- }
- }
- return smallest;
-}
-
void StyleBoxFlat::set_corner_radius(const Corner p_corner, const int radius) {
ERR_FAIL_INDEX((int)p_corner, 4);
corner_radius[p_corner] = radius;
diff --git a/scene/resources/style_box.h b/scene/resources/style_box.h
index a1237776c6..7dd806e840 100644
--- a/scene/resources/style_box.h
+++ b/scene/resources/style_box.h
@@ -184,7 +184,6 @@ public:
//CORNER
void set_corner_radius_all(int radius);
void set_corner_radius_individual(const int radius_top_left, const int radius_top_right, const int radius_botton_right, const int radius_bottom_left);
- int get_corner_radius_min() const;
void set_corner_radius(Corner p_corner, const int radius);
int get_corner_radius(Corner p_corner) const;
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index 3166067573..129f8a48ce 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -33,6 +33,9 @@
#define _VERTEX_SNAP 0.0001
#define EQ_VERTEX_DIST 0.00001
+SurfaceTool::OptimizeVertexCacheFunc SurfaceTool::optimize_vertex_cache_func = nullptr;
+SurfaceTool::SimplifyFunc SurfaceTool::simplify_func = nullptr;
+
bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const {
if (vertex != p_vertex.vertex) {
return false;
@@ -74,12 +77,16 @@ bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const {
}
}
- for (int i = 0; i < RS::ARRAY_CUSTOM_MAX; i++) {
+ for (int i = 0; i < RS::ARRAY_CUSTOM_COUNT; i++) {
if (custom[i] != p_vertex.custom[i]) {
return false;
}
}
+ if (smooth_group != p_vertex.smooth_group) {
+ return false;
+ }
+
return true;
}
@@ -94,6 +101,7 @@ uint32_t SurfaceTool::VertexHasher::hash(const Vertex &p_vtx) {
h = hash_djb2_buffer((const uint8_t *)p_vtx.bones.ptr(), p_vtx.bones.size() * sizeof(int), h);
h = hash_djb2_buffer((const uint8_t *)p_vtx.weights.ptr(), p_vtx.weights.size() * sizeof(float), h);
h = hash_djb2_buffer((const uint8_t *)&p_vtx.custom[0], sizeof(Color) * RS::ARRAY_CUSTOM_COUNT, h);
+ h = hash_djb2_one_32(p_vtx.smooth_group, h);
return h;
}
@@ -118,6 +126,8 @@ void SurfaceTool::add_vertex(const Vector3 &p_vertex) {
vtx.bones = last_bones;
vtx.tangent = last_tangent.normal;
vtx.binormal = last_normal.cross(last_tangent.normal).normalized() * last_tangent.d;
+ vtx.smooth_group = last_smooth_group;
+
for (int i = 0; i < RS::ARRAY_CUSTOM_COUNT; i++) {
vtx.custom[i] = last_custom[i];
}
@@ -252,13 +262,8 @@ void SurfaceTool::set_weights(const Vector<float> &p_weights) {
last_weights = p_weights;
}
-void SurfaceTool::add_smooth_group(bool p_smooth) {
- ERR_FAIL_COND(!begun);
- if (index_array.size()) {
- smooth_groups[index_array.size()] = p_smooth;
- } else {
- smooth_groups[vertex_array.size()] = p_smooth;
- }
+void SurfaceTool::set_smooth_group(uint32_t p_group) {
+ last_smooth_group = p_group;
}
void SurfaceTool::add_triangle_fan(const Vector<Vector3> &p_vertices, const Vector<Vector2> &p_uvs, const Vector<Color> &p_colors, const Vector<Vector2> &p_uv2s, const Vector<Vector3> &p_normals, const Vector<Plane> &p_tangents) {
@@ -315,9 +320,8 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len);
Vector3 *w = array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
switch (i) {
case Mesh::ARRAY_VERTEX: {
@@ -339,9 +343,8 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len);
Vector2 *w = array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
switch (i) {
case Mesh::ARRAY_TEX_UV: {
@@ -360,9 +363,8 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * 4);
float *w = array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx += 4) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
w[idx + 0] = v.tangent.x;
w[idx + 1] = v.tangent.y;
@@ -381,9 +383,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len);
Color *w = array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
w[idx] = v.color;
}
@@ -400,9 +402,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * 4);
uint8_t *w = array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
const Color &c = v.custom[idx];
w[idx * 4 + 0] = CLAMP(int32_t(c.r * 255.0), 0, 255);
w[idx * 4 + 1] = CLAMP(int32_t(c.g * 255.0), 0, 255);
@@ -417,9 +419,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * 4);
uint8_t *w = array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
const Color &c = v.custom[idx];
w[idx * 4 + 0] = uint8_t(int8_t(CLAMP(int32_t(c.r * 127.0), -128, 127)));
w[idx * 4 + 1] = uint8_t(int8_t(CLAMP(int32_t(c.g * 127.0), -128, 127)));
@@ -434,9 +436,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * 4);
uint16_t *w = (uint16_t *)array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
const Color &c = v.custom[idx];
w[idx * 2 + 0] = Math::make_half_float(c.r);
w[idx * 2 + 1] = Math::make_half_float(c.g);
@@ -449,9 +451,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * 8);
uint16_t *w = (uint16_t *)array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
const Color &c = v.custom[idx];
w[idx * 4 + 0] = Math::make_half_float(c.r);
w[idx * 4 + 1] = Math::make_half_float(c.g);
@@ -466,9 +468,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len);
float *w = (float *)array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
const Color &c = v.custom[idx];
w[idx] = c.r;
}
@@ -480,9 +482,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * 2);
float *w = (float *)array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
const Color &c = v.custom[idx];
w[idx * 2 + 0] = c.r;
w[idx * 2 + 1] = c.g;
@@ -495,9 +497,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * 3);
float *w = (float *)array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
const Color &c = v.custom[idx];
w[idx * 3 + 0] = c.r;
w[idx * 3 + 1] = c.g;
@@ -511,9 +513,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * 4);
float *w = (float *)array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx++) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
const Color &c = v.custom[idx];
w[idx * 4 + 0] = c.r;
w[idx * 4 + 1] = c.g;
@@ -533,9 +535,8 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * count);
int *w = array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx += count) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
ERR_CONTINUE(v.bones.size() != count);
@@ -554,9 +555,9 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(varr_len * count);
float *w = array.ptrw();
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next(), idx += count) {
- const Vertex &v = E->get();
+ for (uint32_t idx = 0; idx < vertex_array.size(); idx++) {
+ const Vertex &v = vertex_array[idx];
+
ERR_CONTINUE(v.weights.size() != count);
for (int j = 0; j < count; j++) {
@@ -574,9 +575,8 @@ Array SurfaceTool::commit_to_arrays() {
array.resize(index_array.size());
int *w = array.ptrw();
- int idx = 0;
- for (List<int>::Element *E = index_array.front(); E; E = E->next(), idx++) {
- w[idx] = E->get();
+ for (uint32_t idx = 0; idx < index_array.size(); idx++) {
+ w[idx] = index_array[idx];
}
a[i] = array;
@@ -623,15 +623,16 @@ void SurfaceTool::index() {
}
HashMap<Vertex, int, VertexHasher> indices;
- List<Vertex> new_vertices;
+ LocalVector<Vertex> old_vertex_array = vertex_array;
+ vertex_array.clear();
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) {
- int *idxptr = indices.getptr(E->get());
+ for (uint32_t i = 0; i < old_vertex_array.size(); i++) {
+ int *idxptr = indices.getptr(old_vertex_array[i]);
int idx;
if (!idxptr) {
idx = indices.size();
- new_vertices.push_back(E->get());
- indices[E->get()] = idx;
+ vertex_array.push_back(old_vertex_array[i]);
+ indices[old_vertex_array[i]] = idx;
} else {
idx = *idxptr;
}
@@ -639,9 +640,6 @@ void SurfaceTool::index() {
index_array.push_back(idx);
}
- vertex_array.clear();
- vertex_array = new_vertices;
-
format |= Mesh::ARRAY_FORMAT_INDEX;
}
@@ -649,29 +647,26 @@ void SurfaceTool::deindex() {
if (index_array.size() == 0) {
return; //nothing to deindex
}
- Vector<Vertex> varr;
- varr.resize(vertex_array.size());
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) {
- varr.write[idx++] = E->get();
- }
+
+ LocalVector<Vertex> old_vertex_array = vertex_array;
vertex_array.clear();
- for (List<int>::Element *E = index_array.front(); E; E = E->next()) {
- ERR_FAIL_INDEX(E->get(), varr.size());
- vertex_array.push_back(varr[E->get()]);
+ for (uint32_t i = 0; i < index_array.size(); i++) {
+ uint32_t index = index_array[i];
+ ERR_FAIL_COND(index >= old_vertex_array.size());
+ vertex_array.push_back(old_vertex_array[index]);
}
format &= ~Mesh::ARRAY_FORMAT_INDEX;
index_array.clear();
}
-void SurfaceTool::_create_list(const Ref<Mesh> &p_existing, int p_surface, List<Vertex> *r_vertex, List<int> *r_index, uint32_t &lformat) {
+void SurfaceTool::_create_list(const Ref<Mesh> &p_existing, int p_surface, LocalVector<Vertex> *r_vertex, LocalVector<int> *r_index, uint32_t &lformat) {
Array arr = p_existing->surface_get_arrays(p_surface);
ERR_FAIL_COND(arr.size() != RS::ARRAY_MAX);
_create_list_from_arrays(arr, r_vertex, r_index, lformat);
}
-Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_arrays(const Array &p_arrays, uint32_t *r_format) {
- Vector<SurfaceTool::Vertex> ret;
+void SurfaceTool::create_vertex_array_from_triangle_arrays(const Array &p_arrays, LocalVector<SurfaceTool::Vertex> &ret, uint32_t *r_format) {
+ ret.clear();
Vector<Vector3> varr = p_arrays[RS::ARRAY_VERTEX];
Vector<Vector3> narr = p_arrays[RS::ARRAY_NORMAL];
@@ -688,7 +683,7 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array
if (r_format) {
*r_format = 0;
}
- return ret;
+ return;
}
int lformat = 0;
@@ -799,19 +794,14 @@ Vector<SurfaceTool::Vertex> SurfaceTool::create_vertex_array_from_triangle_array
if (r_format) {
*r_format = lformat;
}
-
- return ret;
}
-void SurfaceTool::_create_list_from_arrays(Array arr, List<Vertex> *r_vertex, List<int> *r_index, uint32_t &lformat) {
- Vector<Vertex> arrays = create_vertex_array_from_triangle_arrays(arr, &lformat);
- ERR_FAIL_COND(arrays.size() == 0);
-
- for (int i = 0; i < arrays.size(); i++) {
- r_vertex->push_back(arrays[i]);
- }
+void SurfaceTool::_create_list_from_arrays(Array arr, LocalVector<Vertex> *r_vertex, LocalVector<int> *r_index, uint32_t &lformat) {
+ create_vertex_array_from_triangle_arrays(arr, *r_vertex, &lformat);
+ ERR_FAIL_COND(r_vertex->size() == 0);
//indices
+ r_index->clear();
Vector<int> idx = arr[RS::ARRAY_INDEX];
int is = idx.size();
@@ -864,14 +854,14 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const
}
uint32_t nformat;
- List<Vertex> nvertices;
- List<int> nindices;
+ LocalVector<Vertex> nvertices;
+ LocalVector<int> nindices;
_create_list(p_existing, p_surface, &nvertices, &nindices, nformat);
format |= nformat;
int vfrom = vertex_array.size();
- for (List<Vertex>::Element *E = nvertices.front(); E; E = E->next()) {
- Vertex v = E->get();
+ for (uint32_t vi = 0; vi < nvertices.size(); vi++) {
+ Vertex v = nvertices[vi];
v.vertex = p_xform.xform(v.vertex);
if (nformat & RS::ARRAY_FORMAT_NORMAL) {
v.normal = p_xform.basis.xform(v.normal);
@@ -884,8 +874,8 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const
vertex_array.push_back(v);
}
- for (List<int>::Element *E = nindices.front(); E; E = E->next()) {
- int dst_index = E->get() + vfrom;
+ for (uint32_t i = 0; i < nindices.size(); i++) {
+ int dst_index = nindices[i] + vfrom;
index_array.push_back(dst_index);
}
if (index_array.size() % 3) {
@@ -896,18 +886,18 @@ void SurfaceTool::append_from(const Ref<Mesh> &p_existing, int p_surface, const
//mikktspace callbacks
namespace {
struct TangentGenerationContextUserData {
- Vector<List<SurfaceTool::Vertex>::Element *> vertices;
- Vector<List<int>::Element *> indices;
+ LocalVector<SurfaceTool::Vertex> *vertices;
+ LocalVector<int> *indices;
};
} // namespace
int SurfaceTool::mikktGetNumFaces(const SMikkTSpaceContext *pContext) {
TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData);
- if (triangle_data.indices.size() > 0) {
- return triangle_data.indices.size() / 3;
+ if (triangle_data.indices->size() > 0) {
+ return triangle_data.indices->size() / 3;
} else {
- return triangle_data.vertices.size() / 3;
+ return triangle_data.vertices->size() / 3;
}
}
@@ -918,13 +908,13 @@ int SurfaceTool::mikktGetNumVerticesOfFace(const SMikkTSpaceContext *pContext, c
void SurfaceTool::mikktGetPosition(const SMikkTSpaceContext *pContext, float fvPosOut[], const int iFace, const int iVert) {
TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData);
Vector3 v;
- if (triangle_data.indices.size() > 0) {
- int index = triangle_data.indices[iFace * 3 + iVert]->get();
- if (index < triangle_data.vertices.size()) {
- v = triangle_data.vertices[index]->get().vertex;
+ if (triangle_data.indices->size() > 0) {
+ uint32_t index = triangle_data.indices->operator[](iFace * 3 + iVert);
+ if (index < triangle_data.vertices->size()) {
+ v = triangle_data.vertices->operator[](index).vertex;
}
} else {
- v = triangle_data.vertices[iFace * 3 + iVert]->get().vertex;
+ v = triangle_data.vertices->operator[](iFace * 3 + iVert).vertex;
}
fvPosOut[0] = v.x;
@@ -935,13 +925,13 @@ void SurfaceTool::mikktGetPosition(const SMikkTSpaceContext *pContext, float fvP
void SurfaceTool::mikktGetNormal(const SMikkTSpaceContext *pContext, float fvNormOut[], const int iFace, const int iVert) {
TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData);
Vector3 v;
- if (triangle_data.indices.size() > 0) {
- int index = triangle_data.indices[iFace * 3 + iVert]->get();
- if (index < triangle_data.vertices.size()) {
- v = triangle_data.vertices[index]->get().normal;
+ if (triangle_data.indices->size() > 0) {
+ uint32_t index = triangle_data.indices->operator[](iFace * 3 + iVert);
+ if (index < triangle_data.vertices->size()) {
+ v = triangle_data.vertices->operator[](index).normal;
}
} else {
- v = triangle_data.vertices[iFace * 3 + iVert]->get().normal;
+ v = triangle_data.vertices->operator[](iFace * 3 + iVert).normal;
}
fvNormOut[0] = v.x;
@@ -952,13 +942,13 @@ void SurfaceTool::mikktGetNormal(const SMikkTSpaceContext *pContext, float fvNor
void SurfaceTool::mikktGetTexCoord(const SMikkTSpaceContext *pContext, float fvTexcOut[], const int iFace, const int iVert) {
TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData);
Vector2 v;
- if (triangle_data.indices.size() > 0) {
- int index = triangle_data.indices[iFace * 3 + iVert]->get();
- if (index < triangle_data.vertices.size()) {
- v = triangle_data.vertices[index]->get().uv;
+ if (triangle_data.indices->size() > 0) {
+ uint32_t index = triangle_data.indices->operator[](iFace * 3 + iVert);
+ if (index < triangle_data.vertices->size()) {
+ v = triangle_data.vertices->operator[](index).uv;
}
} else {
- v = triangle_data.vertices[iFace * 3 + iVert]->get().uv;
+ v = triangle_data.vertices->operator[](iFace * 3 + iVert).uv;
}
fvTexcOut[0] = v.x;
@@ -969,13 +959,13 @@ void SurfaceTool::mikktSetTSpaceDefault(const SMikkTSpaceContext *pContext, cons
const tbool bIsOrientationPreserving, const int iFace, const int iVert) {
TangentGenerationContextUserData &triangle_data = *reinterpret_cast<TangentGenerationContextUserData *>(pContext->m_pUserData);
Vertex *vtx = nullptr;
- if (triangle_data.indices.size() > 0) {
- int index = triangle_data.indices[iFace * 3 + iVert]->get();
- if (index < triangle_data.vertices.size()) {
- vtx = &triangle_data.vertices[index]->get();
+ if (triangle_data.indices->size() > 0) {
+ uint32_t index = triangle_data.indices->operator[](iFace * 3 + iVert);
+ if (index < triangle_data.vertices->size()) {
+ vtx = &triangle_data.vertices->operator[](index);
}
} else {
- vtx = &triangle_data.vertices[iFace * 3 + iVert]->get();
+ vtx = &triangle_data.vertices->operator[](iFace * 3 + iVert);
}
if (vtx != nullptr) {
@@ -1001,18 +991,12 @@ void SurfaceTool::generate_tangents() {
msc.m_pInterface = &mkif;
TangentGenerationContextUserData triangle_data;
- triangle_data.vertices.resize(vertex_array.size());
- int idx = 0;
- for (List<Vertex>::Element *E = vertex_array.front(); E; E = E->next()) {
- triangle_data.vertices.write[idx++] = E;
- E->get().binormal = Vector3();
- E->get().tangent = Vector3();
- }
- triangle_data.indices.resize(index_array.size());
- idx = 0;
- for (List<int>::Element *E = index_array.front(); E; E = E->next()) {
- triangle_data.indices.write[idx++] = E;
+ triangle_data.vertices = &vertex_array;
+ for (uint32_t i = 0; i < vertex_array.size(); i++) {
+ vertex_array[i].binormal = Vector3();
+ vertex_array[i].tangent = Vector3();
}
+ triangle_data.indices = &index_array;
msc.m_pUserData = &triangle_data;
bool res = genTangSpaceDefault(&msc);
@@ -1028,66 +1012,36 @@ void SurfaceTool::generate_normals(bool p_flip) {
deindex();
- HashMap<Vertex, Vector3, VertexHasher> vertex_hash;
+ ERR_FAIL_COND((vertex_array.size() % 3) != 0);
- int count = 0;
- bool smooth = false;
- if (smooth_groups.has(0)) {
- smooth = smooth_groups[0];
- }
+ HashMap<Vertex, Vector3, VertexHasher> vertex_hash;
- List<Vertex>::Element *B = vertex_array.front();
- for (List<Vertex>::Element *E = B; E;) {
- List<Vertex>::Element *v[3];
- v[0] = E;
- v[1] = v[0]->next();
- ERR_FAIL_COND(!v[1]);
- v[2] = v[1]->next();
- ERR_FAIL_COND(!v[2]);
- E = v[2]->next();
+ for (uint32_t vi = 0; vi < vertex_array.size(); vi += 3) {
+ Vertex *v = &vertex_array[vi];
Vector3 normal;
if (!p_flip) {
- normal = Plane(v[0]->get().vertex, v[1]->get().vertex, v[2]->get().vertex).normal;
+ normal = Plane(v[0].vertex, v[1].vertex, v[2].vertex).normal;
} else {
- normal = Plane(v[2]->get().vertex, v[1]->get().vertex, v[0]->get().vertex).normal;
+ normal = Plane(v[2].vertex, v[1].vertex, v[0].vertex).normal;
}
- if (smooth) {
- for (int i = 0; i < 3; i++) {
- Vector3 *lv = vertex_hash.getptr(v[i]->get());
- if (!lv) {
- vertex_hash.set(v[i]->get(), normal);
- } else {
- (*lv) += normal;
- }
- }
- } else {
- for (int i = 0; i < 3; i++) {
- v[i]->get().normal = normal;
- }
- }
- count += 3;
-
- if (smooth_groups.has(count) || !E) {
- if (vertex_hash.size()) {
- while (B != E) {
- Vector3 *lv = vertex_hash.getptr(B->get());
- if (lv) {
- B->get().normal = lv->normalized();
- }
-
- B = B->next();
- }
-
+ for (int i = 0; i < 3; i++) {
+ Vector3 *lv = vertex_hash.getptr(v[i]);
+ if (!lv) {
+ vertex_hash.set(v[i], normal);
} else {
- B = E;
+ (*lv) += normal;
}
+ }
+ }
- vertex_hash.clear();
- if (E) {
- smooth = smooth_groups[count];
- }
+ for (uint32_t vi = 0; vi < vertex_array.size(); vi++) {
+ Vector3 *lv = vertex_hash.getptr(vertex_array[vi]);
+ if (!lv) {
+ vertex_array[vi].normal = Vector3();
+ } else {
+ vertex_array[vi].normal = lv->normalized();
}
}
@@ -1095,7 +1049,6 @@ void SurfaceTool::generate_normals(bool p_flip) {
if (was_indexed) {
index();
- smooth_groups.clear();
}
}
@@ -1111,8 +1064,8 @@ void SurfaceTool::clear() {
last_weights.clear();
index_array.clear();
vertex_array.clear();
- smooth_groups.clear();
material.unref();
+ last_smooth_group = 0;
for (int i = 0; i < RS::ARRAY_CUSTOM_COUNT; i++) {
last_custom_format[i] = CUSTOM_MAX;
}
@@ -1136,6 +1089,51 @@ SurfaceTool::CustomFormat SurfaceTool::get_custom_format(int p_index) const {
ERR_FAIL_INDEX_V(p_index, RS::ARRAY_CUSTOM_COUNT, CUSTOM_MAX);
return last_custom_format[p_index];
}
+void SurfaceTool::optimize_indices_for_cache() {
+ ERR_FAIL_COND(optimize_vertex_cache_func == nullptr);
+ ERR_FAIL_COND(index_array.size() == 0);
+
+ LocalVector old_index_array = index_array;
+ zeromem(index_array.ptr(), index_array.size() * sizeof(int));
+ optimize_vertex_cache_func((unsigned int *)index_array.ptr(), (unsigned int *)old_index_array.ptr(), old_index_array.size(), vertex_array.size());
+}
+
+float SurfaceTool::get_max_axis_length() const {
+ ERR_FAIL_COND_V(vertex_array.size() == 0, 0);
+
+ AABB aabb;
+ for (uint32_t i = 0; i < vertex_array.size(); i++) {
+ if (i == 0) {
+ aabb.position = vertex_array[i].vertex;
+ } else {
+ aabb.expand_to(vertex_array[i].vertex);
+ }
+ }
+
+ return aabb.get_longest_axis_size();
+}
+Vector<int> SurfaceTool::generate_lod(float p_threshold, int p_target_index_count) {
+ Vector<int> lod;
+
+ ERR_FAIL_COND_V(simplify_func == nullptr, lod);
+ ERR_FAIL_COND_V(vertex_array.size() == 0, lod);
+ ERR_FAIL_COND_V(index_array.size() == 0, lod);
+
+ lod.resize(index_array.size());
+ LocalVector<float> vertices; //uses floats
+ vertices.resize(vertex_array.size() * 3);
+ for (uint32_t i = 0; i < vertex_array.size(); i++) {
+ vertices[i * 3 + 0] = vertex_array[i].vertex.x;
+ vertices[i * 3 + 1] = vertex_array[i].vertex.y;
+ vertices[i * 3 + 2] = vertex_array[i].vertex.z;
+ }
+
+ uint32_t index_count = simplify_func((unsigned int *)lod.ptrw(), (unsigned int *)index_array.ptr(), index_array.size(), vertices.ptr(), vertex_array.size(), sizeof(float) * 3, p_target_index_count, p_threshold);
+ ERR_FAIL_COND_V(index_count == 0, lod);
+ lod.resize(index_count);
+
+ return lod;
+}
void SurfaceTool::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_skin_weight_count", "count"), &SurfaceTool::set_skin_weight_count);
@@ -1155,7 +1153,7 @@ void SurfaceTool::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_bones", "bones"), &SurfaceTool::set_bones);
ClassDB::bind_method(D_METHOD("set_weights", "weights"), &SurfaceTool::set_weights);
ClassDB::bind_method(D_METHOD("set_custom", "index", "custom"), &SurfaceTool::set_custom);
- ClassDB::bind_method(D_METHOD("add_smooth_group", "smooth"), &SurfaceTool::add_smooth_group);
+ ClassDB::bind_method(D_METHOD("set_smooth_group", "index"), &SurfaceTool::set_smooth_group);
ClassDB::bind_method(D_METHOD("add_triangle_fan", "vertices", "uvs", "colors", "uv2s", "normals", "tangents"), &SurfaceTool::add_triangle_fan, DEFVAL(Vector<Vector2>()), DEFVAL(Vector<Color>()), DEFVAL(Vector<Vector2>()), DEFVAL(Vector<Vector3>()), DEFVAL(Vector<Plane>()));
@@ -1166,6 +1164,11 @@ void SurfaceTool::_bind_methods() {
ClassDB::bind_method(D_METHOD("generate_normals", "flip"), &SurfaceTool::generate_normals, DEFVAL(false));
ClassDB::bind_method(D_METHOD("generate_tangents"), &SurfaceTool::generate_tangents);
+ ClassDB::bind_method(D_METHOD("optimize_indices_for_cache"), &SurfaceTool::optimize_indices_for_cache);
+
+ ClassDB::bind_method(D_METHOD("get_max_axis_length"), &SurfaceTool::get_max_axis_length);
+ ClassDB::bind_method(D_METHOD("generate_lod", "nd_threshold", "target_index_count"), &SurfaceTool::generate_lod, DEFVAL(3));
+
ClassDB::bind_method(D_METHOD("set_material", "material"), &SurfaceTool::set_material);
ClassDB::bind_method(D_METHOD("clear"), &SurfaceTool::clear);
diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h
index 4a5c7d990c..e80a5339a9 100644
--- a/scene/resources/surface_tool.h
+++ b/scene/resources/surface_tool.h
@@ -31,8 +31,8 @@
#ifndef SURFACE_TOOL_H
#define SURFACE_TOOL_H
+#include "core/templates/local_vector.h"
#include "scene/resources/mesh.h"
-
#include "thirdparty/misc/mikktspace.h"
class SurfaceTool : public Reference {
@@ -50,6 +50,7 @@ public:
Vector<int> bones;
Vector<float> weights;
Color custom[RS::ARRAY_CUSTOM_COUNT];
+ uint32_t smooth_group = 0;
bool operator==(const Vertex &p_vertex) const;
@@ -73,6 +74,11 @@ public:
SKIN_8_WEIGHTS
};
+ typedef void (*OptimizeVertexCacheFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, size_t vertex_count);
+ static OptimizeVertexCacheFunc optimize_vertex_cache_func;
+ typedef size_t (*SimplifyFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, const float *vertex_positions, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error);
+ static SimplifyFunc simplify_func;
+
private:
struct VertexHasher {
static _FORCE_INLINE_ uint32_t hash(const Vertex &p_vtx);
@@ -92,9 +98,8 @@ private:
uint32_t format;
Ref<Material> material;
//arrays
- List<Vertex> vertex_array;
- List<int> index_array;
- Map<int, bool> smooth_groups;
+ LocalVector<Vertex> vertex_array;
+ LocalVector<int> index_array;
//memory
Color last_color;
@@ -104,6 +109,7 @@ private:
Vector<int> last_bones;
Vector<float> last_weights;
Plane last_tangent;
+ uint32_t last_smooth_group = 0;
SkinWeightCount skin_weights;
@@ -111,8 +117,8 @@ private:
CustomFormat last_custom_format[RS::ARRAY_CUSTOM_COUNT];
- void _create_list_from_arrays(Array arr, List<Vertex> *r_vertex, List<int> *r_index, uint32_t &lformat);
- void _create_list(const Ref<Mesh> &p_existing, int p_surface, List<Vertex> *r_vertex, List<int> *r_index, uint32_t &lformat);
+ void _create_list_from_arrays(Array arr, LocalVector<Vertex> *r_vertex, LocalVector<int> *r_index, uint32_t &lformat);
+ void _create_list(const Ref<Mesh> &p_existing, int p_surface, LocalVector<Vertex> *r_vertex, LocalVector<int> *r_index, uint32_t &lformat);
//mikktspace callbacks
static int mikktGetNumFaces(const SMikkTSpaceContext *pContext);
@@ -143,10 +149,10 @@ public:
void set_custom(int p_index, const Color &p_custom);
void set_bones(const Vector<int> &p_bones);
void set_weights(const Vector<float> &p_weights);
+ void set_smooth_group(uint32_t p_group);
void add_vertex(const Vector3 &p_vertex);
- void add_smooth_group(bool p_smooth);
void add_triangle_fan(const Vector<Vector3> &p_vertices, const Vector<Vector2> &p_uvs = Vector<Vector2>(), const Vector<Color> &p_colors = Vector<Color>(), const Vector<Vector2> &p_uv2s = Vector<Vector2>(), const Vector<Vector3> &p_normals = Vector<Vector3>(), const Vector<Plane> &p_tangents = Vector<Plane>());
void add_index(int p_index);
@@ -156,14 +162,18 @@ public:
void generate_normals(bool p_flip = false);
void generate_tangents();
+ void optimize_indices_for_cache();
+ float get_max_axis_length() const;
+ Vector<int> generate_lod(float p_threshold, int p_target_index_count = 3);
+
void set_material(const Ref<Material> &p_material);
void clear();
- List<Vertex> &get_vertex_array() { return vertex_array; }
+ LocalVector<Vertex> &get_vertex_array() { return vertex_array; }
void create_from_triangle_arrays(const Array &p_arrays);
- static Vector<Vertex> create_vertex_array_from_triangle_arrays(const Array &p_arrays, uint32_t *r_format = nullptr);
+ static void create_vertex_array_from_triangle_arrays(const Array &p_arrays, LocalVector<Vertex> &ret, uint32_t *r_format = nullptr);
Array commit_to_arrays();
void create_from(const Ref<Mesh> &p_existing, int p_surface);
void create_from_blend_shape(const Ref<Mesh> &p_existing, int p_surface, const String &p_blend_shape_name);
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index d130470275..6a752d32e7 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -421,52 +421,6 @@ void Theme::get_icon_list(StringName p_node_type, List<StringName> *p_list) cons
}
}
-void Theme::set_shader(const StringName &p_name, const StringName &p_node_type, const Ref<Shader> &p_shader) {
- bool new_value = !shader_map.has(p_node_type) || !shader_map[p_node_type].has(p_name);
-
- shader_map[p_node_type][p_name] = p_shader;
-
- if (new_value) {
- _change_notify();
- emit_changed();
- }
-}
-
-Ref<Shader> Theme::get_shader(const StringName &p_name, const StringName &p_node_type) const {
- if (shader_map.has(p_node_type) && shader_map[p_node_type].has(p_name) && shader_map[p_node_type][p_name].is_valid()) {
- return shader_map[p_node_type][p_name];
- } else {
- return nullptr;
- }
-}
-
-bool Theme::has_shader(const StringName &p_name, const StringName &p_node_type) const {
- return (shader_map.has(p_node_type) && shader_map[p_node_type].has(p_name) && shader_map[p_node_type][p_name].is_valid());
-}
-
-void Theme::clear_shader(const StringName &p_name, const StringName &p_node_type) {
- ERR_FAIL_COND(!shader_map.has(p_node_type));
- ERR_FAIL_COND(!shader_map[p_node_type].has(p_name));
-
- shader_map[p_node_type].erase(p_name);
- _change_notify();
- emit_changed();
-}
-
-void Theme::get_shader_list(const StringName &p_node_type, List<StringName> *p_list) const {
- ERR_FAIL_NULL(p_list);
-
- if (!shader_map.has(p_node_type)) {
- return;
- }
-
- const StringName *key = nullptr;
-
- while ((key = shader_map[p_node_type].next(key))) {
- p_list->push_back(*key);
- }
-}
-
void Theme::set_stylebox(const StringName &p_name, const StringName &p_node_type, const Ref<StyleBox> &p_style) {
//ERR_FAIL_COND(p_style.is_null());
@@ -782,7 +736,6 @@ void Theme::clear() {
icon_map.clear();
style_map.clear();
font_map.clear();
- shader_map.clear();
color_map.clear();
constant_map.clear();
@@ -837,7 +790,6 @@ void Theme::copy_theme(const Ref<Theme> &p_other) {
color_map = p_other->color_map;
constant_map = p_other->constant_map;
- shader_map = p_other->shader_map;
_change_notify();
emit_changed();
diff --git a/scene/resources/theme.h b/scene/resources/theme.h
index 4175e19112..6ac47e8931 100644
--- a/scene/resources/theme.h
+++ b/scene/resources/theme.h
@@ -34,7 +34,6 @@
#include "core/io/resource.h"
#include "core/io/resource_loader.h"
#include "scene/resources/font.h"
-#include "scene/resources/shader.h"
#include "scene/resources/style_box.h"
#include "scene/resources/texture.h"
@@ -48,7 +47,6 @@ class Theme : public Resource {
HashMap<StringName, HashMap<StringName, Ref<StyleBox>>> style_map;
HashMap<StringName, HashMap<StringName, Ref<Font>>> font_map;
HashMap<StringName, HashMap<StringName, int>> font_size_map;
- HashMap<StringName, HashMap<StringName, Ref<Shader>>> shader_map;
HashMap<StringName, HashMap<StringName, Color>> color_map;
HashMap<StringName, HashMap<StringName, int>> constant_map;
@@ -102,12 +100,6 @@ public:
void clear_icon(const StringName &p_name, const StringName &p_node_type);
void get_icon_list(StringName p_node_type, List<StringName> *p_list) const;
- void set_shader(const StringName &p_name, const StringName &p_node_type, const Ref<Shader> &p_shader);
- Ref<Shader> get_shader(const StringName &p_name, const StringName &p_node_type) const;
- bool has_shader(const StringName &p_name, const StringName &p_node_type) const;
- void clear_shader(const StringName &p_name, const StringName &p_node_type);
- void get_shader_list(const StringName &p_node_type, List<StringName> *p_list) const;
-
void set_stylebox(const StringName &p_name, const StringName &p_node_type, const Ref<StyleBox> &p_style);
Ref<StyleBox> get_stylebox(const StringName &p_name, const StringName &p_node_type) const;
bool has_stylebox(const StringName &p_name, const StringName &p_node_type) const;