summaryrefslogtreecommitdiff
path: root/scene/main/window.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'scene/main/window.cpp')
-rw-r--r--scene/main/window.cpp866
1 files changed, 740 insertions, 126 deletions
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 8fb497113d..663dd586c0 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -1,32 +1,32 @@
-/*************************************************************************/
-/* window.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* https://godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2022 Juan Linietsky, Ariel Manzur. */
-/* Copyright (c) 2014-2022 Godot Engine contributors (cf. AUTHORS.md). */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
+/**************************************************************************/
+/* window.cpp */
+/**************************************************************************/
+/* This file is part of: */
+/* GODOT ENGINE */
+/* https://godotengine.org */
+/**************************************************************************/
+/* Copyright (c) 2014-present Godot Engine contributors (see AUTHORS.md). */
+/* Copyright (c) 2007-2014 Juan Linietsky, Ariel Manzur. */
+/* */
+/* Permission is hereby granted, free of charge, to any person obtaining */
+/* a copy of this software and associated documentation files (the */
+/* "Software"), to deal in the Software without restriction, including */
+/* without limitation the rights to use, copy, modify, merge, publish, */
+/* distribute, sublicense, and/or sell copies of the Software, and to */
+/* permit persons to whom the Software is furnished to do so, subject to */
+/* the following conditions: */
+/* */
+/* The above copyright notice and this permission notice shall be */
+/* included in all copies or substantial portions of the Software. */
+/* */
+/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
+/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
+/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. */
+/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
+/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
+/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
+/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
+/**************************************************************************/
#include "window.h"
@@ -40,6 +40,226 @@
#include "scene/theme/theme_db.h"
#include "scene/theme/theme_owner.h"
+// Dynamic properties.
+
+bool Window::_set(const StringName &p_name, const Variant &p_value) {
+ String name = p_name;
+ if (!name.begins_with("theme_override")) {
+ return false;
+ }
+
+ if (p_value.get_type() == Variant::NIL || (p_value.get_type() == Variant::OBJECT && (Object *)p_value == nullptr)) {
+ if (name.begins_with("theme_override_icons/")) {
+ String dname = name.get_slicec('/', 1);
+ if (theme_icon_override.has(dname)) {
+ theme_icon_override[dname]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+ theme_icon_override.erase(dname);
+ _notify_theme_override_changed();
+ } else if (name.begins_with("theme_override_styles/")) {
+ String dname = name.get_slicec('/', 1);
+ if (theme_style_override.has(dname)) {
+ theme_style_override[dname]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+ theme_style_override.erase(dname);
+ _notify_theme_override_changed();
+ } else if (name.begins_with("theme_override_fonts/")) {
+ String dname = name.get_slicec('/', 1);
+ if (theme_font_override.has(dname)) {
+ theme_font_override[dname]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+ theme_font_override.erase(dname);
+ _notify_theme_override_changed();
+ } else if (name.begins_with("theme_override_font_sizes/")) {
+ String dname = name.get_slicec('/', 1);
+ theme_font_size_override.erase(dname);
+ _notify_theme_override_changed();
+ } else if (name.begins_with("theme_override_colors/")) {
+ String dname = name.get_slicec('/', 1);
+ theme_color_override.erase(dname);
+ _notify_theme_override_changed();
+ } else if (name.begins_with("theme_override_constants/")) {
+ String dname = name.get_slicec('/', 1);
+ theme_constant_override.erase(dname);
+ _notify_theme_override_changed();
+ } else {
+ return false;
+ }
+
+ } else {
+ if (name.begins_with("theme_override_icons/")) {
+ String dname = name.get_slicec('/', 1);
+ add_theme_icon_override(dname, p_value);
+ } else if (name.begins_with("theme_override_styles/")) {
+ String dname = name.get_slicec('/', 1);
+ add_theme_style_override(dname, p_value);
+ } else if (name.begins_with("theme_override_fonts/")) {
+ String dname = name.get_slicec('/', 1);
+ add_theme_font_override(dname, p_value);
+ } else if (name.begins_with("theme_override_font_sizes/")) {
+ String dname = name.get_slicec('/', 1);
+ add_theme_font_size_override(dname, p_value);
+ } else if (name.begins_with("theme_override_colors/")) {
+ String dname = name.get_slicec('/', 1);
+ add_theme_color_override(dname, p_value);
+ } else if (name.begins_with("theme_override_constants/")) {
+ String dname = name.get_slicec('/', 1);
+ add_theme_constant_override(dname, p_value);
+ } else {
+ return false;
+ }
+ }
+ return true;
+}
+
+bool Window::_get(const StringName &p_name, Variant &r_ret) const {
+ String sname = p_name;
+ if (!sname.begins_with("theme_override")) {
+ return false;
+ }
+
+ if (sname.begins_with("theme_override_icons/")) {
+ String name = sname.get_slicec('/', 1);
+ r_ret = theme_icon_override.has(name) ? Variant(theme_icon_override[name]) : Variant();
+ } else if (sname.begins_with("theme_override_styles/")) {
+ String name = sname.get_slicec('/', 1);
+ r_ret = theme_style_override.has(name) ? Variant(theme_style_override[name]) : Variant();
+ } else if (sname.begins_with("theme_override_fonts/")) {
+ String name = sname.get_slicec('/', 1);
+ r_ret = theme_font_override.has(name) ? Variant(theme_font_override[name]) : Variant();
+ } else if (sname.begins_with("theme_override_font_sizes/")) {
+ String name = sname.get_slicec('/', 1);
+ r_ret = theme_font_size_override.has(name) ? Variant(theme_font_size_override[name]) : Variant();
+ } else if (sname.begins_with("theme_override_colors/")) {
+ String name = sname.get_slicec('/', 1);
+ r_ret = theme_color_override.has(name) ? Variant(theme_color_override[name]) : Variant();
+ } else if (sname.begins_with("theme_override_constants/")) {
+ String name = sname.get_slicec('/', 1);
+ r_ret = theme_constant_override.has(name) ? Variant(theme_constant_override[name]) : Variant();
+ } else {
+ return false;
+ }
+
+ return true;
+}
+
+void Window::_get_property_list(List<PropertyInfo> *p_list) const {
+ Ref<Theme> default_theme = ThemeDB::get_singleton()->get_default_theme();
+
+ p_list->push_back(PropertyInfo(Variant::NIL, TTRC("Theme Overrides"), PROPERTY_HINT_NONE, "theme_override_", PROPERTY_USAGE_GROUP));
+
+ {
+ List<StringName> names;
+ default_theme->get_color_list(get_class_name(), &names);
+ for (const StringName &E : names) {
+ uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
+ if (theme_color_override.has(E)) {
+ usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
+
+ p_list->push_back(PropertyInfo(Variant::COLOR, "theme_override_colors/" + E, PROPERTY_HINT_NONE, "", usage));
+ }
+ }
+ {
+ List<StringName> names;
+ default_theme->get_constant_list(get_class_name(), &names);
+ for (const StringName &E : names) {
+ uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
+ if (theme_constant_override.has(E)) {
+ usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
+
+ p_list->push_back(PropertyInfo(Variant::INT, "theme_override_constants/" + E, PROPERTY_HINT_RANGE, "-16384,16384", usage));
+ }
+ }
+ {
+ List<StringName> names;
+ default_theme->get_font_list(get_class_name(), &names);
+ for (const StringName &E : names) {
+ uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
+ if (theme_font_override.has(E)) {
+ usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
+
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_fonts/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Font", usage));
+ }
+ }
+ {
+ List<StringName> names;
+ default_theme->get_font_size_list(get_class_name(), &names);
+ for (const StringName &E : names) {
+ uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
+ if (theme_font_size_override.has(E)) {
+ usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
+
+ p_list->push_back(PropertyInfo(Variant::INT, "theme_override_font_sizes/" + E, PROPERTY_HINT_RANGE, "1,256,1,or_greater,suffix:px", usage));
+ }
+ }
+ {
+ List<StringName> names;
+ default_theme->get_icon_list(get_class_name(), &names);
+ for (const StringName &E : names) {
+ uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
+ if (theme_icon_override.has(E)) {
+ usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
+
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_icons/" + E, PROPERTY_HINT_RESOURCE_TYPE, "Texture2D", usage));
+ }
+ }
+ {
+ List<StringName> names;
+ default_theme->get_stylebox_list(get_class_name(), &names);
+ for (const StringName &E : names) {
+ uint32_t usage = PROPERTY_USAGE_EDITOR | PROPERTY_USAGE_CHECKABLE;
+ if (theme_style_override.has(E)) {
+ usage |= PROPERTY_USAGE_STORAGE | PROPERTY_USAGE_CHECKED;
+ }
+
+ p_list->push_back(PropertyInfo(Variant::OBJECT, "theme_override_styles/" + E, PROPERTY_HINT_RESOURCE_TYPE, "StyleBox", usage));
+ }
+ }
+}
+
+void Window::_validate_property(PropertyInfo &p_property) const {
+ if (p_property.name == "position" && initial_position != WINDOW_INITIAL_POSITION_ABSOLUTE) {
+ p_property.usage = PROPERTY_USAGE_NONE;
+ }
+
+ if (p_property.name == "current_screen" && initial_position != WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN) {
+ p_property.usage = PROPERTY_USAGE_NONE;
+ }
+
+ if (p_property.name == "theme_type_variation") {
+ List<StringName> names;
+
+ // Only the default theme and the project theme are used for the list of options.
+ // This is an imposed limitation to simplify the logic needed to leverage those options.
+ ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names);
+ if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
+ ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names);
+ }
+ names.sort_custom<StringName::AlphCompare>();
+
+ Vector<StringName> unique_names;
+ String hint_string;
+ for (const StringName &E : names) {
+ // Skip duplicate values.
+ if (unique_names.has(E)) {
+ continue;
+ }
+
+ hint_string += String(E) + ",";
+ unique_names.append(E);
+ }
+
+ p_property.hint_string = hint_string;
+ }
+}
+
+//
+
void Window::set_title(const String &p_title) {
title = p_title;
@@ -63,6 +283,15 @@ String Window::get_title() const {
return title;
}
+void Window::set_initial_position(Window::WindowInitialPosition p_initial_position) {
+ initial_position = p_initial_position;
+ notify_property_list_changed();
+}
+
+Window::WindowInitialPosition Window::get_initial_position() const {
+ return initial_position;
+}
+
void Window::set_current_screen(int p_screen) {
current_screen = p_screen;
if (window_id == DisplayServer::INVALID_WINDOW_ID) {
@@ -106,15 +335,44 @@ void Window::reset_size() {
set_size(Size2i());
}
-Size2i Window::get_real_size() const {
+Point2i Window::get_position_with_decorations() const {
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
- return DisplayServer::get_singleton()->window_get_real_size(window_id);
+ return DisplayServer::get_singleton()->window_get_position_with_decorations(window_id);
+ }
+ return position;
+}
+
+Size2i Window::get_size_with_decorations() const {
+ if (window_id != DisplayServer::INVALID_WINDOW_ID) {
+ return DisplayServer::get_singleton()->window_get_size_with_decorations(window_id);
}
return size;
}
+Size2i Window::_clamp_limit_size(const Size2i &p_limit_size) {
+ // Force window limits to respect size limitations of rendering server.
+ Size2i max_window_size = RS::get_singleton()->get_maximum_viewport_size();
+ if (max_window_size != Size2i()) {
+ return p_limit_size.clamp(Vector2i(), max_window_size);
+ } else {
+ return p_limit_size.max(Vector2i());
+ }
+}
+
+void Window::_validate_limit_size() {
+ // When max_size is invalid, max_size_used falls back to respect size limitations of rendering server.
+ bool max_size_valid = (max_size.x > 0 || max_size.y > 0) && max_size.x >= min_size.x && max_size.y >= min_size.y;
+ max_size_used = max_size_valid ? max_size : RS::get_singleton()->get_maximum_viewport_size();
+}
+
void Window::set_max_size(const Size2i &p_max_size) {
- max_size = p_max_size;
+ Size2i max_size_clamped = _clamp_limit_size(p_max_size);
+ if (max_size == max_size_clamped) {
+ return;
+ }
+ max_size = max_size_clamped;
+
+ _validate_limit_size();
_update_window_size();
}
@@ -123,7 +381,13 @@ Size2i Window::get_max_size() const {
}
void Window::set_min_size(const Size2i &p_min_size) {
- min_size = p_min_size;
+ Size2i min_size_clamped = _clamp_limit_size(p_min_size);
+ if (min_size == min_size_clamped) {
+ return;
+ }
+ min_size = min_size_clamped;
+
+ _validate_limit_size();
_update_window_size();
}
@@ -243,11 +507,21 @@ void Window::_make_window() {
}
DisplayServer::VSyncMode vsync_mode = DisplayServer::get_singleton()->window_get_vsync_mode(DisplayServer::MAIN_WINDOW_ID);
- window_id = DisplayServer::get_singleton()->create_sub_window(DisplayServer::WindowMode(mode), vsync_mode, f, Rect2i(position, size));
+ Rect2i window_rect;
+ if (initial_position == WINDOW_INITIAL_POSITION_ABSOLUTE) {
+ window_rect = Rect2i(position, size);
+ } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN) {
+ window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(DisplayServer::SCREEN_PRIMARY) + (DisplayServer::get_singleton()->screen_get_size(DisplayServer::SCREEN_PRIMARY) - size) / 2, size);
+ } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN) {
+ window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(DisplayServer::SCREEN_OF_MAIN_WINDOW) + (DisplayServer::get_singleton()->screen_get_size(DisplayServer::SCREEN_OF_MAIN_WINDOW) - size) / 2, size);
+ } else if (initial_position == WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN) {
+ window_rect = Rect2i(DisplayServer::get_singleton()->screen_get_position(current_screen) + (DisplayServer::get_singleton()->screen_get_size(current_screen) - size) / 2, size);
+ }
+ window_id = DisplayServer::get_singleton()->create_sub_window(DisplayServer::WindowMode(mode), vsync_mode, f, window_rect);
ERR_FAIL_COND(window_id == DisplayServer::INVALID_WINDOW_ID);
- DisplayServer::get_singleton()->window_set_current_screen(current_screen, window_id);
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) {
@@ -401,6 +675,7 @@ void Window::update_mouse_cursor_shape() {
mm.instantiate();
mm->set_position(pos);
mm->set_global_position(xform.xform(pos));
+ mm->set_device(InputEvent::DEVICE_ID_INTERNAL);
push_input(mm);
}
@@ -417,18 +692,18 @@ void Window::set_visible(bool p_visible) {
return;
}
- visible = p_visible;
-
if (!is_inside_tree()) {
+ visible = p_visible;
return;
}
- if (updating_child_controls) {
- _update_child_controls();
- }
-
ERR_FAIL_COND_MSG(get_parent() == nullptr, "Can't change visibility of main window.");
+ visible = p_visible;
+
+ // Stop any queued resizing, as the window will be resized right now.
+ updating_child_controls = false;
+
Viewport *embedder_vp = _get_embedder();
if (!embedder_vp) {
@@ -586,37 +861,35 @@ bool Window::is_visible() const {
return visible;
}
-void Window::_update_window_size() {
- Size2i size_limit;
- if (wrap_controls) {
- size_limit = get_contents_minimum_size();
+Size2i Window::_clamp_window_size(const Size2i &p_size) {
+ Size2i window_size_clamped = p_size;
+ Size2 minsize = get_clamped_minimum_size();
+ window_size_clamped = window_size_clamped.max(minsize);
+
+ if (max_size_used != Size2i()) {
+ window_size_clamped = window_size_clamped.min(max_size_used);
}
- size_limit.x = MAX(size_limit.x, min_size.x);
- size_limit.y = MAX(size_limit.y, min_size.y);
+ return window_size_clamped;
+}
+
+void Window::_update_window_size() {
+ Size2i size_limit = get_clamped_minimum_size();
- size.x = MAX(size_limit.x, size.x);
- size.y = MAX(size_limit.y, size.y);
+ size = size.max(size_limit);
bool reset_min_first = false;
- bool max_size_valid = false;
- if ((max_size.x > 0 || max_size.y > 0) && (max_size.x >= min_size.x && max_size.y >= min_size.y)) {
- max_size_valid = true;
+ if (max_size_used != Size2i()) {
+ // Force window size to respect size limitations of max_size_used.
+ size = size.min(max_size_used);
- if (size.x > max_size.x) {
- size.x = max_size.x;
- }
- if (size_limit.x > max_size.x) {
- size_limit.x = max_size.x;
+ if (size_limit.x > max_size_used.x) {
+ size_limit.x = max_size_used.x;
reset_min_first = true;
}
-
- if (size.y > max_size.y) {
- size.y = max_size.y;
- }
- if (size_limit.y > max_size.y) {
- size_limit.y = max_size.y;
+ if (size_limit.y > max_size_used.y) {
+ size_limit.y = max_size_used.y;
reset_min_first = true;
}
}
@@ -632,7 +905,7 @@ void Window::_update_window_size() {
DisplayServer::get_singleton()->window_set_min_size(Size2i(), window_id);
}
- DisplayServer::get_singleton()->window_set_max_size(max_size_valid ? max_size : Size2i(), window_id);
+ DisplayServer::get_singleton()->window_set_max_size(max_size_used, window_id);
DisplayServer::get_singleton()->window_set_min_size(size_limit, window_id);
DisplayServer::get_singleton()->window_set_size(size, window_id);
}
@@ -647,16 +920,13 @@ void Window::_update_viewport_size() {
Size2i final_size;
Size2i final_size_override;
Rect2i attach_to_screen_rect(Point2i(), size);
- Transform2D stretch_transform_new;
float font_oversampling = 1.0;
+ window_transform = Transform2D();
if (content_scale_mode == CONTENT_SCALE_MODE_DISABLED || content_scale_size.x == 0 || content_scale_size.y == 0) {
font_oversampling = content_scale_factor;
final_size = size;
final_size_override = Size2(size) / content_scale_factor;
-
- stretch_transform_new = Transform2D();
- stretch_transform_new.scale(Size2(content_scale_factor, content_scale_factor));
} else {
//actual screen video mode
Size2 video_mode = size;
@@ -732,20 +1002,24 @@ void Window::_update_viewport_size() {
attach_to_screen_rect = Rect2(margin, screen_size);
font_oversampling = (screen_size.x / viewport_size.x) * content_scale_factor;
- Size2 scale = Vector2(screen_size) / Vector2(final_size_override);
- stretch_transform_new.scale(scale);
-
+ window_transform.translate_local(margin);
} break;
case CONTENT_SCALE_MODE_VIEWPORT: {
final_size = (viewport_size / content_scale_factor).floor();
attach_to_screen_rect = Rect2(margin, screen_size);
+ window_transform.translate_local(margin);
+ if (final_size.x != 0 && final_size.y != 0) {
+ Transform2D scale_transform;
+ scale_transform.scale(Vector2(attach_to_screen_rect.size) / Vector2(final_size));
+ window_transform *= scale_transform;
+ }
} break;
}
}
bool allocate = is_inside_tree() && visible && (window_id != DisplayServer::INVALID_WINDOW_ID || embedder != nullptr);
- _set_size(final_size, final_size_override, attach_to_screen_rect, stretch_transform_new, allocate);
+ _set_size(final_size, final_size_override, allocate);
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), attach_to_screen_rect, window_id);
@@ -872,6 +1146,7 @@ void Window::_notification(int p_what) {
case NOTIFICATION_READY: {
if (wrap_controls) {
+ // Finish any resizing immediately so it doesn't interfere on stuff overriding _ready().
_update_child_controls();
}
} break;
@@ -880,9 +1155,7 @@ void Window::_notification(int p_what) {
_invalidate_theme_cache();
_update_theme_item_cache();
- if (embedder) {
- embedder->_sub_window_update(this);
- } else if (window_id != DisplayServer::INVALID_WINDOW_ID) {
+ if (!embedder && window_id != DisplayServer::INVALID_WINDOW_ID) {
String tr_title = atr(title);
#ifdef DEBUG_ENABLED
if (window_id == DisplayServer::MAIN_WINDOW_ID) {
@@ -894,8 +1167,6 @@ void Window::_notification(int p_what) {
#endif
DisplayServer::get_singleton()->window_set_title(tr_title, window_id);
}
-
- child_controls_changed();
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -982,10 +1253,27 @@ DisplayServer::WindowID Window::get_window_id() const {
return window_id;
}
+void Window::set_mouse_passthrough_polygon(const Vector<Vector2> &p_region) {
+ mpath = p_region;
+ if (window_id == DisplayServer::INVALID_WINDOW_ID) {
+ return;
+ }
+ DisplayServer::get_singleton()->window_set_mouse_passthrough(mpath, window_id);
+}
+
+Vector<Vector2> Window::get_mouse_passthrough_polygon() const {
+ return mpath;
+}
+
void Window::set_wrap_controls(bool p_enable) {
wrap_controls = p_enable;
- if (wrap_controls) {
- child_controls_changed();
+
+ if (!is_inside_tree()) {
+ return;
+ }
+
+ if (updating_child_controls) {
+ _update_child_controls();
} else {
_update_window_size();
}
@@ -1012,23 +1300,23 @@ Size2 Window::_get_contents_minimum_size() const {
return max;
}
-void Window::_update_child_controls() {
- if (!updating_child_controls) {
+void Window::child_controls_changed() {
+ if (!is_inside_tree() || !visible || updating_child_controls) {
return;
}
- _update_window_size();
-
- updating_child_controls = false;
+ updating_child_controls = true;
+ call_deferred(SNAME("_update_child_controls"));
}
-void Window::child_controls_changed() {
- if (!is_inside_tree() || !visible || updating_child_controls) {
+void Window::_update_child_controls() {
+ if (!updating_child_controls) {
return;
}
- updating_child_controls = true;
- call_deferred(SNAME("_update_child_controls"));
+ _update_window_size();
+
+ updating_child_controls = false;
}
bool Window::_can_consume_input_events() const {
@@ -1134,6 +1422,9 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio
ERR_FAIL_COND(!is_inside_tree());
ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window.");
+ // Consider the current size when calling with the default value.
+ Size2i expected_size = p_size == Size2i() ? size : p_size;
+
Rect2 parent_rect;
if (is_embedded()) {
@@ -1148,7 +1439,9 @@ void Window::popup_centered_clamped(const Size2i &p_size, float p_fallback_ratio
Vector2i size_ratio = parent_rect.size * p_fallback_ratio;
Rect2i popup_rect;
- popup_rect.size = Vector2i(MIN(size_ratio.x, p_size.x), MIN(size_ratio.y, p_size.y));
+ popup_rect.size = Vector2i(MIN(size_ratio.x, expected_size.x), MIN(size_ratio.y, expected_size.y));
+ popup_rect.size = _clamp_window_size(popup_rect.size);
+
if (parent_rect != Rect2()) {
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
@@ -1160,6 +1453,9 @@ void Window::popup_centered(const Size2i &p_minsize) {
ERR_FAIL_COND(!is_inside_tree());
ERR_FAIL_COND_MSG(window_id == DisplayServer::MAIN_WINDOW_ID, "Can't popup the main window.");
+ // Consider the current size when calling with the default value.
+ Size2i expected_size = p_minsize == Size2i() ? size : p_minsize;
+
Rect2 parent_rect;
if (is_embedded()) {
@@ -1172,9 +1468,7 @@ void Window::popup_centered(const Size2i &p_minsize) {
}
Rect2i popup_rect;
- Size2 contents_minsize = _get_contents_minimum_size();
- popup_rect.size.x = MAX(p_minsize.x, contents_minsize.x);
- popup_rect.size.y = MAX(p_minsize.y, contents_minsize.y);
+ popup_rect.size = _clamp_window_size(expected_size);
if (parent_rect != Rect2()) {
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
@@ -1202,6 +1496,7 @@ void Window::popup_centered_ratio(float p_ratio) {
Rect2i popup_rect;
if (parent_rect != Rect2()) {
popup_rect.size = parent_rect.size * p_ratio;
+ popup_rect.size = _clamp_window_size(popup_rect.size);
popup_rect.position = parent_rect.position + (parent_rect.size - popup_rect.size) / 2;
}
@@ -1265,6 +1560,14 @@ Size2 Window::get_contents_minimum_size() const {
return _get_contents_minimum_size();
}
+Size2 Window::get_clamped_minimum_size() const {
+ if (!wrap_controls) {
+ return min_size;
+ }
+
+ return min_size.max(get_contents_minimum_size());
+}
+
void Window::grab_focus() {
if (embedder) {
embedder->_sub_window_grab_focus(this);
@@ -1304,6 +1607,8 @@ void Window::remove_child_notify(Node *p_child) {
}
}
+// Theming.
+
void Window::set_theme_owner_node(Node *p_node) {
theme_owner->set_owner_node(p_node);
}
@@ -1357,6 +1662,12 @@ void Window::_theme_changed() {
}
}
+void Window::_notify_theme_override_changed() {
+ if (!bulk_theme_override && is_inside_tree()) {
+ notification(NOTIFICATION_THEME_CHANGED);
+ }
+}
+
void Window::_invalidate_theme_cache() {
theme_icon_cache.clear();
theme_style_cache.clear();
@@ -1367,6 +1678,26 @@ void Window::_invalidate_theme_cache() {
}
void Window::_update_theme_item_cache() {
+ // Request an update on the next frame to reflect theme changes.
+ // Updating without a delay can cause a lot of lag.
+ if (!wrap_controls) {
+ updating_embedded_window = true;
+ call_deferred(SNAME("_update_embedded_window"));
+ } else {
+ child_controls_changed();
+ }
+}
+
+void Window::_update_embedded_window() {
+ if (!updating_embedded_window) {
+ return;
+ }
+
+ if (embedder) {
+ embedder->_sub_window_update(this);
+ };
+
+ updating_embedded_window = false;
}
void Window::set_theme_type_variation(const StringName &p_theme_type) {
@@ -1380,7 +1711,16 @@ StringName Window::get_theme_type_variation() const {
return theme_type_variation;
}
+/// Theme property lookup.
+
Ref<Texture2D> Window::get_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ const Ref<Texture2D> *tex = theme_icon_override.getptr(p_name);
+ if (tex) {
+ return *tex;
+ }
+ }
+
if (theme_icon_cache.has(p_theme_type) && theme_icon_cache[p_theme_type].has(p_name)) {
return theme_icon_cache[p_theme_type][p_name];
}
@@ -1393,6 +1733,13 @@ 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 {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ const Ref<StyleBox> *style = theme_style_override.getptr(p_name);
+ if (style) {
+ return *style;
+ }
+ }
+
if (theme_style_cache.has(p_theme_type) && theme_style_cache[p_theme_type].has(p_name)) {
return theme_style_cache[p_theme_type][p_name];
}
@@ -1405,6 +1752,13 @@ 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 {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ const Ref<Font> *font = theme_font_override.getptr(p_name);
+ if (font) {
+ return *font;
+ }
+ }
+
if (theme_font_cache.has(p_theme_type) && theme_font_cache[p_theme_type].has(p_name)) {
return theme_font_cache[p_theme_type][p_name];
}
@@ -1417,6 +1771,13 @@ 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 {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ const int *font_size = theme_font_size_override.getptr(p_name);
+ if (font_size && (*font_size) > 0) {
+ return *font_size;
+ }
+ }
+
if (theme_font_size_cache.has(p_theme_type) && theme_font_size_cache[p_theme_type].has(p_name)) {
return theme_font_size_cache[p_theme_type][p_name];
}
@@ -1429,6 +1790,13 @@ 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 {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ const Color *color = theme_color_override.getptr(p_name);
+ if (color) {
+ return *color;
+ }
+ }
+
if (theme_color_cache.has(p_theme_type) && theme_color_cache[p_theme_type].has(p_name)) {
return theme_color_cache[p_theme_type][p_name];
}
@@ -1441,6 +1809,13 @@ 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 {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ const int *constant = theme_constant_override.getptr(p_name);
+ if (constant) {
+ return *constant;
+ }
+ }
+
if (theme_constant_cache.has(p_theme_type) && theme_constant_cache[p_theme_type].has(p_name)) {
return theme_constant_cache[p_theme_type][p_name];
}
@@ -1453,41 +1828,204 @@ int Window::get_theme_constant(const StringName &p_name, const StringName &p_the
}
bool Window::has_theme_icon(const StringName &p_name, const StringName &p_theme_type) const {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ if (has_theme_icon_override(p_name)) {
+ return true;
+ }
+ }
+
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_ICON, p_name, theme_types);
}
bool Window::has_theme_stylebox(const StringName &p_name, const StringName &p_theme_type) const {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ if (has_theme_stylebox_override(p_name)) {
+ return true;
+ }
+ }
+
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_STYLEBOX, p_name, theme_types);
}
bool Window::has_theme_font(const StringName &p_name, const StringName &p_theme_type) const {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ if (has_theme_font_override(p_name)) {
+ return true;
+ }
+ }
+
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT, p_name, theme_types);
}
bool Window::has_theme_font_size(const StringName &p_name, const StringName &p_theme_type) const {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ if (has_theme_font_size_override(p_name)) {
+ return true;
+ }
+ }
+
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_FONT_SIZE, p_name, theme_types);
}
bool Window::has_theme_color(const StringName &p_name, const StringName &p_theme_type) const {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ if (has_theme_color_override(p_name)) {
+ return true;
+ }
+ }
+
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_COLOR, p_name, theme_types);
}
bool Window::has_theme_constant(const StringName &p_name, const StringName &p_theme_type) const {
+ if (p_theme_type == StringName() || p_theme_type == get_class_name() || p_theme_type == theme_type_variation) {
+ if (has_theme_constant_override(p_name)) {
+ return true;
+ }
+ }
+
List<StringName> theme_types;
theme_owner->get_theme_type_dependencies(this, p_theme_type, &theme_types);
return theme_owner->has_theme_item_in_types(Theme::DATA_TYPE_CONSTANT, p_name, theme_types);
}
+/// Local property overrides.
+
+void Window::add_theme_icon_override(const StringName &p_name, const Ref<Texture2D> &p_icon) {
+ ERR_FAIL_COND(!p_icon.is_valid());
+
+ if (theme_icon_override.has(p_name)) {
+ theme_icon_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+
+ theme_icon_override[p_name] = p_icon;
+ theme_icon_override[p_name]->connect("changed", callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
+ _notify_theme_override_changed();
+}
+
+void Window::add_theme_style_override(const StringName &p_name, const Ref<StyleBox> &p_style) {
+ ERR_FAIL_COND(!p_style.is_valid());
+
+ if (theme_style_override.has(p_name)) {
+ theme_style_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+
+ theme_style_override[p_name] = p_style;
+ theme_style_override[p_name]->connect("changed", callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
+ _notify_theme_override_changed();
+}
+
+void Window::add_theme_font_override(const StringName &p_name, const Ref<Font> &p_font) {
+ ERR_FAIL_COND(!p_font.is_valid());
+
+ if (theme_font_override.has(p_name)) {
+ theme_font_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+
+ theme_font_override[p_name] = p_font;
+ theme_font_override[p_name]->connect("changed", callable_mp(this, &Window::_notify_theme_override_changed), CONNECT_REFERENCE_COUNTED);
+ _notify_theme_override_changed();
+}
+
+void Window::add_theme_font_size_override(const StringName &p_name, int p_font_size) {
+ theme_font_size_override[p_name] = p_font_size;
+ _notify_theme_override_changed();
+}
+
+void Window::add_theme_color_override(const StringName &p_name, const Color &p_color) {
+ theme_color_override[p_name] = p_color;
+ _notify_theme_override_changed();
+}
+
+void Window::add_theme_constant_override(const StringName &p_name, int p_constant) {
+ theme_constant_override[p_name] = p_constant;
+ _notify_theme_override_changed();
+}
+
+void Window::remove_theme_icon_override(const StringName &p_name) {
+ if (theme_icon_override.has(p_name)) {
+ theme_icon_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+
+ theme_icon_override.erase(p_name);
+ _notify_theme_override_changed();
+}
+
+void Window::remove_theme_style_override(const StringName &p_name) {
+ if (theme_style_override.has(p_name)) {
+ theme_style_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+
+ theme_style_override.erase(p_name);
+ _notify_theme_override_changed();
+}
+
+void Window::remove_theme_font_override(const StringName &p_name) {
+ if (theme_font_override.has(p_name)) {
+ theme_font_override[p_name]->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+
+ theme_font_override.erase(p_name);
+ _notify_theme_override_changed();
+}
+
+void Window::remove_theme_font_size_override(const StringName &p_name) {
+ theme_font_size_override.erase(p_name);
+ _notify_theme_override_changed();
+}
+
+void Window::remove_theme_color_override(const StringName &p_name) {
+ theme_color_override.erase(p_name);
+ _notify_theme_override_changed();
+}
+
+void Window::remove_theme_constant_override(const StringName &p_name) {
+ theme_constant_override.erase(p_name);
+ _notify_theme_override_changed();
+}
+
+bool Window::has_theme_icon_override(const StringName &p_name) const {
+ const Ref<Texture2D> *tex = theme_icon_override.getptr(p_name);
+ return tex != nullptr;
+}
+
+bool Window::has_theme_stylebox_override(const StringName &p_name) const {
+ const Ref<StyleBox> *style = theme_style_override.getptr(p_name);
+ return style != nullptr;
+}
+
+bool Window::has_theme_font_override(const StringName &p_name) const {
+ const Ref<Font> *font = theme_font_override.getptr(p_name);
+ return font != nullptr;
+}
+
+bool Window::has_theme_font_size_override(const StringName &p_name) const {
+ const int *font_size = theme_font_size_override.getptr(p_name);
+ return font_size != nullptr;
+}
+
+bool Window::has_theme_color_override(const StringName &p_name) const {
+ const Color *color = theme_color_override.getptr(p_name);
+ return color != nullptr;
+}
+
+bool Window::has_theme_constant_override(const StringName &p_name) const {
+ const int *constant = theme_constant_override.getptr(p_name);
+ return constant != nullptr;
+}
+
+/// Default theme properties.
+
float Window::get_theme_default_base_scale() const {
return theme_owner->get_theme_default_base_scale();
}
@@ -1500,6 +2038,21 @@ int Window::get_theme_default_font_size() const {
return theme_owner->get_theme_default_font_size();
}
+/// Bulk actions.
+
+void Window::begin_bulk_theme_override() {
+ bulk_theme_override = true;
+}
+
+void Window::end_bulk_theme_override() {
+ ERR_FAIL_COND(!bulk_theme_override);
+
+ bulk_theme_override = false;
+ _notify_theme_override_changed();
+}
+
+//
+
Rect2i Window::get_parent_rect() const {
ERR_FAIL_COND_V(!is_inside_tree(), Rect2i());
if (is_embedded()) {
@@ -1592,47 +2145,41 @@ bool Window::is_auto_translating() const {
return auto_translate;
}
-void Window::_validate_property(PropertyInfo &p_property) const {
- if (p_property.name == "theme_type_variation") {
- List<StringName> names;
-
- // Only the default theme and the project theme are used for the list of options.
- // This is an imposed limitation to simplify the logic needed to leverage those options.
- ThemeDB::get_singleton()->get_default_theme()->get_type_variation_list(get_class_name(), &names);
- if (ThemeDB::get_singleton()->get_project_theme().is_valid()) {
- ThemeDB::get_singleton()->get_project_theme()->get_type_variation_list(get_class_name(), &names);
- }
- names.sort_custom<StringName::AlphCompare>();
-
- Vector<StringName> unique_names;
- String hint_string;
- for (const StringName &E : names) {
- // Skip duplicate values.
- if (unique_names.has(E)) {
- continue;
- }
-
- hint_string += String(E) + ",";
- unique_names.append(E);
- }
+Transform2D Window::get_final_transform() const {
+ return window_transform * stretch_transform * global_canvas_transform;
+}
- p_property.hint_string = hint_string;
+Transform2D Window::get_screen_transform_internal(bool p_absolute_position) const {
+ Transform2D embedder_transform;
+ if (_get_embedder()) {
+ embedder_transform.translate_local(get_position());
+ embedder_transform = _get_embedder()->get_screen_transform_internal(p_absolute_position) * embedder_transform;
+ } else if (p_absolute_position) {
+ embedder_transform.translate_local(get_position());
}
+ return embedder_transform * get_final_transform();
}
-Transform2D Window::get_screen_transform() const {
- Transform2D embedder_transform = Transform2D();
+Transform2D Window::get_popup_base_transform() const {
+ if (is_embedding_subwindows()) {
+ return Transform2D();
+ }
+ Transform2D popup_base_transform;
+ popup_base_transform.set_origin(get_position());
+ popup_base_transform *= get_final_transform();
if (_get_embedder()) {
- embedder_transform.translate_local(get_position());
- embedder_transform = _get_embedder()->get_screen_transform() * embedder_transform;
+ return _get_embedder()->get_popup_base_transform() * popup_base_transform;
}
- return embedder_transform * Viewport::get_screen_transform();
+ return popup_base_transform;
}
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("set_initial_position", "initial_position"), &Window::set_initial_position);
+ ClassDB::bind_method(D_METHOD("get_initial_position"), &Window::get_initial_position);
+
ClassDB::bind_method(D_METHOD("set_current_screen", "index"), &Window::set_current_screen);
ClassDB::bind_method(D_METHOD("get_current_screen"), &Window::get_current_screen);
@@ -1643,7 +2190,8 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_size"), &Window::get_size);
ClassDB::bind_method(D_METHOD("reset_size"), &Window::reset_size);
- ClassDB::bind_method(D_METHOD("get_real_size"), &Window::get_real_size);
+ ClassDB::bind_method(D_METHOD("get_position_with_decorations"), &Window::get_position_with_decorations);
+ ClassDB::bind_method(D_METHOD("get_size_with_decorations"), &Window::get_size_with_decorations);
ClassDB::bind_method(D_METHOD("set_max_size", "max_size"), &Window::set_max_size);
ClassDB::bind_method(D_METHOD("get_max_size"), &Window::get_max_size);
@@ -1701,11 +2249,15 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_use_font_oversampling", "enable"), &Window::set_use_font_oversampling);
ClassDB::bind_method(D_METHOD("is_using_font_oversampling"), &Window::is_using_font_oversampling);
+ ClassDB::bind_method(D_METHOD("set_mouse_passthrough_polygon", "polygon"), &Window::set_mouse_passthrough_polygon);
+ ClassDB::bind_method(D_METHOD("get_mouse_passthrough_polygon"), &Window::get_mouse_passthrough_polygon);
+
ClassDB::bind_method(D_METHOD("set_wrap_controls", "enable"), &Window::set_wrap_controls);
ClassDB::bind_method(D_METHOD("is_wrapping_controls"), &Window::is_wrapping_controls);
ClassDB::bind_method(D_METHOD("child_controls_changed"), &Window::child_controls_changed);
ClassDB::bind_method(D_METHOD("_update_child_controls"), &Window::_update_child_controls);
+ ClassDB::bind_method(D_METHOD("_update_embedded_window"), &Window::_update_embedded_window);
ClassDB::bind_method(D_METHOD("set_theme", "theme"), &Window::set_theme);
ClassDB::bind_method(D_METHOD("get_theme"), &Window::get_theme);
@@ -1713,6 +2265,23 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_theme_type_variation", "theme_type"), &Window::set_theme_type_variation);
ClassDB::bind_method(D_METHOD("get_theme_type_variation"), &Window::get_theme_type_variation);
+ ClassDB::bind_method(D_METHOD("begin_bulk_theme_override"), &Window::begin_bulk_theme_override);
+ ClassDB::bind_method(D_METHOD("end_bulk_theme_override"), &Window::end_bulk_theme_override);
+
+ ClassDB::bind_method(D_METHOD("add_theme_icon_override", "name", "texture"), &Window::add_theme_icon_override);
+ ClassDB::bind_method(D_METHOD("add_theme_stylebox_override", "name", "stylebox"), &Window::add_theme_style_override);
+ ClassDB::bind_method(D_METHOD("add_theme_font_override", "name", "font"), &Window::add_theme_font_override);
+ ClassDB::bind_method(D_METHOD("add_theme_font_size_override", "name", "font_size"), &Window::add_theme_font_size_override);
+ ClassDB::bind_method(D_METHOD("add_theme_color_override", "name", "color"), &Window::add_theme_color_override);
+ ClassDB::bind_method(D_METHOD("add_theme_constant_override", "name", "constant"), &Window::add_theme_constant_override);
+
+ ClassDB::bind_method(D_METHOD("remove_theme_icon_override", "name"), &Window::remove_theme_icon_override);
+ ClassDB::bind_method(D_METHOD("remove_theme_stylebox_override", "name"), &Window::remove_theme_style_override);
+ ClassDB::bind_method(D_METHOD("remove_theme_font_override", "name"), &Window::remove_theme_font_override);
+ ClassDB::bind_method(D_METHOD("remove_theme_font_size_override", "name"), &Window::remove_theme_font_size_override);
+ ClassDB::bind_method(D_METHOD("remove_theme_color_override", "name"), &Window::remove_theme_color_override);
+ ClassDB::bind_method(D_METHOD("remove_theme_constant_override", "name"), &Window::remove_theme_constant_override);
+
ClassDB::bind_method(D_METHOD("get_theme_icon", "name", "theme_type"), &Window::get_theme_icon, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_theme_stylebox", "name", "theme_type"), &Window::get_theme_stylebox, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_theme_font", "name", "theme_type"), &Window::get_theme_font, DEFVAL(""));
@@ -1720,6 +2289,13 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("get_theme_color", "name", "theme_type"), &Window::get_theme_color, DEFVAL(""));
ClassDB::bind_method(D_METHOD("get_theme_constant", "name", "theme_type"), &Window::get_theme_constant, DEFVAL(""));
+ ClassDB::bind_method(D_METHOD("has_theme_icon_override", "name"), &Window::has_theme_icon_override);
+ ClassDB::bind_method(D_METHOD("has_theme_stylebox_override", "name"), &Window::has_theme_stylebox_override);
+ ClassDB::bind_method(D_METHOD("has_theme_font_override", "name"), &Window::has_theme_font_override);
+ ClassDB::bind_method(D_METHOD("has_theme_font_size_override", "name"), &Window::has_theme_font_size_override);
+ ClassDB::bind_method(D_METHOD("has_theme_color_override", "name"), &Window::has_theme_color_override);
+ ClassDB::bind_method(D_METHOD("has_theme_constant_override", "name"), &Window::has_theme_constant_override);
+
ClassDB::bind_method(D_METHOD("has_theme_icon", "name", "theme_type"), &Window::has_theme_icon, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_theme_stylebox", "name", "theme_type"), &Window::has_theme_stylebox, DEFVAL(""));
ClassDB::bind_method(D_METHOD("has_theme_font", "name", "theme_type"), &Window::has_theme_font, DEFVAL(""));
@@ -1744,11 +2320,16 @@ void Window::_bind_methods() {
ClassDB::bind_method(D_METHOD("popup_centered", "minsize"), &Window::popup_centered, DEFVAL(Size2i()));
ClassDB::bind_method(D_METHOD("popup_centered_clamped", "minsize", "fallback_ratio"), &Window::popup_centered_clamped, DEFVAL(Size2i()), DEFVAL(0.75));
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "initial_position", PROPERTY_HINT_ENUM, "Absolute,Primary Screen Center,Main Window Screen Center,Other Screen Center"), "set_initial_position", "get_initial_position");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "title"), "set_title", "get_title");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "position", PROPERTY_HINT_NONE, "suffix:px"), "set_position", "get_position");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "size", PROPERTY_HINT_NONE, "suffix:px"), "set_size", "get_size");
ADD_PROPERTY(PropertyInfo(Variant::INT, "mode", PROPERTY_HINT_ENUM, "Windowed,Minimized,Maximized,Fullscreen"), "set_mode", "get_mode");
- ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen"), "set_current_screen", "get_current_screen");
+
+ // Keep the enum values in sync with the `DisplayServer::SCREEN_` enum.
+ ADD_PROPERTY(PropertyInfo(Variant::INT, "current_screen", PROPERTY_HINT_RANGE, "0,64,1,or_greater"), "set_current_screen", "get_current_screen");
+
+ ADD_PROPERTY(PropertyInfo(Variant::PACKED_VECTOR2_ARRAY, "mouse_passthrough_polygon"), "set_mouse_passthrough_polygon", "get_mouse_passthrough_polygon");
ADD_GROUP("Flags", "");
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "visible"), "set_visible", "is_visible");
@@ -1762,6 +2343,7 @@ void Window::_bind_methods() {
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "unfocusable"), "set_flag", "get_flag", FLAG_NO_FOCUS);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "popup_window"), "set_flag", "get_flag", FLAG_POPUP);
ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "extend_to_title"), "set_flag", "get_flag", FLAG_EXTEND_TO_TITLE);
+ ADD_PROPERTYI(PropertyInfo(Variant::BOOL, "mouse_passthrough"), "set_flag", "get_flag", FLAG_MOUSE_PASSTHROUGH);
ADD_GROUP("Limits", "");
ADD_PROPERTY(PropertyInfo(Variant::VECTOR2I, "min_size", PROPERTY_HINT_NONE, "suffix:px"), "set_min_size", "get_min_size");
@@ -1773,13 +2355,13 @@ void Window::_bind_methods() {
ADD_PROPERTY(PropertyInfo(Variant::INT, "content_scale_aspect", PROPERTY_HINT_ENUM, "Ignore,Keep,Keep Width,Keep Height,Expand"), "set_content_scale_aspect", "get_content_scale_aspect");
ADD_PROPERTY(PropertyInfo(Variant::FLOAT, "content_scale_factor"), "set_content_scale_factor", "get_content_scale_factor");
+ ADD_GROUP("Localization", "");
+ ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
+
ADD_GROUP("Theme", "theme_");
ADD_PROPERTY(PropertyInfo(Variant::OBJECT, "theme", PROPERTY_HINT_RESOURCE_TYPE, "Theme"), "set_theme", "get_theme");
ADD_PROPERTY(PropertyInfo(Variant::STRING, "theme_type_variation", PROPERTY_HINT_ENUM_SUGGESTION), "set_theme_type_variation", "get_theme_type_variation");
- ADD_GROUP("Auto Translate", "");
- ADD_PROPERTY(PropertyInfo(Variant::BOOL, "auto_translate"), "set_auto_translate", "is_auto_translating");
-
ADD_SIGNAL(MethodInfo("window_input", PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent")));
ADD_SIGNAL(MethodInfo("files_dropped", PropertyInfo(Variant::PACKED_STRING_ARRAY, "files")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
@@ -1791,6 +2373,7 @@ void Window::_bind_methods() {
ADD_SIGNAL(MethodInfo("visibility_changed"));
ADD_SIGNAL(MethodInfo("about_to_popup"));
ADD_SIGNAL(MethodInfo("theme_changed"));
+ ADD_SIGNAL(MethodInfo("dpi_changed"));
ADD_SIGNAL(MethodInfo("titlebar_changed"));
BIND_CONSTANT(NOTIFICATION_VISIBILITY_CHANGED);
@@ -1809,6 +2392,7 @@ void Window::_bind_methods() {
BIND_ENUM_CONSTANT(FLAG_NO_FOCUS);
BIND_ENUM_CONSTANT(FLAG_POPUP);
BIND_ENUM_CONSTANT(FLAG_EXTEND_TO_TITLE);
+ BIND_ENUM_CONSTANT(FLAG_MOUSE_PASSTHROUGH);
BIND_ENUM_CONSTANT(FLAG_MAX);
BIND_ENUM_CONSTANT(CONTENT_SCALE_MODE_DISABLED);
@@ -1825,13 +2409,43 @@ void Window::_bind_methods() {
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LOCALE);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_LTR);
BIND_ENUM_CONSTANT(LAYOUT_DIRECTION_RTL);
+
+ BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_ABSOLUTE);
+ BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_PRIMARY_SCREEN);
+ BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_MAIN_WINDOW_SCREEN);
+ BIND_ENUM_CONSTANT(WINDOW_INITIAL_POSITION_CENTER_OTHER_SCREEN);
}
Window::Window() {
+ RenderingServer *rendering_server = RenderingServer::get_singleton();
+ if (rendering_server) {
+ max_size = rendering_server->get_maximum_viewport_size();
+ max_size_used = max_size; // Update max_size_used.
+ }
+
theme_owner = memnew(ThemeOwner);
RS::get_singleton()->viewport_set_update_mode(get_viewport_rid(), RS::VIEWPORT_UPDATE_DISABLED);
}
Window::~Window() {
memdelete(theme_owner);
+
+ // Resources need to be disconnected.
+ for (KeyValue<StringName, Ref<Texture2D>> &E : theme_icon_override) {
+ E.value->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+ for (KeyValue<StringName, Ref<StyleBox>> &E : theme_style_override) {
+ E.value->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+ for (KeyValue<StringName, Ref<Font>> &E : theme_font_override) {
+ E.value->disconnect("changed", callable_mp(this, &Window::_notify_theme_override_changed));
+ }
+
+ // Then override maps can be simply cleared.
+ theme_icon_override.clear();
+ theme_style_override.clear();
+ theme_font_override.clear();
+ theme_font_size_override.clear();
+ theme_color_override.clear();
+ theme_constant_override.clear();
}