Browse Source

Disabled linear filtering
Some GUI work

Marko Pintera 12 years ago
parent
commit
9938d21273

+ 2 - 0
BansheeEngine/BansheeEngine.vcxproj

@@ -157,6 +157,7 @@
     <ClInclude Include="Include\BsGUILayoutY.h" />
     <ClInclude Include="Include\BsGUISpace.h" />
     <ClInclude Include="Include\BsGUITexture.h" />
+    <ClInclude Include="Include\BsGUITitleBar.h" />
     <ClInclude Include="Include\BsPrerequisites.h" />
     <ClInclude Include="Include\BsGUIElement.h" />
     <ClInclude Include="Include\BsGUIElementStyle.h" />
@@ -198,6 +199,7 @@
     <ClCompile Include="Source\BsGUIMaterialManager.cpp" />
     <ClCompile Include="Source\BsGUISkin.cpp" />
     <ClCompile Include="Source\BsGUITexture.cpp" />
+    <ClCompile Include="Source\BsGUITitleBar.cpp" />
     <ClCompile Include="Source\BsGUIWidget.cpp" />
     <ClCompile Include="Source\BsGUIWindowFrame.cpp" />
     <ClCompile Include="Source\BsImageSprite.cpp" />

+ 6 - 0
BansheeEngine/BansheeEngine.vcxproj.filters

@@ -147,6 +147,9 @@
     <ClInclude Include="Include\BsGUITexture.h">
       <Filter>Header Files\GUI</Filter>
     </ClInclude>
+    <ClInclude Include="Include\BsGUITitleBar.h">
+      <Filter>Header Files\GUI</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ClCompile Include="Source\BsGUIElement.cpp">
@@ -239,5 +242,8 @@
     <ClCompile Include="Source\BsGUITexture.cpp">
       <Filter>Source Files\GUI</Filter>
     </ClCompile>
+    <ClCompile Include="Source\BsGUITitleBar.cpp">
+      <Filter>Source Files\GUI</Filter>
+    </ClCompile>
   </ItemGroup>
 </Project>

+ 11 - 1
BansheeEngine/Include/BsEngineGUI.h

@@ -21,9 +21,19 @@ namespace BansheeEngine
 		static const CM::String DefaultFontPath;
 		static const UINT32 DefaultFontSize;
 
-		static const CM::String WindowFramePrimaryTexture;
 		static const CM::String WindowBackgroundTexture;
 
+		static const CM::String WindowFrameNormal;
+		static const CM::String WindowFrameFocused;
+
+		static const CM::String WindowTitleBarBg;
+
+		static const CM::String WindowCloseButtonNormal;
+		static const CM::String WindowCloseButtonHover;
+
+		static const CM::String WindowMinButtonNormal;
+		static const CM::String WindowMinButtonHover;
+
 		static const CM::String ButtonNormalTex;
 		static const CM::String ButtonHoverTex;
 	};

+ 59 - 0
BansheeEngine/Include/BsGUITitleBar.h

