Просмотр исходного кода

Resizing a window from the sim thread will now properly trigger the resize event immediately
Updating a GUI element bounds will now properly cause a layout update in case that element has a children of its own
GUI element bound calculations now return bounds relative to GUIWidget, not GUIArea
Fixed an error in layout size range calculation
When creating a new GUI area from C# make sure to immediately set its size

Marko Pintera 10 лет назад
Родитель
Сommit
f4b37776b7

+ 11 - 1
BansheeCore/Include/BsRenderWindowManager.h

@@ -24,6 +24,16 @@ namespace BansheeEngine
 			UINT32 size;
 			UINT32 size;
 		};
 		};
 
 
+		/**
+		 * @brief	Holds information about a window that was moved or resized.
+		 */
+		struct MoveOrResizeData
+		{
+			INT32 x, y;
+			UINT32 width, height;
+			RenderWindow* window;
+		};
+
 	public:
 	public:
 		RenderWindowManager();
 		RenderWindowManager();
 		~RenderWindowManager();
 		~RenderWindowManager();
@@ -115,7 +125,7 @@ namespace BansheeEngine
 
 
 		RenderWindow* mWindowInFocus;
 		RenderWindow* mWindowInFocus;
 		RenderWindow* mNewWindowInFocus;
 		RenderWindow* mNewWindowInFocus;
-		Vector<RenderWindow*> mMovedOrResizedWindows;
+		Vector<MoveOrResizeData> mMovedOrResizedWindows;
 		Vector<RenderWindow*> mMouseLeftWindows;
 		Vector<RenderWindow*> mMouseLeftWindows;
 		Map<RenderWindow*, DirtyPropertyData> mDirtyProperties;
 		Map<RenderWindow*, DirtyPropertyData> mDirtyProperties;
 	};
 	};

+ 2 - 0
BansheeCore/Source/BsRenderWindow.cpp

@@ -143,6 +143,8 @@ namespace BansheeEngine
 
 
 		getMutableProperties().mWidth = width;
 		getMutableProperties().mWidth = width;
 		getMutableProperties().mHeight = height;
 		getMutableProperties().mHeight = height;
+		onResized();
+
 		accessor.queueCommand(std::bind(resizeFunc, getCore(), width, height));
 		accessor.queueCommand(std::bind(resizeFunc, getCore(), width, height));
 	}
 	}
 
 

+ 45 - 17
BansheeCore/Source/BsRenderWindowManager.cpp

@@ -52,7 +52,8 @@ namespace BansheeEngine
 
 
 			mCreatedWindows.erase(iterFind);
 			mCreatedWindows.erase(iterFind);
 
 
-			auto iterFind2 = std::find(begin(mMovedOrResizedWindows), end(mMovedOrResizedWindows), window);
+			auto iterFind2 = std::find_if(begin(mMovedOrResizedWindows), end(mMovedOrResizedWindows), 
+				[&](const MoveOrResizeData& x) { return x.window == window; });
 
 
 			if(iterFind2 != mMovedOrResizedWindows.end())
 			if(iterFind2 != mMovedOrResizedWindows.end())
 				mMovedOrResizedWindows.erase(iterFind2);
 				mMovedOrResizedWindows.erase(iterFind2);
@@ -106,10 +107,30 @@ namespace BansheeEngine
 
 
 		BS_LOCK_MUTEX(mWindowMutex);
 		BS_LOCK_MUTEX(mWindowMutex);
 
 
-		auto iterFind = std::find(begin(mMovedOrResizedWindows), end(mMovedOrResizedWindows), window);
+		auto iterFind = std::find_if(begin(mMovedOrResizedWindows), end(mMovedOrResizedWindows), 
+			[&](const MoveOrResizeData& x) { return x.window == window; });
 
 
-		if (iterFind == end(mMovedOrResizedWindows))
-			mMovedOrResizedWindows.push_back(window);
+		const RenderWindowProperties& props = coreWindow->getProperties();
+		MoveOrResizeData* moveResizeData = nullptr;
+
+		if (iterFind != end(mMovedOrResizedWindows))
+		{
+			moveResizeData = &*iterFind;
+
+		}
+		else
+		{
+			MoveOrResizeData newEntry;
+			newEntry.window = window;
+
+			mMovedOrResizedWindows.push_back(newEntry);
+			moveResizeData = &mMovedOrResizedWindows.back();
+		}
+		
+		moveResizeData->x = props.getLeft();
+		moveResizeData->y = props.getTop();
+		moveResizeData->width = props.getWidth();
+		moveResizeData->height = props.getHeight();
 
 
 		setDirtyProperties(coreWindow);
 		setDirtyProperties(coreWindow);
 	}
 	}
