|
@@ -7,6 +7,7 @@
|
|
|
|
|
|
|
|
#include <Atomic/Engine/Engine.h>
|
|
#include <Atomic/Engine/Engine.h>
|
|
|
#include <Atomic/Input/Input.h>
|
|
#include <Atomic/Input/Input.h>
|
|
|
|
|
+#include <Atomic/Graphics/Graphics.h>
|
|
|
|
|
|
|
|
#include <Atomic/IPC/IPC.h>
|
|
#include <Atomic/IPC/IPC.h>
|
|
|
|
|
|
|
@@ -55,6 +56,8 @@ AEEditorCommon::AEEditorCommon(Context* context) :
|
|
|
|
|
|
|
|
void AEEditorCommon::Start()
|
|
void AEEditorCommon::Start()
|
|
|
{
|
|
{
|
|
|
|
|
+ ValidateWindow();
|
|
|
|
|
+
|
|
|
Input* input = GetSubsystem<Input>();
|
|
Input* input = GetSubsystem<Input>();
|
|
|
input->SetMouseVisible(true);
|
|
input->SetMouseVisible(true);
|
|
|
|
|
|
|
@@ -174,46 +177,103 @@ bool AEEditorCommon::CreateDefaultPreferences(String& path, JSONValue& prefs)
|
|
|
root["recentProjects"] = JSONArray();
|
|
root["recentProjects"] = JSONArray();
|
|
|
|
|
|
|
|
JSONValue editorWindow;
|
|
JSONValue editorWindow;
|
|
|
- editorWindow["x"] = 0;
|
|
|
|
|
- editorWindow["y"] = 0;
|
|
|
|
|
- editorWindow["width"] = 0;
|
|
|
|
|
- editorWindow["height"] = 0;
|
|
|
|
|
- editorWindow["monitor"] = 0;
|
|
|
|
|
- editorWindow["maximized"] = true;
|
|
|
|
|
|
|
+ GetDefaultWindowPreferences(editorWindow, true);
|
|
|
|
|
|
|
|
JSONValue playerWindow;
|
|
JSONValue playerWindow;
|
|
|
- playerWindow["x"] = 0;
|
|
|
|
|
- playerWindow["y"] = 0;
|
|
|
|
|
- playerWindow["width"] = 0;
|
|
|
|
|
- playerWindow["height"] = 0;
|
|
|
|
|
- playerWindow["monitor"] = 0;
|
|
|
|
|
- playerWindow["maximized"] = false;
|
|
|
|
|
|
|
+ GetDefaultWindowPreferences(playerWindow, false);
|
|
|
|
|
|
|
|
root["editorWindow"] = editorWindow;
|
|
root["editorWindow"] = editorWindow;
|
|
|
root["playerWindow"] = playerWindow;
|
|
root["playerWindow"] = playerWindow;
|
|
|
|
|
|
|
|
- SharedPtr<File> file(new File(context_, path, FILE_WRITE));
|
|
|
|
|
|
|
+ prefs = root;
|
|
|
|
|
|
|
|
- if (!file->IsOpen())
|
|
|
|
|
|
|
+ SavePreferences(prefs);
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+bool AEEditorCommon::ReadPreferences()
|
|
|
|
|
+{
|
|
|
|
|
+ FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
|
|
+ String path = GetPreferencesPath();
|
|
|
|
|
+
|
|
|
|
|
+ JSONValue prefs;
|
|
|
|
|
+
|
|
|
|
|
+ LoadPreferences(prefs);
|
|
|
|
|
+
|
|
|
|
|
+ if (!prefs.IsObject() || !prefs["editorWindow"].IsObject())
|
|
|
{
|
|
{
|
|
|
- LOGERRORF("Unable to open Atomic Editor preferences for writing: %s", path.CString());
|
|
|
|
|
- return false;
|
|
|
|
|
|
|
+ if (!CreateDefaultPreferences(path, prefs))
|
|
|
|
|
+ return false;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- jsonFile->Save(*file, " ");
|
|
|
|
|
|
|
+ JSONValue& editorWindow = prefs["editorWindow"];
|
|
|
|
|
|
|
|
- prefs = root;
|
|
|
|
|
|
|
+ engineParameters_["WindowPositionX"] = editorWindow["x"].GetUInt();
|
|
|
|
|
+ engineParameters_["WindowPositionY"] = editorWindow["y"].GetUInt();
|
|
|
|
|
+ engineParameters_["WindowWidth"] = editorWindow["width"].GetUInt();
|
|
|
|
|
+ engineParameters_["WindowHeight"] = editorWindow["height"].GetUInt();
|
|
|
|
|
+ engineParameters_["WindowMaximized"] = editorWindow["maximized"].GetBool();
|
|
|
|
|
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-bool AEEditorCommon::ReadPreferences()
|
|
|
|
|
|
|
+void AEEditorCommon::ValidateWindow()
|
|
|
|
|
+{
|
|
|
|
|
+ Graphics* graphics = GetSubsystem<Graphics>();
|
|
|
|
|
+ IntVector2 windowPosition = graphics->GetWindowPosition();
|
|
|
|
|
+ int monitors = graphics->GetNumMonitors();
|
|
|
|
|
+ IntVector2 maxResolution;
|
|
|
|
|
+
|
|
|
|
|
+ for (int i = 0; i < monitors; i++)
|
|
|
|
|
+ {
|
|
|
|
|
+ IntVector2 monitorResolution = graphics->GetMonitorResolution(i);
|
|
|
|
|
+ maxResolution += monitorResolution;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (windowPosition.x_ >= maxResolution.x_ || windowPosition.y_ >= maxResolution.y_ || (windowPosition.x_ + graphics->GetWidth()) < 0 || (windowPosition.y_ + graphics->GetHeight()) < 0)
|
|
|
|
|
+ {
|
|
|
|
|
+ JSONValue prefs;
|
|
|
|
|
+
|
|
|
|
|
+ if (!LoadPreferences(prefs))
|
|
|
|
|
+ return;
|
|
|
|
|
+
|
|
|
|
|
+ bool editor = context_->GetEditorContext();
|
|
|
|
|
+
|
|
|
|
|
+ JSONValue window;
|
|
|
|
|
+ GetDefaultWindowPreferences(window, editor);
|
|
|
|
|
+
|
|
|
|
|
+ prefs[editor ? "editorWindow" : "playerWindow"] = window;
|
|
|
|
|
+
|
|
|
|
|
+ //Setting the mode to 0 width/height will use engine defaults for window size and layout
|
|
|
|
|
+ graphics->SetMode(0, 0, graphics->GetFullscreen(), graphics->GetBorderless(), graphics->GetResizable(), graphics->GetVSync(), graphics->GetTripleBuffer(), graphics->GetMultiSample(), editor);
|
|
|
|
|
+
|
|
|
|
|
+ SavePreferences(prefs);
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void AEEditorCommon::GetDefaultWindowPreferences(JSONValue& windowPrefs, bool maximized)
|
|
|
|
|
+{
|
|
|
|
|
+ windowPrefs["x"] = 0;
|
|
|
|
|
+ windowPrefs["y"] = 0;
|
|
|
|
|
+ windowPrefs["width"] = 0;
|
|
|
|
|
+ windowPrefs["height"] = 0;
|
|
|
|
|
+ windowPrefs["monitor"] = 0;
|
|
|
|
|
+ windowPrefs["maximized"] = maximized;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+String AEEditorCommon::GetPreferencesPath()
|
|
|
{
|
|
{
|
|
|
FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
String path = fileSystem->GetAppPreferencesDir("AtomicEditor", "Preferences");
|
|
String path = fileSystem->GetAppPreferencesDir("AtomicEditor", "Preferences");
|
|
|
path += "prefs.json";
|
|
path += "prefs.json";
|
|
|
|
|
+ return path;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- JSONValue prefs;
|
|
|
|
|
|
|
+bool AEEditorCommon::LoadPreferences(JSONValue& prefs)
|
|
|
|
|
+{
|
|
|
|
|
+ FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
|
|
+ String path = GetPreferencesPath();
|
|
|
|
|
|
|
|
if (!fileSystem->FileExists(path))
|
|
if (!fileSystem->FileExists(path))
|
|
|
{
|
|
{
|
|
@@ -236,22 +296,31 @@ bool AEEditorCommon::ReadPreferences()
|
|
|
prefs = jsonFile->GetRoot();
|
|
prefs = jsonFile->GetRoot();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ file->Close();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- if (!prefs.IsObject() || !prefs["editorWindow"].IsObject())
|
|
|
|
|
- {
|
|
|
|
|
- if (!CreateDefaultPreferences(path, prefs))
|
|
|
|
|
- return false;
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ return true;
|
|
|
|
|
+}
|
|
|
|
|
|
|
|
- JSONValue& editorWindow = prefs["editorWindow"];
|
|
|
|
|
|
|
+bool AEEditorCommon::SavePreferences(JSONValue& prefs)
|
|
|
|
|
+{
|
|
|
|
|
+ FileSystem* fileSystem = GetSubsystem<FileSystem>();
|
|
|
|
|
+ String path = GetPreferencesPath();
|
|
|
|
|
|
|
|
- engineParameters_["WindowPositionX"] = editorWindow["x"].GetUInt();
|
|
|
|
|
- engineParameters_["WindowPositionY"] = editorWindow["y"].GetUInt();
|
|
|
|
|
- engineParameters_["WindowWidth"] = editorWindow["width"].GetUInt();
|
|
|
|
|
- engineParameters_["WindowHeight"] = editorWindow["height"].GetUInt();
|
|
|
|
|
- engineParameters_["WindowMaximized"] = editorWindow["maximized"].GetBool();
|
|
|
|
|
|
|
+ SharedPtr<File> file(new File(context_, path, FILE_WRITE));
|
|
|
|
|
+ SharedPtr<JSONFile> jsonFile(new JSONFile(context_));
|
|
|
|
|
+
|
|
|
|
|
+ jsonFile->GetRoot() = prefs;
|
|
|
|
|
|
|
|
|
|
+ if (!file->IsOpen())
|
|
|
|
|
+ {
|
|
|
|
|
+ LOGERRORF("Unable to open Atomic Editor preferences for writing: %s", path.CString());
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ jsonFile->Save(*file, " ");
|
|
|
|
|
+ file->Close();
|
|
|
|
|
+
|
|
|
return true;
|
|
return true;
|
|
|
}
|
|
}
|
|
|
|
|
|