# HG changeset patch # User koryspansel # Date 1316032402 25200 # Node ID 4951acfe92fcad920d0c336168453ccd612bbc2f # Parent 88f7c22e7b45defe7bddf29958662a98ac85e689 Reworking GUI system diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/LightClone.vcproj --- 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 @@ > + + + + diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/GuiContainer.cpp --- 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) diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/GuiContainer.h --- 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: /* diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/GuiElement.cpp --- 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 diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/GuiElement.h --- 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 GuiElementList; + +#if 0 class GuiElementList { /* @@ -187,5 +193,6 @@ */ ErrorCode Resize(uint32 nLength); }; +#endif #endif //__GUIELEMENT_H__ diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/GuiInterface.cpp --- 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); } diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/GuiInterface.h --- 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 diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/GuiLabel.cpp --- /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 diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/GuiLabel.h --- /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__ diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/World.cpp --- 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; } /* diff -r 88f7c22e7b45 -r 4951acfe92fc LightClone/Source/World.h --- 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