@@ -155,14 +176,28 @@ namespace BansheeEngine
 	void RenderWindowManager::_update()
 	void RenderWindowManager::_update()
 	{
 	{
 		RenderWindow* newWinInFocus = nullptr;
 		RenderWindow* newWinInFocus = nullptr;
-		Vector<RenderWindow*> movedOrResizedWindows;
+		Vector<MoveOrResizeData> movedOrResizedWindows;
 		Vector<RenderWindow*> mouseLeftWindows;
 		Vector<RenderWindow*> mouseLeftWindows;
 
 
 		{
 		{
 			BS_LOCK_MUTEX(mWindowMutex);
 			BS_LOCK_MUTEX(mWindowMutex);
 			newWinInFocus = mNewWindowInFocus;
 			newWinInFocus = mNewWindowInFocus;
 
 
-			movedOrResizedWindows = mMovedOrResizedWindows;
+			for (auto& moveResizeData : mMovedOrResizedWindows)
+			{
+				RenderWindow* window = moveResizeData.window;
+				const RenderWindowProperties& props = window->getProperties();
+
+				// Need to eliminate non-dirty ones because it's possible we already triggered the resize event
+				// if the resize call originated from the sim thread, so we don't trigger it twice.
+
+				bool isDirty = moveResizeData.x != props.getLeft() || moveResizeData.y != props.getTop()
+					|| moveResizeData.width != props.getWidth() || moveResizeData.height != props.getHeight();
+
+				if (isDirty)
+					movedOrResizedWindows.push_back(moveResizeData);
+			}
+
 			mMovedOrResizedWindows.clear();
 			mMovedOrResizedWindows.clear();
 
 
 			mouseLeftWindows = mMouseLeftWindows;
 			mouseLeftWindows = mMouseLeftWindows;
@@ -185,24 +220,17 @@ namespace BansheeEngine
 		if(mWindowInFocus != newWinInFocus)
 		if(mWindowInFocus != newWinInFocus)
 		{
 		{
 			if(mWindowInFocus != nullptr)
 			if(mWindowInFocus != nullptr)
-			{
-				if(!onFocusLost.empty())
-					onFocusLost(*mWindowInFocus);
-			}
+				onFocusLost(*mWindowInFocus);
 
 
 			if(newWinInFocus != nullptr)
 			if(newWinInFocus != nullptr)
-			{
-				if(!onFocusGained.empty())
-					onFocusGained(*newWinInFocus);
-			}
+				onFocusGained(*newWinInFocus);
 
 
 			mWindowInFocus = newWinInFocus;
 			mWindowInFocus = newWinInFocus;
 		}
 		}
 
 
-		for(auto& window : movedOrResizedWindows)
+		for (auto& moveResizeData : movedOrResizedWindows)
 		{
 		{
-			if(!window->onResized.empty())
-				window->onResized();
+			moveResizeData.window->onResized();
 		}
 		}
 
 
 		if (!onMouseLeftWindow.empty())
 		if (!onMouseLeftWindow.empty())

+ 6 - 0
BansheeEngine/Include/BsGUIElementContainer.h

@@ -11,6 +11,12 @@ namespace BansheeEngine
 	 */
 	 */
 	class BS_EXPORT GUIElementContainer : public GUIElement
 	class BS_EXPORT GUIElementContainer : public GUIElement
 	{
 	{
+	public:
+		/**
+		 * @copydoc	GUIElementBase::setOffset
+		 */
+		void setOffset(const Vector2I& offset) override;
+
 	protected:
 	protected:
 		GUIElementContainer(const GUILayoutOptions& layoutOptions, const String& style = StringUtil::BLANK);
 		GUIElementContainer(const GUILayoutOptions& layoutOptions, const String& style = StringUtil::BLANK);
 		virtual ~GUIElementContainer();
 		virtual ~GUIElementContainer();

+ 8 - 0
BansheeEngine/Source/BsGUIElementContainer.cpp

@@ -10,6 +10,14 @@ namespace BansheeEngine
 	GUIElementContainer::~GUIElementContainer()
 	GUIElementContainer::~GUIElementContainer()
 	{ }
 	{ }
 
 
+	void GUIElementContainer::setOffset(const Vector2I& offset)
+	{
+		if (mOffset != offset)
+			markContentAsDirty();
+
+		GUIElement::setOffset(offset);
+	}
+
 	UINT32 GUIElementContainer::_getNumRenderElements() const
 	UINT32 GUIElementContainer::_getNumRenderElements() const
 	{
 	{
 		return 0;
 		return 0;

+ 2 - 2
BansheeEngine/Source/BsGUILayoutUtility.cpp

@@ -25,8 +25,8 @@ namespace BansheeEngine
 			const GUILayout* layout = static_cast<const GUILayout*>(elem);
 			const GUILayout* layout = static_cast<const GUILayout*>(elem);
 
 
 			GUIArea* parentGUIArea = layout->_getParentGUIArea();
 			GUIArea* parentGUIArea = layout->_getParentGUIArea();
-			parentArea.x = 0; // Zero because we want position relative to parent GUIArea
-			parentArea.y = 0;
+			parentArea.x = parentGUIArea->x();
+			parentArea.y = parentGUIArea->y();
 			parentArea.width = parentGUIArea->width();
 			parentArea.width = parentGUIArea->width();
 			parentArea.height = parentGUIArea->height();
 			parentArea.height = parentGUIArea->height();
 
 

+ 5 - 4
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -29,13 +29,14 @@ namespace BansheeEngine
 
 
 			layoutSizeRange.optimal.x += sizeRange.optimal.x + paddingX;
 			layoutSizeRange.optimal.x += sizeRange.optimal.x + paddingX;
 			layoutSizeRange.min.x += sizeRange.min.x + paddingX;
 			layoutSizeRange.min.x += sizeRange.min.x + paddingX;
-			layoutSizeRange.max.x += sizeRange.max.x + paddingX;
 
 
-			layoutSizeRange.optimal.y = std::max((UINT32)sizeRange.optimal.y, layoutSizeRange.optimal.y + paddingY);
-			layoutSizeRange.min.y = std::max((UINT32)sizeRange.min.y, layoutSizeRange.min.y + paddingY);
-			layoutSizeRange.max.y = std::max((UINT32)sizeRange.max.y, layoutSizeRange.max.y + paddingY);
+			layoutSizeRange.optimal.y = std::max((UINT32)layoutSizeRange.optimal.y, sizeRange.optimal.y + paddingY);
+			layoutSizeRange.min.y = std::max((UINT32)layoutSizeRange.min.y, sizeRange.min.y + paddingY);
 		}
 		}
 
 
+		layoutSizeRange.max.x = 0;
+		layoutSizeRange.max.y = 0;
+
 		return layoutSizeRange;
 		return layoutSizeRange;
 	}
 	}
 
 

+ 5 - 4
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -29,13 +29,14 @@ namespace BansheeEngine
 
 
 			layoutSizeRange.optimal.y += sizeRange.optimal.y + paddingY;
 			layoutSizeRange.optimal.y += sizeRange.optimal.y + paddingY;
 			layoutSizeRange.min.y += sizeRange.min.y + paddingY;
 			layoutSizeRange.min.y += sizeRange.min.y + paddingY;
-			layoutSizeRange.max.y += sizeRange.max.y + paddingY;
 
 
-			layoutSizeRange.optimal.x = std::max((UINT32)sizeRange.optimal.x, layoutSizeRange.optimal.x + paddingX);
-			layoutSizeRange.min.x = std::max((UINT32)sizeRange.min.x, layoutSizeRange.min.x + paddingX);
-			layoutSizeRange.max.x = std::max((UINT32)sizeRange.max.x, layoutSizeRange.max.x + paddingX);
+			layoutSizeRange.optimal.x = std::max((UINT32)layoutSizeRange.optimal.x, sizeRange.optimal.x + paddingX);
+			layoutSizeRange.min.x = std::max((UINT32)layoutSizeRange.min.x, sizeRange.min.x + paddingX);
 		}
 		}
 
 
+		layoutSizeRange.max.x = 0;
+		layoutSizeRange.max.y = 0;
+
 		return layoutSizeRange;
 		return layoutSizeRange;
 	}
 	}
 
 

