Browse Source

GUIWidgets update only if they're actually dirty

Marko Pintera 12 years ago
parent
commit
1d4fc4cd6f

+ 5 - 0
BansheeEngine/Include/BsGUIElement.h

@@ -71,6 +71,10 @@ namespace BansheeEngine
 		void setDepth(INT32 depth) { mDepth = depth; }
 		void setDepth(INT32 depth) { mDepth = depth; }
 		INT32 getDepth() const { return mDepth; }
 		INT32 getDepth() const { return mDepth; }
 
 
+		bool isDirty() const { return mIsDirty; }
+		void markAsClean() { mIsDirty = false; }
+		void markAsDirty() { mIsDirty = true; }
+
 		//  onMouseMove
 		//  onMouseMove
 		//	onMousePress
 		//	onMousePress
 		//	onMouseReleased
 		//	onMouseReleased
@@ -84,6 +88,7 @@ namespace BansheeEngine
 		GUIWidget* mParent;
 		GUIWidget* mParent;
 		CM::Rect mBounds;
 		CM::Rect mBounds;
 		INT32 mDepth;
 		INT32 mDepth;
+		bool mIsDirty;
 		const GUIElementStyle* mStyle;
 		const GUIElementStyle* mStyle;
 
 
 		static void destroy(GUIElement* element);
 		static void destroy(GUIElement* element);

+ 1 - 1
BansheeEngine/Source/BsGUIElement.cpp

@@ -8,7 +8,7 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
 	GUIElement::GUIElement(GUIWidget* parent)
 	GUIElement::GUIElement(GUIWidget* parent)
-		:mParent(parent)
+		:mParent(parent), mIsDirty(true)
 	{
 	{
 		if(parent == nullptr)
 		if(parent == nullptr)
 			CM_EXCEPT(InvalidParametersException, "Cannot create GUI element without providing a parent!");
 			CM_EXCEPT(InvalidParametersException, "Cannot create GUI element without providing a parent!");

+ 2 - 0
BansheeEngine/Source/BsGUILabel.cpp

@@ -64,6 +64,8 @@ namespace BansheeEngine
 
 
 		mTextSprite->update(mDesc);
 		mTextSprite->update(mDesc);
 		mBounds = mTextSprite->getBounds();
 		mBounds = mTextSprite->getBounds();
+
+		markAsDirty();
 	}
 	}
 
 
 	GUILabel* GUILabel::create(GUIWidget* parent, const String& text)
 	GUILabel* GUILabel::create(GUIWidget* parent, const String& text)

+ 1 - 1
BansheeEngine/Source/BsGUIManager.cpp

@@ -58,7 +58,7 @@ namespace BansheeEngine
 		{
 		{
 			const RenderWindow* window = widget->getOwnerWindow();
 			const RenderWindow* window = widget->getOwnerWindow();
 
 
-			if(!window->getHasFocus())
+			if(!window->hasFocus())
 				continue;
 				continue;
 
 
 			Int2 screenPos = Cursor::getWindowPosition(*window);
 			Int2 screenPos = Cursor::getWindowPosition(*window);

+ 14 - 0
BansheeEngine/Source/BsGUIWidget.cpp

@@ -101,6 +101,19 @@ namespace BansheeEngine
 			std::shared_ptr<MeshData> meshData;
 			std::shared_ptr<MeshData> meshData;
 		};
 		};
 
 
+		bool isDirty = false;
+		for(auto& elem : mElements)
+		{
+			if(elem->isDirty())
+			{
+				isDirty = true;
+				break;
+			}
+		}
+
+		if(!isDirty) // Nothing to update
+			return;
+
 		std::unordered_map<UINT64, TempMeshData> meshDataPerRenderElement;
 		std::unordered_map<UINT64, TempMeshData> meshDataPerRenderElement;
 
 
 		// Group meshes based on used materials
 		// Group meshes based on used materials
@@ -169,6 +182,7 @@ namespace BansheeEngine
 				UINT32 indexStride = meshData->getIndexElementSize();
 				UINT32 indexStride = meshData->getIndexElementSize();
 
 
 				elem->fillBuffer(vertices, uvs, indices, startingQuad, maxNumQuads, vertexStride, indexStride, i);
 				elem->fillBuffer(vertices, uvs, indices, startingQuad, maxNumQuads, vertexStride, indexStride, i);
+				elem->markAsClean();
 
 
 				UINT32 numQuads = elem->getNumQuads(i);
 				UINT32 numQuads = elem->getNumQuads(i);
 				meshDataPerRenderElement[meshGroup].quadOffset += numQuads;
 				meshDataPerRenderElement[meshGroup].quadOffset += numQuads;

+ 1 - 2
CamelotClient/CmEditorWindow.cpp

@@ -57,7 +57,6 @@ namespace BansheeEditor
 	{
 	{
 		Int2 cursorPos = Cursor::getWindowPosition(*mRenderWindow);
 		Int2 cursorPos = Cursor::getWindowPosition(*mRenderWindow);
 		
 		
-		mDbgLabel->setText(toString(mDbgLabel->getBounds().x) + ", " + toString(mDbgLabel->getBounds().y) + ", " + 
-			toString(mDbgLabel->getBounds().width) + " - " + toString(mDbgLabel->getBounds().height));
+		mDbgLabel->setText(toString(cursorPos.x) + ", " + toString(cursorPos.y));
 	}
 	}
 }
 }

+ 1 - 1
CamelotCore/Include/CmRenderTarget.h

@@ -175,7 +175,7 @@ namespace CamelotFramework
 		void setVSync(bool vsync)  { mVSync = vsync; }
 		void setVSync(bool vsync)  { mVSync = vsync; }
 
 
 		void setHasFocus(bool focus) { mHasFocus = focus; }
 		void setHasFocus(bool focus) { mHasFocus = focus; }
-		bool getHasFocus() const { return mHasFocus; }
+		bool hasFocus() const { return mHasFocus; }
 
 
     protected:
     protected:
 		RenderTarget();
 		RenderTarget();

+ 2 - 2
CamelotCore/Source/CmWindowEventUtilities.cpp

@@ -165,7 +165,7 @@ LRESULT CALLBACK WindowEventUtilities::_WndProc(HWND hWnd, UINT uMsg, WPARAM wPa
         {
         {
 		    win->setActive( true );
 		    win->setActive( true );
 
 
-			if(!win->getHasFocus())
+			if(!win->hasFocus())
 				win->setHasFocus(true);
 				win->setHasFocus(true);
         }
         }
         else
         else
@@ -175,7 +175,7 @@ LRESULT CALLBACK WindowEventUtilities::_WndProc(HWND hWnd, UINT uMsg, WPARAM wPa
     		    win->setActive( false );
     		    win->setActive( false );
             }
             }
 
 
-			if(win->getHasFocus())
+			if(win->hasFocus())
 				win->setHasFocus(false);
 				win->setHasFocus(false);
         }
         }