Browse Source

Added a way to enable/disable EditorWidgets

Marko Pintera 12 years ago
parent
commit
0ae3c8e937

+ 4 - 0
BansheeEngine/Include/BsGUIArea.h

@@ -55,6 +55,9 @@ namespace BansheeEngine
 		void setPosition(CM::INT32 x, CM::INT32 y);
 		void setSize(CM::UINT32 width, CM::UINT32 height);
 
+		void disable();
+		void enable();
+
 		CM::UINT32 x() const { return mLeft; }
 		CM::UINT32 y() const { return mTop; }
 		CM::UINT32 width() const { return mWidth; }
@@ -71,6 +74,7 @@ namespace BansheeEngine
 		bool mResizeXWithWidget;
 		bool mResizeYWithWidget;
 		bool mIsDirty;
+		bool mIsDisabled;
 
 		GUILayout* mLayout;
 

+ 12 - 0
BansheeEngine/Include/BsGUIElementBase.h

@@ -22,6 +22,16 @@ namespace BansheeEngine
 		GUIElementBase();
 		virtual ~GUIElementBase();
 
+		/**
+		 * @brief	Enables (default) this element and all its children.
+		 */
+		void enableRecursively();
+
+		/**
+		 * @brief	Disables this element and all its children.
+		 */
+		void disableRecursively();
+
 		/************************************************************************/
 		/* 							INTERNAL METHODS                      		*/
 		/************************************************************************/
@@ -47,6 +57,7 @@ namespace BansheeEngine
 
 		bool _isContentDirty() const;
 		bool _isMeshDirty() const; 
