Explorar o código

Title bar tab buttons now toggle properly

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

+ 1 - 1
BansheeEngine/Include/BsGUIToggle.h

@@ -43,7 +43,7 @@ namespace BansheeEngine
 
 		virtual bool mouseEvent(const GUIMouseEvent& ev);
 
-	private:
+	protected:
 		std::shared_ptr<GUIToggleGroup> mToggleGroup;
 		bool mIsToggled;
 	};

+ 1 - 0
BansheeEngine/Include/BsPrerequisites.h

@@ -79,6 +79,7 @@ namespace BansheeEngine
 	typedef std::shared_ptr<Overlay> OverlayPtr;
 	typedef std::shared_ptr<Camera> CameraPtr;
 	typedef std::shared_ptr<Renderable> RenderablePtr;
+	typedef std::shared_ptr<GUIToggleGroup> GUIToggleGroupPtr;
 
 	typedef CM::GameObjectHandle<GUIWidget> HGUIWidget;
 	typedef CM::GameObjectHandle<Camera> HCamera;

+ 5 - 6
CamelotClient/Include/BsGUITabButton.h

@@ -13,11 +13,11 @@ namespace BansheeEditor
 	public:
 		static const CM::String& getGUITypeName();
 
-		static GUITabButton* create(BS::GUIWidget& parent, GUITabbedTitleBar* titleBar, CM::UINT32 index, const CM::HString& text, const BS::GUIElementStyle* style = nullptr);
-		static GUITabButton* create(BS::GUIWidget& parent, const BS::GUIOptions& layoutOptions, GUITabbedTitleBar* titleBar, CM::UINT32 index, const CM::HString& text, const BS::GUIElementStyle* style = nullptr);
+		static GUITabButton* create(BS::GUIWidget& parent, const BS::GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const CM::HString& text, const BS::GUIElementStyle* style = nullptr);
+		static GUITabButton* create(BS::GUIWidget& parent, const BS::GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const CM::HString& text, const BS::GUIOptions& layoutOptions, const BS::GUIElementStyle* style = nullptr);
 	
-		static GUITabButton* create(BS::GUIWidget& parent, GUITabbedTitleBar* titleBar, CM::UINT32 index, const BS::GUIContent& content, const BS::GUIElementStyle* style = nullptr);
-		static GUITabButton* create(BS::GUIWidget& parent, const BS::GUIOptions& layoutOptions, GUITabbedTitleBar* titleBar, CM::UINT32 index, const BS::GUIContent& content, const BS::GUIElementStyle* style = nullptr);
+		static GUITabButton* create(BS::GUIWidget& parent, const BS::GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const BS::GUIContent& content, const BS::GUIElementStyle* style = nullptr);
+		static GUITabButton* create(BS::GUIWidget& parent, const BS::GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const BS::GUIContent& content, const BS::GUIOptions& layoutOptions, const BS::GUIElementStyle* style = nullptr);
 
 		CM::UINT32 getIndex() const { return mIndex; }
 
@@ -27,12 +27,11 @@ namespace BansheeEditor
 		virtual bool mouseEvent(const BS::GUIMouseEvent& ev);
 
 	private:
-		GUITabbedTitleBar* mTitleBar;
 		CM::UINT32 mIndex;
 		CM::Vector2I mDragStartPosition;
 
 		static const CM::UINT32 DRAG_MIN_DISTANCE;
 
-		GUITabButton(BS::GUIWidget& parent, const BS::GUIElementStyle* style, GUITabbedTitleBar* titleBar, CM::UINT32 index, const BS::GUIContent& content, const BS::GUILayoutOptions& layoutOptions);
+		GUITabButton(BS::GUIWidget& parent, const BS::GUIElementStyle* style, const BS::GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const BS::GUIContent& content, const BS::GUILayoutOptions& layoutOptions);
 	};
 }

+ 1 - 0
CamelotClient/Include/BsGUITabbedTitleBar.h

@@ -35,6 +35,7 @@ namespace BansheeEditor
 		BS::GUIArea* mBackgroundArea;
 		BS::GUIButton* mMinBtn;
 		BS::GUIButton* mCloseBtn;
+		BS::GUIToggleGroupPtr mTabToggleGroup;
 		CM::RenderWindow* mParentWindow;
 		CM::RectI mArea;
 

+ 23 - 12
CamelotClient/Source/BsGUITabButton.cpp

@@ -18,13 +18,13 @@ namespace BansheeEditor
 		return name;
 	}
 
-	GUITabButton::GUITabButton(GUIWidget& parent, const GUIElementStyle* style, GUITabbedTitleBar* titleBar, CM::UINT32 index, const GUIContent& content, const GUILayoutOptions& layoutOptions)
-		:GUIToggle(parent, style, content, nullptr, layoutOptions), mTitleBar(titleBar), mIndex(index)
+	GUITabButton::GUITabButton(GUIWidget& parent, const GUIElementStyle* style, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const GUIContent& content, const GUILayoutOptions& layoutOptions)
+		:GUIToggle(parent, style, content, toggleGroup, layoutOptions), mIndex(index)
 	{
 
 	}
 
