Merge pull request #58151 from akien-mga/notification-switch-scene

This commit is contained in:
Rémi Verschelde 2022-02-15 20:48:18 +01:00 committed by GitHub
commit 98b97d34df
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
127 changed files with 2853 additions and 2601 deletions

View File

@ -247,7 +247,6 @@ void AnimatedSprite2D::_notification(int p_what) {
}
texture->draw_rect_region(ci, dst_rect, Rect2(Vector2(), texture->get_size()), Color(1, 1, 1), false);
} break;
}
}

View File

@ -67,6 +67,7 @@ void AudioListener2D::_notification(int p_what) {
make_current();
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {

View File

@ -36,70 +36,72 @@
#include "scene/resources/world_2d.h"
void AudioStreamPlayer2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
}
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
stop();
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
}
case NOTIFICATION_EXIT_TREE: {
stop();
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
} break;
if (p_what == NOTIFICATION_PAUSED) {
if (!can_process()) {
// Node can't process so we start fading out to silence
set_stream_paused(true);
}
}
case NOTIFICATION_PAUSED: {
if (!can_process()) {
// Node can't process so we start fading out to silence.
set_stream_paused(true);
}
} break;
if (p_what == NOTIFICATION_UNPAUSED) {
set_stream_paused(false);
}
case NOTIFICATION_UNPAUSED: {
set_stream_paused(false);
} break;
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
//update anything related to position first, if possible of course
if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
_update_panning();
}
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
// Update anything related to position first, if possible of course.
if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
_update_panning();
}
if (setplay.get() >= 0 && stream.is_valid()) {
active.set();
Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
AudioServer::get_singleton()->start_playback_stream(new_playback, _get_actual_bus(), volume_vector, setplay.get(), pitch_scale);
stream_playbacks.push_back(new_playback);
setplay.set(-1);
}
if (setplay.get() >= 0 && stream.is_valid()) {
active.set();
Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
AudioServer::get_singleton()->start_playback_stream(new_playback, _get_actual_bus(), volume_vector, setplay.get(), pitch_scale);
stream_playbacks.push_back(new_playback);
setplay.set(-1);
}
if (!stream_playbacks.is_empty() && active.is_set()) {
// Stop playing if no longer active.
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
if (!stream_playbacks.is_empty() && active.is_set()) {
// Stop playing if no longer active.
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
}
}
// Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
stream_playbacks.erase(playback);
}
if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
// This node is no longer actively playing audio.
active.clear();
set_physics_process_internal(false);
}
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
}
// Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
stream_playbacks.erase(playback);
}
if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
// This node is no longer actively playing audio.
active.clear();
set_physics_process_internal(false);
}
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
}
while (stream_playbacks.size() > max_polyphony) {
AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
stream_playbacks.remove_at(0);
}
while (stream_playbacks.size() > max_polyphony) {
AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
stream_playbacks.remove_at(0);
}
} break;
}
}

View File

@ -206,15 +206,7 @@ Transform2D Camera2D::get_camera_transform() {
if (rotating) {
xform.set_rotation(angle);
}
xform.set_origin(screen_rect.position /*.floor()*/);
/*
if (0) {
xform = get_global_transform() * xform;
} else {
xform.elements[2]+=get_global_transform().get_origin();
}
*/
xform.set_origin(screen_rect.position);
return (xform).affine_inverse();
}
@ -224,14 +216,14 @@ void Camera2D::_notification(int p_what) {
case NOTIFICATION_INTERNAL_PROCESS:
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
_update_scroll();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_processing_internal() && !is_physics_processing_internal()) {
_update_scroll();
}
} break;
case NOTIFICATION_ENTER_TREE: {
ERR_FAIL_COND(!is_inside_tree());
if (custom_viewport && ObjectDB::get_instance(custom_viewport_id)) {
@ -256,8 +248,8 @@ void Camera2D::_notification(int p_what) {
_update_process_callback();
_update_scroll();
first = true;
} break;
case NOTIFICATION_EXIT_TREE: {
if (is_current()) {
if (viewport && !(custom_viewport && !ObjectDB::get_instance(custom_viewport_id))) {
@ -269,8 +261,8 @@ void Camera2D::_notification(int p_what) {
remove_from_group(group_name);
remove_from_group(canvas_group_name);
viewport = nullptr;
} break;
#ifdef TOOLS_ENABLED
case NOTIFICATION_DRAW: {
if (!is_inside_tree() || !Engine::get_singleton()->is_editor_hint()) {

View File

@ -31,27 +31,32 @@
#include "canvas_modulate.h"
void CanvasModulate::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_CANVAS) {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
switch (p_what) {
case NOTIFICATION_ENTER_CANVAS: {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
} break;
} else if (p_what == NOTIFICATION_EXIT_CANVAS) {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
} else if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
} else {
RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
case NOTIFICATION_EXIT_CANVAS: {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
} break;
update_configuration_warnings();
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible_in_tree()) {
RS::get_singleton()->canvas_set_modulate(get_canvas(), color);
add_to_group("_canvas_modulate_" + itos(get_canvas().get_id()));
} else {
RS::get_singleton()->canvas_set_modulate(get_canvas(), Color(1, 1, 1, 1));
remove_from_group("_canvas_modulate_" + itos(get_canvas().get_id()));
}
update_configuration_warnings();
} break;
}
}

View File

@ -102,26 +102,20 @@ void CollisionPolygon2D::_notification(int p_what) {
_build_polygon();
_update_in_shape_owner();
}
/*if (Engine::get_singleton()->is_editor_hint()) {
//display above all else
set_z_as_relative(false);
set_z_index(RS::CANVAS_ITEM_Z_MAX - 1);
}*/
} break;
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}
} break;
case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);

View File

@ -59,34 +59,28 @@ void CollisionShape2D::_notification(int p_what) {
}
_update_in_shape_owner();
}
/*if (Engine::get_singleton()->is_editor_hint()) {
//display above all else
set_z_as_relative(false);
set_z_index(RS::CANVAS_ITEM_Z_MAX - 1);
}*/
} break;
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}
} break;
case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);
}
owner_id = 0;
parent = nullptr;
} break;
case NOTIFICATION_DRAW: {
ERR_FAIL_COND(!is_inside_tree());

View File

@ -1091,9 +1091,11 @@ void CPUParticles2D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
set_process_internal(emitting);
} break;
case NOTIFICATION_EXIT_TREE: {
_set_redraw(false);
} break;
case NOTIFICATION_DRAW: {
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
@ -1111,9 +1113,11 @@ void CPUParticles2D::_notification(int p_what) {
RS::get_singleton()->canvas_item_add_multimesh(get_canvas_item(), multimesh, texrid);
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
_update_internal();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
inv_emission_transform = get_global_transform().affine_inverse();

View File

@ -377,154 +377,157 @@ void GPUParticles2D::restart() {
}
void GPUParticles2D::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
RID texture_rid;
Size2 size;
if (texture.is_valid()) {
texture_rid = texture->get_rid();
size = texture->get_size();
} else {
size = Size2(1, 1);
}
if (trail_enabled) {
RS::get_singleton()->mesh_clear(mesh);
PackedVector2Array points;
PackedVector2Array uvs;
PackedInt32Array bone_indices;
PackedFloat32Array bone_weights;
PackedInt32Array indices;
int total_segments = trail_sections * trail_section_subdivisions;
real_t depth = size.height * trail_sections;
for (int j = 0; j <= total_segments; j++) {
real_t v = j;
v /= total_segments;
real_t y = depth * v;
y = (depth * 0.5) - y;
int bone = j / trail_section_subdivisions;
real_t blend = 1.0 - real_t(j % trail_section_subdivisions) / real_t(trail_section_subdivisions);
real_t s = size.width;
points.push_back(Vector2(-s * 0.5, 0));
points.push_back(Vector2(+s * 0.5, 0));
uvs.push_back(Vector2(0, v));
uvs.push_back(Vector2(1, v));
for (int i = 0; i < 2; i++) {
bone_indices.push_back(bone);
bone_indices.push_back(MIN(trail_sections, bone + 1));
bone_indices.push_back(0);
bone_indices.push_back(0);
bone_weights.push_back(blend);
bone_weights.push_back(1.0 - blend);
bone_weights.push_back(0);
bone_weights.push_back(0);
}
if (j > 0) {
int base = j * 2 - 2;
indices.push_back(base + 0);
indices.push_back(base + 1);
indices.push_back(base + 2);
indices.push_back(base + 1);
indices.push_back(base + 3);
indices.push_back(base + 2);
}
switch (p_what) {
case NOTIFICATION_DRAW: {
RID texture_rid;
Size2 size;
if (texture.is_valid()) {
texture_rid = texture->get_rid();
size = texture->get_size();
} else {
size = Size2(1, 1);
}
Array arr;
arr.resize(RS::ARRAY_MAX);
arr[RS::ARRAY_VERTEX] = points;
arr[RS::ARRAY_TEX_UV] = uvs;
arr[RS::ARRAY_BONES] = bone_indices;
arr[RS::ARRAY_WEIGHTS] = bone_weights;
arr[RS::ARRAY_INDEX] = indices;
if (trail_enabled) {
RS::get_singleton()->mesh_clear(mesh);
PackedVector2Array points;
PackedVector2Array uvs;
PackedInt32Array bone_indices;
PackedFloat32Array bone_weights;
PackedInt32Array indices;
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
int total_segments = trail_sections * trail_section_subdivisions;
real_t depth = size.height * trail_sections;
Vector<Transform3D> xforms;
for (int i = 0; i <= trail_sections; i++) {
Transform3D xform;
/*
xform.origin.y = depth / 2.0 - size.height * real_t(i);
xform.origin.y = -xform.origin.y; //bind is an inverse transform, so negate y */
xforms.push_back(xform);
for (int j = 0; j <= total_segments; j++) {
real_t v = j;
v /= total_segments;
real_t y = depth * v;
y = (depth * 0.5) - y;
int bone = j / trail_section_subdivisions;
real_t blend = 1.0 - real_t(j % trail_section_subdivisions) / real_t(trail_section_subdivisions);
real_t s = size.width;
points.push_back(Vector2(-s * 0.5, 0));
points.push_back(Vector2(+s * 0.5, 0));
uvs.push_back(Vector2(0, v));
uvs.push_back(Vector2(1, v));
for (int i = 0; i < 2; i++) {
bone_indices.push_back(bone);
bone_indices.push_back(MIN(trail_sections, bone + 1));
bone_indices.push_back(0);
bone_indices.push_back(0);
bone_weights.push_back(blend);
bone_weights.push_back(1.0 - blend);
bone_weights.push_back(0);
bone_weights.push_back(0);
}
if (j > 0) {
int base = j * 2 - 2;
indices.push_back(base + 0);
indices.push_back(base + 1);
indices.push_back(base + 2);
indices.push_back(base + 1);
indices.push_back(base + 3);
indices.push_back(base + 2);
}
}
Array arr;
arr.resize(RS::ARRAY_MAX);
arr[RS::ARRAY_VERTEX] = points;
arr[RS::ARRAY_TEX_UV] = uvs;
arr[RS::ARRAY_BONES] = bone_indices;
arr[RS::ARRAY_WEIGHTS] = bone_weights;
arr[RS::ARRAY_INDEX] = indices;
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
Vector<Transform3D> xforms;
for (int i = 0; i <= trail_sections; i++) {
Transform3D xform;
/*
xform.origin.y = depth / 2.0 - size.height * real_t(i);
xform.origin.y = -xform.origin.y; //bind is an inverse transform, so negate y */
xforms.push_back(xform);
}
RS::get_singleton()->particles_set_trail_bind_poses(particles, xforms);
} else {
RS::get_singleton()->mesh_clear(mesh);
Vector<Vector2> points = {
Vector2(-size.x / 2.0, -size.y / 2.0),
Vector2(size.x / 2.0, -size.y / 2.0),
Vector2(size.x / 2.0, size.y / 2.0),
Vector2(-size.x / 2.0, size.y / 2.0)
};
Vector<Vector2> uvs = {
Vector2(0, 0),
Vector2(1, 0),
Vector2(1, 1),
Vector2(0, 1)
};
Vector<int> indices = { 0, 1, 2, 0, 2, 3 };
Array arr;
arr.resize(RS::ARRAY_MAX);
arr[RS::ARRAY_VERTEX] = points;
arr[RS::ARRAY_TEX_UV] = uvs;
arr[RS::ARRAY_INDEX] = indices;
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
RS::get_singleton()->particles_set_trail_bind_poses(particles, Vector<Transform3D>());
}
RS::get_singleton()->particles_set_trail_bind_poses(particles, xforms);
} else {
RS::get_singleton()->mesh_clear(mesh);
Vector<Vector2> points = {
Vector2(-size.x / 2.0, -size.y / 2.0),
Vector2(size.x / 2.0, -size.y / 2.0),
Vector2(size.x / 2.0, size.y / 2.0),
Vector2(-size.x / 2.0, size.y / 2.0)
};
Vector<Vector2> uvs = {
Vector2(0, 0),
Vector2(1, 0),
Vector2(1, 1),
Vector2(0, 1)
};
Vector<int> indices = { 0, 1, 2, 0, 2, 3 };
Array arr;
arr.resize(RS::ARRAY_MAX);
arr[RS::ARRAY_VERTEX] = points;
arr[RS::ARRAY_TEX_UV] = uvs;
arr[RS::ARRAY_INDEX] = indices;
RS::get_singleton()->mesh_add_surface_from_arrays(mesh, RS::PRIMITIVE_TRIANGLES, arr, Array(), Dictionary(), RS::ARRAY_FLAG_USE_2D_VERTICES);
RS::get_singleton()->particles_set_trail_bind_poses(particles, Vector<Transform3D>());
}
RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid);
RS::get_singleton()->canvas_item_add_particles(get_canvas_item(), particles, texture_rid);
#ifdef TOOLS_ENABLED
if (show_visibility_rect) {
draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false);
}
if (show_visibility_rect) {
draw_rect(visibility_rect, Color(0, 0.7, 0.9, 0.4), false);
}
#endif
}
} break;
if (p_what == NOTIFICATION_ENTER_TREE) {
if (sub_emitter != NodePath()) {
_attach_sub_emitter();
}
}
case NOTIFICATION_ENTER_TREE: {
if (sub_emitter != NodePath()) {
_attach_sub_emitter();
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
RS::get_singleton()->particles_set_subemitter(particles, RID());
}
case NOTIFICATION_EXIT_TREE: {
RS::get_singleton()->particles_set_subemitter(particles, RID());
} break;
if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) {
if (can_process()) {
RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
} else {
RS::get_singleton()->particles_set_speed_scale(particles, 0);
}
}
case NOTIFICATION_PAUSED:
case NOTIFICATION_UNPAUSED: {
if (can_process()) {
RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
} else {
RS::get_singleton()->particles_set_speed_scale(particles, 0);
}
} break;
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
_update_particle_emission_transform();
}
case NOTIFICATION_TRANSFORM_CHANGED: {
_update_particle_emission_transform();
} break;
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
if (one_shot && !is_emitting()) {
notify_property_list_changed();
set_process_internal(false);
}
case NOTIFICATION_INTERNAL_PROCESS: {
if (one_shot && !is_emitting()) {
notify_property_list_changed();
set_process_internal(false);
}
} break;
}
}

View File

@ -162,6 +162,7 @@ void Joint2D::_notification(int p_what) {
case NOTIFICATION_READY: {
_update_joint();
} break;
case NOTIFICATION_EXIT_TREE: {
if (joint.is_valid()) {
_disconnect_signals();

View File

@ -192,21 +192,24 @@ Light2D::BlendMode Light2D::get_blend_mode() const {
}
void Light2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
_update_light_visibility();
}
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, get_canvas());
_update_light_visibility();
} break;
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
}
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
_update_light_visibility();
}
case NOTIFICATION_TRANSFORM_CHANGED: {
RS::get_singleton()->canvas_light_set_transform(canvas_light, get_global_transform());
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
_update_light_visibility();
case NOTIFICATION_VISIBILITY_CHANGED: {
_update_light_visibility();
} break;
case NOTIFICATION_EXIT_TREE: {
RS::get_singleton()->canvas_light_attach_to_canvas(canvas_light, RID());
_update_light_visibility();
} break;
}
}

View File

@ -29,9 +29,9 @@
/*************************************************************************/
#include "light_occluder_2d.h"
#include "core/math/geometry_2d.h"
#include "core/config/engine.h"
#include "core/math/geometry_2d.h"
#define LINE_GRAB_WIDTH 8
@ -158,42 +158,46 @@ void LightOccluder2D::_poly_changed() {
}
void LightOccluder2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_CANVAS) {
RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, get_canvas());
RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
}
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
}
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
}
switch (p_what) {
case NOTIFICATION_ENTER_CANVAS: {
RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, get_canvas());
RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
} break;
if (p_what == NOTIFICATION_DRAW) {
if (Engine::get_singleton()->is_editor_hint()) {
if (occluder_polygon.is_valid()) {
Vector<Vector2> poly = occluder_polygon->get_polygon();
case NOTIFICATION_TRANSFORM_CHANGED: {
RS::get_singleton()->canvas_light_occluder_set_transform(occluder, get_global_transform());
} break;
if (poly.size()) {
if (occluder_polygon->is_closed()) {
Vector<Color> color;
color.push_back(Color(0, 0, 0, 0.6));
draw_polygon(Variant(poly), color);
} else {
int ps = poly.size();
const Vector2 *r = poly.ptr();
for (int i = 0; i < ps - 1; i++) {
draw_line(r[i], r[i + 1], Color(0, 0, 0, 0.6), 3);
case NOTIFICATION_VISIBILITY_CHANGED: {
RS::get_singleton()->canvas_light_occluder_set_enabled(occluder, is_visible_in_tree());
} break;
case NOTIFICATION_DRAW: {
if (Engine::get_singleton()->is_editor_hint()) {
if (occluder_polygon.is_valid()) {
Vector<Vector2> poly = occluder_polygon->get_polygon();
if (poly.size()) {
if (occluder_polygon->is_closed()) {
Vector<Color> color;
color.push_back(Color(0, 0, 0, 0.6));
draw_polygon(Variant(poly), color);
} else {
int ps = poly.size();
const Vector2 *r = poly.ptr();
for (int i = 0; i < ps - 1; i++) {
draw_line(r[i], r[i + 1], Color(0, 0, 0, 0.6), 3);
}
}
}
}
}
}
}
} break;
if (p_what == NOTIFICATION_EXIT_CANVAS) {
RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID());
case NOTIFICATION_EXIT_CANVAS: {
RS::get_singleton()->canvas_light_occluder_attach_to_canvas(occluder, RID());
} break;
}
}

View File

@ -228,9 +228,9 @@ Line2D::LineCapMode Line2D::get_end_cap_mode() const {
void Line2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_DRAW:
case NOTIFICATION_DRAW: {
_draw();
break;
} break;
}
}

View File

@ -29,13 +29,16 @@
/*************************************************************************/
#include "mesh_instance_2d.h"
#include "scene/scene_string_names.h"
void MeshInstance2D::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
if (mesh.is_valid()) {
draw_mesh(mesh, texture);
}
switch (p_what) {
case NOTIFICATION_DRAW: {
if (mesh.is_valid()) {
draw_mesh(mesh, texture);
}
} break;
}
}

View File

@ -29,13 +29,16 @@
/*************************************************************************/
#include "multimesh_instance_2d.h"
#include "scene/scene_string_names.h"
void MultiMeshInstance2D::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
if (multimesh.is_valid()) {
draw_multimesh(multimesh, texture);
}
switch (p_what) {
case NOTIFICATION_DRAW: {
if (multimesh.is_valid()) {
draw_multimesh(multimesh, texture);
}
} break;
}
}

View File

