Browse Source

Negative x/y position for initial window centers on screen

JoshEngebretson 10 years ago
parent
commit
ba88d2657c

+ 5 - 5
Script/AtomicEditor/editor/Preferences.ts

@@ -157,12 +157,12 @@ class PreferencesFormat {
         }
         }
 
 
         this.playerWindow = {
         this.playerWindow = {
-            x: 0,
-            y: 0,
-            width: 0,
-            height: 0,
+            x: -1, // negative value centers on screen
+            y: -1,
+            width: 1280,
+            height: 720,
             monitor: 0,
             monitor: 0,
-            maximized: true
+            maximized: false
         }
         }
 
 
     }
     }

+ 13 - 0
Source/Atomic/Graphics/Direct3D11/D3D11Graphics.cpp

@@ -2200,6 +2200,19 @@ bool Graphics::OpenWindow(int width, int height, bool resizable, bool borderless
         if (borderless)
         if (borderless)
             flags |= SDL_WINDOW_BORDERLESS;
             flags |= SDL_WINDOW_BORDERLESS;
 
 
+        // ATOMIC BEGIN
+
+        // if position is negative, center the window
+        if (position_.x_ < 0 || position_.y_ < 0)
+        {
+            IntVector2 size = GetDesktopResolution();
+            position_.x_ = size.x_/2 -  width/2;
+            position_.y_ = size.y_/2 -  height/2;
+        }
+
+        // ATOMIC END
+
+
         impl_->window_ = SDL_CreateWindow(windowTitle_.CString(), position_.x_, position_.y_, width, height, flags);
         impl_->window_ = SDL_CreateWindow(windowTitle_.CString(), position_.x_, position_.y_, width, height, flags);
     }
     }
     else
     else

+ 12 - 0
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -2390,6 +2390,18 @@ bool Graphics::OpenWindow(int width, int height, bool resizable, bool borderless
         if (borderless)
         if (borderless)
             flags |= SDL_WINDOW_BORDERLESS;
             flags |= SDL_WINDOW_BORDERLESS;
 
 
+        // ATOMIC BEGIN
+
+        // if position is negative, center the window
+        if (position_.x_ < 0 || position_.y_ < 0)
+        {
+            IntVector2 size = GetDesktopResolution();
+            position_.x_ = size.x_/2 -  width/2;
+            position_.y_ = size.y_/2 -  height/2;
+        }
+
+        // ATOMIC END
+
         impl_->window_ = SDL_CreateWindow(windowTitle_.CString(), position_.x_, position_.y_, width, height, flags);
         impl_->window_ = SDL_CreateWindow(windowTitle_.CString(), position_.x_, position_.y_, width, height, flags);
     }
     }
     else
     else

+ 5 - 5
Source/AtomicEditor/Application/AEEditorCommon.cpp

@@ -182,12 +182,12 @@ bool AEEditorCommon::CreateDefaultPreferences(String& path, JSONValue& prefs)
     editorWindow["maximized"] = true;
     editorWindow["maximized"] = true;
 
 
     JSONValue playerWindow;
     JSONValue playerWindow;
-    playerWindow["x"] = 0;
-    playerWindow["y"] = 0;
-    playerWindow["width"] = 0;
-    playerWindow["height"] = 0;
+    playerWindow["x"] = -1; // negative value will center window
+    playerWindow["y"] = -1;
+    playerWindow["width"] = 1280;
+    playerWindow["height"] = 720;
     playerWindow["monitor"] = 0;
     playerWindow["monitor"] = 0;
-    playerWindow["maximized"] = true;
+    playerWindow["maximized"] = false;
 
 
     root["editorWindow"] = editorWindow;
     root["editorWindow"] = editorWindow;
     root["playerWindow"] = playerWindow;
     root["playerWindow"] = playerWindow;