Browse Source

Fixed GUI bound calculation as it was incorrectly using cached layout bounds so it would calculate the wrong bounds if the cached bounds were out of date

Marko Pintera 10 years ago
parent
commit
126035479c

+ 4 - 2
BansheeEngine/Include/BsGUIElementBase.h

@@ -121,9 +121,11 @@ namespace BansheeEngine
 		 * @param	height			Available height for the layout elements.
 		 * @param	elementAreas	Array to hold output areas. Must be the same size as the number of child elements.
 		 * @param	numElements		Size of the element areas array.
-		 * @param	optimalSizes	Ranges of possible sizes used for the elements. Array must be same size as elements array.
+		 * @param	sizeRanges		Ranges of possible sizes used for the child elements. Array must be same size as elements array.
+		 * @param	mySizeRange		Size range of this element.
 		 */
-		virtual void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const;
+		virtual void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 
+			const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const;
 
 		/**
 		 * @brief	Sets a new parent for this element.

+ 2 - 1
BansheeEngine/Include/BsGUILayoutExplicit.h

@@ -29,7 +29,8 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	GUILayout::_getElementAreas
 		 */
-		void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const;
+		void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 
+			const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const;
 
 		/**
 		 * @copydoc	GUILayout::_calcActualSize

+ 2 - 1
BansheeEngine/Include/BsGUILayoutX.h

@@ -29,7 +29,8 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	GUILayout::_getElementAreas
 		 */
-		void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const;
+		void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 
+			const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const;
 
 		/**
 		 * @copydoc	GUILayout::_calcActualSize

+ 2 - 1
BansheeEngine/Include/BsGUILayoutY.h

@@ -29,7 +29,8 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	GUILayout::_getElementAreas
 		 */
-		void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const;
+		void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 
+			const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const;
 
 		/**
 		 * @copydoc	GUILayout::_calcActualSize

+ 2 - 1
BansheeEngine/Include/BsGUIScrollArea.h

@@ -173,7 +173,8 @@ namespace BansheeEngine
 		/**
 		 * @copydoc	GUIElementContainer::_getElementAreas
 		 */
