2
0
Эх сурвалжийг харах

Added a horizontal scroll bar

Marko Pintera 12 жил өмнө
parent
commit
c0e339108d

+ 2 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -162,6 +162,7 @@
     <ClInclude Include="Include\BsGUILayoutX.h" />
     <ClInclude Include="Include\BsGUILayout.h" />
     <ClInclude Include="Include\BsGUILayoutY.h" />
+    <ClInclude Include="Include\BsGUIScrollBar.h" />
     <ClInclude Include="Include\BsGUIScrollBarHandle.h" />
     <ClInclude Include="Include\BsGUIScrollBarHorz.h" />
     <ClInclude Include="Include\BsGUIScrollBarVert.h" />
@@ -216,6 +217,7 @@
     <ClCompile Include="Source\BsGUIManager.cpp" />
     <ClCompile Include="Source\BsGUIMaterialManager.cpp" />
     <ClCompile Include="Source\BsGUIMouseEvent.cpp" />
+    <ClCompile Include="Source\BsGUIScrollBar.cpp" />
     <ClCompile Include="Source\BsGUIScrollBarHandle.cpp" />
     <ClCompile Include="Source\BsGUIScrollBarHorz.cpp" />
     <ClCompile Include="Source\BsGUIScrollBarVert.cpp" />

+ 6 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -186,6 +186,9 @@
     <ClInclude Include="Include\BsGUIScrollArea.h">
       <Filter>Header Files\GUI</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsGUIScrollBar.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -317,5 +320,8 @@
     <ClCompile Include="Source\BsGUIScrollArea.cpp">
       <Filter>Source Files\GUI</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsGUIScrollBar.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 64 - 0
BansheeEngine/Include/BsGUIScrollBar.h

@@ -0,0 +1,64 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+#include "BsGUIElement.h"
+
+#include "boost/signal.hpp"
+
+namespace BansheeEngine
+{
+	class BS_EXPORT GUIScrollBar : public GUIElement
+	{
+	public:
+		boost::signal<void(float newPosition)> scrollPositionChanged;
+
+		void setHandleSize(CM::UINT32 size);
+		void setScrollPos(float pct);
+
+		CM::UINT32 getMaxHandleSize() const;
+	protected:
+		GUIScrollBar(GUIWidget& parent, bool horizontal, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions);
+		virtual ~GUIScrollBar();
+
+		/**
+		 * @copydoc GUIElement::getNumRenderElements()
+		 */
+		virtual CM::UINT32 getNumRenderElements() const;
+
+		/**
+		 * @copydoc GUIElement::getMaterial()
+		 */
+		virtual const CM::HMaterial& 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::updateRenderElementsInternal()
+		 */
+		virtual void updateRenderElementsInternal();
+
+		virtual CM::UINT32 _getOptimalWidth() const;
+		virtual CM::UINT32 _getOptimalHeight() const;
+
+		virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
+	private:
+		GUILayout* mLayout;
+		ImageSprite* mImageSprite;
+
+		GUIButton* mUpBtn;
+		GUIButton* mDownBtn;
+		GUIScrollBarHandle* mHandleBtn;
+		bool mHorizontal;
+
+		void handleMoved(float handlePct);
+	};
+}

+ 5 - 38
BansheeEngine/Include/BsGUIScrollBarHorz.h

@@ -1,54 +1,21 @@
 #pragma once
 
 #include "BsPrerequisites.h"
-#include "BsGUIElement.h"
+#include "BsGUIScrollBar.h"
+
+#include "boost/signal.hpp"
 
 namespace BansheeEngine
 {
-	class BS_EXPORT GUIScrollBarHorz : public GUIElement
+	class BS_EXPORT GUIScrollBarHorz : public GUIScrollBar
 	{
 	public:
 		static const CM::String& getGUITypeName();
 
 		static GUIScrollBarHorz* create(GUIWidget& parent, const GUIElementStyle* style = nullptr);
 		static GUIScrollBarHorz* create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style = nullptr);
-
-		void setText(const CM::WString& text);
-
 	protected:
-		~GUIScrollBarHorz();
-
-		/**
-		 * @copydoc GUIElement::getNumRenderElements()
-		 */
-		virtual CM::UINT32 getNumRenderElements() const;
-
-		/**
-		 * @copydoc GUIElement::getMaterial()
-		 */
-		virtual const CM::HMaterial& 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::updateRenderElementsInternal()
-		 */
-		virtual void updateRenderElementsInternal();
-
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
-	private:
 		GUIScrollBarHorz(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions);
-
-		GUILayout* mLayout;
+		~GUIScrollBarHorz();
 	};
 }

