Browse Source

Moved some GUI elements in default engine skin

Marko Pintera 12 years ago
parent
commit
e15198d3ec

+ 2 - 0
BansheeEngine/Include/BsEngineGUI.h

@@ -18,5 +18,7 @@ namespace BansheeEngine
 
 
 		static const CM::String DefaultFontPath;
 		static const CM::String DefaultFontPath;
 		static const UINT32 DefaultFontSize;
 		static const UINT32 DefaultFontSize;
+
+		static const CM::String WindowFramePrimaryTexture;
 	};
 	};
 }
 }

+ 29 - 0
BansheeEngine/Include/BsGUIElementStyle.h

@@ -1,11 +1,27 @@
 #pragma once
 #pragma once
 
 
 #include "BsPrerequisites.h"
 #include "BsPrerequisites.h"
+#include "CmColor.h"
 
 
 namespace BansheeEngine
 namespace BansheeEngine
 {
 {
+	struct RectOffset
+	{
+		RectOffset()
+			:left(0), right(0), top(0), bottom(0)
+		{ }
+
+		INT32 left, right, top, bottom;
+	};
+
 	struct BS_EXPORT GUIElementStyle
 	struct BS_EXPORT GUIElementStyle
 	{
 	{
+		struct BS_EXPORT GUIElementStateStyle
+		{
+			SpriteTexturePtr texture;
+			CM::Color textColor;
+		};
+
 		GUIElementStyle()
 		GUIElementStyle()
 			:fontSize(8)
 			:fontSize(8)
 		{
 		{
@@ -14,5 +30,18 @@ namespace BansheeEngine
 
 
 		CM::HFont font;
 		CM::HFont font;
 		UINT32 fontSize;
 		UINT32 fontSize;
+
+		GUIElementStateStyle normal;
+		GUIElementStateStyle hover;
+		GUIElementStateStyle active;
+		GUIElementStateStyle focused;
+
+		// For controls that can be turned on-off
+		GUIElementStateStyle normalOn;
+		GUIElementStateStyle hoverOn;
+		GUIElementStateStyle activeOn;
+		GUIElementStateStyle focusedOn;
+
+		RectOffset border;
 	};
 	};
 }
 }

+ 3 - 3
BansheeEngine/Include/BsGUILabel.h

@@ -12,9 +12,9 @@ namespace BansheeEngine
 		static const CM::String& getGUITypeName();
 		static const CM::String& getGUITypeName();
 
 
 		static GUILabel* create(GUIWidget* parent, const CM::String& text);
 		static GUILabel* create(GUIWidget* parent, const CM::String& text);
-		static GUILabel* create(GUIWidget* parent, const CM::String& text, TextHorzAlign horzAlign, TextVertAlign vertAlign);
-		static GUILabel* create(GUIWidget* parent, const CM::String& text, UINT32 fixedWidth, UINT32 fixedHeight, bool wordWrap);
-		static GUILabel* create(GUIWidget* parent, const CM::String& text, UINT32 fixedWidth, UINT32 fixedHeight, bool wordWrap, TextHorzAlign horzAlign, TextVertAlign vertAlign);
+		static GUILabel* create(GUIWidget* parent, const CM::String& text, TextHorzAlign horzAlign, TextVertAlign vertAlign = TVA_Top);
+		static GUILabel* create(GUIWidget* parent, const CM::String& text, UINT32 fixedWidth, UINT32 fixedHeight = 0, bool wordWrap = false);
+		static GUILabel* create(GUIWidget* parent, const CM::String& text, UINT32 fixedWidth, UINT32 fixedHeight, bool wordWrap, TextHorzAlign horzAlign, TextVertAlign vertAlign = TVA_Top);
 
 
 	protected:
 	protected:
 		~GUILabel();
 		~GUILabel();

+ 2 - 3
BansheeEngine/Include/BsGUIWindowFrame.h

@@ -11,7 +11,7 @@ namespace BansheeEngine
 	public:
 	public:
 		static const CM::String& getGUITypeName();
 		static const CM::String& getGUITypeName();
 
 
-		static GUIWindowFrame* create(GUIWidget* parent, const SpriteTexturePtr& texture);
+		static GUIWindowFrame* create(GUIWidget* parent);
 	protected:
 	protected:
 		~GUIWindowFrame();
 		~GUIWindowFrame();
 
 
@@ -37,8 +37,7 @@ namespace BansheeEngine
 			UINT32 maxNumQuads, UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const;
 			UINT32 maxNumQuads, UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const;
 	private:
 	private:
 		ImageSprite* mImageSprite;
 		ImageSprite* mImageSprite;
-		SpriteTexturePtr mTexture;
 
 
-		GUIWindowFrame(GUIWidget* parent, const SpriteTexturePtr& texture);
+		GUIWindowFrame(GUIWidget* parent);
 	};
 	};
 }
 }

