From: RĂ©mi Verschelde Date: Sat, 19 Nov 2016 22:41:28 +0000 (+0100) Subject: Add an option to toggle fullscreen X-Git-Url: https://git.jsancho.org/?p=lugaru.git;a=commitdiff_plain;h=ab5bc544c31256420f735c48723d9e7f7445b8ef Add an option to toggle fullscreen Adds a command line switch, saved config option and option menu entry to toggle fullscreen. Also defaults to windowed mode. --- diff --git a/Source/GameTick.cpp b/Source/GameTick.cpp index bcbce6e..1a743f3 100644 --- a/Source/GameTick.cpp +++ b/Source/GameTick.cpp @@ -148,12 +148,13 @@ extern bool winfreeze; extern bool campaign; +extern void toggleFullscreen(); + void Loadlevel(int which); void Loadlevel(const char *name); - class CampaignLevel { private: @@ -5795,6 +5796,7 @@ void updateSettingsMenu() else sprintf (sbuf, "Resolution: %d*%d (widescreen)", (int)newscreenwidth, (int)newscreenheight); Menu::setText(0, sbuf); + Menu::setText(14, fullscreen ? "Fullscreen: On" : "Fullscreen: Off"); if (newdetail == 0) Menu::setText(1, "Detail: Low"); if (newdetail == 1) Menu::setText(1, "Detail: Medium"); if (newdetail == 2) Menu::setText(1, "Detail: High"); @@ -5875,6 +5877,7 @@ void Game::LoadMenu() break; case 3: Menu::addButton( 0, "", 10 + 20, 440); + Menu::addButton(14, "", 10 + 400, 440); Menu::addButton( 1, "", 10 + 60, 405); Menu::addButton( 2, "", 10 + 70, 370); Menu::addButton( 3, "", 10 + 20 - 1000, 335 - 1000); @@ -6165,6 +6168,9 @@ void MenuTick() case 13: showdamagebar = !showdamagebar; break; + case 14: + toggleFullscreen(); + break; } updateSettingsMenu(); break; diff --git a/Source/Globals.cpp b/Source/Globals.cpp index 1cb6dbf..524f1fa 100644 --- a/Source/Globals.cpp +++ b/Source/Globals.cpp @@ -59,6 +59,7 @@ int difficulty = 0; float multiplier = 0; float realmultiplier = 0; float screenwidth = 0, screenheight = 0; +bool fullscreen = 0; float viewdistance = 0; XYZ viewer; XYZ viewerfacing; diff --git a/Source/OpenGL_Windows.cpp b/Source/OpenGL_Windows.cpp index dc30a03..2c7272d 100644 --- a/Source/OpenGL_Windows.cpp +++ b/Source/OpenGL_Windows.cpp @@ -217,8 +217,9 @@ void initGL() } } -static void toggleFullscreen() +void toggleFullscreen() { + fullscreen = !fullscreen; Uint32 flags = SDL_GetWindowFlags(sdlwindow); if (flags & SDL_WINDOW_FULLSCREEN) { flags &= ~SDL_WINDOW_FULLSCREEN; @@ -331,8 +332,10 @@ Boolean SetUp () SDL_GL_SetAttribute(SDL_GL_STENCIL_SIZE, 1); Uint32 sdlflags = SDL_WINDOW_OPENGL | SDL_WINDOW_SHOWN; - if (!cmdline("windowed")) + if ((fullscreen || cmdline("fullscreen")) && !cmdline("windowed")) { + fullscreen = 1; sdlflags |= SDL_WINDOW_FULLSCREEN; + } if (!cmdline("nomousegrab")) sdlflags |= SDL_WINDOW_INPUT_GRABBED; diff --git a/Source/Settings.cpp b/Source/Settings.cpp index 2a1ad12..e0b4db1 100644 --- a/Source/Settings.cpp +++ b/Source/Settings.cpp @@ -32,6 +32,7 @@ void DefaultSettings() usermousesensitivity = 1; newscreenwidth = kContextWidth = 640; newscreenheight = kContextHeight = 480; + fullscreen = 0; kBitsPerPixel = 32; floatjump = 0; autoslomo = 1; @@ -86,6 +87,8 @@ void SaveSettings() opstream << newscreenwidth; opstream << "\nScreenheight:\n"; opstream << newscreenheight; + opstream << "\nFullscreen:\n"; + opstream << fullscreen; opstream << "\nMouse sensitivity:\n"; opstream << usermousesensitivity; opstream << "\nBlur(0,1):\n"; @@ -198,6 +201,8 @@ bool LoadSettings() ipstream >> kContextWidth; } else if ( !strncmp(setting, "Screenheight", 12) ) { ipstream >> kContextHeight; + } else if ( !strncmp(setting, "Fullscreen", 10) ) { + ipstream >> fullscreen; } else if ( !strncmp(setting, "Mouse sensitivity", 17) ) { ipstream >> usermousesensitivity; } else if ( !strncmp(setting, "Blur", 4) ) { diff --git a/Source/Settings.h b/Source/Settings.h index 0cd2678..e28e346 100644 --- a/Source/Settings.h +++ b/Source/Settings.h @@ -54,6 +54,7 @@ extern int kBitsPerPixel; extern int kContextWidth; extern int kContextHeight; extern float screenwidth, screenheight; +extern bool fullscreen; void DefaultSettings(); void SaveSettings();