Merge pull request #67331 from Sauermann/fix-subviewport-no-stretch-update

Fix stretch transform when resizing SubViewports
This commit is contained in:
Rémi Verschelde 2023-02-01 11:10:01 +01:00
commit 2852d5e613
No known key found for this signature in database
GPG Key ID: C3336907360768E1
3 changed files with 17 additions and 28 deletions

View File

@ -796,15 +796,21 @@ void Viewport::update_canvas_items() {
_update_canvas_items(this); _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) { void Viewport::_set_size(const Size2i &p_size, const Size2i &p_size_2d_override, const Rect2i &p_to_screen_rect, 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) { 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; return;
} }
size = p_size; size = p_size;
size_allocated = p_allocated; size_allocated = p_allocated;
size_2d_override = p_size_2d_override; size_2d_override = p_size_2d_override;
stretch_transform = p_stretch_transform; stretch_transform = stretch_transform_new;
to_screen_rect = p_to_screen_rect; to_screen_rect = p_to_screen_rect;
#ifndef _3D_DISABLED #ifndef _3D_DISABLED
@ -4137,7 +4143,7 @@ void SubViewport::_internal_set_size(const Size2i &p_size, bool p_force) {
return; 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) { if (c) {
c->update_minimum_size(); c->update_minimum_size();
@ -4149,7 +4155,7 @@ Size2i SubViewport::get_size() const {
} }
void SubViewport::set_size_2d_override(const Size2i &p_size) { 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 { Size2i SubViewport::get_size_2d_override() const {
@ -4162,7 +4168,7 @@ void SubViewport::set_size_2d_override_stretch(bool p_enable) {
} }
size_2d_override_stretch = 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 { bool SubViewport::is_size_2d_override_stretch_enabled() const {
@ -4191,17 +4197,6 @@ DisplayServer::WindowID SubViewport::get_window_id() const {
return DisplayServer::INVALID_WINDOW_ID; 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 SubViewport::get_screen_transform() const {
Transform2D container_transform; Transform2D container_transform;
SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent()); SubViewportContainer *c = Object::cast_to<SubViewportContainer>(get_parent());

View File

@ -471,7 +471,7 @@ private:
uint64_t event_count = 0; uint64_t event_count = 0;
protected: 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() const;
Size2i _get_size_2d_override() 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); void set_canvas_cull_mask_bit(uint32_t p_layer, bool p_enable);
bool get_canvas_cull_mask_bit(uint32_t p_layer) const; 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_screen_transform() const;
virtual Transform2D get_popup_base_transform() const { return Transform2D(); } virtual Transform2D get_popup_base_transform() const { return Transform2D(); }
@ -759,7 +761,6 @@ private:
protected: protected:
static void _bind_methods(); static void _bind_methods();
virtual DisplayServer::WindowID get_window_id() const override; virtual DisplayServer::WindowID get_window_id() const override;
Transform2D _stretch_transform();
void _notification(int p_what); void _notification(int p_what);
public: public:
@ -771,7 +772,7 @@ public:
Size2i get_size_2d_override() const; Size2i get_size_2d_override() const;
void set_size_2d_override_stretch(bool p_enable); 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); void set_update_mode(UpdateMode p_mode);
UpdateMode get_update_mode() const; UpdateMode get_update_mode() const;

View File

@ -905,7 +905,6 @@ void Window::_update_viewport_size() {
Size2i final_size; Size2i final_size;
Size2i final_size_override; Size2i final_size_override;
Rect2i attach_to_screen_rect(Point2i(), size); Rect2i attach_to_screen_rect(Point2i(), size);
Transform2D stretch_transform_new;
float font_oversampling = 1.0; float font_oversampling = 1.0;
window_transform = Transform2D(); window_transform = Transform2D();
@ -913,9 +912,6 @@ void Window::_update_viewport_size() {
font_oversampling = content_scale_factor; font_oversampling = content_scale_factor;
final_size = size; final_size = size;
final_size_override = Size2(size) / content_scale_factor; final_size_override = Size2(size) / content_scale_factor;
stretch_transform_new = Transform2D();
stretch_transform_new.scale(Size2(content_scale_factor, content_scale_factor));
} else { } else {
//actual screen video mode //actual screen video mode
Size2 video_mode = size; Size2 video_mode = size;
@ -991,9 +987,6 @@ void Window::_update_viewport_size() {
attach_to_screen_rect = Rect2(margin, screen_size); attach_to_screen_rect = Rect2(margin, screen_size);
font_oversampling = (screen_size.x / viewport_size.x) * content_scale_factor; 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); window_transform.translate_local(margin);
} break; } break;
case CONTENT_SCALE_MODE_VIEWPORT: { 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); 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) { if (window_id != DisplayServer::INVALID_WINDOW_ID) {
RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), attach_to_screen_rect, window_id); RenderingServer::get_singleton()->viewport_attach_to_screen(get_viewport_rid(), attach_to_screen_rect, window_id);