changeset 17:4951acfe92fc

Reworking GUI system
author koryspansel <koryspansel@bendbroadband.com>
date Wed, 14 Sep 2011 13:33:22 -0700
parents 88f7c22e7b45
children 33cb6979ac51
files LightClone/LightClone.vcproj LightClone/Source/GuiContainer.cpp LightClone/Source/GuiContainer.h LightClone/Source/GuiElement.cpp LightClone/Source/GuiElement.h LightClone/Source/GuiInterface.cpp LightClone/Source/GuiInterface.h LightClone/Source/GuiLabel.cpp LightClone/Source/GuiLabel.h LightClone/Source/World.cpp LightClone/Source/World.h
diffstat 11 files changed, 279 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/LightClone/LightClone.vcproj	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/LightClone.vcproj	Wed Sep 14 13:33:22 2011 -0700
@@ -391,6 +391,14 @@
 				>
 			</File>
 			<File
+				RelativePath=".\Source\GuiLabel.cpp"
+				>
+			</File>
+			<File
+				RelativePath=".\Source\GuiLabel.h"
+				>
+			</File>
+			<File
 				RelativePath=".\Source\InputManager.h"
 				>
 			</File>
--- a/LightClone/Source/GuiContainer.cpp	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/Source/GuiContainer.cpp	Wed Sep 14 13:33:22 2011 -0700
@@ -12,6 +12,19 @@
 }
 
 /*
+ * ~GuiContainer
+ */
+GuiContainer::~GuiContainer()
+{
+	for(uint32 i = 0; i < kChildren.GetSize(); ++i)
+	{
+		delete kChildren[i];
+	}
+
+	kChildren.Clear();
+}
+
+/*
  * Initialize
  */
 ErrorCode GuiContainer::Initialize(ResourceManager* pResourceManager)
@@ -35,8 +48,6 @@
 	{
 		kChildren[i]->Terminate();
 	}
-
-	kChildren.Clear();
 }
 
 /*
@@ -79,6 +90,14 @@
 }
 
 /*
+ * Add
+ */
+ErrorCode GuiContainer::Add(GuiElement* pElement)
+{
+	return kChildren.Add(pElement);
+}
+
+/*
  * Layout
  */
 void GuiContainer::Layout(GuiElementList& kElements)
--- a/LightClone/Source/GuiContainer.h	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/Source/GuiContainer.h	Wed Sep 14 13:33:22 2011 -0700
@@ -26,6 +26,11 @@
 	GuiContainer();
 
 	/*
+	 * ~GuiContainer
+	 */
+	~GuiContainer();
+
+	/*
 	 * Initialize
 	 */
 	virtual ErrorCode Initialize(ResourceManager* pResourceManager);
@@ -50,6 +55,11 @@
 	 */
 	virtual GuiElement* Pick(float fX, float fY);
 
+	/*
+	 * Add
+	 */
+	ErrorCode Add(GuiElement* pElement);
+
 protected:
 
 	/*
--- a/LightClone/Source/GuiElement.cpp	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/Source/GuiElement.cpp	Wed Sep 14 13:33:22 2011 -0700
@@ -102,7 +102,7 @@
 	return Rectangle2(kPosition.y, kPosition.y, kDimensions.x, kDimensions.y).Contains(fX, fY) ? this : NULL;
 }
 
-
+#if 0
 /*
  * GuiElementList
  */
@@ -230,4 +230,5 @@
 	}
 
 	return eCode;
-}
\ No newline at end of file
+}
+#endif
\ No newline at end of file
--- a/LightClone/Source/GuiElement.h	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/Source/GuiElement.h	Wed Sep 14 13:33:22 2011 -0700
@@ -9,12 +9,15 @@
 #include "ResourceManager.h"
 #include "RenderContext.h"
 #include "Camera.h"