@ -97,10 +97,12 @@ void NavigationAgent2D::_notification(int p_what) {
}
set_physics_process_internal(true);
} break;
case NOTIFICATION_EXIT_TREE: {
agent_parent = nullptr;
set_physics_process_internal(false);
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (agent_parent) {
NavigationServer2D::get_singleton()->agent_set_position(agent, agent_parent->get_global_position());

View File

@ -63,17 +63,21 @@ void NavigationObstacle2D::_notification(int p_what) {
}
set_physics_process_internal(true);
} break;
case NOTIFICATION_EXIT_TREE: {
parent_node2d = nullptr;
set_physics_process_internal(false);
} break;
case NOTIFICATION_PARENTED: {
parent_node2d = Object::cast_to<Node2D>(get_parent());
reevaluate_agent_radius();
} break;
case NOTIFICATION_UNPARENTED: {
parent_node2d = nullptr;
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (parent_node2d) {
NavigationServer2D::get_singleton()->agent_set_position(agent, parent_node2d->get_global_position());

View File

@ -406,15 +406,18 @@ void NavigationRegion2D::_notification(int p_what) {
NavigationServer2D::get_singleton_mut()->connect("map_changed", callable_mp(this, &NavigationRegion2D::_map_changed));
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
NavigationServer2D::get_singleton()->region_set_transform(region, get_global_transform());
} break;
case NOTIFICATION_EXIT_TREE: {
NavigationServer2D::get_singleton()->region_set_map(region, RID());
if (enabled) {
NavigationServer2D::get_singleton_mut()->disconnect("map_changed", callable_mp(this, &NavigationRegion2D::_map_changed));
}
} break;
case NOTIFICATION_DRAW: {
if (is_inside_tree() && (Engine::get_singleton()->is_editor_hint() || get_tree()->is_debugging_navigation_hint()) && navpoly.is_valid()) {
Vector<Vector2> verts = navpoly->get_vertices();

View File

@ -29,6 +29,7 @@
/*************************************************************************/
#include "parallax_background.h"
#include "parallax_layer.h"
void ParallaxBackground::_notification(int p_what) {
@ -36,8 +37,8 @@ void ParallaxBackground::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
group_name = "__cameras_" + itos(get_viewport().get_id());
add_to_group(group_name);
} break;
case NOTIFICATION_EXIT_TREE: {
remove_from_group(group_name);
} break;

View File

@ -99,6 +99,7 @@ void ParallaxLayer::_notification(int p_what) {
orig_scale = get_scale();
_update_mirroring();
} break;
case NOTIFICATION_EXIT_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
break;

View File

@ -86,36 +86,41 @@ bool Path2D::_edit_is_selected_on_click(const Point2 &p_point, double p_toleranc
#endif
void Path2D::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW && curve.is_valid()) {
//draw the curve!!
switch (p_what) {
// Draw the curve if navigation debugging is enabled.
case NOTIFICATION_DRAW: {
if (!curve.is_valid()) {
break;
}
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_navigation_hint()) {
return;
}
if (!Engine::get_singleton()->is_editor_hint() && !get_tree()->is_debugging_navigation_hint()) {
return;
}
if (curve->get_point_count() < 2) {
return;
}
if (curve->get_point_count() < 2) {
return;
}
#ifdef TOOLS_ENABLED
const real_t line_width = 2 * EDSCALE;
const real_t line_width = 2 * EDSCALE;
#else
const real_t line_width = 2;
const real_t line_width = 2;
#endif
const Color color = Color(0.5, 0.6, 1.0, 0.7);
const Color color = Color(0.5, 0.6, 1.0, 0.7);
_cached_draw_pts.resize(curve->get_point_count() * 8);
int count = 0;
_cached_draw_pts.resize(curve->get_point_count() * 8);
int count = 0;
for (int i = 0; i < curve->get_point_count(); i++) {
for (int j = 0; j < 8; j++) {
real_t frac = j * (1.0 / 8.0);
Vector2 p = curve->interpolate(i, frac);
_cached_draw_pts.set(count++, p);
for (int i = 0; i < curve->get_point_count(); i++) {
for (int j = 0; j < 8; j++) {
real_t frac = j * (1.0 / 8.0);
Vector2 p = curve->interpolate(i, frac);
_cached_draw_pts.set(count++, p);
}
}
}
draw_polyline(_cached_draw_pts, color, line_width, true);
draw_polyline(_cached_draw_pts, color, line_width, true);
} break;
}
}
@ -226,8 +231,8 @@ void PathFollow2D::_notification(int p_what) {
if (path) {
_update_transform();
}
} break;
case NOTIFICATION_EXIT_TREE: {
path = nullptr;
} break;

View File

@ -906,7 +906,7 @@ void RigidDynamicBody2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
set_notify_local_transform(true); //used for warnings and only in editor
set_notify_local_transform(true); // Used for warnings and only in editor.
}
} break;

View File

@ -90,6 +90,7 @@ void Position2D::_notification(int p_what) {
case NOTIFICATION_ENTER_TREE: {
update();
} break;
case NOTIFICATION_DRAW: {
if (!is_inside_tree()) {
break;
@ -97,7 +98,6 @@ void Position2D::_notification(int p_what) {
if (Engine::get_singleton()->is_editor_hint()) {
_draw_cross();
}
} break;
}
}

View File

@ -150,11 +150,11 @@ void RayCast2D::_notification(int p_what) {
}
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (enabled) {
set_physics_process_internal(false);
}
} break;
case NOTIFICATION_DRAW: {
@ -163,16 +163,13 @@ void RayCast2D::_notification(int p_what) {
break;
}
_draw_debug_shape();
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!enabled) {
break;
}
_update_raycast_state();
} break;
}
}

View File

@ -115,8 +115,8 @@ void RemoteTransform2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_cache();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_inside_tree()) {
break;
@ -125,7 +125,6 @@ void RemoteTransform2D::_notification(int p_what) {
if (cache.is_valid()) {
_update_remote();
}
} break;
}
}

View File

@ -201,6 +201,7 @@ void ShapeCast2D::_notification(int p_what) {
}
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (enabled) {
set_physics_process_internal(false);
@ -254,6 +255,7 @@ void ShapeCast2D::_notification(int p_what) {
}
#endif
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!enabled) {
break;

View File

@ -93,223 +93,228 @@ void Bone2D::_get_property_list(List<PropertyInfo> *p_list) const {
}
void Bone2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
Node *parent = get_parent();
parent_bone = Object::cast_to<Bone2D>(parent);
skeleton = nullptr;
while (parent) {
skeleton = Object::cast_to<Skeleton2D>(parent);
if (skeleton) {
break;
}
if (!Object::cast_to<Bone2D>(parent)) {
break; //skeletons must be chained to Bone2Ds.
}
parent = parent->get_parent();
}
if (skeleton) {
Skeleton2D::Bone bone;
bone.bone = this;
skeleton->bones.push_back(bone);
skeleton->_make_bone_setup_dirty();
}
cache_transform = get_transform();
copy_transform_to_cache = true;
#ifdef TOOLS_ENABLED
// Only draw the gizmo in the editor!
if (Engine::get_singleton()->is_editor_hint() == false) {
return;
}
update();
#endif // TOOLS_ENABLED
}
else if (p_what == NOTIFICATION_LOCAL_TRANSFORM_CHANGED) {
if (skeleton) {
skeleton->_make_transform_dirty();
}
if (copy_transform_to_cache) {
cache_transform = get_transform();
}
#ifdef TOOLS_ENABLED
// Only draw the gizmo in the editor!
if (Engine::get_singleton()->is_editor_hint() == false) {
return;
}
update();
if (get_parent()) {
Bone2D *parent_bone = Object::cast_to<Bone2D>(get_parent());
if (parent_bone) {
parent_bone->update();
}
}
#endif // TOOLS_ENABLED
}
else if (p_what == NOTIFICATION_MOVED_IN_PARENT) {
if (skeleton) {
skeleton->_make_bone_setup_dirty();
}
if (copy_transform_to_cache) {
cache_transform = get_transform();
}
}
else if (p_what == NOTIFICATION_EXIT_TREE) {
if (skeleton) {
for (int i = 0; i < skeleton->bones.size(); i++) {
if (skeleton->bones[i].bone == this) {
skeleton->bones.remove_at(i);
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
Node *parent = get_parent();
parent_bone = Object::cast_to<Bone2D>(parent);
skeleton = nullptr;
while (parent) {
skeleton = Object::cast_to<Skeleton2D>(parent);
if (skeleton) {
break;
}
}
skeleton->_make_bone_setup_dirty();
skeleton = nullptr;
}
parent_bone = nullptr;
set_transform(cache_transform);
}
if (!Object::cast_to<Bone2D>(parent)) {
break; //skeletons must be chained to Bone2Ds.
}
parent = parent->get_parent();
}
if (skeleton) {
Skeleton2D::Bone bone;
bone.bone = this;
skeleton->bones.push_back(bone);
skeleton->_make_bone_setup_dirty();
}
cache_transform = get_transform();
copy_transform_to_cache = true;
else if (p_what == NOTIFICATION_READY) {
if (autocalculate_length_and_angle) {
calculate_length_and_rotation();
}
}
#ifdef TOOLS_ENABLED
else if (p_what == NOTIFICATION_EDITOR_PRE_SAVE || p_what == NOTIFICATION_EDITOR_POST_SAVE) {
Transform2D tmp_trans = get_transform();
set_transform(cache_transform);
cache_transform = tmp_trans;
}
// Bone2D Editor gizmo drawing:
// Only draw the gizmo in the editor!
if (Engine::get_singleton()->is_editor_hint() == false) {
return;
}
update();
#endif // TOOLS_ENABLED
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (skeleton) {
skeleton->_make_transform_dirty();
}
if (copy_transform_to_cache) {
cache_transform = get_transform();
}
#ifdef TOOLS_ENABLED
// Only draw the gizmo in the editor!
if (Engine::get_singleton()->is_editor_hint() == false) {
return;
}
update();
if (get_parent()) {
Bone2D *parent_bone = Object::cast_to<Bone2D>(get_parent());
if (parent_bone) {
parent_bone->update();
}
}
#endif // TOOLS_ENABLED
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
if (skeleton) {
skeleton->_make_bone_setup_dirty();
}
if (copy_transform_to_cache) {
cache_transform = get_transform();
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (skeleton) {
for (int i = 0; i < skeleton->bones.size(); i++) {
if (skeleton->bones[i].bone == this) {
skeleton->bones.remove_at(i);
break;
}
}
skeleton->_make_bone_setup_dirty();
skeleton = nullptr;
}
parent_bone = nullptr;
set_transform(cache_transform);
} break;
case NOTIFICATION_READY: {
if (autocalculate_length_and_angle) {
calculate_length_and_rotation();
}
} break;
#ifdef TOOLS_ENABLED
case NOTIFICATION_EDITOR_PRE_SAVE:
case NOTIFICATION_EDITOR_POST_SAVE: {
Transform2D tmp_trans = get_transform();
set_transform(cache_transform);
cache_transform = tmp_trans;
} break;
// Bone2D Editor gizmo drawing:
#ifndef _MSC_VER
#warning TODO Bone2D gizmo drawing needs to be moved to an editor plugin
#endif
else if (p_what == NOTIFICATION_DRAW) {
// Only draw the gizmo in the editor!
if (Engine::get_singleton()->is_editor_hint() == false) {
return;
}
if (editor_gizmo_rid.is_null()) {
editor_gizmo_rid = RenderingServer::get_singleton()->canvas_item_create();
RenderingServer::get_singleton()->canvas_item_set_parent(editor_gizmo_rid, get_canvas_item());
RenderingServer::get_singleton()->canvas_item_set_z_as_relative_to_parent(editor_gizmo_rid, true);
RenderingServer::get_singleton()->canvas_item_set_z_index(editor_gizmo_rid, 10);
}
RenderingServer::get_singleton()->canvas_item_clear(editor_gizmo_rid);
if (!_editor_show_bone_gizmo) {
return;
}
// Undo scaling
Transform2D editor_gizmo_trans = Transform2D();
editor_gizmo_trans.set_scale(Vector2(1, 1) / get_global_scale());
RenderingServer::get_singleton()->canvas_item_set_transform(editor_gizmo_rid, editor_gizmo_trans);
Color bone_color1 = EditorSettings::get_singleton()->get("editors/2d/bone_color1");
Color bone_color2 = EditorSettings::get_singleton()->get("editors/2d/bone_color2");
Color bone_ik_color = EditorSettings::get_singleton()->get("editors/2d/bone_ik_color");
Color bone_outline_color = EditorSettings::get_singleton()->get("editors/2d/bone_outline_color");
Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2d/bone_selected_color");
bool Bone2D_found = false;
for (int i = 0; i < get_child_count(); i++) {
Bone2D *child_node = nullptr;
child_node = Object::cast_to<Bone2D>(get_child(i));
if (!child_node) {
continue;
}
Bone2D_found = true;
Vector<Vector2> bone_shape;
Vector<Vector2> bone_shape_outline;
_editor_get_bone_shape(&bone_shape, &bone_shape_outline, child_node);
Vector<Color> colors;
if (has_meta("_local_pose_override_enabled_")) {
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
} else {
colors.push_back(bone_color1);
colors.push_back(bone_color2);
colors.push_back(bone_color1);
colors.push_back(bone_color2);
case NOTIFICATION_DRAW: {
// Only draw the gizmo in the editor!
if (Engine::get_singleton()->is_editor_hint() == false) {
return;
}
Vector<Color> outline_colors;
if (CanvasItemEditor::get_singleton()->editor_selection->is_selected(this)) {
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
} else {
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
if (editor_gizmo_rid.is_null()) {
editor_gizmo_rid = RenderingServer::get_singleton()->canvas_item_create();
RenderingServer::get_singleton()->canvas_item_set_parent(editor_gizmo_rid, get_canvas_item());
RenderingServer::get_singleton()->canvas_item_set_z_as_relative_to_parent(editor_gizmo_rid, true);
RenderingServer::get_singleton()->canvas_item_set_z_index(editor_gizmo_rid, 10);
}
RenderingServer::get_singleton()->canvas_item_clear(editor_gizmo_rid);
if (!_editor_show_bone_gizmo) {
return;
}
RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape_outline, outline_colors);
RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape, colors);
}
// Undo scaling
Transform2D editor_gizmo_trans = Transform2D();
editor_gizmo_trans.set_scale(Vector2(1, 1) / get_global_scale());
RenderingServer::get_singleton()->canvas_item_set_transform(editor_gizmo_rid, editor_gizmo_trans);
if (!Bone2D_found) {
Vector<Vector2> bone_shape;
Vector<Vector2> bone_shape_outline;
Color bone_color1 = EditorSettings::get_singleton()->get("editors/2d/bone_color1");
Color bone_color2 = EditorSettings::get_singleton()->get("editors/2d/bone_color2");
Color bone_ik_color = EditorSettings::get_singleton()->get("editors/2d/bone_ik_color");
Color bone_outline_color = EditorSettings::get_singleton()->get("editors/2d/bone_outline_color");
Color bone_selected_color = EditorSettings::get_singleton()->get("editors/2d/bone_selected_color");
_editor_get_bone_shape(&bone_shape, &bone_shape_outline, nullptr);
bool Bone2D_found = false;
for (int i = 0; i < get_child_count(); i++) {
Bone2D *child_node = nullptr;
child_node = Object::cast_to<Bone2D>(get_child(i));
if (!child_node) {
continue;
}
Bone2D_found = true;
Vector<Color> colors;
if (has_meta("_local_pose_override_enabled_")) {
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
} else {
colors.push_back(bone_color1);
colors.push_back(bone_color2);
colors.push_back(bone_color1);
colors.push_back(bone_color2);
Vector<Vector2> bone_shape;
Vector<Vector2> bone_shape_outline;
_editor_get_bone_shape(&bone_shape, &bone_shape_outline, child_node);
Vector<Color> colors;
if (has_meta("_local_pose_override_enabled_")) {
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
} else {
colors.push_back(bone_color1);
colors.push_back(bone_color2);
colors.push_back(bone_color1);
colors.push_back(bone_color2);
}
Vector<Color> outline_colors;
if (CanvasItemEditor::get_singleton()->editor_selection->is_selected(this)) {
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
} else {
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
}
RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape_outline, outline_colors);
RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape, colors);
}
Vector<Color> outline_colors;
if (CanvasItemEditor::get_singleton()->editor_selection->is_selected(this)) {
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
} else {
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
}
if (!Bone2D_found) {
Vector<Vector2> bone_shape;
Vector<Vector2> bone_shape_outline;
RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape_outline, outline_colors);
RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape, colors);
}
_editor_get_bone_shape(&bone_shape, &bone_shape_outline, nullptr);
Vector<Color> colors;
if (has_meta("_local_pose_override_enabled_")) {
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
colors.push_back(bone_ik_color);
} else {
colors.push_back(bone_color1);
colors.push_back(bone_color2);
colors.push_back(bone_color1);
colors.push_back(bone_color2);
}
Vector<Color> outline_colors;
if (CanvasItemEditor::get_singleton()->editor_selection->is_selected(this)) {
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
outline_colors.push_back(bone_selected_color);
} else {
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
outline_colors.push_back(bone_outline_color);
}
RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape_outline, outline_colors);
RenderingServer::get_singleton()->canvas_item_add_polygon(editor_gizmo_rid, bone_shape, colors);
}
} break;
#endif // TOOLS_ENABLED
}
#endif // TOOLS_ENALBED
}
#ifdef TOOLS_ENABLED

View File

