2012-07-19 01:14:17 +00:00
|
|
|
#include "GuiComponent.h"
|
|
|
|
#include "Renderer.h"
|
2012-07-19 16:13:27 +00:00
|
|
|
#include <iostream>
|
2012-07-19 01:14:17 +00:00
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
std::vector<GuiComponent*> GuiComponent::sComponentVector;
|
|
|
|
|
|
|
|
GuiComponent::GuiComponent()
|
|
|
|
{
|
|
|
|
sComponentVector.push_back(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiComponent::~GuiComponent()
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < sComponentVector.size(); i++)
|
|
|
|
{
|
|
|
|
if(sComponentVector.at(i) == this)
|
|
|
|
{
|
|
|
|
sComponentVector.erase(sComponentVector.begin() + i);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 16:13:27 +00:00
|
|
|
void GuiComponent::addChild(GuiComponent* comp)
|
2012-07-19 01:14:17 +00:00
|
|
|
{
|
2012-07-19 16:13:27 +00:00
|
|
|
mChildren.push_back(comp);
|
2012-07-19 01:14:17 +00:00
|
|
|
}
|
|
|
|
|
2012-07-19 16:13:27 +00:00
|
|
|
void GuiComponent::removeChild(GuiComponent* comp)
|
2012-07-19 01:14:17 +00:00
|
|
|
{
|
2012-07-19 16:13:27 +00:00
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
|
|
|
{
|
|
|
|
if(mChildren.at(i) == comp)
|
|
|
|
{
|
|
|
|
mChildren.erase(mChildren.begin() + i);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "Error - tried to remove GuiComponent child, but couldn't find it!\n";
|
|
|
|
}
|
|
|
|
|
2012-08-02 01:43:55 +00:00
|
|
|
void GuiComponent::processTicks(int deltaTime)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < sComponentVector.size(); i++)
|
|
|
|
{
|
|
|
|
sComponentVector.at(i)->onTick(deltaTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-07-19 16:13:27 +00:00
|
|
|
void GuiComponent::render()
|
|
|
|
{
|
|
|
|
onRender();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
|
|
|
{
|
|
|
|
mChildren.at(i)->render();
|
|
|
|
}
|
2012-07-19 01:14:17 +00:00
|
|
|
}
|
2012-08-02 01:43:55 +00:00
|
|
|
|