Explorar o código

Added GUIElementContainer so I can more easily make container GUI elements
Moved GUITabbedTitleBar so it derives from GUIElementContainer

Marko Pintera %!s(int64=12) %!d(string=hai) anos
pai
achega
648ecc40e6

+ 2 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -241,6 +241,7 @@
     <ClInclude Include="Include\BsDebugDrawMaterialInfo.h" />
     <ClInclude Include="Include\BsGUIDropDownBox.h" />
     <ClInclude Include="Include\BsGUIDropDownBoxManager.h" />
+    <ClInclude Include="Include\BsGUIElementContainer.h" />
     <ClInclude Include="Include\BsGUIHelper.h" />
     <ClInclude Include="Include\BsGUIListBox.h" />
     <ClInclude Include="Include\BsGUIElementBase.h" />
@@ -310,6 +311,7 @@
     <ClCompile Include="Source\BsGUIContent.cpp" />
     <ClCompile Include="Source\BsGUIDropDownBox.cpp" />
     <ClCompile Include="Source\BsGUIDropDownBoxManager.cpp" />
+    <ClCompile Include="Source\BsGUIElementContainer.cpp" />
     <ClCompile Include="Source\BsGUIHelper.cpp" />
     <ClCompile Include="Source\BsGUILayoutOptions.cpp" />
     <ClCompile Include="Source\BsGUIListBox.cpp" />

+ 6 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -249,6 +249,9 @@
     <ClInclude Include="Include\BsSpriteTextureRTTI.h">
       <Filter>Header Files\RTTI</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsGUIElementContainer.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -431,5 +434,8 @@
     <ClCompile Include="Source\BsScriptManager.cpp">
       <Filter>Source Files\Script</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsGUIElementContainer.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 46 - 0
BansheeEngine/Include/BsGUIElementContainer.h

