Mercurial > LightClone
view LightClone/Source/GuiElement.cpp @ 64:3507bd831c7f
Hook up ServiceProvider
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Tue, 04 Oct 2011 13:02:45 -0700 |
parents | 1fe27776627e |
children | f7095bce01cf |
line wrap: on
line source
/* * GuiElement */ #include "GuiElement.h" /* * EventDrop */ const char* GuiElement::EventDrop = "GuiElement:EventDrop"; /* * GuiElement */ GuiElement::GuiElement() { pContainer = NULL; kPosition = D3DXVECTOR2(0.0f, 0.0f); fDepth = 1.0f; kDimensions = D3DXVECTOR2(0.0f, 0.0f); kColor = D3DCOLOR_XRGB(255, 255, 255); nFlags = GuiElementFlag_Visible; } /* * ~GuiElement */ GuiElement::~GuiElement() { } /* * Initialize */ ErrorCode GuiElement::Initialize(ServiceProvider* pInstance) { ASSERT(pInstance != NULL); pServiceProvider = pInstance; return Error_Success; } /* * Terminate */ void GuiElement::Terminate() { for(uint32 i = 0; i < kChildren.Size(); ++i) { kChildren[i]->Terminate(); } } /* * Update */ void GuiElement::Update(float fElapsed) { for(uint32 i = 0; i < kChildren.Size(); ++i) { kChildren[i]->Update(fElapsed); } } /* * Render */ void GuiElement::Render(GuiRenderContext& kContext) { if(nFlags & GuiElementFlag_Visible) { for(uint32 i = 0; i < kChildren.Size(); ++i) { kChildren[i]->Render(kContext); } } } /* * SetInterface */ void GuiElement::SetInterface(GuiInterface* pInstance) { pInterface = pInstance; for(uint32 i = 0; i < kChildren.Size(); ++i) { kChildren[i]->SetInterface(pInstance); } } /* * GetInterface */ GuiInterface* GuiElement::GetInterface() { return pInterface; } /* * SetParent */ void GuiElement::SetParent(GuiElement* pInstance) { pContainer = pInstance; } /* * GetParent */ GuiElement* GuiElement::GetParent() { 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; } /* * SetDepth */ void GuiElement::SetDepth(float fValue) { fDepth = fValue; } /* * GetDepth */ float GuiElement::GetDepth() const { return fDepth; } /* * 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; } /* * GetWidth */ float GuiElement::GetWidth() const { return kDimensions.x; } /* * GetHeight */ float GuiElement::GetHeight() const { return kDimensions.y; } /* * SetFlag */ void GuiElement::SetFlag(uint32 nValue) { nFlags |= nValue; } /* * ClearFlag */ void GuiElement::ClearFlag(uint32 nValue) { nFlags &= ~nValue; } /* * HasFlag */ bool GuiElement::HasFlag(uint32 nValue) const { return (nFlags & nValue) == nValue; } /* * IsVisible */ bool GuiElement::IsVisible() const { return (nFlags & GuiElementFlag_Visible) != 0; } /* * SetColor */ void GuiElement::SetColor(D3DCOLOR nColor) { kColor = nColor; } /* * Pick */ GuiElement* GuiElement::Pick(float fX, float fY) { GuiElement* pElement = NULL; if(HasFlag(GuiElementFlag_Visible)) { for(int32 i = (int32)kChildren.Size() - 1; i >= 0 && !pElement; --i) { if(kChildren[i]->Contains(fX, fY)) { pElement = kChildren[i]->Pick(fX, fY); } } if(!pElement) { if(HasFlag(GuiElementFlag_Pickable)) { if(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->SetInterface(pInterface); pElement->SetParent(this); } } return eCode; } /* * Remove */ ErrorCode GuiElement::Remove(GuiElement* pElement) { ErrorCode eCode = Error_Fail; if(pElement) { eCode = kChildren.Remove(pElement); if(eCode == Error_Success) { pElement->SetParent(NULL); } } return eCode; } /* * Contains */ bool GuiElement::Contains(float fX, float fY) { const D3DXVECTOR2& kLocation = GetPosition(); const float fDeltaX = fX - kLocation.x; const float fDeltaY = fY - kLocation.y; return (0.0f <= fDeltaX && fDeltaX < kDimensions.x) && (0.0f <= fDeltaY && fDeltaY < kDimensions.y); } /* * OnMouseEnter */ void GuiElement::OnMouseEnter() { } /* * OnMouseLeave */ void GuiElement::OnMouseLeave() { } /* * 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) { } /* * OnDrop */ void GuiElement::OnDrop(GuiElement* pSource, float fX, float fY) { }