Explorar o código

Added settings window
Editor windows can now be resized from managed code
Editor windows will open in the center of the screen

BearishSun %!s(int64=10) %!d(string=hai) anos
pai
achega
97d3129728

+ 1 - 1
BansheeCore/Source/Win32/BsWin32Window.cpp

@@ -226,7 +226,7 @@ namespace BansheeEngine
 	{
 		if (m->hWnd)
 		{
-			RECT rc = { m->top, m->left, width, height };
+			RECT rc = { 0, 0, width, height };
 			AdjustWindowRect(&rc, GetWindowLong(m->hWnd, GWL_STYLE), false);
 			width = rc.right - rc.left;
 			height = rc.bottom - rc.top;

+ 14 - 2
BansheeEditor/Include/BsEditorWidgetContainer.h

@@ -109,9 +109,23 @@ namespace BansheeEngine
 		 */
 		void _notifyWidgetDestroyed(EditorWidgetBase* widget);
 
+		/**
+		 * @brief	Returns the size of a widget docked in a window of the specified size. Window and widget sizes are
+		 * 			different due to the title bar and potentially other window-specific GUI elements.
+		 */
+		static Vector2I windowToWidgetSize(const Vector2I& windowSize);
+
+		/**
+		 * @brief	Returns the size of a window required for displaying a widget of the specified size. Window and widget 
+		 * 			sizes are different due to the title bar and potentially other window-specific GUI elements.
+		 */
+		static Vector2I widgetToWindowSize(const Vector2I& widgetSize);
+
 		Event<void()> onWidgetAdded; /**< Triggered whenever a new widget is added to this container. */
 		Event<void()> onWidgetClosed; /**< Triggered whenever a widget docked in this container is closed. */
 		Event<void()> onMaximized; /**< Triggered when the maximize button is clicked. */
+
+		static const UINT32 TitleBarHeight;
 	private:
 		EditorWindowBase* mParentWindow;
 		GUITabbedTitleBar* mTitleBar;
@@ -122,8 +136,6 @@ namespace BansheeEngine
 		UnorderedMap<UINT32, EditorWidgetBase*> mWidgets;
 		INT32 mActiveWidget;
 
-		static const UINT32 TitleBarHeight;
-
 		/**
 		 * @brief	Removes a widget without triggering a widget closed event.
 		 */

+ 18 - 2
BansheeEditor/Source/BsEditorWidgetContainer.cpp

@@ -170,9 +170,9 @@ namespace BansheeEngine
 		if(mActiveWidget >= 0)
 		{
 			EditorWidgetBase* activeWidgetPtr = mWidgets[mActiveWidget];
-			UINT32 contentHeight = (UINT32)std::max(0, (INT32)height - (INT32)TitleBarHeight);
 
-			activeWidgetPtr->_setSize(width, contentHeight);
+			Vector2I widgetSize = windowToWidgetSize(Vector2I(width, height));
+			activeWidgetPtr->_setSize((UINT32)widgetSize.x, (UINT32)widgetSize.y);
 		}
 
 		mWidth = width;
@@ -301,4 +301,20 @@ namespace BansheeEngine
 			}
 		}		
 	}
+
+	Vector2I EditorWidgetContainer::windowToWidgetSize(const Vector2I& windowSize)
+	{
+		Vector2I widgetSize = windowSize;
+		widgetSize.y = std::max(0, widgetSize.y - (INT32)TitleBarHeight);
+
+		return widgetSize;
+	}
+
+	Vector2I EditorWidgetContainer::widgetToWindowSize(const Vector2I& widgetSize)
+	{
+		Vector2I windowSize = widgetSize;
+		windowSize.y += TitleBarHeight;
+
+		return windowSize;
+	}
 }

+ 2 - 1
BansheeEditor/Source/BsEditorWindowBase.cpp

@@ -22,6 +22,8 @@ namespace BansheeEngine
 		renderWindowDesc.toolWindow = true;
 		renderWindowDesc.modal = isModal;
 		renderWindowDesc.hideUntilSwap = true;
+		renderWindowDesc.left = -1;
+		renderWindowDesc.top = -1;
 
 		mRenderWindow = RenderWindow::create(renderWindowDesc, gCoreApplication().getPrimaryWindow());
 
@@ -46,7 +48,6 @@ namespace BansheeEngine
 
 	void EditorWindowBase::initialize()
 	{
-		setPosition(0, 0);
 		setSize(200, 200);
 	}
 

+ 16 - 2
MBansheeEditor/EditorWindow.cs

@@ -14,12 +14,20 @@ namespace BansheeEditor
         /// <summary>
         /// Width of the window in pixels.
         /// </summary>
