summaryrefslogtreecommitdiff
path: root/scene
diff options
context:
space:
mode:
Diffstat (limited to 'scene')
-rw-r--r--scene/2d/animated_sprite_2d.cpp1
-rw-r--r--scene/2d/audio_listener_2d.cpp1
-rw-r--r--scene/2d/audio_stream_player_2d.cpp113
-rw-r--r--scene/2d/camera_2d.cpp19
-rw-r--r--scene/2d/canvas_modulate.cpp43
-rw-r--r--scene/2d/collision_object_2d.cpp1
-rw-r--r--scene/2d/collision_polygon_2d.cpp12
-rw-r--r--scene/2d/collision_shape_2d.cpp14
-rw-r--r--scene/2d/cpu_particles_2d.cpp4
-rw-r--r--scene/2d/gpu_particles_2d.cpp265
-rw-r--r--scene/2d/joint_2d.cpp1
-rw-r--r--scene/2d/light_2d.cpp33
-rw-r--r--scene/2d/light_occluder_2d.cpp68
-rw-r--r--scene/2d/line_2d.cpp11
-rw-r--r--scene/2d/mesh_instance_2d.cpp11
-rw-r--r--scene/2d/multimesh_instance_2d.cpp11
-rw-r--r--scene/2d/navigation_agent_2d.cpp3
-rw-r--r--scene/2d/navigation_obstacle_2d.cpp5
-rw-r--r--scene/2d/navigation_region_2d.cpp12
-rw-r--r--scene/2d/navigation_region_2d.h4
-rw-r--r--scene/2d/parallax_background.cpp3
-rw-r--r--scene/2d/parallax_layer.cpp1
-rw-r--r--scene/2d/path_2d.cpp47
-rw-r--r--scene/2d/physics_body_2d.cpp2
-rw-r--r--scene/2d/polygon_2d.cpp9
-rw-r--r--scene/2d/position_2d.cpp2
-rw-r--r--scene/2d/ray_cast_2d.cpp13
-rw-r--r--scene/2d/remote_transform_2d.cpp3
-rw-r--r--scene/2d/shape_cast_2d.cpp2
-rw-r--r--scene/2d/shape_cast_2d.h1
-rw-r--r--scene/2d/skeleton_2d.cpp372
-rw-r--r--scene/2d/sprite_2d.cpp5
-rw-r--r--scene/2d/tile_map.cpp19
-rw-r--r--scene/2d/touch_screen_button.cpp6
-rw-r--r--scene/2d/visible_on_screen_notifier_2d.cpp31
-rw-r--r--scene/3d/area_3d.cpp12
-rw-r--r--scene/3d/audio_listener_3d.cpp3
-rw-r--r--scene/3d/audio_stream_player_3d.cpp130
-rw-r--r--scene/3d/bone_attachment_3d.cpp5
-rw-r--r--scene/3d/camera_3d.cpp12
-rw-r--r--scene/3d/camera_3d.h2
-rw-r--r--scene/3d/collision_polygon_3d.cpp5
-rw-r--r--scene/3d/collision_shape_3d.cpp3
-rw-r--r--scene/3d/cpu_particles_3d.cpp100
-rw-r--r--scene/3d/gpu_particles_3d.cpp61
-rw-r--r--scene/3d/gpu_particles_collision_3d.cpp68
-rw-r--r--scene/3d/joint_3d.cpp1
-rw-r--r--scene/3d/light_3d.cpp11
-rw-r--r--scene/3d/lightmap_gi.cpp20
-rw-r--r--scene/3d/mesh_instance_3d.cpp6
-rw-r--r--scene/3d/navigation_agent_3d.cpp2
-rw-r--r--scene/3d/navigation_obstacle_3d.cpp4
-rw-r--r--scene/3d/navigation_region_3d.cpp4
-rw-r--r--scene/3d/node_3d.cpp8
-rw-r--r--scene/3d/node_3d.h1
-rw-r--r--scene/3d/occluder_instance_3d.cpp550
-rw-r--r--scene/3d/occluder_instance_3d.h128
-rw-r--r--scene/3d/path_3d.cpp5
-rw-r--r--scene/3d/path_3d.h1
-rw-r--r--scene/3d/physics_body_3d.cpp2
-rw-r--r--scene/3d/ray_cast_3d.cpp12
-rw-r--r--scene/3d/remote_transform_3d.cpp3
-rw-r--r--scene/3d/skeleton_3d.cpp7
-rw-r--r--scene/3d/skeleton_ik_3d.cpp4
-rw-r--r--scene/3d/spring_arm_3d.cpp23
-rw-r--r--scene/3d/sprite_3d.cpp36
-rw-r--r--scene/3d/vehicle_body_3d.cpp10
-rw-r--r--scene/3d/visible_on_screen_notifier_3d.cpp35
-rw-r--r--scene/3d/visual_instance_3d.cpp15
-rw-r--r--scene/3d/visual_instance_3d.h1
-rw-r--r--scene/3d/world_environment.cpp47
-rw-r--r--scene/3d/xr_nodes.cpp32
-rw-r--r--scene/animation/animation_node_state_machine.cpp3
-rw-r--r--scene/animation/animation_node_state_machine.h1
-rw-r--r--scene/animation/animation_player.cpp11
-rw-r--r--scene/animation/animation_tree.cpp48
-rw-r--r--scene/animation/root_motion_view.cpp127
-rw-r--r--scene/audio/audio_stream_player.cpp80
-rw-r--r--scene/debugger/scene_debugger.cpp103
-rw-r--r--scene/debugger/scene_debugger.h28
-rw-r--r--scene/gui/aspect_ratio_container.cpp18
-rw-r--r--scene/gui/aspect_ratio_container.h3
-rw-r--r--scene/gui/base_button.cpp68
-rw-r--r--scene/gui/base_button.h1
-rw-r--r--scene/gui/box_container.cpp27
-rw-r--r--scene/gui/box_container.h3
-rw-r--r--scene/gui/button.cpp3
-rw-r--r--scene/gui/center_container.cpp38
-rw-r--r--scene/gui/center_container.h3
-rw-r--r--scene/gui/check_box.cpp62
-rw-r--r--scene/gui/check_button.cpp80
-rw-r--r--scene/gui/code_edit.cpp3
-rw-r--r--scene/gui/color_picker.cpp14
-rw-r--r--scene/gui/color_rect.cpp6
-rw-r--r--scene/gui/container.cpp38
-rw-r--r--scene/gui/container.h6
-rw-r--r--scene/gui/control.cpp455
-rw-r--r--scene/gui/control.h29
-rw-r--r--scene/gui/dialogs.cpp11
-rw-r--r--scene/gui/file_dialog.cpp44
-rw-r--r--scene/gui/flow_container.cpp28
-rw-r--r--scene/gui/flow_container.h5
-rw-r--r--scene/gui/gradient_edit.cpp129
-rw-r--r--scene/gui/graph_edit.cpp120
-rw-r--r--scene/gui/graph_edit.h2
-rw-r--r--scene/gui/graph_node.cpp20
-rw-r--r--scene/gui/graph_node.h3
-rw-r--r--scene/gui/grid_container.cpp3
-rw-r--r--scene/gui/item_list.cpp682
-rw-r--r--scene/gui/label.cpp439
-rw-r--r--scene/gui/line_edit.cpp17
-rw-r--r--scene/gui/link_button.cpp6
-rw-r--r--scene/gui/link_button.h1
-rw-r--r--scene/gui/margin_container.cpp19
-rw-r--r--scene/gui/margin_container.h3
-rw-r--r--scene/gui/menu_button.cpp5
-rw-r--r--scene/gui/nine_patch_rect.cpp24
-rw-r--r--scene/gui/option_button.cpp51
-rw-r--r--scene/gui/panel.cpp31
-rw-r--r--scene/gui/panel.h15
-rw-r--r--scene/gui/panel_container.cpp86
-rw-r--r--scene/gui/panel_container.h3
-rw-r--r--scene/gui/popup.cpp29
-rw-r--r--scene/gui/popup_menu.cpp141
-rw-r--r--scene/gui/popup_menu.h3
-rw-r--r--scene/gui/progress_bar.cpp55
-rw-r--r--scene/gui/reference_rect.cpp16
-rw-r--r--scene/gui/rich_text_label.cpp178
-rw-r--r--scene/gui/rich_text_label.h9
-rw-r--r--scene/gui/scroll_bar.cpp302
-rw-r--r--scene/gui/scroll_container.cpp179
-rw-r--r--scene/gui/separator.cpp1
-rw-r--r--scene/gui/slider.cpp8
-rw-r--r--scene/gui/spin_box.cpp66
-rw-r--r--scene/gui/split_container.cpp28
-rw-r--r--scene/gui/split_container.h3
-rw-r--r--scene/gui/subviewport_container.cpp101
-rw-r--r--scene/gui/subviewport_container.h4
-rw-r--r--scene/gui/tab_bar.cpp37
-rw-r--r--scene/gui/tab_container.cpp13
-rw-r--r--scene/gui/tab_container.h3
-rw-r--r--scene/gui/text_edit.cpp20
-rw-r--r--scene/gui/texture_rect.cpp151
-rw-r--r--scene/gui/tree.cpp361
-rw-r--r--scene/gui/tree.h3
-rw-r--r--scene/gui/video_stream_player.cpp49
-rw-r--r--scene/main/canvas_item.cpp105
-rw-r--r--scene/main/canvas_item.h5
-rw-r--r--scene/main/canvas_layer.cpp23
-rw-r--r--scene/main/canvas_layer.h2
-rw-r--r--scene/main/http_request.cpp28
-rw-r--r--scene/main/node.cpp62
-rw-r--r--scene/main/node.h7
-rw-r--r--scene/main/scene_tree.cpp16
-rw-r--r--scene/main/scene_tree.h3
-rw-r--r--scene/main/shader_globals_override.cpp36
-rw-r--r--scene/main/timer.cpp4
-rw-r--r--scene/main/viewport.cpp37
-rw-r--r--scene/main/viewport.h2
-rw-r--r--scene/main/window.cpp29
-rw-r--r--scene/multiplayer/multiplayer_spawner.cpp34
-rw-r--r--scene/multiplayer/multiplayer_synchronizer.cpp13
-rw-r--r--scene/multiplayer/scene_cache_interface.cpp265
-rw-r--r--scene/multiplayer/scene_cache_interface.h82
-rw-r--r--scene/multiplayer/scene_replication_interface.cpp24
-rw-r--r--scene/multiplayer/scene_rpc_interface.cpp511
-rw-r--r--scene/multiplayer/scene_rpc_interface.h91
-rw-r--r--scene/register_scene_types.cpp24
-rw-r--r--scene/resources/animation.cpp34
-rw-r--r--scene/resources/box_shape_3d.cpp1
-rw-r--r--scene/resources/capsule_shape_2d.cpp2
-rw-r--r--scene/resources/capsule_shape_3d.cpp2
-rw-r--r--scene/resources/circle_shape_2d.cpp1
-rw-r--r--scene/resources/cylinder_shape_3d.cpp2
-rw-r--r--scene/resources/default_theme/color_picker_sample.svg1
-rw-r--r--scene/resources/default_theme/default_theme.cpp12
-rw-r--r--scene/resources/default_theme/default_theme.h2
-rw-r--r--scene/resources/default_theme/mini_checkerboard.svg2
-rw-r--r--scene/resources/environment.cpp10
-rw-r--r--scene/resources/environment.h13
-rw-r--r--scene/resources/font.cpp21
-rw-r--r--scene/resources/font.h4
-rw-r--r--scene/resources/importer_mesh.cpp2
-rw-r--r--scene/resources/material.cpp4
-rw-r--r--scene/resources/packed_scene.cpp4
-rw-r--r--scene/resources/rectangle_shape_2d.cpp1
-rw-r--r--scene/resources/resource_format_text.cpp10
-rw-r--r--scene/resources/skeleton_modification_2d_jiggle.cpp2
-rw-r--r--scene/resources/sky_material.cpp40
-rw-r--r--scene/resources/sphere_shape_3d.cpp1
-rw-r--r--scene/resources/surface_tool.cpp88
-rw-r--r--scene/resources/surface_tool.h12
-rw-r--r--scene/resources/texture.cpp2
-rw-r--r--scene/resources/theme.cpp144
-rw-r--r--scene/resources/theme.h10
-rw-r--r--scene/resources/tile_set.cpp8
-rw-r--r--scene/resources/visual_shader.cpp278
-rw-r--r--scene/resources/visual_shader.h6
-rw-r--r--scene/resources/visual_shader_nodes.cpp121
-rw-r--r--scene/resources/visual_shader_nodes.h2
-rw-r--r--scene/resources/visual_shader_particle_nodes.cpp209
-rw-r--r--scene/resources/visual_shader_particle_nodes.h14
-rw-r--r--scene/resources/visual_shader_sdf_nodes.cpp32
-rw-r--r--scene/resources/world_2d.h2
-rw-r--r--scene/resources/world_3d.cpp2
205 files changed, 6380 insertions, 3406 deletions
diff --git a/scene/2d/animated_sprite_2d.cpp b/scene/2d/animated_sprite_2d.cpp
index decb3d0dd8..2d05d46342 100644
--- a/scene/2d/animated_sprite_2d.cpp
+++ b/scene/2d/animated_sprite_2d.cpp
@@ -247,7 +247,6 @@ void AnimatedSprite2D::_notification(int p_what) {
}
texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false);
-
} break;
}
}
diff --git a/scene/2d/audio_listener_2d.cpp b/scene/2d/audio_listener_2d.cpp
index 8fae339756..eb463864e1 100644
--- a/scene/2d/audio_listener_2d.cpp
+++ b/scene/2d/audio_listener_2d.cpp
@@ -67,6 +67,7 @@ void AudioListener2D::_notification(int p_what) {
make_current();
}
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp
index a761d0d1ec..c1328badfb 100644
--- a/scene/2d/audio_stream_player_2d.cpp
+++ b/scene/2d/audio_stream_player_2d.cpp
@@ -33,72 +33,75 @@
#include "scene/2d/area_2d.h"
#include "scene/2d/audio_listener_2d.h"
#include "scene/main/window.h"
+#include "scene/resources/world_2d.h"
void AudioStreamPlayer2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
- if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
- play();
- }
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
+ if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
+ play();
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- stop();
- AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
- }
+ case NOTIFICATION_EXIT_TREE: {
+ stop();
+ AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
+ } break;
- if (p_what == NOTIFICATION_PAUSED) {
- if (!can_process()) {
- // Node can't process so we start fading out to silence
- set_stream_paused(true);
- }
- }
+ case NOTIFICATION_PAUSED: {
+ if (!can_process()) {
+ // Node can't process so we start fading out to silence.
+ set_stream_paused(true);
+ }
+ } break;
- if (p_what == NOTIFICATION_UNPAUSED) {
- set_stream_paused(false);
- }
+ case NOTIFICATION_UNPAUSED: {
+ set_stream_paused(false);
+ } break;
- if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
- //update anything related to position first, if possible of course
- if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
- _update_panning();
- }
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ // Update anything related to position first, if possible of course.
+ if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
+ _update_panning();
+ }
- if (setplay.get() >= 0 && stream.is_valid()) {
- active.set();
- Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
- ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
- AudioServer::get_singleton()->start_playback_stream(new_playback, _get_actual_bus(), volume_vector, setplay.get(), pitch_scale);
- stream_playbacks.push_back(new_playback);
- setplay.set(-1);
- }
+ if (setplay.get() >= 0 && stream.is_valid()) {
+ active.set();
+ Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
+ ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
+ AudioServer::get_singleton()->start_playback_stream(new_playback, _get_actual_bus(), volume_vector, setplay.get(), pitch_scale);
+ stream_playbacks.push_back(new_playback);
+ setplay.set(-1);
+ }
- if (!stream_playbacks.is_empty() && active.is_set()) {
- // Stop playing if no longer active.
- Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
- for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
- if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
- playbacks_to_remove.push_back(playback);
+ if (!stream_playbacks.is_empty() && active.is_set()) {
+ // Stop playing if no longer active.
+ Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
+ for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
+ if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
+ playbacks_to_remove.push_back(playback);
+ }
+ }
+ // Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
+ for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
+ stream_playbacks.erase(playback);
+ }
+ if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
+ // This node is no longer actively playing audio.
+ active.clear();
+ set_physics_process_internal(false);
+ }
+ if (!playbacks_to_remove.is_empty()) {
+ emit_signal(SNAME("finished"));
}
}
- // Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
- for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
- stream_playbacks.erase(playback);
- }
- if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
- // This node is no longer actively playing audio.
- active.clear();
- set_physics_process_internal(false);
- }
- if (!playbacks_to_remove.is_empty()) {
- emit_signal(SNAME("finished"));
- }
- }
- while (stream_playbacks.size() > max_polyphony) {
- AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
- stream_playbacks.remove_at(0);
- }
+ while (stream_playbacks.size() > max_polyphony) {
+ AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
+ stream_playbacks.remove_at(0);
+ }
+ } break;
}
}
diff --git a/scene/2d/camera_2d.cpp b/scene/2d/camera_2d.cpp
index e8dfaf9c2e..390e6685b1 100644
--- a/scene/2d/camera_2d.cpp
+++ b/scene/2d/camera_2d.cpp
@@ -30,6 +30,7 @@
#include "camera_2d.h"
+#include "core/config/project_settings.h"
#include "scene/main/window.h"
void Camera2D::_update_scroll() {
@@ -205,15 +206,7 @@ Transform2D Camera2D::get_camera_transform() {
if (rotating) {
xform.set_rotation(angle);
}
- xform.set_origin(screen_rect.position /*.floor()*/);
-
- /*
- if (0) {
- xform = get_global_transform() * xform;
- } else {
- xform.elements[2]+=get_global_transform().get_origin();
- }
-*/
+ xform.set_origin(screen_rect.position);
return (xform).affine_inverse();
}
@@ -223,14 +216,14 @@ void Camera2D::_notification(int p_what) {
case NOTIFICATION_INTERNAL_PROCESS:
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
_update_scroll();
-
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_processing_internal() && !is_physics_processing_internal()) {
_update_scroll();
}
-
} break;
+
case NOTIFICATION_ENTER_TREE: {
ERR_FAIL_COND(!is_inside_tree());
if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) {
@@ -255,8 +248,8 @@ void Camera2D::_notification(int p_what) {
_update_process_callback();
_update_scroll();
first = true;
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (is_current()) {
if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
@@ -268,8 +261,8 @@ void Camera2D::_notification(int p_what) {
remove_from_group(group_name);
remove_from_group(canvas_group_name);
viewport = nullptr;
-
} break;
+
#ifdef TOOLS_ENABLED
case NOTIFICATION_DRAW: {
if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) {
diff --git a/scene/2d/canvas_modulate.cpp b/scene/2d/canvas_modulate.cpp
index d0abed4a0c..7f7eae51a6 100644
--- a/scene/2d/canvas_modulate.cpp
+++ b/scene/2d/canvas_modulate.cpp
@@ -31,27 +31,32 @@
#include "canvas_modulate.h"
void CanvasModulate::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_CANVAS) {
- if (is_visible_in_tree()) {
- RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
- add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_CANVAS: {
+ if (is_visible_in_tree()) {
+ RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
+ add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
+ }
+ } break;
- } else if (p_what == NOTIFICATION_EXIT_CANVAS) {
- if (is_visible_in_tree()) {
- RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
- remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
- }
- } else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- if (is_visible_in_tree()) {
- RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
- add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
- } else {
- RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
- remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
- }
+ case NOTIFICATION_EXIT_CANVAS: {
+ if (is_visible_in_tree()) {
+ RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
+ remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
+ }
+ } break;
+
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (is_visible_in_tree()) {
+ RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
+ add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
+ } else {
+ RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
+ remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
+ }
- update_configuration_warnings();
+ update_configuration_warnings();
+ } break;
}
}
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index 70c7e48fd4..fbfe1d7eff 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -30,6 +30,7 @@
#include "collision_object_2d.h"
+#include "scene/resources/world_2d.h"
#include "scene/scene_string_names.h"
void CollisionObject2D::_notification(int p_what) {
diff --git a/scene/2d/collision_polygon_2d.cpp b/scene/2d/collision_polygon_2d.cpp
index 2923b287be..e3939130ec 100644
--- a/scene/2d/collision_polygon_2d.cpp
+++ b/scene/2d/collision_polygon_2d.cpp
@@ -102,26 +102,20 @@ void CollisionPolygon2D::_notification(int p_what) {
_build_polygon();
_update_in_shape_owner();
}
-
- /*if (Engine::get_singleton()->is_editor_hint()) {
- //display above all else
- set_z_as_relative(false);
- set_z_index(RS::CANVAS_ITEM_Z_MAX - 1);
- }*/
-
} break;
+
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
-
} break;
+
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}
-
} break;
+
case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);
diff --git a/scene/2d/collision_shape_2d.cpp b/scene/2d/collision_shape_2d.cpp
index a0520ca28f..db9a745436 100644
--- a/scene/2d/collision_shape_2d.cpp
+++ b/scene/2d/collision_shape_2d.cpp
@@ -59,34 +59,28 @@ void CollisionShape2D::_notification(int p_what) {
}
_update_in_shape_owner();
}
-
- /*if (Engine::get_singleton()->is_editor_hint()) {
- //display above all else
- set_z_as_relative(false);
- set_z_index(RS::CANVAS_ITEM_Z_MAX - 1);
- }*/
-
} break;
+
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
-
} break;
+
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}
-
} break;
+
case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);
}
owner_id = 0;
parent = nullptr;
-
} break;
+
case NOTIFICATION_DRAW: {
ERR_FAIL_COND(!is_inside_tree());
diff --git a/scene/2d/cpu_particles_2d.cpp b/scene/2d/cpu_particles_2d.cpp
index 4673a99082..cd2153b132 100644
--- a/scene/2d/cpu_particles_2d.cpp
+++ b/scene/2d/cpu_particles_2d.cpp
@@ -1091,9 +1091,11 @@ void CPUParticles2D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
set_process_internal(emitting);
} break;
+
case NOTIFICATION_EXIT_TREE: {
_set_redraw(false);
} break;
+
case NOTIFICATION_DRAW: {
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
@@ -1111,9 +1113,11 @@ void CPUParticles2D::_notification(int p_what) {
RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid);
} break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
_update_internal();
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
inv_emission_transform = get_global_transform().affine_inverse();
diff --git a/scene/2d/gpu_particles_2d.cpp b/scene/2d/gpu_particles_2d.cpp
index 11c036ac9c..8b0840e7c8 100644
--- a/scene/2d/gpu_particles_2d.cpp
+++ b/scene/2d/gpu_particles_2d.cpp
@@ -377,154 +377,157 @@ void GPUParticles2D::restart() {
}
void GPUParticles2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- RID texture_rid;
- Size2 size;
- if (texture.is_valid()) {
- texture_rid = texture->get_rid();
- size = texture->get_size();
- } else {
- size = Size2(1, 1);
- }
-
- if (trail_enabled) {
- RS::get_singleton()->mesh_clear(mesh);
- PackedVector2Array points;
- PackedVector2Array uvs;
- PackedInt32Array bone_indices;
- PackedFloat32Array bone_weights;
- PackedInt32Array indices;
-
- int total_segments = trail_sections * trail_section_subdivisions;
- real_t depth = size.height * trail_sections;
-
- for (int j = 0; j <= total_segments; j++) {
- real_t v = j;
- v /= total_segments;
-
- real_t y = depth * v;
- y = (depth * 0.5) - y;
-
- int bone = j / trail_section_subdivisions;
- real_t blend = 1.0 - real_t(j % trail_section_subdivisions) / real_t(trail_section_subdivisions);
-
- real_t s = size.width;
-
- points.push_back(Vector2(-s * 0.5, 0));
- points.push_back(Vector2(+s * 0.5, 0));
-
- uvs.push_back(Vector2(0, v));
- uvs.push_back(Vector2(1, v));
-
- for (int i = 0; i < 2; i++) {
- bone_indices.push_back(bone);
- bone_indices.push_back(MIN(trail_sections, bone + 1));
- bone_indices.push_back(0);
- bone_indices.push_back(0);
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ RID texture_rid;
+ Size2 size;
+ if (texture.is_valid()) {
+ texture_rid = texture->get_rid();
+ size = texture->get_size();
+ } else {
+ size = Size2(1, 1);
+ }
- bone_weights.push_back(blend);
- bone_weights.push_back(1.0 - blend);
- bone_weights.push_back(0);
- bone_weights.push_back(0);
+ if (trail_enabled) {
+ RS::get_singleton()->mesh_clear(mesh);
+ PackedVector2Array points;
+ PackedVector2Array uvs;
+ PackedInt32Array bone_indices;
+ PackedFloat32Array bone_weights;
+ PackedInt32Array indices;
+
+ int total_segments = trail_sections * trail_section_subdivisions;
+ real_t depth = size.height * trail_sections;
+
+ for (int j = 0; j <= total_segments; j++) {
+ real_t v = j;
+ v /= total_segments;
+
+ real_t y = depth * v;
+ y = (depth * 0.5) - y;
+
+ int bone = j / trail_section_subdivisions;
+ real_t blend = 1.0 - real_t(j % trail_section_subdivisions) / real_t(trail_section_subdivisions);
+
+ real_t s = size.width;
+
+ points.push_back(Vector2(-s * 0.5, 0));
+ points.push_back(Vector2(+s * 0.5, 0));
+
+ uvs.push_back(Vector2(0, v));
+ uvs.push_back(Vector2(1, v));
+
+ for (int i = 0; i < 2; i++) {
+ bone_indices.push_back(bone);
+ bone_indices.push_back(MIN(trail_sections, bone + 1));
+ bone_indices.push_back(0);
+ bone_indices.push_back(0);
+
+ bone_weights.push_back(blend);
+ bone_weights.push_back(1.0 - blend);
+ bone_weights.push_back(0);
+ bone_weights.push_back(0);
+ }
+
+ if (j > 0) {
+ int base = j * 2 - 2;
+ indices.push_back(base + 0);
+ indices.push_back(base + 1);
+ indices.push_back(base + 2);
+
+ indices.push_back(base + 1);
+ indices.push_back(base + 3);
+ indices.push_back(base + 2);
+ }
}
- if (j > 0) {
- int base = j * 2 - 2;
- indices.push_back(base + 0);
- indices.push_back(base + 1);
- indices.push_back(base + 2);
-
- indices.push_back(base + 1);
- indices.push_back(base + 3);
- indices.push_back(base + 2);
+ Array arr;
+ arr.resize(RS::ARRAY_MAX);
+ arr[RS::ARRAY_VERTEX] = points;
+ arr[RS::ARRAY_TEX_UV] = uvs;
+ arr[RS::ARRAY_BONES] = bone_indices;
+ arr[RS::ARRAY_WEIGHTS] = bone_weights;
+ arr[RS::ARRAY_INDEX] = indices;
+
+ RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
+
+ Vector<Transform3D> xforms;
+ for (int i = 0; i <= trail_sections; i++) {
+ Transform3D xform;
+ /*
+ xform.origin.y = depth / 2.0 - size.height * real_t(i);
+ xform.origin.y = -xform.origin.y; //bind is an inverse transform, so negate y */
+ xforms.push_back(xform);
}
- }
- Array arr;
- arr.resize(RS::ARRAY_MAX);
- arr[RS::ARRAY_VERTEX] = points;
- arr[RS::ARRAY_TEX_UV] = uvs;
- arr[RS::ARRAY_BONES] = bone_indices;
- arr[RS::ARRAY_WEIGHTS] = bone_weights;
- arr[RS::ARRAY_INDEX] = indices;
-
- RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
-
- Vector<Transform3D> xforms;
- for (int i = 0; i <= trail_sections; i++) {
- Transform3D xform;
- /*
- xform.origin.y = depth / 2.0 - size.height * real_t(i);
- xform.origin.y = -xform.origin.y; //bind is an inverse transform, so negate y */
- xforms.push_back(xform);
- }
-
- RS::get_singleton()->particles_set_trail_bind_poses(particles, xforms);
+ RS::get_singleton()->particles_set_trail_bind_poses(particles, xforms);
- } else {
- RS::get_singleton()->mesh_clear(mesh);
+ } else {
+ RS::get_singleton()->mesh_clear(mesh);
- Vector<Vector2> points = {
- Vector2(-size.x / 2.0, -size.y / 2.0),
- Vector2(size.x / 2.0, -size.y / 2.0),
- Vector2(size.x / 2.0, size.y / 2.0),
- Vector2(-size.x / 2.0, size.y / 2.0)
- };
+ Vector<Vector2> points = {
+ Vector2(-size.x / 2.0, -size.y / 2.0),
+ Vector2(size.x / 2.0, -size.y / 2.0),
+ Vector2(size.x / 2.0, size.y / 2.0),
+ Vector2(-size.x / 2.0, size.y / 2.0)
+ };
- Vector<Vector2> uvs = {
- Vector2(0, 0),
- Vector2(1, 0),
- Vector2(1, 1),
- Vector2(0, 1)
- };
+ Vector<Vector2> uvs = {
+ Vector2(0, 0),
+ Vector2(1, 0),
+ Vector2(1, 1),
+ Vector2(0, 1)
+ };
- Vector<int> indices = { 0, 1, 2, 0, 2, 3 };
+ Vector<int> indices = { 0, 1, 2, 0, 2, 3 };
- Array arr;
- arr.resize(RS::ARRAY_MAX);
- arr[RS::ARRAY_VERTEX] = points;
- arr[RS::ARRAY_TEX_UV] = uvs;
- arr[RS::ARRAY_INDEX] = indices;
+ Array arr;
+ arr.resize(RS::ARRAY_MAX);
+ arr[RS::ARRAY_VERTEX] = points;
+ arr[RS::ARRAY_TEX_UV] = uvs;
+ arr[RS::ARRAY_INDEX] = indices;
- RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
- RS::get_singleton()->particles_set_trail_bind_poses(particles, Vector<Transform3D>());
- }
- RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid);
+ RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
+ RS::get_singleton()->particles_set_trail_bind_poses(particles, Vector<Transform3D>());
+ }
+ RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid);
#ifdef TOOLS_ENABLED
- if (show_visibility_rect) {
- draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false);
- }
+ if (show_visibility_rect) {
+ draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false);
+ }
#endif
- }
-
- if (p_what == NOTIFICATION_ENTER_TREE) {
- if (sub_emitter != NodePath()) {
- _attach_sub_emitter();
- }
- }
-
- if (p_what == NOTIFICATION_EXIT_TREE) {
- RS::get_singleton()->particles_set_subemitter(particles, RID());
- }
+ } break;
- if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) {
- if (can_process()) {
- RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
- } else {
- RS::get_singleton()->particles_set_speed_scale(particles, 0);
- }
- }
+ case NOTIFICATION_ENTER_TREE: {
+ if (sub_emitter != NodePath()) {
+ _attach_sub_emitter();
+ }
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
+ RS::get_singleton()->particles_set_subemitter(particles, RID());
+ } break;
+
+ case NOTIFICATION_PAUSED:
+ case NOTIFICATION_UNPAUSED: {
+ if (can_process()) {
+ RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
+ } else {
+ RS::get_singleton()->particles_set_speed_scale(particles, 0);
+ }
+ } break;
- if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- _update_particle_emission_transform();
- }
+ case NOTIFICATION_TRANSFORM_CHANGED: {
+ _update_particle_emission_transform();
+ } break;
- if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- if (one_shot && !is_emitting()) {
- notify_property_list_changed();
- set_process_internal(false);
- }
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ if (one_shot && !is_emitting()) {
+ notify_property_list_changed();
+ set_process_internal(false);
+ }
+ } break;
}
}
diff --git a/scene/2d/joint_2d.cpp b/scene/2d/joint_2d.cpp
index 62a77fb969..0467c39746 100644
--- a/scene/2d/joint_2d.cpp
+++ b/scene/2d/joint_2d.cpp
@@ -162,6 +162,7 @@ void Joint2D::_notification(int p_what) {
case NOTIFICATION_READY: {
_update_joint();
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (joint.is_valid()) {
_disconnect_signals();
diff --git a/scene/2d/light_2d.cpp b/scene/2d/light_2d.cpp
index f496e1aac2..ba168eeb86 100644
--- a/scene/2d/light_2d.cpp
+++ b/scene/2d/light_2d.cpp
@@ -192,21 +192,24 @@ Light2D::BlendMode Light2D::get_blend_mode() const {
}
void Light2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
- _update_light_visibility();
- }
-
- if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
- }
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- _update_light_visibility();
- }
-
- if (p_what == NOTIFICATION_EXIT_TREE) {
- RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
- _update_light_visibility();
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
+ _update_light_visibility();
+ } break;
+
+ case NOTIFICATION_TRANSFORM_CHANGED: {
+ RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
+ } break;
+
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ _update_light_visibility();
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
+ RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
+ _update_light_visibility();
+ } break;
}
}
diff --git a/scene/2d/light_occluder_2d.cpp b/scene/2d/light_occluder_2d.cpp
index 0a7e4c8841..0310817592 100644
--- a/scene/2d/light_occluder_2d.cpp
+++ b/scene/2d/light_occluder_2d.cpp
@@ -29,9 +29,9 @@
/*************************************************************************/
#include "light_occluder_2d.h"
-#include "core/math/geometry_2d.h"
#include "core/config/engine.h"
+#include "core/math/geometry_2d.h"
#define LINE_GRAB_WIDTH 8
@@ -158,42 +158,46 @@ void LightOccluder2D::_poly_changed() {
}
void LightOccluder2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_CANVAS) {
- RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, get_canvas());
- RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
- RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
- }
- if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
- }
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
- }
-
- if (p_what == NOTIFICATION_DRAW) {
- if (Engine::get_singleton()->is_editor_hint()) {
- if (occluder_polygon.is_valid()) {
- Vector<Vector2> poly = occluder_polygon->get_polygon();
-
- if (poly.size()) {
- if (occluder_polygon->is_closed()) {
- Vector<Color> color;
- color.push_back(Color(0, 0, 0, 0.6));
- draw_polygon(Variant(poly), color);
- } else {
- int ps = poly.size();
- const Vector2 *r = poly.ptr();
- for (int i = 0; i < ps - 1; i++) {
- draw_line(r[i], r[i + 1], Color(0, 0, 0, 0.6), 3);
+ switch (p_what) {
+ case NOTIFICATION_ENTER_CANVAS: {
+ RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, get_canvas());
+ RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
+ RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
+ } break;
+
+ case NOTIFICATION_TRANSFORM_CHANGED: {
+ RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
+ } break;
+
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
+ } break;
+
+ case NOTIFICATION_DRAW: {
+ if (Engine::get_singleton()->is_editor_hint()) {
+ if (occluder_polygon.is_valid()) {
+ Vector<Vector2> poly = occluder_polygon->get_polygon();
+
+ if (poly.size()) {
+ if (occluder_polygon->is_closed()) {
+ Vector<Color> color;
+ color.push_back(Color(0, 0, 0, 0.6));
+ draw_polygon(Variant(poly), color);
+ } else {
+ int ps = poly.size();
+ const Vector2 *r = poly.ptr();
+ for (int i = 0; i < ps - 1; i++) {
+ draw_line(r[i], r[i + 1], Color(0, 0, 0, 0.6), 3);
+ }
}
}
}
}
- }
- }
+ } break;
- if (p_what == NOTIFICATION_EXIT_CANVAS) {
- RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID());
+ case NOTIFICATION_EXIT_CANVAS: {
+ RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID());
+ } break;
}
}
diff --git a/scene/2d/line_2d.cpp b/scene/2d/line_2d.cpp
index 7f2290bdc7..2716bb2e25 100644
--- a/scene/2d/line_2d.cpp
+++ b/scene/2d/line_2d.cpp
@@ -228,9 +228,9 @@ Line2D::LineCapMode Line2D::get_end_cap_mode() const {
void Line2D::_notification(int p_what) {
switch (p_what) {
- case NOTIFICATION_DRAW:
+ case NOTIFICATION_DRAW: {
_draw();
- break;
+ } break;
}
}
@@ -247,10 +247,7 @@ float Line2D::get_sharp_limit() const {
}
void Line2D::set_round_precision(int p_precision) {
- if (p_precision < 1) {
- p_precision = 1;
- }
- _round_precision = p_precision;
+ _round_precision = MAX(1, p_precision);
update();
}
@@ -409,7 +406,7 @@ void Line2D::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "end_cap_mode", PROPERTY_HINT_ENUM, "None,Box,Round"), "set_end_cap_mode", "get_end_cap_mode");
ADD_GROUP("Border", "");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sharp_limit"), "set_sharp_limit", "get_sharp_limit");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "round_precision"), "set_round_precision", "get_round_precision");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "round_precision", PROPERTY_HINT_RANGE, "1,32,1"), "set_round_precision", "get_round_precision");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "antialiased"), "set_antialiased", "get_antialiased");
BIND_ENUM_CONSTANT(LINE_JOINT_SHARP);
diff --git a/scene/2d/mesh_instance_2d.cpp b/scene/2d/mesh_instance_2d.cpp
index 5f8a46ad2e..178addd62d 100644
--- a/scene/2d/mesh_instance_2d.cpp
+++ b/scene/2d/mesh_instance_2d.cpp
@@ -29,13 +29,16 @@
/*************************************************************************/
#include "mesh_instance_2d.h"
+
#include "scene/scene_string_names.h"
void MeshInstance2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- if (mesh.is_valid()) {
- draw_mesh(mesh, texture);
- }
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ if (mesh.is_valid()) {
+ draw_mesh(mesh, texture);
+ }
+ } break;
}
}
diff --git a/scene/2d/multimesh_instance_2d.cpp b/scene/2d/multimesh_instance_2d.cpp
index e1af99d931..8f72ff1757 100644
--- a/scene/2d/multimesh_instance_2d.cpp
+++ b/scene/2d/multimesh_instance_2d.cpp
@@ -29,13 +29,16 @@
/*************************************************************************/
#include "multimesh_instance_2d.h"
+
#include "scene/scene_string_names.h"
void MultiMeshInstance2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- if (multimesh.is_valid()) {
- draw_multimesh(multimesh, texture);
- }
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ if (multimesh.is_valid()) {
+ draw_multimesh(multimesh, texture);
+ }
+ } break;
}
}
diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp
index 9331f2dccb..78b5a39e9a 100644
--- a/scene/2d/navigation_agent_2d.cpp
+++ b/scene/2d/navigation_agent_2d.cpp
@@ -31,6 +31,7 @@
#include "navigation_agent_2d.h"
#include "core/math/geometry_2d.h"
+#include "scene/resources/world_2d.h"
#include "servers/navigation_server_2d.h"
void NavigationAgent2D::_bind_methods() {
@@ -96,10 +97,12 @@ void NavigationAgent2D::_notification(int p_what) {
}
set_physics_process_internal(true);
} break;
+
case NOTIFICATION_EXIT_TREE: {
agent_parent = nullptr;
set_physics_process_internal(false);
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (agent_parent) {
NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());
diff --git a/scene/2d/navigation_obstacle_2d.cpp b/scene/2d/navigation_obstacle_2d.cpp
index fad54070a5..65f7adb7a6 100644
--- a/scene/2d/navigation_obstacle_2d.cpp
+++ b/scene/2d/navigation_obstacle_2d.cpp
@@ -31,6 +31,7 @@
#include "navigation_obstacle_2d.h"
#include "scene/2d/collision_shape_2d.h"
+#include "scene/resources/world_2d.h"
#include "servers/navigation_server_2d.h"
void NavigationObstacle2D::_bind_methods() {
@@ -62,17 +63,21 @@ void NavigationObstacle2D::_notification(int p_what) {
}
set_physics_process_internal(true);
} break;
+
case NOTIFICATION_EXIT_TREE: {
parent_node2d = nullptr;
set_physics_process_internal(false);
} break;
+
case NOTIFICATION_PARENTED: {
parent_node2d = Object::cast_to<Node2D>(get_parent());
reevaluate_agent_radius();
} break;
+
case NOTIFICATION_UNPARENTED: {
parent_node2d = nullptr;
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (parent_node2d) {
NavigationServer2D::get_singleton()->agent_set_position(agent, parent_node2d->get_global_position());
diff --git a/scene/2d/navigation_region_2d.cpp b/scene/2d/navigation_region_2d.cpp
index 4bead978f1..34ac02a82a 100644
--- a/scene/2d/navigation_region_2d.cpp
+++ b/scene/2d/navigation_region_2d.cpp
@@ -33,6 +33,7 @@
#include "core/core_string_names.h"
#include "core/math/geometry_2d.h"
#include "core/os/mutex.h"
+#include "scene/resources/world_2d.h"
#include "servers/navigation_server_2d.h"
#include "thirdparty/misc/polypartition.h"
@@ -104,8 +105,8 @@ void NavigationPolygon::_set_polygons(const TypedArray<Vector<int32_t>> &p_array
}
}
-Array NavigationPolygon::_get_polygons() const {
- Array ret;
+TypedArray<Vector<int32_t>> NavigationPolygon::_get_polygons() const {
+ TypedArray<Vector<int32_t>> ret;
ret.resize(polygons.size());
for (int i = 0; i < ret.size(); i++) {
ret[i] = polygons[i].indices;
@@ -122,8 +123,8 @@ void NavigationPolygon::_set_outlines(const TypedArray<Vector<Vector2>> &p_array
rect_cache_dirty = true;
}
-Array NavigationPolygon::_get_outlines() const {
- Array ret;
+TypedArray<Vector<Vector2>> NavigationPolygon::_get_outlines() const {
+ TypedArray<Vector<Vector2>> ret;
ret.resize(outlines.size());
for (int i = 0; i < ret.size(); i++) {
ret[i] = outlines[i];
@@ -405,15 +406,18 @@ void NavigationRegion2D::_notification(int p_what) {
NavigationServer2D::get_singleton_mut()->connect("map_changed", callable_mp(this, &NavigationRegion2D::_map_changed));
}
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
NavigationServer2D::get_singleton()->region_set_transform(region, get_global_transform());
} break;
+
case NOTIFICATION_EXIT_TREE: {
NavigationServer2D::get_singleton()->region_set_map(region, RID());
if (enabled) {
NavigationServer2D::get_singleton_mut()->disconnect("map_changed", callable_mp(this, &NavigationRegion2D::_map_changed));
}
} break;
+
case NOTIFICATION_DRAW: {
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) {
Vector<Vector2> verts = navpoly->get_vertices();
diff --git a/scene/2d/navigation_region_2d.h b/scene/2d/navigation_region_2d.h
index 012debb584..487a578401 100644
--- a/scene/2d/navigation_region_2d.h
+++ b/scene/2d/navigation_region_2d.h
@@ -55,10 +55,10 @@ protected:
static void _bind_methods();
void _set_polygons(const TypedArray<Vector<int32_t>> &p_array);
- Array _get_polygons() const;
+ TypedArray<Vector<int32_t>> _get_polygons() const;
void _set_outlines(const TypedArray<Vector<Vector2>> &p_array);
- Array _get_outlines() const;
+ TypedArray<Vector<Vector2>> _get_outlines() const;
public:
#ifdef TOOLS_ENABLED
diff --git a/scene/2d/parallax_background.cpp b/scene/2d/parallax_background.cpp
index f75baaab0f..dcbb6507f5 100644
--- a/scene/2d/parallax_background.cpp
+++ b/scene/2d/parallax_background.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "parallax_background.h"
+
#include "parallax_layer.h"
void ParallaxBackground::_notification(int p_what) {
@@ -36,8 +37,8 @@ void ParallaxBackground::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
group_name = "__cameras_" + itos(get_viewport().get_id());
add_to_group(group_name);
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
remove_from_group(group_name);
} break;
diff --git a/scene/2d/parallax_layer.cpp b/scene/2d/parallax_layer.cpp
index ff572c9b9a..849412a7ae 100644
--- a/scene/2d/parallax_layer.cpp
+++ b/scene/2d/parallax_layer.cpp
@@ -99,6 +99,7 @@ void ParallaxLayer::_notification(int p_what) {
orig_scale = get_scale();
_update_mirroring();
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
break;
diff --git a/scene/2d/path_2d.cpp b/scene/2d/path_2d.cpp
index 742756113f..d001652ca3 100644
--- a/scene/2d/path_2d.cpp
+++ b/scene/2d/path_2d.cpp
@@ -86,36 +86,41 @@ bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc
#endif
void Path2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW && curve.is_valid()) {
- //draw the curve!!
+ switch (p_what) {
+ // Draw the curve if navigation debugging is enabled.
+ case NOTIFICATION_DRAW: {
+ if (!curve.is_valid()) {
+ break;
+ }
- if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_navigation_hint()) {
- return;
- }
+ if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_navigation_hint()) {
+ return;
+ }
- if (curve->get_point_count() < 2) {
- return;
- }
+ if (curve->get_point_count() < 2) {
+ return;
+ }
#ifdef TOOLS_ENABLED
- const real_t line_width = 2 * EDSCALE;
+ const real_t line_width = 2 * EDSCALE;
#else
- const real_t line_width = 2;
+ const real_t line_width = 2;
#endif
- const Color color = Color(0.5, 0.6, 1.0, 0.7);
+ const Color color = Color(0.5, 0.6, 1.0, 0.7);
- _cached_draw_pts.resize(curve->get_point_count() * 8);
- int count = 0;
+ _cached_draw_pts.resize(curve->get_point_count() * 8);
+ int count = 0;
- for (int i = 0; i < curve->get_point_count(); i++) {
- for (int j = 0; j < 8; j++) {
- real_t frac = j * (1.0 / 8.0);
- Vector2 p = curve->interpolate(i, frac);
- _cached_draw_pts.set(count++, p);
+ for (int i = 0; i < curve->get_point_count(); i++) {
+ for (int j = 0; j < 8; j++) {
+ real_t frac = j * (1.0 / 8.0);
+ Vector2 p = curve->interpolate(i, frac);
+ _cached_draw_pts.set(count++, p);
+ }
}
- }
- draw_polyline(_cached_draw_pts, color, line_width, true);
+ draw_polyline(_cached_draw_pts, color, line_width, true);
+ } break;
}
}
@@ -226,8 +231,8 @@ void PathFollow2D::_notification(int p_what) {
if (path) {
_update_transform();
}
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
path = nullptr;
} break;
diff --git a/scene/2d/physics_body_2d.cpp b/scene/2d/physics_body_2d.cpp
index fb611addf8..a4ad0a8d99 100644
--- a/scene/2d/physics_body_2d.cpp
+++ b/scene/2d/physics_body_2d.cpp
@@ -906,7 +906,7 @@ void RigidDynamicBody2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
- set_notify_local_transform(true); //used for warnings and only in editor
+ set_notify_local_transform(true); // Used for warnings and only in editor.
}
} break;
diff --git a/scene/2d/polygon_2d.cpp b/scene/2d/polygon_2d.cpp
index 1f4dec6864..1fe4adb4db 100644
--- a/scene/2d/polygon_2d.cpp
+++ b/scene/2d/polygon_2d.cpp
@@ -428,15 +428,6 @@ Vector<Color> Polygon2D::get_vertex_colors() const {
void Polygon2D::set_texture(const Ref<Texture2D> &p_texture) {
texture = p_texture;
-
- /*if (texture.is_valid()) {
- uint32_t flags=texture->get_flags();
- flags&=~Texture::FLAG_REPEAT;
- if (tex_tile)
- flags|=Texture::FLAG_REPEAT;
-
- texture->set_flags(flags);
- }*/
update();
}
diff --git a/scene/2d/position_2d.cpp b/scene/2d/position_2d.cpp
index 67aff9c520..518593cee1 100644
--- a/scene/2d/position_2d.cpp
+++ b/scene/2d/position_2d.cpp
@@ -90,6 +90,7 @@ void Position2D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
update();
} break;
+
case NOTIFICATION_DRAW: {
if (!is_inside_tree()) {
break;
@@ -97,7 +98,6 @@ void Position2D::_notification(int p_what) {
if (Engine::get_singleton()->is_editor_hint()) {
_draw_cross();
}
-
} break;
}
}
diff --git a/scene/2d/ray_cast_2d.cpp b/scene/2d/ray_cast_2d.cpp
index 9521667854..37db9211e1 100644
--- a/scene/2d/ray_cast_2d.cpp
+++ b/scene/2d/ray_cast_2d.cpp
@@ -31,6 +31,7 @@
#include "ray_cast_2d.h"
#include "collision_object_2d.h"
+#include "scene/resources/world_2d.h"
void RayCast2D::set_target_position(const Vector2 &p_point) {
target_position = p_point;
@@ -149,11 +150,11 @@ void RayCast2D::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (enabled) {
set_physics_process_internal(false);
}
-
} break;
case NOTIFICATION_DRAW: {
@@ -162,16 +163,13 @@ void RayCast2D::_notification(int p_what) {
break;
}
_draw_debug_shape();
-
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!enabled) {
break;
}
-
_update_raycast_state();
-
} break;
}
}
@@ -279,6 +277,13 @@ void RayCast2D::remove_exception(const CollisionObject2D *p_node) {
void RayCast2D::clear_exceptions() {
exclude.clear();
+
+ if (exclude_parent_body && is_inside_tree()) {
+ CollisionObject2D *parent = Object::cast_to<CollisionObject2D>(get_parent());
+ if (parent) {
+ exclude.insert(parent->get_rid());
+ }
+ }
}
void RayCast2D::set_collide_with_areas(bool p_enabled) {
diff --git a/scene/2d/remote_transform_2d.cpp b/scene/2d/remote_transform_2d.cpp
index e9431efde3..429f0f6f6f 100644
--- a/scene/2d/remote_transform_2d.cpp
+++ b/scene/2d/remote_transform_2d.cpp
@@ -115,8 +115,8 @@ void RemoteTransform2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_cache();
-
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_inside_tree()) {
break;
@@ -125,7 +125,6 @@ void RemoteTransform2D::_notification(int p_what) {
if (cache.is_valid()) {
_update_remote();
}
-
} break;
}
}
diff --git a/scene/2d/shape_cast_2d.cpp b/scene/2d/shape_cast_2d.cpp
index 24199c96b5..a2c5d73b59 100644
--- a/scene/2d/shape_cast_2d.cpp
+++ b/scene/2d/shape_cast_2d.cpp
@@ -201,6 +201,7 @@ void ShapeCast2D::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (enabled) {
set_physics_process_internal(false);
@@ -254,6 +255,7 @@ void ShapeCast2D::_notification(int p_what) {
}
#endif
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!enabled) {
break;
diff --git a/scene/2d/shape_cast_2d.h b/scene/2d/shape_cast_2d.h
index ea36b25068..15436d6e3d 100644
--- a/scene/2d/shape_cast_2d.h
+++ b/scene/2d/shape_cast_2d.h
@@ -33,6 +33,7 @@
#include "scene/2d/node_2d.h"
#include "scene/resources/shape_2d.h"
+#include "scene/resources/world_2d.h"
class CollisionObject2D;
diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp
index 2270926ea7..360650c724 100644
--- a/scene/2d/skeleton_2d.cpp
+++ b/scene/2d/skeleton_2d.cpp
@@ -31,6 +31,7 @@
#include "skeleton_2d.h"
#ifdef TOOLS_ENABLED
+#include "editor/editor_data.h"
#include "editor/editor_settings.h"
#include "editor/plugins/canvas_item_editor_plugin.h"
#endif //TOOLS_ENABLED
@@ -92,223 +93,228 @@ void Bone2D::_get_property_list(List<PropertyInfo> *p_list) const {
}
void Bone2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- Node *parent = get_parent();
- parent_bone = Object::cast_to<Bone2D>(parent);
- skeleton = nullptr;
- while (parent) {
- skeleton = Object::cast_to<Skeleton2D>(parent);
- if (skeleton) {
- break;
- }
- if (!Object::cast_to<Bone2D>(parent)) {
- break; //skeletons must be chained to Bone2Ds.
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ Node *parent = get_parent();
+ parent_bone = Object::cast_to<Bone2D>(parent);
+ skeleton = nullptr;
+ while (parent) {
+ skeleton = Object::cast_to<Skeleton2D>(parent);
+ if (skeleton) {
+ break;
+ }
+ if (!Object::cast_to<Bone2D>(parent)) {
+ break; //skeletons must be chained to Bone2Ds.
+ }
- parent = parent->get_parent();
- }
+ parent = parent->get_parent();
+ }
- if (skeleton) {
- Skeleton2D::Bone bone;
- bone.bone = this;
- skeleton->bones.push_back(bone);
- skeleton->_make_bone_setup_dirty();
- }
+ if (skeleton) {
+ Skeleton2D::Bone bone;
+ bone.bone = this;
+ skeleton->bones.push_back(bone);
+ skeleton->_make_bone_setup_dirty();
+ }
- cache_transform = get_transform();
- copy_transform_to_cache = true;
+ cache_transform = get_transform();
+ copy_transform_to_cache = true;
#ifdef TOOLS_ENABLED
- // Only draw the gizmo in the editor!
- if (Engine::get_singleton()->is_editor_hint() == false) {
- return;
- }
+ // Only draw the gizmo in the editor!
+ if (Engine::get_singleton()->is_editor_hint() == false) {
+ return;
+ }
- update();
+ update();
#endif // TOOLS_ENABLED
- }
+ } break;
- else if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) {
- if (skeleton) {
- skeleton->_make_transform_dirty();
- }
- if (copy_transform_to_cache) {
- cache_transform = get_transform();
- }
+ case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
+ if (skeleton) {
+ skeleton->_make_transform_dirty();
+ }
+ if (copy_transform_to_cache) {
+ cache_transform = get_transform();
+ }
#ifdef TOOLS_ENABLED
- // Only draw the gizmo in the editor!
- if (Engine::get_singleton()->is_editor_hint() == false) {
- return;
- }
+ // Only draw the gizmo in the editor!
+ if (Engine::get_singleton()->is_editor_hint() == false) {
+ return;
+ }
- update();
+ update();
- if (get_parent()) {
- Bone2D *parent_bone = Object::cast_to<Bone2D>(get_parent());
- if (parent_bone) {
- parent_bone->update();
+ if (get_parent()) {
+ Bone2D *parent_bone = Object::cast_to<Bone2D>(get_parent());
+ if (parent_bone) {
+ parent_bone->update();
+ }
}
- }
#endif // TOOLS_ENABLED
- }
+ } break;
- else if (p_what == NOTIFICATION_MOVED_IN_PARENT) {
- if (skeleton) {
- skeleton->_make_bone_setup_dirty();
- }
- if (copy_transform_to_cache) {
- cache_transform = get_transform();
- }
- }
+ case NOTIFICATION_MOVED_IN_PARENT: {
+ if (skeleton) {
+ skeleton->_make_bone_setup_dirty();
+ }
+ if (copy_transform_to_cache) {
+ cache_transform = get_transform();
+ }
+ } break;
- else if (p_what == NOTIFICATION_EXIT_TREE) {
- if (skeleton) {
- for (int i = 0; i < skeleton->bones.size(); i++) {
- if (skeleton->bones[i].bone == this) {
- skeleton->bones.remove_at(i);
- break;
+ case NOTIFICATION_EXIT_TREE: {
+ if (skeleton) {
+ for (int i = 0; i < skeleton->bones.size(); i++) {
+ if (skeleton->bones[i].bone == this) {
+ skeleton->bones.remove_at(i);
+ break;
+ }
}
+ skeleton->_make_bone_setup_dirty();
+ skeleton = nullptr;
}
- skeleton->_make_bone_setup_dirty();
- skeleton = nullptr;
- }
- parent_bone = nullptr;
- set_transform(cache_transform);
- }
+ parent_bone = nullptr;
+ set_transform(cache_transform);
+ } break;
+
+ case NOTIFICATION_READY: {
+ if (autocalculate_length_and_angle) {
+ calculate_length_and_rotation();
+ }
+ } break;
- else if (p_what == NOTIFICATION_READY) {
- if (autocalculate_length_and_angle) {
- calculate_length_and_rotation();
- }
- }
#ifdef TOOLS_ENABLED
- else if (p_what == NOTIFICATION_EDITOR_PRE_SAVE || p_what == NOTIFICATION_EDITOR_POST_SAVE) {
- Transform2D tmp_trans = get_transform();
- set_transform(cache_transform);
- cache_transform = tmp_trans;
- }
- // Bone2D Editor gizmo drawing:
+ case NOTIFICATION_EDITOR_PRE_SAVE:
+ case NOTIFICATION_EDITOR_POST_SAVE: {
+ Transform2D tmp_trans = get_transform();
+ set_transform(cache_transform);
+ cache_transform = tmp_trans;
+ } break;
+
+ // Bone2D Editor gizmo drawing:
#ifndef _MSC_VER
#warning TODO Bone2D gizmo drawing needs to be moved to an editor plugin
#endif
- else if (p_what == NOTIFICATION_DRAW) {
- // Only draw the gizmo in the editor!
- if (Engine::get_singleton()->is_editor_hint() == false) {
- return;
- }
-
- if (editor_gizmo_rid.is_null()) {
- editor_gizmo_rid = RenderingServer::get_singleton()->canvas_item_create();
- RenderingServer::get_singleton()->canvas_item_set_parent(editor_gizmo_rid, get_canvas_item());
- RenderingServer::get_singleton()->canvas_item_set_z_as_relative_to_parent(editor_gizmo_rid, true);
- RenderingServer::get_singleton()->canvas_item_set_z_index(editor_gizmo_rid, 10);
- }
- RenderingServer::get_singleton()->canvas_item_clear(editor_gizmo_rid);
-
- if (!_editor_show_bone_gizmo) {
- return;
- }
-
- // Undo scaling
- Transform2D editor_gizmo_trans = Transform2D();
- editor_gizmo_trans.set_scale(Vector2(1, 1) / get_global_scale());
- RenderingServer::get_singleton()->canvas_item_set_transform(editor_gizmo_rid, editor_gizmo_trans);
-
- Color bone_color1 = EditorSettings::get_singleton()->get("editors/2d/bone_color1");
- Color bone_color2 = EditorSettings::get_singleton()->get("editors/2d/bone_color2");
- Color bone_ik_color = EditorSettings::get_singleton()->get("editors/2d/bone_ik_color");
- Color bone_outline_color = EditorSettings::get_singleton()->get("editors/2d/bone_outline_color");
- Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2d/bone_selected_color");
-
- bool Bone2D_found = false;
- for (int i = 0; i < get_child_count(); i++) {
- Bone2D *child_node = nullptr;
- child_node = Object::cast_to<Bone2D>(get_child(i));
- if (!child_node) {
- continue;
+ case NOTIFICATION_DRAW: {
+ // Only draw the gizmo in the editor!
+ if (Engine::get_singleton()->is_editor_hint() == false) {
+ return;
}
- Bone2D_found = true;
-
- Vector<Vector2> bone_shape;
- Vector<Vector2> bone_shape_outline;
- _editor_get_bone_shape(&bone_shape, &bone_shape_outline, child_node);
-
- Vector<Color> colors;
- if (has_meta("_local_pose_override_enabled_")) {
- colors.push_back(bone_ik_color);
- colors.push_back(bone_ik_color);
- colors.push_back(bone_ik_color);
- colors.push_back(bone_ik_color);
- } else {
- colors.push_back(bone_color1);
- colors.push_back(bone_color2);
- colors.push_back(bone_color1);
- colors.push_back(bone_color2);
+ if (editor_gizmo_rid.is_null()) {
+ editor_gizmo_rid = RenderingServer::get_singleton()->canvas_item_create();
+ RenderingServer::get_singleton()->canvas_item_set_parent(editor_gizmo_rid, get_canvas_item());
+ RenderingServer::get_singleton()->canvas_item_set_z_as_relative_to_parent(editor_gizmo_rid, true);
+ RenderingServer::get_singleton()->canvas_item_set_z_index(editor_gizmo_rid, 10);
}
+ RenderingServer::get_singleton()->canvas_item_clear(editor_gizmo_rid);
- Vector<Color> outline_colors;
- if (CanvasItemEditor::get_singleton()->editor_selection->is_selected(this)) {
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- } else {
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
+ if (!_editor_show_bone_gizmo) {
+ return;
}
- RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape_outline, outline_colors);
- RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape, colors);
- }
-
- if (!Bone2D_found) {
- Vector<Vector2> bone_shape;
- Vector<Vector2> bone_shape_outline;
+ // Undo scaling
+ Transform2D editor_gizmo_trans = Transform2D();
+ editor_gizmo_trans.set_scale(Vector2(1, 1) / get_global_scale());
+ RenderingServer::get_singleton()->canvas_item_set_transform(editor_gizmo_rid, editor_gizmo_trans);
+
+ Color bone_color1 = EditorSettings::get_singleton()->get("editors/2d/bone_color1");
+ Color bone_color2 = EditorSettings::get_singleton()->get("editors/2d/bone_color2");
+ Color bone_ik_color = EditorSettings::get_singleton()->get("editors/2d/bone_ik_color");
+ Color bone_outline_color = EditorSettings::get_singleton()->get("editors/2d/bone_outline_color");
+ Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2d/bone_selected_color");
+
+ bool Bone2D_found = false;
+ for (int i = 0; i < get_child_count(); i++) {
+ Bone2D *child_node = nullptr;
+ child_node = Object::cast_to<Bone2D>(get_child(i));
+ if (!child_node) {
+ continue;
+ }
+ Bone2D_found = true;
+
+ Vector<Vector2> bone_shape;
+ Vector<Vector2> bone_shape_outline;
+
+ _editor_get_bone_shape(&bone_shape, &bone_shape_outline, child_node);
+
+ Vector<Color> colors;
+ if (has_meta("_local_pose_override_enabled_")) {
+ colors.push_back(bone_ik_color);
+ colors.push_back(bone_ik_color);
+ colors.push_back(bone_ik_color);
+ colors.push_back(bone_ik_color);
+ } else {
+ colors.push_back(bone_color1);
+ colors.push_back(bone_color2);
+ colors.push_back(bone_color1);
+ colors.push_back(bone_color2);
+ }
- _editor_get_bone_shape(&bone_shape, &bone_shape_outline, nullptr);
+ Vector<Color> outline_colors;
+ if (CanvasItemEditor::get_singleton()->editor_selection->is_selected(this)) {
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ } else {
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ }
- Vector<Color> colors;
- if (has_meta("_local_pose_override_enabled_")) {
- colors.push_back(bone_ik_color);
- colors.push_back(bone_ik_color);
- colors.push_back(bone_ik_color);
- colors.push_back(bone_ik_color);
- } else {
- colors.push_back(bone_color1);
- colors.push_back(bone_color2);
- colors.push_back(bone_color1);
- colors.push_back(bone_color2);
+ RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape_outline, outline_colors);
+ RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape, colors);
}
- Vector<Color> outline_colors;
- if (CanvasItemEditor::get_singleton()->editor_selection->is_selected(this)) {
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- outline_colors.push_back(bone_selected_color);
- } else {
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- outline_colors.push_back(bone_outline_color);
- }
+ if (!Bone2D_found) {
+ Vector<Vector2> bone_shape;
+ Vector<Vector2> bone_shape_outline;
+
+ _editor_get_bone_shape(&bone_shape, &bone_shape_outline, nullptr);
+
+ Vector<Color> colors;
+ if (has_meta("_local_pose_override_enabled_")) {
+ colors.push_back(bone_ik_color);
+ colors.push_back(bone_ik_color);
+ colors.push_back(bone_ik_color);
+ colors.push_back(bone_ik_color);
+ } else {
+ colors.push_back(bone_color1);
+ colors.push_back(bone_color2);
+ colors.push_back(bone_color1);
+ colors.push_back(bone_color2);
+ }
- RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape_outline, outline_colors);
- RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape, colors);
- }
+ Vector<Color> outline_colors;
+ if (CanvasItemEditor::get_singleton()->editor_selection->is_selected(this)) {
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ outline_colors.push_back(bone_selected_color);
+ } else {
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ outline_colors.push_back(bone_outline_color);
+ }
+
+ RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape_outline, outline_colors);
+ RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape, colors);
+ }
+ } break;
+#endif // TOOLS_ENABLED
}
-#endif // TOOLS_ENALBED
}
#ifdef TOOLS_ENABLED
diff --git a/scene/2d/sprite_2d.cpp b/scene/2d/sprite_2d.cpp
index 389fa0388f..facd164a0e 100644
--- a/scene/2d/sprite_2d.cpp
+++ b/scene/2d/sprite_2d.cpp
@@ -122,11 +122,6 @@ void Sprite2D::_notification(int p_what) {
RID ci = get_canvas_item();
- /*
- texture->draw(ci,Point2());
- break;
- */
-
Rect2 src_rect, dst_rect;
bool filter_clip_enabled;
_get_rects(src_rect, dst_rect, filter_clip_enabled);
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 02ca1ba2aa..0d50d7f8d6 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -31,7 +31,7 @@
#include "tile_map.h"
#include "core/io/marshalls.h"
-
+#include "scene/resources/world_2d.h"
#include "servers/navigation_server_2d.h"
Map<Vector2i, TileSet::CellNeighbor> TileMap::TerrainConstraint::get_overlapping_coords_and_peering_bits() const {
@@ -489,6 +489,7 @@ void TileMap::_notification(int p_what) {
_clear_internals();
_recreate_internals();
} break;
+
case NOTIFICATION_EXIT_TREE: {
_clear_internals();
} break;
@@ -980,7 +981,7 @@ void TileMap::_recompute_rect_cache() {
void TileMap::_rendering_notification(int p_what) {
switch (p_what) {
- case CanvasItem::NOTIFICATION_VISIBILITY_CHANGED: {
+ case NOTIFICATION_VISIBILITY_CHANGED: {
bool visible = is_visible_in_tree();
for (int layer = 0; layer < (int)layers.size(); layer++) {
for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
@@ -997,7 +998,8 @@ void TileMap::_rendering_notification(int p_what) {
}
}
} break;
- case CanvasItem::NOTIFICATION_TRANSFORM_CHANGED: {
+
+ case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_inside_tree()) {
return;
}
@@ -1016,7 +1018,8 @@ void TileMap::_rendering_notification(int p_what) {
}
}
} break;
- case CanvasItem::NOTIFICATION_DRAW: {
+
+ case NOTIFICATION_DRAW: {
if (tile_set.is_valid()) {
RenderingServer::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), is_y_sort_enabled());
}
@@ -1369,7 +1372,7 @@ void TileMap::draw_tile(RID p_canvas_item, Vector2i p_position, const Ref<TileSe
void TileMap::_physics_notification(int p_what) {
switch (p_what) {
- case CanvasItem::NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
bool in_editor = false;
#ifdef TOOLS_ENABLED
in_editor = Engine::get_singleton()->is_editor_hint();
@@ -1382,7 +1385,8 @@ void TileMap::_physics_notification(int p_what) {
set_notify_local_transform(true);
}
} break;
- case CanvasItem::NOTIFICATION_TRANSFORM_CHANGED: {
+
+ case NOTIFICATION_TRANSFORM_CHANGED: {
bool in_editor = false;
#ifdef TOOLS_ENABLED
in_editor = Engine::get_singleton()->is_editor_hint();
@@ -1404,6 +1408,7 @@ void TileMap::_physics_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
bool in_editor = false;
#ifdef TOOLS_ENABLED
@@ -1600,7 +1605,7 @@ void TileMap::_physics_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
void TileMap::_navigation_notification(int p_what) {
switch (p_what) {
- case CanvasItem::NOTIFICATION_TRANSFORM_CHANGED: {
+ case NOTIFICATION_TRANSFORM_CHANGED: {
if (is_inside_tree()) {
for (int layer = 0; layer < (int)layers.size(); layer++) {
Transform2D tilemap_xform = get_global_transform();
diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp
index ff186b01f2..9a68c17269 100644
--- a/scene/2d/touch_screen_button.cpp
+++ b/scene/2d/touch_screen_button.cpp
@@ -134,8 +134,8 @@ void TouchScreenButton::_notification(int p_what) {
draw_set_transform_matrix(get_canvas_transform().translated(pos));
shape->draw(get_canvas_item(), draw_col);
}
-
} break;
+
case NOTIFICATION_ENTER_TREE: {
if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
return;
@@ -145,13 +145,14 @@ void TouchScreenButton::_notification(int p_what) {
if (!Engine::get_singleton()->is_editor_hint()) {
set_process_input(is_visible_in_tree());
}
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (is_pressed()) {
_release(true);
}
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
if (Engine::get_singleton()->is_editor_hint()) {
break;
@@ -165,6 +166,7 @@ void TouchScreenButton::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_PAUSED: {
if (is_pressed()) {
_release();
diff --git a/scene/2d/visible_on_screen_notifier_2d.cpp b/scene/2d/visible_on_screen_notifier_2d.cpp
index a7c2ae5bb1..4bceaf71c6 100644
--- a/scene/2d/visible_on_screen_notifier_2d.cpp
+++ b/scene/2d/visible_on_screen_notifier_2d.cpp
@@ -75,15 +75,16 @@ Rect2 VisibleOnScreenNotifier2D::get_rect() const {
void VisibleOnScreenNotifier2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
- //get_world_2d()->
on_screen = false;
RS::get_singleton()->canvas_item_set_visibility_notifier(get_canvas_item(), true, rect, callable_mp(this, &VisibleOnScreenNotifier2D::_visibility_enter), callable_mp(this, &VisibleOnScreenNotifier2D::_visibility_exit));
} break;
+
case NOTIFICATION_DRAW: {
if (Engine::get_singleton()->is_editor_hint()) {
draw_rect(rect, Color(1, 0.5, 1, 0.2));
}
} break;
+
case NOTIFICATION_EXIT_TREE: {
on_screen = false;
RS::get_singleton()->canvas_item_set_visibility_notifier(get_canvas_item(), false, Rect2(), Callable(), Callable());
@@ -169,21 +170,23 @@ void VisibleOnScreenEnabler2D::_update_enable_mode(bool p_enable) {
}
}
void VisibleOnScreenEnabler2D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- if (Engine::get_singleton()->is_editor_hint()) {
- return;
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ if (Engine::get_singleton()->is_editor_hint()) {
+ return;
+ }
- node_id = ObjectID();
- Node *node = get_node(enable_node_path);
- if (node) {
- node_id = node->get_instance_id();
- node->set_process_mode(PROCESS_MODE_DISABLED);
- }
- }
+ node_id = ObjectID();
+ Node *node = get_node(enable_node_path);
+ if (node) {
+ node_id = node->get_instance_id();
+ node->set_process_mode(PROCESS_MODE_DISABLED);
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- node_id = ObjectID();
+ case NOTIFICATION_EXIT_TREE: {
+ node_id = ObjectID();
+ } break;
}
}
diff --git a/scene/3d/area_3d.cpp b/scene/3d/area_3d.cpp
index 5123a6eb6c..78c968a3d4 100644
--- a/scene/3d/area_3d.cpp
+++ b/scene/3d/area_3d.cpp
@@ -344,10 +344,14 @@ void Area3D::_clear_monitoring() {
}
void Area3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_EXIT_TREE) {
- _clear_monitoring();
- } else if (p_what == NOTIFICATION_ENTER_TREE) {
- _initialize_wind();
+ switch (p_what) {
+ case NOTIFICATION_EXIT_TREE: {
+ _clear_monitoring();
+ } break;
+
+ case NOTIFICATION_ENTER_TREE: {
+ _initialize_wind();
+ } break;
}
}
diff --git a/scene/3d/audio_listener_3d.cpp b/scene/3d/audio_listener_3d.cpp
index 0eb7588958..1ead9bb384 100644
--- a/scene/3d/audio_listener_3d.cpp
+++ b/scene/3d/audio_listener_3d.cpp
@@ -85,9 +85,11 @@ void AudioListener3D::_notification(int p_what) {
make_current();
}
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
_request_listener_update();
} break;
+
case NOTIFICATION_EXIT_WORLD: {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
@@ -100,7 +102,6 @@ void AudioListener3D::_notification(int p_what) {
}
get_viewport()->_audio_listener_3d_remove(this);
-
} break;
}
}
diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp
index 3b52974b8e..b17201f86b 100644
--- a/scene/3d/audio_stream_player_3d.cpp
+++ b/scene/3d/audio_stream_player_3d.cpp
@@ -239,80 +239,82 @@ float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
}
void AudioStreamPlayer3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- velocity_tracker->reset(get_global_transform().origin);
- AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
- if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
- play();
- }
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ velocity_tracker->reset(get_global_transform().origin);
+ AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
+ if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
+ play();
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- stop();
- AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
- }
+ case NOTIFICATION_EXIT_TREE: {
+ stop();
+ AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
+ } break;
- if (p_what == NOTIFICATION_PAUSED) {
- if (!can_process()) {
- // Node can't process so we start fading out to silence
- set_stream_paused(true);
- }
- }
+ case NOTIFICATION_PAUSED: {
+ if (!can_process()) {
+ // Node can't process so we start fading out to silence.
+ set_stream_paused(true);
+ }
+ } break;
- if (p_what == NOTIFICATION_UNPAUSED) {
- set_stream_paused(false);
- }
+ case NOTIFICATION_UNPAUSED: {
+ set_stream_paused(false);
+ } break;
- if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
- velocity_tracker->update_position(get_global_transform().origin);
- }
- }
+ case NOTIFICATION_TRANSFORM_CHANGED: {
+ if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
+ velocity_tracker->update_position(get_global_transform().origin);
+ }
+ } break;
- if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
- //update anything related to position first, if possible of course
- Vector<AudioFrame> volume_vector;
- if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
- volume_vector = _update_panning();
- }
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ // Update anything related to position first, if possible of course.
+ Vector<AudioFrame> volume_vector;
+ if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
+ volume_vector = _update_panning();
+ }
- if (setplay.get() >= 0 && stream.is_valid()) {
- active.set();
- Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
- ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
- Map<StringName, Vector<AudioFrame>> bus_map;
- bus_map[_get_actual_bus()] = volume_vector;
- AudioServer::get_singleton()->start_playback_stream(new_playback, bus_map, setplay.get(), actual_pitch_scale, linear_attenuation, attenuation_filter_cutoff_hz);
- stream_playbacks.push_back(new_playback);
- setplay.set(-1);
- }
+ if (setplay.get() >= 0 && stream.is_valid()) {
+ active.set();
+ Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
+ ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
+ Map<StringName, Vector<AudioFrame>> bus_map;
+ bus_map[_get_actual_bus()] = volume_vector;
+ AudioServer::get_singleton()->start_playback_stream(new_playback, bus_map, setplay.get(), actual_pitch_scale, linear_attenuation, attenuation_filter_cutoff_hz);
+ stream_playbacks.push_back(new_playback);
+ setplay.set(-1);
+ }
- if (!stream_playbacks.is_empty() && active.is_set()) {
- // Stop playing if no longer active.
- Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
- for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
- if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
- playbacks_to_remove.push_back(playback);
+ if (!stream_playbacks.is_empty() && active.is_set()) {
+ // Stop playing if no longer active.
+ Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
+ for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
+ if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
+ playbacks_to_remove.push_back(playback);
+ }
+ }
+ // Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
+ for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
+ stream_playbacks.erase(playback);
+ }
+ if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
+ // This node is no longer actively playing audio.
+ active.clear();
+ set_physics_process_internal(false);
+ }
+ if (!playbacks_to_remove.is_empty()) {
+ emit_signal(SNAME("finished"));
}
}
- // Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
- for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
- stream_playbacks.erase(playback);
- }
- if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
- // This node is no longer actively playing audio.
- active.clear();
- set_physics_process_internal(false);
- }
- if (!playbacks_to_remove.is_empty()) {
- emit_signal(SNAME("finished"));
- }
- }
- while (stream_playbacks.size() > max_polyphony) {
- AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
- stream_playbacks.remove_at(0);
- }
+ while (stream_playbacks.size() > max_polyphony) {
+ AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
+ stream_playbacks.remove_at(0);
+ }
+ } break;
}
}
diff --git a/scene/3d/bone_attachment_3d.cpp b/scene/3d/bone_attachment_3d.cpp
index 73a4dcd1f7..8623c7d8b6 100644
--- a/scene/3d/bone_attachment_3d.cpp
+++ b/scene/3d/bone_attachment_3d.cpp
@@ -340,17 +340,20 @@ void BoneAttachment3D::_notification(int p_what) {
}
_check_bind();
} break;
+
case NOTIFICATION_EXIT_TREE: {
_check_unbind();
} break;
+
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
_transform_changed();
} break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
if (_override_dirty) {
_override_dirty = false;
}
- }
+ } break;
}
}
diff --git a/scene/3d/camera_3d.cpp b/scene/3d/camera_3d.cpp
index 2c95010eb4..4eace17cc0 100644
--- a/scene/3d/camera_3d.cpp
+++ b/scene/3d/camera_3d.cpp
@@ -82,12 +82,6 @@ void Camera3D::_update_camera() {
RenderingServer::get_singleton()->camera_set_transform(camera, get_camera_transform());
- // here goes listener stuff
- /*
- if (viewport_ptr && is_inside_scene() && is_current())
- get_viewport()->_camera_3d_transform_changed_notify();
- */
-
if (get_tree()->is_node_being_edited(this) || !is_current()) {
return;
}
@@ -108,14 +102,15 @@ void Camera3D::_notification(int p_what) {
if (current || first_camera) {
viewport->_camera_3d_set(this);
}
-
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
_request_camera_update();
if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
velocity_tracker->update_position(get_global_transform().origin);
}
} break;
+
case NOTIFICATION_EXIT_WORLD: {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
@@ -131,13 +126,14 @@ void Camera3D::_notification(int p_what) {
viewport->_camera_3d_remove(this);
viewport = nullptr;
}
-
} break;
+
case NOTIFICATION_BECAME_CURRENT: {
if (viewport) {
viewport->find_world_3d()->_register_camera(this);
}
} break;
+
case NOTIFICATION_LOST_CURRENT: {
if (viewport) {
viewport->find_world_3d()->_remove_camera(this);
diff --git a/scene/3d/camera_3d.h b/scene/3d/camera_3d.h
index b5665814c7..9f2f8ceed1 100644
--- a/scene/3d/camera_3d.h
+++ b/scene/3d/camera_3d.h
@@ -33,6 +33,8 @@
#include "scene/3d/node_3d.h"
#include "scene/3d/velocity_tracker_3d.h"
+#include "scene/resources/camera_effects.h"
+#include "scene/resources/environment.h"
class Camera3D : public Node3D {
GDCLASS(Camera3D, Node3D);
diff --git a/scene/3d/collision_polygon_3d.cpp b/scene/3d/collision_polygon_3d.cpp
index 7926175459..88ef44b71f 100644
--- a/scene/3d/collision_polygon_3d.cpp
+++ b/scene/3d/collision_polygon_3d.cpp
@@ -93,18 +93,19 @@ void CollisionPolygon3D::_notification(int p_what) {
_update_in_shape_owner();
}
} break;
+
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
-
} break;
+
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}
-
} break;
+
case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);
diff --git a/scene/3d/collision_shape_3d.cpp b/scene/3d/collision_shape_3d.cpp
index 773095b377..e1a0e1427b 100644
--- a/scene/3d/collision_shape_3d.cpp
+++ b/scene/3d/collision_shape_3d.cpp
@@ -87,16 +87,19 @@ void CollisionShape3D::_notification(int p_what) {
_update_in_shape_owner();
}
} break;
+
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
} break;
+
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}
} break;
+
case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);
diff --git a/scene/3d/cpu_particles_3d.cpp b/scene/3d/cpu_particles_3d.cpp
index e3d551d782..a02b5f48a1 100644
--- a/scene/3d/cpu_particles_3d.cpp
+++ b/scene/3d/cpu_particles_3d.cpp
@@ -1251,65 +1251,67 @@ void CPUParticles3D::_update_render_thread() {
}
void CPUParticles3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- set_process_internal(emitting);
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ set_process_internal(emitting);
- // first update before rendering to avoid one frame delay after emitting starts
- if (emitting && (time == 0)) {
- _update_internal();
- }
- }
+ // first update before rendering to avoid one frame delay after emitting starts
+ if (emitting && (time == 0)) {
+ _update_internal();
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- _set_redraw(false);
- }
+ case NOTIFICATION_EXIT_TREE: {
+ _set_redraw(false);
+ } break;
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- // first update before rendering to avoid one frame delay after emitting starts
- if (emitting && (time == 0)) {
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ // first update before rendering to avoid one frame delay after emitting starts
+ if (emitting && (time == 0)) {
+ _update_internal();
+ }
+ } break;
+
+ case NOTIFICATION_INTERNAL_PROCESS: {
_update_internal();
- }
- }
+ } break;
- if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- _update_internal();
- }
+ case NOTIFICATION_TRANSFORM_CHANGED: {
+ inv_emission_transform = get_global_transform().affine_inverse();
- if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- inv_emission_transform = get_global_transform().affine_inverse();
+ if (!local_coords) {
+ int pc = particles.size();
+
+ float *w = particle_data.ptrw();
+ const Particle *r = particles.ptr();
+ float *ptr = w;
+
+ for (int i = 0; i < pc; i++) {
+ Transform3D t = inv_emission_transform * r[i].transform;
+
+ if (r[i].active) {
+ ptr[0] = t.basis.elements[0][0];
+ ptr[1] = t.basis.elements[0][1];
+ ptr[2] = t.basis.elements[0][2];
+ ptr[3] = t.origin.x;
+ ptr[4] = t.basis.elements[1][0];
+ ptr[5] = t.basis.elements[1][1];
+ ptr[6] = t.basis.elements[1][2];
+ ptr[7] = t.origin.y;
+ ptr[8] = t.basis.elements[2][0];
+ ptr[9] = t.basis.elements[2][1];
+ ptr[10] = t.basis.elements[2][2];
+ ptr[11] = t.origin.z;
+ } else {
+ memset(ptr, 0, sizeof(float) * 12);
+ }
- if (!local_coords) {
- int pc = particles.size();
-
- float *w = particle_data.ptrw();
- const Particle *r = particles.ptr();
- float *ptr = w;
-
- for (int i = 0; i < pc; i++) {
- Transform3D t = inv_emission_transform * r[i].transform;
-
- if (r[i].active) {
- ptr[0] = t.basis.elements[0][0];
- ptr[1] = t.basis.elements[0][1];
- ptr[2] = t.basis.elements[0][2];
- ptr[3] = t.origin.x;
- ptr[4] = t.basis.elements[1][0];
- ptr[5] = t.basis.elements[1][1];
- ptr[6] = t.basis.elements[1][2];
- ptr[7] = t.origin.y;
- ptr[8] = t.basis.elements[2][0];
- ptr[9] = t.basis.elements[2][1];
- ptr[10] = t.basis.elements[2][2];
- ptr[11] = t.origin.z;
- } else {
- memset(ptr, 0, sizeof(float) * 12);
+ ptr += 20;
}
- ptr += 20;
+ can_update.set();
}
-
- can_update.set();
- }
+ } break;
}
}
diff --git a/scene/3d/gpu_particles_3d.cpp b/scene/3d/gpu_particles_3d.cpp
index aaaa728838..4e35f37291 100644
--- a/scene/3d/gpu_particles_3d.cpp
+++ b/scene/3d/gpu_particles_3d.cpp
@@ -423,38 +423,41 @@ NodePath GPUParticles3D::get_sub_emitter() const {
}
void GPUParticles3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) {
- if (can_process()) {
- RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
- } else {
- RS::get_singleton()->particles_set_speed_scale(particles, 0);
- }
- }
-
- // Use internal process when emitting and one_shot is on so that when
- // the shot ends the editor can properly update
- if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- if (one_shot && !is_emitting()) {
- notify_property_list_changed();
- set_process_internal(false);
- }
- }
+ switch (p_what) {
+ case NOTIFICATION_PAUSED:
+ case NOTIFICATION_UNPAUSED: {
+ if (can_process()) {
+ RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
+ } else {
+ RS::get_singleton()->particles_set_speed_scale(particles, 0);
+ }
+ } break;
+
+ // Use internal process when emitting and one_shot is on so that when
+ // the shot ends the editor can properly update.
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ if (one_shot && !is_emitting()) {
+ notify_property_list_changed();
+ set_process_internal(false);
+ }
+ } break;
- if (p_what == NOTIFICATION_ENTER_TREE) {
- if (sub_emitter != NodePath()) {
- _attach_sub_emitter();
- }
- }
+ case NOTIFICATION_ENTER_TREE: {
+ if (sub_emitter != NodePath()) {
+ _attach_sub_emitter();
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- RS::get_singleton()->particles_set_subemitter(particles, RID());
- }
+ case NOTIFICATION_EXIT_TREE: {
+ RS::get_singleton()->particles_set_subemitter(particles, RID());
+ } break;
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- // make sure particles are updated before rendering occurs if they were active before
- if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) {
- RS::get_singleton()->particles_request_process(particles);
- }
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ // Make sure particles are updated before rendering occurs if they were active before.
+ if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) {
+ RS::get_singleton()->particles_request_process(particles);
+ }
+ } break;
}
}
diff --git a/scene/3d/gpu_particles_collision_3d.cpp b/scene/3d/gpu_particles_collision_3d.cpp
index 54fbc720ce..6f94df284a 100644
--- a/scene/3d/gpu_particles_collision_3d.cpp
+++ b/scene/3d/gpu_particles_collision_3d.cpp
@@ -584,47 +584,49 @@ GPUParticlesCollisionSDF3D::~GPUParticlesCollisionSDF3D() {
////////////////////////////
void GPUParticlesCollisionHeightField3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- if (update_mode == UPDATE_MODE_ALWAYS) {
- RS::get_singleton()->particles_collision_height_field_update(_get_collision());
- }
+ switch (p_what) {
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ if (update_mode == UPDATE_MODE_ALWAYS) {
+ RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+ }
- if (follow_camera_mode && get_viewport()) {
- Camera3D *cam = get_viewport()->get_camera_3d();
- if (cam) {
- Transform3D xform = get_global_transform();
- Vector3 x_axis = xform.basis.get_axis(Vector3::AXIS_X).normalized();
- Vector3 z_axis = xform.basis.get_axis(Vector3::AXIS_Z).normalized();
- float x_len = xform.basis.get_scale().x;
- float z_len = xform.basis.get_scale().z;
+ if (follow_camera_mode && get_viewport()) {
+ Camera3D *cam = get_viewport()->get_camera_3d();
+ if (cam) {
+ Transform3D xform = get_global_transform();
+ Vector3 x_axis = xform.basis.get_axis(Vector3::AXIS_X).normalized();
+ Vector3 z_axis = xform.basis.get_axis(Vector3::AXIS_Z).normalized();
+ float x_len = xform.basis.get_scale().x;
+ float z_len = xform.basis.get_scale().z;
- Vector3 cam_pos = cam->get_global_transform().origin;
- Transform3D new_xform = xform;
+ Vector3 cam_pos = cam->get_global_transform().origin;
+ Transform3D new_xform = xform;
- while (x_axis.dot(cam_pos - new_xform.origin) > x_len) {
- new_xform.origin += x_axis * x_len;
- }
- while (x_axis.dot(cam_pos - new_xform.origin) < -x_len) {
- new_xform.origin -= x_axis * x_len;
- }
+ while (x_axis.dot(cam_pos - new_xform.origin) > x_len) {
+ new_xform.origin += x_axis * x_len;
+ }
+ while (x_axis.dot(cam_pos - new_xform.origin) < -x_len) {
+ new_xform.origin -= x_axis * x_len;
+ }
- while (z_axis.dot(cam_pos - new_xform.origin) > z_len) {
- new_xform.origin += z_axis * z_len;
- }
- while (z_axis.dot(cam_pos - new_xform.origin) < -z_len) {
- new_xform.origin -= z_axis * z_len;
- }
+ while (z_axis.dot(cam_pos - new_xform.origin) > z_len) {
+ new_xform.origin += z_axis * z_len;
+ }
+ while (z_axis.dot(cam_pos - new_xform.origin) < -z_len) {
+ new_xform.origin -= z_axis * z_len;
+ }
- if (new_xform != xform) {
- set_global_transform(new_xform);
- RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+ if (new_xform != xform) {
+ set_global_transform(new_xform);
+ RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+ }
}
}
- }
- }
+ } break;
- if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+ case NOTIFICATION_TRANSFORM_CHANGED: {
+ RS::get_singleton()->particles_collision_height_field_update(_get_collision());
+ } break;
}
}
diff --git a/scene/3d/joint_3d.cpp b/scene/3d/joint_3d.cpp
index bd47ab3462..36abd0a5c5 100644
--- a/scene/3d/joint_3d.cpp
+++ b/scene/3d/joint_3d.cpp
@@ -169,6 +169,7 @@ void Joint3D::_notification(int p_what) {
case NOTIFICATION_READY: {
_update_joint();
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (joint.is_valid()) {
_disconnect_signals();
diff --git a/scene/3d/light_3d.cpp b/scene/3d/light_3d.cpp
index d88bb815bc..b2e605a262 100644
--- a/scene/3d/light_3d.cpp
+++ b/scene/3d/light_3d.cpp
@@ -177,12 +177,11 @@ void Light3D::_update_visibility() {
}
void Light3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- _update_visibility();
- }
-
- if (p_what == NOTIFICATION_ENTER_TREE) {
- _update_visibility();
+ switch (p_what) {
+ case NOTIFICATION_VISIBILITY_CHANGED:
+ case NOTIFICATION_ENTER_TREE: {
+ _update_visibility();
+ } break;
}
}
diff --git a/scene/3d/lightmap_gi.cpp b/scene/3d/lightmap_gi.cpp
index 825742da35..68d2b91fad 100644
--- a/scene/3d/lightmap_gi.cpp
+++ b/scene/3d/lightmap_gi.cpp
@@ -1176,16 +1176,18 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
}
void LightmapGI::_notification(int p_what) {
- if (p_what == NOTIFICATION_POST_ENTER_TREE) {
- if (light_data.is_valid()) {
- _assign_lightmaps();
- }
- }
+ switch (p_what) {
+ case NOTIFICATION_POST_ENTER_TREE: {
+ if (light_data.is_valid()) {
+ _assign_lightmaps();
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- if (light_data.is_valid()) {
- _clear_lightmaps();
- }
+ case NOTIFICATION_EXIT_TREE: {
+ if (light_data.is_valid()) {
+ _clear_lightmaps();
+ }
+ } break;
}
}
diff --git a/scene/3d/mesh_instance_3d.cpp b/scene/3d/mesh_instance_3d.cpp
index 58ff512130..fddfa17dbb 100644
--- a/scene/3d/mesh_instance_3d.cpp
+++ b/scene/3d/mesh_instance_3d.cpp
@@ -328,8 +328,10 @@ void MeshInstance3D::create_multiple_convex_collisions() {
}
void MeshInstance3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- _resolve_skeleton_path();
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ _resolve_skeleton_path();
+ } break;
}
}
diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp
index e90971845e..c4f062f0f9 100644
--- a/scene/3d/navigation_agent_3d.cpp
+++ b/scene/3d/navigation_agent_3d.cpp
@@ -103,10 +103,12 @@ void NavigationAgent3D::_notification(int p_what) {
}
set_physics_process_internal(true);
} break;
+
case NOTIFICATION_EXIT_TREE: {
agent_parent = nullptr;
set_physics_process_internal(false);
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (agent_parent) {
NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin);
diff --git a/scene/3d/navigation_obstacle_3d.cpp b/scene/3d/navigation_obstacle_3d.cpp
index ba6c50d98c..308545b2cc 100644
--- a/scene/3d/navigation_obstacle_3d.cpp
+++ b/scene/3d/navigation_obstacle_3d.cpp
@@ -63,17 +63,21 @@ void NavigationObstacle3D::_notification(int p_what) {
}
set_physics_process_internal(true);
} break;
+
case NOTIFICATION_EXIT_TREE: {
parent_node3d = nullptr;
set_physics_process_internal(false);
} break;
+
case NOTIFICATION_PARENTED: {
parent_node3d = Object::cast_to<Node3D>(get_parent());
reevaluate_agent_radius();
} break;
+
case NOTIFICATION_UNPARENTED: {
parent_node3d = nullptr;
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (parent_node3d) {
NavigationServer3D::get_singleton()->agent_set_position(agent, parent_node3d->get_global_transform().origin);
diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp
index 1e298e0137..8f0fd8706d 100644
--- a/scene/3d/navigation_region_3d.cpp
+++ b/scene/3d/navigation_region_3d.cpp
@@ -93,12 +93,12 @@ void NavigationRegion3D::_notification(int p_what) {
add_child(dm);
debug_view = dm;
}
-
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform());
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
NavigationServer3D::get_singleton()->region_set_map(region, RID());
diff --git a/scene/3d/node_3d.cpp b/scene/3d/node_3d.cpp
index cad1201d63..62cc7c143b 100644
--- a/scene/3d/node_3d.cpp
+++ b/scene/3d/node_3d.cpp
@@ -147,8 +147,8 @@ void Node3D::_notification(int p_what) {
notification(NOTIFICATION_ENTER_WORLD);
_update_visibility_parent(true);
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
notification(NOTIFICATION_EXIT_WORLD, true);
if (xform_change.in_list()) {
@@ -162,6 +162,7 @@ void Node3D::_notification(int p_what) {
data.top_level_active = false;
_update_visibility_parent(true);
} break;
+
case NOTIFICATION_ENTER_WORLD: {
data.inside_world = true;
data.viewport = nullptr;
@@ -192,6 +193,7 @@ void Node3D::_notification(int p_what) {
}
#endif
} break;
+
case NOTIFICATION_EXIT_WORLD: {
#ifdef TOOLS_ENABLED
clear_gizmos();
@@ -203,7 +205,6 @@ void Node3D::_notification(int p_what) {
data.viewport = nullptr;
data.inside_world = false;
-
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@@ -213,9 +214,6 @@ void Node3D::_notification(int p_what) {
}
#endif
} break;
-
- default: {
- }
}
}
diff --git a/scene/3d/node_3d.h b/scene/3d/node_3d.h
index 4abda66187..65d0e071cf 100644
--- a/scene/3d/node_3d.h
+++ b/scene/3d/node_3d.h
@@ -32,6 +32,7 @@
#define NODE_3D_H
#include "scene/main/node.h"
+#include "scene/resources/world_3d.h"
class Node3DGizmo : public RefCounted {
GDCLASS(Node3DGizmo, RefCounted);
diff --git a/scene/3d/occluder_instance_3d.cpp b/scene/3d/occluder_instance_3d.cpp
index e0e2eae4a5..855922c341 100644
--- a/scene/3d/occluder_instance_3d.cpp
+++ b/scene/3d/occluder_instance_3d.cpp
@@ -29,42 +29,27 @@
/*************************************************************************/
#include "occluder_instance_3d.h"
+
+#include "core/config/project_settings.h"
#include "core/core_string_names.h"
+#include "core/math/geometry_2d.h"
+#include "core/math/triangulate.h"
+#include "scene/3d/importer_mesh_instance_3d.h"
#include "scene/3d/mesh_instance_3d.h"
+#include "scene/resources/importer_mesh.h"
+#include "scene/resources/surface_tool.h"
+
+#ifdef TOOLS_ENABLED
+#include "editor/editor_node.h"
+#endif
RID Occluder3D::get_rid() const {
- if (!occluder.is_valid()) {
- occluder = RS::get_singleton()->occluder_create();
- RS::get_singleton()->occluder_set_mesh(occluder, vertices, indices);
- }
return occluder;
}
-void Occluder3D::set_vertices(PackedVector3Array p_vertices) {
- vertices = p_vertices;
- if (occluder.is_valid()) {
- RS::get_singleton()->occluder_set_mesh(occluder, vertices, indices);
- }
- _update_changes();
-}
+void Occluder3D::_update() {
+ _update_arrays(vertices, indices);
-PackedVector3Array Occluder3D::get_vertices() const {
- return vertices;
-}
-
-void Occluder3D::set_indices(PackedInt32Array p_indices) {
- indices = p_indices;
- if (occluder.is_valid()) {
- RS::get_singleton()->occluder_set_mesh(occluder, vertices, indices);
- }
- _update_changes();
-}
-
-PackedInt32Array Occluder3D::get_indices() const {
- return indices;
-}
-
-void Occluder3D::_update_changes() {
aabb = AABB();
const Vector3 *ptr = vertices.ptr();
@@ -75,9 +60,18 @@ void Occluder3D::_update_changes() {
debug_lines.clear();
debug_mesh.unref();
+ RS::get_singleton()->occluder_set_mesh(occluder, vertices, indices);
emit_changed();
}
+PackedVector3Array Occluder3D::get_vertices() const {
+ return vertices;
+}
+
+PackedInt32Array Occluder3D::get_indices() const {
+ return indices;
+}
+
Vector<Vector3> Occluder3D::get_debug_lines() const {
if (!debug_lines.is_empty()) {
return debug_lines;
@@ -87,14 +81,18 @@ Vector<Vector3> Occluder3D::get_debug_lines() const {
return Vector<Vector3>();
}
+ const Vector3 *vertices_ptr = vertices.ptr();
+ debug_lines.resize(indices.size() / 3 * 6);
+ Vector3 *line_ptr = debug_lines.ptrw();
+ int line_i = 0;
for (int i = 0; i < indices.size() / 3; i++) {
for (int j = 0; j < 3; j++) {
int a = indices[i * 3 + j];
int b = indices[i * 3 + (j + 1) % 3];
ERR_FAIL_INDEX_V_MSG(a, vertices.size(), Vector<Vector3>(), "Occluder indices are out of range.");
ERR_FAIL_INDEX_V_MSG(b, vertices.size(), Vector<Vector3>(), "Occluder indices are out of range.");
- debug_lines.push_back(vertices[a]);
- debug_lines.push_back(vertices[b]);
+ line_ptr[line_i++] = vertices_ptr[a];
+ line_ptr[line_i++] = vertices_ptr[b];
}
}
return debug_lines;
@@ -105,7 +103,7 @@ Ref<ArrayMesh> Occluder3D::get_debug_mesh() const {
return debug_mesh;
}
- if (indices.size() % 3 != 0) {
+ if (vertices.is_empty() || indices.is_empty() || indices.size() % 3 != 0) {
return debug_mesh;
}
@@ -123,18 +121,19 @@ AABB Occluder3D::get_aabb() const {
return aabb;
}
-void Occluder3D::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &Occluder3D::set_vertices);
- ClassDB::bind_method(D_METHOD("get_vertices"), &Occluder3D::get_vertices);
-
- ClassDB::bind_method(D_METHOD("set_indices", "indices"), &Occluder3D::set_indices);
- ClassDB::bind_method(D_METHOD("get_indices"), &Occluder3D::get_indices);
+void Occluder3D::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_POSTINITIALIZE: {
+ _update();
+ } break;
+ }
+}
- ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_vertices", "get_vertices");
- ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "indices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_indices", "get_indices");
+void Occluder3D::_bind_methods() {
}
Occluder3D::Occluder3D() {
+ occluder = RS::get_singleton()->occluder_create();
}
Occluder3D::~Occluder3D() {
@@ -142,6 +141,289 @@ Occluder3D::~Occluder3D() {
RS::get_singleton()->free(occluder);
}
}
+
+/////////////////////////////////////////////////
+
+void ArrayOccluder3D::set_arrays(PackedVector3Array p_vertices, PackedInt32Array p_indices) {
+ vertices = p_vertices;
+ indices = p_indices;
+ _update();
+}
+
+void ArrayOccluder3D::set_vertices(PackedVector3Array p_vertices) {
+ vertices = p_vertices;
+ _update();
+}
+
+void ArrayOccluder3D::set_indices(PackedInt32Array p_indices) {
+ indices = p_indices;
+ _update();
+}
+
+void ArrayOccluder3D::_update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
+ r_vertices = vertices;
+ r_indices = indices;
+}
+
+void ArrayOccluder3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_arrays", "vertices", "indices"), &ArrayOccluder3D::set_arrays);
+
+ ClassDB::bind_method(D_METHOD("set_vertices", "vertices"), &ArrayOccluder3D::set_vertices);
+ ClassDB::bind_method(D_METHOD("get_vertices"), &ArrayOccluder3D::get_vertices);
+
+ ClassDB::bind_method(D_METHOD("set_indices", "indices"), &ArrayOccluder3D::set_indices);
+ ClassDB::bind_method(D_METHOD("get_indices"), &ArrayOccluder3D::get_indices);
+
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR3_ARRAY, "vertices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_vertices", "get_vertices");
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_INT32_ARRAY, "indices", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NO_EDITOR), "set_indices", "get_indices");
+}
+
+ArrayOccluder3D::ArrayOccluder3D() {
+}
+
+ArrayOccluder3D::~ArrayOccluder3D() {
+}
+
+/////////////////////////////////////////////////
+
+void QuadOccluder3D::set_size(const Vector2 &p_size) {
+ if (size == p_size) {
+ return;
+ }
+
+ size = p_size.max(Vector2());
+ _update();
+}
+
+Vector2 QuadOccluder3D::get_size() const {
+ return size;
+}
+
+void QuadOccluder3D::_update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
+ Vector2 _size = Vector2(size.x / 2.0f, size.y / 2.0f);
+
+ r_vertices = {
+ Vector3(-_size.x, -_size.y, 0),
+ Vector3(-_size.x, _size.y, 0),
+ Vector3(_size.x, _size.y, 0),
+ Vector3(_size.x, -_size.y, 0),
+ };
+
+ r_indices = {
+ 0, 1, 2,
+ 0, 2, 3
+ };
+}
+
+void QuadOccluder3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_size", "size"), &QuadOccluder3D::set_size);
+ ClassDB::bind_method(D_METHOD("get_size"), &QuadOccluder3D::get_size);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size");
+}
+
+QuadOccluder3D::QuadOccluder3D() {
+}
+
+QuadOccluder3D::~QuadOccluder3D() {
+}
+
+/////////////////////////////////////////////////
+
+void BoxOccluder3D::set_size(const Vector3 &p_size) {
+ if (size == p_size) {
+ return;
+ }
+
+ size = Vector3(MAX(p_size.x, 0.0f), MAX(p_size.y, 0.0f), MAX(p_size.z, 0.0f));
+ _update();
+}
+
+Vector3 BoxOccluder3D::get_size() const {
+ return size;
+}
+
+void BoxOccluder3D::_update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
+ Vector3 _size = Vector3(size.x / 2.0f, size.y / 2.0f, size.z / 2.0f);
+
+ r_vertices = {
+ // front
+ Vector3(-_size.x, -_size.y, _size.z),
+ Vector3(_size.x, -_size.y, _size.z),
+ Vector3(_size.x, _size.y, _size.z),
+ Vector3(-_size.x, _size.y, _size.z),
+ // back
+ Vector3(-_size.x, -_size.y, -_size.z),
+ Vector3(_size.x, -_size.y, -_size.z),
+ Vector3(_size.x, _size.y, -_size.z),
+ Vector3(-_size.x, _size.y, -_size.z),
+ };
+
+ r_indices = {
+ // front
+ 0, 1, 2,
+ 2, 3, 0,
+ // right
+ 1, 5, 6,
+ 6, 2, 1,
+ // back
+ 7, 6, 5,
+ 5, 4, 7,
+ // left
+ 4, 0, 3,
+ 3, 7, 4,
+ // bottom
+ 4, 5, 1,
+ 1, 0, 4,
+ // top
+ 3, 2, 6,
+ 6, 7, 3
+ };
+}
+
+void BoxOccluder3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_size", "size"), &BoxOccluder3D::set_size);
+ ClassDB::bind_method(D_METHOD("get_size"), &BoxOccluder3D::get_size);
+
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR3, "size"), "set_size", "get_size");
+}
+
+BoxOccluder3D::BoxOccluder3D() {
+}
+
+BoxOccluder3D::~BoxOccluder3D() {
+}
+
+/////////////////////////////////////////////////
+
+void SphereOccluder3D::set_radius(float p_radius) {
+ if (radius == p_radius) {
+ return;
+ }
+
+ radius = MAX(p_radius, 0.0f);
+ _update();
+}
+
+float SphereOccluder3D::get_radius() const {
+ return radius;
+}
+
+void SphereOccluder3D::_update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
+ r_vertices.resize((RINGS + 2) * (RADIAL_SEGMENTS + 1));
+ int vertex_i = 0;
+ Vector3 *vertex_ptr = r_vertices.ptrw();
+
+ r_indices.resize((RINGS + 1) * RADIAL_SEGMENTS * 6);
+ int idx_i = 0;
+ int *idx_ptr = r_indices.ptrw();
+
+ int current_row = 0;
+ int previous_row = 0;
+ int point = 0;
+ for (int j = 0; j <= (RINGS + 1); j++) {
+ float v = j / float(RINGS + 1);
+ float w = Math::sin(Math_PI * v);
+ float y = Math::cos(Math_PI * v);
+ for (int i = 0; i <= RADIAL_SEGMENTS; i++) {
+ float u = i / float(RADIAL_SEGMENTS);
+
+ float x = Math::cos(u * Math_TAU);
+ float z = Math::sin(u * Math_TAU);
+ vertex_ptr[vertex_i++] = Vector3(x * w, y, z * w) * radius;
+
+ if (i > 0 && j > 0) {
+ idx_ptr[idx_i++] = previous_row + i - 1;
+ idx_ptr[idx_i++] = previous_row + i;
+ idx_ptr[idx_i++] = current_row + i - 1;
+
+ idx_ptr[idx_i++] = previous_row + i;
+ idx_ptr[idx_i++] = current_row + i;
+ idx_ptr[idx_i++] = current_row + i - 1;
+ }
+
+ point++;
+ }
+
+ previous_row = current_row;
+ current_row = point;
+ }
+}
+
+void SphereOccluder3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_radius", "radius"), &SphereOccluder3D::set_radius);
+ ClassDB::bind_method(D_METHOD("get_radius"), &SphereOccluder3D::get_radius);
+
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "radius"), "set_radius", "get_radius");
+}
+
+SphereOccluder3D::SphereOccluder3D() {
+}
+
+SphereOccluder3D::~SphereOccluder3D() {
+}
+
+/////////////////////////////////////////////////
+
+void PolygonOccluder3D::set_polygon(const Vector<Vector2> &p_polygon) {
+ polygon = p_polygon;
+ _update();
+}
+
+Vector<Vector2> PolygonOccluder3D::get_polygon() const {
+ return polygon;
+}
+
+void PolygonOccluder3D::_update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
+ if (polygon.size() < 3) {
+ r_vertices.clear();
+ r_indices.clear();
+ return;
+ }
+
+ Vector<Point2> occluder_polygon = polygon;
+ if (Triangulate::get_area(occluder_polygon) > 0) {
+ occluder_polygon.reverse();
+ }
+
+ Vector<int> occluder_indices = Geometry2D::triangulate_polygon(occluder_polygon);
+
+ if (occluder_indices.size() < 3) {
+ r_vertices.clear();
+ r_indices.clear();
+ ERR_FAIL_MSG("Failed to triangulate PolygonOccluder3D. Make sure the polygon doesn't have any intersecting edges.");
+ }
+
+ r_vertices.resize(occluder_polygon.size());
+ Vector3 *vertex_ptr = r_vertices.ptrw();
+ const Vector2 *polygon_ptr = occluder_polygon.ptr();
+ for (int i = 0; i < occluder_polygon.size(); i++) {
+ vertex_ptr[i] = Vector3(polygon_ptr[i].x, polygon_ptr[i].y, 0.0);
+ }
+
+ r_indices.resize(occluder_indices.size());
+ memcpy(r_indices.ptrw(), occluder_indices.ptr(), occluder_indices.size() * sizeof(int));
+}
+
+bool PolygonOccluder3D::_has_editable_3d_polygon_no_depth() const {
+ return false;
+}
+
+void PolygonOccluder3D::_bind_methods() {
+ ClassDB::bind_method(D_METHOD("set_polygon", "polygon"), &PolygonOccluder3D::set_polygon);
+ ClassDB::bind_method(D_METHOD("get_polygon"), &PolygonOccluder3D::get_polygon);
+
+ ClassDB::bind_method(D_METHOD("_has_editable_3d_polygon_no_depth"), &PolygonOccluder3D::_has_editable_3d_polygon_no_depth);
+
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "polygon"), "set_polygon", "get_polygon");
+}
+
+PolygonOccluder3D::PolygonOccluder3D() {
+}
+
+PolygonOccluder3D::~PolygonOccluder3D() {
+}
+
/////////////////////////////////////////////////
AABB OccluderInstance3D::get_aabb() const {
@@ -175,6 +457,13 @@ void OccluderInstance3D::set_occluder(const Ref<Occluder3D> &p_occluder) {
update_gizmos();
update_configuration_warnings();
+
+#ifdef TOOLS_ENABLED
+ // PolygonOccluder3D is edited via an editor plugin, this ensures the plugin is shown/hidden when necessary
+ if (Engine::get_singleton()->is_editor_hint()) {
+ EditorNode::get_singleton()->call_deferred(SNAME("edit_current"));
+ }
+#endif
}
void OccluderInstance3D::_occluder_changed() {
@@ -195,6 +484,14 @@ uint32_t OccluderInstance3D::get_bake_mask() const {
return bake_mask;
}
+void OccluderInstance3D::set_bake_simplification_distance(float p_dist) {
+ bake_simplification_dist = MAX(p_dist, 0.0f);
+}
+
+float OccluderInstance3D::get_bake_simplification_distance() const {
+ return bake_simplification_dist;
+}
+
void OccluderInstance3D::set_bake_mask_value(int p_layer_number, bool p_value) {
ERR_FAIL_COND_MSG(p_layer_number < 1, "Render layer number must be between 1 and 20 inclusive.");
ERR_FAIL_COND_MSG(p_layer_number > 20, "Render layer number must be between 1 and 20 inclusive.");
@@ -221,6 +518,47 @@ bool OccluderInstance3D::_bake_material_check(Ref<Material> p_material) {
return true;
}
+void OccluderInstance3D::_bake_surface(const Transform3D &p_transform, Array p_surface_arrays, Ref<Material> p_material, float p_simplification_dist, PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
+ if (!_bake_material_check(p_material)) {
+ return;
+ }
+ ERR_FAIL_COND_MSG(p_surface_arrays.size() != Mesh::ARRAY_MAX, "Invalid surface array.");
+
+ PackedVector3Array vertices = p_surface_arrays[Mesh::ARRAY_VERTEX];
+ PackedInt32Array indices = p_surface_arrays[Mesh::ARRAY_INDEX];
+
+ if (vertices.size() == 0 || indices.size() == 0) {
+ return;
+ }
+
+ Vector3 *vertices_ptr = vertices.ptrw();
+ for (int j = 0; j < vertices.size(); j++) {
+ vertices_ptr[j] = p_transform.xform(vertices_ptr[j]);
+ }
+
+ if (!Math::is_zero_approx(p_simplification_dist) && SurfaceTool::simplify_func) {
+ float error_scale = SurfaceTool::simplify_scale_func((float *)vertices.ptr(), vertices.size(), sizeof(Vector3));
+ float target_error = p_simplification_dist / error_scale;
+ float error = -1.0f;
+ int target_index_count = MIN(indices.size(), 36);
+ uint32_t index_count = SurfaceTool::simplify_func((unsigned int *)indices.ptrw(), (unsigned int *)indices.ptr(), indices.size(), (float *)vertices.ptr(), vertices.size(), sizeof(Vector3), target_index_count, target_error, &error);
+ indices.resize(index_count);
+ }
+
+ SurfaceTool::strip_mesh_arrays(vertices, indices);
+
+ int vertex_offset = r_vertices.size();
+ r_vertices.resize(vertex_offset + vertices.size());
+ memcpy(r_vertices.ptrw() + vertex_offset, vertices.ptr(), vertices.size() * sizeof(Vector3));
+
+ int index_offset = r_indices.size();
+ r_indices.resize(index_offset + indices.size());
+ int *idx_ptr = r_indices.ptrw();
+ for (int j = 0; j < indices.size(); j++) {
+ idx_ptr[index_offset + j] = vertex_offset + indices[j];
+ }
+}
+
void OccluderInstance3D::_bake_node(Node *p_node, PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node);
if (mi && mi->is_visible_in_tree()) {
@@ -243,58 +581,76 @@ void OccluderInstance3D::_bake_node(Node *p_node, PackedVector3Array &r_vertices
Transform3D global_to_local = get_global_transform().affine_inverse() * mi->get_global_transform();
for (int i = 0; i < mesh->get_surface_count(); i++) {
- if (mesh->surface_get_primitive_type(i) != Mesh::PRIMITIVE_TRIANGLES) {
- continue;
- }
+ _bake_surface(global_to_local, mesh->surface_get_arrays(i), mi->get_active_material(i), bake_simplification_dist, r_vertices, r_indices);
+ }
+ }
+ }
- if (mi->get_surface_override_material(i).is_valid()) {
- if (!_bake_material_check(mi->get_surface_override_material(i))) {
- continue;
- }
- } else {
- if (!_bake_material_check(mesh->surface_get_material(i))) {
- continue;
- }
- }
+ for (int i = 0; i < p_node->get_child_count(); i++) {
+ Node *child = p_node->get_child(i);
+ if (!child->get_owner()) {
+ continue; // may be a helper
+ }
- Array arrays = mesh->surface_get_arrays(i);
+ _bake_node(child, r_vertices, r_indices);
+ }
+}
- int vertex_offset = r_vertices.size();
- PackedVector3Array vertices = arrays[Mesh::ARRAY_VERTEX];
- r_vertices.resize(r_vertices.size() + vertices.size());
+void OccluderInstance3D::bake_single_node(const Node3D *p_node, float p_simplification_distance, PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
+ ERR_FAIL_COND(!p_node);
- Vector3 *vtx_ptr = r_vertices.ptrw();
- for (int j = 0; j < vertices.size(); j++) {
- vtx_ptr[vertex_offset + j] = global_to_local.xform(vertices[j]);
- }
+ Transform3D xform = p_node->is_inside_tree() ? p_node->get_global_transform() : p_node->get_transform();
- int index_offset = r_indices.size();
- PackedInt32Array indices = arrays[Mesh::ARRAY_INDEX];
- r_indices.resize(r_indices.size() + indices.size());
+ const MeshInstance3D *mi = Object::cast_to<MeshInstance3D>(p_node);
+ if (mi) {
+ Ref<Mesh> mesh = mi->get_mesh();
+ bool valid = true;
- int *idx_ptr = r_indices.ptrw();
- for (int j = 0; j < indices.size(); j++) {
- idx_ptr[index_offset + j] = vertex_offset + indices[j];
- }
+ if (mesh.is_null()) {
+ valid = false;
+ }
+
+ if (valid && !_bake_material_check(mi->get_material_override())) {
+ valid = false;
+ }
+
+ if (valid) {
+ for (int i = 0; i < mesh->get_surface_count(); i++) {
+ _bake_surface(xform, mesh->surface_get_arrays(i), mi->get_active_material(i), p_simplification_distance, r_vertices, r_indices);
}
}
}
- for (int i = 0; i < p_node->get_child_count(); i++) {
- Node *child = p_node->get_child(i);
- if (!child->get_owner()) {
- continue; //maybe a helper
+ const ImporterMeshInstance3D *imi = Object::cast_to<ImporterMeshInstance3D>(p_node);
+ if (imi) {
+ Ref<ImporterMesh> mesh = imi->get_mesh();
+ bool valid = true;
+
+ if (mesh.is_null()) {
+ valid = false;
}
- _bake_node(child, r_vertices, r_indices);
+ if (valid) {
+ for (int i = 0; i < mesh->get_surface_count(); i++) {
+ Ref<Material> material = imi->get_surface_material(i);
+ if (material.is_null()) {
+ material = mesh->get_surface_material(i);
+ }
+ _bake_surface(xform, mesh->get_surface_arrays(i), material, p_simplification_distance, r_vertices, r_indices);
+ }
+ }
}
}
-OccluderInstance3D::BakeError OccluderInstance3D::bake(Node *p_from_node, String p_occluder_path) {
+OccluderInstance3D::BakeError OccluderInstance3D::bake_scene(Node *p_from_node, String p_occluder_path) {
if (p_occluder_path.is_empty()) {
if (get_occluder().is_null()) {
return BAKE_ERROR_NO_SAVE_PATH;
}
+ p_occluder_path = get_occluder()->get_path();
+ if (!p_occluder_path.is_resource_file()) {
+ return BAKE_ERROR_NO_SAVE_PATH;
+ }
}
PackedVector3Array vertices;
@@ -306,16 +662,25 @@ OccluderInstance3D::BakeError OccluderInstance3D::bake(Node *p_from_node, String
return BAKE_ERROR_NO_MESHES;
}
- Ref<Occluder3D> occ;
+ Ref<ArrayOccluder3D> occ;
if (get_occluder().is_valid()) {
occ = get_occluder();
- } else {
+ set_occluder(Ref<Occluder3D>()); // clear
+ }
+
+ if (occ.is_null()) {
occ.instantiate();
- occ->set_path(p_occluder_path);
}
- occ->set_vertices(vertices);
- occ->set_indices(indices);
+ occ->set_arrays(vertices, indices);
+
+ Error err = ResourceSaver::save(p_occluder_path, occ);
+
+ if (err != OK) {
+ return BAKE_ERROR_CANT_SAVE;
+ }
+
+ occ->set_path(p_occluder_path);
set_occluder(occ);
return BAKE_ERROR_OK;
@@ -333,28 +698,49 @@ TypedArray<String> OccluderInstance3D::get_configuration_warnings() const {
}
if (occluder.is_null()) {
- warnings.push_back(TTR("No occluder mesh is defined in the Occluder property, so no occlusion culling will be performed using this OccluderInstance3D.\nTo resolve this, select the OccluderInstance3D then use the Bake Occluders button at the top of the 3D editor viewport."));
- } else if (occluder->get_vertices().size() < 3) {
- // Using the "New Occluder" dropdown button won't result in a correct occluder,
- // so warn the user about this.
- warnings.push_back(TTR("The occluder mesh has less than 3 vertices, so no occlusion culling will be performed using this OccluderInstance3D.\nTo generate a proper occluder mesh, select the OccluderInstance3D then use the Bake Occluders button at the top of the 3D editor viewport."));
+ warnings.push_back(TTR("No occluder mesh is defined in the Occluder property, so no occlusion culling will be performed using this OccluderInstance3D.\nTo resolve this, set the Occluder property to one of the primitive occluder types or bake the scene meshes by selecting the OccluderInstance3D and pressing the Bake Occluders button at the top of the 3D editor viewport."));
+ } else {
+ Ref<ArrayOccluder3D> arr_occluder = occluder;
+ if (arr_occluder.is_valid() && arr_occluder->get_indices().size() < 3) {
+ // Setting a new ArrayOccluder3D from the inspector will create an empty occluder,
+ // so warn the user about this.
+ warnings.push_back(TTR("The occluder mesh has less than 3 vertices, so no occlusion culling will be performed using this OccluderInstance3D.\nTo generate a proper occluder mesh, select the OccluderInstance3D then use the Bake Occluders button at the top of the 3D editor viewport."));
+ }
+ Ref<PolygonOccluder3D> poly_occluder = occluder;
+ if (poly_occluder.is_valid() && poly_occluder->get_polygon().size() < 3) {
+ warnings.push_back(TTR("The polygon occluder has less than 3 vertices, so no occlusion culling will be performed using this OccluderInstance3D.\nVertices can be added in the inspector or using the polygon editing tools at the top of the 3D editor viewport."));
+ }
}
return warnings;
}
+bool OccluderInstance3D::_is_editable_3d_polygon() const {
+ return Ref<PolygonOccluder3D>(occluder).is_valid();
+}
+
+Ref<Resource> OccluderInstance3D::_get_editable_3d_polygon_resource() const {
+ return occluder;
+}
+
void OccluderInstance3D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_bake_mask", "mask"), &OccluderInstance3D::set_bake_mask);
ClassDB::bind_method(D_METHOD("get_bake_mask"), &OccluderInstance3D::get_bake_mask);
ClassDB::bind_method(D_METHOD("set_bake_mask_value", "layer_number", "value"), &OccluderInstance3D::set_bake_mask_value);
ClassDB::bind_method(D_METHOD("get_bake_mask_value", "layer_number"), &OccluderInstance3D::get_bake_mask_value);
+ ClassDB::bind_method(D_METHOD("set_bake_simplification_distance", "simplification_distance"), &OccluderInstance3D::set_bake_simplification_distance);
+ ClassDB::bind_method(D_METHOD("get_bake_simplification_distance"), &OccluderInstance3D::get_bake_simplification_distance);
ClassDB::bind_method(D_METHOD("set_occluder", "occluder"), &OccluderInstance3D::set_occluder);
ClassDB::bind_method(D_METHOD("get_occluder"), &OccluderInstance3D::get_occluder);
+ ClassDB::bind_method(D_METHOD("_is_editable_3d_polygon"), &OccluderInstance3D::_is_editable_3d_polygon);
+ ClassDB::bind_method(D_METHOD("_get_editable_3d_polygon_resource"), &OccluderInstance3D::_get_editable_3d_polygon_resource);
+
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "occluder", PROPERTY_HINT_RESOURCE_TYPE, "Occluder3D"), "set_occluder", "get_occluder");
ADD_GROUP("Bake", "bake_");
ADD_PROPERTY(PropertyInfo(Variant::INT, "bake_mask", PROPERTY_HINT_LAYERS_3D_RENDER), "set_bake_mask", "get_bake_mask");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "bake_simplification_distance", PROPERTY_HINT_RANGE, "0.0,2.0,0.01"), "set_bake_simplification_distance", "get_bake_simplification_distance");
}
OccluderInstance3D::OccluderInstance3D() {
diff --git a/scene/3d/occluder_instance_3d.h b/scene/3d/occluder_instance_3d.h
index 8a8d4c9af4..669ddba775 100644
--- a/scene/3d/occluder_instance_3d.h
+++ b/scene/3d/occluder_instance_3d.h
@@ -37,24 +37,23 @@ class Occluder3D : public Resource {
GDCLASS(Occluder3D, Resource);
RES_BASE_EXTENSION("occ");
- mutable RID occluder;
- mutable Ref<ArrayMesh> debug_mesh;
- mutable Vector<Vector3> debug_lines;
- AABB aabb;
-
+ RID occluder;
PackedVector3Array vertices;
PackedInt32Array indices;
+ AABB aabb;
- void _update_changes();
+ mutable Ref<ArrayMesh> debug_mesh;
+ mutable Vector<Vector3> debug_lines;
protected:
+ void _update();
+ virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) = 0;
+
static void _bind_methods();
+ void _notification(int p_what);
public:
- void set_vertices(PackedVector3Array p_vertices);
PackedVector3Array get_vertices() const;
-
- void set_indices(PackedInt32Array p_indices);
PackedInt32Array get_indices() const;
Vector<Vector3> get_debug_lines() const;
@@ -63,7 +62,102 @@ public:
virtual RID get_rid() const override;
Occluder3D();
- ~Occluder3D();
+ virtual ~Occluder3D();
+};
+
+class ArrayOccluder3D : public Occluder3D {
+ GDCLASS(ArrayOccluder3D, Occluder3D);
+
+ PackedVector3Array vertices;
+ PackedInt32Array indices;
+
+protected:
+ virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
+ static void _bind_methods();
+
+public:
+ void set_arrays(PackedVector3Array p_vertices, PackedInt32Array p_indices);
+ void set_vertices(PackedVector3Array p_vertices);
+ void set_indices(PackedInt32Array p_indices);
+
+ ArrayOccluder3D();
+ ~ArrayOccluder3D();
+};
+
+class QuadOccluder3D : public Occluder3D {
+ GDCLASS(QuadOccluder3D, Occluder3D);
+
+private:
+ Vector2 size = Vector2(1.0f, 1.0f);
+
+protected:
+ virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
+ static void _bind_methods();
+
+public:
+ Vector2 get_size() const;
+ void set_size(const Vector2 &p_size);
+
+ QuadOccluder3D();
+ ~QuadOccluder3D();
+};
+
+class BoxOccluder3D : public Occluder3D {
+ GDCLASS(BoxOccluder3D, Occluder3D);
+
+private:
+ Vector3 size = Vector3(1.0f, 1.0f, 1.0f);
+
+protected:
+ virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
+ static void _bind_methods();
+
+public:
+ Vector3 get_size() const;
+ void set_size(const Vector3 &p_size);
+
+ BoxOccluder3D();
+ ~BoxOccluder3D();
+};
+
+class SphereOccluder3D : public Occluder3D {
+ GDCLASS(SphereOccluder3D, Occluder3D);
+
+private:
+ static constexpr int RINGS = 7;
+ static constexpr int RADIAL_SEGMENTS = 7;
+ float radius = 1.0f;
+
+protected:
+ virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
+ static void _bind_methods();
+
+public:
+ float get_radius() const;
+ void set_radius(float p_radius);
+
+ SphereOccluder3D();
+ ~SphereOccluder3D();
+};
+
+class PolygonOccluder3D : public Occluder3D {
+ GDCLASS(PolygonOccluder3D, Occluder3D);
+
+private:
+ Vector<Vector2> polygon;
+
+ bool _has_editable_3d_polygon_no_depth() const;
+
+protected:
+ virtual void _update_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) override;
+ static void _bind_methods();
+
+public:
+ void set_polygon(const Vector<Vector2> &p_polygon);
+ Vector<Vector2> get_polygon() const;
+
+ PolygonOccluder3D();
+ ~PolygonOccluder3D();
};
class OccluderInstance3D : public VisualInstance3D {
@@ -72,12 +166,17 @@ class OccluderInstance3D : public VisualInstance3D {
private:
Ref<Occluder3D> occluder;
uint32_t bake_mask = 0xFFFFFFFF;
+ float bake_simplification_dist = 0.1f;
void _occluder_changed();
- bool _bake_material_check(Ref<Material> p_material);
+ static bool _bake_material_check(Ref<Material> p_material);
+ static void _bake_surface(const Transform3D &p_transform, Array p_surface_arrays, Ref<Material> p_material, float p_simplification_dist, PackedVector3Array &r_vertices, PackedInt32Array &r_indices);
void _bake_node(Node *p_node, PackedVector3Array &r_vertices, PackedInt32Array &r_indices);
+ bool _is_editable_3d_polygon() const;
+ Ref<Resource> _get_editable_3d_polygon_resource() const;
+
protected:
static void _bind_methods();
@@ -88,6 +187,7 @@ public:
BAKE_ERROR_OK,
BAKE_ERROR_NO_SAVE_PATH,
BAKE_ERROR_NO_MESHES,
+ BAKE_ERROR_CANT_SAVE,
};
void set_occluder(const Ref<Occluder3D> &p_occluder);
@@ -99,10 +199,14 @@ public:
void set_bake_mask(uint32_t p_mask);
uint32_t get_bake_mask() const;
+ void set_bake_simplification_distance(float p_dist);
+ float get_bake_simplification_distance() const;
+
void set_bake_mask_value(int p_layer_number, bool p_enable);
bool get_bake_mask_value(int p_layer_number) const;
- BakeError bake(Node *p_from_node, String p_occluder_path = "");
+ BakeError bake_scene(Node *p_from_node, String p_occluder_path = "");
+ static void bake_single_node(const Node3D *p_node, float p_simplification_distance, PackedVector3Array &r_vertices, PackedInt32Array &r_indices);
OccluderInstance3D();
~OccluderInstance3D();
diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp
index 6e1c9ef781..5fd28a6ff3 100644
--- a/scene/3d/path_3d.cpp
+++ b/scene/3d/path_3d.cpp
@@ -30,9 +30,6 @@
#include "path_3d.h"
-void Path3D::_notification(int p_what) {
-}
-
void Path3D::_curve_changed() {
if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
update_gizmos();
@@ -223,8 +220,8 @@ void PathFollow3D::_notification(int p_what) {
_update_transform(false);
}
}
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
path = nullptr;
} break;
diff --git a/scene/3d/path_3d.h b/scene/3d/path_3d.h
index 32ca5a1beb..e9ab557693 100644
--- a/scene/3d/path_3d.h
+++ b/scene/3d/path_3d.h
@@ -42,7 +42,6 @@ class Path3D : public Node3D {
void _curve_changed();
protected:
- void _notification(int p_what);
static void _bind_methods();
public:
diff --git a/scene/3d/physics_body_3d.cpp b/scene/3d/physics_body_3d.cpp
index 13a38f3b9f..c6d7e1df86 100644
--- a/scene/3d/physics_body_3d.cpp
+++ b/scene/3d/physics_body_3d.cpp
@@ -601,7 +601,7 @@ void RigidDynamicBody3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
- set_notify_local_transform(true); //used for warnings and only in editor
+ set_notify_local_transform(true); // Used for warnings and only in editor.
}
} break;
diff --git a/scene/3d/ray_cast_3d.cpp b/scene/3d/ray_cast_3d.cpp
index b71c54dcf9..f5e08b92ca 100644
--- a/scene/3d/ray_cast_3d.cpp
+++ b/scene/3d/ray_cast_3d.cpp
@@ -171,8 +171,8 @@ void RayCast3D::_notification(int p_what) {
exclude.erase(Object::cast_to<CollisionObject3D>(get_parent())->get_rid());
}
}
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (enabled) {
set_physics_process_internal(false);
@@ -181,8 +181,8 @@ void RayCast3D::_notification(int p_what) {
if (debug_shape) {
_clear_debug_shape();
}
-
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!enabled) {
break;
@@ -193,7 +193,6 @@ void RayCast3D::_notification(int p_what) {
if (prev_collision_state != collided && get_tree()->is_debugging_collisions_hint()) {
_update_debug_shape_material(true);
}
-
} break;
}
}
@@ -259,6 +258,13 @@ void RayCast3D::remove_exception(const CollisionObject3D *p_node) {
void RayCast3D::clear_exceptions() {
exclude.clear();
+
+ if (exclude_parent_body && is_inside_tree()) {
+ CollisionObject3D *parent = Object::cast_to<CollisionObject3D>(get_parent());
+ if (parent) {
+ exclude.insert(parent->get_rid());
+ }
+ }
}
void RayCast3D::set_collide_with_areas(bool p_enabled) {
diff --git a/scene/3d/remote_transform_3d.cpp b/scene/3d/remote_transform_3d.cpp
index 2770b6f40c..8b714850d6 100644
--- a/scene/3d/remote_transform_3d.cpp
+++ b/scene/3d/remote_transform_3d.cpp
@@ -111,8 +111,8 @@ void RemoteTransform3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_cache();
-
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_inside_tree()) {
break;
@@ -121,7 +121,6 @@ void RemoteTransform3D::_notification(int p_what) {
if (cache.is_valid()) {
_update_remote();
}
-
} break;
}
}
diff --git a/scene/3d/skeleton_3d.cpp b/scene/3d/skeleton_3d.cpp
index b6b5920f69..598897456d 100644
--- a/scene/3d/skeleton_3d.cpp
+++ b/scene/3d/skeleton_3d.cpp
@@ -318,11 +318,9 @@ void Skeleton3D::_notification(int p_what) {
rs->skeleton_bone_set_transform(skeleton, i, bonesptr[bone_index].pose_global * skin->get_bind_pose(i));
}
}
-
#ifdef TOOLS_ENABLED
emit_signal(SceneStringNames::get_singleton()->pose_updated);
#endif // TOOLS_ENABLED
-
} break;
#ifndef _3D_DISABLED
@@ -344,19 +342,14 @@ void Skeleton3D::_notification(int p_what) {
if (modification_stack.is_valid()) {
execute_modifications(get_physics_process_delta_time(), SkeletonModificationStack3D::EXECUTION_MODE::execution_mode_physics_process);
}
-
} break;
-#endif // _3D_DISABLED
-#ifndef _3D_DISABLED
case NOTIFICATION_INTERNAL_PROCESS: {
if (modification_stack.is_valid()) {
execute_modifications(get_process_delta_time(), SkeletonModificationStack3D::EXECUTION_MODE::execution_mode_process);
}
} break;
-#endif // _3D_DISABLED
-#ifndef _3D_DISABLED
case NOTIFICATION_READY: {
set_physics_process_internal(true);
set_process_internal(true);
diff --git a/scene/3d/skeleton_ik_3d.cpp b/scene/3d/skeleton_ik_3d.cpp
index c645009c72..f29b060069 100644
--- a/scene/3d/skeleton_ik_3d.cpp
+++ b/scene/3d/skeleton_ik_3d.cpp
@@ -407,14 +407,14 @@ void SkeletonIK3D::_notification(int p_what) {
set_process_priority(1);
reload_chain();
} break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
if (target_node_override) {
reload_goal();
}
-
_solve_chain();
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
reload_chain();
} break;
diff --git a/scene/3d/spring_arm_3d.cpp b/scene/3d/spring_arm_3d.cpp
index e0cd44e05b..230801bd52 100644
--- a/scene/3d/spring_arm_3d.cpp
+++ b/scene/3d/spring_arm_3d.cpp
@@ -29,23 +29,26 @@
/*************************************************************************/
#include "spring_arm_3d.h"
+
#include "scene/3d/camera_3d.h"
void SpringArm3D::_notification(int p_what) {
switch (p_what) {
- case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_ENTER_TREE: {
if (!Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(true);
}
- break;
- case NOTIFICATION_EXIT_TREE:
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
if (!Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(false);
}
- break;
- case NOTIFICATION_INTERNAL_PHYSICS_PROCESS:
+ } break;
+
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
process_spring();
- break;
+ } break;
}
}
@@ -185,14 +188,14 @@ void SpringArm3D::process_spring() {
}
current_spring_length = spring_length * motion_delta;
- Transform3D childs_transform;
- childs_transform.origin = get_global_transform().origin + cast_direction * (spring_length * motion_delta);
+ Transform3D child_transform;
+ child_transform.origin = get_global_transform().origin + cast_direction * (spring_length * motion_delta);
for (int i = get_child_count() - 1; 0 <= i; --i) {
Node3D *child = Object::cast_to<Node3D>(get_child(i));
if (child) {
- childs_transform.basis = child->get_global_transform().basis;
- child->set_global_transform(childs_transform);
+ child_transform.basis = child->get_global_transform().basis;
+ child->set_global_transform(child_transform);
}
}
}
diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp
index 331d58927b..b9fb3e9287 100644
--- a/scene/3d/sprite_3d.cpp
+++ b/scene/3d/sprite_3d.cpp
@@ -66,23 +66,25 @@ void SpriteBase3D::_propagate_color_changed() {
}
void SpriteBase3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- if (!pending_update) {
- _im_update();
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ if (!pending_update) {
+ _im_update();
+ }
- parent_sprite = Object::cast_to<SpriteBase3D>(get_parent());
- if (parent_sprite) {
- pI = parent_sprite->children.push_back(this);
- }
- }
+ parent_sprite = Object::cast_to<SpriteBase3D>(get_parent());
+ if (parent_sprite) {
+ pI = parent_sprite->children.push_back(this);
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- if (parent_sprite) {
- parent_sprite->children.erase(pI);
- pI = nullptr;
- parent_sprite = nullptr;
- }
+ case NOTIFICATION_EXIT_TREE: {
+ if (parent_sprite) {
+ parent_sprite->children.erase(pI);
+ pI = nullptr;
+ parent_sprite = nullptr;
+ }
+ } break;
}
}
@@ -694,10 +696,6 @@ Rect2 Sprite3D::get_item_rect() const {
if (texture.is_null()) {
return Rect2(0, 0, 1, 1);
}
- /*
- if (texture.is_null())
- return CanvasItem::get_item_rect();
- */
Size2 s;
diff --git a/scene/3d/vehicle_body_3d.cpp b/scene/3d/vehicle_body_3d.cpp
index a5fd3a7dd0..8d02d26fc4 100644
--- a/scene/3d/vehicle_body_3d.cpp
+++ b/scene/3d/vehicle_body_3d.cpp
@@ -116,9 +116,7 @@ TypedArray<String> VehicleWheel3D::get_configuration_warnings() const {
}
void VehicleWheel3D::_update(PhysicsDirectBodyState3D *s) {
- if (m_raycastInfo.m_isInContact)
-
- {
+ if (m_raycastInfo.m_isInContact) {
real_t project = m_raycastInfo.m_contactNormalWS.dot(m_raycastInfo.m_wheelDirectionWS);
Vector3 chassis_velocity_at_contactPoint;
Vector3 relpos = m_raycastInfo.m_contactPointWS - s->get_transform().origin;
@@ -135,11 +133,7 @@ void VehicleWheel3D::_update(PhysicsDirectBodyState3D *s) {
m_suspensionRelativeVelocity = projVel * inv;
m_clippedInvContactDotSuspension = inv;
}
-
- }
-
- else // Not in contact : position wheel in a nice (rest length) position
- {
+ } else { // Not in contact : position wheel in a nice (rest length) position
m_raycastInfo.m_suspensionLength = m_suspensionRestLength;
m_suspensionRelativeVelocity = real_t(0.0);
m_raycastInfo.m_contactNormalWS = -m_raycastInfo.m_wheelDirectionWS;
diff --git a/scene/3d/visible_on_screen_notifier_3d.cpp b/scene/3d/visible_on_screen_notifier_3d.cpp
index 44d2a3e03f..11367d7ca9 100644
--- a/scene/3d/visible_on_screen_notifier_3d.cpp
+++ b/scene/3d/visible_on_screen_notifier_3d.cpp
@@ -71,8 +71,11 @@ bool VisibleOnScreenNotifier3D::is_on_screen() const {
}
void VisibleOnScreenNotifier3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_EXIT_TREE) {
- on_screen = false;
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_EXIT_TREE: {
+ on_screen = false;
+ } break;
}
}
@@ -161,21 +164,23 @@ void VisibleOnScreenEnabler3D::_update_enable_mode(bool p_enable) {
}
}
void VisibleOnScreenEnabler3D::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- if (Engine::get_singleton()->is_editor_hint()) {
- return;
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ if (Engine::get_singleton()->is_editor_hint()) {
+ return;
+ }
- node_id = ObjectID();
- Node *node = get_node(enable_node_path);
- if (node) {
- node_id = node->get_instance_id();
- node->set_process_mode(PROCESS_MODE_DISABLED);
- }
- }
+ node_id = ObjectID();
+ Node *node = get_node(enable_node_path);
+ if (node) {
+ node_id = node->get_instance_id();
+ node->set_process_mode(PROCESS_MODE_DISABLED);
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- node_id = ObjectID();
+ case NOTIFICATION_EXIT_TREE: {
+ node_id = ObjectID();
+ } break;
}
}
diff --git a/scene/3d/visual_instance_3d.cpp b/scene/3d/visual_instance_3d.cpp
index 005bb5a737..d8dffe6c7d 100644
--- a/scene/3d/visual_instance_3d.cpp
+++ b/scene/3d/visual_instance_3d.cpp
@@ -47,27 +47,21 @@ void VisualInstance3D::_update_visibility() {
void VisualInstance3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
- // CHECK SKELETON => moving skeleton attaching logic to MeshInstance
- /*
- Skeleton *skeleton=Object::cast_to<Skeleton>(get_parent());
- if (skeleton)
- RenderingServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() );
- */
ERR_FAIL_COND(get_world_3d().is_null());
RenderingServer::get_singleton()->instance_set_scenario(instance, get_world_3d()->get_scenario());
_update_visibility();
-
} break;
+
case NOTIFICATION_TRANSFORM_CHANGED: {
Transform3D gt = get_global_transform();
RenderingServer::get_singleton()->instance_set_transform(instance, gt);
} break;
+
case NOTIFICATION_EXIT_WORLD: {
RenderingServer::get_singleton()->instance_set_scenario(instance, RID());
RenderingServer::get_singleton()->instance_attach_skeleton(instance, RID());
- //RS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() );
-
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
_update_visibility();
} break;
@@ -220,9 +214,6 @@ GeometryInstance3D::VisibilityRangeFadeMode GeometryInstance3D::get_visibility_r
return visibility_range_fade_mode;
}
-void GeometryInstance3D::_notification(int p_what) {
-}
-
const StringName *GeometryInstance3D::_instance_uniform_get_remap(const StringName p_name) const {
StringName *r = instance_uniform_property_remap.getptr(p_name);
if (!r) {
diff --git a/scene/3d/visual_instance_3d.h b/scene/3d/visual_instance_3d.h
index be964e5080..02f62b41e5 100644
--- a/scene/3d/visual_instance_3d.h
+++ b/scene/3d/visual_instance_3d.h
@@ -137,7 +137,6 @@ protected:
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
- void _notification(int p_what);
static void _bind_methods();
public:
diff --git a/scene/3d/world_environment.cpp b/scene/3d/world_environment.cpp
index 98f28a8cff..300e761f39 100644
--- a/scene/3d/world_environment.cpp
+++ b/scene/3d/world_environment.cpp
@@ -34,27 +34,32 @@
#include "scene/main/window.h"
void WorldEnvironment::_notification(int p_what) {
- if (p_what == Node3D::NOTIFICATION_ENTER_WORLD || p_what == Node3D::NOTIFICATION_ENTER_TREE) {
- if (environment.is_valid()) {
- add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
- _update_current_environment();
- }
-
- if (camera_effects.is_valid()) {
- add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
- _update_current_camera_effects();
- }
-
- } else if (p_what == Node3D::NOTIFICATION_EXIT_WORLD || p_what == Node3D::NOTIFICATION_EXIT_TREE) {
- if (environment.is_valid()) {
- remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
- _update_current_environment();
- }
-
- if (camera_effects.is_valid()) {
- remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
- _update_current_camera_effects();
- }
+ switch (p_what) {
+ case Node3D::NOTIFICATION_ENTER_WORLD:
+ case Node3D::NOTIFICATION_ENTER_TREE: {
+ if (environment.is_valid()) {
+ add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
+ _update_current_environment();
+ }
+
+ if (camera_effects.is_valid()) {
+ add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
+ _update_current_camera_effects();
+ }
+ } break;
+
+ case Node3D::NOTIFICATION_EXIT_WORLD:
+ case Node3D::NOTIFICATION_EXIT_TREE: {
+ if (environment.is_valid()) {
+ remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
+ _update_current_environment();
+ }
+
+ if (camera_effects.is_valid()) {
+ remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
+ _update_current_camera_effects();
+ }
+ } break;
}
}
diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp
index a054f35d2e..b18819c920 100644
--- a/scene/3d/xr_nodes.cpp
+++ b/scene/3d/xr_nodes.cpp
@@ -30,6 +30,7 @@
#include "xr_nodes.h"
+#include "core/config/project_settings.h"
#include "scene/main/viewport.h"
#include "servers/xr/xr_interface.h"
@@ -43,16 +44,17 @@ void XRCamera3D::_notification(int p_what) {
if (origin != nullptr) {
origin->set_tracked_camera(this);
}
- }; break;
+ } break;
+
case NOTIFICATION_EXIT_TREE: {
// need to find our XROrigin3D parent and let it know we're no longer its camera!
XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent());
if (origin != nullptr && origin->get_tracked_camera() == this) {
origin->set_tracked_camera(nullptr);
}
- }; break;
- };
-};
+ } break;
+ }
+}
void XRCamera3D::_changed_tracker(const StringName p_tracker_name, int p_tracker_type) {
if (p_tracker_name == tracker_name) {
@@ -482,22 +484,22 @@ void XRController3D::_unbind_tracker() {
void XRController3D::_button_pressed(const String &p_name) {
// just pass it on...
- emit_signal("button_pressed", p_name);
+ emit_signal(SNAME("button_pressed"), p_name);
}
void XRController3D::_button_released(const String &p_name) {
// just pass it on...
- emit_signal("button_released", p_name);
+ emit_signal(SNAME("button_released"), p_name);
}
void XRController3D::_input_value_changed(const String &p_name, float p_value) {
// just pass it on...
- emit_signal("input_value_changed", p_name, p_value);
+ emit_signal(SNAME("input_value_changed"), p_name, p_value);
}
void XRController3D::_input_axis_changed(const String &p_name, Vector2 p_value) {
// just pass it on...
- emit_signal("input_axis_changed", p_name, p_value);
+ emit_signal(SNAME("input_axis_changed"), p_name, p_value);
}
bool XRController3D::is_button_pressed(const StringName &p_name) const {
@@ -656,10 +658,12 @@ void XROrigin3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
set_process_internal(true);
- }; break;
+ } break;
+
case NOTIFICATION_EXIT_TREE: {
set_process_internal(false);
- }; break;
+ } break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
// set our world origin to our node transform
xr_server->set_world_origin(get_global_transform());
@@ -672,11 +676,9 @@ void XROrigin3D::_notification(int p_what) {
// now apply this to our camera
tracked_camera->set_transform(t);
- };
- }; break;
- default:
- break;
- };
+ }
+ } break;
+ }
// send our notification to all active XE interfaces, they may need to react to it also
for (int i = 0; i < xr_server->get_interface_count(); i++) {
diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp
index a68f7e037d..5ea7f4b7d9 100644
--- a/scene/animation/animation_node_state_machine.cpp
+++ b/scene/animation/animation_node_state_machine.cpp
@@ -807,9 +807,6 @@ String AnimationNodeStateMachine::get_caption() const {
return "StateMachine";
}
-void AnimationNodeStateMachine::_notification(int p_what) {
-}
-
Ref<AnimationNode> AnimationNodeStateMachine::get_child_by_name(const StringName &p_name) {
return get_node(p_name);
}
diff --git a/scene/animation/animation_node_state_machine.h b/scene/animation/animation_node_state_machine.h
index b980556875..3bae0fcffa 100644
--- a/scene/animation/animation_node_state_machine.h
+++ b/scene/animation/animation_node_state_machine.h
@@ -164,7 +164,6 @@ private:
void _tree_changed();
protected:
- void _notification(int p_what);
static void _bind_methods();
bool _set(const StringName &p_name, const Variant &p_value);
diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp
index 4a3fd72080..e243915c13 100644
--- a/scene/animation/animation_player.cpp
+++ b/scene/animation/animation_player.cpp
@@ -202,15 +202,16 @@ void AnimationPlayer::_notification(int p_what) {
set_physics_process_internal(false);
set_process_internal(false);
}
- //_set_process(false);
clear_caches();
} break;
+
case NOTIFICATION_READY: {
if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) {
play(autoplay);
_animation_process(0);
}
} break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
if (process_callback == ANIMATION_PROCESS_PHYSICS) {
break;
@@ -220,6 +221,7 @@ void AnimationPlayer::_notification(int p_what) {
_animation_process(get_process_delta_time());
}
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (process_callback == ANIMATION_PROCESS_IDLE) {
break;
@@ -229,6 +231,7 @@ void AnimationPlayer::_notification(int p_what) {
_animation_process(get_physics_process_delta_time());
}
} break;
+
case NOTIFICATION_EXIT_TREE: {
clear_caches();
} break;
@@ -592,18 +595,12 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, double
}
if (update_mode == Animation::UPDATE_CONTINUOUS || update_mode == Animation::UPDATE_CAPTURE || (p_delta == 0 && update_mode == Animation::UPDATE_DISCRETE)) { //delta == 0 means seek
-
Variant value = a->value_track_interpolate(i, p_time);
if (value == Variant()) {
continue;
}
- //thanks to trigger mode, this should be solved now..
- /*
- if (p_delta==0 && value.get_type()==Variant::STRING)
- continue; // doing this with strings is messy, should find another way
- */
if (pa->accum_pass != accum_pass) {
ERR_CONTINUE(cache_update_prop_size >= NODE_CACHE_UPDATE_MAX);
cache_update_prop[cache_update_prop_size++] = pa;
diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp
index f2f69fc439..a50618182d 100644
--- a/scene/animation/animation_tree.cpp
+++ b/scene/animation/animation_tree.cpp
@@ -1586,29 +1586,37 @@ void AnimationTree::advance(real_t p_time) {
}
void AnimationTree::_notification(int p_what) {
- if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_callback == ANIMATION_PROCESS_PHYSICS) {
- _process_graph(get_physics_process_delta_time());
- }
-
- if (active && p_what == NOTIFICATION_INTERNAL_PROCESS && process_callback == ANIMATION_PROCESS_IDLE) {
- _process_graph(get_process_delta_time());
- }
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ if (last_animation_player.is_valid()) {
+ Object *player = ObjectDB::get_instance(last_animation_player);
+ if (player) {
+ player->connect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
+ }
+ }
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
+ _clear_caches();
+ if (last_animation_player.is_valid()) {
+ Object *player = ObjectDB::get_instance(last_animation_player);
+ if (player) {
+ player->disconnect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
+ }
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- _clear_caches();
- if (last_animation_player.is_valid()) {
- Object *player = ObjectDB::get_instance(last_animation_player);
- if (player) {
- player->disconnect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ if (active && process_callback == ANIMATION_PROCESS_IDLE) {
+ _process_graph(get_process_delta_time());
}
- }
- } else if (p_what == NOTIFICATION_ENTER_TREE) {
- if (last_animation_player.is_valid()) {
- Object *player = ObjectDB::get_instance(last_animation_player);
- if (player) {
- player->connect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
+ } break;
+
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ if (active && process_callback == ANIMATION_PROCESS_PHYSICS) {
+ _process_graph(get_physics_process_delta_time());
}
- }
+ } break;
}
}
diff --git a/scene/animation/root_motion_view.cpp b/scene/animation/root_motion_view.cpp
index 0d44687588..46fe832cf5 100644
--- a/scene/animation/root_motion_view.cpp
+++ b/scene/animation/root_motion_view.cpp
@@ -29,8 +29,10 @@
/*************************************************************************/
#include "root_motion_view.h"
+
#include "scene/animation/animation_tree.h"
#include "scene/resources/material.h"
+
void RootMotionView::set_animation_path(const NodePath &p_path) {
path = p_path;
first = true;
@@ -76,84 +78,87 @@ bool RootMotionView::get_zero_y() const {
}
void RootMotionView::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- immediate_material = StandardMaterial3D::get_material_for_2d(false, true, false, false, false);
- first = true;
- }
-
- if (p_what == NOTIFICATION_INTERNAL_PROCESS || p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
- Transform3D transform;
-
- if (has_node(path)) {
- Node *node = get_node(path);
-
- AnimationTree *tree = Object::cast_to<AnimationTree>(node);
- if (tree && tree->is_active() && tree->get_root_motion_track() != NodePath()) {
- if (is_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_PHYSICS) {
- set_process_internal(false);
- set_physics_process_internal(true);
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ immediate_material = StandardMaterial3D::get_material_for_2d(false, true, false, false, false);
+ first = true;
+ } break;
+
+ case NOTIFICATION_INTERNAL_PROCESS:
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ Transform3D transform;
+
+ if (has_node(path)) {
+ Node *node = get_node(path);
+
+ AnimationTree *tree = Object::cast_to<AnimationTree>(node);
+ if (tree && tree->is_active() && tree->get_root_motion_track() != NodePath()) {
+ if (is_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_PHYSICS) {
+ set_process_internal(false);
+ set_physics_process_internal(true);
+ }
+
+ if (is_physics_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_IDLE) {
+ set_process_internal(true);
+ set_physics_process_internal(false);
+ }
+
+ transform = tree->get_root_motion_transform();
}
-
- if (is_physics_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_IDLE) {
- set_process_internal(true);
- set_physics_process_internal(false);
- }
-
- transform = tree->get_root_motion_transform();
}
- }
- if (!first && transform == Transform3D()) {
- return;
- }
+ if (!first && transform == Transform3D()) {
+ return;
+ }
- first = false;
+ first = false;
- transform.orthonormalize(); //don't want scale, too imprecise
- transform.affine_invert();
+ transform.orthonormalize(); //don't want scale, too imprecise
+ transform.affine_invert();
- accumulated = transform * accumulated;
- accumulated.origin.x = Math::fposmod(accumulated.origin.x, cell_size);
- if (zero_y) {
- accumulated.origin.y = 0;
- }
- accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size);
+ accumulated = transform * accumulated;
+ accumulated.origin.x = Math::fposmod(accumulated.origin.x, cell_size);
+ if (zero_y) {
+ accumulated.origin.y = 0;
+ }
+ accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size);
- immediate->clear_surfaces();
+ immediate->clear_surfaces();
- int cells_in_radius = int((radius / cell_size) + 1.0);
+ int cells_in_radius = int((radius / cell_size) + 1.0);
- immediate->surface_begin(Mesh::PRIMITIVE_LINES, immediate_material);
+ immediate->surface_begin(Mesh::PRIMITIVE_LINES, immediate_material);
- for (int i = -cells_in_radius; i < cells_in_radius; i++) {
- for (int j = -cells_in_radius; j < cells_in_radius; j++) {
- Vector3 from(i * cell_size, 0, j * cell_size);
- Vector3 from_i((i + 1) * cell_size, 0, j * cell_size);
- Vector3 from_j(i * cell_size, 0, (j + 1) * cell_size);
- from = accumulated.xform(from);
- from_i = accumulated.xform(from_i);
- from_j = accumulated.xform(from_j);
+ for (int i = -cells_in_radius; i < cells_in_radius; i++) {
+ for (int j = -cells_in_radius; j < cells_in_radius; j++) {
+ Vector3 from(i * cell_size, 0, j * cell_size);
+ Vector3 from_i((i + 1) * cell_size, 0, j * cell_size);
+ Vector3 from_j(i * cell_size, 0, (j + 1) * cell_size);
+ from = accumulated.xform(from);
+ from_i = accumulated.xform(from_i);
+ from_j = accumulated.xform(from_j);
- Color c = color, c_i = color, c_j = color;
- c.a *= MAX(0, 1.0 - from.length() / radius);
- c_i.a *= MAX(0, 1.0 - from_i.length() / radius);
- c_j.a *= MAX(0, 1.0 - from_j.length() / radius);
+ Color c = color, c_i = color, c_j = color;
+ c.a *= MAX(0, 1.0 - from.length() / radius);
+ c_i.a *= MAX(0, 1.0 - from_i.length() / radius);
+ c_j.a *= MAX(0, 1.0 - from_j.length() / radius);
- immediate->surface_set_color(c);
- immediate->surface_add_vertex(from);
+ immediate->surface_set_color(c);
+ immediate->surface_add_vertex(from);
- immediate->surface_set_color(c_i);
- immediate->surface_add_vertex(from_i);
+ immediate->surface_set_color(c_i);
+ immediate->surface_add_vertex(from_i);
- immediate->surface_set_color(c);
- immediate->surface_add_vertex(from);
+ immediate->surface_set_color(c);
+ immediate->surface_add_vertex(from);
- immediate->surface_set_color(c_j);
- immediate->surface_add_vertex(from_j);
+ immediate->surface_set_color(c_j);
+ immediate->surface_add_vertex(from_j);
+ }
}
- }
- immediate->surface_end();
+ immediate->surface_end();
+ } break;
}
}
diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp
index 5f9d8a0d47..c8e8ff1cd1 100644
--- a/scene/audio/audio_stream_player.cpp
+++ b/scene/audio/audio_stream_player.cpp
@@ -35,49 +35,51 @@
#include "servers/audio_server.h"
void AudioStreamPlayer::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
- play();
- }
- }
-
- if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
- for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
- if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
- playbacks_to_remove.push_back(playback);
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
+ play();
}
- }
- // Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
- for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
- stream_playbacks.erase(playback);
- }
- if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
- // This node is no longer actively playing audio.
- active.clear();
- set_process_internal(false);
- }
- if (!playbacks_to_remove.is_empty()) {
- emit_signal(SNAME("finished"));
- }
- }
+ } break;
+
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
+ for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
+ if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
+ playbacks_to_remove.push_back(playback);
+ }
+ }
+ // Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
+ for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
+ stream_playbacks.erase(playback);
+ }
+ if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
+ // This node is no longer actively playing audio.
+ active.clear();
+ set_process_internal(false);
+ }
+ if (!playbacks_to_remove.is_empty()) {
+ emit_signal(SNAME("finished"));
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
- AudioServer::get_singleton()->stop_playback_stream(playback);
- }
- stream_playbacks.clear();
- }
+ case NOTIFICATION_EXIT_TREE: {
+ for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
+ AudioServer::get_singleton()->stop_playback_stream(playback);
+ }
+ stream_playbacks.clear();
+ } break;
- if (p_what == NOTIFICATION_PAUSED) {
- if (!can_process()) {
- // Node can't process so we start fading out to silence
- set_stream_paused(true);
- }
- }
+ case NOTIFICATION_PAUSED: {
+ if (!can_process()) {
+ // Node can't process so we start fading out to silence
+ set_stream_paused(true);
+ }
+ } break;
- if (p_what == NOTIFICATION_UNPAUSED) {
- set_stream_paused(false);
+ case NOTIFICATION_UNPAUSED: {
+ set_stream_paused(false);
+ } break;
}
}
diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp
index 41340f281b..e5b81f9d8d 100644
--- a/scene/debugger/scene_debugger.cpp
+++ b/scene/debugger/scene_debugger.cpp
@@ -31,30 +31,121 @@
#include "scene_debugger.h"
#include "core/debugger/engine_debugger.h"
+#include "core/debugger/engine_profiler.h"
#include "core/io/marshalls.h"
#include "core/object/script_language.h"
#include "scene/main/scene_tree.h"
#include "scene/main/window.h"
#include "scene/resources/packed_scene.h"
-void SceneDebugger::initialize() {
+Array SceneDebugger::RPCProfilerFrame::serialize() {
+ Array arr;
+ arr.push_back(infos.size() * 4);
+ for (int i = 0; i < infos.size(); ++i) {
+ arr.push_back(uint64_t(infos[i].node));
+ arr.push_back(infos[i].node_path);
+ arr.push_back(infos[i].incoming_rpc);
+ arr.push_back(infos[i].outgoing_rpc);
+ }
+ return arr;
+}
+
+bool SceneDebugger::RPCProfilerFrame::deserialize(const Array &p_arr) {
+ ERR_FAIL_COND_V(p_arr.size() < 1, false);
+ uint32_t size = p_arr[0];
+ ERR_FAIL_COND_V(size % 4, false);
+ ERR_FAIL_COND_V((uint32_t)p_arr.size() != size + 1, false);
+ infos.resize(size / 4);
+ int idx = 1;
+ for (uint32_t i = 0; i < size / 4; ++i) {
+ infos.write[i].node = uint64_t(p_arr[idx]);
+ infos.write[i].node_path = p_arr[idx + 1];
+ infos.write[i].incoming_rpc = p_arr[idx + 2];
+ infos.write[i].outgoing_rpc = p_arr[idx + 3];
+ }
+ return true;
+}
+
+class SceneDebugger::RPCProfiler : public EngineProfiler {
+ Map<ObjectID, RPCNodeInfo> rpc_node_data;
+ uint64_t last_profile_time = 0;
+
+ void init_node(const ObjectID p_node) {
+ if (rpc_node_data.has(p_node)) {
+ return;
+ }
+ rpc_node_data.insert(p_node, RPCNodeInfo());
+ rpc_node_data[p_node].node = p_node;
+ rpc_node_data[p_node].node_path = Object::cast_to<Node>(ObjectDB::get_instance(p_node))->get_path();
+ rpc_node_data[p_node].incoming_rpc = 0;
+ rpc_node_data[p_node].outgoing_rpc = 0;
+ }
+
+public:
+ void toggle(bool p_enable, const Array &p_opts) {
+ rpc_node_data.clear();
+ }
+
+ void add(const Array &p_data) {
+ ERR_FAIL_COND(p_data.size() < 2);
+ const ObjectID id = p_data[0];
+ const String what = p_data[1];
+ init_node(id);
+ RPCNodeInfo &info = rpc_node_data[id];
+ if (what == "rpc_in") {
+ info.incoming_rpc++;
+ } else if (what == "rpc_out") {
+ info.outgoing_rpc++;
+ }
+ }
+
+ void tick(double p_frame_time, double p_idle_time, double p_physics_time, double p_physics_frame_time) {
+ uint64_t pt = OS::get_singleton()->get_ticks_msec();
+ if (pt - last_profile_time > 100) {
+ last_profile_time = pt;
+ RPCProfilerFrame frame;
+ for (const KeyValue<ObjectID, RPCNodeInfo> &E : rpc_node_data) {
+ frame.infos.push_back(E.value);
+ }
+ rpc_node_data.clear();
+ EngineDebugger::get_singleton()->send_message("multiplayer:rpc", frame.serialize());
+ }
+ }
+};
+
+SceneDebugger *SceneDebugger::singleton = nullptr;
+
+SceneDebugger::SceneDebugger() {
+ singleton = this;
+ rpc_profiler.instantiate();
+ rpc_profiler->bind("rpc");
#ifdef DEBUG_ENABLED
LiveEditor::singleton = memnew(LiveEditor);
EngineDebugger::register_message_capture("scene", EngineDebugger::Capture(nullptr, SceneDebugger::parse_message));
#endif
}
-void SceneDebugger::deinitialize() {
+SceneDebugger::~SceneDebugger() {
#ifdef DEBUG_ENABLED
if (LiveEditor::singleton) {
- // Should be removed automatically when deiniting debugger, but just in case
- if (EngineDebugger::has_capture("scene")) {
- EngineDebugger::unregister_message_capture("scene");
- }
+ EngineDebugger::unregister_message_capture("scene");
memdelete(LiveEditor::singleton);
LiveEditor::singleton = nullptr;
}
#endif
+ singleton = nullptr;
+}
+
+void SceneDebugger::initialize() {
+ if (EngineDebugger::is_active()) {
+ memnew(SceneDebugger);
+ }
+}
+
+void SceneDebugger::deinitialize() {
+ if (singleton) {
+ memdelete(singleton);
+ }
}
#ifdef DEBUG_ENABLED
diff --git a/scene/debugger/scene_debugger.h b/scene/debugger/scene_debugger.h
index c8298391bb..dd0a17c2dc 100644
--- a/scene/debugger/scene_debugger.h
+++ b/scene/debugger/scene_debugger.h
@@ -32,6 +32,7 @@
#define SCENE_DEBUGGER_H
#include "core/object/class_db.h"
+#include "core/object/ref_counted.h"
#include "core/string/ustring.h"
#include "core/templates/pair.h"
#include "core/variant/array.h"
@@ -41,9 +42,36 @@ class Node;
class SceneDebugger {
public:
+ // RPC profiler
+ struct RPCNodeInfo {
+ ObjectID node;
+ String node_path;
+ int incoming_rpc = 0;
+ int outgoing_rpc = 0;
+ };
+
+ struct RPCProfilerFrame {
+ Vector<RPCNodeInfo> infos;
+
+ Array serialize();
+ bool deserialize(const Array &p_arr);
+ };
+
+private:
+ class RPCProfiler;
+
+ static SceneDebugger *singleton;
+
+ Ref<RPCProfiler> rpc_profiler;
+
+ SceneDebugger();
+
+public:
static void initialize();
static void deinitialize();
+ ~SceneDebugger();
+
#ifdef DEBUG_ENABLED
private:
static void _save_node(ObjectID id, const String &p_path);
diff --git a/scene/gui/aspect_ratio_container.cpp b/scene/gui/aspect_ratio_container.cpp
index 181d1bf33b..b59eda465e 100644
--- a/scene/gui/aspect_ratio_container.cpp
+++ b/scene/gui/aspect_ratio_container.cpp
@@ -70,6 +70,24 @@ void AspectRatioContainer::set_alignment_vertical(AlignmentMode p_alignment_vert
queue_sort();
}
+Vector<int> AspectRatioContainer::get_allowed_size_flags_horizontal() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
+Vector<int> AspectRatioContainer::get_allowed_size_flags_vertical() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
void AspectRatioContainer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
diff --git a/scene/gui/aspect_ratio_container.h b/scene/gui/aspect_ratio_container.h
index 4a168bad14..6740e2f329 100644
--- a/scene/gui/aspect_ratio_container.h
+++ b/scene/gui/aspect_ratio_container.h
@@ -72,6 +72,9 @@ public:
void set_alignment_vertical(AlignmentMode p_alignment_vertical);
AlignmentMode get_alignment_vertical() const { return alignment_vertical; }
+
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
};
VARIANT_ENUM_CAST(AspectRatioContainer::StretchMode);
diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp
index da2ef6c5ec..0338326bbe 100644
--- a/scene/gui/base_button.cpp
+++ b/scene/gui/base_button.cpp
@@ -81,42 +81,50 @@ void BaseButton::gui_input(const Ref<InputEvent> &p_event) {
}
void BaseButton::_notification(int p_what) {
- if (p_what == NOTIFICATION_MOUSE_ENTER) {
- status.hovering = true;
- update();
- }
+ switch (p_what) {
+ case NOTIFICATION_MOUSE_ENTER: {
+ status.hovering = true;
+ update();
+ } break;
- if (p_what == NOTIFICATION_MOUSE_EXIT) {
- status.hovering = false;
- update();
- }
- if (p_what == NOTIFICATION_DRAG_BEGIN || p_what == NOTIFICATION_SCROLL_BEGIN) {
- if (status.press_attempt) {
- status.press_attempt = false;
+ case NOTIFICATION_MOUSE_EXIT: {
+ status.hovering = false;
update();
- }
- }
+ } break;
- if (p_what == NOTIFICATION_FOCUS_ENTER) {
- update();
- }
+ case NOTIFICATION_DRAG_BEGIN:
+ case NOTIFICATION_SCROLL_BEGIN: {
+ if (status.press_attempt) {
+ status.press_attempt = false;
+ update();
+ }
+ } break;
- if (p_what == NOTIFICATION_FOCUS_EXIT) {
- if (status.press_attempt) {
- status.press_attempt = false;
- update();
- } else if (status.hovering) {
+ case NOTIFICATION_FOCUS_ENTER: {
update();
- }
- }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE || (p_what == NOTIFICATION_VISIBILITY_CHANGED && !is_visible_in_tree())) {
- if (!toggle_mode) {
- status.pressed = false;
- }
- status.hovering = false;
- status.press_attempt = false;
- status.pressing_inside = false;
+ case NOTIFICATION_FOCUS_EXIT: {
+ if (status.press_attempt) {
+ status.press_attempt = false;
+ update();
+ } else if (status.hovering) {
+ update();
+ }
+ } break;
+
+ case NOTIFICATION_VISIBILITY_CHANGED:
+ case NOTIFICATION_EXIT_TREE: {
+ if (p_what == NOTIFICATION_VISIBILITY_CHANGED && is_visible_in_tree()) {
+ break;
+ }
+ if (!toggle_mode) {
+ status.pressed = false;
+ }
+ status.hovering = false;
+ status.press_attempt = false;
+ status.pressing_inside = false;
+ } break;
}
}
diff --git a/scene/gui/base_button.h b/scene/gui/base_button.h
index 0bcad4fc0e..6bfffe7575 100644
--- a/scene/gui/base_button.h
+++ b/scene/gui/base_button.h
@@ -31,6 +31,7 @@
#ifndef BASE_BUTTON_H
#define BASE_BUTTON_H
+#include "core/input/shortcut.h"
#include "scene/gui/control.h"
class ButtonGroup;
diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp
index 9827bd0cef..251648da69 100644
--- a/scene/gui/box_container.cpp
+++ b/scene/gui/box_container.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "box_container.h"
+
#include "label.h"
#include "margin_container.h"
@@ -294,9 +295,11 @@ void BoxContainer::_notification(int p_what) {
case NOTIFICATION_SORT_CHILDREN: {
_resort();
} break;
+
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
queue_sort();
@@ -331,6 +334,30 @@ Control *BoxContainer::add_spacer(bool p_begin) {
return c;
}
+Vector<int> BoxContainer::get_allowed_size_flags_horizontal() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ if (!vertical) {
+ flags.append(SIZE_EXPAND);
+ }
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
+Vector<int> BoxContainer::get_allowed_size_flags_vertical() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ if (vertical) {
+ flags.append(SIZE_EXPAND);
+ }
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
BoxContainer::BoxContainer(bool p_vertical) {
vertical = p_vertical;
}
diff --git a/scene/gui/box_container.h b/scene/gui/box_container.h
index 68d55e1aaf..3043c3ea45 100644
--- a/scene/gui/box_container.h
+++ b/scene/gui/box_container.h
@@ -62,6 +62,9 @@ public:
virtual Size2 get_minimum_size() const override;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
BoxContainer(bool p_vertical = false);
};
diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp
index 3ed1b873af..27e8b102be 100644
--- a/scene/gui/button.cpp
+++ b/scene/gui/button.cpp
@@ -78,6 +78,7 @@ void Button::_notification(int p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
update();
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED: {
xl_text = atr(text);
_shape();
@@ -85,12 +86,14 @@ void Button::_notification(int p_what) {
update_minimum_size();
update();
} break;
+
case NOTIFICATION_THEME_CHANGED: {
_shape();
update_minimum_size();
update();
} break;
+
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Size2 size = get_size();
diff --git a/scene/gui/center_container.cpp b/scene/gui/center_container.cpp
index f3306783f3..33ec4006ae 100644
--- a/scene/gui/center_container.cpp
+++ b/scene/gui/center_container.cpp
@@ -69,22 +69,32 @@ bool CenterContainer::is_using_top_left() const {
return use_top_left;
}
+Vector<int> CenterContainer::get_allowed_size_flags_horizontal() const {
+ return Vector<int>();
+}
+
+Vector<int> CenterContainer::get_allowed_size_flags_vertical() const {
+ return Vector<int>();
+}
+
void CenterContainer::_notification(int p_what) {
- if (p_what == NOTIFICATION_SORT_CHILDREN) {
- Size2 size = get_size();
- for (int i = 0; i < get_child_count(); i++) {
- Control *c = Object::cast_to<Control>(get_child(i));
- if (!c) {
- continue;
- }
- if (c->is_set_as_top_level()) {
- continue;
- }
+ switch (p_what) {
+ case NOTIFICATION_SORT_CHILDREN: {
+ Size2 size = get_size();
+ for (int i = 0; i < get_child_count(); i++) {
+ Control *c = Object::cast_to<Control>(get_child(i));
+ if (!c) {
+ continue;
+ }
+ if (c->is_set_as_top_level()) {
+ continue;
+ }
- Size2 minsize = c->get_combined_minimum_size();
- Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor();
- fit_child_in_rect(c, Rect2(ofs, minsize));
- }
+ Size2 minsize = c->get_combined_minimum_size();
+ Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor();
+ fit_child_in_rect(c, Rect2(ofs, minsize));
+ }
+ } break;
}
}
diff --git a/scene/gui/center_container.h b/scene/gui/center_container.h
index 16a10c8070..c35e0c4e29 100644
--- a/scene/gui/center_container.h
+++ b/scene/gui/center_container.h
@@ -48,6 +48,9 @@ public:
virtual Size2 get_minimum_size() const override;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
CenterContainer();
};
diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp
index da2d4369d1..063a154bb2 100644
--- a/scene/gui/check_box.cpp
+++ b/scene/gui/check_box.cpp
@@ -84,34 +84,40 @@ Size2 CheckBox::get_minimum_size() const {
}
void CheckBox::_notification(int p_what) {
- if ((p_what == NOTIFICATION_THEME_CHANGED) || (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || (p_what == NOTIFICATION_TRANSLATION_CHANGED))) {
- if (is_layout_rtl()) {
- _set_internal_margin(SIDE_LEFT, 0.f);
- _set_internal_margin(SIDE_RIGHT, get_icon_size().width);
- } else {
- _set_internal_margin(SIDE_LEFT, get_icon_size().width);
- _set_internal_margin(SIDE_RIGHT, 0.f);
- }
- } else if (p_what == NOTIFICATION_DRAW) {
- RID ci = get_canvas_item();
-
- Ref<Texture2D> on = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_checked" : "checked", is_disabled() ? "_disabled" : ""));
- Ref<Texture2D> off = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_unchecked" : "unchecked", is_disabled() ? "_disabled" : ""));
- Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
-
- Vector2 ofs;
- if (is_layout_rtl()) {
- ofs.x = get_size().x - sb->get_margin(SIDE_RIGHT) - get_icon_size().width;
- } else {
- ofs.x = sb->get_margin(SIDE_LEFT);
- }
- ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant(SNAME("check_vadjust"));
-
- if (is_pressed()) {
- on->draw(ci, ofs);
- } else {
- off->draw(ci, ofs);
- }
+ switch (p_what) {
+ case NOTIFICATION_THEME_CHANGED:
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ if (is_layout_rtl()) {
+ _set_internal_margin(SIDE_LEFT, 0.f);
+ _set_internal_margin(SIDE_RIGHT, get_icon_size().width);
+ } else {
+ _set_internal_margin(SIDE_LEFT, get_icon_size().width);
+ _set_internal_margin(SIDE_RIGHT, 0.f);
+ }
+ } break;
+
+ case NOTIFICATION_DRAW: {
+ RID ci = get_canvas_item();
+
+ Ref<Texture2D> on = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_checked" : "checked", is_disabled() ? "_disabled" : ""));
+ Ref<Texture2D> off = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_unchecked" : "unchecked", is_disabled() ? "_disabled" : ""));
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
+
+ Vector2 ofs;
+ if (is_layout_rtl()) {
+ ofs.x = get_size().x - sb->get_margin(SIDE_RIGHT) - get_icon_size().width;
+ } else {
+ ofs.x = sb->get_margin(SIDE_LEFT);
+ }
+ ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant(SNAME("check_vadjust"));
+
+ if (is_pressed()) {
+ on->draw(ci, ofs);
+ } else {
+ off->draw(ci, ofs);
+ }
+ } break;
}
}
diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp
index afb23a540b..5e3131f8a0 100644
--- a/scene/gui/check_button.cpp
+++ b/scene/gui/check_button.cpp
@@ -61,47 +61,53 @@ Size2 CheckButton::get_minimum_size() const {
}
void CheckButton::_notification(int p_what) {
- if ((p_what == NOTIFICATION_THEME_CHANGED) || (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED) || (p_what == NOTIFICATION_TRANSLATION_CHANGED)) {
- if (is_layout_rtl()) {
- _set_internal_margin(SIDE_LEFT, get_icon_size().width);
- _set_internal_margin(SIDE_RIGHT, 0.f);
- } else {
- _set_internal_margin(SIDE_LEFT, 0.f);
- _set_internal_margin(SIDE_RIGHT, get_icon_size().width);
- }
- } else if (p_what == NOTIFICATION_DRAW) {
- RID ci = get_canvas_item();
- bool rtl = is_layout_rtl();
+ switch (p_what) {
+ case NOTIFICATION_THEME_CHANGED:
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ if (is_layout_rtl()) {
+ _set_internal_margin(SIDE_LEFT, get_icon_size().width);
+ _set_internal_margin(SIDE_RIGHT, 0.f);
+ } else {
+ _set_internal_margin(SIDE_LEFT, 0.f);
+ _set_internal_margin(SIDE_RIGHT, get_icon_size().width);
+ }
+ } break;
- Ref<Texture2D> on;
- if (rtl) {
- on = Control::get_theme_icon(is_disabled() ? "on_disabled_mirrored" : "on_mirrored");
- } else {
- on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on");
- }
- Ref<Texture2D> off;
- if (rtl) {
- off = Control::get_theme_icon(is_disabled() ? "off_disabled_mirrored" : "off_mirrored");
- } else {
- off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off");
- }
+ case NOTIFICATION_DRAW: {
+ RID ci = get_canvas_item();
+ bool rtl = is_layout_rtl();
- Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
- Vector2 ofs;
- Size2 tex_size = get_icon_size();
+ Ref<Texture2D> on;
+ if (rtl) {
+ on = Control::get_theme_icon(is_disabled() ? "on_disabled_mirrored" : "on_mirrored");
+ } else {
+ on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on");
+ }
+ Ref<Texture2D> off;
+ if (rtl) {
+ off = Control::get_theme_icon(is_disabled() ? "off_disabled_mirrored" : "off_mirrored");
+ } else {
+ off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off");
+ }
- if (rtl) {
- ofs.x = sb->get_margin(SIDE_LEFT);
- } else {
- ofs.x = get_size().width - (tex_size.width + sb->get_margin(SIDE_RIGHT));
- }
- ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant(SNAME("check_vadjust"));
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
+ Vector2 ofs;
+ Size2 tex_size = get_icon_size();
- if (is_pressed()) {
- on->draw(ci, ofs);
- } else {
- off->draw(ci, ofs);
- }
+ if (rtl) {
+ ofs.x = sb->get_margin(SIDE_LEFT);
+ } else {
+ ofs.x = get_size().width - (tex_size.width + sb->get_margin(SIDE_RIGHT));
+ }
+ ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant(SNAME("check_vadjust"));
+
+ if (is_pressed()) {
+ on->draw(ci, ofs);
+ } else {
+ off->draw(ci, ofs);
+ }
+ } break;
}
}
diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp
index 8cb8a78e8d..3fa0cec302 100644
--- a/scene/gui/code_edit.cpp
+++ b/scene/gui/code_edit.cpp
@@ -74,6 +74,7 @@ void CodeEdit::_notification(int p_what) {
line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color"));
} break;
+
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
const Size2 size = get_size();
@@ -84,7 +85,7 @@ void CodeEdit::_notification(int p_what) {
if (line_length_guideline_columns.size() > 0) {
const int xmargin_beg = style_normal->get_margin(SIDE_LEFT) + get_total_gutter_width();
const int xmargin_end = size.width - style_normal->get_margin(SIDE_RIGHT) - (is_drawing_minimap() ? get_minimap_width() : 0);
- const int char_size = Math::round(font->get_char_size('0', 0, font_size).width);
+ const float char_size = font->get_char_size('0', 0, font_size).width;
for (int i = 0; i < line_length_guideline_columns.size(); i++) {
const int xoffset = xmargin_beg + char_size * (int)line_length_guideline_columns[i] - get_h_scroll();
diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp
index 36ea843d1e..3ea2a9795d 100644
--- a/scene/gui/color_picker.cpp
+++ b/scene/gui/color_picker.cpp
@@ -33,11 +33,11 @@
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
+#include "scene/main/window.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
#endif
-#include "scene/main/window.h"
List<Color> ColorPicker::preset_cache;
@@ -45,7 +45,6 @@ void ColorPicker::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_color();
-
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
if (preset_cache.is_empty()) {
@@ -1347,17 +1346,18 @@ void ColorPickerButton::_notification(int p_what) {
draw_texture(Control::get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPicker")), normal->get_offset());
}
} break;
+
case NOTIFICATION_WM_CLOSE_REQUEST: {
if (popup) {
popup->hide();
}
} break;
- }
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- if (popup && !is_visible_in_tree()) {
- popup->hide();
- }
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (popup && !is_visible_in_tree()) {
+ popup->hide();
+ }
+ } break;
}
}
diff --git a/scene/gui/color_rect.cpp b/scene/gui/color_rect.cpp
index dbac1fc78a..2955f74a0c 100644
--- a/scene/gui/color_rect.cpp
+++ b/scene/gui/color_rect.cpp
@@ -40,8 +40,10 @@ Color ColorRect::get_color() const {
}
void ColorRect::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- draw_rect(Rect2(Point2(), get_size()), color);
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ draw_rect(Rect2(Point2(), get_size()), color);
+ } break;
}
}
diff --git a/scene/gui/container.cpp b/scene/gui/container.cpp
index 7b213ec314..1dd88371ea 100644
--- a/scene/gui/container.cpp
+++ b/scene/gui/container.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "container.h"
+
#include "core/object/message_queue.h"
#include "scene/scene_string_names.h"
@@ -143,18 +144,46 @@ void Container::queue_sort() {
pending_sort = true;
}
+Vector<int> Container::get_allowed_size_flags_horizontal() const {
+ Vector<int> flags;
+ if (GDVIRTUAL_CALL(_get_allowed_size_flags_horizontal, flags)) {
+ return flags;
+ }
+
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_EXPAND);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
+Vector<int> Container::get_allowed_size_flags_vertical() const {
+ Vector<int> flags;
+ if (GDVIRTUAL_CALL(_get_allowed_size_flags_vertical, flags)) {
+ return flags;
+ }
+
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_EXPAND);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
void Container::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
pending_sort = false;
queue_sort();
} break;
- case NOTIFICATION_RESIZED: {
- queue_sort();
- } break;
+
+ case NOTIFICATION_RESIZED:
case NOTIFICATION_THEME_CHANGED: {
queue_sort();
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible_in_tree()) {
queue_sort();
@@ -177,6 +206,9 @@ void Container::_bind_methods() {
ClassDB::bind_method(D_METHOD("queue_sort"), &Container::queue_sort);
ClassDB::bind_method(D_METHOD("fit_child_in_rect", "child", "rect"), &Container::fit_child_in_rect);
+ GDVIRTUAL_BIND(_get_allowed_size_flags_horizontal);
+ GDVIRTUAL_BIND(_get_allowed_size_flags_vertical);
+
BIND_CONSTANT(NOTIFICATION_PRE_SORT_CHILDREN);
BIND_CONSTANT(NOTIFICATION_SORT_CHILDREN);
diff --git a/scene/gui/container.h b/scene/gui/container.h
index 0e986f46ef..9ec4ad3200 100644
--- a/scene/gui/container.h
+++ b/scene/gui/container.h
@@ -46,6 +46,9 @@ protected:
virtual void move_child_notify(Node *p_child) override;
virtual void remove_child_notify(Node *p_child) override;
+ GDVIRTUAL0RC(Vector<int>, _get_allowed_size_flags_horizontal)
+ GDVIRTUAL0RC(Vector<int>, _get_allowed_size_flags_vertical)
+
void _notification(int p_what);
static void _bind_methods();
@@ -57,6 +60,9 @@ public:
void fit_child_in_rect(Control *p_child, const Rect2 &p_rect);
+ virtual Vector<int> get_allowed_size_flags_horizontal() const;
+ virtual Vector<int> get_allowed_size_flags_vertical() const;
+
TypedArray<String> get_configuration_warnings() const override;
Container();
diff --git a/scene/gui/control.cpp b/scene/gui/control.cpp
index fdae8e2f1f..46f60c92d9 100644
--- a/scene/gui/control.cpp
+++ b/scene/gui/control.cpp
@@ -47,7 +47,7 @@
#include "servers/text_server.h"
#ifdef TOOLS_ENABLED
-#include "editor/plugins/canvas_item_editor_plugin.h"
+#include "editor/plugins/control_editor_plugin.h"
#endif
#ifdef TOOLS_ENABLED
@@ -56,51 +56,71 @@ Dictionary Control::_edit_get_state() const {
s["rotation"] = get_rotation();
s["scale"] = get_scale();
s["pivot"] = get_pivot_offset();
+
Array anchors;
anchors.push_back(get_anchor(SIDE_LEFT));
anchors.push_back(get_anchor(SIDE_TOP));
anchors.push_back(get_anchor(SIDE_RIGHT));
anchors.push_back(get_anchor(SIDE_BOTTOM));
s["anchors"] = anchors;
+
Array offsets;
offsets.push_back(get_offset(SIDE_LEFT));
offsets.push_back(get_offset(SIDE_TOP));
offsets.push_back(get_offset(SIDE_RIGHT));
offsets.push_back(get_offset(SIDE_BOTTOM));
s["offsets"] = offsets;
+
+ s["layout_mode"] = _get_layout_mode();
+ s["anchors_layout_preset"] = _get_anchors_layout_preset();
+
return s;
}
void Control::_edit_set_state(const Dictionary &p_state) {
ERR_FAIL_COND((p_state.size() <= 0) ||
!p_state.has("rotation") || !p_state.has("scale") ||
- !p_state.has("pivot") || !p_state.has("anchors") || !p_state.has("offsets"));
+ !p_state.has("pivot") || !p_state.has("anchors") || !p_state.has("offsets") ||
+ !p_state.has("layout_mode") || !p_state.has("anchors_layout_preset"));
Dictionary state = p_state;
set_rotation(state["rotation"]);
set_scale(state["scale"]);
set_pivot_offset(state["pivot"]);
+
Array anchors = state["anchors"];
+
+ // If anchors are not in their default position, force the anchor layout mode in place of position.
+ LayoutMode _layout = (LayoutMode)(int)state["layout_mode"];
+ if (_layout == LayoutMode::LAYOUT_MODE_POSITION) {
+ bool anchors_mode = ((real_t)anchors[0] != 0.0 || (real_t)anchors[1] != 0.0 || (real_t)anchors[2] != 0.0 || (real_t)anchors[3] != 0.0);
+ if (anchors_mode) {
+ _layout = LayoutMode::LAYOUT_MODE_ANCHORS;
+ }
+ }
+
+ _set_layout_mode(_layout);
+ if (_layout == LayoutMode::LAYOUT_MODE_ANCHORS) {
+ _set_anchors_layout_preset((int)state["anchors_layout_preset"]);
+ }
+
data.anchor[SIDE_LEFT] = anchors[0];
data.anchor[SIDE_TOP] = anchors[1];
data.anchor[SIDE_RIGHT] = anchors[2];
data.anchor[SIDE_BOTTOM] = anchors[3];
+
Array offsets = state["offsets"];
data.offset[SIDE_LEFT] = offsets[0];
data.offset[SIDE_TOP] = offsets[1];
data.offset[SIDE_RIGHT] = offsets[2];
data.offset[SIDE_BOTTOM] = offsets[3];
+
_size_changed();
}
void Control::_edit_set_position(const Point2 &p_position) {
-#ifdef TOOLS_ENABLED
ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
- set_position(p_position, CanvasItemEditor::get_singleton()->is_anchors_mode_enabled() && Object::cast_to<Control>(data.parent));
-#else
- // Unlikely to happen. TODO: enclose all _edit_ functions into TOOLS_ENABLED
- set_position(p_position);
-#endif
+ set_position(p_position, ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled() && Object::cast_to<Control>(data.parent));
};
Point2 Control::_edit_get_position() const {
@@ -116,15 +136,9 @@ Size2 Control::_edit_get_scale() const {
}
void Control::_edit_set_rect(const Rect2 &p_edit_rect) {
-#ifdef TOOLS_ENABLED
ERR_FAIL_COND_MSG(!Engine::get_singleton()->is_editor_hint(), "This function can only be used from editor plugins.");
- set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
- set_size(p_edit_rect.size.snapped(Vector2(1, 1)), CanvasItemEditor::get_singleton()->is_anchors_mode_enabled());
-#else
- // Unlikely to happen. TODO: enclose all _edit_ functions into TOOLS_ENABLED
- set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)));
- set_size(p_edit_rect.size.snapped(Vector2(1, 1)));
-#endif
+ set_position((get_position() + get_transform().basis_xform(p_edit_rect.position)).snapped(Vector2(1, 1)), ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled());
+ set_size(p_edit_rect.size.snapped(Vector2(1, 1)), ControlEditorToolbar::get_singleton()->is_anchors_mode_enabled());
}
Rect2 Control::_edit_get_rect() const {
@@ -177,6 +191,7 @@ String Control::properties_managed_by_container[] = {
"anchor_right",
"anchor_bottom",
"rect_position",
+ "rect_rotation",
"rect_scale",
"rect_size"
};
@@ -430,6 +445,7 @@ void Control::_get_property_list(List<PropertyInfo> *p_list) const {
}
void Control::_validate_property(PropertyInfo &property) const {
+ // Update theme type variation options.
if (property.name == "theme_type_variation") {
List<StringName> names;
@@ -455,10 +471,99 @@ void Control::_validate_property(PropertyInfo &property) const {
property.hint_string = hint_string;
}
- if (!Object::cast_to<Container>(get_parent())) {
- return;
+
+ // Validate which positioning properties should be displayed depending on the parent and the layout mode.
+ Node *parent_node = get_parent_control();
+ if (!parent_node) {
+ // If there is no parent, display both anchor and container options.
+
+ // Set the layout mode to be disabled with the proper value.
+ if (property.name == "layout_mode") {
+ property.hint_string = "Position,Anchors,Container,Uncontrolled";
+ property.usage |= PROPERTY_USAGE_READ_ONLY;
+ }
+
+ // Use the layout mode to display or hide advanced anchoring properties.
+ bool use_custom_anchors = _get_anchors_layout_preset() == -1; // Custom "preset".
+ if (!use_custom_anchors && (property.name.begins_with("anchor_") || property.name.begins_with("offset_") || property.name.begins_with("grow_"))) {
+ property.usage ^= PROPERTY_USAGE_EDITOR;
+ }
+ } else if (Object::cast_to<Container>(parent_node)) {
+ // If the parent is a container, display only container-related properties.
+ if (property.name.begins_with("anchor_") || property.name.begins_with("offset_") || property.name.begins_with("grow_") || property.name == "anchors_preset" ||
+ (property.name.begins_with("rect_") && property.name != "rect_min_size" && property.name != "rect_clip_content" && property.name != "rect_global_position")) {
+ property.usage ^= PROPERTY_USAGE_EDITOR;
+
+ } else if (property.name == "layout_mode") {
+ // Set the layout mode to be disabled with the proper value.
+ property.hint_string = "Position,Anchors,Container,Uncontrolled";
+ property.usage |= PROPERTY_USAGE_READ_ONLY;
+ } else if (property.name == "size_flags_horizontal" || property.name == "size_flags_vertical") {
+ // Filter allowed size flags based on the parent container configuration.
+ Container *parent_container = Object::cast_to<Container>(parent_node);
+ Vector<int> size_flags;
+ if (property.name == "size_flags_horizontal") {
+ size_flags = parent_container->get_allowed_size_flags_horizontal();
+ } else if (property.name == "size_flags_vertical") {
+ size_flags = parent_container->get_allowed_size_flags_vertical();
+ }
+
+ // Enforce the order of the options, regardless of what the container provided.
+ String hint_string;
+ if (size_flags.has(SIZE_FILL)) {
+ hint_string += "Fill:1";
+ }
+ if (size_flags.has(SIZE_EXPAND)) {
+ if (!hint_string.is_empty()) {
+ hint_string += ",";
+ }
+ hint_string += "Expand:2";
+ }
+ if (size_flags.has(SIZE_SHRINK_CENTER)) {
+ if (!hint_string.is_empty()) {
+ hint_string += ",";
+ }
+ hint_string += "Shrink Center:4";
+ }
+ if (size_flags.has(SIZE_SHRINK_END)) {
+ if (!hint_string.is_empty()) {
+ hint_string += ",";
+ }
+ hint_string += "Shrink End:8";
+ }
+
+ if (hint_string.is_empty()) {
+ property.hint_string = "";
+ property.usage |= PROPERTY_USAGE_READ_ONLY;
+ } else {
+ property.hint_string = hint_string;
+ }
+ }
+ } else {
+ // If the parent is NOT a container or not a control at all, display only anchoring-related properties.
+ if (property.name.begins_with("size_flags_")) {
+ property.usage ^= PROPERTY_USAGE_EDITOR;
+
+ } else if (property.name == "layout_mode") {
+ // Set the layout mode to be enabled with proper options.
+ property.hint_string = "Position,Anchors";
+ }
+
+ // Use the layout mode to display or hide advanced anchoring properties.
+ bool use_anchors = _get_layout_mode() == LayoutMode::LAYOUT_MODE_ANCHORS;
+ if (!use_anchors && property.name == "anchors_preset") {
+ property.usage ^= PROPERTY_USAGE_EDITOR;
+ }
+ bool use_custom_anchors = use_anchors && _get_anchors_layout_preset() == -1; // Custom "preset".
+ if (!use_custom_anchors && (property.name.begins_with("anchor_") || property.name.begins_with("offset_") || property.name.begins_with("grow_"))) {
+ property.usage ^= PROPERTY_USAGE_EDITOR;
+ }
}
+
// Disable the property if it's managed by the parent container.
+ if (!Object::cast_to<Container>(parent_node)) {
+ return;
+ }
bool property_is_managed_by_container = false;
for (unsigned i = 0; i < properties_managed_by_container_count; i++) {
property_is_managed_by_container = properties_managed_by_container[i] == property.name;
@@ -586,17 +691,17 @@ void Control::_update_canvas_item_transform() {
void Control::_notification(int p_notification) {
switch (p_notification) {
- case NOTIFICATION_ENTER_TREE: {
- } break;
case NOTIFICATION_POST_ENTER_TREE: {
data.minimum_size_valid = false;
data.is_rtl_dirty = true;
_size_changed();
} break;
+
case NOTIFICATION_EXIT_TREE: {
release_focus();
get_viewport()->_gui_remove_control(this);
} break;
+
case NOTIFICATION_READY: {
#ifdef DEBUG_ENABLED
connect("ready", callable_mp(this, &Control::_clear_size_warning), varray(), CONNECT_DEFERRED | CONNECT_ONESHOT);
@@ -659,6 +764,7 @@ void Control::_notification(int p_notification) {
viewport->connect("size_changed", callable_mp(this, &Control::_size_changed));
}
} break;
+
case NOTIFICATION_EXIT_CANVAS: {
if (data.parent_canvas_item) {
data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed));
@@ -679,8 +785,8 @@ void Control::_notification(int p_notification) {
data.parent_canvas_item = nullptr;
data.parent_window = nullptr;
data.is_rtl_dirty = true;
-
} break;
+
case NOTIFICATION_MOVED_IN_PARENT: {
// some parents need to know the order of the children to draw (like TabContainer)
// update if necessary
@@ -692,50 +798,52 @@ void Control::_notification(int p_notification) {
if (data.RI) {
get_viewport()->_gui_set_root_order_dirty();
}
-
} break;
+
case NOTIFICATION_RESIZED: {
emit_signal(SceneStringNames::get_singleton()->resized);
} break;
+
case NOTIFICATION_DRAW: {
_update_canvas_item_transform();
RenderingServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size()));
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents);
- //emit_signal(SceneStringNames::get_singleton()->draw);
-
} break;
+
case NOTIFICATION_MOUSE_ENTER: {
emit_signal(SceneStringNames::get_singleton()->mouse_entered);
} break;
+
case NOTIFICATION_MOUSE_EXIT: {
emit_signal(SceneStringNames::get_singleton()->mouse_exited);
} break;
+
case NOTIFICATION_FOCUS_ENTER: {
emit_signal(SceneStringNames::get_singleton()->focus_entered);
update();
} break;
+
case NOTIFICATION_FOCUS_EXIT: {
emit_signal(SceneStringNames::get_singleton()->focus_exited);
update();
} break;
+
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
update();
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
if (get_viewport() != nullptr) {
get_viewport()->_gui_hide_control(this);
}
-
- //remove key focus
-
} else {
data.minimum_size_valid = false;
_size_changed();
}
-
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
if (is_inside_tree()) {
@@ -1390,6 +1498,54 @@ void Control::_size_changed() {
}
}
+void Control::_set_layout_mode(LayoutMode p_mode) {
+ bool list_changed = false;
+
+ if (p_mode == LayoutMode::LAYOUT_MODE_POSITION || p_mode == LayoutMode::LAYOUT_MODE_ANCHORS) {
+ if (has_meta("_edit_layout_mode") && (int)get_meta("_edit_layout_mode") != (int)p_mode) {
+ list_changed = true;
+ }
+
+ set_meta("_edit_layout_mode", (int)p_mode);
+
+ if (p_mode == LayoutMode::LAYOUT_MODE_POSITION) {
+ set_meta("_edit_use_custom_anchors", false);
+ set_anchors_and_offsets_preset(LayoutPreset::PRESET_TOP_LEFT, LayoutPresetMode::PRESET_MODE_KEEP_SIZE);
+ set_grow_direction_preset(LayoutPreset::PRESET_TOP_LEFT);
+ }
+ } else {
+ if (has_meta("_edit_layout_mode")) {
+ remove_meta("_edit_layout_mode");
+ list_changed = true;
+ }
+ }
+
+ if (list_changed) {
+ notify_property_list_changed();
+ }
+}
+
+Control::LayoutMode Control::_get_layout_mode() const {
+ Node *parent_node = get_parent_control();
+ // In these modes the property is read-only.
+ if (!parent_node) {
+ return LayoutMode::LAYOUT_MODE_UNCONTROLLED;
+ } else if (Object::cast_to<Container>(parent_node)) {
+ return LayoutMode::LAYOUT_MODE_CONTAINER;
+ }
+
+ // If anchors are not in the top-left position, this is definitely in anchors mode.
+ if (_get_anchors_layout_preset() != (int)LayoutPreset::PRESET_TOP_LEFT) {
+ return LayoutMode::LAYOUT_MODE_ANCHORS;
+ }
+ // Otherwise check what was saved.
+ if (has_meta("_edit_layout_mode")) {
+ return (LayoutMode)(int)get_meta("_edit_layout_mode");
+ }
+ // Or fallback on default.
+ return LayoutMode::LAYOUT_MODE_POSITION;
+}
+
void Control::set_anchor(Side p_side, real_t p_anchor, bool p_keep_offset, bool p_push_opposite_anchor) {
ERR_FAIL_INDEX((int)p_side, 4);
@@ -1431,6 +1587,133 @@ void Control::set_anchor_and_offset(Side p_side, real_t p_anchor, real_t p_pos,
set_offset(p_side, p_pos);
}
+void Control::_set_anchors_layout_preset(int p_preset) {
+ bool list_changed = false;
+
+ if (has_meta("_edit_layout_mode") && (int)get_meta("_edit_layout_mode") != (int)LayoutMode::LAYOUT_MODE_ANCHORS) {
+ list_changed = true;
+ set_meta("_edit_layout_mode", (int)LayoutMode::LAYOUT_MODE_ANCHORS);
+ }
+
+ if (p_preset == -1) {
+ if (!has_meta("_edit_use_custom_anchors") || !(bool)get_meta("_edit_use_custom_anchors")) {
+ set_meta("_edit_use_custom_anchors", true);
+ notify_property_list_changed();
+ }
+ return; // Keep settings as is.
+ }
+
+ if (!has_meta("_edit_use_custom_anchors") || (bool)get_meta("_edit_use_custom_anchors")) {
+ list_changed = true;
+ set_meta("_edit_use_custom_anchors", false);
+ }
+
+ LayoutPreset preset = (LayoutPreset)p_preset;
+ // Set correct anchors.
+ set_anchors_preset(preset);
+
+ // Select correct preset mode.
+ switch (preset) {
+ case PRESET_TOP_LEFT:
+ case PRESET_TOP_RIGHT:
+ case PRESET_BOTTOM_LEFT:
+ case PRESET_BOTTOM_RIGHT:
+ case PRESET_CENTER_LEFT:
+ case PRESET_CENTER_TOP:
+ case PRESET_CENTER_RIGHT:
+ case PRESET_CENTER_BOTTOM:
+ case PRESET_CENTER:
+ set_offsets_preset(preset, LayoutPresetMode::PRESET_MODE_KEEP_SIZE);
+ break;
+ case PRESET_LEFT_WIDE:
+ case PRESET_TOP_WIDE:
+ case PRESET_RIGHT_WIDE:
+ case PRESET_BOTTOM_WIDE:
+ case PRESET_VCENTER_WIDE:
+ case PRESET_HCENTER_WIDE:
+ case PRESET_WIDE:
+ set_offsets_preset(preset, LayoutPresetMode::PRESET_MODE_MINSIZE);
+ break;
+ }
+
+ // Select correct grow directions.
+ set_grow_direction_preset(preset);
+
+ if (list_changed) {
+ notify_property_list_changed();
+ }
+}
+
+int Control::_get_anchors_layout_preset() const {
+ // If the custom preset was selected by user, use it.
+ if (has_meta("_edit_use_custom_anchors") && (bool)get_meta("_edit_use_custom_anchors")) {
+ return -1;
+ }
+
+ // Check anchors to determine if the current state matches a preset, or not.
+
+ float left = get_anchor(SIDE_LEFT);
+ float right = get_anchor(SIDE_RIGHT);
+ float top = get_anchor(SIDE_TOP);
+ float bottom = get_anchor(SIDE_BOTTOM);
+
+ if (left == ANCHOR_BEGIN && right == ANCHOR_BEGIN && top == ANCHOR_BEGIN && bottom == ANCHOR_BEGIN) {
+ return (int)LayoutPreset::PRESET_TOP_LEFT;
+ }
+ if (left == ANCHOR_END && right == ANCHOR_END && top == ANCHOR_BEGIN && bottom == ANCHOR_BEGIN) {
+ return (int)LayoutPreset::PRESET_TOP_RIGHT;
+ }
+ if (left == ANCHOR_BEGIN && right == ANCHOR_BEGIN && top == ANCHOR_END && bottom == ANCHOR_END) {
+ return (int)LayoutPreset::PRESET_BOTTOM_LEFT;
+ }
+ if (left == ANCHOR_END && right == ANCHOR_END && top == ANCHOR_END && bottom == ANCHOR_END) {
+ return (int)LayoutPreset::PRESET_BOTTOM_RIGHT;
+ }
+
+ if (left == ANCHOR_BEGIN && right == ANCHOR_BEGIN && top == 0.5 && bottom == 0.5) {
+ return (int)LayoutPreset::PRESET_CENTER_LEFT;
+ }
+ if (left == ANCHOR_END && right == ANCHOR_END && top == 0.5 && bottom == 0.5) {
+ return (int)LayoutPreset::PRESET_CENTER_RIGHT;
+ }
+ if (left == 0.5 && right == 0.5 && top == ANCHOR_BEGIN && bottom == ANCHOR_BEGIN) {
+ return (int)LayoutPreset::PRESET_CENTER_TOP;
+ }
+ if (left == 0.5 && right == 0.5 && top == ANCHOR_END && bottom == ANCHOR_END) {
+ return (int)LayoutPreset::PRESET_CENTER_BOTTOM;
+ }
+ if (left == 0.5 && right == 0.5 && top == 0.5 && bottom == 0.5) {
+ return (int)LayoutPreset::PRESET_CENTER;
+ }
+
+ if (left == ANCHOR_BEGIN && right == ANCHOR_BEGIN && top == ANCHOR_BEGIN && bottom == ANCHOR_END) {
+ return (int)LayoutPreset::PRESET_LEFT_WIDE;
+ }
+ if (left == ANCHOR_END && right == ANCHOR_END && top == ANCHOR_BEGIN && bottom == ANCHOR_END) {
+ return (int)LayoutPreset::PRESET_RIGHT_WIDE;
+ }
+ if (left == ANCHOR_BEGIN && right == ANCHOR_END && top == ANCHOR_BEGIN && bottom == ANCHOR_BEGIN) {
+ return (int)LayoutPreset::PRESET_TOP_WIDE;
+ }
+ if (left == ANCHOR_BEGIN && right == ANCHOR_END && top == ANCHOR_END && bottom == ANCHOR_END) {
+ return (int)LayoutPreset::PRESET_BOTTOM_WIDE;
+ }
+
+ if (left == 0.5 && right == 0.5 && top == ANCHOR_BEGIN && bottom == ANCHOR_END) {
+ return (int)LayoutPreset::PRESET_VCENTER_WIDE;
+ }
+ if (left == ANCHOR_BEGIN && right == ANCHOR_END && top == 0.5 && bottom == 0.5) {
+ return (int)LayoutPreset::PRESET_HCENTER_WIDE;
+ }
+
+ if (left == ANCHOR_BEGIN && right == ANCHOR_END && top == ANCHOR_BEGIN && bottom == ANCHOR_END) {
+ return (int)LayoutPreset::PRESET_WIDE;
+ }
+
+ // Does not match any preset, return "Custom".
+ return -1;
+}
+
void Control::set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets) {
ERR_FAIL_INDEX((int)p_preset, 16);
@@ -1687,6 +1970,62 @@ void Control::set_anchors_and_offsets_preset(LayoutPreset p_preset, LayoutPreset
set_offsets_preset(p_preset, p_resize_mode, p_margin);
}
+void Control::set_grow_direction_preset(LayoutPreset p_preset) {
+ // Select correct horizontal grow direction.
+ switch (p_preset) {
+ case PRESET_TOP_LEFT:
+ case PRESET_BOTTOM_LEFT:
+ case PRESET_CENTER_LEFT:
+ case PRESET_LEFT_WIDE:
+ set_h_grow_direction(GrowDirection::GROW_DIRECTION_END);
+ break;
+ case PRESET_TOP_RIGHT:
+ case PRESET_BOTTOM_RIGHT:
+ case PRESET_CENTER_RIGHT:
+ case PRESET_RIGHT_WIDE:
+ set_h_grow_direction(GrowDirection::GROW_DIRECTION_BEGIN);
+ break;
+ case PRESET_CENTER_TOP:
+ case PRESET_CENTER_BOTTOM:
+ case PRESET_CENTER:
+ case PRESET_TOP_WIDE:
+ case PRESET_BOTTOM_WIDE:
+ case PRESET_VCENTER_WIDE:
+ case PRESET_HCENTER_WIDE:
+ case PRESET_WIDE:
+ set_h_grow_direction(GrowDirection::GROW_DIRECTION_BOTH);
+ break;
+ }
+
+ // Select correct vertical grow direction.
+ switch (p_preset) {
+ case PRESET_TOP_LEFT:
+ case PRESET_TOP_RIGHT:
+ case PRESET_CENTER_TOP:
+ case PRESET_TOP_WIDE:
+ set_v_grow_direction(GrowDirection::GROW_DIRECTION_END);
+ break;
+
+ case PRESET_BOTTOM_LEFT:
+ case PRESET_BOTTOM_RIGHT:
+ case PRESET_CENTER_BOTTOM:
+ case PRESET_BOTTOM_WIDE:
+ set_v_grow_direction(GrowDirection::GROW_DIRECTION_BEGIN);
+ break;
+
+ case PRESET_CENTER_LEFT:
+ case PRESET_CENTER_RIGHT:
+ case PRESET_CENTER:
+ case PRESET_LEFT_WIDE:
+ case PRESET_RIGHT_WIDE:
+ case PRESET_VCENTER_WIDE:
+ case PRESET_HCENTER_WIDE:
+ case PRESET_WIDE:
+ set_v_grow_direction(GrowDirection::GROW_DIRECTION_BOTH);
+ break;
+ }
+}
+
real_t Control::get_anchor(Side p_side) const {
ERR_FAIL_INDEX_V(int(p_side), 4, 0.0);
@@ -2847,14 +3186,22 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("accept_event"), &Control::accept_event);
ClassDB::bind_method(D_METHOD("get_minimum_size"), &Control::get_minimum_size);
ClassDB::bind_method(D_METHOD("get_combined_minimum_size"), &Control::get_combined_minimum_size);
+
+ ClassDB::bind_method(D_METHOD("_set_layout_mode", "mode"), &Control::_set_layout_mode);
+ ClassDB::bind_method(D_METHOD("_get_layout_mode"), &Control::_get_layout_mode);
+ ClassDB::bind_method(D_METHOD("_set_anchors_layout_preset", "preset"), &Control::_set_anchors_layout_preset);
+ ClassDB::bind_method(D_METHOD("_get_anchors_layout_preset"), &Control::_get_anchors_layout_preset);
ClassDB::bind_method(D_METHOD("set_anchors_preset", "preset", "keep_offsets"), &Control::set_anchors_preset, DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_offsets_preset", "preset", "resize_mode", "margin"), &Control::set_offsets_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0));
ClassDB::bind_method(D_METHOD("set_anchors_and_offsets_preset", "preset", "resize_mode", "margin"), &Control::set_anchors_and_offsets_preset, DEFVAL(PRESET_MODE_MINSIZE), DEFVAL(0));
+
ClassDB::bind_method(D_METHOD("_set_anchor", "side", "anchor"), &Control::_set_anchor);
ClassDB::bind_method(D_METHOD("set_anchor", "side", "anchor", "keep_offset", "push_opposite_anchor"), &Control::set_anchor, DEFVAL(false), DEFVAL(true));
ClassDB::bind_method(D_METHOD("get_anchor", "side"), &Control::get_anchor);
ClassDB::bind_method(D_METHOD("set_offset", "side", "offset"), &Control::set_offset);
+ ClassDB::bind_method(D_METHOD("get_offset", "offset"), &Control::get_offset);
ClassDB::bind_method(D_METHOD("set_anchor_and_offset", "side", "anchor", "offset", "push_opposite_anchor"), &Control::set_anchor_and_offset, DEFVAL(false));
+
ClassDB::bind_method(D_METHOD("set_begin", "position"), &Control::set_begin);
ClassDB::bind_method(D_METHOD("set_end", "position"), &Control::set_end);
ClassDB::bind_method(D_METHOD("set_position", "position", "keep_offsets"), &Control::set_position, DEFVAL(false));
@@ -2868,7 +3215,6 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_rotation", "radians"), &Control::set_rotation);
ClassDB::bind_method(D_METHOD("set_scale", "scale"), &Control::set_scale);
ClassDB::bind_method(D_METHOD("set_pivot_offset", "pivot_offset"), &Control::set_pivot_offset);
- ClassDB::bind_method(D_METHOD("get_offset", "offset"), &Control::get_offset);
ClassDB::bind_method(D_METHOD("get_begin"), &Control::get_begin);
ClassDB::bind_method(D_METHOD("get_end"), &Control::get_end);
ClassDB::bind_method(D_METHOD("get_position"), &Control::get_position);
@@ -2996,37 +3342,54 @@ void Control::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_auto_translate", "enable"), &Control::set_auto_translate);
ClassDB::bind_method(D_METHOD("is_auto_translating"), &Control::is_auto_translating);
- ADD_GROUP("Anchor", "anchor_");
+ ADD_GROUP("Layout", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
+ ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_direction", PROPERTY_HINT_ENUM, "Inherited,Locale,Left-to-Right,Right-to-Left"), "set_layout_direction", "get_layout_direction");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_mode", PROPERTY_HINT_ENUM, "Position,Anchors,Container,Uncontrolled", PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_layout_mode", "_get_layout_mode");
+ ADD_PROPERTY_DEFAULT("layout_mode", LayoutMode::LAYOUT_MODE_POSITION);
+
+ const String anchors_presets_options = "Custom:-1,PresetWide:15,"
+ "PresetTopLeft:0,PresetTopRight:1,PresetBottomRight:3,PresetBottomLeft:2,"
+ "PresetCenterLeft:4,PresetCenterTop:5,PresetCenterRight:6,PresetCenterBottom:7,PresetCenter:8,"
+ "PresetLeftWide:9,PresetTopWide:10,PresetRightWide:11,PresetBottomWide:12,PresetVCenterWide:13,PresetHCenterWide:14";
+
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "anchors_preset", PROPERTY_HINT_ENUM, anchors_presets_options, PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_INTERNAL), "_set_anchors_layout_preset", "_get_anchors_layout_preset");
+ ADD_PROPERTY_DEFAULT("anchors_preset", -1);
+
+ ADD_SUBGROUP_INDENT("Anchor Points", "anchor_", 1);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_left", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_LEFT);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_top", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_right", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_RIGHT);
ADD_PROPERTYI(PropertyInfo(Variant::FLOAT, "anchor_bottom", PROPERTY_HINT_RANGE, "0,1,0.001,or_lesser,or_greater"), "_set_anchor", "get_anchor", SIDE_BOTTOM);
- ADD_GROUP("Offset", "offset_");
+ ADD_SUBGROUP_INDENT("Anchor Offsets", "offset_", 1);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_left", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_LEFT);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_top", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_TOP);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_right", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_RIGHT);
ADD_PROPERTYI(PropertyInfo(Variant::INT, "offset_bottom", PROPERTY_HINT_RANGE, "-4096,4096"), "set_offset", "get_offset", SIDE_BOTTOM);
- ADD_GROUP("Grow Direction", "grow_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Begin,End,Both"), "set_h_grow_direction", "get_h_grow_direction");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Begin,End,Both"), "set_v_grow_direction", "get_v_grow_direction");
-
- ADD_GROUP("Layout Direction", "layout_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "layout_direction", PROPERTY_HINT_ENUM, "Inherited,Locale,Left-to-Right,Right-to-Left"), "set_layout_direction", "get_layout_direction");
-
- ADD_GROUP("Auto Translate", "");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
+ ADD_SUBGROUP_INDENT("Grow Direction", "grow_", 1);
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_horizontal", PROPERTY_HINT_ENUM, "Left,Right,Both"), "set_h_grow_direction", "get_h_grow_direction");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "grow_vertical", PROPERTY_HINT_ENUM, "Top,Bottom,Both"), "set_v_grow_direction", "get_v_grow_direction");
- ADD_GROUP("Rect", "rect_");
+ ADD_SUBGROUP("Rectangle", "rect_");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_global_position", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_NONE), "_set_global_position", "get_global_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_EDITOR), "_set_size", "get_size");
- ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_min_size"), "set_custom_minimum_size", "get_custom_minimum_size");
+
+ ADD_SUBGROUP("Transform", "rect_");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "rect_rotation", PROPERTY_HINT_RANGE, "-360,360,0.1,or_lesser,or_greater,radians"), "set_rotation", "get_rotation");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_scale"), "set_scale", "get_scale");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "rect_pivot_offset"), "set_pivot_offset", "get_pivot_offset");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "rect_clip_content"), "set_clip_contents", "is_clipping_contents");
+
+ ADD_SUBGROUP("Container Sizing", "size_flags_");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_h_size_flags", "get_h_size_flags");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill:1,Expand:2,Shrink Center:4,Shrink End:8"), "set_v_size_flags", "get_v_size_flags");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
+
+ ADD_GROUP("Auto Translate", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
ADD_GROUP("Hint", "hint_");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "hint_tooltip", PROPERTY_HINT_MULTILINE_TEXT), "set_tooltip", "_get_tooltip");
@@ -3044,11 +3407,6 @@ void Control::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_filter", PROPERTY_HINT_ENUM, "Stop,Pass,Ignore"), "set_mouse_filter", "get_mouse_filter");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mouse_default_cursor_shape", PROPERTY_HINT_ENUM, "Arrow,I-Beam,Pointing Hand,Cross,Wait,Busy,Drag,Can Drop,Forbidden,Vertical Resize,Horizontal Resize,Secondary Diagonal Resize,Main Diagonal Resize,Move,Vertical Split,Horizontal Split,Help"), "set_default_cursor_shape", "get_default_cursor_shape");
- ADD_GROUP("Size Flags", "size_flags_");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_horizontal", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_h_size_flags", "get_h_size_flags");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "size_flags_vertical", PROPERTY_HINT_FLAGS, "Fill,Expand,Shrink Center,Shrink End"), "set_v_size_flags", "get_v_size_flags");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "size_flags_stretch_ratio", PROPERTY_HINT_RANGE, "0,20,0.01,or_greater"), "set_stretch_ratio", "get_stretch_ratio");
-
ADD_GROUP("Theme", "theme_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
@@ -3107,6 +3465,7 @@ void Control::_bind_methods() {
BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_HEIGHT);
BIND_ENUM_CONSTANT(PRESET_MODE_KEEP_SIZE);
+ BIND_ENUM_CONSTANT(SIZE_SHRINK_BEGIN);
BIND_ENUM_CONSTANT(SIZE_FILL);
BIND_ENUM_CONSTANT(SIZE_EXPAND);
BIND_ENUM_CONSTANT(SIZE_EXPAND_FILL);
diff --git a/scene/gui/control.h b/scene/gui/control.h
index 962135280f..becb50a118 100644
--- a/scene/gui/control.h
+++ b/scene/gui/control.h
@@ -31,12 +31,10 @@
#ifndef CONTROL_H
#define CONTROL_H
-#include "core/input/shortcut.h"
#include "core/math/transform_2d.h"
#include "core/object/gdvirtual.gen.inc"
#include "core/templates/rid.h"
#include "scene/main/canvas_item.h"
-#include "scene/main/node.h"
#include "scene/main/timer.h"
#include "scene/resources/theme.h"
@@ -67,12 +65,13 @@ public:
};
enum SizeFlags {
+ SIZE_SHRINK_BEGIN = 0,
SIZE_FILL = 1,
SIZE_EXPAND = 2,
- SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL,
- SIZE_SHRINK_CENTER = 4, //ignored by expand or fill
- SIZE_SHRINK_END = 8, //ignored by expand or fill
+ SIZE_SHRINK_CENTER = 4,
+ SIZE_SHRINK_END = 8,
+ SIZE_EXPAND_FILL = SIZE_EXPAND | SIZE_FILL,
};
enum MouseFilter {
@@ -128,6 +127,13 @@ public:
PRESET_MODE_KEEP_SIZE
};
+ enum LayoutMode {
+ LAYOUT_MODE_POSITION,
+ LAYOUT_MODE_ANCHORS,
+ LAYOUT_MODE_CONTAINER,
+ LAYOUT_MODE_UNCONTROLLED,
+ };
+
enum LayoutDirection {
LAYOUT_DIRECTION_INHERITED,
LAYOUT_DIRECTION_LOCALE,
@@ -230,7 +236,7 @@ private:
} data;
- static constexpr unsigned properties_managed_by_container_count = 11;
+ static constexpr unsigned properties_managed_by_container_count = 12;
static String properties_managed_by_container[properties_managed_by_container_count];
void _window_find_focus_neighbor(const Vector2 &p_dir, Node *p_at, const Point2 *p_points, real_t p_min, real_t &r_closest_dist, Control **r_closest);
@@ -241,6 +247,12 @@ private:
void _set_global_position(const Point2 &p_point);
void _set_size(const Size2 &p_size);
+ void _set_layout_mode(LayoutMode p_mode);
+ LayoutMode _get_layout_mode() const;
+
+ void _set_anchors_layout_preset(int p_preset);
+ int _get_anchors_layout_preset() const;
+
void _theme_changed();
void _notify_theme_changed();
@@ -285,9 +297,10 @@ protected:
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
+ virtual void _validate_property(PropertyInfo &property) const override;
+
void _notification(int p_notification);
static void _bind_methods();
- virtual void _validate_property(PropertyInfo &property) const override;
//bind helpers
@@ -378,6 +391,7 @@ public:
void set_anchors_preset(LayoutPreset p_preset, bool p_keep_offsets = true);
void set_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0);
void set_anchors_and_offsets_preset(LayoutPreset p_preset, LayoutPresetMode p_resize_mode = PRESET_MODE_MINSIZE, int p_margin = 0);
+ void set_grow_direction_preset(LayoutPreset p_preset);
void set_anchor(Side p_side, real_t p_anchor, bool p_keep_offset = true, bool p_push_opposite_anchor = true);
real_t get_anchor(Side p_side) const;
@@ -563,6 +577,7 @@ VARIANT_ENUM_CAST(Control::LayoutPresetMode);
VARIANT_ENUM_CAST(Control::MouseFilter);
VARIANT_ENUM_CAST(Control::GrowDirection);
VARIANT_ENUM_CAST(Control::Anchor);
+VARIANT_ENUM_CAST(Control::LayoutMode);
VARIANT_ENUM_CAST(Control::LayoutDirection);
VARIANT_ENUM_CAST(Control::TextDirection);
VARIANT_ENUM_CAST(Control::StructuredTextParser);
diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp
index 1cbe3adb3c..e3744eedca 100644
--- a/scene/gui/dialogs.cpp
+++ b/scene/gui/dialogs.cpp
@@ -33,12 +33,7 @@
#include "core/os/keyboard.h"
#include "core/string/print_string.h"
#include "core/string/translation.h"
-#include "line_edit.h"
-
-#ifdef TOOLS_ENABLED
-#include "editor/editor_node.h"
-#include "scene/main/window.h" // Only used to check for more modals when dimming the editor.
-#endif
+#include "scene/gui/line_edit.h"
// AcceptDialog
@@ -72,21 +67,25 @@ void AcceptDialog::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_THEME_CHANGED: {
bg->add_theme_style_override("panel", bg->get_theme_stylebox(SNAME("panel"), SNAME("AcceptDialog")));
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
parent_visible = nullptr;
}
} break;
+
case NOTIFICATION_READY:
case NOTIFICATION_WM_SIZE_CHANGED: {
if (is_visible()) {
_update_child_rects();
}
} break;
+
case NOTIFICATION_WM_CLOSE_REQUEST: {
_cancel_pressed();
} break;
diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp
index dad84461f4..79aaf5c511 100644
--- a/scene/gui/file_dialog.cpp
+++ b/scene/gui/file_dialog.cpp
@@ -92,26 +92,30 @@ void FileDialog::_theme_changed() {
}
void FileDialog::_notification(int p_what) {
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- if (!is_visible()) {
- set_process_unhandled_input(false);
- }
- }
- if (p_what == NOTIFICATION_ENTER_TREE) {
- dir_up->set_icon(vbox->get_theme_icon(SNAME("parent_folder"), SNAME("FileDialog")));
- if (vbox->is_layout_rtl()) {
- dir_prev->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
- dir_next->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
- } else {
- dir_prev->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
- dir_next->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
- }
- refresh->set_icon(vbox->get_theme_icon(SNAME("reload"), SNAME("FileDialog")));
- show_hidden->set_icon(vbox->get_theme_icon(SNAME("toggle_hidden"), SNAME("FileDialog")));
- _theme_changed();
- }
- if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- update_filters();
+ switch (p_what) {
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (!is_visible()) {
+ set_process_unhandled_input(false);
+ }
+ } break;
+
+ case NOTIFICATION_ENTER_TREE: {
+ dir_up->set_icon(vbox->get_theme_icon(SNAME("parent_folder"), SNAME("FileDialog")));
+ if (vbox->is_layout_rtl()) {
+ dir_prev->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
+ dir_next->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
+ } else {
+ dir_prev->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
+ dir_next->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
+ }
+ refresh->set_icon(vbox->get_theme_icon(SNAME("reload"), SNAME("FileDialog")));
+ show_hidden->set_icon(vbox->get_theme_icon(SNAME("toggle_hidden"), SNAME("FileDialog")));
+ _theme_changed();
+ } break;
+
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ update_filters();
+ } break;
}
}
diff --git a/scene/gui/flow_container.cpp b/scene/gui/flow_container.cpp
index d1ac60b325..3bd21f96b2 100644
--- a/scene/gui/flow_container.cpp
+++ b/scene/gui/flow_container.cpp
@@ -28,8 +28,6 @@
/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
/*************************************************************************/
-#include "scene/gui/container.h"
-
#include "flow_container.h"
struct _LineData {
@@ -223,15 +221,41 @@ Size2 FlowContainer::get_minimum_size() const {
return minimum;
}
+Vector<int> FlowContainer::get_allowed_size_flags_horizontal() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ if (!vertical) {
+ flags.append(SIZE_EXPAND);
+ }
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
+Vector<int> FlowContainer::get_allowed_size_flags_vertical() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ if (vertical) {
+ flags.append(SIZE_EXPAND);
+ }
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
void FlowContainer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
_resort();
update_minimum_size();
} break;
+
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
queue_sort();
diff --git a/scene/gui/flow_container.h b/scene/gui/flow_container.h
index e3ed423ae1..a2da43e071 100644
--- a/scene/gui/flow_container.h
+++ b/scene/gui/flow_container.h
@@ -31,7 +31,7 @@
#ifndef FLOW_CONTAINER_H
#define FLOW_CONTAINER_H
-class Container;
+#include "scene/gui/container.h"
class FlowContainer : public Container {
GDCLASS(FlowContainer, Container);
@@ -54,6 +54,9 @@ public:
virtual Size2 get_minimum_size() const override;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
FlowContainer(bool p_vertical = false);
};
diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp
index bec3d58384..0690acbe16 100644
--- a/scene/gui/gradient_edit.cpp
+++ b/scene/gui/gradient_edit.cpp
@@ -287,84 +287,85 @@ void GradientEdit::gui_input(const Ref<InputEvent> &p_event) {
}
void GradientEdit::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- if (!picker->is_connected("color_changed", callable_mp(this, &GradientEdit::_color_changed))) {
- picker->connect("color_changed", callable_mp(this, &GradientEdit::_color_changed));
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ if (!picker->is_connected("color_changed", callable_mp(this, &GradientEdit::_color_changed))) {
+ picker->connect("color_changed", callable_mp(this, &GradientEdit::_color_changed));
+ }
+ [[fallthrough]];
}
- }
+ case NOTIFICATION_THEME_CHANGED: {
+ draw_spacing = BASE_SPACING * get_theme_default_base_scale();
+ draw_point_width = BASE_POINT_WIDTH * get_theme_default_base_scale();
+ } break;
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- draw_spacing = BASE_SPACING * get_theme_default_base_scale();
- draw_point_width = BASE_POINT_WIDTH * get_theme_default_base_scale();
- }
+ case NOTIFICATION_DRAW: {
+ int w = get_size().x;
+ int h = get_size().y;
- if (p_what == NOTIFICATION_DRAW) {
- int w = get_size().x;
- int h = get_size().y;
+ if (w == 0 || h == 0) {
+ return; // Safety check. We have division by 'h'. And in any case there is nothing to draw with such size.
+ }
- if (w == 0 || h == 0) {
- return; // Safety check. We have division by 'h'. And in any case there is nothing to draw with such size.
- }
+ int total_w = get_size().width - get_size().height - draw_spacing;
- int total_w = get_size().width - get_size().height - draw_spacing;
+ // Draw checker pattern for ramp.
+ draw_texture_rect(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")), Rect2(0, 0, total_w, h), true);
- // Draw checker pattern for ramp.
- draw_texture_rect(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")), Rect2(0, 0, total_w, h), true);
+ // Draw color ramp.
+ gradient_cache->set_points(points);
+ gradient_cache->set_interpolation_mode(interpolation_mode);
+ preview_texture->set_gradient(gradient_cache);
+ draw_texture_rect(preview_texture, Rect2(0, 0, total_w, h));
- // Draw color ramp.
+ // Draw point markers.
+ for (int i = 0; i < points.size(); i++) {
+ Color col = points[i].color.inverted();
+ col.a = 0.9;
- gradient_cache->set_points(points);
- gradient_cache->set_interpolation_mode(interpolation_mode);
- preview_texture->set_gradient(gradient_cache);
- draw_texture_rect(preview_texture, Rect2(0, 0, total_w, h));
+ draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col);
+ Rect2 rect = Rect2(points[i].offset * total_w - draw_point_width / 2, h / 2, draw_point_width, h / 2);
+ draw_rect(rect, points[i].color, true);
+ draw_rect(rect, col, false);
+ if (grabbed == i) {
+ rect = rect.grow(-1);
+ if (has_focus()) {
+ draw_rect(rect, Color(1, 0, 0, 0.9), false);
+ } else {
+ draw_rect(rect, Color(0.6, 0, 0, 0.9), false);
+ }
- // Draw point markers.
- for (int i = 0; i < points.size(); i++) {
- Color col = points[i].color.inverted();
- col.a = 0.9;
-
- draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col);
- Rect2 rect = Rect2(points[i].offset * total_w - draw_point_width / 2, h / 2, draw_point_width, h / 2);
- draw_rect(rect, points[i].color, true);
- draw_rect(rect, col, false);
- if (grabbed == i) {
- rect = rect.grow(-1);
- if (has_focus()) {
- draw_rect(rect, Color(1, 0, 0, 0.9), false);
- } else {
- draw_rect(rect, Color(0.6, 0, 0, 0.9), false);
+ rect = rect.grow(-1);
+ draw_rect(rect, col, false);
}
-
- rect = rect.grow(-1);
- draw_rect(rect, col, false);
}
- }
- //Draw "button" for color selector
- draw_texture_rect(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")), Rect2(total_w + draw_spacing, 0, h, h), true);
- if (grabbed != -1) {
- //Draw with selection color
- draw_rect(Rect2(total_w + draw_spacing, 0, h, h), points[grabbed].color);
- } else {
- //if no color selected draw grey color with 'X' on top.
- draw_rect(Rect2(total_w + draw_spacing, 0, h, h), Color(0.5, 0.5, 0.5, 1));
- draw_line(Vector2(total_w + draw_spacing, 0), Vector2(total_w + draw_spacing + h, h), Color(1, 1, 1, 0.6));
- draw_line(Vector2(total_w + draw_spacing, h), Vector2(total_w + draw_spacing + h, 0), Color(1, 1, 1, 0.6));
- }
+ // Draw "button" for color selector.
+ draw_texture_rect(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")), Rect2(total_w + draw_spacing, 0, h, h), true);
+ if (grabbed != -1) {
+ // Draw with selection color.
+ draw_rect(Rect2(total_w + draw_spacing, 0, h, h), points[grabbed].color);
+ } else {
+ // If no color selected draw grey color with 'X' on top.
+ draw_rect(Rect2(total_w + draw_spacing, 0, h, h), Color(0.5, 0.5, 0.5, 1));
+ draw_line(Vector2(total_w + draw_spacing, 0), Vector2(total_w + draw_spacing + h, h), Color(1, 1, 1, 0.6));
+ draw_line(Vector2(total_w + draw_spacing, h), Vector2(total_w + draw_spacing + h, 0), Color(1, 1, 1, 0.6));
+ }
- // Draw borders around color ramp if in focus.
- if (has_focus()) {
- draw_line(Vector2(-1, -1), Vector2(total_w + 1, -1), Color(1, 1, 1, 0.6));
- draw_line(Vector2(total_w + 1, -1), Vector2(total_w + 1, h + 1), Color(1, 1, 1, 0.6));
- draw_line(Vector2(total_w + 1, h + 1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
- draw_line(Vector2(-1, -1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
- }
- }
+ // Draw borders around color ramp if in focus.
+ if (has_focus()) {
+ draw_line(Vector2(-1, -1), Vector2(total_w + 1, -1), Color(1, 1, 1, 0.6));
+ draw_line(Vector2(total_w + 1, -1), Vector2(total_w + 1, h + 1), Color(1, 1, 1, 0.6));
+ draw_line(Vector2(total_w + 1, h + 1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
+ draw_line(Vector2(-1, -1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
+ }
+ } break;
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- if (!is_visible()) {
- grabbing = false;
- }
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ if (!is_visible()) {
+ grabbing = false;
+ }
+ } break;
}
}
diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp
index 95575a8226..ab21c747cf 100644
--- a/scene/gui/graph_edit.cpp
+++ b/scene/gui/graph_edit.cpp
@@ -423,82 +423,86 @@ void GraphEdit::remove_child_notify(Node *p_child) {
}
void GraphEdit::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
- port_grab_distance_horizontal = get_theme_constant(SNAME("port_grab_distance_horizontal"));
- port_grab_distance_vertical = get_theme_constant(SNAME("port_grab_distance_vertical"));
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED: {
+ port_grab_distance_horizontal = get_theme_constant(SNAME("port_grab_distance_horizontal"));
+ port_grab_distance_vertical = get_theme_constant(SNAME("port_grab_distance_vertical"));
+
+ zoom_minus->set_icon(get_theme_icon(SNAME("minus")));
+ zoom_reset->set_icon(get_theme_icon(SNAME("reset")));
+ zoom_plus->set_icon(get_theme_icon(SNAME("more")));
+ snap_button->set_icon(get_theme_icon(SNAME("snap")));
+ minimap_button->set_icon(get_theme_icon(SNAME("minimap")));
+ layout_button->set_icon(get_theme_icon(SNAME("layout")));
+
+ zoom_label->set_custom_minimum_size(Size2(48, 0) * get_theme_default_base_scale());
+ } break;
- zoom_minus->set_icon(get_theme_icon(SNAME("minus")));
- zoom_reset->set_icon(get_theme_icon(SNAME("reset")));
- zoom_plus->set_icon(get_theme_icon(SNAME("more")));
- snap_button->set_icon(get_theme_icon(SNAME("snap")));
- minimap_button->set_icon(get_theme_icon(SNAME("minimap")));
- layout_button->set_icon(get_theme_icon(SNAME("layout")));
+ case NOTIFICATION_READY: {
+ Size2 hmin = h_scroll->get_combined_minimum_size();
+ Size2 vmin = v_scroll->get_combined_minimum_size();
- zoom_label->set_custom_minimum_size(Size2(48, 0) * get_theme_default_base_scale());
- }
- if (p_what == NOTIFICATION_READY) {
- Size2 hmin = h_scroll->get_combined_minimum_size();
- Size2 vmin = v_scroll->get_combined_minimum_size();
+ h_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, 0);
+ h_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
+ h_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -hmin.height);
+ h_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
- h_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, 0);
- h_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
- h_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -hmin.height);
- h_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
+ v_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -vmin.width);
+ v_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
+ v_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);
+ v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
+ } break;
- v_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -vmin.width);
- v_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
- v_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);
- v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
- }
- if (p_what == NOTIFICATION_DRAW) {
- draw_style_box(get_theme_stylebox(SNAME("bg")), Rect2(Point2(), get_size()));
+ case NOTIFICATION_DRAW: {
+ draw_style_box(get_theme_stylebox(SNAME("bg")), Rect2(Point2(), get_size()));
- if (is_using_snap()) {
- //draw grid
+ if (is_using_snap()) {
+ // Draw grid.
+ int snap = get_snap();
- int snap = get_snap();
+ Vector2 offset = get_scroll_ofs() / zoom;
+ Size2 size = get_size() / zoom;
- Vector2 offset = get_scroll_ofs() / zoom;
- Size2 size = get_size() / zoom;
+ Point2i from = (offset / float(snap)).floor();
+ Point2i len = (size / float(snap)).floor() + Vector2(1, 1);
- Point2i from = (offset / float(snap)).floor();
- Point2i len = (size / float(snap)).floor() + Vector2(1, 1);
+ Color grid_minor = get_theme_color(SNAME("grid_minor"));
+ Color grid_major = get_theme_color(SNAME("grid_major"));
- Color grid_minor = get_theme_color(SNAME("grid_minor"));
- Color grid_major = get_theme_color(SNAME("grid_major"));
+ for (int i = from.x; i < from.x + len.x; i++) {
+ Color color;
- for (int i = from.x; i < from.x + len.x; i++) {
- Color color;
+ if (ABS(i) % 10 == 0) {
+ color = grid_major;
+ } else {
+ color = grid_minor;
+ }
- if (ABS(i) % 10 == 0) {
- color = grid_major;
- } else {
- color = grid_minor;
+ float base_ofs = i * snap * zoom - offset.x * zoom;
+ draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color);
}
- float base_ofs = i * snap * zoom - offset.x * zoom;
- draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color);
- }
+ for (int i = from.y; i < from.y + len.y; i++) {
+ Color color;
- for (int i = from.y; i < from.y + len.y; i++) {
- Color color;
+ if (ABS(i) % 10 == 0) {
+ color = grid_major;
+ } else {
+ color = grid_minor;
+ }
- if (ABS(i) % 10 == 0) {
- color = grid_major;
- } else {
- color = grid_minor;
+ float base_ofs = i * snap * zoom - offset.y * zoom;
+ draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color);
}
-
- float base_ofs = i * snap * zoom - offset.y * zoom;
- draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color);
}
- }
- }
+ } break;
- if (p_what == NOTIFICATION_RESIZED) {
- _update_scroll();
- top_layer->update();
- minimap->update();
+ case NOTIFICATION_RESIZED: {
+ _update_scroll();
+ top_layer->update();
+ minimap->update();
+ } break;
}
}
diff --git a/scene/gui/graph_edit.h b/scene/gui/graph_edit.h
index da973b46f0..b0d1944d6e 100644
--- a/scene/gui/graph_edit.h
+++ b/scene/gui/graph_edit.h
@@ -36,9 +36,7 @@
#include "scene/gui/graph_node.h"
#include "scene/gui/label.h"
#include "scene/gui/scroll_bar.h"
-#include "scene/gui/slider.h"
#include "scene/gui/spin_box.h"
-#include "scene/gui/texture_rect.h"
class GraphEdit;
class ViewPanner;
diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp
index 30f6cf4a14..ef0ac75cb4 100644
--- a/scene/gui/graph_node.cpp
+++ b/scene/gui/graph_node.cpp
@@ -31,6 +31,7 @@
#include "graph_node.h"
#include "core/string/translation.h"
+
#ifdef TOOLS_ENABLED
#include "graph_edit.h"
#endif
@@ -959,6 +960,25 @@ bool GraphNode::is_resizable() const {
return resizable;
}
+Vector<int> GraphNode::get_allowed_size_flags_horizontal() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
+Vector<int> GraphNode::get_allowed_size_flags_vertical() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_EXPAND);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
void GraphNode::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &GraphNode::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &GraphNode::get_title);
diff --git a/scene/gui/graph_node.h b/scene/gui/graph_node.h
index b41fc7f5d4..7eb5f27cff 100644
--- a/scene/gui/graph_node.h
+++ b/scene/gui/graph_node.h
@@ -182,6 +182,9 @@ public:
virtual Size2 get_minimum_size() const override;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
bool is_resizing() const { return resizing; }
GraphNode();
diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp
index 465c9dac78..3c1f4bb93b 100644
--- a/scene/gui/grid_container.cpp
+++ b/scene/gui/grid_container.cpp
@@ -179,11 +179,12 @@ void GridContainer::_notification(int p_what) {
col_ofs += s.width + hsep;
}
}
-
} break;
+
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
queue_sort();
diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp
index 0cb3249c1d..9585b4d51d 100644
--- a/scene/gui/item_list.cpp
+++ b/scene/gui/item_list.cpp
@@ -855,445 +855,449 @@ static Rect2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) {
}
void ItemList::_notification(int p_what) {
- if (p_what == NOTIFICATION_RESIZED) {
- shape_changed = true;
- update();
- }
+ switch (p_what) {
+ case NOTIFICATION_RESIZED: {
+ shape_changed = true;
+ update();
+ } break;
+
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
+ case NOTIFICATION_TRANSLATION_CHANGED:
+ case NOTIFICATION_THEME_CHANGED: {
+ for (int i = 0; i < items.size(); i++) {
+ _shape(i);
+ }
+ shape_changed = true;
+ update();
+ } break;
- if ((p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED) || (p_what == NOTIFICATION_TRANSLATION_CHANGED) || (p_what == NOTIFICATION_THEME_CHANGED)) {
- for (int i = 0; i < items.size(); i++) {
- _shape(i);
- }
- shape_changed = true;
- update();
- }
+ case NOTIFICATION_DRAW: {
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
- if (p_what == NOTIFICATION_DRAW) {
- Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
+ int mw = scroll_bar->get_minimum_size().x;
+ scroll_bar->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -mw);
+ scroll_bar->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
+ scroll_bar->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, bg->get_margin(SIDE_TOP));
+ scroll_bar->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -bg->get_margin(SIDE_BOTTOM));
- int mw = scroll_bar->get_minimum_size().x;
- scroll_bar->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -mw);
- scroll_bar->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
- scroll_bar->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, bg->get_margin(SIDE_TOP));
- scroll_bar->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -bg->get_margin(SIDE_BOTTOM));
+ Size2 size = get_size();
- Size2 size = get_size();
+ int width = size.width - bg->get_minimum_size().width;
+ if (scroll_bar->is_visible()) {
+ width -= mw;
+ }
- int width = size.width - bg->get_minimum_size().width;
- if (scroll_bar->is_visible()) {
- width -= mw;
- }
+ draw_style_box(bg, Rect2(Point2(), size));
- draw_style_box(bg, Rect2(Point2(), size));
+ int hseparation = get_theme_constant(SNAME("hseparation"));
+ int vseparation = get_theme_constant(SNAME("vseparation"));
+ int icon_margin = get_theme_constant(SNAME("icon_margin"));
+ int line_separation = get_theme_constant(SNAME("line_separation"));
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
- int hseparation = get_theme_constant(SNAME("hseparation"));
- int vseparation = get_theme_constant(SNAME("vseparation"));
- int icon_margin = get_theme_constant(SNAME("icon_margin"));
- int line_separation = get_theme_constant(SNAME("line_separation"));
- Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
- int outline_size = get_theme_constant(SNAME("outline_size"));
+ Ref<StyleBox> sbsel = has_focus() ? get_theme_stylebox(SNAME("selected_focus")) : get_theme_stylebox(SNAME("selected"));
+ Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox(SNAME("cursor")) : get_theme_stylebox(SNAME("cursor_unfocused"));
+ bool rtl = is_layout_rtl();
- Ref<StyleBox> sbsel = has_focus() ? get_theme_stylebox(SNAME("selected_focus")) : get_theme_stylebox(SNAME("selected"));
- Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox(SNAME("cursor")) : get_theme_stylebox(SNAME("cursor_unfocused"));
- bool rtl = is_layout_rtl();
+ Color guide_color = get_theme_color(SNAME("guide_color"));
+ Color font_color = get_theme_color(SNAME("font_color"));
+ Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
- Color guide_color = get_theme_color(SNAME("guide_color"));
- Color font_color = get_theme_color(SNAME("font_color"));
- Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
+ if (has_focus()) {
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true);
+ draw_style_box(get_theme_stylebox(SNAME("bg_focus")), Rect2(Point2(), size));
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false);
+ }
- if (has_focus()) {
- RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true);
- draw_style_box(get_theme_stylebox(SNAME("bg_focus")), Rect2(Point2(), size));
- RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false);
- }
+ if (shape_changed) {
+ float max_column_width = 0.0;
- if (shape_changed) {
- float max_column_width = 0.0;
+ //1- compute item minimum sizes
+ for (int i = 0; i < items.size(); i++) {
+ Size2 minsize;
+ if (items[i].icon.is_valid()) {
+ if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
+ minsize = fixed_icon_size * icon_scale;
+ } else {
+ minsize = items[i].get_icon_size() * icon_scale;
+ }
- //1- compute item minimum sizes
- for (int i = 0; i < items.size(); i++) {
- Size2 minsize;
- if (items[i].icon.is_valid()) {
- if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
- minsize = fixed_icon_size * icon_scale;
- } else {
- minsize = items[i].get_icon_size() * icon_scale;
+ if (!items[i].text.is_empty()) {
+ if (icon_mode == ICON_MODE_TOP) {
+ minsize.y += icon_margin;
+ } else {
+ minsize.x += icon_margin;
+ }
+ }
}
if (!items[i].text.is_empty()) {
- if (icon_mode == ICON_MODE_TOP) {
- minsize.y += icon_margin;
- } else {
- minsize.x += icon_margin;
+ int max_width = -1;
+ if (fixed_column_width) {
+ max_width = fixed_column_width;
+ } else if (same_column_width) {
+ max_width = items[i].rect_cache.size.x;
}
- }
- }
+ items.write[i].text_buf->set_width(max_width);
+ Size2 s = items[i].text_buf->get_size();
- if (!items[i].text.is_empty()) {
- int max_width = -1;
- if (fixed_column_width) {
- max_width = fixed_column_width;
- } else if (same_column_width) {
- max_width = items[i].rect_cache.size.x;
- }
- items.write[i].text_buf->set_width(max_width);
- Size2 s = items[i].text_buf->get_size();
+ if (icon_mode == ICON_MODE_TOP) {
+ minsize.x = MAX(minsize.x, s.width);
+ if (max_text_lines > 0) {
+ minsize.y += s.height + line_separation * max_text_lines;
+ } else {
+ minsize.y += s.height;
+ }
- if (icon_mode == ICON_MODE_TOP) {
- minsize.x = MAX(minsize.x, s.width);
- if (max_text_lines > 0) {
- minsize.y += s.height + line_separation * max_text_lines;
} else {
- minsize.y += s.height;
+ minsize.y = MAX(minsize.y, s.height);
+ minsize.x += s.width;
}
+ }
- } else {
- minsize.y = MAX(minsize.y, s.height);
- minsize.x += s.width;
+ if (fixed_column_width > 0) {
+ minsize.x = fixed_column_width;
}
+ max_column_width = MAX(max_column_width, minsize.x);
+
+ // elements need to adapt to the selected size
+ minsize.y += vseparation;
+ minsize.x += hseparation;
+ items.write[i].rect_cache.size = minsize;
+ items.write[i].min_rect_cache.size = minsize;
}
- if (fixed_column_width > 0) {
- minsize.x = fixed_column_width;
+ int fit_size = size.x - bg->get_minimum_size().width - mw;
+
+ //2-attempt best fit
+ current_columns = 0x7FFFFFFF;
+ if (max_columns > 0) {
+ current_columns = max_columns;
}
- max_column_width = MAX(max_column_width, minsize.x);
- // elements need to adapt to the selected size
- minsize.y += vseparation;
- minsize.x += hseparation;
- items.write[i].rect_cache.size = minsize;
- items.write[i].min_rect_cache.size = minsize;
- }
+ while (true) {
+ //repeat until all fits
+ bool all_fit = true;
+ Vector2 ofs;
+ int col = 0;
+ int max_h = 0;
+ separators.clear();
+ for (int i = 0; i < items.size(); i++) {
+ if (current_columns > 1 && items[i].rect_cache.size.width + ofs.x > fit_size) {
+ //went past
+ current_columns = MAX(col, 1);
+ all_fit = false;
+ break;
+ }
- int fit_size = size.x - bg->get_minimum_size().width - mw;
+ if (same_column_width) {
+ items.write[i].rect_cache.size.x = max_column_width;
+ }
+ items.write[i].rect_cache.position = ofs;
+ max_h = MAX(max_h, items[i].rect_cache.size.y);
+ ofs.x += items[i].rect_cache.size.x + hseparation;
+ col++;
+ if (col == current_columns) {
+ if (i < items.size() - 1) {
+ separators.push_back(ofs.y + max_h + vseparation / 2);
+ }
- //2-attempt best fit
- current_columns = 0x7FFFFFFF;
- if (max_columns > 0) {
- current_columns = max_columns;
- }
+ for (int j = i; j >= 0 && col > 0; j--, col--) {
+ items.write[j].rect_cache.size.y = max_h;
+ }
- while (true) {
- //repeat until all fits
- bool all_fit = true;
- Vector2 ofs;
- int col = 0;
- int max_h = 0;
- separators.clear();
- for (int i = 0; i < items.size(); i++) {
- if (current_columns > 1 && items[i].rect_cache.size.width + ofs.x > fit_size) {
- //went past
- current_columns = MAX(col, 1);
- all_fit = false;
- break;
+ ofs.x = 0;
+ ofs.y += max_h + vseparation;
+ col = 0;
+ max_h = 0;
+ }
}
- if (same_column_width) {
- items.write[i].rect_cache.size.x = max_column_width;
+ for (int j = items.size() - 1; j >= 0 && col > 0; j--, col--) {
+ items.write[j].rect_cache.size.y = max_h;
}
- items.write[i].rect_cache.position = ofs;
- max_h = MAX(max_h, items[i].rect_cache.size.y);
- ofs.x += items[i].rect_cache.size.x + hseparation;
- col++;
- if (col == current_columns) {
- if (i < items.size() - 1) {
- separators.push_back(ofs.y + max_h + vseparation / 2);
- }
- for (int j = i; j >= 0 && col > 0; j--, col--) {
- items.write[j].rect_cache.size.y = max_h;
+ if (all_fit) {
+ float page = MAX(0, size.height - bg->get_minimum_size().height);
+ float max = MAX(page, ofs.y + max_h);
+ if (auto_height) {
+ auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
}
+ scroll_bar->set_max(max);
+ scroll_bar->set_page(page);
+ if (max <= page) {
+ scroll_bar->set_value(0);
+ scroll_bar->hide();
+ } else {
+ scroll_bar->show();
- ofs.x = 0;
- ofs.y += max_h + vseparation;
- col = 0;
- max_h = 0;
+ if (do_autoscroll_to_bottom) {
+ scroll_bar->set_value(max);
+ }
+ }
+ break;
}
}
- for (int j = items.size() - 1; j >= 0 && col > 0; j--, col--) {
- items.write[j].rect_cache.size.y = max_h;
- }
+ update_minimum_size();
+ shape_changed = false;
+ }
- if (all_fit) {
- float page = MAX(0, size.height - bg->get_minimum_size().height);
- float max = MAX(page, ofs.y + max_h);
- if (auto_height) {
- auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
- }
- scroll_bar->set_max(max);
- scroll_bar->set_page(page);
- if (max <= page) {
- scroll_bar->set_value(0);
- scroll_bar->hide();
- } else {
- scroll_bar->show();
+ //ensure_selected_visible needs to be checked before we draw the list.
+ if (ensure_selected_visible && current >= 0 && current < items.size()) {
+ Rect2 r = items[current].rect_cache;
+ int from = scroll_bar->get_value();
+ int to = from + scroll_bar->get_page();
- if (do_autoscroll_to_bottom) {
- scroll_bar->set_value(max);
- }
- }
- break;
+ if (r.position.y < from) {
+ scroll_bar->set_value(r.position.y);
+ } else if (r.position.y + r.size.y > to) {
+ scroll_bar->set_value(r.position.y + r.size.y - (to - from));
}
}
- update_minimum_size();
- shape_changed = false;
- }
-
- //ensure_selected_visible needs to be checked before we draw the list.
- if (ensure_selected_visible && current >= 0 && current < items.size()) {
- Rect2 r = items[current].rect_cache;
- int from = scroll_bar->get_value();
- int to = from + scroll_bar->get_page();
+ ensure_selected_visible = false;
- if (r.position.y < from) {
- scroll_bar->set_value(r.position.y);
- } else if (r.position.y + r.size.y > to) {
- scroll_bar->set_value(r.position.y + r.size.y - (to - from));
- }
- }
+ Vector2 base_ofs = bg->get_offset();
+ base_ofs.y -= int(scroll_bar->get_value());
- ensure_selected_visible = false;
+ const Rect2 clip(-base_ofs, size); // visible frame, don't need to draw outside of there
- Vector2 base_ofs = bg->get_offset();
- base_ofs.y -= int(scroll_bar->get_value());
-
- const Rect2 clip(-base_ofs, size); // visible frame, don't need to draw outside of there
-
- int first_item_visible;
- {
- // do a binary search to find the first item whose rect reaches below clip.position.y
- int lo = 0;
- int hi = items.size();
- while (lo < hi) {
- const int mid = (lo + hi) / 2;
- const Rect2 &rcache = items[mid].rect_cache;
- if (rcache.position.y + rcache.size.y < clip.position.y) {
- lo = mid + 1;
- } else {
- hi = mid;
+ int first_item_visible;
+ {
+ // do a binary search to find the first item whose rect reaches below clip.position.y
+ int lo = 0;
+ int hi = items.size();
+ while (lo < hi) {
+ const int mid = (lo + hi) / 2;
+ const Rect2 &rcache = items[mid].rect_cache;
+ if (rcache.position.y + rcache.size.y < clip.position.y) {
+ lo = mid + 1;
+ } else {
+ hi = mid;
+ }
}
- }
- // we might have ended up with column 2, or 3, ..., so let's find the first column
- while (lo > 0 && items[lo - 1].rect_cache.position.y == items[lo].rect_cache.position.y) {
- lo -= 1;
- }
- first_item_visible = lo;
- }
-
- for (int i = first_item_visible; i < items.size(); i++) {
- Rect2 rcache = items[i].rect_cache;
-
- if (rcache.position.y > clip.position.y + clip.size.y) {
- break; // done
+ // we might have ended up with column 2, or 3, ..., so let's find the first column
+ while (lo > 0 && items[lo - 1].rect_cache.position.y == items[lo].rect_cache.position.y) {
+ lo -= 1;
+ }
+ first_item_visible = lo;
}
- if (!clip.intersects(rcache)) {
- continue;
- }
+ for (int i = first_item_visible; i < items.size(); i++) {
+ Rect2 rcache = items[i].rect_cache;
- if (current_columns == 1) {
- rcache.size.width = width - rcache.position.x;
- }
+ if (rcache.position.y > clip.position.y + clip.size.y) {
+ break; // done
+ }
- if (items[i].selected) {
- Rect2 r = rcache;
- r.position += base_ofs;
- r.position.y -= vseparation / 2;
- r.size.y += vseparation;
- r.position.x -= hseparation / 2;
- r.size.x += hseparation;
-
- if (rtl) {
- r.position.x = size.width - r.position.x - r.size.x;
+ if (!clip.intersects(rcache)) {
+ continue;
}
- draw_style_box(sbsel, r);
- }
- if (items[i].custom_bg.a > 0.001) {
- Rect2 r = rcache;
- r.position += base_ofs;
-
- // Size rect to make the align the temperature colors
- r.position.y -= vseparation / 2;
- r.size.y += vseparation;
- r.position.x -= hseparation / 2;
- r.size.x += hseparation;
-
- if (rtl) {
- r.position.x = size.width - r.position.x - r.size.x;
+ if (current_columns == 1) {
+ rcache.size.width = width - rcache.position.x;
}
- draw_rect(r, items[i].custom_bg);
- }
+ if (items[i].selected) {
+ Rect2 r = rcache;
+ r.position += base_ofs;
+ r.position.y -= vseparation / 2;
+ r.size.y += vseparation;
+ r.position.x -= hseparation / 2;
+ r.size.x += hseparation;
- Vector2 text_ofs;
- if (items[i].icon.is_valid()) {
- Size2 icon_size;
- //= _adjust_to_max_size(items[i].get_icon_size(),fixed_icon_size) * icon_scale;
+ if (rtl) {
+ r.position.x = size.width - r.position.x - r.size.x;
+ }
- if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
- icon_size = fixed_icon_size * icon_scale;
- } else {
- icon_size = items[i].get_icon_size() * icon_scale;
+ draw_style_box(sbsel, r);
}
+ if (items[i].custom_bg.a > 0.001) {
+ Rect2 r = rcache;
+ r.position += base_ofs;
- Vector2 icon_ofs;
+ // Size rect to make the align the temperature colors
+ r.position.y -= vseparation / 2;
+ r.size.y += vseparation;
+ r.position.x -= hseparation / 2;
+ r.size.x += hseparation;
- Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs;
+ if (rtl) {
+ r.position.x = size.width - r.position.x - r.size.x;
+ }
- if (icon_mode == ICON_MODE_TOP) {
- pos.x += Math::floor((items[i].rect_cache.size.width - icon_size.width) / 2);
- pos.y += icon_margin;
- text_ofs.y = icon_size.height + icon_margin * 2;
- } else {
- pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2);
- text_ofs.x = icon_size.width + icon_margin;
+ draw_rect(r, items[i].custom_bg);
}
- Rect2 draw_rect = Rect2(pos, icon_size);
+ Vector2 text_ofs;
+ if (items[i].icon.is_valid()) {
+ Size2 icon_size;
+ //= _adjust_to_max_size(items[i].get_icon_size(),fixed_icon_size) * icon_scale;
- if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
- Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale, icon_size);
- draw_rect.position += adj.position;
- draw_rect.size = adj.size;
- }
+ if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
+ icon_size = fixed_icon_size * icon_scale;
+ } else {
+ icon_size = items[i].get_icon_size() * icon_scale;
+ }
- Color modulate = items[i].icon_modulate;
- if (items[i].disabled) {
- modulate.a *= 0.5;
- }
+ Vector2 icon_ofs;
- // If the icon is transposed, we have to switch the size so that it is drawn correctly
- if (items[i].icon_transposed) {
- Size2 size_tmp = draw_rect.size;
- draw_rect.size.x = size_tmp.y;
- draw_rect.size.y = size_tmp.x;
- }
+ Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs;
- Rect2 region = (items[i].icon_region.size.x == 0 || items[i].icon_region.size.y == 0) ? Rect2(Vector2(), items[i].icon->get_size()) : Rect2(items[i].icon_region);
+ if (icon_mode == ICON_MODE_TOP) {
+ pos.x += Math::floor((items[i].rect_cache.size.width - icon_size.width) / 2);
+ pos.y += icon_margin;
+ text_ofs.y = icon_size.height + icon_margin * 2;
+ } else {
+ pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2);
+ text_ofs.x = icon_size.width + icon_margin;
+ }
- if (rtl) {
- draw_rect.position.x = size.width - draw_rect.position.x - draw_rect.size.x;
- }
- draw_texture_rect_region(items[i].icon, draw_rect, region, modulate, items[i].icon_transposed);
- }
+ Rect2 draw_rect = Rect2(pos, icon_size);
- if (items[i].tag_icon.is_valid()) {
- Point2 draw_pos = items[i].rect_cache.position;
- if (rtl) {
- draw_pos.x = size.width - draw_pos.x - items[i].tag_icon->get_width();
- }
- draw_texture(items[i].tag_icon, draw_pos + base_ofs);
- }
+ if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
+ Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale, icon_size);
+ draw_rect.position += adj.position;
+ draw_rect.size = adj.size;
+ }
- if (!items[i].text.is_empty()) {
- int max_len = -1;
+ Color modulate = items[i].icon_modulate;
+ if (items[i].disabled) {
+ modulate.a *= 0.5;
+ }
- Vector2 size2 = items[i].text_buf->get_size();
- if (fixed_column_width) {
- max_len = fixed_column_width;
- } else if (same_column_width) {
- max_len = items[i].rect_cache.size.x;
- } else {
- max_len = size2.x;
- }
+ // If the icon is transposed, we have to switch the size so that it is drawn correctly
+ if (items[i].icon_transposed) {
+ Size2 size_tmp = draw_rect.size;
+ draw_rect.size.x = size_tmp.y;
+ draw_rect.size.y = size_tmp.x;
+ }
- Color modulate = items[i].selected ? font_selected_color : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color);
- if (items[i].disabled) {
- modulate.a *= 0.5;
- }
+ Rect2 region = (items[i].icon_region.size.x == 0 || items[i].icon_region.size.y == 0) ? Rect2(Vector2(), items[i].icon->get_size()) : Rect2(items[i].icon_region);
- if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
- text_ofs += base_ofs;
- text_ofs += items[i].rect_cache.position;
+ if (rtl) {
+ draw_rect.position.x = size.width - draw_rect.position.x - draw_rect.size.x;
+ }
+ draw_texture_rect_region(items[i].icon, draw_rect, region, modulate, items[i].icon_transposed);
+ }
+ if (items[i].tag_icon.is_valid()) {
+ Point2 draw_pos = items[i].rect_cache.position;
if (rtl) {
- text_ofs.x = size.width - text_ofs.x - max_len;
+ draw_pos.x = size.width - draw_pos.x - items[i].tag_icon->get_width();
}
+ draw_texture(items[i].tag_icon, draw_pos + base_ofs);
+ }
- items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_CENTER);
+ if (!items[i].text.is_empty()) {
+ int max_len = -1;
- if (outline_size > 0 && font_outline_color.a > 0) {
- items[i].text_buf->draw_outline(get_canvas_item(), text_ofs, outline_size, font_outline_color);
+ Vector2 size2 = items[i].text_buf->get_size();
+ if (fixed_column_width) {
+ max_len = fixed_column_width;
+ } else if (same_column_width) {
+ max_len = items[i].rect_cache.size.x;
+ } else {
+ max_len = size2.x;
}
- items[i].text_buf->draw(get_canvas_item(), text_ofs, modulate);
- } else {
- if (fixed_column_width > 0) {
- size2.x = MIN(size2.x, fixed_column_width);
+ Color modulate = items[i].selected ? font_selected_color : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color);
+ if (items[i].disabled) {
+ modulate.a *= 0.5;
}
- if (icon_mode == ICON_MODE_TOP) {
- text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2;
- } else {
- text_ofs.y += (items[i].rect_cache.size.height - size2.y) / 2;
- }
+ if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
+ text_ofs += base_ofs;
+ text_ofs += items[i].rect_cache.position;
- text_ofs += base_ofs;
- text_ofs += items[i].rect_cache.position;
+ if (rtl) {
+ text_ofs.x = size.width - text_ofs.x - max_len;
+ }
- if (rtl) {
- text_ofs.x = size.width - text_ofs.x - max_len;
- }
+ items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_CENTER);
- items.write[i].text_buf->set_width(max_len);
+ if (outline_size > 0 && font_outline_color.a > 0) {
+ items[i].text_buf->draw_outline(get_canvas_item(), text_ofs, outline_size, font_outline_color);
+ }
- if (rtl) {
- items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
+ items[i].text_buf->draw(get_canvas_item(), text_ofs, modulate);
} else {
- items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_LEFT);
+ if (fixed_column_width > 0) {
+ size2.x = MIN(size2.x, fixed_column_width);
+ }
+
+ if (icon_mode == ICON_MODE_TOP) {
+ text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2;
+ } else {
+ text_ofs.y += (items[i].rect_cache.size.height - size2.y) / 2;
+ }
+
+ text_ofs += base_ofs;
+ text_ofs += items[i].rect_cache.position;
+
+ if (rtl) {
+ text_ofs.x = size.width - text_ofs.x - max_len;
+ }
+
+ items.write[i].text_buf->set_width(max_len);
+
+ if (rtl) {
+ items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
+ } else {
+ items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_LEFT);
+ }
+
+ if (outline_size > 0 && font_outline_color.a > 0) {
+ items[i].text_buf->draw_outline(get_canvas_item(), text_ofs, outline_size, font_outline_color);
+ }
+
+ items[i].text_buf->draw(get_canvas_item(), text_ofs, modulate);
}
+ }
+
+ if (select_mode == SELECT_MULTI && i == current) {
+ Rect2 r = rcache;
+ r.position += base_ofs;
+ r.position.y -= vseparation / 2;
+ r.size.y += vseparation;
+ r.position.x -= hseparation / 2;
+ r.size.x += hseparation;
- if (outline_size > 0 && font_outline_color.a > 0) {
- items[i].text_buf->draw_outline(get_canvas_item(), text_ofs, outline_size, font_outline_color);
+ if (rtl) {
+ r.position.x = size.width - r.position.x - r.size.x;
}
- items[i].text_buf->draw(get_canvas_item(), text_ofs, modulate);
+ draw_style_box(cursor, r);
}
}
- if (select_mode == SELECT_MULTI && i == current) {
- Rect2 r = rcache;
- r.position += base_ofs;
- r.position.y -= vseparation / 2;
- r.size.y += vseparation;
- r.position.x -= hseparation / 2;
- r.size.x += hseparation;
-
- if (rtl) {
- r.position.x = size.width - r.position.x - r.size.x;
+ int first_visible_separator = 0;
+ {
+ // do a binary search to find the first separator that is below clip_position.y
+ int lo = 0;
+ int hi = separators.size();
+ while (lo < hi) {
+ const int mid = (lo + hi) / 2;
+ if (separators[mid] < clip.position.y) {
+ lo = mid + 1;
+ } else {
+ hi = mid;
+ }
}
-
- draw_style_box(cursor, r);
+ first_visible_separator = lo;
}
- }
- int first_visible_separator = 0;
- {
- // do a binary search to find the first separator that is below clip_position.y
- int lo = 0;
- int hi = separators.size();
- while (lo < hi) {
- const int mid = (lo + hi) / 2;
- if (separators[mid] < clip.position.y) {
- lo = mid + 1;
- } else {
- hi = mid;
+ for (int i = first_visible_separator; i < separators.size(); i++) {
+ if (separators[i] > clip.position.y + clip.size.y) {
+ break; // done
}
- }
- first_visible_separator = lo;
- }
- for (int i = first_visible_separator; i < separators.size(); i++) {
- if (separators[i] > clip.position.y + clip.size.y) {
- break; // done
+ const int y = base_ofs.y + separators[i];
+ draw_line(Vector2(bg->get_margin(SIDE_LEFT), y), Vector2(width, y), guide_color);
}
-
- const int y = base_ofs.y + separators[i];
- draw_line(Vector2(bg->get_margin(SIDE_LEFT), y), Vector2(width, y), guide_color);
- }
+ } break;
}
}
diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp
index 852aaaab24..419901d5ea 100644
--- a/scene/gui/label.cpp
+++ b/scene/gui/label.cpp
@@ -263,168 +263,227 @@ inline void draw_glyph_outline(const Glyph &p_gl, const RID &p_canvas, const Col
}
void Label::_notification(int p_what) {
- if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- String new_text = atr(text);
- if (new_text == xl_text) {
- return; // Nothing new.
- }
- xl_text = new_text;
- if (percent_visible < 1) {
- visible_chars = get_total_character_count() * percent_visible;
- }
- dirty = true;
+ switch (p_what) {
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ String new_text = atr(text);
+ if (new_text == xl_text) {
+ return; // Nothing new.
+ }
+ xl_text = new_text;
+ if (percent_visible < 1) {
+ visible_chars = get_total_character_count() * percent_visible;
+ }
+ dirty = true;
- update();
- }
+ update();
+ } break;
- if (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED) {
- update();
- }
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
+ update();
+ } break;
- if (p_what == NOTIFICATION_DRAW) {
- if (clip) {
- RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
- }
+ case NOTIFICATION_DRAW: {
+ if (clip) {
+ RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
+ }
- if (dirty || font_dirty || lines_dirty) {
- _shape();
- }
+ if (dirty || font_dirty || lines_dirty) {
+ _shape();
+ }
- RID ci = get_canvas_item();
-
- Size2 string_size;
- Size2 size = get_size();
- Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
- Ref<Font> font = get_theme_font(SNAME("font"));
- Color font_color = get_theme_color(SNAME("font_color"));
- Color font_shadow_color = get_theme_color(SNAME("font_shadow_color"));
- Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y")));
- int line_spacing = get_theme_constant(SNAME("line_spacing"));
- Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
- int outline_size = get_theme_constant(SNAME("outline_size"));
- int shadow_outline_size = get_theme_constant(SNAME("shadow_outline_size"));
- bool rtl = (TS->shaped_text_get_inferred_direction(text_rid) == TextServer::DIRECTION_RTL);
- bool rtl_layout = is_layout_rtl();
-
- style->draw(ci, Rect2(Point2(0, 0), get_size()));
-
- float total_h = 0.0;
- int lines_visible = 0;
-
- // Get number of lines to fit to the height.
- for (int64_t i = lines_skipped; i < lines_rid.size(); i++) {
- total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
- if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) {
- break;
+ RID ci = get_canvas_item();
+
+ Size2 string_size;
+ Size2 size = get_size();
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ Color font_color = get_theme_color(SNAME("font_color"));
+ Color font_shadow_color = get_theme_color(SNAME("font_shadow_color"));
+ Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y")));
+ int line_spacing = get_theme_constant(SNAME("line_spacing"));
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
+ int shadow_outline_size = get_theme_constant(SNAME("shadow_outline_size"));
+ bool rtl = (TS->shaped_text_get_inferred_direction(text_rid) == TextServer::DIRECTION_RTL);
+ bool rtl_layout = is_layout_rtl();
+
+ style->draw(ci, Rect2(Point2(0, 0), get_size()));
+
+ float total_h = 0.0;
+ int lines_visible = 0;
+
+ // Get number of lines to fit to the height.
+ for (int64_t i = lines_skipped; i < lines_rid.size(); i++) {
+ total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
+ if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) {
+ break;
+ }
+ lines_visible++;
}
- lines_visible++;
- }
- if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
- lines_visible = max_lines_visible;
- }
+ if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
+ lines_visible = max_lines_visible;
+ }
- int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped);
- bool trim_chars = (visible_chars >= 0) && (visible_chars_behavior == VC_CHARS_AFTER_SHAPING);
- bool trim_glyphs_ltr = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_LTR) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && !rtl_layout));
- bool trim_glyphs_rtl = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_RTL) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && rtl_layout));
-
- // Get real total height.
- int total_glyphs = 0;
- total_h = 0;
- for (int64_t i = lines_skipped; i < last_line; i++) {
- total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
- total_glyphs += TS->shaped_text_get_glyph_count(lines_rid[i]) + TS->shaped_text_get_ellipsis_glyph_count(lines_rid[i]);
- }
- int visible_glyphs = total_glyphs * percent_visible;
- int processed_glyphs = 0;
- total_h += style->get_margin(SIDE_TOP) + style->get_margin(SIDE_BOTTOM);
-
- int vbegin = 0, vsep = 0;
- if (lines_visible > 0) {
- switch (vertical_alignment) {
- case VERTICAL_ALIGNMENT_TOP: {
- // Nothing.
- } break;
- case VERTICAL_ALIGNMENT_CENTER: {
- vbegin = (size.y - (total_h - line_spacing)) / 2;
- vsep = 0;
-
- } break;
- case VERTICAL_ALIGNMENT_BOTTOM: {
- vbegin = size.y - (total_h - line_spacing);
- vsep = 0;
-
- } break;
- case VERTICAL_ALIGNMENT_FILL: {
- vbegin = 0;
- if (lines_visible > 1) {
- vsep = (size.y - (total_h - line_spacing)) / (lines_visible - 1);
- } else {
+ int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped);
+ bool trim_chars = (visible_chars >= 0) && (visible_chars_behavior == VC_CHARS_AFTER_SHAPING);
+ bool trim_glyphs_ltr = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_LTR) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && !rtl_layout));
+ bool trim_glyphs_rtl = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_RTL) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && rtl_layout));
+
+ // Get real total height.
+ int total_glyphs = 0;
+ total_h = 0;
+ for (int64_t i = lines_skipped; i < last_line; i++) {
+ total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
+ total_glyphs += TS->shaped_text_get_glyph_count(lines_rid[i]) + TS->shaped_text_get_ellipsis_glyph_count(lines_rid[i]);
+ }
+ int visible_glyphs = total_glyphs * percent_visible;
+ int processed_glyphs = 0;
+ total_h += style->get_margin(SIDE_TOP) + style->get_margin(SIDE_BOTTOM);
+
+ int vbegin = 0, vsep = 0;
+ if (lines_visible > 0) {
+ switch (vertical_alignment) {
+ case VERTICAL_ALIGNMENT_TOP: {
+ // Nothing.
+ } break;
+ case VERTICAL_ALIGNMENT_CENTER: {
+ vbegin = (size.y - (total_h - line_spacing)) / 2;
+ vsep = 0;
+
+ } break;
+ case VERTICAL_ALIGNMENT_BOTTOM: {
+ vbegin = size.y - (total_h - line_spacing);
vsep = 0;
- }
- } break;
+ } break;
+ case VERTICAL_ALIGNMENT_FILL: {
+ vbegin = 0;
+ if (lines_visible > 1) {
+ vsep = (size.y - (total_h - line_spacing)) / (lines_visible - 1);
+ } else {
+ vsep = 0;
+ }
+
+ } break;
+ }
}
- }
- Vector2 ofs;
- ofs.y = style->get_offset().y + vbegin;
- for (int i = lines_skipped; i < last_line; i++) {
- Size2 line_size = TS->shaped_text_get_size(lines_rid[i]);
- ofs.x = 0;
- ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(TextServer::SPACING_TOP);
- switch (horizontal_alignment) {
- case HORIZONTAL_ALIGNMENT_FILL:
- if (rtl && autowrap_mode != AUTOWRAP_OFF) {
- ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
- } else {
- ofs.x = style->get_offset().x;
- }
- break;
- case HORIZONTAL_ALIGNMENT_LEFT: {
- if (rtl_layout) {
- ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
- } else {
- ofs.x = style->get_offset().x;
- }
- } break;
- case HORIZONTAL_ALIGNMENT_CENTER: {
- ofs.x = int(size.width - line_size.width) / 2;
- } break;
- case HORIZONTAL_ALIGNMENT_RIGHT: {
- if (rtl_layout) {
- ofs.x = style->get_offset().x;
- } else {
- ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
+ Vector2 ofs;
+ ofs.y = style->get_offset().y + vbegin;
+ for (int i = lines_skipped; i < last_line; i++) {
+ Size2 line_size = TS->shaped_text_get_size(lines_rid[i]);
+ ofs.x = 0;
+ ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(TextServer::SPACING_TOP);
+ switch (horizontal_alignment) {
+ case HORIZONTAL_ALIGNMENT_FILL:
+ if (rtl && autowrap_mode != AUTOWRAP_OFF) {
+ ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
+ } else {
+ ofs.x = style->get_offset().x;
+ }
+ break;
+ case HORIZONTAL_ALIGNMENT_LEFT: {
+ if (rtl_layout) {
+ ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
+ } else {
+ ofs.x = style->get_offset().x;
+ }
+ } break;
+ case HORIZONTAL_ALIGNMENT_CENTER: {
+ ofs.x = int(size.width - line_size.width) / 2;
+ } break;
+ case HORIZONTAL_ALIGNMENT_RIGHT: {
+ if (rtl_layout) {
+ ofs.x = style->get_offset().x;
+ } else {
+ ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
+ }
+ } break;
+ }
+
+ const Glyph *glyphs = TS->shaped_text_get_glyphs(lines_rid[i]);
+ int gl_size = TS->shaped_text_get_glyph_count(lines_rid[i]);
+
+ int ellipsis_pos = TS->shaped_text_get_ellipsis_pos(lines_rid[i]);
+ int trim_pos = TS->shaped_text_get_trim_pos(lines_rid[i]);
+
+ const Glyph *ellipsis_glyphs = TS->shaped_text_get_ellipsis_glyphs(lines_rid[i]);
+ int ellipsis_gl_size = TS->shaped_text_get_ellipsis_glyph_count(lines_rid[i]);
+
+ // Draw outline. Note: Do not merge this into the single loop with the main text, to prevent overlaps.
+ int processed_glyphs_ol = processed_glyphs;
+ if ((outline_size > 0 && font_outline_color.a != 0) || (font_shadow_color.a != 0)) {
+ Vector2 offset = ofs;
+ // Draw RTL ellipsis string when necessary.
+ if (rtl && ellipsis_pos >= 0) {
+ for (int gl_idx = ellipsis_gl_size - 1; gl_idx >= 0; gl_idx--) {
+ for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
+ bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
+ //Draw glyph outlines and shadow.
+ if (!skip) {
+ draw_glyph_outline(ellipsis_glyphs[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
+ }
+ processed_glyphs_ol++;
+ offset.x += ellipsis_glyphs[gl_idx].advance;
+ }
+ }
}
- } break;
- }
- const Glyph *glyphs = TS->shaped_text_get_glyphs(lines_rid[i]);
- int gl_size = TS->shaped_text_get_glyph_count(lines_rid[i]);
+ // Draw main text.
+ for (int j = 0; j < gl_size; j++) {
+ // Trim when necessary.
+ if (trim_pos >= 0) {
+ if (rtl) {
+ if (j < trim_pos) {
+ continue;
+ }
+ } else {
+ if (j >= trim_pos) {
+ break;
+ }
+ }
+ }
+ for (int k = 0; k < glyphs[j].repeat; k++) {
+ bool skip = (trim_chars && glyphs[j].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
- int ellipsis_pos = TS->shaped_text_get_ellipsis_pos(lines_rid[i]);
- int trim_pos = TS->shaped_text_get_trim_pos(lines_rid[i]);
+ // Draw glyph outlines and shadow.
+ if (!skip) {
+ draw_glyph_outline(glyphs[j], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
+ }
+ processed_glyphs_ol++;
+ offset.x += glyphs[j].advance;
+ }
+ }
+ // Draw LTR ellipsis string when necessary.
+ if (!rtl && ellipsis_pos >= 0) {
+ for (int gl_idx = 0; gl_idx < ellipsis_gl_size; gl_idx++) {
+ for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
+ bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
+ //Draw glyph outlines and shadow.
+ if (!skip) {
+ draw_glyph_outline(ellipsis_glyphs[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
+ }
+ processed_glyphs_ol++;
+ offset.x += ellipsis_glyphs[gl_idx].advance;
+ }
+ }
+ }
+ }
- const Glyph *ellipsis_glyphs = TS->shaped_text_get_ellipsis_glyphs(lines_rid[i]);
- int ellipsis_gl_size = TS->shaped_text_get_ellipsis_glyph_count(lines_rid[i]);
+ // Draw main text. Note: Do not merge this into the single loop with the outline, to prevent overlaps.
- // Draw outline. Note: Do not merge this into the single loop with the main text, to prevent overlaps.
- int processed_glyphs_ol = processed_glyphs;
- if ((outline_size > 0 && font_outline_color.a != 0) || (font_shadow_color.a != 0)) {
- Vector2 offset = ofs;
// Draw RTL ellipsis string when necessary.
if (rtl && ellipsis_pos >= 0) {
for (int gl_idx = ellipsis_gl_size - 1; gl_idx >= 0; gl_idx--) {
for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
- bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
+ bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
//Draw glyph outlines and shadow.
if (!skip) {
- draw_glyph_outline(ellipsis_glyphs[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
+ draw_glyph(ellipsis_glyphs[gl_idx], ci, font_color, ofs);
}
- processed_glyphs_ol++;
- offset.x += ellipsis_glyphs[gl_idx].advance;
+ processed_glyphs++;
+ ofs.x += ellipsis_glyphs[gl_idx].advance;
}
}
}
@@ -444,98 +503,42 @@ void Label::_notification(int p_what) {
}
}
for (int k = 0; k < glyphs[j].repeat; k++) {
- bool skip = (trim_chars && glyphs[j].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
+ bool skip = (trim_chars && glyphs[j].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
// Draw glyph outlines and shadow.
if (!skip) {
- draw_glyph_outline(glyphs[j], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
+ draw_glyph(glyphs[j], ci, font_color, ofs);
}
- processed_glyphs_ol++;
- offset.x += glyphs[j].advance;
+ processed_glyphs++;
+ ofs.x += glyphs[j].advance;
}
}
// Draw LTR ellipsis string when necessary.
if (!rtl && ellipsis_pos >= 0) {
for (int gl_idx = 0; gl_idx < ellipsis_gl_size; gl_idx++) {
for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
- bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
+ bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
//Draw glyph outlines and shadow.
if (!skip) {
- draw_glyph_outline(ellipsis_glyphs[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
+ draw_glyph(ellipsis_glyphs[gl_idx], ci, font_color, ofs);
}
- processed_glyphs_ol++;
- offset.x += ellipsis_glyphs[gl_idx].advance;
+ processed_glyphs++;
+ ofs.x += ellipsis_glyphs[gl_idx].advance;
}
}
}
+ ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing + font->get_spacing(TextServer::SPACING_BOTTOM);
}
+ } break;
- // Draw main text. Note: Do not merge this into the single loop with the outline, to prevent overlaps.
+ case NOTIFICATION_THEME_CHANGED: {
+ font_dirty = true;
+ update();
+ } break;
- // Draw RTL ellipsis string when necessary.
- if (rtl && ellipsis_pos >= 0) {
- for (int gl_idx = ellipsis_gl_size - 1; gl_idx >= 0; gl_idx--) {
- for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
- bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
- //Draw glyph outlines and shadow.
- if (!skip) {
- draw_glyph(ellipsis_glyphs[gl_idx], ci, font_color, ofs);
- }
- processed_glyphs++;
- ofs.x += ellipsis_glyphs[gl_idx].advance;
- }
- }
- }
-
- // Draw main text.
- for (int j = 0; j < gl_size; j++) {
- // Trim when necessary.
- if (trim_pos >= 0) {
- if (rtl) {
- if (j < trim_pos) {
- continue;
- }
- } else {
- if (j >= trim_pos) {
- break;
- }
- }
- }
- for (int k = 0; k < glyphs[j].repeat; k++) {
- bool skip = (trim_chars && glyphs[j].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
-
- // Draw glyph outlines and shadow.
- if (!skip) {
- draw_glyph(glyphs[j], ci, font_color, ofs);
- }
- processed_glyphs++;
- ofs.x += glyphs[j].advance;
- }
- }
- // Draw LTR ellipsis string when necessary.
- if (!rtl && ellipsis_pos >= 0) {
- for (int gl_idx = 0; gl_idx < ellipsis_gl_size; gl_idx++) {
- for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
- bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
- //Draw glyph outlines and shadow.
- if (!skip) {
- draw_glyph(ellipsis_glyphs[gl_idx], ci, font_color, ofs);
- }
- processed_glyphs++;
- ofs.x += ellipsis_glyphs[gl_idx].advance;
- }
- }
- }
- ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing + font->get_spacing(TextServer::SPACING_BOTTOM);
- }
- }
-
- if (p_what == NOTIFICATION_THEME_CHANGED) {
- font_dirty = true;
- update();
- }
- if (p_what == NOTIFICATION_RESIZED) {
- lines_dirty = true;
+ case NOTIFICATION_RESIZED: {
+ lines_dirty = true;
+ } break;
}
}
@@ -924,20 +927,24 @@ void Label::_bind_methods() {
BIND_ENUM_CONSTANT(VC_GLYPHS_RTL);
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT, "", PROPERTY_USAGE_DEFAULT_INTL), "set_text", "get_text");
- ADD_GROUP("Locale", "");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
- ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language");
ADD_PROPERTY(PropertyInfo(Variant::INT, "horizontal_alignment", PROPERTY_HINT_ENUM, "Left,Center,Right,Fill"), "set_horizontal_alignment", "get_horizontal_alignment");
ADD_PROPERTY(PropertyInfo(Variant::INT, "vertical_alignment", PROPERTY_HINT_ENUM, "Top,Center,Bottom,Fill"), "set_vertical_alignment", "get_vertical_alignment");
ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_mode", PROPERTY_HINT_ENUM, "Off,Arbitrary,Word,Word (Smart)"), "set_autowrap_mode", "get_autowrap_mode");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "clip_text"), "set_clip_text", "is_clipping_text");
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_overrun_behavior", PROPERTY_HINT_ENUM, "Trim Nothing,Trim Characters,Trim Words,Ellipsis,Word Ellipsis"), "set_text_overrun_behavior", "get_text_overrun_behavior");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "uppercase"), "set_uppercase", "is_uppercase");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE, "0,999,1"), "set_lines_skipped", "get_lines_skipped");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "max_lines_visible", PROPERTY_HINT_RANGE, "-1,999,1"), "set_max_lines_visible", "get_max_lines_visible");
+
+ // Note: "visible_characters" and "percent_visible" should be set after "text" to be correctly applied.
ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters");
ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters_behavior", PROPERTY_HINT_ENUM, "Characters Before Shaping,Characters After Shaping,Glyphs (Layout Direction),Glyphs (Left-to-Right),Glyphs (Right-to-Left)"), "set_visible_characters_behavior", "get_visible_characters_behavior");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "lines_skipped", PROPERTY_HINT_RANGE, "0,999,1"), "set_lines_skipped", "get_lines_skipped");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "max_lines_visible", PROPERTY_HINT_RANGE, "-1,999,1"), "set_max_lines_visible", "get_max_lines_visible");
+
+ ADD_GROUP("Locale", "");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
+ ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "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");
diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp
index 3aae3377bc..883eb1a1ba 100644
--- a/scene/gui/line_edit.cpp
+++ b/scene/gui/line_edit.cpp
@@ -656,31 +656,37 @@ void LineEdit::_notification(int p_what) {
}
} break;
#endif
+
case NOTIFICATION_RESIZED: {
_fit_to_width();
scroll_offset = 0;
set_caret_column(get_caret_column());
} break;
+
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
_shape();
update();
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED: {
placeholder_translated = atr(placeholder);
_shape();
update();
} break;
+
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
window_has_focus = true;
draw_caret = true;
update();
} break;
+
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
window_has_focus = false;
draw_caret = false;
update();
} break;
+
case NOTIFICATION_DRAW: {
if ((!has_focus() && !(menu && menu->has_focus()) && !caret_force_displayed) || !window_has_focus) {
draw_caret = false;
@@ -923,6 +929,7 @@ void LineEdit::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_FOCUS_ENTER: {
if (!caret_force_displayed) {
if (caret_blink_enabled) {
@@ -942,6 +949,7 @@ void LineEdit::_notification(int p_what) {
show_virtual_keyboard();
} break;
+
case NOTIFICATION_FOCUS_EXIT: {
if (caret_blink_enabled && !caret_force_displayed) {
caret_blink_timer->stop();
@@ -964,6 +972,7 @@ void LineEdit::_notification(int p_what) {
deselect();
}
} break;
+
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
if (has_focus()) {
ime_text = DisplayServer::get_singleton()->ime_get_text();
@@ -974,10 +983,12 @@ void LineEdit::_notification(int p_what) {
update();
}
} break;
- case Control::NOTIFICATION_DRAG_BEGIN: {
+
+ case NOTIFICATION_DRAG_BEGIN: {
drag_action = true;
} break;
- case Control::NOTIFICATION_DRAG_END: {
+
+ case NOTIFICATION_DRAG_END: {
if (is_drag_successful()) {
if (selection.drag_attempt) {
selection.drag_attempt = false;
@@ -1606,7 +1617,7 @@ Size2 LineEdit::get_minimum_size() const {
Size2 min_size;
// Minimum size of text.
- int em_space_size = font->get_char_size('M', 0, font_size).x;
+ float em_space_size = font->get_char_size('M', 0, font_size).x;
min_size.width = get_theme_constant(SNAME("minimum_character_width")) * em_space_size;
if (expand_to_text_length) {
diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp
index 0ff05faf85..8f40f717c2 100644
--- a/scene/gui/link_button.cpp
+++ b/scene/gui/link_button.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "link_button.h"
+
#include "core/string/translation.h"
void LinkButton::_shape() {
@@ -148,18 +149,20 @@ void LinkButton::_notification(int p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
xl_text = atr(text);
_shape();
-
update_minimum_size();
update();
} break;
+
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
update();
} break;
+
case NOTIFICATION_THEME_CHANGED: {
_shape();
update_minimum_size();
update();
} break;
+
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Size2 size = get_size();
@@ -230,7 +233,6 @@ void LinkButton::_notification(int p_what) {
draw_line(Vector2(0, y), Vector2(width, y), color, text_buf->get_line_underline_thickness());
}
}
-
} break;
}
}
diff --git a/scene/gui/link_button.h b/scene/gui/link_button.h
index 7d302e967d..a455e866b1 100644
--- a/scene/gui/link_button.h
+++ b/scene/gui/link_button.h
@@ -32,7 +32,6 @@
#define LINKBUTTON_H
#include "scene/gui/base_button.h"
-#include "scene/resources/bit_map.h"
#include "scene/resources/text_line.h"
class LinkButton : public BaseButton {
diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp
index 7b696ddb84..fac37a8634 100644
--- a/scene/gui/margin_container.cpp
+++ b/scene/gui/margin_container.cpp
@@ -65,6 +65,24 @@ Size2 MarginContainer::get_minimum_size() const {
return max;
}
+Vector<int> MarginContainer::get_allowed_size_flags_horizontal() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
+Vector<int> MarginContainer::get_allowed_size_flags_vertical() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
void MarginContainer::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
@@ -89,6 +107,7 @@ void MarginContainer::_notification(int p_what) {
fit_child_in_rect(c, Rect2(margin_left, margin_top, w, h));
}
} break;
+
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
diff --git a/scene/gui/margin_container.h b/scene/gui/margin_container.h
index 3a2f0fa8b3..f8a3c5bb11 100644
--- a/scene/gui/margin_container.h
+++ b/scene/gui/margin_container.h
@@ -42,6 +42,9 @@ protected:
public:
virtual Size2 get_minimum_size() const override;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
MarginContainer();
};
diff --git a/scene/gui/menu_button.cpp b/scene/gui/menu_button.cpp
index a985a9d031..46d8a61ca1 100644
--- a/scene/gui/menu_button.cpp
+++ b/scene/gui/menu_button.cpp
@@ -136,11 +136,16 @@ int MenuButton::get_item_count() const {
void MenuButton::_notification(int p_what) {
switch (p_what) {
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
+ popup->set_layout_direction((Window::LayoutDirection)get_layout_direction());
+ } break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
popup->hide();
}
} break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
Vector2i mouse_pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted;
MenuButton *menu_btn_other = Object::cast_to<MenuButton>(get_viewport()->gui_find_control(mouse_pos));
diff --git a/scene/gui/nine_patch_rect.cpp b/scene/gui/nine_patch_rect.cpp
index 779d1307f5..4f34ece86f 100644
--- a/scene/gui/nine_patch_rect.cpp
+++ b/scene/gui/nine_patch_rect.cpp
@@ -34,18 +34,20 @@
#include "servers/rendering_server.h"
void NinePatchRect::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- if (texture.is_null()) {
- return;
- }
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ if (texture.is_null()) {
+ return;
+ }
- Rect2 rect = Rect2(Point2(), get_size());
- Rect2 src_rect = region_rect;
+ Rect2 rect = Rect2(Point2(), get_size());
+ Rect2 src_rect = region_rect;
- texture->get_rect_region(rect, src_rect, rect, src_rect);
+ texture->get_rect_region(rect, src_rect, rect, src_rect);
- RID ci = get_canvas_item();
- RS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[SIDE_LEFT], margin[SIDE_TOP]), Vector2(margin[SIDE_RIGHT], margin[SIDE_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center);
+ RID ci = get_canvas_item();
+ RS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[SIDE_LEFT], margin[SIDE_TOP]), Vector2(margin[SIDE_RIGHT], margin[SIDE_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center);
+ } break;
}
}
@@ -93,10 +95,6 @@ void NinePatchRect::set_texture(const Ref<Texture2D> &p_tex) {
}
texture = p_tex;
update();
- /*
- if (texture.is_valid())
- texture->set_flags(texture->get_flags()&(~Texture::FLAG_REPEAT)); //remove repeat from texture, it looks bad in sprites
- */
update_minimum_size();
emit_signal(SceneStringNames::get_singleton()->texture_changed);
}
diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp
index 9984ab240a..698d74843c 100644
--- a/scene/gui/option_button.cpp
+++ b/scene/gui/option_button.cpp
@@ -91,8 +91,12 @@ void OptionButton::_notification(int p_what) {
}
arrow->draw(ci, ofs, clr);
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED:
- case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
+ popup->set_layout_direction((Window::LayoutDirection)get_layout_direction());
+ [[fallthrough]];
+ }
case NOTIFICATION_THEME_CHANGED: {
if (has_theme_icon(SNAME("arrow"))) {
if (is_layout_rtl()) {
@@ -104,6 +108,7 @@ void OptionButton::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
popup->hide();
@@ -115,6 +120,11 @@ void OptionButton::_notification(int p_what) {
bool OptionButton::_set(const StringName &p_name, const Variant &p_value) {
Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() >= 2 && components[0] == "popup") {
+ String property = components[2];
+ if (property != "text" && property != "icon" && property != "id" && property != "disabled" && property != "separator") {
+ return false;
+ }
+
bool valid;
popup->set(String(p_name).trim_prefix("popup/"), p_value, &valid);
@@ -133,6 +143,11 @@ bool OptionButton::_set(const StringName &p_name, const Variant &p_value) {
bool OptionButton::_get(const StringName &p_name, Variant &r_ret) const {
Vector<String> components = String(p_name).split("/", true, 2);
if (components.size() >= 2 && components[0] == "popup") {
+ String property = components[2];
+ if (property != "text" && property != "icon" && property != "id" && property != "disabled" && property != "separator") {
+ return false;
+ }
+
bool valid;
r_ret = popup->get(String(p_name).trim_prefix("popup/"), &valid);
return valid;
@@ -148,14 +163,6 @@ void OptionButton::_get_property_list(List<PropertyInfo> *p_list) const {
pi.usage &= ~(popup->get_item_icon(i).is_null() ? PROPERTY_USAGE_STORAGE : 0);
p_list->push_back(pi);
- pi = PropertyInfo(Variant::INT, vformat("popup/item_%d/checkable", i), PROPERTY_HINT_ENUM, "No,As checkbox,As radio button");
- pi.usage &= ~(!popup->is_item_checkable(i) ? PROPERTY_USAGE_STORAGE : 0);
- p_list->push_back(pi);
-
- pi = PropertyInfo(Variant::BOOL, vformat("popup/item_%d/checked", i));
- pi.usage &= ~(!popup->is_item_checked(i) ? PROPERTY_USAGE_STORAGE : 0);
- p_list->push_back(pi);
-
pi = PropertyInfo(Variant::INT, vformat("popup/item_%d/id", i), PROPERTY_HINT_RANGE, "0,10,1,or_greater");
p_list->push_back(pi);
@@ -183,10 +190,13 @@ void OptionButton::pressed() {
popup->set_size(Size2(size.width, 0));
// If not triggered by the mouse, start the popup with the checked item selected.
- if (popup->get_item_count() > 0 &&
- ((get_action_mode() == ActionMode::ACTION_MODE_BUTTON_PRESS && Input::get_singleton()->is_action_just_pressed("ui_accept")) ||
- (get_action_mode() == ActionMode::ACTION_MODE_BUTTON_RELEASE && Input::get_singleton()->is_action_just_released("ui_accept")))) {
- popup->set_current_index(current > -1 ? current : 0);
+ if (popup->get_item_count() > 0) {
+ if ((get_action_mode() == ActionMode::ACTION_MODE_BUTTON_PRESS && Input::get_singleton()->is_action_just_pressed("ui_accept")) ||
+ (get_action_mode() == ActionMode::ACTION_MODE_BUTTON_RELEASE && Input::get_singleton()->is_action_just_released("ui_accept"))) {
+ popup->set_current_index(current > -1 ? current : 0);
+ } else {
+ popup->scroll_to_item(current > -1 ? current : 0);
+ }
}
popup->popup();
@@ -264,7 +274,20 @@ bool OptionButton::is_item_disabled(int p_idx) const {
void OptionButton::set_item_count(int p_count) {
ERR_FAIL_COND(p_count < 0);
+
+ int count_old = get_item_count();
+ if (p_count == count_old) {
+ return;
+ }
+
popup->set_item_count(p_count);
+
+ if (p_count > count_old) {
+ for (int i = count_old; i < p_count; i++) {
+ popup->set_item_as_radio_checkable(i, true);
+ }
+ }
+
notify_property_list_changed();
}
@@ -294,7 +317,7 @@ void OptionButton::_select(int p_which, bool p_emit) {
current = NONE_SELECTED;
set_text("");
- set_icon(NULL);
+ set_icon(nullptr);
} else {
ERR_FAIL_INDEX(p_which, popup->get_item_count());
diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp
index 86858fdc78..1ac6cf57ab 100644
--- a/scene/gui/panel.cpp
+++ b/scene/gui/panel.cpp
@@ -30,35 +30,16 @@
#include "panel.h"
-#include "core/string/print_string.h"
-
void Panel::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- RID ci = get_canvas_item();
- Ref<StyleBox> style = mode == MODE_BACKGROUND ? get_theme_stylebox(SNAME("panel")) : get_theme_stylebox(SNAME("panel_fg"));
- style->draw(ci, Rect2(Point2(), get_size()));
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ RID ci = get_canvas_item();
+ Ref<StyleBox> style = get_theme_stylebox(SNAME("panel"));
+ style->draw(ci, Rect2(Point2(), get_size()));
+ } break;
}
}
-void Panel::set_mode(Mode p_mode) {
- mode = p_mode;
- update();
-}
-
-Panel::Mode Panel::get_mode() const {
- return mode;
-}
-
-void Panel::_bind_methods() {
- ClassDB::bind_method(D_METHOD("set_mode", "mode"), &Panel::set_mode);
- ClassDB::bind_method(D_METHOD("get_mode"), &Panel::get_mode);
-
- ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Background,Foreground"), "set_mode", "get_mode");
-
- BIND_ENUM_CONSTANT(MODE_BACKGROUND);
- BIND_ENUM_CONSTANT(MODE_FOREGROUND);
-}
-
Panel::Panel() {
// Has visible stylebox, so stop by default.
set_mouse_filter(MOUSE_FILTER_STOP);
diff --git a/scene/gui/panel.h b/scene/gui/panel.h
index 37f14c250c..5d2e912680 100644
--- a/scene/gui/panel.h
+++ b/scene/gui/panel.h
@@ -36,26 +36,11 @@
class Panel : public Control {
GDCLASS(Panel, Control);
-public:
- enum Mode {
- MODE_BACKGROUND,
- MODE_FOREGROUND,
- };
-
-private:
- Mode mode = MODE_BACKGROUND;
-
protected:
void _notification(int p_what);
- static void _bind_methods();
public:
- void set_mode(Mode p_mode);
- Mode get_mode() const;
-
Panel();
};
-VARIANT_ENUM_CAST(Panel::Mode)
-
#endif // PANEL_H
diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp
index 463ad3c513..fe01712a89 100644
--- a/scene/gui/panel_container.cpp
+++ b/scene/gui/panel_container.cpp
@@ -60,47 +60,67 @@ Size2 PanelContainer::get_minimum_size() const {
return ms;
}
-void PanelContainer::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- RID ci = get_canvas_item();
- Ref<StyleBox> style;
-
- if (has_theme_stylebox(SNAME("panel"))) {
- style = get_theme_stylebox(SNAME("panel"));
- } else {
- style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
- }
+Vector<int> PanelContainer::get_allowed_size_flags_horizontal() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
- style->draw(ci, Rect2(Point2(), get_size()));
- }
+Vector<int> PanelContainer::get_allowed_size_flags_vertical() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
- if (p_what == NOTIFICATION_SORT_CHILDREN) {
- Ref<StyleBox> style;
+void PanelContainer::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ RID ci = get_canvas_item();
+ Ref<StyleBox> style;
- if (has_theme_stylebox(SNAME("panel"))) {
- style = get_theme_stylebox(SNAME("panel"));
- } else {
- style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
- }
+ if (has_theme_stylebox(SNAME("panel"))) {
+ style = get_theme_stylebox(SNAME("panel"));
+ } else {
+ style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
+ }
- Size2 size = get_size();
- Point2 ofs;
- if (style.is_valid()) {
- size -= style->get_minimum_size();
- ofs += style->get_offset();
- }
+ style->draw(ci, Rect2(Point2(), get_size()));
+ } break;
- for (int i = 0; i < get_child_count(); i++) {
- Control *c = Object::cast_to<Control>(get_child(i));
- if (!c || !c->is_visible_in_tree()) {
- continue;
+ case NOTIFICATION_SORT_CHILDREN: {
+ Ref<StyleBox> style;
+
+ if (has_theme_stylebox(SNAME("panel"))) {
+ style = get_theme_stylebox(SNAME("panel"));
+ } else {
+ style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
}
- if (c->is_set_as_top_level()) {
- continue;
+
+ Size2 size = get_size();
+ Point2 ofs;
+ if (style.is_valid()) {
+ size -= style->get_minimum_size();
+ ofs += style->get_offset();
}
- fit_child_in_rect(c, Rect2(ofs, size));
- }
+ for (int i = 0; i < get_child_count(); i++) {
+ Control *c = Object::cast_to<Control>(get_child(i));
+ if (!c || !c->is_visible_in_tree()) {
+ continue;
+ }
+ if (c->is_set_as_top_level()) {
+ continue;
+ }
+
+ fit_child_in_rect(c, Rect2(ofs, size));
+ }
+ } break;
}
}
diff --git a/scene/gui/panel_container.h b/scene/gui/panel_container.h
index a5ff74cebb..8f07ce38eb 100644
--- a/scene/gui/panel_container.h
+++ b/scene/gui/panel_container.h
@@ -42,6 +42,9 @@ protected:
public:
virtual Size2 get_minimum_size() const override;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
PanelContainer();
};
diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp
index 7c03fcbb37..4a5dc57e36 100644
--- a/scene/gui/popup.cpp
+++ b/scene/gui/popup.cpp
@@ -74,19 +74,19 @@ void Popup::_notification(int p_what) {
emit_signal(SNAME("popup_hide"));
popped_up = false;
}
-
} break;
+
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
if (has_focus()) {
popped_up = true;
}
} break;
+
case NOTIFICATION_EXIT_TREE: {
_deinitialize_visible_parents();
} break;
- case NOTIFICATION_WM_CLOSE_REQUEST: {
- _close_pressed();
- } break;
+
+ case NOTIFICATION_WM_CLOSE_REQUEST:
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
_close_pressed();
} break;
@@ -241,13 +241,20 @@ void PopupPanel::_update_child_rects() {
}
void PopupPanel::_notification(int p_what) {
- if (p_what == NOTIFICATION_THEME_CHANGED) {
- panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
- } else if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_ENTER_TREE) {
- panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
- _update_child_rects();
- } else if (p_what == NOTIFICATION_WM_SIZE_CHANGED) {
- _update_child_rects();
+ switch (p_what) {
+ case NOTIFICATION_THEME_CHANGED: {
+ panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
+ } break;
+
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_READY: {
+ panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
+ _update_child_rects();
+ } break;
+
+ case NOTIFICATION_WM_SIZE_CHANGED: {
+ _update_child_rects();
+ } break;
}
}
diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp
index 812339dc19..deca1451ee 100644
--- a/scene/gui/popup_menu.cpp
+++ b/scene/gui/popup_menu.cpp
@@ -30,6 +30,7 @@
#include "popup_menu.h"
+#include "core/config/project_settings.h"
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
@@ -67,7 +68,7 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
size.width += items[i].h_ofs;
- if (items[i].checkable_type) {
+ if (items[i].checkable_type && !items[i].separator) {
has_check = true;
}
@@ -108,10 +109,9 @@ Size2 PopupMenu::_get_contents_minimum_size() const {
int PopupMenu::_get_item_height(int p_item) const {
ERR_FAIL_INDEX_V(p_item, items.size(), 0);
- ERR_FAIL_COND_V(p_item < 0, 0);
int icon_height = items[p_item].get_icon_size().height;
- if (items[p_item].checkable_type) {
+ if (items[p_item].checkable_type && !items[p_item].separator) {
icon_height = MAX(icon_height, MAX(get_theme_icon(SNAME("checked"))->get_height(), get_theme_icon(SNAME("radio_checked"))->get_height()));
}
@@ -141,23 +141,6 @@ int PopupMenu::_get_items_total_height() const {
return items_total_height - vsep;
}
-void PopupMenu::_scroll_to_item(int p_item) {
- ERR_FAIL_INDEX(p_item, items.size());
- ERR_FAIL_COND(p_item < 0);
-
- // Scroll item into view (upwards)
- if (items[p_item]._ofs_cache < -control->get_position().y) {
- int amnt_over = items[p_item]._ofs_cache + control->get_position().y;
- scroll_container->set_v_scroll(scroll_container->get_v_scroll() + amnt_over);
- }
-
- // Scroll item into view (downwards)
- if (items[p_item]._ofs_cache + items[p_item]._height_cache > -control->get_position().y + scroll_container->get_size().height) {
- int amnt_over = items[p_item]._ofs_cache + items[p_item]._height_cache + control->get_position().y - scroll_container->get_size().height;
- scroll_container->set_v_scroll(scroll_container->get_v_scroll() + amnt_over);
- }
-}
-
int PopupMenu::_get_mouse_over(const Point2 &p_over) const {
if (p_over.x < 0 || p_over.x >= get_size().width) {
return -1;
@@ -203,15 +186,17 @@ void PopupMenu::_activate_submenu(int p_over) {
float scroll_offset = control->get_position().y;
- Point2 submenu_pos;
+ submenu_popup->set_as_minsize(); // Shrink the popup size to its contents.
Size2 submenu_size = submenu_popup->get_size();
+
+ Point2 submenu_pos;
if (control->is_layout_rtl()) {
submenu_pos = this_pos + Point2(-submenu_size.width, items[p_over]._ofs_cache + scroll_offset);
} else {
submenu_pos = this_pos + Point2(this_rect.size.width, items[p_over]._ofs_cache + scroll_offset);
}
- // Fix pos if going outside parent rect
+ // Fix pos if going outside parent rect.
if (submenu_pos.x < get_parent_rect().position.x) {
submenu_pos.x = this_pos.x + submenu_size.width;
}
@@ -222,7 +207,6 @@ void PopupMenu::_activate_submenu(int p_over) {
submenu_popup->set_close_on_parent_focus(false);
submenu_popup->set_position(submenu_pos);
- submenu_popup->set_as_minsize(); // Shrink the popup size to its contents.
PopupMenu *submenu_pum = Object::cast_to<PopupMenu>(submenu_popup);
if (!submenu_pum) {
@@ -275,7 +259,7 @@ void PopupMenu::gui_input(const Ref<InputEvent> &p_event) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
emit_signal(SNAME("id_focused"), i);
- _scroll_to_item(i);
+ scroll_to_item(i);
control->update();
set_input_as_handled();
match_found = true;
@@ -289,7 +273,7 @@ void PopupMenu::gui_input(const Ref<InputEvent> &p_event) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
emit_signal(SNAME("id_focused"), i);
- _scroll_to_item(i);
+ scroll_to_item(i);
control->update();
set_input_as_handled();
break;
@@ -307,7 +291,7 @@ void PopupMenu::gui_input(const Ref<InputEvent> &p_event) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
emit_signal(SNAME("id_focused"), i);
- _scroll_to_item(i);
+ scroll_to_item(i);
control->update();
set_input_as_handled();
match_found = true;
@@ -321,7 +305,7 @@ void PopupMenu::gui_input(const Ref<InputEvent> &p_event) {
if (!items[i].separator && !items[i].disabled) {
mouse_over = i;
emit_signal(SNAME("id_focused"), i);
- _scroll_to_item(i);
+ scroll_to_item(i);
control->update();
set_input_as_handled();
break;
@@ -471,7 +455,7 @@ void PopupMenu::gui_input(const Ref<InputEvent> &p_event) {
if (items[i].text.findn(search_string) == 0) {
mouse_over = i;
emit_signal(SNAME("id_focused"), i);
- _scroll_to_item(i);
+ scroll_to_item(i);
control->update();
set_input_as_handled();
break;
@@ -495,7 +479,7 @@ void PopupMenu::_draw_items() {
bool rtl = control->is_layout_rtl();
Ref<StyleBox> style = get_theme_stylebox(SNAME("panel"));
Ref<StyleBox> hover = get_theme_stylebox(SNAME("hover"));
- // In Item::checkable_type enum order (less the non-checkable member)
+ // In Item::checkable_type enum order (less the non-checkable member).
Ref<Texture2D> check[] = { get_theme_icon(SNAME("checked")), get_theme_icon(SNAME("radio_checked")) };
Ref<Texture2D> uncheck[] = { get_theme_icon(SNAME("unchecked")), get_theme_icon(SNAME("radio_unchecked")) };
Ref<Texture2D> submenu;
@@ -524,6 +508,10 @@ void PopupMenu::_draw_items() {
float icon_ofs = 0.0;
bool has_check = false;
for (int i = 0; i < items.size(); i++) {
+ if (items[i].separator) {
+ continue;
+ }
+
icon_ofs = MAX(items[i].get_icon_size().width, icon_ofs);
if (items[i].checkable_type) {
@@ -567,29 +555,33 @@ void PopupMenu::_draw_items() {
if (items[i].separator) {
int sep_h = separator->get_center_size().height + separator->get_minimum_size().height;
int sep_ofs = Math::floor((h - sep_h) / 2.0);
- if (!text.is_empty()) {
- int text_size = items[i].text_buf->get_size().width;
- int text_center = display_width / 2;
- int text_left = text_center - text_size / 2;
- int text_right = text_center + text_size / 2;
- if (text_left > item_ofs.x) {
- labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(MAX(0, text_left - item_ofs.x), sep_h)));
+ if (!text.is_empty() || !items[i].icon.is_null()) {
+ int content_size = items[i].text_buf->get_size().width;
+ if (!items[i].icon.is_null()) {
+ content_size += icon_size.width + hseparation;
+ }
+
+ int content_center = display_width / 2;
+ int content_left = content_center - content_size / 2;
+ int content_right = content_center + content_size / 2;
+ if (content_left > item_ofs.x) {
+ labeled_separator_left->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(MAX(0, content_left - item_ofs.x), sep_h)));
}
- if (text_right < display_width) {
- labeled_separator_right->draw(ci, Rect2(Point2(text_right, item_ofs.y + sep_ofs), Size2(MAX(0, display_width - text_right), sep_h)));
+ if (content_right < display_width) {
+ labeled_separator_right->draw(ci, Rect2(Point2(content_right, item_ofs.y + sep_ofs), Size2(MAX(0, display_width - content_right), sep_h)));
}
} else {
separator->draw(ci, Rect2(item_ofs + Point2(0, sep_ofs), Size2(display_width, sep_h)));
}
}
- Color icon_color(1, 1, 1, items[i].disabled ? 0.5 : 1);
+ Color icon_color(1, 1, 1, items[i].disabled && !items[i].separator ? 0.5 : 1);
// For non-separator items, add some padding for the content.
item_ofs.x += item_start_padding;
// Checkboxes
- if (items[i].checkable_type) {
+ if (items[i].checkable_type && !items[i].separator) {
Texture2D *icon = (items[i].checked ? check[items[i].checkable_type - 1] : uncheck[items[i].checkable_type - 1]).ptr();
if (rtl) {
icon->draw(ci, Size2(control->get_size().width - item_ofs.x - icon->get_width(), item_ofs.y) + Point2(0, Math::floor((h - icon->get_height()) / 2.0)), icon_color);
@@ -598,16 +590,28 @@ void PopupMenu::_draw_items() {
}
}
+ int separator_ofs = (display_width - items[i].text_buf->get_size().width) / 2;
+
// Icon
if (!items[i].icon.is_null()) {
- if (rtl) {
- items[i].icon->draw(ci, Size2(control->get_size().width - item_ofs.x - check_ofs - icon_size.width, item_ofs.y) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color);
+ if (items[i].separator) {
+ separator_ofs -= (icon_size.width + hseparation) / 2;
+
+ if (rtl) {
+ items[i].icon->draw(ci, Size2(control->get_size().width - item_ofs.x - separator_ofs - icon_size.width, item_ofs.y) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color);
+ } else {
+ items[i].icon->draw(ci, item_ofs + Size2(separator_ofs, 0) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color);
+ }
} else {
- items[i].icon->draw(ci, item_ofs + Size2(check_ofs, 0) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color);
+ if (rtl) {
+ items[i].icon->draw(ci, Size2(control->get_size().width - item_ofs.x - check_ofs - icon_size.width, item_ofs.y) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color);
+ } else {
+ items[i].icon->draw(ci, item_ofs + Size2(check_ofs, 0) + Point2(0, Math::floor((h - icon_size.height) / 2.0)), icon_color);
+ }
}
}
- // Submenu arrow on right hand side
+ // Submenu arrow on right hand side.
if (!items[i].submenu.is_empty()) {
if (rtl) {
submenu->draw(ci, Point2(scroll_width + style->get_margin(SIDE_LEFT) + item_end_padding, item_ofs.y + Math::floor(h - submenu->get_height()) / 2), icon_color);
@@ -621,8 +625,11 @@ void PopupMenu::_draw_items() {
int outline_size = get_theme_constant(SNAME("outline_size"));
if (items[i].separator) {
if (!text.is_empty()) {
- int center = (display_width - items[i].text_buf->get_size().width) / 2;
- Vector2 text_pos = Point2(center, item_ofs.y + Math::floor((h - items[i].text_buf->get_size().y) / 2.0));
+ Vector2 text_pos = Point2(separator_ofs, item_ofs.y + Math::floor((h - items[i].text_buf->get_size().y) / 2.0));
+ if (!rtl && !items[i].icon.is_null()) {
+ text_pos.x += icon_size.width + hseparation;
+ }
+
if (outline_size > 0 && font_outline_color.a > 0) {
items[i].text_buf->draw_outline(ci, text_pos, outline_size, font_outline_color);
}
@@ -659,7 +666,7 @@ void PopupMenu::_draw_items() {
items[i].accel_text_buf->draw(ci, text_pos, i == mouse_over ? font_hover_color : font_accelerator_color);
}
- // Cache the item vertical offset from the first item and the height
+ // Cache the item vertical offset from the first item and the height.
items.write[i]._ofs_cache = ofs.y;
items.write[i]._height_cache = h;
@@ -724,11 +731,12 @@ void PopupMenu::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
PopupMenu *pm = Object::cast_to<PopupMenu>(get_parent());
if (pm) {
- // Inherit submenu's popup delay time from parent menu
+ // Inherit submenu's popup delay time from parent menu.
float pm_delay = pm->get_submenu_popup_delay();
set_submenu_popup_delay(pm_delay);
}
} break;
+
case NOTIFICATION_THEME_CHANGED:
case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
@@ -741,23 +749,25 @@ void PopupMenu::_notification(int p_what) {
child_controls_changed();
control->update();
} break;
+
case NOTIFICATION_WM_MOUSE_ENTER: {
grab_focus();
} break;
+
case NOTIFICATION_WM_MOUSE_EXIT: {
if (mouse_over >= 0 && (items[mouse_over].submenu.is_empty() || submenu_over != -1)) {
mouse_over = -1;
control->update();
}
} break;
+
case NOTIFICATION_POST_POPUP: {
initial_button_mask = Input::get_singleton()->get_mouse_button_mask();
during_grabbed_click = (bool)initial_button_mask;
} break;
- case NOTIFICATION_WM_SIZE_CHANGED: {
- } break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
- //only used when using operating system windows
+ // Only used when using operating system windows.
if (!is_embedded() && autohide_areas.size()) {
Point2 mouse_pos = DisplayServer::get_singleton()->mouse_get_position();
mouse_pos -= get_position();
@@ -770,6 +780,7 @@ void PopupMenu::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible()) {
if (mouse_over >= 0) {
@@ -819,7 +830,7 @@ void PopupMenu::_notification(int p_what) {
#define ITEM_SETUP_WITH_ACCEL(p_label, p_id, p_accel) \
item.text = p_label; \
item.xl_text = atr(p_label); \
- item.id = p_id == -1 ? items.size() - 1 : p_id; \
+ item.id = p_id == -1 ? items.size() : p_id; \
item.accel = p_accel;
void PopupMenu::add_item(const String &p_label, int p_id, Key p_accel) {
@@ -901,7 +912,7 @@ void PopupMenu::add_multistate_item(const String &p_label, int p_max_states, int
_ref_shortcut(p_shortcut); \
item.text = p_shortcut->get_name(); \
item.xl_text = atr(item.text); \
- item.id = p_id == -1 ? items.size() - 1 : p_id; \
+ item.id = p_id == -1 ? items.size() : p_id; \
item.shortcut = p_shortcut; \
item.shortcut_is_global = p_global;
@@ -970,7 +981,7 @@ void PopupMenu::add_submenu_item(const String &p_label, const String &p_submenu,
Item item;
item.text = p_label;
item.xl_text = atr(p_label);
- item.id = p_id == -1 ? items.size() - 1 : p_id;
+ item.id = p_id == -1 ? items.size() : p_id;
item.submenu = p_submenu;
items.push_back(item);
_shape_item(items.size() - 1);
@@ -1281,7 +1292,7 @@ bool PopupMenu::is_item_shortcut_disabled(int p_idx) const {
void PopupMenu::set_current_index(int p_idx) {
ERR_FAIL_INDEX(p_idx, items.size());
mouse_over = p_idx;
- _scroll_to_item(mouse_over);
+ scroll_to_item(mouse_over);
control->update();
}
@@ -1309,6 +1320,20 @@ int PopupMenu::get_item_count() const {
return items.size();
}
+void PopupMenu::scroll_to_item(int p_item) {
+ ERR_FAIL_INDEX(p_item, items.size());
+
+ // Scroll item into view (upwards).
+ if (items[p_item]._ofs_cache - scroll_container->get_v_scroll() < -control->get_position().y) {
+ scroll_container->set_v_scroll(items[p_item]._ofs_cache + control->get_position().y);
+ }
+
+ // Scroll item into view (downwards).
+ if (items[p_item]._ofs_cache + items[p_item]._height_cache - scroll_container->get_v_scroll() > -control->get_position().y + scroll_container->get_size().height) {
+ scroll_container->set_v_scroll(items[p_item]._ofs_cache + items[p_item]._height_cache + control->get_position().y);
+ }
+}
+
bool PopupMenu::activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only) {
Key code = Key::NONE;
Ref<InputEventKey> k = p_event;
@@ -1582,7 +1607,7 @@ bool PopupMenu::_set(const StringName &p_name, const Variant &p_value) {
} else if (property == "id") {
set_item_id(item_index, p_value);
return true;
- } else if (components[1] == "disabled") {
+ } else if (property == "disabled") {
set_item_disabled(item_index, p_value);
return true;
} else if (property == "separator") {
@@ -1655,7 +1680,7 @@ bool PopupMenu::_get(const StringName &p_name, Variant &r_ret) const {
} else if (property == "id") {
r_ret = get_item_id(item_index);
return true;
- } else if (components[1] == "disabled") {
+ } else if (property == "disabled") {
r_ret = is_item_disabled(item_index);
return true;
} else if (property == "separator") {
@@ -1761,6 +1786,8 @@ void PopupMenu::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_item_count", "count"), &PopupMenu::set_item_count);
ClassDB::bind_method(D_METHOD("get_item_count"), &PopupMenu::get_item_count);
+ ClassDB::bind_method(D_METHOD("scroll_to_item", "index"), &PopupMenu::scroll_to_item);
+
ClassDB::bind_method(D_METHOD("remove_item", "index"), &PopupMenu::remove_item);
ClassDB::bind_method(D_METHOD("add_separator", "label", "id"), &PopupMenu::add_separator, DEFVAL(String()), DEFVAL(-1));
diff --git a/scene/gui/popup_menu.h b/scene/gui/popup_menu.h
index 7c2212d82d..5ce55209d4 100644
--- a/scene/gui/popup_menu.h
+++ b/scene/gui/popup_menu.h
@@ -103,7 +103,6 @@ class PopupMenu : public Popup {
int _get_item_height(int p_item) const;
int _get_items_total_height() const;
- void _scroll_to_item(int p_item);
void _shape_item(int p_item);
@@ -218,6 +217,8 @@ public:
void set_item_count(int p_count);
int get_item_count() const;
+ void scroll_to_item(int p_item);
+
bool activate_item_by_event(const Ref<InputEvent> &p_event, bool p_for_global_only = false);
void activate_item(int p_item);
diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp
index c20fb0d7a8..20b3513375 100644
--- a/scene/gui/progress_bar.cpp
+++ b/scene/gui/progress_bar.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "progress_bar.h"
+
#include "scene/resources/text_line.h"
Size2 ProgressBar::get_minimum_size() const {
@@ -52,36 +53,38 @@ Size2 ProgressBar::get_minimum_size() const {
}
void ProgressBar::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
- Ref<StyleBox> fg = get_theme_stylebox(SNAME("fg"));
- Ref<Font> font = get_theme_font(SNAME("font"));
- int font_size = get_theme_font_size(SNAME("font_size"));
- Color font_color = get_theme_color(SNAME("font_color"));
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
+ Ref<StyleBox> fg = get_theme_stylebox(SNAME("fg"));
+ Ref<Font> font = get_theme_font(SNAME("font"));
+ int font_size = get_theme_font_size(SNAME("font_size"));
+ Color font_color = get_theme_color(SNAME("font_color"));
- draw_style_box(bg, Rect2(Point2(), get_size()));
- float r = get_as_ratio();
- int mp = fg->get_minimum_size().width;
- int p = r * (get_size().width - mp);
- if (p > 0) {
- if (is_layout_rtl()) {
- draw_style_box(fg, Rect2(Point2(p, 0), Size2(fg->get_minimum_size().width, get_size().height)));
- } else {
- draw_style_box(fg, Rect2(Point2(0, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
+ draw_style_box(bg, Rect2(Point2(), get_size()));
+ float r = get_as_ratio();
+ int mp = fg->get_minimum_size().width;
+ int p = r * (get_size().width - mp);
+ if (p > 0) {
+ if (is_layout_rtl()) {
+ draw_style_box(fg, Rect2(Point2(p, 0), Size2(fg->get_minimum_size().width, get_size().height)));
+ } else {
+ draw_style_box(fg, Rect2(Point2(0, 0), Size2(p + fg->get_minimum_size().width, get_size().height)));
+ }
}
- }
- if (percent_visible) {
- String txt = TS->format_number(itos(int(get_as_ratio() * 100))) + TS->percent_sign();
- TextLine tl = TextLine(txt, font, font_size);
- Vector2 text_pos = (Point2(get_size().width - tl.get_size().x, get_size().height - tl.get_size().y) / 2).round();
- Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
- int outline_size = get_theme_constant(SNAME("outline_size"));
- if (outline_size > 0 && font_outline_color.a > 0) {
- tl.draw_outline(get_canvas_item(), text_pos, outline_size, font_outline_color);
+ if (percent_visible) {
+ String txt = TS->format_number(itos(int(get_as_ratio() * 100))) + TS->percent_sign();
+ TextLine tl = TextLine(txt, font, font_size);
+ Vector2 text_pos = (Point2(get_size().width - tl.get_size().x, get_size().height - tl.get_size().y) / 2).round();
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
+ if (outline_size > 0 && font_outline_color.a > 0) {
+ tl.draw_outline(get_canvas_item(), text_pos, outline_size, font_outline_color);
+ }
+ tl.draw(get_canvas_item(), text_pos, font_color);
}
- tl.draw(get_canvas_item(), text_pos, font_color);
- }
+ } break;
}
}
diff --git a/scene/gui/reference_rect.cpp b/scene/gui/reference_rect.cpp
index e2a0d568a1..ed79da5c22 100644
--- a/scene/gui/reference_rect.cpp
+++ b/scene/gui/reference_rect.cpp
@@ -33,13 +33,15 @@
#include "core/config/engine.h"
void ReferenceRect::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- if (!is_inside_tree()) {
- return;
- }
- if (Engine::get_singleton()->is_editor_hint() || !editor_only) {
- draw_rect(Rect2(Point2(), get_size()), border_color, false, border_width);
- }
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ if (!is_inside_tree()) {
+ return;
+ }
+ if (Engine::get_singleton()->is_editor_hint() || !editor_only) {
+ draw_rect(Rect2(Point2(), get_size()), border_color, false, border_width);
+ }
+ } break;
}
}
diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp
index 4865b9770e..dd07831b83 100644
--- a/scene/gui/rich_text_label.cpp
+++ b/scene/gui/rich_text_label.cpp
@@ -33,6 +33,7 @@
#include "core/math/math_defs.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
+#include "label.h"
#include "scene/scene_string_names.h"
#include "servers/display_server.h"
@@ -513,7 +514,7 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font>
} break;
case ITEM_IMAGE: {
ItemImage *img = (ItemImage *)it;
- l.text_buf->add_object((uint64_t)it, img->image->get_size(), img->inline_align, 1);
+ l.text_buf->add_object((uint64_t)it, img->size, img->inline_align, 1);
text += String::chr(0xfffc);
l.char_count++;
remaining_characters--;
@@ -1501,15 +1502,17 @@ void RichTextLabel::_notification(int p_what) {
update();
}
} break;
+
case NOTIFICATION_RESIZED: {
main->first_resized_line = 0; //invalidate ALL
update();
-
} break;
+
case NOTIFICATION_THEME_CHANGED: {
main->first_invalid_font_line = 0; //invalidate ALL
update();
} break;
+
case NOTIFICATION_ENTER_TREE: {
if (!text.is_empty()) {
set_text(text);
@@ -1518,11 +1521,13 @@ void RichTextLabel::_notification(int p_what) {
main->first_invalid_line = 0; //invalidate ALL
update();
} break;
+
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);
_update_scroll();
@@ -1577,6 +1582,7 @@ void RichTextLabel::_notification(int p_what) {
from_line++;
}
} break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
if (is_visible_in_tree()) {
double dt = get_process_delta_time();
@@ -1584,12 +1590,17 @@ void RichTextLabel::_notification(int p_what) {
update();
}
} break;
+
case NOTIFICATION_FOCUS_EXIT: {
if (deselect_on_focus_loss_enabled) {
selection.active = false;
update();
}
} break;
+
+ case NOTIFICATION_DRAG_END: {
+ selection.drag_attempt = false;
+ } break;
}
}
@@ -1650,6 +1661,8 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
int c_index = 0;
bool outside;
+ selection.drag_attempt = false;
+
_find_click(main, b->get_position(), &c_frame, &c_line, &c_item, &c_index, &outside);
if (c_item != nullptr) {
if (selection.enabled) {
@@ -1660,17 +1673,22 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
// Erase previous selection.
if (selection.active) {
- 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();
+ if (_is_click_inside_selection()) {
+ selection.drag_attempt = true;
+ selection.click_item = nullptr;
+ } else {
+ 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();
+ }
}
}
}
@@ -1683,6 +1701,8 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
int c_index = 0;
bool outside;
+ selection.drag_attempt = false;
+
_find_click(main, b->get_position(), &c_frame, &c_line, &c_item, &c_index, &outside);
if (c_frame) {
@@ -1714,6 +1734,22 @@ void RichTextLabel::gui_input(const Ref<InputEvent> &p_event) {
DisplayServer::get_singleton()->clipboard_set_primary(get_selected_text());
}
selection.click_item = nullptr;
+ if (selection.drag_attempt) {
+ selection.drag_attempt = false;
+ if (_is_click_inside_selection()) {
+ 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();
+ }
+ }
if (!b->is_double_click() && !scroll_updated) {
Item *c_item = nullptr;
@@ -3689,7 +3725,7 @@ void RichTextLabel::scroll_to_line(int p_line) {
if ((line_count <= p_line) && (line_count + main->lines[i].text_buf->get_line_count() >= p_line)) {
float line_offset = 0.f;
for (int j = 0; j < p_line - line_count; j++) {
- line_offset += main->lines[i].text_buf->get_line_size(j).y;
+ line_offset += main->lines[i].text_buf->get_line_size(j).y + get_theme_constant(SNAME("line_separation"));
}
vscroll->set_value(main->lines[i].offset.y + line_offset);
return;
@@ -3698,6 +3734,28 @@ void RichTextLabel::scroll_to_line(int p_line) {
}
}
+float RichTextLabel::get_line_offset(int p_line) {
+ int line_count = 0;
+ for (int i = 0; i < main->lines.size(); i++) {
+ if ((line_count <= p_line) && (p_line <= line_count + main->lines[i].text_buf->get_line_count())) {
+ float line_offset = 0.f;
+ for (int j = 0; j < p_line - line_count; j++) {
+ line_offset += main->lines[i].text_buf->get_line_size(j).y + get_theme_constant(SNAME("line_separation"));
+ }
+ return main->lines[i].offset.y + line_offset;
+ }
+ line_count += main->lines[i].text_buf->get_line_count();
+ }
+ return 0;
+}
+
+float RichTextLabel::get_paragraph_offset(int p_paragraph) {
+ if (0 <= p_paragraph && p_paragraph < main->lines.size()) {
+ return main->lines[p_paragraph].offset.y;
+ }
+ return 0;
+}
+
int RichTextLabel::get_line_count() const {
int line_count = 0;
for (int i = 0; i < main->lines.size(); i++) {
@@ -3734,6 +3792,29 @@ void RichTextLabel::set_deselect_on_focus_loss_enabled(const bool p_enabled) {
}
}
+Variant RichTextLabel::get_drag_data(const Point2 &p_point) {
+ if (selection.drag_attempt && selection.enabled) {
+ String t = get_selected_text();
+ Label *l = memnew(Label);
+ l->set_text(t);
+ set_drag_preview(l);
+ return t;
+ }
+
+ return Variant();
+}
+
+bool RichTextLabel::_is_click_inside_selection() const {
+ if (selection.active && selection.enabled && selection.click_frame && selection.from_frame && selection.to_frame) {
+ const Line &l_click = selection.click_frame->lines[selection.click_line];
+ const Line &l_from = selection.from_frame->lines[selection.from_line];
+ const Line &l_to = selection.to_frame->lines[selection.to_line];
+ return (l_click.char_offset + selection.click_char >= l_from.char_offset + selection.from_char) && (l_click.char_offset + selection.click_char <= l_to.char_offset + selection.to_char);
+ } else {
+ return false;
+ }
+}
+
bool RichTextLabel::_search_table(ItemTable *p_table, List<Item *>::Element *p_from, const String &p_string, bool p_reverse_search) {
List<Item *>::Element *E = p_from;
while (E != nullptr) {
@@ -3992,7 +4073,7 @@ int RichTextLabel::get_selection_to() const {
void RichTextLabel::set_text(const String &p_bbcode) {
text = p_bbcode;
- if (is_inside_tree() && use_bbcode) {
+ if (use_bbcode) {
parse_bbcode(p_bbcode);
} else { // raw text
clear();
@@ -4157,6 +4238,14 @@ int RichTextLabel::get_content_height() const {
return total_height;
}
+int RichTextLabel::get_content_width() const {
+ int total_width = 0;
+ for (int i = 0; i < main->lines.size(); i++) {
+ total_width = MAX(total_width, main->lines[i].offset.x + main->lines[i].text_buf->get_size().x);
+ }
+ return total_width;
+}
+
#ifndef DISABLE_DEPRECATED
// People will be very angry, if their texts get erased, because of #39148. (3.x -> 4.0)
// Although some people may not used bbcode_text, so we only overwrite, if bbcode_text is not empty.
@@ -4267,6 +4356,8 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_percent_visible", "percent_visible"), &RichTextLabel::set_percent_visible);
ClassDB::bind_method(D_METHOD("get_percent_visible"), &RichTextLabel::get_percent_visible);
+ ClassDB::bind_method(D_METHOD("get_character_line", "character"), &RichTextLabel::get_character_line);
+ ClassDB::bind_method(D_METHOD("get_character_paragraph", "character"), &RichTextLabel::get_character_paragraph);
ClassDB::bind_method(D_METHOD("get_total_character_count"), &RichTextLabel::get_total_character_count);
ClassDB::bind_method(D_METHOD("set_use_bbcode", "enable"), &RichTextLabel::set_use_bbcode);
@@ -4279,6 +4370,10 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_visible_paragraph_count"), &RichTextLabel::get_visible_paragraph_count);
ClassDB::bind_method(D_METHOD("get_content_height"), &RichTextLabel::get_content_height);
+ ClassDB::bind_method(D_METHOD("get_content_width"), &RichTextLabel::get_content_width);
+
+ ClassDB::bind_method(D_METHOD("get_line_offset", "line"), &RichTextLabel::get_line_offset);
+ ClassDB::bind_method(D_METHOD("get_paragraph_offset", "paragraph"), &RichTextLabel::get_paragraph_offset);
ClassDB::bind_method(D_METHOD("parse_expressions_for_values", "expressions"), &RichTextLabel::parse_expressions_for_values);
@@ -4286,33 +4381,30 @@ void RichTextLabel::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_effects"), &RichTextLabel::get_effects);
ClassDB::bind_method(D_METHOD("install_effect", "effect"), &RichTextLabel::install_effect);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters");
- ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
-
- ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters_behavior", PROPERTY_HINT_ENUM, "Characters Before Shaping,Characters After Shaping,Glyphs (Layout Direction),Glyphs (Left-to-Right),Glyphs (Right-to-Left)"), "set_visible_characters_behavior", "get_visible_characters_behavior");
+ // Note: set "bbcode_enabled" first, to avoid unnecessery "text" resets.
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta_underlined"), "set_meta_underline", "is_meta_underlined");
ADD_PROPERTY(PropertyInfo(Variant::INT, "tab_size", PROPERTY_HINT_RANGE, "0,24,1"), "set_tab_size", "get_tab_size");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "text", PROPERTY_HINT_MULTILINE_TEXT), "set_text", "get_text");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "bbcode_enabled"), "set_use_bbcode", "is_using_bbcode");
-
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "fit_content_height"), "set_fit_content_height", "is_fit_content_height_enabled");
-
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_active"), "set_scroll_active", "is_scroll_active");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "scroll_following"), "set_scroll_follow", "is_scroll_following");
-
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "selection_enabled"), "set_selection_enabled", "is_selection_enabled");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "override_selected_font_color"), "set_override_selected_font_color", "is_overriding_selected_font_color");
-
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "deselect_on_focus_loss_enabled"), "set_deselect_on_focus_loss_enabled", "is_deselect_on_focus_loss_enabled");
-
ADD_PROPERTY(PropertyInfo(Variant::ARRAY, "custom_effects", PROPERTY_HINT_ARRAY_TYPE, vformat("%s/%s:%s", Variant::OBJECT, PROPERTY_HINT_RESOURCE_TYPE, "RichTextEffect"), (PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_SCRIPT_VARIABLE)), "set_effects", "get_effects");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "meta_underlined"), "set_meta_underline", "is_meta_underlined");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_mode", PROPERTY_HINT_ENUM, "Off,Arbitrary,Word,Word (Smart)"), "set_autowrap_mode", "get_autowrap_mode");
+
+ // Note: "visible_characters" and "percent_visible" should be set after "text" to be correctly applied.
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters", PROPERTY_HINT_RANGE, "-1,128000,1"), "set_visible_characters", "get_visible_characters");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "visible_characters_behavior", PROPERTY_HINT_ENUM, "Characters Before Shaping,Characters After Shaping,Glyphs (Layout Direction),Glyphs (Left-to-Right),Glyphs (Right-to-Left)"), "set_visible_characters_behavior", "get_visible_characters_behavior");
+ ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "percent_visible", PROPERTY_HINT_RANGE, "0,1,0.001"), "set_percent_visible", "get_percent_visible");
+ ADD_GROUP("Locale", "");
ADD_PROPERTY(PropertyInfo(Variant::INT, "text_direction", PROPERTY_HINT_ENUM, "Auto,Left-to-Right,Right-to-Left,Inherited"), "set_text_direction", "get_text_direction");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "language", PROPERTY_HINT_LOCALE_ID, ""), "set_language", "get_language");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "autowrap_mode", PROPERTY_HINT_ENUM, "Off,Arbitrary,Word,Word (Smart)"), "set_autowrap_mode", "get_autowrap_mode");
-
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");
@@ -4401,6 +4493,36 @@ int RichTextLabel::get_visible_characters() const {
return visible_characters;
}
+int RichTextLabel::get_character_line(int p_char) {
+ int line_count = 0;
+ for (int i = 0; i < main->lines.size(); i++) {
+ if (main->lines[i].char_offset < p_char && p_char <= main->lines[i].char_offset + main->lines[i].char_count) {
+ for (int j = 0; j < main->lines[i].text_buf->get_line_count(); j++) {
+ Vector2i range = main->lines[i].text_buf->get_line_range(j);
+ if (main->lines[i].char_offset + range.x < p_char && p_char <= main->lines[i].char_offset + range.y) {
+ return line_count;
+ }
+ line_count++;
+ }
+ } else {
+ line_count += main->lines[i].text_buf->get_line_count();
+ }
+ }
+ return -1;
+}
+
+int RichTextLabel::get_character_paragraph(int p_char) {
+ int para_count = 0;
+ for (int i = 0; i < main->lines.size(); i++) {
+ if (main->lines[i].char_offset < p_char && p_char <= main->lines[i].char_offset + main->lines[i].char_count) {
+ return para_count;
+ } else {
+ para_count++;
+ }
+ }
+ return -1;
+}
+
int RichTextLabel::get_total_character_count() const {
// Note: Do not use line buffer "char_count", it includes only visible characters.
int tc = 0;
diff --git a/scene/gui/rich_text_label.h b/scene/gui/rich_text_label.h
index e79244f2e4..53c2046c8f 100644
--- a/scene/gui/rich_text_label.h
+++ b/scene/gui/rich_text_label.h
@@ -407,6 +407,7 @@ private:
bool active = false; // anything selected? i.e. from, to, etc. valid?
bool enabled = false; // allow selections?
+ bool drag_attempt = false;
};
Selection selection;
@@ -416,6 +417,7 @@ private:
float percent_visible = 1.0;
VisibleCharactersBehavior visible_chars_behavior = VC_CHARS_BEFORE_SHAPING;
+ bool _is_click_inside_selection() const;
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) const;
@@ -549,15 +551,20 @@ public:
int get_paragraph_count() const;
int get_visible_paragraph_count() const;
+ float get_line_offset(int p_line);
+ float get_paragraph_offset(int p_paragraph);
+
void scroll_to_line(int p_line);
int get_line_count() const;
int get_visible_line_count() const;
int get_content_height() const;
+ int get_content_width() const;
VScrollBar *get_v_scroll_bar() { return vscroll; }
virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override;
+ virtual Variant get_drag_data(const Point2 &p_point) override;
void set_selection_enabled(bool p_enabled);
bool is_selection_enabled() const;
@@ -594,6 +601,8 @@ public:
void set_visible_characters(int p_visible);
int get_visible_characters() const;
+ int get_character_line(int p_char);
+ int get_character_paragraph(int p_char);
int get_total_character_count() const;
int get_total_glyph_count() const;
diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp
index 343056957c..e1b0e8cca8 100644
--- a/scene/gui/scroll_bar.cpp
+++ b/scene/gui/scroll_bar.cpp
@@ -218,195 +218,198 @@ void ScrollBar::gui_input(const Ref<InputEvent> &p_event) {
}
void ScrollBar::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- RID ci = get_canvas_item();
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ RID ci = get_canvas_item();
- Ref<Texture2D> decr, incr;
+ Ref<Texture2D> decr, incr;
- if (decr_active) {
- decr = get_theme_icon(SNAME("decrement_pressed"));
- } else if (highlight == HIGHLIGHT_DECR) {
- decr = get_theme_icon(SNAME("decrement_highlight"));
- } else {
- decr = get_theme_icon(SNAME("decrement"));
- }
+ if (decr_active) {
+ decr = get_theme_icon(SNAME("decrement_pressed"));
+ } else if (highlight == HIGHLIGHT_DECR) {
+ decr = get_theme_icon(SNAME("decrement_highlight"));
+ } else {
+ decr = get_theme_icon(SNAME("decrement"));
+ }
- if (incr_active) {
- incr = get_theme_icon(SNAME("increment_pressed"));
- } else if (highlight == HIGHLIGHT_INCR) {
- incr = get_theme_icon(SNAME("increment_highlight"));
- } else {
- incr = get_theme_icon(SNAME("increment"));
- }
+ if (incr_active) {
+ incr = get_theme_icon(SNAME("increment_pressed"));
+ } else if (highlight == HIGHLIGHT_INCR) {
+ incr = get_theme_icon(SNAME("increment_highlight"));
+ } else {
+ incr = get_theme_icon(SNAME("increment"));
+ }
- Ref<StyleBox> bg = has_focus() ? get_theme_stylebox(SNAME("scroll_focus")) : get_theme_stylebox(SNAME("scroll"));
+ Ref<StyleBox> bg = has_focus() ? get_theme_stylebox(SNAME("scroll_focus")) : get_theme_stylebox(SNAME("scroll"));
- Ref<StyleBox> grabber;
- if (drag.active) {
- grabber = get_theme_stylebox(SNAME("grabber_pressed"));
- } else if (highlight == HIGHLIGHT_RANGE) {
- grabber = get_theme_stylebox(SNAME("grabber_highlight"));
- } else {
- grabber = get_theme_stylebox(SNAME("grabber"));
- }
+ Ref<StyleBox> grabber;
+ if (drag.active) {
+ grabber = get_theme_stylebox(SNAME("grabber_pressed"));
+ } else if (highlight == HIGHLIGHT_RANGE) {
+ grabber = get_theme_stylebox(SNAME("grabber_highlight"));
+ } else {
+ grabber = get_theme_stylebox(SNAME("grabber"));
+ }
- Point2 ofs;
+ Point2 ofs;
- decr->draw(ci, Point2());
+ decr->draw(ci, Point2());
- if (orientation == HORIZONTAL) {
- ofs.x += decr->get_width();
- } else {
- ofs.y += decr->get_height();
- }
+ if (orientation == HORIZONTAL) {
+ ofs.x += decr->get_width();
+ } else {
+ ofs.y += decr->get_height();
+ }
- Size2 area = get_size();
+ Size2 area = get_size();
- if (orientation == HORIZONTAL) {
- area.width -= incr->get_width() + decr->get_width();
- } else {
- area.height -= incr->get_height() + decr->get_height();
- }
+ if (orientation == HORIZONTAL) {
+ area.width -= incr->get_width() + decr->get_width();
+ } else {
+ area.height -= incr->get_height() + decr->get_height();
+ }
- bg->draw(ci, Rect2(ofs, area));
+ bg->draw(ci, Rect2(ofs, area));
- if (orientation == HORIZONTAL) {
- ofs.width += area.width;
- } else {
- ofs.height += area.height;
- }
+ if (orientation == HORIZONTAL) {
+ ofs.width += area.width;
+ } else {
+ ofs.height += area.height;
+ }
- incr->draw(ci, ofs);
- Rect2 grabber_rect;
+ incr->draw(ci, ofs);
+ Rect2 grabber_rect;
- if (orientation == HORIZONTAL) {
- grabber_rect.size.width = get_grabber_size();
- grabber_rect.size.height = get_size().height;
- grabber_rect.position.y = 0;
- grabber_rect.position.x = get_grabber_offset() + decr->get_width() + bg->get_margin(SIDE_LEFT);
- } else {
- grabber_rect.size.width = get_size().width;
- grabber_rect.size.height = get_grabber_size();
- grabber_rect.position.y = get_grabber_offset() + decr->get_height() + bg->get_margin(SIDE_TOP);
- grabber_rect.position.x = 0;
- }
+ if (orientation == HORIZONTAL) {
+ grabber_rect.size.width = get_grabber_size();
+ grabber_rect.size.height = get_size().height;
+ grabber_rect.position.y = 0;
+ grabber_rect.position.x = get_grabber_offset() + decr->get_width() + bg->get_margin(SIDE_LEFT);
+ } else {
+ grabber_rect.size.width = get_size().width;
+ grabber_rect.size.height = get_grabber_size();
+ grabber_rect.position.y = get_grabber_offset() + decr->get_height() + bg->get_margin(SIDE_TOP);
+ grabber_rect.position.x = 0;
+ }
- grabber->draw(ci, grabber_rect);
- }
+ grabber->draw(ci, grabber_rect);
+ } break;
- if (p_what == NOTIFICATION_ENTER_TREE) {
- if (has_node(drag_node_path)) {
- Node *n = get_node(drag_node_path);
- drag_node = Object::cast_to<Control>(n);
- }
+ case NOTIFICATION_ENTER_TREE: {
+ if (has_node(drag_node_path)) {
+ Node *n = get_node(drag_node_path);
+ drag_node = Object::cast_to<Control>(n);
+ }
- if (drag_node) {
- drag_node->connect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
- drag_node->connect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit), varray(), CONNECT_ONESHOT);
- }
- }
- if (p_what == NOTIFICATION_EXIT_TREE) {
- if (drag_node) {
- drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
- drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit));
- }
+ if (drag_node) {
+ drag_node->connect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
+ drag_node->connect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit), varray(), CONNECT_ONESHOT);
+ }
+ } break;
- drag_node = nullptr;
- }
+ case NOTIFICATION_EXIT_TREE: {
+ if (drag_node) {
+ drag_node->disconnect("gui_input", callable_mp(this, &ScrollBar::_drag_node_input));
+ drag_node->disconnect("tree_exiting", callable_mp(this, &ScrollBar::_drag_node_exit));
+ }
- if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
- if (scrolling) {
- if (get_value() != target_scroll) {
- double target = target_scroll - get_value();
- double dist = sqrt(target * target);
- double vel = ((target / dist) * 500) * get_physics_process_delta_time();
+ drag_node = nullptr;
+ } break;
- if (Math::abs(vel) >= dist) {
- set_value(target_scroll);
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ if (scrolling) {
+ if (get_value() != target_scroll) {
+ double target = target_scroll - get_value();
+ double dist = sqrt(target * target);
+ double vel = ((target / dist) * 500) * get_physics_process_delta_time();
+
+ if (Math::abs(vel) >= dist) {
+ set_value(target_scroll);
+ scrolling = false;
+ set_physics_process_internal(false);
+ } else {
+ set_value(get_value() + vel);
+ }
+ } else {
scrolling = false;
set_physics_process_internal(false);
- } else {
- set_value(get_value() + vel);
}
- } else {
- scrolling = false;
- set_physics_process_internal(false);
- }
- } else if (drag_node_touching) {
- if (drag_node_touching_deaccel) {
- Vector2 pos = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
- pos += drag_node_speed * get_physics_process_delta_time();
+ } else if (drag_node_touching) {
+ if (drag_node_touching_deaccel) {
+ Vector2 pos = Vector2(orientation == HORIZONTAL ? get_value() : 0, orientation == VERTICAL ? get_value() : 0);
+ pos += drag_node_speed * get_physics_process_delta_time();
- bool turnoff = false;
+ bool turnoff = false;
- if (orientation == HORIZONTAL) {
- if (pos.x < 0) {
- pos.x = 0;
- turnoff = true;
- }
+ if (orientation == HORIZONTAL) {
+ if (pos.x < 0) {
+ pos.x = 0;
+ turnoff = true;
+ }
- if (pos.x > (get_max() - get_page())) {
- pos.x = get_max() - get_page();
- turnoff = true;
- }
+ if (pos.x > (get_max() - get_page())) {
+ pos.x = get_max() - get_page();
+ turnoff = true;
+ }
- set_value(pos.x);
+ set_value(pos.x);
- float sgn_x = drag_node_speed.x < 0 ? -1 : 1;
- float val_x = Math::abs(drag_node_speed.x);
- val_x -= 1000 * get_physics_process_delta_time();
+ float sgn_x = drag_node_speed.x < 0 ? -1 : 1;
+ float val_x = Math::abs(drag_node_speed.x);
+ val_x -= 1000 * get_physics_process_delta_time();
- if (val_x < 0) {
- turnoff = true;
- }
+ if (val_x < 0) {
+ turnoff = true;
+ }
- drag_node_speed.x = sgn_x * val_x;
+ drag_node_speed.x = sgn_x * val_x;
- } else {
- if (pos.y < 0) {
- pos.y = 0;
- turnoff = true;
- }
+ } else {
+ if (pos.y < 0) {
+ pos.y = 0;
+ turnoff = true;
+ }
- if (pos.y > (get_max() - get_page())) {
- pos.y = get_max() - get_page();
- turnoff = true;
- }
+ if (pos.y > (get_max() - get_page())) {
+ pos.y = get_max() - get_page();
+ turnoff = true;
+ }
- set_value(pos.y);
+ set_value(pos.y);
- float sgn_y = drag_node_speed.y < 0 ? -1 : 1;
- float val_y = Math::abs(drag_node_speed.y);
- val_y -= 1000 * get_physics_process_delta_time();
+ float sgn_y = drag_node_speed.y < 0 ? -1 : 1;
+ float val_y = Math::abs(drag_node_speed.y);
+ val_y -= 1000 * get_physics_process_delta_time();
- if (val_y < 0) {
- turnoff = true;
+ if (val_y < 0) {
+ turnoff = true;
+ }
+ drag_node_speed.y = sgn_y * val_y;
}
- drag_node_speed.y = sgn_y * val_y;
- }
- if (turnoff) {
- set_physics_process_internal(false);
- drag_node_touching = false;
- drag_node_touching_deaccel = false;
- }
+ if (turnoff) {
+ set_physics_process_internal(false);
+ drag_node_touching = false;
+ drag_node_touching_deaccel = false;
+ }
- } else {
- if (time_since_motion == 0 || time_since_motion > 0.1) {
- Vector2 diff = drag_node_accum - last_drag_node_accum;
- last_drag_node_accum = drag_node_accum;
- drag_node_speed = diff / get_physics_process_delta_time();
- }
+ } else {
+ if (time_since_motion == 0 || time_since_motion > 0.1) {
+ Vector2 diff = drag_node_accum - last_drag_node_accum;
+ last_drag_node_accum = drag_node_accum;
+ drag_node_speed = diff / get_physics_process_delta_time();
+ }
- time_since_motion += get_physics_process_delta_time();
+ time_since_motion += get_physics_process_delta_time();
+ }
}
- }
- }
+ } break;
- if (p_what == NOTIFICATION_MOUSE_EXIT) {
- highlight = HIGHLIGHT_NONE;
- update();
+ case NOTIFICATION_MOUSE_EXIT: {
+ highlight = HIGHLIGHT_NONE;
+ update();
+ } break;
}
}
@@ -423,11 +426,6 @@ double ScrollBar::get_grabber_size() const {
}
float page = (get_page() > 0) ? get_page() : 0;
- /*
- if (grabber_range < get_step())
- grabber_range=get_step();
- */
-
double area_size = get_area_size();
double grabber_size = page / range * area_size;
return grabber_size + get_grabber_min_size();
diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp
index 5e128d594c..b3cf2cbf7e 100644
--- a/scene/gui/scroll_container.cpp
+++ b/scene/gui/scroll_container.cpp
@@ -29,6 +29,8 @@
/*************************************************************************/
#include "scroll_container.h"
+
+#include "core/config/project_settings.h"
#include "core/os/os.h"
#include "scene/main/window.h"
@@ -314,97 +316,102 @@ void ScrollContainer::_update_dimensions() {
}
void ScrollContainer::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- _updating_scrollbars = true;
- call_deferred(SNAME("_update_scrollbar_position"));
- };
-
- if (p_what == NOTIFICATION_READY) {
- Viewport *viewport = get_viewport();
- ERR_FAIL_COND(!viewport);
- viewport->connect("gui_focus_changed", callable_mp(this, &ScrollContainer::_gui_focus_changed));
- _update_dimensions();
- }
-
- if (p_what == NOTIFICATION_SORT_CHILDREN) {
- _update_dimensions();
- };
-
- if (p_what == NOTIFICATION_DRAW) {
- Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg"));
- draw_style_box(sb, Rect2(Vector2(), get_size()));
-
- update_scrollbars();
- }
-
- if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
- if (drag_touching) {
- if (drag_touching_deaccel) {
- Vector2 pos = Vector2(h_scroll->get_value(), v_scroll->get_value());
- pos += drag_speed * get_physics_process_delta_time();
-
- bool turnoff_h = false;
- bool turnoff_v = false;
-
- if (pos.x < 0) {
- pos.x = 0;
- turnoff_h = true;
- }
- if (pos.x > (h_scroll->get_max() - h_scroll->get_page())) {
- pos.x = h_scroll->get_max() - h_scroll->get_page();
- turnoff_h = true;
- }
-
- if (pos.y < 0) {
- pos.y = 0;
- turnoff_v = true;
- }
- if (pos.y > (v_scroll->get_max() - v_scroll->get_page())) {
- pos.y = v_scroll->get_max() - v_scroll->get_page();
- turnoff_v = true;
- }
-
- if (horizontal_scroll_mode != SCROLL_MODE_DISABLED) {
- h_scroll->set_value(pos.x);
- }
- if (vertical_scroll_mode != SCROLL_MODE_DISABLED) {
- v_scroll->set_value(pos.y);
- }
-
- float sgn_x = drag_speed.x < 0 ? -1 : 1;
- float val_x = Math::abs(drag_speed.x);
- val_x -= 1000 * get_physics_process_delta_time();
-
- if (val_x < 0) {
- turnoff_h = true;
- }
-
- float sgn_y = drag_speed.y < 0 ? -1 : 1;
- float val_y = Math::abs(drag_speed.y);
- val_y -= 1000 * get_physics_process_delta_time();
-
- if (val_y < 0) {
- turnoff_v = true;
- }
-
- drag_speed = Vector2(sgn_x * val_x, sgn_y * val_y);
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_THEME_CHANGED:
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ _updating_scrollbars = true;
+ call_deferred(SNAME("_update_scrollbar_position"));
+ } break;
+
+ case NOTIFICATION_READY: {
+ Viewport *viewport = get_viewport();
+ ERR_FAIL_COND(!viewport);
+ viewport->connect("gui_focus_changed", callable_mp(this, &ScrollContainer::_gui_focus_changed));
+ _update_dimensions();
+ } break;
+
+ case NOTIFICATION_SORT_CHILDREN: {
+ _update_dimensions();
+ } break;
+
+ case NOTIFICATION_DRAW: {
+ Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg"));
+ draw_style_box(sb, Rect2(Vector2(), get_size()));
+
+ update_scrollbars();
+ } break;
+
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ if (drag_touching) {
+ if (drag_touching_deaccel) {
+ Vector2 pos = Vector2(h_scroll->get_value(), v_scroll->get_value());
+ pos += drag_speed * get_physics_process_delta_time();
+
+ bool turnoff_h = false;
+ bool turnoff_v = false;
+
+ if (pos.x < 0) {
+ pos.x = 0;
+ turnoff_h = true;
+ }
+ if (pos.x > (h_scroll->get_max() - h_scroll->get_page())) {
+ pos.x = h_scroll->get_max() - h_scroll->get_page();
+ turnoff_h = true;
+ }
+
+ if (pos.y < 0) {
+ pos.y = 0;
+ turnoff_v = true;
+ }
+ if (pos.y > (v_scroll->get_max() - v_scroll->get_page())) {
+ pos.y = v_scroll->get_max() - v_scroll->get_page();
+ turnoff_v = true;
+ }
+
+ if (horizontal_scroll_mode != SCROLL_MODE_DISABLED) {
+ h_scroll->set_value(pos.x);
+ }
+ if (vertical_scroll_mode != SCROLL_MODE_DISABLED) {
+ v_scroll->set_value(pos.y);
+ }
+
+ float sgn_x = drag_speed.x < 0 ? -1 : 1;
+ float val_x = Math::abs(drag_speed.x);
+ val_x -= 1000 * get_physics_process_delta_time();
+
+ if (val_x < 0) {
+ turnoff_h = true;
+ }
+
+ float sgn_y = drag_speed.y < 0 ? -1 : 1;
+ float val_y = Math::abs(drag_speed.y);
+ val_y -= 1000 * get_physics_process_delta_time();
+
+ if (val_y < 0) {
+ turnoff_v = true;
+ }
+
+ drag_speed = Vector2(sgn_x * val_x, sgn_y * val_y);
+
+ if (turnoff_h && turnoff_v) {
+ _cancel_drag();
+ }
- if (turnoff_h && turnoff_v) {
- _cancel_drag();
- }
+ } else {
+ if (time_since_motion == 0 || time_since_motion > 0.1) {
+ Vector2 diff = drag_accum - last_drag_accum;
+ last_drag_accum = drag_accum;
+ drag_speed = diff / get_physics_process_delta_time();
+ }
- } else {
- if (time_since_motion == 0 || time_since_motion > 0.1) {
- Vector2 diff = drag_accum - last_drag_accum;
- last_drag_accum = drag_accum;
- drag_speed = diff / get_physics_process_delta_time();
+ time_since_motion += get_physics_process_delta_time();
}
-
- time_since_motion += get_physics_process_delta_time();
}
- }
+ } break;
}
-};
+}
void ScrollContainer::update_scrollbars() {
Size2 size = get_size();
diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp
index 9c19eb54dc..e3400d9c8f 100644
--- a/scene/gui/separator.cpp
+++ b/scene/gui/separator.cpp
@@ -52,7 +52,6 @@ void Separator::_notification(int p_what) {
} else {
style->draw(get_canvas_item(), Rect2(0, (size.y - ssize.y) / 2, size.x, ssize.y));
}
-
} break;
}
}
diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp
index 1d459d589f..4b680f72cf 100644
--- a/scene/gui/slider.cpp
+++ b/scene/gui/slider.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "slider.h"
+
#include "core/os/keyboard.h"
Size2 Slider::get_minimum_size() const {
@@ -150,19 +151,23 @@ void Slider::_notification(int p_what) {
update_minimum_size();
update();
} break;
+
case NOTIFICATION_MOUSE_ENTER: {
mouse_inside = true;
update();
} break;
+
case NOTIFICATION_MOUSE_EXIT: {
mouse_inside = false;
update();
} break;
- case NOTIFICATION_VISIBILITY_CHANGED: // fallthrough
+
+ case NOTIFICATION_VISIBILITY_CHANGED:
case NOTIFICATION_EXIT_TREE: {
mouse_inside = false;
grab.active = false;
} break;
+
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Size2i size = get_size();
@@ -209,7 +214,6 @@ void Slider::_notification(int p_what) {
}
grabber->draw(ci, Point2i(ratio * areasize, size.height / 2 - grabber->get_size().height / 2));
}
-
} break;
}
}
diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp
index 19d47ea492..5fd31c5416 100644
--- a/scene/gui/spin_box.cpp
+++ b/scene/gui/spin_box.cpp
@@ -196,34 +196,44 @@ inline void SpinBox::_adjust_width_for_icon(const Ref<Texture2D> &icon) {
}
void SpinBox::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- Ref<Texture2D> updown = get_theme_icon(SNAME("updown"));
-
- _adjust_width_for_icon(updown);
-
- RID ci = get_canvas_item();
- Size2i size = get_size();
-
- if (is_layout_rtl()) {
- updown->draw(ci, Point2i(0, (size.height - updown->get_height()) / 2));
- } else {
- updown->draw(ci, Point2i(size.width - updown->get_width(), (size.height - updown->get_height()) / 2));
- }
-
- } else if (p_what == NOTIFICATION_FOCUS_EXIT) {
- //_value_changed(0);
- } else if (p_what == NOTIFICATION_ENTER_TREE) {
- _adjust_width_for_icon(get_theme_icon(SNAME("updown")));
- _value_changed(0);
- } else if (p_what == NOTIFICATION_EXIT_TREE) {
- _release_mouse();
- } else if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- _value_changed(0);
- } else if (p_what == NOTIFICATION_THEME_CHANGED) {
- call_deferred(SNAME("update_minimum_size"));
- get_line_edit()->call_deferred(SNAME("update_minimum_size"));
- } else if (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- update();
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ Ref<Texture2D> updown = get_theme_icon(SNAME("updown"));
+
+ _adjust_width_for_icon(updown);
+
+ RID ci = get_canvas_item();
+ Size2i size = get_size();
+
+ if (is_layout_rtl()) {
+ updown->draw(ci, Point2i(0, (size.height - updown->get_height()) / 2));
+ } else {
+ updown->draw(ci, Point2i(size.width - updown->get_width(), (size.height - updown->get_height()) / 2));
+ }
+ } break;
+
+ case NOTIFICATION_ENTER_TREE: {
+ _adjust_width_for_icon(get_theme_icon(SNAME("updown")));
+ _value_changed(0);
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
+ _release_mouse();
+ } break;
+
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ _value_changed(0);
+ update();
+ } break;
+
+ case NOTIFICATION_THEME_CHANGED: {
+ call_deferred(SNAME("update_minimum_size"));
+ get_line_edit()->call_deferred(SNAME("update_minimum_size"));
+ } break;
+
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
+ update();
+ } break;
}
}
diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp
index 874e5868b6..6845d46721 100644
--- a/scene/gui/split_container.cpp
+++ b/scene/gui/split_container.cpp
@@ -168,15 +168,18 @@ void SplitContainer::_notification(int p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
queue_sort();
} break;
+
case NOTIFICATION_SORT_CHILDREN: {
_resort();
} break;
+
case NOTIFICATION_MOUSE_EXIT: {
mouse_inside = false;
if (get_theme_constant(SNAME("autohide"))) {
update();
}
} break;
+
case NOTIFICATION_DRAW: {
if (!_getch(0) || !_getch(1)) {
return;
@@ -200,6 +203,7 @@ void SplitContainer::_notification(int p_what) {
draw_texture(tex, Point2i(middle_sep + (sep - tex->get_width()) / 2, (size.y - tex->get_height()) / 2));
}
} break;
+
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
@@ -336,6 +340,30 @@ bool SplitContainer::is_collapsed() const {
return collapsed;
}
+Vector<int> SplitContainer::get_allowed_size_flags_horizontal() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ if (!vertical) {
+ flags.append(SIZE_EXPAND);
+ }
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
+Vector<int> SplitContainer::get_allowed_size_flags_vertical() const {
+ Vector<int> flags;
+ flags.append(SIZE_FILL);
+ if (vertical) {
+ flags.append(SIZE_EXPAND);
+ }
+ flags.append(SIZE_SHRINK_BEGIN);
+ flags.append(SIZE_SHRINK_CENTER);
+ flags.append(SIZE_SHRINK_END);
+ return flags;
+}
+
void SplitContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_split_offset", "offset"), &SplitContainer::set_split_offset);
ClassDB::bind_method(D_METHOD("get_split_offset"), &SplitContainer::get_split_offset);
diff --git a/scene/gui/split_container.h b/scene/gui/split_container.h
index ba6fff6f55..a69ffe4de9 100644
--- a/scene/gui/split_container.h
+++ b/scene/gui/split_container.h
@@ -79,6 +79,9 @@ public:
virtual Size2 get_minimum_size() const override;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
SplitContainer(bool p_vertical = false);
};
diff --git a/scene/gui/subviewport_container.cpp b/scene/gui/subviewport_container.cpp
index 760144591e..c66e145bc4 100644
--- a/scene/gui/subviewport_container.cpp
+++ b/scene/gui/subviewport_container.cpp
@@ -91,52 +91,81 @@ int SubViewportContainer::get_stretch_shrink() const {
return shrink;
}
-void SubViewportContainer::_notification(int p_what) {
- if (p_what == NOTIFICATION_RESIZED) {
- if (!stretch) {
- return;
- }
+Vector<int> SubViewportContainer::get_allowed_size_flags_horizontal() const {
+ return Vector<int>();
+}
+
+Vector<int> SubViewportContainer::get_allowed_size_flags_vertical() const {
+ return Vector<int>();
+}
- for (int i = 0; i < get_child_count(); i++) {
- SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c) {
- continue;
+void SubViewportContainer::_notification(int p_what) {
+ switch (p_what) {
+ case NOTIFICATION_RESIZED: {
+ if (!stretch) {
+ return;
}
- c->set_size(get_size() / shrink);
- }
- }
+ for (int i = 0; i < get_child_count(); i++) {
+ SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
+ if (!c) {
+ continue;
+ }
- if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- for (int i = 0; i < get_child_count(); i++) {
- SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c) {
- continue;
+ c->set_size(get_size() / shrink);
}
-
- if (is_visible_in_tree()) {
- c->set_update_mode(SubViewport::UPDATE_ALWAYS);
- } else {
- c->set_update_mode(SubViewport::UPDATE_DISABLED);
+ } break;
+
+ case NOTIFICATION_ENTER_TREE:
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ for (int i = 0; i < get_child_count(); i++) {
+ SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
+ if (!c) {
+ continue;
+ }
+
+ if (is_visible_in_tree()) {
+ c->set_update_mode(SubViewport::UPDATE_ALWAYS);
+ } else {
+ c->set_update_mode(SubViewport::UPDATE_DISABLED);
+ }
+
+ c->set_handle_input_locally(false); //do not handle input locally here
+ }
+ } break;
+
+ case NOTIFICATION_DRAW: {
+ for (int i = 0; i < get_child_count(); i++) {
+ SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
+ if (!c) {
+ continue;
+ }
+
+ if (stretch) {
+ draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size()));
+ } else {
+ draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size()));
+ }
}
+ } break;
- c->set_handle_input_locally(false); //do not handle input locally here
- }
- }
+ case NOTIFICATION_MOUSE_ENTER: {
+ _notify_viewports(NOTIFICATION_VP_MOUSE_ENTER);
+ } break;
- if (p_what == NOTIFICATION_DRAW) {
- for (int i = 0; i < get_child_count(); i++) {
- SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
- if (!c) {
- continue;
- }
+ case NOTIFICATION_MOUSE_EXIT: {
+ _notify_viewports(NOTIFICATION_VP_MOUSE_EXIT);
+ } break;
+ }
+}
- if (stretch) {
- draw_texture_rect(c->get_texture(), Rect2(Vector2(), get_size()));
- } else {
- draw_texture_rect(c->get_texture(), Rect2(Vector2(), c->get_size()));
- }
+void SubViewportContainer::_notify_viewports(int p_notification) {
+ for (int i = 0; i < get_child_count(); i++) {
+ SubViewport *c = Object::cast_to<SubViewport>(get_child(i));
+ if (!c) {
+ continue;
}
+ c->notification(p_notification);
}
}
diff --git a/scene/gui/subviewport_container.h b/scene/gui/subviewport_container.h
index e7520763fb..f52f01e4e2 100644
--- a/scene/gui/subviewport_container.h
+++ b/scene/gui/subviewport_container.h
@@ -38,6 +38,7 @@ class SubViewportContainer : public Container {
bool stretch = false;
int shrink = 1;
+ void _notify_viewports(int p_notification);
protected:
void _notification(int p_what);
@@ -54,6 +55,9 @@ public:
virtual Size2 get_minimum_size() const override;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
SubViewportContainer();
};
diff --git a/scene/gui/tab_bar.cpp b/scene/gui/tab_bar.cpp
index 5a551ec5a5..ce60da762f 100644
--- a/scene/gui/tab_bar.cpp
+++ b/scene/gui/tab_bar.cpp
@@ -32,7 +32,6 @@
#include "core/object/message_queue.h"
#include "core/string/translation.h"
-
#include "scene/gui/box_container.h"
#include "scene/gui/label.h"
#include "scene/gui/texture_rect.h"
@@ -313,6 +312,7 @@ void TabBar::_notification(int p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
update();
} break;
+
case NOTIFICATION_THEME_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
for (int i = 0; i < tabs.size(); ++i) {
@@ -332,6 +332,7 @@ void TabBar::_notification(int p_what) {
ensure_tab_visible(current);
}
} break;
+
case NOTIFICATION_DRAW: {
if (tabs.is_empty()) {
return;
@@ -524,13 +525,14 @@ void TabBar::set_tab_count(int p_count) {
offset = MIN(offset, p_count - 1);
max_drawn_tab = MIN(max_drawn_tab, p_count - 1);
current = MIN(current, p_count - 1);
- }
- _update_cache();
- _ensure_no_over_offset();
- if (scroll_to_selected) {
- ensure_tab_visible(current);
+ _update_cache();
+ _ensure_no_over_offset();
+ if (scroll_to_selected) {
+ ensure_tab_visible(current);
+ }
}
+
update();
update_minimum_size();
notify_property_list_changed();
@@ -761,6 +763,8 @@ void TabBar::_update_hover() {
return;
}
+ ERR_FAIL_COND(tabs.is_empty());
+
const Point2 &pos = get_local_mouse_position();
// Test hovering to display right or close button.
int hover_now = -1;
@@ -959,7 +963,6 @@ void TabBar::clear_tabs() {
current = 0;
previous = 0;
- _update_cache();
update();
update_minimum_size();
notify_property_list_changed();
@@ -973,18 +976,21 @@ void TabBar::remove_tab(int p_idx) {
}
if (current < 0) {
+ offset = 0;
+ max_drawn_tab = 0;
current = 0;
previous = 0;
- }
- if (current >= tabs.size()) {
- current = tabs.size() - 1;
- }
+ } else {
+ offset = MIN(offset, tabs.size() - 1);
+ max_drawn_tab = MIN(max_drawn_tab, tabs.size() - 1);
- _update_cache();
- _ensure_no_over_offset();
- if (scroll_to_selected && !tabs.is_empty()) {
- ensure_tab_visible(current);
+ _update_cache();
+ _ensure_no_over_offset();
+ if (scroll_to_selected && !tabs.is_empty()) {
+ ensure_tab_visible(current);
+ }
}
+
update();
update_minimum_size();
notify_property_list_changed();
@@ -1436,7 +1442,6 @@ void TabBar::_get_property_list(List<PropertyInfo> *p_list) const {
}
void TabBar::_bind_methods() {
- ClassDB::bind_method(D_METHOD("_update_hover"), &TabBar::_update_hover);
ClassDB::bind_method(D_METHOD("set_tab_count", "count"), &TabBar::set_tab_count);
ClassDB::bind_method(D_METHOD("get_tab_count"), &TabBar::get_tab_count);
ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabBar::set_current_tab);
diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp
index c3fc08731e..31a5e41086 100644
--- a/scene/gui/tab_container.cpp
+++ b/scene/gui/tab_container.cpp
@@ -32,7 +32,6 @@
#include "core/object/message_queue.h"
#include "core/string/translation.h"
-
#include "scene/gui/box_container.h"
#include "scene/gui/label.h"
#include "scene/gui/texture_rect.h"
@@ -326,6 +325,7 @@ void TabContainer::_notification(int p_what) {
first_tab_cache--;
}
} break;
+
case NOTIFICATION_DRAW: {
RID canvas = get_canvas_item();
Size2 size = get_size();
@@ -522,6 +522,7 @@ void TabContainer::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
@@ -704,7 +705,7 @@ void TabContainer::add_child_notify(Node *p_child) {
}
_refresh_texts();
- call_deferred("_repaint");
+ call_deferred(SNAME("_repaint"));
update();
bool first = (_get_tabs().size() == 1);
@@ -1177,6 +1178,14 @@ bool TabContainer::get_use_hidden_tabs_for_min_size() const {
return use_hidden_tabs_for_min_size;
}
+Vector<int> TabContainer::get_allowed_size_flags_horizontal() const {
+ return Vector<int>();
+}
+
+Vector<int> TabContainer::get_allowed_size_flags_vertical() const {
+ return Vector<int>();
+}
+
void TabContainer::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_tab_count"), &TabContainer::get_tab_count);
ClassDB::bind_method(D_METHOD("set_current_tab", "tab_idx"), &TabContainer::set_current_tab);
diff --git a/scene/gui/tab_container.h b/scene/gui/tab_container.h
index 01e71e9fa8..ee1b3fea51 100644
--- a/scene/gui/tab_container.h
+++ b/scene/gui/tab_container.h
@@ -133,6 +133,9 @@ public:
void set_use_hidden_tabs_for_min_size(bool p_use_hidden_tabs);
bool get_use_hidden_tabs_for_min_size() const;
+ virtual Vector<int> get_allowed_size_flags_horizontal() const override;
+ virtual Vector<int> get_allowed_size_flags_vertical() const override;
+
TabContainer();
};
diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp
index bb259843b8..5a3c622c86 100644
--- a/scene/gui/text_edit.cpp
+++ b/scene/gui/text_edit.cpp
@@ -432,32 +432,38 @@ void TextEdit::_notification(int p_what) {
}
_update_wrap_at_column(true);
} break;
+
case NOTIFICATION_RESIZED: {
_update_scrollbars();
_update_wrap_at_column();
} break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible()) {
call_deferred(SNAME("_update_scrollbars"));
call_deferred(SNAME("_update_wrap_at_column"));
}
} break;
+
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
_update_caches();
_update_wrap_at_column(true);
} break;
+
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
window_has_focus = true;
draw_caret = true;
update();
} break;
+
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
window_has_focus = false;
draw_caret = false;
update();
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (scrolling && get_v_scroll() != target_v_scroll) {
double target_y = target_v_scroll - get_v_scroll();
@@ -479,6 +485,7 @@ void TextEdit::_notification(int p_what) {
set_physics_process_internal(false);
}
} break;
+
case NOTIFICATION_DRAW: {
if (first_draw) {
// Size may not be the final one, so attempts to ensure caret was visible may have failed.
@@ -961,7 +968,7 @@ void TextEdit::_notification(int p_what) {
// Give visual indication of empty selected line.
if (selection.active && line >= selection.from_line && line <= selection.to_line && char_margin >= xmargin_beg) {
- int char_w = font->get_char_size(' ', 0, font_size).width;
+ float char_w = font->get_char_size(' ', 0, font_size).width;
if (rtl) {
RenderingServer::get_singleton()->canvas_item_add_rect(ci, Rect2(size.width - xmargin_beg - ofs_x - char_w, ofs_y, char_w, row_height), selection_color);
} else {
@@ -1427,6 +1434,7 @@ void TextEdit::_notification(int p_what) {
}
}
} break;
+
case NOTIFICATION_FOCUS_ENTER: {
if (caret_blink_enabled) {
caret_blink_timer->start();
@@ -1458,6 +1466,7 @@ void TextEdit::_notification(int p_what) {
DisplayServer::get_singleton()->virtual_keyboard_show(get_text(), get_global_rect(), true, -1, caret_start, caret_end);
}
} break;
+
case NOTIFICATION_FOCUS_EXIT: {
if (caret_blink_enabled) {
caret_blink_timer->stop();
@@ -1481,6 +1490,7 @@ void TextEdit::_notification(int p_what) {
deselect();
}
} break;
+
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
if (has_focus()) {
ime_text = DisplayServer::get_singleton()->ime_get_text();
@@ -1497,7 +1507,8 @@ void TextEdit::_notification(int p_what) {
update();
}
} break;
- case Control::NOTIFICATION_DRAG_BEGIN: {
+
+ case NOTIFICATION_DRAG_BEGIN: {
selection.selecting_mode = SelectionMode::SELECTION_MODE_NONE;
drag_action = true;
dragging_minimap = false;
@@ -1505,7 +1516,8 @@ void TextEdit::_notification(int p_what) {
can_drag_minimap = false;
click_select_held->stop();
} break;
- case Control::NOTIFICATION_DRAG_END: {
+
+ case NOTIFICATION_DRAG_END: {
if (is_drag_successful()) {
if (selection.drag_attempt) {
selection.drag_attempt = false;
@@ -2472,7 +2484,7 @@ void TextEdit::_update_placeholder() {
return; // Not in tree?
}
- // Placeholder is generally smaller then text docuemnts, and updates less so this should be fast enough for now.
+ // Placeholder is generally smaller then text documents, and updates less so this should be fast enough for now.
placeholder_data_buf->clear();
placeholder_data_buf->set_width(text.get_width());
placeholder_data_buf->set_direction((TextServer::Direction)text_direction);
diff --git a/scene/gui/texture_rect.cpp b/scene/gui/texture_rect.cpp
index a8cdeb44f5..ecdf55caf0 100644
--- a/scene/gui/texture_rect.cpp
+++ b/scene/gui/texture_rect.cpp
@@ -29,84 +29,87 @@
/*************************************************************************/
#include "texture_rect.h"
+
#include "core/core_string_names.h"
#include "servers/rendering_server.h"
void TextureRect::_notification(int p_what) {
- if (p_what == NOTIFICATION_DRAW) {
- if (texture.is_null()) {
- return;
- }
-
- Size2 size;
- Point2 offset;
- Rect2 region;
- bool tile = false;
-
- switch (stretch_mode) {
- case STRETCH_SCALE: {
- size = get_size();
- } break;
- case STRETCH_TILE: {
- size = get_size();
- tile = true;
- } break;
- case STRETCH_KEEP: {
- size = texture->get_size();
- } break;
- case STRETCH_KEEP_CENTERED: {
- offset = (get_size() - texture->get_size()) / 2;
- size = texture->get_size();
- } break;
- case STRETCH_KEEP_ASPECT_CENTERED:
- case STRETCH_KEEP_ASPECT: {
- size = get_size();
- int tex_width = texture->get_width() * size.height / texture->get_height();
- int tex_height = size.height;
-
- if (tex_width > size.width) {
- tex_width = size.width;
- tex_height = texture->get_height() * tex_width / texture->get_width();
- }
-
- if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) {
- offset.x += (size.width - tex_width) / 2;
- offset.y += (size.height - tex_height) / 2;
- }
-
- size.width = tex_width;
- size.height = tex_height;
- } break;
- case STRETCH_KEEP_ASPECT_COVERED: {
- size = get_size();
-
- Size2 tex_size = texture->get_size();
- Size2 scale_size(size.width / tex_size.width, size.height / tex_size.height);
- float scale = scale_size.width > scale_size.height ? scale_size.width : scale_size.height;
- Size2 scaled_tex_size = tex_size * scale;
-
- region.position = ((scaled_tex_size - size) / scale).abs() / 2.0f;
- region.size = size / scale;
- } break;
- }
-
- Ref<AtlasTexture> p_atlas = texture;
-
- if (p_atlas.is_valid() && region.has_no_area()) {
- Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height());
-
- offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0;
- offset.height += vflip ? p_atlas->get_margin().get_position().height * scale_size.height * 2 : 0;
- }
-
- size.width *= hflip ? -1.0f : 1.0f;
- size.height *= vflip ? -1.0f : 1.0f;
-
- if (region.has_no_area()) {
- draw_texture_rect(texture, Rect2(offset, size), tile);
- } else {
- draw_texture_rect_region(texture, Rect2(offset, size), region);
- }
+ switch (p_what) {
+ case NOTIFICATION_DRAW: {
+ if (texture.is_null()) {
+ return;
+ }
+
+ Size2 size;
+ Point2 offset;
+ Rect2 region;
+ bool tile = false;
+
+ switch (stretch_mode) {
+ case STRETCH_SCALE: {
+ size = get_size();
+ } break;
+ case STRETCH_TILE: {
+ size = get_size();
+ tile = true;
+ } break;
+ case STRETCH_KEEP: {
+ size = texture->get_size();
+ } break;
+ case STRETCH_KEEP_CENTERED: {
+ offset = (get_size() - texture->get_size()) / 2;
+ size = texture->get_size();
+ } break;
+ case STRETCH_KEEP_ASPECT_CENTERED:
+ case STRETCH_KEEP_ASPECT: {
+ size = get_size();
+ int tex_width = texture->get_width() * size.height / texture->get_height();
+ int tex_height = size.height;
+
+ if (tex_width > size.width) {
+ tex_width = size.width;
+ tex_height = texture->get_height() * tex_width / texture->get_width();
+ }
+
+ if (stretch_mode == STRETCH_KEEP_ASPECT_CENTERED) {
+ offset.x += (size.width - tex_width) / 2;
+ offset.y += (size.height - tex_height) / 2;
+ }
+
+ size.width = tex_width;
+ size.height = tex_height;
+ } break;
+ case STRETCH_KEEP_ASPECT_COVERED: {
+ size = get_size();
+
+ Size2 tex_size = texture->get_size();
+ Size2 scale_size(size.width / tex_size.width, size.height / tex_size.height);
+ float scale = scale_size.width > scale_size.height ? scale_size.width : scale_size.height;
+ Size2 scaled_tex_size = tex_size * scale;
+
+ region.position = ((scaled_tex_size - size) / scale).abs() / 2.0f;
+ region.size = size / scale;
+ } break;
+ }
+
+ Ref<AtlasTexture> p_atlas = texture;
+
+ if (p_atlas.is_valid() && region.has_no_area()) {
+ Size2 scale_size(size.width / texture->get_width(), size.height / texture->get_height());
+
+ offset.width += hflip ? p_atlas->get_margin().get_position().width * scale_size.width * 2 : 0;
+ offset.height += vflip ? p_atlas->get_margin().get_position().height * scale_size.height * 2 : 0;
+ }
+
+ size.width *= hflip ? -1.0f : 1.0f;
+ size.height *= vflip ? -1.0f : 1.0f;
+
+ if (region.has_no_area()) {
+ draw_texture_rect(texture, Rect2(offset, size), tile);
+ } else {
+ draw_texture_rect_region(texture, Rect2(offset, size), region);
+ }
+ } break;
}
}
diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp
index a190e08088..73cf2b9c6e 100644
--- a/scene/gui/tree.cpp
+++ b/scene/gui/tree.cpp
@@ -37,10 +37,9 @@
#include "core/os/os.h"
#include "core/string/print_string.h"
#include "core/string/translation.h"
+#include "scene/gui/box_container.h"
#include "scene/main/window.h"
-#include "box_container.h"
-
#include <limits.h>
Size2 TreeItem::Cell::get_icon_size() const {
@@ -202,7 +201,7 @@ void TreeItem::propagate_check(int p_column, bool p_emit_signal) {
bool ch = cells[p_column].checked;
if (p_emit_signal) {
- tree->emit_signal("check_propagated_to_item", this, p_column);
+ tree->emit_signal(SNAME("check_propagated_to_item"), this, p_column);
}
_propagate_check_through_children(p_column, ch, p_emit_signal);
_propagate_check_through_parents(p_column, p_emit_signal);
@@ -213,7 +212,7 @@ void TreeItem::_propagate_check_through_children(int p_column, bool p_checked, b
while (current) {
current->set_checked(p_column, p_checked);
if (p_emit_signal) {
- current->tree->emit_signal("check_propagated_to_item", current, p_column);
+ current->tree->emit_signal(SNAME("check_propagated_to_item"), current, p_column);
}
current->_propagate_check_through_children(p_column, p_checked, p_emit_signal);
current = current->get_next();
@@ -252,7 +251,7 @@ void TreeItem::_propagate_check_through_parents(int p_column, bool p_emit_signal
}
if (p_emit_signal) {
- current->tree->emit_signal("check_propagated_to_item", current, p_column);
+ current->tree->emit_signal(SNAME("check_propagated_to_item"), current, p_column);
}
current->_propagate_check_through_parents(p_column, p_emit_signal);
}
@@ -905,6 +904,12 @@ 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());
@@ -1283,9 +1288,11 @@ void TreeItem::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_custom_as_button", "column", "enable"), &TreeItem::set_custom_as_button);
ClassDB::bind_method(D_METHOD("is_custom_set_as_button", "column"), &TreeItem::is_custom_set_as_button);
- ClassDB::bind_method(D_METHOD("add_button", "column", "button", "button_idx", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("add_button", "column", "button", "id", "disabled", "tooltip"), &TreeItem::add_button, DEFVAL(-1), DEFVAL(false), DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_button_count", "column"), &TreeItem::get_button_count);
ClassDB::bind_method(D_METHOD("get_button_tooltip", "column", "button_idx"), &TreeItem::get_button_tooltip);
+ ClassDB::bind_method(D_METHOD("get_button_id", "column", "button_idx"), &TreeItem::get_button_id);
+ ClassDB::bind_method(D_METHOD("get_button_by_id", "column", "id"), &TreeItem::get_button_by_id);
ClassDB::bind_method(D_METHOD("get_button", "column", "button_idx"), &TreeItem::get_button);
ClassDB::bind_method(D_METHOD("set_button", "column", "button_idx", "button"), &TreeItem::set_button);
ClassDB::bind_method(D_METHOD("erase_button", "column", "button_idx"), &TreeItem::erase_button);
@@ -1694,8 +1701,7 @@ int Tree::draw_item(const Point2i &p_pos, const Point2 &p_draw_ofs, const Size2
bool skip = (p_item == root && hide_root);
if (!skip && (p_pos.y + label_h - cache.offset.y) > 0) {
- //draw separation.
- //if (p_item->get_parent()!=root || !hide_root)
+ // Draw separation.
ERR_FAIL_COND_V(cache.font.is_null(), -1);
@@ -2252,11 +2258,6 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c
emit_signal(SNAME("item_selected"));
emitted_row = true;
}
- /*
- if (p_col==i)
- p_current->selected_signal.call(p_col);
- */
-
} else if (c.selected) {
if (p_selected != p_current) {
// Deselect other rows.
@@ -3628,178 +3629,187 @@ int Tree::_get_title_button_height() const {
}
void Tree::_notification(int p_what) {
- if (p_what == NOTIFICATION_FOCUS_ENTER) {
- if (get_viewport()) {
- focus_in_id = get_viewport()->get_processed_events_count();
- }
- }
- if (p_what == NOTIFICATION_MOUSE_EXIT) {
- if (cache.hover_type != Cache::CLICK_NONE) {
- cache.hover_type = Cache::CLICK_NONE;
- update();
- }
- }
-
- if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
- drag_touching = false;
- }
+ switch (p_what) {
+ case NOTIFICATION_FOCUS_ENTER: {
+ if (get_viewport()) {
+ focus_in_id = get_viewport()->get_processed_events_count();
+ }
+ } break;
- if (p_what == NOTIFICATION_ENTER_TREE) {
- update_cache();
- }
- if (p_what == NOTIFICATION_DRAG_END) {
- drop_mode_flags = 0;
- scrolling = false;
- set_physics_process_internal(false);
- update();
- }
- if (p_what == NOTIFICATION_DRAG_BEGIN) {
- single_select_defer = nullptr;
- if (cache.scroll_speed > 0) {
- scrolling = true;
- set_physics_process_internal(true);
- }
- }
- if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
- if (drag_touching) {
- if (drag_touching_deaccel) {
- float pos = v_scroll->get_value();
- pos += drag_speed * get_physics_process_delta_time();
+ case NOTIFICATION_MOUSE_EXIT: {
+ if (cache.hover_type != Cache::CLICK_NONE) {
+ cache.hover_type = Cache::CLICK_NONE;
+ update();
+ }
+ } break;
- bool turnoff = false;
- if (pos < 0) {
- pos = 0;
- turnoff = true;
- set_physics_process_internal(false);
- drag_touching = false;
- drag_touching_deaccel = false;
- }
- if (pos > (v_scroll->get_max() - v_scroll->get_page())) {
- pos = v_scroll->get_max() - v_scroll->get_page();
- turnoff = true;
- }
+ case NOTIFICATION_VISIBILITY_CHANGED: {
+ drag_touching = false;
+ } break;
- v_scroll->set_value(pos);
- float sgn = drag_speed < 0 ? -1 : 1;
- float val = Math::abs(drag_speed);
- val -= 1000 * get_physics_process_delta_time();
+ case NOTIFICATION_ENTER_TREE: {
+ update_cache();
+ } break;
- if (val < 0) {
- turnoff = true;
- }
- drag_speed = sgn * val;
+ case NOTIFICATION_DRAG_END: {
+ drop_mode_flags = 0;
+ scrolling = false;
+ set_physics_process_internal(false);
+ update();
+ } break;
- if (turnoff) {
- set_physics_process_internal(false);
- drag_touching = false;
- drag_touching_deaccel = false;
- }
+ case NOTIFICATION_DRAG_BEGIN: {
+ single_select_defer = nullptr;
+ if (cache.scroll_speed > 0) {
+ scrolling = true;
+ set_physics_process_internal(true);
}
- }
+ } break;
- Point2 mouse_position = get_viewport()->get_mouse_position() - get_global_position();
- if (scrolling && get_rect().grow(cache.scroll_border).has_point(mouse_position)) {
- Point2 point;
+ case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
+ if (drag_touching) {
+ if (drag_touching_deaccel) {
+ float pos = v_scroll->get_value();
+ pos += drag_speed * get_physics_process_delta_time();
- if ((ABS(mouse_position.x) < ABS(mouse_position.x - get_size().width)) && (ABS(mouse_position.x) < cache.scroll_border)) {
- point.x = mouse_position.x - cache.scroll_border;
- } else if (ABS(mouse_position.x - get_size().width) < cache.scroll_border) {
- point.x = mouse_position.x - (get_size().width - cache.scroll_border);
- }
+ bool turnoff = false;
+ if (pos < 0) {
+ pos = 0;
+ turnoff = true;
+ set_physics_process_internal(false);
+ drag_touching = false;
+ drag_touching_deaccel = false;
+ }
+ if (pos > (v_scroll->get_max() - v_scroll->get_page())) {
+ pos = v_scroll->get_max() - v_scroll->get_page();
+ turnoff = true;
+ }
+
+ v_scroll->set_value(pos);
+ float sgn = drag_speed < 0 ? -1 : 1;
+ float val = Math::abs(drag_speed);
+ val -= 1000 * get_physics_process_delta_time();
- if ((ABS(mouse_position.y) < ABS(mouse_position.y - get_size().height)) && (ABS(mouse_position.y) < cache.scroll_border)) {
- point.y = mouse_position.y - cache.scroll_border;
- } else if (ABS(mouse_position.y - get_size().height) < cache.scroll_border) {
- point.y = mouse_position.y - (get_size().height - cache.scroll_border);
+ if (val < 0) {
+ turnoff = true;
+ }
+ drag_speed = sgn * val;
+
+ if (turnoff) {
+ set_physics_process_internal(false);
+ drag_touching = false;
+ drag_touching_deaccel = false;
+ }
+ }
}
- point *= cache.scroll_speed * get_physics_process_delta_time();
- point += get_scroll();
- h_scroll->set_value(point.x);
- v_scroll->set_value(point.y);
- }
- }
+ Point2 mouse_position = get_viewport()->get_mouse_position() - get_global_position();
+ if (scrolling && get_rect().grow(cache.scroll_border).has_point(mouse_position)) {
+ Point2 point;
- if (p_what == NOTIFICATION_DRAW) {
- update_cache();
- update_scrollbars();
- RID ci = get_canvas_item();
+ if ((ABS(mouse_position.x) < ABS(mouse_position.x - get_size().width)) && (ABS(mouse_position.x) < cache.scroll_border)) {
+ point.x = mouse_position.x - cache.scroll_border;
+ } else if (ABS(mouse_position.x - get_size().width) < cache.scroll_border) {
+ point.x = mouse_position.x - (get_size().width - cache.scroll_border);
+ }
- Ref<StyleBox> bg = cache.bg;
- Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
- int outline_size = get_theme_constant(SNAME("outline_size"));
+ if ((ABS(mouse_position.y) < ABS(mouse_position.y - get_size().height)) && (ABS(mouse_position.y) < cache.scroll_border)) {
+ point.y = mouse_position.y - cache.scroll_border;
+ } else if (ABS(mouse_position.y - get_size().height) < cache.scroll_border) {
+ point.y = mouse_position.y - (get_size().height - cache.scroll_border);
+ }
- Point2 draw_ofs;
- draw_ofs += bg->get_offset();
- Size2 draw_size = get_size() - bg->get_minimum_size();
- if (h_scroll->is_visible()) {
- draw_size.width -= h_scroll->get_minimum_size().width;
- }
+ point *= cache.scroll_speed * get_physics_process_delta_time();
+ point += get_scroll();
+ h_scroll->set_value(point.x);
+ v_scroll->set_value(point.y);
+ }
+ } break;
- bg->draw(ci, Rect2(Point2(), get_size()));
+ case NOTIFICATION_DRAW: {
+ update_cache();
+ update_scrollbars();
+ RID ci = get_canvas_item();
+
+ Ref<StyleBox> bg = cache.bg;
+ Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
+ int outline_size = get_theme_constant(SNAME("outline_size"));
+
+ Point2 draw_ofs;
+ draw_ofs += bg->get_offset();
+ Size2 draw_size = get_size() - bg->get_minimum_size();
+ if (h_scroll->is_visible()) {
+ draw_size.width -= h_scroll->get_minimum_size().width;
+ }
- int tbh = _get_title_button_height();
+ bg->draw(ci, Rect2(Point2(), get_size()));
- draw_ofs.y += tbh;
- draw_size.y -= tbh;
+ int tbh = _get_title_button_height();
- cache.rtl = is_layout_rtl();
+ draw_ofs.y += tbh;
+ draw_size.y -= tbh;
- if (root && get_size().x > 0 && get_size().y > 0) {
- draw_item(Point2(), draw_ofs, draw_size, root);
- }
+ cache.rtl = is_layout_rtl();
- if (show_column_titles) {
- //title buttons
- int ofs2 = cache.bg->get_margin(SIDE_LEFT);
- for (int i = 0; i < columns.size(); i++) {
- Ref<StyleBox> sb = (cache.click_type == Cache::CLICK_TITLE && cache.click_index == i) ? cache.title_button_pressed : ((cache.hover_type == Cache::CLICK_TITLE && cache.hover_index == i) ? cache.title_button_hover : cache.title_button);
- Ref<Font> f = cache.tb_font;
- Rect2 tbrect = Rect2(ofs2 - cache.offset.x, bg->get_margin(SIDE_TOP), get_column_width(i), tbh);
- if (cache.rtl) {
- tbrect.position.x = get_size().width - tbrect.size.x - tbrect.position.x;
- }
- sb->draw(ci, tbrect);
- ofs2 += tbrect.size.width;
- //text
- int clip_w = tbrect.size.width - sb->get_minimum_size().width;
- columns.write[i].text_buf->set_width(clip_w);
-
- Vector2 text_pos = tbrect.position + Point2i(sb->get_offset().x + (tbrect.size.width - columns[i].text_buf->get_size().x) / 2, (tbrect.size.height - columns[i].text_buf->get_size().y) / 2);
- if (outline_size > 0 && font_outline_color.a > 0) {
- columns[i].text_buf->draw_outline(ci, text_pos, outline_size, font_outline_color);
- }
- columns[i].text_buf->draw(ci, text_pos, cache.title_button_color);
+ if (root && get_size().x > 0 && get_size().y > 0) {
+ draw_item(Point2(), draw_ofs, draw_size, root);
}
- }
- // Draw the background focus outline last, so that it is drawn in front of the section headings.
- // Otherwise, section heading backgrounds can appear to be in front of the focus outline when scrolling.
- if (has_focus()) {
- RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
- const Ref<StyleBox> bg_focus = get_theme_stylebox(SNAME("bg_focus"));
- bg_focus->draw(ci, Rect2(Point2(), get_size()));
- RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
- }
- }
+ if (show_column_titles) {
+ //title buttons
+ int ofs2 = cache.bg->get_margin(SIDE_LEFT);
+ for (int i = 0; i < columns.size(); i++) {
+ Ref<StyleBox> sb = (cache.click_type == Cache::CLICK_TITLE && cache.click_index == i) ? cache.title_button_pressed : ((cache.hover_type == Cache::CLICK_TITLE && cache.hover_index == i) ? cache.title_button_hover : cache.title_button);
+ Ref<Font> f = cache.tb_font;
+ Rect2 tbrect = Rect2(ofs2 - cache.offset.x, bg->get_margin(SIDE_TOP), get_column_width(i), tbh);
+ if (cache.rtl) {
+ tbrect.position.x = get_size().width - tbrect.size.x - tbrect.position.x;
+ }
+ sb->draw(ci, tbrect);
+ ofs2 += tbrect.size.width;
+ //text
+ int clip_w = tbrect.size.width - sb->get_minimum_size().width;
+ columns.write[i].text_buf->set_width(clip_w);
+
+ Vector2 text_pos = tbrect.position + Point2i(sb->get_offset().x + (tbrect.size.width - columns[i].text_buf->get_size().x) / 2, (tbrect.size.height - columns[i].text_buf->get_size().y) / 2);
+ if (outline_size > 0 && font_outline_color.a > 0) {
+ columns[i].text_buf->draw_outline(ci, text_pos, outline_size, font_outline_color);
+ }
+ columns[i].text_buf->draw(ci, text_pos, cache.title_button_color);
+ }
+ }
- if (p_what == NOTIFICATION_THEME_CHANGED || p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) {
- update_cache();
- _update_all();
- }
+ // Draw the background focus outline last, so that it is drawn in front of the section headings.
+ // Otherwise, section heading backgrounds can appear to be in front of the focus outline when scrolling.
+ if (has_focus()) {
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true);
+ const Ref<StyleBox> bg_focus = get_theme_stylebox(SNAME("bg_focus"));
+ bg_focus->draw(ci, Rect2(Point2(), get_size()));
+ RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false);
+ }
+ } break;
- if (p_what == NOTIFICATION_RESIZED || p_what == NOTIFICATION_TRANSFORM_CHANGED) {
- if (popup_edited_item != nullptr) {
- Rect2 rect = popup_edited_item->get_meta("__focus_rect");
- Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2);
- Point2i textedpos = get_global_position() + rect.position - ofs;
+ case NOTIFICATION_THEME_CHANGED:
+ case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
+ case NOTIFICATION_TRANSLATION_CHANGED: {
+ update_cache();
+ _update_all();
+ } break;
- if (cache.text_editor_position != textedpos) {
- cache.text_editor_position = textedpos;
- text_editor->set_position(textedpos);
- value_editor->set_position(textedpos + Point2i(0, text_editor->get_size().height));
+ case NOTIFICATION_RESIZED:
+ case NOTIFICATION_TRANSFORM_CHANGED: {
+ if (popup_edited_item != nullptr) {
+ Rect2 rect = popup_edited_item->get_meta("__focus_rect");
+ Vector2 ofs(0, (text_editor->get_size().height - rect.size.height) / 2);
+ Point2i textedpos = get_global_position() + rect.position - ofs;
+
+ if (cache.text_editor_position != textedpos) {
+ cache.text_editor_position = textedpos;
+ text_editor->set_position(textedpos);
+ value_editor->set_position(textedpos + Point2i(0, text_editor->get_size().height));
+ }
}
- }
+ } break;
}
}
@@ -4049,10 +4059,6 @@ int Tree::get_edited_column() const {
}
TreeItem *Tree::get_next_selected(TreeItem *p_item) {
- /*
- if (!p_item)
- return nullptr;
- */
if (!root) {
return nullptr;
}
@@ -4409,21 +4415,29 @@ Point2 Tree::get_scroll() const {
return ofs;
}
-void Tree::scroll_to_item(TreeItem *p_item) {
+void Tree::scroll_to_item(TreeItem *p_item, bool p_center_on_item) {
if (!is_visible_in_tree()) {
- // hack to work around crash in get_item_rect() if Tree is not in tree.
- return;
+ return; // Hack to work around crash in get_item_rect() if Tree is not in tree.
}
- // make sure the scrollbar min and max are up to date with latest changes.
update_scrollbars();
- const Rect2 r = get_item_rect(p_item);
+ const real_t tree_height = get_size().y;
+ const Rect2 item_rect = get_item_rect(p_item);
+ const real_t item_y = item_rect.position.y;
+ const real_t item_height = item_rect.size.y + cache.vseparation;
- if (r.position.y <= v_scroll->get_value()) {
- v_scroll->set_value(r.position.y);
- } else if (r.position.y + r.size.y + 2 * cache.vseparation > v_scroll->get_value() + get_size().y) {
- v_scroll->set_value(r.position.y + r.size.y + 2 * cache.vseparation - get_size().y);
+ if (p_center_on_item) {
+ v_scroll->set_value(item_y - (tree_height - item_height) / 2.0f);
+ } else {
+ if (item_y < v_scroll->get_value()) {
+ v_scroll->set_value(item_y);
+ } else {
+ const real_t new_position = item_y + item_height - tree_height;
+ if (new_position > v_scroll->get_value()) {
+ v_scroll->set_value(new_position);
+ }
+ }
}
}
@@ -4848,6 +4862,7 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_item_at_position", "position"), &Tree::get_item_at_position);
ClassDB::bind_method(D_METHOD("get_column_at_position", "position"), &Tree::get_column_at_position);
ClassDB::bind_method(D_METHOD("get_drop_section_at_position", "position"), &Tree::get_drop_section_at_position);
+ ClassDB::bind_method(D_METHOD("get_button_id_at_position", "position"), &Tree::get_button_id_at_position);
ClassDB::bind_method(D_METHOD("ensure_cursor_is_visible"), &Tree::ensure_cursor_is_visible);
@@ -4868,7 +4883,7 @@ void Tree::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_column_title_language", "column"), &Tree::get_column_title_language);
ClassDB::bind_method(D_METHOD("get_scroll"), &Tree::get_scroll);
- ClassDB::bind_method(D_METHOD("scroll_to_item", "item"), &Tree::scroll_to_item);
+ ClassDB::bind_method(D_METHOD("scroll_to_item", "item", "center_on_item"), &Tree::scroll_to_item, DEFVAL(false));
ClassDB::bind_method(D_METHOD("set_h_scroll_enabled", "h_scroll"), &Tree::set_h_scroll_enabled);
ClassDB::bind_method(D_METHOD("is_h_scroll_enabled"), &Tree::is_h_scroll_enabled);
diff --git a/scene/gui/tree.h b/scene/gui/tree.h
index c24763a0e4..dc786de6dc 100644
--- a/scene/gui/tree.h
+++ b/scene/gui/tree.h
@@ -248,6 +248,7 @@ 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);
@@ -682,7 +683,7 @@ public:
TreeItem *get_item_with_text(const String &p_find) const;
Point2 get_scroll() const;
- void scroll_to_item(TreeItem *p_item);
+ void scroll_to_item(TreeItem *p_item, bool p_center_on_item = false);
void set_h_scroll_enabled(bool p_enable);
bool is_h_scroll_enabled() const;
void set_v_scroll_enabled(bool p_enable);
diff --git a/scene/gui/video_stream_player.cpp b/scene/gui/video_stream_player.cpp
index 1f2a8c8aa1..d7c76aa070 100644
--- a/scene/gui/video_stream_player.cpp
+++ b/scene/gui/video_stream_player.cpp
@@ -134,7 +134,6 @@ void VideoStreamPlayer::_notification(int p_notification) {
if (stream.is_valid() && autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
-
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -162,7 +161,6 @@ void VideoStreamPlayer::_notification(int p_notification) {
if (!playback->is_playing()) {
emit_signal(SceneStringNames::get_singleton()->finished);
}
-
} break;
case NOTIFICATION_DRAW: {
@@ -175,10 +173,9 @@ void VideoStreamPlayer::_notification(int p_notification) {
Size2 s = expand ? get_size() : texture->get_size();
draw_texture_rect(texture, Rect2(Point2(), s), false);
-
} break;
- };
-};
+ }
+}
Size2 VideoStreamPlayer::get_minimum_size() const {
if (!expand && !texture.is_null()) {
@@ -243,11 +240,11 @@ void VideoStreamPlayer::set_stream(const Ref<VideoStream> &p_stream) {
if (!expand) {
update_minimum_size();
}
-};
+}
Ref<VideoStream> VideoStreamPlayer::get_stream() const {
return stream;
-};
+}
void VideoStreamPlayer::play() {
ERR_FAIL_COND(!is_inside_tree());
@@ -257,10 +254,8 @@ void VideoStreamPlayer::play() {
playback->stop();
playback->play();
set_process_internal(true);
- // AudioServer::get_singleton()->stream_set_active(stream_rid,true);
- // AudioServer::get_singleton()->stream_set_volume_scale(stream_rid,volume);
last_audio_time = 0;
-};
+}
void VideoStreamPlayer::stop() {
if (!is_inside_tree()) {
@@ -271,11 +266,10 @@ void VideoStreamPlayer::stop() {
}
playback->stop();
- // AudioServer::get_singleton()->stream_set_active(stream_rid,false);
resampler.flush();
set_process_internal(false);
last_audio_time = 0;
-};
+}
bool VideoStreamPlayer::is_playing() const {
if (playback.is_null()) {
@@ -283,16 +277,16 @@ bool VideoStreamPlayer::is_playing() const {
}
return playback->is_playing();
-};
+}
void VideoStreamPlayer::set_paused(bool p_paused) {
paused = p_paused;
if (playback.is_valid()) {
playback->set_paused(p_paused);
set_process_internal(!p_paused);
- };
+ }
last_audio_time = 0;
-};
+}
bool VideoStreamPlayer::is_paused() const {
return paused;
@@ -316,11 +310,11 @@ int VideoStreamPlayer::get_audio_track() const {
void VideoStreamPlayer::set_volume(float p_vol) {
volume = p_vol;
-};
+}
float VideoStreamPlayer::get_volume() const {
return volume;
-};
+}
void VideoStreamPlayer::set_volume_db(float p_db) {
if (p_db < -79) {
@@ -328,7 +322,7 @@ void VideoStreamPlayer::set_volume_db(float p_db) {
} else {
set_volume(Math::db2linear(p_db));
}
-};
+}
float VideoStreamPlayer::get_volume_db() const {
if (volume == 0) {
@@ -336,21 +330,21 @@ float VideoStreamPlayer::get_volume_db() const {
} else {
return Math::linear2db(volume);
}
-};
+}
String VideoStreamPlayer::get_stream_name() const {
if (stream.is_null()) {
return "<No Stream>";
}
return stream->get_name();
-};
+}
float VideoStreamPlayer::get_stream_position() const {
if (playback.is_null()) {
return 0;
}
return playback->get_playback_position();
-};
+}
void VideoStreamPlayer::set_stream_position(float p_position) {
if (playback.is_valid()) {
@@ -368,14 +362,14 @@ Ref<Texture2D> VideoStreamPlayer::get_video_texture() const {
void VideoStreamPlayer::set_autoplay(bool p_enable) {
autoplay = p_enable;
-};
+}
bool VideoStreamPlayer::has_autoplay() const {
return autoplay;
-};
+}
void VideoStreamPlayer::set_bus(const StringName &p_bus) {
- //if audio is active, must lock this
+ // If audio is active, must lock this.
AudioServer::get_singleton()->lock();
bus = p_bus;
AudioServer::get_singleton()->unlock();
@@ -449,7 +443,6 @@ void VideoStreamPlayer::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "audio_track", PROPERTY_HINT_RANGE, "0,128,1"), "set_audio_track", "get_audio_track");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "stream", PROPERTY_HINT_RESOURCE_TYPE, "VideoStream"), "set_stream", "get_stream");
- //ADD_PROPERTY( PropertyInfo(Variant::BOOL, "stream/loop"), "set_loop", "has_loop") ;
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume_db", PROPERTY_HINT_RANGE, "-80,24,0.01"), "set_volume_db", "get_volume_db");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "volume", PROPERTY_HINT_RANGE, "0,15,0.01,exp", PROPERTY_USAGE_NONE), "set_volume", "get_volume");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "autoplay"), "set_autoplay", "has_autoplay");
@@ -464,7 +457,5 @@ void VideoStreamPlayer::_bind_methods() {
VideoStreamPlayer::VideoStreamPlayer() {}
VideoStreamPlayer::~VideoStreamPlayer() {
- // if (stream_rid.is_valid())
- // AudioServer::get_singleton()->free(stream_rid);
- resampler.clear(); //Not necessary here, but make in consistent with other "stream_player" classes
-};
+ resampler.clear(); // Not necessary here, but make in consistent with other "stream_player" classes.
+}
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp
index a62bbb146c..26b67b763c 100644
--- a/scene/main/canvas_item.cpp
+++ b/scene/main/canvas_item.cpp
@@ -56,43 +56,21 @@ Transform2D CanvasItem::_edit_get_transform() const {
#endif
bool CanvasItem::is_visible_in_tree() const {
- if (!is_inside_tree()) {
- return false;
- }
-
- const CanvasItem *p = this;
-
- while (p) {
- if (!p->visible) {
- return false;
- }
- if (p->window && !p->window->is_visible()) {
- return false;
- }
- p = p->get_parent_item();
- }
-
- const Node *n = get_parent();
- while (n) {
- const CanvasLayer *c = Object::cast_to<CanvasLayer>(n);
- if (c && !c->is_visible()) {
- return false;
- }
- n = n->get_parent();
- }
-
- return true;
+ return visible && parent_visible_in_tree;
}
-void CanvasItem::_propagate_visibility_changed(bool p_visible) {
- if (p_visible && first_draw) { //avoid propagating it twice
+void CanvasItem::_propagate_visibility_changed(bool p_visible, bool p_is_source) {
+ if (p_visible && first_draw) { // Avoid propagating it twice.
first_draw = false;
}
+ if (!p_is_source) {
+ parent_visible_in_tree = p_visible;
+ }
notification(NOTIFICATION_VISIBILITY_CHANGED);
- if (p_visible) {
- update(); //todo optimize
- } else {
+ if (visible && p_visible) {
+ update();
+ } else if (!p_visible && (visible || p_is_source)) {
emit_signal(SceneStringNames::get_singleton()->hidden);
}
_block();
@@ -100,8 +78,12 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) {
for (int i = 0; i < get_child_count(); i++) {
CanvasItem *c = Object::cast_to<CanvasItem>(get_child(i));
- if (c && c->visible) { //should the top_levels stop propagation? i think so but..
- c->_propagate_visibility_changed(p_visible);
+ if (c) { // Should the top_levels stop propagation? I think so, but...
+ if (c->visible) {
+ c->_propagate_visibility_changed(p_visible);
+ } else {
+ c->parent_visible_in_tree = p_visible;
+ }
}
}
@@ -116,11 +98,12 @@ void CanvasItem::set_visible(bool p_visible) {
visible = p_visible;
RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, p_visible);
- if (!is_inside_tree()) {
+ if (!parent_visible_in_tree) {
+ notification(NOTIFICATION_VISIBILITY_CHANGED);
return;
}
- _propagate_visibility_changed(p_visible);
+ _propagate_visibility_changed(p_visible, true);
}
void CanvasItem::show() {
@@ -148,7 +131,7 @@ void CanvasItem::_update_callback() {
RenderingServer::get_singleton()->canvas_item_clear(get_canvas_item());
//todo updating = true - only allow drawing here
- if (is_visible_in_tree()) { //todo optimize this!!
+ if (is_visible_in_tree()) {
if (first_draw) {
notification(NOTIFICATION_VISIBILITY_CHANGED);
first_draw = false;
@@ -282,32 +265,44 @@ void CanvasItem::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
ERR_FAIL_COND(!is_inside_tree());
first_draw = true;
+
Node *parent = get_parent();
if (parent) {
CanvasItem *ci = Object::cast_to<CanvasItem>(parent);
+
if (ci) {
+ parent_visible_in_tree = ci->is_visible_in_tree();
C = ci->children_items.push_back(this);
- }
- if (!ci) {
- //look for a window
- Viewport *viewport = nullptr;
-
- while (parent) {
- viewport = Object::cast_to<Viewport>(parent);
- if (viewport) {
- break;
+ } else {
+ CanvasLayer *cl = Object::cast_to<CanvasLayer>(parent);
+
+ if (cl) {
+ parent_visible_in_tree = cl->is_visible();
+ } else {
+ // Look for a window.
+ Viewport *viewport = nullptr;
+
+ while (parent) {
+ viewport = Object::cast_to<Viewport>(parent);
+ if (viewport) {
+ break;
+ }
+ parent = parent->get_parent();
}
- parent = parent->get_parent();
- }
- ERR_FAIL_COND(!viewport);
+ ERR_FAIL_COND(!viewport);
- window = Object::cast_to<Window>(viewport);
- if (window) {
- window->connect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed));
+ window = Object::cast_to<Window>(viewport);
+ if (window) {
+ window->connect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed));
+ parent_visible_in_tree = window->is_visible();
+ } else {
+ parent_visible_in_tree = true;
+ }
}
}
}
+
_enter_canvas();
_update_texture_filter_changed(false);
@@ -317,6 +312,7 @@ void CanvasItem::_notification(int p_what) {
get_tree()->xform_change_list.add(&xform_change);
}
} break;
+
case NOTIFICATION_MOVED_IN_PARENT: {
if (!is_inside_tree()) {
break;
@@ -329,8 +325,8 @@ void CanvasItem::_notification(int p_what) {
ERR_FAIL_COND(!p);
RenderingServer::get_singleton()->canvas_item_set_draw_index(canvas_item, get_index());
}
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (xform_change.in_list()) {
get_tree()->xform_change_list.remove(&xform_change);
@@ -344,10 +340,9 @@ void CanvasItem::_notification(int p_what) {
window->disconnect(SceneStringNames::get_singleton()->visibility_changed, callable_mp(this, &CanvasItem::_window_visibility_changed));
}
global_invalid = true;
+ parent_visible_in_tree = false;
} break;
- case NOTIFICATION_DRAW:
- case NOTIFICATION_TRANSFORM_CHANGED: {
- } break;
+
case NOTIFICATION_VISIBILITY_CHANGED: {
emit_signal(SceneStringNames::get_singleton()->visibility_changed);
} break;
diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h
index 08fea52c3a..c0558b6be2 100644
--- a/scene/main/canvas_item.h
+++ b/scene/main/canvas_item.h
@@ -32,10 +32,8 @@
#define CANVAS_ITEM_H
#include "scene/main/node.h"
-#include "scene/main/scene_tree.h"
#include "scene/resources/canvas_item_material.h"
#include "scene/resources/font.h"
-#include "servers/text_server.h"
class CanvasLayer;
class MultiMesh;
@@ -87,6 +85,7 @@ private:
Window *window = nullptr;
bool first_draw = false;
bool visible = true;
+ bool parent_visible_in_tree = false;
bool clip_children = false;
bool pending_update = false;
bool top_level = false;
@@ -109,7 +108,7 @@ private:
void _top_level_raise_self();
- void _propagate_visibility_changed(bool p_visible);
+ void _propagate_visibility_changed(bool p_visible, bool p_is_source = false);
void _update_callback();
diff --git a/scene/main/canvas_layer.cpp b/scene/main/canvas_layer.cpp
index 3f3e72357b..be24620904 100644
--- a/scene/main/canvas_layer.cpp
+++ b/scene/main/canvas_layer.cpp
@@ -29,8 +29,10 @@
/*************************************************************************/
#include "canvas_layer.h"
-#include "canvas_item.h"
-#include "viewport.h"
+
+#include "scene/main/canvas_item.h"
+#include "scene/main/viewport.h"
+#include "scene/resources/world_2d.h"
void CanvasLayer::set_layer(int p_xform) {
layer = p_xform;
@@ -59,12 +61,20 @@ void CanvasLayer::set_visible(bool p_visible) {
if (c->is_visible()) {
c->_propagate_visibility_changed(p_visible);
} else {
- c->notification(CanvasItem::NOTIFICATION_VISIBILITY_CHANGED);
+ c->parent_visible_in_tree = p_visible;
}
}
}
}
+void CanvasLayer::show() {
+ set_visible(true);
+}
+
+void CanvasLayer::hide() {
+ set_visible(false);
+}
+
bool CanvasLayer::is_visible() const {
return visible;
}
@@ -164,8 +174,8 @@ void CanvasLayer::_notification(int p_what) {
RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index());
RenderingServer::get_singleton()->viewport_set_canvas_transform(viewport, canvas, transform);
_update_follow_viewport();
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
ERR_FAIL_NULL_MSG(vp, "Viewport is not initialized.");
@@ -173,13 +183,12 @@ void CanvasLayer::_notification(int p_what) {
RenderingServer::get_singleton()->viewport_remove_canvas(viewport, canvas);
viewport = RID();
_update_follow_viewport(false);
-
} break;
+
case NOTIFICATION_MOVED_IN_PARENT: {
if (is_inside_tree()) {
RenderingServer::get_singleton()->viewport_set_canvas_stacking(viewport, canvas, layer, get_index());
}
-
} break;
}
}
@@ -293,6 +302,8 @@ void CanvasLayer::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_visible", "visible"), &CanvasLayer::set_visible);
ClassDB::bind_method(D_METHOD("is_visible"), &CanvasLayer::is_visible);
+ ClassDB::bind_method(D_METHOD("show"), &CanvasLayer::show);
+ ClassDB::bind_method(D_METHOD("hide"), &CanvasLayer::hide);
ClassDB::bind_method(D_METHOD("set_transform", "transform"), &CanvasLayer::set_transform);
ClassDB::bind_method(D_METHOD("get_transform"), &CanvasLayer::get_transform);
diff --git a/scene/main/canvas_layer.h b/scene/main/canvas_layer.h
index b7bd793440..2493675b31 100644
--- a/scene/main/canvas_layer.h
+++ b/scene/main/canvas_layer.h
@@ -72,6 +72,8 @@ public:
void set_visible(bool p_visible);
bool is_visible() const;
+ void show();
+ void hide();
void set_transform(const Transform2D &p_xform);
Transform2D get_transform() const;
diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp
index 4e91548d14..700ba761f6 100644
--- a/scene/main/http_request.cpp
+++ b/scene/main/http_request.cpp
@@ -464,20 +464,22 @@ void HTTPRequest::_request_done(int p_status, int p_code, const PackedStringArra
}
void HTTPRequest::_notification(int p_what) {
- if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
- if (use_threads.is_set()) {
- return;
- }
- bool done = _update_connection();
- if (done) {
- set_process_internal(false);
- }
- }
+ switch (p_what) {
+ case NOTIFICATION_INTERNAL_PROCESS: {
+ if (use_threads.is_set()) {
+ return;
+ }
+ bool done = _update_connection();
+ if (done) {
+ set_process_internal(false);
+ }
+ } break;
- if (p_what == NOTIFICATION_EXIT_TREE) {
- if (requesting) {
- cancel_request();
- }
+ case NOTIFICATION_EXIT_TREE: {
+ if (requesting) {
+ cancel_request();
+ }
+ } break;
}
}
diff --git a/scene/main/node.cpp b/scene/main/node.cpp
index 6b9d8ab211..211667ce38 100644
--- a/scene/main/node.cpp
+++ b/scene/main/node.cpp
@@ -30,6 +30,7 @@
#include "node.h"
+#include "core/config/project_settings.h"
#include "core/core_string_names.h"
#include "core/io/resource_loader.h"
#include "core/multiplayer/multiplayer_api.h"
@@ -53,12 +54,12 @@ void Node::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_PROCESS: {
GDVIRTUAL_CALL(_process, get_process_delta_time());
-
} break;
+
case NOTIFICATION_PHYSICS_PROCESS: {
GDVIRTUAL_CALL(_physics_process, get_physics_process_delta_time());
-
} break;
+
case NOTIFICATION_ENTER_TREE: {
ERR_FAIL_COND(!get_viewport());
ERR_FAIL_COND(!get_tree());
@@ -87,8 +88,8 @@ void Node::_notification(int p_notification) {
get_tree()->node_count++;
orphan_node_count--;
-
} break;
+
case NOTIFICATION_EXIT_TREE: {
ERR_FAIL_COND(!get_viewport());
ERR_FAIL_COND(!get_tree());
@@ -112,12 +113,14 @@ void Node::_notification(int p_notification) {
data.path_cache = nullptr;
}
} break;
+
case NOTIFICATION_PATH_RENAMED: {
if (data.path_cache) {
memdelete(data.path_cache);
data.path_cache = nullptr;
}
} break;
+
case NOTIFICATION_READY: {
if (GDVIRTUAL_IS_OVERRIDDEN(_input)) {
set_process_input(true);
@@ -140,9 +143,11 @@ void Node::_notification(int p_notification) {
GDVIRTUAL_CALL(_ready);
} break;
+
case NOTIFICATION_POSTINITIALIZE: {
data.in_constructor = false;
} break;
+
case NOTIFICATION_PREDELETE: {
if (data.parent) {
data.parent->remove_child(this);
@@ -612,14 +617,15 @@ Variant Node::_rpc_bind(const Variant **p_args, int p_argcount, Callable::CallEr
return Variant();
}
- if (p_args[0]->get_type() != Variant::STRING_NAME) {
+ Variant::Type type = p_args[0]->get_type();
+ if (type != Variant::STRING_NAME && type != Variant::STRING) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 0;
r_error.expected = Variant::STRING_NAME;
return Variant();
}
- StringName method = *p_args[0];
+ StringName method = (*p_args[0]).operator StringName();
rpcp(0, method, &p_args[1], p_argcount - 1);
@@ -641,7 +647,8 @@ Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::Cal
return Variant();
}
- if (p_args[1]->get_type() != Variant::STRING_NAME) {
+ Variant::Type type = p_args[1]->get_type();
+ if (type != Variant::STRING_NAME && type != Variant::STRING) {
r_error.error = Callable::CallError::CALL_ERROR_INVALID_ARGUMENT;
r_error.argument = 1;
r_error.expected = Variant::STRING_NAME;
@@ -649,7 +656,7 @@ Variant Node::_rpc_id_bind(const Variant **p_args, int p_argcount, Callable::Cal
}
int peer_id = *p_args[0];
- StringName method = *p_args[1];
+ StringName method = (*p_args[1]).operator StringName();
rpcp(peer_id, method, &p_args[2], p_argcount - 2);
@@ -1337,27 +1344,45 @@ bool Node::has_node(const NodePath &p_path) const {
return get_node_or_null(p_path) != nullptr;
}
-Node *Node::find_node(const String &p_mask, bool p_recursive, bool p_owned) const {
+TypedArray<Node> Node::find_nodes(const String &p_mask, const String &p_type, bool p_recursive, bool p_owned) const {
+ TypedArray<Node> ret;
+ ERR_FAIL_COND_V(p_mask.is_empty() && p_type.is_empty(), ret);
+
Node *const *cptr = data.children.ptr();
int ccount = data.children.size();
for (int i = 0; i < ccount; i++) {
if (p_owned && !cptr[i]->data.owner) {
continue;
}
- if (cptr[i]->data.name.operator String().match(p_mask)) {
- return cptr[i];
+
+ if (!p_mask.is_empty()) {
+ if (!cptr[i]->data.name.operator String().match(p_mask)) {
+ continue;
+ } else if (p_type.is_empty()) {
+ ret.append(cptr[i]);
+ }
}
- if (!p_recursive) {
- continue;
+ if (cptr[i]->is_class(p_type)) {
+ ret.append(cptr[i]);
+ } else if (cptr[i]->get_script_instance()) {
+ Ref<Script> script = cptr[i]->get_script_instance()->get_script();
+ while (script.is_valid()) {
+ if ((ScriptServer::is_global_class(p_type) && ScriptServer::get_global_class_path(p_type) == script->get_path()) || p_type == script->get_path()) {
+ ret.append(cptr[i]);
+ break;
+ }
+
+ script = script->get_base_script();
+ }
}
- Node *ret = cptr[i]->find_node(p_mask, true, p_owned);
- if (ret) {
- return ret;
+ if (p_recursive) {
+ ret.append_array(cptr[i]->find_nodes(p_mask, p_type, true, p_owned));
}
}
- return nullptr;
+
+ return ret;
}
Node *Node::get_parent() const {
@@ -2699,7 +2724,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_node", "path"), &Node::get_node);
ClassDB::bind_method(D_METHOD("get_node_or_null", "path"), &Node::get_node_or_null);
ClassDB::bind_method(D_METHOD("get_parent"), &Node::get_parent);
- ClassDB::bind_method(D_METHOD("find_node", "mask", "recursive", "owned"), &Node::find_node, DEFVAL(true), DEFVAL(true));
+ ClassDB::bind_method(D_METHOD("find_nodes", "mask", "type", "recursive", "owned"), &Node::find_nodes, DEFVAL(""), DEFVAL(true), DEFVAL(true));
ClassDB::bind_method(D_METHOD("find_parent", "mask"), &Node::find_parent);
ClassDB::bind_method(D_METHOD("has_node_and_resource", "path"), &Node::has_node_and_resource);
ClassDB::bind_method(D_METHOD("get_node_and_resource", "path"), &Node::_get_node_and_resource);
@@ -2838,6 +2863,9 @@ void Node::_bind_methods() {
BIND_CONSTANT(NOTIFICATION_WM_CLOSE_REQUEST);
BIND_CONSTANT(NOTIFICATION_WM_GO_BACK_REQUEST);
BIND_CONSTANT(NOTIFICATION_WM_SIZE_CHANGED);
+ BIND_CONSTANT(NOTIFICATION_WM_DPI_CHANGE);
+ BIND_CONSTANT(NOTIFICATION_VP_MOUSE_ENTER);
+ BIND_CONSTANT(NOTIFICATION_VP_MOUSE_EXIT);
BIND_CONSTANT(NOTIFICATION_OS_MEMORY_WARNING);
BIND_CONSTANT(NOTIFICATION_TRANSLATION_CHANGED);
BIND_CONSTANT(NOTIFICATION_WM_ABOUT);
diff --git a/scene/main/node.h b/scene/main/node.h
index 0ac10f4381..8e49f871a7 100644
--- a/scene/main/node.h
+++ b/scene/main/node.h
@@ -31,9 +31,6 @@
#ifndef NODE_H
#define NODE_H
-#include "core/config/project_settings.h"
-#include "core/object/class_db.h"
-#include "core/object/script_language.h"
#include "core/string/node_path.h"
#include "core/templates/map.h"
#include "core/variant/typed_array.h"
@@ -271,6 +268,8 @@ public:
NOTIFICATION_WM_GO_BACK_REQUEST = 1007,
NOTIFICATION_WM_SIZE_CHANGED = 1008,
NOTIFICATION_WM_DPI_CHANGE = 1009,
+ NOTIFICATION_VP_MOUSE_ENTER = 1010,
+ NOTIFICATION_VP_MOUSE_EXIT = 1011,
NOTIFICATION_OS_MEMORY_WARNING = MainLoop::NOTIFICATION_OS_MEMORY_WARNING,
NOTIFICATION_TRANSLATION_CHANGED = MainLoop::NOTIFICATION_TRANSLATION_CHANGED,
@@ -302,7 +301,7 @@ public:
bool has_node(const NodePath &p_path) const;
Node *get_node(const NodePath &p_path) const;
Node *get_node_or_null(const NodePath &p_path) const;
- Node *find_node(const String &p_mask, bool p_recursive = true, bool p_owned = true) const;
+ TypedArray<Node> find_nodes(const String &p_mask, const String &p_type = "", bool p_recursive = true, bool p_owned = true) const;
bool has_node_and_resource(const NodePath &p_path) const;
Node *get_node_and_resource(const NodePath &p_path, RES &r_res, Vector<StringName> &r_leftover_subpath, bool p_last_is_property = true) const;
diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp
index 0e4a6a4b5c..2b4d7d8331 100644
--- a/scene/main/scene_tree.cpp
+++ b/scene/main/scene_tree.cpp
@@ -44,10 +44,13 @@
#include "node.h"
#include "scene/animation/tween.h"
#include "scene/debugger/scene_debugger.h"
+#include "scene/main/viewport.h"
#include "scene/resources/font.h"
#include "scene/resources/material.h"
#include "scene/resources/mesh.h"
#include "scene/resources/packed_scene.h"
+#include "scene/resources/world_2d.h"
+#include "scene/resources/world_3d.h"
#include "scene/scene_string_names.h"
#include "servers/display_server.h"
#include "servers/navigation_server_3d.h"
@@ -613,6 +616,7 @@ void SceneTree::_notification(int p_notification) {
get_root()->propagate_notification(p_notification);
}
} break;
+
case NOTIFICATION_OS_MEMORY_WARNING:
case NOTIFICATION_OS_IME_UPDATE:
case NOTIFICATION_WM_ABOUT:
@@ -621,13 +625,11 @@ void SceneTree::_notification(int p_notification) {
case NOTIFICATION_APPLICATION_PAUSED:
case NOTIFICATION_APPLICATION_FOCUS_IN:
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
- get_root()->propagate_notification(p_notification); //pass these to nodes, since they are mirrored
+ // Pass these to nodes, since they are mirrored.
+ get_root()->propagate_notification(p_notification);
} break;
-
- default:
- break;
- };
-};
+ }
+}
void SceneTree::set_auto_accept_quit(bool p_enable) {
accept_quit = p_enable;
@@ -1165,7 +1167,7 @@ void SceneTree::set_multiplayer(Ref<MultiplayerAPI> p_multiplayer) {
ERR_FAIL_COND(!p_multiplayer.is_valid());
multiplayer = p_multiplayer;
- multiplayer->set_root_node(root);
+ multiplayer->set_root_path("/" + root->get_name());
}
void SceneTree::_bind_methods() {
diff --git a/scene/main/scene_tree.h b/scene/main/scene_tree.h
index a5cd52b4ca..5f7c1729e8 100644
--- a/scene/main/scene_tree.h
+++ b/scene/main/scene_tree.h
@@ -35,8 +35,6 @@
#include "core/os/thread_safe.h"
#include "core/templates/self_list.h"
#include "scene/resources/mesh.h"
-#include "scene/resources/world_2d.h"
-#include "scene/resources/world_3d.h"
#undef Window
@@ -48,6 +46,7 @@ class Mesh;
class MultiplayerAPI;
class SceneDebugger;
class Tween;
+class Viewport;
class SceneTreeTimer : public RefCounted {
GDCLASS(SceneTreeTimer, RefCounted);
diff --git a/scene/main/shader_globals_override.cpp b/scene/main/shader_globals_override.cpp
index 240e662efb..5387dc01e2 100644
--- a/scene/main/shader_globals_override.cpp
+++ b/scene/main/shader_globals_override.cpp
@@ -221,6 +221,7 @@ void ShaderGlobalsOverride::_get_property_list(List<PropertyInfo> *p_list) const
}
void ShaderGlobalsOverride::_activate() {
+ ERR_FAIL_NULL(get_tree());
List<Node *> nodes;
get_tree()->get_nodes_in_group(SceneStringNames::get_singleton()->shader_overrides_group_active, &nodes);
if (nodes.size() == 0) {
@@ -246,26 +247,29 @@ void ShaderGlobalsOverride::_activate() {
}
void ShaderGlobalsOverride::_notification(int p_what) {
- if (p_what == Node3D::NOTIFICATION_ENTER_TREE) {
- add_to_group(SceneStringNames::get_singleton()->shader_overrides_group);
- _activate();
+ switch (p_what) {
+ case Node3D::NOTIFICATION_ENTER_TREE: {
+ add_to_group(SceneStringNames::get_singleton()->shader_overrides_group);
+ _activate();
+ } break;
- } else if (p_what == Node3D::NOTIFICATION_EXIT_TREE) {
- if (active) {
- //remove overrides
- const StringName *K = nullptr;
- while ((K = overrides.next(K))) {
- Override *o = overrides.getptr(*K);
- if (o->in_use) {
- RS::get_singleton()->global_variable_set_override(*K, Variant());
+ case Node3D::NOTIFICATION_EXIT_TREE: {
+ if (active) {
+ //remove overrides
+ const StringName *K = nullptr;
+ while ((K = overrides.next(K))) {
+ Override *o = overrides.getptr(*K);
+ if (o->in_use) {
+ RS::get_singleton()->global_variable_set_override(*K, Variant());
+ }
}
}
- }
- remove_from_group(SceneStringNames::get_singleton()->shader_overrides_group_active);
- remove_from_group(SceneStringNames::get_singleton()->shader_overrides_group);
- get_tree()->call_group(SceneStringNames::get_singleton()->shader_overrides_group, "_activate"); //another may want to activate when this is removed
- active = false;
+ remove_from_group(SceneStringNames::get_singleton()->shader_overrides_group_active);
+ remove_from_group(SceneStringNames::get_singleton()->shader_overrides_group);
+ get_tree()->call_group(SceneStringNames::get_singleton()->shader_overrides_group, "_activate"); //another may want to activate when this is removed
+ active = false;
+ } break;
}
}
diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp
index babe62f453..120b537e4f 100644
--- a/scene/main/timer.cpp
+++ b/scene/main/timer.cpp
@@ -43,6 +43,7 @@ void Timer::_notification(int p_what) {
autostart = false;
}
} break;
+
case NOTIFICATION_INTERNAL_PROCESS: {
if (!processing || timer_process_callback == TIMER_PROCESS_PHYSICS || !is_processing_internal()) {
return;
@@ -58,8 +59,8 @@ void Timer::_notification(int p_what) {
emit_signal(SNAME("timeout"));
}
-
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!processing || timer_process_callback == TIMER_PROCESS_IDLE || !is_physics_processing_internal()) {
return;
@@ -74,7 +75,6 @@ void Timer::_notification(int p_what) {
}
emit_signal(SNAME("timeout"));
}
-
} break;
}
}
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 522997cdf5..ca817b17bc 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -30,6 +30,7 @@
#include "viewport.h"
+#include "core/config/project_settings.h"
#include "core/core_string_names.h"
#include "core/debugger/engine_debugger.h"
#include "core/object/message_queue.h"
@@ -405,8 +406,8 @@ void Viewport::_notification(int p_what) {
#endif // _3D_DISABLED
set_physics_process_internal(true);
}
-
} break;
+
case NOTIFICATION_READY: {
#ifndef _3D_DISABLED
if (audio_listener_3d_set.size() && !audio_listener_3d) {
@@ -437,6 +438,7 @@ void Viewport::_notification(int p_what) {
}
#endif // _3D_DISABLED
} break;
+
case NOTIFICATION_EXIT_TREE: {
_gui_cancel_tooltip();
@@ -460,6 +462,7 @@ void Viewport::_notification(int p_what) {
RS::get_singleton()->viewport_set_active(viewport, false);
RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, RID());
} break;
+
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!get_tree()) {
return;
@@ -492,17 +495,20 @@ void Viewport::_notification(int p_what) {
}
#endif // _3D_DISABLED
} break;
- case NOTIFICATION_WM_MOUSE_ENTER: {
- gui.mouse_in_window = true;
+
+ case NOTIFICATION_VP_MOUSE_ENTER: {
+ gui.mouse_in_viewport = true;
} break;
- case NOTIFICATION_WM_MOUSE_EXIT: {
- gui.mouse_in_window = false;
+
+ case NOTIFICATION_VP_MOUSE_EXIT: {
+ gui.mouse_in_viewport = false;
_drop_physics_mouseover();
_drop_mouse_over();
- // When the mouse exits the window, we want to end mouse_over, but
+ // When the mouse exits the viewport, we want to end mouse_over, but
// not mouse_focus, because, for example, we want to continue
- // dragging a scrollbar even if the mouse has left the window.
+ // dragging a scrollbar even if the mouse has left the viewport.
} break;
+
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
_drop_physics_mouseover();
if (gui.mouse_focus && !gui.forced_mouse_focus) {
@@ -1677,7 +1683,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
Control *over = nullptr;
if (gui.mouse_focus) {
over = gui.mouse_focus;
- } else if (gui.mouse_in_window) {
+ } else if (gui.mouse_in_viewport) {
over = gui_find_control(mpos);
}
@@ -1713,7 +1719,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) {
if (gui.tooltip_popup) {
if (gui.tooltip_control) {
String tooltip = _gui_get_tooltip(over, gui.tooltip_control->get_global_transform().xform_inv(mpos));
-
+ tooltip = tooltip.strip_edges();
if (tooltip.length() == 0) {
_gui_cancel_tooltip();
} else if (gui.tooltip_label) {
@@ -3938,11 +3944,14 @@ Transform2D SubViewport::_stretch_transform() {
}
void SubViewport::_notification(int p_what) {
- if (p_what == NOTIFICATION_ENTER_TREE) {
- RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
- }
- if (p_what == NOTIFICATION_EXIT_TREE) {
- RS::get_singleton()->viewport_set_active(get_viewport_rid(), false);
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
+ RS::get_singleton()->viewport_set_active(get_viewport_rid(), false);
+ } break;
}
}
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 3a71745f44..93e42f1838 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -335,7 +335,7 @@ private:
// info used when this is a window
bool forced_mouse_focus = false; //used for menu buttons
- bool mouse_in_window = true;
+ bool mouse_in_viewport = true;
bool key_event_accepted = false;
Control *mouse_focus = nullptr;
Control *last_mouse_focus = nullptr;
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index f2ebe50fa3..0ce556d36c 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -30,6 +30,7 @@
#include "window.h"
+#include "core/config/project_settings.h"
#include "core/debugger/engine_debugger.h"
#include "core/string/translation.h"
#include "scene/gui/control.h"
@@ -254,6 +255,7 @@ void Window::_make_window() {
#endif
DisplayServer::get_singleton()->window_set_title(tr_title, window_id);
DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
+ DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
_update_window_size();
@@ -338,9 +340,11 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
case DisplayServer::WINDOW_EVENT_MOUSE_ENTER: {
_propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER);
emit_signal(SNAME("mouse_entered"));
+ notification(NOTIFICATION_VP_MOUSE_ENTER);
DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CURSOR_ARROW); //restore cursor shape
} break;
case DisplayServer::WINDOW_EVENT_MOUSE_EXIT: {
+ notification(NOTIFICATION_VP_MOUSE_EXIT);
_propagate_window_notification(this, NOTIFICATION_WM_MOUSE_EXIT);
emit_signal(SNAME("mouse_exited"));
} break;
@@ -522,6 +526,10 @@ void Window::set_exclusive(bool p_exclusive) {
exclusive = p_exclusive;
+ if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID) {
+ DisplayServer::get_singleton()->window_set_exclusive(window_id, exclusive);
+ }
+
if (transient_parent) {
if (p_exclusive && is_inside_tree() && is_visible()) {
ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child.");
@@ -732,18 +740,16 @@ void Window::_notification(int p_what) {
bool embedded = false;
{
embedder = _get_embedder();
-
if (embedder) {
embedded = true;
-
if (!visible) {
- embedder = nullptr; //not yet since not visible
+ embedder = nullptr; // Not yet since not visible.
}
}
}
if (embedded) {
- //create as embedded
+ // Create as embedded.
if (embedder) {
embedder->_sub_window_register(this);
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
@@ -751,22 +757,22 @@ void Window::_notification(int p_what) {
}
} else {
- if (get_parent() == nullptr) {
- //it's the root window!
- visible = true; //always visible
+ if (!get_parent()) {
+ // It's the root window!
+ visible = true; // Always visible.
window_id = DisplayServer::MAIN_WINDOW_ID;
DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
_update_from_window();
- //since this window already exists (created on start), we must update pos and size from it
+ // Since this window already exists (created on start), we must update pos and size from it.
{
position = DisplayServer::get_singleton()->window_get_position(window_id);
size = DisplayServer::get_singleton()->window_get_size(window_id);
}
- _update_viewport_size(); //then feed back to the viewport
+ _update_viewport_size(); // Then feed back to the viewport.
_update_window_callbacks();
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
} else {
- //create
+ // Create.
if (visible) {
_make_window();
}
@@ -782,11 +788,13 @@ void Window::_notification(int p_what) {
RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
}
} break;
+
case NOTIFICATION_READY: {
if (wrap_controls) {
_update_child_controls();
}
} break;
+
case NOTIFICATION_TRANSLATION_CHANGED: {
if (embedder) {
embedder->_sub_window_update(this);
@@ -805,6 +813,7 @@ void Window::_notification(int p_what) {
child_controls_changed();
} break;
+
case NOTIFICATION_EXIT_TREE: {
if (transient) {
_clear_transient();
diff --git a/scene/multiplayer/multiplayer_spawner.cpp b/scene/multiplayer/multiplayer_spawner.cpp
index 4f2a9d9e83..25ab27f3e7 100644
--- a/scene/multiplayer/multiplayer_spawner.cpp
+++ b/scene/multiplayer/multiplayer_spawner.cpp
@@ -84,22 +84,26 @@ void MultiplayerSpawner::_update_spawn_node() {
}
void MultiplayerSpawner::_notification(int p_what) {
- if (p_what == NOTIFICATION_POST_ENTER_TREE) {
- _update_spawn_node();
- } else if (p_what == NOTIFICATION_EXIT_TREE) {
- _update_spawn_node();
- const ObjectID *oid = nullptr;
- while ((oid = tracked_nodes.next(oid))) {
- Node *node = Object::cast_to<Node>(ObjectDB::get_instance(*oid));
- ERR_CONTINUE(!node);
- node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &MultiplayerSpawner::_node_exit));
- // This is unlikely, but might still crash the engine.
- if (node->is_connected(SceneStringNames::get_singleton()->ready, callable_mp(this, &MultiplayerSpawner::_node_ready))) {
- node->disconnect(SceneStringNames::get_singleton()->ready, callable_mp(this, &MultiplayerSpawner::_node_ready));
+ switch (p_what) {
+ case NOTIFICATION_POST_ENTER_TREE: {
+ _update_spawn_node();
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
+ _update_spawn_node();
+ const ObjectID *oid = nullptr;
+ while ((oid = tracked_nodes.next(oid))) {
+ Node *node = Object::cast_to<Node>(ObjectDB::get_instance(*oid));
+ ERR_CONTINUE(!node);
+ node->disconnect(SceneStringNames::get_singleton()->tree_exiting, callable_mp(this, &MultiplayerSpawner::_node_exit));
+ // This is unlikely, but might still crash the engine.
+ if (node->is_connected(SceneStringNames::get_singleton()->ready, callable_mp(this, &MultiplayerSpawner::_node_ready))) {
+ node->disconnect(SceneStringNames::get_singleton()->ready, callable_mp(this, &MultiplayerSpawner::_node_ready));
+ }
+ get_multiplayer()->despawn(node, this);
}
- get_multiplayer()->despawn(node, this);
- }
- tracked_nodes.clear();
+ tracked_nodes.clear();
+ } break;
}
}
diff --git a/scene/multiplayer/multiplayer_synchronizer.cpp b/scene/multiplayer/multiplayer_synchronizer.cpp
index fbe1b99cc9..33e845a7a3 100644
--- a/scene/multiplayer/multiplayer_synchronizer.cpp
+++ b/scene/multiplayer/multiplayer_synchronizer.cpp
@@ -108,10 +108,15 @@ void MultiplayerSynchronizer::_notification(int p_what) {
if (root_path.is_empty()) {
return;
}
- if (p_what == NOTIFICATION_ENTER_TREE) {
- _start();
- } else if (p_what == NOTIFICATION_EXIT_TREE) {
- _stop();
+
+ switch (p_what) {
+ case NOTIFICATION_ENTER_TREE: {
+ _start();
+ } break;
+
+ case NOTIFICATION_EXIT_TREE: {
+ _stop();
+ } break;
}
}
diff --git a/scene/multiplayer/scene_cache_interface.cpp b/scene/multiplayer/scene_cache_interface.cpp
new file mode 100644
index 0000000000..f05dc5a2da
--- /dev/null
+++ b/scene/multiplayer/scene_cache_interface.cpp
@@ -0,0 +1,265 @@
+/*************************************************************************/
+/* scene_cache_interface.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "scene_cache_interface.h"
+
+#include "core/io/marshalls.h"
+#include "scene/main/node.h"
+#include "scene/main/window.h"
+
+MultiplayerCacheInterface *SceneCacheInterface::_create(MultiplayerAPI *p_multiplayer) {
+ return memnew(SceneCacheInterface(p_multiplayer));
+}
+
+void SceneCacheInterface::make_default() {
+ MultiplayerAPI::create_default_cache_interface = _create;
+}
+
+void SceneCacheInterface::on_peer_change(int p_id, bool p_connected) {
+ if (p_connected) {
+ path_get_cache.insert(p_id, PathGetCache());
+ } else {
+ // Cleanup get cache.
+ path_get_cache.erase(p_id);
+ // Cleanup sent cache.
+ // Some refactoring is needed to make this faster and do paths GC.
+ List<NodePath> keys;
+ path_send_cache.get_key_list(&keys);
+ for (const NodePath &E : keys) {
+ PathSentCache *psc = path_send_cache.getptr(E);
+ psc->confirmed_peers.erase(p_id);
+ }
+ }
+}
+
+void SceneCacheInterface::process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ Node *root_node = SceneTree::get_singleton()->get_root()->get_node(multiplayer->get_root_path());
+ ERR_FAIL_COND(!root_node);
+ ERR_FAIL_COND_MSG(p_packet_len < 38, "Invalid packet received. Size too small.");
+ int ofs = 1;
+
+ String methods_md5;
+ methods_md5.parse_utf8((const char *)(p_packet + ofs), 32);
+ ofs += 33;
+
+ int id = decode_uint32(&p_packet[ofs]);
+ ofs += 4;
+
+ String paths;
+ paths.parse_utf8((const char *)(p_packet + ofs), p_packet_len - ofs);
+
+ NodePath path = paths;
+
+ if (!path_get_cache.has(p_from)) {
+ path_get_cache[p_from] = PathGetCache();
+ }
+
+ Node *node = root_node->get_node(path);
+ ERR_FAIL_COND(node == nullptr);
+ const bool valid_rpc_checksum = multiplayer->get_rpc_md5(node) == methods_md5;
+ if (valid_rpc_checksum == false) {
+ ERR_PRINT("The rpc node checksum failed. Make sure to have the same methods on both nodes. Node path: " + path);
+ }
+
+ PathGetCache::NodeInfo ni;
+ ni.path = path;
+
+ path_get_cache[p_from].nodes[id] = ni;
+
+ // Encode path to send ack.
+ CharString pname = String(path).utf8();
+ int len = encode_cstring(pname.get_data(), nullptr);
+
+ Vector<uint8_t> packet;
+
+ packet.resize(1 + 1 + len);
+ packet.write[0] = MultiplayerAPI::NETWORK_COMMAND_CONFIRM_PATH;
+ packet.write[1] = valid_rpc_checksum;
+ encode_cstring(pname.get_data(), &packet.write[2]);
+
+ Ref<MultiplayerPeer> multiplayer_peer = multiplayer->get_multiplayer_peer();
+ ERR_FAIL_COND(multiplayer_peer.is_null());
+
+#ifdef DEBUG_ENABLED
+ multiplayer->profile_bandwidth("out", packet.size());
+#endif
+
+ multiplayer_peer->set_transfer_channel(0);
+ multiplayer_peer->set_transfer_mode(Multiplayer::TRANSFER_MODE_RELIABLE);
+ multiplayer_peer->set_target_peer(p_from);
+ multiplayer_peer->put_packet(packet.ptr(), packet.size());
+}
+
+void SceneCacheInterface::process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ ERR_FAIL_COND_MSG(p_packet_len < 3, "Invalid packet received. Size too small.");
+
+ const bool valid_rpc_checksum = p_packet[1];
+
+ String paths;
+ paths.parse_utf8((const char *)&p_packet[2], p_packet_len - 2);
+
+ NodePath path = paths;
+
+ if (valid_rpc_checksum == false) {
+ ERR_PRINT("The rpc node checksum failed. Make sure to have the same methods on both nodes. Node path: " + path);
+ }
+
+ PathSentCache *psc = path_send_cache.getptr(path);
+ ERR_FAIL_COND_MSG(!psc, "Invalid packet received. Tries to confirm a path which was not found in cache.");
+
+ Map<int, bool>::Element *E = psc->confirmed_peers.find(p_from);
+ ERR_FAIL_COND_MSG(!E, "Invalid packet received. Source peer was not found in cache for the given path.");
+ E->get() = true;
+}
+
+Error SceneCacheInterface::_send_confirm_path(Node *p_node, NodePath p_path, PathSentCache *psc, const List<int> &p_peers) {
+ // Encode function name.
+ const CharString path = String(p_path).utf8();
+ const int path_len = encode_cstring(path.get_data(), nullptr);
+
+ // Extract MD5 from rpc methods list.
+ const String methods_md5 = multiplayer->get_rpc_md5(p_node);
+ const int methods_md5_len = 33; // 32 + 1 for the `0` that is added by the encoder.
+
+ Vector<uint8_t> packet;
+ packet.resize(1 + 4 + path_len + methods_md5_len);
+ int ofs = 0;
+
+ packet.write[ofs] = MultiplayerAPI::NETWORK_COMMAND_SIMPLIFY_PATH;
+ ofs += 1;
+
+ ofs += encode_cstring(methods_md5.utf8().get_data(), &packet.write[ofs]);
+
+ ofs += encode_uint32(psc->id, &packet.write[ofs]);
+
+ ofs += encode_cstring(path.get_data(), &packet.write[ofs]);
+
+ Ref<MultiplayerPeer> multiplayer_peer = multiplayer->get_multiplayer_peer();
+ ERR_FAIL_COND_V(multiplayer_peer.is_null(), ERR_BUG);
+
+#ifdef DEBUG_ENABLED
+ multiplayer->profile_bandwidth("out", packet.size() * p_peers.size());
+#endif
+
+ Error err = OK;
+ for (int peer_id : p_peers) {
+ multiplayer_peer->set_target_peer(peer_id);
+ multiplayer_peer->set_transfer_channel(0);
+ multiplayer_peer->set_transfer_mode(Multiplayer::TRANSFER_MODE_RELIABLE);
+ err = multiplayer_peer->put_packet(packet.ptr(), packet.size());
+ ERR_FAIL_COND_V(err != OK, err);
+ // Insert into confirmed, but as false since it was not confirmed.
+ psc->confirmed_peers.insert(peer_id, false);
+ }
+ return err;
+}
+
+bool SceneCacheInterface::is_cache_confirmed(NodePath p_path, int p_peer) {
+ const PathSentCache *psc = path_send_cache.getptr(p_path);
+ ERR_FAIL_COND_V(!psc, false);
+ const Map<int, bool>::Element *F = psc->confirmed_peers.find(p_peer);
+ ERR_FAIL_COND_V(!F, false); // Should never happen.
+ return F->get();
+}
+
+bool SceneCacheInterface::send_object_cache(Object *p_obj, NodePath p_path, int p_peer_id, int &r_id) {
+ Node *node = Object::cast_to<Node>(p_obj);
+ ERR_FAIL_COND_V(!node, false);
+ // See if the path is cached.
+ PathSentCache *psc = path_send_cache.getptr(p_path);
+ if (!psc) {
+ // Path is not cached, create.
+ path_send_cache[p_path] = PathSentCache();
+ psc = path_send_cache.getptr(p_path);
+ psc->id = last_send_cache_id++;
+ }
+ r_id = psc->id;
+
+ bool has_all_peers = true;
+ List<int> peers_to_add; // If one is missing, take note to add it.
+
+ if (p_peer_id > 0) {
+ // Fast single peer check.
+ Map<int, bool>::Element *F = psc->confirmed_peers.find(p_peer_id);
+ if (!F) {
+ peers_to_add.push_back(p_peer_id); // Need to also be notified.
+ has_all_peers = false;
+ } else if (!F->get()) {
+ has_all_peers = false;
+ }
+ } else {
+ // Long and painful.
+ for (const Set<int>::Element *E = multiplayer->get_connected_peers().front(); E; E = E->next()) {
+ if (p_peer_id < 0 && E->get() == -p_peer_id) {
+ continue; // Continue, excluded.
+ }
+ if (p_peer_id > 0 && E->get() != p_peer_id) {
+ continue; // Continue, not for this peer.
+ }
+
+ Map<int, bool>::Element *F = psc->confirmed_peers.find(E->get());
+ if (!F) {
+ peers_to_add.push_back(E->get()); // Need to also be notified.
+ has_all_peers = false;
+ } else if (!F->get()) {
+ has_all_peers = false;
+ }
+ }
+ }
+
+ if (peers_to_add.size()) {
+ _send_confirm_path(node, p_path, psc, peers_to_add);
+ }
+
+ return has_all_peers;
+}
+
+Object *SceneCacheInterface::get_cached_object(int p_from, uint32_t p_cache_id) {
+ Node *root_node = SceneTree::get_singleton()->get_root()->get_node(multiplayer->get_root_path());
+ ERR_FAIL_COND_V(!root_node, nullptr);
+ Map<int, PathGetCache>::Element *E = path_get_cache.find(p_from);
+ ERR_FAIL_COND_V_MSG(!E, nullptr, vformat("No cache found for peer %d.", p_from));
+
+ Map<int, PathGetCache::NodeInfo>::Element *F = E->get().nodes.find(p_cache_id);
+ ERR_FAIL_COND_V_MSG(!F, nullptr, vformat("ID %d not found in cache of peer %d.", p_cache_id, p_from));
+
+ PathGetCache::NodeInfo *ni = &F->get();
+ Node *node = root_node->get_node(ni->path);
+ if (!node) {
+ ERR_PRINT("Failed to get cached path: " + String(ni->path) + ".");
+ }
+ return node;
+}
+
+void SceneCacheInterface::clear() {
+ path_get_cache.clear();
+ path_send_cache.clear();
+ last_send_cache_id = 1;
+}
diff --git a/scene/multiplayer/scene_cache_interface.h b/scene/multiplayer/scene_cache_interface.h
new file mode 100644
index 0000000000..c709d26b51
--- /dev/null
+++ b/scene/multiplayer/scene_cache_interface.h
@@ -0,0 +1,82 @@
+/*************************************************************************/
+/* scene_cache_interface.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef SCENE_CACHE_INTERFACE_H
+#define SCENE_CACHE_INTERFACE_H
+
+#include "core/multiplayer/multiplayer_api.h"
+
+class SceneCacheInterface : public MultiplayerCacheInterface {
+ GDCLASS(SceneCacheInterface, MultiplayerCacheInterface);
+
+private:
+ MultiplayerAPI *multiplayer;
+
+ //path sent caches
+ struct PathSentCache {
+ Map<int, bool> confirmed_peers;
+ int id;
+ };
+
+ //path get caches
+ struct PathGetCache {
+ struct NodeInfo {
+ NodePath path;
+ ObjectID instance;
+ };
+
+ Map<int, NodeInfo> nodes;
+ };
+
+ HashMap<NodePath, PathSentCache> path_send_cache;
+ Map<int, PathGetCache> path_get_cache;
+ int last_send_cache_id = 1;
+
+protected:
+ Error _send_confirm_path(Node *p_node, NodePath p_path, PathSentCache *psc, const List<int> &p_peers);
+ static MultiplayerCacheInterface *_create(MultiplayerAPI *p_multiplayer);
+
+public:
+ static void make_default();
+
+ virtual void clear() override;
+ virtual void on_peer_change(int p_id, bool p_connected) override;
+ virtual void process_simplify_path(int p_from, const uint8_t *p_packet, int p_packet_len) override;
+ virtual void process_confirm_path(int p_from, const uint8_t *p_packet, int p_packet_len) override;
+
+ // Returns true if all peers have cached path.
+ virtual bool send_object_cache(Object *p_obj, NodePath p_path, int p_target, int &p_id) override;
+ virtual Object *get_cached_object(int p_from, uint32_t p_cache_id) override;
+ virtual bool is_cache_confirmed(NodePath p_path, int p_peer) override;
+
+ SceneCacheInterface(MultiplayerAPI *p_multiplayer) { multiplayer = p_multiplayer; }
+};
+
+#endif // SCENE_CACHE_INTERFACE_H
diff --git a/scene/multiplayer/scene_replication_interface.cpp b/scene/multiplayer/scene_replication_interface.cpp
index 7155935084..0764f136e4 100644
--- a/scene/multiplayer/scene_replication_interface.cpp
+++ b/scene/multiplayer/scene_replication_interface.cpp
@@ -147,6 +147,11 @@ Error SceneReplicationInterface::_send_raw(const uint8_t *p_buffer, int p_size,
ERR_FAIL_COND_V(!p_buffer || p_size < 1, ERR_INVALID_PARAMETER);
ERR_FAIL_COND_V(!multiplayer, ERR_UNCONFIGURED);
ERR_FAIL_COND_V(!multiplayer->has_multiplayer_peer(), ERR_UNCONFIGURED);
+
+#ifdef DEBUG_ENABLED
+ multiplayer->profile_bandwidth("out", p_size);
+#endif
+
Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer();
peer->set_target_peer(p_peer);
peer->set_transfer_channel(0);
@@ -186,12 +191,10 @@ Error SceneReplicationInterface::_send_spawn(Node *p_node, MultiplayerSpawner *p
}
// Prepare simplified path.
- const Node *root_node = multiplayer->get_root_node();
- ERR_FAIL_COND_V(!root_node, ERR_UNCONFIGURED);
- NodePath rel_path = (root_node->get_path()).rel_path_to(p_spawner->get_path());
+ NodePath rel_path = multiplayer->get_root_path().rel_path_to(p_spawner->get_path());
int path_id = 0;
- multiplayer->send_confirm_path(p_spawner, rel_path, p_peer, path_id);
+ multiplayer->send_object_cache(p_spawner, rel_path, p_peer, path_id);
// Encode name and parent ID.
CharString cname = p_node->get_name().operator String().utf8();
@@ -243,7 +246,7 @@ Error SceneReplicationInterface::on_spawn_receive(int p_from, const uint8_t *p_b
ofs += 1;
uint32_t node_target = decode_uint32(&p_buffer[ofs]);
ofs += 4;
- MultiplayerSpawner *spawner = Object::cast_to<MultiplayerSpawner>(multiplayer->get_cached_node(p_from, node_target));
+ MultiplayerSpawner *spawner = Object::cast_to<MultiplayerSpawner>(multiplayer->get_cached_object(p_from, node_target));
ERR_FAIL_COND_V(!spawner, ERR_DOES_NOT_EXIST);
ERR_FAIL_COND_V(p_from != spawner->get_multiplayer_authority(), ERR_UNAUTHORIZED);
@@ -347,13 +350,12 @@ void SceneReplicationInterface::_send_sync(int p_peer, uint64_t p_msec) {
}
if (size) {
uint32_t net_id = rep_state->get_net_id(oid);
- if (net_id == 0) {
+ if (net_id == 0 || (net_id & 0x80000000)) {
// First time path based ID.
- const Node *root_node = multiplayer->get_root_node();
- ERR_FAIL_COND(!root_node);
- NodePath rel_path = (root_node->get_path()).rel_path_to(sync->get_path());
+ NodePath rel_path = multiplayer->get_root_path().rel_path_to(sync->get_path());
int path_id = 0;
- multiplayer->send_confirm_path(sync, rel_path, p_peer, path_id);
+ multiplayer->send_object_cache(sync, rel_path, p_peer, path_id);
+ ERR_CONTINUE_MSG(net_id && net_id != (uint32_t(path_id) | 0x80000000), "This should never happen!");
net_id = path_id;
rep_state->set_net_id(oid, net_id | 0x80000000);
}
@@ -381,7 +383,7 @@ Error SceneReplicationInterface::on_sync_receive(int p_from, const uint8_t *p_bu
ofs += 4;
Node *node = nullptr;
if (net_id & 0x80000000) {
- MultiplayerSynchronizer *sync = Object::cast_to<MultiplayerSynchronizer>(multiplayer->get_cached_node(p_from, net_id & 0x7FFFFFFF));
+ MultiplayerSynchronizer *sync = Object::cast_to<MultiplayerSynchronizer>(multiplayer->get_cached_object(p_from, net_id & 0x7FFFFFFF));
ERR_FAIL_COND_V(!sync || sync->get_multiplayer_authority() != p_from, ERR_UNAUTHORIZED);
node = sync->get_node(sync->get_root_path());
} else {
diff --git a/scene/multiplayer/scene_rpc_interface.cpp b/scene/multiplayer/scene_rpc_interface.cpp
new file mode 100644
index 0000000000..2239a5d81c
--- /dev/null
+++ b/scene/multiplayer/scene_rpc_interface.cpp
@@ -0,0 +1,511 @@
+/*************************************************************************/
+/* scene_rpc_interface.cpp */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#include "scene/multiplayer/scene_rpc_interface.h"
+
+#include "core/debugger/engine_debugger.h"
+#include "core/io/marshalls.h"
+#include "core/multiplayer/multiplayer_api.h"
+#include "scene/main/node.h"
+#include "scene/main/window.h"
+
+MultiplayerRPCInterface *SceneRPCInterface::_create(MultiplayerAPI *p_multiplayer) {
+ return memnew(SceneRPCInterface(p_multiplayer));
+}
+
+void SceneRPCInterface::make_default() {
+ MultiplayerAPI::create_default_rpc_interface = _create;
+}
+
+#ifdef DEBUG_ENABLED
+_FORCE_INLINE_ void SceneRPCInterface::_profile_node_data(const String &p_what, ObjectID p_id) {
+ if (EngineDebugger::is_profiling("rpc")) {
+ Array values;
+ values.push_back(p_id);
+ values.push_back(p_what);
+ EngineDebugger::profiler_add_frame_data("rpc", values);
+ }
+}
+#else
+_FORCE_INLINE_ void SceneRPCInterface::_profile_node_data(const String &p_what, ObjectID p_id) {}
+#endif
+
+// Returns the packet size stripping the node path added when the node is not yet cached.
+int get_packet_len(uint32_t p_node_target, int p_packet_len) {
+ if (p_node_target & 0x80000000) {
+ int ofs = p_node_target & 0x7FFFFFFF;
+ return p_packet_len - (p_packet_len - ofs);
+ } else {
+ return p_packet_len;
+ }
+}
+
+const Multiplayer::RPCConfig _get_rpc_config(const Node *p_node, const StringName &p_method, uint16_t &r_id) {
+ const Vector<Multiplayer::RPCConfig> node_config = p_node->get_node_rpc_methods();
+ for (int i = 0; i < node_config.size(); i++) {
+ if (node_config[i].name == p_method) {
+ r_id = ((uint16_t)i) | (1 << 15);
+ return node_config[i];
+ }
+ }
+ if (p_node->get_script_instance()) {
+ const Vector<Multiplayer::RPCConfig> script_config = p_node->get_script_instance()->get_rpc_methods();
+ for (int i = 0; i < script_config.size(); i++) {
+ if (script_config[i].name == p_method) {
+ r_id = (uint16_t)i;
+ return script_config[i];
+ }
+ }
+ }
+ return Multiplayer::RPCConfig();
+}
+
+const Multiplayer::RPCConfig _get_rpc_config_by_id(Node *p_node, uint16_t p_id) {
+ Vector<Multiplayer::RPCConfig> config;
+ uint16_t id = p_id;
+ if (id & (1 << 15)) {
+ id = id & ~(1 << 15);
+ config = p_node->get_node_rpc_methods();
+ } else if (p_node->get_script_instance()) {
+ config = p_node->get_script_instance()->get_rpc_methods();
+ }
+ if (id < config.size()) {
+ return config[id];
+ }
+ return Multiplayer::RPCConfig();
+}
+
+_FORCE_INLINE_ bool _can_call_mode(Node *p_node, Multiplayer::RPCMode mode, int p_remote_id) {
+ switch (mode) {
+ case Multiplayer::RPC_MODE_DISABLED: {
+ return false;
+ } break;
+ case Multiplayer::RPC_MODE_ANY_PEER: {
+ return true;
+ } break;
+ case Multiplayer::RPC_MODE_AUTHORITY: {
+ return !p_node->is_multiplayer_authority() && p_remote_id == p_node->get_multiplayer_authority();
+ } break;
+ }
+
+ return false;
+}
+
+String SceneRPCInterface::get_rpc_md5(const Object *p_obj) const {
+ const Node *node = Object::cast_to<Node>(p_obj);
+ ERR_FAIL_COND_V(!node, "");
+ String rpc_list;
+ const Vector<Multiplayer::RPCConfig> node_config = node->get_node_rpc_methods();
+ for (int i = 0; i < node_config.size(); i++) {
+ rpc_list += String(node_config[i].name);
+ }
+ if (node->get_script_instance()) {
+ const Vector<Multiplayer::RPCConfig> script_config = node->get_script_instance()->get_rpc_methods();
+ for (int i = 0; i < script_config.size(); i++) {
+ rpc_list += String(script_config[i].name);
+ }
+ }
+ return rpc_list.md5_text();
+}
+
+Node *SceneRPCInterface::_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len) {
+ Node *root_node = SceneTree::get_singleton()->get_root()->get_node(multiplayer->get_root_path());
+ ERR_FAIL_COND_V(!root_node, nullptr);
+ Node *node = nullptr;
+
+ if (p_node_target & 0x80000000) {
+ // Use full path (not cached yet).
+ int ofs = p_node_target & 0x7FFFFFFF;
+
+ ERR_FAIL_COND_V_MSG(ofs >= p_packet_len, nullptr, "Invalid packet received. Size smaller than declared.");
+
+ String paths;
+ paths.parse_utf8((const char *)&p_packet[ofs], p_packet_len - ofs);
+
+ NodePath np = paths;
+
+ node = root_node->get_node(np);
+
+ if (!node) {
+ ERR_PRINT("Failed to get path from RPC: " + String(np) + ".");
+ }
+ return node;
+ } else {
+ // Use cached path.
+ return Object::cast_to<Node>(multiplayer->get_cached_object(p_from, p_node_target));
+ }
+}
+
+void SceneRPCInterface::process_rpc(int p_from, const uint8_t *p_packet, int p_packet_len) {
+ // Extract packet meta
+ int packet_min_size = 1;
+ int name_id_offset = 1;
+ ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
+ // Compute the meta size, which depends on the compression level.
+ int node_id_compression = (p_packet[0] & NODE_ID_COMPRESSION_FLAG) >> NODE_ID_COMPRESSION_SHIFT;
+ int name_id_compression = (p_packet[0] & NAME_ID_COMPRESSION_FLAG) >> NAME_ID_COMPRESSION_SHIFT;
+
+ switch (node_id_compression) {
+ case NETWORK_NODE_ID_COMPRESSION_8:
+ packet_min_size += 1;
+ name_id_offset += 1;
+ break;
+ case NETWORK_NODE_ID_COMPRESSION_16:
+ packet_min_size += 2;
+ name_id_offset += 2;
+ break;
+ case NETWORK_NODE_ID_COMPRESSION_32:
+ packet_min_size += 4;
+ name_id_offset += 4;
+ break;
+ default:
+ ERR_FAIL_MSG("Was not possible to extract the node id compression mode.");
+ }
+ switch (name_id_compression) {
+ case NETWORK_NAME_ID_COMPRESSION_8:
+ packet_min_size += 1;
+ break;
+ case NETWORK_NAME_ID_COMPRESSION_16:
+ packet_min_size += 2;
+ break;
+ default:
+ ERR_FAIL_MSG("Was not possible to extract the name id compression mode.");
+ }
+ ERR_FAIL_COND_MSG(p_packet_len < packet_min_size, "Invalid packet received. Size too small.");
+
+ uint32_t node_target = 0;
+ switch (node_id_compression) {
+ case NETWORK_NODE_ID_COMPRESSION_8:
+ node_target = p_packet[1];
+ break;
+ case NETWORK_NODE_ID_COMPRESSION_16:
+ node_target = decode_uint16(p_packet + 1);
+ break;
+ case NETWORK_NODE_ID_COMPRESSION_32:
+ node_target = decode_uint32(p_packet + 1);
+ break;
+ default:
+ // Unreachable, checked before.
+ CRASH_NOW();
+ }
+
+ Node *node = _process_get_node(p_from, p_packet, node_target, p_packet_len);
+ ERR_FAIL_COND_MSG(node == nullptr, "Invalid packet received. Requested node was not found.");
+
+ uint16_t name_id = 0;
+ switch (name_id_compression) {
+ case NETWORK_NAME_ID_COMPRESSION_8:
+ name_id = p_packet[name_id_offset];
+ break;
+ case NETWORK_NAME_ID_COMPRESSION_16:
+ name_id = decode_uint16(p_packet + name_id_offset);
+ break;
+ default:
+ // Unreachable, checked before.
+ CRASH_NOW();
+ }
+
+ const int packet_len = get_packet_len(node_target, p_packet_len);
+ _process_rpc(node, name_id, p_from, p_packet, packet_len, packet_min_size);
+}
+
+void SceneRPCInterface::_process_rpc(Node *p_node, const uint16_t p_rpc_method_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset) {
+ ERR_FAIL_COND_MSG(p_offset > p_packet_len, "Invalid packet received. Size too small.");
+
+ // Check that remote can call the RPC on this node.
+ const Multiplayer::RPCConfig config = _get_rpc_config_by_id(p_node, p_rpc_method_id);
+ ERR_FAIL_COND(config.name == StringName());
+
+ bool can_call = _can_call_mode(p_node, config.rpc_mode, p_from);
+ ERR_FAIL_COND_MSG(!can_call, "RPC '" + String(config.name) + "' is not allowed on node " + p_node->get_path() + " from: " + itos(p_from) + ". Mode is " + itos((int)config.rpc_mode) + ", authority is " + itos(p_node->get_multiplayer_authority()) + ".");
+
+ int argc = 0;
+
+ const bool byte_only_or_no_args = p_packet[0] & BYTE_ONLY_OR_NO_ARGS_FLAG;
+ if (byte_only_or_no_args) {
+ if (p_offset < p_packet_len) {
+ // This packet contains only bytes.
+ argc = 1;
+ }
+ } else {
+ // Normal variant, takes the argument count from the packet.
+ ERR_FAIL_COND_MSG(p_offset >= p_packet_len, "Invalid packet received. Size too small.");
+ argc = p_packet[p_offset];
+ p_offset += 1;
+ }
+
+ Vector<Variant> args;
+ Vector<const Variant *> argp;
+ args.resize(argc);
+ argp.resize(argc);
+
+#ifdef DEBUG_ENABLED
+ _profile_node_data("rpc_in", p_node->get_instance_id());
+#endif
+
+ int out;
+ MultiplayerAPI::decode_and_decompress_variants(args, &p_packet[p_offset], p_packet_len - p_offset, out, byte_only_or_no_args, multiplayer->is_object_decoding_allowed());
+ for (int i = 0; i < argc; i++) {
+ argp.write[i] = &args[i];
+ }
+
+ Callable::CallError ce;
+
+ p_node->call(config.name, (const Variant **)argp.ptr(), argc, ce);
+ if (ce.error != Callable::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(p_node, config.name, (const Variant **)argp.ptr(), argc, ce);
+ error = "RPC - " + error;
+ ERR_PRINT(error);
+ }
+}
+
+void SceneRPCInterface::_send_rpc(Node *p_from, int p_to, uint16_t p_rpc_id, const Multiplayer::RPCConfig &p_config, const StringName &p_name, const Variant **p_arg, int p_argcount) {
+ Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer();
+ ERR_FAIL_COND_MSG(peer.is_null(), "Attempt to call RPC without active multiplayer peer.");
+
+ ERR_FAIL_COND_MSG(peer->get_connection_status() == MultiplayerPeer::CONNECTION_CONNECTING, "Attempt to call RPC while multiplayer peer is not connected yet.");
+
+ ERR_FAIL_COND_MSG(peer->get_connection_status() == MultiplayerPeer::CONNECTION_DISCONNECTED, "Attempt to call RPC while multiplayer peer is disconnected.");
+
+ ERR_FAIL_COND_MSG(p_argcount > 255, "Too many arguments (>255).");
+
+ if (p_to != 0 && !multiplayer->get_connected_peers().has(ABS(p_to))) {
+ ERR_FAIL_COND_MSG(p_to == peer->get_unique_id(), "Attempt to call RPC on yourself! Peer unique ID: " + itos(peer->get_unique_id()) + ".");
+
+ ERR_FAIL_MSG("Attempt to call RPC with unknown peer ID: " + itos(p_to) + ".");
+ }
+
+ NodePath from_path = multiplayer->get_root_path().rel_path_to(p_from->get_path());
+ ERR_FAIL_COND_MSG(from_path.is_empty(), "Unable to send RPC. Relative path is empty. THIS IS LIKELY A BUG IN THE ENGINE!");
+
+ // See if all peers have cached path (if so, call can be fast).
+ int psc_id;
+ const bool has_all_peers = multiplayer->send_object_cache(p_from, from_path, p_to, psc_id);
+
+ // Create base packet, lots of hardcode because it must be tight.
+
+ int ofs = 0;
+
+#define MAKE_ROOM(m_amount) \
+ if (packet_cache.size() < m_amount) \
+ packet_cache.resize(m_amount);
+
+ // Encode meta.
+ uint8_t command_type = MultiplayerAPI::NETWORK_COMMAND_REMOTE_CALL;
+ uint8_t node_id_compression = UINT8_MAX;
+ uint8_t name_id_compression = UINT8_MAX;
+ bool byte_only_or_no_args = false;
+
+ MAKE_ROOM(1);
+ // The meta is composed along the way, so just set 0 for now.
+ packet_cache.write[0] = 0;
+ ofs += 1;
+
+ // Encode Node ID.
+ if (has_all_peers) {
+ // Compress the node ID only if all the target peers already know it.
+ if (psc_id >= 0 && psc_id <= 255) {
+ // We can encode the id in 1 byte
+ node_id_compression = NETWORK_NODE_ID_COMPRESSION_8;
+ MAKE_ROOM(ofs + 1);
+ packet_cache.write[ofs] = static_cast<uint8_t>(psc_id);
+ ofs += 1;
+ } else if (psc_id >= 0 && psc_id <= 65535) {
+ // We can encode the id in 2 bytes
+ node_id_compression = NETWORK_NODE_ID_COMPRESSION_16;
+ MAKE_ROOM(ofs + 2);
+ encode_uint16(static_cast<uint16_t>(psc_id), &(packet_cache.write[ofs]));
+ ofs += 2;
+ } else {
+ // Too big, let's use 4 bytes.
+ node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
+ MAKE_ROOM(ofs + 4);
+ encode_uint32(psc_id, &(packet_cache.write[ofs]));
+ ofs += 4;
+ }
+ } else {
+ // The targets don't know the node yet, so we need to use 32 bits int.
+ node_id_compression = NETWORK_NODE_ID_COMPRESSION_32;
+ MAKE_ROOM(ofs + 4);
+ encode_uint32(psc_id, &(packet_cache.write[ofs]));
+ ofs += 4;
+ }
+
+ // Encode method ID
+ if (p_rpc_id <= UINT8_MAX) {
+ // The ID fits in 1 byte
+ name_id_compression = NETWORK_NAME_ID_COMPRESSION_8;
+ MAKE_ROOM(ofs + 1);
+ packet_cache.write[ofs] = static_cast<uint8_t>(p_rpc_id);
+ ofs += 1;
+ } else {
+ // The ID is larger, let's use 2 bytes
+ name_id_compression = NETWORK_NAME_ID_COMPRESSION_16;
+ MAKE_ROOM(ofs + 2);
+ encode_uint16(p_rpc_id, &(packet_cache.write[ofs]));
+ ofs += 2;
+ }
+
+ int len;
+ Error err = MultiplayerAPI::encode_and_compress_variants(p_arg, p_argcount, nullptr, len, &byte_only_or_no_args, multiplayer->is_object_decoding_allowed());
+ ERR_FAIL_COND_MSG(err != OK, "Unable to encode RPC arguments. THIS IS LIKELY A BUG IN THE ENGINE!");
+ if (byte_only_or_no_args) {
+ MAKE_ROOM(ofs + len);
+ } else {
+ MAKE_ROOM(ofs + 1 + len);
+ packet_cache.write[ofs] = p_argcount;
+ ofs += 1;
+ }
+ if (len) {
+ MultiplayerAPI::encode_and_compress_variants(p_arg, p_argcount, &packet_cache.write[ofs], len, &byte_only_or_no_args, multiplayer->is_object_decoding_allowed());
+ ofs += len;
+ }
+
+ ERR_FAIL_COND(command_type > 7);
+ ERR_FAIL_COND(node_id_compression > 3);
+ ERR_FAIL_COND(name_id_compression > 1);
+
+ // We can now set the meta
+ packet_cache.write[0] = command_type + (node_id_compression << NODE_ID_COMPRESSION_SHIFT) + (name_id_compression << NAME_ID_COMPRESSION_SHIFT) + (byte_only_or_no_args ? BYTE_ONLY_OR_NO_ARGS_FLAG : 0);
+
+#ifdef DEBUG_ENABLED
+ multiplayer->profile_bandwidth("out", ofs);
+#endif
+
+ // Take chance and set transfer mode, since all send methods will use it.
+ peer->set_transfer_channel(p_config.channel);
+ peer->set_transfer_mode(p_config.transfer_mode);
+
+ if (has_all_peers) {
+ // They all have verified paths, so send fast.
+ peer->set_target_peer(p_to); // To all of you.
+ peer->put_packet(packet_cache.ptr(), ofs); // A message with love.
+ } else {
+ // Unreachable because the node ID is never compressed if the peers doesn't know it.
+ CRASH_COND(node_id_compression != NETWORK_NODE_ID_COMPRESSION_32);
+
+ // Not all verified path, so send one by one.
+
+ // Append path at the end, since we will need it for some packets.
+ CharString pname = String(from_path).utf8();
+ int path_len = encode_cstring(pname.get_data(), nullptr);
+ MAKE_ROOM(ofs + path_len);
+ encode_cstring(pname.get_data(), &(packet_cache.write[ofs]));
+
+ for (const int &P : multiplayer->get_connected_peers()) {
+ if (p_to < 0 && P == -p_to) {
+ continue; // Continue, excluded.
+ }
+
+ if (p_to > 0 && P != p_to) {
+ continue; // Continue, not for this peer.
+ }
+
+ bool confirmed = multiplayer->is_cache_confirmed(from_path, P);
+
+ peer->set_target_peer(P); // To this one specifically.
+
+ if (confirmed) {
+ // This one confirmed path, so use id.
+ encode_uint32(psc_id, &(packet_cache.write[1]));
+ peer->put_packet(packet_cache.ptr(), ofs);
+ } else {
+ // This one did not confirm path yet, so use entire path (sorry!).
+ encode_uint32(0x80000000 | ofs, &(packet_cache.write[1])); // Offset to path and flag.
+ peer->put_packet(packet_cache.ptr(), ofs + path_len);
+ }
+ }
+ }
+}
+
+void SceneRPCInterface::rpcp(Object *p_obj, int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount) {
+ Ref<MultiplayerPeer> peer = multiplayer->get_multiplayer_peer();
+ ERR_FAIL_COND_MSG(!peer.is_valid(), "Trying to call an RPC while no multiplayer peer is active.");
+ Node *node = Object::cast_to<Node>(p_obj);
+ ERR_FAIL_COND(!node);
+ ERR_FAIL_COND_MSG(!node->is_inside_tree(), "Trying to call an RPC on a node which is not inside SceneTree.");
+ ERR_FAIL_COND_MSG(peer->get_connection_status() != MultiplayerPeer::CONNECTION_CONNECTED, "Trying to call an RPC via a multiplayer peer which is not connected.");
+
+ int node_id = peer->get_unique_id();
+ bool call_local_native = false;
+ bool call_local_script = false;
+ uint16_t rpc_id = UINT16_MAX;
+ const Multiplayer::RPCConfig config = _get_rpc_config(node, p_method, rpc_id);
+ ERR_FAIL_COND_MSG(config.name == StringName(),
+ vformat("Unable to get the RPC configuration for the function \"%s\" at path: \"%s\". This happens when the method is missing or not marked for RPCs in the local script.", p_method, node->get_path()));
+ if (p_peer_id == 0 || p_peer_id == node_id || (p_peer_id < 0 && p_peer_id != -node_id)) {
+ if (rpc_id & (1 << 15)) {
+ call_local_native = config.call_local;
+ } else {
+ call_local_script = config.call_local;
+ }
+ }
+
+ if (p_peer_id != node_id) {
+#ifdef DEBUG_ENABLED
+ _profile_node_data("rpc_out", node->get_instance_id());
+#endif
+
+ _send_rpc(node, p_peer_id, rpc_id, config, p_method, p_arg, p_argcount);
+ }
+
+ if (call_local_native) {
+ Callable::CallError ce;
+
+ multiplayer->set_remote_sender_override(peer->get_unique_id());
+ node->call(p_method, p_arg, p_argcount, ce);
+ multiplayer->set_remote_sender_override(0);
+
+ if (ce.error != Callable::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(node, p_method, p_arg, p_argcount, ce);
+ error = "rpc() aborted in local call: - " + error + ".";
+ ERR_PRINT(error);
+ return;
+ }
+ }
+
+ if (call_local_script) {
+ Callable::CallError ce;
+ ce.error = Callable::CallError::CALL_OK;
+
+ multiplayer->set_remote_sender_override(peer->get_unique_id());
+ node->get_script_instance()->call(p_method, p_arg, p_argcount, ce);
+ multiplayer->set_remote_sender_override(0);
+
+ if (ce.error != Callable::CallError::CALL_OK) {
+ String error = Variant::get_call_error_text(node, p_method, p_arg, p_argcount, ce);
+ error = "rpc() aborted in script local call: - " + error + ".";
+ ERR_PRINT(error);
+ return;
+ }
+ }
+
+ ERR_FAIL_COND_MSG(p_peer_id == node_id && !config.call_local, "RPC '" + p_method + "' on yourself is not allowed by selected mode.");
+}
diff --git a/scene/multiplayer/scene_rpc_interface.h b/scene/multiplayer/scene_rpc_interface.h
new file mode 100644
index 0000000000..86e1d0d280
--- /dev/null
+++ b/scene/multiplayer/scene_rpc_interface.h
@@ -0,0 +1,91 @@
+/*************************************************************************/
+/* scene_rpc_interface.h */
+/*************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/*************************************************************************/
+/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
+/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/*************************************************************************/
+
+#ifndef SCENE_RPC_INTERFACE_H
+#define SCENE_RPC_INTERFACE_H
+
+#include "core/multiplayer/multiplayer.h"
+#include "core/multiplayer/multiplayer_api.h"
+
+class SceneRPCInterface : public MultiplayerRPCInterface {
+ GDCLASS(SceneRPCInterface, MultiplayerRPCInterface);
+
+private:
+ enum NetworkNodeIdCompression {
+ NETWORK_NODE_ID_COMPRESSION_8 = 0,
+ NETWORK_NODE_ID_COMPRESSION_16,
+ NETWORK_NODE_ID_COMPRESSION_32,
+ };
+
+ enum NetworkNameIdCompression {
+ NETWORK_NAME_ID_COMPRESSION_8 = 0,
+ NETWORK_NAME_ID_COMPRESSION_16,
+ };
+
+ // The RPC meta is composed by a single byte that contains (starting from the least significant bit):
+ // - `NetworkCommands` in the first four bits.
+ // - `NetworkNodeIdCompression` in the next 2 bits.
+ // - `NetworkNameIdCompression` in the next 1 bit.
+ // - `byte_only_or_no_args` in the next 1 bit.
+ enum {
+ NODE_ID_COMPRESSION_SHIFT = MultiplayerAPI::CMD_FLAG_0_SHIFT, // 2 bits for this.
+ NAME_ID_COMPRESSION_SHIFT = MultiplayerAPI::CMD_FLAG_2_SHIFT,
+ BYTE_ONLY_OR_NO_ARGS_SHIFT = MultiplayerAPI::CMD_FLAG_3_SHIFT,
+ };
+
+ enum {
+ NODE_ID_COMPRESSION_FLAG = (1 << NODE_ID_COMPRESSION_SHIFT) | (1 << (NODE_ID_COMPRESSION_SHIFT + 1)), // 2 bits for this.
+ NAME_ID_COMPRESSION_FLAG = (1 << NAME_ID_COMPRESSION_SHIFT),
+ BYTE_ONLY_OR_NO_ARGS_FLAG = (1 << BYTE_ONLY_OR_NO_ARGS_SHIFT),
+ };
+
+ MultiplayerAPI *multiplayer = nullptr;
+ Vector<uint8_t> packet_cache;
+
+protected:
+ static MultiplayerRPCInterface *_create(MultiplayerAPI *p_multiplayer);
+
+ _FORCE_INLINE_ void _profile_node_data(const String &p_what, ObjectID p_id);
+ void _process_rpc(Node *p_node, const uint16_t p_rpc_method_id, int p_from, const uint8_t *p_packet, int p_packet_len, int p_offset);
+
+ void _send_rpc(Node *p_from, int p_to, uint16_t p_rpc_id, const Multiplayer::RPCConfig &p_config, const StringName &p_name, const Variant **p_arg, int p_argcount);
+ Node *_process_get_node(int p_from, const uint8_t *p_packet, uint32_t p_node_target, int p_packet_len);
+
+public:
+ static void make_default();
+
+ virtual void rpcp(Object *p_obj, int p_peer_id, const StringName &p_method, const Variant **p_arg, int p_argcount) override;
+ virtual void process_rpc(int p_from, const uint8_t *p_packet, int p_packet_len) override;
+ virtual String get_rpc_md5(const Object *p_obj) const override;
+
+ SceneRPCInterface(MultiplayerAPI *p_multiplayer) { multiplayer = p_multiplayer; }
+};
+
+#endif // SCENE_RPC_INTERFACE_H
diff --git a/scene/register_scene_types.cpp b/scene/register_scene_types.cpp
index f19b018982..152a1616f8 100644
--- a/scene/register_scene_types.cpp
+++ b/scene/register_scene_types.cpp
@@ -136,7 +136,9 @@
#include "scene/main/window.h"
#include "scene/multiplayer/multiplayer_spawner.h"
#include "scene/multiplayer/multiplayer_synchronizer.h"
+#include "scene/multiplayer/scene_cache_interface.h"
#include "scene/multiplayer/scene_replication_interface.h"
+#include "scene/multiplayer/scene_rpc_interface.h"
#include "scene/resources/audio_stream_sample.h"
#include "scene/resources/bit_map.h"
#include "scene/resources/box_shape_3d.h"
@@ -468,7 +470,12 @@ void register_scene_types() {
GDREGISTER_CLASS(XROrigin3D);
GDREGISTER_CLASS(MeshInstance3D);
GDREGISTER_CLASS(OccluderInstance3D);
- GDREGISTER_CLASS(Occluder3D);
+ GDREGISTER_VIRTUAL_CLASS(Occluder3D);
+ GDREGISTER_CLASS(ArrayOccluder3D);
+ GDREGISTER_CLASS(QuadOccluder3D);
+ GDREGISTER_CLASS(BoxOccluder3D);
+ GDREGISTER_CLASS(SphereOccluder3D);
+ GDREGISTER_CLASS(PolygonOccluder3D);
GDREGISTER_VIRTUAL_CLASS(SpriteBase3D);
GDREGISTER_CLASS(Sprite3D);
GDREGISTER_CLASS(AnimatedSprite3D);
@@ -1058,6 +1065,8 @@ void register_scene_types() {
SceneDebugger::initialize();
SceneReplicationInterface::make_default();
+ SceneRPCInterface::make_default();
+ SceneCacheInterface::make_default();
NativeExtensionManager::get_singleton()->initialize_extensions(NativeExtension::INITIALIZATION_LEVEL_SCENE);
}
@@ -1066,11 +1075,22 @@ void initialize_theme() {
// Allow creating the default theme at a different scale to suit higher/lower base resolutions.
float default_theme_scale = GLOBAL_DEF("gui/theme/default_theme_scale", 1.0);
ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/default_theme_scale", PropertyInfo(Variant::FLOAT, "gui/theme/default_theme_scale", PROPERTY_HINT_RANGE, "0.5,8,0.01", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+
String theme_path = GLOBAL_DEF_RST("gui/theme/custom", "");
ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom", PropertyInfo(Variant::STRING, "gui/theme/custom", PROPERTY_HINT_FILE, "*.tres,*.res,*.theme", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+
String font_path = GLOBAL_DEF_RST("gui/theme/custom_font", "");
ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/custom_font", PropertyInfo(Variant::STRING, "gui/theme/custom_font", PROPERTY_HINT_FILE, "*.tres,*.res,*.font", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+ bool font_antialiased = (bool)GLOBAL_DEF_RST("gui/theme/default_font_antialiased", true);
+ ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/default_font_antialiased", PropertyInfo(Variant::BOOL, "gui/theme/default_font_antialiased", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+
+ TextServer::Hinting font_hinting = (TextServer::Hinting)(int)GLOBAL_DEF_RST("gui/theme/default_font_hinting", TextServer::HINTING_LIGHT);
+ ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/default_font_hinting", PropertyInfo(Variant::INT, "gui/theme/default_font_hinting", PROPERTY_HINT_ENUM, "None,Light,Normal", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+
+ TextServer::SubpixelPositioning font_subpixel_positioning = (TextServer::SubpixelPositioning)(int)GLOBAL_DEF_RST("gui/theme/default_font_subpixel_positioning", TextServer::SUBPIXEL_POSITIONING_AUTO);
+ ProjectSettings::get_singleton()->set_custom_property_info("gui/theme/default_font_subpixel_positioning", PropertyInfo(Variant::INT, "gui/theme/default_font_subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One half of a pixel,One quarter of a pixel", PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_RESTART_IF_CHANGED));
+
Ref<Font> font;
if (!font_path.is_empty()) {
font = ResourceLoader::load(font_path);
@@ -1081,7 +1101,7 @@ void initialize_theme() {
// Always make the default theme to avoid invalid default font/icon/style in the given theme.
if (RenderingServer::get_singleton()) {
- make_default_theme(default_theme_scale, font);
+ make_default_theme(default_theme_scale, font, font_subpixel_positioning, font_hinting, font_antialiased);
}
if (!theme_path.is_empty()) {
diff --git a/scene/resources/animation.cpp b/scene/resources/animation.cpp
index b6151bccf4..312a557602 100644
--- a/scene/resources/animation.cpp
+++ b/scene/resources/animation.cpp
@@ -2320,22 +2320,12 @@ Variant Animation::_cubic_interpolate(const Variant &p_pre_a, const Variant &p_a
if (vformat == ((1 << Variant::INT) | (1 << Variant::FLOAT)) || vformat == (1 << Variant::FLOAT)) {
//mix of real and int
+ real_t a = p_a;
+ real_t b = p_b;
+ real_t pa = p_pre_a;
+ real_t pb = p_post_b;
- real_t p0 = p_pre_a;
- real_t p1 = p_a;
- real_t p2 = p_b;
- real_t p3 = p_post_b;
-
- real_t t = p_c;
- real_t t2 = t * t;
- real_t t3 = t2 * t;
-
- return 0.5f *
- ((p1 * 2.0f) +
- (-p0 + p2) * t +
- (2.0f * p0 - 5.0f * p1 + 4 * p2 - p3) * t2 +
- (-p0 + 3.0f * p1 - 3.0f * p2 + p3) * t3);
-
+ return Math::cubic_interpolate(a, b, pa, pb, p_c);
} else if ((vformat & (vformat - 1))) {
return p_a; //can't interpolate, mix of types
}
@@ -2423,7 +2413,7 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol
real_t c = 0.0;
// prepare for all cases of interpolation
- if ((loop_mode == LOOP_LINEAR || loop_mode == LOOP_PINGPONG) && p_loop_wrap) {
+ if (loop_mode == LOOP_LINEAR && p_loop_wrap) {
// loop
if (!p_backward) {
// no backward
@@ -2577,11 +2567,19 @@ T Animation::_interpolate(const Vector<TKey<T>> &p_keys, double p_time, Interpol
case INTERPOLATION_CUBIC: {
int pre = idx - 1;
if (pre < 0) {
- pre = 0;
+ if (loop_mode == LOOP_LINEAR && p_loop_wrap) {
+ pre = len - 1;
+ } else {
+ pre = 0;
+ }
}
int post = next + 1;
if (post >= len) {
- post = next;
+ if (loop_mode == LOOP_LINEAR && p_loop_wrap) {
+ post = 0;
+ } else {
+ post = next;
+ }
}
return _cubic_interpolate(p_keys[pre].value, p_keys[idx].value, p_keys[next].value, p_keys[post].value, c);
diff --git a/scene/resources/box_shape_3d.cpp b/scene/resources/box_shape_3d.cpp
index a1ec9a2230..1abbf366fd 100644
--- a/scene/resources/box_shape_3d.cpp
+++ b/scene/resources/box_shape_3d.cpp
@@ -77,6 +77,7 @@ bool BoxShape3D::_get(const StringName &p_name, Variant &r_property) const {
#endif // DISABLE_DEPRECATED
void BoxShape3D::set_size(const Vector3 &p_size) {
+ ERR_FAIL_COND_MSG(p_size.x < 0 || p_size.y < 0 || p_size.z < 0, "BoxShape3D size cannot be negative.");
size = p_size;
_update_shape();
notify_change_to_owners();
diff --git a/scene/resources/capsule_shape_2d.cpp b/scene/resources/capsule_shape_2d.cpp
index 4d2698d27d..a1ad487bff 100644
--- a/scene/resources/capsule_shape_2d.cpp
+++ b/scene/resources/capsule_shape_2d.cpp
@@ -59,6 +59,7 @@ void CapsuleShape2D::_update_shape() {
}
void CapsuleShape2D::set_radius(real_t p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "CapsuleShape2D radius cannot be negative.");
radius = p_radius;
if (radius > height * 0.5) {
height = radius * 2.0;
@@ -71,6 +72,7 @@ real_t CapsuleShape2D::get_radius() const {
}
void CapsuleShape2D::set_height(real_t p_height) {
+ ERR_FAIL_COND_MSG(p_height < 0, "CapsuleShape2D height cannot be negative.");
height = p_height;
if (radius > height * 0.5) {
radius = height * 0.5;
diff --git a/scene/resources/capsule_shape_3d.cpp b/scene/resources/capsule_shape_3d.cpp
index c16ddad984..2179ce82dd 100644
--- a/scene/resources/capsule_shape_3d.cpp
+++ b/scene/resources/capsule_shape_3d.cpp
@@ -79,6 +79,7 @@ void CapsuleShape3D::_update_shape() {
}
void CapsuleShape3D::set_radius(float p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "CapsuleShape3D radius cannot be negative.");
radius = p_radius;
if (radius > height * 0.5) {
height = radius * 2.0;
@@ -92,6 +93,7 @@ float CapsuleShape3D::get_radius() const {
}
void CapsuleShape3D::set_height(float p_height) {
+ ERR_FAIL_COND_MSG(p_height < 0, "CapsuleShape3D height cannot be negative.");
height = p_height;
if (radius > height * 0.5) {
radius = height * 0.5;
diff --git a/scene/resources/circle_shape_2d.cpp b/scene/resources/circle_shape_2d.cpp
index 9c16ac2eed..de931fca7e 100644
--- a/scene/resources/circle_shape_2d.cpp
+++ b/scene/resources/circle_shape_2d.cpp
@@ -43,6 +43,7 @@ void CircleShape2D::_update_shape() {
}
void CircleShape2D::set_radius(real_t p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "CircleShape2D radius cannot be negative.");
radius = p_radius;
_update_shape();
}
diff --git a/scene/resources/cylinder_shape_3d.cpp b/scene/resources/cylinder_shape_3d.cpp
index 5eeb62d17b..c4f1cba341 100644
--- a/scene/resources/cylinder_shape_3d.cpp
+++ b/scene/resources/cylinder_shape_3d.cpp
@@ -72,6 +72,7 @@ void CylinderShape3D::_update_shape() {
}
void CylinderShape3D::set_radius(float p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "CylinderShape3D radius cannot be negative.");
radius = p_radius;
_update_shape();
notify_change_to_owners();
@@ -82,6 +83,7 @@ float CylinderShape3D::get_radius() const {
}
void CylinderShape3D::set_height(float p_height) {
+ ERR_FAIL_COND_MSG(p_height < 0, "CylinderShape3D height cannot be negative.");
height = p_height;
_update_shape();
notify_change_to_owners();
diff --git a/scene/resources/default_theme/color_picker_sample.svg b/scene/resources/default_theme/color_picker_sample.svg
deleted file mode 100644
index 140ac20a99..0000000000
--- a/scene/resources/default_theme/color_picker_sample.svg
+++ /dev/null
@@ -1 +0,0 @@
-<svg clip-rule="evenodd" fill-rule="evenodd" stroke-linejoin="round" stroke-miterlimit="2" viewBox="0 0 256 20" xmlns="http://www.w3.org/2000/svg"><g fill-rule="nonzero"><path d="m0 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m5 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m80 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m85 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m159.978 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m164.978 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m39.991 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m44.991 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m119.99 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m124.99 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m199.968 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m204.968 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m9.98 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m14.98 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m89.98 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m94.98 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m169.957 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m174.957 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m49.97 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m54.97 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m129.97 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m134.97 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m209.948 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m214.948 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m19.995 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m24.995 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m99.995 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m104.995 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m179.973 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m184.973 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m59.986 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m64.986 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m139.986 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m144.986 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m219.964 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m224.964 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m30.011 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m35.011 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m110.011 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m115.011 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m189.989 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m194.989 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m70.001 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m75.001 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m150.001 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m155.001 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m229.979 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m234.979 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m240.017 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m245.017 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m249.996 0v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m254.996 0v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m249.996 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m254.996 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m240.017 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m245.017 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m0 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m5 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m80 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m85 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m159.978 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m164.978 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m39.991 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m44.991 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m119.99 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m124.99 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m199.968 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m204.968 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m9.98 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m14.98 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m89.98 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m94.98 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m169.957 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m174.957 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m49.97 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m54.97 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m129.97 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m134.97 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m209.948 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m214.948 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m19.995 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m24.995 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m99.995 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m104.995 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m179.973 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m184.973 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m59.986 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m64.986 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m139.986 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m144.986 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m219.964 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m224.964 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m30.011 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m35.011 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m110.011 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m115.011 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m189.989 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m194.989 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m70.001 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m75.001 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m150.001 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m155.001 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/><path d="m229.979 10v5h5v-5zm5 5v5h5v-5z" fill="#e0e0e0"/><path d="m234.979 10v5h5v-5zm0 5h-5v5h5z" fill="#fff"/></g></svg>
diff --git a/scene/resources/default_theme/default_theme.cpp b/scene/resources/default_theme/default_theme.cpp
index 670b141080..61114333fb 100644
--- a/scene/resources/default_theme/default_theme.cpp
+++ b/scene/resources/default_theme/default_theme.cpp
@@ -175,7 +175,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te
theme->set_color("icon_hover_color", "Button", Color(1, 1, 1, 1));
theme->set_color("icon_hover_pressed_color", "Button", Color(1, 1, 1, 1));
theme->set_color("icon_focus_color", "Button", Color(1, 1, 1, 1));
- theme->set_color("icon_disabled_color", "Button", Color(1, 1, 1, 1));
+ theme->set_color("icon_disabled_color", "Button", Color(1, 1, 1, 0.4));
theme->set_constant("hseparation", "Button", 2 * scale);
@@ -466,7 +466,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te
theme->set_color("completion_background_color", "CodeEdit", Color(0.17, 0.16, 0.2));
theme->set_color("completion_selected_color", "CodeEdit", Color(0.26, 0.26, 0.27));
theme->set_color("completion_existing_color", "CodeEdit", Color(0.87, 0.87, 0.87, 0.13));
- theme->set_color("completion_scroll_color", "CodeEdit", control_font_pressed_color);
+ theme->set_color("completion_scroll_color", "CodeEdit", control_font_pressed_color * Color(1, 1, 1, 0.29));
theme->set_color("completion_font_color", "CodeEdit", Color(0.67, 0.67, 0.67));
theme->set_color("font_color", "CodeEdit", control_font_color);
theme->set_color("font_selected_color", "CodeEdit", Color(0, 0, 0));
@@ -490,7 +490,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te
theme->set_constant("completion_lines", "CodeEdit", 7);
theme->set_constant("completion_max_width", "CodeEdit", 50);
- theme->set_constant("completion_scroll_width", "CodeEdit", 3);
+ theme->set_constant("completion_scroll_width", "CodeEdit", 6);
theme->set_constant("line_spacing", "CodeEdit", 4 * scale);
theme->set_constant("outline_size", "CodeEdit", 0);
@@ -864,7 +864,6 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te
theme->set_icon("screen_picker", "ColorPicker", icons["color_picker_pipette"]);
theme->set_icon("add_preset", "ColorPicker", icons["add"]);
theme->set_icon("color_hue", "ColorPicker", icons["color_picker_hue"]);
- theme->set_icon("color_sample", "ColorPicker", icons["color_picker_sample"]);
theme->set_icon("sample_bg", "ColorPicker", icons["mini_checkerboard"]);
theme->set_icon("overbright_indicator", "ColorPicker", icons["color_picker_overbright"]);
theme->set_icon("bar_arrow", "ColorPicker", icons["color_picker_bar_arrow"]);
@@ -1019,7 +1018,7 @@ void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Te
default_style = make_flat_stylebox(Color(1, 0.365, 0.365), 4, 4, 4, 4, 0, false, 2);
}
-void make_default_theme(float p_scale, Ref<Font> p_font) {
+void make_default_theme(float p_scale, Ref<Font> p_font, TextServer::SubpixelPositioning p_subpixel, TextServer::Hinting p_hinting, bool p_aa) {
Ref<Theme> t;
t.instantiate();
@@ -1041,6 +1040,9 @@ void make_default_theme(float p_scale, Ref<Font> p_font) {
Ref<FontData> dynamic_font_data;
dynamic_font_data.instantiate();
dynamic_font_data->set_data_ptr(_font_OpenSans_SemiBold, _font_OpenSans_SemiBold_size);
+ dynamic_font_data->set_subpixel_positioning(p_subpixel);
+ dynamic_font_data->set_hinting(p_hinting);
+ dynamic_font_data->set_antialiased(p_aa);
dynamic_font->add_data(dynamic_font_data);
default_font = dynamic_font;
diff --git a/scene/resources/default_theme/default_theme.h b/scene/resources/default_theme/default_theme.h
index 3016517824..28afd5f5e1 100644
--- a/scene/resources/default_theme/default_theme.h
+++ b/scene/resources/default_theme/default_theme.h
@@ -36,7 +36,7 @@
const int default_font_size = 16;
void fill_default_theme(Ref<Theme> &theme, const Ref<Font> &default_font, Ref<Texture2D> &default_icon, Ref<StyleBox> &default_style, float p_scale);
-void make_default_theme(float p_scale, Ref<Font> p_font);
+void make_default_theme(float p_scale, Ref<Font> p_font, TextServer::SubpixelPositioning p_subpixel, TextServer::Hinting p_hinting, bool p_aa);
void clear_default_theme();
#endif
diff --git a/scene/resources/default_theme/mini_checkerboard.svg b/scene/resources/default_theme/mini_checkerboard.svg
index 0ae6a855bd..03438f75a6 100644
--- a/scene/resources/default_theme/mini_checkerboard.svg
+++ b/scene/resources/default_theme/mini_checkerboard.svg
@@ -1 +1 @@
-<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g stroke-linecap="round" stroke-linejoin="round" stroke-width="1.9994"><path d="m0 0v8h8v-8zm8 8v8h8v-8z" fill="#e0e0e0"/><path d="m8 0v8h8v-8zm0 8h-8v8h8z" fill="#fff"/></g></svg>
+<svg height="16" viewBox="0 0 16 16" width="16" xmlns="http://www.w3.org/2000/svg"><g stroke-width="2"><path d="m0 0v8h8v-8zm8 8v8h8v-8z" fill="#808080"/><path d="m8 0v8h8v-8zm0 8h-8v8h8z" fill="#fff"/></g></svg>
diff --git a/scene/resources/environment.cpp b/scene/resources/environment.cpp
index b13ae9d016..82d8ad4444 100644
--- a/scene/resources/environment.cpp
+++ b/scene/resources/environment.cpp
@@ -155,7 +155,9 @@ float Environment::get_ambient_light_energy() const {
}
void Environment::set_ambient_light_sky_contribution(float p_ratio) {
- ambient_sky_contribution = p_ratio;
+ // Sky contribution values outside the [0.0; 1.0] range don't make sense and
+ // can result in negative colors.
+ ambient_sky_contribution = CLAMP(p_ratio, 0.0, 1.0);
_update_ambient_light();
}
@@ -1332,7 +1334,7 @@ void Environment::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_min_cell_size", PROPERTY_HINT_RANGE, "0.01,64,0.01"), "set_sdfgi_min_cell_size", "get_sdfgi_min_cell_size");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_cascade0_distance", PROPERTY_HINT_RANGE, "0.1,16384,0.1,or_greater"), "set_sdfgi_cascade0_distance", "get_sdfgi_cascade0_distance");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_max_distance", PROPERTY_HINT_RANGE, "0.1,16384,0.1,or_greater"), "set_sdfgi_max_distance", "get_sdfgi_max_distance");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "sdfgi_y_scale", PROPERTY_HINT_ENUM, "Disable,75%,50%"), "set_sdfgi_y_scale", "get_sdfgi_y_scale");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "sdfgi_y_scale", PROPERTY_HINT_ENUM, "50% (Compact),75% (Balanced),100% (Sparse)"), "set_sdfgi_y_scale", "get_sdfgi_y_scale");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_energy"), "set_sdfgi_energy", "get_sdfgi_energy");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_normal_bias"), "set_sdfgi_normal_bias", "get_sdfgi_normal_bias");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "sdfgi_probe_bias"), "set_sdfgi_probe_bias", "get_sdfgi_probe_bias");
@@ -1511,9 +1513,9 @@ void Environment::_bind_methods() {
BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_REPLACE);
BIND_ENUM_CONSTANT(GLOW_BLEND_MODE_MIX);
- BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_DISABLED);
- BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_75_PERCENT);
BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_50_PERCENT);
+ BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_75_PERCENT);
+ BIND_ENUM_CONSTANT(SDFGI_Y_SCALE_100_PERCENT);
}
Environment::Environment() {
diff --git a/scene/resources/environment.h b/scene/resources/environment.h
index b04723a221..b71fe8904a 100644
--- a/scene/resources/environment.h
+++ b/scene/resources/environment.h
@@ -34,7 +34,6 @@
#include "core/io/resource.h"
#include "scene/resources/sky.h"
#include "scene/resources/texture.h"
-#include "servers/rendering_server.h"
class Environment : public Resource {
GDCLASS(Environment, Resource);
@@ -71,9 +70,9 @@ public:
};
enum SDFGIYScale {
- SDFGI_Y_SCALE_DISABLED,
- SDFGI_Y_SCALE_75_PERCENT,
SDFGI_Y_SCALE_50_PERCENT,
+ SDFGI_Y_SCALE_75_PERCENT,
+ SDFGI_Y_SCALE_100_PERCENT,
};
enum GlowBlendMode {
@@ -147,12 +146,12 @@ private:
// SDFGI
bool sdfgi_enabled = false;
- int sdfgi_cascades = 6;
+ int sdfgi_cascades = 4;
float sdfgi_min_cell_size = 0.2;
- SDFGIYScale sdfgi_y_scale = SDFGI_Y_SCALE_DISABLED;
+ SDFGIYScale sdfgi_y_scale = SDFGI_Y_SCALE_75_PERCENT;
bool sdfgi_use_occlusion = false;
- float sdfgi_bounce_feedback = 0.0;
- bool sdfgi_read_sky_light = false;
+ float sdfgi_bounce_feedback = 0.5;
+ bool sdfgi_read_sky_light = true;
float sdfgi_energy = 1.0;
float sdfgi_normal_bias = 1.1;
float sdfgi_probe_bias = 1.1;
diff --git a/scene/resources/font.cpp b/scene/resources/font.cpp
index b512acdd8a..5b57e93950 100644
--- a/scene/resources/font.cpp
+++ b/scene/resources/font.cpp
@@ -60,6 +60,7 @@ _FORCE_INLINE_ void FontData::_ensure_rid(int p_cache_index) const {
TS->font_set_fixed_size(cache[p_cache_index], fixed_size);
TS->font_set_force_autohinter(cache[p_cache_index], force_autohinter);
TS->font_set_hinting(cache[p_cache_index], hinting);
+ TS->font_set_subpixel_positioning(cache[p_cache_index], subpixel_positioning);
TS->font_set_oversampling(cache[p_cache_index], oversampling);
}
}
@@ -101,6 +102,9 @@ void FontData::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_hinting", "hinting"), &FontData::set_hinting);
ClassDB::bind_method(D_METHOD("get_hinting"), &FontData::get_hinting);
+ ClassDB::bind_method(D_METHOD("set_subpixel_positioning", "subpixel_positioning"), &FontData::set_subpixel_positioning);
+ ClassDB::bind_method(D_METHOD("get_subpixel_positioning"), &FontData::get_subpixel_positioning);
+
ClassDB::bind_method(D_METHOD("set_oversampling", "oversampling"), &FontData::set_oversampling);
ClassDB::bind_method(D_METHOD("get_oversampling"), &FontData::get_oversampling);
@@ -204,6 +208,7 @@ void FontData::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::STRING, "font_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_font_name", "get_font_name");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "style_name", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_font_style_name", "get_font_style_name");
ADD_PROPERTY(PropertyInfo(Variant::INT, "font_style", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_font_style", "get_font_style");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "subpixel_positioning", PROPERTY_HINT_ENUM, "Disabled,Auto,One half of a pixel,One quarter of a pixel", PROPERTY_USAGE_STORAGE), "set_subpixel_positioning", "get_subpixel_positioning");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "multichannel_signed_distance_field", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_multichannel_signed_distance_field", "is_multichannel_signed_distance_field");
ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_pixel_range", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_msdf_pixel_range", "get_msdf_pixel_range");
ADD_PROPERTY(PropertyInfo(Variant::INT, "msdf_size", PROPERTY_HINT_NONE, "", PROPERTY_USAGE_STORAGE), "set_msdf_size", "get_msdf_size");
@@ -430,6 +435,7 @@ void FontData::reset_state() {
msdf = false;
force_autohinter = false;
hinting = TextServer::HINTING_LIGHT;
+ subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_DISABLED;
msdf_pixel_range = 14;
msdf_size = 128;
fixed_size = 0;
@@ -1364,6 +1370,21 @@ TextServer::Hinting FontData::get_hinting() const {
return hinting;
}
+void FontData::set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel) {
+ if (subpixel_positioning != p_subpixel) {
+ subpixel_positioning = p_subpixel;
+ for (int i = 0; i < cache.size(); i++) {
+ _ensure_rid(i);
+ TS->font_set_subpixel_positioning(cache[i], subpixel_positioning);
+ }
+ emit_changed();
+ }
+}
+
+TextServer::SubpixelPositioning FontData::get_subpixel_positioning() const {
+ return subpixel_positioning;
+}
+
void FontData::set_oversampling(real_t p_oversampling) {
if (oversampling != p_oversampling) {
oversampling = p_oversampling;
diff --git a/scene/resources/font.h b/scene/resources/font.h
index 93351a3493..aaf0a7fe7b 100644
--- a/scene/resources/font.h
+++ b/scene/resources/font.h
@@ -55,6 +55,7 @@ class FontData : public Resource {
int fixed_size = 0;
bool force_autohinter = false;
TextServer::Hinting hinting = TextServer::HINTING_LIGHT;
+ TextServer::SubpixelPositioning subpixel_positioning = TextServer::SUBPIXEL_POSITIONING_AUTO;
real_t oversampling = 0.f;
// Cache.
@@ -118,6 +119,9 @@ public:
virtual void set_hinting(TextServer::Hinting p_hinting);
virtual TextServer::Hinting get_hinting() const;
+ virtual void set_subpixel_positioning(TextServer::SubpixelPositioning p_subpixel);
+ virtual TextServer::SubpixelPositioning get_subpixel_positioning() const;
+
virtual void set_oversampling(real_t p_oversampling);
virtual real_t get_oversampling() const;
diff --git a/scene/resources/importer_mesh.cpp b/scene/resources/importer_mesh.cpp
index 92ab091b86..a27da11f8d 100644
--- a/scene/resources/importer_mesh.cpp
+++ b/scene/resources/importer_mesh.cpp
@@ -287,7 +287,7 @@ void ImporterMesh::generate_lods(float p_normal_merge_angle, float p_normal_spli
const int *indices_ptr = indices.ptr();
if (normals.is_empty()) {
- normals.resize(vertices.size());
+ normals.resize(index_count);
Vector3 *n_ptr = normals.ptrw();
for (unsigned int j = 0; j < index_count; j += 3) {
const Vector3 &v0 = vertices_ptr[indices_ptr[j + 0]];
diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp
index f3e5ece1f9..b74f44c52f 100644
--- a/scene/resources/material.cpp
+++ b/scene/resources/material.cpp
@@ -2215,7 +2215,9 @@ BaseMaterial3D::EmissionOperator BaseMaterial3D::get_emission_operator() const {
RID BaseMaterial3D::get_shader_rid() const {
MutexLock lock(material_mutex);
- ((BaseMaterial3D *)this)->_update_shader();
+ if (element.in_list()) { // _is_shader_dirty() would create anoder mutex lock
+ ((BaseMaterial3D *)this)->_update_shader();
+ }
ERR_FAIL_COND_V(!shader_map.has(current_key), RID());
return shader_map[current_key].shader;
}
diff --git a/scene/resources/packed_scene.cpp b/scene/resources/packed_scene.cpp
index f9a4eba978..9d388d465d 100644
--- a/scene/resources/packed_scene.cpp
+++ b/scene/resources/packed_scene.cpp
@@ -529,10 +529,6 @@ Error SceneState::_parse_node(Node *p_owner, Node *p_node, int p_parent_idx, Map
if (!gi.persistent) {
continue;
}
- /*
- if (instance_state_node>=0 && instance_state->is_node_in_group(instance_state_node,gi.name))
- continue; //group was instantiated, don't add here
- */
bool skip = false;
for (const SceneState::PackState &ia : states_stack) {
diff --git a/scene/resources/rectangle_shape_2d.cpp b/scene/resources/rectangle_shape_2d.cpp
index 27659f724e..5e88c9974c 100644
--- a/scene/resources/rectangle_shape_2d.cpp
+++ b/scene/resources/rectangle_shape_2d.cpp
@@ -58,6 +58,7 @@ bool RectangleShape2D::_get(const StringName &p_name, Variant &r_property) const
#endif // DISABLE_DEPRECATED
void RectangleShape2D::set_size(const Vector2 &p_size) {
+ ERR_FAIL_COND_MSG(p_size.x < 0 || p_size.y < 0, "RectangleShape2D size cannot be negative.");
size = p_size;
_update_shape();
}
diff --git a/scene/resources/resource_format_text.cpp b/scene/resources/resource_format_text.cpp
index 6bb710b1d9..c03faa2c2d 100644
--- a/scene/resources/resource_format_text.cpp
+++ b/scene/resources/resource_format_text.cpp
@@ -1951,7 +1951,7 @@ Error ResourceFormatSaverTextInstance::save(const String &p_path, const RES &p_r
}
Error ResourceFormatSaverText::save(const String &p_path, const RES &p_resource, uint32_t p_flags) {
- if (p_path.ends_with(".sct") && p_resource->get_class() != "PackedScene") {
+ if (p_path.ends_with(".tscn") && !Ref<PackedScene>(p_resource).is_valid()) {
return ERR_FILE_UNRECOGNIZED;
}
@@ -1960,14 +1960,14 @@ Error ResourceFormatSaverText::save(const String &p_path, const RES &p_resource,
}
bool ResourceFormatSaverText::recognize(const RES &p_resource) const {
- return true; // all recognized!
+ return true; // All resources recognized!
}
void ResourceFormatSaverText::get_recognized_extensions(const RES &p_resource, List<String> *p_extensions) const {
- if (p_resource->get_class() == "PackedScene") {
- p_extensions->push_back("tscn"); //text scene
+ if (Ref<PackedScene>(p_resource).is_valid()) {
+ p_extensions->push_back("tscn"); // Text scene.
} else {
- p_extensions->push_back("tres"); //text resource
+ p_extensions->push_back("tres"); // Text resource.
}
}
diff --git a/scene/resources/skeleton_modification_2d_jiggle.cpp b/scene/resources/skeleton_modification_2d_jiggle.cpp
index eee6067dae..0921417656 100644
--- a/scene/resources/skeleton_modification_2d_jiggle.cpp
+++ b/scene/resources/skeleton_modification_2d_jiggle.cpp
@@ -29,7 +29,9 @@
/*************************************************************************/
#include "skeleton_modification_2d_jiggle.h"
+
#include "scene/2d/skeleton_2d.h"
+#include "scene/resources/world_2d.h"
bool SkeletonModification2DJiggle::_set(const StringName &p_path, const Variant &p_value) {
String path = p_path;
diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp
index c5d5ba2912..8e633a4075 100644
--- a/scene/resources/sky_material.cpp
+++ b/scene/resources/sky_material.cpp
@@ -208,16 +208,16 @@ void ProceduralSkyMaterial::_update_shader() {
shader_type sky;
-uniform vec4 sky_top_color : hint_color = vec4(0.35, 0.46, 0.71, 1.0);
-uniform vec4 sky_horizon_color : hint_color = vec4(0.55, 0.69, 0.81, 1.0);
-uniform float sky_curve : hint_range(0, 1) = 0.09;
+uniform vec4 sky_top_color : hint_color = vec4(0.385, 0.454, 0.55, 1.0);
+uniform vec4 sky_horizon_color : hint_color = vec4(0.646, 0.656, 0.67, 1.0);
+uniform float sky_curve : hint_range(0, 1) = 0.15;
uniform float sky_energy = 1.0;
-uniform vec4 ground_bottom_color : hint_color = vec4(0.12, 0.12, 0.13, 1.0);
-uniform vec4 ground_horizon_color : hint_color = vec4(0.37, 0.33, 0.31, 1.0);
+uniform vec4 ground_bottom_color : hint_color = vec4(0.2, 0.169, 0.133, 1.0);
+uniform vec4 ground_horizon_color : hint_color = vec4(0.646, 0.656, 0.67, 1.0);
uniform float ground_curve : hint_range(0, 1) = 0.02;
uniform float ground_energy = 1.0;
-uniform float sun_angle_max = 1.74;
-uniform float sun_curve : hint_range(0, 1) = 0.05;
+uniform float sun_angle_max = 30.0;
+uniform float sun_curve : hint_range(0, 1) = 0.15;
void sky() {
float v_angle = acos(clamp(EYEDIR.y, -1.0, 1.0));
@@ -277,18 +277,18 @@ void sky() {
}
ProceduralSkyMaterial::ProceduralSkyMaterial() {
- set_sky_top_color(Color(0.35, 0.46, 0.71));
- set_sky_horizon_color(Color(0.55, 0.69, 0.81));
- set_sky_curve(0.09);
+ set_sky_top_color(Color(0.385, 0.454, 0.55));
+ set_sky_horizon_color(Color(0.6463, 0.6558, 0.6708));
+ set_sky_curve(0.15);
set_sky_energy(1.0);
- set_ground_bottom_color(Color(0.12, 0.12, 0.13));
- set_ground_horizon_color(Color(0.37, 0.33, 0.31));
+ set_ground_bottom_color(Color(0.2, 0.169, 0.133));
+ set_ground_horizon_color(Color(0.6463, 0.6558, 0.6708));
set_ground_curve(0.02);
set_ground_energy(1.0);
- set_sun_angle_max(100.0);
- set_sun_curve(0.05);
+ set_sun_angle_max(30.0);
+ set_sun_curve(0.15);
}
ProceduralSkyMaterial::~ProceduralSkyMaterial() {
@@ -583,14 +583,14 @@ void PhysicalSkyMaterial::_update_shader() {
shader_type sky;
uniform float rayleigh : hint_range(0, 64) = 2.0;
-uniform vec4 rayleigh_color : hint_color = vec4(0.26, 0.41, 0.58, 1.0);
+uniform vec4 rayleigh_color : hint_color = vec4(0.3, 0.405, 0.6, 1.0);
uniform float mie : hint_range(0, 1) = 0.005;
uniform float mie_eccentricity : hint_range(-1, 1) = 0.8;
-uniform vec4 mie_color : hint_color = vec4(0.63, 0.77, 0.92, 1.0);
+uniform vec4 mie_color : hint_color = vec4(0.69, 0.729, 0.812, 1.0);
uniform float turbidity : hint_range(0, 1000) = 10.0;
uniform float sun_disk_scale : hint_range(0, 360) = 1.0;
-uniform vec4 ground_color : hint_color = vec4(1.0);
+uniform vec4 ground_color : hint_color = vec4(0.1, 0.07, 0.034, 1.0);
uniform float exposure : hint_range(0, 128) = 0.1;
uniform float dither_strength : hint_range(0, 10) = 1.0;
@@ -680,13 +680,13 @@ void sky() {
PhysicalSkyMaterial::PhysicalSkyMaterial() {
set_rayleigh_coefficient(2.0);
- set_rayleigh_color(Color(0.26, 0.41, 0.58));
+ set_rayleigh_color(Color(0.3, 0.405, 0.6));
set_mie_coefficient(0.005);
set_mie_eccentricity(0.8);
- set_mie_color(Color(0.63, 0.77, 0.92));
+ set_mie_color(Color(0.69, 0.729, 0.812));
set_turbidity(10.0);
set_sun_disk_scale(1.0);
- set_ground_color(Color(1.0, 1.0, 1.0));
+ set_ground_color(Color(0.1, 0.07, 0.034));
set_exposure(0.1);
set_dither_strength(1.0);
}
diff --git a/scene/resources/sphere_shape_3d.cpp b/scene/resources/sphere_shape_3d.cpp
index ee789362c9..8282992401 100644
--- a/scene/resources/sphere_shape_3d.cpp
+++ b/scene/resources/sphere_shape_3d.cpp
@@ -63,6 +63,7 @@ void SphereShape3D::_update_shape() {
}
void SphereShape3D::set_radius(float p_radius) {
+ ERR_FAIL_COND_MSG(p_radius < 0, "SphereShape3D radius cannot be negative.");
radius = p_radius;
_update_shape();
notify_change_to_owners();
diff --git a/scene/resources/surface_tool.cpp b/scene/resources/surface_tool.cpp
index 0677d9c1a8..8ff1fde2cf 100644
--- a/scene/resources/surface_tool.cpp
+++ b/scene/resources/surface_tool.cpp
@@ -37,6 +37,44 @@ SurfaceTool::SimplifyFunc SurfaceTool::simplify_func = nullptr;
SurfaceTool::SimplifyWithAttribFunc SurfaceTool::simplify_with_attrib_func = nullptr;
SurfaceTool::SimplifyScaleFunc SurfaceTool::simplify_scale_func = nullptr;
SurfaceTool::SimplifySloppyFunc SurfaceTool::simplify_sloppy_func = nullptr;
+SurfaceTool::GenerateRemapFunc SurfaceTool::generate_remap_func = nullptr;
+SurfaceTool::RemapVertexFunc SurfaceTool::remap_vertex_func = nullptr;
+SurfaceTool::RemapIndexFunc SurfaceTool::remap_index_func = nullptr;
+
+void SurfaceTool::strip_mesh_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices) {
+ ERR_FAIL_COND_MSG(!generate_remap_func || !remap_vertex_func || !remap_index_func, "Meshoptimizer library is not initialized.");
+
+ Vector<uint32_t> remap;
+ remap.resize(r_vertices.size());
+ uint32_t new_vertex_count = generate_remap_func(remap.ptrw(), (unsigned int *)r_indices.ptr(), r_indices.size(), (float *)r_vertices.ptr(), r_vertices.size(), sizeof(Vector3));
+ remap_vertex_func(r_vertices.ptrw(), r_vertices.ptr(), r_vertices.size(), sizeof(Vector3), remap.ptr());
+ r_vertices.resize(new_vertex_count);
+ remap_index_func((unsigned int *)r_indices.ptrw(), (unsigned int *)r_indices.ptr(), r_indices.size(), remap.ptr());
+
+ HashMap<const int *, bool, TriangleHasher, TriangleHasher> found_triangles;
+ int *idx_ptr = r_indices.ptrw();
+
+ int filtered_indices_count = 0;
+ for (int i = 0; i < r_indices.size() / 3; i++) {
+ const int *tri = idx_ptr + (i * 3);
+
+ if (tri[0] == tri[1] || tri[1] == tri[2] || tri[2] == tri[0]) {
+ continue;
+ }
+
+ if (found_triangles.has(tri)) {
+ continue;
+ }
+
+ if (i != filtered_indices_count) {
+ memcpy(idx_ptr + (filtered_indices_count * 3), tri, sizeof(int) * 3);
+ }
+
+ found_triangles[tri] = true;
+ filtered_indices_count++;
+ }
+ r_indices.resize(filtered_indices_count * 3);
+}
bool SurfaceTool::Vertex::operator==(const Vertex &p_vertex) const {
if (vertex != p_vertex.vertex) {
@@ -107,6 +145,56 @@ uint32_t SurfaceTool::VertexHasher::hash(const Vertex &p_vtx) {
return h;
}
+uint32_t SurfaceTool::TriangleHasher::hash(const int *p_triangle) {
+ int t0 = p_triangle[0];
+ int t1 = p_triangle[1];
+ int t2 = p_triangle[2];
+
+ if (t0 > t1) {
+ SWAP(t0, t1);
+ }
+ if (t1 > t2) {
+ SWAP(t1, t2);
+ }
+ if (t0 > t1) {
+ SWAP(t0, t1);
+ }
+
+ return (t0 * 73856093) ^ (t1 * 19349663) ^ (t2 * 83492791);
+}
+
+bool SurfaceTool::TriangleHasher::compare(const int *p_lhs, const int *p_rhs) {
+ int r0 = p_rhs[0];
+ int r1 = p_rhs[1];
+ int r2 = p_rhs[2];
+
+ if (r0 > r1) {
+ SWAP(r0, r1);
+ }
+ if (r1 > r2) {
+ SWAP(r1, r2);
+ }
+ if (r0 > r1) {
+ SWAP(r0, r1);
+ }
+
+ int l0 = p_lhs[0];
+ int l1 = p_lhs[1];
+ int l2 = p_lhs[2];
+
+ if (l0 > l1) {
+ SWAP(l0, l1);
+ }
+ if (l1 > l2) {
+ SWAP(l1, l2);
+ }
+ if (l0 > l1) {
+ SWAP(l0, l1);
+ }
+
+ return l0 == r0 && l1 == r1 && l2 == r2;
+}
+
void SurfaceTool::begin(Mesh::PrimitiveType p_primitive) {
clear();
diff --git a/scene/resources/surface_tool.h b/scene/resources/surface_tool.h
index 9cb83e0e68..bf4332ad2a 100644
--- a/scene/resources/surface_tool.h
+++ b/scene/resources/surface_tool.h
@@ -84,12 +84,24 @@ public:
static SimplifyScaleFunc simplify_scale_func;
typedef size_t (*SimplifySloppyFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, const float *vertex_positions_data, size_t vertex_count, size_t vertex_positions_stride, size_t target_index_count, float target_error, float *out_result_error);
static SimplifySloppyFunc simplify_sloppy_func;
+ typedef size_t (*GenerateRemapFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, const void *vertices, size_t vertex_count, size_t vertex_size);
+ static GenerateRemapFunc generate_remap_func;
+ typedef void (*RemapVertexFunc)(void *destination, const void *vertices, size_t vertex_count, size_t vertex_size, const unsigned int *remap);
+ static RemapVertexFunc remap_vertex_func;
+ typedef void (*RemapIndexFunc)(unsigned int *destination, const unsigned int *indices, size_t index_count, const unsigned int *remap);
+ static RemapIndexFunc remap_index_func;
+ static void strip_mesh_arrays(PackedVector3Array &r_vertices, PackedInt32Array &r_indices);
private:
struct VertexHasher {
static _FORCE_INLINE_ uint32_t hash(const Vertex &p_vtx);
};
+ struct TriangleHasher {
+ static _FORCE_INLINE_ uint32_t hash(const int *p_triangle);
+ static _FORCE_INLINE_ bool compare(const int *p_lhs, const int *p_rhs);
+ };
+
struct WeightSort {
int index = 0;
float weight = 0.0;
diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp
index ee66a61da8..0ee0e4b33e 100644
--- a/scene/resources/texture.cpp
+++ b/scene/resources/texture.cpp
@@ -1902,7 +1902,7 @@ void GradientTexture2D::_queue_update() {
return;
}
update_pending = true;
- call_deferred("_update");
+ call_deferred(SNAME("_update"));
}
void GradientTexture2D::_update() {
diff --git a/scene/resources/theme.cpp b/scene/resources/theme.cpp
index f962e55666..373fbb94ea 100644
--- a/scene/resources/theme.cpp
+++ b/scene/resources/theme.cpp
@@ -29,6 +29,7 @@
/*************************************************************************/
#include "theme.h"
+
#include "core/string/print_string.h"
// Universal Theme resources used when no other theme has the item.
@@ -401,6 +402,26 @@ void Theme::add_icon_type(const StringName &p_theme_type) {
icon_map[p_theme_type] = HashMap<StringName, Ref<Texture2D>>();
}
+void Theme::remove_icon_type(const StringName &p_theme_type) {
+ if (!icon_map.has(p_theme_type)) {
+ return;
+ }
+
+ _freeze_change_propagation();
+
+ const StringName *L = nullptr;
+ while ((L = icon_map[p_theme_type].next(L))) {
+ Ref<Texture2D> icon = icon_map[p_theme_type][*L];
+ if (icon.is_valid()) {
+ icon->disconnect("changed", callable_mp(this, &Theme::_emit_theme_changed));
+ }
+ }
+
+ icon_map.erase(p_theme_type);
+
+ _unfreeze_and_propagate_changes();
+}
+
void Theme::get_icon_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -488,6 +509,26 @@ void Theme::add_stylebox_type(const StringName &p_theme_type) {
style_map[p_theme_type] = HashMap<StringName, Ref<StyleBox>>();
}
+void Theme::remove_stylebox_type(const StringName &p_theme_type) {
+ if (!style_map.has(p_theme_type)) {
+ return;
+ }
+
+ _freeze_change_propagation();
+
+ const StringName *L = nullptr;
+ while ((L = style_map[p_theme_type].next(L))) {
+ Ref<StyleBox> style = style_map[p_theme_type][*L];
+ if (style.is_valid()) {
+ style->disconnect("changed", callable_mp(this, &Theme::_emit_theme_changed));
+ }
+ }
+
+ style_map.erase(p_theme_type);
+
+ _unfreeze_and_propagate_changes();
+}
+
void Theme::get_stylebox_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -577,6 +618,26 @@ void Theme::add_font_type(const StringName &p_theme_type) {
font_map[p_theme_type] = HashMap<StringName, Ref<Font>>();
}
+void Theme::remove_font_type(const StringName &p_theme_type) {
+ if (!font_map.has(p_theme_type)) {
+ return;
+ }
+
+ _freeze_change_propagation();
+
+ const StringName *L = nullptr;
+ while ((L = font_map[p_theme_type].next(L))) {
+ Ref<Font> font = font_map[p_theme_type][*L];
+ if (font.is_valid()) {
+ font->disconnect("changed", callable_mp(this, &Theme::_emit_theme_changed));
+ }
+ }
+
+ font_map.erase(p_theme_type);
+
+ _unfreeze_and_propagate_changes();
+}
+
void Theme::get_font_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -653,6 +714,14 @@ void Theme::add_font_size_type(const StringName &p_theme_type) {
font_size_map[p_theme_type] = HashMap<StringName, int>();
}
+void Theme::remove_font_size_type(const StringName &p_theme_type) {
+ if (!font_size_map.has(p_theme_type)) {
+ return;
+ }
+
+ font_size_map.erase(p_theme_type);
+}
+
void Theme::get_font_size_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -727,6 +796,14 @@ void Theme::add_color_type(const StringName &p_theme_type) {
color_map[p_theme_type] = HashMap<StringName, Color>();
}
+void Theme::remove_color_type(const StringName &p_theme_type) {
+ if (!color_map.has(p_theme_type)) {
+ return;
+ }
+
+ color_map.erase(p_theme_type);
+}
+
void Theme::get_color_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -801,6 +878,14 @@ void Theme::add_constant_type(const StringName &p_theme_type) {
constant_map[p_theme_type] = HashMap<StringName, int>();
}
+void Theme::remove_constant_type(const StringName &p_theme_type) {
+ if (!constant_map.has(p_theme_type)) {
+ return;
+ }
+
+ constant_map.erase(p_theme_type);
+}
+
void Theme::get_constant_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -1017,6 +1102,31 @@ void Theme::add_theme_item_type(DataType p_data_type, const StringName &p_theme_
}
}
+void Theme::remove_theme_item_type(DataType p_data_type, const StringName &p_theme_type) {
+ switch (p_data_type) {
+ case DATA_TYPE_COLOR:
+ remove_color_type(p_theme_type);
+ break;
+ case DATA_TYPE_CONSTANT:
+ remove_constant_type(p_theme_type);
+ break;
+ case DATA_TYPE_FONT:
+ remove_font_type(p_theme_type);
+ break;
+ case DATA_TYPE_FONT_SIZE:
+ remove_font_size_type(p_theme_type);
+ break;
+ case DATA_TYPE_ICON:
+ remove_icon_type(p_theme_type);
+ break;
+ case DATA_TYPE_STYLEBOX:
+ remove_stylebox_type(p_theme_type);
+ break;
+ case DATA_TYPE_MAX:
+ break; // Can't happen, but silences warning.
+ }
+}
+
void Theme::get_theme_item_type_list(DataType p_data_type, List<StringName> *p_list) const {
switch (p_data_type) {
case DATA_TYPE_COLOR:
@@ -1101,6 +1211,38 @@ void Theme::get_type_variation_list(const StringName &p_base_type, List<StringNa
}
// Theme types.
+void Theme::add_type(const StringName &p_theme_type) {
+ // Add a record to every data type map.
+ for (int i = 0; i < Theme::DATA_TYPE_MAX; i++) {
+ Theme::DataType dt = (Theme::DataType)i;
+ add_theme_item_type(dt, p_theme_type);
+ }
+
+ _emit_theme_changed(true);
+}
+
+void Theme::remove_type(const StringName &p_theme_type) {
+ // Gracefully remove the record from every data type map.
+ for (int i = 0; i < Theme::DATA_TYPE_MAX; i++) {
+ Theme::DataType dt = (Theme::DataType)i;
+ remove_theme_item_type(dt, p_theme_type);
+ }
+
+ // If type is a variation, remove that connection.
+ if (get_type_variation_base(p_theme_type) != StringName()) {
+ clear_type_variation(p_theme_type);
+ }
+
+ // If type is a variation base, remove all those connections.
+ List<StringName> names;
+ get_type_variation_list(p_theme_type, &names);
+ for (const StringName &E : names) {
+ clear_type_variation(E);
+ }
+
+ _emit_theme_changed(true);
+}
+
void Theme::get_type_list(List<StringName> *p_list) const {
ERR_FAIL_NULL(p_list);
@@ -1668,6 +1810,8 @@ void Theme::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_type_variation_base", "theme_type"), &Theme::get_type_variation_base);
ClassDB::bind_method(D_METHOD("get_type_variation_list", "base_type"), &Theme::_get_type_variation_list);
+ ClassDB::bind_method(D_METHOD("add_type", "theme_type"), &Theme::add_type);
+ ClassDB::bind_method(D_METHOD("remove_type", "theme_type"), &Theme::remove_type);
ClassDB::bind_method(D_METHOD("get_type_list"), &Theme::_get_type_list);
ClassDB::bind_method(D_METHOD("merge_with", "other"), &Theme::merge_with);
diff --git a/scene/resources/theme.h b/scene/resources/theme.h
index 822743a1fe..9afe05007d 100644
--- a/scene/resources/theme.h
+++ b/scene/resources/theme.h
@@ -32,7 +32,6 @@
#define THEME_H
#include "core/io/resource.h"
-#include "core/io/resource_loader.h"
#include "scene/resources/font.h"
#include "scene/resources/style_box.h"
#include "scene/resources/texture.h"
@@ -158,6 +157,7 @@ public:
void clear_icon(const StringName &p_name, const StringName &p_theme_type);
void get_icon_list(StringName p_theme_type, List<StringName> *p_list) const;
void add_icon_type(const StringName &p_theme_type);
+ void remove_icon_type(const StringName &p_theme_type);
void get_icon_type_list(List<StringName> *p_list) const;
void set_stylebox(const StringName &p_name, const StringName &p_theme_type, const Ref<StyleBox> &p_style);
@@ -168,6 +168,7 @@ public:
void clear_stylebox(const StringName &p_name, const StringName &p_theme_type);
void get_stylebox_list(StringName p_theme_type, List<StringName> *p_list) const;
void add_stylebox_type(const StringName &p_theme_type);
+ void remove_stylebox_type(const StringName &p_theme_type);
void get_stylebox_type_list(List<StringName> *p_list) const;
void set_font(const StringName &p_name, const StringName &p_theme_type, const Ref<Font> &p_font);
@@ -178,6 +179,7 @@ public:
void clear_font(const StringName &p_name, const StringName &p_theme_type);
void get_font_list(StringName p_theme_type, List<StringName> *p_list) const;
void add_font_type(const StringName &p_theme_type);
+ void remove_font_type(const StringName &p_theme_type);
void get_font_type_list(List<StringName> *p_list) const;
void set_font_size(const StringName &p_name, const StringName &p_theme_type, int p_font_size);
@@ -188,6 +190,7 @@ public:
void clear_font_size(const StringName &p_name, const StringName &p_theme_type);
void get_font_size_list(StringName p_theme_type, List<StringName> *p_list) const;
void add_font_size_type(const StringName &p_theme_type);
+ void remove_font_size_type(const StringName &p_theme_type);
void get_font_size_type_list(List<StringName> *p_list) const;
void set_color(const StringName &p_name, const StringName &p_theme_type, const Color &p_color);
@@ -198,6 +201,7 @@ public:
void clear_color(const StringName &p_name, const StringName &p_theme_type);
void get_color_list(StringName p_theme_type, List<StringName> *p_list) const;
void add_color_type(const StringName &p_theme_type);
+ void remove_color_type(const StringName &p_theme_type);
void get_color_type_list(List<StringName> *p_list) const;
void set_constant(const StringName &p_name, const StringName &p_theme_type, int p_constant);
@@ -208,6 +212,7 @@ public:
void clear_constant(const StringName &p_name, const StringName &p_theme_type);
void get_constant_list(StringName p_theme_type, List<StringName> *p_list) const;
void add_constant_type(const StringName &p_theme_type);
+ void remove_constant_type(const StringName &p_theme_type);
void get_constant_type_list(List<StringName> *p_list) const;
void set_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type, const Variant &p_value);
@@ -218,6 +223,7 @@ public:
void clear_theme_item(DataType p_data_type, const StringName &p_name, const StringName &p_theme_type);
void get_theme_item_list(DataType p_data_type, StringName p_theme_type, List<StringName> *p_list) const;
void add_theme_item_type(DataType p_data_type, const StringName &p_theme_type);
+ void remove_theme_item_type(DataType p_data_type, const StringName &p_theme_type);
void get_theme_item_type_list(DataType p_data_type, List<StringName> *p_list) const;
void set_type_variation(const StringName &p_theme_type, const StringName &p_base_type);
@@ -226,6 +232,8 @@ public:
StringName get_type_variation_base(const StringName &p_theme_type) const;
void get_type_variation_list(const StringName &p_base_type, List<StringName> *p_list) const;
+ void add_type(const StringName &p_theme_type);
+ void remove_type(const StringName &p_theme_type);
void get_type_list(List<StringName> *p_list) const;
void get_type_dependencies(const StringName &p_base_type, const StringName &p_type_variant, List<StringName> *p_list);
diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp
index 2854cbe30d..1174117028 100644
--- a/scene/resources/tile_set.cpp
+++ b/scene/resources/tile_set.cpp
@@ -4410,7 +4410,7 @@ void TileSetAtlasSource::_clear_tiles_outside_texture() {
void TileSetAtlasSource::_queue_update_padded_texture() {
padded_texture_needs_update = true;
- call_deferred("_update_padded_texture");
+ call_deferred(SNAME("_update_padded_texture"));
}
void TileSetAtlasSource::_update_padded_texture() {
@@ -4432,9 +4432,13 @@ void TileSetAtlasSource::_update_padded_texture() {
Ref<Image> src = texture->get_image();
+ if (!src.is_valid()) {
+ return;
+ }
+
Ref<Image> image;
image.instantiate();
- image->create(size.x, size.y, false, Image::FORMAT_RGBA8);
+ image->create(size.x, size.y, false, src->get_format());
for (KeyValue<Vector2i, TileAlternativesData> kv : tiles) {
for (int frame = 0; frame < (int)kv.value.animation_frames_durations.size(); frame++) {
diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp
index dd2f3d2202..dae61c8609 100644
--- a/scene/resources/visual_shader.cpp
+++ b/scene/resources/visual_shader.cpp
@@ -131,7 +131,7 @@ void VisualShaderNode::set_input_port_default_value(int p_port, const Variant &p
} break;
case Variant::VECTOR2: {
Vector2 pv = p_prev_value;
- value = Vector3(pv.x, pv.y, 0.0);
+ value = Vector3(pv.x, pv.y, pv.y);
} break;
case Variant::VECTOR3: {
value = p_prev_value;
@@ -250,7 +250,7 @@ int VisualShaderNode::get_expanded_output_port_count() const {
case PORT_TYPE_VECTOR_2D: {
count2 += 2;
} break;
- case PORT_TYPE_VECTOR: {
+ case PORT_TYPE_VECTOR_3D: {
count2 += 3;
} break;
default:
@@ -289,7 +289,7 @@ String VisualShaderNode::generate_global(Shader::Mode p_mode, VisualShader::Type
return String();
}
-String VisualShaderNode::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+String VisualShaderNode::generate_global_per_node(Shader::Mode p_mode, int p_id) const {
return String();
}
@@ -359,7 +359,7 @@ void VisualShaderNode::_bind_methods() {
BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR);
BIND_ENUM_CONSTANT(PORT_TYPE_SCALAR_INT);
BIND_ENUM_CONSTANT(PORT_TYPE_VECTOR_2D);
- BIND_ENUM_CONSTANT(PORT_TYPE_VECTOR);
+ BIND_ENUM_CONSTANT(PORT_TYPE_VECTOR_3D);
BIND_ENUM_CONSTANT(PORT_TYPE_BOOLEAN);
BIND_ENUM_CONSTANT(PORT_TYPE_TRANSFORM);
BIND_ENUM_CONSTANT(PORT_TYPE_SAMPLER);
@@ -472,7 +472,7 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader::
return code;
}
-String VisualShaderNodeCustom::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+String VisualShaderNodeCustom::generate_global_per_node(Shader::Mode p_mode, int p_id) const {
String ret;
if (GDVIRTUAL_CALL(_get_global_code, p_mode, ret)) {
String code = "// " + get_caption() + "\n";
@@ -1088,7 +1088,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port
case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
code += " COLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + ", 0.0);\n";
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
code += " COLOR.rgb = n_out" + itos(p_node) + "p" + itos(p_port) + ";\n";
} break;
default: {
@@ -1485,7 +1485,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
class_name = vsnode->get_script_instance()->get_script()->get_path();
}
if (!r_classes.has(class_name)) {
- global_code_per_node += vsnode->generate_global_per_node(get_mode(), type, node);
+ global_code_per_node += vsnode->generate_global_per_node(get_mode(), node);
for (int i = 0; i < TYPE_MAX; i++) {
global_code_per_func[Type(i)] += vsnode->generate_global_per_func(get_mode(), Type(i), node);
}
@@ -1549,7 +1549,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
inputs[i] = "dot(" + src_var + ", vec2(0.333333, 0.333333))";
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
inputs[i] = "dot(" + src_var + ", vec3(0.333333, 0.333333, 0.333333))";
} break;
default:
@@ -1567,7 +1567,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
inputs[i] = "dot(float(" + src_var + "), vec2(0.333333, 0.333333))";
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
inputs[i] = "dot(float(" + src_var + "), vec3(0.333333, 0.333333, 0.333333))";
} break;
default:
@@ -1585,7 +1585,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
inputs[i] = "all(bvec2(" + src_var + "))";
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
inputs[i] = "all(bvec3(" + src_var + "))";
} break;
default:
@@ -1603,7 +1603,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_BOOLEAN: {
inputs[i] = "vec2(" + src_var + " ? 1.0 : 0.0)";
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
inputs[i] = "vec2(" + src_var + ".xy)";
} break;
default:
@@ -1611,7 +1611,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
}
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
switch (out_type) {
case VisualShaderNode::PORT_TYPE_SCALAR: {
inputs[i] = "vec3(" + src_var + ")";
@@ -1695,7 +1695,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
output_count += 2;
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
output_count += 3;
} break;
default:
@@ -1722,7 +1722,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_VECTOR_2D:
outputs[i] = "vec2 " + var_name;
break;
- case VisualShaderNode::PORT_TYPE_VECTOR:
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D:
outputs[i] = "vec3 " + var_name;
break;
case VisualShaderNode::PORT_TYPE_BOOLEAN:
@@ -1739,7 +1739,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
j += 2;
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
j += 3;
} break;
default:
@@ -1761,7 +1761,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_VECTOR_2D:
code += " vec2 " + outputs[i] + ";\n";
break;
- case VisualShaderNode::PORT_TYPE_VECTOR:
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D:
code += " vec3 " + outputs[i] + ";\n";
break;
case VisualShaderNode::PORT_TYPE_BOOLEAN:
@@ -1778,7 +1778,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
case VisualShaderNode::PORT_TYPE_VECTOR_2D: {
j += 2;
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
j += 3;
} break;
default:
@@ -1822,7 +1822,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui
i += 2;
} break;
- case VisualShaderNode::PORT_TYPE_VECTOR: {
+ case VisualShaderNode::PORT_TYPE_VECTOR_3D: {
if (vsnode->is_output_port_connected(i + 1) || (for_preview && vsnode->get_output_port_for_preview() == (i + 1))) { // red-component
if (!new_line_inserted) {
code += "\n";
@@ -2146,7 +2146,11 @@ void VisualShader::_update_shader() const {
global_compute_code += " return __rand_from_seed(seed) * (to - from) + from;\n";
global_compute_code += "}\n\n";
- global_compute_code += "vec3 __randv_range(inout uint seed, vec3 from, vec3 to) {\n";
+ global_compute_code += "vec2 __randv2_range(inout uint seed, vec2 from, vec2 to) {\n";
+ global_compute_code += " return vec2(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y));\n";
+ global_compute_code += "}\n\n";
+
+ global_compute_code += "vec3 __randv3_range(inout uint seed, vec3 from, vec3 to) {\n";
global_compute_code += " return vec3(__randf_range(seed, from.x, to.x), __randf_range(seed, from.y, to.y), __randf_range(seed, from.z, to.z));\n";
global_compute_code += "}\n\n";
@@ -2322,17 +2326,17 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
// Node3D
// Node3D, Vertex
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "vertex", "VERTEX" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "NORMAL" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "tangent", "TANGENT" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "binormal", "BINORMAL" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "vertex", "VERTEX" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "NORMAL" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "tangent", "TANGENT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "binormal", "BINORMAL" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv2", "UV2" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "point_size", "POINT_SIZE" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR_INT, "instance_id", "INSTANCE_ID" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "instance_custom", "INSTANCE_CUSTOM.rgb" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "instance_custom", "INSTANCE_CUSTOM.rgb" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "instance_custom_alpha", "INSTANCE_CUSTOM.a" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "roughness", "ROUGHNESS" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_TRANSFORM, "world", "WORLD_MATRIX" },
@@ -2346,15 +2350,15 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_BOOLEAN, "output_is_srgb", "OUTPUT_IS_SRGB" },
// Node3D, Fragment
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.xyz" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "vertex", "VERTEX" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "NORMAL" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "tangent", "TANGENT" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "binormal", "BINORMAL" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "view", "VIEW" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fragcoord", "FRAGCOORD.xyz" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "vertex", "VERTEX" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "NORMAL" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "tangent", "TANGENT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "binormal", "BINORMAL" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "view", "VIEW" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv2", "UV2" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "point_coord", "POINT_COORD" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "screen_uv", "SCREEN_UV" },
@@ -2372,18 +2376,18 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "depth_texture", "DEPTH_TEXTURE" },
// Node3D, Light
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.xyz" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "NORMAL" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fragcoord", "FRAGCOORD.xyz" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "NORMAL" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv2", "UV2" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "view", "VIEW" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light", "LIGHT" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_color", "LIGHT_COLOR" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "view", "VIEW" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light", "LIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light_color", "LIGHT_COLOR" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "attenuation", "ATTENUATION" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "albedo", "ALBEDO" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "backlight", "BACKLIGHT" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "diffuse", "DIFFUSE_LIGHT" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "specular", "SPECULAR_LIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "albedo", "ALBEDO" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "backlight", "BACKLIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "diffuse", "DIFFUSE_LIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "specular", "SPECULAR_LIGHT" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "roughness", "ROUGHNESS" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "metallic", "METALLIC" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_TRANSFORM, "world", "WORLD_MATRIX" },
@@ -2400,7 +2404,7 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
// Canvas Item, Vertex
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "vertex", "VERTEX" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "point_size", "POINT_SIZE" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "texture_pixel_size", "TEXTURE_PIXEL_SIZE" },
@@ -2409,13 +2413,13 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_TRANSFORM, "screen", "SCREEN_MATRIX" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_BOOLEAN, "at_light_pass", "AT_LIGHT_PASS" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "instance_custom", "INSTANCE_CUSTOM.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "instance_custom", "INSTANCE_CUSTOM.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "instance_custom_alpha", "INSTANCE_CUSTOM.a" },
// Canvas Item, Fragment
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.xyz" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fragcoord", "FRAGCOORD.xyz" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "screen_uv", "SCREEN_UV" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "texture_pixel_size", "TEXTURE_PIXEL_SIZE" },
@@ -2426,41 +2430,41 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "texture", "TEXTURE" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "normal_texture", "NORMAL_TEXTURE" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "screen_texture", "SCREEN_TEXTURE" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "specular_shininess", "SPECULAR_SHININESS.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "specular_shininess", "SPECULAR_SHININESS.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "specular_shininess_alpha", "SPECULAR_SHININESS.a" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SAMPLER, "specular_shininess_texture", "SPECULAR_SHININESS_TEXTURE" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "vertex", "VERTEX" },
// Canvas Item, Light
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.xyz" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fragcoord", "FRAGCOORD.xyz" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "NORMAL" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "NORMAL" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light", "LIGHT.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light", "LIGHT.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "light_alpha", "LIGHT.a" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_color", "LIGHT_COLOR.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light_color", "LIGHT_COLOR.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "light_color_alpha", "LIGHT_COLOR.a" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_position", "LIGHT_POSITION" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light_vertex", "LIGHT_VERTEX" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "shadow", "SHADOW_MODULATE.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light_position", "LIGHT_POSITION" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light_vertex", "LIGHT_VERTEX" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "shadow", "SHADOW_MODULATE.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "shadow_alpha", "SHADOW_MODULATE.a" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "screen_uv", "SCREEN_UV" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "texture_pixel_size", "TEXTURE_PIXEL_SIZE" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "point_coord", "POINT_COORD" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SAMPLER, "texture", "TEXTURE" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "specular_shininess", "SPECULAR_SHININESS.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "specular_shininess", "SPECULAR_SHININESS.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "specular_shininess_alpha", "SPECULAR_SHININESS.a" },
// Particles, Start
- { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_VECTOR, "attractor_force", "ATTRACTOR_FORCE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_VECTOR_3D, "attractor_force", "ATTRACTOR_FORCE" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_VECTOR, "velocity", "VELOCITY" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_VECTOR_3D, "velocity", "VELOCITY" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_BOOLEAN, "restart", "RESTART" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_BOOLEAN, "active", "ACTIVE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_VECTOR, "custom", "CUSTOM.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_VECTOR_3D, "custom", "CUSTOM.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR, "custom_alpha", "CUSTOM.a" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" },
@@ -2470,13 +2474,13 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
// Particles, Start (Custom)
- { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR, "attractor_force", "ATTRACTOR_FORCE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR_3D, "attractor_force", "ATTRACTOR_FORCE" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR, "velocity", "VELOCITY" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR_3D, "velocity", "VELOCITY" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_BOOLEAN, "restart", "RESTART" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_BOOLEAN, "active", "ACTIVE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR, "custom", "CUSTOM.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR_3D, "custom", "CUSTOM.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "custom_alpha", "CUSTOM.a" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" },
@@ -2486,13 +2490,13 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_PARTICLES, VisualShader::TYPE_START_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
// Particles, Process
- { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_VECTOR, "attractor_force", "ATTRACTOR_FORCE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_VECTOR_3D, "attractor_force", "ATTRACTOR_FORCE" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_VECTOR, "velocity", "VELOCITY" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_VECTOR_3D, "velocity", "VELOCITY" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_BOOLEAN, "restart", "RESTART" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_BOOLEAN, "active", "ACTIVE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_VECTOR, "custom", "CUSTOM.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_VECTOR_3D, "custom", "CUSTOM.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR, "custom_alpha", "CUSTOM.a" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" },
@@ -2502,13 +2506,13 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
// Particles, Process (Custom)
- { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR, "attractor_force", "ATTRACTOR_FORCE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR_3D, "attractor_force", "ATTRACTOR_FORCE" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR, "velocity", "VELOCITY" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR_3D, "velocity", "VELOCITY" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_BOOLEAN, "restart", "RESTART" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_BOOLEAN, "active", "ACTIVE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR, "custom", "CUSTOM.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_VECTOR_3D, "custom", "CUSTOM.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "custom_alpha", "CUSTOM.a" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" },
@@ -2518,15 +2522,15 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_PARTICLES, VisualShader::TYPE_PROCESS_CUSTOM, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
// Particles, Collide
- { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR, "attractor_force", "ATTRACTOR_FORCE" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR_3D, "attractor_force", "ATTRACTOR_FORCE" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR, "collision_depth", "COLLISION_DEPTH" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR, "collision_normal", "COLLISION_NORMAL" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR_3D, "collision_normal", "COLLISION_NORMAL" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR, "velocity", "VELOCITY" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR_3D, "velocity", "VELOCITY" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_BOOLEAN, "restart", "RESTART" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_BOOLEAN, "active", "ACTIVE" },
- { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR, "custom", "CUSTOM.rgb" },
+ { Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_VECTOR_3D, "custom", "CUSTOM.rgb" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR, "custom_alpha", "CUSTOM.a" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_TRANSFORM, "transform", "TRANSFORM" },
{ Shader::MODE_PARTICLES, VisualShader::TYPE_COLLIDE, VisualShaderNode::PORT_TYPE_SCALAR, "delta", "DELTA" },
@@ -2539,27 +2543,27 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_BOOLEAN, "at_cubemap_pass", "AT_CUBEMAP_PASS" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_BOOLEAN, "at_half_res_pass", "AT_HALF_RES_PASS" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_BOOLEAN, "at_quarter_res_pass", "AT_QUARTER_RES_PASS" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "eyedir", "EYEDIR" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "half_res_color", "HALF_RES_COLOR.rgb" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "eyedir", "EYEDIR" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "half_res_color", "HALF_RES_COLOR.rgb" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "half_res_alpha", "HALF_RES_COLOR.a" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "light0_color", "LIGHT0_COLOR" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "light0_direction", "LIGHT0_DIRECTION" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light0_color", "LIGHT0_COLOR" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light0_direction", "LIGHT0_DIRECTION" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_BOOLEAN, "light0_enabled", "LIGHT0_ENABLED" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "light0_energy", "LIGHT0_ENERGY" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "light1_color", "LIGHT1_COLOR" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "light1_direction", "LIGHT1_DIRECTION" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light1_color", "LIGHT1_COLOR" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light1_direction", "LIGHT1_DIRECTION" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_BOOLEAN, "light1_enabled", "LIGHT1_ENABLED" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "light1_energy", "LIGHT1_ENERGY" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "light2_color", "LIGHT2_COLOR" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "light2_direction", "LIGHT2_DIRECTION" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light2_color", "LIGHT2_COLOR" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light2_direction", "LIGHT2_DIRECTION" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_BOOLEAN, "light2_enabled", "LIGHT2_ENABLED" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "light2_energy", "LIGHT2_ENERGY" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "light3_color", "LIGHT3_COLOR" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "light3_direction", "LIGHT3_DIRECTION" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light3_color", "LIGHT3_COLOR" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light3_direction", "LIGHT3_DIRECTION" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_BOOLEAN, "light3_enabled", "LIGHT3_ENABLED" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "light3_energy", "LIGHT3_ENERGY" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "position", "POSITION" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "quarter_res_color", "QUARTER_RES_COLOR.rgb" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "position", "POSITION" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "quarter_res_color", "QUARTER_RES_COLOR.rgb" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "quarter_res_alpha", "QUARTER_RES_COLOR.a" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SAMPLER, "radiance", "RADIANCE" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_2D, "screen_uv", "SCREEN_UV" },
@@ -2568,10 +2572,10 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
// Fog, Fog
- { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR, "world_position", "WORLD_POSITION" },
- { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR, "object_position", "OBJECT_POSITION" },
- { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR, "uvw", "UVW" },
- { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR, "extents", "EXTENTS" },
+ { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "world_position", "WORLD_POSITION" },
+ { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "object_position", "OBJECT_POSITION" },
+ { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "uvw", "UVW" },
+ { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "extents", "EXTENTS" },
{ Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_SCALAR, "sdf", "SDF" },
{ Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
@@ -2581,25 +2585,25 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::ports[] = {
const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = {
// Spatial, Vertex
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "vec3(0.0, 0.0, 1.0)" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "tangent", "vec3(0.0, 1.0, 0.0)" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "binormal", "vec3(1.0, 0.0, 0.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "vec3(0.0, 0.0, 1.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "tangent", "vec3(0.0, 1.0, 0.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "binormal", "vec3(1.0, 0.0, 0.0)" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv2", "UV" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "color", "vec3(1.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "vec3(1.0)" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "1.0" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "viewport_size", "vec2(1.0)" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
// Spatial, Fragment
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.rgb" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "vec3(0.0, 0.0, 1.0)" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "tangent", "vec3(0.0, 1.0, 0.0)" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "binormal", "vec3(1.0, 0.0, 0.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fragcoord", "FRAGCOORD.rgb" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "vec3(0.0, 0.0, 1.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "tangent", "vec3(0.0, 1.0, 0.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "binormal", "vec3(1.0, 0.0, 0.0)" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv2", "UV" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "color", "vec3(1.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "vec3(1.0)" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "1.0" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "screen_uv", "SCREEN_UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "viewport_size", "vec2(1.0)" },
@@ -2607,8 +2611,8 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = {
// Spatial, Light
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.rgb" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "vec3(0.0, 0.0, 1.0)" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fragcoord", "FRAGCOORD.rgb" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "vec3(0.0, 0.0, 1.0)" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv2", "UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "viewport_size", "vec2(1.0)" },
@@ -2618,25 +2622,25 @@ const VisualShaderNodeInput::Port VisualShaderNodeInput::preview_ports[] = {
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "vertex", "VERTEX" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "color", "vec3(1.0)" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "vec3(1.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "1.0" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
// Canvas Item, Fragment
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fragcoord", "FRAGCOORD.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "color", "vec3(1.0)" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "vec3(1.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "1.0" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "screen_uv", "SCREEN_UV" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
// Canvas Item, Light
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "fragcoord", "FRAGCOORD.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fragcoord", "FRAGCOORD.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "vec3(0.0, 0.0, 1.0)" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "color", "vec3(1.0)" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "vec3(0.0, 0.0, 1.0)" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "vec3(1.0)" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "1.0" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "screen_uv", "SCREEN_UV" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "time", "TIME" },
@@ -2718,7 +2722,7 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T
case PORT_TYPE_VECTOR_2D: {
code = " " + p_output_vars[0] + " = vec2(0.0);\n";
} break;
- case PORT_TYPE_VECTOR: {
+ case PORT_TYPE_VECTOR_3D: {
code = " " + p_output_vars[0] + " = vec3(0.0);\n";
} break;
case PORT_TYPE_BOOLEAN: {
@@ -2960,12 +2964,12 @@ VisualShaderNodeUniformRef::PortType VisualShaderNodeUniformRef::get_output_port
case UniformType::UNIFORM_TYPE_VECTOR2:
return PortType::PORT_TYPE_VECTOR_2D;
case UniformType::UNIFORM_TYPE_VECTOR3:
- return PortType::PORT_TYPE_VECTOR;
+ return PortType::PORT_TYPE_VECTOR_3D;
case UniformType::UNIFORM_TYPE_TRANSFORM:
return PortType::PORT_TYPE_TRANSFORM;
case UniformType::UNIFORM_TYPE_COLOR:
if (p_port == 0) {
- return PortType::PORT_TYPE_VECTOR;
+ return PortType::PORT_TYPE_VECTOR_3D;
} else if (p_port == 1) {
return PORT_TYPE_SCALAR;
}
@@ -3061,11 +3065,11 @@ VisualShaderNodeUniformRef::PortType VisualShaderNodeUniformRef::get_port_type_b
case UniformType::UNIFORM_TYPE_VECTOR2:
return PORT_TYPE_VECTOR_2D;
case UniformType::UNIFORM_TYPE_VECTOR3:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case UniformType::UNIFORM_TYPE_TRANSFORM:
return PORT_TYPE_TRANSFORM;
case UniformType::UNIFORM_TYPE_COLOR:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -3131,29 +3135,29 @@ const VisualShaderNodeOutput::Port VisualShaderNodeOutput::ports[] = {
////////////////////////////////////////////////////////////////////////
// Node3D, Vertex.
////////////////////////////////////////////////////////////////////////
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "vertex", "VERTEX" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "NORMAL" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "tangent", "TANGENT" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "binormal", "BINORMAL" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "vertex", "VERTEX" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "NORMAL" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "tangent", "TANGENT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "binormal", "BINORMAL" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv2", "UV2" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "roughness", "ROUGHNESS" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_TRANSFORM, "model_view_matrix", "MODELVIEW_MATRIX" },
////////////////////////////////////////////////////////////////////////
// Node3D, Fragment.
////////////////////////////////////////////////////////////////////////
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "albedo", "ALBEDO" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "albedo", "ALBEDO" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "ALPHA" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "metallic", "METALLIC" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "roughness", "ROUGHNESS" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "specular", "SPECULAR" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "emission", "EMISSION" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "emission", "EMISSION" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "ao", "AO" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "NORMAL" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "normal_map", "NORMAL_MAP" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "NORMAL" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal_map", "NORMAL_MAP" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "normal_map_depth", "NORMAL_MAP_DEPTH" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "rim", "RIM" },
@@ -3163,15 +3167,15 @@ const VisualShaderNodeOutput::Port VisualShaderNodeOutput::ports[] = {
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "anisotropy", "ANISOTROPY" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "anisotropy_flow", "ANISOTROPY_FLOW" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "subsurf_scatter", "SSS_STRENGTH" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "backlight", "BACKLIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "backlight", "BACKLIGHT" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha_scissor_threshold", "ALPHA_SCISSOR_THRESHOLD" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "ao_light_affect", "AO_LIGHT_AFFECT" },
////////////////////////////////////////////////////////////////////////
// Node3D, Light.
////////////////////////////////////////////////////////////////////////
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "diffuse", "DIFFUSE_LIGHT" },
- { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "specular", "SPECULAR_LIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "diffuse", "DIFFUSE_LIGHT" },
+ { Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "specular", "SPECULAR_LIGHT" },
{ Shader::MODE_SPATIAL, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "ALPHA" },
////////////////////////////////////////////////////////////////////////
@@ -3181,39 +3185,39 @@ const VisualShaderNodeOutput::Port VisualShaderNodeOutput::ports[] = {
////////////////////////////////////////////////////////////////////////
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "vertex", "VERTEX" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_2D, "uv", "UV" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_VERTEX, VisualShaderNode::PORT_TYPE_SCALAR, "point_size", "POINT_SIZE" },
////////////////////////////////////////////////////////////////////////
// Canvas Item, Fragment.
////////////////////////////////////////////////////////////////////////
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "COLOR.a" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "normal", "NORMAL" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "normal_map", "NORMAL_MAP" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal", "NORMAL" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "normal_map", "NORMAL_MAP" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_SCALAR, "normal_map_depth", "NORMAL_MAP_DEPTH" },
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR, "light_vertex", "LIGHT_VERTEX" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light_vertex", "LIGHT_VERTEX" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_FRAGMENT, VisualShaderNode::PORT_TYPE_VECTOR_2D, "shadow_vertex", "SHADOW_VERTEX" },
////////////////////////////////////////////////////////////////////////
// Canvas Item, Light.
////////////////////////////////////////////////////////////////////////
- { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR, "light", "LIGHT.rgb" },
+ { Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_VECTOR_3D, "light", "LIGHT.rgb" },
{ Shader::MODE_CANVAS_ITEM, VisualShader::TYPE_LIGHT, VisualShaderNode::PORT_TYPE_SCALAR, "light_alpha", "LIGHT.a" },
////////////////////////////////////////////////////////////////////////
// Sky, Sky.
////////////////////////////////////////////////////////////////////////
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "color", "COLOR" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "color", "COLOR" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "alpha", "ALPHA" },
- { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR, "fog", "FOG.rgb" },
+ { Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_VECTOR_3D, "fog", "FOG.rgb" },
{ Shader::MODE_SKY, VisualShader::TYPE_SKY, VisualShaderNode::PORT_TYPE_SCALAR, "fog_alpha", "FOG.a" },
////////////////////////////////////////////////////////////////////////
// Fog, Fog.
////////////////////////////////////////////////////////////////////////
{ Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_SCALAR, "density", "DENSITY" },
- { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR, "albedo", "ALBEDO" },
- { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR, "emission", "EMISSION" },
+ { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "albedo", "ALBEDO" },
+ { Shader::MODE_FOG, VisualShader::TYPE_FOG, VisualShaderNode::PORT_TYPE_VECTOR_3D, "emission", "EMISSION" },
////////////////////////////////////////////////////////////////////////
{ Shader::MODE_MAX, VisualShader::TYPE_MAX, VisualShaderNode::PORT_TYPE_TRANSFORM, nullptr, nullptr },
@@ -4147,7 +4151,7 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad
case PORT_TYPE_VECTOR_2D:
tk = "vec2(0.0, 0.0)";
break;
- case PORT_TYPE_VECTOR:
+ case PORT_TYPE_VECTOR_3D:
tk = "vec3(0.0, 0.0, 0.0)";
break;
case PORT_TYPE_BOOLEAN:
diff --git a/scene/resources/visual_shader.h b/scene/resources/visual_shader.h
index 9f877e08a5..d3b5365893 100644
--- a/scene/resources/visual_shader.h
+++ b/scene/resources/visual_shader.h
@@ -215,7 +215,7 @@ public:
PORT_TYPE_SCALAR,
PORT_TYPE_SCALAR_INT,
PORT_TYPE_VECTOR_2D,
- PORT_TYPE_VECTOR,
+ PORT_TYPE_VECTOR_3D,
PORT_TYPE_BOOLEAN,
PORT_TYPE_TRANSFORM,
PORT_TYPE_SAMPLER,
@@ -275,7 +275,7 @@ public:
virtual Vector<VisualShader::DefaultTextureParam> get_default_texture_parameters(VisualShader::Type p_type, int p_id) const;
virtual String generate_global(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
- virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
+ virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const;
virtual String generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const;
// If no output is connected, the output var passed will be empty. If no input is connected and input is NIL, the input var passed will be empty.
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const = 0;
@@ -335,7 +335,7 @@ protected:
void _set_input_port_default_value(int p_port, const Variant &p_value);
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override;
- virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
+ virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override;
static void _bind_methods();
diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp
index 9a714fd3dd..a6aa6d8c49 100644
--- a/scene/resources/visual_shader_nodes.cpp
+++ b/scene/resources/visual_shader_nodes.cpp
@@ -37,7 +37,7 @@ VisualShaderNodeVectorBase::PortType VisualShaderNodeVectorBase::get_input_port_
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -49,7 +49,7 @@ VisualShaderNodeVectorBase::PortType VisualShaderNodeVectorBase::get_output_port
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -291,7 +291,7 @@ int VisualShaderNodeColorConstant::get_input_port_count() const {
}
VisualShaderNodeColorConstant::PortType VisualShaderNodeColorConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeColorConstant::get_input_port_name(int p_port) const {
@@ -303,7 +303,7 @@ int VisualShaderNodeColorConstant::get_output_port_count() const {
}
VisualShaderNodeColorConstant::PortType VisualShaderNodeColorConstant::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
+ return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
}
String VisualShaderNodeColorConstant::get_output_port_name(int p_port) const {
@@ -426,7 +426,7 @@ int VisualShaderNodeVec3Constant::get_input_port_count() const {
}
VisualShaderNodeVec3Constant::PortType VisualShaderNodeVec3Constant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeVec3Constant::get_input_port_name(int p_port) const {
@@ -438,7 +438,7 @@ int VisualShaderNodeVec3Constant::get_output_port_count() const {
}
VisualShaderNodeVec3Constant::PortType VisualShaderNodeVec3Constant::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeVec3Constant::get_output_port_name(int p_port) const {
@@ -488,7 +488,7 @@ int VisualShaderNodeTransformConstant::get_input_port_count() const {
}
VisualShaderNodeTransformConstant::PortType VisualShaderNodeTransformConstant::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeTransformConstant::get_input_port_name(int p_port) const {
@@ -591,7 +591,7 @@ VisualShaderNodeTexture::PortType VisualShaderNodeTexture::get_output_port_type(
if (p_port == 0 && source == SOURCE_DEPTH) {
return PORT_TYPE_SCALAR;
}
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
+ return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
}
String VisualShaderNodeTexture::get_output_port_name(int p_port) const {
@@ -1064,7 +1064,7 @@ int VisualShaderNodeCurveXYZTexture::get_output_port_count() const {
}
VisualShaderNodeCurveXYZTexture::PortType VisualShaderNodeCurveXYZTexture::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeCurveXYZTexture::get_output_port_name(int p_port) const {
@@ -1135,7 +1135,7 @@ int VisualShaderNodeSample3D::get_input_port_count() const {
VisualShaderNodeSample3D::PortType VisualShaderNodeSample3D::get_input_port_type(int p_port) const {
switch (p_port) {
case 0:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case 1:
return PORT_TYPE_SCALAR;
case 2:
@@ -1161,7 +1161,7 @@ int VisualShaderNodeSample3D::get_output_port_count() const {
}
VisualShaderNodeSample3D::PortType VisualShaderNodeSample3D::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
+ return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
}
String VisualShaderNodeSample3D::get_output_port_name(int p_port) const {
@@ -1398,7 +1398,7 @@ int VisualShaderNodeCubemap::get_input_port_count() const {
VisualShaderNodeCubemap::PortType VisualShaderNodeCubemap::get_input_port_type(int p_port) const {
switch (p_port) {
case 0:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case 1:
return PORT_TYPE_SCALAR;
case 2:
@@ -1426,7 +1426,7 @@ int VisualShaderNodeCubemap::get_output_port_count() const {
}
VisualShaderNodeCubemap::PortType VisualShaderNodeCubemap::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
+ return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
}
String VisualShaderNodeCubemap::get_output_port_name(int p_port) const {
@@ -2020,7 +2020,7 @@ int VisualShaderNodeColorOp::get_input_port_count() const {
}
VisualShaderNodeColorOp::PortType VisualShaderNodeColorOp::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeColorOp::get_input_port_name(int p_port) const {
@@ -2032,7 +2032,7 @@ int VisualShaderNodeColorOp::get_output_port_count() const {
}
VisualShaderNodeColorOp::PortType VisualShaderNodeColorOp::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeColorOp::get_output_port_name(int p_port) const {
@@ -2293,7 +2293,7 @@ int VisualShaderNodeTransformVecMult::get_input_port_count() const {
}
VisualShaderNodeTransformVecMult::PortType VisualShaderNodeTransformVecMult::get_input_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_TRANSFORM : PORT_TYPE_VECTOR;
+ return p_port == 0 ? PORT_TYPE_TRANSFORM : PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeTransformVecMult::get_input_port_name(int p_port) const {
@@ -2305,7 +2305,7 @@ int VisualShaderNodeTransformVecMult::get_output_port_count() const {
}
VisualShaderNodeTransformVecMult::PortType VisualShaderNodeTransformVecMult::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeTransformVecMult::get_output_port_name(int p_port) const {
@@ -2815,7 +2815,7 @@ int VisualShaderNodeColorFunc::get_input_port_count() const {
}
VisualShaderNodeColorFunc::PortType VisualShaderNodeColorFunc::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeColorFunc::get_input_port_name(int p_port) const {
@@ -2827,7 +2827,7 @@ int VisualShaderNodeColorFunc::get_output_port_count() const {
}
VisualShaderNodeColorFunc::PortType VisualShaderNodeColorFunc::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeColorFunc::get_output_port_name(int p_port) const {
@@ -2843,8 +2843,7 @@ String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShade
code += " vec3 c = " + p_input_vars[0] + ";\n";
code += " float max1 = max(c.r, c.g);\n";
code += " float max2 = max(max1, c.b);\n";
- code += " float max3 = max(max1, max2);\n";
- code += " " + p_output_vars[0] + " = vec3(max3, max3, max3);\n";
+ code += " " + p_output_vars[0] + " = vec3(max2, max2, max2);\n";
code += " }\n";
break;
case FUNC_SEPIA:
@@ -3124,7 +3123,7 @@ int VisualShaderNodeDotProduct::get_input_port_count() const {
}
VisualShaderNodeDotProduct::PortType VisualShaderNodeDotProduct::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeDotProduct::get_input_port_name(int p_port) const {
@@ -3258,7 +3257,7 @@ VisualShaderNodeDerivativeFunc::PortType VisualShaderNodeDerivativeFunc::get_inp
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -3278,7 +3277,7 @@ VisualShaderNodeDerivativeFunc::PortType VisualShaderNodeDerivativeFunc::get_out
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -3389,7 +3388,7 @@ VisualShaderNodeClamp::PortType VisualShaderNodeClamp::get_input_port_type(int p
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -3418,7 +3417,7 @@ VisualShaderNodeClamp::PortType VisualShaderNodeClamp::get_output_port_type(int
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -3570,7 +3569,7 @@ int VisualShaderNodeOuterProduct::get_input_port_count() const {
}
VisualShaderNodeOuterProduct::PortType VisualShaderNodeOuterProduct::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeOuterProduct::get_input_port_name(int p_port) const {
@@ -3625,10 +3624,10 @@ VisualShaderNodeStep::PortType VisualShaderNodeStep::get_input_port_type(int p_p
}
break;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case OP_TYPE_VECTOR_3D_SCALAR:
if (p_port == 1) {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
break;
default:
@@ -3658,9 +3657,9 @@ VisualShaderNodeStep::PortType VisualShaderNodeStep::get_output_port_type(int p_
case OP_TYPE_VECTOR_2D_SCALAR:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case OP_TYPE_VECTOR_3D_SCALAR:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -3757,10 +3756,10 @@ VisualShaderNodeSmoothStep::PortType VisualShaderNodeSmoothStep::get_input_port_
}
break;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case OP_TYPE_VECTOR_3D_SCALAR:
if (p_port == 2) {
- return PORT_TYPE_VECTOR; // x
+ return PORT_TYPE_VECTOR_3D; // x
}
break;
default:
@@ -3792,9 +3791,9 @@ VisualShaderNodeSmoothStep::PortType VisualShaderNodeSmoothStep::get_output_port
case OP_TYPE_VECTOR_2D_SCALAR:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case OP_TYPE_VECTOR_3D_SCALAR:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -3954,7 +3953,7 @@ VisualShaderNodeVectorRefract::PortType VisualShaderNodeVectorRefract::get_input
return PORT_TYPE_SCALAR;
}
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeVectorRefract::get_input_port_name(int p_port) const {
@@ -3974,7 +3973,7 @@ int VisualShaderNodeVectorRefract::get_output_port_count() const {
}
VisualShaderNodeVectorRefract::PortType VisualShaderNodeVectorRefract::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeVectorRefract::get_output_port_name(int p_port) const {
@@ -4011,12 +4010,12 @@ VisualShaderNodeMix::PortType VisualShaderNodeMix::get_input_port_type(int p_por
}
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case OP_TYPE_VECTOR_3D_SCALAR:
if (p_port == 2) {
break;
}
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -4044,9 +4043,9 @@ VisualShaderNodeMix::PortType VisualShaderNodeMix::get_output_port_type(int p_po
case OP_TYPE_VECTOR_2D_SCALAR:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case OP_TYPE_VECTOR_3D_SCALAR:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -4245,7 +4244,7 @@ int VisualShaderNodeTransformCompose::get_input_port_count() const {
}
VisualShaderNodeTransformCompose::PortType VisualShaderNodeTransformCompose::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeTransformCompose::get_input_port_name(int p_port) const {
@@ -4402,7 +4401,7 @@ int VisualShaderNodeTransformDecompose::get_output_port_count() const {
}
VisualShaderNodeTransformDecompose::PortType VisualShaderNodeTransformDecompose::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeTransformDecompose::get_output_port_name(int p_port) const {
@@ -4933,7 +4932,7 @@ int VisualShaderNodeColorUniform::get_input_port_count() const {
}
VisualShaderNodeColorUniform::PortType VisualShaderNodeColorUniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeColorUniform::get_input_port_name(int p_port) const {
@@ -4945,7 +4944,7 @@ int VisualShaderNodeColorUniform::get_output_port_count() const {
}
VisualShaderNodeColorUniform::PortType VisualShaderNodeColorUniform::get_output_port_type(int p_port) const {
- return p_port == 0 ? PORT_TYPE_VECTOR : PORT_TYPE_SCALAR;
+ return p_port == 0 ? PORT_TYPE_VECTOR_3D : PORT_TYPE_SCALAR;
}
String VisualShaderNodeColorUniform::get_output_port_name(int p_port) const {
@@ -5137,7 +5136,7 @@ int VisualShaderNodeVec3Uniform::get_input_port_count() const {
}
VisualShaderNodeVec3Uniform::PortType VisualShaderNodeVec3Uniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeVec3Uniform::get_input_port_name(int p_port) const {
@@ -5149,7 +5148,7 @@ int VisualShaderNodeVec3Uniform::get_output_port_count() const {
}
VisualShaderNodeVec3Uniform::PortType VisualShaderNodeVec3Uniform::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeVec3Uniform::get_output_port_name(int p_port) const {
@@ -5237,7 +5236,7 @@ int VisualShaderNodeTransformUniform::get_input_port_count() const {
}
VisualShaderNodeTransformUniform::PortType VisualShaderNodeTransformUniform::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeTransformUniform::get_input_port_name(int p_port) const {
@@ -5358,7 +5357,7 @@ int VisualShaderNodeTextureUniform::get_output_port_count() const {
VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniform::get_output_port_type(int p_port) const {
switch (p_port) {
case 0:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case 1:
return PORT_TYPE_SCALAR;
case 2:
@@ -5680,7 +5679,7 @@ int VisualShaderNodeTextureUniformTriplanar::get_input_port_count() const {
VisualShaderNodeTextureUniform::PortType VisualShaderNodeTextureUniformTriplanar::get_input_port_type(int p_port) const {
if (p_port == 0 || p_port == 1) {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
return PORT_TYPE_SCALAR;
}
@@ -5694,7 +5693,7 @@ String VisualShaderNodeTextureUniformTriplanar::get_input_port_name(int p_port)
return "";
}
-String VisualShaderNodeTextureUniformTriplanar::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+String VisualShaderNodeTextureUniformTriplanar::generate_global_per_node(Shader::Mode p_mode, int p_id) const {
String code;
code += "// TRIPLANAR FUNCTION GLOBAL CODE\n";
@@ -5996,7 +5995,7 @@ VisualShaderNodeIf::PortType VisualShaderNodeIf::get_input_port_type(int p_port)
if (p_port == 0 || p_port == 1 || p_port == 2) {
return PORT_TYPE_SCALAR;
}
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeIf::get_input_port_name(int p_port) const {
@@ -6023,7 +6022,7 @@ int VisualShaderNodeIf::get_output_port_count() const {
}
VisualShaderNodeIf::PortType VisualShaderNodeIf::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeIf::get_output_port_name(int p_port) const {
@@ -6078,7 +6077,7 @@ VisualShaderNodeSwitch::PortType VisualShaderNodeSwitch::get_input_port_type(int
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case OP_TYPE_BOOLEAN:
return PORT_TYPE_BOOLEAN;
case OP_TYPE_TRANSFORM:
@@ -6114,7 +6113,7 @@ VisualShaderNodeSwitch::PortType VisualShaderNodeSwitch::get_output_port_type(in
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case OP_TYPE_BOOLEAN:
return PORT_TYPE_BOOLEAN;
case OP_TYPE_TRANSFORM:
@@ -6224,15 +6223,15 @@ int VisualShaderNodeFresnel::get_input_port_count() const {
VisualShaderNodeFresnel::PortType VisualShaderNodeFresnel::get_input_port_type(int p_port) const {
switch (p_port) {
case 0:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case 1:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case 2:
return PORT_TYPE_BOOLEAN;
case 3:
return PORT_TYPE_SCALAR;
default:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
}
@@ -6418,7 +6417,7 @@ VisualShaderNodeCompare::PortType VisualShaderNodeCompare::get_input_port_type(i
case CTYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case CTYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case CTYPE_BOOLEAN:
return PORT_TYPE_BOOLEAN;
case CTYPE_TRANSFORM:
@@ -6670,7 +6669,7 @@ VisualShaderNodeMultiplyAdd::PortType VisualShaderNodeMultiplyAdd::get_input_por
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
@@ -6697,7 +6696,7 @@ VisualShaderNodeMultiplyAdd::PortType VisualShaderNodeMultiplyAdd::get_output_po
case OP_TYPE_VECTOR_2D:
return PORT_TYPE_VECTOR_2D;
case OP_TYPE_VECTOR_3D:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
default:
break;
}
diff --git a/scene/resources/visual_shader_nodes.h b/scene/resources/visual_shader_nodes.h
index 5c7a674d34..eeeb91a3ee 100644
--- a/scene/resources/visual_shader_nodes.h
+++ b/scene/resources/visual_shader_nodes.h
@@ -2136,7 +2136,7 @@ public:
virtual bool is_input_port_default(int p_port, Shader::Mode p_mode) const override;
- virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
+ virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override;
virtual String generate_global_per_func(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override;
diff --git a/scene/resources/visual_shader_particle_nodes.cpp b/scene/resources/visual_shader_particle_nodes.cpp
index fbac92a06d..398c33c452 100644
--- a/scene/resources/visual_shader_particle_nodes.cpp
+++ b/scene/resources/visual_shader_particle_nodes.cpp
@@ -39,7 +39,10 @@ int VisualShaderNodeParticleEmitter::get_output_port_count() const {
}
VisualShaderNodeParticleEmitter::PortType VisualShaderNodeParticleEmitter::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ if (mode_2d) {
+ return PORT_TYPE_VECTOR_2D;
+ }
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeParticleEmitter::get_output_port_name(int p_port) const {
@@ -54,6 +57,9 @@ bool VisualShaderNodeParticleEmitter::has_output_port_preview(int p_port) const
}
void VisualShaderNodeParticleEmitter::set_mode_2d(bool p_enabled) {
+ if (mode_2d == p_enabled) {
+ return;
+ }
mode_2d = p_enabled;
emit_changed();
}
@@ -111,7 +117,7 @@ String VisualShaderNodeParticleSphereEmitter::get_input_port_name(int p_port) co
return String();
}
-String VisualShaderNodeParticleSphereEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+String VisualShaderNodeParticleSphereEmitter::generate_global_per_node(Shader::Mode p_mode, int p_id) const {
String code;
code += "vec2 __get_random_point_in_circle(inout uint seed, float radius, float inner_radius) {\n";
@@ -129,7 +135,7 @@ String VisualShaderNodeParticleSphereEmitter::generate_code(Shader::Mode p_mode,
String code;
if (mode_2d) {
- code += " " + p_output_vars[0] + " = vec3(__get_random_point_in_circle(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + "), 0.0);\n";
+ code += " " + p_output_vars[0] + " = __get_random_point_in_circle(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n";
} else {
code += " " + p_output_vars[0] + " = __get_random_point_in_sphere(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n";
}
@@ -154,11 +160,27 @@ int VisualShaderNodeParticleBoxEmitter::get_input_port_count() const {
VisualShaderNodeParticleBoxEmitter::PortType VisualShaderNodeParticleBoxEmitter::get_input_port_type(int p_port) const {
if (p_port == 0) {
- return PORT_TYPE_VECTOR;
+ if (mode_2d) {
+ return PORT_TYPE_VECTOR_2D;
+ }
+ return PORT_TYPE_VECTOR_3D;
}
return PORT_TYPE_SCALAR;
}
+void VisualShaderNodeParticleBoxEmitter::set_mode_2d(bool p_enabled) {
+ if (mode_2d == p_enabled) {
+ return;
+ }
+ if (p_enabled) {
+ set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
+ } else {
+ set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
+ }
+ mode_2d = p_enabled;
+ emit_changed();
+}
+
String VisualShaderNodeParticleBoxEmitter::get_input_port_name(int p_port) const {
if (p_port == 0) {
return "extents";
@@ -166,7 +188,7 @@ String VisualShaderNodeParticleBoxEmitter::get_input_port_name(int p_port) const
return String();
}
-String VisualShaderNodeParticleBoxEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+String VisualShaderNodeParticleBoxEmitter::generate_global_per_node(Shader::Mode p_mode, int p_id) const {
String code;
code += "vec2 __get_random_point_in_box2d(inout uint seed, vec2 extents) {\n";
@@ -185,7 +207,7 @@ String VisualShaderNodeParticleBoxEmitter::generate_global_per_node(Shader::Mode
String VisualShaderNodeParticleBoxEmitter::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
String code;
if (mode_2d) {
- code += " " + p_output_vars[0] + " = vec3(__get_random_point_in_box2d(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ".xy), 0.0);\n";
+ code += " " + p_output_vars[0] + " = __get_random_point_in_box2d(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ");\n";
} else {
code += " " + p_output_vars[0] + " = __get_random_point_in_box3d(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ");\n";
}
@@ -221,7 +243,7 @@ String VisualShaderNodeParticleRingEmitter::get_input_port_name(int p_port) cons
return String();
}
-String VisualShaderNodeParticleRingEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const {
+String VisualShaderNodeParticleRingEmitter::generate_global_per_node(Shader::Mode p_mode, int p_id) const {
String code;
code += "vec2 __get_random_point_on_ring2d(inout uint seed, float radius, float inner_radius) {\n";
@@ -243,7 +265,7 @@ String VisualShaderNodeParticleRingEmitter::generate_code(Shader::Mode p_mode, V
String code;
if (mode_2d) {
- code = " " + p_output_vars[0] + " = vec3(__get_random_point_on_ring2d(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + "), 0.0);\n";
+ code = " " + p_output_vars[0] + " = __get_random_point_on_ring2d(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n";
} else {
code = " " + p_output_vars[0] + " = __get_random_point_on_ring3d(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ", " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ", " + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ");\n";
}
@@ -269,18 +291,24 @@ int VisualShaderNodeParticleMeshEmitter::get_output_port_count() const {
VisualShaderNodeParticleBoxEmitter::PortType VisualShaderNodeParticleMeshEmitter::get_output_port_type(int p_port) const {
switch (p_port) {
- case 0:
- return PORT_TYPE_VECTOR; // position
- case 1:
- return PORT_TYPE_VECTOR; // normal
- case 2:
- return PORT_TYPE_VECTOR; // color
- case 3:
- return PORT_TYPE_SCALAR; // alpha
- case 4:
- return PORT_TYPE_VECTOR; // uv
- case 5:
- return PORT_TYPE_VECTOR; // uv2
+ case 0: // position
+ if (mode_2d) {
+ return PORT_TYPE_VECTOR_2D;
+ }
+ return PORT_TYPE_VECTOR_3D;
+ case 1: // normal
+ if (mode_2d) {
+ return PORT_TYPE_VECTOR_2D;
+ }
+ return PORT_TYPE_VECTOR_3D;
+ case 2: // color
+ return PORT_TYPE_VECTOR_3D;
+ case 3: // alpha
+ return PORT_TYPE_SCALAR;
+ case 4: // uv
+ return PORT_TYPE_VECTOR_2D;
+ case 5: // uv2
+ return PORT_TYPE_VECTOR_2D;
}
return PORT_TYPE_SCALAR;
}
@@ -341,18 +369,22 @@ String VisualShaderNodeParticleMeshEmitter::generate_global(Shader::Mode p_mode,
return code;
}
-String VisualShaderNodeParticleMeshEmitter::_generate_code(VisualShader::Type p_type, int p_id, const String *p_output_vars, int p_index, const String &p_texture_name, bool p_ignore_mode2d) const {
+String VisualShaderNodeParticleMeshEmitter::_generate_code(VisualShader::Type p_type, int p_id, const String *p_output_vars, int p_index, const String &p_texture_name, PortType p_port_type) const {
String code;
if (is_output_port_connected(p_index)) {
- if (mode_2d && !p_ignore_mode2d) {
- code += " " + p_output_vars[p_index] + " = vec3(";
- code += "texelFetch(";
- code += make_unique_id(p_type, p_id, p_texture_name) + ", ";
- code += "ivec2(__scalar_ibuff, 0), 0).xy, 0.0);\n";
- } else {
- code += " " + p_output_vars[p_index] + " = texelFetch(";
- code += make_unique_id(p_type, p_id, p_texture_name) + ", ";
- code += "ivec2(__scalar_ibuff, 0), 0).xyz;\n";
+ switch (p_port_type) {
+ case PORT_TYPE_VECTOR_2D: {
+ code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xy;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name));
+ } break;
+ case PORT_TYPE_VECTOR_3D: {
+ if (mode_2d) {
+ code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xy;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name));
+ } else {
+ code += vformat(" %s = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0).xyz;\n", p_output_vars[p_index], make_unique_id(p_type, p_id, p_texture_name));
+ }
+ } break;
+ default:
+ break;
}
}
return code;
@@ -362,27 +394,22 @@ String VisualShaderNodeParticleMeshEmitter::generate_code(Shader::Mode p_mode, V
String code;
code += " __scalar_ibuff = int(__rand_from_seed(__seed) * 65535.0) % " + itos(position_texture->get_width()) + ";\n";
- code += _generate_code(p_type, p_id, p_output_vars, 0, "mesh_vx");
- code += _generate_code(p_type, p_id, p_output_vars, 1, "mesh_nm");
+ code += _generate_code(p_type, p_id, p_output_vars, 0, "mesh_vx", VisualShaderNode::PORT_TYPE_VECTOR_3D);
+ code += _generate_code(p_type, p_id, p_output_vars, 1, "mesh_nm", VisualShaderNode::PORT_TYPE_VECTOR_3D);
if (is_output_port_connected(2) || is_output_port_connected(3)) {
- code += " __vec4_buff = texelFetch(";
- code += make_unique_id(p_type, p_id, "mesh_col") + ", ";
- code += "ivec2(__scalar_ibuff, 0), 0);\n";
+ code += vformat(" __vec4_buff = texelFetch(%s, ivec2(__scalar_ibuff, 0), 0);\n", make_unique_id(p_type, p_id, "mesh_col"));
+
if (is_output_port_connected(2)) {
code += " " + p_output_vars[2] + " = __vec4_buff.rgb;\n";
- } else {
- code += " " + p_output_vars[2] + " = vec3(0.0);\n";
}
if (is_output_port_connected(3)) {
code += " " + p_output_vars[3] + " = __vec4_buff.a;\n";
- } else {
- code += " " + p_output_vars[3] + " = 0.0;\n";
}
}
- code += _generate_code(p_type, p_id, p_output_vars, 4, "mesh_uv", true);
- code += _generate_code(p_type, p_id, p_output_vars, 5, "mesh_uv2", true);
+ code += _generate_code(p_type, p_id, p_output_vars, 4, "mesh_uv", VisualShaderNode::PORT_TYPE_VECTOR_2D);
+ code += _generate_code(p_type, p_id, p_output_vars, 5, "mesh_uv2", VisualShaderNode::PORT_TYPE_VECTOR_2D);
return code;
}
@@ -731,7 +758,7 @@ int VisualShaderNodeParticleMultiplyByAxisAngle::get_input_port_count() const {
VisualShaderNodeParticleMultiplyByAxisAngle::PortType VisualShaderNodeParticleMultiplyByAxisAngle::get_input_port_type(int p_port) const {
if (p_port == 0 || p_port == 1) { // position, rotation_axis
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
return PORT_TYPE_SCALAR; // angle (degrees/radians)
}
@@ -762,7 +789,7 @@ int VisualShaderNodeParticleMultiplyByAxisAngle::get_output_port_count() const {
}
VisualShaderNodeParticleMultiplyByAxisAngle::PortType VisualShaderNodeParticleMultiplyByAxisAngle::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeParticleMultiplyByAxisAngle::get_output_port_name(int p_port) const {
@@ -815,7 +842,7 @@ int VisualShaderNodeParticleConeVelocity::get_input_port_count() const {
VisualShaderNodeParticleConeVelocity::PortType VisualShaderNodeParticleConeVelocity::get_input_port_type(int p_port) const {
if (p_port == 0) {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
} else if (p_port == 1) {
return PORT_TYPE_SCALAR;
}
@@ -836,7 +863,7 @@ int VisualShaderNodeParticleConeVelocity::get_output_port_count() const {
}
VisualShaderNodeParticleConeVelocity::PortType VisualShaderNodeParticleConeVelocity::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeParticleConeVelocity::get_output_port_name(int p_port) const {
@@ -876,10 +903,11 @@ void VisualShaderNodeParticleRandomness::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_op_type", "type"), &VisualShaderNodeParticleRandomness::set_op_type);
ClassDB::bind_method(D_METHOD("get_op_type"), &VisualShaderNodeParticleRandomness::get_op_type);
- ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector"), "set_op_type", "get_op_type");
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "op_type", PROPERTY_HINT_ENUM, "Scalar,Vector2,Vector3"), "set_op_type", "get_op_type");
BIND_ENUM_CONSTANT(OP_TYPE_SCALAR);
- BIND_ENUM_CONSTANT(OP_TYPE_VECTOR);
+ BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_2D);
+ BIND_ENUM_CONSTANT(OP_TYPE_VECTOR_3D);
BIND_ENUM_CONSTANT(OP_TYPE_MAX);
}
@@ -898,8 +926,13 @@ int VisualShaderNodeParticleRandomness::get_output_port_count() const {
}
VisualShaderNodeParticleRandomness::PortType VisualShaderNodeParticleRandomness::get_output_port_type(int p_port) const {
- if (op_type == OP_TYPE_VECTOR) {
- return PORT_TYPE_VECTOR;
+ switch (op_type) {
+ case OP_TYPE_VECTOR_2D:
+ return PORT_TYPE_VECTOR_2D;
+ case OP_TYPE_VECTOR_3D:
+ return PORT_TYPE_VECTOR_3D;
+ default:
+ break;
}
return PORT_TYPE_SCALAR;
}
@@ -913,8 +946,13 @@ int VisualShaderNodeParticleRandomness::get_input_port_count() const {
}
VisualShaderNodeParticleRandomness::PortType VisualShaderNodeParticleRandomness::get_input_port_type(int p_port) const {
- if (op_type == OP_TYPE_VECTOR) {
- return PORT_TYPE_VECTOR;
+ switch (op_type) {
+ case OP_TYPE_VECTOR_2D:
+ return PORT_TYPE_VECTOR_2D;
+ case OP_TYPE_VECTOR_3D:
+ return PORT_TYPE_VECTOR_3D;
+ default:
+ break;
}
return PORT_TYPE_SCALAR;
}
@@ -930,10 +968,18 @@ String VisualShaderNodeParticleRandomness::get_input_port_name(int p_port) const
String VisualShaderNodeParticleRandomness::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
String code;
- if (op_type == OP_TYPE_SCALAR) {
- code += vformat(" %s = __randf_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
- } else if (op_type == OP_TYPE_VECTOR) {
- code += vformat(" %s = __randv_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
+ switch (op_type) {
+ case OP_TYPE_SCALAR: {
+ code += vformat(" %s = __randf_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
+ } break;
+ case OP_TYPE_VECTOR_2D: {
+ code += vformat(" %s = __randv2_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
+ } break;
+ case OP_TYPE_VECTOR_3D: {
+ code += vformat(" %s = __randv3_range(__seed, %s, %s);\n", p_output_vars[0], p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0], p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]);
+ } break;
+ default:
+ break;
}
return code;
}
@@ -943,12 +989,21 @@ void VisualShaderNodeParticleRandomness::set_op_type(OpType p_op_type) {
if (op_type == p_op_type) {
return;
}
- if (p_op_type == OP_TYPE_SCALAR) {
- set_input_port_default_value(0, 0.0);
- set_input_port_default_value(1, 1.0);
- } else {
- set_input_port_default_value(0, Vector3(-1.0, -1.0, -1.0));
- set_input_port_default_value(1, Vector3(1.0, 1.0, 1.0));
+ switch (p_op_type) {
+ case OP_TYPE_SCALAR: {
+ set_input_port_default_value(0, 0.0, get_input_port_default_value(0));
+ set_input_port_default_value(1, 0.0, get_input_port_default_value(1));
+ } break;
+ case OP_TYPE_VECTOR_2D: {
+ set_input_port_default_value(0, Vector2(), get_input_port_default_value(0));
+ set_input_port_default_value(1, Vector2(), get_input_port_default_value(1));
+ } break;
+ case OP_TYPE_VECTOR_3D: {
+ set_input_port_default_value(0, Vector3(), get_input_port_default_value(0));
+ set_input_port_default_value(1, Vector3(), get_input_port_default_value(1));
+ } break;
+ default:
+ break;
}
op_type = p_op_type;
emit_changed();
@@ -963,7 +1018,7 @@ bool VisualShaderNodeParticleRandomness::has_output_port_preview(int p_port) con
}
VisualShaderNodeParticleRandomness::VisualShaderNodeParticleRandomness() {
- set_input_port_default_value(0, 0.0);
+ set_input_port_default_value(0, -1.0);
set_input_port_default_value(1, 1.0);
}
@@ -996,7 +1051,7 @@ int VisualShaderNodeParticleAccelerator::get_output_port_count() const {
}
VisualShaderNodeParticleAccelerator::PortType VisualShaderNodeParticleAccelerator::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
String VisualShaderNodeParticleAccelerator::get_output_port_name(int p_port) const {
@@ -1009,11 +1064,11 @@ int VisualShaderNodeParticleAccelerator::get_input_port_count() const {
VisualShaderNodeParticleAccelerator::PortType VisualShaderNodeParticleAccelerator::get_input_port_type(int p_port) const {
if (p_port == 0) {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
} else if (p_port == 1) {
return PORT_TYPE_SCALAR;
} else if (p_port == 2) {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
}
return PORT_TYPE_SCALAR;
}
@@ -1106,19 +1161,19 @@ VisualShaderNodeParticleOutput::PortType VisualShaderNodeParticleOutput::get_inp
switch (p_port) {
case 0:
if (shader_type == VisualShader::TYPE_START_CUSTOM || shader_type == VisualShader::TYPE_PROCESS_CUSTOM) {
- return PORT_TYPE_VECTOR; // custom.rgb
+ return PORT_TYPE_VECTOR_3D; // custom.rgb
}
return PORT_TYPE_BOOLEAN; // active
case 1:
if (shader_type == VisualShader::TYPE_START_CUSTOM || shader_type == VisualShader::TYPE_PROCESS_CUSTOM) {
break; // custom.a (scalar)
}
- return PORT_TYPE_VECTOR; // velocity
+ return PORT_TYPE_VECTOR_3D; // velocity
case 2:
- return PORT_TYPE_VECTOR; // color & velocity
+ return PORT_TYPE_VECTOR_3D; // color & velocity
case 3:
if (shader_type == VisualShader::TYPE_START_CUSTOM || shader_type == VisualShader::TYPE_PROCESS_CUSTOM) {
- return PORT_TYPE_VECTOR; // color
+ return PORT_TYPE_VECTOR_3D; // color
}
break; // alpha (scalar)
case 4:
@@ -1131,18 +1186,18 @@ VisualShaderNodeParticleOutput::PortType VisualShaderNodeParticleOutput::get_inp
if (shader_type == VisualShader::TYPE_COLLIDE) {
return PORT_TYPE_TRANSFORM; // transform
}
- return PORT_TYPE_VECTOR; // position
+ return PORT_TYPE_VECTOR_3D; // position
case 5:
if (shader_type == VisualShader::TYPE_START_CUSTOM || shader_type == VisualShader::TYPE_PROCESS_CUSTOM) {
return PORT_TYPE_TRANSFORM; // transform
}
if (shader_type == VisualShader::TYPE_PROCESS) {
- return PORT_TYPE_VECTOR; // rotation_axis
+ return PORT_TYPE_VECTOR_3D; // rotation_axis
}
break; // scale (scalar)
case 6:
if (shader_type == VisualShader::TYPE_START) {
- return PORT_TYPE_VECTOR; // rotation_axis
+ return PORT_TYPE_VECTOR_3D; // rotation_axis
}
break;
case 7:
@@ -1263,7 +1318,7 @@ String VisualShaderNodeParticleOutput::generate_code(Shader::Mode p_mode, Visual
code += tab + "TRANSFORM = " + p_input_vars[5] + ";\n";
}
} else {
- if (!p_input_vars[0].is_empty()) { // active (begin)
+ if (!p_input_vars[0].is_empty()) { // Active (begin).
code += tab + "ACTIVE = " + p_input_vars[0] + ";\n";
code += tab + "if(ACTIVE) {\n";
tab += " ";
@@ -1326,7 +1381,7 @@ String VisualShaderNodeParticleOutput::generate_code(Shader::Mode p_mode, Visual
code += tab + "TRANSFORM " + op + " mat4(vec4(" + p_input_vars[scale] + ", 0, 0, 0), vec4(0, " + p_input_vars[scale] + ", 0, 0), vec4(0, 0, " + p_input_vars[scale] + ", 0), vec4(0, 0, 0, 1));\n";
}
}
- if (!p_input_vars[0].is_empty()) { // active (end)
+ if (!p_input_vars[0].is_empty()) { // Active (end).
code += " }\n";
}
}
@@ -1372,13 +1427,13 @@ VisualShaderNodeParticleEmit::PortType VisualShaderNodeParticleEmit::get_input_p
case 1:
return PORT_TYPE_TRANSFORM;
case 2:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case 3:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case 4:
return PORT_TYPE_SCALAR;
case 5:
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_3D;
case 6:
return PORT_TYPE_SCALAR;
}
diff --git a/scene/resources/visual_shader_particle_nodes.h b/scene/resources/visual_shader_particle_nodes.h
index ce0d896c01..0b91cba5e0 100644
--- a/scene/resources/visual_shader_particle_nodes.h
+++ b/scene/resources/visual_shader_particle_nodes.h
@@ -48,7 +48,7 @@ public:
virtual String get_output_port_name(int p_port) const override;
virtual bool has_output_port_preview(int p_port) const override;
- void set_mode_2d(bool p_enabled);
+ virtual void set_mode_2d(bool p_enabled);
bool is_mode_2d() const;
Vector<StringName> get_editable_properties() const override;
@@ -68,7 +68,7 @@ public:
virtual PortType get_input_port_type(int p_port) const override;
virtual String get_input_port_name(int p_port) const override;
- virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
+ virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override;
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override;
VisualShaderNodeParticleSphereEmitter();
@@ -83,8 +83,9 @@ public:
virtual int get_input_port_count() const override;
virtual PortType get_input_port_type(int p_port) const override;
virtual String get_input_port_name(int p_port) const override;
+ virtual void set_mode_2d(bool p_enabled) override;
- virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
+ virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override;
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override;
VisualShaderNodeParticleBoxEmitter();
@@ -100,7 +101,7 @@ public:
virtual PortType get_input_port_type(int p_port) const override;
virtual String get_input_port_name(int p_port) const override;
- virtual String generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const override;
+ virtual String generate_global_per_node(Shader::Mode p_mode, int p_id) const override;
virtual String generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview = false) const override;
VisualShaderNodeParticleRingEmitter();
@@ -118,7 +119,7 @@ class VisualShaderNodeParticleMeshEmitter : public VisualShaderNodeParticleEmitt
Ref<ImageTexture> uv_texture;
Ref<ImageTexture> uv2_texture;
- String _generate_code(VisualShader::Type p_type, int p_id, const String *p_output_vars, int p_index, const String &p_texture_name, bool p_ignore_mode2d = false) const;
+ String _generate_code(VisualShader::Type p_type, int p_id, const String *p_output_vars, int p_index, const String &p_texture_name, PortType p_port_type) const;
void _update_texture(const Vector<Vector2> &p_array, Ref<ImageTexture> &r_texture);
void _update_texture(const Vector<Vector3> &p_array, Ref<ImageTexture> &r_texture);
@@ -213,7 +214,8 @@ class VisualShaderNodeParticleRandomness : public VisualShaderNode {
public:
enum OpType {
OP_TYPE_SCALAR,
- OP_TYPE_VECTOR,
+ OP_TYPE_VECTOR_2D,
+ OP_TYPE_VECTOR_3D,
OP_TYPE_MAX,
};
diff --git a/scene/resources/visual_shader_sdf_nodes.cpp b/scene/resources/visual_shader_sdf_nodes.cpp
index 6654e2319b..cbd3ebd83b 100644
--- a/scene/resources/visual_shader_sdf_nodes.cpp
+++ b/scene/resources/visual_shader_sdf_nodes.cpp
@@ -41,7 +41,7 @@ int VisualShaderNodeSDFToScreenUV::get_input_port_count() const {
}
VisualShaderNodeSDFToScreenUV::PortType VisualShaderNodeSDFToScreenUV::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
String VisualShaderNodeSDFToScreenUV::get_input_port_name(int p_port) const {
@@ -53,7 +53,7 @@ int VisualShaderNodeSDFToScreenUV::get_output_port_count() const {
}
VisualShaderNodeSDFToScreenUV::PortType VisualShaderNodeSDFToScreenUV::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
String VisualShaderNodeSDFToScreenUV::get_output_port_name(int p_port) const {
@@ -61,7 +61,7 @@ String VisualShaderNodeSDFToScreenUV::get_output_port_name(int p_port) const {
}
String VisualShaderNodeSDFToScreenUV::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = sdf_to_screen_uv(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0]) + ");\n";
}
VisualShaderNodeSDFToScreenUV::VisualShaderNodeSDFToScreenUV() {
@@ -78,7 +78,7 @@ int VisualShaderNodeScreenUVToSDF::get_input_port_count() const {
}
VisualShaderNodeScreenUVToSDF::PortType VisualShaderNodeScreenUVToSDF::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
String VisualShaderNodeScreenUVToSDF::get_input_port_name(int p_port) const {
@@ -90,7 +90,7 @@ int VisualShaderNodeScreenUVToSDF::get_output_port_count() const {
}
VisualShaderNodeScreenUVToSDF::PortType VisualShaderNodeScreenUVToSDF::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
String VisualShaderNodeScreenUVToSDF::get_output_port_name(int p_port) const {
@@ -105,7 +105,7 @@ bool VisualShaderNodeScreenUVToSDF::is_input_port_default(int p_port, Shader::Mo
}
String VisualShaderNodeScreenUVToSDF::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0].is_empty() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = screen_uv_to_sdf(" + (p_input_vars[0].is_empty() ? "SCREEN_UV" : p_input_vars[0]) + ");\n";
}
VisualShaderNodeScreenUVToSDF::VisualShaderNodeScreenUVToSDF() {
@@ -122,7 +122,7 @@ int VisualShaderNodeTextureSDF::get_input_port_count() const {
}
VisualShaderNodeTextureSDF::PortType VisualShaderNodeTextureSDF::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
String VisualShaderNodeTextureSDF::get_input_port_name(int p_port) const {
@@ -142,7 +142,7 @@ String VisualShaderNodeTextureSDF::get_output_port_name(int p_port) const {
}
String VisualShaderNodeTextureSDF::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n";
+ return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0]) + ");\n";
}
VisualShaderNodeTextureSDF::VisualShaderNodeTextureSDF() {
@@ -159,7 +159,7 @@ int VisualShaderNodeTextureSDFNormal::get_input_port_count() const {
}
VisualShaderNodeTextureSDFNormal::PortType VisualShaderNodeTextureSDFNormal::get_input_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
String VisualShaderNodeTextureSDFNormal::get_input_port_name(int p_port) const {
@@ -171,7 +171,7 @@ int VisualShaderNodeTextureSDFNormal::get_output_port_count() const {
}
VisualShaderNodeTextureSDFNormal::PortType VisualShaderNodeTextureSDFNormal::get_output_port_type(int p_port) const {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
String VisualShaderNodeTextureSDFNormal::get_output_port_name(int p_port) const {
@@ -179,7 +179,7 @@ String VisualShaderNodeTextureSDFNormal::get_output_port_name(int p_port) const
}
String VisualShaderNodeTextureSDFNormal::generate_code(Shader::Mode p_mode, VisualShader::Type p_type, int p_id, const String *p_input_vars, const String *p_output_vars, bool p_for_preview) const {
- return " " + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n";
+ return " " + p_output_vars[0] + " = texture_sdf_normal(" + (p_input_vars[0].is_empty() ? "vec2(0.0)" : p_input_vars[0]) + ");\n";
}
VisualShaderNodeTextureSDFNormal::VisualShaderNodeTextureSDFNormal() {
@@ -197,7 +197,7 @@ int VisualShaderNodeSDFRaymarch::get_input_port_count() const {
VisualShaderNodeSDFRaymarch::PortType VisualShaderNodeSDFRaymarch::get_input_port_type(int p_port) const {
if (p_port == 0 || p_port == 1) {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
return PORT_TYPE_SCALAR;
}
@@ -221,7 +221,7 @@ VisualShaderNodeSDFRaymarch::PortType VisualShaderNodeSDFRaymarch::get_output_po
} else if (p_port == 1) {
return PORT_TYPE_BOOLEAN;
} else if (p_port == 2) {
- return PORT_TYPE_VECTOR;
+ return PORT_TYPE_VECTOR_2D;
}
return PORT_TYPE_SCALAR;
}
@@ -245,13 +245,13 @@ String VisualShaderNodeSDFRaymarch::generate_code(Shader::Mode p_mode, VisualSha
if (p_input_vars[0].is_empty()) {
code += " vec2 __from_pos = vec2(0.0f);\n";
} else {
- code += " vec2 __from_pos = " + p_input_vars[0] + ".xy;\n";
+ code += " vec2 __from_pos = " + p_input_vars[0] + ";\n";
}
if (p_input_vars[1].is_empty()) {
code += " vec2 __to_pos = vec2(0.0f);\n";
} else {
- code += " vec2 __to_pos = " + p_input_vars[1] + ".xy;\n";
+ code += " vec2 __to_pos = " + p_input_vars[1] + ";\n";
}
code += "\n vec2 __at = __from_pos;\n";
@@ -271,7 +271,7 @@ String VisualShaderNodeSDFRaymarch::generate_code(Shader::Mode p_mode, VisualSha
code += " float __dist = min(__max_dist, __accum);\n";
code += " " + p_output_vars[0] + " = __dist;\n";
code += " " + p_output_vars[1] + " = __accum < __max_dist;\n";
- code += " " + p_output_vars[2] + " = vec3(__from_pos + __dir * __dist, 0.0f);\n";
+ code += " " + p_output_vars[2] + " = __from_pos + __dir * __dist;\n";
code += " }\n";
diff --git a/scene/resources/world_2d.h b/scene/resources/world_2d.h
index 91f9a026d3..4a277c3d84 100644
--- a/scene/resources/world_2d.h
+++ b/scene/resources/world_2d.h
@@ -31,8 +31,8 @@
#ifndef WORLD_2D_H
#define WORLD_2D_H
-#include "core/config/project_settings.h"
#include "core/io/resource.h"
+#include "scene/resources/world_2d.h"
#include "servers/physics_server_2d.h"
class VisibleOnScreenNotifier2D;
diff --git a/scene/resources/world_3d.cpp b/scene/resources/world_3d.cpp
index c012ab6177..0088236112 100644
--- a/scene/resources/world_3d.cpp
+++ b/scene/resources/world_3d.cpp
@@ -30,7 +30,7 @@
#include "world_3d.h"
-#include "core/math/camera_matrix.h"
+#include "core/config/project_settings.h"
#include "core/math/octree.h"
#include "scene/3d/camera_3d.h"
#include "scene/3d/visible_on_screen_notifier_3d.h"