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-10 11:29:43 +00:00
|
|
|
GuiComponent::GuiComponent(Window* window) : mWindow(window), mParent(NULL), mOpacity(255),
|
|
|
|
mPosition(Eigen::Vector3f::Zero()), mSize(Eigen::Vector2f::Zero()), mTransform(Eigen::Affine3f::Identity())
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void GuiComponent::render(const Eigen::Affine3f& parentTrans)
|
2013-06-02 19:34:50 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Affine3f trans = parentTrans * getTransform();
|
|
|
|
renderChildren(trans);
|
2013-06-02 19:34:50 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void GuiComponent::renderChildren(const Eigen::Affine3f& transform) const
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
|
|
|
for(unsigned int i = 0; i < getChildCount(); i++)
|
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
getChild(i)->render(transform);
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector3f GuiComponent::getPosition() const
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
return mPosition;
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void GuiComponent::setPosition(const Eigen::Vector3f& offset)
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
mPosition = offset;
|
|
|
|
onPositionChanged();
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void GuiComponent::setPosition(float x, float y, float z)
|
2013-06-02 15:08:32 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
mPosition << x, y, z;
|
|
|
|
onPositionChanged();
|
2013-06-02 15:08:32 +00:00
|
|
|
}
|
2013-06-02 16:11:29 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Vector2f GuiComponent::getSize() const
|
2013-06-02 22:33:49 +00:00
|
|
|
{
|
|
|
|
return mSize;
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void GuiComponent::setSize(const Eigen::Vector2f& size)
|
2013-07-02 23:48:39 +00:00
|
|
|
{
|
|
|
|
mSize = size;
|
|
|
|
onSizeChanged();
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void GuiComponent::setSize(float w, float h)
|
2013-07-02 23:48:39 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
mSize << w, h;
|
2013-07-02 23:48:39 +00:00
|
|
|
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)
|
|
|
|
{
|
2013-11-12 23:28:15 +00:00
|
|
|
if(!cmp->getParent())
|
|
|
|
return;
|
|
|
|
|
2013-06-02 16:11:29 +00:00
|
|
|
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();
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
unsigned int GuiComponent::getChildCount() const
|
2013-06-02 16:11:29 +00:00
|
|
|
{
|
|
|
|
return mChildren.size();
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
GuiComponent* GuiComponent::getChild(unsigned int i) const
|
2013-06-02 16:11:29 +00:00
|
|
|
{
|
|
|
|
return mChildren.at(i);
|
|
|
|
}
|
2013-06-02 19:34:50 +00:00
|
|
|
|
|
|
|
void GuiComponent::setParent(GuiComponent* parent)
|
|
|
|
{
|
|
|
|
mParent = parent;
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
GuiComponent* GuiComponent::getParent() const
|
2013-06-02 19:34:50 +00:00
|
|
|
{
|
|
|
|
return mParent;
|
|
|
|
}
|
2013-07-02 14:51:33 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
unsigned char GuiComponent::getOpacity() const
|
2013-07-02 14:51:33 +00:00
|
|
|
{
|
|
|
|
return mOpacity;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GuiComponent::setOpacity(unsigned char opacity)
|
|
|
|
{
|
|
|
|
mOpacity = opacity;
|
2013-10-10 21:14:33 +00:00
|
|
|
for(auto it = mChildren.begin(); it != mChildren.end(); it++)
|
|
|
|
{
|
|
|
|
(*it)->setOpacity(opacity);
|
|
|
|
}
|
2013-07-03 00:12:49 +00:00
|
|
|
}
|
2013-07-10 11:29:43 +00:00
|
|
|
|
|
|
|
const Eigen::Affine3f GuiComponent::getTransform()
|
|
|
|
{
|
|
|
|
mTransform.setIdentity();
|
|
|
|
mTransform.translate(mPosition);
|
|
|
|
return mTransform;
|
|
|
|
}
|
2013-08-14 12:16:49 +00:00
|
|
|
|
|
|
|
void GuiComponent::setValue(const std::string& value)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
std::string GuiComponent::getValue() const
|
|
|
|
{
|
|
|
|
return "";
|
|
|
|
}
|
2013-08-19 15:36:48 +00:00
|
|
|
|
|
|
|
void GuiComponent::textInput(const char* text)
|
|
|
|
{
|
|
|
|
for(auto iter = mChildren.begin(); iter != mChildren.end(); iter++)
|
|
|
|
{
|
|
|
|
(*iter)->textInput(text);
|
|
|
|
}
|
|
|
|
}
|