@ -122,11 +122,6 @@ void Sprite2D::_notification(int p_what) {
RID ci = get_canvas_item();
/*
texture->draw(ci,Point2());
break;
*/
Rect2 src_rect, dst_rect;
bool filter_clip_enabled;
_get_rects(src_rect, dst_rect, filter_clip_enabled);

View File

@ -489,6 +489,7 @@ void TileMap::_notification(int p_what) {
_clear_internals();
_recreate_internals();
} break;
case NOTIFICATION_EXIT_TREE: {
_clear_internals();
} break;
@ -980,7 +981,7 @@ void TileMap::_recompute_rect_cache() {
void TileMap::_rendering_notification(int p_what) {
switch (p_what) {
case CanvasItem::NOTIFICATION_VISIBILITY_CHANGED: {
case NOTIFICATION_VISIBILITY_CHANGED: {
bool visible = is_visible_in_tree();
for (int layer = 0; layer < (int)layers.size(); layer++) {
for (KeyValue<Vector2i, TileMapQuadrant> &E_quadrant : layers[layer].quadrant_map) {
@ -997,7 +998,8 @@ void TileMap::_rendering_notification(int p_what) {
}
}
} break;
case CanvasItem::NOTIFICATION_TRANSFORM_CHANGED: {
case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_inside_tree()) {
return;
}
@ -1016,7 +1018,8 @@ void TileMap::_rendering_notification(int p_what) {
}
}
} break;
case CanvasItem::NOTIFICATION_DRAW: {
case NOTIFICATION_DRAW: {
if (tile_set.is_valid()) {
RenderingServer::get_singleton()->canvas_item_set_sort_children_by_y(get_canvas_item(), is_y_sort_enabled());
}
@ -1369,7 +1372,7 @@ void TileMap::draw_tile(RID p_canvas_item, Vector2i p_position, const Ref<TileSe
void TileMap::_physics_notification(int p_what) {
switch (p_what) {
case CanvasItem::NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
bool in_editor = false;
#ifdef TOOLS_ENABLED
in_editor = Engine::get_singleton()->is_editor_hint();
@ -1382,7 +1385,8 @@ void TileMap::_physics_notification(int p_what) {
set_notify_local_transform(true);
}
} break;
case CanvasItem::NOTIFICATION_TRANSFORM_CHANGED: {
case NOTIFICATION_TRANSFORM_CHANGED: {
bool in_editor = false;
#ifdef TOOLS_ENABLED
in_editor = Engine::get_singleton()->is_editor_hint();
@ -1404,6 +1408,7 @@ void TileMap::_physics_notification(int p_what) {
}
}
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
bool in_editor = false;
#ifdef TOOLS_ENABLED
@ -1600,7 +1605,7 @@ void TileMap::_physics_draw_quadrant_debug(TileMapQuadrant *p_quadrant) {
void TileMap::_navigation_notification(int p_what) {
switch (p_what) {
case CanvasItem::NOTIFICATION_TRANSFORM_CHANGED: {
case NOTIFICATION_TRANSFORM_CHANGED: {
if (is_inside_tree()) {
for (int layer = 0; layer < (int)layers.size(); layer++) {
Transform2D tilemap_xform = get_global_transform();

View File

@ -134,8 +134,8 @@ void TouchScreenButton::_notification(int p_what) {
draw_set_transform_matrix(get_canvas_transform().translated(pos));
shape->draw(get_canvas_item(), draw_col);
}
} break;
case NOTIFICATION_ENTER_TREE: {
if (!Engine::get_singleton()->is_editor_hint() && !!DisplayServer::get_singleton()->screen_is_touchscreen(DisplayServer::get_singleton()->window_get_current_screen(get_viewport()->get_window_id())) && visibility == VISIBILITY_TOUCHSCREEN_ONLY) {
return;
@ -145,13 +145,14 @@ void TouchScreenButton::_notification(int p_what) {
if (!Engine::get_singleton()->is_editor_hint()) {
set_process_input(is_visible_in_tree());
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (is_pressed()) {
_release(true);
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (Engine::get_singleton()->is_editor_hint()) {
break;
@ -165,6 +166,7 @@ void TouchScreenButton::_notification(int p_what) {
}
}
} break;
case NOTIFICATION_PAUSED: {
if (is_pressed()) {
_release();

View File

@ -75,15 +75,16 @@ Rect2 VisibleOnScreenNotifier2D::get_rect() const {
void VisibleOnScreenNotifier2D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
//get_world_2d()->
on_screen = false;
RS::get_singleton()->canvas_item_set_visibility_notifier(get_canvas_item(), true, rect, callable_mp(this, &VisibleOnScreenNotifier2D::_visibility_enter), callable_mp(this, &VisibleOnScreenNotifier2D::_visibility_exit));
} break;
case NOTIFICATION_DRAW: {
if (Engine::get_singleton()->is_editor_hint()) {
draw_rect(rect, Color(1, 0.5, 1, 0.2));
}
} break;
case NOTIFICATION_EXIT_TREE: {
on_screen = false;
RS::get_singleton()->canvas_item_set_visibility_notifier(get_canvas_item(), false, Rect2(), Callable(), Callable());
@ -169,21 +170,23 @@ void VisibleOnScreenEnabler2D::_update_enable_mode(bool p_enable) {
}
}
void VisibleOnScreenEnabler2D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
node_id = ObjectID();
Node *node = get_node(enable_node_path);
if (node) {
node_id = node->get_instance_id();
node->set_process_mode(PROCESS_MODE_DISABLED);
}
}
node_id = ObjectID();
Node *node = get_node(enable_node_path);
if (node) {
node_id = node->get_instance_id();
node->set_process_mode(PROCESS_MODE_DISABLED);
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
node_id = ObjectID();
case NOTIFICATION_EXIT_TREE: {
node_id = ObjectID();
} break;
}
}

View File

@ -344,10 +344,14 @@ void Area3D::_clear_monitoring() {
}
void Area3D::_notification(int p_what) {
if (p_what == NOTIFICATION_EXIT_TREE) {
_clear_monitoring();
} else if (p_what == NOTIFICATION_ENTER_TREE) {
_initialize_wind();
switch (p_what) {
case NOTIFICATION_EXIT_TREE: {
_clear_monitoring();
} break;
case NOTIFICATION_ENTER_TREE: {
_initialize_wind();
} break;
}
}

View File

@ -85,9 +85,11 @@ void AudioListener3D::_notification(int p_what) {
make_current();
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
_request_listener_update();
} break;
case NOTIFICATION_EXIT_WORLD: {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
@ -100,7 +102,6 @@ void AudioListener3D::_notification(int p_what) {
}
get_viewport()->_audio_listener_3d_remove(this);
} break;
}
}

View File

@ -239,80 +239,82 @@ float AudioStreamPlayer3D::_get_attenuation_db(float p_distance) const {
}
void AudioStreamPlayer3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
velocity_tracker->reset(get_global_transform().origin);
AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
}
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
velocity_tracker->reset(get_global_transform().origin);
AudioServer::get_singleton()->add_listener_changed_callback(_listener_changed_cb, this);
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
stop();
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
}
case NOTIFICATION_EXIT_TREE: {
stop();
AudioServer::get_singleton()->remove_listener_changed_callback(_listener_changed_cb, this);
} break;
if (p_what == NOTIFICATION_PAUSED) {
if (!can_process()) {
// Node can't process so we start fading out to silence
set_stream_paused(true);
}
}
case NOTIFICATION_PAUSED: {
if (!can_process()) {
// Node can't process so we start fading out to silence.
set_stream_paused(true);
}
} break;
if (p_what == NOTIFICATION_UNPAUSED) {
set_stream_paused(false);
}
case NOTIFICATION_UNPAUSED: {
set_stream_paused(false);
} break;
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
velocity_tracker->update_position(get_global_transform().origin);
}
}
case NOTIFICATION_TRANSFORM_CHANGED: {
if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
velocity_tracker->update_position(get_global_transform().origin);
}
} break;
if (p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
//update anything related to position first, if possible of course
Vector<AudioFrame> volume_vector;
if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
volume_vector = _update_panning();
}
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
// Update anything related to position first, if possible of course.
Vector<AudioFrame> volume_vector;
if (setplay.get() > 0 || (active.is_set() && last_mix_count != AudioServer::get_singleton()->get_mix_count())) {
volume_vector = _update_panning();
}
if (setplay.get() >= 0 && stream.is_valid()) {
active.set();
Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
Map<StringName, Vector<AudioFrame>> bus_map;
bus_map[_get_actual_bus()] = volume_vector;
AudioServer::get_singleton()->start_playback_stream(new_playback, bus_map, setplay.get(), actual_pitch_scale, linear_attenuation, attenuation_filter_cutoff_hz);
stream_playbacks.push_back(new_playback);
setplay.set(-1);
}
if (setplay.get() >= 0 && stream.is_valid()) {
active.set();
Ref<AudioStreamPlayback> new_playback = stream->instance_playback();
ERR_FAIL_COND_MSG(new_playback.is_null(), "Failed to instantiate playback.");
Map<StringName, Vector<AudioFrame>> bus_map;
bus_map[_get_actual_bus()] = volume_vector;
AudioServer::get_singleton()->start_playback_stream(new_playback, bus_map, setplay.get(), actual_pitch_scale, linear_attenuation, attenuation_filter_cutoff_hz);
stream_playbacks.push_back(new_playback);
setplay.set(-1);
}
if (!stream_playbacks.is_empty() && active.is_set()) {
// Stop playing if no longer active.
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
if (!stream_playbacks.is_empty() && active.is_set()) {
// Stop playing if no longer active.
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
}
}
// Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
stream_playbacks.erase(playback);
}
if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
// This node is no longer actively playing audio.
active.clear();
set_physics_process_internal(false);
}
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
}
// Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
stream_playbacks.erase(playback);
}
if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
// This node is no longer actively playing audio.
active.clear();
set_physics_process_internal(false);
}
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
}
while (stream_playbacks.size() > max_polyphony) {
AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
stream_playbacks.remove_at(0);
}
while (stream_playbacks.size() > max_polyphony) {
AudioServer::get_singleton()->stop_playback_stream(stream_playbacks[0]);
stream_playbacks.remove_at(0);
}
} break;
}
}

View File

@ -340,17 +340,20 @@ void BoneAttachment3D::_notification(int p_what) {
}
_check_bind();
} break;
case NOTIFICATION_EXIT_TREE: {
_check_unbind();
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
_transform_changed();
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
if (_override_dirty) {
_override_dirty = false;
}
}
} break;
}
}

View File

@ -108,14 +108,15 @@ void Camera3D::_notification(int p_what) {
if (current || first_camera) {
viewport->_camera_3d_set(this);
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
_request_camera_update();
if (doppler_tracking != DOPPLER_TRACKING_DISABLED) {
velocity_tracker->update_position(get_global_transform().origin);
}
} break;
case NOTIFICATION_EXIT_WORLD: {
if (!get_tree()->is_node_being_edited(this)) {
if (is_current()) {
@ -131,13 +132,14 @@ void Camera3D::_notification(int p_what) {
viewport->_camera_3d_remove(this);
viewport = nullptr;
}
} break;
case NOTIFICATION_BECAME_CURRENT: {
if (viewport) {
viewport->find_world_3d()->_register_camera(this);
}
} break;
case NOTIFICATION_LOST_CURRENT: {
if (viewport) {
viewport->find_world_3d()->_remove_camera(this);

View File

@ -93,18 +93,19 @@ void CollisionPolygon3D::_notification(int p_what) {
_update_in_shape_owner();
}
} break;
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}
} break;
case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);

View File

@ -87,16 +87,19 @@ void CollisionShape3D::_notification(int p_what) {
_update_in_shape_owner();
}
} break;
case NOTIFICATION_ENTER_TREE: {
if (parent) {
_update_in_shape_owner();
}
} break;
case NOTIFICATION_LOCAL_TRANSFORM_CHANGED: {
if (parent) {
_update_in_shape_owner(true);
}
} break;
case NOTIFICATION_UNPARENTED: {
if (parent) {
parent->remove_shape_owner(owner_id);

View File

@ -1251,65 +1251,67 @@ void CPUParticles3D::_update_render_thread() {
}
void CPUParticles3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
set_process_internal(emitting);
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
set_process_internal(emitting);
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
_update_internal();
}
} break;
case NOTIFICATION_EXIT_TREE: {
_set_redraw(false);
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
_update_internal();
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
_update_internal();
}
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
_set_redraw(false);
}
case NOTIFICATION_TRANSFORM_CHANGED: {
inv_emission_transform = get_global_transform().affine_inverse();
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
// first update before rendering to avoid one frame delay after emitting starts
if (emitting && (time == 0)) {
_update_internal();
}
}
if (!local_coords) {
int pc = particles.size();
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
_update_internal();
}
float *w = particle_data.ptrw();
const Particle *r = particles.ptr();
float *ptr = w;
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
inv_emission_transform = get_global_transform().affine_inverse();
for (int i = 0; i < pc; i++) {
Transform3D t = inv_emission_transform * r[i].transform;
if (!local_coords) {
int pc = particles.size();
if (r[i].active) {
ptr[0] = t.basis.elements[0][0];
ptr[1] = t.basis.elements[0][1];
ptr[2] = t.basis.elements[0][2];
ptr[3] = t.origin.x;
ptr[4] = t.basis.elements[1][0];
ptr[5] = t.basis.elements[1][1];
ptr[6] = t.basis.elements[1][2];
ptr[7] = t.origin.y;
ptr[8] = t.basis.elements[2][0];
ptr[9] = t.basis.elements[2][1];
ptr[10] = t.basis.elements[2][2];
ptr[11] = t.origin.z;
} else {
memset(ptr, 0, sizeof(float) * 12);
}
float *w = particle_data.ptrw();
const Particle *r = particles.ptr();
float *ptr = w;
for (int i = 0; i < pc; i++) {
Transform3D t = inv_emission_transform * r[i].transform;
if (r[i].active) {
ptr[0] = t.basis.elements[0][0];
ptr[1] = t.basis.elements[0][1];
ptr[2] = t.basis.elements[0][2];
ptr[3] = t.origin.x;
ptr[4] = t.basis.elements[1][0];
ptr[5] = t.basis.elements[1][1];
ptr[6] = t.basis.elements[1][2];
ptr[7] = t.origin.y;
ptr[8] = t.basis.elements[2][0];
ptr[9] = t.basis.elements[2][1];
ptr[10] = t.basis.elements[2][2];
ptr[11] = t.origin.z;
} else {
memset(ptr, 0, sizeof(float) * 12);
ptr += 20;
}
ptr += 20;
can_update.set();
}
can_update.set();
}
} break;
}
}

View File

@ -423,38 +423,41 @@ NodePath GPUParticles3D::get_sub_emitter() const {
}
void GPUParticles3D::_notification(int p_what) {
if (p_what == NOTIFICATION_PAUSED || p_what == NOTIFICATION_UNPAUSED) {
if (can_process()) {
RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
} else {
RS::get_singleton()->particles_set_speed_scale(particles, 0);
}
}
switch (p_what) {
case NOTIFICATION_PAUSED:
case NOTIFICATION_UNPAUSED: {
if (can_process()) {
RS::get_singleton()->particles_set_speed_scale(particles, speed_scale);
} else {
RS::get_singleton()->particles_set_speed_scale(particles, 0);
}
} break;
// Use internal process when emitting and one_shot is on so that when
// the shot ends the editor can properly update
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
if (one_shot && !is_emitting()) {
notify_property_list_changed();
set_process_internal(false);
}
}
// Use internal process when emitting and one_shot is on so that when
// the shot ends the editor can properly update.
case NOTIFICATION_INTERNAL_PROCESS: {
if (one_shot && !is_emitting()) {
notify_property_list_changed();
set_process_internal(false);
}
} break;
if (p_what == NOTIFICATION_ENTER_TREE) {
if (sub_emitter != NodePath()) {
_attach_sub_emitter();
}
}
case NOTIFICATION_ENTER_TREE: {
if (sub_emitter != NodePath()) {
_attach_sub_emitter();
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
RS::get_singleton()->particles_set_subemitter(particles, RID());
}
case NOTIFICATION_EXIT_TREE: {
RS::get_singleton()->particles_set_subemitter(particles, RID());
} break;
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
// make sure particles are updated before rendering occurs if they were active before
if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) {
RS::get_singleton()->particles_request_process(particles);
}
case NOTIFICATION_VISIBILITY_CHANGED: {
// Make sure particles are updated before rendering occurs if they were active before.
if (is_visible_in_tree() && !RS::get_singleton()->particles_is_inactive(particles)) {
RS::get_singleton()->particles_request_process(particles);
}
} break;
}
}

View File

@ -584,47 +584,49 @@ GPUParticlesCollisionSDF3D::~GPUParticlesCollisionSDF3D() {
////////////////////////////
void GPUParticlesCollisionHeightField3D::_notification(int p_what) {
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
if (update_mode == UPDATE_MODE_ALWAYS) {
RS::get_singleton()->particles_collision_height_field_update(_get_collision());
}
switch (p_what) {
case NOTIFICATION_INTERNAL_PROCESS: {
if (update_mode == UPDATE_MODE_ALWAYS) {
RS::get_singleton()->particles_collision_height_field_update(_get_collision());
}
if (follow_camera_mode && get_viewport()) {
Camera3D *cam = get_viewport()->get_camera_3d();
if (cam) {
Transform3D xform = get_global_transform();
Vector3 x_axis = xform.basis.get_axis(Vector3::AXIS_X).normalized();
Vector3 z_axis = xform.basis.get_axis(Vector3::AXIS_Z).normalized();
float x_len = xform.basis.get_scale().x;
float z_len = xform.basis.get_scale().z;
if (follow_camera_mode && get_viewport()) {
Camera3D *cam = get_viewport()->get_camera_3d();
if (cam) {
Transform3D xform = get_global_transform();
Vector3 x_axis = xform.basis.get_axis(Vector3::AXIS_X).normalized();
Vector3 z_axis = xform.basis.get_axis(Vector3::AXIS_Z).normalized();
float x_len = xform.basis.get_scale().x;
float z_len = xform.basis.get_scale().z;
Vector3 cam_pos = cam->get_global_transform().origin;
Transform3D new_xform = xform;
Vector3 cam_pos = cam->get_global_transform().origin;
Transform3D new_xform = xform;
while (x_axis.dot(cam_pos - new_xform.origin) > x_len) {
new_xform.origin += x_axis * x_len;
}
while (x_axis.dot(cam_pos - new_xform.origin) < -x_len) {
new_xform.origin -= x_axis * x_len;
}
while (x_axis.dot(cam_pos - new_xform.origin) > x_len) {
new_xform.origin += x_axis * x_len;
}
while (x_axis.dot(cam_pos - new_xform.origin) < -x_len) {
new_xform.origin -= x_axis * x_len;
}
while (z_axis.dot(cam_pos - new_xform.origin) > z_len) {
new_xform.origin += z_axis * z_len;
}
while (z_axis.dot(cam_pos - new_xform.origin) < -z_len) {
new_xform.origin -= z_axis * z_len;
}
while (z_axis.dot(cam_pos - new_xform.origin) > z_len) {
new_xform.origin += z_axis * z_len;
}
while (z_axis.dot(cam_pos - new_xform.origin) < -z_len) {
new_xform.origin -= z_axis * z_len;
}
if (new_xform != xform) {
set_global_transform(new_xform);
RS::get_singleton()->particles_collision_height_field_update(_get_collision());
if (new_xform != xform) {
set_global_transform(new_xform);
RS::get_singleton()->particles_collision_height_field_update(_get_collision());
}
}
}
}
}
} break;
if (p_what == NOTIFICATION_TRANSFORM_CHANGED) {
RS::get_singleton()->particles_collision_height_field_update(_get_collision());
case NOTIFICATION_TRANSFORM_CHANGED: {
RS::get_singleton()->particles_collision_height_field_update(_get_collision());
} break;
}
}

View File

@ -169,6 +169,7 @@ void Joint3D::_notification(int p_what) {
case NOTIFICATION_READY: {
_update_joint();
} break;
case NOTIFICATION_EXIT_TREE: {
if (joint.is_valid()) {
_disconnect_signals();

View File

@ -177,12 +177,11 @@ void Light3D::_update_visibility() {
}
void Light3D::_notification(int p_what) {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
_update_visibility();
}
if (p_what == NOTIFICATION_ENTER_TREE) {
_update_visibility();
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED:
case NOTIFICATION_ENTER_TREE: {
_update_visibility();
} break;
}
}

View File

@ -1176,16 +1176,18 @@ LightmapGI::BakeError LightmapGI::bake(Node *p_from_node, String p_image_data_pa
}
void LightmapGI::_notification(int p_what) {
if (p_what == NOTIFICATION_POST_ENTER_TREE) {
if (light_data.is_valid()) {
_assign_lightmaps();
}
}
switch (p_what) {
case NOTIFICATION_POST_ENTER_TREE: {
if (light_data.is_valid()) {
_assign_lightmaps();
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
if (light_data.is_valid()) {
_clear_lightmaps();
}
case NOTIFICATION_EXIT_TREE: {
if (light_data.is_valid()) {
_clear_lightmaps();
}
} break;
}
}

View File

@ -328,8 +328,10 @@ void MeshInstance3D::create_multiple_convex_collisions() {
}
void MeshInstance3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
_resolve_skeleton_path();
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_resolve_skeleton_path();
} break;
}
}

View File

@ -103,10 +103,12 @@ void NavigationAgent3D::_notification(int p_what) {
}
set_physics_process_internal(true);
} break;
case NOTIFICATION_EXIT_TREE: {
agent_parent = nullptr;
set_physics_process_internal(false);
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (agent_parent) {
NavigationServer3D::get_singleton()->agent_set_position(agent, agent_parent->get_global_transform().origin);

View File

@ -63,17 +63,21 @@ void NavigationObstacle3D::_notification(int p_what) {
}
set_physics_process_internal(true);
} break;
case NOTIFICATION_EXIT_TREE: {
parent_node3d = nullptr;
set_physics_process_internal(false);
} break;
case NOTIFICATION_PARENTED: {
parent_node3d = Object::cast_to<Node3D>(get_parent());
reevaluate_agent_radius();
} break;
case NOTIFICATION_UNPARENTED: {
parent_node3d = nullptr;
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (parent_node3d) {
NavigationServer3D::get_singleton()->agent_set_position(agent, parent_node3d->get_global_transform().origin);

View File

@ -93,12 +93,12 @@ void NavigationRegion3D::_notification(int p_what) {
add_child(dm);
debug_view = dm;
}
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
NavigationServer3D::get_singleton()->region_set_transform(region, get_global_transform());
} break;
case NOTIFICATION_EXIT_TREE: {
NavigationServer3D::get_singleton()->region_set_map(region, RID());

View File

@ -147,8 +147,8 @@ void Node3D::_notification(int p_what) {
notification(NOTIFICATION_ENTER_WORLD);
_update_visibility_parent(true);
} break;
case NOTIFICATION_EXIT_TREE: {
notification(NOTIFICATION_EXIT_WORLD, true);
if (xform_change.in_list()) {
@ -162,6 +162,7 @@ void Node3D::_notification(int p_what) {
data.top_level_active = false;
_update_visibility_parent(true);
} break;
case NOTIFICATION_ENTER_WORLD: {
data.inside_world = true;
data.viewport = nullptr;
@ -192,6 +193,7 @@ void Node3D::_notification(int p_what) {
}
#endif
} break;
case NOTIFICATION_EXIT_WORLD: {
#ifdef TOOLS_ENABLED
clear_gizmos();
@ -203,7 +205,6 @@ void Node3D::_notification(int p_what) {
data.viewport = nullptr;
data.inside_world = false;
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
@ -213,9 +214,6 @@ void Node3D::_notification(int p_what) {
}
#endif
} break;
default: {
}
}
}

View File

@ -122,8 +122,10 @@ AABB Occluder3D::get_aabb() const {
}
void Occluder3D::_notification(int p_what) {
if (p_what == NOTIFICATION_POSTINITIALIZE) {
_update();
switch (p_what) {
case NOTIFICATION_POSTINITIALIZE: {
_update();
} break;
}
}

View File

@ -30,9 +30,6 @@
#include "path_3d.h"
void Path3D::_notification(int p_what) {
}
void Path3D::_curve_changed() {
if (is_inside_tree() && Engine::get_singleton()->is_editor_hint()) {
update_gizmos();
@ -223,8 +220,8 @@ void PathFollow3D::_notification(int p_what) {
_update_transform(false);
}
}
} break;
case NOTIFICATION_EXIT_TREE: {
path = nullptr;
} break;

View File

@ -42,7 +42,6 @@ class Path3D : public Node3D {
void _curve_changed();
protected:
void _notification(int p_what);
static void _bind_methods();
public:

View File

@ -601,7 +601,7 @@ void RigidDynamicBody3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
set_notify_local_transform(true); //used for warnings and only in editor
set_notify_local_transform(true); // Used for warnings and only in editor.
}
} break;

View File

@ -171,8 +171,8 @@ void RayCast3D::_notification(int p_what) {
exclude.erase(Object::cast_to<CollisionObject3D>(get_parent())->get_rid());
}
}
} break;
case NOTIFICATION_EXIT_TREE: {
if (enabled) {
set_physics_process_internal(false);
@ -181,8 +181,8 @@ void RayCast3D::_notification(int p_what) {
if (debug_shape) {
_clear_debug_shape();
}
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (!enabled) {
break;
@ -193,7 +193,6 @@ void RayCast3D::_notification(int p_what) {
if (prev_collision_state != collided && get_tree()->is_debugging_collisions_hint()) {
_update_debug_shape_material(true);
}
} break;
}
}

View File

@ -111,8 +111,8 @@ void RemoteTransform3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_cache();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
if (!is_inside_tree()) {
break;
@ -121,7 +121,6 @@ void RemoteTransform3D::_notification(int p_what) {
if (cache.is_valid()) {
_update_remote();
}
} break;
}
}

View File

@ -318,11 +318,9 @@ void Skeleton3D::_notification(int p_what) {
rs->skeleton_bone_set_transform(skeleton, i, bonesptr[bone_index].pose_global * skin->get_bind_pose(i));
}
}
#ifdef TOOLS_ENABLED
emit_signal(SceneStringNames::get_singleton()->pose_updated);
#endif // TOOLS_ENABLED
} break;
#ifndef _3D_DISABLED
@ -344,19 +342,14 @@ void Skeleton3D::_notification(int p_what) {
if (modification_stack.is_valid()) {
execute_modifications(get_physics_process_delta_time(), SkeletonModificationStack3D::EXECUTION_MODE::execution_mode_physics_process);
}
} break;
#endif // _3D_DISABLED
#ifndef _3D_DISABLED
case NOTIFICATION_INTERNAL_PROCESS: {
if (modification_stack.is_valid()) {
execute_modifications(get_process_delta_time(), SkeletonModificationStack3D::EXECUTION_MODE::execution_mode_process);
}
} break;
#endif // _3D_DISABLED
#ifndef _3D_DISABLED
case NOTIFICATION_READY: {
set_physics_process_internal(true);
set_process_internal(true);

View File

@ -407,14 +407,14 @@ void SkeletonIK3D::_notification(int p_what) {
set_process_priority(1);
reload_chain();
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
if (target_node_override) {
reload_goal();
}
_solve_chain();
} break;
case NOTIFICATION_EXIT_TREE: {
reload_chain();
} break;

View File

@ -29,23 +29,26 @@
/*************************************************************************/
#include "spring_arm_3d.h"
#include "scene/3d/camera_3d.h"
void SpringArm3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_ENTER_TREE: {
if (!Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(true);
}
break;
case NOTIFICATION_EXIT_TREE:
} break;
case NOTIFICATION_EXIT_TREE: {
if (!Engine::get_singleton()->is_editor_hint()) {
set_physics_process_internal(false);
}
break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS:
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
process_spring();
break;
} break;
}
}

View File

@ -66,23 +66,25 @@ void SpriteBase3D::_propagate_color_changed() {
}
void SpriteBase3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
if (!pending_update) {
_im_update();
}
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (!pending_update) {
_im_update();
}
parent_sprite = Object::cast_to<SpriteBase3D>(get_parent());
if (parent_sprite) {
pI = parent_sprite->children.push_back(this);
}
}
parent_sprite = Object::cast_to<SpriteBase3D>(get_parent());
if (parent_sprite) {
pI = parent_sprite->children.push_back(this);
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
if (parent_sprite) {
parent_sprite->children.erase(pI);
pI = nullptr;
parent_sprite = nullptr;
}
case NOTIFICATION_EXIT_TREE: {
if (parent_sprite) {
parent_sprite->children.erase(pI);
pI = nullptr;
parent_sprite = nullptr;
}
} break;
}
}

View File

@ -71,8 +71,11 @@ bool VisibleOnScreenNotifier3D::is_on_screen() const {
}
void VisibleOnScreenNotifier3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_EXIT_TREE) {
on_screen = false;
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_EXIT_TREE: {
on_screen = false;
} break;
}
}
@ -161,21 +164,23 @@ void VisibleOnScreenEnabler3D::_update_enable_mode(bool p_enable) {
}
}
void VisibleOnScreenEnabler3D::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (Engine::get_singleton()->is_editor_hint()) {
return;
}
node_id = ObjectID();
Node *node = get_node(enable_node_path);
if (node) {
node_id = node->get_instance_id();
node->set_process_mode(PROCESS_MODE_DISABLED);
}
}
node_id = ObjectID();
Node *node = get_node(enable_node_path);
if (node) {
node_id = node->get_instance_id();
node->set_process_mode(PROCESS_MODE_DISABLED);
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
node_id = ObjectID();
case NOTIFICATION_EXIT_TREE: {
node_id = ObjectID();
} break;
}
}

