summaryrefslogtreecommitdiff
path: root/scene/main
diff options
context:
space:
mode:
authorMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2022-10-13 02:17:04 +0200
committerMarkus Sauermann <6299227+Sauermann@users.noreply.github.com>2023-02-01 08:34:40 +0100
commit8182f29d40018d489f498e9a590e68d3378a52e1 (patch)
tree95162e4c2569f699b5561af953d7f65cf8b558c5 /scene/main
parent68299e0f947fa0ef0c95b9de816b270ad756e4ff (diff)
Fix stretch transform when resizing SubViewports
Move calculation of stretch transform from outside to inside of `Viewport::_set_size` function.
Diffstat (limited to 'scene/main')
-rw-r--r--scene/main/viewport.cpp29
-rw-r--r--scene/main/viewport.h7
-rw-r--r--scene/main/window.cpp9
3 files changed, 17 insertions, 28 deletions
diff --git a/scene/main/viewport.cpp b/scene/main/viewport.cpp
index fe82fed2f7..9ce2a0e893 100644
--- a/scene/main/viewport.cpp
+++ b/scene/main/viewport.cpp
@@ -791,15 +791,21 @@ void Viewport::update_canvas_items() {
_update_canvas_items(this);
}
-void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated) {
- if (size == p_size && size_allocated == p_allocated && stretch_transform == p_stretch_transform && p_size_2d_override == size_2d_override && to_screen_rect == p_to_screen_rect) {
+void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, bool p_allocated) {
+ Transform2D stretch_transform_new = Transform2D();
+ if (is_size_2d_override_stretch_enabled() && p_size_2d_override.width > 0 && p_size_2d_override.height > 0) {
+ Size2 scale = Size2(p_size) / Size2(p_size_2d_override);
+ stretch_transform_new.scale(scale);
+ }
+
+ if (size == p_size && size_allocated == p_allocated && stretch_transform == stretch_transform_new && p_size_2d_override == size_2d_override && to_screen_rect == p_to_screen_rect) {
return;
}
size = p_size;
size_allocated = p_allocated;
size_2d_override = p_size_2d_override;
- stretch_transform = p_stretch_transform;
+ stretch_transform = stretch_transform_new;
to_screen_rect = p_to_screen_rect;
#ifndef _3D_DISABLED
@@ -4132,7 +4138,7 @@ void SubViewport::_internal_set_size(const Size2i &p_size, bool p_force) {
return;
}
- _set_size(p_size, _get_size_2d_override(), Rect2i(), _stretch_transform(), true);
+ _set_size(p_size, _get_size_2d_override(), Rect2i(), true);
if (c) {
c->update_minimum_size();
@@ -4144,7 +4150,7 @@ Size2i SubViewport::get_size() const {
}
void SubViewport::set_size_2d_override(const Size2i &p_size) {
- _set_size(_get_size(), p_size, Rect2i(), _stretch_transform(), true);
+ _set_size(_get_size(), p_size, Rect2i(), true);
}
Size2i SubViewport::get_size_2d_override() const {
@@ -4157,7 +4163,7 @@ void SubViewport::set_size_2d_override_stretch(bool p_enable) {
}
size_2d_override_stretch = p_enable;
- _set_size(_get_size(), _get_size_2d_override(), Rect2i(), _stretch_transform(), true);
+ _set_size(_get_size(), _get_size_2d_override(), Rect2i(), true);
}
bool SubViewport::is_size_2d_override_stretch_enabled() const {
@@ -4186,17 +4192,6 @@ DisplayServer::WindowID SubViewport::get_window_id() const {
return DisplayServer::INVALID_WINDOW_ID;
}
-Transform2D SubViewport::_stretch_transform() {
- Transform2D transform;
- Size2i view_size_2d_override = _get_size_2d_override();
- if (size_2d_override_stretch && view_size_2d_override.width > 0 && view_size_2d_override.height > 0) {
- Size2 scale = Size2(_get_size()) / Size2(view_size_2d_override);
- transform.scale(scale);
- }
-
- return transform;
-}
-
Transform2D SubViewport::get_screen_transform() const {
Transform2D container_transform;
SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent());
diff --git a/scene/main/viewport.h b/scene/main/viewport.h
index 2a4ddc422f..7546838568 100644
--- a/scene/main/viewport.h
+++ b/scene/main/viewport.h
@@ -471,7 +471,7 @@ private:
uint64_t event_count = 0;
protected:
- void _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, const Transform2D &p_stretch_transform, bool p_allocated);
+ void _set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, bool p_allocated);
Size2i _get_size() const;
Size2i _get_size_2d_override() const;
@@ -649,6 +649,8 @@ public:
void set_canvas_cull_mask_bit(uint32_t p_layer, bool p_enable);
bool get_canvas_cull_mask_bit(uint32_t p_layer) const;
+ virtual bool is_size_2d_override_stretch_enabled() const { return true; }
+
virtual Transform2D get_screen_transform() const;
virtual Transform2D get_popup_base_transform() const { return Transform2D(); }
@@ -759,7 +761,6 @@ private:
protected:
static void _bind_methods();
virtual DisplayServer::WindowID get_window_id() const override;
- Transform2D _stretch_transform();
void _notification(int p_what);
public:
@@ -771,7 +772,7 @@ public:
Size2i get_size_2d_override() const;
void set_size_2d_override_stretch(bool p_enable);
- bool is_size_2d_override_stretch_enabled() const;
+ bool is_size_2d_override_stretch_enabled() const override;
void set_update_mode(UpdateMode p_mode);
UpdateMode get_update_mode() const;
diff --git a/scene/main/window.cpp b/scene/main/window.cpp
index 5fd39dfc68..b6f1d3f54b 100644
--- a/scene/main/window.cpp
+++ b/scene/main/window.cpp
@@ -905,7 +905,6 @@ 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();
@@ -913,9 +912,6 @@ void Window::_update_viewport_size() {
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;
@@ -991,9 +987,6 @@ 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: {
@@ -1011,7 +1004,7 @@ void Window::_update_viewport_size() {
}
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, attach_to_screen_rect, allocate);
if (window_id != DisplayServer::INVALID_WINDOW_ID) {
RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), attach_to_screen_rect, window_id);