+ 3 - 3
MBansheeEditor/ColorPicker.cs

@@ -92,14 +92,14 @@ namespace BansheeEditor
 
 
         protected ColorPicker()
         protected ColorPicker()
             : base(false)
             : base(false)
+        { }
+
+        private void OnInitialize()
         {
         {
             Title = "Color Picker";
             Title = "Color Picker";
             Width = 270;
             Width = 270;
             Height = 400;
             Height = 400;
-        }
 
 
-        private void OnInitialize()
-        {
             guiColor = new GUIColorField("", GUIOption.FixedWidth(100));
             guiColor = new GUIColorField("", GUIOption.FixedWidth(100));
             guiSlider2DTex = new GUITexture(null, GUIOption.FixedHeight(200), GUIOption.FixedWidth(200));
             guiSlider2DTex = new GUITexture(null, GUIOption.FixedHeight(200), GUIOption.FixedWidth(200));
             guiSliderVertTex = new GUITexture(null, GUIOption.FixedHeight(200), GUIOption.FixedWidth(40));
             guiSliderVertTex = new GUITexture(null, GUIOption.FixedHeight(200), GUIOption.FixedWidth(40));

+ 5 - 0
MBansheeEditor/DebugWindow.cs

@@ -21,6 +21,11 @@ namespace BansheeEditor
 
 
             GUI.layout.AddElement(refreshAssembly);
             GUI.layout.AddElement(refreshAssembly);
             GUI.layout.AddElement(compileGame);
             GUI.layout.AddElement(compileGame);
+
+            GUIButton testExplicitBtn = new GUIButton("TESTING EXPLICIT");
+            testExplicitBtn.Bounds = compileGame.Bounds;
+            GUIArea overlay = GUI.AddArea(0, 0, Width, Height, -1, GUILayoutType.Explicit);
+            overlay.layout.AddElement(testExplicitBtn);
         }
         }
 
 
         void RefreshAssembly_OnClick()
         void RefreshAssembly_OnClick()

