Browse Source

GUIElementBase can now have position/bounds too
Added C# wrappers for retrieving GUI element bounds

Marko Pintera 11 years ago
parent
commit
e96ede4d3b

+ 9 - 26
BansheeEngine/Include/BsGUIElement.h

@@ -54,39 +54,24 @@ namespace BansheeEngine
 		void setStyle(const String& styleName);
 		void setStyle(const String& styleName);
 
 
 		/**
 		/**
-		 * @brief	Sets element position relative to widget origin.
-		 *
-		 * @note	Be aware that this value will get overwritten if your element is part of a non-explicit layout.
+		 * @copydoc	GUIElementBase::setWidth
 		 */
 		 */
-		void setOffset(const Vector2I& offset);
+		void setWidth(UINT32 width) override;
 
 
 		/**
 		/**
-		 * @brief	Sets element width in pixels.
-		 *
-		 * @note	Be aware that this value will get overwritten if your element is part of a non-explicit layout.
+		 * @copydoc	GUIElementBase::setHeight
 		 */
 		 */
-		void setWidth(UINT32 width);
+		void setHeight(UINT32 height) override;
 
 
 		/**
 		/**
-		 * @brief	Sets element height in pixels.
-		 *
-		 * @note	Be aware that this value will get overwritten if your element is part of a non-explicit layout.
+		 * @copydoc	GUIElementBase::setOffset
 		 */
 		 */
-		void setHeight(UINT32 height);
+		void setOffset(const Vector2I& offset) override;
 
 
 		/**
 		/**
-		 * @brief	Returns non-clipped bounds of the GUI element. Relative to the parent widget.
-		 *
-		 * @note	This call can be potentially expensive as the bounds need to be calculated based on current GUI state.
+		 * @copydoc	GUIElementBase::getVisibleBounds
 		 */
 		 */
-		Rect2I getBounds() const;
-
-		/**
-		 * @brief	Returns non-clipped visible bounds of the GUI element (bounds exclude the margins). Relative to parent widget.
-		 *
-		 * @note	This call can be potentially expensive as the bounds need to be calculated based on current GUI state.
-		 */
-		Rect2I getVisibleBounds() const;
+		Rect2I getVisibleBounds() const override;
 
 
 		/**
 		/**
 		 * @brief	Destroy the element. Removes it from parent and widget, and queues
 		 * @brief	Destroy the element. Removes it from parent and widget, and queues
@@ -98,7 +83,7 @@ namespace BansheeEngine
 		/* 							INTERNAL METHODS                      		*/
 		/* 							INTERNAL METHODS                      		*/
 		/************************************************************************/
 		/************************************************************************/
 
 
-/**
+		/**
 		 * @brief	Returns the number of separate render elements in the GUI element.
 		 * @brief	Returns the number of separate render elements in the GUI element.
 		 * 			
 		 * 			
 		 * @return	The number render elements.
 		 * @return	The number render elements.
@@ -480,8 +465,6 @@ namespace BansheeEngine
 		Rect2I mClippedBounds;
 		Rect2I mClippedBounds;
 
 
 		UINT32 mDepth;
 		UINT32 mDepth;
-		Vector2I mOffset;
-		UINT32 mWidth, mHeight;
 		Rect2I mClipRect;
 		Rect2I mClipRect;
 
 
 	private:
 	private:

+ 38 - 0
BansheeEngine/Include/BsGUIElementBase.h

@@ -40,6 +40,41 @@ namespace BansheeEngine
 		 */
 		 */
 		void disableRecursively();
 		void disableRecursively();
 
 
