Browse Source

Window creation improvements for Direct3D11

JoshEngebretson 10 years ago
parent
commit
56bcdf18b4
1 changed files with 17 additions and 8 deletions
  1. 17 8
      Source/Atomic/Graphics/Direct3D11/D3D11Graphics.cpp

+ 17 - 8
Source/Atomic/Graphics/Direct3D11/D3D11Graphics.cpp

@@ -422,18 +422,27 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     SDL_GetDesktopDisplayMode(0, &mode);
     SDL_GetDesktopDisplayMode(0, &mode);
     DXGI_FORMAT fullscreenFormat = SDL_BITSPERPIXEL(mode.format) == 16 ? DXGI_FORMAT_B5G6R5_UNORM : DXGI_FORMAT_R8G8B8A8_UNORM;
     DXGI_FORMAT fullscreenFormat = SDL_BITSPERPIXEL(mode.format) == 16 ? DXGI_FORMAT_B5G6R5_UNORM : DXGI_FORMAT_R8G8B8A8_UNORM;
 
 
+    bool center = false;
+
     // If zero dimensions in windowed mode, set windowed mode to maximize and set a predefined default restored window size. If zero in fullscreen, use desktop mode
     // If zero dimensions in windowed mode, set windowed mode to maximize and set a predefined default restored window size. If zero in fullscreen, use desktop mode
     if (!width || !height)
     if (!width || !height)
     {
     {
-        if (fullscreen || borderless || maximize)
+        if (fullscreen || borderless)
         {
         {
             width = mode.w;
             width = mode.w;
             height = mode.h;
             height = mode.h;
         }
         }
         else
         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;
         }
         }
     }
     }
 
 
@@ -484,13 +493,13 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
         }
         }
     }
     }
 
 
+    if (maximize)
+        width = height = 0;
+
     AdjustWindow(width, height, fullscreen, borderless);
     AdjustWindow(width, height, fullscreen, borderless);
 
 
-    if (maximize)
-    {
-        Maximize();
-        SDL_GetWindowSize(impl_->window_, &width, &height);
-    }
+    if (center)
+        CenterWindow();
 
 
     if (!impl_->device_ || multiSample_ != multiSample)
     if (!impl_->device_ || multiSample_ != multiSample)
         CreateDevice(width, height, multiSample);
         CreateDevice(width, height, multiSample);