Pārlūkot izejas kodu

Added a way to add layouts to GUIElement

Marko Pintera 12 gadi atpakaļ
vecāks
revīzija
0d7d909cdf

+ 6 - 0
BansheeEngine/Include/BsGUIElementBase.h

@@ -58,6 +58,12 @@ namespace BansheeEngine
 		 */
 		void markMeshAsDirty();
 
+		GUILayout& addLayoutXInternal();
+		GUILayout& addLayoutYInternal();
+		void removeLayoutInternal(GUILayout& layout);
+		GUILayout& insertLayoutXInternal(CM::UINT32 idx);
+		GUILayout& insertLayoutYInternal(CM::UINT32 idx);
+
 		GUILayout* mParentLayout;
 		CM::Vector<GUIElementBase*>::type mChildren;	
 		CM::UINT8 mIsDirty;

+ 5 - 5
BansheeEngine/Include/BsGUILayout.h

@@ -16,11 +16,11 @@ namespace BansheeEngine
 		void removeElement(GUIElement* element);
 		void insertElement(CM::UINT32 idx, GUIElement* element);
 
-		GUILayout& addLayoutX();
-		GUILayout& addLayoutY();
-		void removeLayout(GUILayout& layout);
-		GUILayout& insertLayoutX(CM::UINT32 idx);
-		GUILayout& insertLayoutY(CM::UINT32 idx);
+		GUILayout& addLayoutX() { return addLayoutXInternal(); }
+		GUILayout& addLayoutY() { return addLayoutYInternal(); }
+		void removeLayout(GUILayout& layout) { removeLayoutInternal(layout); }
+		GUILayout& insertLayoutX(CM::UINT32 idx) { return insertLayoutXInternal(idx); }
+		GUILayout& insertLayoutY(CM::UINT32 idx) { return insertLayoutYInternal(idx); }
 
 		GUIFixedSpace& addSpace(CM::UINT32 size);
 		void removeSpace(GUIFixedSpace& space);

+ 71 - 0
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -1,5 +1,8 @@
 #include "BsGUIElementBase.h"
 #include "BsGUILayout.h"
+#include "BsGUILayoutX.h"
+#include "BsGUILayoutY.h"
+#include "CmException.h"
 
 using namespace CamelotFramework;
 
@@ -72,4 +75,72 @@ namespace BansheeEngine
 				child->_updateLayout(x, y, width, height, widgetDepth, areaDepth);
 		}
 	}
+
+	GUILayout& GUIElementBase::addLayoutXInternal()
+	{
+		GUILayoutX* entry = cm_new<GUILayoutX, PoolAlloc>();
+
+		mChildren.push_back(entry);
+		markContentAsDirty();
+
+		return *entry;
+	}
+
+	GUILayout& GUIElementBase::addLayoutYInternal()
+	{
+		GUILayoutY* entry = cm_new<GUILayoutY, PoolAlloc>();
+
+		mChildren.push_back(entry);
+		markContentAsDirty();
+
+		return *entry;
+	}
+
+	void GUIElementBase::removeLayoutInternal(GUILayout& layout)
+	{
+		bool foundElem = false;
+		for(auto iter = mChildren.begin(); iter != mChildren.end(); ++iter)
+		{
+			GUIElementBase* child = *iter;
+
+			if(child->_getType() == GUIElementBase::Type::Layout && child == &layout)
+			{
+				cm_delete<PoolAlloc>(child);
+
+				mChildren.erase(iter);
+				foundElem = true;
+				markContentAsDirty();
+				break;
+			}
+		}
+
+		if(!foundElem)
+			CM_EXCEPT(InvalidParametersException, "Provided element is not a part of this layout.");
+	}
+
+	GUILayout& GUIElementBase::insertLayoutXInternal(UINT32 idx)
+	{
+		if(idx < 0 || idx >= (UINT32)mChildren.size())
+			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
+
+		GUILayoutX* entry = cm_new<GUILayoutX, PoolAlloc>();
+
+		mChildren.insert(mChildren.begin() + idx, entry);
+		markContentAsDirty();
+
+		return *entry;
+	}
+
+	GUILayout& GUIElementBase::insertLayoutYInternal(UINT32 idx)
+	{
+		if(idx < 0 || idx >= (UINT32)mChildren.size())
+			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
+
+		GUILayoutY* entry = cm_new<GUILayoutY, PoolAlloc>();
+
+		mChildren.insert(mChildren.begin() + idx, entry);
+		markContentAsDirty();
+
+		return *entry;
+	}
 }

+ 0 - 68
BansheeEngine/Source/BsGUILayout.cpp

@@ -73,74 +73,6 @@ namespace BansheeEngine
 		markContentAsDirty();
 	}
 
-	GUILayout& GUILayout::addLayoutX()
-	{
-		GUILayoutX* entry = cm_new<GUILayoutX, PoolAlloc>();
-
-		mChildren.push_back(entry);
-		markContentAsDirty();
-
-		return *entry;
-	}
-
-	GUILayout& GUILayout::addLayoutY()
-	{
-		GUILayoutY* entry = cm_new<GUILayoutY, PoolAlloc>();
-
-		mChildren.push_back(entry);
-		markContentAsDirty();
-
-		return *entry;
-	}
-
-	void GUILayout::removeLayout(GUILayout& layout)
-	{
-		bool foundElem = false;
-		for(auto iter = mChildren.begin(); iter != mChildren.end(); ++iter)
-		{
-			GUIElementBase* child = *iter;
-
-			if(child->_getType() == GUIElementBase::Type::Layout && child == &layout)
-			{
-				cm_delete<PoolAlloc>(child);
-
-				mChildren.erase(iter);
-				foundElem = true;
-				markContentAsDirty();
-				break;
-			}
-		}
-
-		if(!foundElem)
-			CM_EXCEPT(InvalidParametersException, "Provided element is not a part of this layout.");
-	}
-
-	GUILayout& GUILayout::insertLayoutX(UINT32 idx)
-	{
-		if(idx < 0 || idx >= (UINT32)mChildren.size())
-			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
-
-		GUILayoutX* entry = cm_new<GUILayoutX, PoolAlloc>();
-
-		mChildren.insert(mChildren.begin() + idx, entry);
-		markContentAsDirty();
-
-		return *entry;
-	}
-
-	GUILayout& GUILayout::insertLayoutY(UINT32 idx)
-	{
-		if(idx < 0 || idx >= (UINT32)mChildren.size())
-			CM_EXCEPT(InvalidParametersException, "Index out of range: " + toString(idx) + ". Valid range: 0 .. " + toString((UINT32)mChildren.size()));
-
-		GUILayoutY* entry = cm_new<GUILayoutY, PoolAlloc>();
-
-		mChildren.insert(mChildren.begin() + idx, entry);
-		markContentAsDirty();
-
-		return *entry;
-	}
-
 	GUIFixedSpace& GUILayout::addSpace(UINT32 size)
 	{
 		GUIFixedSpace* entry = cm_new<GUIFixedSpace, PoolAlloc>(size);