View File

@ -47,27 +47,21 @@ void VisualInstance3D::_update_visibility() {
void VisualInstance3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_WORLD: {
// CHECK SKELETON => moving skeleton attaching logic to MeshInstance
/*
Skeleton *skeleton=Object::cast_to<Skeleton>(get_parent());
if (skeleton)
RenderingServer::get_singleton()->instance_attach_skeleton( instance, skeleton->get_skeleton() );
*/
ERR_FAIL_COND(get_world_3d().is_null());
RenderingServer::get_singleton()->instance_set_scenario(instance, get_world_3d()->get_scenario());
_update_visibility();
} break;
case NOTIFICATION_TRANSFORM_CHANGED: {
Transform3D gt = get_global_transform();
RenderingServer::get_singleton()->instance_set_transform(instance, gt);
} break;
case NOTIFICATION_EXIT_WORLD: {
RenderingServer::get_singleton()->instance_set_scenario(instance, RID());
RenderingServer::get_singleton()->instance_attach_skeleton(instance, RID());
//RS::get_singleton()->instance_geometry_set_baked_light_sampler(instance, RID() );
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
_update_visibility();
} break;
@ -220,9 +214,6 @@ GeometryInstance3D::VisibilityRangeFadeMode GeometryInstance3D::get_visibility_r
return visibility_range_fade_mode;
}
void GeometryInstance3D::_notification(int p_what) {
}
const StringName *GeometryInstance3D::_instance_uniform_get_remap(const StringName p_name) const {
StringName *r = instance_uniform_property_remap.getptr(p_name);
if (!r) {

View File

@ -137,7 +137,6 @@ protected:
bool _get(const StringName &p_name, Variant &r_ret) const;
void _get_property_list(List<PropertyInfo> *p_list) const;
void _notification(int p_what);
static void _bind_methods();
public:

View File

@ -34,27 +34,32 @@
#include "scene/main/window.h"
void WorldEnvironment::_notification(int p_what) {
if (p_what == Node3D::NOTIFICATION_ENTER_WORLD || p_what == Node3D::NOTIFICATION_ENTER_TREE) {
if (environment.is_valid()) {
add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
_update_current_environment();
}
switch (p_what) {
case Node3D::NOTIFICATION_ENTER_WORLD:
case Node3D::NOTIFICATION_ENTER_TREE: {
if (environment.is_valid()) {
add_to_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
_update_current_environment();
}
if (camera_effects.is_valid()) {
add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
_update_current_camera_effects();
}
if (camera_effects.is_valid()) {
add_to_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
_update_current_camera_effects();
}
} break;
} else if (p_what == Node3D::NOTIFICATION_EXIT_WORLD || p_what == Node3D::NOTIFICATION_EXIT_TREE) {
if (environment.is_valid()) {
remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
_update_current_environment();
}
case Node3D::NOTIFICATION_EXIT_WORLD:
case Node3D::NOTIFICATION_EXIT_TREE: {
if (environment.is_valid()) {
remove_from_group("_world_environment_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
_update_current_environment();
}
if (camera_effects.is_valid()) {
remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
_update_current_camera_effects();
}
if (camera_effects.is_valid()) {
remove_from_group("_world_camera_effects_" + itos(get_viewport()->find_world_3d()->get_scenario().get_id()));
_update_current_camera_effects();
}
} break;
}
}

View File

@ -44,16 +44,17 @@ void XRCamera3D::_notification(int p_what) {
if (origin != nullptr) {
origin->set_tracked_camera(this);
}
}; break;
} break;
case NOTIFICATION_EXIT_TREE: {
// need to find our XROrigin3D parent and let it know we're no longer its camera!
XROrigin3D *origin = Object::cast_to<XROrigin3D>(get_parent());
if (origin != nullptr && origin->get_tracked_camera() == this) {
origin->set_tracked_camera(nullptr);
}
}; break;
};
};
} break;
}
}
void XRCamera3D::_changed_tracker(const StringName p_tracker_name, int p_tracker_type) {
if (p_tracker_name == tracker_name) {
@ -657,10 +658,12 @@ void XROrigin3D::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
set_process_internal(true);
}; break;
} break;
case NOTIFICATION_EXIT_TREE: {
set_process_internal(false);
}; break;
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
// set our world origin to our node transform
xr_server->set_world_origin(get_global_transform());
@ -673,11 +676,9 @@ void XROrigin3D::_notification(int p_what) {
// now apply this to our camera
tracked_camera->set_transform(t);
};
}; break;
default:
break;
};
}
} break;
}
// send our notification to all active XE interfaces, they may need to react to it also
for (int i = 0; i < xr_server->get_interface_count(); i++) {

View File

@ -807,9 +807,6 @@ String AnimationNodeStateMachine::get_caption() const {
return "StateMachine";
}
void AnimationNodeStateMachine::_notification(int p_what) {
}
Ref<AnimationNode> AnimationNodeStateMachine::get_child_by_name(const StringName &p_name) {
return get_node(p_name);
}

View File

@ -164,7 +164,6 @@ private:
void _tree_changed();
protected:
void _notification(int p_what);
static void _bind_methods();
bool _set(const StringName &p_name, const Variant &p_value);

View File

@ -202,15 +202,16 @@ void AnimationPlayer::_notification(int p_what) {
set_physics_process_internal(false);
set_process_internal(false);
}
//_set_process(false);
clear_caches();
} break;
case NOTIFICATION_READY: {
if (!Engine::get_singleton()->is_editor_hint() && animation_set.has(autoplay)) {
play(autoplay);
_animation_process(0);
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
if (process_callback == ANIMATION_PROCESS_PHYSICS) {
break;
@ -220,6 +221,7 @@ void AnimationPlayer::_notification(int p_what) {
_animation_process(get_process_delta_time());
}
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (process_callback == ANIMATION_PROCESS_IDLE) {
break;
@ -229,6 +231,7 @@ void AnimationPlayer::_notification(int p_what) {
_animation_process(get_physics_process_delta_time());
}
} break;
case NOTIFICATION_EXIT_TREE: {
clear_caches();
} break;

View File

@ -1586,29 +1586,37 @@ void AnimationTree::advance(real_t p_time) {
}
void AnimationTree::_notification(int p_what) {
if (active && p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS && process_callback == ANIMATION_PROCESS_PHYSICS) {
_process_graph(get_physics_process_delta_time());
}
if (active && p_what == NOTIFICATION_INTERNAL_PROCESS && process_callback == ANIMATION_PROCESS_IDLE) {
_process_graph(get_process_delta_time());
}
if (p_what == NOTIFICATION_EXIT_TREE) {
_clear_caches();
if (last_animation_player.is_valid()) {
Object *player = ObjectDB::get_instance(last_animation_player);
if (player) {
player->disconnect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (last_animation_player.is_valid()) {
Object *player = ObjectDB::get_instance(last_animation_player);
if (player) {
player->connect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
}
}
}
} else if (p_what == NOTIFICATION_ENTER_TREE) {
if (last_animation_player.is_valid()) {
Object *player = ObjectDB::get_instance(last_animation_player);
if (player) {
player->connect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
} break;
case NOTIFICATION_EXIT_TREE: {
_clear_caches();
if (last_animation_player.is_valid()) {
Object *player = ObjectDB::get_instance(last_animation_player);
if (player) {
player->disconnect("caches_cleared", callable_mp(this, &AnimationTree::_clear_caches));
}
}
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
if (active && process_callback == ANIMATION_PROCESS_IDLE) {
_process_graph(get_process_delta_time());
}
} break;
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
if (active && process_callback == ANIMATION_PROCESS_PHYSICS) {
_process_graph(get_physics_process_delta_time());
}
} break;
}
}

View File

@ -29,8 +29,10 @@
/*************************************************************************/
#include "root_motion_view.h"
#include "scene/animation/animation_tree.h"
#include "scene/resources/material.h"
void RootMotionView::set_animation_path(const NodePath &p_path) {
path = p_path;
first = true;
@ -76,84 +78,87 @@ bool RootMotionView::get_zero_y() const {
}
void RootMotionView::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
immediate_material = StandardMaterial3D::get_material_for_2d(false, true, false, false, false);
first = true;
}
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
immediate_material = StandardMaterial3D::get_material_for_2d(false, true, false, false, false);
first = true;
} break;
if (p_what == NOTIFICATION_INTERNAL_PROCESS || p_what == NOTIFICATION_INTERNAL_PHYSICS_PROCESS) {
Transform3D transform;
case NOTIFICATION_INTERNAL_PROCESS:
case NOTIFICATION_INTERNAL_PHYSICS_PROCESS: {
Transform3D transform;
if (has_node(path)) {
Node *node = get_node(path);
if (has_node(path)) {
Node *node = get_node(path);
AnimationTree *tree = Object::cast_to<AnimationTree>(node);
if (tree && tree->is_active() && tree->get_root_motion_track() != NodePath()) {
if (is_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_PHYSICS) {
set_process_internal(false);
set_physics_process_internal(true);
AnimationTree *tree = Object::cast_to<AnimationTree>(node);
if (tree && tree->is_active() && tree->get_root_motion_track() != NodePath()) {
if (is_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_PHYSICS) {
set_process_internal(false);
set_physics_process_internal(true);
}
if (is_physics_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_IDLE) {
set_process_internal(true);
set_physics_process_internal(false);
}
transform = tree->get_root_motion_transform();
}
}
if (is_physics_processing_internal() && tree->get_process_callback() == AnimationTree::ANIMATION_PROCESS_IDLE) {
set_process_internal(true);
set_physics_process_internal(false);
if (!first && transform == Transform3D()) {
return;
}
first = false;
transform.orthonormalize(); //don't want scale, too imprecise
transform.affine_invert();
accumulated = transform * accumulated;
accumulated.origin.x = Math::fposmod(accumulated.origin.x, cell_size);
if (zero_y) {
accumulated.origin.y = 0;
}
accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size);
immediate->clear_surfaces();
int cells_in_radius = int((radius / cell_size) + 1.0);
immediate->surface_begin(Mesh::PRIMITIVE_LINES, immediate_material);
for (int i = -cells_in_radius; i < cells_in_radius; i++) {
for (int j = -cells_in_radius; j < cells_in_radius; j++) {
Vector3 from(i * cell_size, 0, j * cell_size);
Vector3 from_i((i + 1) * cell_size, 0, j * cell_size);
Vector3 from_j(i * cell_size, 0, (j + 1) * cell_size);
from = accumulated.xform(from);
from_i = accumulated.xform(from_i);
from_j = accumulated.xform(from_j);
Color c = color, c_i = color, c_j = color;
c.a *= MAX(0, 1.0 - from.length() / radius);
c_i.a *= MAX(0, 1.0 - from_i.length() / radius);
c_j.a *= MAX(0, 1.0 - from_j.length() / radius);
immediate->surface_set_color(c);
immediate->surface_add_vertex(from);
immediate->surface_set_color(c_i);
immediate->surface_add_vertex(from_i);
immediate->surface_set_color(c);
immediate->surface_add_vertex(from);
immediate->surface_set_color(c_j);
immediate->surface_add_vertex(from_j);
}
transform = tree->get_root_motion_transform();
}
}
if (!first && transform == Transform3D()) {
return;
}
first = false;
transform.orthonormalize(); //don't want scale, too imprecise
transform.affine_invert();
accumulated = transform * accumulated;
accumulated.origin.x = Math::fposmod(accumulated.origin.x, cell_size);
if (zero_y) {
accumulated.origin.y = 0;
}
accumulated.origin.z = Math::fposmod(accumulated.origin.z, cell_size);
immediate->clear_surfaces();
int cells_in_radius = int((radius / cell_size) + 1.0);
immediate->surface_begin(Mesh::PRIMITIVE_LINES, immediate_material);
for (int i = -cells_in_radius; i < cells_in_radius; i++) {
for (int j = -cells_in_radius; j < cells_in_radius; j++) {
Vector3 from(i * cell_size, 0, j * cell_size);
Vector3 from_i((i + 1) * cell_size, 0, j * cell_size);
Vector3 from_j(i * cell_size, 0, (j + 1) * cell_size);
from = accumulated.xform(from);
from_i = accumulated.xform(from_i);
from_j = accumulated.xform(from_j);
Color c = color, c_i = color, c_j = color;
c.a *= MAX(0, 1.0 - from.length() / radius);
c_i.a *= MAX(0, 1.0 - from_i.length() / radius);
c_j.a *= MAX(0, 1.0 - from_j.length() / radius);
immediate->surface_set_color(c);
immediate->surface_add_vertex(from);
immediate->surface_set_color(c_i);
immediate->surface_add_vertex(from_i);
immediate->surface_set_color(c);
immediate->surface_add_vertex(from);
immediate->surface_set_color(c_j);
immediate->surface_add_vertex(from_j);
}
}
immediate->surface_end();
immediate->surface_end();
} break;
}
}

View File

@ -35,49 +35,51 @@
#include "servers/audio_server.h"
void AudioStreamPlayer::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
}
if (p_what == NOTIFICATION_INTERNAL_PROCESS) {
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (autoplay && !Engine::get_singleton()->is_editor_hint()) {
play();
}
}
// Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
stream_playbacks.erase(playback);
}
if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
// This node is no longer actively playing audio.
active.clear();
set_process_internal(false);
}
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
}
} break;
if (p_what == NOTIFICATION_EXIT_TREE) {
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
AudioServer::get_singleton()->stop_playback_stream(playback);
}
stream_playbacks.clear();
}
case NOTIFICATION_INTERNAL_PROCESS: {
Vector<Ref<AudioStreamPlayback>> playbacks_to_remove;
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
if (playback.is_valid() && !AudioServer::get_singleton()->is_playback_active(playback) && !AudioServer::get_singleton()->is_playback_paused(playback)) {
playbacks_to_remove.push_back(playback);
}
}
// Now go through and remove playbacks that have finished. Removing elements from a Vector in a range based for is asking for trouble.
for (Ref<AudioStreamPlayback> &playback : playbacks_to_remove) {
stream_playbacks.erase(playback);
}
if (!playbacks_to_remove.is_empty() && stream_playbacks.is_empty()) {
// This node is no longer actively playing audio.
active.clear();
set_process_internal(false);
}
if (!playbacks_to_remove.is_empty()) {
emit_signal(SNAME("finished"));
}
} break;
if (p_what == NOTIFICATION_PAUSED) {
if (!can_process()) {
// Node can't process so we start fading out to silence
set_stream_paused(true);
}
}
case NOTIFICATION_EXIT_TREE: {
for (Ref<AudioStreamPlayback> &playback : stream_playbacks) {
AudioServer::get_singleton()->stop_playback_stream(playback);
}
stream_playbacks.clear();
} break;
if (p_what == NOTIFICATION_UNPAUSED) {
set_stream_paused(false);
case NOTIFICATION_PAUSED: {
if (!can_process()) {
// Node can't process so we start fading out to silence
set_stream_paused(true);
}
} break;
case NOTIFICATION_UNPAUSED: {
set_stream_paused(false);
} break;
}
}

