Browse Source

Merge pull request #545 from rsredsq/RED-EDITOR-511

Windows editor start maximized if exited in this state
LaraEngebretson 10 years ago
parent
commit
a8b8b9d445

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

@@ -54,9 +54,22 @@ class Editor extends Atomic.ScriptObject {
         });
 
         this.subscribeToEvent("IPCPlayerWindowChanged", (data) => {
-            Preferences.getInstance().savePlayerWindowData(data.posX, data.posY, data.width, data.height, data.monitor);
+            var playerWindow = Preferences.getInstance().playerWindow;
+            //if player window is maximized, then we want keep the window size from the previous state
+            if (data.maximized) {
+                playerWindow.x = data.posX;
+                playerWindow.y = data.posY;
+                playerWindow.monitor = data.monitor;
+                playerWindow.maximized = true;
+            } else {
+                playerWindow = {x: data.posX, y: data.posY, width: data.width, height: data.height, monitor: data.monitor, maximized: data.maximized};
+            }
+            Preferences.getInstance().savePlayerWindowData(playerWindow);
         });
 
+        this.subscribeToEvent("ScreenMode", (data:Atomic.ScreenModeEvent) => this.saveWindowPreferences(data));
+        this.subscribeToEvent("WindowPos", (data:Atomic.ScreenModeEvent) => this.saveWindowPreferences(data));
+
         this.subscribeToEvent("ExitRequested", (data) => this.handleExitRequested(data));
 
         this.subscribeToEvent("ProjectLoaded", (data) => {
@@ -85,6 +98,31 @@ class Editor extends Atomic.ScriptObject {
 
     }
 
+    saveWindowPreferences(data: Atomic.ScreenModeEvent): boolean {
+        var graphics = Atomic.getGraphics();
+        if (!graphics) return false;
+
+        var pos = graphics.getWindowPosition();
+        var width = graphics.getWidth();
+        var height = graphics.getHeight();
+        var monitor = graphics.getCurrentMonitor();
+
+        var editorWindowData = Preferences.getInstance().editorWindow;
+
+        if (graphics.getMaximized()) {
+            editorWindowData.x = pos[0];
+            editorWindowData.y = pos[1];
+            editorWindowData.maximized = true;
+            editorWindowData.monitor = monitor;
+        } else {
+            editorWindowData = {x: pos[0], y: pos[1], width: width, height: height, monitor: monitor, maximized: false}
+        }
+
+        Preferences.getInstance().saveEditorWindowData(editorWindowData);
+
+        return true;
+    }
+
     handleEditorLoadProject(event: EditorEvents.LoadProjectEvent): boolean {
 
         var system = ToolCore.getToolSystem();
@@ -170,7 +208,7 @@ class Editor extends Atomic.ScriptObject {
     }
 
     exit() {
-        Preferences.getInstance().write();
+        //Preferences.getInstance().write();
         EditorUI.shutdown();
         Atomic.getEngine().exit();
     }

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

@@ -83,27 +83,26 @@ class Preferences {
 
     }
 
-    write(): void {
+    write(): boolean {
         var filePath = this.getPreferencesFullPath();
         var jsonFile = new Atomic.File(filePath, Atomic.FILE_WRITE);
-        if (!jsonFile.isOpen()) return;
-        var graphics = Atomic.getGraphics();
-        var pos, width, height;
-        if (graphics && !graphics.getFullscreen()) {
-            pos = graphics.getWindowPosition();
-            width = graphics.getWidth();
-            height = graphics.getHeight();
-        }
-        this._prefs.editorWindow = { x: pos[0], y: pos[1], width: width, height: height, monitor: graphics.getCurrentMonitor() };
+        if (!jsonFile.isOpen()) return false;
         jsonFile.writeString(JSON.stringify(this._prefs, null, 2));
     }
 
-    savePlayerWindowData(x, y, width, height, monitor) {
-        this._prefs.playerWindow = { x: x, y: y, width: width, height: height, monitor: monitor };
+    saveEditorWindowData(windowData:WindowData) {
+        this._prefs.editorWindow = windowData;
+        this.write();
+    }
+
+    savePlayerWindowData(windowData:WindowData) {
+        this._prefs.playerWindow = windowData;
+        this.write();
     }
 
     useDefaultConfig():void {
         this._prefs = new PreferencesFormat();
+        if (!this._prefs.recentProjects) this._prefs.recentProjects = [""];
     }
 
     get editorWindow():WindowData {
@@ -129,6 +128,7 @@ interface WindowData {
     width: number;
     height: number;
     monitor: number;
+    maximized: boolean;
 }
 
 class PreferencesFormat {

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

@@ -36,6 +36,9 @@ class Shortcuts extends Atomic.ScriptObject {
                     Atomic.editorMode.playProject(args, debug);
                 } else {
                     var args = "--windowposx " + playerWindow.x + " --windowposy " + playerWindow.y + " --windowwidth " + playerWindow.width + " --windowheight " + playerWindow.height + " --resizable";
+                    if (playerWindow.maximized) {
+                        args += " --maximize";
+                    }
                     Atomic.editorMode.playProject(args, debug);
                 }
             } else {

+ 2 - 1
Source/Atomic/Engine/Engine.cpp

@@ -375,7 +375,8 @@ bool Engine::Initialize(const VariantMap& parameters)
             GetParameter(parameters, "WindowResizable", false).GetBool(),
             GetParameter(parameters, "VSync", false).GetBool(),
             GetParameter(parameters, "TripleBuffer", false).GetBool(),
-            GetParameter(parameters, "MultiSample", 1).GetInt()
+            GetParameter(parameters, "MultiSample", 1).GetInt(),
+            GetParameter(parameters, "WindowMaximized", false).GetBool()
         ))
             return false;
 

+ 10 - 6
Source/Atomic/Graphics/Direct3D11/D3D11Graphics.cpp

@@ -413,12 +413,10 @@ void Graphics::RaiseWindow()
 }
 
 bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer,
-    int multiSample)
+    int multiSample, bool maximize)
 {
     PROFILE(SetScreenMode);
 
-    bool maximize = false;
-
     // Find out the full screen mode display format (match desktop color depth)
     SDL_DisplayMode mode;
     SDL_GetDesktopDisplayMode(0, &mode);
@@ -434,7 +432,6 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
         }
         else
         {
-            maximize = resizable;
             width = 1024;
             height = 768;
         }
@@ -536,7 +533,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_);
+    return SetMode(width, height, fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false);
 }
 
 void Graphics::SetSRGB(bool enable)
