Browse Source

Bugfix: Fix color picker GUI being slightly cut off
- Also added a way to set/get content size of a modal window

BearishSun 6 years ago
parent
commit
d1ac5748e7

+ 19 - 1
Source/EditorCore/EditorWindow/BsModalWindow.cpp

@@ -116,6 +116,24 @@ namespace bs
 		updateSize();
 		updateSize();
 	}
 	}
 
 
+	UINT32 ModalWindow::getContentWidth() const
+	{
+		return getWidth() - 2;
+	}
+
+	UINT32 ModalWindow::getContentHeight() const
+	{
+		return getHeight() - getTitleBarHeight() - 2;
+	}
+
+	void ModalWindow::setContentSize(UINT32 width, UINT32 height)
+	{
+		UINT32 actualWidth = width + 2;
+		UINT32 actualHeight = height + getTitleBarHeight() + 2;
+
+		setSize(actualWidth, actualHeight);
+	}
+
 	void ModalWindow::resized()
 	void ModalWindow::resized()
 	{
 	{
 		EditorWindowBase::resized();
 		EditorWindowBase::resized();
@@ -140,7 +158,7 @@ namespace bs
 
 
 	Rect2I ModalWindow::getContentArea() const
 	Rect2I ModalWindow::getContentArea() const
 	{
 	{
-		return Rect2I(1, 1 + getTitleBarHeight(), getWidth() - 2, getHeight() - getTitleBarHeight() - 2);
+		return Rect2I(1, 1 + getTitleBarHeight(), getContentWidth(), getContentHeight());
 	}
 	}
 
 
 	UINT32 ModalWindow::getTitleBarHeight() const
 	UINT32 ModalWindow::getTitleBarHeight() const

+ 18 - 0
Source/EditorCore/EditorWindow/BsModalWindow.h

@@ -33,6 +33,24 @@ namespace bs
 		/** @copydoc EditorWindowBase::setSize */
 		/** @copydoc EditorWindowBase::setSize */
 		void setSize(UINT32 width, UINT32 height) override;
 		void setSize(UINT32 width, UINT32 height) override;
 
 
+		/**	
+		 * Returns the width of the content area of the window, in pixels. The content area represents the area of the
+		 * window not including the title bar and the border.
+		 */
+		UINT32 getContentWidth() const;
+
+		/**	
+		 * Returns the height of the content area of the window, in pixels. The content area represents the area of the
+		 * window not including the title bar and the border.
+		 */
+		UINT32 getContentHeight() const;
+
+		/** 
+		 * Sets the width & height of the content area of the window, in pixels. The content area represents the area of
+		 * the window not including the titlebar and the border.
+		 */
+		void setContentSize(UINT32 width, UINT32 height);
+
 		/** Converts screen pointer coordinates into coordinates relative to the window content's GUI panel. */
 		/** Converts screen pointer coordinates into coordinates relative to the window content's GUI panel. */
 		Vector2I screenToWindowPos(const Vector2I& screenPos) const;
 		Vector2I screenToWindowPos(const Vector2I& screenPos) const;
 
 

+ 32 - 0
Source/EditorManaged/Window/ModalWindow.cs

@@ -36,6 +36,26 @@ namespace bs.Editor
             set { Internal_SetHeight(mCachedPtr, value); }
             set { Internal_SetHeight(mCachedPtr, value); }
         }
         }
 
 
+        /// <summary>
+        /// Width of the content area of the window, in pixels. The content area represents the area of the window not
+        /// including the title bar and the border.
+        /// </summary>
+        public int ContentWidth
+        {
+            get { return Internal_GetContentWidth(mCachedPtr); }
+            set { Internal_SetContentWidth(mCachedPtr, value); }
+        }
+
+        /// <summary>
+        /// Height of the content area of the window, in pixels. The content area represents the area of the window not
+        /// including the title bar and the border.
+        /// </summary>
+        public int ContentHeight
+        {
+            get { return Internal_GetContentHeight(mCachedPtr); }
+            set { Internal_SetContentHeight(mCachedPtr, value); }
+        }
+
         protected GUIPanel GUI;
         protected GUIPanel GUI;
 
 
         /// <summary>
         /// <summary>
