mirror of
https://github.com/godotengine/godot.git
synced 2025-03-07 23:32:58 +08:00
Add helper method to get Window from ID
This commit is contained in:
parent
0eadbdb5d0
commit
e0304a7d00
@ -1601,18 +1601,12 @@ void ColorPicker::_pick_button_pressed_legacy() {
|
||||
// Add the Texture of each Window to the Image.
|
||||
Vector<DisplayServer::WindowID> wl = ds->get_window_list();
|
||||
// FIXME: sort windows by visibility.
|
||||
for (int index = 0; index < wl.size(); index++) {
|
||||
DisplayServer::WindowID wid = wl[index];
|
||||
if (wid == DisplayServer::INVALID_WINDOW_ID) {
|
||||
for (const DisplayServer::WindowID &window_id : wl) {
|
||||
Window *w = Window::get_from_id(window_id);
|
||||
if (!w) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ObjectID woid = DisplayServer::get_singleton()->window_get_attached_instance_id(wid);
|
||||
if (woid == ObjectID()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Window *w = Object::cast_to<Window>(ObjectDB::get_instance(woid));
|
||||
Ref<Image> img = w->get_texture()->get_image();
|
||||
if (!img.is_valid() || img->is_empty()) {
|
||||
continue;
|
||||
|
@ -3771,19 +3771,9 @@ void Viewport::set_embedding_subwindows(bool p_embed) {
|
||||
}
|
||||
|
||||
if (allow_change) {
|
||||
Vector<int> wl = DisplayServer::get_singleton()->get_window_list();
|
||||
for (int index = 0; index < wl.size(); index++) {
|
||||
DisplayServer::WindowID wid = wl[index];
|
||||
if (wid == DisplayServer::INVALID_WINDOW_ID) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ObjectID woid = DisplayServer::get_singleton()->window_get_attached_instance_id(wid);
|
||||
if (woid.is_null()) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Window *w = Object::cast_to<Window>(ObjectDB::get_instance(woid));
|
||||
Vector<DisplayServer::WindowID> wl = DisplayServer::get_singleton()->get_window_list();
|
||||
for (const DisplayServer::WindowID &window_id : wl) {
|
||||
const Window *w = Window::get_from_id(window_id);
|
||||
if (w && is_ancestor_of(w)) {
|
||||
// Prevent change when this viewport has child windows that are displayed as native windows.
|
||||
allow_change = false;
|
||||
|
@ -270,6 +270,13 @@ void Window::_validate_property(PropertyInfo &p_property) const {
|
||||
|
||||
//
|
||||
|
||||
Window *Window::get_from_id(DisplayServer::WindowID p_window_id) {
|
||||
if (p_window_id == DisplayServer::INVALID_WINDOW_ID) {
|
||||
return nullptr;
|
||||
}
|
||||
return Object::cast_to<Window>(ObjectDB::get_instance(DisplayServer::get_singleton()->window_get_attached_instance_id(p_window_id)));
|
||||
}
|
||||
|
||||
void Window::set_title(const String &p_title) {
|
||||
ERR_MAIN_THREAD_GUARD;
|
||||
|
||||
@ -912,7 +919,7 @@ void Window::_make_transient() {
|
||||
if (!is_embedded() && transient_to_focused) {
|
||||
DisplayServer::WindowID focused_window_id = DisplayServer::get_singleton()->get_focused_window();
|
||||
if (focused_window_id != DisplayServer::INVALID_WINDOW_ID) {
|
||||
window = Object::cast_to<Window>(ObjectDB::get_instance(DisplayServer::get_singleton()->window_get_attached_instance_id(focused_window_id)));
|
||||
window = Window::get_from_id(focused_window_id);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -271,6 +271,7 @@ public:
|
||||
};
|
||||
|
||||
static void set_root_layout_direction(int p_root_dir);
|
||||
static Window *get_from_id(DisplayServer::WindowID p_window_id);
|
||||
|
||||
void set_title(const String &p_title);
|
||||
String get_title() const;
|
||||
|
Loading…
Reference in New Issue
Block a user