feat: modules moved and engine moved to submodule

This commit is contained in:
Jan van der Weide 2025-04-12 18:40:44 +02:00
parent dfb5e645cd
commit c33d2130cc
5136 changed files with 225275 additions and 64485 deletions

View file

@ -48,6 +48,8 @@ void Window::set_root_layout_direction(int p_root_dir) {
// Dynamic properties.
Window *Window::focused_window = nullptr;
bool Window::_set(const StringName &p_name, const Variant &p_value) {
ERR_MAIN_THREAD_GUARD_V(false);
String name = p_name;
@ -275,7 +277,7 @@ 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)));
return ObjectDB::get_instance<Window>(DisplayServer::get_singleton()->window_get_attached_instance_id(p_window_id));
}
void Window::set_title(const String &p_title) {
@ -310,11 +312,11 @@ void Window::set_title(const String &p_title) {
#ifdef DEBUG_ENABLED
if (EngineDebugger::get_singleton() && window_id == DisplayServer::MAIN_WINDOW_ID && !Engine::get_singleton()->is_project_manager_hint()) {
Array arr;
arr.push_back(tr_title);
Array arr = { tr_title };
EngineDebugger::get_singleton()->send_message("window:title", arr);
}
#endif
queue_accessibility_update();
}
String Window::get_title() const {
@ -688,6 +690,11 @@ void Window::_make_window() {
}
}
if (get_tree() && get_tree()->is_accessibility_supported()) {
get_tree()->_accessibility_force_update();
_accessibility_notify_enter(this);
}
_update_window_callbacks();
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_VISIBLE);
@ -719,6 +726,10 @@ void Window::_clear_window() {
_update_from_window();
if (get_tree() && get_tree()->is_accessibility_supported()) {
_accessibility_notify_exit(this);
}
DisplayServer::get_singleton()->delete_sub_window(window_id);
window_id = DisplayServer::INVALID_WINDOW_ID;
@ -750,6 +761,14 @@ void Window::_rect_changed_callback(const Rect2i &p_callback) {
size = p_callback.size;
_update_viewport_size();
}
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
Vector2 sz_out = DisplayServer::get_singleton()->window_get_size_with_decorations(window_id);
Vector2 pos_out = DisplayServer::get_singleton()->window_get_position_with_decorations(window_id);
Vector2 sz_in = DisplayServer::get_singleton()->window_get_size(window_id);
Vector2 pos_in = DisplayServer::get_singleton()->window_get_position(window_id);
DisplayServer::get_singleton()->accessibility_set_window_rect(window_id, Rect2(pos_out, sz_out), Rect2(pos_in, sz_in));
}
queue_accessibility_update();
}
void Window::_propagate_window_notification(Node *p_node, int p_notification) {
@ -808,12 +827,15 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
} break;
case DisplayServer::WINDOW_EVENT_FOCUS_IN: {
focused = true;
focused_window = this;
_propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_IN);
emit_signal(SceneStringName(focus_entered));
} break;
case DisplayServer::WINDOW_EVENT_FOCUS_OUT: {
focused = false;
if (focused_window == this) {
focused_window = nullptr;
}
_propagate_window_notification(this, NOTIFICATION_WM_WINDOW_FOCUS_OUT);
emit_signal(SceneStringName(focus_exited));
} break;
@ -836,6 +858,9 @@ void Window::_event_callback(DisplayServer::WindowEvent p_event) {
case DisplayServer::WINDOW_EVENT_TITLEBAR_CHANGE: {
emit_signal(SNAME("titlebar_changed"));
} break;
case DisplayServer::WINDOW_EVENT_FORCE_CLOSE: {
hide();
} break;
}
}
@ -866,6 +891,36 @@ void Window::hide() {
set_visible(false);
}
void Window::_accessibility_notify_enter(Node *p_node) {
p_node->queue_accessibility_update();
if (p_node != this) {
const Window *window = Object::cast_to<Window>(p_node);
if (window && !window->is_embedded()) {
return;
}
}
for (int i = 0; i < p_node->get_child_count(); i++) {
_accessibility_notify_enter(p_node->get_child(i));
}
}
void Window::_accessibility_notify_exit(Node *p_node) {
p_node->notification(Node::NOTIFICATION_ACCESSIBILITY_INVALIDATE);
if (p_node != this) {
const Window *window = Object::cast_to<Window>(p_node);
if (window && !window->is_embedded()) {
return;
}
}
for (int i = 0; i < p_node->get_child_count(); i++) {
_accessibility_notify_exit(p_node->get_child(i));
}
}
void Window::set_visible(bool p_visible) {
ERR_MAIN_THREAD_GUARD;
if (visible == p_visible) {
@ -905,9 +960,11 @@ void Window::set_visible(bool p_visible) {
}
}
embedder->_sub_window_register(this);
embedder->queue_accessibility_update();
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_WHEN_PARENT_VISIBLE);
} else {
embedder->_sub_window_remove(this);
embedder->queue_accessibility_update();
embedder = nullptr;
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
}
@ -916,7 +973,11 @@ void Window::set_visible(bool p_visible) {
if (!visible) {
focused = false;
if (focused_window == this) {
focused_window = nullptr;
}
}
notification(NOTIFICATION_VISIBILITY_CHANGED);
emit_signal(SceneStringName(visibility_changed));
@ -1133,7 +1194,7 @@ void Window::_update_viewport_size() {
//update the viewport part
Size2i final_size;
Size2i final_size_override;
Size2 final_size_override;
Rect2i attach_to_screen_rect(Point2i(), size);
double font_oversampling = 1.0;
window_transform = Transform2D();
@ -1330,9 +1391,78 @@ Viewport *Window::get_embedder() const {
return nullptr;
}
RID Window::get_accessibility_element() const {
if (is_part_of_edited_scene()) {
return RID();
}
if (get_embedder()) {
return Node::get_accessibility_element();
} else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
return DisplayServer::get_singleton()->accessibility_get_window_root(window_id);
} else {
return RID();
}
}
RID Window::get_focused_accessibility_element() const {
if (window_id == DisplayServer::MAIN_WINDOW_ID) {
if (get_child_count() > 0) {
return get_child(0)->get_focused_accessibility_element(); // Try scene tree root node.
}
}
return Node::get_focused_accessibility_element();
}
void Window::_notification(int p_what) {
ERR_MAIN_THREAD_GUARD;
switch (p_what) {
case NOTIFICATION_ACCESSIBILITY_INVALIDATE: {
accessibility_title_element = RID();
accessibility_announcement_element = RID();
} break;
case NOTIFICATION_ACCESSIBILITY_UPDATE: {
RID ae = get_accessibility_element();
ERR_FAIL_COND(ae.is_null());
DisplayServer::get_singleton()->accessibility_update_set_role(ae, DisplayServer::AccessibilityRole::ROLE_WINDOW);
DisplayServer::get_singleton()->accessibility_update_set_name(ae, tr_title);
DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_MODAL, exclusive);
DisplayServer::get_singleton()->accessibility_update_add_action(ae, DisplayServer::AccessibilityAction::ACTION_FOCUS, callable_mp(this, &Window::_accessibility_action_grab_focus));
DisplayServer::get_singleton()->accessibility_update_set_flag(ae, DisplayServer::AccessibilityFlags::FLAG_HIDDEN, !visible);
if (get_embedder()) {
Control *parent_ctrl = Object::cast_to<Control>(get_parent());
Transform2D parent_tr = parent_ctrl ? parent_ctrl->get_global_transform() : Transform2D();
Transform2D tr;
tr.set_origin(position);
DisplayServer::get_singleton()->accessibility_update_set_transform(ae, parent_tr.affine_inverse() * tr);
DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, Rect2(Point2(), size));
if (accessibility_title_element.is_null()) {
accessibility_title_element = DisplayServer::get_singleton()->accessibility_create_sub_element(ae, DisplayServer::AccessibilityRole::ROLE_TITLE_BAR);
}
int w = get_theme_constant(SNAME("title_height"));
DisplayServer::get_singleton()->accessibility_update_set_name(accessibility_title_element, tr_title);
DisplayServer::get_singleton()->accessibility_update_set_bounds(accessibility_title_element, Rect2(Vector2(0, -w), Size2(size.x, w)));
} else {
DisplayServer::get_singleton()->accessibility_update_set_transform(ae, Transform2D());
DisplayServer::get_singleton()->accessibility_update_set_bounds(ae, Rect2(Point2(), size));
if (accessibility_announcement_element.is_null()) {
accessibility_announcement_element = DisplayServer::get_singleton()->accessibility_create_sub_element(ae, DisplayServer::AccessibilityRole::ROLE_STATIC_TEXT);
}
if (announcement.is_empty()) {
DisplayServer::get_singleton()->accessibility_update_set_live(accessibility_announcement_element, DisplayServer::LIVE_OFF);
} else {
DisplayServer::get_singleton()->accessibility_update_set_name(accessibility_announcement_element, announcement);
DisplayServer::get_singleton()->accessibility_update_set_live(accessibility_announcement_element, DisplayServer::LIVE_ASSERTIVE);
}
}
} break;
case NOTIFICATION_POSTINITIALIZE: {
initialized = true;
@ -1387,6 +1517,7 @@ void Window::_notification(int p_what) {
// It's the root window!
visible = true; // Always visible.
window_id = DisplayServer::MAIN_WINDOW_ID;
focused_window = this;
DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id);
_update_from_window();
// Since this window already exists (created on start), we must update pos and size from it.
@ -1465,6 +1596,7 @@ void Window::_notification(int p_what) {
}
}
}
queue_accessibility_update();
} break;
case NOTIFICATION_VISIBILITY_CHANGED: {
@ -1483,6 +1615,9 @@ void Window::_notification(int p_what) {
set_theme_context(nullptr, false);
accessibility_title_element = RID();
accessibility_announcement_element = RID();
if (transient) {
_clear_transient();
}
@ -1602,7 +1737,12 @@ bool Window::is_using_font_oversampling() const {
DisplayServer::WindowID Window::get_window_id() const {
ERR_READ_THREAD_GUARD_V(DisplayServer::INVALID_WINDOW_ID);
if (embedder) {
if (get_embedder()) {
#ifdef TOOLS_ENABLED
if (is_part_of_edited_scene()) {
return DisplayServer::MAIN_WINDOW_ID;
}
#endif
return parent->get_window_id();
}
return window_id;
@ -1860,12 +2000,19 @@ void Window::popup(const Rect2i &p_screen_rect) {
// Update window size to calculate the actual window size based on contents minimum size and minimum size.
_update_window_size();
bool should_fit = !DisplayServer::get_singleton()->has_feature(DisplayServer::FEATURE_SELF_FITTING_WINDOWS);
if (p_screen_rect != Rect2i()) {
set_position(p_screen_rect.position);
int screen_id = DisplayServer::get_singleton()->get_screen_from_rect(p_screen_rect);
Size2i screen_size = DisplayServer::get_singleton()->screen_get_usable_rect(screen_id).size;
Size2i new_size = p_screen_rect.size.min(screen_size);
set_size(new_size);
if (should_fit) {
int screen_id = DisplayServer::get_singleton()->get_screen_from_rect(p_screen_rect);
Size2i screen_size = DisplayServer::get_singleton()->screen_get_usable_rect(screen_id).size;
Size2i new_size = p_screen_rect.size.min(screen_size);
set_size(new_size);
} else {
set_size(p_screen_rect.size);
}
}
Rect2i adjust = _popup_adjust_rect();
@ -1893,7 +2040,7 @@ void Window::popup(const Rect2i &p_screen_rect) {
int screen_id = DisplayServer::get_singleton()->window_get_current_screen(get_window_id());
parent_rect = DisplayServer::get_singleton()->screen_get_usable_rect(screen_id);
}
if (parent_rect != Rect2i() && !parent_rect.intersects(Rect2i(position, size))) {
if (should_fit && parent_rect != Rect2i() && !parent_rect.intersects(Rect2i(position, size))) {
ERR_PRINT(vformat("Window %d spawned at invalid position: %s.", get_window_id(), position));
set_position((parent_rect.size - size) / 2);
}
@ -2071,6 +2218,11 @@ Rect2i Window::get_usable_parent_rect() const {
return parent_rect;
}
void Window::accessibility_announcement(const String &p_announcement) {
announcement = p_announcement;
queue_accessibility_update();
}
void Window::add_child_notify(Node *p_child) {
if (is_inside_tree() && wrap_controls) {
child_controls_changed();
@ -2372,6 +2524,18 @@ Variant Window::get_theme_item(Theme::DataType p_data_type, const StringName &p_
Ref<Texture2D> Window::get_editor_theme_icon(const StringName &p_name) const {
return get_theme_icon(p_name, SNAME("EditorIcons"));
}
Ref<Texture2D> Window::get_editor_theme_native_menu_icon(const StringName &p_name, bool p_global_menu, bool p_dark_mode) const {
if (!p_global_menu) {
return get_theme_icon(p_name, SNAME("EditorIcons"));
}
if (p_dark_mode && has_theme_icon(String(p_name) + "Dark", SNAME("EditorIcons"))) {
return get_theme_icon(String(p_name) + "Dark", SNAME("EditorIcons"));
} else if (!p_dark_mode && has_theme_icon(String(p_name) + "Light", SNAME("EditorIcons"))) {
return get_theme_icon(String(p_name) + "Light", SNAME("EditorIcons"));
}
return get_theme_icon(p_name, SNAME("EditorIcons"));
}
#endif
bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
@ -2885,8 +3049,6 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_title", "title"), &Window::set_title);
ClassDB::bind_method(D_METHOD("get_title"), &Window::get_title);
ClassDB::bind_method(D_METHOD("get_window_id"), &Window::get_window_id);
ClassDB::bind_method(D_METHOD("set_initial_position", "initial_position"), &Window::set_initial_position);
ClassDB::bind_method(D_METHOD("get_initial_position"), &Window::get_initial_position);
@ -3034,6 +3196,10 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_theme_default_font"), &Window::get_theme_default_font);
ClassDB::bind_method(D_METHOD("get_theme_default_font_size"), &Window::get_theme_default_font_size);
ClassDB::bind_method(D_METHOD("get_window_id"), &Window::get_window_id);
ClassDB::bind_static_method("Window", D_METHOD("get_focused_window"), &Window::get_focused_window);
ClassDB::bind_method(D_METHOD("set_layout_direction", "direction"), &Window::set_layout_direction);
ClassDB::bind_method(D_METHOD("get_layout_direction"), &Window::get_layout_direction);
ClassDB::bind_method(D_METHOD("is_layout_rtl"), &Window::is_layout_rtl);
@ -3084,6 +3250,9 @@ void Window::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "mouse_passthrough"), "set_flag", "get_flag", FLAG_MOUSE_PASSTHROUGH);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "sharp_corners"), "set_flag", "get_flag", FLAG_SHARP_CORNERS);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "exclude_from_capture"), "set_flag", "get_flag", FLAG_EXCLUDE_FROM_CAPTURE);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "popup_wm_hint"), "set_flag", "get_flag", FLAG_POPUP_WM_HINT);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "minimize_disabled"), "set_flag", "get_flag", FLAG_MINIMIZE_DISABLED);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "maximize_disabled"), "set_flag", "get_flag", FLAG_MAXIMIZE_DISABLED);
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "force_native"), "set_force_native", "get_force_native");
ADD_GROUP("Limits", "");
@ -3140,6 +3309,9 @@ void Window::_bind_methods() {
BIND_ENUM_CONSTANT(FLAG_MOUSE_PASSTHROUGH);
BIND_ENUM_CONSTANT(FLAG_SHARP_CORNERS);
BIND_ENUM_CONSTANT(FLAG_EXCLUDE_FROM_CAPTURE);
BIND_ENUM_CONSTANT(FLAG_POPUP_WM_HINT);
BIND_ENUM_CONSTANT(FLAG_MINIMIZE_DISABLED);
BIND_ENUM_CONSTANT(FLAG_MAXIMIZE_DISABLED);
BIND_ENUM_CONSTANT(FLAG_MAX);
BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_DISABLED);
@ -3204,6 +3376,9 @@ Window::Window() {
}
Window::~Window() {
if (focused_window == this) {
focused_window = nullptr;
}
memdelete(theme_owner);
// Resources need to be disconnected.