@@ -0,0 +1,46 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+#include "BsGUIElement.h"
+
+namespace BansheeEngine
+{
+	class BS_EXPORT GUIElementContainer : public BS::GUIElement
+	{
+	protected:
+		GUIElementContainer(BS::GUIWidget& parent, const BS::GUILayoutOptions& layoutOptions);
+		virtual ~GUIElementContainer();
+
+		/**
+		 * @copydoc GUIElement::getNumRenderElements()
+		 */
+		virtual CM::UINT32 getNumRenderElements() const;
+
+		/**
+		 * @copydoc GUIElement::getMaterial()
+		 */
+		virtual const BS::GUIMaterialInfo& getMaterial(CM::UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::getNumQuads()
+		 */
+		virtual CM::UINT32 getNumQuads(CM::UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::fillBuffer()
+		 */
+		virtual void fillBuffer(CM::UINT8* vertices, CM::UINT8* uv, CM::UINT32* indices, CM::UINT32 startingQuad, 
+			CM::UINT32 maxNumQuads, CM::UINT32 vertexStride, CM::UINT32 indexStride, CM::UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::updateBounds()
+		 */
+		virtual void updateClippedBounds();
+
+		virtual CM::Vector2I _getOptimalSize() const;
+		void _changeParentWidget(BS::GUIWidget* widget);
+
+		virtual CM::UINT32 getNumChildElements() const = 0;
+		virtual GUIElement* getChildElement(CM::UINT32 idx) const = 0;
+	};
+}

+ 52 - 0
BansheeEngine/Source/BsGUIElementContainer.cpp

@@ -0,0 +1,52 @@
+#include "BsGUIElementContainer.h"
+#include "BsGUISkin.h"
+
+using namespace CamelotFramework;
+using namespace BansheeEngine;
+
+namespace BansheeEngine
+{
+	GUIElementContainer::GUIElementContainer(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
+		:GUIElement(parent, &GUISkin::DefaultStyle, layoutOptions, false)
+	{ }
+
+	GUIElementContainer::~GUIElementContainer()
+	{ }
+
+	UINT32 GUIElementContainer::getNumRenderElements() const
+	{
+		return 0;
+	}
+
+	const GUIMaterialInfo& GUIElementContainer::getMaterial(UINT32 renderElementIdx) const
+	{
+		CM_EXCEPT(InvalidStateException, "Trying to retrieve a material from an element with no render elements.");
+	}
+
+	UINT32 GUIElementContainer::getNumQuads(UINT32 renderElementIdx) const
+	{
+		return 0;
+	}
+
+	void GUIElementContainer::updateClippedBounds()
+	{
+		mClippedBounds = RectI(0, 0, 0, 0); // We don't want any mouse input for this element. This is just a container.
+	}
+
+	void GUIElementContainer::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
+		UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
+	{ }
+
+	Vector2I GUIElementContainer::_getOptimalSize() const
+	{
+		return Vector2I();
+	}
+
+	void GUIElementContainer::_changeParentWidget(GUIWidget* widget)
+	{
+		GUIElement::_changeParentWidget(widget);
+
+		for(UINT32 i = 0; i < getNumChildElements(); i++)
+			getChildElement(i)->_changeParentWidget(widget);
+	}
+}

+ 4 - 30
CamelotClient/Include/BsGUITabbedTitleBar.h

@@ -1,13 +1,13 @@
 #pragma once
 
 #include "BsEditorPrerequisites.h"
-#include "BsGUIElement.h"
+#include "BsGUIElementContainer.h"
 #include "CmRectI.h"
 #include <boost/signal.hpp>
 
 namespace BansheeEditor
 {
-	class GUITabbedTitleBar : public BS::GUIElement
+	class GUITabbedTitleBar : public BS::GUIElementContainer
 	{
 	public:
 		static const CM::String& getGUITypeName();
@@ -33,32 +33,6 @@ namespace BansheeEditor
 	protected:
 		virtual ~GUITabbedTitleBar();
 
-		/**
-		 * @copydoc GUIElement::getNumRenderElements()
-		 */
-		virtual CM::UINT32 getNumRenderElements() const;
-
-		/**
-		 * @copydoc GUIElement::getMaterial()
-		 */
-		virtual const BS::GUIMaterialInfo& getMaterial(CM::UINT32 renderElementIdx) const;
-
-		/**
-		 * @copydoc GUIElement::getNumQuads()
-		 */
-		virtual CM::UINT32 getNumQuads(CM::UINT32 renderElementIdx) const;
-
-		/**
-		 * @copydoc GUIElement::fillBuffer()
-		 */
-		virtual void fillBuffer(CM::UINT8* vertices, CM::UINT8* uv, CM::UINT32* indices, CM::UINT32 startingQuad, 
-			CM::UINT32 maxNumQuads, CM::UINT32 vertexStride, CM::UINT32 indexStride, CM::UINT32 renderElementIdx) const;
-
-		/**
-		 * @copydoc GUIElement::updateBounds()
-		 */
-		virtual void updateClippedBounds();
-
 		void _updateLayoutInternal(CM::INT32 x, CM::INT32 y, CM::UINT32 width, CM::UINT32 height,
 			CM::RectI clipRect, CM::UINT8 widgetDepth, CM::UINT16 areaDepth);
 	protected:
@@ -90,8 +64,8 @@ namespace BansheeEditor
 			BS::GUIElementStyle* minBtnStyle, BS::GUIElementStyle* closeBtnStyle, const BS::GUILayoutOptions& layoutOptions);
 
 		virtual bool mouseEvent(const BS::GUIMouseEvent& ev);
-		virtual CM::Vector2I _getOptimalSize() const;
-		void _changeParentWidget(BS::GUIWidget* widget);
+		virtual CM::UINT32 getNumChildElements() const;
+		virtual GUIElement* getChildElement(CM::UINT32 idx) const;
 
 		void tabToggled(CM::UINT32 tabIdx);
 		void tabClosed();

+ 15 - 45
CamelotClient/Source/BsGUITabbedTitleBar.cpp

@@ -21,7 +21,7 @@ namespace BansheeEditor
 
 	GUITabbedTitleBar::GUITabbedTitleBar(GUIWidget& parent, RenderWindow* parentWindow, GUIElementStyle* backgroundStyle, GUIElementStyle* tabBtnStyle, 
 		GUIElementStyle* minBtnStyle, GUIElementStyle* closeBtnStyle, const GUILayoutOptions& layoutOptions)
-		:GUIElement(parent, &GUISkin::DefaultStyle, layoutOptions, false), mParentWindow(parentWindow), mMinBtn(nullptr), 
+		:GUIElementContainer(parent, layoutOptions), mParentWindow(parentWindow), mMinBtn(nullptr), 
 		mCloseBtn(nullptr), mParentWidget(&parent), mBackgroundImage(nullptr), mUniqueTabIdx(0), mActiveTabIdx(0),
 		mDragInProgress(false), mDraggedBtn(nullptr), mDragBtnOffset(0), mInitialDragOffset(0), mBackgroundStyle(backgroundStyle),
 		mTabBtnStyle(tabBtnStyle), mMinimizeBtnStyle(minBtnStyle), mCloseBtnStyle(closeBtnStyle)
@@ -49,15 +49,8 @@ namespace BansheeEditor
 
 	GUITabbedTitleBar::~GUITabbedTitleBar()
 	{
-		GUIElement::destroy(mBackgroundImage);
-
-		GUIElement::destroy(mMinBtn);
-		GUIElement::destroy(mCloseBtn);
-
-		for(auto& tabButton : mTabButtons)
-		{
-			GUIElement::destroy(tabButton);
-		}
+		for(UINT32 i = 0; i < getNumChildElements(); i++)
+			GUIElement::destroy(getChildElement(i));
 	}
 
 	GUITabbedTitleBar* GUITabbedTitleBar::create(GUIWidget& parent, RenderWindow* parentWindow, GUIElementStyle* backgroundStyle, 
@@ -112,30 +105,6 @@ namespace BansheeEditor
 		mTabButtons.erase(mTabButtons.begin() + idx);
 	}
 
-	UINT32 GUITabbedTitleBar::getNumRenderElements() const
-	{
-		return 0;
-	}
-
-	const GUIMaterialInfo& GUITabbedTitleBar::getMaterial(UINT32 renderElementIdx) const
-	{
-		CM_EXCEPT(InvalidStateException, "Trying to retrieve a material from an element with no render elements.");
-	}
-
-	UINT32 GUITabbedTitleBar::getNumQuads(UINT32 renderElementIdx) const
-	{
-		return 0;
-	}
-
-	void GUITabbedTitleBar::updateClippedBounds()
-	{
-		mClippedBounds = RectI(0, 0, 0, 0); // We don't want any mouse input for this element. This is just a container.
-	}
-
-	void GUITabbedTitleBar::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
-		UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
-	{ }
-
 	bool GUITabbedTitleBar::mouseEvent(const GUIMouseEvent& ev)
 	{
 		// TODO
@@ -143,23 +112,24 @@ namespace BansheeEditor
 		return false;
 	}
 
-	Vector2I GUITabbedTitleBar::_getOptimalSize() const
+	UINT32 GUITabbedTitleBar::getNumChildElements() const
 	{
-		return Vector2I();
+		return 3 + (UINT32)mTabButtons.size();
 	}
 
-	void GUITabbedTitleBar::_changeParentWidget(GUIWidget* widget)
+	GUIElement* GUITabbedTitleBar::getChildElement(CM::UINT32 idx) const
 	{
-		GUIElement::_changeParentWidget(widget);
-
-		mBackgroundImage->_changeParentWidget(widget);
-		mMinBtn->_changeParentWidget(widget);
-		mCloseBtn->_changeParentWidget(widget);
-
-		for(auto& tabButton : mTabButtons)
+		switch (idx)
 		{
-			tabButton->_changeParentWidget(widget);
+		case 0:
+			return mBackgroundImage;
+		case 1:
+			return mMinBtn;
+		case 2:
+			return mCloseBtn;
 		}
+
+		return mTabButtons[idx - 3];
 	}
 
 	void GUITabbedTitleBar::_updateLayoutInternal(INT32 x, INT32 y, UINT32 width, UINT32 height,

+ 1 - 10
EditorWindowDock.txt

@@ -1,24 +1,15 @@
 TODO:
  - Add GUIElementContainer, a class that does no rendering but contains other GUIElements. Use it for GUIScrolArea, GUITabbedTitleBar and GUIDockManager
- - DO NOT make EditorWidgetContainer a GUIElement. Instead refactor _updateLayoutInternal in GUITabbedTitleBar into "updateLayout" and make it do all the work EditorWidgetContainer does now
- - Docking/Undocking elements will cause an exception. Happened after TabbedTitleBar refactor
- - When I dock two windows (maybe even just one?) and drag the title bar, layout seems to get messed up
- - Ensure that dragging items onto the title bar works
+ - Change DockManager into a GUIElement
 
 Resize sliders
  - Add a button between docked windows
  - Allow the button to be dragged, and it will automatically resize separating widgets
 
 TitleBar dock/undock 
- - Releasing the dragged window over the drop overlay will dock the window
  - Moving the dragged window over a title bar will temporarily dock the title bar and allow you to move it (as in first step)
    - If you release the mouse the window will then be permanently docked at that location
 
-CONSIDER getting rid of mouse event filters for DockManager
- - I can probably convert DockManager into a GUIElement?
-   - EditorWidgetContainer as well!
-      - Make sure to update GUITabbedTitleBar::tabDragEnd when I do convert it to GUIElement
-
 Polish TOOD:
  - Change cursor icon when window is dragged
  - Prevent docking if available size is less than 20 pixels, otherwise there might be some weirdness