@@ -0,0 +1,59 @@
+#pragma once
+
+#include "BsPrerequisites.h"
+#include "BsGUIElement.h"
+#include "BsImageSprite.h"
+
+namespace BansheeEngine
+{
+	class BS_EXPORT GUITitleBar : public GUIElement
+	{
+	public:
+		static const CM::String& getGUITypeName();
+
+		static GUITitleBar* create(GUIWidget& parent, const CM::String& title, const GUIElementStyle* style = nullptr);
+		static GUITitleBar* create(GUIWidget& parent, const CM::String& title, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style = nullptr);
+	protected:
+		~GUITitleBar();
+
+		/**
+		 * @copydoc GUIElement::getNumRenderElements()
+		 */
+		virtual UINT32 getNumRenderElements() const;
+
+		/**
+		 * @copydoc GUIElement::getMaterial()
+		 */
+		virtual const CM::HMaterial& getMaterial(UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::getNumQuads()
+		 */
+		virtual UINT32 getNumQuads(UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::fillBuffer()
+		 */
+		virtual void fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, 
+			UINT32 maxNumQuads, UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const;
+
+		/**
+		 * @copydoc GUIElement::updateRenderElementsInternal()
+		 */
+		virtual void updateRenderElementsInternal();
+
+		virtual UINT32 _getOptimalWidth() const;
+		virtual UINT32 _getOptimalHeight() const;
+
+		virtual UINT32 _getRenderElementDepth(UINT32 renderElementIdx) const;
+	private:
+		ImageSprite* mImageSprite;
+		TextSprite* mTextSprite;
+		UINT32 mNumImageRenderElements;
+
+		IMAGE_SPRITE_DESC mImageDesc;
+		CM::String mText;
+
+		GUITitleBar(GUIWidget& parent, const GUIElementStyle* style, const CM::String& title, const GUILayoutOptions& layoutOptions);
+	};
+}

+ 2 - 2
BansheeEngine/Source/BsD3D11BuiltinMaterialFactory.cpp

@@ -19,8 +19,8 @@ namespace BansheeEngine
 		initDebugDrawShader();
 
 		SAMPLER_STATE_DESC ssDesc;
-		ssDesc.magFilter = FO_LINEAR;
-		ssDesc.minFilter = FO_LINEAR;
+		ssDesc.magFilter = FO_POINT;
+		ssDesc.minFilter = FO_POINT;
 		ssDesc.mipFilter = FO_POINT;
 
 		mGUISamplerState = SamplerState::create(ssDesc);

+ 2 - 2
BansheeEngine/Source/BsD3D9BuiltinMaterialFactory.cpp

@@ -19,8 +19,8 @@ namespace BansheeEngine
 		initDebugDrawShader();
 
 		SAMPLER_STATE_DESC ssDesc;
-		ssDesc.magFilter = FO_LINEAR;
-		ssDesc.minFilter = FO_LINEAR;
+		ssDesc.magFilter = FO_POINT;
+		ssDesc.minFilter = FO_POINT;
 		ssDesc.mipFilter = FO_POINT;
 
 		mGUISamplerState = SamplerState::create(ssDesc);

+ 23 - 6
BansheeEngine/Source/BsEngineGUI.cpp

@@ -19,12 +19,22 @@ namespace BansheeEngine
 	const String EngineGUI::DefaultFontPath = "C:\\arial.ttf";
 	const UINT32 EngineGUI::DefaultFontSize = 10;
 
-	const String EngineGUI::WindowFramePrimaryTexture = "C:\\WindowFrame.psd";
 	const String EngineGUI::WindowBackgroundTexture = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowBgTile.psd";
 
 	const String EngineGUI::ButtonNormalTex = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\ButtonNormal.psd";
 	const String EngineGUI::ButtonHoverTex = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\ButtonHover.psd";
 
+	const String EngineGUI::WindowFrameNormal = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowFrameNormal.psd";
+	const String EngineGUI::WindowFrameFocused = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowFrameFocused.psd";
+
+	const String EngineGUI::WindowTitleBarBg = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowTitleBarBg.psd";
+
+	const String EngineGUI::WindowCloseButtonNormal = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowCloseBtnNormal.psd";
+	const String EngineGUI::WindowCloseButtonHover = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowCloseBtnHover.psd";
+
+	const String EngineGUI::WindowMinButtonNormal = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowMinBtnNormal.psd";
+	const String EngineGUI::WindowMinButtonHover = "C:\\Projects\\BansheeEngine\\Data\\Editor\\Skin\\WindowMinBtnHover.psd";
+
 	EngineGUI::EngineGUI()
 	{
 		// TODO - Normally I want to load this from some file
@@ -58,11 +68,12 @@ namespace BansheeEngine
 		mSkin.setStyle(GUILabel::getGUITypeName(), labelStyle);
 
 		// Window frame
-		HTexture windowFrameTex = static_resource_cast<Texture>(Importer::instance().import(WindowFramePrimaryTexture));
-		windowFrameTex.waitUntilLoaded();
+		HTexture windowFrameNormalTex = static_resource_cast<Texture>(Importer::instance().import(WindowFrameNormal));
+		HTexture windowFrameFocusedTex = static_resource_cast<Texture>(Importer::instance().import(WindowFrameFocused));
 
 		GUIElementStyle windowFrameStyle;
-		windowFrameStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowFrameTex));
+		windowFrameStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowFrameNormalTex));
+		windowFrameStyle.focused.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowFrameFocusedTex));
 		windowFrameStyle.border.left = 1;
 		windowFrameStyle.border.right = 1;
 		windowFrameStyle.border.top = 1;
