Просмотр исходного кода

GUI element tint now responds to element's disabled state

BearishSun 10 лет назад
Родитель
Сommit
555fb8e97a

+ 2 - 8
BansheeEditor/Include/BsGUIColor.h

@@ -52,12 +52,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Returns the currently displayed color.
 		 */
-		Color getColor() const { return mColor; }
-
-		/**
-		 * @copydoc	GUIElement::setTint
-		 */
-		virtual void setTint(const Color& color) override;
+		Color getColor() const { return mValue; }
 
 		Event<void(const Color&)> onValueChanged; /**< Triggered when the displayed color value changes. */
 	protected:
@@ -109,7 +104,6 @@ namespace BansheeEngine
 		IMAGE_SPRITE_DESC mColorImageDesc;
 		IMAGE_SPRITE_DESC mAlphaImageDesc;
 
-		Color mColor;
-		Color mTint;
+		Color mValue;
 	};
 }

+ 3 - 10
BansheeEditor/Source/BsGUIColor.cpp

@@ -47,21 +47,14 @@ namespace BansheeEngine
 
 	void GUIColor::setColor(const Color& color)
 	{
-		if (color != mColor)
+		if (color != mValue)
 		{
-			mColor = color;
+			mValue = color;
 
 			_markContentAsDirty();
 		}
 	}
 
-	void GUIColor::setTint(const Color& color)
-	{
-		mTint = color;
-
-		_markContentAsDirty();
-	}
-
 	UINT32 GUIColor::_getNumRenderElements() const
 	{
 		UINT32 numElements = mColorSprite->getNumRenderElements();
@@ -95,7 +88,7 @@ namespace BansheeEngine
 
 	void GUIColor::updateRenderElementsInternal()
 	{		
-		Color color = mColor * mTint;
+		Color color = mValue * getTint();
 
 		mColorImageDesc.color = color;
 		mColorImageDesc.color.a = 1.0f;

+ 0 - 6
BansheeEngine/Include/BsGUIButtonBase.h

@@ -35,11 +35,6 @@ namespace BansheeEngine
 		 */
 		void setContent(const GUIContent& content);
 
-		/**
-		 * @copydoc	GUIElement::setTint
-		 */
-		virtual void setTint(const Color& color) override;
-
 		/**
 		 * @brief	Change the button "on" state. This state determines
 		 *			whether the button uses normal or "on" fields specified
@@ -157,7 +152,6 @@ namespace BansheeEngine
 		ImageSprite* mContentImageSprite;
 		TextSprite* mTextSprite;
 		GUIButtonState mActiveState;
-		Color mColor;
 
 		IMAGE_SPRITE_DESC mImageDesc;
 		GUIContent mContent;

+ 10 - 2
BansheeEngine/Include/BsGUIElement.h

@@ -43,7 +43,7 @@ namespace BansheeEngine
 		/**
 		 * @brief	Sets the tint of the GUI element.
 		 */
-		virtual void setTint(const Color& color) { }
+		virtual void setTint(const Color& color);
 
 		/**
 		 * @copydoc	GUIElementBase::resetDimensions
@@ -388,13 +388,21 @@ namespace BansheeEngine
 		 */
 		Rect2I getCachedContentClipRect() const;
 
+		/**
+		 * @brief	Returns the tint that is applied to the GUI element.
+		 */
+		Color getTint() const;
+
 		bool mIsDestroyed;
 		Rect2I mClippedBounds;
-
+		
 	private:
+		static const Color DISABLED_COLOR;
+
 		const GUIElementStyle* mStyle;
 		String mStyleName;
 
 		GUIContextMenuPtr mContextMenu;
+		Color mColor;
 	};
 }

+ 0 - 6
BansheeEngine/Include/BsGUIInputBox.h

@@ -81,11 +81,6 @@ namespace BansheeEngine
 		 */
 		void setFilter(std::function<bool(const WString&)> filter) { mFilter = filter; }
 
-		/**
-		 * @copydoc	GUIElement::setTint
-		 */
-		virtual void setTint(const Color& color) override;
-
 		/**
 		 * @copydoc	GUIElement::getElementType
 		 */
@@ -332,7 +327,6 @@ namespace BansheeEngine
 		bool mHasFocus;
 		bool mIsMouseOver;
 		State mState;
-		Color mColor;
 
 		IMAGE_SPRITE_DESC mImageDesc;
 		WString mText;

+ 0 - 6
BansheeEngine/Include/BsGUILabel.h

@@ -67,11 +67,6 @@ namespace BansheeEngine
 		 */
 		void setContent(const GUIContent& content);
 
-		/**
-		 * @copydoc	GUIElement::setTint
-		 */
-		virtual void setTint(const Color& color) override;
-
 		/**
 		 * @copydoc	GUIElement::_getOptimalSize
 		 */
@@ -119,7 +114,6 @@ namespace BansheeEngine
 
 		TextSprite* mTextSprite;
 		GUIContent mContent;
-		Color mColor;
 
 		TEXT_SPRITE_DESC mDesc;
 	};

