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

Gotten rid of default LayoutOptions and using GUIElementStyle instead

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

+ 0 - 2
BansheeEngine/Include/BsGUIButton.h

@@ -44,8 +44,6 @@ namespace BansheeEngine
 
 
 		virtual UINT32 _getOptimalWidth() const;
 		virtual UINT32 _getOptimalWidth() const;
 		virtual UINT32 _getOptimalHeight() const;
 		virtual UINT32 _getOptimalHeight() const;
-
-		static const GUILayoutOptions& getDefaultLayoutOptions();
 	private:
 	private:
 		ImageSprite* mImageSprite;
 		ImageSprite* mImageSprite;
 		IMAGE_SPRITE_DESC mDesc;
 		IMAGE_SPRITE_DESC mDesc;

+ 2 - 0
BansheeEngine/Include/BsGUIElement.h

@@ -118,6 +118,8 @@ namespace BansheeEngine
 		void markAsClean() { mIsDirty = false; }
 		void markAsClean() { mIsDirty = false; }
 		void markAsDirty();
 		void markAsDirty();
 
 
+		static GUILayoutOptions getDefaultLayoutOptions(const GUIElementStyle* style);
+
 		GUIWidget& mParent;
 		GUIWidget& mParent;
 		GUILayout* mParentLayout;
 		GUILayout* mParentLayout;
 		GUILayoutOptions mLayoutOptions;
 		GUILayoutOptions mLayoutOptions;

+ 10 - 1
BansheeEngine/Include/BsGUIElementStyle.h

@@ -23,7 +23,9 @@ namespace BansheeEngine
 		};
 		};
 
 
 		GUIElementStyle()
 		GUIElementStyle()
-			:fontSize(8)
+			:fontSize(8), width(0), height(0),
+			fixedWidth(false), fixedHeight(false), minWidth(0), maxWidth(0),
+			minHeight(0), maxHeight(0)
 		{
 		{
 
 
 		}
 		}
@@ -43,5 +45,12 @@ namespace BansheeEngine
 		GUIElementStateStyle focusedOn;
 		GUIElementStateStyle focusedOn;
 
 
 		RectOffset border;
 		RectOffset border;
+
+		UINT32 width;
+		UINT32 height;
+		UINT32 minWidth, maxWidth;
+		UINT32 minHeight, maxHeight;
+		bool fixedWidth;
+		bool fixedHeight;
 	};
 	};
 }
 }

+ 0 - 2
BansheeEngine/Include/BsGUILabel.h

@@ -52,8 +52,6 @@ namespace BansheeEngine
 
 
 		virtual UINT32 _getOptimalWidth() const;
 		virtual UINT32 _getOptimalWidth() const;
 		virtual UINT32 _getOptimalHeight() const;
 		virtual UINT32 _getOptimalHeight() const;
-
-		static const GUILayoutOptions& getDefaultLayoutOptions();
 	private:
 	private:
 		TextSprite* mTextSprite;
 		TextSprite* mTextSprite;
 		CM::String mText;
 		CM::String mText;

+ 0 - 2
BansheeEngine/Include/BsGUIWindowFrame.h

@@ -44,8 +44,6 @@ namespace BansheeEngine
 
 
 		virtual UINT32 _getOptimalWidth() const;
 		virtual UINT32 _getOptimalWidth() const;
 		virtual UINT32 _getOptimalHeight() const;
 		virtual UINT32 _getOptimalHeight() const;
-
-		static const GUILayoutOptions& getDefaultLayoutOptions();
 	private:
 	private:
 		ImageSprite* mImageSprite;
 		ImageSprite* mImageSprite;
 		IMAGE_SPRITE_DESC mDesc;
 		IMAGE_SPRITE_DESC mDesc;

+ 7 - 0
BansheeEngine/Source/BsEngineGUI.cpp

@@ -48,6 +48,10 @@ namespace BansheeEngine
 		GUIElementStyle labelStyle;
 		GUIElementStyle labelStyle;
 		labelStyle.font = font;
 		labelStyle.font = font;
 		labelStyle.fontSize = DefaultFontSize;
 		labelStyle.fontSize = DefaultFontSize;
+		labelStyle.fixedWidth = false;
+		labelStyle.fixedHeight = true;
+		labelStyle.height = 16;
+		labelStyle.minWidth = 10;
 
 
 		mSkin.setStyle(GUILabel::getGUITypeName(), labelStyle);
 		mSkin.setStyle(GUILabel::getGUITypeName(), labelStyle);
 
 
@@ -77,6 +81,9 @@ namespace BansheeEngine
 		buttonStyle.border.right = 5;
 		buttonStyle.border.right = 5;
 		buttonStyle.border.top = 5;
 		buttonStyle.border.top = 5;
 		buttonStyle.border.bottom = 5;
 		buttonStyle.border.bottom = 5;
+		buttonStyle.fixedHeight = true;
+		buttonStyle.height = 21;
+		buttonStyle.minWidth = 10;
 
 
 		mSkin.setStyle(GUIButton::getGUITypeName(), buttonStyle);
 		mSkin.setStyle(GUIButton::getGUITypeName(), buttonStyle);
 	}
 	}

+ 4 - 17
BansheeEngine/Source/BsGUIButton.cpp

@@ -46,7 +46,10 @@ namespace BansheeEngine
 
 
 	GUIButton* GUIButton::create(GUIWidget& parent)
 	GUIButton* GUIButton::create(GUIWidget& parent)
 	{
 	{
-		return CM_NEW(GUIButton, PoolAlloc) GUIButton(parent, getDefaultLayoutOptions());
+		const GUISkin* skin = parent.getGUISkin();
+		const GUIElementStyle* style = skin->getStyle(getGUITypeName());
+
+		return CM_NEW(GUIButton, PoolAlloc) GUIButton(parent, getDefaultLayoutOptions(style));
 	}
 	}
 
 
 	GUIButton* GUIButton::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
 	GUIButton* GUIButton::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