@@ -126,6 +146,18 @@ namespace bs.Editor
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern int Internal_SetHeight(IntPtr nativeInstance, int value);
         private static extern int Internal_SetHeight(IntPtr nativeInstance, int value);
 
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern int Internal_GetContentWidth(IntPtr nativeInstance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern int Internal_SetContentWidth(IntPtr nativeInstance, int value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern int Internal_GetContentHeight(IntPtr nativeInstance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern int Internal_SetContentHeight(IntPtr nativeInstance, int value);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I windowPos);
         private static extern void Internal_ScreenToWindowPos(IntPtr nativeInstance, ref Vector2I position, out Vector2I windowPos);
 
 

+ 4 - 4
Source/EditorManaged/Windows/ColorPicker.cs

@@ -198,8 +198,8 @@ namespace bs.Editor
             guiCancel.OnClick += OnCancel;
             guiCancel.OnClick += OnCancel;
 
 
             GUIPanel mainPanel = GUI.AddPanel(0);
             GUIPanel mainPanel = GUI.AddPanel(0);
-            mainPanel.SetWidth(Width);
-            mainPanel.SetHeight(Height);
+            mainPanel.SetWidth(ContentWidth);
+            mainPanel.SetHeight(ContentHeight);
             GUILayout v0 = mainPanel.AddLayoutY();
             GUILayout v0 = mainPanel.AddLayoutY();
 
 
             v0.AddSpace(5);
             v0.AddSpace(5);
@@ -277,8 +277,8 @@ namespace bs.Editor
             v0.AddSpace(5);
             v0.AddSpace(5);
 
 
             GUIPanel overlay = GUI.AddPanel(-1);
             GUIPanel overlay = GUI.AddPanel(-1);
-            overlay.SetWidth(Width);
-            overlay.SetHeight(Height);
+            overlay.SetWidth(ContentWidth);
+            overlay.SetHeight(ContentHeight);
 
 
             overlay.AddElement(guiSliderVert);
             overlay.AddElement(guiSliderVert);
             overlay.AddElement(guiSliderRHorz);
             overlay.AddElement(guiSliderRHorz);

+ 32 - 0
Source/EditorScript/Wrappers/BsScriptModalWindow.cpp

@@ -39,6 +39,10 @@ namespace bs
 		metaData.scriptClass->addInternalCall("Internal_GetHeight", (void*)&ScriptModalWindow::internal_getHeight);
 		metaData.scriptClass->addInternalCall("Internal_GetHeight", (void*)&ScriptModalWindow::internal_getHeight);
 		metaData.scriptClass->addInternalCall("Internal_SetWidth", (void*)&ScriptModalWindow::internal_setWidth);
 		metaData.scriptClass->addInternalCall("Internal_SetWidth", (void*)&ScriptModalWindow::internal_setWidth);
 		metaData.scriptClass->addInternalCall("Internal_SetHeight", (void*)&ScriptModalWindow::internal_setHeight);
 		metaData.scriptClass->addInternalCall("Internal_SetHeight", (void*)&ScriptModalWindow::internal_setHeight);
+		metaData.scriptClass->addInternalCall("Internal_GetContentWidth", (void*)&ScriptModalWindow::internal_getContentWidth);
+		metaData.scriptClass->addInternalCall("Internal_GetContentHeight", (void*)&ScriptModalWindow::internal_getContentHeight);
+		metaData.scriptClass->addInternalCall("Internal_SetContentWidth", (void*)&ScriptModalWindow::internal_setContentWidth);
+		metaData.scriptClass->addInternalCall("Internal_SetContentHeight", (void*)&ScriptModalWindow::internal_setContentHeight);
 		metaData.scriptClass->addInternalCall("Internal_SetTitle", (void*)&ScriptModalWindow::internal_setTitle);
 		metaData.scriptClass->addInternalCall("Internal_SetTitle", (void*)&ScriptModalWindow::internal_setTitle);
 		metaData.scriptClass->addInternalCall("Internal_ScreenToWindowPos", (void*)&ScriptModalWindow::internal_screenToWindowPos);
 		metaData.scriptClass->addInternalCall("Internal_ScreenToWindowPos", (void*)&ScriptModalWindow::internal_screenToWindowPos);
 		metaData.scriptClass->addInternalCall("Internal_WindowToScreenPos", (void*)&ScriptModalWindow::internal_windowToScreenPos);
 		metaData.scriptClass->addInternalCall("Internal_WindowToScreenPos", (void*)&ScriptModalWindow::internal_windowToScreenPos);
@@ -132,6 +136,34 @@ namespace bs
 			thisPtr->mModalWindow->setSize(thisPtr->mModalWindow->getWidth(), value);
 			thisPtr->mModalWindow->setSize(thisPtr->mModalWindow->getWidth(), value);
 	}
 	}
 
 
