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

Make stretch_shrink (in SubViewportContainer) work in both ways: shrink and expand #7288

Open
Krasapan opened this issue Jul 15, 2023 · 3 comments

Comments

@Krasapan
Copy link

Krasapan commented Jul 15, 2023

Describe the project you are working on

Currently porting my 3.5 game to 4.1, faced the issue of viewport scaling

Describe the problem or limitation you are having in your project

Godot's 3.5 viewport scaling doesn't work in Godot 4.X because of changed viewport structure

In SubViewportContainer, there's a variable stretch_shrink, which makes viewport scale smaller if you set a bigger int. It's not possible to make viewport scale bigger with this variable, because you can't set the value smaller than the default 1 (otherwise throws an error: scene/gui/subviewport_container.cpp:72 - Condition "p_shrink < 1" is true.), therefore this scaling feature works only in one way, but for me the viewport scale is required to be able to both expand and shrink

Describe the feature / enhancement and how it helps to overcome the problem or limitation

Just a few changes in the initial code, just make it recieve any positive float value and set the viewport scale in percent

I think it should work with these changes:

1. Source link

  • From:
int shrink = 1;
  • To:
float scale = 1.0;

2. Source link

  • From:
void SubViewportContainer::set_stretch_shrink(int p_shrink) {
	ERR_FAIL_COND(p_shrink < 1);
	if (shrink == p_shrink) {
		return;
	}

	shrink = p_shrink;
  • To:
void SubViewportContainer::set_scale(float p_scale) {
	ERR_FAIL_COND(p_scale < 0.0);
	if (scale == p_scale) {
		return;
	}

	scale = p_scale;

3. Source link

  • From:
c->set_size_force(get_size() / shrink);
  • To:
c->set_size_force(get_size() * scale);

Describe how your proposal will work, with code, pseudo-code, mock-ups, and/or diagrams

For example:

0.15 value = 15% viewport scale
1.0 value = 100% viewport scale
3.1 value = 310% viewport scale

If this enhancement will not be used often, can it be worked around with a few lines of script?

I haven't found a way yet, I was trying to make the official method work in Godot 4.X by fixing errors and trying slightly different approaches (even changing the order of nodes changes the result for some reason), but the result wasn't unequivocal, it was broken in different ways (for example, it scales in a bigger way, but when scaled back it changed the viewport size on the screen, not scale)

So I think it's technically possible to implement in Godot 4.X in some way, but I'm sure it won't be made in just a few lines of script

Is there a reason why this should be core and not an add-on in the asset library?

For much easier way of scaling the viewport on runtime with only one variable responsible for that

@AThousandShips
Copy link
Member

Related: #6921

@Krasapan Krasapan changed the title Make stretch_shrink (in SubViewportContainer) work in both ways, as scale Make stretch_shrink (in SubViewportContainer) work in both ways: shrink **and expand** Jul 15, 2023
@Krasapan Krasapan changed the title Make stretch_shrink (in SubViewportContainer) work in both ways: shrink **and expand** Make stretch_shrink (in SubViewportContainer) work in both ways: shrink and expand Jul 15, 2023
@Krasapan
Copy link
Author

Krasapan commented Jul 15, 2023

I think scaling_3d_scale already does this thing, just found it out, looked again into Resolution Scaling doc page, it finally got up to date!

(But it doesn't work in Compatibility renderer)

@Calinou
Copy link
Member

Calinou commented Jul 15, 2023

See discussion in godotengine/godot-demo-projects#891.

(But it doesn't work in Compatibility renderer)

This is being tracked in godotengine/godot#70142. I would prefer we implement scaling in the Compatibility rendering method, as the multi-viewport approach has some overhead on its own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants