2
0
Эх сурвалжийг харах

Added a way to change GUIArea and GUIElement parents

Marko Pintera 12 жил өмнө
parent
commit
6346a5aa56

+ 2 - 0
BansheeEngine/Include/BsGUIArea.h

@@ -58,6 +58,8 @@ namespace BansheeEngine
 		void disable();
 		void enable();
 
+		void changeParentWidget(GUIWidget& widget);
+
 		CM::UINT32 x() const { return mLeft; }
 		CM::UINT32 y() const { return mTop; }
 		CM::UINT32 width() const { return mWidth; }

+ 2 - 1
BansheeEngine/Include/BsGUIElement.h

@@ -92,7 +92,8 @@ namespace BansheeEngine
 		void _setClipRect(const CM::Rect& clipRect);
 		void _setAcceptsKeyboardFocus(bool acceptsKeyboardFocus) { mAcceptsKeyboardFocus = acceptsKeyboardFocus; }
 		virtual void _setFocus(bool focus) {}
-		
+		virtual void _changeParentWidget(GUIWidget& widget);
+
 		CM::UINT32 _getWidth() const { return mWidth; }
 		CM::UINT32 _getHeight() const { return mHeight; }
 		CM::Int2 _getOffset() const { return mOffset; }

+ 2 - 0
BansheeEngine/Include/BsGUIElementBase.h

@@ -59,6 +59,8 @@ namespace BansheeEngine
 		bool _isMeshDirty() const; 
 		bool _isDisabled() const { return mIsDisabled; }
 
+		virtual void _changeParentWidget(GUIWidget& widget);
+
 	protected:
 		/**
 		 * @brief	Marks the elements contents as dirty, which causes the sprite meshes to be recreated from scratch.

+ 13 - 0
BansheeEngine/Source/BsGUIArea.cpp

@@ -99,6 +99,19 @@ namespace BansheeEngine
 		mLayout->enableRecursively();
 	}
 
+	void GUIArea::changeParentWidget(GUIWidget& widget)
+	{
+		if(&mWidget == &widget)
+			return;
+
+		mWidget.unregisterArea(this);
+		widget.registerArea(this);
+
+		mWidget = widget;
+
+		mLayout->_changeParentWidget(widget);
+	}
+
 	void GUIArea::_update()
 	{
 		if(!mIsDisabled && isDirty())

+ 13 - 0
BansheeEngine/Source/BsGUIElement.cpp

@@ -118,6 +118,19 @@ namespace BansheeEngine
 		}
 	}
 
+	void GUIElement::_changeParentWidget(GUIWidget& widget)
+	{
+		if(&mParent != &widget)
+		{
+			mParent.unregisterElement(this);
+			widget.registerElement(this);
+
+			mParent = widget;
+		}
+
+		GUIElementBase::_changeParentWidget(widget);
+	}
+
 	Rect GUIElement::getVisibleBounds() const
 	{
 		Rect bounds = _getBounds();

+ 8 - 0
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -181,4 +181,12 @@ namespace BansheeEngine
 
 		return *entry;
 	}
+
+	void GUIElementBase::_changeParentWidget(GUIWidget& widget)
+	{
+		for(auto& child : mChildren)
+		{
+			child->_changeParentWidget(widget);
+		}
+	}
 }

+ 6 - 5
CamelotClient/Source/BsEditorWidget.cpp

@@ -43,12 +43,13 @@ namespace BansheeEditor
 	{
 		if(mParentWidget != &widget) 
 		{
-			// TODO - GUIArea mContent should be recreated (or moved) to the new widget
-			// TODO - Not only GUIArea needs to be moved, but all GUIElements
-		}
+			if(mParentWidget == nullptr)
+				mContent = GUIArea::create(widget, 0, 0, 0, 0, 10000);
+			else
+				mContent->changeParentWidget(widget);
 
-		mParentWidget = &widget;
-		mContent = GUIArea::create(widget, 0, 0, 0, 0, 10000);
+			mParentWidget = &widget;
+		}
 	}
 
 	void EditorWidget::_disable()