@@ -106,22 +109,6 @@ namespace BansheeEngine
 		mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
 		mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
 	}
 	}
 
 
-	const GUILayoutOptions& GUIButton::getDefaultLayoutOptions()
-	{
-		static GUILayoutOptions layoutOptions;
-		static bool layoutOptionsInitialized = false;
-
-		if(!layoutOptionsInitialized)
-		{
-			layoutOptions.fixedWidth = false;
-			layoutOptions.fixedHeight = false;
-
-			layoutOptionsInitialized = true;
-		}
-
-		return layoutOptions;
-	}
-
 	bool GUIButton::mouseEvent(const GUIMouseEvent& ev)
 	bool GUIButton::mouseEvent(const GUIMouseEvent& ev)
 	{
 	{
 		if(ev.getType() == GUIMouseEventType::MouseOver)
 		if(ev.getType() == GUIMouseEventType::MouseOver)

+ 16 - 0
BansheeEngine/Source/BsGUIElement.cpp

@@ -90,6 +90,22 @@ namespace BansheeEngine
 		}
 		}
 	}
 	}
 
 
+	GUILayoutOptions GUIElement::getDefaultLayoutOptions(const GUIElementStyle* style)
+	{
+		GUILayoutOptions layoutOptions;
+
+		layoutOptions.fixedWidth = style->fixedWidth;
+		layoutOptions.fixedHeight = style->fixedHeight;
+		layoutOptions.width = style->width;
+		layoutOptions.height = style->height;
+		layoutOptions.minWidth = style->minWidth;
+		layoutOptions.maxWidth = style->maxWidth;
+		layoutOptions.minHeight = style->minHeight;
+		layoutOptions.maxHeight = style->maxHeight;
+
+		return layoutOptions;
+	}
+
 	void GUIElement::_destroyInternal(GUIElement* element)
 	void GUIElement::_destroyInternal(GUIElement* element)
 	{
 	{
 		CM_DELETE(element, GUIElement, PoolAlloc);
 		CM_DELETE(element, GUIElement, PoolAlloc);

+ 8 - 20
BansheeEngine/Source/BsGUILabel.cpp

@@ -103,24 +103,6 @@ namespace BansheeEngine
 		mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
 		mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
 	}
 	}
 
 
-	const GUILayoutOptions& GUILabel::getDefaultLayoutOptions()
-	{
-		static GUILayoutOptions layoutOptions;
-		static bool layoutOptionsInitialized = false;
-
-		if(!layoutOptionsInitialized)
-		{
-			layoutOptions.fixedWidth = false;
-			layoutOptions.fixedHeight = true;
-			layoutOptions.height = 16;
-			layoutOptions.minWidth = 10;
-
-			layoutOptionsInitialized = true;
-		}
-
-		return layoutOptions;
-	}
-
 	void GUILabel::setText(const CM::String& text)
 	void GUILabel::setText(const CM::String& text)
 	{
 	{
 		mDesc.text = text;
 		mDesc.text = text;
@@ -133,7 +115,10 @@ namespace BansheeEngine
 
 
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, bool wordWrap)
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, bool wordWrap)
 	{
 	{
-		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, THA_Left, TVA_Top, getDefaultLayoutOptions());
+		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));
 	}
 	}
 
 
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, bool wordWrap)
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, bool wordWrap)
@@ -143,7 +128,10 @@ namespace BansheeEngine
 
 
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, TextHorzAlign horzAlign, TextVertAlign vertAlign, bool wordWrap)
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, TextHorzAlign horzAlign, TextVertAlign vertAlign, bool wordWrap)
 	{
 	{
-		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, horzAlign, vertAlign, getDefaultLayoutOptions());
+		const GUISkin* skin = parent.getGUISkin();
+		const GUIElementStyle* style = skin->getStyle(getGUITypeName());
+
+		return CM_NEW(GUILabel, PoolAlloc) GUILabel(parent, text, wordWrap, horzAlign, vertAlign, getDefaultLayoutOptions(style));
 	}
 	}
 
 
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, TextHorzAlign horzAlign, TextVertAlign vertAlign, bool wordWrap)
 	GUILabel* GUILabel::create(GUIWidget& parent, const String& text, const GUILayoutOptions& layoutOptions, TextHorzAlign horzAlign, TextVertAlign vertAlign, bool wordWrap)

+ 4 - 17
BansheeEngine/Source/BsGUIWindowFrame.cpp

@@ -45,7 +45,10 @@ namespace BansheeEngine
 
 
 	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent)
 	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent)
 	{
 	{
-		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, getDefaultLayoutOptions());
+		const GUISkin* skin = parent.getGUISkin();
+		const GUIElementStyle* style = skin->getStyle(getGUITypeName());
+
+		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, getDefaultLayoutOptions(style));
 	}
 	}
 
 
 	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
 	GUIWindowFrame* GUIWindowFrame::create(GUIWidget& parent, const GUILayoutOptions& layoutOptions)
@@ -104,20 +107,4 @@ namespace BansheeEngine
 	{
 	{
 		mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
 		mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
 	}
 	}
-
-	const GUILayoutOptions& GUIWindowFrame::getDefaultLayoutOptions()
-	{
-		static GUILayoutOptions layoutOptions;
-		static bool layoutOptionsInitialized = false;
-
-		if(!layoutOptionsInitialized)
-		{
-			layoutOptions.fixedWidth = false;
-			layoutOptions.fixedHeight = false;
-
-			layoutOptionsInitialized = true;
-		}
-
-		return layoutOptions;
-	}
 }
 }