From b218727599b956384c4c77446535737cbd415173 Mon Sep 17 00:00:00 2001 From: kobewi Date: Sun, 10 Apr 2022 20:52:55 +0200 Subject: [PATCH] Rename raise() to move_to_front() --- doc/classes/CanvasItem.xml | 7 +++++++ doc/classes/Node.xml | 6 ------ editor/editor_node.cpp | 8 ++++---- editor/plugins/asset_library_editor_plugin.cpp | 2 +- editor/progress_dialog.cpp | 2 +- scene/gui/color_picker.cpp | 2 +- scene/gui/graph_edit.cpp | 2 +- scene/main/canvas_item.cpp | 8 ++++++++ scene/main/canvas_item.h | 1 + scene/main/node.cpp | 16 ---------------- scene/main/node.h | 1 - scene/main/viewport.cpp | 2 +- 12 files changed, 25 insertions(+), 32 deletions(-) diff --git a/doc/classes/CanvasItem.xml b/doc/classes/CanvasItem.xml index d8c1af0b3c5e..70d825efac8a 100644 --- a/doc/classes/CanvasItem.xml +++ b/doc/classes/CanvasItem.xml @@ -500,6 +500,13 @@ Transformations issued by [param event]'s inputs are applied in local space instead of global space. + + + + Moves this node to display on top of its siblings. This has more use in [Control], as [Node2D] can be ordered with [member Node2D.z_index]. + Internally, the node is moved to the bottom of parent's children list. The method has no effect on nodes without a parent. + + diff --git a/doc/classes/Node.xml b/doc/classes/Node.xml index 87edc7de0acb..c18bf3d40f69 100644 --- a/doc/classes/Node.xml +++ b/doc/classes/Node.xml @@ -577,12 +577,6 @@ Queues a node for deletion at the end of the current frame. When deleted, all of its child nodes will be deleted as well. This method ensures it's safe to delete the node, contrary to [method Object.free]. Use [method Object.is_queued_for_deletion] to check whether a node will be deleted at the end of the frame. - - - - Moves this node to the bottom of parent node's children hierarchy. This is often useful in GUIs ([Control] nodes), because their order of drawing depends on their order in the tree. The top Node is drawn first, then any siblings below the top Node in the hierarchy are successively drawn on top of it. After using [code]raise[/code], a Control will be drawn on top of its siblings. - - diff --git a/editor/editor_node.cpp b/editor/editor_node.cpp index 7a7576b2415a..d0e0adf04bfd 100644 --- a/editor/editor_node.cpp +++ b/editor/editor_node.cpp @@ -3375,7 +3375,7 @@ void EditorNode::add_editor_plugin(EditorPlugin *p_editor, bool p_config_changed singleton->main_editor_button_vb->add_child(tb); singleton->editor_table.push_back(p_editor); - singleton->distraction_free->raise(); + singleton->distraction_free->move_to_front(); } singleton->editor_data.add_editor_plugin(p_editor); singleton->add_child(p_editor); @@ -4965,7 +4965,7 @@ void EditorNode::_load_docks_from_config(Ref p_layout, const String } if (atidx == i) { - node->raise(); + node->move_to_front(); continue; } @@ -5390,7 +5390,7 @@ Button *EditorNode::add_bottom_panel_item(String p_text, Control *p_item) { tb->set_toggle_mode(true); tb->set_focus_mode(Control::FOCUS_NONE); bottom_panel_vb->add_child(p_item); - bottom_panel_hb->raise(); + bottom_panel_hb->move_to_front(); bottom_panel_hb_editors->add_child(tb); p_item->set_v_size_flags(Control::SIZE_EXPAND_FILL); p_item->hide(); @@ -5424,7 +5424,7 @@ void EditorNode::make_bottom_panel_item_visible(Control *p_item) { void EditorNode::raise_bottom_panel_item(Control *p_item) { for (int i = 0; i < bottom_panel_items.size(); i++) { if (bottom_panel_items[i].control == p_item) { - bottom_panel_items[i].button->raise(); + bottom_panel_items[i].button->move_to_front(); SWAP(bottom_panel_items.write[i], bottom_panel_items.write[bottom_panel_items.size() - 1]); break; } diff --git a/editor/plugins/asset_library_editor_plugin.cpp b/editor/plugins/asset_library_editor_plugin.cpp index 6bc443039f28..4434bcd765b9 100644 --- a/editor/plugins/asset_library_editor_plugin.cpp +++ b/editor/plugins/asset_library_editor_plugin.cpp @@ -577,7 +577,7 @@ void EditorAssetLibrary::_notification(int p_what) { switch (p_what) { case NOTIFICATION_READY: { add_theme_style_override("panel", get_theme_stylebox(SNAME("bg"), SNAME("AssetLib"))); - error_label->raise(); + error_label->move_to_front(); } break; case NOTIFICATION_ENTER_TREE: diff --git a/editor/progress_dialog.cpp b/editor/progress_dialog.cpp index 1c9afa8be8d9..e90b063349d9 100644 --- a/editor/progress_dialog.cpp +++ b/editor/progress_dialog.cpp @@ -176,7 +176,7 @@ void ProgressDialog::add_task(const String &p_task, const String &p_label, int p } else { cancel_hb->hide(); } - cancel_hb->raise(); + cancel_hb->move_to_front(); cancelled = false; _popup(); if (p_can_cancel) { diff --git a/scene/gui/color_picker.cpp b/scene/gui/color_picker.cpp index 41ed1d16c442..4a1f2ab7c659 100644 --- a/scene/gui/color_picker.cpp +++ b/scene/gui/color_picker.cpp @@ -1086,7 +1086,7 @@ void ColorPicker::_screen_pick_pressed() { } else { screen->show(); } - screen->raise(); + screen->move_to_front(); #ifndef _MSC_VER #warning show modal no longer works, needs to be converted to a popup #endif diff --git a/scene/gui/graph_edit.cpp b/scene/gui/graph_edit.cpp index 3efd465939cc..c8de8789fed3 100644 --- a/scene/gui/graph_edit.cpp +++ b/scene/gui/graph_edit.cpp @@ -351,7 +351,7 @@ void GraphEdit::_graph_node_raised(Node *p_gn) { if (gn->is_comment()) { move_child(gn, 0); } else { - gn->raise(); + gn->move_to_front(); } } diff --git a/scene/main/canvas_item.cpp b/scene/main/canvas_item.cpp index 65e7ba3e6741..093e4a8cd39f 100644 --- a/scene/main/canvas_item.cpp +++ b/scene/main/canvas_item.cpp @@ -369,6 +369,13 @@ void CanvasItem::queue_redraw() { MessageQueue::get_singleton()->push_callable(callable_mp(this, &CanvasItem::_redraw_callback)); } +void CanvasItem::move_to_front() { + if (!get_parent()) { + return; + } + get_parent()->move_child(this, get_parent()->get_child_count() - 1); +} + void CanvasItem::set_modulate(const Color &p_modulate) { if (modulate == p_modulate) { return; @@ -897,6 +904,7 @@ void CanvasItem::_bind_methods() { ClassDB::bind_method(D_METHOD("hide"), &CanvasItem::hide); ClassDB::bind_method(D_METHOD("queue_redraw"), &CanvasItem::queue_redraw); + ClassDB::bind_method(D_METHOD("move_to_front"), &CanvasItem::move_to_front); ClassDB::bind_method(D_METHOD("set_as_top_level", "enable"), &CanvasItem::set_as_top_level); ClassDB::bind_method(D_METHOD("is_set_as_top_level"), &CanvasItem::is_set_as_top_level); diff --git a/scene/main/canvas_item.h b/scene/main/canvas_item.h index 1abb4edec90e..b80289fdb411 100644 --- a/scene/main/canvas_item.h +++ b/scene/main/canvas_item.h @@ -198,6 +198,7 @@ class CanvasItem : public Node { void hide(); void queue_redraw(); + void move_to_front(); void set_clip_children(bool p_enabled); bool is_clipping_children() const; diff --git a/scene/main/node.cpp b/scene/main/node.cpp index 289e9630778a..273507a9fafe 100644 --- a/scene/main/node.cpp +++ b/scene/main/node.cpp @@ -389,21 +389,6 @@ void Node::_move_child(Node *p_child, int p_pos, bool p_ignore_end) { data.blocked--; } -void Node::raise() { - if (!data.parent) { - return; - } - - // Internal children move within a different index range. - if (_is_internal_front()) { - data.parent->move_child(this, data.parent->data.internal_children_front - 1); - } else if (_is_internal_back()) { - data.parent->move_child(this, data.parent->data.internal_children_back - 1); - } else { - data.parent->move_child(this, data.parent->get_child_count(false) - 1); - } -} - void Node::_propagate_groups_dirty() { for (const KeyValue &E : data.grouped) { if (E.value.group) { @@ -2816,7 +2801,6 @@ void Node::_bind_methods() { ClassDB::bind_method(D_METHOD("is_in_group", "group"), &Node::is_in_group); ClassDB::bind_method(D_METHOD("move_child", "child_node", "to_position"), &Node::move_child); ClassDB::bind_method(D_METHOD("get_groups"), &Node::_get_groups); - ClassDB::bind_method(D_METHOD("raise"), &Node::raise); ClassDB::bind_method(D_METHOD("set_owner", "owner"), &Node::set_owner); ClassDB::bind_method(D_METHOD("get_owner"), &Node::get_owner); ClassDB::bind_method(D_METHOD("remove_and_skip"), &Node::remove_and_skip); diff --git a/scene/main/node.h b/scene/main/node.h index ae6a9975795e..29f5410478d2 100644 --- a/scene/main/node.h +++ b/scene/main/node.h @@ -348,7 +348,6 @@ class Node : public Object { void move_child(Node *p_child, int p_pos); void _move_child(Node *p_child, int p_pos, bool p_ignore_end = false); - void raise(); void set_owner(Node *p_owner); Node *get_owner() const; diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index e901f76c0a55..5295de5c09d8 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2103,7 +2103,7 @@ void Viewport::_gui_set_drag_preview(Control *p_base, Control *p_control) { p_control->set_as_top_level(true); p_control->set_position(gui.last_mouse_pos); p_base->get_root_parent_control()->add_child(p_control); // Add as child of viewport. - p_control->raise(); + p_control->move_to_front(); gui.drag_preview_id = p_control->get_instance_id(); }