Explorar o código

Added a global engine GUI style in EngineGUI

Marko Pintera %!s(int64=12) %!d(string=hai) anos
pai
achega
66f2eb6b18

+ 2 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -147,6 +147,7 @@
   </ItemDefinitionGroup>
   <ItemGroup>
     <ClInclude Include="Include\BsApplication.h" />
+    <ClInclude Include="Include\BsEngineGUI.h" />
     <ClInclude Include="Include\BsPrerequisites.h" />
     <ClInclude Include="Include\BsGUIElement.h" />
     <ClInclude Include="Include\BsGUIElementStyle.h" />
@@ -175,6 +176,7 @@
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsApplication.cpp" />
+    <ClCompile Include="Source\BsEngineGUI.cpp" />
     <ClCompile Include="Source\BsGUIElement.cpp" />
     <ClCompile Include="Source\BsGUILabel.cpp" />
     <ClCompile Include="Source\BsGUIManager.cpp" />

+ 6 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -114,6 +114,9 @@
     <ClInclude Include="Include\BsGLBuiltinMaterialFactory.h">
       <Filter>Header Files</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsEngineGUI.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -179,5 +182,8 @@
     <ClCompile Include="Source\BsGUIWindowFrame.cpp">
       <Filter>Source Files\GUI</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsEngineGUI.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 4 - 0
BansheeEngine/Include/BsCamera.h