+		/**
+		 * @brief	Sets element position relative to widget origin.
+		 *
+		 * @note	Be aware that this value will get overwritten if your element is part of a non-explicit layout.
+		 */
+		virtual void setOffset(const Vector2I& offset);
+
+		/**
+		 * @brief	Sets element width in pixels.
+		 *
+		 * @note	Be aware that this value will get overwritten if your element is part of a non-explicit layout.
+		 */
+		virtual void setWidth(UINT32 width);
+
+		/**
+		 * @brief	Sets element height in pixels.
+		 *
+		 * @note	Be aware that this value will get overwritten if your element is part of a non-explicit layout.
+		 */
+		virtual void setHeight(UINT32 height);
+
+		/**
+		 * @brief	Returns non-clipped bounds of the GUI element. Relative to the parent widget.
+		 *
+		 * @note	This call can be potentially expensive as the bounds need to be calculated based on current GUI state.
+		 */
+		virtual Rect2I getBounds() const;
+
+		/**
+		 * @brief	Returns non-clipped visible bounds of the GUI element (bounds exclude the margins). Relative to parent widget.
+		 *
+		 * @note	This call can be potentially expensive as the bounds need to be calculated based on current GUI state.
+		 */
+		virtual Rect2I getVisibleBounds() const;
+
 		/************************************************************************/
 		/************************************************************************/
 		/* 							INTERNAL METHODS                      		*/
 		/* 							INTERNAL METHODS                      		*/
 		/************************************************************************/
 		/************************************************************************/
@@ -262,5 +297,8 @@ namespace BansheeEngine
 		Vector<GUIElementBase*> mChildren;	
 		Vector<GUIElementBase*> mChildren;	
 		UINT8 mIsDirty;
 		UINT8 mIsDirty;
 		bool mIsDisabled;
 		bool mIsDisabled;
+
+		Vector2I mOffset;
+		UINT32 mWidth, mHeight;
 	};
 	};
 }
 }

+ 4 - 0
BansheeEngine/Source/BsGUIArea.cpp

@@ -137,6 +137,10 @@ namespace BansheeEngine
 				clipRect = newClipRect;
 				clipRect = newClipRect;
 			}
 			}
 
 
+			mLayout->setOffset(Vector2I(mLeft, mTop));
+			mLayout->setWidth(mWidth);
+			mLayout->setHeight(mHeight);
+
 			mLayout->_updateLayout(mLeft, mTop, mWidth, mHeight, clipRect, mWidget->getDepth(), mDepth);
 			mLayout->_updateLayout(mLeft, mTop, mWidth, mHeight, clipRect, mWidget->getDepth(), mDepth);
 			mIsDirty = false;
 			mIsDirty = false;
 		}
 		}

+ 28 - 33
BansheeEngine/Source/BsGUIElement.cpp

@@ -9,7 +9,7 @@
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	GUIElement::GUIElement(const String& styleName, const GUILayoutOptions& layoutOptions)
 	GUIElement::GUIElement(const String& styleName, const GUILayoutOptions& layoutOptions)
-		:mLayoutOptions(layoutOptions), mWidth(0), mHeight(0), mDepth(0), mStyle(nullptr),
+		:mLayoutOptions(layoutOptions), mDepth(0), mStyle(nullptr),
 		mIsDestroyed(false), mStyleName(styleName)
 		mIsDestroyed(false), mStyleName(styleName)
 	{
 	{
 		_refreshStyle();
 		_refreshStyle();
@@ -29,6 +29,33 @@ namespace BansheeEngine
 		updateClippedBounds();
 		updateClippedBounds();
 	}
 	}
 
 
+	void GUIElement::setOffset(const Vector2I& offset)
+	{
+		if (mOffset != offset)
+		{
+			markMeshAsDirty();
+
+			mOffset = offset;
+			updateClippedBounds();
+		}
+	}
+
+	void GUIElement::setWidth(UINT32 width)
+	{
+		if (mWidth != width)
+			markContentAsDirty();
+
+		mWidth = width;
+	}
+
+	void GUIElement::setHeight(UINT32 height)
+	{
+		if (mHeight != height)
+			markContentAsDirty();
+
+		mHeight = height;
+	}
+
 	void GUIElement::setLayoutOptions(const GUILayoutOptions& layoutOptions) 
 	void GUIElement::setLayoutOptions(const GUILayoutOptions& layoutOptions) 
 	{
 	{
 		if(layoutOptions.maxWidth < layoutOptions.minWidth)
 		if(layoutOptions.maxWidth < layoutOptions.minWidth)
@@ -90,33 +117,6 @@ namespace BansheeEngine
 		markMeshAsDirty();
 		markMeshAsDirty();
 	}
 	}
 
 