+ 3 - 51
BansheeEngine/Include/BsGUIScrollBarVert.h

@@ -1,69 +1,21 @@
 #pragma once
 
 #include "BsPrerequisites.h"
-#include "BsGUIElement.h"
+#include "BsGUIScrollBar.h"
 
 #include "boost/signal.hpp"
 
 namespace BansheeEngine
 {
-	class BS_EXPORT GUIScrollBarVert : public GUIElement
+	class BS_EXPORT GUIScrollBarVert : public GUIScrollBar
 	{
 	public:
 		static const CM::String& getGUITypeName();
 
 		static GUIScrollBarVert* create(GUIWidget& parent, const GUIElementStyle* style = nullptr);
 		static GUIScrollBarVert* create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style = nullptr);
-
-		boost::signal<void(float newPosition)> scrollPositionChanged;
-
-		void setHandleSize(CM::UINT32 size);
-		void setScrollPos(float pct);
-
-		CM::UINT32 getMaxHandleSize() const;
 	protected:
-		~GUIScrollBarVert();
-
-		/**
-		 * @copydoc GUIElement::getNumRenderElements()
-		 */
-		virtual CM::UINT32 getNumRenderElements() const;
-
-		/**
-		 * @copydoc GUIElement::getMaterial()
-		 */
-		virtual const CM::HMaterial& 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::updateRenderElementsInternal()
-		 */
-		virtual void updateRenderElementsInternal();
-
-		virtual CM::UINT32 _getOptimalWidth() const;
-		virtual CM::UINT32 _getOptimalHeight() const;
-
-		virtual CM::UINT32 _getRenderElementDepth(CM::UINT32 renderElementIdx) const;
-	private:
 		GUIScrollBarVert(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions);
-
-		GUILayout* mLayout;
-		ImageSprite* mImageSprite;
-
-		GUIButton* mUpBtn;
-		GUIButton* mDownBtn;
-		GUIScrollBarHandle* mHandleBtn;
-
-		void handleMoved(float handlePct);
+		~GUIScrollBarVert();
 	};
 }

+ 127 - 0
BansheeEngine/Source/BsGUIScrollBar.cpp