+ 0 - 1
BansheeEngine/Include/BsGUIScrollBar.h

@@ -142,7 +142,6 @@ namespace BansheeEngine
 		GUIButton* mDownBtn;
 		GUISliderHandle* mHandleBtn;
 		bool mHorizontal;
-		Color mColor;
 
 		static const UINT32 ButtonScrollAmount;
 	};

+ 0 - 6
BansheeEngine/Include/BsGUISliderHandle.h

@@ -98,11 +98,6 @@ namespace BansheeEngine
 		 */
 		void setStep(float step);
 
-		/**
-		 * @copydoc	GUIElement::setTint
-		 */
-		virtual void setTint(const Color& color) override;
-
 		/**
 		 * @copydoc	GUIElement::_getOptimalSize
 		 */
@@ -177,6 +172,5 @@ namespace BansheeEngine
 		bool mMouseOverHandle;
 		bool mHandleDragged;
 		State mState;
-		Color mColor;
 	};
 }

+ 0 - 6
BansheeEngine/Include/BsGUITexture.h

@@ -162,11 +162,6 @@ namespace BansheeEngine
 		 */
 		void setTexture(const HSpriteTexture& texture);
 
-		/**
-		 * @copydoc	GUIElement::setTint
-		 */
-		virtual void setTint(const Color& color) override;
-		
 		/**
 		 * @copydoc	GUIElement::getElementType
 		 */
@@ -223,6 +218,5 @@ namespace BansheeEngine
 		GUIImageScaleMode mScaleMode;
 		bool mTransparent;
 		bool mUsingStyleTexture;
-		Color mColor;
 	};
 }

+ 3 - 10
BansheeEngine/Source/BsGUIButtonBase.cpp

@@ -59,13 +59,6 @@ namespace BansheeEngine
 			_markContentAsDirty();
 	}
 
-	void GUIButtonBase::setTint(const Color& color)
-	{
-		mColor = color;
-
-		_markContentAsDirty();
-	}
-
 	void GUIButtonBase::_setOn(bool on) 
 	{ 
 		if(on)
@@ -134,7 +127,7 @@ namespace BansheeEngine
 		mImageDesc.borderRight = _getStyle()->border.right;
 		mImageDesc.borderTop = _getStyle()->border.top;
 		mImageDesc.borderBottom = _getStyle()->border.bottom;
-		mImageDesc.color = mColor;
+		mImageDesc.color = getTint();
 
 		mImageSprite->update(mImageDesc, (UINT64)_getParentWidget());
 
@@ -168,7 +161,7 @@ namespace BansheeEngine
 			contentImgDesc.texture = mContent.getImage().getInternalPtr();
 			contentImgDesc.width = contentWidth;
 			contentImgDesc.height = contentHeight;
-			contentImgDesc.color = mColor;
+			contentImgDesc.color = getTint();
 
 			mContentImageSprite->update(contentImgDesc, (UINT64)_getParentWidget());
 		}
@@ -353,7 +346,7 @@ namespace BansheeEngine
 		textDesc.text = mContent.getText();
 		textDesc.font = _getStyle()->font;
 		textDesc.fontSize = _getStyle()->fontSize;
-		textDesc.color = mColor * getActiveTextColor();
+		textDesc.color = getTint() * getActiveTextColor();
 
 		Rect2I textBounds = getCachedContentBounds();
 

+ 17 - 0
BansheeEngine/Source/BsGUIElement.cpp

@@ -9,6 +9,8 @@
 
 namespace BansheeEngine
 {
+	const Color GUIElement::DISABLED_COLOR = Color(0.3f, 0.3f, 0.3f, 1.0f);
+
 	GUIElement::GUIElement(const String& styleName, const GUIDimensions& dimensions)
 		:GUIElementBase(dimensions), mStyle(&GUISkin::DefaultStyle),
 		mIsDestroyed(false), mStyleName(styleName)
@@ -63,6 +65,13 @@ namespace BansheeEngine
 		return false;
 	}
 
+	void GUIElement::setTint(const Color& color)
+	{
+		mColor = color;
+
+		_markContentAsDirty();
+	}
+
 	void GUIElement::_setElementDepth(UINT8 depth)
 	{
 		mLayoutData.depth = depth | (mLayoutData.depth & 0xFFFFFF00);
@@ -167,6 +176,14 @@ namespace BansheeEngine
 		return contentClipRect;
 	}
 
+	Color GUIElement::getTint() const
+	{
+		if (!_isDisabled())
+			return mColor;
+
+		return mColor * DISABLED_COLOR;
+	}
+
 	bool GUIElement::_isInBounds(const Vector2I position) const
 	{
 		Rect2I contentBounds = getCachedVisibleBounds();

+ 2 - 9
BansheeEngine/Source/BsGUIInputBox.cpp

@@ -104,13 +104,6 @@ namespace BansheeEngine
 		}
 	}
 
