2013-06-02 15:08:32 +00:00
|
|
|
#include "GuiComponent.h"
|
|
|
|
#include "Window.h"
|
2013-06-02 16:11:29 +00:00
|
|
|
#include "Log.h"
|
2013-06-02 19:34:50 +00:00
|
|
|
#include "Renderer.h"
|
2013-06-02 15:08:32 +00:00
|
|
|
|
2013-07-09 05:48:23 +00:00
|
|
|
GuiComponent::GuiComponent(Window* window) : mWindow(window), mParent(NULL), mOpacity(255)
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiComponent::~GuiComponent()
|
|
|
|
{
|
|
|
|
mWindow->removeGui(this);
|
|
|
|
|
|
|
|
if(mParent)
|
|
|
|
mParent->removeChild(this);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
getChild(i)->setParent(NULL);
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool GuiComponent::input(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
{
|
|
|
|
if(getChild(i)->input(config, input))
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::update(int deltaTime)
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
{
|
|
|
|
getChild(i)->update(deltaTime);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::render()
|
2013-06-02 19:34:50 +00:00
|
|
|
{
|
|
|
|
Renderer::translate(mOffset);
|
|
|
|
|
|
|
|
onRender();
|
|
|
|
|
|
|
|
Renderer::translate(-mOffset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::onRender()
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
{
|
|
|
|
getChild(i)->render();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::init()
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
{
|
|
|
|
getChild(i)->init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::deinit()
|
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
{
|
|
|
|
getChild(i)->deinit();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-06-02 19:34:50 +00:00
|
|
|
//Offset stuff.
|
2013-06-02 15:08:32 +00:00
|
|
|
Vector2i GuiComponent::getGlobalOffset()
|
|
|
|
{
|
|
|
|
if(mParent)
|
|
|
|
return mParent->getGlobalOffset() + mOffset;
|
|
|
|
else
|
|
|
|
return mOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
Vector2i GuiComponent::getOffset()
|
|
|
|
{
|
|
|
|
return mOffset;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setOffset(Vector2i offset)
|
|
|
|
{
|
2013-06-19 01:12:30 +00:00
|
|
|
setOffset(offset.x, offset.y);
|
|
|
|
onOffsetChanged();
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setOffset(int x, int y)
|
|
|
|
{
|
|
|
|
mOffset.x = x;
|
|
|
|
mOffset.y = y;
|
2013-06-19 01:12:30 +00:00
|
|
|
onOffsetChanged();
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
2013-06-02 16:11:29 +00:00
|
|
|
|
2013-06-02 22:33:49 +00:00
|
|
|
Vector2u GuiComponent::getSize()
|
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
2013-07-02 23:48:39 +00:00
|
|
|
void GuiComponent::setSize(Vector2u size)
|
|
|
|
{
|
|
|
|
mSize = size;
|
|
|
|
onSizeChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setSize(unsigned int w, unsigned int h)
|
|
|
|
{
|
|
|
|
mSize.x = w;
|
|
|
|
mSize.y = h;
|
|
|
|
onSizeChanged();
|
|
|
|
}
|
|
|
|
|
2013-06-02 19:34:50 +00:00
|
|
|
//Children stuff.
|
2013-06-02 16:11:29 +00:00
|
|
|
void GuiComponent::addChild(GuiComponent* cmp)
|
|
|
|
{
|
|
|
|
mChildren.push_back(cmp);
|
|
|
|
|
|
|
|
if(cmp->getParent())
|
|
|
|
cmp->getParent()->removeChild(cmp);
|
|
|
|
|
|
|
|
cmp->setParent(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::removeChild(GuiComponent* cmp)
|
|
|
|
{
|
|
|
|
if(cmp->getParent() != this)
|
|
|
|
{
|
|
|
|
LOG(LogError) << "Tried to remove child from incorrect parent!";
|
|
|
|
}
|
|
|
|
|
|
|
|
cmp->setParent(NULL);
|
|
|
|
|
|
|
|
for(auto i = mChildren.begin(); i != mChildren.end(); i++)
|
|
|
|
{
|
|
|
|
if(*i == cmp)
|
|
|
|
{
|
|
|
|
mChildren.erase(i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::clearChildren()
|
|
|
|
{
|
|
|
|
mChildren.clear();
|
|
|
|
}
|
|
|
|
|
|
|
|
unsigned int GuiComponent::getChildCount()
|
|
|
|
{
|
|
|
|
return mChildren.size();
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiComponent* GuiComponent::getChild(unsigned int i)
|
|
|
|
{
|
|
|
|
return mChildren.at(i);
|
|
|
|
}
|
2013-06-02 19:34:50 +00:00
|
|
|
|
|
|
|
void GuiComponent::setParent(GuiComponent* parent)
|
|
|
|
{
|
|
|
|
mParent = parent;
|
|
|
|
}
|
|
|
|
|
|
|
|
GuiComponent* GuiComponent::getParent()
|
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
2013-07-02 14:51:33 +00:00
|
|
|
|
|
|
|
|
|
|
|
unsigned char GuiComponent::getOpacity()
|
|
|
|
{
|
|
|
|
return mOpacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setOpacity(unsigned char opacity)
|
|
|
|
{
|
|
|
|
mOpacity = opacity;
|
2013-07-03 00:12:49 +00:00
|
|
|
}
|