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

Added vert/horz text to GUIButton
Added even more customization options GUIElementStyle

Marko Pintera 12 лет назад
Родитель
Сommit
84b6518356

+ 3 - 3
BansheeEngine/Include/BsGUIButton.h

@@ -11,8 +11,8 @@ namespace BansheeEngine
 	public:
 	public:
 		static const CM::String& getGUITypeName();
 		static const CM::String& getGUITypeName();
 
 
-		static GUIButton* create(GUIWidget& parent, const CM::String& text);
-		static GUIButton* create(GUIWidget& parent, const CM::String& text, const GUILayoutOptions& layoutOptions);
+		static GUIButton* create(GUIWidget& parent, const CM::String& text, const GUIElementStyle* style = nullptr);
+		static GUIButton* create(GUIWidget& parent, const CM::String& text, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style = nullptr);
 	protected:
 	protected:
 		~GUIButton();
 		~GUIButton();
 
 
@@ -54,7 +54,7 @@ namespace BansheeEngine
 		IMAGE_SPRITE_DESC mImageDesc;
 		IMAGE_SPRITE_DESC mImageDesc;
 		CM::String mText;
 		CM::String mText;
 
 
-		GUIButton(GUIWidget& parent, const CM::String& text, const GUILayoutOptions& layoutOptions);
+		GUIButton(GUIWidget& parent, const GUIElementStyle* style, const CM::String& text, const GUILayoutOptions& layoutOptions);
 
 
 		virtual bool mouseEvent(const GUIMouseEvent& ev);
 		virtual bool mouseEvent(const GUIMouseEvent& ev);
 	};
 	};

+ 1 - 1
BansheeEngine/Include/BsGUIElement.h

