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

Getting UI working back to normal after GUIArea refactor

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

+ 1 - 0
BansheeEditor/Include/BsGUIMenuBar.h

@@ -30,6 +30,7 @@ namespace BansheeEngine
 		RenderWindow* mParentWindow;
 		GUIWidget* mParentWidget;
 		GUIPanel* mMainPanel;
+		GUIPanel* mBgPanel;
 		GUILayout* mMainLayout;
 		GUITexture* mBgTexture;
 		GUITexture* mLogoTexture;

+ 12 - 2
BansheeEditor/Source/BsGUIMenuBar.cpp

@@ -19,14 +19,18 @@ namespace BansheeEngine
 
 	GUIMenuBar::GUIMenuBar(GUIWidget* parent, RenderWindow* parentWindow)
 		:mParentWidget(parent), mParentWindow(parentWindow), mMainPanel(nullptr), mMainLayout(nullptr),
-		mBgTexture(nullptr), mLogoTexture(nullptr), mSubMenuOpen(false), mSubMenuButton(nullptr)
+		mBgTexture(nullptr), mLogoTexture(nullptr), mSubMenuOpen(false), mSubMenuButton(nullptr), mBgPanel(nullptr)
 	{
 		mMainPanel = parent->getPanel()->addNewElement<GUIPanel>(0);
 		mMainPanel->setWidth(1);
 		mMainPanel->setHeight(13);
 
+		mBgPanel = parent->getPanel()->addNewElement<GUIPanel>(1);
+		mBgPanel->setWidth(1);
+		mBgPanel->setHeight(13);
+
 		mMainLayout = mMainPanel->addNewElement<GUILayoutX>();
-		GUILayoutX* bgLayout = mMainPanel->addNewElement<GUILayoutX>();
+		GUILayoutX* bgLayout = mBgPanel->addNewElement<GUILayoutX>();
 
 		mBgTexture = GUITexture::create(GUIImageScaleMode::StretchToFit, GUIOptions(GUIOption::flexibleWidth(), GUIOption::flexibleHeight()), "MenuBarBg");
 		bgLayout->addElement(mBgTexture);
@@ -67,6 +71,7 @@ namespace BansheeEngine
 		}
 
 		GUILayout::destroy(mMainPanel);
+		GUILayout::destroy(mBgPanel);
 	}
 
 	void GUIMenuBar::setArea(INT32 x, INT32 y, UINT32 width, UINT32 height)
@@ -76,6 +81,11 @@ namespace BansheeEngine
 		mMainPanel->setWidth(width);
 		mMainPanel->setHeight(height);
 
+		mBgPanel->setPosition(x, y);
+
+		mBgPanel->setWidth(width);
+		mBgPanel->setHeight(height);
+
 		refreshNonClientAreas();
 	}
 

+ 44 - 4
BansheeEngine/Source/BsGUIPanel.cpp

@@ -104,10 +104,50 @@ namespace BansheeEngine
 		UINT32 childIdx = 0;
 		for (auto& child : mChildren)
 		{
-			elementAreas[childIdx].x = x + child->_getDimensions().x;
-			elementAreas[childIdx].y = y + child->_getDimensions().y;
-			elementAreas[childIdx].width = (UINT32)sizeRanges[childIdx].optimal.x;
-			elementAreas[childIdx].height = (UINT32)sizeRanges[childIdx].optimal.y;
+			const GUIDimensions& dimensions = child->_getDimensions();
+
+			elementAreas[childIdx].x = x + dimensions.x;
+			elementAreas[childIdx].y = y + dimensions.y;
+
+			if (dimensions.fixedWidth())
+				elementAreas[childIdx].width = (UINT32)sizeRanges[childIdx].optimal.x;
+			else
+			{
+				UINT32 modifiedWidth = (UINT32)std::max(0, (INT32)width - dimensions.x);
+				
+				if (modifiedWidth > (UINT32)sizeRanges[childIdx].optimal.x)
+				{
+					if (dimensions.maxWidth > 0)
+						modifiedWidth = std::min(modifiedWidth, dimensions.maxWidth);
+				}
+				else if (modifiedWidth < (UINT32)sizeRanges[childIdx].optimal.x)
+				{
+					if (dimensions.minWidth > 0)
+						modifiedWidth = std::max(modifiedWidth, dimensions.minWidth);
+				}
+
+				elementAreas[childIdx].width = modifiedWidth;
+			}
+
+			if (dimensions.fixedHeight())
+				elementAreas[childIdx].height = (UINT32)sizeRanges[childIdx].optimal.y;
+			else
+			{
+				UINT32 modifiedHeight = (UINT32)std::max(0, (INT32)height - dimensions.y);
+
+				if (modifiedHeight > (UINT32)sizeRanges[childIdx].optimal.y)
+				{
+					if (dimensions.maxHeight > 0)
+						modifiedHeight = std::min(modifiedHeight, dimensions.maxHeight);
+				}
+				else if (modifiedHeight < (UINT32)sizeRanges[childIdx].optimal.y)
+				{
+					if (dimensions.minHeight > 0)
+						modifiedHeight = std::max(modifiedHeight, dimensions.minHeight);
+				}
+
+				elementAreas[childIdx].height = modifiedHeight;
+			}
 
 			childIdx++;
 		}

+ 1 - 0
BansheeEngine/Source/BsGUIWidget.cpp

@@ -36,6 +36,7 @@ namespace BansheeEngine
 		GUIManager::instance().registerWidget(this);
 
 		mPanel = GUIPanel::create();
+		mPanel->_changeParentWidget(this);
 	}
 
 	GUIWidget::~GUIWidget()

+ 2 - 1
MBansheeEditor/ColorPicker.cs

@@ -148,7 +148,8 @@ namespace BansheeEditor
             guiOK.OnClick += OnOK;
             guiCancel.OnClick += OnCancel;
 
-            GUILayout v0 = GUI.AddLayoutY();
+            GUIPanel mainPanel = GUI.AddPanel(0);
+            GUILayout v0 = mainPanel.AddLayoutY();
 
             v0.AddSpace(5);