@@ -0,0 +1,127 @@
+#include "BsGUIScrollBar.h"
+#include "BsGUIElementStyle.h"
+#include "BsGUISkin.h"
+#include "BsGUIWidget.h"
+#include "BsGUILayoutOptions.h"
+#include "BsGUILayout.h"
+#include "BsGUISkin.h"
+#include "BsGUIButton.h"
+#include "BsGUIScrollBarHandle.h"
+#include "BsGUISpace.h"
+#include "CmException.h"
+
+using namespace CamelotFramework;
+
+namespace BansheeEngine
+{
+	GUIScrollBar::GUIScrollBar(GUIWidget& parent, bool horizontal, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
+		:GUIElement(parent, style, layoutOptions), mHorizontal(horizontal)
+	{
+		mImageSprite = cm_new<ImageSprite, PoolAlloc>();
+
+		if(mHorizontal)
+		{
+			mLayout = &addLayoutXInternal();
+
+			mUpBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollLeftBtn"));
+			mDownBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollRightBtn"));
+
+			mHandleBtn = GUIScrollBarHandle::create(parent, mHorizontal, GUILayoutOptions::expandableY(6), parent.getSkin()->getStyle("ScrollBarHorzBtn"));
+		}
+		else
+		{
+			mLayout = &addLayoutYInternal();
+
+			mUpBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollUpBtn"));
+			mDownBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollDownBtn"));
+
+			mHandleBtn = GUIScrollBarHandle::create(parent, mHorizontal, GUILayoutOptions::expandableY(6), parent.getSkin()->getStyle("ScrollBarVertBtn"));
+		}
+
+		mLayout->addSpace(2);
+		mLayout->addElement(mUpBtn);
+		mLayout->addSpace(2);
+		mLayout->addElement(mHandleBtn);
+		mLayout->addSpace(2);
+		mLayout->addElement(mDownBtn);
+		mLayout->addSpace(2);
+
+		mHandleBtn->handleMoved.connect(boost::bind(&GUIScrollBar::handleMoved, this, _1));
+	}
+
+	GUIScrollBar::~GUIScrollBar()
+	{
+		cm_delete<PoolAlloc>(mImageSprite);
+
+		GUIElement::destroy(mUpBtn);
+		GUIElement::destroy(mDownBtn);
+		GUIElement::destroy(mHandleBtn);
+	}
+
+	UINT32 GUIScrollBar::getNumRenderElements() const
+	{
+		return mImageSprite->getNumRenderElements();
+	}
+
+	const HMaterial& GUIScrollBar::getMaterial(UINT32 renderElementIdx) const
+	{
+		return mImageSprite->getMaterial(renderElementIdx);
+	}
+
+	UINT32 GUIScrollBar::getNumQuads(UINT32 renderElementIdx) const
+	{
+		return mImageSprite->getNumQuads(renderElementIdx);
+	}
+
+	void GUIScrollBar::updateRenderElementsInternal()
+	{
+		IMAGE_SPRITE_DESC desc;
+		desc.texture = mStyle->normal.texture;
+		desc.width = mWidth;
+		desc.height = mHeight;
+
+		mImageSprite->update(desc);
+	}
+
+	UINT32 GUIScrollBar::_getOptimalWidth() const
+	{
+		return mLayout->_getOptimalWidth();
+	}
+
+	UINT32 GUIScrollBar::_getOptimalHeight() const
+	{
+		return mLayout->_getOptimalHeight();
+	}
+
+	UINT32 GUIScrollBar::_getRenderElementDepth(UINT32 renderElementIdx) const
+	{
+		return _getDepth() + 2; // + 2 depth because child buttons use +1
+	}
+
+	void GUIScrollBar::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
+		UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
+	{
+		mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx, mOffset, mClipRect);
+	}
+
+	void GUIScrollBar::handleMoved(float handlePct)
+	{
+		if(!scrollPositionChanged.empty())
+			scrollPositionChanged(handlePct);
+	}
+
+	void GUIScrollBar::setHandleSize(UINT32 size)
+	{
+		mHandleBtn->setHandleSize(size);
+	}
+
+	void GUIScrollBar::setScrollPos(float pct)
+	{
+		mHandleBtn->setHandlePos(pct);
+	}
+
+	CM::UINT32 GUIScrollBar::getMaxHandleSize() const
+	{
+		return mHandleBtn->getMaxSize();
+	}
+}

+ 6 - 34
BansheeEngine/Source/BsGUIScrollBarHorz.cpp

@@ -4,6 +4,10 @@
 #include "BsGUIWidget.h"
 #include "BsGUILayoutOptions.h"
 #include "BsGUILayout.h"
+#include "BsGUISkin.h"
+#include "BsGUIButton.h"
+#include "BsGUIScrollBarHandle.h"
+#include "BsGUISpace.h"
 #include "CmException.h"
 
 using namespace CamelotFramework;