+#include "ArrayList.h"
 
 /*
  * GuiElement
  */
 class GuiElement
 {
+protected:
+
 	/*
 	 * pContainer
 	 */
@@ -116,6 +119,9 @@
 /*
  * GuiElementList
  */
+typedef ArrayList<GuiElement*> GuiElementList;
+
+#if 0
 class GuiElementList
 {
 	/*
@@ -187,5 +193,6 @@
 	 */
 	ErrorCode Resize(uint32 nLength);
 };
+#endif
 
 #endif //__GUIELEMENT_H__
--- a/LightClone/Source/GuiInterface.cpp	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/Source/GuiInterface.cpp	Wed Sep 14 13:33:22 2011 -0700
@@ -48,8 +48,13 @@
 /*
  * Render
  */
-void GuiInterface::Render(RenderContext& kContext)
+void GuiInterface::Render(RenderContext& kContext, Camera& kCamera)
 {
+	//TODO: Should I send the camera down the tree?  Ideally I would have a
+	//		single VB for all UI quads, so really the interface could setup
+	//		the camera and effect at this point.  May also need a wrapper
+	//		around render context (GuiRenderContext)
+
 	pRoot->Render(kContext);
 }
 
--- a/LightClone/Source/GuiInterface.h	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/Source/GuiInterface.h	Wed Sep 14 13:33:22 2011 -0700
@@ -48,7 +48,7 @@
 	/*
 	 * Render
 	 */
-	void Render(RenderContext& kContext);
+	void Render(RenderContext& kContext, Camera& kCamera);
 
 	/*
 	 * Pick
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/GuiLabel.cpp	Wed Sep 14 13:33:22 2011 -0700
@@ -0,0 +1,104 @@
+/*
+ * GuiLabel
+ */
+
+#include "GuiLabel.h"
+
+/*
+ * GuiLabel
+ */
+GuiLabel::GuiLabel() : pResourceManager(NULL), pFont(NULL), nFlags(0), kColor(0xFFFFFFFF)
+{
+	memset(kLabel, 0, sizeof(kLabel));
+}
+
+/*
+ * Initialize
+ */
+ErrorCode GuiLabel::Initialize(ResourceManager* pManager)
+{
+	return pResourceManager = pManager, Error_Success;
+}
+
+/*
+ * Terminate
+ */
+void GuiLabel::Terminate()
+{
+	if(pFont)
+	{
+		pFont->Release();
+		pFont = NULL;
+	}
+}
+
+/*
+ * Update
+ */
+void GuiLabel::Update(float fElapsed)
+{
+}
+
+/*
+ * Render
+ */
+void GuiLabel::Render(RenderContext& kContext)
+{
+	if(pFont)
+	{
+		//TODO: Position needs to be relative to the parent
+
+		RECT kRectangle;
+		kRectangle.left		= (int32)kPosition.x;
+		kRectangle.top		= (int32)kPosition.y;
+		kRectangle.right	= (int32)kPosition.x;
+		kRectangle.bottom	= (int32)kPosition.y;
+
+		uint32 nLength = strlen(kLabel);
+		uint32 nFormat = 0;
+
+		if(nFlags & GuiLabelFlag_CenterX)
+		{
+			nFormat |= DT_CENTER;
+		}
+
+		if(nFlags & GuiLabelFlag_CenterY)
+		{
+			nFormat |= DT_VCENTER;
+		}
+
+		pFont->DrawTextA(NULL, kLabel, nLength, &kRectangle, nFormat | DT_CALCRECT, kColor);
+		pFont->DrawTextA(NULL, kLabel, nLength, &kRectangle, nFormat, kColor);
+	}
+}
+
+/*
+ * SetFont
+ */
+ErrorCode GuiLabel::SetFont(const char* pName, uint32 nSize, uint32 nWeight)
+{
+	if(pFont)
+	{
+		pFont->Release();
+		pFont = NULL;
+	}
+
+	return pResourceManager->CreateFontFromName(pName, nSize, nWeight, &pFont);
+}
+
+/*
+ * SetText
+ */
+ErrorCode GuiLabel::SetText(const char* pText)
+{
+	ErrorCode eCode = Error_Fail;
+
+	uint32 nLength = strlen(pText);
+	if(nLength < MaximumLabelLength)
+	{
+		strncpy_s(kLabel, pText, nLength);
+		eCode = Error_Success;
+	}
+
+	return eCode;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/LightClone/Source/GuiLabel.h	Wed Sep 14 13:33:22 2011 -0700
@@ -0,0 +1,93 @@
+/*
+ * GuiLabel
+ */
+
+#ifndef __GUILABEL_H__
+#define __GUILABEL_H__
+
+#include "Core.h"
+#include "GuiElement.h"
+
+/*
+ * GuiLabelFlag
+ */
+enum
+{
+	GuiLabelFlag_CenterX	= (1 << 0),
+	GuiLabelFlag_CenterY	= (1 << 1),
+};
+
+/*
+ * GuiLabel
+ */
+class GuiLabel : public GuiElement
+{
+	/*
+	 * MaximumLabelLength
+	 */
+	static const uint32 MaximumLabelLength = 32;
+
+	/*
+	 * pResourceManager
+	 */
+	ResourceManager* pResourceManager;
+
+	/*
+	 * pFont
+	 */
+	ID3DXFont* pFont;
+
+	/*
+	 * kLabel
+	 */
+	char kLabel[MaximumLabelLength];
+
+	/*
+	 * nFlags
+	 */
+	uint32 nFlags;
+
+	/*
+	 * kColor
+	 */
+	D3DCOLOR kColor;
+
+public:
+
+	/*
+	 * GuiLabel
+	 */
+	GuiLabel();
+
+	/*
+	 * Initialize
+	 */
+	virtual ErrorCode Initialize(ResourceManager* pResourceManager);
+
+	/*
+	 * Terminate
+	 */
+	virtual void Terminate();
+
+	/*
+	 * Update
+	 */
+	virtual void Update(float fElapsed);
+
+	/*
+	 * Render
+	 */
+	virtual void Render(RenderContext& kContext);
+
+	/*
+	 * SetFont
+	 */
+	ErrorCode SetFont(const char* pName, uint32 nSize, uint32 nHeight = FW_NORMAL);
+
+	/*
+	 * SetText
+	 */
+	ErrorCode SetText(const char* pText);
+};
+
+#endif //__GUILABEL_H__
--- a/LightClone/Source/World.cpp	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/Source/World.cpp	Wed Sep 14 13:33:22 2011 -0700
@@ -4,6 +4,7 @@
 
 #include "World.h"
 #include "VertexTypes.h"
+#include "GuiLabel.h"
 
 /*
  * World
@@ -245,6 +246,8 @@
 				}
 			}
 		}
+
+		kInterface.Update(fElapsed);
 	}
 }
 
@@ -274,7 +277,19 @@
  */
 ErrorCode World::InitializeInterface(ResourceManager* pResourceManager)
 {
-	return kInterface.Initialize(pInputManager, pResourceManager);
+	GuiContainer* pRoot = kInterface.GetRoot();
+	//ASSERT(pRoot != NULL);
+
+	GuiLabel*
+	pLabel = new GuiLabel();
+	pLabel->Initialize(pResourceManager);
+	pLabel->SetFont("Courier New", 16);
+	pLabel->SetText("This is a test!");
+	pLabel->SetPosition(0.5f * ScreenSizeX, 0.5f * ScreenSizeY);
+
+	pRoot->Add(pLabel);
+
+	//return kInterface.Initialize(pResourceManager);
 
 	/*
 	GuiElement* pRoot = kInterface.GetRoot();
@@ -367,8 +382,9 @@
 	pRoot->Add(pLevelDialog);
 	pRoot->Add(pGameDialog);
 	pRoot->Add(pConfirmDialog);
+	*/
 
-	*/
+	return Error_Success;
 }
 
 /*
--- a/LightClone/Source/World.h	Wed Sep 14 12:40:50 2011 -0700
+++ b/LightClone/Source/World.h	Wed Sep 14 13:33:22 2011 -0700
@@ -18,7 +18,8 @@
 #include "InputManager.h"
 #include "ButtonPane.h"
 #include "Dialog.h"
-#include "Interface.h"
+//#include "Interface.h"
+#include "GuiInterface.h"
 
 /*
  * World
@@ -81,6 +82,11 @@
 	CameraController kCameraController;
 
 	/*
+	 * kInterface
+	 */
+	GuiInterface kInterface;
+
+	/*
 	 * kDragController
 	 */
 	DragController kDragController;
@@ -124,7 +130,7 @@
 	 * kInterface
 	 *	Move to World
 	 */
-	Interface kInterface;
+	//Interface kInterface;
 
 	/*
 	 * kDialog