The International Simutrans Forum

 

Author Topic: [patch] Add fullscreen in-game GUI setting  (Read 578 times)

0 Members and 1 Guest are viewing this topic.

Offline Roboron

  • Devotee
  • *
  • Posts: 360
    • Las Galácticas Aventuras de Komoyo Diga
  • Languages: ES, EN
[patch] Add fullscreen in-game GUI setting
« on: October 11, 2021, 09:26:23 PM »
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.

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [patch] Add fullscreen in-game GUI setting
« Reply #1 on: October 12, 2021, 01:23:54 AM »
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.

Offline Roboron

  • Devotee
  • *
  • Posts: 360
    • Las Galácticas Aventuras de Komoyo Diga
  • Languages: ES, EN
Re: [patch] Add fullscreen in-game GUI setting
« Reply #2 on: October 12, 2021, 12:50:21 PM »
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.

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [patch] Add fullscreen in-game GUI setting
« Reply #3 on: October 12, 2021, 02:32:29 PM »
Added support for GDI (and fixed a fullscreen bug there as well) and comitted it. THanks

Offline Roboron

  • Devotee
  • *
  • Posts: 360
    • Las Galácticas Aventuras de Komoyo Diga
  • Languages: ES, EN
Re: [patch] Add fullscreen in-game GUI setting
« Reply #4 on: October 12, 2021, 05:08:55 PM »
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_"?

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [patch] Add fullscreen in-game GUI setting
« Reply #5 on: October 13, 2021, 12:48:28 AM »
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?


Offline Roboron

  • Devotee
  • *
  • Posts: 360
    • Las Galácticas Aventuras de Komoyo Diga
  • Languages: ES, EN
Re: [patch] Add fullscreen in-game GUI setting
« Reply #6 on: October 13, 2021, 02:01:38 PM »
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).

Offline Andarix

  • *
  • Posts: 314
  • Languages: de
Re: [patch] Add fullscreen in-game GUI setting
« Reply #7 on: October 13, 2021, 02:31:50 PM »
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.

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [patch] Add fullscreen in-game GUI setting
« Reply #8 on: October 14, 2021, 05:36:36 AM »
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.

Offline Andarix

  • *
  • Posts: 314
  • Languages: de
Re: [patch] Add fullscreen in-game GUI setting
« Reply #9 on: October 14, 2021, 03:29:37 PM »
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.

Offline Roboron

  • Devotee
  • *
  • Posts: 360
    • Las Galácticas Aventuras de Komoyo Diga
  • Languages: ES, EN
Re: [patch] Add fullscreen in-game GUI setting
« Reply #10 on: October 14, 2021, 05:35:33 PM »
Seems that prissi forgot to update the fullscreen status in his implementation

Online prissi

  • Developer
  • Administrator
  • *
  • Posts: 10905
  • Languages: De,EN,JP
Re: [patch] Add fullscreen in-game GUI setting
« Reply #11 on: October 15, 2021, 06:53:18 AM »
Thanks. Also removed the ability to switch to fullscreen, when SDL2 does not actually support it ...