-        public int Width { get { return Internal_GetWidth(mCachedPtr); } }
+        public int Width
+        {
+            get { return Internal_GetWidth(mCachedPtr); }
+            set { Internal_SetWidth(mCachedPtr, value); }
+        }
 
         /// <summary>
         /// Height of the window in pixels.
         /// </summary>
-        public int Height { get { return Internal_GetHeight(mCachedPtr); } }
+        public int Height
+        {
+            get { return Internal_GetHeight(mCachedPtr); }
+            set { Internal_SetHeight(mCachedPtr, value); }
+        }
 
         /// <summary>
         /// Determines whether the editor window currently has keyboard focus (has been clicked on most recently).
@@ -109,9 +117,15 @@ namespace BansheeEditor
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern int Internal_GetWidth(IntPtr nativeInstance);
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetWidth(IntPtr nativeInstance, int width);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern int Internal_GetHeight(IntPtr nativeInstance);
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetHeight(IntPtr nativeInstance, int height);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern bool Internal_HasFocus(IntPtr nativeInstance);
 

+ 1 - 0
MBansheeEditor/MBansheeEditor.csproj

@@ -148,6 +148,7 @@
     <Compile Include="Scene\ScaleHandle.cs" />
     <Compile Include="ScriptCompiler.cs" />
     <Compile Include="Selection.cs" />
+    <Compile Include="SettingsWindow.cs" />
     <Compile Include="ToolbarItem.cs" />
     <Compile Include="UndoRedo.cs" />
     <Compile Include="UnitTests.cs" />

+ 78 - 0
MBansheeEditor/SettingsWindow.cs

@@ -0,0 +1,78 @@
+using BansheeEngine;
+
+namespace BansheeEditor
+{
+    /// <summary>
+    /// Displays project and editor settings
+    /// </summary>
+    internal sealed class SettingsWindow : EditorWindow
+    {
+        private GUIFloatField defaultHandleSizeField;
+        private GUIToggleField autoLoadLastProjectField;
+
+        /// <summary>
+        /// Opens the settings window if its not open already.
+        /// </summary>
+        [MenuItem("Tools/Settings", 9297, true)]
+        private static void OpenSettingsWindow()
+        {
+            OpenWindow<SettingsWindow>();
+        }
+
+        /// <inheritdoc/>
+        protected override LocString GetDisplayName()
+        {
+            return new LocEdString("Settings");
+        }
+
+        private void OnInitialize()
+        {
+            Width = 300;
+
+            GUIToggle projectFoldout = new GUIToggle(new LocEdString("Project"), EditorStyles.Foldout);
+            GUIToggle editorFoldout = new GUIToggle(new LocEdString("Editor"), EditorStyles.Foldout);
+
+            defaultHandleSizeField = new GUIFloatField(new LocEdString("Handle size"), 200);
+            defaultHandleSizeField.OnChanged += (x) => { EditorSettings.DefaultHandleSize = x; };
+
+            autoLoadLastProjectField = new GUIToggleField(new LocEdString("Automatically load last project"), 200);
+            autoLoadLastProjectField.OnChanged += (x) => { EditorSettings.AutoLoadLastProject = x; };
+
+            GUILayout mainLayout = GUI.AddLayoutY();
+            mainLayout.AddElement(projectFoldout);
+            GUILayout projectLayoutOuterY = mainLayout.AddLayoutY();
+            projectLayoutOuterY.AddSpace(5);
+            GUILayout projectLayoutOuterX = projectLayoutOuterY.AddLayoutX();
+            projectLayoutOuterX.AddSpace(5);
+            GUILayout projectLayout = projectLayoutOuterX.AddLayoutY();
+            projectLayoutOuterX.AddSpace(5);
+            projectLayoutOuterY.AddSpace(5);
+
+            mainLayout.AddElement(editorFoldout);
+            GUILayout editorLayoutOuterY = mainLayout.AddLayoutY();
+            editorLayoutOuterY.AddSpace(5);
+            GUILayout editorLayoutOuterX = editorLayoutOuterY.AddLayoutX();
+            editorLayoutOuterX.AddSpace(5);
+            GUILayout editorLayout = editorLayoutOuterX.AddLayoutY();
+            editorLayoutOuterX.AddSpace(5);
+            editorLayoutOuterY.AddSpace(5);
+
+            mainLayout.AddFlexibleSpace();
+
+            editorLayout.AddElement(defaultHandleSizeField);
+            editorLayout.AddElement(autoLoadLastProjectField);
+
+            projectFoldout.Value = true;
+            editorFoldout.Value = true;
+
+            projectFoldout.OnToggled += (x) => projectLayout.Active = x;
+            editorFoldout.OnToggled += (x) => editorLayout.Active = x;
+        }
+
+        private void OnEditorUpdate()
+        {
+            defaultHandleSizeField.Value = EditorSettings.DefaultHandleSize;
+            autoLoadLastProjectField.Value = EditorSettings.AutoLoadLastProject;
+        }
+    }
+}