@@ -10,7 +10,7 @@ namespace BansheeEngine
 	class BS_EXPORT GUIElement
 	class BS_EXPORT GUIElement
 	{
 	{
 	public:
 	public:
-		GUIElement(GUIWidget& parent, const GUILayoutOptions& layoutOptions);
+		GUIElement(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions);
 
 
 		/**
 		/**
 		 * @brief	Returns the number of separate render elements in the GUI element.
 		 * @brief	Returns the number of separate render elements in the GUI element.

+ 5 - 1
BansheeEngine/Include/BsGUIElementStyle.h

@@ -1,6 +1,7 @@
 #pragma once
 #pragma once
 
 
 #include "BsPrerequisites.h"
 #include "BsPrerequisites.h"
+#include "BsTextSprite.h"
 #include "CmColor.h"
 #include "CmColor.h"
 #include "CmInt2.h"
 #include "CmInt2.h"
 
 
@@ -26,13 +27,16 @@ namespace BansheeEngine
 		GUIElementStyle()
 		GUIElementStyle()
 			:fontSize(8), width(0), height(0),
 			:fontSize(8), width(0), height(0),
 			fixedWidth(false), fixedHeight(false), minWidth(0), maxWidth(0),
 			fixedWidth(false), fixedHeight(false), minWidth(0), maxWidth(0),
-			minHeight(0), maxHeight(0)
+			minHeight(0), maxHeight(0), textHorzAlign(THA_Left), textVertAlign(TVA_Top), wordWrap(false)
 		{
 		{
 
 
 		}
 		}
 
 
 		CM::HFont font;
 		CM::HFont font;
 		UINT32 fontSize;
 		UINT32 fontSize;
+		TextHorzAlign textHorzAlign;
+		TextVertAlign textVertAlign;
+		bool wordWrap;
 
 
 		GUIElementStateStyle normal;
 		GUIElementStateStyle normal;
 		GUIElementStateStyle hover;
 		GUIElementStateStyle hover;

+ 4 - 12
BansheeEngine/Include/BsGUILabel.h

@@ -11,13 +11,8 @@ namespace BansheeEngine
 	public:
 	public:
 		static const CM::String& getGUITypeName();
 		static const CM::String& getGUITypeName();
 
 
-		static GUILabel* create(GUIWidget& parent, const CM::String& text, bool wordWrap = false);
-		static GUILabel* create(GUIWidget& parent, const CM::String& text, const GUILayoutOptions& layoutOptions, bool wordWrap = false);
-
-		static GUILabel* create(GUIWidget& parent, const CM::String& text, TextHorzAlign horzAlign, 
-			TextVertAlign vertAlign = TVA_Top, bool wordWrap = false);
-		static GUILabel* create(GUIWidget& parent, const CM::String& text, const GUILayoutOptions& layoutOptions,
-			TextHorzAlign horzAlign, TextVertAlign vertAlign = TVA_Top, bool wordWrap = false);
+		static GUILabel* create(GUIWidget& parent, const CM::String& text, const GUIElementStyle* style = nullptr);
+		static GUILabel* create(GUIWidget& parent, const CM::String& text, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style = nullptr);
 
 
 		void setText(const CM::String& text);
 		void setText(const CM::String& text);
 
 
@@ -55,12 +50,9 @@ namespace BansheeEngine
 	private:
 	private:
 		TextSprite* mTextSprite;
 		TextSprite* mTextSprite;
 		CM::String mText;
 		CM::String mText;
-		bool mWordWrap;
-		TextHorzAlign mHorzAlign;
-		TextVertAlign mVertAlign;
+
 		TEXT_SPRITE_DESC mDesc;
 		TEXT_SPRITE_DESC mDesc;
 		
 		
-		GUILabel(GUIWidget& parent, const CM::String& text, bool wordWrap, TextHorzAlign horzAlign, TextVertAlign vertAlign, 
-			const GUILayoutOptions& layoutOptions);
+		GUILabel(GUIWidget& parent, const GUIElementStyle* style, const CM::String& text, const GUILayoutOptions& layoutOptions);
 	};
 	};
 }
 }

+ 3 - 3
BansheeEngine/Include/BsGUIWindowFrame.h

@@ -11,8 +11,8 @@ namespace BansheeEngine
 	public:
 	public:
 		static const CM::String& getGUITypeName();
 		static const CM::String& getGUITypeName();
 
 
-		static GUIWindowFrame* create(GUIWidget& parent);
-		static GUIWindowFrame* create(GUIWidget& parent, const GUILayoutOptions& layoutOptions);
+		static GUIWindowFrame* create(GUIWidget& parent, const GUIElementStyle* style = nullptr);
+		static GUIWindowFrame* create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style = nullptr);
 	protected:
 	protected:
 		~GUIWindowFrame();
 		~GUIWindowFrame();
 
 
@@ -48,6 +48,6 @@ namespace BansheeEngine
 		ImageSprite* mImageSprite;
 		ImageSprite* mImageSprite;
 		IMAGE_SPRITE_DESC mDesc;
 		IMAGE_SPRITE_DESC mDesc;
 
 
-		GUIWindowFrame(GUIWidget& parent, const GUILayoutOptions& layoutOptions);
+		GUIWindowFrame(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions);
 	};
 	};
 }
 }

+ 3 - 0
BansheeEngine/Source/BsEngineGUI.cpp

@@ -4,6 +4,7 @@
 #include "BsGUILabel.h"
 #include "BsGUILabel.h"
 #include "BsGUIWindowFrame.h"
 #include "BsGUIWindowFrame.h"
 #include "BsGUIButton.h"
 #include "BsGUIButton.h"
+#include "BsTextSprite.h"
 #include "BsSpriteTexture.h"
 #include "BsSpriteTexture.h"
 
 
 #include "CmFont.h"
 #include "CmFont.h"
@@ -92,6 +93,8 @@ namespace BansheeEngine
 		buttonStyle.minWidth = 10;
 		buttonStyle.minWidth = 10;
 		buttonStyle.font = font;
 		buttonStyle.font = font;
 		buttonStyle.fontSize = DefaultFontSize;
 		buttonStyle.fontSize = DefaultFontSize;
+		buttonStyle.textHorzAlign = THA_Center;
+		buttonStyle.textVertAlign = TVA_Center;
 
 
 		mSkin.setStyle(GUIButton::getGUITypeName(), buttonStyle);
 		mSkin.setStyle(GUIButton::getGUITypeName(), buttonStyle);
 	}
 	}

+ 19 - 13
BansheeEngine/Source/BsGUIButton.cpp

@@ -18,12 +18,9 @@ namespace BansheeEngine
 		return name;
 		return name;
 	}
 	}
 
 
-	GUIButton::GUIButton(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions)
-		:GUIElement(parent, layoutOptions), mText(text), mNumImageRenderElements(0)
+	GUIButton::GUIButton(GUIWidget& parent, const GUIElementStyle* style, const String& text, const GUILayoutOptions& layoutOptions)
+		:GUIElement(parent, style, layoutOptions), mText(text), mNumImageRenderElements(0)
 	{
 	{
-		const GUISkin* skin = parent.getGUISkin();
-
-		mStyle = skin->getStyle(getGUITypeName());
 		mImageSprite = CM_NEW(ImageSprite, PoolAlloc) ImageSprite();
 		mImageSprite = CM_NEW(ImageSprite, PoolAlloc) ImageSprite();
 		mTextSprite = CM_NEW(TextSprite, PoolAlloc) TextSprite();
 		mTextSprite = CM_NEW(TextSprite, PoolAlloc) TextSprite();
 
 
@@ -47,17 +44,26 @@ namespace BansheeEngine
 		CM_DELETE(mImageSprite, ImageSprite, PoolAlloc);
 		CM_DELETE(mImageSprite, ImageSprite, PoolAlloc);
 	}
 	}
 
 
-	GUIButton* GUIButton::create(GUIWidget& parent, const String& text)
+	GUIButton* GUIButton::create(GUIWidget& parent, const String& text, const GUIElementStyle* style)
 	{
 	{
-		const GUISkin* skin = parent.getGUISkin();
-		const GUIElementStyle* style = skin->getStyle(getGUITypeName());
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getGUISkin();
+			style = skin->getStyle(getGUITypeName());
+		}
 
 
-		return CM_NEW(GUIButton, PoolAlloc) GUIButton(parent, text, getDefaultLayoutOptions(style));
+		return CM_NEW(GUIButton, PoolAlloc) GUIButton(parent, style, text, getDefaultLayoutOptions(style));
 	}
 	}
 
 
-	GUIButton* GUIButton::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions)
+	GUIButton* GUIButton::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
 	{
 	{
-		return CM_NEW(GUIButton, PoolAlloc) GUIButton(parent, text, layoutOptions);
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getGUISkin();
+			style = skin->getStyle(getGUITypeName());
+		}
+
+		return CM_NEW(GUIButton, PoolAlloc) GUIButton(parent, style, text, layoutOptions);
 	}
 	}
 
 
 	UINT32 GUIButton::getNumRenderElements() const
 	UINT32 GUIButton::getNumRenderElements() const
@@ -116,10 +122,10 @@ namespace BansheeEngine
 		textDesc.width = contentBounds.width;
 		textDesc.width = contentBounds.width;
 		textDesc.height = contentBounds.height;
 		textDesc.height = contentBounds.height;
 		textDesc.clipRect = Rect(0, 0, textDesc.width, textDesc.height);
 		textDesc.clipRect = Rect(0, 0, textDesc.width, textDesc.height);
+		textDesc.horzAlign = mStyle->textHorzAlign;
+		textDesc.vertAlign = mStyle->textVertAlign;
 
 
 		mTextSprite->update(textDesc);
 		mTextSprite->update(textDesc);
-
-		
 	}
 	}
 
 
 	UINT32 GUIButton::_getOptimalWidth() const
 	UINT32 GUIButton::_getOptimalWidth() const

+ 2 - 2
BansheeEngine/Source/BsGUIElement.cpp

@@ -8,8 +8,8 @@ using namespace CamelotFramework;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	GUIElement::GUIElement(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
-		:mParent(parent), mIsDirty(true), mParentLayout(nullptr), mLayoutOptions(layoutOptions), mWidth(0), mHeight(0), mDepth(0)
+	GUIElement::GUIElement(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
+		:mParent(parent), mIsDirty(true), mParentLayout(nullptr), mLayoutOptions(layoutOptions), mWidth(0), mHeight(0), mDepth(0), mStyle(style)
 	{
 	{
 		mParent.registerElement(this);
 		mParent.registerElement(this);
 	}
 	}

+ 19 - 28
BansheeEngine/Source/BsGUILabel.cpp

@@ -10,22 +10,17 @@ using namespace CamelotFramework;
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
-	GUILabel::GUILabel(GUIWidget& parent, const String& text, bool wordWrap, TextHorzAlign horzAlign, 
-		TextVertAlign vertAlign, const GUILayoutOptions& layoutOptions)
-		:GUIElement(parent, layoutOptions), mText(text), mWordWrap(wordWrap),
-		mHorzAlign(horzAlign), mVertAlign(vertAlign)
+	GUILabel::GUILabel(GUIWidget& parent, const GUIElementStyle* style, const String& text, const GUILayoutOptions& layoutOptions)
+		:GUIElement(parent, style, layoutOptions), mText(text)
 	{
 	{
-		const GUISkin* skin = parent.getGUISkin();
-
-		mStyle = skin->getStyle(getGUITypeName());
 		mTextSprite = CM_NEW(TextSprite, PoolAlloc) TextSprite();
 		mTextSprite = CM_NEW(TextSprite, PoolAlloc) TextSprite();
 
 
 		mDesc.text = text;
 		mDesc.text = text;
 		mDesc.font = mStyle->font;
 		mDesc.font = mStyle->font;
 		mDesc.fontSize = mStyle->fontSize;
 		mDesc.fontSize = mStyle->fontSize;
-		mDesc.wordWrap = wordWrap;
-		mDesc.horzAlign = horzAlign;
-		mDesc.vertAlign = vertAlign;
+		mDesc.wordWrap = mStyle->wordWrap;
+		mDesc.horzAlign = mStyle->textHorzAlign;
+		mDesc.vertAlign = mStyle->textVertAlign;
 	}
 	}
 
 
 	GUILabel::~GUILabel()
 	GUILabel::~GUILabel()
@@ -113,30 +108,26 @@ namespace BansheeEngine
 		markAsDirty();
 		markAsDirty();
 	}
 	}
 
 
-	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, bool wordWrap)
+	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUIElementStyle* style)
 	{
 	{
-		const GUISkin* skin = parent.getGUISkin();
-		const GUIElementStyle* style = skin->getStyle(getGUITypeName());
-
-		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, THA_Left, TVA_Top, getDefaultLayoutOptions(style));
-	}
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getGUISkin();
+			style = skin->getStyle(getGUITypeName());
+		}
 
 
-	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, bool wordWrap)
-	{
-		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, THA_Left, TVA_Top, layoutOptions);
+		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, style, text, getDefaultLayoutOptions(style));
 	}
 	}
 
 
-	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, TextHorzAlign horzAlign, TextVertAlign vertAlign, bool wordWrap)
+	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
 	{
 	{
-		const GUISkin* skin = parent.getGUISkin();
-		const GUIElementStyle* style = skin->getStyle(getGUITypeName());
-
-		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, horzAlign, vertAlign, getDefaultLayoutOptions(style));
-	}
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getGUISkin();
+			style = skin->getStyle(getGUITypeName());
+		}
 
 
-	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, TextHorzAlign horzAlign, TextVertAlign vertAlign, bool wordWrap)
-	{
-		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, horzAlign, vertAlign, layoutOptions);
+		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, style, text, layoutOptions);
 	}
 	}
 
 
 	const String& GUILabel::getGUITypeName()
 	const String& GUILabel::getGUITypeName()

+ 17 - 11
BansheeEngine/Source/BsGUIWindowFrame.cpp

@@ -16,12 +16,9 @@ namespace BansheeEngine
 		return name;
 		return name;
 	}
 	}
 
 
-	GUIWindowFrame::GUIWindowFrame(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
-		:GUIElement(parent, layoutOptions)
+	GUIWindowFrame::GUIWindowFrame(GUIWidget& parent, const GUIElementStyle* style, const GUILayoutOptions& layoutOptions)
+		:GUIElement(parent, style, layoutOptions)
 	{
 	{
-		const GUISkin* skin = parent.getGUISkin();
-
-		mStyle = skin->getStyle(getGUITypeName());
 		mImageSprite = CM_NEW(ImageSprite, PoolAlloc) ImageSprite();
 		mImageSprite = CM_NEW(ImageSprite, PoolAlloc) ImageSprite();
 
 
 		mDesc.texture = mStyle->normal.texture;
 		mDesc.texture = mStyle->normal.texture;
@@ -43,17 +40,26 @@ namespace BansheeEngine
 		CM_DELETE(mImageSprite, ImageSprite, PoolAlloc);
 		CM_DELETE(mImageSprite, ImageSprite, PoolAlloc);
 	}
 	}
 
 
-	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent)
+	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent, const GUIElementStyle* style)
 	{
 	{
-		const GUISkin* skin = parent.getGUISkin();
-		const GUIElementStyle* style = skin->getStyle(getGUITypeName());
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getGUISkin();
+			style = skin->getStyle(getGUITypeName());
+		}
 
 
-		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, getDefaultLayoutOptions(style));
+		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, style, getDefaultLayoutOptions(style));
 	}
 	}
 
 
-	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
+	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
 	{
 	{
-		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, layoutOptions);
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getGUISkin();
+			style = skin->getStyle(getGUITypeName());
+		}
+
+		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, style, layoutOptions);
 	}
 	}
 
 
 	UINT32 GUIWindowFrame::getNumRenderElements() const
 	UINT32 GUIWindowFrame::getNumRenderElements() const

+ 1 - 1
CamelotClient/CmTestTextSprite.cpp

@@ -30,7 +30,7 @@ namespace CamelotFramework
 	{
 	{
 		setSkin(&EngineGUI::instance().getSkin());
 		setSkin(&EngineGUI::instance().getSkin());
 
 
-		GUILabel::create(*this, text, THA_Right, TVA_Bottom, true);
+		GUILabel::create(*this, text);
 		GUIWindowFrame::create(*this);
 		GUIWindowFrame::create(*this);
 	}
 	}