Mercurial > LightClone
view LightClone/Source/GuiElement.cpp @ 21:b4dc5d674e22
Added GUI event system and some support data structures
author | koryspansel |
---|---|
date | Thu, 15 Sep 2011 18:42:12 -0700 |
parents | 4e9b5299ffdc |
children | a785b0aaf004 |
line wrap: on
line source
/* * GuiElement */ #include "GuiElement.h" /* * GuiElement */ GuiElement::GuiElement() : pContainer(NULL), kPosition(0.0f, 0.0f), kDimensions(0.0f, 0.0f) { } /* * ~GuiElement */ GuiElement::~GuiElement() { } /* * Initialize */ ErrorCode GuiElement::Initialize(ResourceManager* pResourceManager) { return Error_Success; } /* * Terminate */ void GuiElement::Terminate() { } /* * Update */ void GuiElement::Update(float fElapsed) { for(uint32 i = 0; i < kChildren.Size(); ++i) { kChildren[i]->Update(fElapsed); } } /* * Render */ void GuiElement::Render(RenderContext& kContext, Camera& kCamera) { for(uint32 i = 0; i < kChildren.Size(); ++i) { kChildren[i]->Render(kContext, kCamera); } } /* * Attach */ void GuiElement::Attach(GuiElement* pInstance) { pContainer = pInstance; } /* * Detach */ GuiElement* GuiElement::Detach() { GuiElement* pInstance = pContainer; pContainer = NULL; return pInstance; } /* * GetContainer */ GuiElement* GuiElement::GetContainer() { return pContainer; } /* * SetPosition */ void GuiElement::SetPosition(float fX, float fY) { kPosition.x = fX; kPosition.y = fY; } /* * SetPosition */ void GuiElement::SetPosition(const D3DXVECTOR2& kValue) { kPosition = kValue; } /* * GetPosition */ const D3DXVECTOR2 GuiElement::GetPosition() const { return pContainer ? pContainer->GetPosition() + kPosition : kPosition; } /* * SetDimensions */ void GuiElement::SetDimensions(float fWidth, float fHeight) { kDimensions.x = fWidth; kDimensions.y = fHeight; } /* * SetDimensions */ void GuiElement::SetDimensions(const D3DXVECTOR2& kValue) { kDimensions = kValue; } /* * GetDimensions */ const D3DXVECTOR2 GuiElement::GetDimensions() const { return kDimensions; } /* * Pick */ GuiElement* GuiElement::Pick(float fX, float fY) { GuiElement* pElement = NULL; for(uint32 i = 0; i < kChildren.Size() && !pElement; ++i) { const D3DXVECTOR2& kLocation = kChildren[i]->GetPosition(); const D3DXVECTOR2& kSize = kChildren[i]->GetDimensions(); if(Rectangle2(kLocation.x, kLocation.y, kSize.x, kSize.y).Contains(fX, fY)) { pElement = kChildren[i]; } } if(!pElement) { const D3DXVECTOR2& kLocation = GetPosition(); const D3DXVECTOR2& kSize = GetDimensions(); if(Rectangle2(kLocation.x, kLocation.y, kSize.x, kSize.y).Contains(fX, fY)) { pElement = this; } } return pElement; } /* * Add */ ErrorCode GuiElement::Add(GuiElement* pElement) { ErrorCode eCode = Error_Fail; if(pElement) { eCode = kChildren.Add(pElement); if(eCode == Error_Success) { pElement->Attach(this); } } return eCode; } /* * Remove */ ErrorCode GuiElement::Remove(GuiElement* pElement) { ErrorCode eCode = Error_Fail; if(pElement) { eCode = kChildren.Remove(pElement); if(eCode == Error_Success) { pElement->Detach(); } } return eCode; } /* * AllowDrag */ bool GuiElement::AllowDrag() const { return false; } /* * AllowDrop */ bool GuiElement::AllowDrop() const { return false; } /* * OnMouseDown */ void GuiElement::OnMouseDown(uint32 nButton, float fX, float fY) { } /* * OnMouseUp */ void GuiElement::OnMouseUp(uint32 nButton, float fX, float fY) { } /* * OnMouseMove */ void GuiElement::OnMouseMove(float fX, float fY) { } /* * OnDrag */ void GuiElement::OnDrag(float fX, float fY) { } /* * OnDrop */ void GuiElement::OnDrop(GuiElement* pSource, float fX, float fY) { }