diff options
Diffstat (limited to 'scene')
77 files changed, 2104 insertions, 2107 deletions
diff --git a/scene/2d/audio_stream_player_2d.cpp b/scene/2d/audio_stream_player_2d.cpp index 860ccfec64..4b96689613 100644 --- a/scene/2d/audio_stream_player_2d.cpp +++ b/scene/2d/audio_stream_player_2d.cpp @@ -255,7 +255,7 @@ void AudioStreamPlayer2D::_notification(int p_what) { //stop playing if no longer active if (!active.is_set()) { set_physics_process_internal(false); - emit_signal("finished"); + emit_signal(SNAME("finished")); } } } diff --git a/scene/2d/navigation_agent_2d.cpp b/scene/2d/navigation_agent_2d.cpp index f9cbdbf377..e9a95b680c 100644 --- a/scene/2d/navigation_agent_2d.cpp +++ b/scene/2d/navigation_agent_2d.cpp @@ -235,7 +235,7 @@ void NavigationAgent2D::_avoidance_done(Vector3 p_new_velocity) { } velocity_submitted = false; - emit_signal("velocity_computed", velocity); + emit_signal(SNAME("velocity_computed"), velocity); } TypedArray<String> NavigationAgent2D::get_configuration_warnings() const { @@ -287,7 +287,7 @@ void NavigationAgent2D::update_navigation() { navigation_path = NavigationServer2D::get_singleton()->map_get_path(agent_parent->get_world_2d()->get_navigation_map(), o, target_location, true, navigable_layers); navigation_finished = false; nav_path_index = 0; - emit_signal("path_changed"); + emit_signal(SNAME("path_changed")); } if (navigation_path.size() == 0) { @@ -303,7 +303,7 @@ void NavigationAgent2D::update_navigation() { _check_distance_to_target(); nav_path_index -= 1; navigation_finished = true; - emit_signal("navigation_finished"); + emit_signal(SNAME("navigation_finished")); break; } } @@ -313,7 +313,7 @@ void NavigationAgent2D::update_navigation() { void NavigationAgent2D::_check_distance_to_target() { if (!target_reached) { if (distance_to_target() < target_desired_distance) { - emit_signal("target_reached"); + emit_signal(SNAME("target_reached")); target_reached = true; } } diff --git a/scene/2d/skeleton_2d.cpp b/scene/2d/skeleton_2d.cpp index 8f1f5fadbc..15cbdf535e 100644 --- a/scene/2d/skeleton_2d.cpp +++ b/scene/2d/skeleton_2d.cpp @@ -568,7 +568,7 @@ void Skeleton2D::_make_bone_setup_dirty() { } bone_setup_dirty = true; if (is_inside_tree()) { - call_deferred("_update_bone_setup"); + call_deferred(SNAME("_update_bone_setup")); } } @@ -597,7 +597,7 @@ void Skeleton2D::_update_bone_setup() { transform_dirty = true; _update_transform(); - emit_signal("bone_setup_changed"); + emit_signal(SNAME("bone_setup_changed")); } void Skeleton2D::_make_transform_dirty() { @@ -606,7 +606,7 @@ void Skeleton2D::_make_transform_dirty() { } transform_dirty = true; if (is_inside_tree()) { - call_deferred("_update_transform"); + call_deferred(SNAME("_update_transform")); } } diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp index e39c8841cd..6d1e27bf1b 100644 --- a/scene/2d/tile_map.cpp +++ b/scene/2d/tile_map.cpp @@ -299,7 +299,7 @@ void TileMap::set_tileset(const Ref<TileSet> &p_tileset) { _recreate_quadrants(); } - emit_signal("changed"); + emit_signal(SNAME("changed")); } int TileMap::get_quadrant_size() const { @@ -311,13 +311,13 @@ void TileMap::set_quadrant_size(int p_size) { quadrant_size = p_size; _recreate_quadrants(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileMap::set_collision_visibility_mode(TileMap::VisibilityMode p_show_collision) { show_collision = p_show_collision; _recreate_quadrants(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } TileMap::VisibilityMode TileMap::get_collision_visibility_mode() { @@ -327,7 +327,7 @@ TileMap::VisibilityMode TileMap::get_collision_visibility_mode() { void TileMap::set_navigation_visibility_mode(TileMap::VisibilityMode p_show_navigation) { show_navigation = p_show_navigation; _recreate_quadrants(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() { @@ -337,7 +337,7 @@ TileMap::VisibilityMode TileMap::get_navigation_visibility_mode() { void TileMap::set_y_sort_enabled(bool p_enable) { Node2D::set_y_sort_enabled(p_enable); _recreate_quadrants(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileMap::update_dirty_quadrants() { @@ -480,7 +480,7 @@ void TileMap::_make_all_quadrants_dirty(bool p_update) { return; } if (p_update) { - call_deferred("update_dirty_quadrants"); + call_deferred(SNAME("update_dirty_quadrants")); } } @@ -500,7 +500,7 @@ void TileMap::_make_quadrant_dirty(Map<Vector2i, TileMapQuadrant>::Element *Q, b } if (p_update) { - call_deferred("update_dirty_quadrants"); + call_deferred(SNAME("update_dirty_quadrants")); } } @@ -1764,7 +1764,7 @@ void TileMap::_bind_methods() { } void TileMap::_tile_set_changed() { - emit_signal("changed"); + emit_signal(SNAME("changed")); _make_all_quadrants_dirty(true); } diff --git a/scene/2d/touch_screen_button.cpp b/scene/2d/touch_screen_button.cpp index 0a6393551c..7c345ad377 100644 --- a/scene/2d/touch_screen_button.cpp +++ b/scene/2d/touch_screen_button.cpp @@ -294,7 +294,7 @@ void TouchScreenButton::_press(int p_finger_pressed) { get_viewport()->input(iea, true); } - emit_signal("pressed"); + emit_signal(SNAME("pressed")); update(); } @@ -313,7 +313,7 @@ void TouchScreenButton::_release(bool p_exiting_tree) { } if (!p_exiting_tree) { - emit_signal("released"); + emit_signal(SNAME("released")); update(); } } diff --git a/scene/3d/audio_stream_player_3d.cpp b/scene/3d/audio_stream_player_3d.cpp index ba559b4ecb..dd8cb1f20d 100644 --- a/scene/3d/audio_stream_player_3d.cpp +++ b/scene/3d/audio_stream_player_3d.cpp @@ -607,7 +607,7 @@ void AudioStreamPlayer3D::_notification(int p_what) { //stop playing if no longer active if (!active.is_set()) { set_physics_process_internal(false); - emit_signal("finished"); + emit_signal(SNAME("finished")); } } } diff --git a/scene/3d/navigation_agent_3d.cpp b/scene/3d/navigation_agent_3d.cpp index 64cfe4dca7..f890ceeb95 100644 --- a/scene/3d/navigation_agent_3d.cpp +++ b/scene/3d/navigation_agent_3d.cpp @@ -242,7 +242,7 @@ void NavigationAgent3D::_avoidance_done(Vector3 p_new_velocity) { } velocity_submitted = false; - emit_signal("velocity_computed", p_new_velocity); + emit_signal(SNAME("velocity_computed"), p_new_velocity); } TypedArray<String> NavigationAgent3D::get_configuration_warnings() const { @@ -296,7 +296,7 @@ void NavigationAgent3D::update_navigation() { navigation_path = NavigationServer3D::get_singleton()->map_get_path(agent_parent->get_world_3d()->get_navigation_map(), o, target_location, true); navigation_finished = false; nav_path_index = 0; - emit_signal("path_changed"); + emit_signal(SNAME("path_changed")); } if (navigation_path.size() == 0) { @@ -312,7 +312,7 @@ void NavigationAgent3D::update_navigation() { _check_distance_to_target(); nav_path_index -= 1; navigation_finished = true; - emit_signal("navigation_finished"); + emit_signal(SNAME("navigation_finished")); break; } } @@ -322,7 +322,7 @@ void NavigationAgent3D::update_navigation() { void NavigationAgent3D::_check_distance_to_target() { if (!target_reached) { if (distance_to_target() < target_desired_distance) { - emit_signal("target_reached"); + emit_signal(SNAME("target_reached")); target_reached = true; } } diff --git a/scene/3d/navigation_region_3d.cpp b/scene/3d/navigation_region_3d.cpp index 0afad62404..19abb3f33a 100644 --- a/scene/3d/navigation_region_3d.cpp +++ b/scene/3d/navigation_region_3d.cpp @@ -132,7 +132,7 @@ void NavigationRegion3D::set_navigation_mesh(const Ref<NavigationMesh> &p_navmes Object::cast_to<MeshInstance3D>(debug_view)->set_mesh(navmesh->get_debug_mesh()); } - emit_signal("navigation_mesh_changed"); + emit_signal(SNAME("navigation_mesh_changed")); update_gizmo(); update_configuration_warnings(); @@ -153,11 +153,11 @@ void _bake_navigation_mesh(void *p_user_data) { Ref<NavigationMesh> nav_mesh = args->nav_region->get_navigation_mesh()->duplicate(); NavigationServer3D::get_singleton()->region_bake_navmesh(nav_mesh, args->nav_region); - args->nav_region->call_deferred("_bake_finished", nav_mesh); + args->nav_region->call_deferred(SNAME("_bake_finished"), nav_mesh); memdelete(args); } else { ERR_PRINT("Can't bake the navigation mesh if the `NavigationMesh` resource doesn't exist"); - args->nav_region->call_deferred("_bake_finished", Ref<NavigationMesh>()); + args->nav_region->call_deferred(SNAME("_bake_finished"), Ref<NavigationMesh>()); memdelete(args); } } @@ -174,7 +174,7 @@ void NavigationRegion3D::bake_navigation_mesh() { void NavigationRegion3D::_bake_finished(Ref<NavigationMesh> p_nav_mesh) { set_navigation_mesh(p_nav_mesh); bake_thread.wait_to_finish(); - emit_signal("bake_finished"); + emit_signal(SNAME("bake_finished")); } TypedArray<String> NavigationRegion3D::get_configuration_warnings() const { diff --git a/scene/3d/path_3d.cpp b/scene/3d/path_3d.cpp index de115b35e3..54ae2cef75 100644 --- a/scene/3d/path_3d.cpp +++ b/scene/3d/path_3d.cpp @@ -41,7 +41,7 @@ void Path3D::_curve_changed() { update_gizmo(); } if (is_inside_tree()) { - emit_signal("curve_changed"); + emit_signal(SNAME("curve_changed")); } // update the configuration warnings of all children of type PathFollow diff --git a/scene/3d/proximity_group_3d.cpp b/scene/3d/proximity_group_3d.cpp index 9d9fea68b0..037110eaa1 100644 --- a/scene/3d/proximity_group_3d.cpp +++ b/scene/3d/proximity_group_3d.cpp @@ -130,7 +130,7 @@ void ProximityGroup3D::_proximity_group_broadcast(String p_method, Variant p_par if (dispatch_mode == MODE_PROXY) { get_parent()->call(p_method, p_parameters); } else { - emit_signal("broadcast", p_method, p_parameters); + emit_signal(SNAME("broadcast"), p_method, p_parameters); } } diff --git a/scene/3d/soft_body_3d.cpp b/scene/3d/soft_body_3d.cpp index efd8a2b50c..05530c39a1 100644 --- a/scene/3d/soft_body_3d.cpp +++ b/scene/3d/soft_body_3d.cpp @@ -425,8 +425,8 @@ void SoftBody3D::_draw_soft_mesh() { /// Necessary in order to render the mesh correctly (Soft body nodes are in global space) simulation_started = true; - call_deferred("set_as_top_level", true); - call_deferred("set_transform", Transform3D()); + call_deferred(SNAME("set_as_top_level"), true); + call_deferred(SNAME("set_transform"), Transform3D()); } _update_physics_server(); diff --git a/scene/3d/sprite_3d.cpp b/scene/3d/sprite_3d.cpp index 13f8002721..2a53dd6aca 100644 --- a/scene/3d/sprite_3d.cpp +++ b/scene/3d/sprite_3d.cpp @@ -583,10 +583,10 @@ void Sprite3D::_draw() { aabb.expand_to(vtx); } - float v_uv[2] = { uvs[i].x, uvs[i].y }; + float v_uv[2] = { (float)uvs[i].x, (float)uvs[i].y }; memcpy(&attribute_write_buffer[i * attrib_stride + mesh_surface_offsets[RS::ARRAY_TEX_UV]], v_uv, 8); - float v_vertex[3] = { vtx.x, vtx.y, vtx.z }; + float v_vertex[3] = { (float)vtx.x, (float)vtx.y, (float)vtx.z }; memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_VERTEX]], &v_vertex, sizeof(float) * 3); memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_NORMAL]], &v_normal, 4); @@ -949,10 +949,10 @@ void AnimatedSprite3D::_draw() { aabb.expand_to(vtx); } - float v_uv[2] = { uvs[i].x, uvs[i].y }; + float v_uv[2] = { (float)uvs[i].x, (float)uvs[i].y }; memcpy(&attribute_write_buffer[i * attrib_stride + mesh_surface_offsets[RS::ARRAY_TEX_UV]], v_uv, 8); - float v_vertex[3] = { vtx.x, vtx.y, vtx.z }; + float v_vertex[3] = { (float)vtx.x, (float)vtx.y, (float)vtx.z }; memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_VERTEX]], &v_vertex, sizeof(float) * 3); memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_NORMAL]], &v_normal, 4); memcpy(&vertex_write_buffer[i * vertex_stride + mesh_surface_offsets[RS::ARRAY_TANGENT]], &v_tangent, 4); diff --git a/scene/3d/xr_nodes.cpp b/scene/3d/xr_nodes.cpp index a91e712b0b..b04c7e2858 100644 --- a/scene/3d/xr_nodes.cpp +++ b/scene/3d/xr_nodes.cpp @@ -207,10 +207,10 @@ void XRController3D::_notification(int p_what) { bool is_pressed = Input::get_singleton()->is_joy_button_pressed(joy_id, (JoyButton)i); if (!was_pressed && is_pressed) { - emit_signal("button_pressed", i); + emit_signal(SNAME("button_pressed"), i); button_states += mask; } else if (was_pressed && !is_pressed) { - emit_signal("button_released", i); + emit_signal(SNAME("button_released"), i); button_states -= mask; }; @@ -225,7 +225,7 @@ void XRController3D::_notification(int p_what) { Ref<Mesh> trackerMesh = tracker->get_mesh(); if (mesh != trackerMesh) { mesh = trackerMesh; - emit_signal("mesh_updated", mesh); + emit_signal(SNAME("mesh_updated"), mesh); } }; }; break; @@ -422,7 +422,7 @@ void XRAnchor3D::_notification(int p_what) { Ref<Mesh> trackerMesh = tracker->get_mesh(); if (mesh != trackerMesh) { mesh = trackerMesh; - emit_signal("mesh_updated", mesh); + emit_signal(SNAME("mesh_updated"), mesh); } }; }; break; diff --git a/scene/animation/animation_blend_space_1d.cpp b/scene/animation/animation_blend_space_1d.cpp index 3818c7edd1..6e5d964b76 100644 --- a/scene/animation/animation_blend_space_1d.cpp +++ b/scene/animation/animation_blend_space_1d.cpp @@ -54,7 +54,7 @@ void AnimationNodeBlendSpace1D::_validate_property(PropertyInfo &property) const } void AnimationNodeBlendSpace1D::_tree_changed() { - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeBlendSpace1D::_bind_methods() { @@ -120,7 +120,7 @@ void AnimationNodeBlendSpace1D::add_blend_point(const Ref<AnimationRootNode> &p_ blend_points[p_at_index].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace1D::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED); blend_points_used++; - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeBlendSpace1D::set_blend_point_position(int p_point, float p_position) { @@ -140,7 +140,7 @@ void AnimationNodeBlendSpace1D::set_blend_point_node(int p_point, const Ref<Anim blend_points[p_point].node = p_node; blend_points[p_point].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace1D::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } float AnimationNodeBlendSpace1D::get_blend_point_position(int p_point) const { @@ -164,7 +164,7 @@ void AnimationNodeBlendSpace1D::remove_blend_point(int p_point) { } blend_points_used--; - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } int AnimationNodeBlendSpace1D::get_blend_point_count() const { diff --git a/scene/animation/animation_blend_space_2d.cpp b/scene/animation/animation_blend_space_2d.cpp index 0871423fbd..6878cbaa12 100644 --- a/scene/animation/animation_blend_space_2d.cpp +++ b/scene/animation/animation_blend_space_2d.cpp @@ -84,7 +84,7 @@ void AnimationNodeBlendSpace2D::add_blend_point(const Ref<AnimationRootNode> &p_ _queue_auto_triangles(); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeBlendSpace2D::set_blend_point_position(int p_point, const Vector2 &p_position) { @@ -103,7 +103,7 @@ void AnimationNodeBlendSpace2D::set_blend_point_node(int p_point, const Ref<Anim blend_points[p_point].node = p_node; blend_points[p_point].node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendSpace2D::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } Vector2 AnimationNodeBlendSpace2D::get_blend_point_position(int p_point) const { @@ -143,7 +143,7 @@ void AnimationNodeBlendSpace2D::remove_blend_point(int p_point) { blend_points[i] = blend_points[i + 1]; } blend_points_used--; - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } int AnimationNodeBlendSpace2D::get_blend_point_count() const { @@ -321,7 +321,7 @@ void AnimationNodeBlendSpace2D::_queue_auto_triangles() { } trianges_dirty = true; - call_deferred("_update_triangles"); + call_deferred(SNAME("_update_triangles")); } void AnimationNodeBlendSpace2D::_update_triangles() { @@ -332,7 +332,7 @@ void AnimationNodeBlendSpace2D::_update_triangles() { trianges_dirty = false; triangles.clear(); if (blend_points_used < 3) { - emit_signal("triangles_updated"); + emit_signal(SNAME("triangles_updated")); return; } @@ -347,7 +347,7 @@ void AnimationNodeBlendSpace2D::_update_triangles() { for (int i = 0; i < triangles.size(); i++) { add_triangle(triangles[i].points[0], triangles[i].points[1], triangles[i].points[2]); } - emit_signal("triangles_updated"); + emit_signal(SNAME("triangles_updated")); } Vector2 AnimationNodeBlendSpace2D::get_closest_point(const Vector2 &p_point) { @@ -586,7 +586,7 @@ Ref<AnimationNode> AnimationNodeBlendSpace2D::get_child_by_name(const StringName } void AnimationNodeBlendSpace2D::_tree_changed() { - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeBlendSpace2D::set_blend_mode(BlendMode p_blend_mode) { diff --git a/scene/animation/animation_blend_tree.cpp b/scene/animation/animation_blend_tree.cpp index 6a988042b5..200a688067 100644 --- a/scene/animation/animation_blend_tree.cpp +++ b/scene/animation/animation_blend_tree.cpp @@ -816,7 +816,7 @@ void AnimationNodeBlendTree::add_node(const StringName &p_name, Ref<AnimationNod nodes[p_name] = n; emit_changed(); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); p_node->connect("tree_changed", callable_mp(this, &AnimationNodeBlendTree::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED); p_node->connect("changed", callable_mp(this, &AnimationNodeBlendTree::_node_changed), varray(p_name), CONNECT_REFERENCE_COUNTED); @@ -896,7 +896,7 @@ void AnimationNodeBlendTree::remove_node(const StringName &p_name) { } emit_changed(); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeBlendTree::rename_node(const StringName &p_name, const StringName &p_new_name) { @@ -921,7 +921,7 @@ void AnimationNodeBlendTree::rename_node(const StringName &p_name, const StringN //connection must be done with new name nodes[p_new_name].node->connect("changed", callable_mp(this, &AnimationNodeBlendTree::_node_changed), varray(p_new_name), CONNECT_REFERENCE_COUNTED); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeBlendTree::connect_node(const StringName &p_input_node, int p_input_index, const StringName &p_output_node) { @@ -1125,11 +1125,11 @@ void AnimationNodeBlendTree::reset_state() { graph_offset = Vector2(); nodes.clear(); emit_changed(); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeBlendTree::_tree_changed() { - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeBlendTree::_node_changed(const StringName &p_node) { diff --git a/scene/animation/animation_node_state_machine.cpp b/scene/animation/animation_node_state_machine.cpp index f494f5c163..6496331cb0 100644 --- a/scene/animation/animation_node_state_machine.cpp +++ b/scene/animation/animation_node_state_machine.cpp @@ -57,7 +57,7 @@ void AnimationNodeStateMachineTransition::set_advance_condition(const StringName } else { advance_condition_name = StringName(); } - emit_signal("advance_condition_changed"); + emit_signal(SNAME("advance_condition_changed")); } StringName AnimationNodeStateMachineTransition::get_advance_condition() const { @@ -539,7 +539,7 @@ void AnimationNodeStateMachine::add_node(const StringName &p_name, Ref<Animation states[p_name] = state; emit_changed(); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); p_node->connect("tree_changed", callable_mp(this, &AnimationNodeStateMachine::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED); } @@ -559,7 +559,7 @@ void AnimationNodeStateMachine::replace_node(const StringName &p_name, Ref<Anima states[p_name].node = p_node; emit_changed(); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); p_node->connect("tree_changed", callable_mp(this, &AnimationNodeStateMachine::_tree_changed), varray(), CONNECT_REFERENCE_COUNTED); } @@ -636,7 +636,7 @@ void AnimationNodeStateMachine::remove_node(const StringName &p_name) { }*/ emit_changed(); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeStateMachine::rename_node(const StringName &p_name, const StringName &p_new_name) { @@ -669,7 +669,7 @@ void AnimationNodeStateMachine::rename_node(const StringName &p_name, const Stri }*/ //path.clear(); //clear path - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeStateMachine::get_node_list(List<StringName> *r_nodes) const { @@ -923,7 +923,7 @@ void AnimationNodeStateMachine::reset_state() { graph_offset = Vector2(); emit_changed(); - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeStateMachine::set_node_position(const StringName &p_name, const Vector2 &p_position) { @@ -937,7 +937,7 @@ Vector2 AnimationNodeStateMachine::get_node_position(const StringName &p_name) c } void AnimationNodeStateMachine::_tree_changed() { - emit_signal("tree_changed"); + emit_signal(SNAME("tree_changed")); } void AnimationNodeStateMachine::_bind_methods() { diff --git a/scene/animation/animation_player.cpp b/scene/animation/animation_player.cpp index 6154eef3cf..14ca325c25 100644 --- a/scene/animation/animation_player.cpp +++ b/scene/animation/animation_player.cpp @@ -557,6 +557,7 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float } #endif + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); if (can_call) { if (method_call_mode == ANIMATION_METHOD_CALL_DEFERRED) { MessageQueue::get_singleton()->push_call( @@ -566,7 +567,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float s >= 2 ? params[1] : Variant(), s >= 3 ? params[2] : Variant(), s >= 4 ? params[3] : Variant(), - s >= 5 ? params[4] : Variant()); + s >= 5 ? params[4] : Variant(), + s >= 6 ? params[5] : Variant(), + s >= 7 ? params[6] : Variant(), + s >= 8 ? params[7] : Variant()); } else { nc->node->call( method, @@ -574,7 +578,10 @@ void AnimationPlayer::_animation_process_animation(AnimationData *p_anim, float s >= 2 ? params[1] : Variant(), s >= 3 ? params[2] : Variant(), s >= 4 ? params[3] : Variant(), - s >= 5 ? params[4] : Variant()); + s >= 5 ? params[4] : Variant(), + s >= 6 ? params[5] : Variant(), + s >= 7 ? params[6] : Variant(), + s >= 8 ? params[7] : Variant()); } } } @@ -1325,7 +1332,7 @@ float AnimationPlayer::get_current_animation_length() const { void AnimationPlayer::_animation_changed() { clear_caches(); - emit_signal("caches_cleared"); + emit_signal(SNAME("caches_cleared")); if (is_playing()) { playback.seeked = true; //need to restart stuff, like audio } diff --git a/scene/animation/animation_tree.cpp b/scene/animation/animation_tree.cpp index 1e07f83d09..72448fc4f7 100644 --- a/scene/animation/animation_tree.cpp +++ b/scene/animation/animation_tree.cpp @@ -985,6 +985,7 @@ void AnimationTree::_process_graph(float p_delta) { int s = params.size(); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); ERR_CONTINUE(s > VARIANT_ARG_MAX); if (can_call) { t->object->call_deferred( @@ -993,7 +994,10 @@ void AnimationTree::_process_graph(float p_delta) { s >= 2 ? params[1] : Variant(), s >= 3 ? params[2] : Variant(), s >= 4 ? params[3] : Variant(), - s >= 5 ? params[4] : Variant()); + s >= 5 ? params[4] : Variant(), + s >= 6 ? params[5] : Variant(), + s >= 7 ? params[6] : Variant(), + s >= 8 ? params[7] : Variant()); } } @@ -1327,7 +1331,7 @@ void AnimationTree::_tree_changed() { return; } - call_deferred("_update_properties"); + call_deferred(SNAME("_update_properties")); properties_dirty = true; } diff --git a/scene/animation/tween.cpp b/scene/animation/tween.cpp index 7bf616e602..761046c14a 100644 --- a/scene/animation/tween.cpp +++ b/scene/animation/tween.cpp @@ -264,7 +264,7 @@ bool Tween::step(float p_delta) { rem_delta = step_delta; if (!step_active) { - emit_signal("step_finished", current_step); + emit_signal(SNAME("step_finished"), current_step); current_step++; if (current_step == tweeners.size()) { @@ -272,9 +272,9 @@ bool Tween::step(float p_delta) { if (loops_done == loops) { running = false; dead = true; - emit_signal("finished"); + emit_signal(SNAME("finished")); } else { - emit_signal("loop_finished", loops_done); + emit_signal(SNAME("loop_finished"), loops_done); current_step = 0; start_tweeners(); } @@ -690,7 +690,7 @@ bool PropertyTweener::step(float &r_delta) { } else { finished = true; r_delta = elapsed_time - delay - duration; - emit_signal("finished"); + emit_signal(SNAME("finished")); return false; } } @@ -745,7 +745,7 @@ bool IntervalTweener::step(float &r_delta) { } else { finished = true; r_delta = elapsed_time - duration; - emit_signal("finished"); + emit_signal(SNAME("finished")); return false; } } @@ -784,7 +784,7 @@ bool CallbackTweener::step(float &r_delta) { finished = true; r_delta = elapsed_time - delay; - emit_signal("finished"); + emit_signal(SNAME("finished")); return false; } @@ -854,7 +854,7 @@ bool MethodTweener::step(float &r_delta) { } else { finished = true; r_delta = elapsed_time - delay - duration; - emit_signal("finished"); + emit_signal(SNAME("finished")); return false; } } diff --git a/scene/audio/audio_stream_player.cpp b/scene/audio/audio_stream_player.cpp index 1478cbf69e..298d75b668 100644 --- a/scene/audio/audio_stream_player.cpp +++ b/scene/audio/audio_stream_player.cpp @@ -146,7 +146,7 @@ void AudioStreamPlayer::_notification(int p_what) { if (!active.is_set() || (setseek.get() < 0 && !stream_playback->is_playing())) { active.clear(); set_process_internal(false); - emit_signal("finished"); + emit_signal(SNAME("finished")); } } diff --git a/scene/debugger/scene_debugger.cpp b/scene/debugger/scene_debugger.cpp index 1e121ab6e5..fd5637be11 100644 --- a/scene/debugger/scene_debugger.cpp +++ b/scene/debugger/scene_debugger.cpp @@ -145,12 +145,12 @@ Error SceneDebugger::parse_message(void *p_user, const String &p_msg, const Arra live_editor->_res_set_func(p_args[0], p_args[1], p_args[2]); } else if (p_msg == "live_node_call") { - ERR_FAIL_COND_V(p_args.size() < 7, ERR_INVALID_DATA); - live_editor->_node_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6]); + ERR_FAIL_COND_V(p_args.size() < 10, ERR_INVALID_DATA); + live_editor->_node_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6], p_args[7], p_args[8], p_args[9]); } else if (p_msg == "live_res_call") { - ERR_FAIL_COND_V(p_args.size() < 7, ERR_INVALID_DATA); - live_editor->_res_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6]); + ERR_FAIL_COND_V(p_args.size() < 10, ERR_INVALID_DATA); + live_editor->_res_call_func(p_args[0], p_args[1], p_args[2], p_args[3], p_args[4], p_args[5], p_args[6], p_args[7], p_args[8], p_args[9]); } else if (p_msg == "live_create_node") { ERR_FAIL_COND_V(p_args.size() < 3, ERR_INVALID_DATA); diff --git a/scene/gui/base_button.cpp b/scene/gui/base_button.cpp index 8414c4dc78..75a4464a40 100644 --- a/scene/gui/base_button.cpp +++ b/scene/gui/base_button.cpp @@ -125,7 +125,7 @@ void BaseButton::_pressed() { get_script_instance()->call(SceneStringNames::get_singleton()->_pressed); } pressed(); - emit_signal("pressed"); + emit_signal(SNAME("pressed")); } void BaseButton::_toggled(bool p_pressed) { @@ -133,14 +133,14 @@ void BaseButton::_toggled(bool p_pressed) { get_script_instance()->call(SceneStringNames::get_singleton()->_toggled, p_pressed); } toggled(p_pressed); - emit_signal("toggled", p_pressed); + emit_signal(SNAME("toggled"), p_pressed); } void BaseButton::on_action_event(Ref<InputEvent> p_event) { if (p_event->is_pressed()) { status.press_attempt = true; status.pressing_inside = true; - emit_signal("button_down"); + emit_signal(SNAME("button_down")); } if (status.press_attempt && status.pressing_inside) { @@ -153,7 +153,7 @@ void BaseButton::on_action_event(Ref<InputEvent> p_event) { status.pressed = !status.pressed; _unpress_group(); if (button_group.is_valid()) { - button_group->emit_signal("pressed", this); + button_group->emit_signal(SNAME("pressed"), this); } _toggled(status.pressed); _pressed(); @@ -174,7 +174,7 @@ void BaseButton::on_action_event(Ref<InputEvent> p_event) { } status.press_attempt = false; status.pressing_inside = false; - emit_signal("button_up"); + emit_signal(SNAME("button_up")); } update(); @@ -218,7 +218,7 @@ void BaseButton::set_pressed(bool p_pressed) { if (p_pressed) { _unpress_group(); if (button_group.is_valid()) { - button_group->emit_signal("pressed", this); + button_group->emit_signal(SNAME("pressed"), this); } } _toggled(status.pressed); diff --git a/scene/gui/box_container.cpp b/scene/gui/box_container.cpp index 40a49dbb58..a2f1d2b15a 100644 --- a/scene/gui/box_container.cpp +++ b/scene/gui/box_container.cpp @@ -43,7 +43,7 @@ void BoxContainer::_resort() { Size2i new_size = get_size(); - int sep = get_theme_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); + int sep = get_theme_constant(SNAME("separation")); //,vertical?"VBoxContainer":"HBoxContainer"); bool rtl = is_layout_rtl(); bool first = true; @@ -247,7 +247,7 @@ Size2 BoxContainer::get_minimum_size() const { /* Calculate MINIMUM SIZE */ Size2i minimum; - int sep = get_theme_constant("separation"); //,vertical?"VBoxContainer":"HBoxContainer"); + int sep = get_theme_constant(SNAME("separation")); //,vertical?"VBoxContainer":"HBoxContainer"); bool first = true; diff --git a/scene/gui/button.cpp b/scene/gui/button.cpp index bcc273114b..4b6c0ef697 100644 --- a/scene/gui/button.cpp +++ b/scene/gui/button.cpp @@ -41,8 +41,8 @@ Size2 Button::get_minimum_size() const { if (!expand_icon) { Ref<Texture2D> _icon; - if (icon.is_null() && has_theme_icon("icon")) { - _icon = Control::get_theme_icon("icon"); + if (icon.is_null() && has_theme_icon(SNAME("icon"))) { + _icon = Control::get_theme_icon(SNAME("icon")); } else { _icon = icon; } @@ -53,7 +53,7 @@ Size2 Button::get_minimum_size() const { if (icon_align != ALIGN_CENTER) { minsize.width += _icon->get_width(); if (xl_text != "") { - minsize.width += get_theme_constant("hseparation"); + minsize.width += get_theme_constant(SNAME("hseparation")); } } else { minsize.width = MAX(minsize.width, _icon->get_width()); @@ -61,12 +61,12 @@ Size2 Button::get_minimum_size() const { } } - Ref<Font> font = get_theme_font("font"); - float font_height = font->get_height(get_theme_font_size("font_size")); + Ref<Font> font = get_theme_font(SNAME("font")); + float font_height = font->get_height(get_theme_font_size(SNAME("font_size"))); minsize.height = MAX(font_height, minsize.height); - return get_theme_stylebox("normal")->get_minimum_size() + minsize; + return get_theme_stylebox(SNAME("normal"))->get_minimum_size() + minsize; } void Button::_set_internal_margin(Side p_side, float p_value) { @@ -97,43 +97,43 @@ void Button::_notification(int p_what) { Color color; Color color_icon(1, 1, 1, 1); - Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); bool rtl = is_layout_rtl(); switch (get_draw_mode()) { case DRAW_NORMAL: { - if (rtl && has_theme_stylebox("normal_mirrored")) { - style = get_theme_stylebox("normal_mirrored"); + if (rtl && has_theme_stylebox(SNAME("normal_mirrored"))) { + style = get_theme_stylebox(SNAME("normal_mirrored")); } else { - style = get_theme_stylebox("normal"); + style = get_theme_stylebox(SNAME("normal")); } if (!flat) { style->draw(ci, Rect2(Point2(0, 0), size)); } - color = get_theme_color("font_color"); - if (has_theme_color("icon_normal_color")) { - color_icon = get_theme_color("icon_normal_color"); + color = get_theme_color(SNAME("font_color")); + if (has_theme_color(SNAME("icon_normal_color"))) { + color_icon = get_theme_color(SNAME("icon_normal_color")); } } break; case DRAW_HOVER_PRESSED: { - if (has_theme_stylebox("hover_pressed") && has_theme_stylebox_override("hover_pressed")) { - if (rtl && has_theme_stylebox("hover_pressed_mirrored")) { - style = get_theme_stylebox("hover_pressed_mirrored"); + if (has_theme_stylebox(SNAME("hover_pressed")) && has_theme_stylebox_override("hover_pressed")) { + if (rtl && has_theme_stylebox(SNAME("hover_pressed_mirrored"))) { + style = get_theme_stylebox(SNAME("hover_pressed_mirrored")); } else { - style = get_theme_stylebox("hover_pressed"); + style = get_theme_stylebox(SNAME("hover_pressed")); } if (!flat) { style->draw(ci, Rect2(Point2(0, 0), size)); } - if (has_theme_color("font_hover_pressed_color")) { - color = get_theme_color("font_hover_pressed_color"); + if (has_theme_color(SNAME("font_hover_pressed_color"))) { + color = get_theme_color(SNAME("font_hover_pressed_color")); } else { - color = get_theme_color("font_color"); + color = get_theme_color(SNAME("font_color")); } - if (has_theme_color("icon_hover_pressed_color")) { - color_icon = get_theme_color("icon_hover_pressed_color"); + if (has_theme_color(SNAME("icon_hover_pressed_color"))) { + color_icon = get_theme_color(SNAME("icon_hover_pressed_color")); } break; @@ -141,67 +141,67 @@ void Button::_notification(int p_what) { [[fallthrough]]; } case DRAW_PRESSED: { - if (rtl && has_theme_stylebox("pressed_mirrored")) { - style = get_theme_stylebox("pressed_mirrored"); + if (rtl && has_theme_stylebox(SNAME("pressed_mirrored"))) { + style = get_theme_stylebox(SNAME("pressed_mirrored")); } else { - style = get_theme_stylebox("pressed"); + style = get_theme_stylebox(SNAME("pressed")); } if (!flat) { style->draw(ci, Rect2(Point2(0, 0), size)); } - if (has_theme_color("font_pressed_color")) { - color = get_theme_color("font_pressed_color"); + if (has_theme_color(SNAME("font_pressed_color"))) { + color = get_theme_color(SNAME("font_pressed_color")); } else { - color = get_theme_color("font_color"); + color = get_theme_color(SNAME("font_color")); } - if (has_theme_color("icon_pressed_color")) { - color_icon = get_theme_color("icon_pressed_color"); + if (has_theme_color(SNAME("icon_pressed_color"))) { + color_icon = get_theme_color(SNAME("icon_pressed_color")); } } break; case DRAW_HOVER: { - if (rtl && has_theme_stylebox("hover_mirrored")) { - style = get_theme_stylebox("hover_mirrored"); + if (rtl && has_theme_stylebox(SNAME("hover_mirrored"))) { + style = get_theme_stylebox(SNAME("hover_mirrored")); } else { - style = get_theme_stylebox("hover"); + style = get_theme_stylebox(SNAME("hover")); } if (!flat) { style->draw(ci, Rect2(Point2(0, 0), size)); } - color = get_theme_color("font_hover_color"); - if (has_theme_color("icon_hover_color")) { - color_icon = get_theme_color("icon_hover_color"); + color = get_theme_color(SNAME("font_hover_color")); + if (has_theme_color(SNAME("icon_hover_color"))) { + color_icon = get_theme_color(SNAME("icon_hover_color")); } } break; case DRAW_DISABLED: { - if (rtl && has_theme_stylebox("disabled_mirrored")) { - style = get_theme_stylebox("disabled_mirrored"); + if (rtl && has_theme_stylebox(SNAME("disabled_mirrored"))) { + style = get_theme_stylebox(SNAME("disabled_mirrored")); } else { - style = get_theme_stylebox("disabled"); + style = get_theme_stylebox(SNAME("disabled")); } if (!flat) { style->draw(ci, Rect2(Point2(0, 0), size)); } - color = get_theme_color("font_disabled_color"); - if (has_theme_color("icon_disabled_color")) { - color_icon = get_theme_color("icon_disabled_color"); + color = get_theme_color(SNAME("font_disabled_color")); + if (has_theme_color(SNAME("icon_disabled_color"))) { + color_icon = get_theme_color(SNAME("icon_disabled_color")); } } break; } if (has_focus()) { - Ref<StyleBox> style2 = get_theme_stylebox("focus"); + Ref<StyleBox> style2 = get_theme_stylebox(SNAME("focus")); style2->draw(ci, Rect2(Point2(), size)); } Ref<Texture2D> _icon; - if (icon.is_null() && has_theme_icon("icon")) { - _icon = Control::get_theme_icon("icon"); + if (icon.is_null() && has_theme_icon(SNAME("icon"))) { + _icon = Control::get_theme_icon(SNAME("icon")); } else { _icon = icon; } @@ -234,21 +234,21 @@ void Button::_notification(int p_what) { if (icon_align_rtl_checked == ALIGN_LEFT) { style_offset.x = style->get_margin(SIDE_LEFT); if (_internal_margin[SIDE_LEFT] > 0) { - icon_ofs_region = _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation"); + icon_ofs_region = _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation")); } } else if (icon_align_rtl_checked == ALIGN_CENTER) { style_offset.x = 0.0; } else if (icon_align_rtl_checked == ALIGN_RIGHT) { style_offset.x = -style->get_margin(SIDE_RIGHT); if (_internal_margin[SIDE_RIGHT] > 0) { - icon_ofs_region = -_internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation"); + icon_ofs_region = -_internal_margin[SIDE_RIGHT] - get_theme_constant(SNAME("hseparation")); } } style_offset.y = style->get_margin(SIDE_TOP); if (expand_icon) { Size2 _size = get_size() - style->get_offset() * 2; - _size.width -= get_theme_constant("hseparation") + icon_ofs_region; + _size.width -= get_theme_constant(SNAME("hseparation")) + icon_ofs_region; if (!clip_text && icon_align_rtl_checked != ALIGN_CENTER) { _size.width -= text_buf->get_size().width; } @@ -276,7 +276,7 @@ void Button::_notification(int p_what) { } } - Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant("hseparation"), 0) : Point2(); + Point2 icon_ofs = !_icon.is_null() ? Point2(icon_region.size.width + get_theme_constant(SNAME("hseparation")), 0) : Point2(); if (align_rtl_checked == ALIGN_CENTER && icon_align_rtl_checked == ALIGN_CENTER) { icon_ofs.x = 0.0; } @@ -286,10 +286,10 @@ void Button::_notification(int p_what) { int text_width = clip_text ? MIN(text_clip, text_buf->get_size().x) : text_buf->get_size().x; if (_internal_margin[SIDE_LEFT] > 0) { - text_clip -= _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation"); + text_clip -= _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation")); } if (_internal_margin[SIDE_RIGHT] > 0) { - text_clip -= _internal_margin[SIDE_RIGHT] + get_theme_constant("hseparation"); + text_clip -= _internal_margin[SIDE_RIGHT] + get_theme_constant(SNAME("hseparation")); } Point2 text_ofs = (size - style->get_minimum_size() - icon_ofs - text_buf->get_size() - Point2(_internal_margin[SIDE_RIGHT] - _internal_margin[SIDE_LEFT], 0)) / 2.0; @@ -300,7 +300,7 @@ void Button::_notification(int p_what) { icon_ofs.x = 0.0; } if (_internal_margin[SIDE_LEFT] > 0) { - text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant("hseparation"); + text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x + _internal_margin[SIDE_LEFT] + get_theme_constant(SNAME("hseparation")); } else { text_ofs.x = style->get_margin(SIDE_LEFT) + icon_ofs.x; } @@ -317,7 +317,7 @@ void Button::_notification(int p_what) { } break; case ALIGN_RIGHT: { if (_internal_margin[SIDE_RIGHT] > 0) { - text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant("hseparation"); + text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width - _internal_margin[SIDE_RIGHT] - get_theme_constant(SNAME("hseparation")); } else { text_ofs.x = size.x - style->get_margin(SIDE_RIGHT) - text_width; } @@ -328,8 +328,8 @@ void Button::_notification(int p_what) { } break; } - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); + 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) { text_buf->draw_outline(ci, text_ofs, outline_size, font_outline_color); } @@ -340,8 +340,8 @@ void Button::_notification(int p_what) { } void Button::_shape() { - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + Ref<Font> font = get_theme_font(SNAME("font")); + int font_size = get_theme_font_size(SNAME("font_size")); text_buf->clear(); if (text_direction == Control::TEXT_DIRECTION_INHERITED) { diff --git a/scene/gui/check_box.cpp b/scene/gui/check_box.cpp index c0650a8f3f..d93107df2d 100644 --- a/scene/gui/check_box.cpp +++ b/scene/gui/check_box.cpp @@ -33,12 +33,12 @@ #include "servers/rendering_server.h" Size2 CheckBox::get_icon_size() const { - Ref<Texture2D> checked = Control::get_theme_icon("checked"); - Ref<Texture2D> checked_disabled = Control::get_theme_icon("checked_disabled"); - Ref<Texture2D> unchecked = Control::get_theme_icon("unchecked"); - Ref<Texture2D> unchecked_disabled = Control::get_theme_icon("unchecked_disabled"); - Ref<Texture2D> radio_checked = Control::get_theme_icon("radio_checked"); - Ref<Texture2D> radio_unchecked = Control::get_theme_icon("radio_unchecked"); + Ref<Texture2D> checked = Control::get_theme_icon(SNAME("checked")); + Ref<Texture2D> checked_disabled = Control::get_theme_icon(SNAME("checked_disabled")); + Ref<Texture2D> unchecked = Control::get_theme_icon(SNAME("unchecked")); + Ref<Texture2D> unchecked_disabled = Control::get_theme_icon(SNAME("unchecked_disabled")); + Ref<Texture2D> radio_checked = Control::get_theme_icon(SNAME("radio_checked")); + Ref<Texture2D> radio_unchecked = Control::get_theme_icon(SNAME("radio_unchecked")); Size2 tex_size = Size2(0, 0); if (!checked.is_null()) { @@ -61,9 +61,9 @@ Size2 CheckBox::get_minimum_size() const { Size2 tex_size = get_icon_size(); minsize.width += tex_size.width; if (get_text().length() > 0) { - minsize.width += get_theme_constant("hseparation"); + minsize.width += get_theme_constant(SNAME("hseparation")); } - Ref<StyleBox> sb = get_theme_stylebox("normal"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal")); minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM)); return minsize; @@ -83,7 +83,7 @@ void CheckBox::_notification(int p_what) { 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("normal"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal")); Vector2 ofs; if (is_layout_rtl()) { @@ -91,7 +91,7 @@ void CheckBox::_notification(int p_what) { } else { ofs.x = sb->get_margin(SIDE_LEFT); } - ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant("check_vadjust"); + ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant(SNAME("check_vadjust")); if (is_pressed()) { on->draw(ci, ofs); diff --git a/scene/gui/check_button.cpp b/scene/gui/check_button.cpp index a8bf449355..162a256d23 100644 --- a/scene/gui/check_button.cpp +++ b/scene/gui/check_button.cpp @@ -52,9 +52,9 @@ Size2 CheckButton::get_minimum_size() const { Size2 tex_size = get_icon_size(); minsize.width += tex_size.width; if (get_text().length() > 0) { - minsize.width += get_theme_constant("hseparation"); + minsize.width += get_theme_constant(SNAME("hseparation")); } - Ref<StyleBox> sb = get_theme_stylebox("normal"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal")); minsize.height = MAX(minsize.height, tex_size.height + sb->get_margin(SIDE_TOP) + sb->get_margin(SIDE_BOTTOM)); return minsize; @@ -86,7 +86,7 @@ void CheckButton::_notification(int p_what) { off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off"); } - Ref<StyleBox> sb = get_theme_stylebox("normal"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal")); Vector2 ofs; Size2 tex_size = get_icon_size(); @@ -95,7 +95,7 @@ void CheckButton::_notification(int p_what) { } 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("check_vadjust"); + ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant(SNAME("check_vadjust")); if (is_pressed()) { on->draw(ci, ofs); diff --git a/scene/gui/code_edit.cpp b/scene/gui/code_edit.cpp index ba1534ed5c..f302f64224 100644 --- a/scene/gui/code_edit.cpp +++ b/scene/gui/code_edit.cpp @@ -50,28 +50,28 @@ void CodeEdit::_notification(int p_what) { set_gutter_width(line_number_gutter, (line_number_digits + 1) * cache.font->get_char_size('0', 0, cache.font_size).width); set_gutter_width(fold_gutter, get_row_height() / 1.2); - breakpoint_color = get_theme_color("breakpoint_color"); - breakpoint_icon = get_theme_icon("breakpoint"); + breakpoint_color = get_theme_color(SNAME("breakpoint_color")); + breakpoint_icon = get_theme_icon(SNAME("breakpoint")); - bookmark_color = get_theme_color("bookmark_color"); - bookmark_icon = get_theme_icon("bookmark"); + bookmark_color = get_theme_color(SNAME("bookmark_color")); + bookmark_icon = get_theme_icon(SNAME("bookmark")); - executing_line_color = get_theme_color("executing_line_color"); - executing_line_icon = get_theme_icon("executing_line"); + executing_line_color = get_theme_color(SNAME("executing_line_color")); + executing_line_icon = get_theme_icon(SNAME("executing_line")); - line_number_color = get_theme_color("line_number_color"); + line_number_color = get_theme_color(SNAME("line_number_color")); - folding_color = get_theme_color("code_folding_color"); - can_fold_icon = get_theme_icon("can_fold"); - folded_icon = get_theme_icon("folded"); + folding_color = get_theme_color(SNAME("code_folding_color")); + can_fold_icon = get_theme_icon(SNAME("can_fold")); + folded_icon = get_theme_icon(SNAME("folded")); - code_completion_max_width = get_theme_constant("completion_max_width") * cache.font->get_char_size('x').x; - code_completion_max_lines = get_theme_constant("completion_lines"); - code_completion_scroll_width = get_theme_constant("completion_scroll_width"); - code_completion_scroll_color = get_theme_color("completion_scroll_color"); - code_completion_background_color = get_theme_color("completion_background_color"); - code_completion_selected_color = get_theme_color("completion_selected_color"); - code_completion_existing_color = get_theme_color("completion_existing_color"); + code_completion_max_width = get_theme_constant(SNAME("completion_max_width")) * cache.font->get_char_size('x').x; + code_completion_max_lines = get_theme_constant(SNAME("completion_lines")); + code_completion_scroll_width = get_theme_constant(SNAME("completion_scroll_width")); + code_completion_scroll_color = get_theme_color(SNAME("completion_scroll_color")); + code_completion_background_color = get_theme_color(SNAME("completion_background_color")); + code_completion_selected_color = get_theme_color(SNAME("completion_selected_color")); + code_completion_existing_color = get_theme_color(SNAME("completion_existing_color")); } break; case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); @@ -81,11 +81,11 @@ void CodeEdit::_notification(int p_what) { bool code_completion_below = false; if (caret_visible && code_completion_active && code_completion_options.size() > 0) { - Ref<StyleBox> csb = get_theme_stylebox("completion"); + Ref<StyleBox> csb = get_theme_stylebox(SNAME("completion")); const int code_completion_options_count = code_completion_options.size(); const int lines = MIN(code_completion_options_count, code_completion_max_lines); - const int icon_hsep = get_theme_constant("hseparation", "ItemList"); + const int icon_hsep = get_theme_constant(SNAME("hseparation"), SNAME("ItemList")); const Size2 icon_area_size(row_height, row_height); code_completion_rect.size.width = code_completion_longest_line + icon_hsep + icon_area_size.width + 2; @@ -164,8 +164,8 @@ void CodeEdit::_notification(int p_what) { if (caret_visible && code_hint != "" && (!code_completion_active || (code_completion_below != code_hint_draw_below))) { const Ref<Font> font = cache.font; const int font_height = font->get_height(cache.font_size); - Ref<StyleBox> sb = get_theme_stylebox("panel", "TooltipPanel"); - Color font_color = get_theme_color("font_color", "TooltipLabel"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel"), SNAME("TooltipPanel")); + Color font_color = get_theme_color(SNAME("font_color"), SNAME("TooltipLabel")); Vector<String> code_hint_lines = code_hint.split("\n"); int line_count = code_hint_lines.size(); @@ -969,7 +969,7 @@ void CodeEdit::set_line_as_breakpoint(int p_line, bool p_breakpointed) { } else if (breakpointed_lines.has(p_line)) { breakpointed_lines.erase(p_line); } - emit_signal("breakpoint_toggled", p_line); + emit_signal(SNAME("breakpoint_toggled"), p_line); update(); } @@ -1551,7 +1551,7 @@ void CodeEdit::request_code_completion(bool p_force) { } if (p_force) { - emit_signal("request_code_completion"); + emit_signal(SNAME("request_code_completion")); return; } @@ -1559,9 +1559,9 @@ void CodeEdit::request_code_completion(bool p_force) { int ofs = CLAMP(cursor_get_column(), 0, line.length()); if (ofs > 0 && (is_in_string(cursor_get_line(), ofs) != -1 || _is_char(line[ofs - 1]) || code_completion_prefixes.has(String::chr(line[ofs - 1])))) { - emit_signal("request_code_completion"); + emit_signal(SNAME("request_code_completion")); } else if (ofs > 1 && line[ofs - 1] == ' ' && code_completion_prefixes.has(String::chr(line[ofs - 2]))) { - emit_signal("request_code_completion"); + emit_signal(SNAME("request_code_completion")); } } @@ -2534,9 +2534,9 @@ void CodeEdit::_lines_edited_from(int p_from_line, int p_to_line) { } breakpointed_lines.erase(line); - emit_signal("breakpoint_toggled", line); + emit_signal(SNAME("breakpoint_toggled"), line); if (line_count > 0 || line >= p_from_line) { - emit_signal("breakpoint_toggled", line + line_count); + emit_signal(SNAME("breakpoint_toggled"), line + line_count); breakpointed_lines[line + line_count] = true; continue; } @@ -2562,7 +2562,7 @@ CodeEdit::CodeEdit() { set_gutter_name(gutter_idx, "main_gutter"); set_gutter_draw(gutter_idx, false); set_gutter_overwritable(gutter_idx, true); - set_gutter_type(gutter_idx, GUTTER_TPYE_CUSTOM); + set_gutter_type(gutter_idx, GUTTER_TYPE_CUSTOM); set_gutter_custom_draw(gutter_idx, this, "_main_gutter_draw_callback"); gutter_idx++; @@ -2570,7 +2570,7 @@ CodeEdit::CodeEdit() { add_gutter(); set_gutter_name(gutter_idx, "line_numbers"); set_gutter_draw(gutter_idx, false); - set_gutter_type(gutter_idx, GUTTER_TPYE_CUSTOM); + set_gutter_type(gutter_idx, GUTTER_TYPE_CUSTOM); set_gutter_custom_draw(gutter_idx, this, "_line_number_draw_callback"); gutter_idx++; @@ -2578,7 +2578,7 @@ CodeEdit::CodeEdit() { add_gutter(); set_gutter_name(gutter_idx, "fold_gutter"); set_gutter_draw(gutter_idx, false); - set_gutter_type(gutter_idx, GUTTER_TPYE_CUSTOM); + set_gutter_type(gutter_idx, GUTTER_TYPE_CUSTOM); set_gutter_custom_draw(gutter_idx, this, "_fold_gutter_draw_callback"); gutter_idx++; diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 842cef3b83..261480bcdd 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -45,14 +45,14 @@ List<Color> ColorPicker::preset_cache; void ColorPicker::_notification(int p_what) { switch (p_what) { case NOTIFICATION_THEME_CHANGED: { - btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker")); - bt_add_preset->set_icon(get_theme_icon("add_preset")); + btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker"))); + bt_add_preset->set_icon(get_theme_icon(SNAME("add_preset"))); _update_controls(); } break; case NOTIFICATION_ENTER_TREE: { - btn_pick->set_icon(get_theme_icon("screen_picker", "ColorPicker")); - bt_add_preset->set_icon(get_theme_icon("add_preset")); + btn_pick->set_icon(get_theme_icon(SNAME("screen_picker"), SNAME("ColorPicker"))); + bt_add_preset->set_icon(get_theme_icon(SNAME("add_preset"))); _update_controls(); _update_color(); @@ -75,13 +75,13 @@ void ColorPicker::_notification(int p_what) { } break; case NOTIFICATION_PARENTED: { for (int i = 0; i < 4; i++) { - set_offset((Side)i, get_offset((Side)i) + get_theme_constant("margin")); + set_offset((Side)i, get_offset((Side)i) + get_theme_constant(SNAME("margin"))); } } break; case NOTIFICATION_VISIBILITY_CHANGED: { Popup *p = Object::cast_to<Popup>(get_parent()); if (p) { - p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant("margin") * 2, get_combined_minimum_size().height + get_theme_constant("margin") * 2)); + p->set_size(Size2(get_combined_minimum_size().width + get_theme_constant(SNAME("margin")) * 2, get_combined_minimum_size().height + get_theme_constant(SNAME("margin")) * 2)); } } break; case NOTIFICATION_WM_CLOSE_REQUEST: { @@ -97,43 +97,49 @@ Ref<Shader> ColorPicker::circle_shader; void ColorPicker::init_shaders() { wheel_shader.instantiate(); - wheel_shader->set_code( - "shader_type canvas_item;" - "void fragment() {" - " float x = UV.x - 0.5;" - " float y = UV.y - 0.5;" - " float a = atan(y, x);" - " x += 0.001;" - " y += 0.001;" - " float b = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);" - " x -= 0.002;" - " float b2 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);" - " y -= 0.002;" - " float b3 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);" - " x += 0.002;" - " float b4 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42);" - " COLOR = vec4(clamp((abs(fract(((a - TAU) / TAU) + vec3(3.0, 2.0, 1.0) / 3.0) * 6.0 - 3.0) - 1.0), 0.0, 1.0), (b + b2 + b3 + b4) / 4.00);" - "}"); + wheel_shader->set_code(R"( +shader_type canvas_item; + +void fragment() { + float x = UV.x - 0.5; + float y = UV.y - 0.5; + float a = atan(y, x); + x += 0.001; + y += 0.001; + float b = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42); + x -= 0.002; + float b2 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42); + y -= 0.002; + float b3 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42); + x += 0.002; + float b4 = float(sqrt(x * x + y * y) < 0.5) * float(sqrt(x * x + y * y) > 0.42); + + COLOR = vec4(clamp((abs(fract(((a - TAU) / TAU) + vec3(3.0, 2.0, 1.0) / 3.0) * 6.0 - 3.0) - 1.0), 0.0, 1.0), (b + b2 + b3 + b4) / 4.00); +} +)"); circle_shader.instantiate(); - circle_shader->set_code( - "shader_type canvas_item;" - "uniform float v = 1.0;" - "void fragment() {" - " float x = UV.x - 0.5;" - " float y = UV.y - 0.5;" - " float a = atan(y, x);" - " x += 0.001;" - " y += 0.001;" - " float b = float(sqrt(x * x + y * y) < 0.5);" - " x -= 0.002;" - " float b2 = float(sqrt(x * x + y * y) < 0.5);" - " y -= 0.002;" - " float b3 = float(sqrt(x * x + y * y) < 0.5);" - " x += 0.002;" - " float b4 = float(sqrt(x * x + y * y) < 0.5);" - " COLOR = vec4(mix(vec3(1.0), clamp(abs(fract(vec3((a - TAU) / TAU) + vec3(1.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - vec3(3.0)) - vec3(1.0), 0.0, 1.0), ((float(sqrt(x * x + y * y)) * 2.0)) / 1.0) * vec3(v), (b + b2 + b3 + b4) / 4.00);" - "}"); + circle_shader->set_code(R"( +shader_type canvas_item; + +uniform float v = 1.0; + +void fragment() { + float x = UV.x - 0.5; + float y = UV.y - 0.5; + float a = atan(y, x); + x += 0.001; + y += 0.001; + float b = float(sqrt(x * x + y * y) < 0.5); + x -= 0.002; + float b2 = float(sqrt(x * x + y * y) < 0.5); + y -= 0.002; + float b3 = float(sqrt(x * x + y * y) < 0.5); + x += 0.002; + float b4 = float(sqrt(x * x + y * y) < 0.5); + + COLOR = vec4(mix(vec3(1.0), clamp(abs(fract(vec3((a - TAU) / TAU) + vec3(1.0, 2.0 / 3.0, 1.0 / 3.0)) * 6.0 - vec3(3.0)) - vec3(1.0), 0.0, 1.0), ((float(sqrt(x * x + y * y)) * 2.0)) / 1.0) * vec3(v), (b + b2 + b3 + b4) / 4.00); +})"); } void ColorPicker::finish_shaders() { @@ -142,7 +148,7 @@ void ColorPicker::finish_shaders() { } void ColorPicker::set_focus_on_line_edit() { - c_text->call_deferred("grab_focus"); + c_text->call_deferred(SNAME("grab_focus")); } void ColorPicker::_update_controls() { @@ -180,7 +186,7 @@ void ColorPicker::_update_controls() { } } else { Ref<StyleBoxEmpty> style_box_empty(memnew(StyleBoxEmpty)); - Ref<Texture2D> bar_arrow = get_theme_icon("bar_arrow"); + Ref<Texture2D> bar_arrow = get_theme_icon(SNAME("bar_arrow")); for (int i = 0; i < 4; i++) { scroll[i]->add_theme_icon_override("grabber", bar_arrow); @@ -294,7 +300,7 @@ void ColorPicker::_value_changed(double) { } _set_pick_color(color, false); - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } void ColorPicker::_html_submitted(const String &p_html) { @@ -313,7 +319,7 @@ void ColorPicker::_html_submitted(const String &p_html) { } set_pick_color(color); - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } void ColorPicker::_update_color(bool p_update_sliders) { @@ -388,7 +394,7 @@ void ColorPicker::_text_type_toggled() { text_is_constructor = !text_is_constructor; if (text_is_constructor) { text_type->set_text(""); - text_type->set_icon(get_theme_icon("Script", "EditorIcons")); + text_type->set_icon(get_theme_icon(SNAME("Script"), SNAME("EditorIcons"))); c_text->set_editable(false); } else { @@ -537,7 +543,7 @@ void ColorPicker::_sample_input(const Ref<InputEvent> &p_event) { // Revert to the old color when left-clicking the old color sample. color = old_color; _update_color(); - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } } } @@ -554,28 +560,28 @@ void ColorPicker::_sample_draw() { const Rect2 rect_old = Rect2(Point2(), Size2(sample->get_size().width * 0.5, sample->get_size().height * 0.95)); if (display_old_color && old_color.a < 1.0) { - sample->draw_texture_rect(get_theme_icon("preset_bg", "ColorPicker"), rect_old, true); + sample->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), rect_old, true); } sample->draw_rect(rect_old, old_color); if (old_color.r > 1 || old_color.g > 1 || old_color.b > 1) { // Draw an indicator to denote that the old color is "overbright" and can't be displayed accurately in the preview. - sample->draw_texture(get_theme_icon("overbright_indicator", "ColorPicker"), Point2()); + sample->draw_texture(get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPicker")), Point2()); } } else { rect_new = Rect2(Point2(), Size2(sample->get_size().width, sample->get_size().height * 0.95)); } if (color.a < 1.0) { - sample->draw_texture_rect(get_theme_icon("preset_bg", "ColorPicker"), rect_new, true); + sample->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), rect_new, true); } sample->draw_rect(rect_new, color); if (color.r > 1 || color.g > 1 || color.b > 1) { // Draw an indicator to denote that the new color is "overbright" and can't be displayed accurately in the preview. - sample->draw_texture(get_theme_icon("overbright_indicator", "ColorPicker"), Point2(uv_edit->get_size().width * 0.5, 0)); + sample->draw_texture(get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPicker")), Point2(uv_edit->get_size().width * 0.5, 0)); } } @@ -649,7 +655,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) { default: { } } - Ref<Texture2D> cursor = get_theme_icon("picker_cursor", "ColorPicker"); + Ref<Texture2D> cursor = get_theme_icon(SNAME("picker_cursor"), SNAME("ColorPicker")); int x; int y; if (picker_type == SHAPE_VHS_CIRCLE) { @@ -679,7 +685,7 @@ void ColorPicker::_hsv_draw(int p_which, Control *c) { } else if (p_which == 1) { if (picker_type == SHAPE_HSV_RECTANGLE) { - Ref<Texture2D> hue = get_theme_icon("color_hue", "ColorPicker"); + Ref<Texture2D> hue = get_theme_icon(SNAME("color_hue"), SNAME("ColorPicker")); c->draw_texture_rect(hue, Rect2(Point2(), c->get_size())); int y = c->get_size().y - c->get_size().y * (1.0 - h); Color col; @@ -728,7 +734,7 @@ void ColorPicker::_slider_draw(int p_which) { #endif if (p_which == 3) { - scroll[p_which]->draw_texture_rect(get_theme_icon("preset_bg", "ColorPicker"), Rect2(Point2(0, margin), Size2(size.x, margin)), true); + scroll[p_which]->draw_texture_rect(get_theme_icon(SNAME("preset_bg"), SNAME("ColorPicker")), Rect2(Point2(0, margin), Size2(size.x, margin)), true); left_color = color; left_color.a = 0; @@ -740,7 +746,7 @@ void ColorPicker::_slider_draw(int p_which) { } if (hsv_mode_enabled) { if (p_which == 0) { - Ref<Texture2D> hue = get_theme_icon("color_hue", "ColorPicker"); + Ref<Texture2D> hue = get_theme_icon(SNAME("color_hue"), SNAME("ColorPicker")); scroll[p_which]->draw_set_transform(Point2(), -Math_PI / 2, Size2(1.0, 1.0)); scroll[p_which]->draw_texture_rect(hue, Rect2(Vector2(margin * -2, 0), Vector2(scroll[p_which]->get_size().x, margin)), false, Color(1, 1, 1), true); return; @@ -826,10 +832,10 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) { set_pick_color(color); _update_color(); if (!deferred_mode_enabled) { - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } } else if (deferred_mode_enabled && !bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_LEFT) { - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); changing_color = false; spinning = false; } else { @@ -873,7 +879,7 @@ void ColorPicker::_uv_input(const Ref<InputEvent> &p_event, Control *c) { set_pick_color(color); _update_color(); if (!deferred_mode_enabled) { - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } } } @@ -898,9 +904,9 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) { set_pick_color(color); _update_color(); if (!deferred_mode_enabled) { - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } else if (!bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_LEFT) { - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } } @@ -921,7 +927,7 @@ void ColorPicker::_w_input(const Ref<InputEvent> &p_event) { set_pick_color(color); _update_color(); if (!deferred_mode_enabled) { - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } } } @@ -941,12 +947,12 @@ void ColorPicker::_preset_input(const Ref<InputEvent> &p_event) { } set_pick_color(presets[index]); _update_color(); - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } else if (bev->is_pressed() && bev->get_button_index() == MOUSE_BUTTON_RIGHT && presets_enabled) { index = bev->get_position().x / (preset->get_size().x / presets.size()); Color clicked_preset = presets[index]; erase_preset(clicked_preset); - emit_signal("preset_removed", clicked_preset); + emit_signal(SNAME("preset_removed"), clicked_preset); bt_add_preset->show(); } } @@ -972,7 +978,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) { Ref<InputEventMouseButton> bev = p_event; if (bev.is_valid() && bev->get_button_index() == MOUSE_BUTTON_LEFT && !bev->is_pressed()) { - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); screen->hide(); } @@ -995,7 +1001,7 @@ void ColorPicker::_screen_input(const Ref<InputEvent> &p_event) { void ColorPicker::_add_preset_pressed() { add_preset(color); - emit_signal("preset_added", color); + emit_signal(SNAME("preset_added"), color); } void ColorPicker::_screen_pick_pressed() { @@ -1012,7 +1018,7 @@ void ColorPicker::_screen_pick_pressed() { screen->set_default_cursor_shape(CURSOR_POINTING_HAND); screen->connect("gui_input", callable_mp(this, &ColorPicker::_screen_input)); // It immediately toggles off in the first press otherwise. - screen->call_deferred("connect", "hidden", Callable(btn_pick, "set_pressed"), varray(false)); + screen->call_deferred(SNAME("connect"), "hidden", Callable(btn_pick, "set_pressed"), varray(false)); } screen->raise(); #ifndef _MSC_VER @@ -1131,7 +1137,7 @@ ColorPicker::ColorPicker() : uv_edit->set_mouse_filter(MOUSE_FILTER_PASS); uv_edit->set_h_size_flags(SIZE_EXPAND_FILL); uv_edit->set_v_size_flags(SIZE_EXPAND_FILL); - uv_edit->set_custom_minimum_size(Size2(get_theme_constant("sv_width"), get_theme_constant("sv_height"))); + uv_edit->set_custom_minimum_size(Size2(get_theme_constant(SNAME("sv_width")), get_theme_constant(SNAME("sv_height")))); uv_edit->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw), make_binds(0, uv_edit)); HBoxContainer *hb_smpl = memnew(HBoxContainer); @@ -1161,7 +1167,7 @@ ColorPicker::ColorPicker() : HBoxContainer *hbc = memnew(HBoxContainer); labels[i] = memnew(Label()); - labels[i]->set_custom_minimum_size(Size2(get_theme_constant("label_width"), 0)); + labels[i]->set_custom_minimum_size(Size2(get_theme_constant(SNAME("label_width")), 0)); labels[i]->set_v_size_flags(SIZE_SHRINK_CENTER); hbc->add_child(labels[i]); @@ -1220,7 +1226,7 @@ ColorPicker::ColorPicker() : wheel_edit->set_h_size_flags(SIZE_EXPAND_FILL); wheel_edit->set_v_size_flags(SIZE_EXPAND_FILL); - wheel_edit->set_custom_minimum_size(Size2(get_theme_constant("sv_width"), get_theme_constant("sv_height"))); + wheel_edit->set_custom_minimum_size(Size2(get_theme_constant(SNAME("sv_width")), get_theme_constant(SNAME("sv_height")))); hb_edit->add_child(wheel_edit); wheel_mat.instantiate(); @@ -1245,7 +1251,7 @@ ColorPicker::ColorPicker() : wheel_uv->connect("draw", callable_mp(this, &ColorPicker::_hsv_draw), make_binds(0, wheel_uv)); hb_edit->add_child(w_edit); - w_edit->set_custom_minimum_size(Size2(get_theme_constant("h_width"), 0)); + w_edit->set_custom_minimum_size(Size2(get_theme_constant(SNAME("h_width")), 0)); w_edit->set_h_size_flags(SIZE_FILL); w_edit->set_v_size_flags(SIZE_EXPAND_FILL); w_edit->connect("gui_input", callable_mp(this, &ColorPicker::_w_input)); @@ -1285,11 +1291,11 @@ void ColorPickerButton::_about_to_popup() { void ColorPickerButton::_color_changed(const Color &p_color) { color = p_color; update(); - emit_signal("color_changed", color); + emit_signal(SNAME("color_changed"), color); } void ColorPickerButton::_modal_closed() { - emit_signal("popup_closed"); + emit_signal(SNAME("popup_closed")); set_pressed(false); } @@ -1327,14 +1333,14 @@ void ColorPickerButton::pressed() { void ColorPickerButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - const Ref<StyleBox> normal = get_theme_stylebox("normal"); + const Ref<StyleBox> normal = get_theme_stylebox(SNAME("normal")); const Rect2 r = Rect2(normal->get_offset(), get_size() - normal->get_minimum_size()); - draw_texture_rect(Control::get_theme_icon("bg", "ColorPickerButton"), r, true); + draw_texture_rect(Control::get_theme_icon(SNAME("bg"), SNAME("ColorPickerButton")), r, true); draw_rect(r, color); if (color.r > 1 || color.g > 1 || color.b > 1) { // Draw an indicator to denote that the color is "overbright" and can't be displayed accurately in the preview - draw_texture(Control::get_theme_icon("overbright_indicator", "ColorPicker"), normal->get_offset()); + draw_texture(Control::get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPicker")), normal->get_offset()); } } break; case NOTIFICATION_WM_CLOSE_REQUEST: { @@ -1399,7 +1405,7 @@ void ColorPickerButton::_update_picker() { picker->set_pick_color(color); picker->set_edit_alpha(edit_alpha); picker->set_display_old_color(true); - emit_signal("picker_created"); + emit_signal(SNAME("picker_created")); } } diff --git a/scene/gui/dialogs.cpp b/scene/gui/dialogs.cpp index 9d0a6a3380..f5c764e9cc 100644 --- a/scene/gui/dialogs.cpp +++ b/scene/gui/dialogs.cpp @@ -76,7 +76,7 @@ void AcceptDialog::_notification(int p_what) { } break; case NOTIFICATION_THEME_CHANGED: { - bg->add_theme_style_override("panel", bg->get_theme_stylebox("panel", "AcceptDialog")); + bg->add_theme_style_override("panel", bg->get_theme_stylebox(SNAME("panel"), SNAME("AcceptDialog"))); } break; case NOTIFICATION_EXIT_TREE: { @@ -106,7 +106,7 @@ void AcceptDialog::_ok_pressed() { set_visible(false); } ok_pressed(); - emit_signal("confirmed"); + emit_signal(SNAME("confirmed")); } void AcceptDialog::_cancel_pressed() { @@ -116,9 +116,9 @@ void AcceptDialog::_cancel_pressed() { parent_visible = nullptr; } - call_deferred("hide"); + call_deferred(SNAME("hide")); - emit_signal("cancelled"); + emit_signal(SNAME("cancelled")); cancel_pressed(); @@ -168,7 +168,7 @@ void AcceptDialog::_update_child_rects() { if (label->get_text().is_empty()) { label_size.height = 0; } - int margin = hbc->get_theme_constant("margin", "Dialogs"); + int margin = hbc->get_theme_constant(SNAME("margin"), SNAME("Dialogs")); Size2 size = get_size(); Size2 hminsize = hbc->get_combined_minimum_size(); @@ -200,7 +200,7 @@ void AcceptDialog::_update_child_rects() { } Size2 AcceptDialog::_get_contents_minimum_size() const { - int margin = hbc->get_theme_constant("margin", "Dialogs"); + int margin = hbc->get_theme_constant(SNAME("margin"), SNAME("Dialogs")); Size2 minsize = label->get_combined_minimum_size(); for (int i = 0; i < get_child_count(); i++) { @@ -230,7 +230,7 @@ Size2 AcceptDialog::_get_contents_minimum_size() const { } void AcceptDialog::_custom_action(const String &p_action) { - emit_signal("custom_action", p_action); + emit_signal(SNAME("custom_action"), p_action); custom_action(p_action); } @@ -326,8 +326,8 @@ AcceptDialog::AcceptDialog() { hbc = memnew(HBoxContainer); - int margin = hbc->get_theme_constant("margin", "Dialogs"); - int button_margin = hbc->get_theme_constant("button_margin", "Dialogs"); + int margin = hbc->get_theme_constant(SNAME("margin"), SNAME("Dialogs")); + int button_margin = hbc->get_theme_constant(SNAME("button_margin"), SNAME("Dialogs")); label = memnew(Label); label->set_anchor(SIDE_RIGHT, Control::ANCHOR_END); diff --git a/scene/gui/file_dialog.cpp b/scene/gui/file_dialog.cpp index f8cee6daec..9ed3a2244e 100644 --- a/scene/gui/file_dialog.cpp +++ b/scene/gui/file_dialog.cpp @@ -49,9 +49,9 @@ VBoxContainer *FileDialog::get_vbox() { } void FileDialog::_theme_changed() { - Color font_color = vbox->get_theme_color("font_color", "Button"); - Color font_hover_color = vbox->get_theme_color("font_hover_color", "Button"); - Color font_pressed_color = vbox->get_theme_color("font_pressed_color", "Button"); + Color font_color = vbox->get_theme_color(SNAME("font_color"), SNAME("Button")); + Color font_hover_color = vbox->get_theme_color(SNAME("font_hover_color"), SNAME("Button")); + Color font_pressed_color = vbox->get_theme_color(SNAME("font_pressed_color"), SNAME("Button")); dir_up->add_theme_color_override("icon_normal_color", font_color); dir_up->add_theme_color_override("icon_hover_color", font_hover_color); @@ -81,16 +81,16 @@ void FileDialog::_notification(int p_what) { } } if (p_what == NOTIFICATION_ENTER_TREE) { - dir_up->set_icon(vbox->get_theme_icon("parent_folder", "FileDialog")); + 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("forward_folder", "FileDialog")); - dir_next->set_icon(vbox->get_theme_icon("back_folder", "FileDialog")); + 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("back_folder", "FileDialog")); - dir_next->set_icon(vbox->get_theme_icon("forward_folder", "FileDialog")); + 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("reload", "FileDialog")); - show_hidden->set_icon(vbox->get_theme_icon("toggle_hidden", "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(); } } @@ -170,7 +170,7 @@ void FileDialog::_file_submitted(const String &p_file) { void FileDialog::_save_confirm_pressed() { String f = dir_access->get_current_dir().plus_file(file->get_text()); - emit_signal("file_selected", f); + emit_signal(SNAME("file_selected"), f); hide(); } @@ -224,7 +224,7 @@ void FileDialog::_action_pressed() { } if (files.size()) { - emit_signal("files_selected", files); + emit_signal(SNAME("files_selected"), files); hide(); } @@ -234,7 +234,7 @@ void FileDialog::_action_pressed() { String f = dir_access->get_current_dir().plus_file(file->get_text()); if ((mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_FILE) && dir_access->file_exists(f)) { - emit_signal("file_selected", f); + emit_signal(SNAME("file_selected"), f); hide(); } else if (mode == FILE_MODE_OPEN_ANY || mode == FILE_MODE_OPEN_DIR) { String path = dir_access->get_current_dir(); @@ -248,7 +248,7 @@ void FileDialog::_action_pressed() { } } - emit_signal("dir_selected", path); + emit_signal(SNAME("dir_selected"), path); hide(); } @@ -308,7 +308,7 @@ void FileDialog::_action_pressed() { confirm_save->set_text(TTRC("File exists, overwrite?")); confirm_save->popup_centered(Size2(200, 80)); } else { - emit_signal("file_selected", f); + emit_signal(SNAME("file_selected"), f); hide(); } } @@ -437,8 +437,8 @@ void FileDialog::_tree_item_activated() { if (mode == FILE_MODE_OPEN_FILE || mode == FILE_MODE_OPEN_FILES || mode == FILE_MODE_OPEN_DIR || mode == FILE_MODE_OPEN_ANY) { file->set_text(""); } - call_deferred("_update_file_list"); - call_deferred("_update_dir"); + call_deferred(SNAME("_update_file_list")); + call_deferred(SNAME("_update_dir")); _push_history(); } else { _action_pressed(); @@ -468,10 +468,10 @@ void FileDialog::update_file_list() { dir_access->list_dir_begin(); TreeItem *root = tree->create_item(); - Ref<Texture2D> folder = vbox->get_theme_icon("folder", "FileDialog"); - Ref<Texture2D> file_icon = vbox->get_theme_icon("file", "FileDialog"); - const Color folder_color = vbox->get_theme_color("folder_icon_modulate", "FileDialog"); - const Color file_color = vbox->get_theme_color("file_icon_modulate", "FileDialog"); + Ref<Texture2D> folder = vbox->get_theme_icon(SNAME("folder"), SNAME("FileDialog")); + Ref<Texture2D> file_icon = vbox->get_theme_icon(SNAME("file"), SNAME("FileDialog")); + const Color folder_color = vbox->get_theme_color(SNAME("folder_icon_modulate"), SNAME("FileDialog")); + const Color file_color = vbox->get_theme_color(SNAME("file_icon_modulate"), SNAME("FileDialog")); List<String> files; List<String> dirs; @@ -573,7 +573,7 @@ void FileDialog::update_file_list() { ti->set_icon_modulate(0, file_color); if (mode == FILE_MODE_OPEN_DIR) { - ti->set_custom_color(0, vbox->get_theme_color("files_disabled", "FileDialog")); + ti->set_custom_color(0, vbox->get_theme_color(SNAME("files_disabled"), SNAME("FileDialog"))); ti->set_selectable(0, false); } Dictionary d; diff --git a/scene/gui/gradient_edit.cpp b/scene/gui/gradient_edit.cpp index 7278ca6e94..83ecf1d534 100644 --- a/scene/gui/gradient_edit.cpp +++ b/scene/gui/gradient_edit.cpp @@ -101,7 +101,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { grabbed = -1; grabbing = false; update(); - emit_signal("ramp_changed"); + emit_signal(SNAME("ramp_changed")); accept_event(); } @@ -121,7 +121,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { grabbed = -1; grabbing = false; update(); - emit_signal("ramp_changed"); + emit_signal(SNAME("ramp_changed")); accept_event(); } } @@ -145,7 +145,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { } } - emit_signal("ramp_changed"); + emit_signal(SNAME("ramp_changed")); update(); } } @@ -214,13 +214,13 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { } } - emit_signal("ramp_changed"); + emit_signal(SNAME("ramp_changed")); } if (mb.is_valid() && mb->get_button_index() == 1 && !mb->is_pressed()) { if (grabbing) { grabbing = false; - emit_signal("ramp_changed"); + emit_signal(SNAME("ramp_changed")); } update(); } @@ -288,7 +288,7 @@ void GradientEdit::_gui_input(const Ref<InputEvent> &p_event) { } } - emit_signal("ramp_changed"); + emit_signal(SNAME("ramp_changed")); update(); } @@ -436,7 +436,7 @@ void GradientEdit::_color_changed(const Color &p_color) { } points.write[grabbed].color = p_color; update(); - emit_signal("ramp_changed"); + emit_signal(SNAME("ramp_changed")); } void GradientEdit::set_ramp(const Vector<float> &p_offsets, const Vector<Color> &p_colors) { diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 39aa6749e7..2281fb19c6 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -162,7 +162,7 @@ void GraphEditMinimap::_gui_input(const Ref<InputEvent> &p_ev) { if (mb->is_pressed()) { is_pressing = true; - Ref<Texture2D> resizer = get_theme_icon("resizer"); + Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer")); Rect2 resizer_hitbox = Rect2(Point2(), resizer->get_size()); if (resizer_hitbox.has_point(mb->get_position())) { is_resizing = true; @@ -257,7 +257,7 @@ Vector2 GraphEdit::get_scroll_ofs() const { void GraphEdit::_scroll_moved(double) { if (!awaiting_scroll_offset_update) { - call_deferred("_update_scroll_offset"); + call_deferred(SNAME("_update_scroll_offset")); awaiting_scroll_offset_update = true; } top_layer->update(); @@ -265,7 +265,7 @@ void GraphEdit::_scroll_moved(double) { update(); if (!setting_scroll_ofs) { //in godot, signals on change value are avoided as a convention - emit_signal("scroll_offset_changed", get_scroll_ofs()); + emit_signal(SNAME("scroll_offset_changed"), get_scroll_ofs()); } } @@ -345,7 +345,7 @@ void GraphEdit::_update_scroll() { set_block_minimum_size_adjust(false); if (!awaiting_scroll_offset_update) { - call_deferred("_update_scroll_offset"); + call_deferred(SNAME("_update_scroll_offset")); awaiting_scroll_offset_update = true; } @@ -371,7 +371,7 @@ void GraphEdit::_graph_node_raised(Node *p_gn) { move_child(connections_layer, first_not_comment); top_layer->raise(); - emit_signal("node_selected", p_gn); + emit_signal(SNAME("node_selected"), p_gn); } void GraphEdit::_graph_node_moved(Node *p_gn) { @@ -395,7 +395,7 @@ void GraphEdit::_graph_node_slot_updated(int p_index, Node *p_gn) { void GraphEdit::add_child_notify(Node *p_child) { Control::add_child_notify(p_child); - top_layer->call_deferred("raise"); // Top layer always on top! + top_layer->call_deferred(SNAME("raise")); // Top layer always on top! GraphNode *gn = Object::cast_to<GraphNode>(p_child); if (gn) { @@ -421,7 +421,7 @@ void GraphEdit::remove_child_notify(Node *p_child) { } if (top_layer != nullptr && is_inside_tree()) { - top_layer->call_deferred("raise"); // Top layer always on top! + top_layer->call_deferred(SNAME("raise")); // Top layer always on top! } GraphNode *gn = Object::cast_to<GraphNode>(p_child); @@ -442,14 +442,14 @@ 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("port_grab_distance_horizontal"); - port_grab_distance_vertical = get_theme_constant("port_grab_distance_vertical"); - - zoom_minus->set_icon(get_theme_icon("minus")); - zoom_reset->set_icon(get_theme_icon("reset")); - zoom_plus->set_icon(get_theme_icon("more")); - snap_button->set_icon(get_theme_icon("snap")); - minimap_button->set_icon(get_theme_icon("minimap")); + 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"))); } if (p_what == NOTIFICATION_READY) { Size2 hmin = h_scroll->get_combined_minimum_size(); @@ -466,7 +466,7 @@ void GraphEdit::_notification(int p_what) { v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0); } if (p_what == NOTIFICATION_DRAW) { - draw_style_box(get_theme_stylebox("bg"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox(SNAME("bg")), Rect2(Point2(), get_size())); if (is_using_snap()) { //draw grid @@ -479,8 +479,8 @@ void GraphEdit::_notification(int p_what) { Point2i from = (offset / float(snap)).floor(); Point2i len = (size / float(snap)).floor() + Vector2(1, 1); - Color grid_minor = get_theme_color("grid_minor"); - Color grid_major = get_theme_color("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; @@ -518,7 +518,7 @@ void GraphEdit::_notification(int p_what) { } bool GraphEdit::_filter_input(const Point2 &p_point) { - Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode")); for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); @@ -548,7 +548,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { Ref<InputEventMouseButton> mb = p_ev; if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_LEFT && mb->is_pressed()) { connecting_valid = false; - Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode")); click_pos = mb->get_position() / zoom; for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); @@ -574,7 +574,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { connecting_to = pos; just_disconnected = true; - emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port); + emit_signal(SNAME("disconnection_request"), E->get().from, E->get().from_port, E->get().to, E->get().to_port); to = get_node(String(connecting_from)); //maybe it was erased if (Object::cast_to<GraphNode>(to)) { connecting = true; @@ -616,7 +616,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { connecting_to = pos; just_disconnected = true; - emit_signal("disconnection_request", E->get().from, E->get().from_port, E->get().to, E->get().to_port); + emit_signal(SNAME("disconnection_request"), E->get().from, E->get().from_port, E->get().to, E->get().to_port); fr = get_node(String(connecting_from)); //maybe it was erased if (Object::cast_to<GraphNode>(fr)) { connecting = true; @@ -652,7 +652,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { connecting_valid = just_disconnected || click_pos.distance_to(connecting_to / zoom) > 20.0 * zoom; if (connecting_valid) { - Ref<Texture2D> port = get_theme_icon("port", "GraphNode"); + Ref<Texture2D> port = get_theme_icon(SNAME("port"), SNAME("GraphNode")); Vector2 mpos = mm->get_position() / zoom; for (int i = get_child_count() - 1; i >= 0; i--) { GraphNode *gn = Object::cast_to<GraphNode>(get_child(i)); @@ -701,7 +701,7 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { SWAP(from, to); SWAP(from_slot, to_slot); } - emit_signal("connection_request", from, from_slot, to, to_slot); + emit_signal(SNAME("connection_request"), from, from_slot, to, to_slot); } else if (!just_disconnected) { String from = connecting_from; @@ -709,9 +709,9 @@ void GraphEdit::_top_layer_input(const Ref<InputEvent> &p_ev) { Vector2 ofs = Vector2(mb->get_position().x, mb->get_position().y); if (!connecting_out) { - emit_signal("connection_from_empty", from, from_slot, ofs); + emit_signal(SNAME("connection_from_empty"), from, from_slot, ofs); } else { - emit_signal("connection_to_empty", from, from_slot, ofs); + emit_signal(SNAME("connection_to_empty"), from, from_slot, ofs); } } } @@ -819,8 +819,8 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const //cubic bezier code float diff = p_to.x - p_from.x; float cp_offset; - int cp_len = get_theme_constant("bezier_len_pos") * p_bezier_ratio; - int cp_neg_len = get_theme_constant("bezier_len_neg") * p_bezier_ratio; + int cp_len = get_theme_constant(SNAME("bezier_len_pos")) * p_bezier_ratio; + int cp_neg_len = get_theme_constant(SNAME("bezier_len_neg")) * p_bezier_ratio; if (diff > 0) { cp_offset = MIN(cp_len, diff * 0.5); @@ -849,7 +849,7 @@ void GraphEdit::_draw_cos_line(CanvasItem *p_where, const Vector2 &p_from, const } void GraphEdit::_connections_layer_draw() { - Color activity_color = get_theme_color("activity"); + Color activity_color = get_theme_color(SNAME("activity")); //draw connections List<List<Connection>::Element *> to_erase; for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { @@ -934,8 +934,8 @@ void GraphEdit::_top_layer_draw() { } if (box_selecting) { - top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_fill")); - top_layer->draw_rect(box_selecting_rect, get_theme_color("selection_stroke"), false); + top_layer->draw_rect(box_selecting_rect, get_theme_color(SNAME("selection_fill"))); + top_layer->draw_rect(box_selecting_rect, get_theme_color(SNAME("selection_stroke")), false); } } @@ -948,7 +948,7 @@ void GraphEdit::_minimap_draw() { // Draw the minimap background. Rect2 minimap_rect = Rect2(Point2(), minimap->get_size()); - minimap->draw_style_box(minimap->get_theme_stylebox("bg"), minimap_rect); + minimap->draw_style_box(minimap->get_theme_stylebox(SNAME("bg")), minimap_rect); Vector2 graph_offset = minimap->_get_graph_offset(); Vector2 minimap_offset = minimap->minimap_offset; @@ -964,7 +964,7 @@ void GraphEdit::_minimap_draw() { Vector2 node_size = minimap->_convert_from_graph_position(gn->get_size() * zoom); Rect2 node_rect = Rect2(node_position, node_size); - Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox("node")->duplicate(); + Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox(SNAME("node"))->duplicate(); // Override default values with colors provided by the GraphNode's stylebox, if possible. Ref<StyleBoxFlat> sbf = gn->get_theme_stylebox(gn->is_selected() ? "commentfocus" : "comment"); @@ -987,7 +987,7 @@ void GraphEdit::_minimap_draw() { Vector2 node_size = minimap->_convert_from_graph_position(gn->get_size() * zoom); Rect2 node_rect = Rect2(node_position, node_size); - Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox("node")->duplicate(); + Ref<StyleBoxFlat> sb_minimap = minimap->get_theme_stylebox(SNAME("node"))->duplicate(); // Override default values with colors provided by the GraphNode's stylebox, if possible. Ref<StyleBoxFlat> sbf = gn->get_theme_stylebox(gn->is_selected() ? "selectedframe" : "frame"); @@ -1000,7 +1000,7 @@ void GraphEdit::_minimap_draw() { } // Draw node connections. - Color activity_color = get_theme_color("activity"); + Color activity_color = get_theme_color(SNAME("activity")); for (List<Connection>::Element *E = connections.front(); E; E = E->next()) { NodePath fromnp(E->get().from); @@ -1039,11 +1039,11 @@ void GraphEdit::_minimap_draw() { // Draw the "camera" viewport. Rect2 camera_rect = minimap->get_camera_rect(); - minimap->draw_style_box(minimap->get_theme_stylebox("camera"), camera_rect); + minimap->draw_style_box(minimap->get_theme_stylebox(SNAME("camera")), camera_rect); // Draw the resizer control. - Ref<Texture2D> resizer = minimap->get_theme_icon("resizer"); - Color resizer_color = minimap->get_theme_color("resizer_color"); + Ref<Texture2D> resizer = minimap->get_theme_icon(SNAME("resizer")); + Color resizer_color = minimap->get_theme_color(SNAME("resizer_color")); minimap->draw_texture(resizer, Point2(), resizer_color); } @@ -1070,7 +1070,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { if (mm.is_valid() && dragging) { if (!moving_selection) { - emit_signal("begin_node_move"); + emit_signal(SNAME("begin_node_move")); moving_selection = true; } @@ -1113,17 +1113,17 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { if (in_box) { if (!gn->is_selected() && box_selection_mode_additive) { - emit_signal("node_selected", gn); + emit_signal(SNAME("node_selected"), gn); } else if (gn->is_selected() && !box_selection_mode_additive) { - emit_signal("node_deselected", gn); + emit_signal(SNAME("node_deselected"), gn); } gn->set_selected(box_selection_mode_additive); } else { bool select = (previous_selected.find(gn) != nullptr); if (gn->is_selected() && !select) { - emit_signal("node_deselected", gn); + emit_signal(SNAME("node_deselected"), gn); } else if (!gn->is_selected() && select) { - emit_signal("node_selected", gn); + emit_signal(SNAME("node_selected"), gn); } gn->set_selected(select); } @@ -1146,9 +1146,9 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { bool select = (previous_selected.find(gn) != nullptr); if (gn->is_selected() && !select) { - emit_signal("node_deselected", gn); + emit_signal(SNAME("node_deselected"), gn); } else if (!gn->is_selected() && select) { - emit_signal("node_selected", gn); + emit_signal(SNAME("node_selected"), gn); } gn->set_selected(select); } @@ -1160,7 +1160,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { top_layer->update(); minimap->update(); } else { - emit_signal("popup_request", b->get_global_position()); + emit_signal(SNAME("popup_request"), b->get_global_position()); } } } @@ -1175,7 +1175,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { Rect2 r = gn->get_rect(); r.size *= zoom; if (r.has_point(b->get_position())) { - emit_signal("node_deselected", gn); + emit_signal(SNAME("node_deselected"), gn); gn->set_selected(false); } } @@ -1192,7 +1192,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { } if (moving_selection) { - emit_signal("end_node_move"); + emit_signal(SNAME("end_node_move")); moving_selection = false; } @@ -1238,7 +1238,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { o_gn->set_selected(true); } else { if (o_gn->is_selected()) { - emit_signal("node_deselected", o_gn); + emit_signal(SNAME("node_deselected"), o_gn); } o_gn->set_selected(false); } @@ -1298,7 +1298,7 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { continue; } if (gn2->is_selected()) { - emit_signal("node_deselected", gn2); + emit_signal(SNAME("node_deselected"), gn2); } gn2->set_selected(false); } @@ -1333,16 +1333,16 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { if (p_ev->is_pressed()) { if (p_ev->is_action("ui_graph_duplicate")) { - emit_signal("duplicate_nodes_request"); + emit_signal(SNAME("duplicate_nodes_request")); accept_event(); } else if (p_ev->is_action("ui_copy")) { - emit_signal("copy_nodes_request"); + emit_signal(SNAME("copy_nodes_request")); accept_event(); } else if (p_ev->is_action("ui_paste")) { - emit_signal("paste_nodes_request"); + emit_signal(SNAME("paste_nodes_request")); accept_event(); } else if (p_ev->is_action("ui_graph_delete")) { - emit_signal("delete_nodes_request"); + emit_signal(SNAME("delete_nodes_request")); accept_event(); } } diff --git a/scene/gui/graph_node.cpp b/scene/gui/graph_node.cpp index 836bffdf46..e85cefcb7b 100644 --- a/scene/gui/graph_node.cpp +++ b/scene/gui/graph_node.cpp @@ -180,9 +180,9 @@ void GraphNode::_resort() { /** First pass, determine minimum size AND amount of stretchable elements */ Size2i new_size = get_size(); - Ref<StyleBox> sb = get_theme_stylebox("frame"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame")); - int sep = get_theme_constant("separation"); + int sep = get_theme_constant(SNAME("separation")); bool first = true; int children_count = 0; @@ -323,8 +323,8 @@ void GraphNode::_resort() { bool GraphNode::has_point(const Point2 &p_point) const { if (comment) { - Ref<StyleBox> comment = get_theme_stylebox("comment"); - Ref<Texture2D> resizer = get_theme_icon("resizer"); + Ref<StyleBox> comment = get_theme_stylebox(SNAME("comment")); + Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer")); if (Rect2(get_size() - resizer->get_size(), resizer->get_size()).has_point(p_point)) { return true; @@ -355,18 +355,18 @@ void GraphNode::_notification(int p_what) { //sb=sb->duplicate(); //sb->call("set_modulate",modulate); - Ref<Texture2D> port = get_theme_icon("port"); - Ref<Texture2D> close = get_theme_icon("close"); - Ref<Texture2D> resizer = get_theme_icon("resizer"); - int close_offset = get_theme_constant("close_offset"); - int close_h_offset = get_theme_constant("close_h_offset"); - Color close_color = get_theme_color("close_color"); - Color resizer_color = get_theme_color("resizer_color"); - int title_offset = get_theme_constant("title_offset"); - int title_h_offset = get_theme_constant("title_h_offset"); - Color title_color = get_theme_color("title_color"); + Ref<Texture2D> port = get_theme_icon(SNAME("port")); + Ref<Texture2D> close = get_theme_icon(SNAME("close")); + Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer")); + int close_offset = get_theme_constant(SNAME("close_offset")); + int close_h_offset = get_theme_constant(SNAME("close_h_offset")); + Color close_color = get_theme_color(SNAME("close_color")); + Color resizer_color = get_theme_color(SNAME("resizer_color")); + int title_offset = get_theme_constant(SNAME("title_offset")); + int title_h_offset = get_theme_constant(SNAME("title_h_offset")); + Color title_color = get_theme_color(SNAME("title_color")); Point2i icofs = -port->get_size() * 0.5; - int edgeofs = get_theme_constant("port_offset"); + int edgeofs = get_theme_constant(SNAME("port_offset")); icofs.y += sb->get_margin(SIDE_TOP); draw_style_box(sb, Rect2(Point2(), get_size())); @@ -375,10 +375,10 @@ void GraphNode::_notification(int p_what) { case OVERLAY_DISABLED: { } break; case OVERLAY_BREAKPOINT: { - draw_style_box(get_theme_stylebox("breakpoint"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox(SNAME("breakpoint")), Rect2(Point2(), get_size())); } break; case OVERLAY_POSITION: { - draw_style_box(get_theme_stylebox("position"), Rect2(Point2(), get_size())); + draw_style_box(get_theme_stylebox(SNAME("position")), Rect2(Point2(), get_size())); } break; } @@ -446,8 +446,8 @@ void GraphNode::_notification(int p_what) { } void GraphNode::_shape() { - Ref<Font> font = get_theme_font("title_font"); - int font_size = get_theme_font_size("title_font_size"); + Ref<Font> font = get_theme_font(SNAME("title_font")); + int font_size = get_theme_font_size(SNAME("title_font_size")); title_buf->clear(); if (text_direction == Control::TEXT_DIRECTION_INHERITED) { @@ -481,7 +481,7 @@ void GraphNode::set_slot(int p_idx, bool p_enable_left, int p_type_left, const C update(); connpos_dirty = true; - emit_signal("slot_updated", p_idx); + emit_signal(SNAME("slot_updated"), p_idx); } void GraphNode::clear_slot(int p_idx) { @@ -510,7 +510,7 @@ void GraphNode::set_slot_enabled_left(int p_idx, bool p_enable_left) { update(); connpos_dirty = true; - emit_signal("slot_updated", p_idx); + emit_signal(SNAME("slot_updated"), p_idx); } void GraphNode::set_slot_type_left(int p_idx, int p_type_left) { @@ -520,7 +520,7 @@ void GraphNode::set_slot_type_left(int p_idx, int p_type_left) { update(); connpos_dirty = true; - emit_signal("slot_updated", p_idx); + emit_signal(SNAME("slot_updated"), p_idx); } int GraphNode::get_slot_type_left(int p_idx) const { @@ -537,7 +537,7 @@ void GraphNode::set_slot_color_left(int p_idx, const Color &p_color_left) { update(); connpos_dirty = true; - emit_signal("slot_updated", p_idx); + emit_signal(SNAME("slot_updated"), p_idx); } Color GraphNode::get_slot_color_left(int p_idx) const { @@ -561,7 +561,7 @@ void GraphNode::set_slot_enabled_right(int p_idx, bool p_enable_right) { update(); connpos_dirty = true; - emit_signal("slot_updated", p_idx); + emit_signal(SNAME("slot_updated"), p_idx); } void GraphNode::set_slot_type_right(int p_idx, int p_type_right) { @@ -571,7 +571,7 @@ void GraphNode::set_slot_type_right(int p_idx, int p_type_right) { update(); connpos_dirty = true; - emit_signal("slot_updated", p_idx); + emit_signal(SNAME("slot_updated"), p_idx); } int GraphNode::get_slot_type_right(int p_idx) const { @@ -588,7 +588,7 @@ void GraphNode::set_slot_color_right(int p_idx, const Color &p_color_right) { update(); connpos_dirty = true; - emit_signal("slot_updated", p_idx); + emit_signal(SNAME("slot_updated"), p_idx); } Color GraphNode::get_slot_color_right(int p_idx) const { @@ -599,14 +599,14 @@ Color GraphNode::get_slot_color_right(int p_idx) const { } Size2 GraphNode::get_minimum_size() const { - int sep = get_theme_constant("separation"); - Ref<StyleBox> sb = get_theme_stylebox("frame"); + int sep = get_theme_constant(SNAME("separation")); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame")); bool first = true; Size2 minsize; minsize.x = title_buf->get_size().x; if (show_close) { - Ref<Texture2D> close = get_theme_icon("close"); + Ref<Texture2D> close = get_theme_icon(SNAME("close")); minsize.x += sep + close->get_width(); } @@ -699,7 +699,7 @@ String GraphNode::get_language() const { void GraphNode::set_position_offset(const Vector2 &p_offset) { position_offset = p_offset; - emit_signal("position_offset_changed"); + emit_signal(SNAME("position_offset_changed")); update(); } @@ -720,7 +720,7 @@ void GraphNode::set_drag(bool p_drag) { if (p_drag) { drag_from = get_position_offset(); } else { - emit_signal("dragged", drag_from, get_position_offset()); //useful for undo/redo + emit_signal(SNAME("dragged"), drag_from, get_position_offset()); //useful for undo/redo } } @@ -738,10 +738,10 @@ bool GraphNode::is_close_button_visible() const { } void GraphNode::_connpos_update() { - int edgeofs = get_theme_constant("port_offset"); - int sep = get_theme_constant("separation"); + int edgeofs = get_theme_constant(SNAME("port_offset")); + int sep = get_theme_constant(SNAME("separation")); - Ref<StyleBox> sb = get_theme_stylebox("frame"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("frame")); conn_input_cache.clear(); conn_output_cache.clear(); int vofs = 0; @@ -875,12 +875,12 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { if (close_rect.size != Size2() && close_rect.has_point(mpos)) { //send focus to parent get_parent_control()->grab_focus(); - emit_signal("close_request"); + emit_signal(SNAME("close_request")); accept_event(); return; } - Ref<Texture2D> resizer = get_theme_icon("resizer"); + Ref<Texture2D> resizer = get_theme_icon(SNAME("resizer")); if (resizable && mpos.x > get_size().x - resizer->get_width() && mpos.y > get_size().y - resizer->get_height()) { resizing = true; @@ -890,7 +890,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { return; } - emit_signal("raise_request"); + emit_signal(SNAME("raise_request")); } if (!mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) { @@ -904,7 +904,7 @@ void GraphNode::_gui_input(const Ref<InputEvent> &p_ev) { Vector2 diff = mpos - resizing_from; - emit_signal("resize_request", resizing_from_size + diff); + emit_signal(SNAME("resize_request"), resizing_from_size + diff); } } diff --git a/scene/gui/grid_container.cpp b/scene/gui/grid_container.cpp index a54f5eef06..1107e3a4af 100644 --- a/scene/gui/grid_container.cpp +++ b/scene/gui/grid_container.cpp @@ -38,8 +38,8 @@ void GridContainer::_notification(int p_what) { Set<int> col_expanded; // Columns which have the SIZE_EXPAND flag set. Set<int> row_expanded; // Rows which have the SIZE_EXPAND flag set. - int hsep = get_theme_constant("hseparation"); - int vsep = get_theme_constant("vseparation"); + int hsep = get_theme_constant(SNAME("hseparation")); + int vsep = get_theme_constant(SNAME("vseparation")); int max_col = MIN(get_child_count(), columns); int max_row = ceil((float)get_child_count() / (float)columns); @@ -213,8 +213,8 @@ Size2 GridContainer::get_minimum_size() const { Map<int, int> col_minw; Map<int, int> row_minh; - int hsep = get_theme_constant("hseparation"); - int vsep = get_theme_constant("vseparation"); + int hsep = get_theme_constant(SNAME("hseparation")); + int vsep = get_theme_constant(SNAME("vseparation")); int max_row = 0; int max_col = 0; diff --git a/scene/gui/item_list.cpp b/scene/gui/item_list.cpp index b0d54bf8c9..fdf6181f1d 100644 --- a/scene/gui/item_list.cpp +++ b/scene/gui/item_list.cpp @@ -42,7 +42,7 @@ void ItemList::_shape(int p_idx) { } else { item.text_buf->set_direction((TextServer::Direction)item.text_direction); } - item.text_buf->add_string(item.text, get_theme_font("font"), get_theme_font_size("font_size"), item.opentype_features, (item.language != "") ? item.language : TranslationServer::get_singleton()->get_tool_locale()); + item.text_buf->add_string(item.text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), item.opentype_features, (item.language != "") ? item.language : TranslationServer::get_singleton()->get_tool_locale()); if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) { item.text_buf->set_flags(TextServer::BREAK_MANDATORY | TextServer::BREAK_WORD_BOUND | TextServer::BREAK_GRAPHEME_BOUND); } else { @@ -548,7 +548,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (defer_select_single >= 0 && mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_LEFT && !mb->is_pressed()) { select(defer_select_single, true); - emit_signal("multi_selected", defer_select_single, true); + emit_signal(SNAME("multi_selected"), defer_select_single, true); defer_select_single = -1; return; } @@ -556,7 +556,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && (mb->get_button_index() == MOUSE_BUTTON_LEFT || (allow_rmb_select && mb->get_button_index() == MOUSE_BUTTON_RIGHT)) && mb->is_pressed()) { search_string = ""; //any mousepress cancels Vector2 pos = mb->get_position(); - Ref<StyleBox> bg = get_theme_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg")); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); @@ -583,7 +583,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (select_mode == SELECT_MULTI && items[i].selected && mb->is_command_pressed()) { deselect(i); - emit_signal("multi_selected", i, false); + emit_signal(SNAME("multi_selected"), i, false); } else if (select_mode == SELECT_MULTI && mb->is_shift_pressed() && current >= 0 && current < items.size() && current != i) { int from = current; @@ -595,12 +595,12 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { bool selected = !items[j].selected; select(j, false); if (selected) { - emit_signal("multi_selected", j, true); + emit_signal(SNAME("multi_selected"), j, true); } } if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, get_local_mouse_position()); + emit_signal(SNAME("item_rmb_selected"), i, get_local_mouse_position()); } } else { if (!mb->is_double_click() && !mb->is_command_pressed() && select_mode == SELECT_MULTI && items[i].selectable && !items[i].disabled && items[i].selected && mb->get_button_index() == MOUSE_BUTTON_LEFT) { @@ -609,7 +609,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { } if (items[i].selected && mb->get_button_index() == MOUSE_BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, get_local_mouse_position()); + emit_signal(SNAME("item_rmb_selected"), i, get_local_mouse_position()); } else { bool selected = items[i].selected; @@ -617,16 +617,16 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (!selected || allow_reselect) { if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", i); + emit_signal(SNAME("item_selected"), i); } else { - emit_signal("multi_selected", i, true); + emit_signal(SNAME("multi_selected"), i, true); } } if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { - emit_signal("item_rmb_selected", i, get_local_mouse_position()); + emit_signal(SNAME("item_rmb_selected"), i, get_local_mouse_position()); } else if (/*select_mode==SELECT_SINGLE &&*/ mb->is_double_click()) { - emit_signal("item_activated", i); + emit_signal(SNAME("item_activated"), i); } } } @@ -634,13 +634,13 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { return; } if (mb->get_button_index() == MOUSE_BUTTON_RIGHT) { - emit_signal("rmb_clicked", mb->get_position()); + emit_signal(SNAME("rmb_clicked"), mb->get_position()); return; } // Since closest is null, more likely we clicked on empty space, so send signal to interested controls. Allows, for example, implement items deselecting. - emit_signal("nothing_selected"); + emit_signal(SNAME("nothing_selected")); } if (mb.is_valid() && mb->get_button_index() == MOUSE_BUTTON_WHEEL_UP && mb->is_pressed()) { scroll_bar->set_value(scroll_bar->get_value() - scroll_bar->get_page() * mb->get_factor() / 8); @@ -661,7 +661,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(i); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } break; @@ -676,7 +676,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(current - current_columns); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } accept_event(); } @@ -691,7 +691,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(i); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } break; } @@ -705,7 +705,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(current + current_columns); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } accept_event(); } @@ -717,7 +717,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(current - current_columns * i); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } accept_event(); break; @@ -731,7 +731,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(current + current_columns * i); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } accept_event(); @@ -745,7 +745,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(current - 1); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } accept_event(); } @@ -756,7 +756,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(current + 1); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } accept_event(); } @@ -766,17 +766,17 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { if (current >= 0 && current < items.size()) { if (items[current].selectable && !items[current].disabled && !items[current].selected) { select(current, false); - emit_signal("multi_selected", current, true); + emit_signal(SNAME("multi_selected"), current, true); } else if (items[current].selected) { deselect(current); - emit_signal("multi_selected", current, false); + emit_signal(SNAME("multi_selected"), current, false); } } } else if (p_event->is_action("ui_accept")) { search_string = ""; //any mousepress cancels if (current >= 0 && current < items.size()) { - emit_signal("item_activated", current); + emit_signal(SNAME("item_activated"), current); } } else { Ref<InputEventKey> k = p_event; @@ -812,7 +812,7 @@ void ItemList::_gui_input(const Ref<InputEvent> &p_event) { set_current(i); ensure_current_is_visible(); if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } break; } @@ -867,7 +867,7 @@ void ItemList::_notification(int p_what) { } if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> bg = get_theme_stylebox("bg"); + 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); @@ -884,24 +884,24 @@ void ItemList::_notification(int p_what) { draw_style_box(bg, Rect2(Point2(), size)); - int hseparation = get_theme_constant("hseparation"); - int vseparation = get_theme_constant("vseparation"); - int icon_margin = get_theme_constant("icon_margin"); - int line_separation = get_theme_constant("line_separation"); - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("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("selected_focus") : get_theme_stylebox("selected"); - Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox("cursor") : get_theme_stylebox("cursor_unfocused"); + 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("guide_color"); - Color font_color = get_theme_color("font_color"); - Color font_selected_color = get_theme_color("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("bg_focus"), Rect2(Point2(), size)); + draw_style_box(get_theme_stylebox(SNAME("bg_focus")), Rect2(Point2(), size)); RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false); } @@ -1299,7 +1299,7 @@ void ItemList::_scroll_changed(double) { int ItemList::get_item_at_position(const Point2 &p_pos, bool p_exact) const { Vector2 pos = p_pos; - Ref<StyleBox> bg = get_theme_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg")); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); @@ -1337,7 +1337,7 @@ bool ItemList::is_pos_at_end_of_items(const Point2 &p_pos) const { } Vector2 pos = p_pos; - Ref<StyleBox> bg = get_theme_stylebox("bg"); + Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg")); pos -= bg->get_offset(); pos.y += scroll_bar->get_value(); diff --git a/scene/gui/label.cpp b/scene/gui/label.cpp index 78b9ad2569..06faf3fa3e 100644 --- a/scene/gui/label.cpp +++ b/scene/gui/label.cpp @@ -64,7 +64,7 @@ bool Label::is_uppercase() const { } int Label::get_line_height(int p_line) const { - Ref<Font> font = get_theme_font("font"); + Ref<Font> font = get_theme_font(SNAME("font")); if (p_line >= 0 && p_line < lines_rid.size()) { return TS->shaped_text_get_size(lines_rid[p_line]).y + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM); } else if (lines_rid.size() > 0) { @@ -74,12 +74,12 @@ int Label::get_line_height(int p_line) const { } return h; } else { - return font->get_height(get_theme_font_size("font_size")); + return font->get_height(get_theme_font_size(SNAME("font_size"))); } } void Label::_shape() { - Ref<StyleBox> style = get_theme_stylebox("normal", "Label"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"), SNAME("Label")); int width = (get_size().width - style->get_minimum_size().width); if (dirty) { @@ -89,7 +89,7 @@ void Label::_shape() { } else { TS->shaped_text_set_direction(text_rid, (TextServer::Direction)text_direction); } - TS->shaped_text_add_string(text_rid, (uppercase) ? xl_text.to_upper() : xl_text, get_theme_font("font")->get_rids(), get_theme_font_size("font_size"), opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); + TS->shaped_text_add_string(text_rid, (uppercase) ? xl_text.to_upper() : xl_text, get_theme_font(SNAME("font"))->get_rids(), get_theme_font_size(SNAME("font_size")), opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, xl_text)); dirty = false; lines_dirty = true; @@ -200,9 +200,9 @@ void Label::_shape() { } void Label::_update_visible() { - int line_spacing = get_theme_constant("line_spacing", "Label"); - Ref<StyleBox> style = get_theme_stylebox("normal", "Label"); - Ref<Font> font = get_theme_font("font"); + int line_spacing = get_theme_constant(SNAME("line_spacing"), SNAME("Label")); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"), SNAME("Label")); + Ref<Font> font = get_theme_font(SNAME("font")); int lines_visible = lines_rid.size(); if (max_lines_visible >= 0 && lines_visible > max_lines_visible) { @@ -244,15 +244,15 @@ void Label::_notification(int p_what) { Size2 string_size; Size2 size = get_size(); - Ref<StyleBox> style = get_theme_stylebox("normal"); - Ref<Font> font = get_theme_font("font"); - Color font_color = get_theme_color("font_color"); - Color font_shadow_color = get_theme_color("font_shadow_color"); - Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); - int line_spacing = get_theme_constant("line_spacing"); - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); - int shadow_outline_size = get_theme_constant("shadow_outline_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 = is_layout_rtl(); style->draw(ci, Rect2(Point2(0, 0), get_size())); @@ -429,10 +429,10 @@ Size2 Label::get_minimum_size() const { Size2 min_size = minsize; - Ref<Font> font = get_theme_font("font"); - min_size.height = MAX(min_size.height, font->get_height(get_theme_font_size("font_size")) + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM)); + Ref<Font> font = get_theme_font(SNAME("font")); + min_size.height = MAX(min_size.height, font->get_height(get_theme_font_size(SNAME("font_size"))) + font->get_spacing(Font::SPACING_TOP) + font->get_spacing(Font::SPACING_BOTTOM)); - Size2 min_style = get_theme_stylebox("normal")->get_minimum_size(); + Size2 min_style = get_theme_stylebox(SNAME("normal"))->get_minimum_size(); if (autowrap_mode != AUTOWRAP_OFF) { return Size2(1, (clip || overrun_behavior != OVERRUN_NO_TRIMMING) ? 1 : min_size.height) + min_style; } else { @@ -455,9 +455,9 @@ int Label::get_line_count() const { } int Label::get_visible_line_count() const { - Ref<Font> font = get_theme_font("font"); - Ref<StyleBox> style = get_theme_stylebox("normal"); - int line_spacing = get_theme_constant("line_spacing"); + Ref<Font> font = get_theme_font(SNAME("font")); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); + int line_spacing = get_theme_constant(SNAME("line_spacing")); int lines_visible = 0; float total_h = 0.0; for (int64_t i = lines_skipped; i < lines_rid.size(); i++) { diff --git a/scene/gui/line_edit.cpp b/scene/gui/line_edit.cpp index c862624f98..19ffcfca6d 100644 --- a/scene/gui/line_edit.cpp +++ b/scene/gui/line_edit.cpp @@ -230,7 +230,6 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { _ensure_menu(); menu->set_position(get_screen_transform().xform(get_local_mouse_position())); menu->set_size(Vector2(1, 1)); - _generate_context_menu(); menu->popup(); grab_focus(); accept_event(); @@ -350,10 +349,9 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { if (context_menu_enabled) { if (k->is_action("ui_menu", true)) { _ensure_menu(); - Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + get_theme_font("font")->get_height(get_theme_font_size("font_size"))) / 2); + Point2 pos = Point2(get_caret_pixel_pos().x, (get_size().y + get_theme_font(SNAME("font"))->get_height(get_theme_font_size(SNAME("font_size")))) / 2); menu->set_position(get_global_transform().xform(pos)); menu->set_size(Vector2(1, 1)); - _generate_context_menu(); menu->popup(); menu->grab_focus(); } @@ -361,7 +359,7 @@ void LineEdit::_gui_input(Ref<InputEvent> p_event) { // Default is ENTER and KP_ENTER. Cannot use ui_accept as default includes SPACE if (k->is_action("ui_text_submit", false)) { - emit_signal("text_submitted", text); + emit_signal(SNAME("text_submitted"), text); if (DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_VIRTUAL_KEYBOARD) && virtual_keyboard_enabled) { DisplayServer::get_singleton()->virtual_keyboard_hide(); } @@ -569,8 +567,8 @@ bool LineEdit::_is_over_clear_button(const Point2 &p_pos) const { if (!clear_button_enabled || !has_point(p_pos)) { return false; } - Ref<Texture2D> icon = Control::get_theme_icon("clear"); - int x_ofs = get_theme_stylebox("normal")->get_offset().x; + Ref<Texture2D> icon = Control::get_theme_icon(SNAME("clear")); + int x_ofs = get_theme_stylebox(SNAME("normal"))->get_offset().x; return p_pos.x > get_size().width - icon->get_width() - x_ofs; } @@ -627,17 +625,17 @@ void LineEdit::_notification(int p_what) { RID ci = get_canvas_item(); - Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); if (!is_editable()) { - style = get_theme_stylebox("read_only"); + style = get_theme_stylebox(SNAME("read_only")); draw_caret = false; } - Ref<Font> font = get_theme_font("font"); + Ref<Font> font = get_theme_font(SNAME("font")); style->draw(ci, Rect2(Point2(), size)); if (has_focus()) { - get_theme_stylebox("focus")->draw(ci, Rect2(Point2(), size)); + get_theme_stylebox(SNAME("focus"))->draw(ci, Rect2(Point2(), size)); } int x_ofs = 0; @@ -675,10 +673,10 @@ void LineEdit::_notification(int p_what) { int y_area = height - style->get_minimum_size().height; int y_ofs = style->get_offset().y + (y_area - text_height) / 2; - Color selection_color = get_theme_color("selection_color"); - Color font_color = is_editable() ? get_theme_color("font_color") : get_theme_color("font_uneditable_color"); - Color font_selected_color = get_theme_color("font_selected_color"); - Color caret_color = get_theme_color("caret_color"); + Color selection_color = get_theme_color(SNAME("selection_color")); + Color font_color = is_editable() ? get_theme_color(SNAME("font_color")) : get_theme_color(SNAME("font_uneditable_color")); + Color font_selected_color = get_theme_color(SNAME("font_selected_color")); + Color caret_color = get_theme_color(SNAME("caret_color")); // Draw placeholder color. if (using_placeholder) { @@ -687,13 +685,13 @@ void LineEdit::_notification(int p_what) { bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon; Color color_icon(1, 1, 1, !is_editable() ? .5 * .9 : .9); if (display_clear_icon) { if (clear_button_status.press_attempt && clear_button_status.pressing_inside) { - color_icon = get_theme_color("clear_button_color_pressed"); + color_icon = get_theme_color(SNAME("clear_button_color_pressed")); } else { - color_icon = get_theme_color("clear_button_color"); + color_icon = get_theme_color(SNAME("clear_button_color")); } } @@ -740,8 +738,8 @@ void LineEdit::_notification(int p_what) { // Draw text. ofs.y += TS->shaped_text_get_ascent(text_rid); - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); + 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) { Vector2 oofs = ofs; for (int i = 0; i < gl_size; i++) { @@ -786,7 +784,7 @@ void LineEdit::_notification(int p_what) { if (l_caret == Rect2() && t_caret == Rect2()) { // No carets, add one at the start. - int h = get_theme_font("font")->get_height(get_theme_font_size("font_size")); + int h = get_theme_font(SNAME("font"))->get_height(get_theme_font_size(SNAME("font_size"))); int y = style->get_offset().y + (y_area - h) / 2; if (rtl) { l_dir = TextServer::DIRECTION_RTL; @@ -1008,7 +1006,7 @@ void LineEdit::shift_selection_check_post(bool p_shift) { } void LineEdit::set_caret_at_pixel_pos(int p_x) { - Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); bool rtl = is_layout_rtl(); int x_ofs = 0; @@ -1041,7 +1039,7 @@ void LineEdit::set_caret_at_pixel_pos(int p_x) { bool using_placeholder = text.is_empty() && ime_text.is_empty(); bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon; if (align == ALIGN_CENTER) { if (scroll_offset == 0) { x_ofs = MAX(style->get_margin(SIDE_LEFT), int(get_size().width - text_width - r_icon->get_width() - style->get_margin(SIDE_RIGHT) * 2) / 2); @@ -1056,7 +1054,7 @@ void LineEdit::set_caret_at_pixel_pos(int p_x) { } Vector2i LineEdit::get_caret_pixel_pos() { - Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); bool rtl = is_layout_rtl(); int x_ofs = 0; @@ -1089,7 +1087,7 @@ Vector2i LineEdit::get_caret_pixel_pos() { bool using_placeholder = text.is_empty() && ime_text.is_empty(); bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon; if (align == ALIGN_CENTER) { if (scroll_offset == 0) { x_ofs = MAX(style->get_margin(SIDE_LEFT), int(get_size().width - text_width - r_icon->get_width() - style->get_margin(SIDE_RIGHT) * 2) / 2); @@ -1402,7 +1400,7 @@ void LineEdit::set_caret_column(int p_column) { return; } - Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); bool rtl = is_layout_rtl(); int x_ofs = 0; @@ -1436,7 +1434,7 @@ void LineEdit::set_caret_column(int p_column) { bool using_placeholder = text.is_empty() && ime_text.is_empty(); bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon; if (align == ALIGN_CENTER) { if (scroll_offset == 0) { x_ofs = MAX(style->get_margin(SIDE_LEFT), int(get_size().width - text_width - r_icon->get_width() - style->get_margin(SIDE_RIGHT) * 2) / 2); @@ -1480,7 +1478,7 @@ void LineEdit::insert_text_at_caret(String p_text) { // Truncate text to append to fit in max_length, if needed. int available_chars = max_length - text.length(); if (p_text.length() > available_chars) { - emit_signal("text_change_rejected", p_text.substr(available_chars)); + emit_signal(SNAME("text_change_rejected"), p_text.substr(available_chars)); p_text = p_text.substr(0, available_chars); } } @@ -1507,15 +1505,15 @@ void LineEdit::clear_internal() { } Size2 LineEdit::get_minimum_size() const { - Ref<StyleBox> style = get_theme_stylebox("normal"); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); + Ref<Font> font = get_theme_font(SNAME("font")); + int font_size = get_theme_font_size(SNAME("font_size")); Size2 min_size; // Minimum size of text. int em_space_size = font->get_char_size('M', 0, font_size).x; - min_size.width = get_theme_constant("minimum_character_width") * em_space_size; + min_size.width = get_theme_constant(SNAME("minimum_character_width")) * em_space_size; if (expand_to_text_length) { // Add a space because some fonts are too exact, and because caret needs a bit more when at the end. @@ -1528,7 +1526,7 @@ Size2 LineEdit::get_minimum_size() const { bool using_placeholder = text.is_empty() && ime_text.is_empty(); bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon; min_size.width += r_icon->get_width(); min_size.height = MAX(min_size.height, r_icon->get_height()); } @@ -1602,7 +1600,6 @@ void LineEdit::set_editable(bool p_editable) { } editable = p_editable; - _generate_context_menu(); minimum_size_changed(); update(); @@ -1858,8 +1855,6 @@ bool LineEdit::is_clear_button_enabled() const { void LineEdit::set_shortcut_keys_enabled(bool p_enabled) { shortcut_keys_enabled = p_enabled; - - _generate_context_menu(); } bool LineEdit::is_shortcut_keys_enabled() const { @@ -1880,8 +1875,6 @@ void LineEdit::set_selecting_enabled(bool p_enabled) { if (!selecting_enabled) { deselect(); } - - _generate_context_menu(); } bool LineEdit::is_selecting_enabled() const { @@ -1908,7 +1901,7 @@ void LineEdit::_text_changed() { } void LineEdit::_emit_text_change() { - emit_signal("text_changed", text); + emit_signal(SNAME("text_changed"), text); text_changed_dirty = false; } @@ -1935,8 +1928,8 @@ void LineEdit::_shape() { } TS->shaped_text_set_preserve_control(text_rid, draw_control_chars); - const Ref<Font> &font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + const Ref<Font> &font = get_theme_font(SNAME("font")); + int font_size = get_theme_font_size(SNAME("font_size")); TS->shaped_text_add_string(text_rid, t, font->get_rids(), font_size, opentype_features, (language != "") ? language : TranslationServer::get_singleton()->get_tool_locale()); TS->shaped_text_set_bidi_override(text_rid, structured_text_parser(st_parser, st_args, t)); @@ -1952,12 +1945,12 @@ void LineEdit::_shape() { void LineEdit::_fit_to_width() { if (align == ALIGN_FILL) { - Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); int t_width = get_size().width - style->get_margin(SIDE_RIGHT) - style->get_margin(SIDE_LEFT); bool using_placeholder = text.is_empty() && ime_text.is_empty(); bool display_clear_icon = !using_placeholder && is_editable() && clear_button_enabled; if (right_icon.is_valid() || display_clear_icon) { - Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon("clear") : right_icon; + Ref<Texture2D> r_icon = display_clear_icon ? Control::get_theme_icon(SNAME("clear")) : right_icon; t_width -= r_icon->get_width(); } TS->shaped_text_fit_to_width(text_rid, MAX(t_width, full_width)); @@ -2018,36 +2011,6 @@ int LineEdit::_get_menu_action_accelerator(const String &p_action) { } } -void LineEdit::_generate_context_menu() { - // Reorganize context menu. - _ensure_menu(); - menu->clear(); - if (editable) { - menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0); - } - menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0); - if (editable) { - menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0); - } - menu->add_separator(); - if (is_selecting_enabled()) { - menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0); - } - if (editable) { - menu->add_item(RTR("Clear"), MENU_CLEAR); - menu->add_separator(); - menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0); - menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0); - } - menu->add_separator(); - menu->add_submenu_item(RTR("Text writing direction"), "DirMenu"); - menu->add_separator(); - menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC); - if (editable) { - menu->add_submenu_item(RTR("Insert control character"), "CTLMenu"); - } -} - bool LineEdit::_set(const StringName &p_name, const Variant &p_value) { String str = p_name; if (str.begins_with("opentype_features/")) { @@ -2244,48 +2207,72 @@ void LineEdit::_bind_methods() { } void LineEdit::_ensure_menu() { - if (menu) { - return; + if (!menu) { + menu = memnew(PopupMenu); + add_child(menu); + + menu_dir = memnew(PopupMenu); + menu_dir->set_name("DirMenu"); + menu_dir->add_radio_check_item(RTR("Same as layout direction"), MENU_DIR_INHERITED); + menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO); + menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR); + menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL); + menu->add_child(menu_dir); + + menu_ctl = memnew(PopupMenu); + menu_ctl->set_name("CTLMenu"); + menu_ctl->add_item(RTR("Left-to-right mark (LRM)"), MENU_INSERT_LRM); + menu_ctl->add_item(RTR("Right-to-left mark (RLM)"), MENU_INSERT_RLM); + menu_ctl->add_item(RTR("Start of left-to-right embedding (LRE)"), MENU_INSERT_LRE); + menu_ctl->add_item(RTR("Start of right-to-left embedding (RLE)"), MENU_INSERT_RLE); + menu_ctl->add_item(RTR("Start of left-to-right override (LRO)"), MENU_INSERT_LRO); + menu_ctl->add_item(RTR("Start of right-to-left override (RLO)"), MENU_INSERT_RLO); + menu_ctl->add_item(RTR("Pop direction formatting (PDF)"), MENU_INSERT_PDF); + menu_ctl->add_separator(); + menu_ctl->add_item(RTR("Arabic letter mark (ALM)"), MENU_INSERT_ALM); + menu_ctl->add_item(RTR("Left-to-right isolate (LRI)"), MENU_INSERT_LRI); + menu_ctl->add_item(RTR("Right-to-left isolate (RLI)"), MENU_INSERT_RLI); + menu_ctl->add_item(RTR("First strong isolate (FSI)"), MENU_INSERT_FSI); + menu_ctl->add_item(RTR("Pop direction isolate (PDI)"), MENU_INSERT_PDI); + menu_ctl->add_separator(); + menu_ctl->add_item(RTR("Zero width joiner (ZWJ)"), MENU_INSERT_ZWJ); + menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ); + menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ); + menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY); + menu->add_child(menu_ctl); + + menu->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); + menu_dir->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); + menu_ctl->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); } - menu = memnew(PopupMenu); - add_child(menu); - menu->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); - - menu_dir = memnew(PopupMenu); - menu_dir->set_name("DirMenu"); - menu_dir->add_radio_check_item(RTR("Same as layout direction"), MENU_DIR_INHERITED); - menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO); - menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR); - menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL); - menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), true); - menu->add_child(menu_dir); - - menu_ctl = memnew(PopupMenu); - menu_ctl->set_name("CTLMenu"); - menu_ctl->add_item(RTR("Left-to-right mark (LRM)"), MENU_INSERT_LRM); - menu_ctl->add_item(RTR("Right-to-left mark (RLM)"), MENU_INSERT_RLM); - menu_ctl->add_item(RTR("Start of left-to-right embedding (LRE)"), MENU_INSERT_LRE); - menu_ctl->add_item(RTR("Start of right-to-left embedding (RLE)"), MENU_INSERT_RLE); - menu_ctl->add_item(RTR("Start of left-to-right override (LRO)"), MENU_INSERT_LRO); - menu_ctl->add_item(RTR("Start of right-to-left override (RLO)"), MENU_INSERT_RLO); - menu_ctl->add_item(RTR("Pop direction formatting (PDF)"), MENU_INSERT_PDF); - menu_ctl->add_separator(); - menu_ctl->add_item(RTR("Arabic letter mark (ALM)"), MENU_INSERT_ALM); - menu_ctl->add_item(RTR("Left-to-right isolate (LRI)"), MENU_INSERT_LRI); - menu_ctl->add_item(RTR("Right-to-left isolate (RLI)"), MENU_INSERT_RLI); - menu_ctl->add_item(RTR("First strong isolate (FSI)"), MENU_INSERT_FSI); - menu_ctl->add_item(RTR("Pop direction isolate (PDI)"), MENU_INSERT_PDI); - menu_ctl->add_separator(); - menu_ctl->add_item(RTR("Zero width joiner (ZWJ)"), MENU_INSERT_ZWJ); - menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ); - menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ); - menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY); - menu->add_child(menu_ctl); - - menu_dir->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); - menu_ctl->connect("id_pressed", callable_mp(this, &LineEdit::menu_option)); - + // Reorganize context menu. + menu->clear(); + if (editable) { + menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0); + } + menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0); + if (editable) { + menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0); + } + menu->add_separator(); + if (is_selecting_enabled()) { + menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0); + } + if (editable) { + menu->add_item(RTR("Clear"), MENU_CLEAR); + menu->add_separator(); + menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0); + menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0); + } + menu->add_separator(); + menu->add_submenu_item(RTR("Text writing direction"), "DirMenu"); + menu->add_separator(); + menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC); + menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars); + if (editable) { + menu->add_submenu_item(RTR("Insert control character"), "CTLMenu"); + } menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED); menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO); menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR); diff --git a/scene/gui/line_edit.h b/scene/gui/line_edit.h index 16f3356637..c5c92d60aa 100644 --- a/scene/gui/line_edit.h +++ b/scene/gui/line_edit.h @@ -165,7 +165,6 @@ private: void _create_undo_state(); int _get_menu_action_accelerator(const String &p_action); - void _generate_context_menu(); void _shape(); void _fit_to_width(); diff --git a/scene/gui/link_button.cpp b/scene/gui/link_button.cpp index ee0618a991..419d49bccf 100644 --- a/scene/gui/link_button.cpp +++ b/scene/gui/link_button.cpp @@ -32,8 +32,8 @@ #include "core/string/translation.h" void LinkButton::_shape() { - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + Ref<Font> font = get_theme_font(SNAME("font")); + int font_size = get_theme_font_size(SNAME("font_size")); text_buf->clear(); if (text_direction == Control::TEXT_DIRECTION_INHERITED) { @@ -158,41 +158,41 @@ void LinkButton::_notification(int p_what) { switch (get_draw_mode()) { case DRAW_NORMAL: { - color = get_theme_color("font_color"); + color = get_theme_color(SNAME("font_color")); do_underline = underline_mode == UNDERLINE_MODE_ALWAYS; } break; case DRAW_HOVER_PRESSED: case DRAW_PRESSED: { - if (has_theme_color("font_pressed_color")) { - color = get_theme_color("font_pressed_color"); + if (has_theme_color(SNAME("font_pressed_color"))) { + color = get_theme_color(SNAME("font_pressed_color")); } else { - color = get_theme_color("font_color"); + color = get_theme_color(SNAME("font_color")); } do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; case DRAW_HOVER: { - color = get_theme_color("font_hover_color"); + color = get_theme_color(SNAME("font_hover_color")); do_underline = underline_mode != UNDERLINE_MODE_NEVER; } break; case DRAW_DISABLED: { - color = get_theme_color("font_disabled_color"); + color = get_theme_color(SNAME("font_disabled_color")); do_underline = underline_mode == UNDERLINE_MODE_ALWAYS; } break; } if (has_focus()) { - Ref<StyleBox> style = get_theme_stylebox("focus"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("focus")); style->draw(ci, Rect2(Point2(), size)); } int width = text_buf->get_line_width(); - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); + Color font_outline_color = get_theme_color(SNAME("font_outline_color")); + int outline_size = get_theme_constant(SNAME("outline_size")); if (is_layout_rtl()) { if (outline_size > 0 && font_outline_color.a > 0) { text_buf->draw_outline(get_canvas_item(), Vector2(size.width - width, 0), outline_size, font_outline_color); @@ -206,7 +206,7 @@ void LinkButton::_notification(int p_what) { } if (do_underline) { - int underline_spacing = get_theme_constant("underline_spacing") + text_buf->get_line_underline_position(); + int underline_spacing = get_theme_constant(SNAME("underline_spacing")) + text_buf->get_line_underline_position(); int y = text_buf->get_line_ascent() + underline_spacing; if (is_layout_rtl()) { diff --git a/scene/gui/margin_container.cpp b/scene/gui/margin_container.cpp index 0e9610d0a3..50b4d192a9 100644 --- a/scene/gui/margin_container.cpp +++ b/scene/gui/margin_container.cpp @@ -31,10 +31,10 @@ #include "margin_container.h" Size2 MarginContainer::get_minimum_size() const { - int margin_left = get_theme_constant("margin_left"); - int margin_top = get_theme_constant("margin_top"); - int margin_right = get_theme_constant("margin_right"); - int margin_bottom = get_theme_constant("margin_bottom"); + int margin_left = get_theme_constant(SNAME("margin_left")); + int margin_top = get_theme_constant(SNAME("margin_top")); + int margin_right = get_theme_constant(SNAME("margin_right")); + int margin_bottom = get_theme_constant(SNAME("margin_bottom")); Size2 max; @@ -68,10 +68,10 @@ Size2 MarginContainer::get_minimum_size() const { void MarginContainer::_notification(int p_what) { switch (p_what) { case NOTIFICATION_SORT_CHILDREN: { - int margin_left = get_theme_constant("margin_left"); - int margin_top = get_theme_constant("margin_top"); - int margin_right = get_theme_constant("margin_right"); - int margin_bottom = get_theme_constant("margin_bottom"); + int margin_left = get_theme_constant(SNAME("margin_left")); + int margin_top = get_theme_constant(SNAME("margin_top")); + int margin_right = get_theme_constant(SNAME("margin_right")); + int margin_bottom = get_theme_constant(SNAME("margin_bottom")); Size2 s = get_size(); diff --git a/scene/gui/option_button.cpp b/scene/gui/option_button.cpp index e52b6917be..cd55f258b3 100644 --- a/scene/gui/option_button.cpp +++ b/scene/gui/option_button.cpp @@ -35,12 +35,12 @@ Size2 OptionButton::get_minimum_size() const { Size2 minsize = Button::get_minimum_size(); - if (has_theme_icon("arrow")) { - const Size2 padding = get_theme_stylebox("normal")->get_minimum_size(); - const Size2 arrow_size = Control::get_theme_icon("arrow")->get_size(); + if (has_theme_icon(SNAME("arrow"))) { + const Size2 padding = get_theme_stylebox(SNAME("normal"))->get_minimum_size(); + const Size2 arrow_size = Control::get_theme_icon(SNAME("arrow"))->get_size(); Size2 content_size = minsize - padding; - content_size.width += arrow_size.width + get_theme_constant("hseparation"); + content_size.width += arrow_size.width + get_theme_constant(SNAME("hseparation")); content_size.height = MAX(content_size.height, arrow_size.height); minsize = content_size + padding; @@ -52,26 +52,26 @@ Size2 OptionButton::get_minimum_size() const { void OptionButton::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { - if (!has_theme_icon("arrow")) { + if (!has_theme_icon(SNAME("arrow"))) { return; } RID ci = get_canvas_item(); - Ref<Texture2D> arrow = Control::get_theme_icon("arrow"); + Ref<Texture2D> arrow = Control::get_theme_icon(SNAME("arrow")); Color clr = Color(1, 1, 1); - if (get_theme_constant("modulate_arrow")) { + if (get_theme_constant(SNAME("modulate_arrow"))) { switch (get_draw_mode()) { case DRAW_PRESSED: - clr = get_theme_color("font_pressed_color"); + clr = get_theme_color(SNAME("font_pressed_color")); break; case DRAW_HOVER: - clr = get_theme_color("font_hover_color"); + clr = get_theme_color(SNAME("font_hover_color")); break; case DRAW_DISABLED: - clr = get_theme_color("font_disabled_color"); + clr = get_theme_color(SNAME("font_disabled_color")); break; default: - clr = get_theme_color("font_color"); + clr = get_theme_color(SNAME("font_color")); } } @@ -79,22 +79,22 @@ void OptionButton::_notification(int p_what) { Point2 ofs; if (is_layout_rtl()) { - ofs = Point2(get_theme_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2))); + ofs = Point2(get_theme_constant(SNAME("arrow_margin")), int(Math::abs((size.height - arrow->get_height()) / 2))); } else { - ofs = Point2(size.width - arrow->get_width() - get_theme_constant("arrow_margin"), int(Math::abs((size.height - arrow->get_height()) / 2))); + ofs = Point2(size.width - arrow->get_width() - get_theme_constant(SNAME("arrow_margin")), int(Math::abs((size.height - arrow->get_height()) / 2))); } arrow->draw(ci, ofs, clr); } break; case NOTIFICATION_TRANSLATION_CHANGED: case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: case NOTIFICATION_THEME_CHANGED: { - if (has_theme_icon("arrow")) { + if (has_theme_icon(SNAME("arrow"))) { if (is_layout_rtl()) { - _set_internal_margin(SIDE_LEFT, Control::get_theme_icon("arrow")->get_width()); + _set_internal_margin(SIDE_LEFT, Control::get_theme_icon(SNAME("arrow"))->get_width()); _set_internal_margin(SIDE_RIGHT, 0.f); } else { _set_internal_margin(SIDE_LEFT, 0.f); - _set_internal_margin(SIDE_RIGHT, Control::get_theme_icon("arrow")->get_width()); + _set_internal_margin(SIDE_RIGHT, Control::get_theme_icon(SNAME("arrow"))->get_width()); } } } break; @@ -107,7 +107,7 @@ void OptionButton::_notification(int p_what) { } void OptionButton::_focused(int p_which) { - emit_signal("item_focused", p_which); + emit_signal(SNAME("item_focused"), p_which); } void OptionButton::_selected(int p_which) { @@ -220,7 +220,7 @@ void OptionButton::_select(int p_which, bool p_emit) { set_icon(popup->get_item_icon(current)); if (is_inside_tree() && p_emit) { - emit_signal("item_selected", current); + emit_signal(SNAME("item_selected"), current); } } @@ -339,12 +339,12 @@ OptionButton::OptionButton() { set_toggle_mode(true); set_text_align(ALIGN_LEFT); if (is_layout_rtl()) { - if (has_theme_icon("arrow")) { - _set_internal_margin(SIDE_LEFT, Control::get_theme_icon("arrow")->get_width()); + if (has_theme_icon(SNAME("arrow"))) { + _set_internal_margin(SIDE_LEFT, Control::get_theme_icon(SNAME("arrow"))->get_width()); } } else { - if (has_theme_icon("arrow")) { - _set_internal_margin(SIDE_RIGHT, Control::get_theme_icon("arrow")->get_width()); + if (has_theme_icon(SNAME("arrow"))) { + _set_internal_margin(SIDE_RIGHT, Control::get_theme_icon(SNAME("arrow"))->get_width()); } } set_action_mode(ACTION_MODE_BUTTON_PRESS); diff --git a/scene/gui/panel.cpp b/scene/gui/panel.cpp index 995e985c3a..e8e7e3d997 100644 --- a/scene/gui/panel.cpp +++ b/scene/gui/panel.cpp @@ -35,7 +35,7 @@ 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("panel") : get_theme_stylebox("panel_fg"); + Ref<StyleBox> style = mode == MODE_BACKGROUND ? get_theme_stylebox(SNAME("panel")) : get_theme_stylebox(SNAME("panel_fg")); style->draw(ci, Rect2(Point2(), get_size())); } } diff --git a/scene/gui/panel_container.cpp b/scene/gui/panel_container.cpp index 11d822c5e1..d910e1e882 100644 --- a/scene/gui/panel_container.cpp +++ b/scene/gui/panel_container.cpp @@ -33,10 +33,10 @@ Size2 PanelContainer::get_minimum_size() const { Ref<StyleBox> style; - if (has_theme_stylebox("panel")) { - style = get_theme_stylebox("panel"); + if (has_theme_stylebox(SNAME("panel"))) { + style = get_theme_stylebox(SNAME("panel")); } else { - style = get_theme_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer")); } Size2 ms; @@ -65,10 +65,10 @@ void PanelContainer::_notification(int p_what) { RID ci = get_canvas_item(); Ref<StyleBox> style; - if (has_theme_stylebox("panel")) { - style = get_theme_stylebox("panel"); + if (has_theme_stylebox(SNAME("panel"))) { + style = get_theme_stylebox(SNAME("panel")); } else { - style = get_theme_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer")); } style->draw(ci, Rect2(Point2(), get_size())); @@ -77,10 +77,10 @@ void PanelContainer::_notification(int p_what) { if (p_what == NOTIFICATION_SORT_CHILDREN) { Ref<StyleBox> style; - if (has_theme_stylebox("panel")) { - style = get_theme_stylebox("panel"); + if (has_theme_stylebox(SNAME("panel"))) { + style = get_theme_stylebox(SNAME("panel")); } else { - style = get_theme_stylebox("panel", "PanelContainer"); + style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer")); } Size2 size = get_size(); diff --git a/scene/gui/popup.cpp b/scene/gui/popup.cpp index 36bcca61a7..5e1c8cec37 100644 --- a/scene/gui/popup.cpp +++ b/scene/gui/popup.cpp @@ -71,7 +71,7 @@ void Popup::_notification(int p_what) { _initialize_visible_parents(); } else { _deinitialize_visible_parents(); - emit_signal("popup_hide"); + emit_signal(SNAME("popup_hide")); } } break; @@ -103,9 +103,9 @@ void Popup::_close_pressed() { _deinitialize_visible_parents(); - call_deferred("hide"); + call_deferred(SNAME("hide")); - emit_signal("cancelled"); + emit_signal(SNAME("cancelled")); } void Popup::set_as_minsize() { diff --git a/scene/gui/popup_menu.cpp b/scene/gui/popup_menu.cpp index 2100707d2d..ee9e0e8ab8 100644 --- a/scene/gui/popup_menu.cpp +++ b/scene/gui/popup_menu.cpp @@ -46,15 +46,15 @@ String PopupMenu::_get_accel_text(const Item &p_item) const { } Size2 PopupMenu::_get_contents_minimum_size() const { - int vseparation = get_theme_constant("vseparation"); - int hseparation = get_theme_constant("hseparation"); + int vseparation = get_theme_constant(SNAME("vseparation")); + int hseparation = get_theme_constant(SNAME("hseparation")); - Size2 minsize = get_theme_stylebox("panel")->get_minimum_size(); // Accounts for margin in the margin container + Size2 minsize = get_theme_stylebox(SNAME("panel"))->get_minimum_size(); // Accounts for margin in the margin container minsize.x += scroll_container->get_v_scrollbar()->get_size().width * 2; // Adds a buffer so that the scrollbar does not render over the top of content float max_w = 0.0; float icon_w = 0.0; - int check_w = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation; + int check_w = MAX(get_theme_icon(SNAME("checked"))->get_width(), get_theme_icon(SNAME("radio_checked"))->get_width()) + hseparation; int accel_max_w = 0; bool has_check = false; @@ -81,7 +81,7 @@ Size2 PopupMenu::_get_contents_minimum_size() const { } if (items[i].submenu != "") { - size.width += get_theme_icon("submenu")->get_width(); + size.width += get_theme_icon(SNAME("submenu"))->get_width(); } max_w = MAX(max_w, size.width); @@ -89,7 +89,7 @@ Size2 PopupMenu::_get_contents_minimum_size() const { minsize.height += size.height; } - int item_side_padding = get_theme_constant("item_start_padding") + get_theme_constant("item_end_padding"); + int item_side_padding = get_theme_constant(SNAME("item_start_padding")) + get_theme_constant(SNAME("item_end_padding")); minsize.width += max_w + icon_w + accel_max_w + item_side_padding; if (has_check) { @@ -112,24 +112,24 @@ int PopupMenu::_get_item_height(int p_item) const { int icon_height = items[p_item].get_icon_size().height; if (items[p_item].checkable_type) { - icon_height = MAX(icon_height, MAX(get_theme_icon("checked")->get_height(), get_theme_icon("radio_checked")->get_height())); + icon_height = MAX(icon_height, MAX(get_theme_icon(SNAME("checked"))->get_height(), get_theme_icon(SNAME("radio_checked"))->get_height())); } int text_height = items[p_item].text_buf->get_size().height; if (text_height == 0 && !items[p_item].separator) { - text_height = get_theme_font("font")->get_height(get_theme_font_size("font_size")); + text_height = get_theme_font(SNAME("font"))->get_height(get_theme_font_size(SNAME("font_size"))); } int separator_height = 0; if (items[p_item].separator) { - separator_height = MAX(get_theme_stylebox("separator")->get_minimum_size().height, MAX(get_theme_stylebox("labeled_separator_left")->get_minimum_size().height, get_theme_stylebox("labeled_separator_right")->get_minimum_size().height)); + separator_height = MAX(get_theme_stylebox(SNAME("separator"))->get_minimum_size().height, MAX(get_theme_stylebox(SNAME("labeled_separator_left"))->get_minimum_size().height, get_theme_stylebox(SNAME("labeled_separator_right"))->get_minimum_size().height)); } return MAX(separator_height, MAX(text_height, icon_height)); } int PopupMenu::_get_items_total_height() const { - int vsep = get_theme_constant("vseparation"); + int vsep = get_theme_constant(SNAME("vseparation")); // Get total height of all items by taking max of icon height and font height int items_total_height = 0; @@ -163,9 +163,9 @@ int PopupMenu::_get_mouse_over(const Point2 &p_over) const { return -1; } - Ref<StyleBox> style = get_theme_stylebox("panel"); // Accounts for margin in the margin container + Ref<StyleBox> style = get_theme_stylebox(SNAME("panel")); // Accounts for margin in the margin container - int vseparation = get_theme_constant("vseparation"); + int vseparation = get_theme_constant(SNAME("vseparation")); Point2 ofs = style->get_offset() + Point2(0, vseparation / 2); @@ -195,8 +195,8 @@ void PopupMenu::_activate_submenu(int p_over) { return; //already visible! } - Ref<StyleBox> style = get_theme_stylebox("panel"); - int vsep = get_theme_constant("vseparation"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("panel")); + int vsep = get_theme_constant(SNAME("vseparation")); Point2 this_pos = get_position(); Rect2 this_rect(this_pos, get_size()); @@ -264,7 +264,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { for (int i = search_from; i < items.size(); i++) { if (!items[i].separator && !items[i].disabled) { mouse_over = i; - emit_signal("id_focused", i); + emit_signal(SNAME("id_focused"), i); _scroll_to_item(i); control->update(); set_input_as_handled(); @@ -278,7 +278,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { for (int i = 0; i < search_from; i++) { if (!items[i].separator && !items[i].disabled) { mouse_over = i; - emit_signal("id_focused", i); + emit_signal(SNAME("id_focused"), i); _scroll_to_item(i); control->update(); set_input_as_handled(); @@ -296,7 +296,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { for (int i = search_from; i >= 0; i--) { if (!items[i].separator && !items[i].disabled) { mouse_over = i; - emit_signal("id_focused", i); + emit_signal(SNAME("id_focused"), i); _scroll_to_item(i); control->update(); set_input_as_handled(); @@ -310,7 +310,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { for (int i = items.size() - 1; i >= search_from; i--) { if (!items[i].separator && !items[i].disabled) { mouse_over = i; - emit_signal("id_focused", i); + emit_signal(SNAME("id_focused"), i); _scroll_to_item(i); control->update(); set_input_as_handled(); @@ -459,7 +459,7 @@ void PopupMenu::_gui_input(const Ref<InputEvent> &p_event) { if (items[i].text.findn(search_string) == 0) { mouse_over = i; - emit_signal("id_focused", i); + emit_signal(SNAME("id_focused"), i); _scroll_to_item(i); control->update(); set_input_as_handled(); @@ -474,37 +474,37 @@ void PopupMenu::_draw_items() { RID ci = control->get_canvas_item(); Size2 margin_size; - margin_size.width = margin_container->get_theme_constant("margin_right") + margin_container->get_theme_constant("margin_left"); - margin_size.height = margin_container->get_theme_constant("margin_top") + margin_container->get_theme_constant("margin_bottom"); + margin_size.width = margin_container->get_theme_constant(SNAME("margin_right")) + margin_container->get_theme_constant(SNAME("margin_left")); + margin_size.height = margin_container->get_theme_constant(SNAME("margin_top")) + margin_container->get_theme_constant(SNAME("margin_bottom")); // Space between the item content and the sides of popup menu. - int item_start_padding = get_theme_constant("item_start_padding"); - int item_end_padding = get_theme_constant("item_end_padding"); + int item_start_padding = get_theme_constant(SNAME("item_start_padding")); + int item_end_padding = get_theme_constant(SNAME("item_end_padding")); bool rtl = control->is_layout_rtl(); - Ref<StyleBox> style = get_theme_stylebox("panel"); - Ref<StyleBox> hover = get_theme_stylebox("hover"); + 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) - Ref<Texture2D> check[] = { get_theme_icon("checked"), get_theme_icon("radio_checked") }; - Ref<Texture2D> uncheck[] = { get_theme_icon("unchecked"), get_theme_icon("radio_unchecked") }; + 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; if (rtl) { - submenu = get_theme_icon("submenu_mirrored"); + submenu = get_theme_icon(SNAME("submenu_mirrored")); } else { - submenu = get_theme_icon("submenu"); + submenu = get_theme_icon(SNAME("submenu")); } - Ref<StyleBox> separator = get_theme_stylebox("separator"); - Ref<StyleBox> labeled_separator_left = get_theme_stylebox("labeled_separator_left"); - Ref<StyleBox> labeled_separator_right = get_theme_stylebox("labeled_separator_right"); + Ref<StyleBox> separator = get_theme_stylebox(SNAME("separator")); + Ref<StyleBox> labeled_separator_left = get_theme_stylebox(SNAME("labeled_separator_left")); + Ref<StyleBox> labeled_separator_right = get_theme_stylebox(SNAME("labeled_separator_right")); - int vseparation = get_theme_constant("vseparation"); - int hseparation = get_theme_constant("hseparation"); - Color font_color = get_theme_color("font_color"); - Color font_disabled_color = get_theme_color("font_disabled_color"); - Color font_accelerator_color = get_theme_color("font_accelerator_color"); - Color font_hover_color = get_theme_color("font_hover_color"); - Color font_separator_color = get_theme_color("font_separator_color"); + int vseparation = get_theme_constant(SNAME("vseparation")); + int hseparation = get_theme_constant(SNAME("hseparation")); + Color font_color = get_theme_color(SNAME("font_color")); + Color font_disabled_color = get_theme_color(SNAME("font_disabled_color")); + Color font_accelerator_color = get_theme_color(SNAME("font_accelerator_color")); + Color font_hover_color = get_theme_color(SNAME("font_hover_color")); + Color font_separator_color = get_theme_color(SNAME("font_separator_color")); float scroll_width = scroll_container->get_v_scrollbar()->is_visible_in_tree() ? scroll_container->get_v_scrollbar()->get_size().width : 0; float display_width = control->get_size().width - scroll_width; @@ -525,7 +525,7 @@ void PopupMenu::_draw_items() { float check_ofs = 0.0; if (has_check) { - check_ofs = MAX(get_theme_icon("checked")->get_width(), get_theme_icon("radio_checked")->get_width()) + hseparation; + check_ofs = MAX(get_theme_icon(SNAME("checked"))->get_width(), get_theme_icon(SNAME("radio_checked"))->get_width()) + hseparation; } Point2 ofs = Point2(); @@ -606,8 +606,8 @@ void PopupMenu::_draw_items() { } // Text - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); + Color font_outline_color = get_theme_color(SNAME("font_outline_color")); + int outline_size = get_theme_constant(SNAME("outline_size")); if (items[i].separator) { if (text != String()) { int center = (display_width - items[i].text_buf->get_size().width) / 2; @@ -657,7 +657,7 @@ void PopupMenu::_draw_items() { } void PopupMenu::_draw_background() { - Ref<StyleBox> style = get_theme_stylebox("panel"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("panel")); RID ci2 = margin_container->get_canvas_item(); style->draw(ci2, Rect2(Point2(), margin_container->get_size())); } @@ -691,8 +691,8 @@ void PopupMenu::_shape_item(int p_item) { if (items.write[p_item].dirty) { items.write[p_item].text_buf->clear(); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + Ref<Font> font = get_theme_font(SNAME("font")); + int font_size = get_theme_font_size(SNAME("font_size")); if (items[p_item].text_direction == Control::TEXT_DIRECTION_INHERITED) { items.write[p_item].text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); @@ -791,7 +791,7 @@ void PopupMenu::_notification(int p_what) { } // Set margin on the margin container - Ref<StyleBox> panel_style = get_theme_stylebox("panel"); + Ref<StyleBox> panel_style = get_theme_stylebox(SNAME("panel")); margin_container->add_theme_constant_override("margin_top", panel_style->get_margin(Side::SIDE_TOP)); margin_container->add_theme_constant_override("margin_bottom", panel_style->get_margin(Side::SIDE_BOTTOM)); margin_container->add_theme_constant_override("margin_left", panel_style->get_margin(Side::SIDE_LEFT)); @@ -1376,8 +1376,8 @@ void PopupMenu::activate_item(int p_item) { need_hide = false; } - emit_signal("id_pressed", id); - emit_signal("index_pressed", p_item); + emit_signal(SNAME("id_pressed"), id); + emit_signal(SNAME("index_pressed"), p_item); if (need_hide) { hide(); diff --git a/scene/gui/progress_bar.cpp b/scene/gui/progress_bar.cpp index 6e8dfd5994..2cfaaa2fde 100644 --- a/scene/gui/progress_bar.cpp +++ b/scene/gui/progress_bar.cpp @@ -32,10 +32,10 @@ #include "scene/resources/text_line.h" Size2 ProgressBar::get_minimum_size() const { - Ref<StyleBox> bg = get_theme_stylebox("bg"); - Ref<StyleBox> fg = get_theme_stylebox("fg"); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + 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")); Size2 minimum_size = bg->get_minimum_size(); minimum_size.height = MAX(minimum_size.height, fg->get_minimum_size().height); @@ -53,11 +53,11 @@ Size2 ProgressBar::get_minimum_size() const { void ProgressBar::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> bg = get_theme_stylebox("bg"); - Ref<StyleBox> fg = get_theme_stylebox("fg"); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); - Color font_color = get_theme_color("font_color"); + 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(); @@ -75,8 +75,8 @@ void ProgressBar::_notification(int p_what) { 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("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); + 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); } diff --git a/scene/gui/range.cpp b/scene/gui/range.cpp index 4ea1e1eb9f..92d4261d8d 100644 --- a/scene/gui/range.cpp +++ b/scene/gui/range.cpp @@ -42,7 +42,7 @@ TypedArray<String> Range::get_configuration_warnings() const { void Range::_value_changed_notify() { _value_changed(shared->val); - emit_signal("value_changed", shared->val); + emit_signal(SNAME("value_changed"), shared->val); update(); } @@ -57,7 +57,7 @@ void Range::Shared::emit_value_changed() { } void Range::_changed_notify(const char *p_what) { - emit_signal("changed"); + emit_signal(SNAME("changed")); update(); } diff --git a/scene/gui/rich_text_label.cpp b/scene/gui/rich_text_label.cpp index f32ad2144a..99395aae30 100644 --- a/scene/gui/rich_text_label.cpp +++ b/scene/gui/rich_text_label.cpp @@ -136,7 +136,7 @@ RichTextLabel::Item *RichTextLabel::_get_prev_item(Item *p_item, bool p_free) co } Rect2 RichTextLabel::_get_text_rect() { - Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); return Rect2(style->get_offset(), get_size() - style->get_minimum_size()); } @@ -229,8 +229,8 @@ void RichTextLabel::_resize_line(ItemFrame *p_frame, int p_line, const Ref<Font> switch (it->type) { case ITEM_TABLE: { ItemTable *table = static_cast<ItemTable *>(it); - int hseparation = get_theme_constant("table_hseparation"); - int vseparation = get_theme_constant("table_vseparation"); + int hseparation = get_theme_constant(SNAME("table_hseparation")); + int vseparation = get_theme_constant(SNAME("table_vseparation")); int col_count = table->columns.size(); for (int i = 0; i < col_count; i++) { @@ -458,8 +458,8 @@ void RichTextLabel::_shape_line(ItemFrame *p_frame, int p_line, const Ref<Font> } break; case ITEM_TABLE: { ItemTable *table = static_cast<ItemTable *>(it); - int hseparation = get_theme_constant("table_hseparation"); - int vseparation = get_theme_constant("table_vseparation"); + int hseparation = get_theme_constant(SNAME("table_hseparation")); + int vseparation = get_theme_constant(SNAME("table_vseparation")); int col_count = table->columns.size(); int t_char_count = 0; // Set minimums to zero. @@ -672,11 +672,11 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o if (prefix != "") { Ref<Font> font = _find_font(l.from); if (font.is_null()) { - font = get_theme_font("normal_font"); + font = get_theme_font(SNAME("normal_font")); } int font_size = _find_font_size(l.from); if (font_size == -1) { - font_size = get_theme_font_size("normal_font_size"); + font_size = get_theme_font_size(SNAME("normal_font_size")); } if (rtl) { float offx = 0.0f; @@ -775,10 +775,10 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o } break; case ITEM_TABLE: { ItemTable *table = static_cast<ItemTable *>(it); - Color odd_row_bg = get_theme_color("table_odd_row_bg"); - Color even_row_bg = get_theme_color("table_even_row_bg"); - Color border = get_theme_color("table_border"); - int hseparation = get_theme_constant("table_hseparation"); + Color odd_row_bg = get_theme_color(SNAME("table_odd_row_bg")); + Color even_row_bg = get_theme_color(SNAME("table_even_row_bg")); + Color border = get_theme_color(SNAME("table_border")); + int hseparation = get_theme_constant(SNAME("table_hseparation")); int col_count = table->columns.size(); int row_count = table->rows.size(); @@ -916,7 +916,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o } } - Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); + Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y"))); // Draw glyph outlines. for (int j = 0; j < glyphs[i].repeat; j++) { @@ -940,8 +940,8 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o _draw_fbg_boxes(ci, rid, fbg_line_off, it_from, it_to, chr_range.x, chr_range.y, 0); // Draw main text. - Color selection_fg = get_theme_color("font_selected_color"); - Color selection_bg = get_theme_color("selection_color"); + Color selection_fg = get_theme_color(SNAME("font_selected_color")); + Color selection_bg = get_theme_color(SNAME("selection_color")); int sel_start = -1; int sel_end = -1; @@ -1192,8 +1192,8 @@ float RichTextLabel::_find_click_in_line(ItemFrame *p_frame, int p_line, const V if (rect.has_point(p_click - p_ofs - off)) { switch (it->type) { case ITEM_TABLE: { - int hseparation = get_theme_constant("table_hseparation"); - int vseparation = get_theme_constant("table_vseparation"); + int hseparation = get_theme_constant(SNAME("table_hseparation")); + int vseparation = get_theme_constant(SNAME("table_vseparation")); ItemTable *table = static_cast<ItemTable *>(it); @@ -1362,7 +1362,7 @@ void RichTextLabel::_notification(int p_what) { case NOTIFICATION_MOUSE_EXIT: { if (meta_hovering) { meta_hovering = nullptr; - emit_signal("meta_hover_ended", current_meta); + emit_signal(SNAME("meta_hover_ended"), current_meta); current_meta = false; update(); } @@ -1395,11 +1395,11 @@ void RichTextLabel::_notification(int p_what) { Size2 size = get_size(); Rect2 text_rect = _get_text_rect(); - draw_style_box(get_theme_stylebox("normal"), Rect2(Point2(), size)); + draw_style_box(get_theme_stylebox(SNAME("normal")), Rect2(Point2(), size)); if (has_focus()) { RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, true); - draw_style_box(get_theme_stylebox("focus"), Rect2(Point2(), size)); + draw_style_box(get_theme_stylebox(SNAME("focus")), Rect2(Point2(), size)); RenderingServer::get_singleton()->canvas_item_add_clip_ignore(ci, false); } @@ -1419,13 +1419,13 @@ void RichTextLabel::_notification(int p_what) { if (from_line >= main->lines.size()) { break; //nothing to draw } - Ref<Font> base_font = get_theme_font("normal_font"); - Color base_color = get_theme_color("default_color"); - Color outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); - Color font_shadow_color = get_theme_color("font_shadow_color"); - bool use_outline = get_theme_constant("shadow_as_outline"); - Point2 shadow_ofs(get_theme_constant("shadow_offset_x"), get_theme_constant("shadow_offset_y")); + Ref<Font> base_font = get_theme_font(SNAME("normal_font")); + Color base_color = get_theme_color(SNAME("default_color")); + Color outline_color = get_theme_color(SNAME("font_outline_color")); + int outline_size = get_theme_constant(SNAME("outline_size")); + Color font_shadow_color = get_theme_color(SNAME("font_shadow_color")); + bool use_outline = get_theme_constant(SNAME("shadow_as_outline")); + Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y"))); visible_paragraph_count = 0; visible_line_count = 0; @@ -1568,7 +1568,7 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { Variant meta; if (!outside && _find_meta(c_item, &meta)) { //meta clicked - emit_signal("meta_clicked", meta); + emit_signal(SNAME("meta_clicked"), meta); } } } @@ -1611,11 +1611,11 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { handled = true; } if (k->is_action("ui_up") && vscroll->is_visible_in_tree()) { - vscroll->set_value(vscroll->get_value() - get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size"))); + vscroll->set_value(vscroll->get_value() - get_theme_font(SNAME("normal_font"))->get_height(get_theme_font_size(SNAME("normal_font_size")))); handled = true; } if (k->is_action("ui_down") && vscroll->is_visible_in_tree()) { - vscroll->set_value(vscroll->get_value() + get_theme_font("normal_font")->get_height(get_theme_font_size("normal_font_size"))); + vscroll->set_value(vscroll->get_value() + get_theme_font(SNAME("normal_font"))->get_height(get_theme_font_size(SNAME("normal_font_size")))); handled = true; } if (k->is_action("ui_home") && vscroll->is_visible_in_tree()) { @@ -1693,15 +1693,15 @@ void RichTextLabel::_gui_input(Ref<InputEvent> p_event) { if (c_item && !outside && _find_meta(c_item, &meta, &item_meta)) { if (meta_hovering != item_meta) { if (meta_hovering) { - emit_signal("meta_hover_ended", current_meta); + emit_signal(SNAME("meta_hover_ended"), current_meta); } meta_hovering = item_meta; current_meta = meta; - emit_signal("meta_hover_started", meta); + emit_signal(SNAME("meta_hover_started"), meta); } } else if (meta_hovering) { meta_hovering = nullptr; - emit_signal("meta_hover_ended", current_meta); + emit_signal(SNAME("meta_hover_ended"), current_meta); current_meta = false; } } @@ -2105,8 +2105,8 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { } Rect2 text_rect = _get_text_rect(); - Ref<Font> base_font = get_theme_font("normal_font"); - int base_font_size = get_theme_font_size("normal_font_size"); + Ref<Font> base_font = get_theme_font(SNAME("normal_font")); + int base_font_size = get_theme_font_size(SNAME("normal_font_size")); for (int i = p_frame->first_resized_line; i < p_frame->lines.size(); i++) { _resize_line(p_frame, i, base_font, base_font_size, text_rect.get_size().width - scroll_w); @@ -2140,8 +2140,8 @@ void RichTextLabel::_validate_line_caches(ItemFrame *p_frame) { } Rect2 text_rect = _get_text_rect(); - Ref<Font> base_font = get_theme_font("normal_font"); - int base_font_size = get_theme_font_size("normal_font_size"); + Ref<Font> base_font = get_theme_font(SNAME("normal_font")); + int base_font_size = get_theme_font_size(SNAME("normal_font_size")); int total_chars = (p_frame->first_invalid_line == 0) ? 0 : (p_frame->lines[p_frame->first_invalid_line].char_offset + p_frame->lines[p_frame->first_invalid_line].char_count); for (int i = p_frame->first_invalid_line; i < p_frame->lines.size(); i++) { @@ -2406,35 +2406,35 @@ void RichTextLabel::push_font(const Ref<Font> &p_font) { } void RichTextLabel::push_normal() { - Ref<Font> normal_font = get_theme_font("normal_font"); + Ref<Font> normal_font = get_theme_font(SNAME("normal_font")); ERR_FAIL_COND(normal_font.is_null()); push_font(normal_font); } void RichTextLabel::push_bold() { - Ref<Font> bold_font = get_theme_font("bold_font"); + Ref<Font> bold_font = get_theme_font(SNAME("bold_font")); ERR_FAIL_COND(bold_font.is_null()); push_font(bold_font); } void RichTextLabel::push_bold_italics() { - Ref<Font> bold_italics_font = get_theme_font("bold_italics_font"); + Ref<Font> bold_italics_font = get_theme_font(SNAME("bold_italics_font")); ERR_FAIL_COND(bold_italics_font.is_null()); push_font(bold_italics_font); } void RichTextLabel::push_italics() { - Ref<Font> italics_font = get_theme_font("italics_font"); + Ref<Font> italics_font = get_theme_font(SNAME("italics_font")); ERR_FAIL_COND(italics_font.is_null()); push_font(italics_font); } void RichTextLabel::push_mono() { - Ref<Font> mono_font = get_theme_font("mono_font"); + Ref<Font> mono_font = get_theme_font(SNAME("mono_font")); ERR_FAIL_COND(mono_font.is_null()); push_font(mono_font); @@ -2774,13 +2774,13 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { int pos = 0; List<String> tag_stack; - Ref<Font> normal_font = get_theme_font("normal_font"); - Ref<Font> bold_font = get_theme_font("bold_font"); - Ref<Font> italics_font = get_theme_font("italics_font"); - Ref<Font> bold_italics_font = get_theme_font("bold_italics_font"); - Ref<Font> mono_font = get_theme_font("mono_font"); + Ref<Font> normal_font = get_theme_font(SNAME("normal_font")); + Ref<Font> bold_font = get_theme_font(SNAME("bold_font")); + Ref<Font> italics_font = get_theme_font(SNAME("italics_font")); + Ref<Font> bold_italics_font = get_theme_font(SNAME("bold_italics_font")); + Ref<Font> mono_font = get_theme_font(SNAME("mono_font")); - Color base_color = get_theme_color("default_color"); + Color base_color = get_theme_color(SNAME("default_color")); int indent_level = 0; @@ -3140,11 +3140,11 @@ Error RichTextLabel::append_bbcode(const String &p_bbcode) { tag_stack.push_front("url"); } else if (tag.begins_with("dropcap")) { Vector<String> subtag = tag.substr(5, tag.length()).split(" "); - Ref<Font> f = get_theme_font("normal_font"); - int fs = get_theme_font_size("normal_font_size") * 3; - Color color = get_theme_color("default_color"); - Color outline_color = get_theme_color("outline_color"); - int outline_size = get_theme_constant("outline_size"); + Ref<Font> f = get_theme_font(SNAME("normal_font")); + int fs = get_theme_font_size(SNAME("normal_font_size")) * 3; + Color color = get_theme_color(SNAME("default_color")); + Color outline_color = get_theme_color(SNAME("outline_color")); + int outline_size = get_theme_constant(SNAME("outline_size")); Rect2 dropcap_margins = Rect2(); for (int i = 0; i < subtag.size(); i++) { @@ -4168,7 +4168,7 @@ void RichTextLabel::set_fixed_size_to_width(int p_width) { } Size2 RichTextLabel::get_minimum_size() const { - Ref<StyleBox> style = get_theme_stylebox("normal"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("normal")); Size2 size = style->get_minimum_size(); if (fixed_width != -1) { diff --git a/scene/gui/scroll_bar.cpp b/scene/gui/scroll_bar.cpp index 62276e3af0..ce04a0204b 100644 --- a/scene/gui/scroll_bar.cpp +++ b/scene/gui/scroll_bar.cpp @@ -46,7 +46,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { Ref<InputEventMouseMotion> m = p_event; if (!m.is_valid() || drag.active) { - emit_signal("scrolling"); + emit_signal(SNAME("scrolling")); } Ref<InputEventMouseButton> b = p_event; @@ -70,8 +70,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (b->is_pressed()) { double ofs = orientation == VERTICAL ? b->get_position().y : b->get_position().x; - Ref<Texture2D> decr = get_theme_icon("decrement"); - Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -140,7 +140,7 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { if (drag.active) { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); ofs -= decr_size; @@ -150,8 +150,8 @@ void ScrollBar::_gui_input(Ref<InputEvent> p_event) { set_as_ratio(drag.value_at_click + diff); } else { double ofs = orientation == VERTICAL ? m->get_position().y : m->get_position().x; - Ref<Texture2D> decr = get_theme_icon("decrement"); - Ref<Texture2D> incr = get_theme_icon("increment"); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); double decr_size = orientation == VERTICAL ? decr->get_height() : decr->get_width(); double incr_size = orientation == VERTICAL ? incr->get_height() : incr->get_width(); @@ -215,17 +215,17 @@ void ScrollBar::_notification(int p_what) { if (p_what == NOTIFICATION_DRAW) { RID ci = get_canvas_item(); - Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon("decrement_highlight") : get_theme_icon("decrement"); - Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_theme_icon("increment_highlight") : get_theme_icon("increment"); - Ref<StyleBox> bg = has_focus() ? get_theme_stylebox("scroll_focus") : get_theme_stylebox("scroll"); + Ref<Texture2D> decr = highlight == HIGHLIGHT_DECR ? get_theme_icon(SNAME("decrement_highlight")) : get_theme_icon(SNAME("decrement")); + Ref<Texture2D> incr = highlight == HIGHLIGHT_INCR ? get_theme_icon(SNAME("increment_highlight")) : get_theme_icon(SNAME("increment")); + 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("grabber_pressed"); + grabber = get_theme_stylebox(SNAME("grabber_pressed")); } else if (highlight == HIGHLIGHT_RANGE) { - grabber = get_theme_stylebox("grabber_highlight"); + grabber = get_theme_stylebox(SNAME("grabber_highlight")); } else { - grabber = get_theme_stylebox("grabber"); + grabber = get_theme_stylebox(SNAME("grabber")); } Point2 ofs; @@ -389,7 +389,7 @@ void ScrollBar::_notification(int p_what) { } double ScrollBar::get_grabber_min_size() const { - Ref<StyleBox> grabber = get_theme_stylebox("grabber"); + Ref<StyleBox> grabber = get_theme_stylebox(SNAME("grabber")); Size2 gminsize = grabber->get_minimum_size() + grabber->get_center_size(); return (orientation == VERTICAL) ? gminsize.height : gminsize.width; } @@ -415,17 +415,17 @@ double ScrollBar::get_area_size() const { switch (orientation) { case VERTICAL: { double area = get_size().height; - area -= get_theme_stylebox("scroll")->get_minimum_size().height; - area -= get_theme_icon("increment")->get_height(); - area -= get_theme_icon("decrement")->get_height(); + area -= get_theme_stylebox(SNAME("scroll"))->get_minimum_size().height; + area -= get_theme_icon(SNAME("increment"))->get_height(); + area -= get_theme_icon(SNAME("decrement"))->get_height(); area -= get_grabber_min_size(); return area; } break; case HORIZONTAL: { double area = get_size().width; - area -= get_theme_stylebox("scroll")->get_minimum_size().width; - area -= get_theme_icon("increment")->get_width(); - area -= get_theme_icon("decrement")->get_width(); + area -= get_theme_stylebox(SNAME("scroll"))->get_minimum_size().width; + area -= get_theme_icon(SNAME("increment"))->get_width(); + area -= get_theme_icon(SNAME("decrement"))->get_width(); area -= get_grabber_min_size(); return area; } break; @@ -439,13 +439,13 @@ double ScrollBar::get_area_offset() const { double ofs = 0.0; if (orientation == VERTICAL) { - ofs += get_theme_stylebox("hscroll")->get_margin(SIDE_TOP); - ofs += get_theme_icon("decrement")->get_height(); + ofs += get_theme_stylebox(SNAME("hscroll"))->get_margin(SIDE_TOP); + ofs += get_theme_icon(SNAME("decrement"))->get_height(); } if (orientation == HORIZONTAL) { - ofs += get_theme_stylebox("hscroll")->get_margin(SIDE_LEFT); - ofs += get_theme_icon("decrement")->get_width(); + ofs += get_theme_stylebox(SNAME("hscroll"))->get_margin(SIDE_LEFT); + ofs += get_theme_icon(SNAME("decrement"))->get_width(); } return ofs; @@ -456,9 +456,9 @@ double ScrollBar::get_grabber_offset() const { } Size2 ScrollBar::get_minimum_size() const { - Ref<Texture2D> incr = get_theme_icon("increment"); - Ref<Texture2D> decr = get_theme_icon("decrement"); - Ref<StyleBox> bg = get_theme_stylebox("scroll"); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); + Ref<StyleBox> bg = get_theme_stylebox(SNAME("scroll")); Size2 minsize; if (orientation == VERTICAL) { diff --git a/scene/gui/scroll_container.cpp b/scene/gui/scroll_container.cpp index 177f146b6a..eb5fc924da 100644 --- a/scene/gui/scroll_container.cpp +++ b/scene/gui/scroll_container.cpp @@ -33,7 +33,7 @@ #include "scene/main/window.h" Size2 ScrollContainer::get_minimum_size() const { - Ref<StyleBox> sb = get_theme_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg")); Size2 min_size; for (int i = 0; i < get_child_count(); i++) { @@ -77,7 +77,7 @@ void ScrollContainer::_cancel_drag() { drag_from = Vector2(); if (beyond_deadzone) { - emit_signal("scroll_ended"); + emit_signal(SNAME("scroll_ended")); propagate_notification(NOTIFICATION_SCROLL_END); beyond_deadzone = false; } @@ -173,7 +173,7 @@ void ScrollContainer::_gui_input(const Ref<InputEvent> &p_gui_input) { if (beyond_deadzone || (scroll_h && Math::abs(drag_accum.x) > deadzone) || (scroll_v && Math::abs(drag_accum.y) > deadzone)) { if (!beyond_deadzone) { propagate_notification(NOTIFICATION_SCROLL_BEGIN); - emit_signal("scroll_started"); + emit_signal(SNAME("scroll_started")); beyond_deadzone = true; // resetting drag_accum here ensures smooth scrolling after reaching deadzone @@ -260,7 +260,7 @@ void ScrollContainer::_update_dimensions() { Size2 size = get_size(); Point2 ofs; - Ref<StyleBox> sb = get_theme_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg")); size -= sb->get_minimum_size(); ofs += sb->get_offset(); bool rtl = is_layout_rtl(); @@ -319,7 +319,7 @@ 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("_update_scrollbar_position"); + call_deferred(SNAME("_update_scrollbar_position")); }; if (p_what == NOTIFICATION_READY) { @@ -332,7 +332,7 @@ void ScrollContainer::_notification(int p_what) { }; if (p_what == NOTIFICATION_DRAW) { - Ref<StyleBox> sb = get_theme_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg")); draw_style_box(sb, Rect2(Vector2(), get_size())); update_scrollbars(); @@ -409,7 +409,7 @@ void ScrollContainer::_notification(int p_what) { void ScrollContainer::update_scrollbars() { Size2 size = get_size(); - Ref<StyleBox> sb = get_theme_stylebox("bg"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("bg")); size -= sb->get_minimum_size(); Size2 hmin; diff --git a/scene/gui/separator.cpp b/scene/gui/separator.cpp index 3cb8ccf135..1f3cb7aa24 100644 --- a/scene/gui/separator.cpp +++ b/scene/gui/separator.cpp @@ -33,9 +33,9 @@ Size2 Separator::get_minimum_size() const { Size2 ms(3, 3); if (orientation == VERTICAL) { - ms.x = get_theme_constant("separation"); + ms.x = get_theme_constant(SNAME("separation")); } else { // HORIZONTAL - ms.y = get_theme_constant("separation"); + ms.y = get_theme_constant(SNAME("separation")); } return ms; } @@ -44,7 +44,7 @@ void Separator::_notification(int p_what) { switch (p_what) { case NOTIFICATION_DRAW: { Size2i size = get_size(); - Ref<StyleBox> style = get_theme_stylebox("separator"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("separator")); Size2i ssize = style->get_minimum_size() + style->get_center_size(); if (orientation == VERTICAL) { diff --git a/scene/gui/slider.cpp b/scene/gui/slider.cpp index 5947f3b99e..61b5325175 100644 --- a/scene/gui/slider.cpp +++ b/scene/gui/slider.cpp @@ -32,10 +32,10 @@ #include "core/os/keyboard.h" Size2 Slider::get_minimum_size() const { - Ref<StyleBox> style = get_theme_stylebox("slider"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("slider")); Size2i ss = style->get_minimum_size() + style->get_center_size(); - Ref<Texture2D> grabber = get_theme_icon("grabber"); + Ref<Texture2D> grabber = get_theme_icon(SNAME("grabber")); Size2i rs = grabber->get_size(); if (orientation == HORIZONTAL) { @@ -89,7 +89,7 @@ void Slider::_gui_input(Ref<InputEvent> p_event) { if (mm.is_valid()) { if (grab.active) { Size2i size = get_size(); - Ref<Texture2D> grabber = get_theme_icon("grabber"); + Ref<Texture2D> grabber = get_theme_icon(SNAME("grabber")); float motion = (orientation == VERTICAL ? mm->get_position().y : mm->get_position().x) - grab.pos; if (orientation == VERTICAL) { motion = -motion; @@ -161,11 +161,11 @@ void Slider::_notification(int p_what) { case NOTIFICATION_DRAW: { RID ci = get_canvas_item(); Size2i size = get_size(); - Ref<StyleBox> style = get_theme_stylebox("slider"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("slider")); bool highlighted = mouse_inside || has_focus(); Ref<StyleBox> grabber_area = get_theme_stylebox(highlighted ? "grabber_area_highlight" : "grabber_area"); Ref<Texture2D> grabber = get_theme_icon(editable ? (highlighted ? "grabber_highlight" : "grabber") : "grabber_disabled"); - Ref<Texture2D> tick = get_theme_icon("tick"); + Ref<Texture2D> tick = get_theme_icon(SNAME("tick")); double ratio = Math::is_nan(get_as_ratio()) ? 0 : get_as_ratio(); if (orientation == VERTICAL) { diff --git a/scene/gui/spin_box.cpp b/scene/gui/spin_box.cpp index 5c7b375608..3f0368a4e2 100644 --- a/scene/gui/spin_box.cpp +++ b/scene/gui/spin_box.cpp @@ -188,7 +188,7 @@ 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("updown"); + Ref<Texture2D> updown = get_theme_icon(SNAME("updown")); _adjust_width_for_icon(updown); @@ -204,15 +204,15 @@ void SpinBox::_notification(int p_what) { } else if (p_what == NOTIFICATION_FOCUS_EXIT) { //_value_changed(0); } else if (p_what == NOTIFICATION_ENTER_TREE) { - _adjust_width_for_icon(get_theme_icon("updown")); + _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("minimum_size_changed"); - get_line_edit()->call_deferred("minimum_size_changed"); + call_deferred(SNAME("minimum_size_changed")); + get_line_edit()->call_deferred(SNAME("minimum_size_changed")); } else if (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || p_what == NOTIFICATION_TRANSLATION_CHANGED) { update(); } diff --git a/scene/gui/split_container.cpp b/scene/gui/split_container.cpp index 9796b32c6b..3114e5b7c0 100644 --- a/scene/gui/split_container.cpp +++ b/scene/gui/split_container.cpp @@ -76,8 +76,8 @@ void SplitContainer::_resort() { bool second_expanded = (vertical ? second->get_v_size_flags() : second->get_h_size_flags()) & SIZE_EXPAND; // Determine the separation between items - Ref<Texture2D> g = get_theme_icon("grabber"); - int sep = get_theme_constant("separation"); + Ref<Texture2D> g = get_theme_icon(SNAME("grabber")); + int sep = get_theme_constant(SNAME("separation")); sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0; // Compute the minimum size @@ -131,8 +131,8 @@ Size2 SplitContainer::get_minimum_size() const { /* Calculate MINIMUM SIZE */ Size2i minimum; - Ref<Texture2D> g = get_theme_icon("grabber"); - int sep = get_theme_constant("separation"); + Ref<Texture2D> g = get_theme_icon(SNAME("grabber")); + int sep = get_theme_constant(SNAME("separation")); sep = (dragger_visibility != DRAGGER_HIDDEN_COLLAPSED) ? MAX(sep, vertical ? g->get_height() : g->get_width()) : 0; for (int i = 0; i < 2; i++) { @@ -173,7 +173,7 @@ void SplitContainer::_notification(int p_what) { } break; case NOTIFICATION_MOUSE_EXIT: { mouse_inside = false; - if (get_theme_constant("autohide")) { + if (get_theme_constant(SNAME("autohide"))) { update(); } } break; @@ -182,7 +182,7 @@ void SplitContainer::_notification(int p_what) { return; } - if (collapsed || (!dragging && !mouse_inside && get_theme_constant("autohide"))) { + if (collapsed || (!dragging && !mouse_inside && get_theme_constant(SNAME("autohide")))) { return; } @@ -190,8 +190,8 @@ void SplitContainer::_notification(int p_what) { return; } - int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant("separation") : 0; - Ref<Texture2D> tex = get_theme_icon("grabber"); + int sep = dragger_visibility != DRAGGER_HIDDEN_COLLAPSED ? get_theme_constant(SNAME("separation")) : 0; + Ref<Texture2D> tex = get_theme_icon(SNAME("grabber")); Size2 size = get_size(); if (vertical) { @@ -218,7 +218,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { if (mb.is_valid()) { if (mb->get_button_index() == MOUSE_BUTTON_LEFT) { if (mb->is_pressed()) { - int sep = get_theme_constant("separation"); + int sep = get_theme_constant(SNAME("separation")); if (vertical) { if (mb->get_position().y > middle_sep && mb->get_position().y < middle_sep + sep) { @@ -244,14 +244,14 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { if (mm.is_valid()) { bool mouse_inside_state = false; if (vertical) { - mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant("separation"); + mouse_inside_state = mm->get_position().y > middle_sep && mm->get_position().y < middle_sep + get_theme_constant(SNAME("separation")); } else { - mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant("separation"); + mouse_inside_state = mm->get_position().x > middle_sep && mm->get_position().x < middle_sep + get_theme_constant(SNAME("separation")); } if (mouse_inside != mouse_inside_state) { mouse_inside = mouse_inside_state; - if (get_theme_constant("autohide")) { + if (get_theme_constant(SNAME("autohide"))) { update(); } } @@ -267,7 +267,7 @@ void SplitContainer::_gui_input(const Ref<InputEvent> &p_event) { } should_clamp_split_offset = true; queue_sort(); - emit_signal("dragged", get_split_offset()); + emit_signal(SNAME("dragged"), get_split_offset()); } } @@ -277,7 +277,7 @@ Control::CursorShape SplitContainer::get_cursor_shape(const Point2 &p_pos) const } if (!collapsed && _getch(0) && _getch(1) && dragger_visibility == DRAGGER_VISIBLE) { - int sep = get_theme_constant("separation"); + int sep = get_theme_constant(SNAME("separation")); if (vertical) { if (p_pos.y > middle_sep && p_pos.y < middle_sep + sep) { diff --git a/scene/gui/tab_container.cpp b/scene/gui/tab_container.cpp index 133966013b..8f84585f9b 100644 --- a/scene/gui/tab_container.cpp +++ b/scene/gui/tab_container.cpp @@ -43,9 +43,9 @@ int TabContainer::_get_top_margin() const { } // Respect the minimum tab height. - Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected"); - Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected"); - Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected")); + Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected")); + Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled")); int tab_height = MAX(MAX(tab_unselected->get_minimum_size().height, tab_selected->get_minimum_size().height), tab_disabled->get_minimum_size().height); @@ -88,11 +88,11 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { } // Handle menu button. - Ref<Texture2D> menu = get_theme_icon("menu"); + Ref<Texture2D> menu = get_theme_icon(SNAME("menu")); if (is_layout_rtl()) { if (popup && pos.x < menu->get_width()) { - emit_signal("pre_popup_pressed"); + emit_signal(SNAME("pre_popup_pressed")); Vector2 popup_pos = get_screen_position(); popup_pos.y += menu->get_height(); @@ -103,7 +103,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { } } else { if (popup && pos.x > size.width - menu->get_width()) { - emit_signal("pre_popup_pressed"); + emit_signal(SNAME("pre_popup_pressed")); Vector2 popup_pos = get_screen_position(); popup_pos.x += size.width - popup->get_size().width; @@ -129,8 +129,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { popup_ofs = menu->get_width(); } - Ref<Texture2D> increment = get_theme_icon("increment"); - Ref<Texture2D> decrement = get_theme_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement")); if (is_layout_rtl()) { if (pos.x < popup_ofs + decrement->get_width()) { if (last_tab_cache < tabs.size() - 1) { @@ -203,7 +203,7 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { return; } - Ref<Texture2D> menu = get_theme_icon("menu"); + Ref<Texture2D> menu = get_theme_icon(SNAME("menu")); if (popup) { if (is_layout_rtl()) { if (pos.x <= menu->get_width()) { @@ -248,8 +248,8 @@ void TabContainer::_gui_input(const Ref<InputEvent> &p_event) { popup_ofs = menu->get_width(); } - Ref<Texture2D> increment = get_theme_icon("increment"); - Ref<Texture2D> decrement = get_theme_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement")); if (is_layout_rtl()) { if (pos.x <= popup_ofs + decrement->get_width()) { @@ -289,10 +289,10 @@ void TabContainer::_notification(int p_what) { switch (p_what) { case NOTIFICATION_RESIZED: { Vector<Control *> tabs = _get_tabs(); - int side_margin = get_theme_constant("side_margin"); - Ref<Texture2D> menu = get_theme_icon("menu"); - Ref<Texture2D> increment = get_theme_icon("increment"); - Ref<Texture2D> decrement = get_theme_icon("decrement"); + int side_margin = get_theme_constant(SNAME("side_margin")); + Ref<Texture2D> menu = get_theme_icon(SNAME("menu")); + Ref<Texture2D> increment = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement")); int header_width = get_size().width - side_margin * 2; // Find the width of the header area. @@ -332,26 +332,26 @@ void TabContainer::_notification(int p_what) { bool rtl = is_layout_rtl(); // Draw only the tab area if the header is hidden. - Ref<StyleBox> panel = get_theme_stylebox("panel"); + Ref<StyleBox> panel = get_theme_stylebox(SNAME("panel")); if (!tabs_visible) { panel->draw(canvas, Rect2(0, 0, size.width, size.height)); return; } Vector<Control *> tabs = _get_tabs(); - Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected"); - Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected"); - Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); - Ref<Texture2D> increment = get_theme_icon("increment"); - Ref<Texture2D> increment_hl = get_theme_icon("increment_highlight"); - Ref<Texture2D> decrement = get_theme_icon("decrement"); - Ref<Texture2D> decrement_hl = get_theme_icon("decrement_highlight"); - Ref<Texture2D> menu = get_theme_icon("menu"); - Ref<Texture2D> menu_hl = get_theme_icon("menu_highlight"); - Color font_selected_color = get_theme_color("font_selected_color"); - Color font_unselected_color = get_theme_color("font_unselected_color"); - Color font_disabled_color = get_theme_color("font_disabled_color"); - int side_margin = get_theme_constant("side_margin"); + Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected")); + Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected")); + Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled")); + Ref<Texture2D> increment = get_theme_icon(SNAME("increment")); + Ref<Texture2D> increment_hl = get_theme_icon(SNAME("increment_highlight")); + Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement")); + Ref<Texture2D> decrement_hl = get_theme_icon(SNAME("decrement_highlight")); + Ref<Texture2D> menu = get_theme_icon(SNAME("menu")); + Ref<Texture2D> menu_hl = get_theme_icon(SNAME("menu_highlight")); + Color font_selected_color = get_theme_color(SNAME("font_selected_color")); + Color font_unselected_color = get_theme_color(SNAME("font_unselected_color")); + Color font_disabled_color = get_theme_color(SNAME("font_disabled_color")); + int side_margin = get_theme_constant(SNAME("side_margin")); // Find out start and width of the header area. int header_x = side_margin; @@ -529,7 +529,7 @@ void TabContainer::_notification(int p_what) { text_buf.write[i]->clear(); } _theme_changing = true; - call_deferred("_on_theme_changed"); // Wait until all changed theme. + call_deferred(SNAME("_on_theme_changed")); // Wait until all changed theme. } break; } } @@ -537,10 +537,10 @@ void TabContainer::_notification(int p_what) { void TabContainer::_draw_tab(Ref<StyleBox> &p_tab_style, Color &p_font_color, int p_index, float p_x) { Vector<Control *> tabs = _get_tabs(); RID canvas = get_canvas_item(); - Ref<Font> font = get_theme_font("font"); - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); - int icon_text_distance = get_theme_constant("icon_separation"); + Ref<Font> font = get_theme_font(SNAME("font")); + Color font_outline_color = get_theme_color(SNAME("font_outline_color")); + int outline_size = get_theme_constant(SNAME("outline_size")); + int icon_text_distance = get_theme_constant(SNAME("icon_separation")); int tab_width = _get_tab_width(p_index); int header_height = _get_top_margin(); @@ -580,8 +580,8 @@ void TabContainer::_refresh_texts() { text_buf.clear(); Vector<Control *> tabs = _get_tabs(); bool rtl = is_layout_rtl(); - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + Ref<Font> font = get_theme_font(SNAME("font")); + int font_size = get_theme_font_size(SNAME("font_size")); for (int i = 0; i < tabs.size(); i++) { Control *control = Object::cast_to<Control>(tabs[i]); String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); @@ -609,7 +609,7 @@ void TabContainer::_on_theme_changed() { } void TabContainer::_repaint() { - Ref<StyleBox> sb = get_theme_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel")); Vector<Control *> tabs = _get_tabs(); for (int i = 0; i < tabs.size(); i++) { Control *c = tabs[i]; @@ -646,8 +646,8 @@ int TabContainer::_get_tab_width(int p_index) const { } // Get the width of the text displayed on the tab. - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + Ref<Font> font = get_theme_font(SNAME("font")); + int font_size = get_theme_font_size(SNAME("font_size")); String text = control->has_meta("_tab_name") ? String(tr(String(control->get_meta("_tab_name")))) : String(tr(control->get_name())); int width = font->get_string_size(text, font_size).width; @@ -657,15 +657,15 @@ int TabContainer::_get_tab_width(int p_index) const { if (icon.is_valid()) { width += icon->get_width(); if (text != "") { - width += get_theme_constant("icon_separation"); + width += get_theme_constant(SNAME("icon_separation")); } } } // Respect a minimum size. - Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected"); - Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected"); - Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected")); + Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected")); + Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled")); if (get_tab_disabled(p_index)) { width += tab_disabled->get_minimum_size().width; } else if (p_index == current) { @@ -715,7 +715,7 @@ void TabContainer::add_child_notify(Node *p_child) { c->hide(); } else { c->show(); - //call_deferred("set_current_tab",0); + //call_deferred(SNAME("set_current_tab"),0); first = true; current = 0; previous = 0; @@ -724,7 +724,7 @@ void TabContainer::add_child_notify(Node *p_child) { if (tabs_visible) { c->set_offset(SIDE_TOP, _get_top_margin()); } - Ref<StyleBox> sb = get_theme_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel")); c->set_offset(Side(SIDE_TOP), c->get_offset(Side(SIDE_TOP)) + sb->get_margin(Side(SIDE_TOP))); c->set_offset(Side(SIDE_LEFT), c->get_offset(Side(SIDE_LEFT)) + sb->get_margin(Side(SIDE_LEFT))); c->set_offset(Side(SIDE_RIGHT), c->get_offset(Side(SIDE_RIGHT)) - sb->get_margin(Side(SIDE_RIGHT))); @@ -732,13 +732,13 @@ void TabContainer::add_child_notify(Node *p_child) { update(); p_child->connect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback)); if (first && is_inside_tree()) { - emit_signal("tab_changed", current); + emit_signal(SNAME("tab_changed"), current); } } void TabContainer::move_child_notify(Node *p_child) { Container::move_child_notify(p_child); - call_deferred("_update_current_tab"); + call_deferred(SNAME("_update_current_tab")); _refresh_texts(); update(); } @@ -756,11 +756,11 @@ void TabContainer::set_current_tab(int p_current) { _repaint(); if (pending_previous == current) { - emit_signal("tab_selected", current); + emit_signal(SNAME("tab_selected"), current); } else { previous = pending_previous; - emit_signal("tab_selected", current); - emit_signal("tab_changed", current); + emit_signal(SNAME("tab_selected"), current); + emit_signal(SNAME("tab_changed"), current); } update(); @@ -799,7 +799,7 @@ void TabContainer::remove_child_notify(Node *p_child) { return; } - call_deferred("_update_current_tab"); + call_deferred(SNAME("_update_current_tab")); p_child->disconnect("renamed", callable_mp(this, &TabContainer::_child_renamed_callback)); @@ -913,7 +913,7 @@ void TabContainer::drop_data(const Point2 &p_point, const Variant &p_data) { } move_child(moving_tabc, hover_now); set_current_tab(hover_now); - emit_signal("tab_changed", hover_now); + emit_signal(SNAME("tab_changed"), hover_now); } } } @@ -944,12 +944,12 @@ int TabContainer::get_tab_idx_at_point(const Point2 &p_point) const { Popup *popup = get_popup(); if (popup) { - Ref<Texture2D> menu = get_theme_icon("menu"); + Ref<Texture2D> menu = get_theme_icon(SNAME("menu")); button_ofs += menu->get_width(); } if (buttons_visible_cache) { - Ref<Texture2D> increment = get_theme_icon("increment"); - Ref<Texture2D> decrement = get_theme_icon("decrement"); + Ref<Texture2D> increment = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decrement = get_theme_icon(SNAME("decrement")); button_ofs += increment->get_width() + decrement->get_width(); } if (px > size.width - button_ofs) { @@ -1136,17 +1136,17 @@ Size2 TabContainer::get_minimum_size() const { ms.y = MAX(ms.y, cms.y); } - Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected"); - Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected"); - Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); - Ref<Font> font = get_theme_font("font"); + Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected")); + Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected")); + Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled")); + Ref<Font> font = get_theme_font(SNAME("font")); if (tabs_visible) { ms.y += MAX(MAX(tab_unselected->get_minimum_size().y, tab_selected->get_minimum_size().y), tab_disabled->get_minimum_size().y); ms.y += _get_top_margin(); } - Ref<StyleBox> sb = get_theme_stylebox("panel"); + Ref<StyleBox> sb = get_theme_stylebox(SNAME("panel")); ms += sb->get_minimum_size(); return ms; diff --git a/scene/gui/tabs.cpp b/scene/gui/tabs.cpp index 6f1cff9ec8..9e8fe27ffb 100644 --- a/scene/gui/tabs.cpp +++ b/scene/gui/tabs.cpp @@ -38,9 +38,9 @@ #include "scene/gui/texture_rect.h" Size2 Tabs::get_minimum_size() const { - Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected"); - Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected"); - Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected")); + Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected")); + Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled")); int y_margin = MAX(MAX(tab_unselected->get_minimum_size().height, tab_selected->get_minimum_size().height), tab_disabled->get_minimum_size().height); @@ -51,7 +51,7 @@ Size2 Tabs::get_minimum_size() const { if (tex.is_valid()) { ms.height = MAX(ms.height, tex->get_size().height); if (tabs[i].text != "") { - ms.width += get_theme_constant("hseparation"); + ms.width += get_theme_constant(SNAME("hseparation")); } } @@ -69,15 +69,15 @@ Size2 Tabs::get_minimum_size() const { if (tabs[i].right_button.is_valid()) { Ref<Texture2D> rb = tabs[i].right_button; Size2 bms = rb->get_size(); - bms.width += get_theme_constant("hseparation"); + bms.width += get_theme_constant(SNAME("hseparation")); ms.width += bms.width; ms.height = MAX(bms.height + tab_unselected->get_minimum_size().height, ms.height); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<Texture2D> cb = get_theme_icon("close"); + Ref<Texture2D> cb = get_theme_icon(SNAME("close")); Size2 bms = cb->get_size(); - bms.width += get_theme_constant("hseparation"); + bms.width += get_theme_constant(SNAME("hseparation")); ms.width += bms.width; ms.height = MAX(bms.height + tab_unselected->get_minimum_size().height, ms.height); } @@ -100,8 +100,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { highlight_arrow = -1; if (buttons_visible) { - Ref<Texture2D> incr = get_theme_icon("increment"); - Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); if (is_layout_rtl()) { if (pos.x < decr->get_width()) { @@ -148,7 +148,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { if (rb_pressing && !mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) { if (rb_hover != -1) { //pressed - emit_signal("right_button_pressed", rb_hover); + emit_signal(SNAME("right_button_pressed"), rb_hover); } rb_pressing = false; @@ -158,7 +158,7 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { if (cb_pressing && !mb->is_pressed() && mb->get_button_index() == MOUSE_BUTTON_LEFT) { if (cb_hover != -1) { //pressed - emit_signal("tab_closed", cb_hover); + emit_signal(SNAME("tab_closed"), cb_hover); } cb_pressing = false; @@ -170,8 +170,8 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { Point2 pos(mb->get_position().x, mb->get_position().y); if (buttons_visible) { - Ref<Texture2D> incr = get_theme_icon("increment"); - Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); if (is_layout_rtl()) { if (pos.x < decr->get_width()) { @@ -229,15 +229,15 @@ void Tabs::_gui_input(const Ref<InputEvent> &p_event) { if (found != -1) { set_current_tab(found); - emit_signal("tab_clicked", found); + emit_signal(SNAME("tab_clicked"), found); } } } } void Tabs::_shape(int p_tab) { - Ref<Font> font = get_theme_font("font"); - int font_size = get_theme_font_size("font_size"); + Ref<Font> font = get_theme_font(SNAME("font")); + int font_size = get_theme_font_size(SNAME("font_size")); tabs.write[p_tab].xl_text = tr(tabs[p_tab].text); tabs.write[p_tab].text_buf->clear(); @@ -274,15 +274,15 @@ void Tabs::_notification(int p_what) { _update_cache(); RID ci = get_canvas_item(); - Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected"); - Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected"); - Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); - Color font_selected_color = get_theme_color("font_selected_color"); - Color font_unselected_color = get_theme_color("font_unselected_color"); - Color font_disabled_color = get_theme_color("font_disabled_color"); - Ref<Texture2D> close = get_theme_icon("close"); - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); + Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected")); + Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected")); + Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled")); + Color font_selected_color = get_theme_color(SNAME("font_selected_color")); + Color font_unselected_color = get_theme_color(SNAME("font_unselected_color")); + Color font_disabled_color = get_theme_color(SNAME("font_disabled_color")); + Ref<Texture2D> close = get_theme_icon(SNAME("close")); + Color font_outline_color = get_theme_color(SNAME("font_outline_color")); + int outline_size = get_theme_constant(SNAME("outline_size")); Vector2 size = get_size(); bool rtl = is_layout_rtl(); @@ -306,10 +306,10 @@ void Tabs::_notification(int p_what) { w = 0; } - Ref<Texture2D> incr = get_theme_icon("increment"); - Ref<Texture2D> decr = get_theme_icon("decrement"); - Ref<Texture2D> incr_hl = get_theme_icon("increment_highlight"); - Ref<Texture2D> decr_hl = get_theme_icon("decrement_highlight"); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); + Ref<Texture2D> incr_hl = get_theme_icon(SNAME("increment_highlight")); + Ref<Texture2D> decr_hl = get_theme_icon(SNAME("decrement_highlight")); int limit = get_size().width; int limit_minus_buttons = get_size().width - incr->get_width() - decr->get_width(); @@ -363,7 +363,7 @@ void Tabs::_notification(int p_what) { icon->draw(ci, Point2i(w, sb->get_margin(SIDE_TOP) + ((sb_rect.size.y - sb_ms.y) - icon->get_height()) / 2)); } if (tabs[i].text != "") { - w += icon->get_width() + get_theme_constant("hseparation"); + w += icon->get_width() + get_theme_constant(SNAME("hseparation")); } } @@ -384,10 +384,10 @@ void Tabs::_notification(int p_what) { w += tabs[i].size_text; if (tabs[i].right_button.is_valid()) { - Ref<StyleBox> style = get_theme_stylebox("button"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("button")); Ref<Texture2D> rb = tabs[i].right_button; - w += get_theme_constant("hseparation"); + w += get_theme_constant(SNAME("hseparation")); Rect2 rb_rect; rb_rect.size = style->get_minimum_size() + rb->get_size(); @@ -400,7 +400,7 @@ void Tabs::_notification(int p_what) { if (rb_hover == i) { if (rb_pressing) { - get_theme_stylebox("button_pressed")->draw(ci, rb_rect); + get_theme_stylebox(SNAME("button_pressed"))->draw(ci, rb_rect); } else { style->draw(ci, rb_rect); } @@ -416,10 +416,10 @@ void Tabs::_notification(int p_what) { } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<StyleBox> style = get_theme_stylebox("button"); + Ref<StyleBox> style = get_theme_stylebox(SNAME("button")); Ref<Texture2D> cb = close; - w += get_theme_constant("hseparation"); + w += get_theme_constant(SNAME("hseparation")); Rect2 cb_rect; cb_rect.size = style->get_minimum_size() + cb->get_size(); @@ -432,7 +432,7 @@ void Tabs::_notification(int p_what) { if (!tabs[i].disabled && cb_hover == i) { if (cb_pressing) { - get_theme_stylebox("button_pressed")->draw(ci, cb_rect); + get_theme_stylebox(SNAME("button_pressed"))->draw(ci, cb_rect); } else { style->draw(ci, cb_rect); } @@ -503,7 +503,7 @@ void Tabs::set_current_tab(int p_current) { _update_cache(); update(); - emit_signal("tab_changed", p_current); + emit_signal(SNAME("tab_changed"), p_current); } int Tabs::get_current_tab() const { @@ -659,7 +659,7 @@ void Tabs::_update_hover() { } if (hover != hover_now) { hover = hover_now; - emit_signal("tab_hovered", hover); + emit_signal(SNAME("tab_hovered"), hover); } if (hover_buttons == -1) { // no hover @@ -669,11 +669,11 @@ void Tabs::_update_hover() { } void Tabs::_update_cache() { - Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); - Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected"); - Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected"); - Ref<Texture2D> incr = get_theme_icon("increment"); - Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled")); + Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected")); + Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected")); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); int limit_minus_buttons = get_size().width - incr->get_width() - decr->get_width(); int w = 0; @@ -712,12 +712,12 @@ void Tabs::_update_cache() { slen = m_width - (sb->get_margin(SIDE_LEFT) + sb->get_margin(SIDE_RIGHT)); if (tabs[i].icon.is_valid()) { slen -= tabs[i].icon->get_width(); - slen -= get_theme_constant("hseparation"); + slen -= get_theme_constant(SNAME("hseparation")); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && i == current)) { - Ref<Texture2D> cb = get_theme_icon("close"); + Ref<Texture2D> cb = get_theme_icon(SNAME("close")); slen -= cb->get_width(); - slen -= get_theme_constant("hseparation"); + slen -= get_theme_constant(SNAME("hseparation")); } slen = MAX(slen, 1); lsize = m_width; @@ -745,7 +745,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) { t.xl_text = tr(p_str); t.text_buf.instantiate(); t.text_buf->set_direction(is_layout_rtl() ? TextServer::DIRECTION_RTL : TextServer::DIRECTION_LTR); - t.text_buf->add_string(t.xl_text, get_theme_font("font"), get_theme_font_size("font_size"), Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); + t.text_buf->add_string(t.xl_text, get_theme_font(SNAME("font")), get_theme_font_size(SNAME("font_size")), Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); t.icon = p_icon; t.disabled = false; t.ofs_cache = 0; @@ -753,7 +753,7 @@ void Tabs::add_tab(const String &p_str, const Ref<Texture2D> &p_icon) { tabs.push_back(t); _update_cache(); - call_deferred("_update_hover"); + call_deferred(SNAME("_update_hover")); update(); minimum_size_changed(); } @@ -762,7 +762,7 @@ void Tabs::clear_tabs() { tabs.clear(); current = 0; previous = 0; - call_deferred("_update_hover"); + call_deferred(SNAME("_update_hover")); update(); } @@ -773,7 +773,7 @@ void Tabs::remove_tab(int p_idx) { current--; } _update_cache(); - call_deferred("_update_hover"); + call_deferred(SNAME("_update_hover")); update(); minimum_size_changed(); @@ -870,7 +870,7 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) { hover_now = get_tab_count() - 1; } move_tab(tab_from_id, hover_now); - emit_signal("reposition_active_tab_request", hover_now); + emit_signal(SNAME("reposition_active_tab_request"), hover_now); set_current_tab(hover_now); } else if (get_tabs_rearrange_group() != -1) { // drag and drop between Tabs @@ -887,7 +887,7 @@ void Tabs::drop_data(const Point2 &p_point, const Variant &p_data) { tabs.insert(hover_now, moving_tab); from_tabs->remove_tab(tab_from_id); set_current_tab(hover_now); - emit_signal("tab_changed", hover_now); + emit_signal(SNAME("tab_changed"), hover_now); _update_cache(); } } @@ -949,9 +949,9 @@ void Tabs::move_tab(int from, int to) { int Tabs::get_tab_width(int p_idx) const { ERR_FAIL_INDEX_V(p_idx, tabs.size(), 0); - Ref<StyleBox> tab_unselected = get_theme_stylebox("tab_unselected"); - Ref<StyleBox> tab_selected = get_theme_stylebox("tab_selected"); - Ref<StyleBox> tab_disabled = get_theme_stylebox("tab_disabled"); + Ref<StyleBox> tab_unselected = get_theme_stylebox(SNAME("tab_unselected")); + Ref<StyleBox> tab_selected = get_theme_stylebox(SNAME("tab_selected")); + Ref<StyleBox> tab_disabled = get_theme_stylebox(SNAME("tab_disabled")); int x = 0; @@ -959,7 +959,7 @@ int Tabs::get_tab_width(int p_idx) const { if (tex.is_valid()) { x += tex->get_width(); if (tabs[p_idx].text != "") { - x += get_theme_constant("hseparation"); + x += get_theme_constant(SNAME("hseparation")); } } @@ -976,13 +976,13 @@ int Tabs::get_tab_width(int p_idx) const { if (tabs[p_idx].right_button.is_valid()) { Ref<Texture2D> rb = tabs[p_idx].right_button; x += rb->get_width(); - x += get_theme_constant("hseparation"); + x += get_theme_constant(SNAME("hseparation")); } if (cb_displaypolicy == CLOSE_BUTTON_SHOW_ALWAYS || (cb_displaypolicy == CLOSE_BUTTON_SHOW_ACTIVE_ONLY && p_idx == current)) { - Ref<Texture2D> cb = get_theme_icon("close"); + Ref<Texture2D> cb = get_theme_icon(SNAME("close")); x += cb->get_width(); - x += get_theme_constant("hseparation"); + x += get_theme_constant(SNAME("hseparation")); } return x; @@ -993,8 +993,8 @@ void Tabs::_ensure_no_over_offset() { return; } - Ref<Texture2D> incr = get_theme_icon("increment"); - Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); int limit = get_size().width; int limit_minus_buttons = get_size().width - incr->get_width() - decr->get_width(); @@ -1034,8 +1034,8 @@ void Tabs::ensure_tab_visible(int p_idx) { } int prev_offset = offset; - Ref<Texture2D> incr = get_theme_icon("increment"); - Ref<Texture2D> decr = get_theme_icon("decrement"); + Ref<Texture2D> incr = get_theme_icon(SNAME("increment")); + Ref<Texture2D> decr = get_theme_icon(SNAME("decrement")); int limit = get_size().width; int limit_minus_buttons = get_size().width - incr->get_width() - decr->get_width(); diff --git a/scene/gui/text_edit.cpp b/scene/gui/text_edit.cpp index 9450b39aed..be3edccc99 100644 --- a/scene/gui/text_edit.cpp +++ b/scene/gui/text_edit.cpp @@ -542,8 +542,8 @@ void TextEdit::_notification(int p_what) { } break; case NOTIFICATION_VISIBILITY_CHANGED: { if (is_visible()) { - call_deferred("_update_scrollbars"); - call_deferred("_update_wrap_at"); + call_deferred(SNAME("_update_scrollbars")); + call_deferred(SNAME("_update_wrap_at")); } } break; case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: @@ -1119,7 +1119,7 @@ void TextEdit::_notification(int p_what) { } tl->draw(ci, Point2(gutter_offset + ofs_x, yofs), get_line_gutter_item_color(line, g)); } break; - case GUTTER_TPYE_ICON: { + case GUTTER_TYPE_ICON: { const Ref<Texture2D> icon = get_line_gutter_icon(line, g); if (icon.is_null()) { break; @@ -1147,7 +1147,7 @@ void TextEdit::_notification(int p_what) { icon->draw_rect(ci, gutter_rect, false, get_line_gutter_item_color(line, g)); } break; - case GUTTER_TPYE_CUSTOM: { + case GUTTER_TYPE_CUSTOM: { if (gutter.custom_draw_obj.is_valid()) { Object *cdo = ObjectDB::get_instance(gutter.custom_draw_obj); if (cdo) { @@ -2361,7 +2361,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { } if (mpos.x > left_margin && mpos.x <= (left_margin + gutters[i].width) - 3) { - emit_signal("gutter_clicked", row, i); + emit_signal(SNAME("gutter_clicked"), row, i); return; } @@ -2473,7 +2473,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { _ensure_menu(); menu->set_position(get_screen_transform().xform(mpos)); menu->set_size(Vector2(1, 1)); - _generate_context_menu(); menu->popup(); grab_focus(); } @@ -2483,7 +2482,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { int row, col; _get_mouse_pos(Point2i(mpos.x, mpos.y), row, col); - emit_signal("symbol_lookup", highlighted_word, row, col); + emit_signal(SNAME("symbol_lookup"), highlighted_word, row, col); return; } @@ -2525,7 +2524,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (!dragging_minimap && !dragging_selection && mm->is_command_pressed() && mm->get_button_mask() == 0) { String new_word = get_word_at_pos(mpos); if (new_word != highlighted_word) { - emit_signal("symbol_validate", new_word); + emit_signal(SNAME("symbol_validate"), new_word); } } else { if (highlighted_word != String()) { @@ -2576,7 +2575,7 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { if (select_identifiers_enabled) { if (k->is_pressed() && !dragging_minimap && !dragging_selection) { Point2 mp = _get_local_mouse_pos(); - emit_signal("symbol_validate", get_word_at_pos(mp)); + emit_signal(SNAME("symbol_validate"), get_word_at_pos(mp)); } else { set_highlighted_word(String()); } @@ -2713,7 +2712,6 @@ void TextEdit::_gui_input(const Ref<InputEvent> &p_gui_input) { _ensure_menu(); menu->set_position(get_screen_transform().xform(_get_cursor_pixel_pos())); menu->set_size(Vector2(1, 1)); - _generate_context_menu(); menu->popup(); menu->grab_focus(); } @@ -2992,7 +2990,7 @@ void TextEdit::_base_insert_text(int p_line, int p_char, const String &p_text, i } text_changed_dirty = true; } - emit_signal("lines_edited_from", p_line, r_end_line); + emit_signal(SNAME("lines_edited_from"), p_line, r_end_line); } String TextEdit::_base_get_text(int p_from_line, int p_from_column, int p_to_line, int p_to_column) const { @@ -3043,7 +3041,7 @@ void TextEdit::_base_remove_text(int p_from_line, int p_from_column, int p_to_li } text_changed_dirty = true; } - emit_signal("lines_edited_from", p_to_line, p_from_line); + emit_signal(SNAME("lines_edited_from"), p_to_line, p_from_line); } void TextEdit::_insert_text(int p_line, int p_char, const String &p_text, int *r_end_line, int *r_end_char) { @@ -3214,36 +3212,6 @@ int TextEdit::_get_menu_action_accelerator(const String &p_action) { } } -void TextEdit::_generate_context_menu() { - // Reorganize context menu. - _ensure_menu(); - menu->clear(); - if (!readonly) { - menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0); - } - menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0); - if (!readonly) { - menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0); - } - menu->add_separator(); - if (is_selecting_enabled()) { - menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0); - } - if (!readonly) { - menu->add_item(RTR("Clear"), MENU_CLEAR); - menu->add_separator(); - menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0); - menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0); - } - menu->add_separator(); - menu->add_submenu_item(RTR("Text writing direction"), "DirMenu"); - menu->add_separator(); - menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC); - if (!readonly) { - menu->add_submenu_item(RTR("Insert control character"), "CTLMenu"); - } -} - int TextEdit::get_visible_rows() const { return _get_control_height() / get_row_height(); } @@ -3995,7 +3963,6 @@ void TextEdit::set_readonly(bool p_readonly) { } readonly = p_readonly; - _generate_context_menu(); update(); } @@ -4034,35 +4001,35 @@ void TextEdit::_toggle_draw_caret() { } void TextEdit::_update_caches() { - cache.style_normal = get_theme_stylebox("normal"); - cache.style_focus = get_theme_stylebox("focus"); - cache.style_readonly = get_theme_stylebox("read_only"); - cache.font = get_theme_font("font"); - cache.font_size = get_theme_font_size("font_size"); - cache.outline_color = get_theme_color("font_outline_color"); - cache.outline_size = get_theme_constant("outline_size"); - cache.caret_color = get_theme_color("caret_color"); - cache.caret_background_color = get_theme_color("caret_background_color"); - cache.font_color = get_theme_color("font_color"); - cache.font_selected_color = get_theme_color("font_selected_color"); - cache.font_readonly_color = get_theme_color("font_readonly_color"); - cache.selection_color = get_theme_color("selection_color"); - cache.current_line_color = get_theme_color("current_line_color"); - cache.line_length_guideline_color = get_theme_color("line_length_guideline_color"); - cache.code_folding_color = get_theme_color("code_folding_color", "CodeEdit"); - cache.brace_mismatch_color = get_theme_color("brace_mismatch_color"); - cache.word_highlighted_color = get_theme_color("word_highlighted_color"); - cache.search_result_color = get_theme_color("search_result_color"); - cache.search_result_border_color = get_theme_color("search_result_border_color"); - cache.background_color = get_theme_color("background_color"); + cache.style_normal = get_theme_stylebox(SNAME("normal")); + cache.style_focus = get_theme_stylebox(SNAME("focus")); + cache.style_readonly = get_theme_stylebox(SNAME("read_only")); + cache.font = get_theme_font(SNAME("font")); + cache.font_size = get_theme_font_size(SNAME("font_size")); + cache.outline_color = get_theme_color(SNAME("font_outline_color")); + cache.outline_size = get_theme_constant(SNAME("outline_size")); + cache.caret_color = get_theme_color(SNAME("caret_color")); + cache.caret_background_color = get_theme_color(SNAME("caret_background_color")); + cache.font_color = get_theme_color(SNAME("font_color")); + cache.font_selected_color = get_theme_color(SNAME("font_selected_color")); + cache.font_readonly_color = get_theme_color(SNAME("font_readonly_color")); + cache.selection_color = get_theme_color(SNAME("selection_color")); + cache.current_line_color = get_theme_color(SNAME("current_line_color")); + cache.line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color")); + cache.code_folding_color = get_theme_color(SNAME("code_folding_color"), SNAME("CodeEdit")); + cache.brace_mismatch_color = get_theme_color(SNAME("brace_mismatch_color")); + cache.word_highlighted_color = get_theme_color(SNAME("word_highlighted_color")); + cache.search_result_color = get_theme_color(SNAME("search_result_color")); + cache.search_result_border_color = get_theme_color(SNAME("search_result_border_color")); + cache.background_color = get_theme_color(SNAME("background_color")); #ifdef TOOLS_ENABLED - cache.line_spacing = get_theme_constant("line_spacing") * EDSCALE; + cache.line_spacing = get_theme_constant(SNAME("line_spacing")) * EDSCALE; #else - cache.line_spacing = get_theme_constant("line_spacing"); + cache.line_spacing = get_theme_constant(SNAME("line_spacing")); #endif - cache.tab_icon = get_theme_icon("tab"); - cache.space_icon = get_theme_icon("space"); - cache.folded_eol_icon = get_theme_icon("folded_eol_icon", "CodeEdit"); + cache.tab_icon = get_theme_icon(SNAME("tab")); + cache.space_icon = get_theme_icon(SNAME("space")); + cache.folded_eol_icon = get_theme_icon(SNAME("folded_eol_icon"), SNAME("CodeEdit")); TextServer::Direction dir; if (text_direction == Control::TEXT_DIRECTION_INHERITED) { @@ -4119,7 +4086,7 @@ void TextEdit::add_gutter(int p_at) { for (int i = 0; i < text.size() + 1; i++) { text.add_gutter(p_at); } - emit_signal("gutter_added"); + emit_signal(SNAME("gutter_added")); update(); } @@ -4131,7 +4098,7 @@ void TextEdit::remove_gutter(int p_gutter) { for (int i = 0; i < text.size() + 1; i++) { text.remove_gutter(p_gutter); } - emit_signal("gutter_removed"); + emit_signal(SNAME("gutter_removed")); update(); } @@ -4755,12 +4722,12 @@ bool TextEdit::search(const String &p_key, uint32_t p_search_flags, int p_from_l } void TextEdit::_cursor_changed_emit() { - emit_signal("cursor_changed"); + emit_signal(SNAME("cursor_changed")); cursor_changed_dirty = false; } void TextEdit::_text_changed_emit() { - emit_signal("text_changed"); + emit_signal(SNAME("text_changed")); text_changed_dirty = false; } @@ -5571,8 +5538,6 @@ bool TextEdit::is_context_menu_enabled() { void TextEdit::set_shortcut_keys_enabled(bool p_enabled) { shortcut_keys_enabled = p_enabled; - - _generate_context_menu(); } void TextEdit::set_virtual_keyboard_enabled(bool p_enable) { @@ -5585,8 +5550,6 @@ void TextEdit::set_selecting_enabled(bool p_enabled) { if (!selecting_enabled) { deselect(); } - - _generate_context_menu(); } bool TextEdit::is_selecting_enabled() const { @@ -5794,8 +5757,8 @@ void TextEdit::_bind_methods() { /* Gutters. */ BIND_ENUM_CONSTANT(GUTTER_TYPE_STRING); - BIND_ENUM_CONSTANT(GUTTER_TPYE_ICON); - BIND_ENUM_CONSTANT(GUTTER_TPYE_CUSTOM); + BIND_ENUM_CONSTANT(GUTTER_TYPE_ICON); + BIND_ENUM_CONSTANT(GUTTER_TYPE_CUSTOM); ClassDB::bind_method(D_METHOD("add_gutter", "at"), &TextEdit::add_gutter, DEFVAL(-1)); ClassDB::bind_method(D_METHOD("remove_gutter", "gutter"), &TextEdit::remove_gutter); @@ -5935,47 +5898,72 @@ void TextEdit::_bind_methods() { } void TextEdit::_ensure_menu() { - if (menu) { - return; + if (!menu) { + menu = memnew(PopupMenu); + add_child(menu); + + menu_dir = memnew(PopupMenu); + menu_dir->set_name("DirMenu"); + menu_dir->add_radio_check_item(RTR("Same as layout direction"), MENU_DIR_INHERITED); + menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO); + menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR); + menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL); + menu->add_child(menu_dir); + + menu_ctl = memnew(PopupMenu); + menu_ctl->set_name("CTLMenu"); + menu_ctl->add_item(RTR("Left-to-right mark (LRM)"), MENU_INSERT_LRM); + menu_ctl->add_item(RTR("Right-to-left mark (RLM)"), MENU_INSERT_RLM); + menu_ctl->add_item(RTR("Start of left-to-right embedding (LRE)"), MENU_INSERT_LRE); + menu_ctl->add_item(RTR("Start of right-to-left embedding (RLE)"), MENU_INSERT_RLE); + menu_ctl->add_item(RTR("Start of left-to-right override (LRO)"), MENU_INSERT_LRO); + menu_ctl->add_item(RTR("Start of right-to-left override (RLO)"), MENU_INSERT_RLO); + menu_ctl->add_item(RTR("Pop direction formatting (PDF)"), MENU_INSERT_PDF); + menu_ctl->add_separator(); + menu_ctl->add_item(RTR("Arabic letter mark (ALM)"), MENU_INSERT_ALM); + menu_ctl->add_item(RTR("Left-to-right isolate (LRI)"), MENU_INSERT_LRI); + menu_ctl->add_item(RTR("Right-to-left isolate (RLI)"), MENU_INSERT_RLI); + menu_ctl->add_item(RTR("First strong isolate (FSI)"), MENU_INSERT_FSI); + menu_ctl->add_item(RTR("Pop direction isolate (PDI)"), MENU_INSERT_PDI); + menu_ctl->add_separator(); + menu_ctl->add_item(RTR("Zero width joiner (ZWJ)"), MENU_INSERT_ZWJ); + menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ); + menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ); + menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY); + menu->add_child(menu_ctl); + + menu->connect("id_pressed", callable_mp(this, &TextEdit::menu_option)); + menu_dir->connect("id_pressed", callable_mp(this, &TextEdit::menu_option)); + menu_ctl->connect("id_pressed", callable_mp(this, &TextEdit::menu_option)); } - menu = memnew(PopupMenu); - add_child(menu); - - menu_dir = memnew(PopupMenu); - menu_dir->set_name("DirMenu"); - menu_dir->add_radio_check_item(RTR("Same as layout direction"), MENU_DIR_INHERITED); - menu_dir->add_radio_check_item(RTR("Auto-detect direction"), MENU_DIR_AUTO); - menu_dir->add_radio_check_item(RTR("Left-to-right"), MENU_DIR_LTR); - menu_dir->add_radio_check_item(RTR("Right-to-left"), MENU_DIR_RTL); - menu->add_child(menu_dir); - - menu_ctl = memnew(PopupMenu); - menu_ctl->set_name("CTLMenu"); - menu_ctl->add_item(RTR("Left-to-right mark (LRM)"), MENU_INSERT_LRM); - menu_ctl->add_item(RTR("Right-to-left mark (RLM)"), MENU_INSERT_RLM); - menu_ctl->add_item(RTR("Start of left-to-right embedding (LRE)"), MENU_INSERT_LRE); - menu_ctl->add_item(RTR("Start of right-to-left embedding (RLE)"), MENU_INSERT_RLE); - menu_ctl->add_item(RTR("Start of left-to-right override (LRO)"), MENU_INSERT_LRO); - menu_ctl->add_item(RTR("Start of right-to-left override (RLO)"), MENU_INSERT_RLO); - menu_ctl->add_item(RTR("Pop direction formatting (PDF)"), MENU_INSERT_PDF); - menu_ctl->add_separator(); - menu_ctl->add_item(RTR("Arabic letter mark (ALM)"), MENU_INSERT_ALM); - menu_ctl->add_item(RTR("Left-to-right isolate (LRI)"), MENU_INSERT_LRI); - menu_ctl->add_item(RTR("Right-to-left isolate (RLI)"), MENU_INSERT_RLI); - menu_ctl->add_item(RTR("First strong isolate (FSI)"), MENU_INSERT_FSI); - menu_ctl->add_item(RTR("Pop direction isolate (PDI)"), MENU_INSERT_PDI); - menu_ctl->add_separator(); - menu_ctl->add_item(RTR("Zero width joiner (ZWJ)"), MENU_INSERT_ZWJ); - menu_ctl->add_item(RTR("Zero width non-joiner (ZWNJ)"), MENU_INSERT_ZWNJ); - menu_ctl->add_item(RTR("Word joiner (WJ)"), MENU_INSERT_WJ); - menu_ctl->add_item(RTR("Soft hyphen (SHY)"), MENU_INSERT_SHY); - menu->add_child(menu_ctl); - - menu->connect("id_pressed", callable_mp(this, &TextEdit::menu_option)); - menu_dir->connect("id_pressed", callable_mp(this, &TextEdit::menu_option)); - menu_ctl->connect("id_pressed", callable_mp(this, &TextEdit::menu_option)); - + // Reorganize context menu. + menu->clear(); + if (!readonly) { + menu->add_item(RTR("Cut"), MENU_CUT, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_cut") : 0); + } + menu->add_item(RTR("Copy"), MENU_COPY, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_copy") : 0); + if (!readonly) { + menu->add_item(RTR("Paste"), MENU_PASTE, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_paste") : 0); + } + menu->add_separator(); + if (is_selecting_enabled()) { + menu->add_item(RTR("Select All"), MENU_SELECT_ALL, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_text_select_all") : 0); + } + if (!readonly) { + menu->add_item(RTR("Clear"), MENU_CLEAR); + menu->add_separator(); + menu->add_item(RTR("Undo"), MENU_UNDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_undo") : 0); + menu->add_item(RTR("Redo"), MENU_REDO, is_shortcut_keys_enabled() ? _get_menu_action_accelerator("ui_redo") : 0); + } + menu->add_separator(); + menu->add_submenu_item(RTR("Text writing direction"), "DirMenu"); + menu->add_separator(); + menu->add_check_item(RTR("Display control characters"), MENU_DISPLAY_UCC); + menu->set_item_checked(menu->get_item_index(MENU_DISPLAY_UCC), draw_control_chars); + if (!readonly) { + menu->add_submenu_item(RTR("Insert control character"), "CTLMenu"); + } menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_INHERITED), text_direction == TEXT_DIRECTION_INHERITED); menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_AUTO), text_direction == TEXT_DIRECTION_AUTO); menu_dir->set_item_checked(menu_dir->get_item_index(MENU_DIR_LTR), text_direction == TEXT_DIRECTION_LTR); diff --git a/scene/gui/text_edit.h b/scene/gui/text_edit.h index 7863499878..62d576b48a 100644 --- a/scene/gui/text_edit.h +++ b/scene/gui/text_edit.h @@ -44,8 +44,8 @@ class TextEdit : public Control { public: enum GutterType { GUTTER_TYPE_STRING, - GUTTER_TPYE_ICON, - GUTTER_TPYE_CUSTOM + GUTTER_TYPE_ICON, + GUTTER_TYPE_CUSTOM }; enum SelectionMode { @@ -336,8 +336,6 @@ private: bool shortcut_keys_enabled = true; bool virtual_keyboard_enabled = true; - void _generate_context_menu(); - int get_visible_rows() const; int get_total_visible_rows() const; diff --git a/scene/gui/tree.cpp b/scene/gui/tree.cpp index 4d2cb81f23..09db3205d9 100644 --- a/scene/gui/tree.cpp +++ b/scene/gui/tree.cpp @@ -416,7 +416,7 @@ void TreeItem::set_collapsed(bool p_collapsed) { if (tree->select_mode == Tree::SELECT_MULTI) { tree->selected_item = this; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); } else { select(tree->selected_col); } @@ -426,7 +426,7 @@ void TreeItem::set_collapsed(bool p_collapsed) { } _changed_notify(); - tree->emit_signal("item_collapsed", this); + tree->emit_signal(SNAME("item_collapsed"), this); } bool TreeItem::is_collapsed() { @@ -1215,62 +1215,62 @@ TreeItem::~TreeItem() { /**********************************************/ void Tree::update_cache() { - cache.font = get_theme_font("font"); - cache.font_size = get_theme_font_size("font_size"); - cache.tb_font = get_theme_font("title_button_font"); - cache.tb_font_size = get_theme_font_size("title_button_font_size"); - cache.bg = get_theme_stylebox("bg"); - cache.selected = get_theme_stylebox("selected"); - cache.selected_focus = get_theme_stylebox("selected_focus"); - cache.cursor = get_theme_stylebox("cursor"); - cache.cursor_unfocus = get_theme_stylebox("cursor_unfocused"); - cache.button_pressed = get_theme_stylebox("button_pressed"); - - cache.checked = get_theme_icon("checked"); - cache.unchecked = get_theme_icon("unchecked"); + cache.font = get_theme_font(SNAME("font")); + cache.font_size = get_theme_font_size(SNAME("font_size")); + cache.tb_font = get_theme_font(SNAME("title_button_font")); + cache.tb_font_size = get_theme_font_size(SNAME("title_button_font_size")); + cache.bg = get_theme_stylebox(SNAME("bg")); + cache.selected = get_theme_stylebox(SNAME("selected")); + cache.selected_focus = get_theme_stylebox(SNAME("selected_focus")); + cache.cursor = get_theme_stylebox(SNAME("cursor")); + cache.cursor_unfocus = get_theme_stylebox(SNAME("cursor_unfocused")); + cache.button_pressed = get_theme_stylebox(SNAME("button_pressed")); + + cache.checked = get_theme_icon(SNAME("checked")); + cache.unchecked = get_theme_icon(SNAME("unchecked")); if (is_layout_rtl()) { - cache.arrow_collapsed = get_theme_icon("arrow_collapsed_mirrored"); + cache.arrow_collapsed = get_theme_icon(SNAME("arrow_collapsed_mirrored")); } else { - cache.arrow_collapsed = get_theme_icon("arrow_collapsed"); - } - cache.arrow = get_theme_icon("arrow"); - cache.select_arrow = get_theme_icon("select_arrow"); - cache.updown = get_theme_icon("updown"); - - cache.custom_button = get_theme_stylebox("custom_button"); - cache.custom_button_hover = get_theme_stylebox("custom_button_hover"); - cache.custom_button_pressed = get_theme_stylebox("custom_button_pressed"); - cache.custom_button_font_highlight = get_theme_color("custom_button_font_highlight"); - - cache.font_color = get_theme_color("font_color"); - cache.font_selected_color = get_theme_color("font_selected_color"); - cache.drop_position_color = get_theme_color("drop_position_color"); - cache.hseparation = get_theme_constant("hseparation"); - cache.vseparation = get_theme_constant("vseparation"); - cache.item_margin = get_theme_constant("item_margin"); - cache.button_margin = get_theme_constant("button_margin"); - - cache.font_outline_color = get_theme_color("font_outline_color"); - cache.font_outline_size = get_theme_constant("outline_size"); - - cache.draw_guides = get_theme_constant("draw_guides"); - cache.guide_color = get_theme_color("guide_color"); - cache.draw_relationship_lines = get_theme_constant("draw_relationship_lines"); - cache.relationship_line_width = get_theme_constant("relationship_line_width"); - cache.parent_hl_line_width = get_theme_constant("parent_hl_line_width"); - cache.children_hl_line_width = get_theme_constant("children_hl_line_width"); - cache.parent_hl_line_margin = get_theme_constant("parent_hl_line_margin"); - cache.relationship_line_color = get_theme_color("relationship_line_color"); - cache.parent_hl_line_color = get_theme_color("parent_hl_line_color"); - cache.children_hl_line_color = get_theme_color("children_hl_line_color"); - - cache.scroll_border = get_theme_constant("scroll_border"); - cache.scroll_speed = get_theme_constant("scroll_speed"); - - cache.title_button = get_theme_stylebox("title_button_normal"); - cache.title_button_pressed = get_theme_stylebox("title_button_pressed"); - cache.title_button_hover = get_theme_stylebox("title_button_hover"); - cache.title_button_color = get_theme_color("title_button_color"); + cache.arrow_collapsed = get_theme_icon(SNAME("arrow_collapsed")); + } + cache.arrow = get_theme_icon(SNAME("arrow")); + cache.select_arrow = get_theme_icon(SNAME("select_arrow")); + cache.updown = get_theme_icon(SNAME("updown")); + + cache.custom_button = get_theme_stylebox(SNAME("custom_button")); + cache.custom_button_hover = get_theme_stylebox(SNAME("custom_button_hover")); + cache.custom_button_pressed = get_theme_stylebox(SNAME("custom_button_pressed")); + cache.custom_button_font_highlight = get_theme_color(SNAME("custom_button_font_highlight")); + + cache.font_color = get_theme_color(SNAME("font_color")); + cache.font_selected_color = get_theme_color(SNAME("font_selected_color")); + cache.drop_position_color = get_theme_color(SNAME("drop_position_color")); + cache.hseparation = get_theme_constant(SNAME("hseparation")); + cache.vseparation = get_theme_constant(SNAME("vseparation")); + cache.item_margin = get_theme_constant(SNAME("item_margin")); + cache.button_margin = get_theme_constant(SNAME("button_margin")); + + cache.font_outline_color = get_theme_color(SNAME("font_outline_color")); + cache.font_outline_size = get_theme_constant(SNAME("outline_size")); + + cache.draw_guides = get_theme_constant(SNAME("draw_guides")); + cache.guide_color = get_theme_color(SNAME("guide_color")); + cache.draw_relationship_lines = get_theme_constant(SNAME("draw_relationship_lines")); + cache.relationship_line_width = get_theme_constant(SNAME("relationship_line_width")); + cache.parent_hl_line_width = get_theme_constant(SNAME("parent_hl_line_width")); + cache.children_hl_line_width = get_theme_constant(SNAME("children_hl_line_width")); + cache.parent_hl_line_margin = get_theme_constant(SNAME("parent_hl_line_margin")); + cache.relationship_line_color = get_theme_color(SNAME("relationship_line_color")); + cache.parent_hl_line_color = get_theme_color(SNAME("parent_hl_line_color")); + cache.children_hl_line_color = get_theme_color(SNAME("children_hl_line_color")); + + cache.scroll_border = get_theme_constant(SNAME("scroll_border")); + cache.scroll_speed = get_theme_constant(SNAME("scroll_speed")); + + cache.title_button = get_theme_stylebox(SNAME("title_button_normal")); + cache.title_button_pressed = get_theme_stylebox(SNAME("title_button_pressed")); + cache.title_button_hover = get_theme_stylebox(SNAME("title_button_hover")); + cache.title_button_color = get_theme_color(SNAME("title_button_color")); v_scroll->set_custom_step(cache.font->get_height(cache.font_size)); } @@ -2075,7 +2075,7 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c selected_item = p_selected; selected_col = 0; if (!emitted_row) { - emit_signal("item_selected"); + emit_signal(SNAME("item_selected")); emitted_row = true; } /* @@ -2095,28 +2095,28 @@ void Tree::select_single_item(TreeItem *p_selected, TreeItem *p_current, int p_c selected_item = p_selected; selected_col = i; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); if (select_mode == SELECT_MULTI) { - emit_signal("multi_selected", p_current, i, true); + emit_signal(SNAME("multi_selected"), p_current, i, true); } else if (select_mode == SELECT_SINGLE) { - emit_signal("item_selected"); + emit_signal(SNAME("item_selected")); } } else if (select_mode == SELECT_MULTI && (selected_item != p_selected || selected_col != i)) { selected_item = p_selected; selected_col = i; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); } } else { if (r_in_range && *r_in_range && !p_force_deselect) { if (!c.selected && c.selectable) { c.selected = true; - emit_signal("multi_selected", p_current, i, true); + emit_signal(SNAME("multi_selected"), p_current, i, true); } } else if (!r_in_range || p_force_deselect) { if (select_mode == SELECT_MULTI && c.selected) { - emit_signal("multi_selected", p_current, i, false); + emit_signal(SNAME("multi_selected"), p_current, i, false); } c.selected = false; } @@ -2184,7 +2184,7 @@ void Tree::_range_click_timeout() { } if (propagate_mouse_activated) { - emit_signal("item_activated"); + emit_signal(SNAME("item_activated")); propagate_mouse_activated = false; } @@ -2297,7 +2297,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int cache.click_column = col; cache.click_pos = get_global_mouse_position() - get_global_position(); update(); - //emit_signal("button_pressed"); + //emit_signal(SNAME("button_pressed")); return -1; } @@ -2318,15 +2318,15 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int if (select_mode == SELECT_MULTI && p_mod->is_command_pressed() && c.selectable) { if (!c.selected || p_button == MOUSE_BUTTON_RIGHT) { p_item->select(col); - emit_signal("multi_selected", p_item, col, true); + emit_signal(SNAME("multi_selected"), p_item, col, true); if (p_button == MOUSE_BUTTON_RIGHT) { - emit_signal("item_rmb_selected", get_local_mouse_position()); + emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position()); } //p_item->selected_signal.call(col); } else { p_item->deselect(col); - emit_signal("multi_selected", p_item, col, false); + emit_signal(SNAME("multi_selected"), p_item, col, false); //p_item->deselected_signal.call(col); } @@ -2337,7 +2337,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int select_single_item(p_item, root, col, selected_item, &inrange); if (p_button == MOUSE_BUTTON_RIGHT) { - emit_signal("item_rmb_selected", get_local_mouse_position()); + emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position()); } } else { int icount = _count_selected_items(root); @@ -2351,14 +2351,14 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int } if (p_button == MOUSE_BUTTON_RIGHT) { - emit_signal("item_rmb_selected", get_local_mouse_position()); + emit_signal(SNAME("item_rmb_selected"), get_local_mouse_position()); } } } /* if (!c.selected && select_mode==SELECT_MULTI) { - emit_signal("multi_selected",p_item,col,true); + emit_signal(SNAME("multi_selected"),p_item,col,true); } */ update(); @@ -2472,7 +2472,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int custom_popup_rect = Rect2i(get_global_position() + Point2i(col_ofs, _get_title_button_height() + y_ofs + item_h - cache.offset.y), Size2(get_column_width(col), item_h)); if (on_arrow || !p_item->cells[col].custom_button) { - emit_signal("custom_popup_edited", ((bool)(x >= (col_width - item_h / 2)))); + emit_signal(SNAME("custom_popup_edited"), ((bool)(x >= (col_width - item_h / 2)))); } if (!p_item->cells[col].custom_button || !on_arrow) { @@ -2524,7 +2524,7 @@ int Tree::propagate_mouse_event(const Point2i &p_pos, int x_ofs, int y_ofs, int } } if (p_item == root && p_button == MOUSE_BUTTON_RIGHT) { - emit_signal("empty_rmb", get_local_mouse_position()); + emit_signal(SNAME("empty_rmb"), get_local_mouse_position()); } } @@ -2630,7 +2630,7 @@ void Tree::_go_left() { } else { if (select_mode == SELECT_MULTI) { selected_col--; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); } else { selected_item->select(selected_col - 1); } @@ -2651,7 +2651,7 @@ void Tree::_go_right() { } else { if (select_mode == SELECT_MULTI) { selected_col++; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); } else { selected_item->select(selected_col + 1); } @@ -2684,7 +2684,7 @@ void Tree::_go_up() { return; } selected_item = prev; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); update(); } else { int col = selected_col < 0 ? 0 : selected_col; @@ -2727,7 +2727,7 @@ void Tree::_go_down() { } selected_item = next; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); update(); } else { int col = selected_col < 0 ? 0 : selected_col; @@ -2828,7 +2828,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (select_mode == SELECT_MULTI) { selected_item = next; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); update(); } else { while (next && !next->cells[selected_col].selectable) { @@ -2866,7 +2866,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (select_mode == SELECT_MULTI) { selected_item = prev; - emit_signal("cell_selected"); + emit_signal(SNAME("cell_selected")); update(); } else { while (prev && !prev->cells[selected_col].selectable) { @@ -2882,7 +2882,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (selected_item) { //bring up editor if possible if (!edit_selected()) { - emit_signal("item_activated"); + emit_signal(SNAME("item_activated")); incr_search.clear(); } } @@ -2894,10 +2894,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } if (selected_item->is_selected(selected_col)) { selected_item->deselect(selected_col); - emit_signal("multi_selected", selected_item, selected_col, false); + emit_signal(SNAME("multi_selected"), selected_item, selected_col, false); } else if (selected_item->is_selectable(selected_col)) { selected_item->select(selected_col); - emit_signal("multi_selected", selected_item, selected_col, true); + emit_signal(SNAME("multi_selected"), selected_item, selected_col, true); } } accept_event(); @@ -3081,7 +3081,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { for (int i = 0; i < columns.size(); i++) { len += get_column_width(i); if (pos.x < len) { - emit_signal("column_title_pressed", i); + emit_signal(SNAME("column_title_pressed"), i); break; } } @@ -3108,10 +3108,10 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } if (rect.has_point(mpos)) { if (!edit_selected()) { - emit_signal("item_double_clicked"); + emit_signal(SNAME("item_double_clicked")); } } else { - emit_signal("item_double_clicked"); + emit_signal(SNAME("item_double_clicked")); } } pressing_for_editor = false; @@ -3120,7 +3120,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (cache.click_type == Cache::CLICK_BUTTON && cache.click_item != nullptr) { // make sure in case of wrong reference after reconstructing whole TreeItems cache.click_item = get_item_at_position(cache.click_pos); - emit_signal("button_pressed", cache.click_item, cache.click_column, cache.click_id); + emit_signal(SNAME("button_pressed"), cache.click_item, cache.click_column, cache.click_id); } cache.click_type = Cache::CLICK_NONE; cache.click_index = -1; @@ -3180,7 +3180,7 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { } if (!root || (!root->get_first_child() && hide_root)) { if (b->get_button_index() == MOUSE_BUTTON_RIGHT && allow_rmb_select) { - emit_signal("empty_tree_rmb_selected", get_local_mouse_position()); + emit_signal(SNAME("empty_tree_rmb_selected"), get_local_mouse_position()); } break; } @@ -3231,13 +3231,13 @@ void Tree::_gui_input(Ref<InputEvent> p_event) { if (b->get_button_index() == MOUSE_BUTTON_LEFT) { if (get_item_at_position(b->get_position()) == nullptr && !b->is_shift_pressed() && !b->is_ctrl_pressed() && !b->is_command_pressed()) { - emit_signal("nothing_selected"); + emit_signal(SNAME("nothing_selected")); } } } if (propagate_mouse_activated) { - emit_signal("item_activated"); + emit_signal(SNAME("item_activated")); propagate_mouse_activated = false; } @@ -3306,7 +3306,7 @@ bool Tree::edit_selected() { edited_item = s; edited_col = col; custom_popup_rect = Rect2i(get_global_position() + rect.position, rect.size); - emit_signal("custom_popup_edited", false); + emit_signal(SNAME("custom_popup_edited"), false); item_edited(col, s); return true; @@ -3542,8 +3542,8 @@ void Tree::_notification(int p_what) { RID ci = get_canvas_item(); Ref<StyleBox> bg = cache.bg; - Color font_outline_color = get_theme_color("font_outline_color"); - int outline_size = get_theme_constant("outline_size"); + 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(); @@ -3593,7 +3593,7 @@ void Tree::_notification(int p_what) { // 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("bg_focus"); + 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); } @@ -3694,9 +3694,9 @@ void Tree::item_edited(int p_column, TreeItem *p_item, bool p_lmb) { edited_item->cells.write[p_column].dirty = true; } if (p_lmb) { - emit_signal("item_edited"); + emit_signal(SNAME("item_edited")); } else { - emit_signal("item_rmb_edited"); + emit_signal(SNAME("item_rmb_edited")); } } @@ -3714,7 +3714,7 @@ void Tree::item_selected(int p_column, TreeItem *p_item) { } p_item->cells.write[p_column].selected = true; - //emit_signal("multi_selected",p_item,p_column,true); - NO this is for TreeItem::select + //emit_signal(SNAME("multi_selected"),p_item,p_column,true); - NO this is for TreeItem::select selected_col = p_column; if (!selected_item) { @@ -4075,7 +4075,7 @@ void Tree::ensure_cursor_is_visible() { if (cell_h > screen_h) { // Screen size is too small, maybe it was not resized yet. v_scroll->set_value(y_offset); } else if (y_offset + cell_h > v_scroll->get_value() + screen_h) { - v_scroll->call_deferred("set_value", y_offset - screen_h + cell_h); + v_scroll->call_deferred(SNAME("set_value"), y_offset - screen_h + cell_h); } else if (y_offset < v_scroll->get_value()) { v_scroll->set_value(y_offset); } @@ -4093,7 +4093,7 @@ void Tree::ensure_cursor_is_visible() { if (cell_w > screen_w) { h_scroll->set_value(x_offset); } else if (x_offset + cell_w > h_scroll->get_value() + screen_w) { - h_scroll->call_deferred("set_value", x_offset - screen_w + cell_w); + h_scroll->call_deferred(SNAME("set_value"), x_offset - screen_w + cell_w); } else if (x_offset < h_scroll->get_value()) { h_scroll->set_value(x_offset); } diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index f81a3ef630..c3fd62640a 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -128,24 +128,21 @@ void CanvasItemMaterial::_update_shader() { if (particles_animation) { code += "uniform int particles_anim_h_frames;\n"; code += "uniform int particles_anim_v_frames;\n"; - code += "uniform bool particles_anim_loop;\n"; + code += "uniform bool particles_anim_loop;\n\n"; code += "void vertex() {\n"; - - code += "\tfloat h_frames = float(particles_anim_h_frames);\n"; - code += "\tfloat v_frames = float(particles_anim_v_frames);\n"; - - code += "\tVERTEX.xy /= vec2(h_frames, v_frames);\n"; - - code += "\tfloat particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n"; - code += "\tfloat particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; - code += "\tif (!particles_anim_loop) {\n"; - code += "\t\tparticle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n"; - code += "\t} else {\n"; - code += "\t\tparticle_frame = mod(particle_frame, particle_total_frames);\n"; - code += "\t}"; - code += "\tUV /= vec2(h_frames, v_frames);\n"; - code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n"; + code += " float h_frames = float(particles_anim_h_frames);\n"; + code += " float v_frames = float(particles_anim_v_frames);\n"; + code += " VERTEX.xy /= vec2(h_frames, v_frames);\n"; + code += " float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n"; + code += " float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; + code += " if (!particles_anim_loop) {\n"; + code += " particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n"; + code += " } else {\n"; + code += " particle_frame = mod(particle_frame, particle_total_frames);\n"; + code += " }"; + code += " UV /= vec2(h_frames, v_frames);\n"; + code += " UV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n"; code += "}\n"; } diff --git a/scene/main/http_request.cpp b/scene/main/http_request.cpp index 775dfa4c46..f649380afa 100644 --- a/scene/main/http_request.cpp +++ b/scene/main/http_request.cpp @@ -151,7 +151,7 @@ Error HTTPRequest::request_raw(const String &p_url, const Vector<String> &p_cust client->set_blocking_mode(false); err = _request(); if (err != OK) { - call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); return ERR_CANT_CONNECT; } @@ -167,7 +167,7 @@ void HTTPRequest::_thread_func(void *p_userdata) { Error err = hr->_request(); if (err != OK) { - hr->call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); + hr->call_deferred(SNAME("_request_done"), RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); } else { while (!hr->thread_request_quit.is_set()) { bool exit = hr->_update_connection(); @@ -209,7 +209,7 @@ void HTTPRequest::cancel_request() { bool HTTPRequest::_handle_response(bool *ret_value) { if (!client->has_response()) { - call_deferred("_request_done", RESULT_NO_RESPONSE, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_NO_RESPONSE, 0, PackedStringArray(), PackedByteArray()); *ret_value = true; return true; } @@ -228,7 +228,7 @@ bool HTTPRequest::_handle_response(bool *ret_value) { // Handle redirect if (max_redirects >= 0 && redirections >= max_redirects) { - call_deferred("_request_done", RESULT_REDIRECT_LIMIT_REACHED, response_code, response_headers, PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_REDIRECT_LIMIT_REACHED, response_code, response_headers, PackedByteArray()); *ret_value = true; return true; } @@ -273,7 +273,7 @@ bool HTTPRequest::_handle_response(bool *ret_value) { bool HTTPRequest::_update_connection() { switch (client->get_status()) { case HTTPClient::STATUS_DISCONNECTED: { - call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); return true; // End it, since it's doing something } break; case HTTPClient::STATUS_RESOLVING: { @@ -282,7 +282,7 @@ bool HTTPRequest::_update_connection() { return false; } break; case HTTPClient::STATUS_CANT_RESOLVE: { - call_deferred("_request_done", RESULT_CANT_RESOLVE, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_CANT_RESOLVE, 0, PackedStringArray(), PackedByteArray()); return true; } break; @@ -292,7 +292,7 @@ bool HTTPRequest::_update_connection() { return false; } break; // Connecting to IP case HTTPClient::STATUS_CANT_CONNECT: { - call_deferred("_request_done", RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_CANT_CONNECT, 0, PackedStringArray(), PackedByteArray()); return true; } break; @@ -307,16 +307,16 @@ bool HTTPRequest::_update_connection() { return ret_value; } - call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, PackedByteArray()); return true; } if (body_len < 0) { // Chunked transfer is done - call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body); + call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, body); return true; } - call_deferred("_request_done", RESULT_CHUNKED_BODY_SIZE_MISMATCH, response_code, response_headers, PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_CHUNKED_BODY_SIZE_MISMATCH, response_code, response_headers, PackedByteArray()); return true; // Request might have been done } else { @@ -325,7 +325,7 @@ bool HTTPRequest::_update_connection() { int size = request_data.size(); Error err = client->request(method, request_string, headers, size > 0 ? request_data.ptr() : nullptr, size); if (err != OK) { - call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray()); return true; } @@ -348,7 +348,7 @@ bool HTTPRequest::_update_connection() { } if (!client->is_response_chunked() && client->get_response_body_length() == 0) { - call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, PackedByteArray()); return true; } @@ -357,14 +357,14 @@ bool HTTPRequest::_update_connection() { body_len = client->get_response_body_length(); if (body_size_limit >= 0 && body_len > body_size_limit) { - call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray()); return true; } if (download_to_file != String()) { file = FileAccess::open(download_to_file, FileAccess::WRITE); if (!file) { - call_deferred("_request_done", RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_DOWNLOAD_FILE_CANT_OPEN, response_code, response_headers, PackedByteArray()); return true; } } @@ -383,7 +383,7 @@ bool HTTPRequest::_update_connection() { const uint8_t *r = chunk.ptr(); file->store_buffer(r, chunk.size()); if (file->get_error() != OK) { - call_deferred("_request_done", RESULT_DOWNLOAD_FILE_WRITE_ERROR, response_code, response_headers, PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_DOWNLOAD_FILE_WRITE_ERROR, response_code, response_headers, PackedByteArray()); return true; } } else { @@ -392,18 +392,18 @@ bool HTTPRequest::_update_connection() { } if (body_size_limit >= 0 && downloaded.get() > body_size_limit) { - call_deferred("_request_done", RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_BODY_SIZE_LIMIT_EXCEEDED, response_code, response_headers, PackedByteArray()); return true; } if (body_len >= 0) { if (downloaded.get() == body_len) { - call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body); + call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, body); return true; } } else if (client->get_status() == HTTPClient::STATUS_DISCONNECTED) { // We read till EOF, with no errors. Request is done. - call_deferred("_request_done", RESULT_SUCCESS, response_code, response_headers, body); + call_deferred(SNAME("_request_done"), RESULT_SUCCESS, response_code, response_headers, body); return true; } @@ -411,11 +411,11 @@ bool HTTPRequest::_update_connection() { } break; // Request resulted in body: break which must be read case HTTPClient::STATUS_CONNECTION_ERROR: { - call_deferred("_request_done", RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_CONNECTION_ERROR, 0, PackedStringArray(), PackedByteArray()); return true; } break; case HTTPClient::STATUS_SSL_HANDSHAKE_ERROR: { - call_deferred("_request_done", RESULT_SSL_HANDSHAKE_ERROR, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_SSL_HANDSHAKE_ERROR, 0, PackedStringArray(), PackedByteArray()); return true; } break; } @@ -463,7 +463,7 @@ void HTTPRequest::_request_done(int p_status, int p_code, const PackedStringArra data = &p_data; } - emit_signal("request_completed", p_status, p_code, p_headers, *data); + emit_signal(SNAME("request_completed"), p_status, p_code, p_headers, *data); } void HTTPRequest::_notification(int p_what) { @@ -563,7 +563,7 @@ int HTTPRequest::get_timeout() { void HTTPRequest::_timeout() { cancel_request(); - call_deferred("_request_done", RESULT_TIMEOUT, 0, PackedStringArray(), PackedByteArray()); + call_deferred(SNAME("_request_done"), RESULT_TIMEOUT, 0, PackedStringArray(), PackedByteArray()); } void HTTPRequest::_bind_methods() { diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 0935e64678..0d060240de 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -442,7 +442,7 @@ void Node::set_process_mode(ProcessMode p_mode) { // This is required for the editor to update the visibility of disabled nodes // It's very expensive during runtime to change, so editor-only if (Engine::get_singleton()->is_editor_hint()) { - get_tree()->emit_signal("tree_process_mode_changed"); + get_tree()->emit_signal(SNAME("tree_process_mode_changed")); } #endif } @@ -868,7 +868,7 @@ void Node::set_name(const String &p_name) { propagate_notification(NOTIFICATION_PATH_CHANGED); if (is_inside_tree()) { - emit_signal("renamed"); + emit_signal(SNAME("renamed")); get_tree()->node_renamed(this); get_tree()->tree_changed(); } diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index fefe4c9f0d..cc947560a2 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -169,8 +169,8 @@ void SceneTree::_flush_ugc() { v[i] = E->get()[i]; } - static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5"); - call_group_flags(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4]); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + call_group_flags(GROUP_CALL_REALTIME, E->key().group, E->key().call, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); unique_group_calls.erase(E); } @@ -406,7 +406,7 @@ bool SceneTree::physics_process(float p_time) { MainLoop::physics_process(p_time); physics_process_time = p_time; - emit_signal("physics_frame"); + emit_signal(SNAME("physics_frame")); _notify_group_pause("physics_process_internal", Node::NOTIFICATION_INTERNAL_PHYSICS_PROCESS); call_group_flags(GROUP_CALL_REALTIME, "_viewports", "_process_picking"); @@ -436,7 +436,7 @@ bool SceneTree::process(float p_time) { multiplayer->poll(); } - emit_signal("process_frame"); + emit_signal(SNAME("process_frame")); MessageQueue::get_singleton()->flush(); //small little hack @@ -471,7 +471,7 @@ bool SceneTree::process(float p_time) { E->get()->set_time_left(time_left); if (time_left < 0) { - E->get()->emit_signal("timeout"); + E->get()->emit_signal(SNAME("timeout")); timers.erase(E); } if (E == L) { @@ -927,8 +927,8 @@ Variant SceneTree::_call_group_flags(const Variant **p_args, int p_argcount, Cal v[i] = *p_args[i + 3]; } - static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5"); - call_group_flags(flags, group, method, v[0], v[1], v[2], v[3], v[4]); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + call_group_flags(flags, group, method, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); return Variant(); } @@ -947,8 +947,8 @@ Variant SceneTree::_call_group(const Variant **p_args, int p_argcount, Callable: v[i] = *p_args[i + 2]; } - static_assert(VARIANT_ARG_MAX == 5, "This code needs to be updated if VARIANT_ARG_MAX != 5"); - call_group_flags(0, group, method, v[0], v[1], v[2], v[3], v[4]); + static_assert(VARIANT_ARG_MAX == 8, "This code needs to be updated if VARIANT_ARG_MAX != 8"); + call_group_flags(0, group, method, v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); return Variant(); } @@ -1097,7 +1097,7 @@ Error SceneTree::change_scene_to(const Ref<PackedScene> &p_scene) { ERR_FAIL_COND_V(!new_scene, ERR_CANT_CREATE); } - call_deferred("_change_scene", new_scene); + call_deferred(SNAME("_change_scene"), new_scene); return OK; } diff --git a/scene/main/timer.cpp b/scene/main/timer.cpp index f52237251c..ef8245076f 100644 --- a/scene/main/timer.cpp +++ b/scene/main/timer.cpp @@ -58,7 +58,7 @@ void Timer::_notification(int p_what) { stop(); } - emit_signal("timeout"); + emit_signal(SNAME("timeout")); } } break; @@ -74,7 +74,7 @@ void Timer::_notification(int p_what) { } else { stop(); } - emit_signal("timeout"); + emit_signal(SNAME("timeout")); } } break; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index b359685d31..b366f2d670 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -248,16 +248,16 @@ void Viewport::_sub_window_update(Window *p_window) { Rect2i r = Rect2i(p_window->get_position(), sw.window->get_size()); if (!p_window->get_flag(Window::FLAG_BORDERLESS)) { - Ref<StyleBox> panel = p_window->get_theme_stylebox("panel_window"); + Ref<StyleBox> panel = p_window->get_theme_stylebox(SNAME("panel_window")); panel->draw(sw.canvas_item, r); // Draw the title bar text. - Ref<Font> title_font = p_window->get_theme_font("title_font"); - int font_size = p_window->get_theme_font_size("title_font_size"); - Color title_color = p_window->get_theme_color("title_color"); - int title_height = p_window->get_theme_constant("title_height"); - int close_h_ofs = p_window->get_theme_constant("close_h_ofs"); - int close_v_ofs = p_window->get_theme_constant("close_v_ofs"); + Ref<Font> title_font = p_window->get_theme_font(SNAME("title_font")); + int font_size = p_window->get_theme_font_size(SNAME("title_font_size")); + Color title_color = p_window->get_theme_color(SNAME("title_color")); + int title_height = p_window->get_theme_constant(SNAME("title_height")); + int close_h_ofs = p_window->get_theme_constant(SNAME("close_h_ofs")); + int close_v_ofs = p_window->get_theme_constant(SNAME("close_v_ofs")); TextLine title_text = TextLine(p_window->get_title(), title_font, font_size, Dictionary(), TranslationServer::get_singleton()->get_tool_locale()); title_text.set_width(r.size.width - panel->get_minimum_size().x - close_h_ofs); @@ -265,8 +265,8 @@ void Viewport::_sub_window_update(Window *p_window) { int x = (r.size.width - title_text.get_size().x) / 2; int y = (-title_height - title_text.get_size().y) / 2; - Color font_outline_color = p_window->get_theme_color("title_outline_modulate"); - int outline_size = p_window->get_theme_constant("title_outline_size"); + Color font_outline_color = p_window->get_theme_color(SNAME("title_outline_modulate")); + int outline_size = p_window->get_theme_constant(SNAME("title_outline_size")); if (outline_size > 0 && font_outline_color.a > 0) { title_text.draw_outline(sw.canvas_item, r.position + Point2(x, y), outline_size, font_outline_color); } @@ -847,7 +847,7 @@ void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, update_canvas_items(); - emit_signal("size_changed"); + emit_signal(SNAME("size_changed")); } Size2i Viewport::_get_size() const { @@ -1550,6 +1550,9 @@ void Viewport::_gui_show_tooltip() { return; } + // Popup window which houses the tooltip content. + TooltipPanel *panel = memnew(TooltipPanel); + // Controls can implement `make_custom_tooltip` to provide their own tooltip. // This should be a Control node which will be added as child to a TooltipPanel. Control *base_tooltip = tooltip_owner->make_custom_tooltip(tooltip_text); @@ -1559,11 +1562,11 @@ void Viewport::_gui_show_tooltip() { gui.tooltip_label = memnew(TooltipLabel); gui.tooltip_label->set_text(tooltip_text); base_tooltip = gui.tooltip_label; + panel->connect("mouse_entered", callable_mp(this, &Viewport::_gui_cancel_tooltip)); } base_tooltip->set_anchors_and_offsets_preset(Control::PRESET_WIDE); - TooltipPanel *panel = memnew(TooltipPanel); panel->set_transient(false); panel->set_flag(Window::FLAG_NO_FOCUS, true); panel->set_wrap_controls(true); @@ -2211,7 +2214,7 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { Window *sw = embedder->gui.sub_windows[i].window; Rect2 swrect = Rect2i(sw->get_position(), sw->get_size()); if (!sw->get_flag(Window::FLAG_BORDERLESS)) { - int title_height = sw->get_theme_constant("title_height"); + int title_height = sw->get_theme_constant(SNAME("title_height")); swrect.position.y -= title_height; swrect.size.y += title_height; } @@ -2560,7 +2563,7 @@ void Viewport::_gui_control_grab_focus(Control *p_control) { } get_tree()->call_group_flags(SceneTree::GROUP_CALL_REALTIME, "_viewports", "_gui_remove_focus_for_window", (Node *)get_base_window()); gui.key_focus = p_control; - emit_signal("gui_focus_changed", p_control); + emit_signal(SNAME("gui_focus_changed"), p_control); p_control->notification(Control::NOTIFICATION_FOCUS_ENTER); p_control->update(); } @@ -2670,7 +2673,7 @@ Control *Viewport::_gui_get_focus_owner() { void Viewport::_gui_grab_click_focus(Control *p_control) { gui.mouse_click_grabber = p_control; - call_deferred("_post_gui_grab_click_focus"); + call_deferred(SNAME("_post_gui_grab_click_focus")); } void Viewport::_post_gui_grab_click_focus() { @@ -2743,7 +2746,7 @@ Viewport::SubWindowResize Viewport::_sub_window_get_resize_margin(Window *p_subw Rect2i r = Rect2i(p_subwindow->get_position(), p_subwindow->get_size()); - int title_height = p_subwindow->get_theme_constant("title_height"); + int title_height = p_subwindow->get_theme_constant(SNAME("title_height")); r.position.y -= title_height; r.size.y += title_height; @@ -2755,7 +2758,7 @@ Viewport::SubWindowResize Viewport::_sub_window_get_resize_margin(Window *p_subw int dist_x = p_point.x < r.position.x ? (p_point.x - r.position.x) : (p_point.x > (r.position.x + r.size.x) ? (p_point.x - (r.position.x + r.size.x)) : 0); int dist_y = p_point.y < r.position.y ? (p_point.y - r.position.y) : (p_point.y > (r.position.y + r.size.y) ? (p_point.y - (r.position.y + r.size.y)) : 0); - int limit = p_subwindow->get_theme_constant("resize_margin"); + int limit = p_subwindow->get_theme_constant(SNAME("resize_margin")); if (ABS(dist_x) > limit) { return SUB_WINDOW_RESIZE_DISABLED; @@ -2837,7 +2840,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) { new_rect.position.x = 0; } - int title_height = gui.subwindow_focused->get_flag(Window::FLAG_BORDERLESS) ? 0 : gui.subwindow_focused->get_theme_constant("title_height"); + int title_height = gui.subwindow_focused->get_flag(Window::FLAG_BORDERLESS) ? 0 : gui.subwindow_focused->get_theme_constant(SNAME("title_height")); if (new_rect.position.y < title_height) { new_rect.position.y = title_height; @@ -2941,7 +2944,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) { if (!sw.window->get_flag(Window::FLAG_BORDERLESS)) { //check top bar - int title_height = sw.window->get_theme_constant("title_height"); + int title_height = sw.window->get_theme_constant(SNAME("title_height")); Rect2i title_bar = r; title_bar.position.y -= title_height; title_bar.size.y = title_height; @@ -2949,9 +2952,9 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) { if (title_bar.has_point(mb->get_position())) { click_on_window = true; - int close_h_ofs = sw.window->get_theme_constant("close_h_ofs"); - int close_v_ofs = sw.window->get_theme_constant("close_v_ofs"); - Ref<Texture2D> close_icon = sw.window->get_theme_icon("close"); + int close_h_ofs = sw.window->get_theme_constant(SNAME("close_h_ofs")); + int close_v_ofs = sw.window->get_theme_constant(SNAME("close_v_ofs")); + Ref<Texture2D> close_icon = sw.window->get_theme_icon(SNAME("close")); Rect2 close_rect; close_rect.position = Vector2(r.position.x + r.size.x - close_v_ofs, r.position.y - close_h_ofs); diff --git a/scene/main/window.cpp b/scene/main/window.cpp index c557fd0101..7aa88fa766 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -313,39 +313,39 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) { switch (p_event) { case DisplayServer::WINDOW_EVENT_MOUSE_ENTER: { _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_ENTER); - emit_signal("mouse_entered"); + emit_signal(SNAME("mouse_entered")); DisplayServer::get_singleton()->cursor_set_shape(DisplayServer::CURSOR_ARROW); //restore cursor shape } break; case DisplayServer::WINDOW_EVENT_MOUSE_EXIT: { _propagate_window_notification(this, NOTIFICATION_WM_MOUSE_EXIT); - emit_signal("mouse_exited"); + emit_signal(SNAME("mouse_exited")); } break; case DisplayServer::WINDOW_EVENT_FOCUS_IN: { focused = true; _propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_IN); - emit_signal("focus_entered"); + emit_signal(SNAME("focus_entered")); } break; case DisplayServer::WINDOW_EVENT_FOCUS_OUT: { focused = false; _propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_OUT); - emit_signal("focus_exited"); + emit_signal(SNAME("focus_exited")); } break; case DisplayServer::WINDOW_EVENT_CLOSE_REQUEST: { if (exclusive_child != nullptr) { break; //has an exclusive child, can't get events until child is closed } _propagate_window_notification(this, NOTIFICATION_WM_CLOSE_REQUEST); - emit_signal("close_requested"); + emit_signal(SNAME("close_requested")); } break; case DisplayServer::WINDOW_EVENT_GO_BACK_REQUEST: { _propagate_window_notification(this, NOTIFICATION_WM_GO_BACK_REQUEST); - emit_signal("go_back_requested"); + emit_signal(SNAME("go_back_requested")); } break; case DisplayServer::WINDOW_EVENT_DPI_CHANGE: { _update_viewport_size(); _propagate_window_notification(this, NOTIFICATION_WM_DPI_CHANGE); - emit_signal("dpi_changed"); + emit_signal(SNAME("dpi_changed")); } break; } } @@ -882,7 +882,7 @@ void Window::child_controls_changed() { } updating_child_controls = true; - call_deferred("_update_child_controls"); + call_deferred(SNAME("_update_child_controls")); } bool Window::_can_consume_input_events() const { @@ -925,7 +925,7 @@ void Window::_window_input_text(const String &p_text) { } void Window::_window_drop_files(const Vector<String> &p_files) { - emit_signal("files_dropped", p_files, current_screen); + emit_signal(SNAME("files_dropped"), p_files, current_screen); } Viewport *Window::get_parent_viewport() const { @@ -1043,7 +1043,7 @@ void Window::popup_centered_ratio(float p_ratio) { } void Window::popup(const Rect2i &p_screen_rect) { - emit_signal("about_to_popup"); + emit_signal(SNAME("about_to_popup")); // Update window size to calculate the actual window size based on contents minimum size and minimum size. _update_window_size(); diff --git a/scene/resources/curve.cpp b/scene/resources/curve.cpp index 846da39221..53979e16df 100644 --- a/scene/resources/curve.cpp +++ b/scene/resources/curve.cpp @@ -286,7 +286,7 @@ void Curve::set_min_value(float p_min) { } // Note: min and max are indicative values, // it's still possible that existing points are out of range at this point. - emit_signal(SIGNAL_RANGE_CHANGED); + emit_signal(SNAME(SIGNAL_RANGE_CHANGED)); } void Curve::set_max_value(float p_max) { @@ -296,7 +296,7 @@ void Curve::set_max_value(float p_max) { _minmax_set_once |= 0b01; // second bit is "max set" _max_value = p_max; } - emit_signal(SIGNAL_RANGE_CHANGED); + emit_signal(SNAME(SIGNAL_RANGE_CHANGED)); } real_t Curve::interpolate(real_t offset) const { diff --git a/scene/resources/material.cpp b/scene/resources/material.cpp index a264c2d1eb..7d49533afd 100644 --- a/scene/resources/material.cpp +++ b/scene/resources/material.cpp @@ -757,148 +757,148 @@ void BaseMaterial3D::_update_shader() { code += "void vertex() {\n"; if (flags[FLAG_SRGB_VERTEX_COLOR]) { - code += "\tif (!OUTPUT_IS_SRGB) {\n"; - code += "\t\tCOLOR.rgb = mix(pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb * (1.0 / 12.92), lessThan(COLOR.rgb, vec3(0.04045)));\n"; - code += "\t}\n"; + code += " if (!OUTPUT_IS_SRGB) {\n"; + code += " COLOR.rgb = mix(pow((COLOR.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)), vec3(2.4)), COLOR.rgb * (1.0 / 12.92), lessThan(COLOR.rgb, vec3(0.04045)));\n"; + code += " }\n"; } if (flags[FLAG_USE_POINT_SIZE]) { - code += "\tPOINT_SIZE=point_size;\n"; + code += " POINT_SIZE=point_size;\n"; } if (shading_mode == SHADING_MODE_PER_VERTEX) { - code += "\tROUGHNESS=roughness;\n"; + code += " ROUGHNESS=roughness;\n"; } if (!flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tUV=UV*uv1_scale.xy+uv1_offset.xy;\n"; + code += " UV=UV*uv1_scale.xy+uv1_offset.xy;\n"; } switch (billboard_mode) { case BILLBOARD_DISABLED: { } break; case BILLBOARD_ENABLED: { - code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],CAMERA_MATRIX[1],CAMERA_MATRIX[2],WORLD_MATRIX[3]);\n"; + code += " MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],CAMERA_MATRIX[1],CAMERA_MATRIX[2],WORLD_MATRIX[3]);\n"; if (flags[FLAG_BILLBOARD_KEEP_SCALE]) { - code += "\tMODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n"; + code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n"; } } break; case BILLBOARD_FIXED_Y: { - code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],WORLD_MATRIX[1],vec4(normalize(cross(CAMERA_MATRIX[0].xyz,WORLD_MATRIX[1].xyz)), 0.0),WORLD_MATRIX[3]);\n"; + code += " MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0],WORLD_MATRIX[1],vec4(normalize(cross(CAMERA_MATRIX[0].xyz,WORLD_MATRIX[1].xyz)), 0.0),WORLD_MATRIX[3]);\n"; if (flags[FLAG_BILLBOARD_KEEP_SCALE]) { - code += "\tMODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, 1.0, 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; + code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0),vec4(0.0, 1.0, 0.0, 0.0),vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; } else { - code += "\tMODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(1.0, 0.0, 0.0, 0.0),vec4(0.0, 1.0/length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0 ,1.0));\n"; + code += " MODELVIEW_MATRIX = MODELVIEW_MATRIX * mat4(vec4(1.0, 0.0, 0.0, 0.0),vec4(0.0, 1.0/length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0 ,1.0));\n"; } } break; case BILLBOARD_PARTICLES: { //make billboard - code += "\tmat4 mat_world = mat4(normalize(CAMERA_MATRIX[0])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[1])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[2])*length(WORLD_MATRIX[2]),WORLD_MATRIX[3]);\n"; + code += " mat4 mat_world = mat4(normalize(CAMERA_MATRIX[0])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[1])*length(WORLD_MATRIX[0]),normalize(CAMERA_MATRIX[2])*length(WORLD_MATRIX[2]),WORLD_MATRIX[3]);\n"; //rotate by rotation - code += "\tmat_world = mat_world * mat4( vec4(cos(INSTANCE_CUSTOM.x),-sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0),vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n"; + code += " mat_world = mat_world * mat4( vec4(cos(INSTANCE_CUSTOM.x),-sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0),vec4(0.0, 0.0, 1.0, 0.0),vec4(0.0, 0.0, 0.0, 1.0));\n"; //set modelview - code += "\tMODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat_world;\n"; + code += " MODELVIEW_MATRIX = INV_CAMERA_MATRIX * mat_world;\n"; //handle animation - code += "\tfloat h_frames = float(particles_anim_h_frames);\n"; - code += "\tfloat v_frames = float(particles_anim_v_frames);\n"; - code += "\tfloat particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n"; - code += "\tfloat particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; - code += "\tif (!particles_anim_loop) {\n"; - code += "\t\tparticle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n"; - code += "\t} else {\n"; - code += "\t\tparticle_frame = mod(particle_frame, particle_total_frames);\n"; - code += "\t}"; - code += "\tUV /= vec2(h_frames, v_frames);\n"; - code += "\tUV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n"; + code += " float h_frames = float(particles_anim_h_frames);\n"; + code += " float v_frames = float(particles_anim_v_frames);\n"; + code += " float particle_total_frames = float(particles_anim_h_frames * particles_anim_v_frames);\n"; + code += " float particle_frame = floor(INSTANCE_CUSTOM.z * float(particle_total_frames));\n"; + code += " if (!particles_anim_loop) {\n"; + code += " particle_frame = clamp(particle_frame, 0.0, particle_total_frames - 1.0);\n"; + code += " } else {\n"; + code += " particle_frame = mod(particle_frame, particle_total_frames);\n"; + code += " }"; + code += " UV /= vec2(h_frames, v_frames);\n"; + code += " UV += vec2(mod(particle_frame, h_frames) / h_frames, floor(particle_frame / h_frames) / v_frames);\n"; } break; case BILLBOARD_MAX: break; // Internal value, skip. } if (flags[FLAG_FIXED_SIZE]) { - code += "\tif (PROJECTION_MATRIX[3][3] != 0.0) {\n"; + code += " if (PROJECTION_MATRIX[3][3] != 0.0) {\n"; //orthogonal matrix, try to do about the same //with viewport size - code += "\t\tfloat h = abs(1.0 / (2.0 * PROJECTION_MATRIX[1][1]));\n"; - code += "\t\tfloat sc = (h * 2.0); //consistent with Y-fov\n"; - code += "\t\tMODELVIEW_MATRIX[0]*=sc;\n"; - code += "\t\tMODELVIEW_MATRIX[1]*=sc;\n"; - code += "\t\tMODELVIEW_MATRIX[2]*=sc;\n"; - code += "\t} else {\n"; + code += " float h = abs(1.0 / (2.0 * PROJECTION_MATRIX[1][1]));\n"; + code += " float sc = (h * 2.0); //consistent with Y-fov\n"; + code += " MODELVIEW_MATRIX[0]*=sc;\n"; + code += " MODELVIEW_MATRIX[1]*=sc;\n"; + code += " MODELVIEW_MATRIX[2]*=sc;\n"; + code += " } else {\n"; //just scale by depth - code += "\t\tfloat sc = -(MODELVIEW_MATRIX)[3].z;\n"; - code += "\t\tMODELVIEW_MATRIX[0]*=sc;\n"; - code += "\t\tMODELVIEW_MATRIX[1]*=sc;\n"; - code += "\t\tMODELVIEW_MATRIX[2]*=sc;\n"; - code += "\t}\n"; + code += " float sc = -(MODELVIEW_MATRIX)[3].z;\n"; + code += " MODELVIEW_MATRIX[0]*=sc;\n"; + code += " MODELVIEW_MATRIX[1]*=sc;\n"; + code += " MODELVIEW_MATRIX[2]*=sc;\n"; + code += " }\n"; } if (detail_uv == DETAIL_UV_2 && !flags[FLAG_UV2_USE_TRIPLANAR]) { - code += "\tUV2=UV2*uv2_scale.xy+uv2_offset.xy;\n"; + code += " UV2=UV2*uv2_scale.xy+uv2_offset.xy;\n"; } if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) { //generate tangent and binormal in world space - code += "\tTANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);\n"; - code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.y);\n"; - code += "\tTANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);\n"; - code += "\tTANGENT = normalize(TANGENT);\n"; + code += " TANGENT = vec3(0.0,0.0,-1.0) * abs(NORMAL.x);\n"; + code += " TANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.y);\n"; + code += " TANGENT+= vec3(1.0,0.0,0.0) * abs(NORMAL.z);\n"; + code += " TANGENT = normalize(TANGENT);\n"; - code += "\tBINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);\n"; - code += "\tBINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);\n"; - code += "\tBINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);\n"; - code += "\tBINORMAL = normalize(BINORMAL);\n"; + code += " BINORMAL = vec3(0.0,1.0,0.0) * abs(NORMAL.x);\n"; + code += " BINORMAL+= vec3(0.0,0.0,-1.0) * abs(NORMAL.y);\n"; + code += " BINORMAL+= vec3(0.0,1.0,0.0) * abs(NORMAL.z);\n"; + code += " BINORMAL = normalize(BINORMAL);\n"; } if (flags[FLAG_UV1_USE_TRIPLANAR]) { if (flags[FLAG_UV1_USE_WORLD_TRIPLANAR]) { - code += "\tuv1_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL),vec3(uv1_blend_sharpness));\n"; - code += "\tuv1_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv1_scale + uv1_offset;\n"; + code += " uv1_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL),vec3(uv1_blend_sharpness));\n"; + code += " uv1_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv1_scale + uv1_offset;\n"; } else { - code += "\tuv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n"; - code += "\tuv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;\n"; + code += " uv1_power_normal=pow(abs(NORMAL),vec3(uv1_blend_sharpness));\n"; + code += " uv1_triplanar_pos = VERTEX * uv1_scale + uv1_offset;\n"; } - code += "\tuv1_power_normal/=dot(uv1_power_normal,vec3(1.0));\n"; - code += "\tuv1_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n"; + code += " uv1_power_normal/=dot(uv1_power_normal,vec3(1.0));\n"; + code += " uv1_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n"; } if (flags[FLAG_UV2_USE_TRIPLANAR]) { if (flags[FLAG_UV2_USE_WORLD_TRIPLANAR]) { - code += "\tuv2_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL), vec3(uv2_blend_sharpness));\n"; - code += "\tuv2_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv2_scale + uv2_offset;\n"; + code += " uv2_power_normal=pow(abs(mat3(WORLD_MATRIX) * NORMAL), vec3(uv2_blend_sharpness));\n"; + code += " uv2_triplanar_pos = (WORLD_MATRIX * vec4(VERTEX, 1.0f)).xyz * uv2_scale + uv2_offset;\n"; } else { - code += "\tuv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n"; - code += "\tuv2_triplanar_pos = VERTEX * uv2_scale + uv2_offset;\n"; + code += " uv2_power_normal=pow(abs(NORMAL), vec3(uv2_blend_sharpness));\n"; + code += " uv2_triplanar_pos = VERTEX * uv2_scale + uv2_offset;\n"; } - code += "\tuv2_power_normal/=dot(uv2_power_normal,vec3(1.0));\n"; - code += "\tuv2_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n"; + code += " uv2_power_normal/=dot(uv2_power_normal,vec3(1.0));\n"; + code += " uv2_triplanar_pos *= vec3(1.0,-1.0, 1.0);\n"; } if (grow_enabled) { - code += "\tVERTEX+=NORMAL*grow;\n"; + code += " VERTEX+=NORMAL*grow;\n"; } code += "}\n"; code += "\n\n"; if (flags[FLAG_UV1_USE_TRIPLANAR] || flags[FLAG_UV2_USE_TRIPLANAR]) { code += "vec4 triplanar_texture(sampler2D p_sampler,vec3 p_weights,vec3 p_triplanar_pos) {\n"; - code += "\tvec4 samp=vec4(0.0);\n"; - code += "\tsamp+= texture(p_sampler,p_triplanar_pos.xy) * p_weights.z;\n"; - code += "\tsamp+= texture(p_sampler,p_triplanar_pos.xz) * p_weights.y;\n"; - code += "\tsamp+= texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)) * p_weights.x;\n"; - code += "\treturn samp;\n"; + code += " vec4 samp=vec4(0.0);\n"; + code += " samp+= texture(p_sampler,p_triplanar_pos.xy) * p_weights.z;\n"; + code += " samp+= texture(p_sampler,p_triplanar_pos.xz) * p_weights.y;\n"; + code += " samp+= texture(p_sampler,p_triplanar_pos.zy * vec2(-1.0,1.0)) * p_weights.x;\n"; + code += " return samp;\n"; code += "}\n"; } code += "\n\n"; code += "void fragment() {\n"; if (!flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec2 base_uv = UV;\n"; + code += " vec2 base_uv = UV;\n"; } if ((features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) || (features[FEATURE_AMBIENT_OCCLUSION] && flags[FLAG_AO_ON_UV2]) || (features[FEATURE_EMISSION] && flags[FLAG_EMISSION_ON_UV2])) { - code += "\tvec2 base_uv2 = UV2;\n"; + code += " vec2 base_uv2 = UV2;\n"; } if (features[FEATURE_HEIGHT_MAPPING] && flags[FLAG_UV1_USE_TRIPLANAR]) { @@ -916,317 +916,317 @@ void BaseMaterial3D::_update_shader() { } if (!RenderingServer::get_singleton()->is_low_end() && features[FEATURE_HEIGHT_MAPPING] && !flags[FLAG_UV1_USE_TRIPLANAR]) { //heightmap not supported with triplanar - code += "\t{\n"; - code += "\t\tvec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*heightmap_flip.x,-BINORMAL*heightmap_flip.y,NORMAL));\n"; // binormal is negative due to mikktspace, flip 'unflips' it ;-) + code += " {\n"; + code += " vec3 view_dir = normalize(normalize(-VERTEX)*mat3(TANGENT*heightmap_flip.x,-BINORMAL*heightmap_flip.y,NORMAL));\n"; // binormal is negative due to mikktspace, flip 'unflips' it ;-) if (deep_parallax) { - code += "\t\tfloat num_layers = mix(float(heightmap_max_layers),float(heightmap_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n"; - code += "\t\tfloat layer_depth = 1.0 / num_layers;\n"; - code += "\t\tfloat current_layer_depth = 0.0;\n"; - code += "\t\tvec2 P = view_dir.xy * heightmap_scale;\n"; - code += "\t\tvec2 delta = P / num_layers;\n"; - code += "\t\tvec2 ofs = base_uv;\n"; + code += " float num_layers = mix(float(heightmap_max_layers),float(heightmap_min_layers), abs(dot(vec3(0.0, 0.0, 1.0), view_dir)));\n"; + code += " float layer_depth = 1.0 / num_layers;\n"; + code += " float current_layer_depth = 0.0;\n"; + code += " vec2 P = view_dir.xy * heightmap_scale;\n"; + code += " vec2 delta = P / num_layers;\n"; + code += " vec2 ofs = base_uv;\n"; if (flags[FLAG_INVERT_HEIGHTMAP]) { - code += "\t\tfloat depth = texture(texture_heightmap, ofs).r;\n"; + code += " float depth = texture(texture_heightmap, ofs).r;\n"; } else { - code += "\t\tfloat depth = 1.0 - texture(texture_heightmap, ofs).r;\n"; + code += " float depth = 1.0 - texture(texture_heightmap, ofs).r;\n"; } - code += "\t\tfloat current_depth = 0.0;\n"; - code += "\t\twhile(current_depth < depth) {\n"; - code += "\t\t\tofs -= delta;\n"; + code += " float current_depth = 0.0;\n"; + code += " while(current_depth < depth) {\n"; + code += " ofs -= delta;\n"; if (flags[FLAG_INVERT_HEIGHTMAP]) { - code += "\t\t\tdepth = texture(texture_heightmap, ofs).r;\n"; + code += " depth = texture(texture_heightmap, ofs).r;\n"; } else { - code += "\t\t\tdepth = 1.0 - texture(texture_heightmap, ofs).r;\n"; + code += " depth = 1.0 - texture(texture_heightmap, ofs).r;\n"; } - code += "\t\t\tcurrent_depth += layer_depth;\n"; - code += "\t\t}\n"; - code += "\t\tvec2 prev_ofs = ofs + delta;\n"; - code += "\t\tfloat after_depth = depth - current_depth;\n"; + code += " current_depth += layer_depth;\n"; + code += " }\n"; + code += " vec2 prev_ofs = ofs + delta;\n"; + code += " float after_depth = depth - current_depth;\n"; if (flags[FLAG_INVERT_HEIGHTMAP]) { - code += "\t\tfloat before_depth = texture(texture_heightmap, prev_ofs).r - current_depth + layer_depth;\n"; + code += " float before_depth = texture(texture_heightmap, prev_ofs).r - current_depth + layer_depth;\n"; } else { - code += "\t\tfloat before_depth = ( 1.0 - texture(texture_heightmap, prev_ofs).r ) - current_depth + layer_depth;\n"; + code += " float before_depth = ( 1.0 - texture(texture_heightmap, prev_ofs).r ) - current_depth + layer_depth;\n"; } - code += "\t\tfloat weight = after_depth / (after_depth - before_depth);\n"; - code += "\t\tofs = mix(ofs,prev_ofs,weight);\n"; + code += " float weight = after_depth / (after_depth - before_depth);\n"; + code += " ofs = mix(ofs,prev_ofs,weight);\n"; } else { if (flags[FLAG_INVERT_HEIGHTMAP]) { - code += "\t\tfloat depth = texture(texture_heightmap, base_uv).r;\n"; + code += " float depth = texture(texture_heightmap, base_uv).r;\n"; } else { - code += "\t\tfloat depth = 1.0 - texture(texture_heightmap, base_uv).r;\n"; + code += " float depth = 1.0 - texture(texture_heightmap, base_uv).r;\n"; } - code += "\t\tvec2 ofs = base_uv - view_dir.xy / view_dir.z * (depth * heightmap_scale);\n"; + code += " vec2 ofs = base_uv - view_dir.xy / view_dir.z * (depth * heightmap_scale);\n"; } - code += "\t\tbase_uv=ofs;\n"; + code += " base_uv=ofs;\n"; if (features[FEATURE_DETAIL] && detail_uv == DETAIL_UV_2) { - code += "\t\tbase_uv2-=ofs;\n"; + code += " base_uv2-=ofs;\n"; } - code += "\t}\n"; + code += " }\n"; } if (flags[FLAG_USE_POINT_SIZE]) { - code += "\tvec4 albedo_tex = texture(texture_albedo,POINT_COORD);\n"; + code += " vec4 albedo_tex = texture(texture_albedo,POINT_COORD);\n"; } else { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos);\n"; + code += " vec4 albedo_tex = triplanar_texture(texture_albedo,uv1_power_normal,uv1_triplanar_pos);\n"; } else { - code += "\tvec4 albedo_tex = texture(texture_albedo,base_uv);\n"; + code += " vec4 albedo_tex = texture(texture_albedo,base_uv);\n"; } } if (flags[FLAG_ALBEDO_TEXTURE_FORCE_SRGB]) { - code += "\talbedo_tex.rgb = mix(pow((albedo_tex.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)),vec3(2.4)),albedo_tex.rgb.rgb * (1.0 / 12.92),lessThan(albedo_tex.rgb,vec3(0.04045)));\n"; + code += " albedo_tex.rgb = mix(pow((albedo_tex.rgb + vec3(0.055)) * (1.0 / (1.0 + 0.055)),vec3(2.4)),albedo_tex.rgb.rgb * (1.0 / 12.92),lessThan(albedo_tex.rgb,vec3(0.04045)));\n"; } if (flags[FLAG_ALBEDO_FROM_VERTEX_COLOR]) { - code += "\talbedo_tex *= COLOR;\n"; + code += " albedo_tex *= COLOR;\n"; } - code += "\tALBEDO = albedo.rgb * albedo_tex.rgb;\n"; + code += " ALBEDO = albedo.rgb * albedo_tex.rgb;\n"; if (!orm) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tfloat metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);\n"; + code += " float metallic_tex = dot(triplanar_texture(texture_metallic,uv1_power_normal,uv1_triplanar_pos),metallic_texture_channel);\n"; } else { - code += "\tfloat metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);\n"; + code += " float metallic_tex = dot(texture(texture_metallic,base_uv),metallic_texture_channel);\n"; } - code += "\tMETALLIC = metallic_tex * metallic;\n"; + code += " METALLIC = metallic_tex * metallic;\n"; switch (roughness_texture_channel) { case TEXTURE_CHANNEL_RED: { - code += "\tvec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);\n"; + code += " vec4 roughness_texture_channel = vec4(1.0,0.0,0.0,0.0);\n"; } break; case TEXTURE_CHANNEL_GREEN: { - code += "\tvec4 roughness_texture_channel = vec4(0.0,1.0,0.0,0.0);\n"; + code += " vec4 roughness_texture_channel = vec4(0.0,1.0,0.0,0.0);\n"; } break; case TEXTURE_CHANNEL_BLUE: { - code += "\tvec4 roughness_texture_channel = vec4(0.0,0.0,1.0,0.0);\n"; + code += " vec4 roughness_texture_channel = vec4(0.0,0.0,1.0,0.0);\n"; } break; case TEXTURE_CHANNEL_ALPHA: { - code += "\tvec4 roughness_texture_channel = vec4(0.0,0.0,0.0,1.0);\n"; + code += " vec4 roughness_texture_channel = vec4(0.0,0.0,0.0,1.0);\n"; } break; case TEXTURE_CHANNEL_GRAYSCALE: { - code += "\tvec4 roughness_texture_channel = vec4(0.333333,0.333333,0.333333,0.0);\n"; + code += " vec4 roughness_texture_channel = vec4(0.333333,0.333333,0.333333,0.0);\n"; } break; case TEXTURE_CHANNEL_MAX: break; // Internal value, skip. } if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tfloat roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);\n"; + code += " float roughness_tex = dot(triplanar_texture(texture_roughness,uv1_power_normal,uv1_triplanar_pos),roughness_texture_channel);\n"; } else { - code += "\tfloat roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);\n"; + code += " float roughness_tex = dot(texture(texture_roughness,base_uv),roughness_texture_channel);\n"; } - code += "\tROUGHNESS = roughness_tex * roughness;\n"; - code += "\tSPECULAR = specular;\n"; + code += " ROUGHNESS = roughness_tex * roughness;\n"; + code += " SPECULAR = specular;\n"; } else { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec4 orm_tex = triplanar_texture(texture_orm,uv1_power_normal,uv1_triplanar_pos);\n"; + code += " vec4 orm_tex = triplanar_texture(texture_orm,uv1_power_normal,uv1_triplanar_pos);\n"; } else { - code += "\tvec4 orm_tex = texture(texture_orm,base_uv);\n"; + code += " vec4 orm_tex = texture(texture_orm,base_uv);\n"; } - code += "\tROUGHNESS = orm_tex.g;\n"; - code += "\tMETALLIC = orm_tex.b;\n"; + code += " ROUGHNESS = orm_tex.g;\n"; + code += " METALLIC = orm_tex.b;\n"; } if (features[FEATURE_NORMAL_MAPPING]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tNORMAL_MAP = triplanar_texture(texture_normal,uv1_power_normal,uv1_triplanar_pos).rgb;\n"; + code += " NORMAL_MAP = triplanar_texture(texture_normal,uv1_power_normal,uv1_triplanar_pos).rgb;\n"; } else { - code += "\tNORMAL_MAP = texture(texture_normal,base_uv).rgb;\n"; + code += " NORMAL_MAP = texture(texture_normal,base_uv).rgb;\n"; } - code += "\tNORMAL_MAP_DEPTH = normal_scale;\n"; + code += " NORMAL_MAP_DEPTH = normal_scale;\n"; } if (features[FEATURE_EMISSION]) { if (flags[FLAG_EMISSION_ON_UV2]) { if (flags[FLAG_UV2_USE_TRIPLANAR]) { - code += "\tvec3 emission_tex = triplanar_texture(texture_emission,uv2_power_normal,uv2_triplanar_pos).rgb;\n"; + code += " vec3 emission_tex = triplanar_texture(texture_emission,uv2_power_normal,uv2_triplanar_pos).rgb;\n"; } else { - code += "\tvec3 emission_tex = texture(texture_emission,base_uv2).rgb;\n"; + code += " vec3 emission_tex = texture(texture_emission,base_uv2).rgb;\n"; } } else { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec3 emission_tex = triplanar_texture(texture_emission,uv1_power_normal,uv1_triplanar_pos).rgb;\n"; + code += " vec3 emission_tex = triplanar_texture(texture_emission,uv1_power_normal,uv1_triplanar_pos).rgb;\n"; } else { - code += "\tvec3 emission_tex = texture(texture_emission,base_uv).rgb;\n"; + code += " vec3 emission_tex = texture(texture_emission,base_uv).rgb;\n"; } } if (emission_op == EMISSION_OP_ADD) { - code += "\tEMISSION = (emission.rgb+emission_tex)*emission_energy;\n"; + code += " EMISSION = (emission.rgb+emission_tex)*emission_energy;\n"; } else { - code += "\tEMISSION = (emission.rgb*emission_tex)*emission_energy;\n"; + code += " EMISSION = (emission.rgb*emission_tex)*emission_energy;\n"; } } if (features[FEATURE_REFRACTION]) { if (features[FEATURE_NORMAL_MAPPING]) { - code += "\tvec3 unpacked_normal = NORMAL_MAP;\n"; - code += "\tunpacked_normal.xy = unpacked_normal.xy * 2.0 - 1.0;\n"; - code += "\tunpacked_normal.z = sqrt(max(0.0, 1.0 - dot(unpacked_normal.xy, unpacked_normal.xy)));\n"; - code += "\tvec3 ref_normal = normalize( mix(NORMAL,TANGENT * unpacked_normal.x + BINORMAL * unpacked_normal.y + NORMAL * unpacked_normal.z,NORMAL_MAP_DEPTH) );\n"; + code += " vec3 unpacked_normal = NORMAL_MAP;\n"; + code += " unpacked_normal.xy = unpacked_normal.xy * 2.0 - 1.0;\n"; + code += " unpacked_normal.z = sqrt(max(0.0, 1.0 - dot(unpacked_normal.xy, unpacked_normal.xy)));\n"; + code += " vec3 ref_normal = normalize( mix(NORMAL,TANGENT * unpacked_normal.x + BINORMAL * unpacked_normal.y + NORMAL * unpacked_normal.z,NORMAL_MAP_DEPTH) );\n"; } else { - code += "\tvec3 ref_normal = NORMAL;\n"; + code += " vec3 ref_normal = NORMAL;\n"; } if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(triplanar_texture(texture_refraction,uv1_power_normal,uv1_triplanar_pos),refraction_texture_channel) * refraction;\n"; + code += " vec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(triplanar_texture(texture_refraction,uv1_power_normal,uv1_triplanar_pos),refraction_texture_channel) * refraction;\n"; } else { - code += "\tvec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(texture(texture_refraction,base_uv),refraction_texture_channel) * refraction;\n"; + code += " vec2 ref_ofs = SCREEN_UV - ref_normal.xy * dot(texture(texture_refraction,base_uv),refraction_texture_channel) * refraction;\n"; } - code += "\tfloat ref_amount = 1.0 - albedo.a * albedo_tex.a;\n"; - code += "\tEMISSION += textureLod(SCREEN_TEXTURE,ref_ofs,ROUGHNESS * 8.0).rgb * ref_amount;\n"; - code += "\tALBEDO *= 1.0 - ref_amount;\n"; - code += "\tALPHA = 1.0;\n"; + code += " float ref_amount = 1.0 - albedo.a * albedo_tex.a;\n"; + code += " EMISSION += textureLod(SCREEN_TEXTURE,ref_ofs,ROUGHNESS * 8.0).rgb * ref_amount;\n"; + code += " ALBEDO *= 1.0 - ref_amount;\n"; + code += " ALPHA = 1.0;\n"; } else if (transparency != TRANSPARENCY_DISABLED || flags[FLAG_USE_SHADOW_TO_OPACITY] || (distance_fade == DISTANCE_FADE_PIXEL_ALPHA) || proximity_fade_enabled) { - code += "\tALPHA = albedo.a * albedo_tex.a;\n"; + code += " ALPHA = albedo.a * albedo_tex.a;\n"; } if (transparency == TRANSPARENCY_ALPHA_HASH) { - code += "\tALPHA_HASH_SCALE = alpha_hash_scale;\n"; + code += " ALPHA_HASH_SCALE = alpha_hash_scale;\n"; } else if (transparency == TRANSPARENCY_ALPHA_SCISSOR) { - code += "\tALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;\n"; + code += " ALPHA_SCISSOR_THRESHOLD = alpha_scissor_threshold;\n"; } if (alpha_antialiasing_mode != ALPHA_ANTIALIASING_OFF && (transparency == TRANSPARENCY_ALPHA_HASH || transparency == TRANSPARENCY_ALPHA_SCISSOR)) { - code += "\tALPHA_ANTIALIASING_EDGE = alpha_antialiasing_edge;\n"; - code += "\tALPHA_TEXTURE_COORDINATE = UV * vec2(albedo_texture_size);\n"; + code += " ALPHA_ANTIALIASING_EDGE = alpha_antialiasing_edge;\n"; + code += " ALPHA_TEXTURE_COORDINATE = UV * vec2(albedo_texture_size);\n"; } if (proximity_fade_enabled) { - code += "\tfloat depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;\n"; - code += "\tvec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);\n"; - code += "\tworld_pos.xyz/=world_pos.w;\n"; - code += "\tALPHA*=clamp(1.0-smoothstep(world_pos.z+proximity_fade_distance,world_pos.z,VERTEX.z),0.0,1.0);\n"; + code += " float depth_tex = textureLod(DEPTH_TEXTURE,SCREEN_UV,0.0).r;\n"; + code += " vec4 world_pos = INV_PROJECTION_MATRIX * vec4(SCREEN_UV*2.0-1.0,depth_tex*2.0-1.0,1.0);\n"; + code += " world_pos.xyz/=world_pos.w;\n"; + code += " ALPHA*=clamp(1.0-smoothstep(world_pos.z+proximity_fade_distance,world_pos.z,VERTEX.z),0.0,1.0);\n"; } if (distance_fade != DISTANCE_FADE_DISABLED) { if ((distance_fade == DISTANCE_FADE_OBJECT_DITHER || distance_fade == DISTANCE_FADE_PIXEL_DITHER)) { if (!RenderingServer::get_singleton()->is_low_end()) { - code += "\t{\n"; + code += " {\n"; if (distance_fade == DISTANCE_FADE_OBJECT_DITHER) { - code += "\t\tfloat fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n"; + code += " float fade_distance = abs((INV_CAMERA_MATRIX * WORLD_MATRIX[3]).z);\n"; } else { - code += "\t\tfloat fade_distance=-VERTEX.z;\n"; + code += " float fade_distance=-VERTEX.z;\n"; } - code += "\t\tfloat fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n"; - code += "\t\tint x = int(FRAGCOORD.x) % 4;\n"; - code += "\t\tint y = int(FRAGCOORD.y) % 4;\n"; - code += "\t\tint index = x + y * 4;\n"; - code += "\t\tfloat limit = 0.0;\n\n"; - code += "\t\tif (x < 8) {\n"; - code += "\t\t\tif (index == 0) limit = 0.0625;\n"; - code += "\t\t\tif (index == 1) limit = 0.5625;\n"; - code += "\t\t\tif (index == 2) limit = 0.1875;\n"; - code += "\t\t\tif (index == 3) limit = 0.6875;\n"; - code += "\t\t\tif (index == 4) limit = 0.8125;\n"; - code += "\t\t\tif (index == 5) limit = 0.3125;\n"; - code += "\t\t\tif (index == 6) limit = 0.9375;\n"; - code += "\t\t\tif (index == 7) limit = 0.4375;\n"; - code += "\t\t\tif (index == 8) limit = 0.25;\n"; - code += "\t\t\tif (index == 9) limit = 0.75;\n"; - code += "\t\t\tif (index == 10) limit = 0.125;\n"; - code += "\t\t\tif (index == 11) limit = 0.625;\n"; - code += "\t\t\tif (index == 12) limit = 1.0;\n"; - code += "\t\t\tif (index == 13) limit = 0.5;\n"; - code += "\t\t\tif (index == 14) limit = 0.875;\n"; - code += "\t\t\tif (index == 15) limit = 0.375;\n"; - code += "\t\t}\n\n"; - code += "\tif (fade < limit)\n"; - code += "\t\tdiscard;\n"; - code += "\t}\n\n"; + code += " float fade=clamp(smoothstep(distance_fade_min,distance_fade_max,fade_distance),0.0,1.0);\n"; + code += " int x = int(FRAGCOORD.x) % 4;\n"; + code += " int y = int(FRAGCOORD.y) % 4;\n"; + code += " int index = x + y * 4;\n"; + code += " float limit = 0.0;\n\n"; + code += " if (x < 8) {\n"; + code += " if (index == 0) limit = 0.0625;\n"; + code += " if (index == 1) limit = 0.5625;\n"; + code += " if (index == 2) limit = 0.1875;\n"; + code += " if (index == 3) limit = 0.6875;\n"; + code += " if (index == 4) limit = 0.8125;\n"; + code += " if (index == 5) limit = 0.3125;\n"; + code += " if (index == 6) limit = 0.9375;\n"; + code += " if (index == 7) limit = 0.4375;\n"; + code += " if (index == 8) limit = 0.25;\n"; + code += " if (index == 9) limit = 0.75;\n"; + code += " if (index == 10) limit = 0.125;\n"; + code += " if (index == 11) limit = 0.625;\n"; + code += " if (index == 12) limit = 1.0;\n"; + code += " if (index == 13) limit = 0.5;\n"; + code += " if (index == 14) limit = 0.875;\n"; + code += " if (index == 15) limit = 0.375;\n"; + code += " }\n\n"; + code += " if (fade < limit)\n"; + code += " discard;\n"; + code += " }\n\n"; } } else { - code += "\tALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n"; + code += " ALPHA*=clamp(smoothstep(distance_fade_min,distance_fade_max,-VERTEX.z),0.0,1.0);\n"; } } if (features[FEATURE_RIM]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec2 rim_tex = triplanar_texture(texture_rim,uv1_power_normal,uv1_triplanar_pos).xy;\n"; + code += " vec2 rim_tex = triplanar_texture(texture_rim,uv1_power_normal,uv1_triplanar_pos).xy;\n"; } else { - code += "\tvec2 rim_tex = texture(texture_rim,base_uv).xy;\n"; + code += " vec2 rim_tex = texture(texture_rim,base_uv).xy;\n"; } - code += "\tRIM = rim*rim_tex.x;"; - code += "\tRIM_TINT = rim_tint*rim_tex.y;\n"; + code += " RIM = rim*rim_tex.x;"; + code += " RIM_TINT = rim_tint*rim_tex.y;\n"; } if (features[FEATURE_CLEARCOAT]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec2 clearcoat_tex = triplanar_texture(texture_clearcoat,uv1_power_normal,uv1_triplanar_pos).xy;\n"; + code += " vec2 clearcoat_tex = triplanar_texture(texture_clearcoat,uv1_power_normal,uv1_triplanar_pos).xy;\n"; } else { - code += "\tvec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xy;\n"; + code += " vec2 clearcoat_tex = texture(texture_clearcoat,base_uv).xy;\n"; } - code += "\tCLEARCOAT = clearcoat*clearcoat_tex.x;"; - code += "\tCLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y;\n"; + code += " CLEARCOAT = clearcoat*clearcoat_tex.x;"; + code += " CLEARCOAT_GLOSS = clearcoat_gloss*clearcoat_tex.y;\n"; } if (features[FEATURE_ANISOTROPY]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec3 anisotropy_tex = triplanar_texture(texture_flowmap,uv1_power_normal,uv1_triplanar_pos).rga;\n"; + code += " vec3 anisotropy_tex = triplanar_texture(texture_flowmap,uv1_power_normal,uv1_triplanar_pos).rga;\n"; } else { - code += "\tvec3 anisotropy_tex = texture(texture_flowmap,base_uv).rga;\n"; + code += " vec3 anisotropy_tex = texture(texture_flowmap,base_uv).rga;\n"; } - code += "\tANISOTROPY = anisotropy_ratio*anisotropy_tex.b;\n"; - code += "\tANISOTROPY_FLOW = anisotropy_tex.rg*2.0-1.0;\n"; + code += " ANISOTROPY = anisotropy_ratio*anisotropy_tex.b;\n"; + code += " ANISOTROPY_FLOW = anisotropy_tex.rg*2.0-1.0;\n"; } if (features[FEATURE_AMBIENT_OCCLUSION]) { if (!orm) { if (flags[FLAG_AO_ON_UV2]) { if (flags[FLAG_UV2_USE_TRIPLANAR]) { - code += "\tAO = dot(triplanar_texture(texture_ambient_occlusion,uv2_power_normal,uv2_triplanar_pos),ao_texture_channel);\n"; + code += " AO = dot(triplanar_texture(texture_ambient_occlusion,uv2_power_normal,uv2_triplanar_pos),ao_texture_channel);\n"; } else { - code += "\tAO = dot(texture(texture_ambient_occlusion,base_uv2),ao_texture_channel);\n"; + code += " AO = dot(texture(texture_ambient_occlusion,base_uv2),ao_texture_channel);\n"; } } else { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tAO = dot(triplanar_texture(texture_ambient_occlusion,uv1_power_normal,uv1_triplanar_pos),ao_texture_channel);\n"; + code += " AO = dot(triplanar_texture(texture_ambient_occlusion,uv1_power_normal,uv1_triplanar_pos),ao_texture_channel);\n"; } else { - code += "\tAO = dot(texture(texture_ambient_occlusion,base_uv),ao_texture_channel);\n"; + code += " AO = dot(texture(texture_ambient_occlusion,base_uv),ao_texture_channel);\n"; } } } else { - code += "\tAO = orm_tex.r;\n"; + code += " AO = orm_tex.r;\n"; } - code += "\tAO_LIGHT_AFFECT = ao_light_affect;\n"; + code += " AO_LIGHT_AFFECT = ao_light_affect;\n"; } if (features[FEATURE_SUBSURFACE_SCATTERING]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tfloat sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_triplanar_pos).r;\n"; + code += " float sss_tex = triplanar_texture(texture_subsurface_scattering,uv1_power_normal,uv1_triplanar_pos).r;\n"; } else { - code += "\tfloat sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n"; + code += " float sss_tex = texture(texture_subsurface_scattering,base_uv).r;\n"; } - code += "\tSSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n"; + code += " SSS_STRENGTH=subsurface_scattering_strength*sss_tex;\n"; } if (features[FEATURE_SUBSURFACE_TRANSMITTANCE]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec4 trans_color_tex = triplanar_texture(texture_subsurface_transmittance,uv1_power_normal,uv1_triplanar_pos);\n"; + code += " vec4 trans_color_tex = triplanar_texture(texture_subsurface_transmittance,uv1_power_normal,uv1_triplanar_pos);\n"; } else { - code += "\tvec4 trans_color_tex = texture(texture_subsurface_transmittance,base_uv);\n"; + code += " vec4 trans_color_tex = texture(texture_subsurface_transmittance,base_uv);\n"; } - code += "\tSSS_TRANSMITTANCE_COLOR=transmittance_color*trans_color_tex;\n"; + code += " SSS_TRANSMITTANCE_COLOR=transmittance_color*trans_color_tex;\n"; - code += "\tSSS_TRANSMITTANCE_DEPTH=transmittance_depth;\n"; - code += "\tSSS_TRANSMITTANCE_BOOST=transmittance_boost;\n"; + code += " SSS_TRANSMITTANCE_DEPTH=transmittance_depth;\n"; + code += " SSS_TRANSMITTANCE_BOOST=transmittance_boost;\n"; } if (features[FEATURE_BACKLIGHT]) { if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec3 backlight_tex = triplanar_texture(texture_backlight,uv1_power_normal,uv1_triplanar_pos).rgb;\n"; + code += " vec3 backlight_tex = triplanar_texture(texture_backlight,uv1_power_normal,uv1_triplanar_pos).rgb;\n"; } else { - code += "\tvec3 backlight_tex = texture(texture_backlight,base_uv).rgb;\n"; + code += " vec3 backlight_tex = texture(texture_backlight,base_uv).rgb;\n"; } - code += "\tBACKLIGHT = (backlight.rgb+backlight_tex);\n"; + code += " BACKLIGHT = (backlight.rgb+backlight_tex);\n"; } if (features[FEATURE_DETAIL]) { @@ -1234,41 +1234,41 @@ void BaseMaterial3D::_update_shader() { if (triplanar) { String tp_uv = detail_uv == DETAIL_UV_1 ? "uv1" : "uv2"; - code += "\tvec4 detail_tex = triplanar_texture(texture_detail_albedo," + tp_uv + "_power_normal," + tp_uv + "_triplanar_pos);\n"; - code += "\tvec4 detail_norm_tex = triplanar_texture(texture_detail_normal," + tp_uv + "_power_normal," + tp_uv + "_triplanar_pos);\n"; + code += " vec4 detail_tex = triplanar_texture(texture_detail_albedo," + tp_uv + "_power_normal," + tp_uv + "_triplanar_pos);\n"; + code += " vec4 detail_norm_tex = triplanar_texture(texture_detail_normal," + tp_uv + "_power_normal," + tp_uv + "_triplanar_pos);\n"; } else { String det_uv = detail_uv == DETAIL_UV_1 ? "base_uv" : "base_uv2"; - code += "\tvec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n"; - code += "\tvec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n"; + code += " vec4 detail_tex = texture(texture_detail_albedo," + det_uv + ");\n"; + code += " vec4 detail_norm_tex = texture(texture_detail_normal," + det_uv + ");\n"; } if (flags[FLAG_UV1_USE_TRIPLANAR]) { - code += "\tvec4 detail_mask_tex = triplanar_texture(texture_detail_mask,uv1_power_normal,uv1_triplanar_pos);\n"; + code += " vec4 detail_mask_tex = triplanar_texture(texture_detail_mask,uv1_power_normal,uv1_triplanar_pos);\n"; } else { - code += "\tvec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n"; + code += " vec4 detail_mask_tex = texture(texture_detail_mask,base_uv);\n"; } switch (detail_blend_mode) { case BLEND_MODE_MIX: { - code += "\tvec3 detail = mix(ALBEDO.rgb,detail_tex.rgb,detail_tex.a);\n"; + code += " vec3 detail = mix(ALBEDO.rgb,detail_tex.rgb,detail_tex.a);\n"; } break; case BLEND_MODE_ADD: { - code += "\tvec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb+detail_tex.rgb,detail_tex.a);\n"; + code += " vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb+detail_tex.rgb,detail_tex.a);\n"; } break; case BLEND_MODE_SUB: { - code += "\tvec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb-detail_tex.rgb,detail_tex.a);\n"; + code += " vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb-detail_tex.rgb,detail_tex.a);\n"; } break; case BLEND_MODE_MUL: { - code += "\tvec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb*detail_tex.rgb,detail_tex.a);\n"; + code += " vec3 detail = mix(ALBEDO.rgb,ALBEDO.rgb*detail_tex.rgb,detail_tex.a);\n"; } break; case BLEND_MODE_MAX: break; // Internal value, skip. } - code += "\tvec3 detail_norm = mix(NORMAL_MAP,detail_norm_tex.rgb,detail_tex.a);\n"; - code += "\tNORMAL_MAP = mix(NORMAL_MAP,detail_norm,detail_mask_tex.r);\n"; - code += "\tALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n"; + code += " vec3 detail_norm = mix(NORMAL_MAP,detail_norm_tex.rgb,detail_tex.a);\n"; + code += " NORMAL_MAP = mix(NORMAL_MAP,detail_norm,detail_mask_tex.r);\n"; + code += " ALBEDO.rgb = mix(ALBEDO.rgb,detail,detail_mask_tex.r);\n"; } code += "}\n"; diff --git a/scene/resources/sky_material.cpp b/scene/resources/sky_material.cpp index 89b3336118..b34d3feb47 100644 --- a/scene/resources/sky_material.cpp +++ b/scene/resources/sky_material.cpp @@ -181,68 +181,75 @@ void ProceduralSkyMaterial::_bind_methods() { } ProceduralSkyMaterial::ProceduralSkyMaterial() { - String code = "shader_type sky;\n\n"; - - code += "uniform vec4 sky_top_color : hint_color = vec4(0.35, 0.46, 0.71, 1.0);\n"; - code += "uniform vec4 sky_horizon_color : hint_color = vec4(0.55, 0.69, 0.81, 1.0);\n"; - code += "uniform float sky_curve : hint_range(0, 1) = 0.09;\n"; - code += "uniform float sky_energy = 1.0;\n\n"; - code += "uniform vec4 ground_bottom_color : hint_color = vec4(0.12, 0.12, 0.13, 1.0);\n"; - code += "uniform vec4 ground_horizon_color : hint_color = vec4(0.37, 0.33, 0.31, 1.0);\n"; - code += "uniform float ground_curve : hint_range(0, 1) = 0.02;\n"; - code += "uniform float ground_energy = 1.0;\n\n"; - code += "uniform float sun_angle_max = 1.74;\n"; - code += "uniform float sun_curve : hint_range(0, 1) = 0.05;\n\n"; - code += "void sky() {\n"; - code += "\tfloat v_angle = acos(clamp(EYEDIR.y, -1.0, 1.0));\n"; - code += "\tfloat c = (1.0 - v_angle / (PI * 0.5));\n"; - code += "\tvec3 sky = mix(sky_horizon_color.rgb, sky_top_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / sky_curve), 0.0, 1.0));\n"; - code += "\tsky *= sky_energy;\n"; - code += "\tif (LIGHT0_ENABLED) {\n"; - code += "\t\tfloat sun_angle = acos(dot(LIGHT0_DIRECTION, EYEDIR));\n"; - code += "\t\tif (sun_angle < LIGHT0_SIZE) {\n"; - code += "\t\t\tsky = LIGHT0_COLOR * LIGHT0_ENERGY;\n"; - code += "\t\t} else if (sun_angle < sun_angle_max) {\n"; - code += "\t\t\tfloat c2 = (sun_angle - LIGHT0_SIZE) / (sun_angle_max - LIGHT0_SIZE);\n"; - code += "\t\t\tsky = mix(LIGHT0_COLOR * LIGHT0_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n"; - code += "\t\t}\n"; - code += "\t}\n"; - code += "\tif (LIGHT1_ENABLED) {\n"; - code += "\t\tfloat sun_angle = acos(dot(LIGHT1_DIRECTION, EYEDIR));\n"; - code += "\t\tif (sun_angle < LIGHT1_SIZE) {\n"; - code += "\t\t\tsky = LIGHT1_COLOR * LIGHT1_ENERGY;\n"; - code += "\t\t} else if (sun_angle < sun_angle_max) {\n"; - code += "\t\t\tfloat c2 = (sun_angle - LIGHT1_SIZE) / (sun_angle_max - LIGHT1_SIZE);\n"; - code += "\t\t\tsky = mix(LIGHT1_COLOR * LIGHT1_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n"; - code += "\t\t}\n"; - code += "\t}\n"; - code += "\tif (LIGHT2_ENABLED) {\n"; - code += "\t\tfloat sun_angle = acos(dot(LIGHT2_DIRECTION, EYEDIR));\n"; - code += "\t\tif (sun_angle < LIGHT2_SIZE) {\n"; - code += "\t\t\tsky = LIGHT2_COLOR * LIGHT2_ENERGY;\n"; - code += "\t\t} else if (sun_angle < sun_angle_max) {\n"; - code += "\t\t\tfloat c2 = (sun_angle - LIGHT2_SIZE) / (sun_angle_max - LIGHT2_SIZE);\n"; - code += "\t\t\tsky = mix(LIGHT2_COLOR * LIGHT2_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n"; - code += "\t\t}\n"; - code += "\t}\n"; - code += "\tif (LIGHT3_ENABLED) {\n"; - code += "\t\tfloat sun_angle = acos(dot(LIGHT3_DIRECTION, EYEDIR));\n"; - code += "\t\tif (sun_angle < LIGHT3_SIZE) {\n"; - code += "\t\t\tsky = LIGHT3_COLOR * LIGHT3_ENERGY;\n"; - code += "\t\t} else if (sun_angle < sun_angle_max) {\n"; - code += "\t\t\tfloat c2 = (sun_angle - LIGHT3_SIZE) / (sun_angle_max - LIGHT3_SIZE);\n"; - code += "\t\t\tsky = mix(LIGHT3_COLOR * LIGHT3_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0));\n"; - code += "\t\t}\n"; - code += "\t}\n"; - code += "\tc = (v_angle - (PI * 0.5)) / (PI * 0.5);\n"; - code += "\tvec3 ground = mix(ground_horizon_color.rgb, ground_bottom_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / ground_curve), 0.0, 1.0));\n"; - code += "\tground *= ground_energy;\n"; - code += "\tCOLOR = mix(ground, sky, step(0.0, EYEDIR.y));\n"; - code += "}\n"; - shader = RS::get_singleton()->shader_create(); - RS::get_singleton()->shader_set_code(shader, code); + RS::get_singleton()->shader_set_code(shader, R"( +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 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 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; + +void sky() { + float v_angle = acos(clamp(EYEDIR.y, -1.0, 1.0)); + float c = (1.0 - v_angle / (PI * 0.5)); + vec3 sky = mix(sky_horizon_color.rgb, sky_top_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / sky_curve), 0.0, 1.0)); + sky *= sky_energy; + + if (LIGHT0_ENABLED) { + float sun_angle = acos(dot(LIGHT0_DIRECTION, EYEDIR)); + if (sun_angle < LIGHT0_SIZE) { + sky = LIGHT0_COLOR * LIGHT0_ENERGY; + } else if (sun_angle < sun_angle_max) { + float c2 = (sun_angle - LIGHT0_SIZE) / (sun_angle_max - LIGHT0_SIZE); + sky = mix(LIGHT0_COLOR * LIGHT0_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0)); + } + } + + if (LIGHT1_ENABLED) { + float sun_angle = acos(dot(LIGHT1_DIRECTION, EYEDIR)); + if (sun_angle < LIGHT1_SIZE) { + sky = LIGHT1_COLOR * LIGHT1_ENERGY; + } else if (sun_angle < sun_angle_max) { + float c2 = (sun_angle - LIGHT1_SIZE) / (sun_angle_max - LIGHT1_SIZE); + sky = mix(LIGHT1_COLOR * LIGHT1_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0)); + } + } + + if (LIGHT2_ENABLED) { + float sun_angle = acos(dot(LIGHT2_DIRECTION, EYEDIR)); + if (sun_angle < LIGHT2_SIZE) { + sky = LIGHT2_COLOR * LIGHT2_ENERGY; + } else if (sun_angle < sun_angle_max) { + float c2 = (sun_angle - LIGHT2_SIZE) / (sun_angle_max - LIGHT2_SIZE); + sky = mix(LIGHT2_COLOR * LIGHT2_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0)); + } + } + + if (LIGHT3_ENABLED) { + float sun_angle = acos(dot(LIGHT3_DIRECTION, EYEDIR)); + if (sun_angle < LIGHT3_SIZE) { + sky = LIGHT3_COLOR * LIGHT3_ENERGY; + } else if (sun_angle < sun_angle_max) { + float c2 = (sun_angle - LIGHT3_SIZE) / (sun_angle_max - LIGHT3_SIZE); + sky = mix(LIGHT3_COLOR * LIGHT3_ENERGY, sky, clamp(1.0 - pow(1.0 - c2, 1.0 / sun_curve), 0.0, 1.0)); + } + } + + c = (v_angle - (PI * 0.5)) / (PI * 0.5); + vec3 ground = mix(ground_horizon_color.rgb, ground_bottom_color.rgb, clamp(1.0 - pow(1.0 - c, 1.0 / ground_curve), 0.0, 1.0)); + ground *= ground_energy; + + COLOR = mix(ground, sky, step(0.0, EYEDIR.y)); +} +)"); RS::get_singleton()->material_set_shader(_get_material(), shader); @@ -298,16 +305,17 @@ void PanoramaSkyMaterial::_bind_methods() { } PanoramaSkyMaterial::PanoramaSkyMaterial() { - String code = "shader_type sky;\n\n"; + shader = RS::get_singleton()->shader_create(); - code += "uniform sampler2D source_panorama : filter_linear;\n"; - code += "void sky() {\n"; - code += "\tCOLOR = texture(source_panorama, SKY_COORDS).rgb;\n"; - code += "}"; + RS::get_singleton()->shader_set_code(shader, R"( +shader_type sky; - shader = RS::get_singleton()->shader_create(); +uniform sampler2D source_panorama : filter_linear; - RS::get_singleton()->shader_set_code(shader, code); +void sky() { + COLOR = texture(source_panorama, SKY_COORDS).rgb; +} +)"); RS::get_singleton()->material_set_shader(_get_material(), shader); } @@ -484,102 +492,102 @@ void PhysicalSkyMaterial::_bind_methods() { } PhysicalSkyMaterial::PhysicalSkyMaterial() { - String code = "shader_type sky;\n\n"; - - code += "uniform float rayleigh : hint_range(0, 64) = 2.0;\n"; - code += "uniform vec4 rayleigh_color : hint_color = vec4(0.056, 0.14, 0.3, 1.0);\n"; - code += "uniform float mie : hint_range(0, 1) = 0.005;\n"; - code += "uniform float mie_eccentricity : hint_range(-1, 1) = 0.8;\n"; - code += "uniform vec4 mie_color : hint_color = vec4(0.36, 0.56, 0.82, 1.0);\n\n"; - - code += "uniform float turbidity : hint_range(0, 1000) = 10.0;\n"; - code += "uniform float sun_disk_scale : hint_range(0, 360) = 1.0;\n"; - code += "uniform vec4 ground_color : hint_color = vec4(1.0);\n"; - code += "uniform float exposure : hint_range(0, 128) = 0.1;\n"; - code += "uniform float dither_strength : hint_range(0, 10) = 1.0;\n\n"; - - code += "uniform sampler2D night_sky : hint_black;"; - - code += "const vec3 UP = vec3( 0.0, 1.0, 0.0 );\n\n"; - - code += "// Sun constants\n"; - code += "const float SUN_ENERGY = 1000.0;\n\n"; - - code += "// optical length at zenith for molecules\n"; - code += "const float rayleigh_zenith_size = 8.4e3;\n"; - code += "const float mie_zenith_size = 1.25e3;\n\n"; - - code += "float henyey_greenstein(float cos_theta, float g) {\n"; - code += "\tconst float k = 0.0795774715459;\n"; - code += "\treturn k * (1.0 - g * g) / (pow(1.0 + g * g - 2.0 * g * cos_theta, 1.5));\n"; - code += "}\n\n"; - - code += "// From: https://www.shadertoy.com/view/4sfGzS credit to iq\n"; - code += "float hash(vec3 p) {\n"; - code += "\tp = fract( p * 0.3183099 + 0.1 );\n"; - code += "\tp *= 17.0;\n"; - code += "\treturn fract(p.x * p.y * p.z * (p.x + p.y + p.z));\n"; - code += "}\n\n"; - - code += "void sky() {\n"; - code += "\tif (LIGHT0_ENABLED) {\n"; - code += "\t\tfloat zenith_angle = clamp( dot(UP, normalize(LIGHT0_DIRECTION)), -1.0, 1.0 );\n"; - code += "\t\tfloat sun_energy = max(0.0, 1.0 - exp(-((PI * 0.5) - acos(zenith_angle)))) * SUN_ENERGY * LIGHT0_ENERGY;\n"; - code += "\t\tfloat sun_fade = 1.0 - clamp(1.0 - exp(LIGHT0_DIRECTION.y), 0.0, 1.0);\n\n"; - - code += "\t\t// rayleigh coefficients\n"; - code += "\t\tfloat rayleigh_coefficient = rayleigh - ( 1.0 * ( 1.0 - sun_fade ) );\n"; - code += "\t\tvec3 rayleigh_beta = rayleigh_coefficient * rayleigh_color.rgb * 0.0001;\n"; - code += "\t\t// mie coefficients from Preetham\n"; - code += "\t\tvec3 mie_beta = turbidity * mie * mie_color.rgb * 0.000434;\n\n"; - - code += "\t\t// optical length\n"; - code += "\t\tfloat zenith = acos(max(0.0, dot(UP, EYEDIR)));\n"; - code += "\t\tfloat optical_mass = 1.0 / (cos(zenith) + 0.15 * pow(93.885 - degrees(zenith), -1.253));\n"; - code += "\t\tfloat rayleigh_scatter = rayleigh_zenith_size * optical_mass;\n"; - code += "\t\tfloat mie_scatter = mie_zenith_size * optical_mass;\n\n"; - - code += "\t\t// light extinction based on thickness of atmosphere\n"; - code += "\t\tvec3 extinction = exp(-(rayleigh_beta * rayleigh_scatter + mie_beta * mie_scatter));\n\n"; - - code += "\t\t// in scattering\n"; - code += "\t\tfloat cos_theta = dot(EYEDIR, normalize(LIGHT0_DIRECTION));\n\n"; - - code += "\t\tfloat rayleigh_phase = (3.0 / (16.0 * PI)) * (1.0 + pow(cos_theta * 0.5 + 0.5, 2.0));\n"; - code += "\t\tvec3 betaRTheta = rayleigh_beta * rayleigh_phase;\n\n"; - - code += "\t\tfloat mie_phase = henyey_greenstein(cos_theta, mie_eccentricity);\n"; - code += "\t\tvec3 betaMTheta = mie_beta * mie_phase;\n\n"; - - code += "\t\tvec3 Lin = pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * (1.0 - extinction), vec3(1.5));\n"; - code += "\t\t// Hack from https://github.com/mrdoob/three.js/blob/master/examples/jsm/objects/Sky.js\n"; - code += "\t\tLin *= mix(vec3(1.0), pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * extinction, vec3(0.5)), clamp(pow(1.0 - zenith_angle, 5.0), 0.0, 1.0));\n\n"; - - code += "\t\t// Hack in the ground color\n"; - code += "\t\tLin *= mix(ground_color.rgb, vec3(1.0), smoothstep(-0.1, 0.1, dot(UP, EYEDIR)));\n\n"; - - code += "\t\t// Solar disk and out-scattering\n"; - code += "\t\tfloat sunAngularDiameterCos = cos(LIGHT0_SIZE * sun_disk_scale);\n"; - code += "\t\tfloat sunAngularDiameterCos2 = cos(LIGHT0_SIZE * sun_disk_scale*0.5);\n"; - code += "\t\tfloat sundisk = smoothstep(sunAngularDiameterCos, sunAngularDiameterCos2, cos_theta);\n"; - code += "\t\tvec3 L0 = (sun_energy * 1900.0 * extinction) * sundisk * LIGHT0_COLOR;\n"; - code += "\t\tL0 += texture(night_sky, SKY_COORDS).xyz * extinction;\n\n"; - - code += "\t\tvec3 color = (Lin + L0) * 0.04;\n"; - code += "\t\tCOLOR = pow(color, vec3(1.0 / (1.2 + (1.2 * sun_fade))));\n"; - code += "\t\tCOLOR *= exposure;\n"; - code += "\t\t// Make optional, eliminates banding\n"; - code += "\t\tCOLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.016 * dither_strength;\n"; - code += "\t} else {\n"; - code += "\t\t// There is no sun, so display night_sky and nothing else\n"; - code += "\t\tCOLOR = texture(night_sky, SKY_COORDS).xyz * 0.04;\n"; - code += "\t\tCOLOR *= exposure;\n"; - code += "\t}\n"; - code += "}\n"; - shader = RS::get_singleton()->shader_create(); - RS::get_singleton()->shader_set_code(shader, code); + RS::get_singleton()->shader_set_code(shader, R"( +shader_type sky; + +uniform float rayleigh : hint_range(0, 64) = 2.0; +uniform vec4 rayleigh_color : hint_color = vec4(0.056, 0.14, 0.3, 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.36, 0.56, 0.82, 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 float exposure : hint_range(0, 128) = 0.1; +uniform float dither_strength : hint_range(0, 10) = 1.0; + +uniform sampler2D night_sky : hint_black; + +const vec3 UP = vec3( 0.0, 1.0, 0.0 ); + +// Sun constants +const float SUN_ENERGY = 1000.0; + +// Optical length at zenith for molecules. +const float rayleigh_zenith_size = 8.4e3; +const float mie_zenith_size = 1.25e3; + +float henyey_greenstein(float cos_theta, float g) { + const float k = 0.0795774715459; + return k * (1.0 - g * g) / (pow(1.0 + g * g - 2.0 * g * cos_theta, 1.5)); +} + +// From: https://www.shadertoy.com/view/4sfGzS credit to iq +float hash(vec3 p) { + p = fract( p * 0.3183099 + 0.1 ); + p *= 17.0; + return fract(p.x * p.y * p.z * (p.x + p.y + p.z)); +} + +void sky() { + if (LIGHT0_ENABLED) { + float zenith_angle = clamp( dot(UP, normalize(LIGHT0_DIRECTION)), -1.0, 1.0 ); + float sun_energy = max(0.0, 1.0 - exp(-((PI * 0.5) - acos(zenith_angle)))) * SUN_ENERGY * LIGHT0_ENERGY; + float sun_fade = 1.0 - clamp(1.0 - exp(LIGHT0_DIRECTION.y), 0.0, 1.0); + + // Rayleigh coefficients. + float rayleigh_coefficient = rayleigh - ( 1.0 * ( 1.0 - sun_fade ) ); + vec3 rayleigh_beta = rayleigh_coefficient * rayleigh_color.rgb * 0.0001; + // mie coefficients from Preetham + vec3 mie_beta = turbidity * mie * mie_color.rgb * 0.000434; + + // Optical length. + float zenith = acos(max(0.0, dot(UP, EYEDIR))); + float optical_mass = 1.0 / (cos(zenith) + 0.15 * pow(93.885 - degrees(zenith), -1.253)); + float rayleigh_scatter = rayleigh_zenith_size * optical_mass; + float mie_scatter = mie_zenith_size * optical_mass; + + // Light extinction based on thickness of atmosphere. + vec3 extinction = exp(-(rayleigh_beta * rayleigh_scatter + mie_beta * mie_scatter)); + + // In scattering. + float cos_theta = dot(EYEDIR, normalize(LIGHT0_DIRECTION)); + + float rayleigh_phase = (3.0 / (16.0 * PI)) * (1.0 + pow(cos_theta * 0.5 + 0.5, 2.0)); + vec3 betaRTheta = rayleigh_beta * rayleigh_phase; + + float mie_phase = henyey_greenstein(cos_theta, mie_eccentricity); + vec3 betaMTheta = mie_beta * mie_phase; + + vec3 Lin = pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * (1.0 - extinction), vec3(1.5)); + // Hack from https://github.com/mrdoob/three.js/blob/master/examples/jsm/objects/Sky.js + Lin *= mix(vec3(1.0), pow(sun_energy * ((betaRTheta + betaMTheta) / (rayleigh_beta + mie_beta)) * extinction, vec3(0.5)), clamp(pow(1.0 - zenith_angle, 5.0), 0.0, 1.0)); + + // Hack in the ground color. + Lin *= mix(ground_color.rgb, vec3(1.0), smoothstep(-0.1, 0.1, dot(UP, EYEDIR))); + + // Solar disk and out-scattering. + float sunAngularDiameterCos = cos(LIGHT0_SIZE * sun_disk_scale); + float sunAngularDiameterCos2 = cos(LIGHT0_SIZE * sun_disk_scale*0.5); + float sundisk = smoothstep(sunAngularDiameterCos, sunAngularDiameterCos2, cos_theta); + vec3 L0 = (sun_energy * 1900.0 * extinction) * sundisk * LIGHT0_COLOR; + L0 += texture(night_sky, SKY_COORDS).xyz * extinction; + + vec3 color = (Lin + L0) * 0.04; + COLOR = pow(color, vec3(1.0 / (1.2 + (1.2 * sun_fade)))); + COLOR *= exposure; + // Make optional, eliminates banding. + COLOR += (hash(EYEDIR * 1741.9782) * 0.08 - 0.04) * 0.016 * dither_strength; + } else { + // There is no sun, so display night_sky and nothing else. + COLOR = texture(night_sky, SKY_COORDS).xyz * 0.04; + COLOR *= exposure; + } +} +)"); RS::get_singleton()->material_set_shader(_get_material(), shader); diff --git a/scene/resources/syntax_highlighter.cpp b/scene/resources/syntax_highlighter.cpp index 9dd00849f4..bf889d7a1c 100644 --- a/scene/resources/syntax_highlighter.cpp +++ b/scene/resources/syntax_highlighter.cpp @@ -405,7 +405,7 @@ void CodeHighlighter::_clear_highlighting_cache() { } void CodeHighlighter::_update_cache() { - font_color = text_edit->get_theme_color("font_color"); + font_color = text_edit->get_theme_color(SNAME("font_color")); } void CodeHighlighter::add_keyword_color(const String &p_keyword, const Color &p_color) { diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 26c0d432a9..38042d84fd 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -1790,7 +1790,7 @@ void GradientTexture::_queue_update() { } update_pending = true; - call_deferred("_update"); + call_deferred(SNAME("_update")); } void GradientTexture::_update() { diff --git a/scene/resources/tile_set.cpp b/scene/resources/tile_set.cpp index deee22f05f..deb5a50eb2 100644 --- a/scene/resources/tile_set.cpp +++ b/scene/resources/tile_set.cpp @@ -2569,7 +2569,7 @@ void TileSetAtlasSource::create_tile(const Vector2i p_atlas_coords, const Vector } } - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) { @@ -2595,7 +2595,7 @@ void TileSetAtlasSource::remove_tile(Vector2i p_atlas_coords) { tiles_ids.erase(p_atlas_coords); tiles_ids.sort(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool TileSetAtlasSource::has_tile(Vector2i p_atlas_coords) const { @@ -2723,7 +2723,7 @@ void TileSetAtlasSource::move_tile_in_atlas(Vector2i p_atlas_coords, Vector2i p_ } } - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool TileSetAtlasSource::has_tiles_outside_texture() { @@ -2768,7 +2768,7 @@ int TileSetAtlasSource::create_alternative_tile(const Vector2i p_atlas_coords, i tiles[p_atlas_coords].alternatives_ids.sort(); _compute_next_alternative_id(p_atlas_coords); - emit_signal("changed"); + emit_signal(SNAME("changed")); return new_alternative_id; } @@ -2783,7 +2783,7 @@ void TileSetAtlasSource::remove_alternative_tile(const Vector2i p_atlas_coords, tiles[p_atlas_coords].alternatives_ids.erase(p_alternative_tile); tiles[p_atlas_coords].alternatives_ids.sort(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileSetAtlasSource::set_alternative_tile_id(const Vector2i p_atlas_coords, int p_alternative_tile, int p_new_id) { @@ -2800,7 +2800,7 @@ void TileSetAtlasSource::set_alternative_tile_id(const Vector2i p_atlas_coords, tiles[p_atlas_coords].alternatives_ids.erase(p_alternative_tile); tiles[p_atlas_coords].alternatives_ids.sort(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool TileSetAtlasSource::has_alternative_tile(const Vector2i p_atlas_coords, int p_alternative_tile) const { @@ -2958,7 +2958,7 @@ int TileSetScenesCollectionSource::create_scene_tile(Ref<PackedScene> p_packed_s set_scene_tile_scene(new_scene_id, p_packed_scene); _compute_next_alternative_id(); - emit_signal("changed"); + emit_signal(SNAME("changed")); return new_scene_id; } @@ -2978,7 +2978,7 @@ void TileSetScenesCollectionSource::set_scene_tile_id(int p_id, int p_new_id) { scenes.erase(p_id); scenes_ids.erase(p_id); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedScene> p_packed_scene) { @@ -2997,7 +2997,7 @@ void TileSetScenesCollectionSource::set_scene_tile_scene(int p_id, Ref<PackedSce } else { scenes[p_id].scene = Ref<PackedScene>(); } - emit_signal("changed"); + emit_signal(SNAME("changed")); } Ref<PackedScene> TileSetScenesCollectionSource::get_scene_tile_scene(int p_id) const { @@ -3010,7 +3010,7 @@ void TileSetScenesCollectionSource::set_scene_tile_display_placeholder(int p_id, scenes[p_id].display_placeholder = p_display_placeholder; - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool TileSetScenesCollectionSource::get_scene_tile_display_placeholder(int p_id) const { @@ -3023,7 +3023,7 @@ void TileSetScenesCollectionSource::remove_scene_tile(int p_id) { scenes.erase(p_id); scenes_ids.erase(p_id); - emit_signal("changed"); + emit_signal(SNAME("changed")); } int TileSetScenesCollectionSource::get_next_scene_tile_id() const { @@ -3144,7 +3144,7 @@ void TileData::notify_tile_data_properties_should_change() { } notify_property_list_changed(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileData::reset_state() { @@ -3166,7 +3166,7 @@ bool TileData::is_allowing_transform() const { void TileData::set_flip_h(bool p_flip_h) { ERR_FAIL_COND_MSG(!allow_transform && p_flip_h, "Transform is only allowed for alternative tiles (with its alternative_id != 0)"); flip_h = p_flip_h; - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool TileData::get_flip_h() const { return flip_h; @@ -3175,7 +3175,7 @@ bool TileData::get_flip_h() const { void TileData::set_flip_v(bool p_flip_v) { ERR_FAIL_COND_MSG(!allow_transform && p_flip_v, "Transform is only allowed for alternative tiles (with its alternative_id != 0)"); flip_v = p_flip_v; - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool TileData::get_flip_v() const { @@ -3185,7 +3185,7 @@ bool TileData::get_flip_v() const { void TileData::set_transpose(bool p_transpose) { ERR_FAIL_COND_MSG(!allow_transform && p_transpose, "Transform is only allowed for alternative tiles (with its alternative_id != 0)"); transpose = p_transpose; - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool TileData::get_transpose() const { return transpose; @@ -3193,7 +3193,7 @@ bool TileData::get_transpose() const { void TileData::set_texture_offset(Vector2i p_texture_offset) { tex_offset = p_texture_offset; - emit_signal("changed"); + emit_signal(SNAME("changed")); } Vector2i TileData::get_texture_offset() const { @@ -3202,7 +3202,7 @@ Vector2i TileData::get_texture_offset() const { void TileData::tile_set_material(Ref<ShaderMaterial> p_material) { material = p_material; - emit_signal("changed"); + emit_signal(SNAME("changed")); } Ref<ShaderMaterial> TileData::tile_get_material() const { return material; @@ -3210,7 +3210,7 @@ Ref<ShaderMaterial> TileData::tile_get_material() const { void TileData::set_modulate(Color p_modulate) { modulate = p_modulate; - emit_signal("changed"); + emit_signal(SNAME("changed")); } Color TileData::get_modulate() const { return modulate; @@ -3218,7 +3218,7 @@ Color TileData::get_modulate() const { void TileData::set_z_index(int p_z_index) { z_index = p_z_index; - emit_signal("changed"); + emit_signal(SNAME("changed")); } int TileData::get_z_index() const { return z_index; @@ -3226,7 +3226,7 @@ int TileData::get_z_index() const { void TileData::set_y_sort_origin(int p_y_sort_origin) { y_sort_origin = p_y_sort_origin; - emit_signal("changed"); + emit_signal(SNAME("changed")); } int TileData::get_y_sort_origin() const { return y_sort_origin; @@ -3235,7 +3235,7 @@ int TileData::get_y_sort_origin() const { void TileData::set_occluder(int p_layer_id, Ref<OccluderPolygon2D> p_occluder_polygon) { ERR_FAIL_INDEX(p_layer_id, occluders.size()); occluders.write[p_layer_id] = p_occluder_polygon; - emit_signal("changed"); + emit_signal(SNAME("changed")); } Ref<OccluderPolygon2D> TileData::get_occluder(int p_layer_id) const { @@ -3254,20 +3254,20 @@ void TileData::set_collision_polygons_count(int p_layer_id, int p_polygons_count ERR_FAIL_COND(p_polygons_count < 0); physics.write[p_layer_id].polygons.resize(p_polygons_count); notify_property_list_changed(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileData::add_collision_polygon(int p_layer_id) { ERR_FAIL_INDEX(p_layer_id, physics.size()); physics.write[p_layer_id].polygons.push_back(PhysicsLayerTileData::PolygonShapeTileData()); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileData::remove_collision_polygon(int p_layer_id, int p_polygon_index) { ERR_FAIL_INDEX(p_layer_id, physics.size()); ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size()); physics.write[p_layer_id].polygons.remove(p_polygon_index); - emit_signal("changed"); + emit_signal(SNAME("changed")); } void TileData::set_collision_polygon_points(int p_layer_id, int p_polygon_index, Vector<Vector2> p_polygon) { @@ -3291,7 +3291,7 @@ void TileData::set_collision_polygon_points(int p_layer_id, int p_polygon_index, } } physics.write[p_layer_id].polygons.write[p_polygon_index].polygon = p_polygon; - emit_signal("changed"); + emit_signal(SNAME("changed")); } Vector<Vector2> TileData::get_collision_polygon_points(int p_layer_id, int p_polygon_index) const { @@ -3304,7 +3304,7 @@ void TileData::set_collision_polygon_one_way(int p_layer_id, int p_polygon_index ERR_FAIL_INDEX(p_layer_id, physics.size()); ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size()); physics.write[p_layer_id].polygons.write[p_polygon_index].one_way = p_one_way; - emit_signal("changed"); + emit_signal(SNAME("changed")); } bool TileData::is_collision_polygon_one_way(int p_layer_id, int p_polygon_index) const { @@ -3317,7 +3317,7 @@ void TileData::set_collision_polygon_one_way_margin(int p_layer_id, int p_polygo ERR_FAIL_INDEX(p_layer_id, physics.size()); ERR_FAIL_INDEX(p_polygon_index, physics[p_layer_id].polygons.size()); physics.write[p_layer_id].polygons.write[p_polygon_index].one_way_margin = p_one_way_margin; - emit_signal("changed"); + emit_signal(SNAME("changed")); } float TileData::get_collision_polygon_one_way_margin(int p_layer_id, int p_polygon_index) const { @@ -3353,7 +3353,7 @@ void TileData::set_terrain_set(int p_terrain_set) { } terrain_set = p_terrain_set; notify_property_list_changed(); - emit_signal("changed"); + emit_signal(SNAME("changed")); } int TileData::get_terrain_set() const { @@ -3368,7 +3368,7 @@ void TileData::set_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit, int ERR_FAIL_COND(!is_valid_peering_bit_terrain(p_peering_bit)); } terrain_peering_bits[p_peering_bit] = p_terrain_index; - emit_signal("changed"); + emit_signal(SNAME("changed")); } int TileData::get_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit) const { @@ -3386,7 +3386,7 @@ bool TileData::is_valid_peering_bit_terrain(TileSet::CellNeighbor p_peering_bit) void TileData::set_navigation_polygon(int p_layer_id, Ref<NavigationPolygon> p_navigation_polygon) { ERR_FAIL_INDEX(p_layer_id, navigation.size()); navigation.write[p_layer_id] = p_navigation_polygon; - emit_signal("changed"); + emit_signal(SNAME("changed")); } Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id) const { @@ -3398,7 +3398,7 @@ Ref<NavigationPolygon> TileData::get_navigation_polygon(int p_layer_id) const { void TileData::set_probability(float p_probability) { ERR_FAIL_COND(p_probability < 0.0); probability = p_probability; - emit_signal("changed"); + emit_signal(SNAME("changed")); } float TileData::get_probability() const { return probability; @@ -3422,7 +3422,7 @@ Variant TileData::get_custom_data(String p_layer_name) const { void TileData::set_custom_data_by_layer_id(int p_layer_id, Variant p_value) { ERR_FAIL_INDEX(p_layer_id, custom_data.size()); custom_data.write[p_layer_id] = p_value; - emit_signal("changed"); + emit_signal(SNAME("changed")); } Variant TileData::get_custom_data_by_layer_id(int p_layer_id) const { diff --git a/scene/resources/visual_shader.cpp b/scene/resources/visual_shader.cpp index b4a95f2592..0f6412e6e9 100644 --- a/scene/resources/visual_shader.cpp +++ b/scene/resources/visual_shader.cpp @@ -352,14 +352,14 @@ String VisualShaderNodeCustom::generate_code(Shader::Mode p_mode, VisualShader:: for (int i = 0; i < get_output_port_count(); i++) { output_vars.push_back(p_output_vars[i]); } - String code = "\t{\n"; + String code = " {\n"; String _code = (String)get_script_instance()->call("_get_code", input_vars, output_vars, (int)p_mode, (int)p_type); bool nend = _code.ends_with("\n"); - _code = _code.insert(0, "\t\t"); - _code = _code.replace("\n", "\n\t\t"); + _code = _code.insert(0, " "); + _code = _code.replace("\n", "\n "); code += _code; if (!nend) { - code += "\n\t}"; + code += "\n }"; } else { code.remove(code.size() - 1); code += "}"; @@ -900,7 +900,7 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port String expr = ""; expr += "// " + global_expression->get_caption() + ":" + itos(index++) + "\n"; expr += global_expression->generate_global(get_mode(), Type(i), -1); - expr = expr.replace("\n", "\n\t"); + expr = expr.replace("\n", "\n "); expr += "\n"; global_expressions += expr; } @@ -935,13 +935,13 @@ String VisualShader::generate_preview_shader(Type p_type, int p_node, int p_port ERR_FAIL_COND_V(err != OK, String()); if (node->get_output_port_type(p_port) == VisualShaderNode::PORT_TYPE_SCALAR) { - code += "\tCOLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " );\n"; + code += " COLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " );\n"; } else if (node->get_output_port_type(p_port) == VisualShaderNode::PORT_TYPE_SCALAR_INT) { - code += "\tCOLOR.rgb = vec3(float(n_out" + itos(p_node) + "p" + itos(p_port) + "));\n"; + code += " COLOR.rgb = vec3(float(n_out" + itos(p_node) + "p" + itos(p_port) + "));\n"; } else if (node->get_output_port_type(p_port) == VisualShaderNode::PORT_TYPE_BOOLEAN) { - code += "\tCOLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " ? 1.0 : 0.0);\n"; + code += " COLOR.rgb = vec3(n_out" + itos(p_node) + "p" + itos(p_port) + " ? 1.0 : 0.0);\n"; } else { - code += "\tCOLOR.rgb = n_out" + itos(p_node) + "p" + itos(p_port) + ";\n"; + code += " COLOR.rgb = n_out" + itos(p_node) + "p" + itos(p_port) + ";\n"; } code += "}\n"; @@ -1302,7 +1302,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui if (vsnode->is_disabled()) { code += "// " + vsnode->get_caption() + ":" + itos(node) + "\n"; - code += "\t// Node is disabled and code is not generated.\n"; + code += " // Node is disabled and code is not generated.\n"; return OK; } @@ -1432,19 +1432,19 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui if (defval.get_type() == Variant::FLOAT) { float val = defval; inputs[i] = "n_in" + itos(node) + "p" + itos(i); - node_code += "\tfloat " + inputs[i] + " = " + vformat("%.5f", val) + ";\n"; + node_code += " float " + inputs[i] + " = " + vformat("%.5f", val) + ";\n"; } else if (defval.get_type() == Variant::INT) { int val = defval; inputs[i] = "n_in" + itos(node) + "p" + itos(i); - node_code += "\tint " + inputs[i] + " = " + itos(val) + ";\n"; + node_code += " int " + inputs[i] + " = " + itos(val) + ";\n"; } else if (defval.get_type() == Variant::BOOL) { bool val = defval; inputs[i] = "n_in" + itos(node) + "p" + itos(i); - node_code += "\tbool " + inputs[i] + " = " + (val ? "true" : "false") + ";\n"; + node_code += " bool " + inputs[i] + " = " + (val ? "true" : "false") + ";\n"; } else if (defval.get_type() == Variant::VECTOR3) { Vector3 val = defval; inputs[i] = "n_in" + itos(node) + "p" + itos(i); - node_code += "\tvec3 " + inputs[i] + " = " + vformat("vec3(%.5f, %.5f, %.5f);\n", val.x, val.y, val.z); + node_code += " vec3 " + inputs[i] + " = " + vformat("vec3(%.5f, %.5f, %.5f);\n", val.x, val.y, val.z); } else if (defval.get_type() == Variant::TRANSFORM3D) { Transform3D val = defval; val.basis.transpose(); @@ -1459,7 +1459,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui values.push_back(val.origin.y); values.push_back(val.origin.z); bool err = false; - node_code += "\tmat4 " + inputs[i] + " = " + String("mat4(vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 1.0));\n").sprintf(values, &err); + node_code += " mat4 " + inputs[i] + " = " + String("mat4(vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 0.0), vec4(%.5f, %.5f, %.5f, 1.0));\n").sprintf(values, &err); } else { //will go empty, node is expected to know what it is doing at this point and handle it } @@ -1522,19 +1522,19 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui outputs[i] = "n_out" + itos(node) + "p" + itos(j); switch (vsnode->get_output_port_type(i)) { case VisualShaderNode::PORT_TYPE_SCALAR: - code += "\tfloat " + outputs[i] + ";\n"; + code += " float " + outputs[i] + ";\n"; break; case VisualShaderNode::PORT_TYPE_SCALAR_INT: - code += "\tint " + outputs[i] + ";\n"; + code += " int " + outputs[i] + ";\n"; break; case VisualShaderNode::PORT_TYPE_VECTOR: - code += "\tvec3 " + outputs[i] + ";\n"; + code += " vec3 " + outputs[i] + ";\n"; break; case VisualShaderNode::PORT_TYPE_BOOLEAN: - code += "\tbool " + outputs[i] + ";\n"; + code += " bool " + outputs[i] + ";\n"; break; case VisualShaderNode::PORT_TYPE_TRANSFORM: - code += "\tmat4 " + outputs[i] + ";\n"; + code += " mat4 " + outputs[i] + ";\n"; break; default: { } @@ -1564,7 +1564,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui new_line_inserted = true; } String r = "n_out" + itos(node) + "p" + itos(i + 1); - code += "\tfloat " + r + " = n_out" + itos(node) + "p" + itos(i) + ".r;\n"; + code += " float " + r + " = n_out" + itos(node) + "p" + itos(i) + ".r;\n"; outputs[i + 1] = r; } @@ -1574,7 +1574,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui new_line_inserted = true; } String g = "n_out" + itos(node) + "p" + itos(i + 2); - code += "\tfloat " + g + " = n_out" + itos(node) + "p" + itos(i) + ".g;\n"; + code += " float " + g + " = n_out" + itos(node) + "p" + itos(i) + ".g;\n"; outputs[i + 2] = g; } @@ -1584,7 +1584,7 @@ Error VisualShader::_write_node(Type type, StringBuilder &global_code, StringBui new_line_inserted = true; } String b = "n_out" + itos(node) + "p" + itos(i + 3); - code += "\tfloat " + b + " = n_out" + itos(node) + "p" + itos(i) + ".b;\n"; + code += " float " + b + " = n_out" + itos(node) + "p" + itos(i) + ".b;\n"; outputs[i + 3] = b; } @@ -1701,7 +1701,7 @@ void VisualShader::_update_shader() const { String expr = ""; expr += "// " + global_expression->get_caption() + ":" + itos(index++) + "\n"; expr += global_expression->generate_global(get_mode(), Type(i), -1); - expr = expr.replace("\n", "\n\t"); + expr = expr.replace("\n", "\n "); expr += "\n"; global_expressions += expr; } @@ -1814,112 +1814,112 @@ void VisualShader::_update_shader() const { code += "void start() {\n"; if (has_start || has_start_custom) { - code += "\tuint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n"; - code += "\tvec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n"; - code += "\tfloat __radians;\n"; - code += "\tvec3 __vec3_buff1;\n"; - code += "\tvec3 __vec3_buff2;\n"; - code += "\tfloat __scalar_buff1;\n"; - code += "\tfloat __scalar_buff2;\n"; - code += "\tvec3 __ndiff = normalize(__diff);\n\n"; + code += " uint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n"; + code += " vec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n"; + code += " float __radians;\n"; + code += " vec3 __vec3_buff1;\n"; + code += " vec3 __vec3_buff2;\n"; + code += " float __scalar_buff1;\n"; + code += " float __scalar_buff2;\n"; + code += " vec3 __ndiff = normalize(__diff);\n\n"; } if (has_start) { - code += "\t{\n"; - code += code_map[TYPE_START].replace("\n\t", "\n\t\t"); - code += "\t}\n"; + code += " {\n"; + code += code_map[TYPE_START].replace("\n ", "\n "); + code += " }\n"; if (has_start_custom) { - code += "\t\n"; + code += " \n"; } } if (has_start_custom) { - code += "\t{\n"; - code += code_map[TYPE_START_CUSTOM].replace("\n\t", "\n\t\t"); - code += "\t}\n"; + code += " {\n"; + code += code_map[TYPE_START_CUSTOM].replace("\n ", "\n "); + code += " }\n"; } code += "}\n\n"; code += "void process() {\n"; if (has_process || has_process_custom || has_collide) { - code += "\tuint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n"; - code += "\tvec3 __vec3_buff1;\n"; - code += "\tvec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n"; - code += "\tvec3 __ndiff = normalize(__diff);\n\n"; + code += " uint __seed = __hash(NUMBER + uint(1) + RANDOM_SEED);\n"; + code += " vec3 __vec3_buff1;\n"; + code += " vec3 __diff = TRANSFORM[3].xyz - EMISSION_TRANSFORM[3].xyz;\n"; + code += " vec3 __ndiff = normalize(__diff);\n\n"; } - code += "\t{\n"; - String tab = "\t"; + code += " {\n"; + String tab = " "; if (has_collide) { - code += "\t\tif (COLLIDED) {\n\n"; - code += code_map[TYPE_COLLIDE].replace("\n\t", "\n\t\t\t"); + code += " if (COLLIDED) {\n\n"; + code += code_map[TYPE_COLLIDE].replace("\n ", "\n "); if (has_process) { - code += "\t\t} else {\n\n"; - tab += "\t"; + code += " } else {\n\n"; + tab += " "; } } if (has_process) { - code += code_map[TYPE_PROCESS].replace("\n\t", "\n\t" + tab); + code += code_map[TYPE_PROCESS].replace("\n ", "\n " + tab); } if (has_collide) { - code += "\t\t}\n"; + code += " }\n"; } - code += "\t}\n"; + code += " }\n"; if (has_process_custom) { - code += "\t{\n\n"; - code += code_map[TYPE_PROCESS_CUSTOM].replace("\n\t", "\n\t\t"); - code += "\t}\n"; + code += " {\n\n"; + code += code_map[TYPE_PROCESS_CUSTOM].replace("\n ", "\n "); + code += " }\n"; } code += "}\n\n"; global_compute_code += "float __rand_from_seed(inout uint seed) {\n"; - global_compute_code += "\tint k;\n"; - global_compute_code += "\tint s = int(seed);\n"; - global_compute_code += "\tif (s == 0)\n"; - global_compute_code += "\ts = 305420679;\n"; - global_compute_code += "\tk = s / 127773;\n"; - global_compute_code += "\ts = 16807 * (s - k * 127773) - 2836 * k;\n"; - global_compute_code += "\tif (s < 0)\n"; - global_compute_code += "\t\ts += 2147483647;\n"; - global_compute_code += "\tseed = uint(s);\n"; - global_compute_code += "\treturn float(seed % uint(65536)) / 65535.0;\n"; + global_compute_code += " int k;\n"; + global_compute_code += " int s = int(seed);\n"; + global_compute_code += " if (s == 0)\n"; + global_compute_code += " s = 305420679;\n"; + global_compute_code += " k = s / 127773;\n"; + global_compute_code += " s = 16807 * (s - k * 127773) - 2836 * k;\n"; + global_compute_code += " if (s < 0)\n"; + global_compute_code += " s += 2147483647;\n"; + global_compute_code += " seed = uint(s);\n"; + global_compute_code += " return float(seed % uint(65536)) / 65535.0;\n"; global_compute_code += "}\n\n"; global_compute_code += "float __rand_from_seed_m1_p1(inout uint seed) {\n"; - global_compute_code += "\treturn __rand_from_seed(seed) * 2.0 - 1.0;\n"; + global_compute_code += " return __rand_from_seed(seed) * 2.0 - 1.0;\n"; global_compute_code += "}\n\n"; global_compute_code += "float __randf_range(inout uint seed, float from, float to) {\n"; - global_compute_code += "\treturn __rand_from_seed(seed) * (to - from) + from;\n"; + 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 += "\treturn 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 += " 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"; global_compute_code += "uint __hash(uint x) {\n"; - global_compute_code += "\tx = ((x >> uint(16)) ^ x) * uint(73244475);\n"; - global_compute_code += "\tx = ((x >> uint(16)) ^ x) * uint(73244475);\n"; - global_compute_code += "\tx = (x >> uint(16)) ^ x;\n"; - global_compute_code += "\treturn x;\n"; + global_compute_code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; + global_compute_code += " x = ((x >> uint(16)) ^ x) * uint(73244475);\n"; + global_compute_code += " x = (x >> uint(16)) ^ x;\n"; + global_compute_code += " return x;\n"; global_compute_code += "}\n\n"; global_compute_code += "mat3 __build_rotation_mat3(vec3 axis, float angle) {\n"; - global_compute_code += "\taxis = normalize(axis);\n"; - global_compute_code += "\tfloat s = sin(angle);\n"; - global_compute_code += "\tfloat c = cos(angle);\n"; - global_compute_code += "\tfloat oc = 1.0 - c;\n"; - global_compute_code += "\treturn mat3(vec3(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s), vec3(oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s), vec3(oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c));\n"; + global_compute_code += " axis = normalize(axis);\n"; + global_compute_code += " float s = sin(angle);\n"; + global_compute_code += " float c = cos(angle);\n"; + global_compute_code += " float oc = 1.0 - c;\n"; + global_compute_code += " return mat3(vec3(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s), vec3(oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s), vec3(oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c));\n"; global_compute_code += "}\n\n"; global_compute_code += "mat4 __build_rotation_mat4(vec3 axis, float angle) {\n"; - global_compute_code += "\taxis = normalize(axis);\n"; - global_compute_code += "\tfloat s = sin(angle);\n"; - global_compute_code += "\tfloat c = cos(angle);\n"; - global_compute_code += "\tfloat oc = 1.0 - c;\n"; - global_compute_code += "\treturn mat4(vec4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0), vec4(oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0), vec4(oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0), vec4(0, 0, 0, 1));\n"; + global_compute_code += " axis = normalize(axis);\n"; + global_compute_code += " float s = sin(angle);\n"; + global_compute_code += " float c = cos(angle);\n"; + global_compute_code += " float oc = 1.0 - c;\n"; + global_compute_code += " return mat4(vec4(oc * axis.x * axis.x + c, oc * axis.x * axis.y - axis.z * s, oc * axis.z * axis.x + axis.y * s, 0), vec4(oc * axis.x * axis.y + axis.z * s, oc * axis.y * axis.y + c, oc * axis.y * axis.z - axis.x * s, 0), vec4(oc * axis.z * axis.x - axis.y * s, oc * axis.y * axis.z + axis.x * s, oc * axis.z * axis.z + c, 0), vec4(0, 0, 0, 1));\n"; global_compute_code += "}\n\n"; global_compute_code += "vec3 __get_random_unit_vec3(inout uint seed) {\n"; - global_compute_code += "\treturn normalize(vec3(__rand_from_seed_m1_p1(seed), __rand_from_seed_m1_p1(seed), __rand_from_seed_m1_p1(seed)));\n"; + global_compute_code += " return normalize(vec3(__rand_from_seed_m1_p1(seed), __rand_from_seed_m1_p1(seed), __rand_from_seed_m1_p1(seed)));\n"; global_compute_code += "}\n\n"; } @@ -1943,7 +1943,7 @@ void VisualShader::_update_shader() const { const_cast<VisualShader *>(this)->set_default_texture_param(default_tex_params[i].name, default_tex_params[i].param); } if (previous_code != final_code) { - const_cast<VisualShader *>(this)->emit_signal("changed"); + const_cast<VisualShader *>(this)->emit_signal(SNAME("changed")); } previous_code = final_code; } @@ -1954,7 +1954,7 @@ void VisualShader::_queue_update() { } dirty.set(); - call_deferred("_update_shader"); + call_deferred(SNAME("_update_shader")); } void VisualShader::_input_type_changed(Type p_type, int p_id) { @@ -2380,7 +2380,7 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T while (preview_ports[idx].mode != Shader::MODE_MAX) { if (preview_ports[idx].mode == shader_mode && preview_ports[idx].shader_type == shader_type && preview_ports[idx].name == input_name) { - code = "\t" + p_output_vars[0] + " = " + preview_ports[idx].string + ";\n"; + code = " " + p_output_vars[0] + " = " + preview_ports[idx].string + ";\n"; break; } idx++; @@ -2389,19 +2389,19 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T if (code == String()) { switch (get_output_port_type(0)) { case PORT_TYPE_SCALAR: { - code = "\t" + p_output_vars[0] + " = 0.0;\n"; + code = " " + p_output_vars[0] + " = 0.0;\n"; } break; case PORT_TYPE_SCALAR_INT: { - code = "\t" + p_output_vars[0] + " = 0;\n"; + code = " " + p_output_vars[0] + " = 0;\n"; } break; case PORT_TYPE_VECTOR: { - code = "\t" + p_output_vars[0] + " = vec3(0.0);\n"; + code = " " + p_output_vars[0] + " = vec3(0.0);\n"; } break; case PORT_TYPE_TRANSFORM: { - code = "\t" + p_output_vars[0] + " = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; + code = " " + p_output_vars[0] + " = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; } break; case PORT_TYPE_BOOLEAN: { - code = "\t" + p_output_vars[0] + " = false;\n"; + code = " " + p_output_vars[0] + " = false;\n"; } break; default: //default (none found) is scalar break; @@ -2417,14 +2417,14 @@ String VisualShaderNodeInput::generate_code(Shader::Mode p_mode, VisualShader::T while (ports[idx].mode != Shader::MODE_MAX) { if (ports[idx].mode == shader_mode && ports[idx].shader_type == shader_type && ports[idx].name == input_name) { - code = "\t" + p_output_vars[0] + " = " + ports[idx].string + ";\n"; + code = " " + p_output_vars[0] + " = " + ports[idx].string + ";\n"; break; } idx++; } if (code == String()) { - code = "\t" + p_output_vars[0] + " = 0.0;\n"; //default (none found) is scalar + code = " " + p_output_vars[0] + " = 0.0;\n"; //default (none found) is scalar } return code; @@ -2436,7 +2436,7 @@ void VisualShaderNodeInput::set_input_name(String p_name) { input_name = p_name; emit_changed(); if (get_input_type_by_name(input_name) != prev_type) { - emit_signal("input_type_changed"); + emit_signal(SNAME("input_type_changed")); } } @@ -2748,20 +2748,20 @@ String VisualShaderNodeUniformRef::generate_code(Shader::Mode p_mode, VisualShad switch (uniform_type) { case UniformType::UNIFORM_TYPE_FLOAT: if (uniform_name == "[None]") { - return "\t" + p_output_vars[0] + " = 0.0;\n"; + return " " + p_output_vars[0] + " = 0.0;\n"; } - return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; case UniformType::UNIFORM_TYPE_INT: - return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; case UniformType::UNIFORM_TYPE_BOOLEAN: - return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; case UniformType::UNIFORM_TYPE_VECTOR: - return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; case UniformType::UNIFORM_TYPE_TRANSFORM: - return "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; case UniformType::UNIFORM_TYPE_COLOR: { - String code = "\t" + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n"; - code += "\t" + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n"; + String code = " " + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n"; + code += " " + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n"; return code; } break; case UniformType::UNIFORM_TYPE_SAMPLER: @@ -2957,9 +2957,9 @@ String VisualShaderNodeOutput::generate_code(Shader::Mode p_mode, VisualShader:: if (p_input_vars[count] != String()) { String s = ports[idx].string; if (s.find(":") != -1) { - code += "\t" + s.get_slicec(':', 0) + " = " + p_input_vars[count] + "." + s.get_slicec(':', 1) + ";\n"; + code += " " + s.get_slicec(':', 0) + " = " + p_input_vars[count] + "." + s.get_slicec(':', 1) + ";\n"; } else { - code += "\t" + s + " = " + p_input_vars[count] + ";\n"; + code += " " + s + " = " + p_input_vars[count] + ";\n"; } } count++; @@ -2977,7 +2977,7 @@ VisualShaderNodeOutput::VisualShaderNodeOutput() { void VisualShaderNodeUniform::set_uniform_name(const String &p_name) { uniform_name = p_name; - emit_signal("name_changed"); + emit_signal(SNAME("name_changed")); emit_changed(); } @@ -3634,11 +3634,11 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad String _expression = expression; _expression = _expression.insert(0, "\n"); - _expression = _expression.replace("\n", "\n\t\t"); + _expression = _expression.replace("\n", "\n "); static Vector<String> pre_symbols; if (pre_symbols.is_empty()) { - pre_symbols.push_back("\t"); + pre_symbols.push_back(" "); pre_symbols.push_back(","); pre_symbols.push_back(";"); pre_symbols.push_back("{"); @@ -3658,7 +3658,7 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad static Vector<String> post_symbols; if (post_symbols.is_empty()) { - post_symbols.push_back("\t"); + post_symbols.push_back(" "); post_symbols.push_back("\n"); post_symbols.push_back(","); post_symbols.push_back(";"); @@ -3717,14 +3717,14 @@ String VisualShaderNodeExpression::generate_code(Shader::Mode p_mode, VisualShad default: continue; } - output_initializer += "\t" + p_output_vars[i] + " = " + tk + ";\n"; + output_initializer += " " + p_output_vars[i] + " = " + tk + ";\n"; } String code; code += output_initializer; - code += "\t{"; + code += " {"; code += _expression; - code += "\n\t}\n"; + code += "\n }\n"; return code; } diff --git a/scene/resources/visual_shader_nodes.cpp b/scene/resources/visual_shader_nodes.cpp index 79ea9d72df..6fd6fd8f3b 100644 --- a/scene/resources/visual_shader_nodes.cpp +++ b/scene/resources/visual_shader_nodes.cpp @@ -66,7 +66,7 @@ String VisualShaderNodeFloatConstant::get_output_port_name(int p_port) const { } String VisualShaderNodeFloatConstant::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 "\t" + p_output_vars[0] + " = " + vformat("%.6f", constant) + ";\n"; + return " " + p_output_vars[0] + " = " + vformat("%.6f", constant) + ";\n"; } void VisualShaderNodeFloatConstant::set_constant(float p_value) { @@ -125,7 +125,7 @@ String VisualShaderNodeIntConstant::get_output_port_name(int p_port) const { } String VisualShaderNodeIntConstant::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 "\t" + p_output_vars[0] + " = " + itos(constant) + ";\n"; + return " " + p_output_vars[0] + " = " + itos(constant) + ";\n"; } void VisualShaderNodeIntConstant::set_constant(int p_value) { @@ -184,7 +184,7 @@ String VisualShaderNodeBooleanConstant::get_output_port_name(int p_port) const { } String VisualShaderNodeBooleanConstant::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 "\t" + p_output_vars[0] + " = " + (constant ? "true" : "false") + ";\n"; + return " " + p_output_vars[0] + " = " + (constant ? "true" : "false") + ";\n"; } void VisualShaderNodeBooleanConstant::set_constant(bool p_value) { @@ -251,8 +251,8 @@ bool VisualShaderNodeColorConstant::is_output_port_expandable(int p_port) const String VisualShaderNodeColorConstant::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; - code += "\t" + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.r, constant.g, constant.b) + ";\n"; - code += "\t" + p_output_vars[1] + " = " + vformat("%.6f", constant.a) + ";\n"; + code += " " + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.r, constant.g, constant.b) + ";\n"; + code += " " + p_output_vars[1] + " = " + vformat("%.6f", constant.a) + ";\n"; return code; } @@ -313,7 +313,7 @@ String VisualShaderNodeVec3Constant::get_output_port_name(int p_port) const { } String VisualShaderNodeVec3Constant::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 "\t" + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.x, constant.y, constant.z) + ";\n"; + return " " + p_output_vars[0] + " = " + vformat("vec3(%.6f, %.6f, %.6f)", constant.x, constant.y, constant.z) + ";\n"; } void VisualShaderNodeVec3Constant::set_constant(Vector3 p_value) { @@ -375,7 +375,7 @@ String VisualShaderNodeTransformConstant::generate_code(Shader::Mode p_mode, Vis Transform3D t = constant; t.basis.transpose(); - String code = "\t" + p_output_vars[0] + " = mat4("; + String code = " " + p_output_vars[0] + " = mat4("; code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[0].x, t.basis[0].y, t.basis[0].z); code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[1].x, t.basis[1].y, t.basis[1].z); code += vformat("vec4(%.6f, %.6f, %.6f, 0.0), ", t.basis[2].x, t.basis[2].y, t.basis[2].z); @@ -523,20 +523,20 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: if (p_input_vars[0] == String()) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\tvec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n"; + code += " vec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n"; } else { - code += "\tvec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; + code += " vec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\tvec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; + code += " vec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { - code += "\tvec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; + code += " vec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; } - code += "\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n"; - code += "\t" + p_output_vars[1] + " = " + id + "_read.a;\n"; + code += " " + p_output_vars[0] + " = " + id + "_read.rgb;\n"; + code += " " + p_output_vars[1] + " = " + id + "_read.a;\n"; return code; } @@ -544,98 +544,98 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: String id = p_input_vars[2]; String code; - code += "\t{\n"; + code += " {\n"; if (id == String()) { - code += "\t\tvec4 " + id + "_tex_read = vec4(0.0);\n"; + code += " vec4 " + id + "_tex_read = vec4(0.0);\n"; } else { if (p_input_vars[0] == String()) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n"; + code += " vec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { - code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; + code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; + code += " vec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { - code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; + code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; } - code += "\t\t" + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = " + id + "_tex_read.a;\n"; + code += " " + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n"; + code += " " + p_output_vars[1] + " = " + id + "_tex_read.a;\n"; } - code += "\t}\n"; + code += " }\n"; return code; } if (source == SOURCE_SCREEN && (p_mode == Shader::MODE_SPATIAL || p_mode == Shader::MODE_CANVAS_ITEM) && p_type == VisualShader::TYPE_FRAGMENT) { - String code = "\t{\n"; + String code = " {\n"; if (p_input_vars[0] == String() || p_for_preview) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", 0.0 );\n"; + code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", 0.0 );\n"; } else { - code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; + code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, 0.0);\n"; + code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, 0.0);\n"; } else { - code += "\t\tvec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; + code += " vec4 _tex_read = textureLod(SCREEN_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; } - code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = _tex_read.rgb;\n"; + code += " " + p_output_vars[1] + " = _tex_read.a;\n"; + code += " }\n"; return code; } if (source == SOURCE_2D_TEXTURE && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { - String code = "\t{\n"; + String code = " {\n"; if (p_input_vars[0] == String()) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\t\tvec4 _tex_read = texture(TEXTURE, " + default_uv + ");\n"; + code += " vec4 _tex_read = texture(TEXTURE, " + default_uv + ");\n"; } else { - code += "\t\tvec4 _tex_read = textureLod(TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; + code += " vec4 _tex_read = textureLod(TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\t\tvec4 _tex_read = texture(TEXTURE, " + p_input_vars[0] + ".xy);\n"; + code += " vec4 _tex_read = texture(TEXTURE, " + p_input_vars[0] + ".xy);\n"; } else { - code += "\t\tvec4 _tex_read = textureLod(TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; + code += " vec4 _tex_read = textureLod(TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; } - code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = _tex_read.rgb;\n"; + code += " " + p_output_vars[1] + " = _tex_read.a;\n"; + code += " }\n"; return code; } if (source == SOURCE_2D_NORMAL && p_mode == Shader::MODE_CANVAS_ITEM && p_type == VisualShader::TYPE_FRAGMENT) { - String code = "\t{\n"; + String code = " {\n"; if (p_input_vars[0] == String()) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\t\tvec4 _tex_read = texture(NORMAL_TEXTURE, " + default_uv + ");\n"; + code += " vec4 _tex_read = texture(NORMAL_TEXTURE, " + default_uv + ");\n"; } else { - code += "\t\tvec4 _tex_read = textureLod(NORMAL_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; + code += " vec4 _tex_read = textureLod(NORMAL_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ");\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\t\tvec4 _tex_read = texture(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy);\n"; + code += " vec4 _tex_read = texture(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy);\n"; } else { - code += "\t\tvec4 _tex_read = textureLod(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; + code += " vec4 _tex_read = textureLod(NORMAL_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; } - code += "\t\t" + p_output_vars[0] + " = _tex_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = _tex_read.a;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = _tex_read.rgb;\n"; + code += " " + p_output_vars[1] + " = _tex_read.a;\n"; + code += " }\n"; return code; } @@ -643,44 +643,44 @@ String VisualShaderNodeTexture::generate_code(Shader::Mode p_mode, VisualShader: { if (source == SOURCE_DEPTH) { String code; - code += "\t" + p_output_vars[0] + " = 0.0;\n"; - code += "\t" + p_output_vars[1] + " = 1.0;\n"; + code += " " + p_output_vars[0] + " = 0.0;\n"; + code += " " + p_output_vars[1] + " = 1.0;\n"; return code; } } if (source == SOURCE_DEPTH && p_mode == Shader::MODE_SPATIAL && p_type == VisualShader::TYPE_FRAGMENT) { - String code = "\t{\n"; + String code = " {\n"; if (p_input_vars[0] == String()) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\t\tfloat _depth = texture(DEPTH_TEXTURE, " + default_uv + ").r;\n"; + code += " float _depth = texture(DEPTH_TEXTURE, " + default_uv + ").r;\n"; } else { - code += "\t\tfloat _depth = textureLod(DEPTH_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ").r;\n"; + code += " float _depth = textureLod(DEPTH_TEXTURE, " + default_uv + ", " + p_input_vars[1] + ").r;\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\t\tfloat _depth = texture(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy).r;\n"; + code += " float _depth = texture(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy).r;\n"; } else { - code += "\t\tfloat _depth = textureLod(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ").r;\n"; + code += " float _depth = textureLod(DEPTH_TEXTURE, " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ").r;\n"; } - code += "\t\t" + p_output_vars[0] + " = _depth;\n"; - code += "\t\t" + p_output_vars[1] + " = 1.0;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = _depth;\n"; + code += " " + p_output_vars[1] + " = 1.0;\n"; + code += " }\n"; return code; } else if (source == SOURCE_DEPTH) { String code; - code += "\t" + p_output_vars[0] + " = 0.0;\n"; - code += "\t" + p_output_vars[1] + " = 1.0;\n"; + code += " " + p_output_vars[0] + " = 0.0;\n"; + code += " " + p_output_vars[1] + " = 1.0;\n"; return code; } //none String code; - code += "\t" + p_output_vars[0] + " = vec3(0.0);\n"; - code += "\t" + p_output_vars[1] + " = 1.0;\n"; + code += " " + p_output_vars[0] + " = vec3(0.0);\n"; + code += " " + p_output_vars[1] + " = 1.0;\n"; return code; } @@ -707,7 +707,7 @@ void VisualShaderNodeTexture::set_source(Source p_source) { break; } emit_changed(); - emit_signal("editor_refresh_request"); + emit_signal(SNAME("editor_refresh_request")); } VisualShaderNodeTexture::Source VisualShaderNodeTexture::get_source() const { @@ -856,11 +856,11 @@ String VisualShaderNodeCurveTexture::generate_global(Shader::Mode p_mode, Visual String VisualShaderNodeCurveTexture::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 { if (p_input_vars[0] == String()) { - return "\t" + p_output_vars[0] + " = 0.0;\n"; + return " " + p_output_vars[0] + " = 0.0;\n"; } String id = make_unique_id(p_type, p_id, "curve"); String code; - code += "\t" + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).r;\n"; + code += " " + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).r;\n"; return code; } @@ -940,11 +940,11 @@ String VisualShaderNodeCurveXYZTexture::generate_global(Shader::Mode p_mode, Vis String VisualShaderNodeCurveXYZTexture::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 { if (p_input_vars[0] == String()) { - return "\t" + p_output_vars[0] + " = vec3(0.0);\n"; + return " " + p_output_vars[0] + " = vec3(0.0);\n"; } String id = make_unique_id(p_type, p_id, "curve3d"); String code; - code += "\t" + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).rgb;\n"; + code += " " + p_output_vars[0] + " = texture(" + id + ", vec2(" + p_input_vars[0] + ")).rgb;\n"; return code; } @@ -1040,7 +1040,7 @@ String VisualShaderNodeSample3D::generate_code(Shader::Mode p_mode, VisualShader String code; if (source == SOURCE_TEXTURE || source == SOURCE_PORT) { String id; - code += "\t{\n"; + code += " {\n"; if (source == SOURCE_TEXTURE) { id = make_unique_id(p_type, p_id, "tex3d"); } else { @@ -1049,34 +1049,34 @@ String VisualShaderNodeSample3D::generate_code(Shader::Mode p_mode, VisualShader if (id != String()) { if (p_input_vars[0] == String()) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n"; + code += " vec4 " + id + "_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { - code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; + code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\t\tvec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; + code += " vec4 " + id + "_tex_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; } else { - code += "\t\tvec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + code += " vec4 " + id + "_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } } else { - code += "\t\tvec4 " + id + "_tex_read = vec4(0.0);\n"; + code += " vec4 " + id + "_tex_read = vec4(0.0);\n"; } - code += "\t\t" + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = " + id + "_tex_read.a;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = " + id + "_tex_read.rgb;\n"; + code += " " + p_output_vars[1] + " = " + id + "_tex_read.a;\n"; + code += " }\n"; return code; } - code += "\t" + p_output_vars[0] + " = vec3(0.0);\n"; - code += "\t" + p_output_vars[1] + " = 1.0;\n"; + code += " " + p_output_vars[0] + " = vec3(0.0);\n"; + code += " " + p_output_vars[1] + " = 1.0;\n"; return code; } void VisualShaderNodeSample3D::set_source(Source p_source) { source = p_source; emit_changed(); - emit_signal("editor_refresh_request"); + emit_signal(SNAME("editor_refresh_request")); } VisualShaderNodeSample3D::Source VisualShaderNodeSample3D::get_source() const { @@ -1325,33 +1325,33 @@ String VisualShaderNodeCubemap::generate_code(Shader::Mode p_mode, VisualShader: return String(); } - code += "\t{\n"; + code += " {\n"; if (id == String()) { - code += "\t\tvec4 " + id + "_read = vec4(0.0);\n"; - code += "\t\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = " + id + "_read.a;\n"; - code += "\t}\n"; + code += " vec4 " + id + "_read = vec4(0.0);\n"; + code += " " + p_output_vars[0] + " = " + id + "_read.rgb;\n"; + code += " " + p_output_vars[1] + " = " + id + "_read.a;\n"; + code += " }\n"; return code; } if (p_input_vars[0] == String()) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\t\tvec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n"; + code += " vec4 " + id + "_read = texture(" + id + ", " + default_uv + ");\n"; } else { - code += "\t\tvec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + " );\n"; + code += " vec4 " + id + "_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + " );\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\t\tvec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; + code += " vec4 " + id + "_read = texture(" + id + ", " + p_input_vars[0] + ");\n"; } else { - code += "\t\tvec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + code += " vec4 " + id + "_read = textureLod(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } - code += "\t\t" + p_output_vars[0] + " = " + id + "_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = " + id + "_read.a;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = " + id + "_read.rgb;\n"; + code += " " + p_output_vars[1] + " = " + id + "_read.a;\n"; + code += " }\n"; return code; } @@ -1366,7 +1366,7 @@ String VisualShaderNodeCubemap::get_input_port_default_hint(int p_port) const { void VisualShaderNodeCubemap::set_source(Source p_source) { source = p_source; emit_changed(); - emit_signal("editor_refresh_request"); + emit_signal(SNAME("editor_refresh_request")); } VisualShaderNodeCubemap::Source VisualShaderNodeCubemap::get_source() const { @@ -1465,7 +1465,7 @@ String VisualShaderNodeFloatOp::get_output_port_name(int p_port) const { } String VisualShaderNodeFloatOp::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 = "\t" + p_output_vars[0] + " = "; + String code = " " + p_output_vars[0] + " = "; switch (op) { case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; @@ -1571,7 +1571,7 @@ String VisualShaderNodeIntOp::get_output_port_name(int p_port) const { } String VisualShaderNodeIntOp::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 = "\t" + p_output_vars[0] + " = "; + String code = " " + p_output_vars[0] + " = "; switch (op) { case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; @@ -1665,7 +1665,7 @@ String VisualShaderNodeVectorOp::get_output_port_name(int p_port) const { } String VisualShaderNodeVectorOp::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 = "\t" + p_output_vars[0] + " = "; + String code = " " + p_output_vars[0] + " = "; switch (op) { case OP_ADD: code += p_input_vars[0] + " + " + p_input_vars[1] + ";\n"; @@ -1783,64 +1783,64 @@ String VisualShaderNodeColorOp::generate_code(Shader::Mode p_mode, VisualShader: static const char *axisn[3] = { "x", "y", "z" }; switch (op) { case OP_SCREEN: { - code += "\t" + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") * (vec3(1.0) - " + p_input_vars[1] + ");\n"; + code += " " + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") * (vec3(1.0) - " + p_input_vars[1] + ");\n"; } break; case OP_DIFFERENCE: { - code += "\t" + p_output_vars[0] + " = abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ");\n"; + code += " " + p_output_vars[0] + " = abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ");\n"; } break; case OP_DARKEN: { - code += "\t" + p_output_vars[0] + " = min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + code += " " + p_output_vars[0] + " = min(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } break; case OP_LIGHTEN: { - code += "\t" + p_output_vars[0] + " = max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + code += " " + p_output_vars[0] + " = max(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } break; case OP_OVERLAY: { for (int i = 0; i < 3; i++) { - code += "\t{\n"; - code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; - code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n"; - code += "\t\tif (base < 0.5) {\n"; - code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = 2.0 * base * blend;\n"; - code += "\t\t} else {\n"; - code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n"; - code += "\t\t}\n"; - code += "\t}\n"; + code += " {\n"; + code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; + code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n"; + code += " if (base < 0.5) {\n"; + code += " " + p_output_vars[0] + "." + axisn[i] + " = 2.0 * base * blend;\n"; + code += " } else {\n"; + code += " " + p_output_vars[0] + "." + axisn[i] + " = 1.0 - 2.0 * (1.0 - blend) * (1.0 - base);\n"; + code += " }\n"; + code += " }\n"; } } break; case OP_DODGE: { - code += "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + ") / (vec3(1.0) - " + p_input_vars[1] + ");\n"; + code += " " + p_output_vars[0] + " = (" + p_input_vars[0] + ") / (vec3(1.0) - " + p_input_vars[1] + ");\n"; } break; case OP_BURN: { - code += "\t" + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") / (" + p_input_vars[1] + ");\n"; + code += " " + p_output_vars[0] + " = vec3(1.0) - (vec3(1.0) - " + p_input_vars[0] + ") / (" + p_input_vars[1] + ");\n"; } break; case OP_SOFT_LIGHT: { for (int i = 0; i < 3; i++) { - code += "\t{\n"; - code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; - code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n"; - code += "\t\tif (base < 0.5) {\n"; - code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (base * (blend + 0.5));\n"; - code += "\t\t} else {\n"; - code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - (blend - 0.5)));\n"; - code += "\t\t}\n"; - code += "\t}\n"; + code += " {\n"; + code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; + code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n"; + code += " if (base < 0.5) {\n"; + code += " " + p_output_vars[0] + "." + axisn[i] + " = (base * (blend + 0.5));\n"; + code += " } else {\n"; + code += " " + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - (blend - 0.5)));\n"; + code += " }\n"; + code += " }\n"; } } break; case OP_HARD_LIGHT: { for (int i = 0; i < 3; i++) { - code += "\t{\n"; - code += "\t\tfloat base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; - code += "\t\tfloat blend = " + p_input_vars[1] + "." + axisn[i] + ";\n"; - code += "\t\tif (base < 0.5) {\n"; - code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (base * (2.0 * blend));\n"; - code += "\t\t} else {\n"; - code += "\t\t\t" + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - 2.0 * (blend - 0.5)));\n"; - code += "\t\t}\n"; - code += "\t}\n"; + code += " {\n"; + code += " float base = " + p_input_vars[0] + "." + axisn[i] + ";\n"; + code += " float blend = " + p_input_vars[1] + "." + axisn[i] + ";\n"; + code += " if (base < 0.5) {\n"; + code += " " + p_output_vars[0] + "." + axisn[i] + " = (base * (2.0 * blend));\n"; + code += " } else {\n"; + code += " " + p_output_vars[0] + "." + axisn[i] + " = (1.0 - (1.0 - base) * (1.0 - 2.0 * (blend - 0.5)));\n"; + code += " }\n"; + code += " }\n"; } } break; @@ -1947,13 +1947,13 @@ String VisualShaderNodeTransformMult::get_output_port_name(int p_port) const { String VisualShaderNodeTransformMult::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 { if (op == OP_AxB) { - return "\t" + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n"; + return " " + p_output_vars[0] + " = " + p_input_vars[0] + " * " + p_input_vars[1] + ";\n"; } else if (op == OP_BxA) { - return "\t" + p_output_vars[0] + " = " + p_input_vars[1] + " * " + p_input_vars[0] + ";\n"; + return " " + p_output_vars[0] + " = " + p_input_vars[1] + " * " + p_input_vars[0] + ";\n"; } else if (op == OP_AxB_COMP) { - return "\t" + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } else { - return "\t" + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[1] + ", " + p_input_vars[0] + ");\n"; + return " " + p_output_vars[0] + " = matrixCompMult(" + p_input_vars[1] + ", " + p_input_vars[0] + ");\n"; } } @@ -2021,13 +2021,13 @@ String VisualShaderNodeTransformVecMult::get_output_port_name(int p_port) const String VisualShaderNodeTransformVecMult::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 { if (op == OP_AxB) { - return "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 1.0)).xyz;\n"; + return " " + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 1.0)).xyz;\n"; } else if (op == OP_BxA) { - return "\t" + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 1.0) * " + p_input_vars[0] + ").xyz;\n"; + return " " + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 1.0) * " + p_input_vars[0] + ").xyz;\n"; } else if (op == OP_3x3_AxB) { - return "\t" + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 0.0)).xyz;\n"; + return " " + p_output_vars[0] + " = (" + p_input_vars[0] + " * vec4(" + p_input_vars[1] + ", 0.0)).xyz;\n"; } else { - return "\t" + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 0.0) * " + p_input_vars[0] + ").xyz;\n"; + return " " + p_output_vars[0] + " = (vec4(" + p_input_vars[1] + ", 0.0) * " + p_input_vars[0] + ").xyz;\n"; } } @@ -2129,7 +2129,7 @@ String VisualShaderNodeFloatFunc::generate_code(Shader::Mode p_mode, VisualShade "1.0 - $" }; - return "\t" + p_output_vars[0] + " = " + String(scalar_func_id[func]).replace("$", p_input_vars[0]) + ";\n"; + return " " + p_output_vars[0] + " = " + String(scalar_func_id[func]).replace("$", p_input_vars[0]) + ";\n"; } void VisualShaderNodeFloatFunc::set_function(Function p_func) { @@ -2228,7 +2228,7 @@ String VisualShaderNodeIntFunc::generate_code(Shader::Mode p_mode, VisualShader: "sign($)" }; - return "\t" + p_output_vars[0] + " = " + String(int_func_id[func]).replace("$", p_input_vars[0]) + ";\n"; + return " " + p_output_vars[0] + " = " + String(int_func_id[func]).replace("$", p_input_vars[0]) + ";\n"; } void VisualShaderNodeIntFunc::set_function(Function p_func) { @@ -2333,25 +2333,25 @@ String VisualShaderNodeVectorFunc::generate_code(Shader::Mode p_mode, VisualShad String code; if (func == FUNC_RGB2HSV) { - code += "\t{\n"; - code += "\t\tvec3 c = " + p_input_vars[0] + ";\n"; - code += "\t\tvec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n"; - code += "\t\tvec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n"; - code += "\t\tvec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n"; - code += "\t\tfloat d = q.x - min(q.w, q.y);\n"; - code += "\t\tfloat e = 1.0e-10;\n"; - code += "\t\t" + p_output_vars[0] + " = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n"; - code += "\t}\n"; + code += " {\n"; + code += " vec3 c = " + p_input_vars[0] + ";\n"; + code += " vec4 K = vec4(0.0, -1.0 / 3.0, 2.0 / 3.0, -1.0);\n"; + code += " vec4 p = mix(vec4(c.bg, K.wz), vec4(c.gb, K.xy), step(c.b, c.g));\n"; + code += " vec4 q = mix(vec4(p.xyw, c.r), vec4(c.r, p.yzx), step(p.x, c.r));\n"; + code += " float d = q.x - min(q.w, q.y);\n"; + code += " float e = 1.0e-10;\n"; + code += " " + p_output_vars[0] + " = vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x);\n"; + code += " }\n"; } else if (func == FUNC_HSV2RGB) { - code += "\t{\n"; - code += "\t\tvec3 c = " + p_input_vars[0] + ";\n"; - code += "\t\tvec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n"; - code += "\t\tvec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n"; - code += "\t\t" + p_output_vars[0] + " = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n"; - code += "\t}\n"; + code += " {\n"; + code += " vec3 c = " + p_input_vars[0] + ";\n"; + code += " vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0);\n"; + code += " vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www);\n"; + code += " " + p_output_vars[0] + " = c.z * mix(K.xxx, clamp(p - K.xxx, 0.0, 1.0), c.y);\n"; + code += " }\n"; } else { - code += "\t" + p_output_vars[0] + " = " + String(vec_func_id[func]).replace("$", p_input_vars[0]) + ";\n"; + code += " " + p_output_vars[0] + " = " + String(vec_func_id[func]).replace("$", p_input_vars[0]) + ";\n"; } return code; @@ -2461,22 +2461,22 @@ String VisualShaderNodeColorFunc::generate_code(Shader::Mode p_mode, VisualShade switch (func) { case FUNC_GRAYSCALE: - code += "\t{\n"; - code += "\t\tvec3 c = " + p_input_vars[0] + ";\n"; - code += "\t\tfloat max1 = max(c.r, c.g);\n"; - code += "\t\tfloat max2 = max(max1, c.b);\n"; - code += "\t\tfloat max3 = max(max1, max2);\n"; - code += "\t\t" + p_output_vars[0] + " = vec3(max3, max3, max3);\n"; - code += "\t}\n"; + code += " {\n"; + 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 += " }\n"; break; case FUNC_SEPIA: - code += "\t{\n"; - code += "\t\tvec3 c = " + p_input_vars[0] + ";\n"; - code += "\t\tfloat r = (c.r * .393) + (c.g *.769) + (c.b * .189);\n"; - code += "\t\tfloat g = (c.r * .349) + (c.g *.686) + (c.b * .168);\n"; - code += "\t\tfloat b = (c.r * .272) + (c.g *.534) + (c.b * .131);\n"; - code += "\t\t" + p_output_vars[0] + " = vec3(r, g, b);\n"; - code += "\t}\n"; + code += " {\n"; + code += " vec3 c = " + p_input_vars[0] + ";\n"; + code += " float r = (c.r * .393) + (c.g *.769) + (c.b * .189);\n"; + code += " float g = (c.r * .349) + (c.g *.686) + (c.b * .168);\n"; + code += " float b = (c.r * .272) + (c.g *.534) + (c.b * .131);\n"; + code += " " + p_output_vars[0] + " = vec3(r, g, b);\n"; + code += " }\n"; break; } @@ -2550,7 +2550,7 @@ String VisualShaderNodeTransformFunc::generate_code(Shader::Mode p_mode, VisualS }; String code; - code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n"; + code += " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n"; return code; } @@ -2668,10 +2668,10 @@ String VisualShaderNodeUVFunc::generate_code(Shader::Mode p_mode, VisualShader:: switch (func) { case FUNC_PANNING: { - code += vformat("\t%s = fma(%s, %s, %s);\n", p_output_vars[0], offset_pivot, scale, uv); + code += vformat(" %s = fma(%s, %s, %s);\n", p_output_vars[0], offset_pivot, scale, uv); } break; case FUNC_SCALING: { - code += vformat("\t%s = fma((%s - %s), %s, %s);\n", p_output_vars[0], uv, offset_pivot, scale, offset_pivot); + code += vformat(" %s = fma((%s - %s), %s, %s);\n", p_output_vars[0], uv, offset_pivot, scale, offset_pivot); } break; case FUNC_MAX: break; @@ -2751,7 +2751,7 @@ String VisualShaderNodeDotProduct::get_output_port_name(int p_port) const { } String VisualShaderNodeDotProduct::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 "\t" + p_output_vars[0] + " = dot(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + return " " + p_output_vars[0] + " = dot(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } VisualShaderNodeDotProduct::VisualShaderNodeDotProduct() { @@ -2790,7 +2790,7 @@ String VisualShaderNodeVectorLen::get_output_port_name(int p_port) const { } String VisualShaderNodeVectorLen::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 "\t" + p_output_vars[0] + " = length(" + p_input_vars[0] + ");\n"; + return " " + p_output_vars[0] + " = length(" + p_input_vars[0] + ");\n"; } VisualShaderNodeVectorLen::VisualShaderNodeVectorLen() { @@ -2828,7 +2828,7 @@ String VisualShaderNodeDeterminant::get_output_port_name(int p_port) const { } String VisualShaderNodeDeterminant::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 "\t" + p_output_vars[0] + " = determinant(" + p_input_vars[0] + ");\n"; + return " " + p_output_vars[0] + " = determinant(" + p_input_vars[0] + ");\n"; } VisualShaderNodeDeterminant::VisualShaderNodeDeterminant() { @@ -2873,7 +2873,7 @@ String VisualShaderNodeScalarDerivativeFunc::generate_code(Shader::Mode p_mode, }; String code; - code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n"; + code += " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n"; return code; } @@ -2945,7 +2945,7 @@ String VisualShaderNodeVectorDerivativeFunc::generate_code(Shader::Mode p_mode, }; String code; - code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n"; + code += " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n"; return code; } @@ -3033,7 +3033,7 @@ String VisualShaderNodeClamp::get_output_port_name(int p_port) const { } String VisualShaderNodeClamp::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 "\t" + p_output_vars[0] + " = clamp(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; + return " " + p_output_vars[0] + " = clamp(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; } void VisualShaderNodeClamp::set_op_type(OpType p_op_type) { @@ -3132,7 +3132,7 @@ String VisualShaderNodeFaceForward::get_output_port_name(int p_port) const { } String VisualShaderNodeFaceForward::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 "\t" + p_output_vars[0] + " = faceforward(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; + return " " + p_output_vars[0] + " = faceforward(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; } VisualShaderNodeFaceForward::VisualShaderNodeFaceForward() { @@ -3179,7 +3179,7 @@ String VisualShaderNodeOuterProduct::get_output_port_name(int p_port) const { } String VisualShaderNodeOuterProduct::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 "\t" + p_output_vars[0] + " = outerProduct(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0));\n"; + return " " + p_output_vars[0] + " = outerProduct(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0));\n"; } VisualShaderNodeOuterProduct::VisualShaderNodeOuterProduct() { @@ -3283,7 +3283,7 @@ VisualShaderNodeStep::OpType VisualShaderNodeStep::get_op_type() const { } String VisualShaderNodeStep::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 "\t" + p_output_vars[0] + " = step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + return " " + p_output_vars[0] + " = step(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } Vector<StringName> VisualShaderNodeStep::get_editable_properties() const { @@ -3410,7 +3410,7 @@ VisualShaderNodeSmoothStep::OpType VisualShaderNodeSmoothStep::get_op_type() con } String VisualShaderNodeSmoothStep::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 "\t" + p_output_vars[0] + " = smoothstep(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; + return " " + p_output_vars[0] + " = smoothstep(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; } Vector<StringName> VisualShaderNodeSmoothStep::get_editable_properties() const { @@ -3473,7 +3473,7 @@ String VisualShaderNodeVectorDistance::get_output_port_name(int p_port) const { } String VisualShaderNodeVectorDistance::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 "\t" + p_output_vars[0] + " = distance(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + return " " + p_output_vars[0] + " = distance(" + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } VisualShaderNodeVectorDistance::VisualShaderNodeVectorDistance() { @@ -3523,7 +3523,7 @@ String VisualShaderNodeVectorRefract::get_output_port_name(int p_port) const { } String VisualShaderNodeVectorRefract::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 "\t" + p_output_vars[0] + " = refract(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; + return " " + p_output_vars[0] + " = refract(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; } VisualShaderNodeVectorRefract::VisualShaderNodeVectorRefract() { @@ -3626,7 +3626,7 @@ VisualShaderNodeMix::OpType VisualShaderNodeMix::get_op_type() const { } String VisualShaderNodeMix::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 "\t" + p_output_vars[0] + " = mix(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; + return " " + p_output_vars[0] + " = mix(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; } Vector<StringName> VisualShaderNodeMix::get_editable_properties() const { @@ -3690,7 +3690,7 @@ String VisualShaderNodeVectorCompose::get_output_port_name(int p_port) const { } String VisualShaderNodeVectorCompose::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 "\t" + p_output_vars[0] + " = vec3(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; + return " " + p_output_vars[0] + " = vec3(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; } VisualShaderNodeVectorCompose::VisualShaderNodeVectorCompose() { @@ -3738,7 +3738,7 @@ String VisualShaderNodeTransformCompose::get_output_port_name(int p_port) const } String VisualShaderNodeTransformCompose::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 "\t" + p_output_vars[0] + " = mat4(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0), vec4(" + p_input_vars[2] + ", 0.0), vec4(" + p_input_vars[3] + ", 1.0));\n"; + return " " + p_output_vars[0] + " = mat4(vec4(" + p_input_vars[0] + ", 0.0), vec4(" + p_input_vars[1] + ", 0.0), vec4(" + p_input_vars[2] + ", 0.0), vec4(" + p_input_vars[3] + ", 1.0));\n"; } VisualShaderNodeTransformCompose::VisualShaderNodeTransformCompose() { @@ -3785,9 +3785,9 @@ String VisualShaderNodeVectorDecompose::get_output_port_name(int p_port) const { String VisualShaderNodeVectorDecompose::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; - code += "\t" + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n"; - code += "\t" + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n"; - code += "\t" + p_output_vars[2] + " = " + p_input_vars[0] + ".z;\n"; + code += " " + p_output_vars[0] + " = " + p_input_vars[0] + ".x;\n"; + code += " " + p_output_vars[1] + " = " + p_input_vars[0] + ".y;\n"; + code += " " + p_output_vars[2] + " = " + p_input_vars[0] + ".z;\n"; return code; } @@ -3835,10 +3835,10 @@ String VisualShaderNodeTransformDecompose::get_output_port_name(int p_port) cons String VisualShaderNodeTransformDecompose::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; - code += "\t" + p_output_vars[0] + " = " + p_input_vars[0] + "[0].xyz;\n"; - code += "\t" + p_output_vars[1] + " = " + p_input_vars[0] + "[1].xyz;\n"; - code += "\t" + p_output_vars[2] + " = " + p_input_vars[0] + "[2].xyz;\n"; - code += "\t" + p_output_vars[3] + " = " + p_input_vars[0] + "[3].xyz;\n"; + code += " " + p_output_vars[0] + " = " + p_input_vars[0] + "[0].xyz;\n"; + code += " " + p_output_vars[1] + " = " + p_input_vars[0] + "[1].xyz;\n"; + code += " " + p_output_vars[2] + " = " + p_input_vars[0] + "[2].xyz;\n"; + code += " " + p_output_vars[3] + " = " + p_input_vars[0] + "[3].xyz;\n"; return code; } @@ -3893,7 +3893,7 @@ String VisualShaderNodeFloatUniform::generate_global(Shader::Mode p_mode, Visual } String VisualShaderNodeFloatUniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } bool VisualShaderNodeFloatUniform::is_show_prop_names() const { @@ -4064,7 +4064,7 @@ String VisualShaderNodeIntUniform::generate_global(Shader::Mode p_mode, VisualSh } String VisualShaderNodeIntUniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } bool VisualShaderNodeIntUniform::is_show_prop_names() const { @@ -4250,7 +4250,7 @@ String VisualShaderNodeBooleanUniform::generate_global(Shader::Mode p_mode, Visu } String VisualShaderNodeBooleanUniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } bool VisualShaderNodeBooleanUniform::is_show_prop_names() const { @@ -4350,8 +4350,8 @@ String VisualShaderNodeColorUniform::generate_global(Shader::Mode p_mode, Visual } String VisualShaderNodeColorUniform::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 = "\t" + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n"; - code += "\t" + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n"; + String code = " " + p_output_vars[0] + " = " + get_uniform_name() + ".rgb;\n"; + code += " " + p_output_vars[1] + " = " + get_uniform_name() + ".a;\n"; return code; } @@ -4448,7 +4448,7 @@ String VisualShaderNodeVec3Uniform::generate_global(Shader::Mode p_mode, VisualS } String VisualShaderNodeVec3Uniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } void VisualShaderNodeVec3Uniform::_bind_methods() { @@ -4552,7 +4552,7 @@ String VisualShaderNodeTransformUniform::generate_global(Shader::Mode p_mode, Vi } String VisualShaderNodeTransformUniform::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 "\t" + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; + return " " + p_output_vars[0] + " = " + get_uniform_name() + ";\n"; } void VisualShaderNodeTransformUniform::_bind_methods() { @@ -4684,23 +4684,23 @@ String VisualShaderNodeTextureUniform::generate_code(Shader::Mode p_mode, Visual } String id = get_uniform_name(); - String code = "\t{\n"; + String code = " {\n"; if (p_input_vars[0] == String()) { // Use UV by default. if (p_input_vars[1] == String()) { - code += "\t\tvec4 n_tex_read = texture(" + id + ", " + default_uv + ");\n"; + code += " vec4 n_tex_read = texture(" + id + ", " + default_uv + ");\n"; } else { - code += "\t\tvec4 n_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; + code += " vec4 n_tex_read = textureLod(" + id + ", " + default_uv + ", " + p_input_vars[1] + ");\n"; } } else if (p_input_vars[1] == String()) { //no lod - code += "\t\tvec4 n_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; + code += " vec4 n_tex_read = texture(" + id + ", " + p_input_vars[0] + ".xy);\n"; } else { - code += "\t\tvec4 n_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; + code += " vec4 n_tex_read = textureLod(" + id + ", " + p_input_vars[0] + ".xy, " + p_input_vars[1] + ");\n"; } - code += "\t\t" + p_output_vars[0] + " = n_tex_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = n_tex_read.a;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = n_tex_read.rgb;\n"; + code += " " + p_output_vars[1] + " = n_tex_read.a;\n"; + code += " }\n"; return code; } @@ -4805,20 +4805,20 @@ String VisualShaderNodeTextureUniformTriplanar::generate_global_per_node(Shader: String code; code += "// TRIPLANAR FUNCTION GLOBAL CODE\n"; - code += "\tvec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) {\n"; - code += "\t\tvec4 samp = vec4(0.0);\n"; - code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z;\n"; - code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y;\n"; - code += "\t\tsamp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x;\n"; - code += "\t\treturn samp;\n"; - code += "\t}\n"; + code += " vec4 triplanar_texture(sampler2D p_sampler, vec3 p_weights, vec3 p_triplanar_pos) {\n"; + code += " vec4 samp = vec4(0.0);\n"; + code += " samp += texture(p_sampler, p_triplanar_pos.xy) * p_weights.z;\n"; + code += " samp += texture(p_sampler, p_triplanar_pos.xz) * p_weights.y;\n"; + code += " samp += texture(p_sampler, p_triplanar_pos.zy * vec2(-1.0, 1.0)) * p_weights.x;\n"; + code += " return samp;\n"; + code += " }\n"; code += "\n"; - code += "\tuniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0);\n"; - code += "\tuniform vec3 triplanar_offset;\n"; - code += "\tuniform float triplanar_sharpness = 0.5;\n"; + code += " uniform vec3 triplanar_scale = vec3(1.0, 1.0, 1.0);\n"; + code += " uniform vec3 triplanar_offset;\n"; + code += " uniform float triplanar_sharpness = 0.5;\n"; code += "\n"; - code += "\tvarying vec3 triplanar_power_normal;\n"; - code += "\tvarying vec3 triplanar_pos;\n"; + code += " varying vec3 triplanar_power_normal;\n"; + code += " varying vec3 triplanar_pos;\n"; return code; } @@ -4827,11 +4827,11 @@ String VisualShaderNodeTextureUniformTriplanar::generate_global_per_func(Shader: String code; if (p_type == VisualShader::TYPE_VERTEX) { - code += "\t// TRIPLANAR FUNCTION VERTEX CODE\n"; - code += "\t\ttriplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness));\n"; - code += "\t\ttriplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0));\n"; - code += "\t\ttriplanar_pos = VERTEX * triplanar_scale + triplanar_offset;\n"; - code += "\t\ttriplanar_pos *= vec3(1.0, -1.0, 1.0);\n"; + code += " // TRIPLANAR FUNCTION VERTEX CODE\n"; + code += " triplanar_power_normal = pow(abs(NORMAL), vec3(triplanar_sharpness));\n"; + code += " triplanar_power_normal /= dot(triplanar_power_normal, vec3(1.0));\n"; + code += " triplanar_pos = VERTEX * triplanar_scale + triplanar_offset;\n"; + code += " triplanar_pos *= vec3(1.0, -1.0, 1.0);\n"; } return code; @@ -4839,21 +4839,21 @@ String VisualShaderNodeTextureUniformTriplanar::generate_global_per_func(Shader: String VisualShaderNodeTextureUniformTriplanar::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 id = get_uniform_name(); - String code = "\t{\n"; + String code = " {\n"; if (p_input_vars[0] == String() && p_input_vars[1] == String()) { - code += "\t\tvec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, triplanar_pos);\n"; + code += " vec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, triplanar_pos);\n"; } else if (p_input_vars[0] != String() && p_input_vars[1] == String()) { - code += "\t\tvec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", triplanar_pos);\n"; + code += " vec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", triplanar_pos);\n"; } else if (p_input_vars[0] == String() && p_input_vars[1] != String()) { - code += "\t\tvec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, " + p_input_vars[1] + ");\n"; + code += " vec4 n_tex_read = triplanar_texture(" + id + ", triplanar_power_normal, " + p_input_vars[1] + ");\n"; } else { - code += "\t\tvec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; + code += " vec4 n_tex_read = triplanar_texture(" + id + ", " + p_input_vars[0] + ", " + p_input_vars[1] + ");\n"; } - code += "\t\t" + p_output_vars[0] + " = n_tex_read.rgb;\n"; - code += "\t\t" + p_output_vars[1] + " = n_tex_read.a;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = n_tex_read.rgb;\n"; + code += " " + p_output_vars[1] + " = n_tex_read.a;\n"; + code += " }\n"; return code; } @@ -5130,18 +5130,18 @@ String VisualShaderNodeIf::get_output_port_name(int p_port) const { String VisualShaderNodeIf::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; - code += "\tif(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ")\n"; // abs(a - b) < tolerance eg. a == b - code += "\t{\n"; - code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[3] + ";\n"; - code += "\t}\n"; - code += "\telse if(" + p_input_vars[0] + " < " + p_input_vars[1] + ")\n"; // a < b - code += "\t{\n"; - code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[5] + ";\n"; - code += "\t}\n"; - code += "\telse\n"; // a > b (or a >= b if abs(a - b) < tolerance is false) - code += "\t{\n"; - code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[4] + ";\n"; - code += "\t}\n"; + code += " if(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ")\n"; // abs(a - b) < tolerance eg. a == b + code += " {\n"; + code += " " + p_output_vars[0] + " = " + p_input_vars[3] + ";\n"; + code += " }\n"; + code += " else if(" + p_input_vars[0] + " < " + p_input_vars[1] + ")\n"; // a < b + code += " {\n"; + code += " " + p_output_vars[0] + " = " + p_input_vars[5] + ";\n"; + code += " }\n"; + code += " else\n"; // a > b (or a >= b if abs(a - b) < tolerance is false) + code += " {\n"; + code += " " + p_output_vars[0] + " = " + p_input_vars[4] + ";\n"; + code += " }\n"; return code; } @@ -5282,14 +5282,14 @@ void VisualShaderNodeSwitch::_bind_methods() { // static String VisualShaderNodeSwitch::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; - code += "\tif(" + p_input_vars[0] + ")\n"; - code += "\t{\n"; - code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[1] + ";\n"; - code += "\t}\n"; - code += "\telse\n"; - code += "\t{\n"; - code += "\t\t" + p_output_vars[0] + " = " + p_input_vars[2] + ";\n"; - code += "\t}\n"; + code += " if(" + p_input_vars[0] + ")\n"; + code += " {\n"; + code += " " + p_output_vars[0] + " = " + p_input_vars[1] + ";\n"; + code += " }\n"; + code += " else\n"; + code += " {\n"; + code += " " + p_output_vars[0] + " = " + p_input_vars[2] + ";\n"; + code += " }\n"; return code; } @@ -5374,12 +5374,12 @@ String VisualShaderNodeFresnel::generate_code(Shader::Mode p_mode, VisualShader: } if (is_input_port_connected(2)) { - return "\t" + p_output_vars[0] + " = " + p_input_vars[2] + " ? (pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ")) : (pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + "));\n"; + return " " + p_output_vars[0] + " = " + p_input_vars[2] + " ? (pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ")) : (pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + "));\n"; } else { if (get_input_port_default_value(2)) { - return "\t" + p_output_vars[0] + " = pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n"; + return " " + p_output_vars[0] + " = pow(clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n"; } else { - return "\t" + p_output_vars[0] + " = pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n"; + return " " + p_output_vars[0] + " = pow(1.0 - clamp(dot(" + normal + ", " + view + "), 0.0, 1.0), " + p_input_vars[3] + ");\n"; } } } @@ -5435,7 +5435,7 @@ String VisualShaderNodeIs::generate_code(Shader::Mode p_mode, VisualShader::Type }; String code; - code += "\t" + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n"; + code += " " + p_output_vars[0] + " = " + String(funcs[func]).replace("$", p_input_vars[0]) + ";\n"; return code; } @@ -5562,37 +5562,37 @@ String VisualShaderNodeCompare::generate_code(Shader::Mode p_mode, VisualShader: switch (ctype) { case CTYPE_SCALAR: if (func == FUNC_EQUAL) { - code += "\t" + p_output_vars[0] + " = (abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");"; + code += " " + p_output_vars[0] + " = (abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");"; } else if (func == FUNC_NOT_EQUAL) { - code += "\t" + p_output_vars[0] + " = !(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");"; + code += " " + p_output_vars[0] + " = !(abs(" + p_input_vars[0] + " - " + p_input_vars[1] + ") < " + p_input_vars[2] + ");"; } else { - code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; + code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; } break; case CTYPE_SCALAR_INT: - code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; + code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; break; case CTYPE_VECTOR: - code += "\t{\n"; - code += "\t\tbvec3 _bv = " + String(funcs[func]).replace("$", p_input_vars[0] + ", " + p_input_vars[1]) + ";\n"; - code += "\t\t" + p_output_vars[0] + " = " + String(conds[condition]).replace("$", "_bv") + ";\n"; - code += "\t}\n"; + code += " {\n"; + code += " bvec3 _bv = " + String(funcs[func]).replace("$", p_input_vars[0] + ", " + p_input_vars[1]) + ";\n"; + code += " " + p_output_vars[0] + " = " + String(conds[condition]).replace("$", "_bv") + ";\n"; + code += " }\n"; break; case CTYPE_BOOLEAN: if (func > FUNC_NOT_EQUAL) { - return "\t" + p_output_vars[0] + " = false;\n"; + return " " + p_output_vars[0] + " = false;\n"; } - code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; + code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; break; case CTYPE_TRANSFORM: if (func > FUNC_NOT_EQUAL) { - return "\t" + p_output_vars[0] + " = false;\n"; + return " " + p_output_vars[0] + " = false;\n"; } - code += "\t" + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; + code += " " + p_output_vars[0] + " = " + (p_input_vars[0] + " $ " + p_input_vars[1]).replace("$", ops[func]) + ";\n"; break; default: @@ -5748,7 +5748,7 @@ String VisualShaderNodeMultiplyAdd::get_output_port_name(int p_port) const { } String VisualShaderNodeMultiplyAdd::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 "\t" + p_output_vars[0] + " = fma(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; + return " " + p_output_vars[0] + " = fma(" + p_input_vars[0] + ", " + p_input_vars[1] + ", " + p_input_vars[2] + ");\n"; } void VisualShaderNodeMultiplyAdd::set_op_type(OpType p_op_type) { @@ -5836,34 +5836,34 @@ String VisualShaderNodeBillboard::generate_code(Shader::Mode p_mode, VisualShade switch (billboard_type) { case BILLBOARD_TYPE_ENABLED: - code += "\t{\n"; - code += "\t\tmat4 __mvm = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0], CAMERA_MATRIX[1], CAMERA_MATRIX[2], WORLD_MATRIX[3]);\n"; + code += " {\n"; + code += " mat4 __mvm = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0], CAMERA_MATRIX[1], CAMERA_MATRIX[2], WORLD_MATRIX[3]);\n"; if (keep_scale) { - code += "\t\t__mvm = __mvm * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; + code += " __mvm = __mvm * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; } - code += "\t\t" + p_output_vars[0] + " = __mvm;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = __mvm;\n"; + code += " }\n"; break; case BILLBOARD_TYPE_FIXED_Y: - code += "\t{\n"; - code += "\t\tmat4 __mvm = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0], WORLD_MATRIX[1], vec4(normalize(cross(CAMERA_MATRIX[0].xyz, WORLD_MATRIX[1].xyz)), 0.0), WORLD_MATRIX[3]);\n"; + code += " {\n"; + code += " mat4 __mvm = INV_CAMERA_MATRIX * mat4(CAMERA_MATRIX[0], WORLD_MATRIX[1], vec4(normalize(cross(CAMERA_MATRIX[0].xyz, WORLD_MATRIX[1].xyz)), 0.0), WORLD_MATRIX[3]);\n"; if (keep_scale) { - code += "\t\t__mvm = __mvm * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; + code += " __mvm = __mvm * mat4(vec4(length(WORLD_MATRIX[0].xyz), 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, length(WORLD_MATRIX[2].xyz), 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; } else { - code += "\t\t__mvm = __mvm * mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0 / length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; + code += " __mvm = __mvm * mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0 / length(WORLD_MATRIX[1].xyz), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; } - code += "\t\t" + p_output_vars[0] + " = __mvm;\n"; - code += "\t}\n"; + code += " " + p_output_vars[0] + " = __mvm;\n"; + code += " }\n"; break; case BILLBOARD_TYPE_PARTICLES: - code += "\t{\n"; - code += "\t\tmat4 __wm = mat4(normalize(CAMERA_MATRIX[0]) * length(WORLD_MATRIX[0]), normalize(CAMERA_MATRIX[1]) * length(WORLD_MATRIX[0]), normalize(CAMERA_MATRIX[2]) * length(WORLD_MATRIX[2]), WORLD_MATRIX[3]);\n"; - code += "\t\t__wm = __wm * mat4(vec4(cos(INSTANCE_CUSTOM.x), -sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; - code += "\t\t" + p_output_vars[0] + " = INV_CAMERA_MATRIX * __wm;\n"; - code += "\t}\n"; + code += " {\n"; + code += " mat4 __wm = mat4(normalize(CAMERA_MATRIX[0]) * length(WORLD_MATRIX[0]), normalize(CAMERA_MATRIX[1]) * length(WORLD_MATRIX[0]), normalize(CAMERA_MATRIX[2]) * length(WORLD_MATRIX[2]), WORLD_MATRIX[3]);\n"; + code += " __wm = __wm * mat4(vec4(cos(INSTANCE_CUSTOM.x), -sin(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(sin(INSTANCE_CUSTOM.x), cos(INSTANCE_CUSTOM.x), 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; + code += " " + p_output_vars[0] + " = INV_CAMERA_MATRIX * __wm;\n"; + code += " }\n"; break; default: - code += "\t" + p_output_vars[0] + " = mat4(1.0);\n"; + code += " " + p_output_vars[0] + " = mat4(1.0);\n"; break; } diff --git a/scene/resources/visual_shader_particle_nodes.cpp b/scene/resources/visual_shader_particle_nodes.cpp index 29d583a82a..2250cf8d95 100644 --- a/scene/resources/visual_shader_particle_nodes.cpp +++ b/scene/resources/visual_shader_particle_nodes.cpp @@ -76,14 +76,14 @@ String VisualShaderNodeParticleSphereEmitter::get_input_port_name(int p_port) co String VisualShaderNodeParticleSphereEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { String code; code += "vec3 __get_random_point_in_sphere(inout uint seed, float radius, float inner_radius) {\n"; - code += "\treturn __get_random_unit_vec3(seed) * __randf_range(seed, inner_radius, radius);\n"; + code += " return __get_random_unit_vec3(seed) * __randf_range(seed, inner_radius, radius);\n"; code += "}\n\n"; return code; } String VisualShaderNodeParticleSphereEmitter::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; - code += "\t" + 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"; + 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"; return code; } @@ -119,15 +119,15 @@ String VisualShaderNodeParticleBoxEmitter::get_input_port_name(int p_port) const String VisualShaderNodeParticleBoxEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { String code; code += "vec3 __get_random_point_in_box(inout uint seed, vec3 extents) {\n"; - code += "\tvec3 half_extents = extents / 2.0;\n"; - code += "\treturn vec3(__randf_range(seed, -half_extents.x, half_extents.x), __randf_range(seed, -half_extents.y, half_extents.y), __randf_range(seed, -half_extents.z, half_extents.z));\n"; + code += " vec3 half_extents = extents / 2.0;\n"; + code += " return vec3(__randf_range(seed, -half_extents.x, half_extents.x), __randf_range(seed, -half_extents.y, half_extents.y), __randf_range(seed, -half_extents.z, half_extents.z));\n"; code += "}\n\n"; return code; } 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; - code += "\t" + p_output_vars[0] + " = __get_random_point_in_box(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ");\n"; + code += " " + p_output_vars[0] + " = __get_random_point_in_box(__seed, " + (p_input_vars[0].is_empty() ? (String)get_input_port_default_value(0) : p_input_vars[0]) + ");\n"; return code; } @@ -163,16 +163,16 @@ String VisualShaderNodeParticleRingEmitter::get_input_port_name(int p_port) cons String VisualShaderNodeParticleRingEmitter::generate_global_per_node(Shader::Mode p_mode, VisualShader::Type p_type, int p_id) const { String code; code += "vec3 __get_random_point_on_ring(inout uint seed, float radius, float inner_radius, float height) {\n"; - code += "\tfloat angle = __rand_from_seed(seed) * PI * 2.0;\n"; - code += "\tvec2 ring = vec2(sin(angle), cos(angle)) * __randf_range(seed, inner_radius, radius);\n"; - code += "\treturn vec3(ring.x, __randf_range(seed, min(0.0, height), max(0.0, height)), ring.y);\n"; + code += " float angle = __rand_from_seed(seed) * PI * 2.0;\n"; + code += " vec2 ring = vec2(sin(angle), cos(angle)) * __randf_range(seed, inner_radius, radius);\n"; + code += " return vec3(ring.x, __randf_range(seed, min(0.0, height), max(0.0, height)), ring.y);\n"; code += "}\n\n"; return code; } String VisualShaderNodeParticleRingEmitter::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; - code = "\t" + p_output_vars[0] + " = __get_random_point_on_ring(__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"; + code = " " + p_output_vars[0] + " = __get_random_point_on_ring(__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"; return code; } @@ -242,9 +242,9 @@ String VisualShaderNodeParticleMultiplyByAxisAngle::get_output_port_name(int p_p String VisualShaderNodeParticleMultiplyByAxisAngle::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 (degrees_mode) { - code += "\t" + p_output_vars[0] + " = __build_rotation_mat3(" + (p_input_vars[1].is_empty() ? ("vec3" + (String)get_input_port_default_value(1)) : p_input_vars[1]) + ", radians(" + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ")) * " + (p_input_vars[0].is_empty() ? "vec3(0.0)" : p_input_vars[0]) + ";\n"; + code += " " + p_output_vars[0] + " = __build_rotation_mat3(" + (p_input_vars[1].is_empty() ? ("vec3" + (String)get_input_port_default_value(1)) : p_input_vars[1]) + ", radians(" + (p_input_vars[2].is_empty() ? (String)get_input_port_default_value(2) : p_input_vars[2]) + ")) * " + (p_input_vars[0].is_empty() ? "vec3(0.0)" : p_input_vars[0]) + ";\n"; } else { - code += "\t" + p_output_vars[0] + " = __build_rotation_mat3(" + (p_input_vars[1].is_empty() ? ("vec3" + (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]) + ") * " + (p_input_vars[0].is_empty() ? "vec3(0.0)" : p_input_vars[0]) + ";\n"; + code += " " + p_output_vars[0] + " = __build_rotation_mat3(" + (p_input_vars[1].is_empty() ? ("vec3" + (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]) + ") * " + (p_input_vars[0].is_empty() ? "vec3(0.0)" : p_input_vars[0]) + ";\n"; } return code; } @@ -315,16 +315,16 @@ String VisualShaderNodeParticleConeVelocity::get_output_port_name(int p_port) co String VisualShaderNodeParticleConeVelocity::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; - code += "\t__radians = radians(" + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n"; - code += "\t__scalar_buff1 = __rand_from_seed_m1_p1(__seed) * __radians;\n"; - code += "\t__scalar_buff2 = __rand_from_seed_m1_p1(__seed) * __radians;\n"; - code += "\t__vec3_buff1 = " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + ";\n"; - code += "\t__scalar_buff1 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.x, __vec3_buff1.z) : sign(__vec3_buff1.x) * (PI / 2.0);\n"; - code += "\t__scalar_buff2 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.z)) : (__vec3_buff1.x != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.x)) : sign(__vec3_buff1.y) * (PI / 2.0));\n"; - code += "\t__vec3_buff1 = vec3(sin(__scalar_buff1), 0.0, cos(__scalar_buff1));\n"; - code += "\t__vec3_buff2 = vec3(0.0, sin(__scalar_buff2), cos(__scalar_buff2));\n"; - code += "\t__vec3_buff2.z = __vec3_buff2.z / max(0.0001, sqrt(abs(__vec3_buff2.z)));\n"; - code += "\t" + p_output_vars[0] + " = normalize(vec3(__vec3_buff1.x * __vec3_buff2.z, __vec3_buff2.y, __vec3_buff1.z * __vec3_buff2.z));\n"; + code += " __radians = radians(" + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ");\n"; + code += " __scalar_buff1 = __rand_from_seed_m1_p1(__seed) * __radians;\n"; + code += " __scalar_buff2 = __rand_from_seed_m1_p1(__seed) * __radians;\n"; + code += " __vec3_buff1 = " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + ";\n"; + code += " __scalar_buff1 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.x, __vec3_buff1.z) : sign(__vec3_buff1.x) * (PI / 2.0);\n"; + code += " __scalar_buff2 += __vec3_buff1.z != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.z)) : (__vec3_buff1.x != 0.0 ? atan(__vec3_buff1.y, abs(__vec3_buff1.x)) : sign(__vec3_buff1.y) * (PI / 2.0));\n"; + code += " __vec3_buff1 = vec3(sin(__scalar_buff1), 0.0, cos(__scalar_buff1));\n"; + code += " __vec3_buff2 = vec3(0.0, sin(__scalar_buff2), cos(__scalar_buff2));\n"; + code += " __vec3_buff2.z = __vec3_buff2.z / max(0.0001, sqrt(abs(__vec3_buff2.z)));\n"; + code += " " + p_output_vars[0] + " = normalize(vec3(__vec3_buff1.x * __vec3_buff2.z, __vec3_buff2.y, __vec3_buff1.z * __vec3_buff2.z));\n"; return code; } @@ -394,9 +394,9 @@ 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("\t%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]); + 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("\t%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]); + 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]); } return code; } @@ -491,14 +491,14 @@ String VisualShaderNodeParticleAccelerator::generate_code(Shader::Mode p_mode, V String code; switch (mode) { case MODE_LINEAR: - code += "\t" + p_output_vars[0] + " = length(VELOCITY) > 0.0 ? " + "normalize(VELOCITY) * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n"; + code += " " + p_output_vars[0] + " = length(VELOCITY) > 0.0 ? " + "normalize(VELOCITY) * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n"; break; case MODE_RADIAL: - code += "\t" + p_output_vars[0] + " = length(__diff) > 0.0 ? __ndiff * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n"; + code += " " + p_output_vars[0] + " = length(__diff) > 0.0 ? __ndiff * " + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ") : vec3(0.0);\n"; break; case MODE_TANGENTIAL: - code += "\t__vec3_buff1 = cross(__ndiff, normalize(" + (p_input_vars[2].is_empty() ? "vec3" + (String)get_input_port_default_value(2) : p_input_vars[2]) + "));\n"; - code += "\t" + p_output_vars[0] + " = length(__vec3_buff1) > 0.0 ? normalize(__vec3_buff1) * (" + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ")) : vec3(0.0);\n"; + code += " __vec3_buff1 = cross(__ndiff, normalize(" + (p_input_vars[2].is_empty() ? "vec3" + (String)get_input_port_default_value(2) : p_input_vars[2]) + "));\n"; + code += " " + p_output_vars[0] + " = length(__vec3_buff1) > 0.0 ? normalize(__vec3_buff1) * (" + (p_input_vars[0].is_empty() ? "vec3" + (String)get_input_port_default_value(0) : p_input_vars[0]) + " * mix(1.0, __rand_from_seed(__seed), " + (p_input_vars[1].is_empty() ? (String)get_input_port_default_value(1) : p_input_vars[1]) + ")) : vec3(0.0);\n"; break; case MODE_MAX: break; @@ -693,7 +693,7 @@ bool VisualShaderNodeParticleOutput::is_port_separator(int p_index) const { String VisualShaderNodeParticleOutput::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; - String tab = "\t"; + String tab = " "; if (shader_type == VisualShader::TYPE_START_CUSTOM || shader_type == VisualShader::TYPE_PROCESS_CUSTOM) { if (!p_input_vars[0].is_empty()) { // custom.rgb @@ -718,7 +718,7 @@ String VisualShaderNodeParticleOutput::generate_code(Shader::Mode p_mode, Visual if (!p_input_vars[0].is_empty()) { // active (begin) code += tab + "ACTIVE = " + p_input_vars[0] + ";\n"; code += tab + "if(ACTIVE) {\n"; - tab += "\t"; + tab += " "; } if (!p_input_vars[1].is_empty()) { // velocity code += tab + "VELOCITY = " + p_input_vars[1] + ";\n"; @@ -734,14 +734,14 @@ String VisualShaderNodeParticleOutput::generate_code(Shader::Mode p_mode, Visual if (shader_type == VisualShader::TYPE_START) { code += tab + "if (RESTART_POSITION) {\n"; if (!p_input_vars[4].is_empty()) { - code += tab + "\tTRANSFORM = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(" + p_input_vars[4] + ", 1.0));\n"; + code += tab + " TRANSFORM = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(" + p_input_vars[4] + ", 1.0));\n"; } else { - code += tab + "\tTRANSFORM = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; + code += tab + " TRANSFORM = mat4(vec4(1.0, 0.0, 0.0, 0.0), vec4(0.0, 1.0, 0.0, 0.0), vec4(0.0, 0.0, 1.0, 0.0), vec4(0.0, 0.0, 0.0, 1.0));\n"; } - code += tab + "\tif (RESTART_VELOCITY) {\n"; - code += tab + "\t\tVELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY, 0.0)).xyz;\n"; - code += tab + "\t}\n"; - code += tab + "\tTRANSFORM = EMISSION_TRANSFORM * TRANSFORM;\n"; + code += tab + " if (RESTART_VELOCITY) {\n"; + code += tab + " VELOCITY = (EMISSION_TRANSFORM * vec4(VELOCITY, 0.0)).xyz;\n"; + code += tab + " }\n"; + code += tab + " TRANSFORM = EMISSION_TRANSFORM * TRANSFORM;\n"; code += tab + "}\n"; } else if (shader_type == VisualShader::TYPE_COLLIDE) { // position if (!p_input_vars[4].is_empty()) { @@ -779,7 +779,7 @@ String VisualShaderNodeParticleOutput::generate_code(Shader::Mode p_mode, Visual } } if (!p_input_vars[0].is_empty()) { // active (end) - code += "\t}\n"; + code += " }\n"; } } return code; @@ -926,12 +926,12 @@ String VisualShaderNodeParticleEmit::generate_code(Shader::Mode p_mode, VisualSh if (!is_input_port_connected(0)) { default_condition = true; if (get_input_port_default_value(0)) { - tab = "\t"; + tab = " "; } else { return code; } } else { - tab = "\t\t"; + tab = " "; } String transform; @@ -1008,13 +1008,13 @@ String VisualShaderNodeParticleEmit::generate_code(Shader::Mode p_mode, VisualSh } if (!default_condition) { - code += "\tif (" + p_input_vars[0] + ") {\n"; + code += " if (" + p_input_vars[0] + ") {\n"; } code += tab + "emit_subparticle(" + transform + ", " + velocity + ", vec4(" + color + ", " + alpha + "), vec4(" + custom + ", " + custom_alpha + "), " + flags + ");\n"; if (!default_condition) { - code += "\t}\n"; + code += " }\n"; } return code; diff --git a/scene/resources/visual_shader_sdf_nodes.cpp b/scene/resources/visual_shader_sdf_nodes.cpp index d25e32b070..14c655b129 100644 --- a/scene/resources/visual_shader_sdf_nodes.cpp +++ b/scene/resources/visual_shader_sdf_nodes.cpp @@ -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 "\t" + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(sdf_to_screen_uv(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeSDFToScreenUV::VisualShaderNodeSDFToScreenUV() { @@ -105,7 +105,7 @@ String VisualShaderNodeScreenUVToSDF::get_input_port_default_hint(int p_port) co } 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 "\t" + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0] == String() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(screen_uv_to_sdf(" + (p_input_vars[0] == String() ? "SCREEN_UV" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeScreenUVToSDF::VisualShaderNodeScreenUVToSDF() { @@ -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 "\t" + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n"; + return " " + p_output_vars[0] + " = texture_sdf(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + ");\n"; } VisualShaderNodeTextureSDF::VisualShaderNodeTextureSDF() { @@ -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 "\t" + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; + return " " + p_output_vars[0] + " = vec3(texture_sdf_normal(" + (p_input_vars[0] == String() ? "vec2(0.0)" : p_input_vars[0] + ".xy") + "), 0.0f);\n"; } VisualShaderNodeTextureSDFNormal::VisualShaderNodeTextureSDFNormal() { @@ -240,40 +240,40 @@ String VisualShaderNodeSDFRaymarch::get_output_port_name(int p_port) const { String VisualShaderNodeSDFRaymarch::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; - code += "\t{\n"; + code += " {\n"; if (p_input_vars[0] == String()) { - code += "\t\tvec2 __from_pos = vec2(0.0f);\n"; + code += " vec2 __from_pos = vec2(0.0f);\n"; } else { - code += "\t\tvec2 __from_pos = " + p_input_vars[0] + ".xy;\n"; + code += " vec2 __from_pos = " + p_input_vars[0] + ".xy;\n"; } if (p_input_vars[1] == String()) { - code += "\t\tvec2 __to_pos = vec2(0.0f);\n"; + code += " vec2 __to_pos = vec2(0.0f);\n"; } else { - code += "\t\tvec2 __to_pos = " + p_input_vars[1] + ".xy;\n"; + code += " vec2 __to_pos = " + p_input_vars[1] + ".xy;\n"; } - code += "\n\t\tvec2 __at = __from_pos;\n"; - code += "\t\tfloat __max_dist = distance(__from_pos, __to_pos);\n"; - code += "\t\tvec2 __dir = normalize(__to_pos - __from_pos);\n\n"; - - code += "\t\tfloat __accum = 0.0f;\n"; - code += "\t\twhile(__accum < __max_dist) {\n"; - code += "\t\t\tfloat __d = texture_sdf(__at);\n"; - code += "\t\t\t__accum += __d;\n"; - code += "\t\t\tif (__d < 0.01f) {\n"; - code += "\t\t\t\tbreak;\n"; - code += "\t\t\t}\n"; - code += "\t\t\t__at += __d * __dir;\n"; - code += "\t\t}\n"; - - code += "\t\tfloat __dist = min(__max_dist, __accum);\n"; - code += "\t\t" + p_output_vars[0] + " = __dist;\n"; - code += "\t\t" + p_output_vars[1] + " = __accum < __max_dist;\n"; - code += "\t\t" + p_output_vars[2] + " = vec3(__from_pos + __dir * __dist, 0.0f);\n"; - - code += "\t}\n"; + code += "\n vec2 __at = __from_pos;\n"; + code += " float __max_dist = distance(__from_pos, __to_pos);\n"; + code += " vec2 __dir = normalize(__to_pos - __from_pos);\n\n"; + + code += " float __accum = 0.0f;\n"; + code += " while(__accum < __max_dist) {\n"; + code += " float __d = texture_sdf(__at);\n"; + code += " __accum += __d;\n"; + code += " if (__d < 0.01f) {\n"; + code += " break;\n"; + code += " }\n"; + code += " __at += __d * __dir;\n"; + code += " }\n"; + + 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 += " }\n"; return code; } |