diff options
Diffstat (limited to 'scene/main')
-rw-r--r-- | scene/main/canvas_item.cpp | 45 | ||||
-rw-r--r-- | scene/main/node.cpp | 74 | ||||
-rw-r--r-- | scene/main/node.h | 1 | ||||
-rw-r--r-- | scene/main/scene_tree.cpp | 2 | ||||
-rw-r--r-- | scene/main/viewport.cpp | 24 | ||||
-rw-r--r-- | scene/main/viewport.h | 3 | ||||
-rw-r--r-- | scene/main/window.cpp | 6 |
7 files changed, 68 insertions, 87 deletions
diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index c80665cf2e..a0916c6291 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -99,34 +99,31 @@ void CanvasItem::_propagate_visibility_changed(bool p_visible) { _unblock(); } -void CanvasItem::show() { - if (visible) { +void CanvasItem::set_visible(bool p_visible) { + if (visible == p_visible) { return; } - visible = true; - RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, true); + visible = p_visible; + RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, p_visible); if (!is_inside_tree()) { return; } - _propagate_visibility_changed(true); + _propagate_visibility_changed(p_visible); } -void CanvasItem::hide() { - if (!visible) { - return; - } - - visible = false; - RenderingServer::get_singleton()->canvas_item_set_visible(canvas_item, false); +void CanvasItem::show() { + set_visible(true); +} - if (!is_inside_tree()) { - return; - } +void CanvasItem::hide() { + set_visible(false); +} - _propagate_visibility_changed(false); +bool CanvasItem::is_visible() const { + return visible; } CanvasItem *CanvasItem::current_item_drawn = nullptr; @@ -348,24 +345,12 @@ void CanvasItem::_notification(int p_what) { } } -void CanvasItem::set_visible(bool p_visible) { - if (p_visible) { - show(); - } else { - hide(); - } -} - void CanvasItem::_window_visibility_changed() { if (visible) { _propagate_visibility_changed(window->is_visible()); } } -bool CanvasItem::is_visible() const { - return visible; -} - void CanvasItem::update() { if (!is_inside_tree()) { return; @@ -1032,8 +1017,8 @@ void CanvasItem::set_notify_transform(bool p_enable) { notify_transform = p_enable; if (notify_transform && is_inside_tree()) { - //this ensures that invalid globals get resolved, so notifications can be received - get_global_transform(); + // This ensures that invalid globals get resolved, so notifications can be received. + _ALLOW_DISCARD_ get_global_transform(); } } diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 442d7ae6e6..416dec3e4f 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -152,12 +152,6 @@ void Node::_notification(int p_notification) { data.in_constructor = false; } break; case NOTIFICATION_PREDELETE: { - set_owner(nullptr); - - while (data.owned.size()) { - data.owned.front()->get()->set_owner(nullptr); - } - if (data.parent) { data.parent->remove_child(this); } @@ -165,10 +159,8 @@ void Node::_notification(int p_notification) { // kill children as cleanly as possible while (data.children.size()) { Node *child = data.children[data.children.size() - 1]; //begin from the end because its faster and more consistent with creation - remove_child(child); memdelete(child); } - } break; } } @@ -237,11 +229,32 @@ void Node::_propagate_enter_tree() { } void Node::_propagate_after_exit_tree() { + // Clear owner if it was not part of the pruned branch + if (data.owner) { + bool found = false; + Node *parent = data.parent; + + while (parent) { + if (parent == data.owner) { + found = true; + break; + } + + parent = parent->data.parent; + } + + if (!found) { + data.owner->data.owned.erase(data.OW); + data.owner = nullptr; + } + } + data.blocked++; - for (int i = 0; i < data.children.size(); i++) { + for (int i = data.children.size() - 1; i >= 0; i--) { data.children[i]->_propagate_after_exit_tree(); } data.blocked--; + emit_signal(SceneStringNames::get_singleton()->tree_exited); } @@ -1144,31 +1157,6 @@ void Node::add_sibling(Node *p_sibling, bool p_legible_unique_name) { data.parent->_move_child(p_sibling, get_index() + 1); } -void Node::_propagate_validate_owner() { - if (data.owner) { - bool found = false; - Node *parent = data.parent; - - while (parent) { - if (parent == data.owner) { - found = true; - break; - } - - parent = parent->data.parent; - } - - if (!found) { - data.owner->data.owned.erase(data.OW); - data.owner = nullptr; - } - } - - for (int i = 0; i < data.children.size(); i++) { - data.children[i]->_propagate_validate_owner(); - } -} - void Node::remove_child(Node *p_child) { ERR_FAIL_NULL(p_child); ERR_FAIL_COND_MSG(data.blocked > 0, "Parent node is busy setting up children, remove_node() failed. Consider using call_deferred(\"remove_child\", child) instead."); @@ -1222,9 +1210,6 @@ void Node::remove_child(Node *p_child) { p_child->data.parent = nullptr; p_child->data.pos = -1; - // validate owner - p_child->_propagate_validate_owner(); - if (data.inside_tree) { p_child->_propagate_after_exit_tree(); } @@ -1331,12 +1316,14 @@ Node *Node::get_node_or_null(const NodePath &p_path) const { Node *Node::get_node(const NodePath &p_path) const { Node *node = get_node_or_null(p_path); - if (p_path.is_absolute()) { - ERR_FAIL_COND_V_MSG(!node, nullptr, - vformat(R"(Node not found: "%s" (absolute path attempted from "%s").)", p_path, get_path())); - } else { - ERR_FAIL_COND_V_MSG(!node, nullptr, - vformat(R"(Node not found: "%s" (relative to "%s").)", p_path, get_path())); + if (unlikely(!node)) { + if (p_path.is_absolute()) { + ERR_FAIL_V_MSG(nullptr, + vformat(R"(Node not found: "%s" (absolute path attempted from "%s").)", p_path, get_path())); + } else { + ERR_FAIL_V_MSG(nullptr, + vformat(R"(Node not found: "%s" (relative to "%s").)", p_path, get_path())); + } } return node; @@ -2001,6 +1988,7 @@ Node *Node::_duplicate(int p_flags, Map<const Node *, Node *> *r_duplimap) const #endif node = res->instantiate(ges); ERR_FAIL_COND_V(!node, nullptr); + node->set_scene_instance_load_placeholder(get_scene_instance_load_placeholder()); instantiated = true; diff --git a/scene/main/node.h b/scene/main/node.h index 8613c4736c..a1fc672a15 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -172,7 +172,6 @@ private: void _propagate_ready(); void _propagate_exit_tree(); void _propagate_after_exit_tree(); - void _propagate_validate_owner(); void _print_stray_nodes(); void _propagate_process_owner(Node *p_owner, int p_pause_notification, int p_enabled_notification); Array _get_node_and_resource(const NodePath &p_path); diff --git a/scene/main/scene_tree.cpp b/scene/main/scene_tree.cpp index 9e4908a23d..cafa4a43fd 100644 --- a/scene/main/scene_tree.cpp +++ b/scene/main/scene_tree.cpp @@ -535,7 +535,7 @@ void SceneTree::process_tweens(float p_delta, bool p_physics) { for (List<Ref<Tween>>::Element *E = tweens.front(); E;) { List<Ref<Tween>>::Element *N = E->next(); // Don't process if paused or process mode doesn't match. - if ((paused && E->get()->should_pause()) || (p_physics == (E->get()->get_process_mode() == Tween::TWEEN_PROCESS_IDLE))) { + if (!E->get()->can_process(paused) || (p_physics == (E->get()->get_process_mode() == Tween::TWEEN_PROCESS_IDLE))) { if (E == L) { break; } diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 0a9f98bb2f..2cdafefba7 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -48,6 +48,7 @@ #include "scene/gui/label.h" #include "scene/gui/popup.h" #include "scene/gui/popup_menu.h" +#include "scene/gui/subviewport_container.h" #include "scene/main/canvas_layer.h" #include "scene/main/window.h" #include "scene/resources/mesh.h" @@ -371,8 +372,6 @@ void Viewport::_sub_window_remove(Window *p_window) { void Viewport::_notification(int p_what) { switch (p_what) { case NOTIFICATION_ENTER_TREE: { - gui.embedding_subwindows = gui.embed_subwindows_hint; - if (get_parent()) { parent = get_parent()->get_viewport(); RenderingServer::get_singleton()->viewport_set_parent_viewport(viewport, parent->get_viewport_rid()); @@ -1700,13 +1699,13 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (over) { Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); Size2 pos = localizer.xform(mpos); - Vector2 speed = localizer.basis_xform(mm->get_speed()); + Vector2 velocity = localizer.basis_xform(mm->get_velocity()); Vector2 rel = localizer.basis_xform(mm->get_relative()); mm = mm->xformed_by(Transform2D()); // Make a copy. mm->set_global_position(mpos); - mm->set_speed(speed); + mm->set_velocity(velocity); mm->set_relative(rel); if (mm->get_button_mask() == MouseButton::NONE) { @@ -1956,12 +1955,12 @@ void Viewport::_gui_input_event(Ref<InputEvent> p_event) { if (over->can_process()) { Transform2D localizer = over->get_global_transform_with_canvas().affine_inverse(); Size2 pos = localizer.xform(drag_event->get_position()); - Vector2 speed = localizer.basis_xform(drag_event->get_speed()); + Vector2 velocity = localizer.basis_xform(drag_event->get_velocity()); Vector2 rel = localizer.basis_xform(drag_event->get_relative()); drag_event = drag_event->xformed_by(Transform2D()); // Make a copy. - drag_event->set_speed(speed); + drag_event->set_velocity(velocity); drag_event->set_relative(rel); drag_event->set_position(pos); @@ -2349,7 +2348,7 @@ void Viewport::push_text_input(const String &p_text) { } Viewport::SubWindowResize Viewport::_sub_window_get_resize_margin(Window *p_subwindow, const Point2 &p_point) { - if (p_subwindow->get_flag(Window::FLAG_BORDERLESS)) { + if (p_subwindow->get_flag(Window::FLAG_BORDERLESS) || p_subwindow->get_flag(Window::FLAG_RESIZE_DISABLED)) { return SUB_WINDOW_RESIZE_DISABLED; } @@ -2545,7 +2544,7 @@ bool Viewport::_sub_windows_forward_input(const Ref<InputEvent> &p_event) { if (mb.is_valid() && mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT) { bool click_on_window = false; for (int i = gui.sub_windows.size() - 1; i >= 0; i--) { - SubWindow &sw = gui.sub_windows.write[i]; + SubWindow sw = gui.sub_windows.write[i]; // Clicked inside window? @@ -3865,6 +3864,11 @@ Viewport::~Viewport() { void SubViewport::set_size(const Size2i &p_size) { _set_size(p_size, _get_size_2d_override(), Rect2i(), _stretch_transform(), true); + + SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent()); + if (c) { + c->update_minimum_size(); + } } Size2i SubViewport::get_size() const { @@ -3950,8 +3954,8 @@ void SubViewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_clear_mode", "mode"), &SubViewport::set_clear_mode); ClassDB::bind_method(D_METHOD("get_clear_mode"), &SubViewport::get_clear_mode); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size"), "set_size", "get_size"); - ADD_PROPERTY(PropertyInfo(Variant::VECTOR2, "size_2d_override"), "set_size_2d_override", "get_size_2d_override"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size"), "set_size", "get_size"); + ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size_2d_override"), "set_size_2d_override", "get_size_2d_override"); ADD_PROPERTY(PropertyInfo(Variant::BOOL, "size_2d_override_stretch"), "set_size_2d_override_stretch", "is_size_2d_override_stretch_enabled"); ADD_GROUP("Render Target", "render_target_"); ADD_PROPERTY(PropertyInfo(Variant::INT, "render_target_clear_mode", PROPERTY_HINT_ENUM, "Always,Never,Next Frame"), "set_clear_mode", "get_clear_mode"); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 57e1100521..a3127811f5 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -362,7 +362,6 @@ private: bool dragging = false; bool drag_successful = false; bool embed_subwindows_hint = false; - bool embedding_subwindows = false; Window *subwindow_focused = nullptr; SubWindowDrag subwindow_drag = SUB_WINDOW_DRAG_DISABLED; @@ -373,7 +372,7 @@ private: SubWindowResize subwindow_resize_mode; Rect2i subwindow_resize_from_rect; - Vector<SubWindow> sub_windows; + Vector<SubWindow> sub_windows; // Don't obtain references or pointers to the elements, as their location can change. } gui; DefaultCanvasItemTextureFilter default_canvas_item_texture_filter = DEFAULT_CANVAS_ITEM_TEXTURE_FILTER_LINEAR; diff --git a/scene/main/window.cpp b/scene/main/window.cpp index 43de4187d4..532b457843 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -281,6 +281,11 @@ void Window::_clear_window() { DisplayServer::get_singleton()->delete_sub_window(window_id); window_id = DisplayServer::INVALID_WINDOW_ID; + // If closing window was focused and has a parent, return focus. + if (focused && transient_parent) { + transient_parent->grab_focus(); + } + _update_viewport_size(); RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED); } @@ -1574,6 +1579,7 @@ void Window::_bind_methods() { ADD_SIGNAL(MethodInfo("go_back_requested")); ADD_SIGNAL(MethodInfo("visibility_changed")); ADD_SIGNAL(MethodInfo("about_to_popup")); + ADD_SIGNAL(MethodInfo("theme_changed")); BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED); |