Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix viewport attach position when forced integer stretch scale of 1 makes it bigger than window #91787

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
13 changes: 8 additions & 5 deletions scene/main/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1127,6 +1127,8 @@ void Window::_update_viewport_size() {
screen_size = screen_size.floor();
viewport_size = viewport_size.floor();

Size2 attach_to_screen_offset;

if (content_scale_stretch == Window::CONTENT_SCALE_STRETCH_INTEGER) {
Size2i screen_scale = (screen_size / viewport_size).floor();
int scale_factor = MIN(screen_scale.x, screen_scale.y);
Expand All @@ -1136,19 +1138,20 @@ void Window::_update_viewport_size() {
}

screen_size = viewport_size * scale_factor;

if (screen_size.y > video_mode.y) {
attach_to_screen_offset.y = video_mode.y - screen_size.y;
}
}

Size2 margin;
Size2 offset;

if (screen_size.x < video_mode.x) {
margin.x = Math::round((video_mode.x - screen_size.x) / 2.0);
offset.x = Math::round(margin.x * viewport_size.y / screen_size.y);
}

if (screen_size.y < video_mode.y) {
margin.y = Math::round((video_mode.y - screen_size.y) / 2.0);
offset.y = Math::round(margin.y * viewport_size.x / screen_size.x);
Comment on lines -1142 to -1151
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This offset was unused, hence removing it.

}

switch (content_scale_mode) {
Expand All @@ -1159,14 +1162,14 @@ void Window::_update_viewport_size() {
case CONTENT_SCALE_MODE_CANVAS_ITEMS: {
final_size = screen_size;
final_size_override = viewport_size / content_scale_factor;
attach_to_screen_rect = Rect2(margin, screen_size);
attach_to_screen_rect = Rect2(margin + attach_to_screen_offset, screen_size);
font_oversampling = (screen_size.x / viewport_size.x) * content_scale_factor;

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);
attach_to_screen_rect = Rect2(margin + attach_to_screen_offset, screen_size);

window_transform.translate_local(margin);
if (final_size.x != 0 && final_size.y != 0) {
Expand Down