summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2023-02-13 00:34:16 +0100
committerYuri Sizov <yuris@humnom.net>2023-03-27 16:34:05 +0200
commit3cae980c178905ac5be51c168698af7b355c4e9c (patch)
tree8e18a40f72092532c68b087457d2a1a01c53d095 /scene/main
parent34a087cc2c8f7c1444642723bbb4178e359dad61 (diff)
Fix some ways to create inconsistent Viewport sizes
In the editor, it was possible to set the size of a `SubViewport` even in cases where a parent `SubViewportContainer` had stretch enabled. This PR disables editing a `SubViewport.size` while the parent disallows it and it makes necessary adjustments during `NOTIFICATION_ENTER_TREE`. (cherry picked from commit 34a7fc744762dcf66eff7e3b5e4d46e09e7c0bdc)
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/viewport.cpp16
-rw-r--r--scene/main/viewport.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index 244e0d5b93..8cd57536bf 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -4281,6 +4281,11 @@ void SubViewport::_notification(int p_what) {
switch (p_what) {
case NOTIFICATION_ENTER_TREE: {
RS::get_singleton()->viewport_set_active(get_viewport_rid(), true);
+
+ SubViewportContainer *parent_svc = Object::cast_to<SubViewportContainer>(get_parent());
+ if (parent_svc) {
+ parent_svc->recalc_force_viewport_sizes();
+ }
} break;
case NOTIFICATION_EXIT_TREE: {
@@ -4323,6 +4328,17 @@ void SubViewport::_bind_methods() {
BIND_ENUM_CONSTANT(UPDATE_ALWAYS);
}
+void SubViewport::_validate_property(PropertyInfo &p_property) const {
+ if (p_property.name == "size") {
+ SubViewportContainer *parent_svc = Object::cast_to<SubViewportContainer>(get_parent());
+ if (parent_svc && parent_svc->is_stretch_enabled()) {
+ p_property.usage = PROPERTY_USAGE_DEFAULT | PROPERTY_USAGE_READ_ONLY;
+ } else {
+ p_property.usage = PROPERTY_USAGE_DEFAULT;
+ }
+ }
+}
+
SubViewport::SubViewport() {
RS::get_singleton()->viewport_set_size(get_viewport_rid(), get_size().width, get_size().height);
}
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 055fad5369..5213c0db01 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -784,6 +784,7 @@ public:
virtual Transform2D get_screen_transform_internal(bool p_absolute_position = false) const override;
virtual Transform2D get_popup_base_transform() const override;
+ void _validate_property(PropertyInfo &p_property) const;
SubViewport();
~SubViewport();
};