-		void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const;
+		void _getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 
+			const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const;
 
 		/**
 		 * @copydoc	GUIElementContainer::_getElementAreas

+ 2 - 1
BansheeEngine/Source/BsGUIElementBase.cpp

@@ -153,7 +153,8 @@ namespace BansheeEngine
 		}
 	}
 
-	void GUIElementBase::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const
+	void GUIElementBase::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements,
+		const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const
 	{
 		assert(mChildren.size() == 0);
 	}

+ 2 - 1
BansheeEngine/Source/BsGUILayoutExplicit.cpp

@@ -20,7 +20,8 @@ namespace BansheeEngine
 
 	}
 
-	void GUILayoutExplicit::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const
+	void GUILayoutExplicit::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements,
+		const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const
 	{
 		assert(mChildren.size() == numElements);
 

+ 3 - 2
BansheeEngine/Source/BsGUILayoutUtility.cpp

@@ -52,7 +52,8 @@ namespace BansheeEngine
 		if (numElements > 0)
 			elementAreas = stackConstructN<Rect2I>(numElements);
 
-		parent->_getElementAreas(parentArea.x, parentArea.y, parentArea.width, parentArea.height, elementAreas, numElements, sizeRanges);
+		parent->_getElementAreas(parentArea.x, parentArea.y, parentArea.width, parentArea.height, elementAreas, 
+			numElements, sizeRanges, parent->_calculateLayoutSizeRange());
 		Rect2I myArea = elementAreas[myIndex];
 
 		if (elementAreas != nullptr)
@@ -77,7 +78,7 @@ namespace BansheeEngine
 		if (numElements > 0)
 			elementAreas = stackConstructN<Rect2I>(numElements);
 
-		layout->_getElementAreas(0, 0, width, height, elementAreas, numElements, sizeRanges);
+		layout->_getElementAreas(0, 0, width, height, elementAreas, numElements, sizeRanges, layout->_calculateLayoutSizeRange());
 		Rect2I* actualAreas = elementAreas; // We re-use the same array
 
 		for (UINT32 i = 0; i < numElements; i++)

+ 4 - 3
BansheeEngine/Source/BsGUILayoutX.cpp

@@ -92,11 +92,12 @@ namespace BansheeEngine
 		mSizeRange.max.y = 0;
 	}
 
-	void GUILayoutX::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const
+	void GUILayoutX::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 
+		const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const
 	{
 		assert(mChildren.size() == numElements);
 
-		UINT32 totalOptimalSize = _getOptimalSize().x;
+		UINT32 totalOptimalSize = mySizeRange.optimal.x;
 		UINT32 totalNonClampedSize = 0;
 		UINT32 numNonClampedElements = 0;
 		UINT32 numFlexibleSpaces = 0;
@@ -386,7 +387,7 @@ namespace BansheeEngine
 		if (numElements > 0)
 			elementAreas = stackConstructN<Rect2I>(numElements);
 
-		_getElementAreas(x, y,width, height, elementAreas, numElements, mChildSizeRanges);
+		_getElementAreas(x, y,width, height, elementAreas, numElements, mChildSizeRanges, mSizeRange);
 
 		// Now that we have all the areas, actually assign them
 		UINT32 childIdx = 0;

+ 3 - 3
BansheeEngine/Source/BsGUILayoutY.cpp

@@ -93,11 +93,11 @@ namespace BansheeEngine
 	}
 
 	void GUILayoutY::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 
-		const Vector<LayoutSizeRange>& sizeRanges) const
+		const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const
 	{
 		assert(mChildren.size() == numElements);
 
-		UINT32 totalOptimalSize = _getOptimalSize().y;
+		UINT32 totalOptimalSize = mySizeRange.optimal.y;
 		UINT32 totalNonClampedSize = 0;
 		UINT32 numNonClampedElements = 0;
 		UINT32 numFlexibleSpaces = 0;
@@ -383,7 +383,7 @@ namespace BansheeEngine
 		if (numElements > 0)
 			elementAreas = stackConstructN<Rect2I>(numElements);
 
-		_getElementAreas(x, y, width, height, elementAreas, numElements, mChildSizeRanges);
+		_getElementAreas(x, y, width, height, elementAreas, numElements, mChildSizeRanges, mSizeRange);
 
 		// Now that we have all the areas, actually assign them
 		UINT32 childIdx = 0;

+ 2 - 1
BansheeEngine/Source/BsGUIScrollArea.cpp

@@ -51,7 +51,8 @@ namespace BansheeEngine
 		mClippedBounds = bounds;
 	}
 
-	void GUIScrollArea::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, const Vector<LayoutSizeRange>& sizeRanges) const
+	void GUIScrollArea::_getElementAreas(INT32 x, INT32 y, UINT32 width, UINT32 height, Rect2I* elementAreas, UINT32 numElements, 
+		const Vector<LayoutSizeRange>& sizeRanges, const LayoutSizeRange& mySizeRange) const
 	{
 		Vector2I visibleSize, contentSize;
 		_getElementAreas(x, y, width, height, elementAreas, numElements, sizeRanges, visibleSize, contentSize);

+ 14 - 12
MBansheeEditor/ColorPicker.cs

@@ -749,12 +749,6 @@ namespace BansheeEditor
 
                 texture = new Texture2D(width, height);
                 spriteTexture = new SpriteTexture(texture);
-
-                Rect2I sliderBounds = guiTexture.Bounds;
-                sliderBounds.y -= SLIDER_HEIGHT;
-                sliderBounds.height += SLIDER_HEIGHT;
-
-                guiSlider.Bounds = sliderBounds;
             }
 
             public void UpdateTexture(Color start, Color step, bool isHSV)
@@ -770,6 +764,13 @@ namespace BansheeEditor
 
                 texture.SetPixels(colors);
                 guiTexture.SetTexture(spriteTexture);
+
+                Rect2I sliderBounds = guiTexture.Bounds;
+                sliderBounds.y -= SLIDER_HEIGHT;
+                sliderBounds.height += SLIDER_HEIGHT;
+
+                Debug.Log("SLIDER BOUNDS HORZ: " + sliderBounds);
+                guiSlider.Bounds = sliderBounds;
             }
         }
 
@@ -793,12 +794,6 @@ namespace BansheeEditor
 
                 texture = new Texture2D(width, height);
                 spriteTexture = new SpriteTexture(texture);
-
-                Rect2I sliderBounds = guiTexture.Bounds;
-                sliderBounds.x -= SLIDER_WIDTH;
-                sliderBounds.width += SLIDER_WIDTH;
-
-                guiSlider.Bounds = sliderBounds;
             }
 
             public void UpdateTexture(Color start, Color step, bool isHSV)
@@ -814,6 +809,13 @@ namespace BansheeEditor
 
                 texture.SetPixels(colors);
                 guiTexture.SetTexture(spriteTexture);
+
+                Rect2I sliderBounds = guiTexture.Bounds;
+                sliderBounds.x -= SLIDER_WIDTH;
+                sliderBounds.width += SLIDER_WIDTH;
+
+                Debug.Log("SLIDER BOUNDS VERT: " + sliderBounds);
+                guiSlider.Bounds = sliderBounds;
             }
         }
 

+ 1 - 1
MBansheeEditor/EditorApplication.cs

@@ -118,7 +118,7 @@ namespace BansheeEditor
             gizmoDbgObject.AddComponent<DbgGizmoComponent>();
 
             //ProgressBar.Show("Test", 0.5f);
-            //ColorPicker.Show();
+            ColorPicker.Show();
 
             // DEBUG ONLY END
         }