View File

@ -81,42 +81,50 @@ void BaseButton::gui_input(const Ref<InputEvent> &p_event) {
}
void BaseButton::_notification(int p_what) {
if (p_what == NOTIFICATION_MOUSE_ENTER) {
status.hovering = true;
update();
}
switch (p_what) {
case NOTIFICATION_MOUSE_ENTER: {
status.hovering = true;
update();
} break;
if (p_what == NOTIFICATION_MOUSE_EXIT) {
status.hovering = false;
update();
}
if (p_what == NOTIFICATION_DRAG_BEGIN || p_what == NOTIFICATION_SCROLL_BEGIN) {
if (status.press_attempt) {
case NOTIFICATION_MOUSE_EXIT: {
status.hovering = false;
update();
} break;
case NOTIFICATION_DRAG_BEGIN:
case NOTIFICATION_SCROLL_BEGIN: {
if (status.press_attempt) {
status.press_attempt = false;
update();
}
} break;
case NOTIFICATION_FOCUS_ENTER: {
update();
} break;
case NOTIFICATION_FOCUS_EXIT: {
if (status.press_attempt) {
status.press_attempt = false;
update();
} else if (status.hovering) {
update();
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED:
case NOTIFICATION_EXIT_TREE: {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED && is_visible_in_tree()) {
break;
}
if (!toggle_mode) {
status.pressed = false;
}
status.hovering = false;
status.press_attempt = false;
update();
}
}
if (p_what == NOTIFICATION_FOCUS_ENTER) {
update();
}
if (p_what == NOTIFICATION_FOCUS_EXIT) {
if (status.press_attempt) {
status.press_attempt = false;
update();
} else if (status.hovering) {
update();
}
}
if (p_what == NOTIFICATION_EXIT_TREE || (p_what == NOTIFICATION_VISIBILITY_CHANGED && !is_visible_in_tree())) {
if (!toggle_mode) {
status.pressed = false;
}
status.hovering = false;
status.press_attempt = false;
status.pressing_inside = false;
status.pressing_inside = false;
} break;
}
}

View File

@ -29,6 +29,7 @@
/*************************************************************************/
#include "box_container.h"
#include "label.h"
#include "margin_container.h"
@ -294,9 +295,11 @@ void BoxContainer::_notification(int p_what) {
case NOTIFICATION_SORT_CHILDREN: {
_resort();
} break;
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
queue_sort();

View File

@ -78,6 +78,7 @@ void Button::_notification(int p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
update();
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
xl_text = atr(text);
_shape();
@ -85,12 +86,14 @@ void Button::_notification(int p_what) {
update_minimum_size();
update();
} break;
case NOTIFICATION_THEME_CHANGED: {
_shape();
update_minimum_size();
update();
} break;
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Size2 size = get_size();

View File

@ -78,21 +78,23 @@ Vector<int> CenterContainer::get_allowed_size_flags_vertical() const {
}
void CenterContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_SORT_CHILDREN) {
Size2 size = get_size();
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
if (!c) {
continue;
}
if (c->is_set_as_top_level()) {
continue;
}
switch (p_what) {
case NOTIFICATION_SORT_CHILDREN: {
Size2 size = get_size();
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
if (!c) {
continue;
}
if (c->is_set_as_top_level()) {
continue;
}
Size2 minsize = c->get_combined_minimum_size();
Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor();
fit_child_in_rect(c, Rect2(ofs, minsize));
}
Size2 minsize = c->get_combined_minimum_size();
Point2 ofs = use_top_left ? (-minsize * 0.5).floor() : ((size - minsize) / 2.0).floor();
fit_child_in_rect(c, Rect2(ofs, minsize));
}
} break;
}
}

View File

@ -84,34 +84,40 @@ Size2 CheckBox::get_minimum_size() const {
}
void CheckBox::_notification(int p_what) {
if ((p_what == NOTIFICATION_THEME_CHANGED) || (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED || (p_what == NOTIFICATION_TRANSLATION_CHANGED))) {
if (is_layout_rtl()) {
_set_internal_margin(SIDE_LEFT, 0.f);
_set_internal_margin(SIDE_RIGHT, get_icon_size().width);
} else {
_set_internal_margin(SIDE_LEFT, get_icon_size().width);
_set_internal_margin(SIDE_RIGHT, 0.f);
}
} else if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item();
switch (p_what) {
case NOTIFICATION_THEME_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
if (is_layout_rtl()) {
_set_internal_margin(SIDE_LEFT, 0.f);
_set_internal_margin(SIDE_RIGHT, get_icon_size().width);
} else {
_set_internal_margin(SIDE_LEFT, get_icon_size().width);
_set_internal_margin(SIDE_RIGHT, 0.f);
}
} break;
Ref<Texture2D> on = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_checked" : "checked", is_disabled() ? "_disabled" : ""));
Ref<Texture2D> off = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_unchecked" : "unchecked", is_disabled() ? "_disabled" : ""));
Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Vector2 ofs;
if (is_layout_rtl()) {
ofs.x = get_size().x - sb->get_margin(SIDE_RIGHT) - get_icon_size().width;
} else {
ofs.x = sb->get_margin(SIDE_LEFT);
}
ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant(SNAME("check_vadjust"));
Ref<Texture2D> on = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_checked" : "checked", is_disabled() ? "_disabled" : ""));
Ref<Texture2D> off = Control::get_theme_icon(vformat("%s%s", is_radio() ? "radio_unchecked" : "unchecked", is_disabled() ? "_disabled" : ""));
Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
if (is_pressed()) {
on->draw(ci, ofs);
} else {
off->draw(ci, ofs);
}
Vector2 ofs;
if (is_layout_rtl()) {
ofs.x = get_size().x - sb->get_margin(SIDE_RIGHT) - get_icon_size().width;
} else {
ofs.x = sb->get_margin(SIDE_LEFT);
}
ofs.y = int((get_size().height - get_icon_size().height) / 2) + get_theme_constant(SNAME("check_vadjust"));
if (is_pressed()) {
on->draw(ci, ofs);
} else {
off->draw(ci, ofs);
}
} break;
}
}

View File

@ -61,47 +61,53 @@ Size2 CheckButton::get_minimum_size() const {
}
void CheckButton::_notification(int p_what) {
if ((p_what == NOTIFICATION_THEME_CHANGED) || (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED) || (p_what == NOTIFICATION_TRANSLATION_CHANGED)) {
if (is_layout_rtl()) {
_set_internal_margin(SIDE_LEFT, get_icon_size().width);
_set_internal_margin(SIDE_RIGHT, 0.f);
} else {
_set_internal_margin(SIDE_LEFT, 0.f);
_set_internal_margin(SIDE_RIGHT, get_icon_size().width);
}
} else if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item();
bool rtl = is_layout_rtl();
switch (p_what) {
case NOTIFICATION_THEME_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
if (is_layout_rtl()) {
_set_internal_margin(SIDE_LEFT, get_icon_size().width);
_set_internal_margin(SIDE_RIGHT, 0.f);
} else {
_set_internal_margin(SIDE_LEFT, 0.f);
_set_internal_margin(SIDE_RIGHT, get_icon_size().width);
}
} break;
Ref<Texture2D> on;
if (rtl) {
on = Control::get_theme_icon(is_disabled() ? "on_disabled_mirrored" : "on_mirrored");
} else {
on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on");
}
Ref<Texture2D> off;
if (rtl) {
off = Control::get_theme_icon(is_disabled() ? "off_disabled_mirrored" : "off_mirrored");
} else {
off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off");
}
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
bool rtl = is_layout_rtl();
Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
Vector2 ofs;
Size2 tex_size = get_icon_size();
Ref<Texture2D> on;
if (rtl) {
on = Control::get_theme_icon(is_disabled() ? "on_disabled_mirrored" : "on_mirrored");
} else {
on = Control::get_theme_icon(is_disabled() ? "on_disabled" : "on");
}
Ref<Texture2D> off;
if (rtl) {
off = Control::get_theme_icon(is_disabled() ? "off_disabled_mirrored" : "off_mirrored");
} else {
off = Control::get_theme_icon(is_disabled() ? "off_disabled" : "off");
}
if (rtl) {
ofs.x = sb->get_margin(SIDE_LEFT);
} else {
ofs.x = get_size().width - (tex_size.width + sb->get_margin(SIDE_RIGHT));
}
ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant(SNAME("check_vadjust"));
Ref<StyleBox> sb = get_theme_stylebox(SNAME("normal"));
Vector2 ofs;
Size2 tex_size = get_icon_size();
if (is_pressed()) {
on->draw(ci, ofs);
} else {
off->draw(ci, ofs);
}
if (rtl) {
ofs.x = sb->get_margin(SIDE_LEFT);
} else {
ofs.x = get_size().width - (tex_size.width + sb->get_margin(SIDE_RIGHT));
}
ofs.y = (get_size().height - tex_size.height) / 2 + get_theme_constant(SNAME("check_vadjust"));
if (is_pressed()) {
on->draw(ci, ofs);
} else {
off->draw(ci, ofs);
}
} break;
}
}

View File

@ -74,6 +74,7 @@ void CodeEdit::_notification(int p_what) {
line_length_guideline_color = get_theme_color(SNAME("line_length_guideline_color"));
} break;
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
const Size2 size = get_size();

View File

@ -33,11 +33,11 @@
#include "core/input/input.h"
#include "core/os/keyboard.h"
#include "core/os/os.h"
#include "scene/main/window.h"
#ifdef TOOLS_ENABLED
#include "editor/editor_settings.h"
#endif
#include "scene/main/window.h"
List<Color> ColorPicker::preset_cache;
@ -45,7 +45,6 @@ void ColorPicker::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
_update_color();
#ifdef TOOLS_ENABLED
if (Engine::get_singleton()->is_editor_hint()) {
if (preset_cache.is_empty()) {
@ -1347,17 +1346,18 @@ void ColorPickerButton::_notification(int p_what) {
draw_texture(Control::get_theme_icon(SNAME("overbright_indicator"), SNAME("ColorPicker")), normal->get_offset());
}
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
if (popup) {
popup->hide();
}
} break;
}
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (popup && !is_visible_in_tree()) {
popup->hide();
}
case NOTIFICATION_VISIBILITY_CHANGED: {
if (popup && !is_visible_in_tree()) {
popup->hide();
}
} break;
}
}

View File

@ -40,8 +40,10 @@ Color ColorRect::get_color() const {
}
void ColorRect::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
draw_rect(Rect2(Point2(), get_size()), color);
switch (p_what) {
case NOTIFICATION_DRAW: {
draw_rect(Rect2(Point2(), get_size()), color);
} break;
}
}

View File

@ -29,6 +29,7 @@
/*************************************************************************/
#include "container.h"
#include "core/object/message_queue.h"
#include "scene/scene_string_names.h"
@ -177,12 +178,12 @@ void Container::_notification(int p_what) {
pending_sort = false;
queue_sort();
} break;
case NOTIFICATION_RESIZED: {
queue_sort();
} break;
case NOTIFICATION_RESIZED:
case NOTIFICATION_THEME_CHANGED: {
queue_sort();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (is_visible_in_tree()) {
queue_sort();

View File

@ -691,17 +691,17 @@ void Control::_update_canvas_item_transform() {
void Control::_notification(int p_notification) {
switch (p_notification) {
case NOTIFICATION_ENTER_TREE: {
} break;
case NOTIFICATION_POST_ENTER_TREE: {
data.minimum_size_valid = false;
data.is_rtl_dirty = true;
_size_changed();
} break;
case NOTIFICATION_EXIT_TREE: {
release_focus();
get_viewport()->_gui_remove_control(this);
} break;
case NOTIFICATION_READY: {
#ifdef DEBUG_ENABLED
connect("ready", callable_mp(this, &Control::_clear_size_warning), varray(), CONNECT_DEFERRED | CONNECT_ONESHOT);
@ -764,6 +764,7 @@ void Control::_notification(int p_notification) {
viewport->connect("size_changed", callable_mp(this, &Control::_size_changed));
}
} break;
case NOTIFICATION_EXIT_CANVAS: {
if (data.parent_canvas_item) {
data.parent_canvas_item->disconnect("item_rect_changed", callable_mp(this, &Control::_size_changed));
@ -784,8 +785,8 @@ void Control::_notification(int p_notification) {
data.parent_canvas_item = nullptr;
data.parent_window = nullptr;
data.is_rtl_dirty = true;
} break;
case NOTIFICATION_MOVED_IN_PARENT: {
// some parents need to know the order of the children to draw (like TabContainer)
// update if necessary
@ -797,50 +798,52 @@ void Control::_notification(int p_notification) {
if (data.RI) {
get_viewport()->_gui_set_root_order_dirty();
}
} break;
case NOTIFICATION_RESIZED: {
emit_signal(SceneStringNames::get_singleton()->resized);
} break;
case NOTIFICATION_DRAW: {
_update_canvas_item_transform();
RenderingServer::get_singleton()->canvas_item_set_custom_rect(get_canvas_item(), !data.disable_visibility_clip, Rect2(Point2(), get_size()));
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), data.clip_contents);
//emit_signal(SceneStringNames::get_singleton()->draw);
} break;
case NOTIFICATION_MOUSE_ENTER: {
emit_signal(SceneStringNames::get_singleton()->mouse_entered);
} break;
case NOTIFICATION_MOUSE_EXIT: {
emit_signal(SceneStringNames::get_singleton()->mouse_exited);
} break;
case NOTIFICATION_FOCUS_ENTER: {
emit_signal(SceneStringNames::get_singleton()->focus_entered);
update();
} break;
case NOTIFICATION_FOCUS_EXIT: {
emit_signal(SceneStringNames::get_singleton()->focus_exited);
update();
} break;
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
update();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
if (get_viewport() != nullptr) {
get_viewport()->_gui_hide_control(this);
}
//remove key focus
} else {
data.minimum_size_valid = false;
_size_changed();
}
} break;
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
if (is_inside_tree()) {

View File

@ -67,21 +67,25 @@ void AcceptDialog::_notification(int p_what) {
}
}
} break;
case NOTIFICATION_THEME_CHANGED: {
bg->add_theme_style_override("panel", bg->get_theme_stylebox(SNAME("panel"), SNAME("AcceptDialog")));
} break;
case NOTIFICATION_EXIT_TREE: {
if (parent_visible) {
parent_visible->disconnect("focus_entered", callable_mp(this, &AcceptDialog::_parent_focused));
parent_visible = nullptr;
}
} break;
case NOTIFICATION_READY:
case NOTIFICATION_WM_SIZE_CHANGED: {
if (is_visible()) {
_update_child_rects();
}
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
_cancel_pressed();
} break;

View File

@ -92,26 +92,30 @@ void FileDialog::_theme_changed() {
}
void FileDialog::_notification(int p_what) {
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (!is_visible()) {
set_process_unhandled_input(false);
}
}
if (p_what == NOTIFICATION_ENTER_TREE) {
dir_up->set_icon(vbox->get_theme_icon(SNAME("parent_folder"), SNAME("FileDialog")));
if (vbox->is_layout_rtl()) {
dir_prev->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
dir_next->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
} else {
dir_prev->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
dir_next->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
}
refresh->set_icon(vbox->get_theme_icon(SNAME("reload"), SNAME("FileDialog")));
show_hidden->set_icon(vbox->get_theme_icon(SNAME("toggle_hidden"), SNAME("FileDialog")));
_theme_changed();
}
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
update_filters();
switch (p_what) {
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible()) {
set_process_unhandled_input(false);
}
} break;
case NOTIFICATION_ENTER_TREE: {
dir_up->set_icon(vbox->get_theme_icon(SNAME("parent_folder"), SNAME("FileDialog")));
if (vbox->is_layout_rtl()) {
dir_prev->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
dir_next->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
} else {
dir_prev->set_icon(vbox->get_theme_icon(SNAME("back_folder"), SNAME("FileDialog")));
dir_next->set_icon(vbox->get_theme_icon(SNAME("forward_folder"), SNAME("FileDialog")));
}
refresh->set_icon(vbox->get_theme_icon(SNAME("reload"), SNAME("FileDialog")));
show_hidden->set_icon(vbox->get_theme_icon(SNAME("toggle_hidden"), SNAME("FileDialog")));
_theme_changed();
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
update_filters();
} break;
}
}

View File

@ -251,9 +251,11 @@ void FlowContainer::_notification(int p_what) {
_resort();
update_minimum_size();
} break;
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
queue_sort();

View File