@@ -73,8 +84,6 @@ namespace BansheeEngine
 		// Button
 		HTexture buttonNormalTex = static_resource_cast<Texture>(Importer::instance().import(ButtonNormalTex));
 		HTexture buttonHoverTex = static_resource_cast<Texture>(Importer::instance().import(ButtonHoverTex));
-		buttonNormalTex.waitUntilLoaded();
-		buttonHoverTex.waitUntilLoaded();
 
 		GUIElementStyle buttonStyle;
 		buttonStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(buttonNormalTex));
@@ -102,6 +111,14 @@ namespace BansheeEngine
 		// Window background texture
 		HTexture windowBgTexture = static_resource_cast<Texture>(Importer::instance().import(WindowBackgroundTexture));
 		mWindowBgTex = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowBgTexture));
+
+		// Window title bar background
+		HTexture windowTitleBarBg = static_resource_cast<Texture>(Importer::instance().import(WindowTitleBarBg));
+
+		GUIElementStyle titleBarStyle;
+		titleBarStyle.normal.texture = cm_shared_ptr<SpriteTexture, PoolAlloc>(std::cref(windowTitleBarBg));
+		titleBarStyle.fixedHeight = true;
+		titleBarStyle.height = 11;
 	}
 
 }

+ 2 - 2
BansheeEngine/Source/BsGLBuiltinMaterialFactory.cpp

@@ -19,8 +19,8 @@ namespace BansheeEngine
 		initDebugDrawShader();
 
 		SAMPLER_STATE_DESC ssDesc;
-		ssDesc.magFilter = FO_LINEAR;
-		ssDesc.minFilter = FO_LINEAR;
+		ssDesc.magFilter = FO_POINT;
+		ssDesc.minFilter = FO_POINT;
 		ssDesc.mipFilter = FO_POINT;
 
 		mGUISamplerState = SamplerState::create(ssDesc);

+ 167 - 0
BansheeEngine/Source/BsGUITitleBar.cpp