@@ -11,48 +15,16 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 {
 	GUIScrollBarHorz::GUIScrollBarHorz(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
-		:GUIElement(parent, style, layoutOptions), mLayout(nullptr)
-	{
-		// TODO - Init mLayout
-	}
-
-	GUIScrollBarHorz::~GUIScrollBarHorz()
+		:GUIScrollBar(parent, true, style, layoutOptions)
 	{
 
 	}
 
-	UINT32 GUIScrollBarHorz::getNumRenderElements() const
-	{
-		return 0;
-	}
-
-	const HMaterial& GUIScrollBarHorz::getMaterial(UINT32 renderElementIdx) const
-	{
-		CM_EXCEPT(InternalErrorException, "Invalid render element index. This class has no render elements.");
-	}
-
-	UINT32 GUIScrollBarHorz::getNumQuads(UINT32 renderElementIdx) const
-	{
-		return 0;
-	}
-
-	void GUIScrollBarHorz::updateRenderElementsInternal()
-	{ }
-
-	UINT32 GUIScrollBarHorz::_getOptimalWidth() const
+	GUIScrollBarHorz::~GUIScrollBarHorz()
 	{
-		return mLayout->_getOptimalWidth();
-	}
 
-	UINT32 GUIScrollBarHorz::_getOptimalHeight() const
-	{
-		return mLayout->_getOptimalHeight();
 	}
 
-	void GUIScrollBarHorz::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
-		UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
-	{ }
-
 	GUIScrollBarHorz* GUIScrollBarHorz::create(GUIWidget& parent, const GUIElementStyle* style)
 	{
 		if(style == nullptr)

+ 1 - 88
BansheeEngine/Source/BsGUIScrollBarVert.cpp

@@ -15,101 +15,14 @@ using namespace CamelotFramework;
 namespace BansheeEngine
 {
 	GUIScrollBarVert::GUIScrollBarVert(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
-		:GUIElement(parent, style, layoutOptions)
+		:GUIScrollBar(parent, false, style, layoutOptions)
 	{
-		mImageSprite = cm_new<ImageSprite, PoolAlloc>();
 
-		mLayout = &addLayoutYInternal();
-
-		mUpBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollUpBtn"));
-		mDownBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollDownBtn"));
-		mHandleBtn = GUIScrollBarHandle::create(parent, false, GUILayoutOptions::expandableY(6), parent.getSkin()->getStyle("ScrollBarVertBtn"));
-
-		mLayout->addSpace(2);
-		mLayout->addElement(mUpBtn);
-		mLayout->addSpace(2);
-		mLayout->addElement(mHandleBtn);
-		mLayout->addSpace(2);
-		mLayout->addElement(mDownBtn);
-		mLayout->addSpace(2);
-
-		mHandleBtn->handleMoved.connect(boost::bind(&GUIScrollBarVert::handleMoved, this, _1));
 	}
 
 	GUIScrollBarVert::~GUIScrollBarVert()
 	{
-		cm_delete<PoolAlloc>(mImageSprite);
-
-		GUIElement::destroy(mUpBtn);
-		GUIElement::destroy(mDownBtn);
-		GUIElement::destroy(mHandleBtn);
-	}
-
-	UINT32 GUIScrollBarVert::getNumRenderElements() const
-	{
-		return mImageSprite->getNumRenderElements();
-	}
-
-	const HMaterial& GUIScrollBarVert::getMaterial(UINT32 renderElementIdx) const
-	{
-		return mImageSprite->getMaterial(renderElementIdx);
-	}
-
-	UINT32 GUIScrollBarVert::getNumQuads(UINT32 renderElementIdx) const
-	{
-		return mImageSprite->getNumQuads(renderElementIdx);
-	}
-
-	void GUIScrollBarVert::updateRenderElementsInternal()
-	{
-		IMAGE_SPRITE_DESC desc;
-		desc.texture = mStyle->normal.texture;
-		desc.width = mWidth;
-		desc.height = mHeight;
-
-		mImageSprite->update(desc);
-	}
-
-	UINT32 GUIScrollBarVert::_getOptimalWidth() const
-	{
-		return mLayout->_getOptimalWidth();
-	}
-
-	UINT32 GUIScrollBarVert::_getOptimalHeight() const
-	{
-		return mLayout->_getOptimalHeight();
-	}
-
-	UINT32 GUIScrollBarVert::_getRenderElementDepth(UINT32 renderElementIdx) const
-	{
-		return _getDepth() + 2; // + 2 depth because child buttons use +1
-	}
-
-	void GUIScrollBarVert::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
-		UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
-	{
-		mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx, mOffset, mClipRect);
-	}
 
-	void GUIScrollBarVert::handleMoved(float handlePct)
-	{
-		if(!scrollPositionChanged.empty())
-			scrollPositionChanged(handlePct);
-	}
-
-	void GUIScrollBarVert::setHandleSize(UINT32 size)
-	{
-		mHandleBtn->setHandleSize(size);
-	}
-
-	void GUIScrollBarVert::setScrollPos(float pct)
-	{
-		mHandleBtn->setHandlePos(pct);
-	}
-
-	CM::UINT32 GUIScrollBarVert::getMaxHandleSize() const
-	{
-		return mHandleBtn->getMaxSize();
 	}
 
 	GUIScrollBarVert* GUIScrollBarVert::create(GUIWidget& parent, const GUIElementStyle* style)

+ 0 - 1
TODO.txt

@@ -34,7 +34,6 @@ IMMEDIATE:
 - When clipping scrolled GUIButton the text doesn't seem to get clipped properly
 - Clicking on the scroll buttons does nothing
 - Clicking on the empty scroll area doesn't do anything
-- Handle size is not dynamic
 - Hover colors of the scroll bar are wrong
 - Add horizontal scrollbar