ソースを参照

Added a background to the scroll bar

Marko Pintera 12 年 前
コミット
1cbedb412a

+ 2 - 0
BansheeEngine/Include/BsEngineGUI.h

@@ -66,5 +66,7 @@ namespace BansheeEngine
 		static const CM::String ScrollBarHandleVertNormalTex;
 		static const CM::String ScrollBarHandleVertHoverTex;
 		static const CM::String ScrollBarHandleVertActiveTex;
+
+		static const CM::String ScrollBarBgTex;
 	};
 }

+ 3 - 2
BansheeEngine/Include/BsGUIScrollBarVert.h

@@ -13,8 +13,6 @@ namespace BansheeEngine
 		static GUIScrollBarVert* create(GUIWidget& parent, const GUIElementStyle* style = nullptr);
 		static GUIScrollBarVert* create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style = nullptr);
 
-		void setText(const CM::WString& text);
-
 	protected:
 		~GUIScrollBarVert();
 
@@ -46,9 +44,12 @@ namespace BansheeEngine
 
 		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;
 	};
 }

+ 11 - 0
BansheeEngine/Source/BsEngineGUI.cpp

@@ -66,6 +66,8 @@ namespace BansheeEngine
 	const String EngineGUI::ScrollBarHandleVertHoverTex = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\ScrollBarVertHandleHover.psd";
 	const String EngineGUI::ScrollBarHandleVertActiveTex = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\ScrollBarVertHandleActive.psd";
 
+	const String EngineGUI::ScrollBarBgTex = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\ScrollBarBg.psd";
+
 	EngineGUI::EngineGUI()
 	{
 		// TODO - Normally I want to load this from some file
@@ -349,8 +351,14 @@ namespace BansheeEngine
 
 		mSkin.setStyle("ScrollBarVertBtn", scrollBarVertBtnStyle);
 
+		HTexture scrollBarBg = static_resource_cast<Texture>(Importer::instance().import(ScrollBarBgTex));
+		SpriteTexturePtr scrollBarBgPtr = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(scrollBarBg));
+
 		// Vertical scroll bar
 		GUIElementStyle vertScrollBarStyle;
+		vertScrollBarStyle.normal.texture = scrollBarBgPtr;
+		vertScrollBarStyle.hover.texture = scrollBarBgPtr;
+		vertScrollBarStyle.active.texture = scrollBarBgPtr;
 		vertScrollBarStyle.fixedHeight = false;
 		vertScrollBarStyle.fixedWidth = true;
 		vertScrollBarStyle.minHeight = 16;
@@ -360,6 +368,9 @@ namespace BansheeEngine
 
 		// Horizontal scroll bar
 		GUIElementStyle horzScrollBarStyle;
+		horzScrollBarStyle.normal.texture = scrollBarBgPtr;
+		horzScrollBarStyle.hover.texture = scrollBarBgPtr;
+		horzScrollBarStyle.active.texture = scrollBarBgPtr;
 		horzScrollBarStyle.fixedHeight = true;
 		horzScrollBarStyle.fixedWidth = false;
 		horzScrollBarStyle.minWidth = 16;

+ 24 - 6
BansheeEngine/Source/BsGUIScrollBarVert.cpp

@@ -16,41 +16,52 @@ namespace BansheeEngine
 	GUIScrollBarVert::GUIScrollBarVert(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
 		:GUIElement(parent, style, layoutOptions), mLayout(nullptr)
 	{
+		mImageSprite = cm_new<ImageSprite, PoolAlloc>();
+
 		mLayout = &addLayoutYInternal();
 
 		GUIButton* upBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollUpBtn"));
 		GUIButton* downBtn = GUIButton::create(parent, L"", parent.getSkin()->getStyle("ScrollDownBtn"));
 		GUIButton* handleBtn = GUIButton::create(parent, L"", GUILayoutOptions::expandableY(6), parent.getSkin()->getStyle("ScrollBarVertBtn"));
 
+		mLayout->addSpace(2);
 		mLayout->addElement(upBtn);
 		mLayout->addSpace(2);
 		mLayout->addElement(handleBtn); // We might want a special element for this?
 		mLayout->addSpace(2);
 		mLayout->addElement(downBtn);
+		mLayout->addSpace(2);
 	}
 
 	GUIScrollBarVert::~GUIScrollBarVert()
 	{
-
+		cm_delete<PoolAlloc>(mImageSprite);
 	}
 
 	UINT32 GUIScrollBarVert::getNumRenderElements() const
 	{
-		return 0;
+		return mImageSprite->getNumRenderElements();
 	}
 
 	const HMaterial& GUIScrollBarVert::getMaterial(UINT32 renderElementIdx) const
 	{
-		CM_EXCEPT(InternalErrorException, "Invalid render element index. This class has no render elements.");
+		return mImageSprite->getMaterial(renderElementIdx);
 	}
 
 	UINT32 GUIScrollBarVert::getNumQuads(UINT32 renderElementIdx) const
 	{
-		return 0;
+		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
 	{
@@ -62,9 +73,16 @@ namespace BansheeEngine
 		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);
+	}
 
 	GUIScrollBarVert* GUIScrollBarVert::create(GUIWidget& parent, const GUIElementStyle* style)
 	{

+ 1 - 1
CamelotClient/CmEditorWindow.cpp

@@ -66,7 +66,7 @@ namespace BansheeEditor
 
 		//// DEBUG
 		
-		GUIArea* dbgArea = GUIArea::createStretchedXY(*mGUI, 5, 5, 14, 2, 475);
+		GUIArea* dbgArea = GUIArea::createStretchedXY(*mGUI, 1, 1, 14, 2, 475);
 		GUILayout& layout = dbgArea->getLayout();
 		//
 		//mDbgLabel = GUILabel::create(*mGUI, "Testing test");

+ 0 - 1
TODO.txt

@@ -26,7 +26,6 @@ IMMEDIATE:
 	- SpriteTexture keeps a static reference to DUmmyTexture which I need to release before shutdown
 
 - Hover colors of the scroll bar are wrong
-- GUIArea needs a margin, so it can still be resized with window but always with an offset
 - Scroll bar background
 - Add horizontal scrollbar
 - Resizable scroll handle (Special element)