+ 13 - 0
BansheeEngine/Source/BsEngineGUI.cpp

@@ -3,6 +3,7 @@
 
 
 #include "BsGUILabel.h"
 #include "BsGUILabel.h"
 #include "BsGUIWindowFrame.h"
 #include "BsGUIWindowFrame.h"
+#include "BsSpriteTexture.h"
 
 
 #include "CmFont.h"
 #include "CmFont.h"
 #include "CmFontImportOptions.h"
 #include "CmFontImportOptions.h"
@@ -16,10 +17,13 @@ namespace BansheeEngine
 	const String EngineGUI::DefaultFontPath = "C:\\arial.ttf";
 	const String EngineGUI::DefaultFontPath = "C:\\arial.ttf";
 	const UINT32 EngineGUI::DefaultFontSize = 12;
 	const UINT32 EngineGUI::DefaultFontSize = 12;
 
 
+	const CM::String EngineGUI::WindowFramePrimaryTexture = "C:\\WindowFrameTest.bmp";
+
 	EngineGUI::EngineGUI()
 	EngineGUI::EngineGUI()
 	{
 	{
 		// TODO - Normally I want to load this from some file
 		// TODO - Normally I want to load this from some file
 		
 		
+		// Label
 		// TODO - Instead of importing font every time, try to save a resource and then just load it?
 		// TODO - Instead of importing font every time, try to save a resource and then just load it?
 		HFont font;
 		HFont font;
 
 
@@ -42,6 +46,15 @@ namespace BansheeEngine
 		labelStyle.fontSize = DefaultFontSize;
 		labelStyle.fontSize = DefaultFontSize;
 
 
 		mSkin.setStyle(GUILabel::getGUITypeName(), labelStyle);
 		mSkin.setStyle(GUILabel::getGUITypeName(), labelStyle);
+
+		// Window frame
+		HTexture windowFrameTex = static_resource_cast<Texture>(Importer::instance().import(WindowFramePrimaryTexture));
+		windowFrameTex.waitUntilLoaded();
+
+		GUIElementStyle windowFrameStyle;
+		windowFrameStyle.normal.texture = SpriteTexturePtr(CM_NEW(SpriteTexture, PoolAlloc) SpriteTexture(windowFrameTex), &MemAllocDeleter<SpriteTexture, PoolAlloc>::deleter);
+
+		mSkin.setStyle(GUIWindowFrame::getGUITypeName(), windowFrameStyle);
 	}
 	}
 
 
 }
 }

+ 17 - 7
BansheeEngine/Source/BsGUIWindowFrame.cpp

@@ -15,8 +15,8 @@ namespace BansheeEngine
 		return name;
 		return name;
 	}
 	}
 
 
