Browse Source

Added depth to GUIWidget and made GUIArea and GUIWidget depth UINT16, then combining them for final depth

Marko Pintera 12 years ago
parent
commit
648f795e82

+ 5 - 5
BansheeEngine/Include/BsGUIArea.h

@@ -14,25 +14,25 @@ namespace BansheeEngine
 		 *			If you want the area to expand vertically or horizontally, together with its parent
 		 *			widget, set height or width to 0, respectively.
 		 */
-		static GUIArea* create(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width = 0, UINT32 height = 0, UINT32 depth = 0);
+		static GUIArea* create(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width = 0, UINT32 height = 0, UINT16 depth = 0);
 		static void destroy(GUIArea* area);
 
 		GUILayout& getLayout() const { return *mLayout; }
 
-		UINT32 getDepth() const { return mDepth; }
-		void setDepth(UINT32 depth) { mDepth = depth; }
+		UINT16 getDepth() const { return mDepth; }
+		void setDepth(UINT16 depth) { mDepth = depth; }
 
 	private:
 		friend class GUIWidget;
 
 		GUIWidget& mWidget;
 		UINT32 mX, mY, mWidth, mHeight;
-		UINT32 mDepth;
+		UINT16 mDepth;
 		bool resizeWidthWithWindow, resizeHeightWithWindow;
 
 		GUILayout* mLayout;
 
-		GUIArea(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT32 depth);
+		GUIArea(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT16 depth);
 		~GUIArea();
 
 		void notifyWindowResized(UINT32 newWidth, UINT32 newHeight);

+ 4 - 0
BansheeEngine/Include/BsGUIWidget.h

@@ -23,6 +23,9 @@ namespace BansheeEngine
 		void setSkin(const GUISkin* skin);
 		const GUISkin* getGUISkin() const;
 
+		UINT16 getDepth() const { return mDepth; }
+		void setDepth(UINT16 depth) { mDepth = depth; }
+
 		bool inBounds(const CM::Int2& position) const;
 
 		/**
@@ -60,6 +63,7 @@ namespace BansheeEngine
 		CM::Viewport* mTarget;
 		std::vector<GUIElement*> mElements;
 		std::vector<GUIArea*> mAreas;
+		UINT16 mDepth;
 
 		mutable bool mWidgetIsDirty;
 		mutable CM::Rect mBounds;

+ 7 - 3
BansheeEngine/Source/BsGUIArea.cpp

@@ -6,7 +6,7 @@ using namespace CamelotFramework;
 
 namespace BansheeEngine
 {
-	GUIArea::GUIArea(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT32 depth)
+	GUIArea::GUIArea(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT16 depth)
 		:mWidget(widget), mX(x), mY(y), mWidth(width), mHeight(height), mDepth(depth)
 	{
 		mLayout = CM_NEW(GUILayoutX, PoolAlloc) GUILayoutX();
@@ -22,7 +22,7 @@ namespace BansheeEngine
 		CM_DELETE(mLayout, GUILayout, PoolAlloc);
 	}
 
-	GUIArea* GUIArea::create(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT32 depth)
+	GUIArea* GUIArea::create(GUIWidget& widget, UINT32 x, UINT32 y, UINT32 width, UINT32 height, UINT16 depth)
 	{
 		return CM_NEW(GUIArea, PoolAlloc) GUIArea(widget, x, y, width, height, depth);
 	}
@@ -48,6 +48,10 @@ namespace BansheeEngine
 			mHeight = newHeight;
 
 		if(resizeWidthWithWindow || resizeHeightWithWindow)
-			mLayout->_update(mX, mY, mWidth, mHeight, mDepth);
+		{
+			UINT32 combinedDepth = UINT32(mWidget.getDepth()) << 16 | UINT32(mDepth);
+
+			mLayout->_update(mX, mY, mWidth, mHeight, combinedDepth);
+		}
 	}
 }

+ 1 - 1
BansheeEngine/Source/BsGUIWidget.cpp

@@ -23,7 +23,7 @@ namespace BansheeEngine
 	GUISkin GUIWidget::DefaultSkin;
 
 	GUIWidget::GUIWidget(const HSceneObject& parent)
-		:Component(parent), mSkin(nullptr), mOwnerWindow(nullptr), mWidgetIsDirty(false), mTarget(nullptr)
+		:Component(parent), mSkin(nullptr), mOwnerWindow(nullptr), mWidgetIsDirty(false), mTarget(nullptr), mDepth(0)
 	{	}
 
 	GUIWidget::~GUIWidget()

+ 0 - 1
TODO.txt

@@ -22,7 +22,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
 
 IMMEDIATE:
- - Calling GUIElement::getBounds before element was updated
  - I'm not setting worldTransform of GUI material in GUIManager::render
    - I need to separate meshes per-widget and later implement some kind of smart batching using multiple transforms per mesh
  - Widgets should probably have their own depth. Make widget and area depths UINT16, and element depth UINT32, a combination of those two.