@@ -0,0 +1,167 @@
+#include "BsGUITitleBar.h"
+#include "BsImageSprite.h"
+#include "BsGUIWidget.h"
+#include "BsGUISkin.h"
+#include "BsSpriteTexture.h"
+#include "BsTextSprite.h"
+#include "BsGUILayoutOptions.h"
+#include "BsGUIMouseEvent.h"
+#include "CmTexture.h"
+
+using namespace CamelotFramework;
+
+namespace BansheeEngine
+{
+	const String& GUITitleBar::getGUITypeName()
+	{
+		static String name = "TitleBar";
+		return name;
+	}
+
+	GUITitleBar::GUITitleBar(GUIWidget& parent, const GUIElementStyle* style, const String& title, const GUILayoutOptions& layoutOptions)
+		:GUIElement(parent, style, layoutOptions), mText(title), mNumImageRenderElements(0)
+	{
+		mImageSprite = cm_new<ImageSprite, PoolAlloc>();
+		mTextSprite = cm_new<TextSprite, PoolAlloc>();
+
+		mImageDesc.texture = mStyle->normal.texture;
+
+		if(mImageDesc.texture != nullptr)
+		{
+			mImageDesc.width = mImageDesc.texture->getTexture()->getWidth();
+			mImageDesc.height = mImageDesc.texture->getTexture()->getHeight();
+		}
+
+		mImageDesc.borderLeft = mStyle->border.left;
+		mImageDesc.borderRight = mStyle->border.right;
+		mImageDesc.borderTop = mStyle->border.top;
+		mImageDesc.borderBottom = mStyle->border.bottom;
+	}
+
+	GUITitleBar::~GUITitleBar()
+	{
+		cm_delete<PoolAlloc>(mTextSprite);
+		cm_delete<PoolAlloc>(mImageSprite);
+	}
+
+	GUITitleBar* GUITitleBar::create(GUIWidget& parent, const String& title, const GUIElementStyle* style)
+	{
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getGUISkin();
+			style = skin->getStyle(getGUITypeName());
+		}
+
+		return new (cm_alloc<GUITitleBar, PoolAlloc>()) GUITitleBar(parent, style, title, getDefaultLayoutOptions(style));
+	}
+
+	GUITitleBar* GUITitleBar::create(GUIWidget& parent, const String& title, const GUILayoutOptions& layoutOptions, const GUIElementStyle* style)
+	{
+		if(style == nullptr)
+		{
+			const GUISkin* skin = parent.getGUISkin();
+			style = skin->getStyle(getGUITypeName());
+		}
+
+		return new (cm_alloc<GUITitleBar, PoolAlloc>()) GUITitleBar(parent, style, title, layoutOptions);
+	}
+
+	UINT32 GUITitleBar::getNumRenderElements() const
+	{
+		UINT32 numElements = mImageSprite->getNumRenderElements();
+		numElements += mTextSprite->getNumRenderElements();
+
+		return numElements;
+	}
+
+	const HMaterial& GUITitleBar::getMaterial(UINT32 renderElementIdx) const
+	{
+		if(renderElementIdx >= mNumImageRenderElements)
+			return mTextSprite->getMaterial(mNumImageRenderElements - renderElementIdx);
+		else
+			return mImageSprite->getMaterial(renderElementIdx);
+	}
+
+	UINT32 GUITitleBar::getNumQuads(UINT32 renderElementIdx) const
+	{
+		UINT32 numQuads = 0;
+		if(renderElementIdx >= mNumImageRenderElements)
+			numQuads = mTextSprite->getNumQuads(mNumImageRenderElements - renderElementIdx);
+		else
+			numQuads = mImageSprite->getNumQuads(renderElementIdx);
+
+		return numQuads;
+	}
+
+	void GUITitleBar::updateRenderElementsInternal()
+	{		
+		mImageDesc.offset = mOffset;
+		mImageDesc.width = mWidth;
+		mImageDesc.height = mHeight;
+		mImageDesc.clipRect = mClipRect;
+
+		mImageSprite->update(mImageDesc);
+		mBounds = mImageSprite->getBounds();
+		mNumImageRenderElements = mImageSprite->getNumRenderElements();
+
+		TEXT_SPRITE_DESC textDesc;
+		textDesc.text = mText;
+		textDesc.font = mStyle->font;
+		textDesc.fontSize = mStyle->fontSize;
+
+		Rect contentBounds = mBounds;
+
+		contentBounds.x += mStyle->margins.left + mStyle->contentOffset.left;
+		contentBounds.y += mStyle->margins.top + mStyle->contentOffset.top;
+		contentBounds.width = (UINT32)std::max(0, (INT32)contentBounds.width - 
+			(INT32)(mStyle->margins.left + mStyle->margins.right + mStyle->contentOffset.left + mStyle->contentOffset.right));
+		contentBounds.height = (UINT32)std::max(0, (INT32)contentBounds.height - 
+			(INT32)(mStyle->margins.top + mStyle->margins.bottom + mStyle->contentOffset.top + mStyle->contentOffset.bottom));
+
+		textDesc.offset = Int2(contentBounds.x, contentBounds.y);
+		textDesc.width = contentBounds.width;
+		textDesc.height = contentBounds.height;
+		textDesc.clipRect = Rect(0, 0, textDesc.width, textDesc.height);
+		textDesc.horzAlign = mStyle->textHorzAlign;
+		textDesc.vertAlign = mStyle->textVertAlign;
+
+		mTextSprite->update(textDesc);
+	}
+
+	UINT32 GUITitleBar::_getOptimalWidth() const
+	{
+		if(mImageDesc.texture != nullptr)
+		{
+			return mImageDesc.texture->getTexture()->getWidth();
+		}
+
+		return 0;
+	}
+
+	UINT32 GUITitleBar::_getOptimalHeight() const
+	{
+		if(mImageDesc.texture != nullptr)
+		{
+			return mImageDesc.texture->getTexture()->getHeight();
+		}
+
+		return 0;
+	}
+
+	UINT32 GUITitleBar::_getRenderElementDepth(UINT32 renderElementIdx) const
+	{
+		if(renderElementIdx >= mNumImageRenderElements)
+			return _getDepth();
+		else
+			return _getDepth() + 1;
+	}
+
+	void GUITitleBar::fillBuffer(UINT8* vertices, UINT8* uv, UINT32* indices, UINT32 startingQuad, UINT32 maxNumQuads, 
+		UINT32 vertexStride, UINT32 indexStride, UINT32 renderElementIdx) const
+	{
+		if(renderElementIdx >= mNumImageRenderElements)
+			mTextSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, mNumImageRenderElements - renderElementIdx);
+		else
+			mImageSprite->fillBuffer(vertices, uv, indices, startingQuad, maxNumQuads, vertexStride, indexStride, renderElementIdx);
+	}
+}