-	void GUIInputBox::setTint(const Color& color)
-	{
-		mColor = color;
-
-		_markContentAsDirty();
-	}
-
 	UINT32 GUIInputBox::_getNumRenderElements() const
 	{
 		UINT32 numElements = mImageSprite->getNumRenderElements();
@@ -155,7 +148,7 @@ namespace BansheeEngine
 		mImageDesc.borderRight = _getStyle()->border.right;
 		mImageDesc.borderTop = _getStyle()->border.top;
 		mImageDesc.borderBottom = _getStyle()->border.bottom;
-		mImageDesc.color = mColor;
+		mImageDesc.color = getTint();
 
 		const HSpriteTexture& activeTex = getActiveTexture();
 		if(SpriteTexture::checkIsLoaded(activeTex))
@@ -1120,7 +1113,7 @@ namespace BansheeEngine
 		textDesc.text = mText;
 		textDesc.font = _getStyle()->font;
 		textDesc.fontSize = _getStyle()->fontSize;
-		textDesc.color = mColor * getActiveTextColor();
+		textDesc.color = getTint() * getActiveTextColor();
 
 		Rect2I textBounds = getCachedContentBounds();
 		textDesc.width = textBounds.width;

+ 1 - 8
BansheeEngine/Source/BsGUILabel.cpp

@@ -45,7 +45,7 @@ namespace BansheeEngine
 		mDesc.width = mLayoutData.area.width;
 		mDesc.height = mLayoutData.area.height;
 		mDesc.text = mContent.getText();
-		mDesc.color = mColor * _getStyle()->normal.textColor;;
+		mDesc.color = getTint() * _getStyle()->normal.textColor;;
 
 		mTextSprite->update(mDesc, (UINT64)_getParentWidget());
 
@@ -84,13 +84,6 @@ namespace BansheeEngine
 			_markContentAsDirty();
 	}
 
-	void GUILabel::setTint(const Color& color)
-	{
-		mColor = color;
-
-		_markContentAsDirty();
-	}
-
 	GUILabel* GUILabel::create(const HString& text, const String& styleName)
 	{
 		return create(GUIContent(text), styleName);

+ 1 - 1
BansheeEngine/Source/BsGUIRenderTexture.cpp

@@ -72,7 +72,7 @@ namespace BansheeEngine
 		mDesc.width = mLayoutData.area.width;
 		mDesc.height = mLayoutData.area.height;
 		mDesc.transparent = false;
-		mDesc.color = mColor;
+		mDesc.color = getTint();
 
 		mImageSprite->update(mDesc, (UINT64)_getParentWidget());
 

+ 5 - 3
BansheeEngine/Source/BsGUIScrollBar.cpp

@@ -89,7 +89,7 @@ namespace BansheeEngine
 
 		desc.width = mLayoutData.area.width;
 		desc.height = mLayoutData.area.height;
-		desc.color = mColor;
+		desc.color = getTint();
 
 		mImageSprite->update(desc, (UINT64)_getParentWidget());
 
@@ -190,8 +190,10 @@ namespace BansheeEngine
 
 	void GUIScrollBar::setTint(const Color& color)
 	{
-		mColor = color;
+		mUpBtn->setTint(color);
+		mDownBtn->setTint(color);
+		mHandleBtn->setTint(color);
 
-		_markLayoutAsDirty();
+		GUIElement::setTint(color);
 	}
 }

+ 1 - 8
BansheeEngine/Source/BsGUISliderHandle.cpp

@@ -70,13 +70,6 @@ namespace BansheeEngine
 		return getMaxSize() - mHandleSize;
 	}
 
-	void GUISliderHandle::setTint(const Color& color)
-	{
-		mColor = color;
-
-		_markLayoutAsDirty();
-	}
-
 	UINT32 GUISliderHandle::_getNumRenderElements() const
 	{
 		return mImageSprite->getNumRenderElements();
@@ -121,7 +114,7 @@ namespace BansheeEngine
 		desc.borderRight = _getStyle()->border.right;
 		desc.borderTop = _getStyle()->border.top;
 		desc.borderBottom = _getStyle()->border.bottom;
-		desc.color = mColor;
+		desc.color = getTint();
 		mImageSprite->update(desc, (UINT64)_getParentWidget());
 		
 		GUIElement::updateRenderElementsInternal();

+ 1 - 8
BansheeEngine/Source/BsGUITexture.cpp

@@ -103,13 +103,6 @@ namespace BansheeEngine
 			HSpriteTexture(), GUIImageScaleMode::StretchToFit, true, GUIDimensions::create());
 	}
 
-	void GUITexture::setTint(const Color& color)
-	{
-		mColor = color;
-
-		_markContentAsDirty();
-	}
-
 	void GUITexture::setTexture(const HSpriteTexture& texture)
 	{
 		Vector2I origSize = mDimensions.calculateSizeRange(_getOptimalSize()).optimal;
@@ -149,7 +142,7 @@ namespace BansheeEngine
 		mDesc.borderTop = _getStyle()->border.top;
 		mDesc.borderBottom = _getStyle()->border.bottom;
 		mDesc.transparent = mTransparent;
-		mDesc.color = mColor;
+		mDesc.color = getTint();
 
 		float optimalWidth = 0.0f;
 		float optimalHeight = 0.0f;