@ -287,84 +287,85 @@ void GradientEdit::gui_input(const Ref<InputEvent> &p_event) {
}
void GradientEdit::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE) {
if (!picker->is_connected("color_changed", callable_mp(this, &GradientEdit::_color_changed))) {
picker->connect("color_changed", callable_mp(this, &GradientEdit::_color_changed));
}
}
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
draw_spacing = BASE_SPACING * get_theme_default_base_scale();
draw_point_width = BASE_POINT_WIDTH * get_theme_default_base_scale();
}
if (p_what == NOTIFICATION_DRAW) {
int w = get_size().x;
int h = get_size().y;
if (w == 0 || h == 0) {
return; // Safety check. We have division by 'h'. And in any case there is nothing to draw with such size.
}
int total_w = get_size().width - get_size().height - draw_spacing;
// Draw checker pattern for ramp.
draw_texture_rect(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")), Rect2(0, 0, total_w, h), true);
// Draw color ramp.
gradient_cache->set_points(points);
gradient_cache->set_interpolation_mode(interpolation_mode);
preview_texture->set_gradient(gradient_cache);
draw_texture_rect(preview_texture, Rect2(0, 0, total_w, h));
// Draw point markers.
for (int i = 0; i < points.size(); i++) {
Color col = points[i].color.inverted();
col.a = 0.9;
draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col);
Rect2 rect = Rect2(points[i].offset * total_w - draw_point_width / 2, h / 2, draw_point_width, h / 2);
draw_rect(rect, points[i].color, true);
draw_rect(rect, col, false);
if (grabbed == i) {
rect = rect.grow(-1);
if (has_focus()) {
draw_rect(rect, Color(1, 0, 0, 0.9), false);
} else {
draw_rect(rect, Color(0.6, 0, 0, 0.9), false);
}
rect = rect.grow(-1);
draw_rect(rect, col, false);
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
if (!picker->is_connected("color_changed", callable_mp(this, &GradientEdit::_color_changed))) {
picker->connect("color_changed", callable_mp(this, &GradientEdit::_color_changed));
}
[[fallthrough]];
}
case NOTIFICATION_THEME_CHANGED: {
draw_spacing = BASE_SPACING * get_theme_default_base_scale();
draw_point_width = BASE_POINT_WIDTH * get_theme_default_base_scale();
} break;
//Draw "button" for color selector
draw_texture_rect(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")), Rect2(total_w + draw_spacing, 0, h, h), true);
if (grabbed != -1) {
//Draw with selection color
draw_rect(Rect2(total_w + draw_spacing, 0, h, h), points[grabbed].color);
} else {
//if no color selected draw grey color with 'X' on top.
draw_rect(Rect2(total_w + draw_spacing, 0, h, h), Color(0.5, 0.5, 0.5, 1));
draw_line(Vector2(total_w + draw_spacing, 0), Vector2(total_w + draw_spacing + h, h), Color(1, 1, 1, 0.6));
draw_line(Vector2(total_w + draw_spacing, h), Vector2(total_w + draw_spacing + h, 0), Color(1, 1, 1, 0.6));
}
case NOTIFICATION_DRAW: {
int w = get_size().x;
int h = get_size().y;
// Draw borders around color ramp if in focus.
if (has_focus()) {
draw_line(Vector2(-1, -1), Vector2(total_w + 1, -1), Color(1, 1, 1, 0.6));
draw_line(Vector2(total_w + 1, -1), Vector2(total_w + 1, h + 1), Color(1, 1, 1, 0.6));
draw_line(Vector2(total_w + 1, h + 1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
draw_line(Vector2(-1, -1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
}
}
if (w == 0 || h == 0) {
return; // Safety check. We have division by 'h'. And in any case there is nothing to draw with such size.
}
if (p_what == NOTIFICATION_VISIBILITY_CHANGED) {
if (!is_visible()) {
grabbing = false;
}
int total_w = get_size().width - get_size().height - draw_spacing;
// Draw checker pattern for ramp.
draw_texture_rect(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")), Rect2(0, 0, total_w, h), true);
// Draw color ramp.
gradient_cache->set_points(points);
gradient_cache->set_interpolation_mode(interpolation_mode);
preview_texture->set_gradient(gradient_cache);
draw_texture_rect(preview_texture, Rect2(0, 0, total_w, h));
// Draw point markers.
for (int i = 0; i < points.size(); i++) {
Color col = points[i].color.inverted();
col.a = 0.9;
draw_line(Vector2(points[i].offset * total_w, 0), Vector2(points[i].offset * total_w, h / 2), col);
Rect2 rect = Rect2(points[i].offset * total_w - draw_point_width / 2, h / 2, draw_point_width, h / 2);
draw_rect(rect, points[i].color, true);
draw_rect(rect, col, false);
if (grabbed == i) {
rect = rect.grow(-1);
if (has_focus()) {
draw_rect(rect, Color(1, 0, 0, 0.9), false);
} else {
draw_rect(rect, Color(0.6, 0, 0, 0.9), false);
}
rect = rect.grow(-1);
draw_rect(rect, col, false);
}
}
// Draw "button" for color selector.
draw_texture_rect(get_theme_icon(SNAME("GuiMiniCheckerboard"), SNAME("EditorIcons")), Rect2(total_w + draw_spacing, 0, h, h), true);
if (grabbed != -1) {
// Draw with selection color.
draw_rect(Rect2(total_w + draw_spacing, 0, h, h), points[grabbed].color);
} else {
// If no color selected draw grey color with 'X' on top.
draw_rect(Rect2(total_w + draw_spacing, 0, h, h), Color(0.5, 0.5, 0.5, 1));
draw_line(Vector2(total_w + draw_spacing, 0), Vector2(total_w + draw_spacing + h, h), Color(1, 1, 1, 0.6));
draw_line(Vector2(total_w + draw_spacing, h), Vector2(total_w + draw_spacing + h, 0), Color(1, 1, 1, 0.6));
}
// Draw borders around color ramp if in focus.
if (has_focus()) {
draw_line(Vector2(-1, -1), Vector2(total_w + 1, -1), Color(1, 1, 1, 0.6));
draw_line(Vector2(total_w + 1, -1), Vector2(total_w + 1, h + 1), Color(1, 1, 1, 0.6));
draw_line(Vector2(total_w + 1, h + 1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
draw_line(Vector2(-1, -1), Vector2(-1, h + 1), Color(1, 1, 1, 0.6));
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible()) {
grabbing = false;
}
} break;
}
}

View File

@ -423,82 +423,86 @@ void GraphEdit::remove_child_notify(Node *p_child) {
}
void GraphEdit::_notification(int p_what) {
if (p_what == NOTIFICATION_ENTER_TREE || p_what == NOTIFICATION_THEME_CHANGED) {
port_grab_distance_horizontal = get_theme_constant(SNAME("port_grab_distance_horizontal"));
port_grab_distance_vertical = get_theme_constant(SNAME("port_grab_distance_vertical"));
switch (p_what) {
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_THEME_CHANGED: {
port_grab_distance_horizontal = get_theme_constant(SNAME("port_grab_distance_horizontal"));
port_grab_distance_vertical = get_theme_constant(SNAME("port_grab_distance_vertical"));
zoom_minus->set_icon(get_theme_icon(SNAME("minus")));
zoom_reset->set_icon(get_theme_icon(SNAME("reset")));
zoom_plus->set_icon(get_theme_icon(SNAME("more")));
snap_button->set_icon(get_theme_icon(SNAME("snap")));
minimap_button->set_icon(get_theme_icon(SNAME("minimap")));
layout_button->set_icon(get_theme_icon(SNAME("layout")));
zoom_minus->set_icon(get_theme_icon(SNAME("minus")));
zoom_reset->set_icon(get_theme_icon(SNAME("reset")));
zoom_plus->set_icon(get_theme_icon(SNAME("more")));
snap_button->set_icon(get_theme_icon(SNAME("snap")));
minimap_button->set_icon(get_theme_icon(SNAME("minimap")));
layout_button->set_icon(get_theme_icon(SNAME("layout")));
zoom_label->set_custom_minimum_size(Size2(48, 0) * get_theme_default_base_scale());
}
if (p_what == NOTIFICATION_READY) {
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
zoom_label->set_custom_minimum_size(Size2(48, 0) * get_theme_default_base_scale());
} break;
h_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, 0);
h_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
h_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -hmin.height);
h_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
case NOTIFICATION_READY: {
Size2 hmin = h_scroll->get_combined_minimum_size();
Size2 vmin = v_scroll->get_combined_minimum_size();
v_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -vmin.width);
v_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
v_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);
v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
}
if (p_what == NOTIFICATION_DRAW) {
draw_style_box(get_theme_stylebox(SNAME("bg")), Rect2(Point2(), get_size()));
h_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_BEGIN, 0);
h_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
h_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_END, -hmin.height);
h_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
if (is_using_snap()) {
//draw grid
v_scroll->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -vmin.width);
v_scroll->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
v_scroll->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, 0);
v_scroll->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, 0);
} break;
int snap = get_snap();
case NOTIFICATION_DRAW: {
draw_style_box(get_theme_stylebox(SNAME("bg")), Rect2(Point2(), get_size()));
Vector2 offset = get_scroll_ofs() / zoom;
Size2 size = get_size() / zoom;
if (is_using_snap()) {
// Draw grid.
int snap = get_snap();
Point2i from = (offset / float(snap)).floor();
Point2i len = (size / float(snap)).floor() + Vector2(1, 1);
Vector2 offset = get_scroll_ofs() / zoom;
Size2 size = get_size() / zoom;
Color grid_minor = get_theme_color(SNAME("grid_minor"));
Color grid_major = get_theme_color(SNAME("grid_major"));
Point2i from = (offset / float(snap)).floor();
Point2i len = (size / float(snap)).floor() + Vector2(1, 1);
for (int i = from.x; i < from.x + len.x; i++) {
Color color;
Color grid_minor = get_theme_color(SNAME("grid_minor"));
Color grid_major = get_theme_color(SNAME("grid_major"));
if (ABS(i) % 10 == 0) {
color = grid_major;
} else {
color = grid_minor;
for (int i = from.x; i < from.x + len.x; i++) {
Color color;
if (ABS(i) % 10 == 0) {
color = grid_major;
} else {
color = grid_minor;
}
float base_ofs = i * snap * zoom - offset.x * zoom;
draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color);
}
float base_ofs = i * snap * zoom - offset.x * zoom;
draw_line(Vector2(base_ofs, 0), Vector2(base_ofs, get_size().height), color);
}
for (int i = from.y; i < from.y + len.y; i++) {
Color color;
for (int i = from.y; i < from.y + len.y; i++) {
Color color;
if (ABS(i) % 10 == 0) {
color = grid_major;
} else {
color = grid_minor;
}
if (ABS(i) % 10 == 0) {
color = grid_major;
} else {
color = grid_minor;
float base_ofs = i * snap * zoom - offset.y * zoom;
draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color);
}
float base_ofs = i * snap * zoom - offset.y * zoom;
draw_line(Vector2(0, base_ofs), Vector2(get_size().width, base_ofs), color);
}
}
}
} break;
if (p_what == NOTIFICATION_RESIZED) {
_update_scroll();
top_layer->update();
minimap->update();
case NOTIFICATION_RESIZED: {
_update_scroll();
top_layer->update();
minimap->update();
} break;
}
}

View File

@ -31,6 +31,7 @@
#include "graph_node.h"
#include "core/string/translation.h"
#ifdef TOOLS_ENABLED
#include "graph_edit.h"
#endif

View File

@ -179,11 +179,12 @@ void GridContainer::_notification(int p_what) {
col_ofs += s.width + hsep;
}
}
} break;
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
queue_sort();

View File

