Browse Source

OpenGL updates for window preferences

Josh Engebretson 10 years ago
parent
commit
ab485f8a2e

+ 18 - 8
Source/Atomic/Graphics/OpenGL/OGLGraphics.cpp

@@ -334,10 +334,12 @@ void* Graphics::GetSDLWindow()
 }
 
 bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer,
-    int multiSample, bool maximize, bool center)
+    int multiSample, bool maximize)
 {
     PROFILE(SetScreenMode);
 
+    bool center = false;
+
     // Fullscreen or Borderless can not be resizable
     if (fullscreen || borderless)
         resizable = false;
@@ -365,17 +367,25 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     // If zero in fullscreen, use desktop mode
     if (!width || !height)
     {
-        if (fullscreen || borderless || maximize)
+        SDL_DisplayMode mode;
+        SDL_GetDesktopDisplayMode(0, &mode);
+
+        if (fullscreen || borderless)
         {
-            SDL_DisplayMode mode;
-            SDL_GetDesktopDisplayMode(0, &mode);
             width = mode.w;
             height = mode.h;
         }
         else
         {
-            width = 1024;
-            height = 768;
+            // If we don't have a height/width calculate a reasonable starting window size, and center it
+            // this will also be the restore size when switching from maximized
+            float ratio = float(mode.h) / float(mode.w);
+            width = mode.w - 200;
+            height = (int) (float (mode.w - 200) * ratio);
+            SetWindowPosition(mode.w/2 - width/2, mode.h/2 - height/2);
+
+            if (!maximize)
+                center = true;
         }
     }
 
@@ -580,7 +590,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 
 bool Graphics::SetMode(int width, int height)
 {
-    return SetMode(width, height, fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false, false);
+    return SetMode(width, height, fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false);
 }
 
 void Graphics::SetSRGB(bool enable)
@@ -617,7 +627,7 @@ void Graphics::SetOrientations(const String& orientations)
 
 bool Graphics::ToggleFullscreen()
 {
-    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false, false);
+    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false);
 }
 
 void Graphics::Close()

+ 1 - 1
Source/Atomic/Graphics/OpenGL/OGLGraphics.h

@@ -103,7 +103,7 @@ public:
     /// Get the SDL_Window as a void* to avoid having to include the graphics implementation
     void* GetSDLWindow();
     /// Set screen mode. Return true if successful.
-    bool SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample, bool maximize, bool center);
+    bool SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer, int multiSample, bool maximize);
     /// Set screen resolution only. Return true if successful.
     bool SetMode(int width, int height);
     /// Set whether the main window uses sRGB conversion on write.