+ 10 - 4
CamelotClient/CmEditorWindow.cpp

@@ -57,9 +57,7 @@ namespace BansheeEditor
 		mDbgLabel = GUILabel::create(*mGUI, "Testing test");
 		/*layout.addElement(mDbgLabel);*/
 
-		GUIArea* mainArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 1);
-		GUILayout& otherLayout = mainArea->getLayout();
-
+		
 		//GUIFlexibleSpace& space4 = otherLayout.addFlexibleSpace();
 		//otherLayout.addElement(mDbgLabel);
 
@@ -67,11 +65,19 @@ namespace BansheeEditor
 		//GUIFlexibleSpace& space3 = otherLayout.addFlexibleSpace();
 		//otherLayout.addElement(GUIWindowFrame::create(*mGUI, GUILayoutOptions::fixed(100, 100)));
 		//GUIFixedSpace& space2 = otherLayout.addSpace(10);
-		otherLayout.addElement(GUIButton::create(*mGUI, "Test"));
+		//otherLayout.addElement(GUIButton::create(*mGUI, "Test"));
 		//otherLayout.addElement(GUIWindowFrame::create(*mGUI));
 		
 		GUIArea* backgroundArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 2000);
 		backgroundArea->getLayout().addElement(GUITexture::create(*mGUI, EngineGUI::instance().getWindowBgTex(), GUIImageScaleMode::RepeatToFit, GUILayoutOptions::expandableXY()));
+
+		GUIArea* windowFrameArea = GUIArea::create(*mGUI, 0, 0, 0, 0, 1999);
+		windowFrameArea->getLayout().addElement(GUIWindowFrame::create(*mGUI));
+
+		//GUIArea* titleBarBackgroundArea = GUIArea::create(*mGUI, 0, 1, 0, 11, 1999);
+		//titleBarBackgroundArea->getLayout().addSpace(1);
+		//titleBarBackgroundArea->getLayout().addElement(GUITexture::create(*mGUI, GUIImageScaleMode::RepeatToFit, GUILayoutOptions::expandableXY(), mGUI->getGUISkin()->getStyle("TitleBarBg")));
+		//titleBarBackgroundArea->getLayout().addSpace(1);
 	}
 
 	EditorWindow::~EditorWindow()