Skip to content

Commit

Permalink
Merge pull request #71147 from bruvzg/get_win
Browse files Browse the repository at this point in the history
Add Node::get_window() method.
  • Loading branch information
akien-mga committed Jan 10, 2023
2 parents 7966909 + ca8b762 commit e3a8764
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
6 changes: 6 additions & 0 deletions doc/classes/Node.xml
Original file line number Diff line number Diff line change
Expand Up @@ -421,6 +421,12 @@
Returns the node's [Viewport].
</description>
</method>
<method name="get_window" qualifiers="const">
<return type="Window" />
<description>
Returns the [Window] that contains this node. If the node is in the main window, this is equivalent to getting the root node ([code]get_tree().get_root()[/code]).
</description>
</method>
<method name="has_node" qualifiers="const">
<return type="bool" />
<param index="0" name="path" type="NodePath" />
Expand Down
10 changes: 10 additions & 0 deletions scene/main/node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include "scene/animation/tween.h"
#include "scene/debugger/scene_debugger.h"
#include "scene/main/multiplayer_api.h"
#include "scene/main/window.h"
#include "scene/resources/packed_scene.h"
#include "scene/scene_string_names.h"
#include "viewport.h"
Expand Down Expand Up @@ -1467,6 +1468,14 @@ Node *Node::find_parent(const String &p_pattern) const {
return nullptr;
}

Window *Node::get_window() const {
Viewport *vp = get_viewport();
if (vp) {
return vp->get_base_window();
}
return nullptr;
}

bool Node::is_ancestor_of(const Node *p_node) const {
ERR_FAIL_NULL_V(p_node, false);
Node *p = p_node->data.parent;
Expand Down Expand Up @@ -2858,6 +2867,7 @@ void Node::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_physics_process_internal", "enable"), &Node::set_physics_process_internal);
ClassDB::bind_method(D_METHOD("is_physics_processing_internal"), &Node::is_physics_processing_internal);

ClassDB::bind_method(D_METHOD("get_window"), &Node::get_window);
ClassDB::bind_method(D_METHOD("get_tree"), &Node::get_tree);
ClassDB::bind_method(D_METHOD("create_tween"), &Node::create_tween);

Expand Down
3 changes: 3 additions & 0 deletions scene/main/node.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include "scene/main/scene_tree.h"

class Viewport;
class Window;
class SceneState;
class Tween;
class PropertyTweener;
Expand Down Expand Up @@ -321,6 +322,8 @@ class Node : public Object {
Node *get_parent() const;
Node *find_parent(const String &p_pattern) const;

Window *get_window() const;

_FORCE_INLINE_ SceneTree *get_tree() const {
ERR_FAIL_COND_V(!data.tree, nullptr);
return data.tree;
Expand Down

0 comments on commit e3a8764

Please sign in to comment.