Browse Source

Refactored GUIElement visibility flag in preparation for enabled/disabled flag

BearishSun 10 years ago
parent
commit
1e4cc33626

+ 2 - 2
BansheeEditor/Source/BsEditorWidget.cpp

@@ -159,12 +159,12 @@ namespace BansheeEngine
 
 	void EditorWidgetBase::_disable()
 	{
-		mContent->disableRecursively();
+		mContent->setVisible(false);
 	}
 
 	void EditorWidgetBase::_enable()
 	{
-		mContent->enableRecursively();
+		mContent->setVisible(true);
 	}
 
 	CGUIWidget& EditorWidgetBase::getParentWidget() const

+ 15 - 27
BansheeEditor/Source/BsGUITreeView.cpp

@@ -119,7 +119,7 @@ namespace BansheeEngine
 
 		mBackgroundImage = GUITexture::create(mBackgroundStyle);
 		mNameEditBox = GUITreeViewEditBox::create(mEditBoxStyle);
-		mNameEditBox->disableRecursively();
+		mNameEditBox->setVisible(false);
 
 		mNameEditBox->onInputConfirmed.connect(std::bind(&GUITreeView::onEditAccepted, this));
 		mNameEditBox->onInputCanceled.connect(std::bind(&GUITreeView::onEditCanceled, this));
@@ -128,8 +128,8 @@ namespace BansheeEngine
 		mDragHighlight = GUITexture::create(mDragHighlightStyle);
 		mDragSepHighlight = GUITexture::create(mDragSepHighlightStyle);
 
-		mDragHighlight->disableRecursively();
-		mDragSepHighlight->disableRecursively();
+		mDragHighlight->setVisible(false);
+		mDragSepHighlight->setVisible(false);
 
 		mDragHighlight->_setElementDepth(2);
 		mDragSepHighlight->_setElementDepth(2);
@@ -879,12 +879,12 @@ namespace BansheeEngine
 		assert(mEditElement == nullptr);
 
 		mEditElement = element;
-		mNameEditBox->enableRecursively();
+		mNameEditBox->setVisible(true);
 		mNameEditBox->setText(toWString(element->mName));
 		mNameEditBox->setFocus(true);
 
 		if(element->mElement != nullptr)
-			element->mElement->disableRecursively();
+			element->mElement->setVisible(false);
 	}
 
 	void GUITreeView::disableEdit(bool applyChanges)
@@ -892,7 +892,7 @@ namespace BansheeEngine
 		assert(mEditElement != nullptr);
 
 		if(mEditElement->mElement != nullptr)
-			mEditElement->mElement->enableRecursively();
+			mEditElement->mElement->setVisible(true);
 
 		if(applyChanges)
 		{
@@ -901,7 +901,7 @@ namespace BansheeEngine
 		}
 
 		mNameEditBox->setFocus(false);
-		mNameEditBox->disableRecursively();
+		mNameEditBox->setVisible(false);
 		mEditElement = nullptr;
 	}
 
