Przeglądaj źródła

Added a fill bar to GUI slider
New UI for GUI slider

BearishSun 10 lat temu
rodzic
commit
dbc70baf59

+ 8 - 0
BansheeEditor/Include/BsBuiltinEditorResources.h

@@ -254,6 +254,14 @@ namespace BansheeEngine
 		static const WString ObjectClearBtnHoverTex;
 		static const WString ObjectClearBtnActiveTex;
 
+		static const WString SliderHBackgroundTex;
+		static const WString SliderHFillTex;
+		static const WString SliderVBackgroundTex;
+		static const WString SliderVFillTex;
+		static const WString SliderHandleNormalTex;
+		static const WString SliderHandleHoverTex;
+		static const WString SliderHandleActiveTex;
+
 		static const WString FoldoutOpenNormalTex;
 		static const WString FoldoutOpenHoverTex;
 		static const WString FoldoutClosedNormalTex;

+ 84 - 3
BansheeEditor/Source/BsBuiltinEditorResources.cpp

@@ -131,6 +131,14 @@ namespace BansheeEngine
 	const WString BuiltinEditorResources::DropDownBtnHoverTex = L"DropDownButtonHover.png";
 	const WString BuiltinEditorResources::DropDownBtnActiveTex = L"DropDownButtonActive.png";
 
+	const WString BuiltinEditorResources::SliderHBackgroundTex = L"SliderHBackground.png";
+	const WString BuiltinEditorResources::SliderHFillTex = L"SliderHFill.png";
+	const WString BuiltinEditorResources::SliderVBackgroundTex = L"SliderVBackground.png";
+	const WString BuiltinEditorResources::SliderVFillTex = L"SliderVFill.png";
+	const WString BuiltinEditorResources::SliderHandleNormalTex = L"SliderHandleNormal.png";
+	const WString BuiltinEditorResources::SliderHandleHoverTex = L"SliderHandleHover.png";
+	const WString BuiltinEditorResources::SliderHandleActiveTex = L"SliderHandleActive.png";
+
 	const WString BuiltinEditorResources::FoldoutOpenNormalTex = L"FoldoutOpenNormal.psd";
 	const WString BuiltinEditorResources::FoldoutOpenHoverTex = L"FoldoutOpenHover.psd";
 	const WString BuiltinEditorResources::FoldoutClosedNormalTex = L"FoldoutClosedNormal.psd";
@@ -1467,6 +1475,79 @@ namespace BansheeEngine
 
 		skin->setStyle(GUIProgressBar::getGUITypeName(), progressBarStyle);
 
+		/************************************************************************/
+		/* 								SLIDER                      			*/
+		/************************************************************************/
+
+		GUIElementStyle sliderHandleStyle;
+		sliderHandleStyle.fixedHeight = true;
+		sliderHandleStyle.fixedWidth = true;
+		sliderHandleStyle.width = 12;
+		sliderHandleStyle.height = 13;
+		sliderHandleStyle.normal.texture = getGUITexture(SliderHandleNormalTex);
+		sliderHandleStyle.hover.texture = getGUITexture(SliderHandleHoverTex);
+		sliderHandleStyle.active.texture = getGUITexture(SliderHandleActiveTex);
+
+		skin->setStyle(GUISlider::getHandleStyleType(), sliderHandleStyle);
+
+		GUIElementStyle sliderHorizontalBgStyle;
+		sliderHorizontalBgStyle.fixedHeight = true;
+		sliderHorizontalBgStyle.height = 10;
+		sliderHorizontalBgStyle.normal.texture = getGUITexture(SliderHBackgroundTex);
+		sliderHorizontalBgStyle.border.left = 4;
+		sliderHorizontalBgStyle.border.right = 4;
+
+		skin->setStyle("SliderHorzBg", sliderHorizontalBgStyle);
+
+		GUIElementStyle sliderHorizontalFillStyle;
+		sliderHorizontalFillStyle.fixedHeight = true;
+		sliderHorizontalFillStyle.height = 10;
+		sliderHorizontalFillStyle.normal.texture = getGUITexture(SliderHFillTex);
+		sliderHorizontalFillStyle.border.left = 6;
+		sliderHorizontalFillStyle.border.right = 4;
+
+		skin->setStyle("SliderHorzFill", sliderHorizontalFillStyle);
+
+		GUIElementStyle sliderHorizontalStyle;
+		sliderHorizontalStyle.fixedHeight = true;
+		sliderHorizontalStyle.height = 13;
+		sliderHorizontalStyle.width = 150;
+		sliderHorizontalStyle.minWidth = 10;
+		sliderHorizontalStyle.subStyles[GUISlider::getHandleStyleType()] = GUISlider::getHandleStyleType();
+		sliderHorizontalStyle.subStyles[GUISlider::getBackgroundStyleType()] = "SliderHorzBg";
+		sliderHorizontalStyle.subStyles[GUISlider::getFillStyleType()] = "SliderHorzFill";
+
+		skin->setStyle(GUISliderHorz::getGUITypeName(), sliderHorizontalStyle);
+
+		GUIElementStyle sliderVerticalBgStyle;
+		sliderVerticalBgStyle.fixedWidth = true;
+		sliderVerticalBgStyle.width = 10;
+		sliderVerticalBgStyle.normal.texture = getGUITexture(SliderVBackgroundTex);
+		sliderVerticalBgStyle.border.top = 4;
+		sliderVerticalBgStyle.border.bottom = 4;
+
+		skin->setStyle("SliderVertBg", sliderVerticalBgStyle);
+
+		GUIElementStyle sliderVerticalFillStyle;
+		sliderVerticalFillStyle.fixedWidth = true;
+		sliderVerticalFillStyle.width = 10;
+		sliderVerticalFillStyle.normal.texture = getGUITexture(SliderVFillTex);
+		sliderVerticalFillStyle.border.top = 6;
+		sliderVerticalFillStyle.border.bottom = 4;
+
+		skin->setStyle("SliderVertFill", sliderVerticalFillStyle);
+
+		GUIElementStyle sliderVerticalStyle;
+		sliderVerticalStyle.fixedWidth = true;
+		sliderVerticalStyle.width = 13;
+		sliderVerticalStyle.height = 150;
+		sliderVerticalStyle.minHeight = 10;
+		sliderVerticalStyle.subStyles[GUISlider::getHandleStyleType()] = GUISlider::getHandleStyleType();
+		sliderVerticalStyle.subStyles[GUISlider::getBackgroundStyleType()] = "SliderVertBg";
+		sliderVerticalStyle.subStyles[GUISlider::getFillStyleType()] = "SliderVertFill";
+
+		skin->setStyle(GUISliderVert::getGUITypeName(), sliderVerticalStyle);
+
 		/************************************************************************/
 		/* 							COLOR PICKER SLIDER                      	*/
 		/************************************************************************/
