From b700ed311114e868e4cd5ba30ca4661626183aa4 Mon Sep 17 00:00:00 2001 From: Joshua Goins Date: Wed, 17 Oct 2018 17:11:26 -0400 Subject: [PATCH] Add fullscreen support --- src/main.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/main.cpp b/src/main.cpp index 150b820..cdf40d3 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -33,6 +33,7 @@ int windowX = SDL_WINDOWPOS_CENTERED; int windowY = SDL_WINDOWPOS_CENTERED; int windowWidth = 640; int windowHeight = 480; +int windowFullscreen = 0; int toInt(const std::string &str) { std::stringstream ss(str); @@ -62,6 +63,8 @@ void readConfig() { windowWidth = toInt(value); } else if(key == "height") { windowHeight = toInt(value); + } else if(key == "fullscreen") { + windowFullscreen = toInt(value); } } } @@ -81,6 +84,8 @@ void writeConfig() { file << "width=" << w << "\n"; file << "height=" << h << "\n"; + + file << "fullscreen=" << windowFullscreen << "\n"; } int main(int, char*[]) { @@ -95,6 +100,8 @@ int main(int, char*[]) { SDL_WINDOW_RESIZABLE); if(!window) return -1; + + SDL_SetWindowFullscreen(window, windowFullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0); Renderer* renderer = new Renderer(); @@ -139,6 +146,18 @@ int main(int, char*[]) { if(event.window.event == SDL_WINDOWEVENT_RESIZED) target = renderer->createSurfaceRenderTarget(surface, target); } + + if(event.type == SDL_KEYDOWN && event.key.keysym.scancode == SDL_SCANCODE_F11) { + if(windowFullscreen == 1) { + SDL_SetWindowFullscreen(window, 0); + windowFullscreen = 0; + } else { + SDL_SetWindowFullscreen(window, SDL_WINDOW_FULLSCREEN_DESKTOP); + windowFullscreen = 1; + } + + target = renderer->createSurfaceRenderTarget(surface, target); + } } renderer->render(world, target);