News:

Use the "Forum Search"
It may help you to find anything in the forum ;).

[patch] Add fullscreen in-game GUI setting

Started by Roboron, October 11, 2021, 09:26:23 PM

Previous topic - Next topic

0 Members and 1 Guest are viewing this topic.

Roboron

Motivation: One of the few useful functions remaining of the Simutrans Preloader is a GUI button to turn off/on fullscreen. Since my plan is to get rid of the preloader, it would be nice to translate this to a proper GUI setting before.

This patch adds a "Fullscreen" toggle button to display settings GUI that switches fullscreen on/off. If such button is pressed, the setting will be saved and loaded the next time Simutrans is started.

More details:
- Function "bool is_fullscreen()" added to simsys, returns the current fullscreen status (usually using a "fullscreen" variable to keep track of it, but one could maybe query the backend for such information).
- Function "bool toggle_fullscreen" added to simsys, will toggle the fullscreen on/off, and returns the fullscreen status after the toggle.
- Added env_t::fullscreen variable. Fullscreen status will be saved to env_t::fullscreen (and settings.xml) *only* when using the GUI setting, meaning that, for example, if you use the -fullscreen start option, the fullscreen status won't be saved and game won't start in full screen the next time. But if you set fullscreen via GUI settings, the game will remember the fullscreen status and start fullscreen next time.
- Currently I only implemented the toggle_fullscreen() function for SDL2. It was my intention to try to implement it at least also for GDI... but that thing... it scares me...
- If any of you want to implement it for other backends, please do jump in. I don't know if there's enough interest, so I left a dummy toggle_fullscreen() function that does nothing when the button is pressed. For my own purposes the SDL2 backend alone do suffices...
- Also for SDL2, I initially considered "true" fullscreen, but it caused a myriad of issues (one of my tests, the windows decoration changed from Windows 10 style to Windows Vista style after exiting fullscreen, lol). For that reason I settled on "fake" fullscreen (borderless). This should be enough for our case, anyway.

prissi

That does not work properly on many devices, and also not with GDI. The real fullscreeen mode actually may sets the video to 16 bit color depth and thus disables windows decoration. Switching this backwards and forwards is a very bad idea and will likely lead to the same effects you had with SDL. Also in fullscreen the resolution can be switched as well (used by some guys for zooming in), which is no longer possible when using fake fullscreen.

So it is probably better to separate the fullscreen mode from the borderless mode. Allegro, SDL and GDI all have a real fullscreen mode that even switches resolution and color depth to 16 bit. In SDL2 it does not work any more.

I rather suggest a borderless mode with its own flags, environment, simuconf.tab entry etc.  which can be toggled and is disabled if there is a real fullscreen mode in progress (i.e. with different screen size). Or remove the full screen support with resolution switching, although this will make some guys unhappy.

Roboron

I really hate that I don't subscribe automatically to new threads I post: I always forget!

Okay, back to the cuisine with a different approach. I now tried something that would satisfy both users, fullscreen and borderless. See if you like this:

- env_t::fullscreen and related variables will be now of type int. This way we can store an extra possibility:
  - 0 for windowed (just like now)
  - 1 for fullscreen (just like now)
  - 2 for borderless (new!)
- Added an enum to keep track of it (WINDOWED, FULLSCREEN, BORDERLESS)
- toggle_fullscreen renamed to toggle_borderless and is_fullscreen renamed to get_fullscreen, both now returns an int
- The button "Fullscreen" will only change the env_t::fullscreen variable, specifying that a restart is needed for the change to take effect
- The button "Borderless fullscreen" is the old "Fulscreen" button, but it will be disabled if we are in true fullscreen mode.
- Also added "-borderless" parameter.

This would enable for the setting to be at least configurable via GUI in any case.

prissi

Added support for GDI (and fixed a fullscreen bug there as well) and comitted it. THanks

Roboron

You forgot to add "dr_" prefix to symsys_s functions https://github.com/aburch/simutrans/commit/aa9ec5861443ce619510be3014ecba7756716b42#diff-0f9ac21b3ed8ab4569b2abb077a314f911e1e23439d63045a9a95622d45700bf

I have always wondered, but never asked, so this is a good time: What is the meaning of "dr_"?

prissi

And that is for trusting the refactoring function of MSVC.

dr_ is just an indicator that this is a system dependent function. I am not sure what dr_ stands for . Maybe driver?


Roboron

I dug deep in the Internet and I found  a paper mentioning a similar thing: " all the data [..] was handled  by  a  derived  result  class  instance.    Specific  code  modules  were  denoted  by  a  "dr_"  prefix  for  "derived  result". "

I don't think it means "derived result" in our case but it got me thinking that it could be an abbreviation of "derived" alone (as in, the functions are derived for every system).

Andarix

Option "Borderless fullscreen" not correct work by me.
Windows 10 german

GDI (MSVC compiled) from my GitRepo r10151

- aktivate ok
-> option show as disabled
-> no return to windowed mode with frame

And I can't bring anything else to the fore. Neither a window nor the taskbar.

prissi

The fullscreen is real fullscreen, including changing of color depth to 16 bit per pixel and changing resolution, and thus not compatible with window mode. If you are in fullcreen mode, you need to quit simutrans. Hence the button to decide on the mode after a restart.

Borderless is just a normal window without borders that is kept on top. This is the default mode for SDL2, since the other mode does not work. "-fullscreen" with SDL2 does nothing, just a borderless window.

Andarix

I'm also talking about the frameless window in full screen.

I can click the option and the frame will be removed and the image enlarged to full screen.

The option then still appears as deactivated. The picture then always remains active in the foreground, but this contradicts the window system. With a window, you can bring other windows to the foreground and the taskbar also comes to the foreground.

But neither is possible here.

If these options should only be for SDL2, then they should not be available with GDI either.

Roboron

Seems that prissi forgot to update the fullscreen status in his implementation

prissi

Thanks. Also removed the ability to switch to fullscreen, when SDL2 does not actually support it ...