@ -855,445 +855,449 @@ static Rect2 _adjust_to_max_size(Size2 p_size, Size2 p_max_size) {
}
void ItemList::_notification(int p_what) {
if (p_what == NOTIFICATION_RESIZED) {
shape_changed = true;
update();
}
switch (p_what) {
case NOTIFICATION_RESIZED: {
shape_changed = true;
update();
} break;
if ((p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED) || (p_what == NOTIFICATION_TRANSLATION_CHANGED) || (p_what == NOTIFICATION_THEME_CHANGED)) {
for (int i = 0; i < items.size(); i++) {
_shape(i);
}
shape_changed = true;
update();
}
if (p_what == NOTIFICATION_DRAW) {
Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
int mw = scroll_bar->get_minimum_size().x;
scroll_bar->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -mw);
scroll_bar->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
scroll_bar->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, bg->get_margin(SIDE_TOP));
scroll_bar->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -bg->get_margin(SIDE_BOTTOM));
Size2 size = get_size();
int width = size.width - bg->get_minimum_size().width;
if (scroll_bar->is_visible()) {
width -= mw;
}
draw_style_box(bg, Rect2(Point2(), size));
int hseparation = get_theme_constant(SNAME("hseparation"));
int vseparation = get_theme_constant(SNAME("vseparation"));
int icon_margin = get_theme_constant(SNAME("icon_margin"));
int line_separation = get_theme_constant(SNAME("line_separation"));
Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
int outline_size = get_theme_constant(SNAME("outline_size"));
Ref<StyleBox> sbsel = has_focus() ? get_theme_stylebox(SNAME("selected_focus")) : get_theme_stylebox(SNAME("selected"));
Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox(SNAME("cursor")) : get_theme_stylebox(SNAME("cursor_unfocused"));
bool rtl = is_layout_rtl();
Color guide_color = get_theme_color(SNAME("guide_color"));
Color font_color = get_theme_color(SNAME("font_color"));
Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
if (has_focus()) {
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true);
draw_style_box(get_theme_stylebox(SNAME("bg_focus")), Rect2(Point2(), size));
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false);
}
if (shape_changed) {
float max_column_width = 0.0;
//1- compute item minimum sizes
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
for (int i = 0; i < items.size(); i++) {
Size2 minsize;
if (items[i].icon.is_valid()) {
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
minsize = fixed_icon_size * icon_scale;
} else {
minsize = items[i].get_icon_size() * icon_scale;
_shape(i);
}
shape_changed = true;
update();
} break;
case NOTIFICATION_DRAW: {
Ref<StyleBox> bg = get_theme_stylebox(SNAME("bg"));
int mw = scroll_bar->get_minimum_size().x;
scroll_bar->set_anchor_and_offset(SIDE_LEFT, ANCHOR_END, -mw);
scroll_bar->set_anchor_and_offset(SIDE_RIGHT, ANCHOR_END, 0);
scroll_bar->set_anchor_and_offset(SIDE_TOP, ANCHOR_BEGIN, bg->get_margin(SIDE_TOP));
scroll_bar->set_anchor_and_offset(SIDE_BOTTOM, ANCHOR_END, -bg->get_margin(SIDE_BOTTOM));
Size2 size = get_size();
int width = size.width - bg->get_minimum_size().width;
if (scroll_bar->is_visible()) {
width -= mw;
}
draw_style_box(bg, Rect2(Point2(), size));
int hseparation = get_theme_constant(SNAME("hseparation"));
int vseparation = get_theme_constant(SNAME("vseparation"));
int icon_margin = get_theme_constant(SNAME("icon_margin"));
int line_separation = get_theme_constant(SNAME("line_separation"));
Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
int outline_size = get_theme_constant(SNAME("outline_size"));
Ref<StyleBox> sbsel = has_focus() ? get_theme_stylebox(SNAME("selected_focus")) : get_theme_stylebox(SNAME("selected"));
Ref<StyleBox> cursor = has_focus() ? get_theme_stylebox(SNAME("cursor")) : get_theme_stylebox(SNAME("cursor_unfocused"));
bool rtl = is_layout_rtl();
Color guide_color = get_theme_color(SNAME("guide_color"));
Color font_color = get_theme_color(SNAME("font_color"));
Color font_selected_color = get_theme_color(SNAME("font_selected_color"));
if (has_focus()) {
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), true);
draw_style_box(get_theme_stylebox(SNAME("bg_focus")), Rect2(Point2(), size));
RenderingServer::get_singleton()->canvas_item_add_clip_ignore(get_canvas_item(), false);
}
if (shape_changed) {
float max_column_width = 0.0;
//1- compute item minimum sizes
for (int i = 0; i < items.size(); i++) {
Size2 minsize;
if (items[i].icon.is_valid()) {
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
minsize = fixed_icon_size * icon_scale;
} else {
minsize = items[i].get_icon_size() * icon_scale;
}
if (!items[i].text.is_empty()) {
if (icon_mode == ICON_MODE_TOP) {
minsize.y += icon_margin;
} else {
minsize.x += icon_margin;
}
}
}
if (!items[i].text.is_empty()) {
int max_width = -1;
if (fixed_column_width) {
max_width = fixed_column_width;
} else if (same_column_width) {
max_width = items[i].rect_cache.size.x;
}
items.write[i].text_buf->set_width(max_width);
Size2 s = items[i].text_buf->get_size();
if (icon_mode == ICON_MODE_TOP) {
minsize.y += icon_margin;
minsize.x = MAX(minsize.x, s.width);
if (max_text_lines > 0) {
minsize.y += s.height + line_separation * max_text_lines;
} else {
minsize.y += s.height;
}
} else {
minsize.x += icon_margin;
minsize.y = MAX(minsize.y, s.height);
minsize.x += s.width;
}
}
if (fixed_column_width > 0) {
minsize.x = fixed_column_width;
}
max_column_width = MAX(max_column_width, minsize.x);
// elements need to adapt to the selected size
minsize.y += vseparation;
minsize.x += hseparation;
items.write[i].rect_cache.size = minsize;
items.write[i].min_rect_cache.size = minsize;
}
int fit_size = size.x - bg->get_minimum_size().width - mw;
//2-attempt best fit
current_columns = 0x7FFFFFFF;
if (max_columns > 0) {
current_columns = max_columns;
}
while (true) {
//repeat until all fits
bool all_fit = true;
Vector2 ofs;
int col = 0;
int max_h = 0;
separators.clear();
for (int i = 0; i < items.size(); i++) {
if (current_columns > 1 && items[i].rect_cache.size.width + ofs.x > fit_size) {
//went past
current_columns = MAX(col, 1);
all_fit = false;
break;
}
if (same_column_width) {
items.write[i].rect_cache.size.x = max_column_width;
}
items.write[i].rect_cache.position = ofs;
max_h = MAX(max_h, items[i].rect_cache.size.y);
ofs.x += items[i].rect_cache.size.x + hseparation;
col++;
if (col == current_columns) {
if (i < items.size() - 1) {
separators.push_back(ofs.y + max_h + vseparation / 2);
}
for (int j = i; j >= 0 && col > 0; j--, col--) {
items.write[j].rect_cache.size.y = max_h;
}
ofs.x = 0;
ofs.y += max_h + vseparation;
col = 0;
max_h = 0;
}
}
for (int j = items.size() - 1; j >= 0 && col > 0; j--, col--) {
items.write[j].rect_cache.size.y = max_h;
}
if (all_fit) {
float page = MAX(0, size.height - bg->get_minimum_size().height);
float max = MAX(page, ofs.y + max_h);
if (auto_height) {
auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
}
scroll_bar->set_max(max);
scroll_bar->set_page(page);
if (max <= page) {
scroll_bar->set_value(0);
scroll_bar->hide();
} else {
scroll_bar->show();
if (do_autoscroll_to_bottom) {
scroll_bar->set_value(max);
}
}
break;
}
}
update_minimum_size();
shape_changed = false;
}
//ensure_selected_visible needs to be checked before we draw the list.
if (ensure_selected_visible && current >= 0 && current < items.size()) {
Rect2 r = items[current].rect_cache;
int from = scroll_bar->get_value();
int to = from + scroll_bar->get_page();
if (r.position.y < from) {
scroll_bar->set_value(r.position.y);
} else if (r.position.y + r.size.y > to) {
scroll_bar->set_value(r.position.y + r.size.y - (to - from));
}
}
ensure_selected_visible = false;
Vector2 base_ofs = bg->get_offset();
base_ofs.y -= int(scroll_bar->get_value());
const Rect2 clip(-base_ofs, size); // visible frame, don't need to draw outside of there
int first_item_visible;
{
// do a binary search to find the first item whose rect reaches below clip.position.y
int lo = 0;
int hi = items.size();
while (lo < hi) {
const int mid = (lo + hi) / 2;
const Rect2 &rcache = items[mid].rect_cache;
if (rcache.position.y + rcache.size.y < clip.position.y) {
lo = mid + 1;
} else {
hi = mid;
}
}
// we might have ended up with column 2, or 3, ..., so let's find the first column
while (lo > 0 && items[lo - 1].rect_cache.position.y == items[lo].rect_cache.position.y) {
lo -= 1;
}
first_item_visible = lo;
}
for (int i = first_item_visible; i < items.size(); i++) {
Rect2 rcache = items[i].rect_cache;
if (rcache.position.y > clip.position.y + clip.size.y) {
break; // done
}
if (!clip.intersects(rcache)) {
continue;
}
if (current_columns == 1) {
rcache.size.width = width - rcache.position.x;
}
if (items[i].selected) {
Rect2 r = rcache;
r.position += base_ofs;
r.position.y -= vseparation / 2;
r.size.y += vseparation;
r.position.x -= hseparation / 2;
r.size.x += hseparation;
if (rtl) {
r.position.x = size.width - r.position.x - r.size.x;
}
draw_style_box(sbsel, r);
}
if (items[i].custom_bg.a > 0.001) {
Rect2 r = rcache;
r.position += base_ofs;
// Size rect to make the align the temperature colors
r.position.y -= vseparation / 2;
r.size.y += vseparation;
r.position.x -= hseparation / 2;
r.size.x += hseparation;
if (rtl) {
r.position.x = size.width - r.position.x - r.size.x;
}
draw_rect(r, items[i].custom_bg);
}
Vector2 text_ofs;
if (items[i].icon.is_valid()) {
Size2 icon_size;
//= _adjust_to_max_size(items[i].get_icon_size(),fixed_icon_size) * icon_scale;
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
icon_size = fixed_icon_size * icon_scale;
} else {
icon_size = items[i].get_icon_size() * icon_scale;
}
Vector2 icon_ofs;
Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs;
if (icon_mode == ICON_MODE_TOP) {
pos.x += Math::floor((items[i].rect_cache.size.width - icon_size.width) / 2);
pos.y += icon_margin;
text_ofs.y = icon_size.height + icon_margin * 2;
} else {
pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2);
text_ofs.x = icon_size.width + icon_margin;
}
Rect2 draw_rect = Rect2(pos, icon_size);
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale, icon_size);
draw_rect.position += adj.position;
draw_rect.size = adj.size;
}
Color modulate = items[i].icon_modulate;
if (items[i].disabled) {
modulate.a *= 0.5;
}
// If the icon is transposed, we have to switch the size so that it is drawn correctly
if (items[i].icon_transposed) {
Size2 size_tmp = draw_rect.size;
draw_rect.size.x = size_tmp.y;
draw_rect.size.y = size_tmp.x;
}
Rect2 region = (items[i].icon_region.size.x == 0 || items[i].icon_region.size.y == 0) ? Rect2(Vector2(), items[i].icon->get_size()) : Rect2(items[i].icon_region);
if (rtl) {
draw_rect.position.x = size.width - draw_rect.position.x - draw_rect.size.x;
}
draw_texture_rect_region(items[i].icon, draw_rect, region, modulate, items[i].icon_transposed);
}
if (items[i].tag_icon.is_valid()) {
Point2 draw_pos = items[i].rect_cache.position;
if (rtl) {
draw_pos.x = size.width - draw_pos.x - items[i].tag_icon->get_width();
}
draw_texture(items[i].tag_icon, draw_pos + base_ofs);
}
if (!items[i].text.is_empty()) {
int max_width = -1;
int max_len = -1;
Vector2 size2 = items[i].text_buf->get_size();
if (fixed_column_width) {
max_width = fixed_column_width;
max_len = fixed_column_width;
} else if (same_column_width) {
max_width = items[i].rect_cache.size.x;
max_len = items[i].rect_cache.size.x;
} else {
max_len = size2.x;
}
items.write[i].text_buf->set_width(max_width);
Size2 s = items[i].text_buf->get_size();
if (icon_mode == ICON_MODE_TOP) {
minsize.x = MAX(minsize.x, s.width);
if (max_text_lines > 0) {
minsize.y += s.height + line_separation * max_text_lines;
Color modulate = items[i].selected ? font_selected_color : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color);
if (items[i].disabled) {
modulate.a *= 0.5;
}
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
text_ofs += base_ofs;
text_ofs += items[i].rect_cache.position;
if (rtl) {
text_ofs.x = size.width - text_ofs.x - max_len;
}
items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_CENTER);
if (outline_size > 0 && font_outline_color.a > 0) {
items[i].text_buf->draw_outline(get_canvas_item(), text_ofs, outline_size, font_outline_color);
}
items[i].text_buf->draw(get_canvas_item(), text_ofs, modulate);
} else {
if (fixed_column_width > 0) {
size2.x = MIN(size2.x, fixed_column_width);
}
if (icon_mode == ICON_MODE_TOP) {
text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2;
} else {
minsize.y += s.height;
text_ofs.y += (items[i].rect_cache.size.height - size2.y) / 2;
}
} else {
minsize.y = MAX(minsize.y, s.height);
minsize.x += s.width;
}
}
text_ofs += base_ofs;
text_ofs += items[i].rect_cache.position;
if (fixed_column_width > 0) {
minsize.x = fixed_column_width;
}
max_column_width = MAX(max_column_width, minsize.x);
// elements need to adapt to the selected size
minsize.y += vseparation;
minsize.x += hseparation;
items.write[i].rect_cache.size = minsize;
items.write[i].min_rect_cache.size = minsize;
}
int fit_size = size.x - bg->get_minimum_size().width - mw;
//2-attempt best fit
current_columns = 0x7FFFFFFF;
if (max_columns > 0) {
current_columns = max_columns;
}
while (true) {
//repeat until all fits
bool all_fit = true;
Vector2 ofs;
int col = 0;
int max_h = 0;
separators.clear();
for (int i = 0; i < items.size(); i++) {
if (current_columns > 1 && items[i].rect_cache.size.width + ofs.x > fit_size) {
//went past
current_columns = MAX(col, 1);
all_fit = false;
break;
}
if (same_column_width) {
items.write[i].rect_cache.size.x = max_column_width;
}
items.write[i].rect_cache.position = ofs;
max_h = MAX(max_h, items[i].rect_cache.size.y);
ofs.x += items[i].rect_cache.size.x + hseparation;
col++;
if (col == current_columns) {
if (i < items.size() - 1) {
separators.push_back(ofs.y + max_h + vseparation / 2);
if (rtl) {
text_ofs.x = size.width - text_ofs.x - max_len;
}
for (int j = i; j >= 0 && col > 0; j--, col--) {
items.write[j].rect_cache.size.y = max_h;
items.write[i].text_buf->set_width(max_len);
if (rtl) {
items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
} else {
items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_LEFT);
}
ofs.x = 0;
ofs.y += max_h + vseparation;
col = 0;
max_h = 0;
}
}
for (int j = items.size() - 1; j >= 0 && col > 0; j--, col--) {
items.write[j].rect_cache.size.y = max_h;
}
if (all_fit) {
float page = MAX(0, size.height - bg->get_minimum_size().height);
float max = MAX(page, ofs.y + max_h);
if (auto_height) {
auto_height_value = ofs.y + max_h + bg->get_minimum_size().height;
}
scroll_bar->set_max(max);
scroll_bar->set_page(page);
if (max <= page) {
scroll_bar->set_value(0);
scroll_bar->hide();
} else {
scroll_bar->show();
if (do_autoscroll_to_bottom) {
scroll_bar->set_value(max);
if (outline_size > 0 && font_outline_color.a > 0) {
items[i].text_buf->draw_outline(get_canvas_item(), text_ofs, outline_size, font_outline_color);
}
items[i].text_buf->draw(get_canvas_item(), text_ofs, modulate);
}
break;
}
}
update_minimum_size();
shape_changed = false;
}
//ensure_selected_visible needs to be checked before we draw the list.
if (ensure_selected_visible && current >= 0 && current < items.size()) {
Rect2 r = items[current].rect_cache;
int from = scroll_bar->get_value();
int to = from + scroll_bar->get_page();
if (r.position.y < from) {
scroll_bar->set_value(r.position.y);
} else if (r.position.y + r.size.y > to) {
scroll_bar->set_value(r.position.y + r.size.y - (to - from));
}
}
ensure_selected_visible = false;
Vector2 base_ofs = bg->get_offset();
base_ofs.y -= int(scroll_bar->get_value());
const Rect2 clip(-base_ofs, size); // visible frame, don't need to draw outside of there
int first_item_visible;
{
// do a binary search to find the first item whose rect reaches below clip.position.y
int lo = 0;
int hi = items.size();
while (lo < hi) {
const int mid = (lo + hi) / 2;
const Rect2 &rcache = items[mid].rect_cache;
if (rcache.position.y + rcache.size.y < clip.position.y) {
lo = mid + 1;
} else {
hi = mid;
}
}
// we might have ended up with column 2, or 3, ..., so let's find the first column
while (lo > 0 && items[lo - 1].rect_cache.position.y == items[lo].rect_cache.position.y) {
lo -= 1;
}
first_item_visible = lo;
}
for (int i = first_item_visible; i < items.size(); i++) {
Rect2 rcache = items[i].rect_cache;
if (rcache.position.y > clip.position.y + clip.size.y) {
break; // done
}
if (!clip.intersects(rcache)) {
continue;
}
if (current_columns == 1) {
rcache.size.width = width - rcache.position.x;
}
if (items[i].selected) {
Rect2 r = rcache;
r.position += base_ofs;
r.position.y -= vseparation / 2;
r.size.y += vseparation;
r.position.x -= hseparation / 2;
r.size.x += hseparation;
if (rtl) {
r.position.x = size.width - r.position.x - r.size.x;
}
draw_style_box(sbsel, r);
}
if (items[i].custom_bg.a > 0.001) {
Rect2 r = rcache;
r.position += base_ofs;
// Size rect to make the align the temperature colors
r.position.y -= vseparation / 2;
r.size.y += vseparation;
r.position.x -= hseparation / 2;
r.size.x += hseparation;
if (rtl) {
r.position.x = size.width - r.position.x - r.size.x;
}
draw_rect(r, items[i].custom_bg);
}
Vector2 text_ofs;
if (items[i].icon.is_valid()) {
Size2 icon_size;
//= _adjust_to_max_size(items[i].get_icon_size(),fixed_icon_size) * icon_scale;
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
icon_size = fixed_icon_size * icon_scale;
} else {
icon_size = items[i].get_icon_size() * icon_scale;
}
Vector2 icon_ofs;
Point2 pos = items[i].rect_cache.position + icon_ofs + base_ofs;
if (icon_mode == ICON_MODE_TOP) {
pos.x += Math::floor((items[i].rect_cache.size.width - icon_size.width) / 2);
pos.y += icon_margin;
text_ofs.y = icon_size.height + icon_margin * 2;
} else {
pos.y += Math::floor((items[i].rect_cache.size.height - icon_size.height) / 2);
text_ofs.x = icon_size.width + icon_margin;
}
Rect2 draw_rect = Rect2(pos, icon_size);
if (fixed_icon_size.x > 0 && fixed_icon_size.y > 0) {
Rect2 adj = _adjust_to_max_size(items[i].get_icon_size() * icon_scale, icon_size);
draw_rect.position += adj.position;
draw_rect.size = adj.size;
}
Color modulate = items[i].icon_modulate;
if (items[i].disabled) {
modulate.a *= 0.5;
}
// If the icon is transposed, we have to switch the size so that it is drawn correctly
if (items[i].icon_transposed) {
Size2 size_tmp = draw_rect.size;
draw_rect.size.x = size_tmp.y;
draw_rect.size.y = size_tmp.x;
}
Rect2 region = (items[i].icon_region.size.x == 0 || items[i].icon_region.size.y == 0) ? Rect2(Vector2(), items[i].icon->get_size()) : Rect2(items[i].icon_region);
if (rtl) {
draw_rect.position.x = size.width - draw_rect.position.x - draw_rect.size.x;
}
draw_texture_rect_region(items[i].icon, draw_rect, region, modulate, items[i].icon_transposed);
}
if (items[i].tag_icon.is_valid()) {
Point2 draw_pos = items[i].rect_cache.position;
if (rtl) {
draw_pos.x = size.width - draw_pos.x - items[i].tag_icon->get_width();
}
draw_texture(items[i].tag_icon, draw_pos + base_ofs);
}
if (!items[i].text.is_empty()) {
int max_len = -1;
Vector2 size2 = items[i].text_buf->get_size();
if (fixed_column_width) {
max_len = fixed_column_width;
} else if (same_column_width) {
max_len = items[i].rect_cache.size.x;
} else {
max_len = size2.x;
}
Color modulate = items[i].selected ? font_selected_color : (items[i].custom_fg != Color() ? items[i].custom_fg : font_color);
if (items[i].disabled) {
modulate.a *= 0.5;
}
if (icon_mode == ICON_MODE_TOP && max_text_lines > 0) {
text_ofs += base_ofs;
text_ofs += items[i].rect_cache.position;
if (select_mode == SELECT_MULTI && i == current) {
Rect2 r = rcache;
r.position += base_ofs;
r.position.y -= vseparation / 2;
r.size.y += vseparation;
r.position.x -= hseparation / 2;
r.size.x += hseparation;
if (rtl) {
text_ofs.x = size.width - text_ofs.x - max_len;
r.position.x = size.width - r.position.x - r.size.x;
}
items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_CENTER);
draw_style_box(cursor, r);
}
}
if (outline_size > 0 && font_outline_color.a > 0) {
items[i].text_buf->draw_outline(get_canvas_item(), text_ofs, outline_size, font_outline_color);
}
items[i].text_buf->draw(get_canvas_item(), text_ofs, modulate);
} else {
if (fixed_column_width > 0) {
size2.x = MIN(size2.x, fixed_column_width);
}
if (icon_mode == ICON_MODE_TOP) {
text_ofs.x += (items[i].rect_cache.size.width - size2.x) / 2;
int first_visible_separator = 0;
{
// do a binary search to find the first separator that is below clip_position.y
int lo = 0;
int hi = separators.size();
while (lo < hi) {
const int mid = (lo + hi) / 2;
if (separators[mid] < clip.position.y) {
lo = mid + 1;
} else {
text_ofs.y += (items[i].rect_cache.size.height - size2.y) / 2;
hi = mid;
}
text_ofs += base_ofs;
text_ofs += items[i].rect_cache.position;
if (rtl) {
text_ofs.x = size.width - text_ofs.x - max_len;
}
items.write[i].text_buf->set_width(max_len);
if (rtl) {
items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_RIGHT);
} else {
items.write[i].text_buf->set_alignment(HORIZONTAL_ALIGNMENT_LEFT);
}
if (outline_size > 0 && font_outline_color.a > 0) {
items[i].text_buf->draw_outline(get_canvas_item(), text_ofs, outline_size, font_outline_color);
}
items[i].text_buf->draw(get_canvas_item(), text_ofs, modulate);
}
first_visible_separator = lo;
}
if (select_mode == SELECT_MULTI && i == current) {
Rect2 r = rcache;
r.position += base_ofs;
r.position.y -= vseparation / 2;
r.size.y += vseparation;
r.position.x -= hseparation / 2;
r.size.x += hseparation;
if (rtl) {
r.position.x = size.width - r.position.x - r.size.x;
for (int i = first_visible_separator; i < separators.size(); i++) {
if (separators[i] > clip.position.y + clip.size.y) {
break; // done
}
draw_style_box(cursor, r);
const int y = base_ofs.y + separators[i];
draw_line(Vector2(bg->get_margin(SIDE_LEFT), y), Vector2(width, y), guide_color);
}
}
int first_visible_separator = 0;
{
// do a binary search to find the first separator that is below clip_position.y
int lo = 0;
int hi = separators.size();
while (lo < hi) {
const int mid = (lo + hi) / 2;
if (separators[mid] < clip.position.y) {
lo = mid + 1;
} else {
hi = mid;
}
}
first_visible_separator = lo;
}
for (int i = first_visible_separator; i < separators.size(); i++) {
if (separators[i] > clip.position.y + clip.size.y) {
break; // done
}
const int y = base_ofs.y + separators[i];
draw_line(Vector2(bg->get_margin(SIDE_LEFT), y), Vector2(width, y), guide_color);
}
} break;
}
}

View File

