Mercurial > LightClone
view LightClone/Source/GuiElement.cpp @ 17:4951acfe92fc
Reworking GUI system
author | koryspansel <koryspansel@bendbroadband.com> |
---|---|
date | Wed, 14 Sep 2011 13:33:22 -0700 |
parents | d80d06d5ff53 |
children | 33cb6979ac51 |
line wrap: on
line source
/* * GuiElement */ #include "GuiElement.h" /* * GuiElement */ GuiElement::GuiElement() { } /* * ~GuiElement */ GuiElement::~GuiElement() { } /* * 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 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) { return Rectangle2(kPosition.y, kPosition.y, kDimensions.x, kDimensions.y).Contains(fX, fY) ? this : NULL; } #if 0 /* * GuiElementList */ GuiElementList::GuiElementList() : pElement(NULL), nSize(0), nCount(0) { } /* * ~GuiElementList */ GuiElementList::~GuiElementList() { delete[] pElement; pElement = NULL; } /* * Add */ ErrorCode GuiElementList::Add(GuiElement* pInstance) { ErrorCode eCode = Resize(nCount + 1); if(eCode == Error_Success) { pElement[nCount++] = pInstance; } return eCode; } /* * Remove */ ErrorCode GuiElementList::Remove(uint32 nIndex) { if(nIndex < nCount) { --nCount; for(uint32 i = nIndex; i < nCount; ++i) { pElement[i] = pElement[i + 1]; } return Error_Success; } return Error_Fail; } /* * Clear */ void GuiElementList::Clear() { nCount = 0; } /* * Find */ int32 GuiElementList::Find(GuiElement* pInstance) { for(uint32 i = 0; i < nCount; ++i) { if(pElement[i] == pInstance) { return (int32)i; } } return -1; } /* * GetSize */ uint32 GuiElementList::GetSize() const { return nCount; } /* * operator [] */ GuiElement* GuiElementList::operator[](uint32 nIndex) { //ASSERT(nIndex < nCount); return pElement[nIndex]; } /* * operator [] */ const GuiElement* GuiElementList::operator[](uint32 nIndex) const { //ASSERT(nIndex < nCount); return pElement[nIndex]; } /* * Resize */ ErrorCode GuiElementList::Resize(uint32 nLength) { ErrorCode eCode = Error_Success; if(nLength > nSize) { //TODO: Reallocate array and copy GuiElement** pArray = new GuiElement*[2 * nSize + 1]; if(pElement) { for(uint32 i = 0; i < nCount; ++i) { pArray[i] = pElement[i]; } delete[] pElement; } pElement = pArray; nSize *= 2; } return eCode; } #endif