2013-06-19 01:12:30 +00:00
|
|
|
#include "SwitchComponent.h"
|
|
|
|
#include "../Renderer.h"
|
2013-10-04 23:24:41 +00:00
|
|
|
#include "../resources/Font.h"
|
2013-07-03 07:54:55 +00:00
|
|
|
#include "../Window.h"
|
2013-06-19 01:12:30 +00:00
|
|
|
|
|
|
|
SwitchComponent::SwitchComponent(Window* window, bool state) : GuiComponent(window), mState(state)
|
|
|
|
{
|
|
|
|
//mSize = Vector2u((unsigned int)(Renderer::getScreenWidth() * 0.05),
|
|
|
|
// (unsigned int)(Renderer::getScreenHeight() * 0.05));
|
|
|
|
|
2013-10-04 23:09:54 +00:00
|
|
|
mSize = Font::get(FONT_SIZE_MEDIUM)->sizeText("OFF");
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SwitchComponent::input(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
if(config->isMappedTo("a", input) && input.value)
|
|
|
|
{
|
|
|
|
mState = !mState;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
void SwitchComponent::render(const Eigen::Affine3f& parentTrans)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2013-07-10 11:29:43 +00:00
|
|
|
//Renderer::pushClipRect(getGlobalOffset(), getSize());
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
Eigen::Affine3f trans = parentTrans * getTransform();
|
|
|
|
Renderer::setMatrix(trans);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-10-04 23:09:54 +00:00
|
|
|
Font::get(FONT_SIZE_MEDIUM)->drawText(mState ? "ON" : "OFF", Eigen::Vector2f(0, 0), mState ? 0x00FF00FF : 0xFF0000FF);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2013-07-10 11:29:43 +00:00
|
|
|
//Renderer::popClipRect();
|
|
|
|
|
|
|
|
GuiComponent::renderChildren(trans);
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool SwitchComponent::getState()
|
|
|
|
{
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchComponent::setState(bool state)
|
|
|
|
{
|
|
|
|
mState = state;
|
|
|
|
}
|