@@ -276,9 +276,6 @@ namespace FlaxEditor.Modules
|
||||
|
||||
// Get metadata
|
||||
int version = int.Parse(root.Attributes["Version"].Value, CultureInfo.InvariantCulture);
|
||||
var virtualDesktopBounds = Platform.VirtualDesktopBounds;
|
||||
var virtualDesktopSafeLeftCorner = virtualDesktopBounds.Location;
|
||||
var virtualDesktopSafeRightCorner = virtualDesktopBounds.BottomRight;
|
||||
|
||||
switch (version)
|
||||
{
|
||||
@@ -288,31 +285,9 @@ namespace FlaxEditor.Modules
|
||||
if (MainWindow)
|
||||
{
|
||||
var mainWindowNode = root["MainWindow"];
|
||||
Rectangle bounds = LoadBounds(mainWindowNode["Bounds"]);
|
||||
bool isMaximized = bool.Parse(mainWindowNode.GetAttribute("IsMaximized"));
|
||||
|
||||
// Clamp position to match current desktop dimensions (if window was on desktop that is now inactive)
|
||||
if (bounds.X < virtualDesktopSafeLeftCorner.X || bounds.Y < virtualDesktopSafeLeftCorner.Y || bounds.X > virtualDesktopSafeRightCorner.X || bounds.Y > virtualDesktopSafeRightCorner.Y)
|
||||
bounds.Location = virtualDesktopSafeLeftCorner;
|
||||
|
||||
if (isMaximized)
|
||||
{
|
||||
if (MainWindow.IsMaximized)
|
||||
MainWindow.Restore();
|
||||
MainWindow.ClientPosition = bounds.Location;
|
||||
MainWindow.Maximize();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mathf.Min(bounds.Size.X, bounds.Size.Y) >= 1)
|
||||
{
|
||||
MainWindow.ClientBounds = bounds;
|
||||
}
|
||||
else
|
||||
{
|
||||
MainWindow.ClientPosition = bounds.Location;
|
||||
}
|
||||
}
|
||||
bool isMaximized = true, isMinimized = false;
|
||||
Rectangle bounds = LoadBounds(mainWindowNode, ref isMaximized, ref isMinimized);
|
||||
LoadWindow(MainWindow, ref bounds, isMaximized, false);
|
||||
}
|
||||
|
||||
// Load master panel structure
|
||||
@@ -332,11 +307,13 @@ namespace FlaxEditor.Modules
|
||||
continue;
|
||||
|
||||
// Get window properties
|
||||
Rectangle bounds = LoadBounds(child["Bounds"]);
|
||||
bool isMaximized = false, isMinimized = false;
|
||||
Rectangle bounds = LoadBounds(child, ref isMaximized, ref isMinimized);
|
||||
|
||||
// Create window and floating dock panel
|
||||
var window = FloatWindowDockPanel.CreateFloatWindow(MainWindow.GUI, bounds.Location, bounds.Size, WindowStartPosition.Manual, string.Empty);
|
||||
var panel = new FloatWindowDockPanel(masterPanel, window.GUI);
|
||||
LoadWindow(panel.Window.Window, ref bounds, isMaximized, isMinimized);
|
||||
|
||||
// Load structure
|
||||
LoadPanel(child, panel);
|
||||
@@ -493,23 +470,73 @@ namespace FlaxEditor.Modules
|
||||
|
||||
private static void SaveBounds(XmlWriter writer, Window win)
|
||||
{
|
||||
var bounds = win.ClientBounds;
|
||||
|
||||
writer.WriteAttributeString("X", bounds.X.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteAttributeString("Y", bounds.Y.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteAttributeString("Width", bounds.Width.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteAttributeString("Height", bounds.Height.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteStartElement("Bounds");
|
||||
{
|
||||
var isMaximized = win.IsMaximized;
|
||||
var isMinimized = win.IsMinimized;
|
||||
if (isMinimized)
|
||||
win.Restore(); // Restore window back to desktop to get proper client bounds
|
||||
var bounds = win.ClientBounds;
|
||||
if (isMinimized)
|
||||
win.Minimize();
|
||||
writer.WriteAttributeString("X", bounds.X.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteAttributeString("Y", bounds.Y.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteAttributeString("Width", bounds.Width.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteAttributeString("Height", bounds.Height.ToString(CultureInfo.InvariantCulture));
|
||||
writer.WriteAttributeString("IsMaximized", isMaximized.ToString());
|
||||
writer.WriteAttributeString("IsMinimized", isMinimized.ToString());
|
||||
}
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
private static Rectangle LoadBounds(XmlElement node)
|
||||
private static Rectangle LoadBounds(XmlElement node, ref bool isMaximized, ref bool isMinimized)
|
||||
{
|
||||
float x = float.Parse(node.GetAttribute("X"), CultureInfo.InvariantCulture);
|
||||
float y = float.Parse(node.GetAttribute("Y"), CultureInfo.InvariantCulture);
|
||||
float width = float.Parse(node.GetAttribute("Width"), CultureInfo.InvariantCulture);
|
||||
float height = float.Parse(node.GetAttribute("Height"), CultureInfo.InvariantCulture);
|
||||
var bounds = node["Bounds"];
|
||||
var isMaximizedText = bounds.GetAttribute("IsMaximized");
|
||||
if (!string.IsNullOrEmpty(isMaximizedText))
|
||||
isMaximized = bool.Parse(isMaximizedText);
|
||||
var isMinimizedText = bounds.GetAttribute("IsMinimized");
|
||||
if (!string.IsNullOrEmpty(isMinimizedText))
|
||||
isMinimized = bool.Parse(isMinimizedText);
|
||||
float x = float.Parse(bounds.GetAttribute("X"), CultureInfo.InvariantCulture);
|
||||
float y = float.Parse(bounds.GetAttribute("Y"), CultureInfo.InvariantCulture);
|
||||
float width = float.Parse(bounds.GetAttribute("Width"), CultureInfo.InvariantCulture);
|
||||
float height = float.Parse(bounds.GetAttribute("Height"), CultureInfo.InvariantCulture);
|
||||
return new Rectangle(x, y, width, height);
|
||||
}
|
||||
|
||||
private static void LoadWindow(Window win, ref Rectangle bounds, bool isMaximized, bool isMinimized)
|
||||
{
|
||||
var virtualDesktopBounds = Platform.VirtualDesktopBounds;
|
||||
var virtualDesktopSafeLeftCorner = virtualDesktopBounds.Location;
|
||||
var virtualDesktopSafeRightCorner = virtualDesktopBounds.BottomRight;
|
||||
|
||||
// Clamp position to match current desktop dimensions (if window was on desktop that is now inactive)
|
||||
if (bounds.X < virtualDesktopSafeLeftCorner.X || bounds.Y < virtualDesktopSafeLeftCorner.Y || bounds.X > virtualDesktopSafeRightCorner.X || bounds.Y > virtualDesktopSafeRightCorner.Y)
|
||||
bounds.Location = virtualDesktopSafeLeftCorner;
|
||||
|
||||
if (isMaximized)
|
||||
{
|
||||
if (win.IsMaximized)
|
||||
win.Restore();
|
||||
win.ClientPosition = bounds.Location;
|
||||
win.Maximize();
|
||||
}
|
||||
else
|
||||
{
|
||||
if (Mathf.Min(bounds.Size.X, bounds.Size.Y) >= 1)
|
||||
{
|
||||
win.ClientBounds = bounds;
|
||||
}
|
||||
else
|
||||
{
|
||||
win.ClientPosition = bounds.Location;
|
||||
}
|
||||
if (isMinimized)
|
||||
win.Minimize();
|
||||
}
|
||||
}
|
||||
|
||||
private class LayoutNameDialog : Dialog
|
||||
{
|
||||
private TextBox _textbox;
|
||||
@@ -609,13 +636,8 @@ namespace FlaxEditor.Modules
|
||||
if (MainWindow)
|
||||
{
|
||||
writer.WriteStartElement("MainWindow");
|
||||
writer.WriteAttributeString("IsMaximized", MainWindow.IsMaximized.ToString());
|
||||
|
||||
writer.WriteStartElement("Bounds");
|
||||
SaveBounds(writer, MainWindow);
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
// Master panel structure
|
||||
@@ -628,22 +650,13 @@ namespace FlaxEditor.Modules
|
||||
{
|
||||
var panel = masterPanel.FloatingPanels[i];
|
||||
var window = panel.Window;
|
||||
|
||||
if (window == null)
|
||||
{
|
||||
Editor.LogWarning("Floating panel has missing window");
|
||||
continue;
|
||||
}
|
||||
|
||||
writer.WriteStartElement("Float");
|
||||
|
||||
SavePanel(writer, panel);
|
||||
|
||||
writer.WriteStartElement("Bounds");
|
||||
SaveBounds(writer, window.Window);
|
||||
writer.WriteEndElement();
|
||||
|
||||
writer.WriteEndElement();
|
||||
}
|
||||
|
||||
writer.WriteEndElement();
|
||||
|
||||
Reference in New Issue
Block a user