From de27df5da30ebf3576cd545b7ef3c55788efd083 Mon Sep 17 00:00:00 2001 From: Michael Alexsander Date: Tue, 15 Aug 2023 22:06:15 -0300 Subject: [PATCH] Allow to get a list of visible embedded `Window`s --- doc/classes/Viewport.xml | 7 +++++++ scene/main/viewport.cpp | 11 +++++++++++ scene/main/viewport.h | 1 + 3 files changed, 19 insertions(+) diff --git a/doc/classes/Viewport.xml b/doc/classes/Viewport.xml index 98836db157b2..101717966ecc 100644 --- a/doc/classes/Viewport.xml +++ b/doc/classes/Viewport.xml @@ -52,6 +52,13 @@ Returns an individual bit on the rendering layer mask. + + + + Returns a list of the visible embedded [Window]s inside the viewport. + [b]Note:[/b] [Window]s inside other viewports will not be listed. + + diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp index 180efaaa603c..41034466f948 100644 --- a/scene/main/viewport.cpp +++ b/scene/main/viewport.cpp @@ -2439,6 +2439,7 @@ Window *Viewport::get_base_window() const { return w; } + void Viewport::_gui_remove_focus_for_window(Node *p_window) { if (get_base_window() == p_window) { gui_release_focus(); @@ -3656,6 +3657,15 @@ bool Viewport::is_embedding_subwindows() const { return gui.embed_subwindows_hint; } +TypedArray Viewport::get_embedded_subwindows() const { + TypedArray windows; + for (int i = 0; i < gui.sub_windows.size(); i++) { + windows.append(gui.sub_windows[i].window); + } + + return windows; +} + void Viewport::subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect) { int index = _sub_window_find(p_window); ERR_FAIL_COND(index == -1); @@ -4384,6 +4394,7 @@ void Viewport::_bind_methods() { ClassDB::bind_method(D_METHOD("set_embedding_subwindows", "enable"), &Viewport::set_embedding_subwindows); ClassDB::bind_method(D_METHOD("is_embedding_subwindows"), &Viewport::is_embedding_subwindows); + ClassDB::bind_method(D_METHOD("get_embedded_subwindows"), &Viewport::get_embedded_subwindows); ClassDB::bind_method(D_METHOD("set_canvas_cull_mask", "mask"), &Viewport::set_canvas_cull_mask); ClassDB::bind_method(D_METHOD("get_canvas_cull_mask"), &Viewport::get_canvas_cull_mask); diff --git a/scene/main/viewport.h b/scene/main/viewport.h index 1e107ea99c6e..346dc6af7e0f 100644 --- a/scene/main/viewport.h +++ b/scene/main/viewport.h @@ -653,6 +653,7 @@ class Viewport : public Node { void set_embedding_subwindows(bool p_embed); bool is_embedding_subwindows() const; + TypedArray get_embedded_subwindows() const; void subwindow_set_popup_safe_rect(Window *p_window, const Rect2i &p_rect); Rect2i subwindow_get_popup_safe_rect(Window *p_window) const;