@@ -1483,9 +1564,9 @@ namespace BansheeEngine
 		skin->setStyle("ColorSliderHorzHandle", colorPickerSliderHorzHandleStyle);
 
 		GUIElementStyle colorPickerSliderHorzStyle;
-		colorPickerSliderHorzHandleStyle.fixedHeight = true;
-		colorPickerSliderHorzHandleStyle.height = 32;
-		colorPickerSliderHorzHandleStyle.minWidth = 20;
+		colorPickerSliderHorzStyle.fixedHeight = true;
+		colorPickerSliderHorzStyle.height = 32;
+		colorPickerSliderHorzStyle.minWidth = 20;
 		colorPickerSliderHorzStyle.subStyles[GUISlider::getHandleStyleType()] = "ColorSliderHorzHandle";
 
 		skin->setStyle("ColorSliderHorz", colorPickerSliderHorzStyle);

+ 7 - 0
BansheeEngine/Include/BsGUISlider.h

@@ -22,6 +22,11 @@ namespace BansheeEngine
 		 */
 		static const String& getBackgroundStyleType();
 
+		/**
+		 * @brief	Name of the style for the background fill image used by the slider.
+		 */
+		static const String& getFillStyleType();
+
 		/**
 		 * @brief	Moves the slider handle the the specified position in the handle area.
 		 *
@@ -67,6 +72,8 @@ namespace BansheeEngine
 	private:
 		GUISliderHandle* mSliderHandle;
 		GUITexture* mBackground;
+		GUITexture* mFillBackground;
+		bool mHorizontal;
 
 		HEvent mHandleMovedConn;
 	};

+ 5 - 5
BansheeEngine/Include/BsGUISliderHandle.h

@@ -77,6 +77,11 @@ namespace BansheeEngine
 		 */
 		float getHandlePos() const;
 
+		/**
+		 * @brief	Returns the position of the slider handle, in pixels. Relative to this object.
+		 */
+		INT32 getHandlePosPx() const;
+
 		/**
 		 * @brief	Returns remaining length of the scrollable area not covered by the handle, in pixels.
 		 */
@@ -134,11 +139,6 @@ namespace BansheeEngine
 	private:
 		GUISliderHandle(bool horizontal, bool jumpOnClick, const String& styleName, const GUIDimensions& dimensions);
 
-		/**
-		 * @brief	Returns the position of the slider handle, in pixels.
-		 */
-		INT32 getHandlePosPx() const;
-
 		/**
 		 * @copydoc	GUIElement::mouseEvent
 		 */

+ 76 - 4
BansheeEngine/Source/BsGUISlider.cpp