@@ -578,7 +575,7 @@ void Graphics::SetOrientations(const String& orientations)
 
 bool Graphics::ToggleFullscreen()
 {
-    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false);
 }
 
 void Graphics::Close()
@@ -2791,6 +2788,13 @@ int Graphics::GetMonitorsNumber()
 {
     return SDL_GetNumVideoDisplays();
 }
+bool Graphics::GetMaximized()
+{
+    if (!impl_->window_)
+        return false;
+
+    return SDL_GetWindowFlags(impl_->window_) & SDL_WINDOW_MAXIMIZED;
+}
 // ATOMIC END
 
 }

+ 3 - 1
Source/Atomic/Graphics/Direct3D11/D3D11Graphics.h

@@ -107,7 +107,7 @@ public:
     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);
+        (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.
@@ -504,6 +504,8 @@ public:
     int GetCurrentMonitor();
     /// Return the available monitors number
     int GetMonitorsNumber();
+    /// Return true if window is maximized
+    bool GetMaximized();
     // ATOMIC END
 
 private:

+ 11 - 6
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.cpp

@@ -405,12 +405,10 @@ 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)
+    int multiSample, bool maximize)
 {
     PROFILE(SetScreenMode);
 
-    bool maximize = false;
-
     // Find out the full screen mode display format (match desktop color depth)
     SDL_DisplayMode mode;
     SDL_GetDesktopDisplayMode(0, &mode);
@@ -426,7 +424,6 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
         }
         else
         {
-            maximize = resizable;
             width = 1024;
             height = 768;
         }
@@ -602,7 +599,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_);
+    return SetMode(width, height, fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false);
 }
 
 void Graphics::SetSRGB(bool enable)
@@ -623,7 +620,7 @@ void Graphics::SetOrientations(const String& orientations)
 
 bool Graphics::ToggleFullscreen()
 {
-    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false);
 }
 
 void Graphics::Close()
@@ -2771,6 +2768,14 @@ int Graphics::GetMonitorsNumber()
 {
     return SDL_GetNumVideoDisplays();
 }
+
+bool Graphics::GetMaximized()
+{
+    if (!impl_->window_)
+        return false;
+
+    return SDL_GetWindowFlags(impl_->window_) & SDL_WINDOW_MAXIMIZED;
+}
 // ATOMIC END
 
 }

+ 3 - 1
Source/Atomic/Graphics/Direct3D9/D3D9Graphics.h

@@ -105,7 +105,7 @@ public:
     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);
+        (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.
@@ -498,6 +498,8 @@ public:
     int GetCurrentMonitor();
     /// Return the available monitors number
     int GetMonitorsNumber();
+    /// Return true if window is maximized
+    bool GetMaximized();
     // ATOMIC END
 
 private:

+ 10 - 6
Source/Atomic/Graphics/OpenGL/OGLGraphics.cpp

@@ -334,12 +334,10 @@ void* Graphics::GetSDLWindow()
 }
 
 bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless, bool resizable, bool vsync, bool tripleBuffer,
-    int multiSample)
+    int multiSample, bool maximize)
 {
     PROFILE(SetScreenMode);
 
-    bool maximize = false;
-
     // Fullscreen or Borderless can not be resizable
     if (fullscreen || borderless)
         resizable = false;
@@ -376,7 +374,6 @@ bool Graphics::SetMode(int width, int height, bool fullscreen, bool borderless,
         }
         else
         {
-            maximize = resizable;
             width = 1024;
             height = 768;
         }
@@ -580,7 +577,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_);
+    return SetMode(width, height, fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false);
 }
 
 void Graphics::SetSRGB(bool enable)
