Skip to content

Commit e38da58

Browse files
authored
Merge pull request #454 from ferafiks/window-configuration
Window configuration page
2 parents acb96b7 + 74c45ef commit e38da58

3 files changed

Lines changed: 130 additions & 2 deletions

File tree

en/manual/graphics/index.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,11 @@ The graphics module provides a set of methods to display the game. Although Stri
2525
* [Textures](textures/index.md)
2626
* [Lights and shadows](lights-and-shadows/index.md)
2727
* [Post effects](post-effects/index.md)
28+
* [Window Configuration](window-configuration.md)
2829
* [Graphics compositor](graphics-compositor/index.md)
2930
* [Effects and shaders](effects-and-shaders/index.md)
3031
* [Low-level API](low-level-api/index.md)
3132
* [Rendering pipeline](rendering-pipeline/index.md)
3233
* [Sprite fonts](sprite-fonts.md)
3334
* [Voxel Cone Tracing GI](lights-and-shadows/voxel-cone-tracing-gi.md)
34-
* [Graphics API](graphics-api.md)
35+
* [Graphics API](graphics-api.md)
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
# Window Configuration
2+
3+
<span class="badge text-bg-primary">Beginner</span>
4+
5+
Properties of the game's window can be controled through code.
6+
7+
Currently, this cannot be configured in Game Studio, so a simple alternative is to have a [`Startup Script`](../scripts/types-of-script#startup-scripts) in the root scene of your project, that changes values of `Game.Window`.
8+
9+
> [!Note]
10+
> The best solution would be to change these properties before the window is opened, by overriding the `Game` class, but this is outside of the scope of this page.
11+
12+
```csharp
13+
using Stride.Engine;
14+
15+
namespace MyGame
16+
{
17+
public class WindowSetupScript : StartupScript
18+
{
19+
public override void Start()
20+
{
21+
// Set window properties here
22+
23+
// Example
24+
Game.Window.IsBorderLess = true;
25+
}
26+
}
27+
}
28+
```
29+
30+
## Making the window resizable
31+
32+
To allow for window resizing, set `AllowUserResizing` to `true`.
33+
34+
```csharp
35+
Game.Window.AllowUserResizing = true
36+
```
37+
38+
## Fullscreen
39+
40+
To enter fullscreen mode, set `IsFullscreen` to `true`.
41+
42+
```csharp
43+
Game.Window.IsFullscreen = true
44+
```
45+
46+
By default, Stride uses **exclusive fullscreen**. This can be changed to **borderless fullscreen** by setting `FullscreenIsBorderlessWindow` to `true`.
47+
48+
```csharp
49+
Game.Window.FullscreenIsBorderlessWindow = true;
50+
```
51+
52+
The main difference between these two fullscreen modes is that **exclusive fullscreen** renders the game directly to the screen, while **borderless fullscreen** resizes the window to take up the entire display.
53+
54+
> [!Note]
55+
> **Exclusive fullscreen** can slightly improve performence, but is generally disliked by most players due to making switching between different applications slower and more cumbersome.
56+
57+
## Resolution
58+
59+
Resolution can be set using the `SetSize` method and read using the `ClientBounds` property.
60+
61+
```csharp
62+
// Setting the window size to 1920x1080
63+
Game.Window.SetSize(new Int2(1920, 1080));
64+
65+
// Reading window size and position
66+
var newBounds = Game.Window.ClientBounds;
67+
```
68+
69+
The size of the entire screen can be found in `Game.GraphicsDevice`.
70+
71+
```csharp
72+
// List of all connected displays
73+
var monitors = Game.GraphicsDevice.Outputs;
74+
75+
// Reading the size and position of the first connected display
76+
var bounds = monitors[0].DesktopBounds;
77+
```
78+
79+
Each output also contains a list of supported display modes for the monitor. This is useful for **creating a resolution dropdown** in a settings menu of your game.
80+
81+
```csharp
82+
var supportedDisplayModes = monitors[0].SupportedDisplayModes;
83+
84+
// Create a list of avaliable resolutions
85+
var resolutions = new List<Int2>();
86+
foreach (var mode in supportedDisplayModes)
87+
{
88+
var res = new Int2(mode.Width, mode.Height);
89+
if (!resolutions.Contains(res))
90+
resolutions.Add(res);
91+
}
92+
```
93+
94+
## Title
95+
96+
The window title can be changed using the `Title` property.
97+
98+
```csharp
99+
Game.Window.Title = "My Title Here";
100+
```
101+
102+
## Other window properties
103+
104+
Here are other miscellaneous window properties.
105+
106+
```csharp
107+
// Changes window opacity
108+
Game.Window.Opacity = 0.6f;
109+
110+
// Removes window borders
111+
Game.Window.IsBorderless = true;
112+
113+
// Changes mouse visibility
114+
Game.Window.IsMouseVisible = false;
115+
116+
// Changes the position of the window
117+
Game.Window.Position = new Int2(50, 50);
118+
119+
120+
// True when the window has focus
121+
var hasFocus = Game.Window.IsFocused;
122+
123+
// True when the window is minimized
124+
var minimized = Game.Window.IsMinimized;
125+
```

en/manual/toc.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,8 @@ items:
289289
href: graphics/post-effects/light-streaks.md
290290
- name: Local reflections
291291
href: graphics/post-effects/local-reflections.md
292+
- name: Window Configuration
293+
href: graphics/window-configuration.md
292294
- name: Graphics compositor
293295
href: graphics/graphics-compositor/index.md
294296
items:
@@ -636,4 +638,4 @@ items:
636638
href: troubleshooting/unable-to-resolve-stride-game-studio.md
637639

638640
- name: Glossary
639-
href: glossary/index.md
641+
href: glossary/index.md

0 commit comments

Comments
 (0)