-	void GUIElement::setOffset(const Vector2I& offset) 
-	{ 
-		if(mOffset != offset)
-		{
-			markMeshAsDirty();
-
-			mOffset = offset;
-			updateClippedBounds();
-		}
-	}
-
-	void GUIElement::setWidth(UINT32 width) 
-	{ 
-		if(mWidth != width)
-			markContentAsDirty();
-
-		mWidth = width; 
-	}
-
-	void GUIElement::setHeight(UINT32 height) 
-	{ 
-		if(mHeight != height)
-			markContentAsDirty();
-
-		mHeight = height;
-	}
-
 	void GUIElement::_setClipRect(const Rect2I& clipRect) 
 	void GUIElement::_setClipRect(const Rect2I& clipRect) 
 	{ 
 	{ 
 		if(mClipRect != clipRect)
 		if(mClipRect != clipRect)
@@ -316,11 +316,6 @@ namespace BansheeEngine
 		GUIManager::instance().queueForDestroy(element);
 		GUIManager::instance().queueForDestroy(element);
 	}
 	}
 
 
-	Rect2I GUIElement::getBounds() const
-	{
-		return GUILayoutUtility::calcBounds(this);
-	}
-
 	Rect2I GUIElement::getVisibleBounds() const
 	Rect2I GUIElement::getVisibleBounds() const
 	{
 	{
 		Rect2I bounds = getBounds();
 		Rect2I bounds = getBounds();

+ 34 - 1
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -6,11 +6,13 @@
 #include "BsGUIElement.h"
 #include "BsGUIElement.h"
 #include "BsException.h"
 #include "BsException.h"
 #include "BsGUIWidget.h"
 #include "BsGUIWidget.h"
+#include "BsGUILayoutUtility.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	GUIElementBase::GUIElementBase()
 	GUIElementBase::GUIElementBase()
-		:mIsDirty(true), mParentElement(nullptr), mIsDisabled(false), mParentWidget(nullptr)
+		:mIsDirty(true), mParentElement(nullptr), mIsDisabled(false), 
+		mParentWidget(nullptr), mWidth(0), mHeight(0)
 	{
 	{
 
 
 	}
 	}
@@ -37,6 +39,37 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
+	void GUIElementBase::setOffset(const Vector2I& offset)
+	{
+		mOffset = offset;
+	}
+
+	void GUIElementBase::setWidth(UINT32 width)
+	{
+		if (mWidth != width)
+			markContentAsDirty();
+
+		mWidth = width;
+	}
+
+	void GUIElementBase::setHeight(UINT32 height)
+	{
+		if (mHeight != height)
+			markContentAsDirty();
+
+		mHeight = height;
+	}
+
+	Rect2I GUIElementBase::getBounds() const
+	{
+		return GUILayoutUtility::calcBounds(this);
+	}
+
+	Rect2I GUIElementBase::getVisibleBounds() const
+	{
+		return getBounds();
+	}
+
 	bool GUIElementBase::_isContentDirty() const
 	bool GUIElementBase::_isContentDirty() const
 	{
 	{
 		if((mIsDirty & 0x01) != 0)
 		if((mIsDirty & 0x01) != 0)

+ 10 - 4
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -408,14 +408,15 @@ namespace BansheeEngine
 		{
 		{
 			Rect2I childArea = elementAreas[childIdx];
 			Rect2I childArea = elementAreas[childIdx];
 
 
+			Vector2I offset(childArea.x, childArea.y);
+			child->setOffset(offset);
+			child->setWidth(childArea.width);
+
 			if(child->_getType() == GUIElementBase::Type::Element)
 			if(child->_getType() == GUIElementBase::Type::Element)
 			{
 			{
 				GUIElement* element = static_cast<GUIElement*>(child);
 				GUIElement* element = static_cast<GUIElement*>(child);
-				element->setWidth(childArea.width);
-				element->setHeight(childArea.height);
 
 
-				Vector2I offset(childArea.x, childArea.y);
-				element->setOffset(offset);
+				element->setHeight(childArea.height);
 				element->_setWidgetDepth(widgetDepth);
 				element->_setWidgetDepth(widgetDepth);
 				element->_setAreaDepth(areaDepth);
 				element->_setAreaDepth(areaDepth);
 
 
@@ -432,6 +433,8 @@ namespace BansheeEngine
 			{
 			{
 				GUILayout* layout = static_cast<GUILayout*>(child);
 				GUILayout* layout = static_cast<GUILayout*>(child);
 
 
+				layout->setHeight(height);
+
 				Rect2I newClipRect(childArea.x, childArea.y, childArea.width, height);
 				Rect2I newClipRect(childArea.x, childArea.y, childArea.width, height);
 				newClipRect.clip(clipRect);
 				newClipRect.clip(clipRect);
 				layout->_updateLayoutInternal(childArea.x, childArea.y, childArea.width, height, newClipRect, widgetDepth, areaDepth);
 				layout->_updateLayoutInternal(childArea.x, childArea.y, childArea.width, height, newClipRect, widgetDepth, areaDepth);
@@ -439,7 +442,10 @@ namespace BansheeEngine
 				actualSizes[childIdx].height = layout->_getActualHeight();
 				actualSizes[childIdx].height = layout->_getActualHeight();
 			}
 			}
 			else
 			else
+			{
+				child->setHeight(childArea.height);
 				actualSizes[childIdx].height = childArea.height;
 				actualSizes[childIdx].height = childArea.height;
+			}
 
 
 			actualSizes[childIdx].x = childArea.width + child->_getPadding().left + child->_getPadding().right;
 			actualSizes[childIdx].x = childArea.width + child->_getPadding().left + child->_getPadding().right;
 			childIdx++;
 			childIdx++;

+ 9 - 4
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -405,15 +405,15 @@ namespace BansheeEngine
 		{
 		{
 			Rect2I childArea = elementAreas[childIdx];
 			Rect2I childArea = elementAreas[childIdx];
 
 
+			Vector2I offset(childArea.x, childArea.y);
+			child->setOffset(offset);
+			child->setHeight(childArea.height);
+
 			if(child->_getType() == GUIElementBase::Type::Element)
 			if(child->_getType() == GUIElementBase::Type::Element)
 			{
 			{
 				GUIElement* element = static_cast<GUIElement*>(child);
 				GUIElement* element = static_cast<GUIElement*>(child);
 
 
 				element->setWidth(childArea.width);
 				element->setWidth(childArea.width);
-				element->setHeight(childArea.height);
-
-				Vector2I offset(childArea.x, childArea.y);
-				element->setOffset(offset);
 				element->_setWidgetDepth(widgetDepth);
 				element->_setWidgetDepth(widgetDepth);
 				element->_setAreaDepth(areaDepth);
 				element->_setAreaDepth(areaDepth);
 
 
@@ -430,6 +430,8 @@ namespace BansheeEngine
 			{
 			{
 				GUILayout* layout = static_cast<GUILayout*>(child);
 				GUILayout* layout = static_cast<GUILayout*>(child);
 
 
+				child->setWidth(width);
+
 				Rect2I newClipRect(childArea.x, childArea.y, width, childArea.height);
 				Rect2I newClipRect(childArea.x, childArea.y, width, childArea.height);
 				newClipRect.clip(clipRect);
 				newClipRect.clip(clipRect);
 				layout->_updateLayoutInternal(childArea.x, childArea.y, width, childArea.height, newClipRect, widgetDepth, areaDepth);
 				layout->_updateLayoutInternal(childArea.x, childArea.y, width, childArea.height, newClipRect, widgetDepth, areaDepth);
@@ -437,7 +439,10 @@ namespace BansheeEngine
 				actualSizes[childIdx].width = layout->_getActualWidth();
 				actualSizes[childIdx].width = layout->_getActualWidth();
 			}
 			}
 			else
 			else
+			{
+				child->setWidth(childArea.width);
 				actualSizes[childIdx].width = childArea.width;
 				actualSizes[childIdx].width = childArea.width;
+			}
 
 
 			actualSizes[childIdx].height = childArea.height + child->_getPadding().top + child->_getPadding().bottom;
 			actualSizes[childIdx].height = childArea.height + child->_getPadding().top + child->_getPadding().bottom;
 			childIdx++;
 			childIdx++;

+ 1 - 1
MBansheeEditor/EditorApplication.cs

@@ -95,7 +95,7 @@ namespace BansheeEditor
             SceneObject gizmoDbgObject = new SceneObject("GizmoDebug");
             SceneObject gizmoDbgObject = new SceneObject("GizmoDebug");
             gizmoDbgObject.AddComponent<DbgGizmoComponent>();
             gizmoDbgObject.AddComponent<DbgGizmoComponent>();
 
 
-            ProgressBar.Show("Test", 0.5f);
+            //ProgressBar.Show("Test", 0.5f);
 
 
             // DEBUG ONLY END
             // DEBUG ONLY END
         }
         }

+ 20 - 0
MBansheeEngine/GUI/GUIElement.cs

@@ -9,6 +9,17 @@ namespace BansheeEngine
         protected GUILayout parent;
         protected GUILayout parent;
         private bool isDestroyed;
         private bool isDestroyed;
 
 
+        public Rect2I Bounds
+        {
+            get { return Internal_GetBounds(mCachedPtr); }
+            set { Internal_SetBounds(mCachedPtr, value); }
+        }
+
+        public Rect2I VisualBounds
+        {
+            get { return Internal_GetVisualBounds(mCachedPtr); }
+        }
+
         internal virtual void SetParent(GUILayout layout)
         internal virtual void SetParent(GUILayout layout)
         {
         {
             if (parent != null)
             if (parent != null)
@@ -51,6 +62,15 @@ namespace BansheeEngine
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
         private static extern void Internal_SetVisible(IntPtr nativeInstance, bool visible);
 
 
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Rect2I Internal_GetBounds(IntPtr nativeInstance);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern void Internal_SetBounds(IntPtr nativeInstance, Rect2I value);
+
+        [MethodImpl(MethodImplOptions.InternalCall)]
+        private static extern Rect2I Internal_GetVisualBounds(IntPtr nativeInstance);
+
         [MethodImpl(MethodImplOptions.InternalCall)]
         [MethodImpl(MethodImplOptions.InternalCall)]
         private static extern void Internal_Destroy(IntPtr nativeInstance);
         private static extern void Internal_Destroy(IntPtr nativeInstance);
     }
     }

+ 3 - 0
SBansheeEngine/Include/BsScriptGUIElement.h

@@ -90,6 +90,9 @@ namespace BansheeEngine
 	private:
 	private:
 		static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
 		static void internal_destroy(ScriptGUIElementBaseTBase* nativeInstance);
 		static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
 		static void internal_setVisible(ScriptGUIElementBaseTBase* nativeInstance, bool visible);
+		static Rect2I internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance);
+		static void internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds);
+		static Rect2I internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance);
 		static void internal_setLayoutOptions(ScriptGUIElementBaseTBase* nativeInstance, MonoArray* guiOptions);
 		static void internal_setLayoutOptions(ScriptGUIElementBaseTBase* nativeInstance, MonoArray* guiOptions);
 
 
 		ScriptGUIElement(MonoObject* instance);
 		ScriptGUIElement(MonoObject* instance);

+ 20 - 0
SBansheeEngine/Source/BsScriptGUIElement.cpp

@@ -58,6 +58,9 @@ namespace BansheeEngine
 	{
 	{
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIElement::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_Destroy", &ScriptGUIElement::internal_destroy);
 		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIElement::internal_setVisible);
 		metaData.scriptClass->addInternalCall("Internal_SetVisible", &ScriptGUIElement::internal_setVisible);
+		metaData.scriptClass->addInternalCall("Internal_GetBounds", &ScriptGUIElement::internal_getBounds);
+		metaData.scriptClass->addInternalCall("Internal_SetBounds", &ScriptGUIElement::internal_setBounds);
+		metaData.scriptClass->addInternalCall("Internal_GetVisibleBounds", &ScriptGUIElement::internal_getVisibleBounds);
 		metaData.scriptClass->addInternalCall("Internal_SetLayoutOptions", &ScriptGUIElement::internal_setLayoutOptions);
 		metaData.scriptClass->addInternalCall("Internal_SetLayoutOptions", &ScriptGUIElement::internal_setLayoutOptions);
 	}
 	}
 
 
@@ -74,6 +77,23 @@ namespace BansheeEngine
 			nativeInstance->getGUIElement()->disableRecursively();
 			nativeInstance->getGUIElement()->disableRecursively();
 	}
 	}
 
 
+	Rect2I ScriptGUIElement::internal_getBounds(ScriptGUIElementBaseTBase* nativeInstance)
+	{
+		return nativeInstance->getGUIElement()->getBounds();
+	}
+
+	void ScriptGUIElement::internal_setBounds(ScriptGUIElementBaseTBase* nativeInstance, Rect2I bounds)
+	{
+		nativeInstance->getGUIElement()->setOffset(Vector2I(bounds.x, bounds.y));
+		nativeInstance->getGUIElement()->setWidth(bounds.width);
+		nativeInstance->getGUIElement()->setHeight(bounds.height);
+	}
+
+	Rect2I ScriptGUIElement::internal_getVisibleBounds(ScriptGUIElementBaseTBase* nativeInstance)
+	{
+		return nativeInstance->getGUIElement()->getVisibleBounds();
+	}
+
 	void ScriptGUIElement::internal_setLayoutOptions(ScriptGUIElementBaseTBase* nativeInstance, MonoArray* guiOptions)
 	void ScriptGUIElement::internal_setLayoutOptions(ScriptGUIElementBaseTBase* nativeInstance, MonoArray* guiOptions)
 	{
 	{
 		GUIOptions options;
 		GUIOptions options;

+ 0 - 4
TODO.txt

@@ -9,12 +9,8 @@ Possibly set up automatic refresh in debug mode after initialization? As an ad-h
 
 
 Test file/folder open/save dialog
 Test file/folder open/save dialog
 
 
-Check why focus highlight on windows doesn't work
-Elements in GUIScrollArea will not have valid bounds calculated using GUILayoutUtility::calcBounds
-
 C#:
 C#:
 Dialog.Show(title, text, btn1 text, btn1 callback, btn2 text, btn2 callback, btn3 text, btn3 callback)
 Dialog.Show(title, text, btn1 text, btn1 callback, btn2 text, btn2 callback, btn3 text, btn3 callback)
-ProgressBar.Show(float percent) / ProgressBar.Hide()
 
 
 Add C# wrappers GUIElement bounds and visible bounds (with ability to set non-visible bounds)
 Add C# wrappers GUIElement bounds and visible bounds (with ability to set non-visible bounds)