-	GUIWindowFrame::GUIWindowFrame(GUIWidget* parent, const SpriteTexturePtr& texture)
-		:GUIElement(parent), mTexture(texture)
+	GUIWindowFrame::GUIWindowFrame(GUIWidget* parent)
+		:GUIElement(parent)
 	{
 	{
 		const GUISkin* skin = parent->getGUISkin();
 		const GUISkin* skin = parent->getGUISkin();
 
 
@@ -24,9 +24,19 @@ namespace BansheeEngine
 		mImageSprite = CM_NEW(ImageSprite, PoolAlloc) ImageSprite();
 		mImageSprite = CM_NEW(ImageSprite, PoolAlloc) ImageSprite();
 
 
 		IMAGE_SPRITE_DESC desc;
 		IMAGE_SPRITE_DESC desc;
-		desc.texture = texture;
-		desc.width = texture->getTexture()->getWidth();
-		desc.height = texture->getTexture()->getHeight();
+		desc.texture = mStyle->normal.texture;
+
+		if(desc.texture != nullptr)
+		{
+			desc.width = desc.texture->getTexture()->getWidth();
+			desc.height = desc.texture->getTexture()->getHeight();
+		}
+
+		desc.borderLeft = mStyle->border.left;
+		desc.borderRight = mStyle->border.right;
+		desc.borderTop = mStyle->border.top;
+		desc.borderBottom = mStyle->border.bottom;
+
 		mImageSprite->update(desc);
 		mImageSprite->update(desc);
 
 
 		mBounds = mImageSprite->getBounds();
 		mBounds = mImageSprite->getBounds();
@@ -37,9 +47,9 @@ namespace BansheeEngine
 		CM_DELETE(mImageSprite, ImageSprite, PoolAlloc);
 		CM_DELETE(mImageSprite, ImageSprite, PoolAlloc);
 	}
 	}
 
 
-	GUIWindowFrame* GUIWindowFrame::create(GUIWidget* parent, const SpriteTexturePtr& texture)
+	GUIWindowFrame* GUIWindowFrame::create(GUIWidget* parent)
 	{
 	{
-		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent, texture);
+		return CM_NEW(GUIWindowFrame, PoolAlloc) GUIWindowFrame(parent);
 	}
 	}
 
 
 	UINT32 GUIWindowFrame::getNumRenderElements() const
 	UINT32 GUIWindowFrame::getNumRenderElements() const

+ 0 - 1
BansheeEngine/Source/BsImageSprite.cpp

@@ -73,7 +73,6 @@ namespace BansheeEngine
 		Vector2 uvOffset(0.0f, 0.0f);
 		Vector2 uvOffset(0.0f, 0.0f);
 		Vector2 uvScale(1.0f, 1.0f);
 		Vector2 uvScale(1.0f, 1.0f);
 		
 		