@@ -11,15 +11,18 @@ using namespace std::placeholders;
 namespace BansheeEngine
 {
 	GUISlider::GUISlider(bool horizontal, const String& styleName, const GUIDimensions& dimensions)
-		:GUIElementContainer(dimensions, styleName)
+		:GUIElementContainer(dimensions, styleName), mHorizontal(horizontal)
 	{
 		mSliderHandle = GUISliderHandle::create(horizontal, true, getSubStyleName(getHandleStyleType()));
 		mBackground = GUITexture::create(getSubStyleName(getBackgroundStyleType()));
+		mFillBackground = GUITexture::create(getSubStyleName(getFillStyleType()));
 
-		mBackground->_setElementDepth(mSliderHandle->_getRenderElementDepthRange());
+		mBackground->_setElementDepth(mSliderHandle->_getRenderElementDepthRange() + mFillBackground->_getRenderElementDepthRange());
+		mFillBackground->_setElementDepth(mSliderHandle->_getRenderElementDepthRange());
 
 		_registerChildElement(mSliderHandle);
 		_registerChildElement(mBackground);
+		_registerChildElement(mFillBackground);
 
 		mHandleMovedConn = mSliderHandle->onHandleMoved.connect(std::bind(&GUISlider::onHandleMoved, this, _1));
 	}
@@ -41,6 +44,12 @@ namespace BansheeEngine
 		return BACKGROUND_STYLE_TYPE;
 	}
 
+	const String& GUISlider::getFillStyleType()
+	{
+		static String FILL_STYLE_TYPE = "SliderFill";
+		return FILL_STYLE_TYPE;
+	}
+
 	Vector2I GUISlider::_getOptimalSize() const
 	{
 		Vector2I optimalSize = mSliderHandle->_getOptimalSize();
@@ -54,13 +63,76 @@ namespace BansheeEngine
 
 	void GUISlider::_updateLayoutInternal(const GUILayoutData& data)
 	{
-		mBackground->_setLayoutData(data);
-		mSliderHandle->_setLayoutData(data);
+		GUILayoutData childData = data;
+
+		if (mHorizontal)
+		{
+			Vector2I optimalSize = mBackground->_getOptimalSize();
+			childData.area.height = optimalSize.y;
+			childData.area.y += (INT32)((data.area.height - childData.area.height) * 0.5f);
+
+			childData.clipRect = data.area;
+			childData.clipRect.clip(data.clipRect);
+
+			mBackground->_setLayoutData(childData);
+
+			optimalSize = mSliderHandle->_getOptimalSize();
+			childData.area.height = optimalSize.y;
+			childData.area.y += (INT32)((data.area.height - childData.area.height) * 0.5f);
+
+			childData.clipRect = data.area;
+			childData.clipRect.clip(data.clipRect);
+
+			mSliderHandle->_setLayoutData(childData);
+			UINT32 handleWidth = optimalSize.x;
+
+			optimalSize = mFillBackground->_getOptimalSize();
+			childData.area.height = optimalSize.y;
+			childData.area.y += (INT32)((data.area.height - childData.area.height) * 0.5f);
+			childData.area.width = mSliderHandle->getHandlePosPx() + handleWidth / 2;
+
+			childData.clipRect = data.area;
+			childData.clipRect.clip(data.clipRect);
+
+			mFillBackground->_setLayoutData(childData);
+		}
+		else
+		{
+			Vector2I optimalSize = mBackground->_getOptimalSize();
+			childData.area.width = optimalSize.x;
+			childData.area.x += (INT32)((data.area.width - childData.area.width) * 0.5f);
+
+			childData.clipRect = data.area;
+			childData.clipRect.clip(data.clipRect);
+
+			mBackground->_setLayoutData(childData);
+
+			optimalSize = mSliderHandle->_getOptimalSize();
+			childData.area.width = optimalSize.x;
+			childData.area.x += (INT32)((data.area.width - childData.area.width) * 0.5f);
+
+			childData.clipRect = data.area;
+			childData.clipRect.clip(data.clipRect);
+
+			mSliderHandle->_setLayoutData(childData);
+			UINT32 handleHeight = optimalSize.y;
+
+			optimalSize = mFillBackground->_getOptimalSize();
+			childData.area.width = optimalSize.x;
+			childData.area.x += (INT32)((data.area.width - childData.area.width) * 0.5f);
+			childData.area.height = mSliderHandle->getHandlePosPx() + handleHeight / 2;
+
+			childData.clipRect = data.area;
+			childData.clipRect.clip(data.clipRect);
+
+			mFillBackground->_setLayoutData(childData);
+		}
 	}
 
 	void GUISlider::styleUpdated()
 	{
 		mBackground->setStyle(getSubStyleName(getBackgroundStyleType()));
+		mFillBackground->setStyle(getSubStyleName(getFillStyleType()));
 		mSliderHandle->setStyle(getSubStyleName(getHandleStyleType()));
 	}
 

+ 1 - 2
TODO.txt

@@ -53,7 +53,6 @@ Code quality improvements:
 Polish
 
 Ribek use:
- - Clicking on a menu bar item hides the text (likely a depth issue) 
  - Hook up color picker to guicolor field
  - UseCustomInspector isn't implemented
  - Camera, Renderable, Material, Texture inspector
@@ -113,7 +112,7 @@ Finalizing:
  - Add copyright notices in all files & change license to GPL
  - Documentation
  - Need to generate a proper merge of dev and preview branches
-
+   - Use "git revert --no-commit <COMMITID>..HEAD" to reverse anything on the preview branch that was done after the branch creation, then merge
 ----------------------------------------------------------------------
 Build system
  - Test Resources (if loading works and if they're properly packaged in build)