Răsfoiți Sursa

Additional window preference cleanup

JoshEngebretson 10 ani în urmă
părinte
comite
4b18bb6b37

+ 2 - 3
Script/AtomicEditor/editor/Editor.ts

@@ -61,9 +61,8 @@ class Editor extends Atomic.ScriptObject {
                 playerWindow.y = data.posY;
                 playerWindow.monitor = data.monitor;
                 playerWindow.maximized = true;
-                playerWindow.centered = false;
             } else {
-                playerWindow = {x: data.posX, y: data.posY, width: data.width, height: data.height, monitor: data.monitor, maximized: data.maximized, centered: false};
+                playerWindow = {x: data.posX, y: data.posY, width: data.width, height: data.height, monitor: data.monitor, maximized: data.maximized};
             }
             Preferences.getInstance().savePlayerWindowData(playerWindow);
         });
@@ -116,7 +115,7 @@ class Editor extends Atomic.ScriptObject {
             editorWindowData.maximized = true;
             editorWindowData.monitor = monitor;
         } else {
-            editorWindowData = {x: pos[0], y: pos[1], width: width, height: height, monitor: monitor, maximized: false, centered: false}
+            editorWindowData = {x: pos[0], y: pos[1], width: width, height: height, monitor: monitor, maximized: false}
         }
 
         Preferences.getInstance().saveEditorWindowData(editorWindowData);

+ 4 - 7
Script/AtomicEditor/editor/Preferences.ts

@@ -131,7 +131,6 @@ interface WindowData {
     height: number;
     monitor: number;
     maximized: boolean;
-    centered: boolean;
 }
 
 class PreferencesFormat {
@@ -151,18 +150,16 @@ class PreferencesFormat {
             width: 0,
             height: 0,
             monitor: 0,
-            maximized: true,
-            centered: false
+            maximized: true
         }
 
         this.playerWindow = {
             x: 0,
             y: 0,
-            width: 1280,
-            height: 720,
+            width: 0,
+            height: 0,
             monitor: 0,
-            maximized: false,
-            centered: true
+            maximized: false
         }
 
     }

+ 0 - 3
Script/AtomicEditor/ui/Shortcuts.ts

@@ -39,9 +39,6 @@ class Shortcuts extends Atomic.ScriptObject {
                     if (playerWindow.maximized) {
                         args += " --maximize";
                     }
-                    if (playerWindow.centered) {
-                        args += " --center";
-                    }
                     Atomic.editorMode.playProject(args, debug);
                 }
             } else {

+ 3 - 4
Source/Atomic/Engine/Engine.cpp

@@ -368,16 +368,15 @@ bool Engine::Initialize(const VariantMap& parameters)
 #endif
 
         if (!graphics->SetMode(
-            GetParameter(parameters, "WindowWidth", 0).GetInt(),
-            GetParameter(parameters, "WindowHeight", 0).GetInt(),
+            GetParameter(parameters, "WindowMaximized", false).GetBool() ? 0 : GetParameter(parameters, "WindowWidth", 0).GetInt(),
+            GetParameter(parameters, "WindowMaximized", false).GetBool() ? 0 : GetParameter(parameters, "WindowHeight", 0).GetInt(),
             GetParameter(parameters, "FullScreen", true).GetBool(),
             GetParameter(parameters, "Borderless", false).GetBool(),
             GetParameter(parameters, "WindowResizable", false).GetBool(),
             GetParameter(parameters, "VSync", false).GetBool(),
             GetParameter(parameters, "TripleBuffer", false).GetBool(),
             GetParameter(parameters, "MultiSample", 1).GetInt(),
-            GetParameter(parameters, "WindowMaximized", false).GetBool(),
-            GetParameter(parameters, "WindowCentered", false).GetBool()
+            GetParameter(parameters, "WindowMaximized", false).GetBool()
         ))
             return false;
 

+ 22 - 16
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -405,7 +405,7 @@ void Graphics::RaiseWindow()
         SDL_RaiseWindow(impl_->window_);
 }
 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);
 
@@ -414,18 +414,27 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
     SDL_GetDesktopDisplayMode(0, &mode);
     D3DFORMAT fullscreenFormat = SDL_BITSPERPIXEL(mode.format) == 16 ? D3DFMT_R5G6B5 : D3DFMT_X8R8G8B8;
 
+    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 (!width || !height)
     {
-        if (fullscreen || borderless || maximize)
+        if (fullscreen || borderless)
         {
             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;
         }
     }
 
@@ -448,7 +457,7 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
 
     if (!impl_->window_)
     {
-        if (!OpenWindow(width, height, resizable, borderless, center))
+        if (!OpenWindow(width, height, resizable, borderless))
             return false;
     }
 
@@ -497,13 +506,13 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
             multiSample = 1;
     }
 
+    if (maximize)
+        width = height = 0;
+
     AdjustWindow(width, height, fullscreen, borderless);
 
-    if (maximize)
-    {
-        Maximize();
-        SDL_GetWindowSize(impl_->window_, &width, &height);
-    }
+    if (center)
+        CenterWindow();
 
     if (fullscreen)
     {
@@ -599,7 +608,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)
@@ -620,7 +629,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()
@@ -2380,7 +2389,7 @@ void Graphics::ResetStreamFrequencies()
     }
 }
 
-bool Graphics::OpenWindow(int width, int height, bool resizable, bool borderless, bool center)
+bool Graphics::OpenWindow(int width, int height, bool resizable, bool borderless)
 {
     if (!externalWindow_)
     {
@@ -2401,9 +2410,6 @@ bool Graphics::OpenWindow(int width, int height, bool resizable, bool borderless
         return false;
     }
 
-    if (center)
-        CenterWindow();
-
     SDL_GetWindowPosition(impl_->window_, &position_.x_, &position_.y_);
 
     CreateWindowIcon();

+ 2 - 2
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.h

@@ -104,7 +104,7 @@ public:
     /// Bring the window to front with focus
     void RaiseWindow();
     /// 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.
@@ -507,7 +507,7 @@ private:
     /// Reset stream frequencies.
     void ResetStreamFrequencies();
     /// Create the application window.
-    bool OpenWindow(int width, int height, bool resizable, bool borderless, bool center);
+    bool OpenWindow(int width, int height, bool resizable, bool borderless);
     /// Create the application window icon.
     void CreateWindowIcon();
     /// Adjust the window for new resolution and fullscreen mode.

+ 2 - 4
Source/AtomicEditor/Application/AEEditorCommon.cpp

@@ -180,16 +180,14 @@ bool AEEditorCommon::CreateDefaultPreferences(String& path, JSONValue& prefs)
     editorWindow["height"] = 0;
     editorWindow["monitor"] = 0;
     editorWindow["maximized"] = true;
-    editorWindow["centered"] = false;
 
     JSONValue playerWindow;
     playerWindow["x"] = 0;
     playerWindow["y"] = 0;
-    playerWindow["width"] = 1280;
-    playerWindow["height"] = 720;
+    playerWindow["width"] = 0;
+    playerWindow["height"] = 0;
     playerWindow["monitor"] = 0;
     playerWindow["maximized"] = false;
-    playerWindow["centered"] = true;
 
     root["editorWindow"] = editorWindow;
     root["playerWindow"] = playerWindow;

+ 0 - 4
Source/AtomicEditor/Application/AEPlayerApp.cpp

@@ -179,10 +179,6 @@ void AEPlayerApplication::Setup()
             {
                 engineParameters_["WindowMaximized"] = true;
             }
-            else if (argument == "--center")
-            {
-                engineParameters_["WindowCentered"] = true;
-            }
         }
     }