diff options
Diffstat (limited to 'scene/main/window.cpp')
-rw-r--r-- | scene/main/window.cpp | 142 |
1 files changed, 75 insertions, 67 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp index c345c3d179..71ec9b29c5 100644 --- a/scene/main/window.cpp +++ b/scene/main/window.cpp @@ -270,20 +270,21 @@ void Window::set_title(const String &p_title) { ERR_MAIN_THREAD_GUARD; title = p_title; + tr_title = atr(p_title); +#ifdef DEBUG_ENABLED + if (window_id == DisplayServer::MAIN_WINDOW_ID) { + // Append a suffix to the window title to denote that the project is running + // from a debug build (including the editor). Since this results in lower performance, + // this should be clearly presented to the user. + tr_title = vformat("%s (DEBUG)", tr_title); + } +#endif if (embedder) { embedder->_sub_window_update(this); } else if (window_id != DisplayServer::INVALID_WINDOW_ID) { - String tr_title = atr(p_title); -#ifdef DEBUG_ENABLED - if (window_id == DisplayServer::MAIN_WINDOW_ID) { - // Append a suffix to the window title to denote that the project is running - // from a debug build (including the editor). Since this results in lower performance, - // this should be clearly presented to the user. - tr_title = vformat("%s (DEBUG)", tr_title); - } -#endif DisplayServer::get_singleton()->window_set_title(tr_title, window_id); + _update_window_size(); } } @@ -586,15 +587,6 @@ void Window::_make_window() { DisplayServer::get_singleton()->window_set_max_size(Size2i(), window_id); DisplayServer::get_singleton()->window_set_min_size(Size2i(), window_id); DisplayServer::get_singleton()->window_set_mouse_passthrough(mpath, window_id); - String tr_title = atr(title); -#ifdef DEBUG_ENABLED - if (window_id == DisplayServer::MAIN_WINDOW_ID) { - // Append a suffix to the window title to denote that the project is running - // from a debug build (including the editor). Since this results in lower performance, - // this should be clearly presented to the user. - tr_title = vformat("%s (DEBUG)", tr_title); - } -#endif DisplayServer::get_singleton()->window_set_title(tr_title, window_id); DisplayServer::get_singleton()->window_attach_instance_id(get_instance_id(), window_id); @@ -829,16 +821,7 @@ void Window::set_visible(bool p_visible) { //update transient exclusive if (transient_parent) { - if (exclusive && visible) { - if (!is_in_edited_scene_root()) { - ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child."); - transient_parent->exclusive_child = this; - } - } else { - if (transient_parent->exclusive_child == this) { - transient_parent->exclusive_child = nullptr; - } - } + _set_transient_exclusive_child(true); } } @@ -878,15 +861,7 @@ void Window::_make_transient() { if (window) { transient_parent = window; window->transient_children.insert(this); - if (is_inside_tree() && is_visible() && exclusive) { - if (transient_parent->exclusive_child == nullptr) { - if (!is_in_edited_scene_root()) { - transient_parent->exclusive_child = this; - } - } else if (transient_parent->exclusive_child != this) { - ERR_PRINT("Making child transient exclusive, but parent has another exclusive child"); - } - } + _set_transient_exclusive_child(); } //see if we can make transient @@ -895,6 +870,22 @@ void Window::_make_transient() { } } +void Window::_set_transient_exclusive_child(bool p_clear_invalid) { + if (exclusive && visible && is_inside_tree()) { + if (!is_in_edited_scene_root()) { + // Transient parent has another exclusive child. + if (transient_parent->exclusive_child && transient_parent->exclusive_child != this) { + ERR_PRINT(vformat("Attempting to make child window exclusive, but the parent window already has another exclusive child. This window: %s, parent window: %s, current exclusive child window: %s", this->get_description(), transient_parent->get_description(), transient_parent->exclusive_child->get_description())); + } + transient_parent->exclusive_child = this; + } + } else if (p_clear_invalid) { + if (transient_parent->exclusive_child == this) { + transient_parent->exclusive_child = nullptr; + } + } +} + void Window::set_transient(bool p_transient) { ERR_MAIN_THREAD_GUARD; if (transient == p_transient) { @@ -936,16 +927,7 @@ void Window::set_exclusive(bool p_exclusive) { } if (transient_parent) { - if (p_exclusive && is_inside_tree() && is_visible()) { - ERR_FAIL_COND_MSG(transient_parent->exclusive_child && transient_parent->exclusive_child != this, "Transient parent has another exclusive child."); - if (!is_in_edited_scene_root()) { - transient_parent->exclusive_child = this; - } - } else { - if (transient_parent->exclusive_child == this) { - transient_parent->exclusive_child = nullptr; - } - } + _set_transient_exclusive_child(true); } } @@ -1004,6 +986,12 @@ void Window::_update_window_size() { } DisplayServer::get_singleton()->window_set_max_size(max_size_used, window_id); + + if (keep_title_visible) { + Size2i title_size = DisplayServer::get_singleton()->window_get_title_size(tr_title, window_id); + size_limit = size_limit.max(title_size); + } + DisplayServer::get_singleton()->window_set_min_size(size_limit, window_id); DisplayServer::get_singleton()->window_set_size(size, window_id); } @@ -1291,17 +1279,19 @@ void Window::_notification(int p_what) { _invalidate_theme_cache(); _update_theme_item_cache(); - if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID) { - String tr_title = atr(title); + tr_title = atr(title); #ifdef DEBUG_ENABLED - if (window_id == DisplayServer::MAIN_WINDOW_ID) { - // Append a suffix to the window title to denote that the project is running - // from a debug build (including the editor). Since this results in lower performance, - // this should be clearly presented to the user. - tr_title = vformat("%s (DEBUG)", tr_title); - } + if (window_id == DisplayServer::MAIN_WINDOW_ID) { + // Append a suffix to the window title to denote that the project is running + // from a debug build (including the editor). Since this results in lower performance, + // this should be clearly presented to the user. + tr_title = vformat("%s (DEBUG)", tr_title); + } #endif + + if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID) { DisplayServer::get_singleton()->window_set_title(tr_title, window_id); + _update_window_size(); } } break; @@ -1394,6 +1384,20 @@ Window::ContentScaleStretch Window::get_content_scale_stretch() const { return content_scale_stretch; } +void Window::set_keep_title_visible(bool p_title_visible) { + if (keep_title_visible == p_title_visible) { + return; + } + keep_title_visible = p_title_visible; + if (window_id != DisplayServer::INVALID_WINDOW_ID) { + _update_window_size(); + } +} + +bool Window::get_keep_title_visible() const { + return keep_title_visible; +} + void Window::set_content_scale_factor(real_t p_factor) { ERR_MAIN_THREAD_GUARD; ERR_FAIL_COND(p_factor <= 0); @@ -1999,7 +2003,7 @@ StringName Window::get_theme_type_variation() const { Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<Texture2D>()); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2023,7 +2027,7 @@ Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<StyleBox>()); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2047,7 +2051,7 @@ Ref<StyleBox> Window::get_theme_stylebox(const StringName &p_name, const StringN Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Ref<Font>()); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2071,7 +2075,7 @@ Ref<Font> Window::get_theme_font(const StringName &p_name, const StringName &p_t int Window::get_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(0); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2095,7 +2099,7 @@ int Window::get_theme_font_size(const StringName &p_name, const StringName &p_th Color Window::get_theme_color(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(Color()); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2119,7 +2123,7 @@ Color Window::get_theme_color(const StringName &p_name, const StringName &p_them int Window::get_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(0); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2170,7 +2174,7 @@ Ref<Texture2D> Window::get_editor_theme_icon(const StringName &p_name) const { bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2187,7 +2191,7 @@ bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_ bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2204,7 +2208,7 @@ bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_th bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2221,7 +2225,7 @@ bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_ bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2238,7 +2242,7 @@ bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_t bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2255,7 +2259,7 @@ bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme bool Window::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const { ERR_READ_THREAD_GUARD_V(false); if (!initialized) { - WARN_PRINT_ONCE("Attempting to access theme items too early; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED"); + WARN_PRINT_ONCE(vformat("Attempting to access theme items too early in %s; prefer NOTIFICATION_POSTINITIALIZE and NOTIFICATION_THEME_CHANGED", this->get_description())); } if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) { @@ -2723,6 +2727,9 @@ void Window::_bind_methods() { ClassDB::bind_method(D_METHOD("set_content_scale_stretch", "stretch"), &Window::set_content_scale_stretch); ClassDB::bind_method(D_METHOD("get_content_scale_stretch"), &Window::get_content_scale_stretch); + ClassDB::bind_method(D_METHOD("set_keep_title_visible", "title_visible"), &Window::set_keep_title_visible); + ClassDB::bind_method(D_METHOD("get_keep_title_visible"), &Window::get_keep_title_visible); + ClassDB::bind_method(D_METHOD("set_content_scale_factor", "factor"), &Window::set_content_scale_factor); ClassDB::bind_method(D_METHOD("get_content_scale_factor"), &Window::get_content_scale_factor); @@ -2836,6 +2843,7 @@ void Window::_bind_methods() { ADD_GROUP("Limits", ""); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "min_size", PROPERTY_HINT_NONE, "suffix:px"), "set_min_size", "get_min_size"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "max_size", PROPERTY_HINT_NONE, "suffix:px"), "set_max_size", "get_max_size"); + ADD_PROPERTY(PropertyInfo(Variant::BOOL, "keep_title_visible"), "set_keep_title_visible", "get_keep_title_visible"); ADD_GROUP("Content Scale", "content_scale_"); ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "content_scale_size"), "set_content_scale_size", "get_content_scale_size"); |