-	GUITabButton* GUITabButton::create(GUIWidget& parent, GUITabbedTitleBar* titleBar, CM::UINT32 index, const HString& text, const GUIElementStyle* style)
+	GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const HString& text, const GUIElementStyle* style)
 	{
 		if(style == nullptr)
 		{
@@ -32,10 +32,10 @@ namespace BansheeEditor
 			style = skin.getStyle(getGUITypeName());
 		}
 
-		return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, titleBar, index, GUIContent(text), GUILayoutOptions::create(style));
+		return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, toggleGroup, index, GUIContent(text), GUILayoutOptions::create(style));
 	}
 
-	GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIOptions& layoutOptions, GUITabbedTitleBar* titleBar, CM::UINT32 index, const HString& text, const GUIElementStyle* style)
+	GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const HString& text, const GUIOptions& layoutOptions, const GUIElementStyle* style)
 	{
 		if(style == nullptr)
 		{
@@ -43,10 +43,10 @@ namespace BansheeEditor
 			style = skin.getStyle(getGUITypeName());
 		}
 
-		return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, titleBar, index, GUIContent(text), GUILayoutOptions::create(layoutOptions, style));
+		return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, toggleGroup, index, GUIContent(text), GUILayoutOptions::create(layoutOptions, style));
 	}
 
-	GUITabButton* GUITabButton::create(GUIWidget& parent, GUITabbedTitleBar* titleBar, CM::UINT32 index, const GUIContent& content, const GUIElementStyle* style)
+	GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const GUIContent& content, const GUIElementStyle* style)
 	{
 		if(style == nullptr)
 		{
@@ -54,10 +54,10 @@ namespace BansheeEditor
 			style = skin.getStyle(getGUITypeName());
 		}
 
-		return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, titleBar, index, content, GUILayoutOptions::create(style));
+		return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, toggleGroup, index, content, GUILayoutOptions::create(style));
 	}
 
-	GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIOptions& layoutOptions, GUITabbedTitleBar* titleBar, CM::UINT32 index, const GUIContent& content, const GUIElementStyle* style)
+	GUITabButton* GUITabButton::create(GUIWidget& parent, const GUIToggleGroupPtr& toggleGroup, CM::UINT32 index, const GUIContent& content, const GUIOptions& layoutOptions, const GUIElementStyle* style)
 	{
 		if(style == nullptr)
 		{
@@ -65,14 +65,21 @@ namespace BansheeEditor
 			style = skin.getStyle(getGUITypeName());
 		}
 
-		return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, titleBar, index, content, GUILayoutOptions::create(layoutOptions, style));
+		return new (cm_alloc<GUITabButton, PoolAlloc>()) GUITabButton(parent, style, toggleGroup, index, content, GUILayoutOptions::create(layoutOptions, style));
 	}
 
 	bool GUITabButton::mouseEvent(const GUIMouseEvent& ev)
 	{
-		bool eventProcessed = GUIToggle::mouseEvent(ev);
+		bool eventProcessed = GUIButtonBase::mouseEvent(ev);
 
-		if(ev.getType() == GUIMouseEventType::MouseDragStart)
+		if(ev.getType() == GUIMouseEventType::MouseUp)
+		{
+			if(!mIsToggled)
+				toggleOn();
+
+			return true;
+		}
+		else if(ev.getType() == GUIMouseEventType::MouseDragStart)
 		{
 			mDragStartPosition = ev.getPosition();
 
@@ -87,6 +94,8 @@ namespace BansheeEditor
 				if(!onDragged.empty())
 					onDragged(mIndex, ev.getPosition());
 			}
+
+			return true;
 		}
 		else if(ev.getType() == GUIMouseEventType::MouseDragEnd)
 		{
@@ -97,6 +106,8 @@ namespace BansheeEditor
 				if(!onDragEnd.empty())
 					onDragEnd(mIndex, ev.getPosition());
 			}
+
+			return true;
 		}
 
 		return eventProcessed;

+ 3 - 1
CamelotClient/Source/BsGUITabbedTitleBar.cpp

@@ -37,6 +37,8 @@ namespace BansheeEditor
 		mCloseBtn = GUIButton::create(*parent, HString(L""), mCloseBtnStyle);
 
 		mCloseBtn->onClick.connect(boost::bind(&GUITabbedTitleBar::tabClosed, this));
+
+		mTabToggleGroup = GUIToggle::createToggleGroup();
 	}
 
 	GUITabbedTitleBar::~GUITabbedTitleBar()
@@ -59,7 +61,7 @@ namespace BansheeEditor
 
 	void GUITabbedTitleBar::insertTab(UINT32 idx, const CM::HString& name)
 	{
-		GUITabButton* newTabToggle = GUITabButton::create(*mParentWidget, this, mUniqueTabIdx, name, EngineGUI::instance().getSkin().getStyle("TabbedBarBtn"));
+		GUITabButton* newTabToggle = GUITabButton::create(*mParentWidget, mTabToggleGroup, mUniqueTabIdx, name, EngineGUI::instance().getSkin().getStyle("TabbedBarBtn"));
 
 		idx = Math::clamp(idx, 0U, (UINT32)mTabButtons.size());