From f5166c437eeaf075c9228102a3d20e1b5ab5ff5d Mon Sep 17 00:00:00 2001 From: Misa Date: Sat, 25 Dec 2021 22:55:55 -0800 Subject: [PATCH] Add forced fullscreen mode This is mainly to make sure the game is definitely set to fullscreen in Big Picture and on the Steam Deck, and to also remove windowed options that wouldn't make sense if you're not on a desktop (toggling fullscreen, resize to nearest). Those options would also be removed on console and mobile too. There's a bit of an annoying bug where if you launch the game in forced fullscreen mode, but then exit and relaunch in normal mode, your game will have fullscreen window sizes but it won't be fullscreen. This is because forced fullscreen mode tries to preserve your non-forced fullscreen setting, but due to the way window sizes are stored and queried, it can't preserve the non-forced window size. This is a bit difficult to work around, so I'm just putting in a FIXME here because we can fix it later and I'd rather have a slightly buggy forced fullscreen mode than not have one at all. Closes #849. --- desktop_version/src/FileSystemUtils.cpp | 7 +--- desktop_version/src/Game.cpp | 10 ++++- desktop_version/src/Input.cpp | 53 +++++++++++++++++-------- desktop_version/src/Render.cpp | 41 +++++++++++++------ desktop_version/src/Screen.cpp | 13 +++++- desktop_version/src/Screen.h | 2 + 6 files changed, 89 insertions(+), 37 deletions(-) diff --git a/desktop_version/src/FileSystemUtils.cpp b/desktop_version/src/FileSystemUtils.cpp index 265a7370..6d2893b0 100644 --- a/desktop_version/src/FileSystemUtils.cpp +++ b/desktop_version/src/FileSystemUtils.cpp @@ -8,6 +8,7 @@ #include "Exit.h" #include "Graphics.h" #include "Maths.h" +#include "Screen.h" #include "Unused.h" #include "UtilityClass.h" #include "Vlogging.h" @@ -1061,11 +1062,7 @@ static int PLATFORM_getOSDirectory(char* output, const size_t output_size) bool FILESYSTEM_openDirectoryEnabled(void) { - /* This is just a check to see if we're on a desktop or tenfoot setup. - * If you're working on a tenfoot-only build, add a def that always - * returns false! - */ - return !SDL_GetHintBoolean("SteamTenfoot", SDL_FALSE); + return !gameScreen.isForcedFullscreen(); } #if defined(__EMSCRIPTEN__) diff --git a/desktop_version/src/Game.cpp b/desktop_version/src/Game.cpp index c7b5c0d7..934aac8a 100644 --- a/desktop_version/src/Game.cpp +++ b/desktop_version/src/Game.cpp @@ -6035,9 +6035,15 @@ void Game::createmenu( enum Menu::MenuName t, bool samemenu/*= false*/ ) maxspacing = 15; break; case Menu::graphicoptions: - option("toggle fullscreen"); + if (!gameScreen.isForcedFullscreen()) + { + option("toggle fullscreen"); + } option("scaling mode"); - option("resize to nearest", gameScreen.isWindowed); + if (!gameScreen.isForcedFullscreen()) + { + option("resize to nearest", gameScreen.isWindowed); + } option("toggle filter"); option("toggle analogue"); option("toggle vsync"); diff --git a/desktop_version/src/Input.cpp b/desktop_version/src/Input.cpp index 1f501c8e..0cce6eab 100644 --- a/desktop_version/src/Input.cpp +++ b/desktop_version/src/Input.cpp @@ -605,19 +605,29 @@ static void menuactionpress(void) map.nexttowercolour(); break; case Menu::graphicoptions: - switch (game.currentmenuoption) + { + int offset = 0; + bool processed = false; + if (game.currentmenuoption == offset + 0 && !gameScreen.isForcedFullscreen()) { - case 0: + processed = true; music.playef(11); gameScreen.toggleFullScreen(); - game.savestatsandsettings_menu(); - break; - case 1: + } + if (gameScreen.isForcedFullscreen()) + { + --offset; + } + if (game.currentmenuoption == offset + 1) + { + processed = true; music.playef(11); gameScreen.toggleScalingMode(); game.savestatsandsettings_menu(); - break; - case 2: + } + if (game.currentmenuoption == offset + 2 && !gameScreen.isForcedFullscreen()) + { + processed = true; // resize to nearest multiple if (gameScreen.isWindowed) { @@ -629,19 +639,29 @@ static void menuactionpress(void) { music.playef(2); } - break; - case 3: + } + if (gameScreen.isForcedFullscreen()) + { + --offset; + } + if (game.currentmenuoption == offset + 3) + { + processed = true; music.playef(11); gameScreen.toggleLinearFilter(); game.savestatsandsettings_menu(); - break; - case 4: + } + if (game.currentmenuoption == offset + 4) + { + processed = true; //change smoothing music.playef(11); gameScreen.badSignalEffect= !gameScreen.badSignalEffect; game.savestatsandsettings_menu(); - break; - case 5: + } + if (game.currentmenuoption == offset + 5) + { + processed = true; /* FIXME: Upgrade to SDL 2.0.18 and remove this ifdef when it releases! */ #if SDL_VERSION_ATLEAST(2, 0, 17) //toggle vsync @@ -649,15 +669,16 @@ static void menuactionpress(void) gameScreen.toggleVSync(); game.savestatsandsettings_menu(); #endif - break; - default: + } + if (!processed) + { //back music.playef(11); game.returnmenu(); map.nexttowercolour(); - break; } break; + } case Menu::youwannaquit: switch (game.currentmenuoption) { diff --git a/desktop_version/src/Render.cpp b/desktop_version/src/Render.cpp index de4a8a20..947347e1 100644 --- a/desktop_version/src/Render.cpp +++ b/desktop_version/src/Render.cpp @@ -289,9 +289,10 @@ static void menurender(void) } break; case Menu::graphicoptions: - switch (game.currentmenuoption) + { + int offset = 0; + if (game.currentmenuoption == offset + 0 && !gameScreen.isForcedFullscreen()) { - case 0: graphics.bigprint( -1, 30, "Toggle Fullscreen", tr, tg, tb, true); graphics.Print( -1, 65, "Change to fullscreen/windowed mode.", tr, tg, tb, true); @@ -303,9 +304,15 @@ static void menurender(void) { graphics.Print( -1, 85, "Current mode: FULLSCREEN", tr, tg, tb, true); } - break; + } - case 1: + if (gameScreen.isForcedFullscreen()) + { + --offset; + } + + if (game.currentmenuoption == offset + 1) + { graphics.bigprint( -1, 30, "Scaling Mode", tr, tg, tb, true); graphics.Print( -1, 65, "Choose letterbox/stretch/integer mode.", tr, tg, tb, true); @@ -321,8 +328,9 @@ static void menurender(void) graphics.Print( -1, 85, "Current mode: LETTERBOX", tr, tg, tb, true); break; } - break; - case 2: + } + if (game.currentmenuoption == offset + 2 && !gameScreen.isForcedFullscreen()) + { graphics.bigprint(-1, 30, "Resize to Nearest", tr, tg, tb, true); graphics.Print(-1, 65, "Resize to the nearest window size", tr, tg, tb, true); graphics.Print(-1, 75, "that is of an integer multiple.", tr, tg, tb, true); @@ -331,8 +339,13 @@ static void menurender(void) graphics.Print(-1, 95, "You must be in windowed mode", tr, tg, tb, true); graphics.Print(-1, 105, "to use this option.", tr, tg, tb, true); } - break; - case 3: + } + if (gameScreen.isForcedFullscreen()) + { + --offset; + } + if (game.currentmenuoption == offset + 3) + { graphics.bigprint( -1, 30, "Toggle Filter", tr, tg, tb, true); graphics.Print( -1, 65, "Change to nearest/linear filter.", tr, tg, tb, true); @@ -344,15 +357,17 @@ static void menurender(void) { graphics.Print( -1, 85, "Current mode: NEAREST", tr, tg, tb, true); } - break; + } - case 4: + if (game.currentmenuoption == offset + 4) + { graphics.bigprint( -1, 30, "Analogue Mode", tr, tg, tb, true); graphics.Print( -1, 65, "There is nothing wrong with your", tr, tg, tb, true); graphics.Print( -1, 75, "television set. Do not attempt to", tr, tg, tb, true); graphics.Print( -1, 85, "adjust the picture.", tr, tg, tb, true); - break; - case 5: + } + if (game.currentmenuoption == offset + 5) + { graphics.bigprint(-1, 30, "Toggle VSync", tr, tg, tb, true); /* FIXME: Upgrade to SDL 2.0.18 and remove this ifdef when it releases! */ #if SDL_VERSION_ATLEAST(2, 0, 17) @@ -370,9 +385,9 @@ static void menurender(void) { graphics.Print(-1, 85, "Current mode: VSYNC ON", tr, tg, tb, true); } - break; } break; + } case Menu::audiooptions: switch (game.currentmenuoption) { diff --git a/desktop_version/src/Screen.cpp b/desktop_version/src/Screen.cpp index d84c7f71..8f181bec 100644 --- a/desktop_version/src/Screen.cpp +++ b/desktop_version/src/Screen.cpp @@ -140,7 +140,7 @@ void Screen::ResizeScreen(int x, int y) resY = y; } - if(!isWindowed) + if (!isWindowed || isForcedFullscreen()) { int result = SDL_SetWindowFullscreen(m_window, SDL_WINDOW_FULLSCREEN_DESKTOP); if (result != 0) @@ -360,3 +360,14 @@ void Screen::toggleVSync(void) SDL_RenderSetVSync(m_renderer, (int) vsync); #endif } + +/* FIXME: Launching in forced fullscreen then exiting and relaunching in normal + * mode will result in the window having fullscreen size but being windowed. */ +bool Screen::isForcedFullscreen(void) +{ + /* This is just a check to see if we're on a desktop or tenfoot setup. + * If you're working on a tenfoot-only build, add a def that always + * returns true! + */ + return SDL_GetHintBoolean("SteamTenfoot", SDL_FALSE); +} diff --git a/desktop_version/src/Screen.h b/desktop_version/src/Screen.h index 0bfac967..66c86e7a 100644 --- a/desktop_version/src/Screen.h +++ b/desktop_version/src/Screen.h @@ -29,6 +29,8 @@ public: void toggleLinearFilter(void); void toggleVSync(void); + bool isForcedFullscreen(void); + bool isWindowed; bool isFiltered; bool badSignalEffect;