+	UINT32 ScriptModalWindow::internal_getContentWidth(ScriptModalWindow* thisPtr)
+	{
+		if (thisPtr->mModalWindow != nullptr)
+			return thisPtr->mModalWindow->getContentWidth();
+
+		return 0;
+	}
+
+	UINT32 ScriptModalWindow::internal_getContentHeight(ScriptModalWindow* thisPtr)
+	{
+		if (thisPtr->mModalWindow != nullptr)
+			return thisPtr->mModalWindow->getContentHeight();
+
+		return 0;
+	}
+
+	void ScriptModalWindow::internal_setContentWidth(ScriptModalWindow* thisPtr, UINT32 value)
+	{
+		if (thisPtr->mModalWindow != nullptr)
+			thisPtr->mModalWindow->setSize(value, thisPtr->mModalWindow->getHeight());
+	}
+
+	void ScriptModalWindow::internal_setContentHeight(ScriptModalWindow* thisPtr, UINT32 value)
+	{
+		if (thisPtr->mModalWindow != nullptr)
+			thisPtr->mModalWindow->setSize(thisPtr->mModalWindow->getWidth(), value);
+	}
+
 	void ScriptModalWindow::internal_screenToWindowPos(ScriptModalWindow* thisPtr, Vector2I* screenPos, Vector2I* windowPos)
 	void ScriptModalWindow::internal_screenToWindowPos(ScriptModalWindow* thisPtr, Vector2I* screenPos, Vector2I* windowPos)
 	{
 	{
 		if (thisPtr->mModalWindow != nullptr)
 		if (thisPtr->mModalWindow != nullptr)

+ 6 - 2
Source/EditorScript/Wrappers/BsScriptModalWindow.h

@@ -54,6 +54,10 @@ namespace bs
 		static UINT32 internal_getHeight(ScriptModalWindow* thisPtr);
 		static UINT32 internal_getHeight(ScriptModalWindow* thisPtr);
 		static void internal_setWidth(ScriptModalWindow* thisPtr, UINT32 value);
 		static void internal_setWidth(ScriptModalWindow* thisPtr, UINT32 value);
 		static void internal_setHeight(ScriptModalWindow* thisPtr, UINT32 value);
 		static void internal_setHeight(ScriptModalWindow* thisPtr, UINT32 value);
+		static UINT32 internal_getContentWidth(ScriptModalWindow* thisPtr);
+		static UINT32 internal_getContentHeight(ScriptModalWindow* thisPtr);
+		static void internal_setContentWidth(ScriptModalWindow* thisPtr, UINT32 value);
+		static void internal_setContentHeight(ScriptModalWindow* thisPtr, UINT32 value);
 		static void internal_setTitle(ScriptModalWindow* thisPtr, MonoObject* title);
 		static void internal_setTitle(ScriptModalWindow* thisPtr, MonoObject* title);
 		static void internal_screenToWindowPos(ScriptModalWindow* thisPtr, Vector2I* screenPos, Vector2I* windowPos);
 		static void internal_screenToWindowPos(ScriptModalWindow* thisPtr, Vector2I* screenPos, Vector2I* windowPos);
 		static void internal_windowToScreenPos(ScriptModalWindow* thisPtr, Vector2I* windowPos, Vector2I* screenPos);
 		static void internal_windowToScreenPos(ScriptModalWindow* thisPtr, Vector2I* windowPos, Vector2I* screenPos);
@@ -114,10 +118,10 @@ namespace bs
 		MonoObject* getManagedInstance() const { return mManagedInstance; }
 		MonoObject* getManagedInstance() const { return mManagedInstance; }
 	protected:
 	protected:
 		/** @copydoc ModalWindow::resized */
 		/** @copydoc ModalWindow::resized */
-		virtual void resized() override;
+		void resized() override;
 
 
 		/** @copydoc ModalWindow::close */
 		/** @copydoc ModalWindow::close */
-		virtual void close() override;
+		void close() override;
 
 
 	private:
 	private:
 		friend class ScriptModalWindow;
 		friend class ScriptModalWindow;