@@ -153,6 +153,7 @@ namespace BansheeEngine {
 		bool mCustomProjMatrix;
 		/// Have the frustum extents been manually set?
 		bool mFrustumExtentsManuallySet;
+		bool mIgnoreSceneRenderables;
 		/// Frustum extents
 		mutable float mLeft, mRight, mTop, mBottom;
 		
@@ -490,6 +491,9 @@ namespace BansheeEngine {
 		*/
 		virtual float getOrthoWindowWidth() const;
 
+		void setIgnoreSceneRenderables(bool value) { mIgnoreSceneRenderables = true; }
+		bool getIgnoreSceneRenderables() const { return mIgnoreSceneRenderables; }
+
         /** Project a sphere onto the near plane and get the bounding rectangle. 
         @param sphere The world-space sphere to project
         @param radius Radius of the sphere

+ 22 - 0
BansheeEngine/Include/BsEngineGUI.h

@@ -0,0 +1,22 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+#include "BsGUISkin.h"
+#include "CmModule.h"
+
+namespace BansheeEngine
+{
+	class BS_EXPORT EngineGUI : public CamelotFramework::Module<EngineGUI>
+	{
+	public:
+		EngineGUI();
+
+		const GUISkin& getSkin() const { return mSkin; }
+
+	private:
+		GUISkin mSkin;
+
+		static const CM::String DefaultFontPath;
+		static const UINT32 DefaultFontSize;
+	};
+}

+ 5 - 0
BansheeEngine/Source/BsApplication.cpp

@@ -6,6 +6,7 @@
 #include "BsD3D9BuiltinMaterialFactory.h"
 #include "BsD3D11BuiltinMaterialFactory.h"
 #include "BsGLBuiltinMaterialFactory.h"
+#include "BsEngineGUI.h"
 #include "CmApplication.h"
 
 using namespace CamelotFramework;
@@ -42,6 +43,8 @@ namespace BansheeEngine
 		BuiltinMaterialManager::instance().addFactory(CM_NEW(D3D11BuiltinMaterialFactory, GenAlloc) D3D11BuiltinMaterialFactory());
 		BuiltinMaterialManager::instance().addFactory(CM_NEW(GLBuiltinMaterialFactory, GenAlloc) GLBuiltinMaterialFactory());
 		BuiltinMaterialManager::instance().setActive(desc.renderSystem);
+
+		EngineGUI::startUp(new EngineGUI());
 	}
 
 	void Application::runMainLoop()
@@ -51,6 +54,8 @@ namespace BansheeEngine
 
 	void Application::shutDown()
 	{
+		EngineGUI::shutDown();
+
 		GUIMaterialManager::instance().forceReleaseAllMaterials();
 
 		BuiltinMaterialManager::shutDown();

+ 2 - 1
BansheeEngine/Source/BsCamera.cpp

@@ -65,7 +65,8 @@ namespace BansheeEngine
 		mRecalcVertexData(true),
 		mCustomViewMatrix(false),
 		mCustomProjMatrix(false),
-		mFrustumExtentsManuallySet(false)
+		mFrustumExtentsManuallySet(false),
+		mIgnoreSceneRenderables(false)
     {
 		updateView();
 		updateFrustum();

+ 47 - 0
BansheeEngine/Source/BsEngineGUI.cpp

@@ -0,0 +1,47 @@
+#include "BsEngineGUI.h"
+#include "BsGUIElementStyle.h"
+
+#include "BsGUILabel.h"
+#include "BsGUIWindowFrame.h"
+
+#include "CmFont.h"
+#include "CmFontImportOptions.h"
+#include "CmImporter.h"
+#include "CmRTTIType.h"
+
+using namespace CamelotFramework;
+
+namespace BansheeEngine
+{
+	const String EngineGUI::DefaultFontPath = "C:\\arial.ttf";
+	const UINT32 EngineGUI::DefaultFontSize = 12;
+
+	EngineGUI::EngineGUI()
+	{
+		// TODO - Normally I want to load this from some file
+		
+		// TODO - Instead of importing font every time, try to save a resource and then just load it?
+		HFont font;
+
+		{
+			ImportOptionsPtr fontImportOptions = Importer::instance().createImportOptions(DefaultFontPath);
+			if(rtti_is_of_type<FontImportOptions>(fontImportOptions))
+			{
+				FontImportOptions* importOptions = static_cast<FontImportOptions*>(fontImportOptions.get());
+
+				vector<CamelotFramework::UINT32>::type fontSizes;
+				fontSizes.push_back(DefaultFontSize);
+				importOptions->setFontSizes(fontSizes);
+			}
+
+			font = Importer::instance().import(DefaultFontPath, fontImportOptions);
+		}
+
+		GUIElementStyle labelStyle;
+		labelStyle.font = font;
+		labelStyle.fontSize = DefaultFontSize;
+
+		mSkin.setStyle(GUILabel::getGUITypeName(), labelStyle);
+	}
+
+}

+ 4 - 1
BansheeForwardRenderer/Source/BsForwardRenderer.cpp

@@ -53,7 +53,10 @@ namespace BansheeEngine
 
 	void ForwardRenderer::render(const HCamera& camera) 
 	{
-		vector<HRenderable>::type allRenderables = gSceneManager().getVisibleRenderables(camera);
+		vector<HRenderable>::type allRenderables;
+		
+		if(!camera->getIgnoreSceneRenderables())
+			allRenderables = gSceneManager().getVisibleRenderables(camera);
 
 		RenderContext& renderContext = gMainRC();
 		renderContext.setViewport(camera->getViewport());

+ 3 - 19
CamelotClient/CamelotClient.cpp

@@ -27,6 +27,7 @@
 #include "CmDebugCamera.h"
 #include "CmTestTextSprite.h"
 #include "CmEditorWindow.h"
+#include "CmRTTIType.h"
 
 #define DX11
 //#define DX9
@@ -81,28 +82,12 @@ int CALLBACK WinMain(
 	HSceneObject testTextGO = SceneObject::create("TestText");
 	GameObjectHandle<TestTextSprite> textSprite = testTextGO->addComponent<TestTextSprite>();
 
-	HFont font;
-	
-	{
-		ImportOptionsPtr fontImportOptions = Importer::instance().createImportOptions("C:\\arial.ttf");
-		if(rtti_is_of_type<FontImportOptions>(fontImportOptions))
-		{
-			FontImportOptions* importOptions = static_cast<FontImportOptions*>(fontImportOptions.get());
-
-			vector<CamelotFramework::UINT32>::type fontSizes;
-			fontSizes.push_back(12);
-			importOptions->setFontSizes(fontSizes);
-		}
-
-		font = Importer::instance().import("C:\\arial.ttf", fontImportOptions);
-	}
-
 	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?", font, 12, windowFrameTex);
+	textSprite->init(camera, "Testing in a new row, does this work?", windowFrameTex);
 
 #if defined DX9
 	///////////////// HLSL 9 SHADERS //////////////////////////
@@ -292,7 +277,7 @@ int CALLBACK WinMain(
 	//// Set the new state for the flag
 	//_CrtSetDbgFlag( tmpFlag );
 	
-	EditorWindow* newWindow = new EditorWindow("Test window", font, 12);
+	EditorWindow* newWindow = new EditorWindow("Test window");
 
 	gBansheeApp().runMainLoop();
 
@@ -312,7 +297,6 @@ int CALLBACK WinMain(
 	gResources().unload(testMaterial);
 	gResources().unload(windowFrameTex);
 
-	font.reset();
 	testMaterial.reset();
 	testTexRef.reset();
 	dbgMeshRef.reset();

+ 4 - 2
CamelotClient/CmEditorWindow.cpp

@@ -7,13 +7,14 @@
 #include "BsGUISkin.h"
 #include "BsOverlayManager.h"
 #include "BsCamera.h"
+#include "BsEngineGUI.h"
 
 using namespace CamelotFramework;
 using namespace BansheeEngine;
 
 namespace CamelotEditor
 {
-	EditorWindow::EditorWindow(const String& name, const HFont& dbgFont, CM::UINT32 dbgFontSize)
+	EditorWindow::EditorWindow(const String& name)
 	{
 		RENDER_WINDOW_DESC renderWindowDesc;
 		renderWindowDesc.width = 200;
@@ -26,12 +27,13 @@ namespace CamelotEditor
 		mRenderWindow = RenderWindow::create(renderWindowDesc, gApplication().getPrimaryRenderWindow());
 
 		HSceneObject so = SceneObject::create("EditorWindow-" + name);
-		//HGUIWidget gui = so->addComponent<GUIWidget>();
+		HGUIWidget gui = so->addComponent<GUIWidget>();
 		HCamera camera = so->addComponent<Camera>();
 
 		camera->init(mRenderWindow, 0.0f, 0.0f, 1.0f, 1.0f, 0);
 		camera->setNearClipDistance(5);
 		camera->setAspectRatio(1.0f);
+		camera->setIgnoreSceneRenderables(true);
 		
 		//// DEBUG ONLY - Skin should exist externally
 		//mSkin = CM_NEW(GUISkin, GUIAlloc) GUISkin();

+ 1 - 1
CamelotClient/CmEditorWindow.h

@@ -7,7 +7,7 @@ namespace CamelotEditor
 	class EditorWindow
 	{
 	public:
-		EditorWindow(const CM::String& name, const CM::HFont& dbgFont, CamelotFramework::UINT32 dbgFontSize);
+		EditorWindow(const CM::String& name);
 		virtual ~EditorWindow();
 
 	private:

+ 4 - 13
CamelotClient/CmTestTextSprite.cpp

@@ -11,35 +11,26 @@
 #include "BsGUISkin.h"
 #include "BsOverlayManager.h"
 #include "BsSpriteTexture.h"
+#include "BsEngineGUI.h"
 
 using namespace BansheeEngine;
 
 namespace CamelotFramework
 {
 	TestTextSprite::TestTextSprite(const HSceneObject& parent)
-		:GUIWidget(parent), mSkin(nullptr)
+		:GUIWidget(parent)
 	{
 	}
 
 	TestTextSprite::~TestTextSprite()
 	{
-		if(mSkin != nullptr)
-			CM_DELETE(mSkin, GUISkin, PoolAlloc);
 	}
 
-	void TestTextSprite::init(const HCamera& camera, const String& text, HFont font, UINT32 fontSize, const HTexture& windowFrameTex)
+	void TestTextSprite::init(const HCamera& camera, const String& text, const HTexture& windowFrameTex)
 	{
-		mSkin = CM_NEW(GUISkin, PoolAlloc) GUISkin();
-
 		OverlayManager::instance().attachOverlay(camera.get(), this);		
 
-		GUIElementStyle labelStyle;
-		labelStyle.font = font;
-		labelStyle.fontSize = fontSize;
-
-		mSkin->setStyle(GUILabel::getGUITypeName(), labelStyle);
-
-		setSkin(mSkin);
+		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);

+ 1 - 3
CamelotClient/CmTestTextSprite.h

@@ -9,13 +9,11 @@ namespace CamelotFramework
 		friend class CM::SceneObject;
 
 		TestTextSprite(const HSceneObject& parent);
-
-		BansheeEngine::GUISkin* mSkin;
 	public:
 		~TestTextSprite();
 
 		virtual void update();
 
-		void init(const BS::HCamera& camera, const String& text, HFont font, UINT32 fontSize, const HTexture& windowFrameTex);
+		void init(const BS::HCamera& camera, const String& text, const HTexture& windowFrameTex);
 	};
 }

+ 0 - 24
CamelotCore/Include/CmPrerequisites.h

@@ -280,30 +280,6 @@ namespace CamelotFramework
 		TID_PixelData = 1062,
 		TID_GpuResourceData = 1063
 	};
-
-	/**
-	 * @brief	Returns true if the provided object can be safely cast into type T.
-	 */
-	template<class T>
-	bool rtti_is_of_type(IReflectable* object)
-	{
-		BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotFramework::IReflectable, T>::value), 
-			"Invalid data type for type checking. It needs to derive from CamelotFramework::IReflectable.");
-
-		return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
-	}
-
-	/**
-	 * @brief	Returns true if the provided object can be safely cast into type T.
-	 */
-	template<class T>
-	bool rtti_is_of_type(std::shared_ptr<IReflectable> object)
-	{
-		BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotFramework::IReflectable, T>::value), 
-			"Invalid data type for type checking. It needs to derive from CamelotFramework::IReflectable.");
-
-		return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
-	}
 }
 
 /************************************************************************/

+ 24 - 0
CamelotUtility/Include/CmRTTIType.h

@@ -664,4 +664,28 @@ namespace CamelotFramework
 
 	template <typename Type, typename BaseType, typename MyRTTIType>
 	InitRTTIOnStart<Type, BaseType> RTTIType<Type, BaseType, MyRTTIType>::initOnStart;
+
+	/**
+	 * @brief	Returns true if the provided object can be safely cast into type T.
+	 */
+	template<class T>
+	bool rtti_is_of_type(IReflectable* object)
+	{
+		BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotFramework::IReflectable, T>::value), 
+			"Invalid data type for type checking. It needs to derive from CamelotFramework::IReflectable.");
+
+		return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
+	}
+
+	/**
+	 * @brief	Returns true if the provided object can be safely cast into type T.
+	 */
+	template<class T>
+	bool rtti_is_of_type(std::shared_ptr<IReflectable> object)
+	{
+		BOOST_STATIC_ASSERT_MSG((boost::is_base_of<CamelotFramework::IReflectable, T>::value), 
+			"Invalid data type for type checking. It needs to derive from CamelotFramework::IReflectable.");
+
+		return object->getTypeId() == T::getRTTIStatic()->getRTTIId();
+	}
 }