Browse Source

Change graphics to allow non fullscreen display

Godzil 1 year ago
parent
commit
a0f117fcf3
2 changed files with 23 additions and 6 deletions
  1. 21 5
      source/graphics.cpp
  2. 2 1
      source/include/graphics.h

+ 21 - 5
source/graphics.cpp

@@ -24,11 +24,12 @@
 
 SDL_Window* graphics::window = nullptr;
 SDL_Renderer* graphics::renderer = nullptr;
+int graphics::windowFlags = 0;
 int graphics::windowWidth = 0;
 int graphics::windowHeight = 0;
 TTF_Font *graphics::font = nullptr;
 
-bool graphics::openWindow()
+bool graphics::openWindow(bool fullScreen)
 {
     if (SDL_Init(SDL_INIT_EVERYTHING) != 0)
     {
@@ -45,11 +46,23 @@ bool graphics::openWindow()
     SDL_DisplayMode display_mode;
     SDL_GetCurrentDisplayMode(0, &display_mode);
 
-    graphics::windowWidth = display_mode.w;
-    graphics::windowHeight = display_mode.h;
+    if (fullScreen)
+    {
+        graphics::windowWidth = display_mode.w;
+        graphics::windowHeight = display_mode.h;
+        graphics::windowFlags = SDL_WINDOW_BORDERLESS;
+    }
+    else
+    {
+        graphics::windowWidth = 1024;
+        graphics::windowHeight = 758;
+        graphics::windowFlags = 0;
+    }
 
     graphics::window = SDL_CreateWindow(nullptr, 0, 0,
-                                        windowWidth, windowHeight, SDL_WINDOW_BORDERLESS);
+                                        graphics::windowWidth, graphics::windowHeight,
+                                        graphics::windowFlags);
+
     if (!graphics::window)
     {
         logger::critical("Error creating SDL window: %s", SDL_GetError());
@@ -70,7 +83,10 @@ bool graphics::openWindow()
         return false;
     }
 
-    SDL_SetWindowFullscreen(graphics::window, SDL_WINDOW_FULLSCREEN);
+    if (fullScreen)
+    {
+        SDL_SetWindowFullscreen(graphics::window, SDL_WINDOW_FULLSCREEN);
+    }
 
     ImGui::CreateContext();
     ImGuiSDL::Initialize(graphics::renderer, graphics::windowWidth, graphics::windowHeight);

+ 2 - 1
source/include/graphics.h

@@ -21,6 +21,7 @@ class graphics {
 private:
     static int windowWidth;
     static int windowHeight;
+    static int windowFlags;
     static SDL_Window* window;
     static SDL_Renderer* renderer;
     static TTF_Font *font;
@@ -28,7 +29,7 @@ private:
 public:
     static int width() { return graphics::windowWidth; }
     static int height() { return graphics::windowHeight; }
-    static bool openWindow();
+    static bool openWindow(bool fullScreen = true);
     static void closeWindow();
     static void clearScreen(uint32_t color);
     static void renderFrame();