+		bool _isDisabled() const { return mIsDisabled; }
 
 	protected:
 		/**
@@ -69,5 +80,6 @@ namespace BansheeEngine
 		GUIElementBase* mParentElement;
 		CM::Vector<GUIElementBase*>::type mChildren;	
 		CM::UINT8 mIsDirty;
+		bool mIsDisabled;
 	};
 }

+ 16 - 2
BansheeEngine/Source/BsGUIArea.cpp

@@ -8,7 +8,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 {
 	GUIArea::GUIArea(GUIWidget& widget, UINT32 x, UINT32 y, UINT16 depth)
-		:mWidget(widget), mLeft(x), mTop(y), mDepth(depth), mIsDirty(true), 
+		:mWidget(widget), mLeft(x), mTop(y), mDepth(depth), mIsDirty(true), mIsDisabled(false),
 		mResizeXWithWidget(false), mResizeYWithWidget(false), mWidth(0), mHeight(0), mRight(0), mBottom(0)
 	{
 		mLayout = cm_new<GUILayoutX, PoolAlloc>();
@@ -85,9 +85,23 @@ namespace BansheeEngine
 		cm_delete<PoolAlloc>(area);
 	}
 
+	void GUIArea::disable()
+	{
+		mIsDisabled = true;
+
+		mLayout->disableRecursively();
+	}
+
+	void GUIArea::enable()
+	{
+		mIsDisabled = false;
+
+		mLayout->enableRecursively();
+	}
+
 	void GUIArea::_update()
 	{
-		if(isDirty())
+		if(!mIsDisabled && isDirty())
 		{
 			Rect clipRect(mLeft, mTop, mWidth, mHeight);
 			mLayout->_updateLayout(mLeft, mTop, mWidth, mHeight, clipRect, mWidget.getDepth(), mDepth);

+ 30 - 1
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -10,7 +10,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 {
 	GUIElementBase::GUIElementBase()
-		:mIsDirty(true), mParentElement(nullptr)
+		:mIsDirty(true), mParentElement(nullptr), mIsDisabled(false)
 	{
 
 	}
@@ -51,14 +51,43 @@ namespace BansheeEngine
 
 	void GUIElementBase::markContentAsDirty() 
 	{ 
+		if(_isDisabled())
+			return;
+
 		mIsDirty |= 0x01; 
 	}
 
 	void GUIElementBase::markMeshAsDirty()
 	{
+		if(_isDisabled())
+			return;
+
 		mIsDirty |= 0x02;
 	}
 
+	void GUIElementBase::enableRecursively()
+	{
+		// Make sure to mark everything as dirty, as we didn't track any dirty flags while the element was disabled
+		markContentAsDirty();
+		mIsDisabled = false;
+
+		for(auto& elem : mChildren)
+		{
+			elem->enableRecursively();
+		}
+	}
+
+	void GUIElementBase::disableRecursively()
+	{
+		markMeshAsDirty(); // Just need to hide the mesh
+		mIsDisabled = true;
+
+		for(auto& elem : mChildren)
+		{
+			elem->disableRecursively();
+		}
+	}
+
 	void GUIElementBase::_updateLayout(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect clipRect, UINT8 widgetDepth, UINT16 areaDepth)
 	{
 		_updateOptimalLayoutSizes(); // We calculate optimal sizes of all layouts as a pre-processing step, as they are requested often during update

+ 4 - 1
BansheeEngine/Source/BsGUIManager.cpp

@@ -265,6 +265,9 @@ namespace BansheeEngine
 
 				for(auto& element : elements)
 				{
+					if(element->_isDisabled())
+						continue;
+
 					UINT32 numRenderElems = element->getNumRenderElements();
 					for(UINT32 i = 0; i < numRenderElems; i++)
 					{
@@ -706,7 +709,7 @@ namespace BansheeEngine
 					{
 						GUIElement* element = *iter;
 
-						if(element->_isInBounds(localPos) && element->_getDepth() < topMostDepth)
+						if(!element->_isDisabled() && element->_isInBounds(localPos) && element->_getDepth() < topMostDepth)
 						{
 							topMostElement = element;
 							topMostDepth = element->_getDepth();

+ 2 - 2
CamelotClient/Source/BsEditorWidget.cpp

@@ -53,11 +53,11 @@ namespace BansheeEditor
 
 	void EditorWidget::_disable()
 	{
-		// TODO - Hide all child GUIElements
+		mContent->disable();
 	}
 
 	void EditorWidget::_enable()
 	{
-		// TODO - Show all child GUIElements
+		mContent->enable();
 	}
 }

+ 2 - 0
CamelotClient/Source/BsEditorWidgetContainer.cpp

@@ -35,6 +35,8 @@ namespace BansheeEditor
 		{
 			setActiveWidget((UINT32)mWidgets.size() - 1);
 		}
+		else
+			widget._disable();
 	}
 
 	void EditorWidgetContainer::remove(EditorWidget& widget)

+ 14 - 0
EditorWindowDock.txt

@@ -58,6 +58,20 @@ Implementation plan:
 
  TODO - I don't release EditorWindow or EditorWidget anywhere!!!
 
+ Things that need cleanup:
+  All elements contained in GUITabbedTitleBar
+  EditorWidget when its closed
+  EditorWidgetContainer when last widget is removed
+  EditorWindow when last widget is removed
+
+Shutdown of the game should destroy all EditorWindows (and all their children)
+
+A way to disable/enable EditorWidgets so I can switch tabs in EditorWidgetContainer
+ - Also hook up the toggle buttons
+A way to move EditorWidget child GUIArea and GUIElements to another widget
+Notify parent EditorWindow or Dockmanager when last element is removed from EditorWidgetContainer (probably just a callback)
+ - Also hook up the X button on the tabbed title bar so it closes the widget
+
 ------------------------
 
 Some use cases:

+ 0 - 1
TODO.txt

@@ -12,7 +12,6 @@ I call waitUntilLoaded too many times. Sometimes 5-6 times in a single function.
 GUIWidget::updateMeshes leaks. If I leave the game running I can see memory continously going up
  - Resizing from the top doesn't work
  - Resizing from the left actually resizes the right side
- - Clipping areas outside of a widget (or GUIArea for that matter) are not set up at all
 
 Over the holidays:
  - Get release mode working