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);
|
2012-09-15 21:24:33 +00:00
|
|
|
|
|
|
|
mOffsetX = 0;
|
|
|
|
mOffsetY = 0;
|
2012-08-02 01:43:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
2012-10-05 20:04:12 +00:00
|
|
|
return;
|
2012-07-19 16:13:27 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cerr << "Error - tried to remove GuiComponent child, but couldn't find it!\n";
|
|
|
|
}
|
|
|
|
|
2012-08-11 04:17:52 +00:00
|
|
|
void GuiComponent::clearChildren()
|
|
|
|
{
|
|
|
|
mChildren.clear();
|
|
|
|
}
|
|
|
|
|
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
|
|
|
|
2012-08-02 04:03:15 +00:00
|
|
|
void GuiComponent::pause()
|
|
|
|
{
|
|
|
|
onPause();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
|
|
|
mChildren.at(i)->pause();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::resume()
|
|
|
|
{
|
|
|
|
onResume();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
|
|
|
mChildren.at(i)->resume();
|
|
|
|
}
|
2012-08-11 04:17:52 +00:00
|
|
|
|
2012-09-04 16:45:16 +00:00
|
|
|
void GuiComponent::init()
|
|
|
|
{
|
|
|
|
onInit();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
|
|
|
{
|
|
|
|
mChildren.at(i)->init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::deinit()
|
|
|
|
{
|
|
|
|
onDeinit();
|
|
|
|
|
|
|
|
for(unsigned int i = 0; i < mChildren.size(); i++)
|
|
|
|
{
|
|
|
|
mChildren.at(i)->deinit();
|
|
|
|
}
|
|
|
|
}
|
2012-09-15 21:24:33 +00:00
|
|
|
|
|
|
|
void GuiComponent::setOffsetX(int val) { mOffsetX = val; }
|
|
|
|
void GuiComponent::setOffsetY(int val) { mOffsetY = val; }
|
|
|
|
int GuiComponent::getOffsetX() { return mOffsetX; }
|
|
|
|
int GuiComponent::getOffsetY() { return mOffsetY; }
|