+ 2 - 1
SBansheeEditor/Include/BsScriptEditorWindow.h

@@ -134,8 +134,9 @@ namespace BansheeEngine
 		static void internal_screenToWindowPos(ScriptEditorWindow* thisPtr, Vector2I screenPos, Vector2I* windowPos);
 		static void internal_windowToScreenPos(ScriptEditorWindow* thisPtr, Vector2I windowPos, Vector2I* screenPos);
 		static UINT32 internal_getWidth(ScriptEditorWindow* thisPtr);
+		static void internal_setWidth(ScriptEditorWindow* thisPtr, UINT32 width);
 		static UINT32 internal_getHeight(ScriptEditorWindow* thisPtr);
-
+		static void internal_setHeight(ScriptEditorWindow* thisPtr, UINT32 height);
 	};
 
 	/**

+ 33 - 0
SBansheeEditor/Source/BsScriptEditorWindow.cpp

@@ -5,6 +5,7 @@
 #include "BsMonoMethod.h"
 #include "BsMonoManager.h"
 #include "BsMonoUtil.h"
+#include "BsEditorWindow.h"
 #include "BsEditorWidget.h"
 #include "BsEditorWidgetManager.h"
 #include "BsEditorWidgetContainer.h"
@@ -47,7 +48,9 @@ namespace BansheeEngine
 		metaData.scriptClass->addInternalCall("Internal_CreateOrGetInstance", &ScriptEditorWindow::internal_createOrGetInstance);
 		metaData.scriptClass->addInternalCall("Internal_GetInstance", &ScriptEditorWindow::internal_getInstance);
 		metaData.scriptClass->addInternalCall("Internal_GetWidth", &ScriptEditorWindow::internal_getWidth);
+		metaData.scriptClass->addInternalCall("Internal_SetWidth", &ScriptEditorWindow::internal_setWidth);
 		metaData.scriptClass->addInternalCall("Internal_GetHeight", &ScriptEditorWindow::internal_getHeight);
+		metaData.scriptClass->addInternalCall("Internal_SetHeight", &ScriptEditorWindow::internal_setHeight);
 		metaData.scriptClass->addInternalCall("Internal_HasFocus", &ScriptEditorWindow::internal_hasFocus);
 		metaData.scriptClass->addInternalCall("Internal_ScreenToWindowPos", &ScriptEditorWindow::internal_screenToWindowPos);
 		metaData.scriptClass->addInternalCall("Internal_WindowToScreenPos", &ScriptEditorWindow::internal_windowToScreenPos);
@@ -197,6 +200,21 @@ namespace BansheeEngine
 			return 0;
 	}
 
+	void ScriptEditorWindow::internal_setWidth(ScriptEditorWindow* thisPtr, UINT32 width)
+	{
+		if (!thisPtr->isDestroyed())
+		{
+			EditorWindowBase* editorWindow = thisPtr->mEditorWidget->getParentWindow();
+			if (editorWindow != nullptr)
+			{
+				Vector2I widgetSize(width, thisPtr->mEditorWidget->getHeight());
+				Vector2I windowSize = EditorWidgetContainer::widgetToWindowSize(widgetSize);
+
+				editorWindow->setSize((UINT32)windowSize.x, (UINT32)windowSize.y);
+			}
+		}
+	}
+
 	UINT32 ScriptEditorWindow::internal_getHeight(ScriptEditorWindow* thisPtr)
 	{
 		if (!thisPtr->isDestroyed())
@@ -205,6 +223,21 @@ namespace BansheeEngine
 			return 0;
 	}
 
+	void ScriptEditorWindow::internal_setHeight(ScriptEditorWindow* thisPtr, UINT32 height)
+	{
+		if (!thisPtr->isDestroyed())
+		{
+			EditorWindowBase* editorWindow = thisPtr->mEditorWidget->getParentWindow();
+			if (editorWindow != nullptr)
+			{
+				Vector2I widgetSize(thisPtr->mEditorWidget->getWidth(), height);
+				Vector2I windowSize = EditorWidgetContainer::widgetToWindowSize(widgetSize);
+
+				editorWindow->setSize((UINT32)windowSize.x, (UINT32)windowSize.y);
+			}
+		}
+	}
+
 	void ScriptEditorWindow::onWidgetResized(UINT32 width, UINT32 height)
 	{
 		if (isDestroyed() || !mEditorWidget->isInitialized() || mManagedInstance == nullptr)