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

Add ability to customize Viewport background #5590

Open
dalexeev opened this issue Oct 14, 2022 · 2 comments
Open

Add ability to customize Viewport background #5590

dalexeev opened this issue Oct 14, 2022 · 2 comments

Comments

@dalexeev
Copy link
Member

Describe the project you are working on

A game.

Describe the problem or limitation you are having in your project

In 4.0-dev you can't change the background color of a Viewport (Window, SubViewport) in a simple way. In addition, you cannot set different clear colors for different Viewports.

3.x has the following methods:

  • VisualServer.black_bars_set_images;
  • VisualServer.black_bars_set_margins;
  • VisualServer.viewport_attach_to_screen;
  • Viewport.set_attach_to_screen_rect;
  • etc.

This allows you to set the window background color or texture. Also, although not documented, you can attach a Viewport with a background behind the root Viewport without changing the main scene and autoload hierarchy (without nesting them in a new Viewport) and keeping the project settings working (display/window section).

Another point is the integer scaling of Viewport size (or the rectangle on which it is displayed), which is necessary for some pixel games. In 4.0-dev, there is no analogue of the Viewport.set_attach_to_screen_rect method. An example of a plugin that uses the method: Yukitty/godot-addon-integer_resolution_handler.

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

Add methods to set clear color, background color, background texture to Viewport. Add an analogue of the set_attach_to_screen_rect method.

I also had an idea to add theme properties to the Window (colors and StyleBox), but SubViewport doesn't support themes. Maybe move the theme functionality to the Viewport?

In addition, we can add project settings for the main window:

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

See above.

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

You can ignore the display/window settings, display the background and SubViewportContainer in the root Window and implement the desired scaling logic. All content must be added to this SubViewport and not to the root of the scene tree. However, this is much less convenient, does not work well with autoloads and with the functionality of the editor (Run Current Scene (F6)).

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

This is the basic functionality. The workaround implementation described above will be awkward whether you implement it yourself or find it in AssetLib.

@Calinou
Copy link
Member

Calinou commented Oct 14, 2022

Another point is the integer scaling of Viewport size (or the rectangle on which it is displayed), which is necessary for some pixel games. In 4.0-dev, there is no analogue of the Viewport.set_attach_to_screen_rect method. An example of a plugin that uses the method: Yukitty/godot-addon-integer_resolution_handler.

This is being tracked in #1666.

@dalexeev
Copy link
Member Author

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