@ -263,168 +263,227 @@ inline void draw_glyph_outline(const Glyph &p_gl, const RID &p_canvas, const Col
}
void Label::_notification(int p_what) {
if (p_what == NOTIFICATION_TRANSLATION_CHANGED) {
String new_text = atr(text);
if (new_text == xl_text) {
return; // Nothing new.
}
xl_text = new_text;
if (percent_visible < 1) {
visible_chars = get_total_character_count() * percent_visible;
}
dirty = true;
update();
}
if (p_what == NOTIFICATION_LAYOUT_DIRECTION_CHANGED) {
update();
}
if (p_what == NOTIFICATION_DRAW) {
if (clip) {
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
}
if (dirty || font_dirty || lines_dirty) {
_shape();
}
RID ci = get_canvas_item();
Size2 string_size;
Size2 size = get_size();
Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
Ref<Font> font = get_theme_font(SNAME("font"));
Color font_color = get_theme_color(SNAME("font_color"));
Color font_shadow_color = get_theme_color(SNAME("font_shadow_color"));
Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y")));
int line_spacing = get_theme_constant(SNAME("line_spacing"));
Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
int outline_size = get_theme_constant(SNAME("outline_size"));
int shadow_outline_size = get_theme_constant(SNAME("shadow_outline_size"));
bool rtl = (TS->shaped_text_get_inferred_direction(text_rid) == TextServer::DIRECTION_RTL);
bool rtl_layout = is_layout_rtl();
style->draw(ci, Rect2(Point2(0, 0), get_size()));
float total_h = 0.0;
int lines_visible = 0;
// Get number of lines to fit to the height.
for (int64_t i = lines_skipped; i < lines_rid.size(); i++) {
total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) {
break;
switch (p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
String new_text = atr(text);
if (new_text == xl_text) {
return; // Nothing new.
}
lines_visible++;
}
if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
lines_visible = max_lines_visible;
}
int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped);
bool trim_chars = (visible_chars >= 0) && (visible_chars_behavior == VC_CHARS_AFTER_SHAPING);
bool trim_glyphs_ltr = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_LTR) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && !rtl_layout));
bool trim_glyphs_rtl = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_RTL) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && rtl_layout));
// Get real total height.
int total_glyphs = 0;
total_h = 0;
for (int64_t i = lines_skipped; i < last_line; i++) {
total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
total_glyphs += TS->shaped_text_get_glyph_count(lines_rid[i]) + TS->shaped_text_get_ellipsis_glyph_count(lines_rid[i]);
}
int visible_glyphs = total_glyphs * percent_visible;
int processed_glyphs = 0;
total_h += style->get_margin(SIDE_TOP) + style->get_margin(SIDE_BOTTOM);
int vbegin = 0, vsep = 0;
if (lines_visible > 0) {
switch (vertical_alignment) {
case VERTICAL_ALIGNMENT_TOP: {
// Nothing.
} break;
case VERTICAL_ALIGNMENT_CENTER: {
vbegin = (size.y - (total_h - line_spacing)) / 2;
vsep = 0;
} break;
case VERTICAL_ALIGNMENT_BOTTOM: {
vbegin = size.y - (total_h - line_spacing);
vsep = 0;
} break;
case VERTICAL_ALIGNMENT_FILL: {
vbegin = 0;
if (lines_visible > 1) {
vsep = (size.y - (total_h - line_spacing)) / (lines_visible - 1);
} else {
vsep = 0;
}
} break;
xl_text = new_text;
if (percent_visible < 1) {
visible_chars = get_total_character_count() * percent_visible;
}
}
dirty = true;
Vector2 ofs;
ofs.y = style->get_offset().y + vbegin;
for (int i = lines_skipped; i < last_line; i++) {
Size2 line_size = TS->shaped_text_get_size(lines_rid[i]);
ofs.x = 0;
ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(TextServer::SPACING_TOP);
switch (horizontal_alignment) {
case HORIZONTAL_ALIGNMENT_FILL:
if (rtl && autowrap_mode != AUTOWRAP_OFF) {
ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
} else {
ofs.x = style->get_offset().x;
}
update();
} break;
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
update();
} break;
case NOTIFICATION_DRAW: {
if (clip) {
RenderingServer::get_singleton()->canvas_item_set_clip(get_canvas_item(), true);
}
if (dirty || font_dirty || lines_dirty) {
_shape();
}
RID ci = get_canvas_item();
Size2 string_size;
Size2 size = get_size();
Ref<StyleBox> style = get_theme_stylebox(SNAME("normal"));
Ref<Font> font = get_theme_font(SNAME("font"));
Color font_color = get_theme_color(SNAME("font_color"));
Color font_shadow_color = get_theme_color(SNAME("font_shadow_color"));
Point2 shadow_ofs(get_theme_constant(SNAME("shadow_offset_x")), get_theme_constant(SNAME("shadow_offset_y")));
int line_spacing = get_theme_constant(SNAME("line_spacing"));
Color font_outline_color = get_theme_color(SNAME("font_outline_color"));
int outline_size = get_theme_constant(SNAME("outline_size"));
int shadow_outline_size = get_theme_constant(SNAME("shadow_outline_size"));
bool rtl = (TS->shaped_text_get_inferred_direction(text_rid) == TextServer::DIRECTION_RTL);
bool rtl_layout = is_layout_rtl();
style->draw(ci, Rect2(Point2(0, 0), get_size()));
float total_h = 0.0;
int lines_visible = 0;
// Get number of lines to fit to the height.
for (int64_t i = lines_skipped; i < lines_rid.size(); i++) {
total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
if (total_h > (get_size().height - style->get_minimum_size().height + line_spacing)) {
break;
case HORIZONTAL_ALIGNMENT_LEFT: {
if (rtl_layout) {
ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
} else {
ofs.x = style->get_offset().x;
}
} break;
case HORIZONTAL_ALIGNMENT_CENTER: {
ofs.x = int(size.width - line_size.width) / 2;
} break;
case HORIZONTAL_ALIGNMENT_RIGHT: {
if (rtl_layout) {
ofs.x = style->get_offset().x;
} else {
ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
}
} break;
}
lines_visible++;
}
const Glyph *glyphs = TS->shaped_text_get_glyphs(lines_rid[i]);
int gl_size = TS->shaped_text_get_glyph_count(lines_rid[i]);
if (max_lines_visible >= 0 && lines_visible > max_lines_visible) {
lines_visible = max_lines_visible;
}
int ellipsis_pos = TS->shaped_text_get_ellipsis_pos(lines_rid[i]);
int trim_pos = TS->shaped_text_get_trim_pos(lines_rid[i]);
int last_line = MIN(lines_rid.size(), lines_visible + lines_skipped);
bool trim_chars = (visible_chars >= 0) && (visible_chars_behavior == VC_CHARS_AFTER_SHAPING);
bool trim_glyphs_ltr = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_LTR) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && !rtl_layout));
bool trim_glyphs_rtl = (visible_chars >= 0) && ((visible_chars_behavior == VC_GLYPHS_RTL) || ((visible_chars_behavior == VC_GLYPHS_AUTO) && rtl_layout));
const Glyph *ellipsis_glyphs = TS->shaped_text_get_ellipsis_glyphs(lines_rid[i]);
int ellipsis_gl_size = TS->shaped_text_get_ellipsis_glyph_count(lines_rid[i]);
// Get real total height.
int total_glyphs = 0;
total_h = 0;
for (int64_t i = lines_skipped; i < last_line; i++) {
total_h += TS->shaped_text_get_size(lines_rid[i]).y + font->get_spacing(TextServer::SPACING_TOP) + font->get_spacing(TextServer::SPACING_BOTTOM) + line_spacing;
total_glyphs += TS->shaped_text_get_glyph_count(lines_rid[i]) + TS->shaped_text_get_ellipsis_glyph_count(lines_rid[i]);
}
int visible_glyphs = total_glyphs * percent_visible;
int processed_glyphs = 0;
total_h += style->get_margin(SIDE_TOP) + style->get_margin(SIDE_BOTTOM);
int vbegin = 0, vsep = 0;
if (lines_visible > 0) {
switch (vertical_alignment) {
case VERTICAL_ALIGNMENT_TOP: {
// Nothing.
} break;
case VERTICAL_ALIGNMENT_CENTER: {
vbegin = (size.y - (total_h - line_spacing)) / 2;
vsep = 0;
} break;
case VERTICAL_ALIGNMENT_BOTTOM: {
vbegin = size.y - (total_h - line_spacing);
vsep = 0;
} break;
case VERTICAL_ALIGNMENT_FILL: {
vbegin = 0;
if (lines_visible > 1) {
vsep = (size.y - (total_h - line_spacing)) / (lines_visible - 1);
} else {
vsep = 0;
}
} break;
}
}
Vector2 ofs;
ofs.y = style->get_offset().y + vbegin;
for (int i = lines_skipped; i < last_line; i++) {
Size2 line_size = TS->shaped_text_get_size(lines_rid[i]);
ofs.x = 0;
ofs.y += TS->shaped_text_get_ascent(lines_rid[i]) + font->get_spacing(TextServer::SPACING_TOP);
switch (horizontal_alignment) {
case HORIZONTAL_ALIGNMENT_FILL:
if (rtl && autowrap_mode != AUTOWRAP_OFF) {
ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
} else {
ofs.x = style->get_offset().x;
}
break;
case HORIZONTAL_ALIGNMENT_LEFT: {
if (rtl_layout) {
ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
} else {
ofs.x = style->get_offset().x;
}
} break;
case HORIZONTAL_ALIGNMENT_CENTER: {
ofs.x = int(size.width - line_size.width) / 2;
} break;
case HORIZONTAL_ALIGNMENT_RIGHT: {
if (rtl_layout) {
ofs.x = style->get_offset().x;
} else {
ofs.x = int(size.width - style->get_margin(SIDE_RIGHT) - line_size.width);
}
} break;
}
const Glyph *glyphs = TS->shaped_text_get_glyphs(lines_rid[i]);
int gl_size = TS->shaped_text_get_glyph_count(lines_rid[i]);
int ellipsis_pos = TS->shaped_text_get_ellipsis_pos(lines_rid[i]);
int trim_pos = TS->shaped_text_get_trim_pos(lines_rid[i]);
const Glyph *ellipsis_glyphs = TS->shaped_text_get_ellipsis_glyphs(lines_rid[i]);
int ellipsis_gl_size = TS->shaped_text_get_ellipsis_glyph_count(lines_rid[i]);
// Draw outline. Note: Do not merge this into the single loop with the main text, to prevent overlaps.
int processed_glyphs_ol = processed_glyphs;
if ((outline_size > 0 && font_outline_color.a != 0) || (font_shadow_color.a != 0)) {
Vector2 offset = ofs;
// Draw RTL ellipsis string when necessary.
if (rtl && ellipsis_pos >= 0) {
for (int gl_idx = ellipsis_gl_size - 1; gl_idx >= 0; gl_idx--) {
for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
//Draw glyph outlines and shadow.
if (!skip) {
draw_glyph_outline(ellipsis_glyphs[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
}
processed_glyphs_ol++;
offset.x += ellipsis_glyphs[gl_idx].advance;
}
}
}
// Draw main text.
for (int j = 0; j < gl_size; j++) {
// Trim when necessary.
if (trim_pos >= 0) {
if (rtl) {
if (j < trim_pos) {
continue;
}
} else {
if (j >= trim_pos) {
break;
}
}
}
for (int k = 0; k < glyphs[j].repeat; k++) {
bool skip = (trim_chars && glyphs[j].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
// Draw glyph outlines and shadow.
if (!skip) {
draw_glyph_outline(glyphs[j], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
}
processed_glyphs_ol++;
offset.x += glyphs[j].advance;
}
}
// Draw LTR ellipsis string when necessary.
if (!rtl && ellipsis_pos >= 0) {
for (int gl_idx = 0; gl_idx < ellipsis_gl_size; gl_idx++) {
for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
//Draw glyph outlines and shadow.
if (!skip) {
draw_glyph_outline(ellipsis_glyphs[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
}
processed_glyphs_ol++;
offset.x += ellipsis_glyphs[gl_idx].advance;
}
}
}
}
// Draw main text. Note: Do not merge this into the single loop with the outline, to prevent overlaps.
// Draw outline. Note: Do not merge this into the single loop with the main text, to prevent overlaps.
int processed_glyphs_ol = processed_glyphs;
if ((outline_size > 0 && font_outline_color.a != 0) || (font_shadow_color.a != 0)) {
Vector2 offset = ofs;
// Draw RTL ellipsis string when necessary.
if (rtl && ellipsis_pos >= 0) {
for (int gl_idx = ellipsis_gl_size - 1; gl_idx >= 0; gl_idx--) {
for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
//Draw glyph outlines and shadow.
if (!skip) {
draw_glyph_outline(ellipsis_glyphs[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
draw_glyph(ellipsis_glyphs[gl_idx], ci, font_color, ofs);
}
processed_glyphs_ol++;
offset.x += ellipsis_glyphs[gl_idx].advance;
processed_glyphs++;
ofs.x += ellipsis_glyphs[gl_idx].advance;
}
}
}
@ -444,98 +503,42 @@ void Label::_notification(int p_what) {
}
}
for (int k = 0; k < glyphs[j].repeat; k++) {
bool skip = (trim_chars && glyphs[j].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
bool skip = (trim_chars && glyphs[j].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
// Draw glyph outlines and shadow.
if (!skip) {
draw_glyph_outline(glyphs[j], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
draw_glyph(glyphs[j], ci, font_color, ofs);
}
processed_glyphs_ol++;
offset.x += glyphs[j].advance;
processed_glyphs++;
ofs.x += glyphs[j].advance;
}
}
// Draw LTR ellipsis string when necessary.
if (!rtl && ellipsis_pos >= 0) {
for (int gl_idx = 0; gl_idx < ellipsis_gl_size; gl_idx++) {
for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs_ol >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs_ol < total_glyphs - visible_glyphs));
bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
//Draw glyph outlines and shadow.
if (!skip) {
draw_glyph_outline(ellipsis_glyphs[gl_idx], ci, font_color, font_shadow_color, font_outline_color, shadow_outline_size, outline_size, offset, shadow_ofs);
draw_glyph(ellipsis_glyphs[gl_idx], ci, font_color, ofs);
}
processed_glyphs_ol++;
offset.x += ellipsis_glyphs[gl_idx].advance;
processed_glyphs++;
ofs.x += ellipsis_glyphs[gl_idx].advance;
}
}
}
ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing + font->get_spacing(TextServer::SPACING_BOTTOM);
}
} break;
// Draw main text. Note: Do not merge this into the single loop with the outline, to prevent overlaps.
case NOTIFICATION_THEME_CHANGED: {
font_dirty = true;
update();
} break;
// Draw RTL ellipsis string when necessary.
if (rtl && ellipsis_pos >= 0) {
for (int gl_idx = ellipsis_gl_size - 1; gl_idx >= 0; gl_idx--) {
for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
//Draw glyph outlines and shadow.
if (!skip) {
draw_glyph(ellipsis_glyphs[gl_idx], ci, font_color, ofs);
}
processed_glyphs++;
ofs.x += ellipsis_glyphs[gl_idx].advance;
}
}
}
// Draw main text.
for (int j = 0; j < gl_size; j++) {
// Trim when necessary.
if (trim_pos >= 0) {
if (rtl) {
if (j < trim_pos) {
continue;
}
} else {
if (j >= trim_pos) {
break;
}
}
}
for (int k = 0; k < glyphs[j].repeat; k++) {
bool skip = (trim_chars && glyphs[j].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
// Draw glyph outlines and shadow.
if (!skip) {
draw_glyph(glyphs[j], ci, font_color, ofs);
}
processed_glyphs++;
ofs.x += glyphs[j].advance;
}
}
// Draw LTR ellipsis string when necessary.
if (!rtl && ellipsis_pos >= 0) {
for (int gl_idx = 0; gl_idx < ellipsis_gl_size; gl_idx++) {
for (int j = 0; j < ellipsis_glyphs[gl_idx].repeat; j++) {
bool skip = (trim_chars && ellipsis_glyphs[gl_idx].end > visible_chars) || (trim_glyphs_ltr && (processed_glyphs >= visible_glyphs)) || (trim_glyphs_rtl && (processed_glyphs < total_glyphs - visible_glyphs));
//Draw glyph outlines and shadow.
if (!skip) {
draw_glyph(ellipsis_glyphs[gl_idx], ci, font_color, ofs);
}
processed_glyphs++;
ofs.x += ellipsis_glyphs[gl_idx].advance;
}
}
}
ofs.y += TS->shaped_text_get_descent(lines_rid[i]) + vsep + line_spacing + font->get_spacing(TextServer::SPACING_BOTTOM);
}
}
if (p_what == NOTIFICATION_THEME_CHANGED) {
font_dirty = true;
update();
}
if (p_what == NOTIFICATION_RESIZED) {
lines_dirty = true;
case NOTIFICATION_RESIZED: {
lines_dirty = true;
} break;
}
}

View File

@ -656,31 +656,37 @@ void LineEdit::_notification(int p_what) {
}
} break;
#endif
case NOTIFICATION_RESIZED: {
_fit_to_width();
scroll_offset = 0;
set_caret_column(get_caret_column());
} break;
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_THEME_CHANGED: {
_shape();
update();
} break;
case NOTIFICATION_TRANSLATION_CHANGED: {
placeholder_translated = atr(placeholder);
_shape();
update();
} break;
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
window_has_focus = true;
draw_caret = true;
update();
} break;
case NOTIFICATION_WM_WINDOW_FOCUS_OUT: {
window_has_focus = false;
draw_caret = false;
update();
} break;
case NOTIFICATION_DRAW: {
if ((!has_focus() && !(menu && menu->has_focus()) && !caret_force_displayed) || !window_has_focus) {
draw_caret = false;
@ -923,6 +929,7 @@ void LineEdit::_notification(int p_what) {
}
}
} break;
case NOTIFICATION_FOCUS_ENTER: {
if (!caret_force_displayed) {
if (caret_blink_enabled) {
@ -942,6 +949,7 @@ void LineEdit::_notification(int p_what) {
show_virtual_keyboard();
} break;
case NOTIFICATION_FOCUS_EXIT: {
if (caret_blink_enabled && !caret_force_displayed) {
caret_blink_timer->stop();
@ -964,6 +972,7 @@ void LineEdit::_notification(int p_what) {
deselect();
}
} break;
case MainLoop::NOTIFICATION_OS_IME_UPDATE: {
if (has_focus()) {
ime_text = DisplayServer::get_singleton()->ime_get_text();
@ -974,10 +983,12 @@ void LineEdit::_notification(int p_what) {
update();
}
} break;
case Control::NOTIFICATION_DRAG_BEGIN: {
case NOTIFICATION_DRAG_BEGIN: {
drag_action = true;
} break;
case Control::NOTIFICATION_DRAG_END: {
case NOTIFICATION_DRAG_END: {
if (is_drag_successful()) {
if (selection.drag_attempt) {
selection.drag_attempt = false;

View File

@ -29,6 +29,7 @@
/*************************************************************************/
#include "link_button.h"
#include "core/string/translation.h"
void LinkButton::_shape() {
@ -148,18 +149,20 @@ void LinkButton::_notification(int p_what) {
case NOTIFICATION_TRANSLATION_CHANGED: {
xl_text = atr(text);
_shape();
update_minimum_size();
update();
} break;
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
update();
} break;
case NOTIFICATION_THEME_CHANGED: {
_shape();
update_minimum_size();
update();
} break;
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Size2 size = get_size();
@ -230,7 +233,6 @@ void LinkButton::_notification(int p_what) {
draw_line(Vector2(0, y), Vector2(width, y), color, text_buf->get_line_underline_thickness());
}
}
} break;
}
}

View File

@ -107,6 +107,7 @@ void MarginContainer::_notification(int p_what) {
fit_child_in_rect(c, Rect2(margin_left, margin_top, w, h));
}
} break;
case NOTIFICATION_THEME_CHANGED: {
update_minimum_size();
} break;

View File

@ -139,11 +139,13 @@ void MenuButton::_notification(int p_what) {
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
popup->set_layout_direction((Window::LayoutDirection)get_layout_direction());
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
popup->hide();
}
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
Vector2i mouse_pos = DisplayServer::get_singleton()->mouse_get_position() - mouse_pos_adjusted;
MenuButton *menu_btn_other = Object::cast_to<MenuButton>(get_viewport()->gui_find_control(mouse_pos));

View File

@ -34,18 +34,20 @@
#include "servers/rendering_server.h"
void NinePatchRect::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
if (texture.is_null()) {
return;
}
switch (p_what) {
case NOTIFICATION_DRAW: {
if (texture.is_null()) {
return;
}
Rect2 rect = Rect2(Point2(), get_size());
Rect2 src_rect = region_rect;
Rect2 rect = Rect2(Point2(), get_size());
Rect2 src_rect = region_rect;
texture->get_rect_region(rect, src_rect, rect, src_rect);
texture->get_rect_region(rect, src_rect, rect, src_rect);
RID ci = get_canvas_item();
RS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[SIDE_LEFT], margin[SIDE_TOP]), Vector2(margin[SIDE_RIGHT], margin[SIDE_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center);
RID ci = get_canvas_item();
RS::get_singleton()->canvas_item_add_nine_patch(ci, rect, src_rect, texture->get_rid(), Vector2(margin[SIDE_LEFT], margin[SIDE_TOP]), Vector2(margin[SIDE_RIGHT], margin[SIDE_BOTTOM]), RS::NinePatchAxisMode(axis_h), RS::NinePatchAxisMode(axis_v), draw_center);
} break;
}
}

View File

@ -91,6 +91,7 @@ void OptionButton::_notification(int p_what) {
}
arrow->draw(ci, ofs, clr);
} break;
case NOTIFICATION_TRANSLATION_CHANGED:
case NOTIFICATION_LAYOUT_DIRECTION_CHANGED: {
popup->set_layout_direction((Window::LayoutDirection)get_layout_direction());
@ -107,6 +108,7 @@ void OptionButton::_notification(int p_what) {
}
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible_in_tree()) {
popup->hide();

View File

@ -31,10 +31,12 @@
#include "panel.h"
void Panel::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item();
Ref<StyleBox> style = get_theme_stylebox(SNAME("panel"));
style->draw(ci, Rect2(Point2(), get_size()));
switch (p_what) {
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Ref<StyleBox> style = get_theme_stylebox(SNAME("panel"));
style->draw(ci, Rect2(Point2(), get_size()));
} break;
}
}

View File

@ -79,46 +79,48 @@ Vector<int> PanelContainer::get_allowed_size_flags_vertical() const {
}
void PanelContainer::_notification(int p_what) {
if (p_what == NOTIFICATION_DRAW) {
RID ci = get_canvas_item();
Ref<StyleBox> style;
switch (p_what) {
case NOTIFICATION_DRAW: {
RID ci = get_canvas_item();
Ref<StyleBox> style;
if (has_theme_stylebox(SNAME("panel"))) {
style = get_theme_stylebox(SNAME("panel"));
} else {
style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
}
style->draw(ci, Rect2(Point2(), get_size()));
}
if (p_what == NOTIFICATION_SORT_CHILDREN) {
Ref<StyleBox> style;
if (has_theme_stylebox(SNAME("panel"))) {
style = get_theme_stylebox(SNAME("panel"));
} else {
style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
}
Size2 size = get_size();
Point2 ofs;
if (style.is_valid()) {
size -= style->get_minimum_size();
ofs += style->get_offset();
}
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
if (!c || !c->is_visible_in_tree()) {
continue;
}
if (c->is_set_as_top_level()) {
continue;
if (has_theme_stylebox(SNAME("panel"))) {
style = get_theme_stylebox(SNAME("panel"));
} else {
style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
}
fit_child_in_rect(c, Rect2(ofs, size));
}
style->draw(ci, Rect2(Point2(), get_size()));
} break;
case NOTIFICATION_SORT_CHILDREN: {
Ref<StyleBox> style;
if (has_theme_stylebox(SNAME("panel"))) {
style = get_theme_stylebox(SNAME("panel"));
} else {
style = get_theme_stylebox(SNAME("panel"), SNAME("PanelContainer"));
}
Size2 size = get_size();
Point2 ofs;
if (style.is_valid()) {
size -= style->get_minimum_size();
ofs += style->get_offset();
}
for (int i = 0; i < get_child_count(); i++) {
Control *c = Object::cast_to<Control>(get_child(i));
if (!c || !c->is_visible_in_tree()) {
continue;
}
if (c->is_set_as_top_level()) {
continue;
}
fit_child_in_rect(c, Rect2(ofs, size));
}
} break;
}
}

View File

@ -74,19 +74,19 @@ void Popup::_notification(int p_what) {
emit_signal(SNAME("popup_hide"));
popped_up = false;
}
} break;
case NOTIFICATION_WM_WINDOW_FOCUS_IN: {
if (has_focus()) {
popped_up = true;
}
} break;
case NOTIFICATION_EXIT_TREE: {
_deinitialize_visible_parents();
} break;
case NOTIFICATION_WM_CLOSE_REQUEST: {
_close_pressed();
} break;
case NOTIFICATION_WM_CLOSE_REQUEST:
case NOTIFICATION_APPLICATION_FOCUS_OUT: {
_close_pressed();
} break;
@ -241,13 +241,20 @@ void PopupPanel::_update_child_rects() {
}
void PopupPanel::_notification(int p_what) {
if (p_what == NOTIFICATION_THEME_CHANGED) {
panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
} else if (p_what == NOTIFICATION_READY || p_what == NOTIFICATION_ENTER_TREE) {
panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
_update_child_rects();
} else if (p_what == NOTIFICATION_WM_SIZE_CHANGED) {
_update_child_rects();
switch (p_what) {
case NOTIFICATION_THEME_CHANGED: {
panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
} break;
case NOTIFICATION_ENTER_TREE:
case NOTIFICATION_READY: {
panel->add_theme_style_override("panel", get_theme_stylebox(SNAME("panel"), get_class_name()));
_update_child_rects();
} break;
case NOTIFICATION_WM_SIZE_CHANGED: {
_update_child_rects();
} break;
}
}

View File

@ -736,6 +736,7 @@ void PopupMenu::_notification(int p_what) {
set_submenu_popup_delay(pm_delay);
}
} break;
case NOTIFICATION_THEME_CHANGED:
case Control::NOTIFICATION_LAYOUT_DIRECTION_CHANGED:
case NOTIFICATION_TRANSLATION_CHANGED: {
@ -748,23 +749,25 @@ void PopupMenu::_notification(int p_what) {
child_controls_changed();
control->update();
} break;
case NOTIFICATION_WM_MOUSE_ENTER: {
grab_focus();
} break;
case NOTIFICATION_WM_MOUSE_EXIT: {
if (mouse_over >= 0 && (items[mouse_over].submenu.is_empty() || submenu_over != -1)) {
mouse_over = -1;
control->update();
}
} break;
case NOTIFICATION_POST_POPUP: {
initial_button_mask = Input::get_singleton()->get_mouse_button_mask();
during_grabbed_click = (bool)initial_button_mask;
} break;
case NOTIFICATION_WM_SIZE_CHANGED: {
} break;
case NOTIFICATION_INTERNAL_PROCESS: {
//only used when using operating system windows
// Only used when using operating system windows.
if (!is_embedded() && autohide_areas.size()) {
Point2 mouse_pos = DisplayServer::get_singleton()->mouse_get_position();
mouse_pos -= get_position();
@ -777,6 +780,7 @@ void PopupMenu::_notification(int p_what) {
}
}
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
if (!is_visible()) {
if (mouse_over >= 0) {

Some files were not shown because too many files have changed in this diff Show More