+ 1 - 0
MBansheeEngine/GUI/GUIArea.cs

@@ -34,6 +34,7 @@ namespace BansheeEngine
             GUIArea newArea = new GUIArea();
             GUIArea newArea = new GUIArea();
             Internal_CreateInstance(newArea, parent, x, y, width, height, depth, layoutType);
             Internal_CreateInstance(newArea, parent, x, y, width, height, depth, layoutType);
             newArea._layout = new GUILayoutX(newArea);
             newArea._layout = new GUILayoutX(newArea);
+            newArea.SetArea(x, y, width, height, depth);
 
 
             return newArea;
             return newArea;
         }
         }

+ 9 - 0
TODO.txt

@@ -18,6 +18,15 @@ Figure out how to create a C# BuiltinResources class. It should be able to load
 My GUID generation is screwed up. If multiple GUIDs are generated in succession then the timestamp will remain
 My GUID generation is screwed up. If multiple GUIDs are generated in succession then the timestamp will remain
 the same and the only variable will be the 4byte random number, which can sometimes end up identical to the previous number.
 the same and the only variable will be the 4byte random number, which can sometimes end up identical to the previous number.
 
 
+----------------------------------------------------------------------
+MenuItem
+
+MenuItem[] attribute in C#
+ - Allowed on static methods in editor assembly
+
+MenuItemManager registers then menu items with MainEditorWindow
+ - upon assembly refresh all menu items are removed, and then re-added
+
 ----------------------------------------------------------------------
 ----------------------------------------------------------------------
 VisualStudio integration
 VisualStudio integration