@@ -617,7 +614,7 @@ void Graphics::SetOrientations(const String& orientations)
 
 bool Graphics::ToggleFullscreen()
 {
-    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_);
+    return SetMode(width_, height_, !fullscreen_, borderless_, resizable_, vsync_, tripleBuffer_, multiSample_, false);
 }
 
 void Graphics::Close()
@@ -3306,6 +3303,13 @@ int Graphics::GetMonitorsNumber()
 {
     return SDL_GetNumVideoDisplays();
 }
+bool Graphics::GetMaximized()
+{
+    if (!impl_->window_)
+        return false;
+
+    return SDL_GetWindowFlags(impl_->window_) & SDL_WINDOW_MAXIMIZED;
+}
 // ATOMIC END
 
 }

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

@@ -104,7 +104,7 @@ public:
     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);
+        (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.
@@ -530,6 +530,8 @@ public:
     int GetCurrentMonitor();
     /// Return the available monitors number
     int GetMonitorsNumber();
+    /// Return true if window is maximized
+    bool GetMaximized();
     // ATOMIC END
 
 private:

+ 1 - 0
Source/AtomicEditor/Application/AEEditorApp.cpp

@@ -122,6 +122,7 @@ void AEEditorApp::Setup()
             engineParameters_["WindowPositionY"] = editorWindow.Get("y").GetUInt();
             engineParameters_["WindowWidth"] = editorWindow.Get("width").GetUInt();
             engineParameters_["WindowHeight"] = editorWindow.Get("height").GetUInt();
+            engineParameters_["WindowMaximized"] = editorWindow.Get("maximized").GetBool();
         }
     }
 }

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

@@ -173,6 +173,10 @@ void AEPlayerApplication::Setup()
             else if (argument == "--resizable") 
             {
                 engineParameters_["WindowResizable"] = true;
+            } 
+            else if (argument == "--maximize")
+            {
+                engineParameters_["WindowMaximized"] = true;
             }
         }
     }

+ 1 - 0
Source/AtomicEditor/PlayerMode/AEPlayerEvents.h

@@ -26,6 +26,7 @@ EVENT(E_IPCPLAYERWINDOWCHANGED, IPCPlayerWindowChanged)
     PARAM(P_WIDTH, Width);
     PARAM(P_HEIGHT, Height);
     PARAM(P_MONITOR, Monitor);
+    PARAM(P_MAXIMIZED, Maximized);
 }
 
 EVENT(E_PLAYERQUIT, PlayerQuit)

+ 8 - 1
Source/AtomicEditor/PlayerMode/AEPlayerMode.cpp

@@ -47,6 +47,8 @@ PlayerMode::PlayerMode(Context* context) :
     SubscribeToEvent(E_LOGMESSAGE, HANDLER(PlayerMode, HandleLogMessage));
     SubscribeToEvent(E_JSERROR, HANDLER(PlayerMode, HandleJSError));
     SubscribeToEvent(E_EXITREQUESTED, HANDLER(PlayerMode, HandleExitRequest));
+    SubscribeToEvent(E_SCREENMODE, HANDLER(PlayerMode, HandlePlayerWindowChanged));
+    SubscribeToEvent(E_WINDOWPOS, HANDLER(PlayerMode, HandlePlayerWindowChanged));
 
     // BEGIN LICENSE MANAGEMENT
     SubscribeToEvent(E_BEGINVIEWRENDER, HANDLER(PlayerMode, HandleViewRender));
@@ -239,7 +241,7 @@ void PlayerMode::HandleViewRender(StringHash eventType, VariantMap& eventData)
 
 }
 
-void PlayerMode::HandleExitRequest(StringHash eventType, VariantMap& eventData)
+void PlayerMode::HandlePlayerWindowChanged(StringHash eventType, VariantMap& eventData)
 {
     Graphics* graphics = GetSubsystem<Graphics>();
     using namespace IPCPlayerWindowChanged;
@@ -249,7 +251,12 @@ void PlayerMode::HandleExitRequest(StringHash eventType, VariantMap& eventData)
     data[P_WIDTH] = graphics->GetWidth();
     data[P_HEIGHT] = graphics->GetHeight();
     data[P_MONITOR] = graphics->GetCurrentMonitor();
+    data[P_MAXIMIZED] = graphics->GetMaximized();
     ipc_->SendEventToBroker(E_IPCPLAYERWINDOWCHANGED, data);
+}
+
+void PlayerMode::HandleExitRequest(StringHash eventType, VariantMap& eventData)
+{
     SendEvent(E_PLAYERQUIT);
 }
 

+ 1 - 0
Source/AtomicEditor/PlayerMode/AEPlayerMode.h

@@ -42,6 +42,7 @@ private:
     void HandleIPCInitialize(StringHash eventType, VariantMap& eventData);
     void HandleViewRender(StringHash eventType, VariantMap& eventData);
     void HandleExitRequest(StringHash eventType, VariantMap& eventData);
+    void HandlePlayerWindowChanged(StringHash eventType, VariantMap& eventData);
 
 // BEGIN LICENSE MANAGEMENT
     void HandleMessageAck(StringHash eventType, VariantMap& eventData);