-
 		if(useScale9Grid)
 		if(useScale9Grid)
 		{
 		{
 			UINT32 leftBorder = desc.borderLeft;
 			UINT32 leftBorder = desc.borderLeft;

+ 1 - 8
CamelotClient/CamelotClient.cpp

@@ -82,12 +82,7 @@ int CALLBACK WinMain(
 	HSceneObject testTextGO = SceneObject::create("TestText");
 	HSceneObject testTextGO = SceneObject::create("TestText");
 	GameObjectHandle<TestTextSprite> textSprite = testTextGO->addComponent<TestTextSprite>();
 	GameObjectHandle<TestTextSprite> textSprite = testTextGO->addComponent<TestTextSprite>();
 
 
-	HTexture windowFrameTex = static_resource_cast<Texture>(Importer::instance().import("C:\\WindowFrameTest.bmp"));
-	gResources().create(windowFrameTex, "C:\\WindowFrameTest.tex", true);
-
-	windowFrameTex.waitUntilLoaded();
-
-	textSprite->init(camera, "Testing in a new row, does this work?", windowFrameTex);
+	textSprite->init(camera, "Testing in a new row, does this work?");
 
 
 #if defined DX9
 #if defined DX9
 	///////////////// HLSL 9 SHADERS //////////////////////////
 	///////////////// HLSL 9 SHADERS //////////////////////////
@@ -295,14 +290,12 @@ int CALLBACK WinMain(
 	gResources().unload(fragProgRef);
 	gResources().unload(fragProgRef);
 	gResources().unload(vertProgRef);
 	gResources().unload(vertProgRef);
 	gResources().unload(testMaterial);
 	gResources().unload(testMaterial);
-	gResources().unload(windowFrameTex);
 
 
 	testMaterial.reset();
 	testMaterial.reset();
 	testTexRef.reset();
 	testTexRef.reset();
 	dbgMeshRef.reset();
 	dbgMeshRef.reset();
 	fragProgRef.reset();
 	fragProgRef.reset();
 	vertProgRef.reset();
 	vertProgRef.reset();
-	windowFrameTex.reset();
 
 
 	testModelGO->destroy();
 	testModelGO->destroy();
 	cameraGO->destroy();
 	cameraGO->destroy();

+ 3 - 3
CamelotClient/CmEditorWindow.cpp

@@ -38,7 +38,7 @@ namespace CamelotEditor
 		//// DEBUG ONLY - Skin should exist externally
 		//// DEBUG ONLY - Skin should exist externally
 		//mSkin = CM_NEW(GUISkin, GUIAlloc) GUISkin();
 		//mSkin = CM_NEW(GUISkin, GUIAlloc) GUISkin();
 
 
-		//OverlayManager::instance().attachOverlay(camera.get(), gui.get());		
+		OverlayManager::instance().attachOverlay(camera.get(), gui.get());		
 
 
 		//GUIElementStyle labelStyle;
 		//GUIElementStyle labelStyle;
 		//labelStyle.font = dbgFont;
 		//labelStyle.font = dbgFont;
@@ -48,8 +48,8 @@ namespace CamelotEditor
 
 
 		//gui->setSkin(mSkin);
 		//gui->setSkin(mSkin);
 		//// END DEBUG
 		//// END DEBUG
-
-		//gui->addLabel("Testing test");
+		gui->setSkin(&EngineGUI::instance().getSkin());
+		GUILabel::create(gui.get(), "Testing test", renderWindowDesc.width);
 	}
 	}
 
 
 	EditorWindow::~EditorWindow()
 	EditorWindow::~EditorWindow()

+ 3 - 4
CamelotClient/CmTestTextSprite.cpp

@@ -26,15 +26,14 @@ namespace CamelotFramework
 	{
 	{
 	}
 	}
 
 
-	void TestTextSprite::init(const HCamera& camera, const String& text, const HTexture& windowFrameTex)
+	void TestTextSprite::init(const HCamera& camera, const String& text)
 	{
 	{
 		OverlayManager::instance().attachOverlay(camera.get(), this);		
 		OverlayManager::instance().attachOverlay(camera.get(), this);		
 
 
 		setSkin(&EngineGUI::instance().getSkin());
 		setSkin(&EngineGUI::instance().getSkin());
-		GUILabel::create(this, text, 400, 400, true, THA_Right, TVA_Bottom);
 
 
-		SpriteTexturePtr frameSpriteTex(CM_NEW(SpriteTexture, PoolAlloc) SpriteTexture(windowFrameTex), &MemAllocDeleter<SpriteTexture, PoolAlloc>::deleter);
-		GUIWindowFrame::create(this, frameSpriteTex);
+		GUILabel::create(this, text, 400, 400, true, THA_Right, TVA_Bottom);
+		GUIWindowFrame::create(this);
 	}
 	}
 
 
 	void TestTextSprite::update()
 	void TestTextSprite::update()

+ 1 - 1
CamelotClient/CmTestTextSprite.h

@@ -14,6 +14,6 @@ namespace CamelotFramework
 
 
 		virtual void update();
 		virtual void update();
 
 
-		void init(const BS::HCamera& camera, const String& text, const HTexture& windowFrameTex);
+		void init(const BS::HCamera& camera, const String& text);
 	};
 	};
 }
 }