@@ -1132,21 +1132,15 @@ namespace BansheeEngine
 
 			if(interactableElement == nullptr)
 			{
-				if(!mDragHighlight->_isDisabled())
-					mDragHighlight->disableRecursively();
-
-				if(!mDragSepHighlight->_isDisabled())
-					mDragSepHighlight->disableRecursively();
+				mDragHighlight->setVisible(false);
+				mDragSepHighlight->setVisible(false);
 			}
 			else
 			{
 				if(interactableElement->isTreeElement())
 				{
-					if(!mDragSepHighlight->_isDisabled())
-						mDragSepHighlight->disableRecursively();
-
-					if(mDragHighlight->_isDisabled())
-						mDragHighlight->enableRecursively();
+					mDragSepHighlight->setVisible(false);
+					mDragHighlight->setVisible(true);
 
 					GUILayoutData childData = data;
 					childData.area = interactableElement->bounds;
@@ -1155,11 +1149,8 @@ namespace BansheeEngine
 				}
 				else
 				{
-					if(!mDragHighlight->_isDisabled())
-						mDragHighlight->disableRecursively();
-
-					if(mDragSepHighlight->_isDisabled())
-						mDragSepHighlight->enableRecursively();
+					mDragHighlight->setVisible(false);
+					mDragSepHighlight->setVisible(true);
 
 					GUILayoutData childData = data;
 					childData.area = interactableElement->bounds;
@@ -1170,11 +1161,8 @@ namespace BansheeEngine
 		}
 		else
 		{
-			if(!mDragHighlight->_isDisabled())
-				mDragHighlight->disableRecursively();
-
-			if(!mDragSepHighlight->_isDisabled())
-				mDragSepHighlight->disableRecursively();
+			mDragHighlight->setVisible(false);
+			mDragSepHighlight->setVisible(false);
 		}
 
 		// Update scroll bounds

+ 7 - 10
BansheeEngine/Include/BsGUIElementBase.h

@@ -71,14 +71,11 @@ namespace BansheeEngine
 		virtual void resetDimensions();
 
 		/**
-		 * @brief	Enables (default) this element and all its children.
+		 * @brief	Hides or shows this element and recursively applies the same state to all the child elements.
+		 * 			This will not remove the element from the layout, the room for it will still be reserved but it just
+		 * 			won't be visible.
 		 */
-		void enableRecursively();
-
-		/**
-		 * @brief	Disables this element and all its children.
-		 */
-		void disableRecursively();
+		void setVisible(bool visible);
 
 		/**
 		 * @brief	Returns non-clipped bounds of the GUI element. Relative to a parent GUI panel.
@@ -262,11 +259,11 @@ namespace BansheeEngine
 		CGUIWidget* _getParentWidget() const { return mParentWidget; }
 
 		/**
-		 * @brief	Returns true if element is disabled and won't be visible or interactable.
+		 * @brief	Returns if element is visible or hidden.
 		 *
 		 * @note	Internal method.
 		 */
-		bool _isDisabled() const { return mIsDisabled; }
+		bool _isVisible() const { return mIsVisible; }
 
 		/**
 		 * @brief	Changes the active GUI element widget. This allows you to move an element
@@ -376,7 +373,7 @@ namespace BansheeEngine
 		GUIElementBase* mParentElement;
 
 		Vector<GUIElementBase*> mChildren;	
-		bool mIsDisabled;
+		bool mIsVisible;
 		bool mIsDirty;
 
 		GUIDimensions mDimensions;

+ 18 - 33
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -13,14 +13,14 @@
 namespace BansheeEngine
 {
 	GUIElementBase::GUIElementBase()
-		:mIsDirty(true), mParentElement(nullptr), mIsDisabled(false), 
+		:mIsDirty(true), mParentElement(nullptr), mIsVisible(true), 
 		mParentWidget(nullptr), mAnchorParent(nullptr), mUpdateParent(nullptr)
 	{
 
 	}
 
 	GUIElementBase::GUIElementBase(const GUIDimensions& dimensions)
-		:mIsDirty(true), mParentElement(nullptr), mIsDisabled(false),
+		:mIsDirty(true), mParentElement(nullptr), mIsVisible(true),
 		mParentWidget(nullptr), mDimensions(dimensions), 
 		mAnchorParent(nullptr), mUpdateParent(nullptr)
 	{
@@ -193,7 +193,7 @@ namespace BansheeEngine
 
 	void GUIElementBase::_markLayoutAsDirty() 
 	{ 
-		if(_isDisabled())
+		if(!_isVisible())
 			return;
 
 		if (mUpdateParent != nullptr)
@@ -204,7 +204,7 @@ namespace BansheeEngine
 
 	void GUIElementBase::_markContentAsDirty()
 	{
-		if (_isDisabled())
+		if (!_isVisible())
 			return;
 
 		if (mParentWidget != nullptr)
@@ -213,43 +213,31 @@ namespace BansheeEngine
 
 	void GUIElementBase::_markMeshAsDirty()
 	{
-		if(_isDisabled())
+		if(!_isVisible())
 			return;
 
 		if (mParentWidget != nullptr)
 			mParentWidget->_markMeshDirty(this);
 	}
 
-	void GUIElementBase::enableRecursively()
+	void GUIElementBase::setVisible(bool visible)
 	{
-		if (mParentElement != nullptr && mParentElement->mIsDisabled)
-			return; // Cannot enable if parent is disabled
+		if (visible && mParentElement != nullptr && !mParentElement->mIsVisible)
+			return; // Cannot make visible if parent is not visible
 
-		// Make sure to mark everything as dirty, as we didn't track any dirty flags while the element was disabled
-		if (mIsDisabled)
+		if (mIsVisible != visible)
 		{
-			mIsDisabled = false;
-			_markLayoutAsDirty();
-		}
-
-		for(auto& elem : mChildren)
-		{
-			elem->enableRecursively();
-		}
-	}
+			// If making an element visible make sure to mark layout as dirty, as we didn't track any dirty flags while the element was disabled
+			if (!visible)
+				_markMeshAsDirty();
+			else
+				_markLayoutAsDirty();
 
-	void GUIElementBase::disableRecursively()
-	{
-		if (!mIsDisabled)
-		{
-			_markLayoutAsDirty();
-			mIsDisabled = true;
+			mIsVisible = visible;
 		}
 
 		for(auto& elem : mChildren)
-		{
-			elem->disableRecursively();
-		}
+			elem->setVisible(visible);
 	}
 
 	void GUIElementBase::_updateLayout(const GUILayoutData& data)
@@ -276,9 +264,6 @@ namespace BansheeEngine
 
 	LayoutSizeRange GUIElementBase::_calculateLayoutSizeRange() const
 	{
-		if (mIsDisabled)
-			return LayoutSizeRange();
-
 		const GUIDimensions& dimensions = _getDimensions();
 		return dimensions.calculateSizeRange(_getOptimalSize());
 	}
@@ -324,8 +309,8 @@ namespace BansheeEngine
 		element->_setParent(this);
 		mChildren.push_back(element);
 
-		if (mIsDisabled)
-			element->disableRecursively();
+		if (!mIsVisible)
+			element->setVisible(false);
 
 		_markLayoutAsDirty();
 	}

+ 2 - 2
BansheeEngine/Source/BsGUILayout.cpp

@@ -48,8 +48,8 @@ namespace BansheeEngine
 		element->_setParent(this);
 		mChildren.insert(mChildren.begin() + idx, element);
 		
-		if (mIsDisabled)
-			element->disableRecursively();
+		if (!mIsVisible)
+			element->setVisible(false);
 
 		_markLayoutAsDirty();
 	}

+ 0 - 3
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -13,9 +13,6 @@ namespace BansheeEngine
 
 	LayoutSizeRange GUILayoutX::_calculateLayoutSizeRange() const
 	{
-		if (mIsDisabled)
-			return LayoutSizeRange();
-
 		Vector2I optimalSize;
 		Vector2I minSize;
 		for (auto& child : mChildren)

+ 0 - 3
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -12,9 +12,6 @@ namespace BansheeEngine
 
 	LayoutSizeRange GUILayoutY::_calculateLayoutSizeRange() const
 	{
-		if (mIsDisabled)
-			return LayoutSizeRange();
-
 		Vector2I optimalSize;
 		Vector2I minSize;
 

+ 2 - 2
BansheeEngine/Source/BsGUIManager.cpp

@@ -430,7 +430,7 @@ namespace BansheeEngine
 
 					for (auto& element : elements)
 					{
-						if (element->_isDisabled())
+						if (!element->_isVisible())
 							continue;
 
 						UINT32 numRenderElems = element->_getNumRenderElements();
@@ -1215,7 +1215,7 @@ namespace BansheeEngine
 					{
 						GUIElement* element = *iter;
 
-						if(!element->_isDisabled() && element->_isInBounds(localPos))
+						if(element->_isVisible() && element->_isInBounds(localPos))
 						{
 							ElementInfoUnderPointer elementInfo(element, widget);
 

+ 0 - 3
BansheeEngine/Source/BsGUIPanel.cpp

@@ -22,9 +22,6 @@ namespace BansheeEngine
 
 	LayoutSizeRange GUIPanel::_calculateLayoutSizeRange() const
 	{
-		if (mIsDisabled)
-			return LayoutSizeRange();
-
 		Vector2I optimalSize;
 		Vector2I minSize;
 

+ 0 - 3
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -64,9 +64,6 @@ namespace BansheeEngine
 
 	LayoutSizeRange GUIScrollArea::_calculateLayoutSizeRange() const
 	{
-		if (mIsDisabled)
-			return LayoutSizeRange();
-
 		// I'm ignoring scroll bars here since if the content layout fits
 		// then they're not needed and the range is valid. And if it doesn't
 		// fit the area will get clipped anyway and including the scroll bars

+ 28 - 28
BansheeEngine/Source/BsProfilerOverlay.cpp

@@ -41,8 +41,8 @@ namespace BansheeEngine
 
 				if (!row.disabled)
 				{
-					row.labelLayout->disableRecursively();
-					row.contentLayout->disableRecursively();
+					row.labelLayout->setVisible(false);
+					row.contentLayout->setVisible(false);
 					row.disabled = true;
 				}
 			}
@@ -111,8 +111,8 @@ namespace BansheeEngine
 
 			if (row.disabled)
 			{
-				row.labelLayout->enableRecursively();
-				row.contentLayout->enableRecursively();
+				row.labelLayout->setVisible(true);
+				row.contentLayout->setVisible(true);
 				row.disabled = false;
 			}
 
@@ -142,8 +142,8 @@ namespace BansheeEngine
 
 				if (!row.disabled)
 				{
-					row.labelLayout->disableRecursively();
-					row.contentLayout->disableRecursively();
+					row.labelLayout->setVisible(false);
+					row.contentLayout->setVisible(false);
 					row.disabled = true;
 				}
 			}
@@ -212,8 +212,8 @@ namespace BansheeEngine
 
 			if (row.disabled)
 			{
-				row.labelLayout->enableRecursively();
-				row.contentLayout->enableRecursively();
+				row.labelLayout->setVisible(true);
+				row.contentLayout->setVisible(true);
 				row.disabled = false;
 			}
 
@@ -242,7 +242,7 @@ namespace BansheeEngine
 
 				if (!row.disabled)
 				{
-					row.layout->disableRecursively();
+					row.layout->setVisible(false);
 					row.disabled = true;
 				}
 			}
@@ -277,7 +277,7 @@ namespace BansheeEngine
 
 			if (row.disabled)
 			{
-				row.layout->enableRecursively();
+				row.layout->setVisible(true);
 				row.disabled = false;
 			}
 
@@ -507,21 +507,21 @@ namespace BansheeEngine
 	{
 		if (type == ProfilerOverlayType::CPUSamples)
 		{
-			mBasicLayoutLabels->enableRecursively();
-			mPreciseLayoutLabels->enableRecursively();
-			mBasicLayoutContents->enableRecursively();
-			mPreciseLayoutContents->enableRecursively();
-			mGPULayoutFrameContents->disableRecursively();
-			mGPULayoutSamples->disableRecursively();
+			mBasicLayoutLabels->setVisible(true);
+			mPreciseLayoutLabels->setVisible(true);
+			mBasicLayoutContents->setVisible(true);
+			mPreciseLayoutContents->setVisible(true);
+			mGPULayoutFrameContents->setVisible(false);
+			mGPULayoutSamples->setVisible(false);
 		}
 		else
 		{
-			mGPULayoutFrameContents->enableRecursively();
-			mGPULayoutSamples->enableRecursively();
-			mBasicLayoutLabels->disableRecursively();
-			mPreciseLayoutLabels->disableRecursively();
-			mBasicLayoutContents->disableRecursively();
-			mPreciseLayoutContents->disableRecursively();
+			mGPULayoutFrameContents->setVisible(true);
+			mGPULayoutSamples->setVisible(true);
+			mBasicLayoutLabels->setVisible(false);
+			mPreciseLayoutLabels->setVisible(false);
+			mBasicLayoutContents->setVisible(false);
+			mPreciseLayoutContents->setVisible(false);
 		}
 
 		mType = type;
@@ -530,12 +530,12 @@ namespace BansheeEngine
 
 	void ProfilerOverlayInternal::hide()
 	{
-		mBasicLayoutLabels->disableRecursively();
-		mPreciseLayoutLabels->disableRecursively();
-		mBasicLayoutContents->disableRecursively();
-		mPreciseLayoutContents->disableRecursively();
-		mGPULayoutFrameContents->disableRecursively();
-		mGPULayoutSamples->disableRecursively();
+		mBasicLayoutLabels->setVisible(false);
+		mPreciseLayoutLabels->setVisible(false);
+		mBasicLayoutContents->setVisible(false);
+		mPreciseLayoutContents->setVisible(false);
+		mGPULayoutFrameContents->setVisible(false);
+		mGPULayoutSamples->setVisible(false);
 		mIsShown = false;
 	}
 

+ 2 - 2
SBansheeEditor/Source/BsGUITextureField.cpp

@@ -194,12 +194,12 @@ namespace BansheeEngine
 		{
 			HSpriteTexture sprite = SpriteTexture::create(texture);
 			mDropButton->setContent(GUIContent(sprite));
-			mClearButton->enableRecursively();
+			mClearButton->setVisible(true);
 		}
 		else
 		{
 			mDropButton->setContent(GUIContent(HString(L"(None)")));
-			mClearButton->disableRecursively();
+			mClearButton->setVisible(false);
 		}
 
 		onValueChanged(mUUID);

+ 1 - 4
SBansheeEngine/Source/BsScriptGUIElement.cpp

@@ -101,10 +101,7 @@ namespace BansheeEngine
 		if (nativeInstance->isDestroyed())
 			return;
 
-		if(visible)
-			nativeInstance->getGUIElement()->enableRecursively();
-		else
-			nativeInstance->getGUIElement()->disableRecursively();
+		nativeInstance->getGUIElement()->setVisible(visible);
 	}
 
 	void ScriptGUIElement::internal_setFocus(ScriptGUIElementBaseTBase* nativeInstance, bool focus)