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
|
|
|
|
2014-03-08 01:35:16 +00:00
|
|
|
SwitchComponent::SwitchComponent(Window* window, bool state) : GuiComponent(window), mImage(window), mState(state)
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
2014-03-22 21:55:18 +00:00
|
|
|
mImage.setImage(":/off.svg");
|
2014-03-22 21:02:25 +00:00
|
|
|
mImage.setResize(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight());
|
2014-03-08 01:35:16 +00:00
|
|
|
mSize = mImage.getSize();
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2014-03-22 21:55:18 +00:00
|
|
|
void SwitchComponent::onSizeChanged()
|
|
|
|
{
|
|
|
|
mImage.setSize(mSize);
|
|
|
|
}
|
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
bool SwitchComponent::input(InputConfig* config, Input input)
|
|
|
|
{
|
|
|
|
if(config->isMappedTo("a", input) && input.value)
|
|
|
|
{
|
|
|
|
mState = !mState;
|
2014-03-08 01:35:16 +00:00
|
|
|
onStateChanged();
|
2013-06-19 01:12:30 +00:00
|
|
|
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
|
|
|
Eigen::Affine3f trans = parentTrans * getTransform();
|
2014-03-08 01:35:16 +00:00
|
|
|
|
|
|
|
mImage.render(trans);
|
2013-07-10 11:29:43 +00:00
|
|
|
|
2014-03-08 01:35:16 +00:00
|
|
|
renderChildren(trans);
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
|
|
|
|
2014-03-08 01:35:16 +00:00
|
|
|
bool SwitchComponent::getState() const
|
2013-06-19 01:12:30 +00:00
|
|
|
{
|
|
|
|
return mState;
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchComponent::setState(bool state)
|
|
|
|
{
|
|
|
|
mState = state;
|
2014-03-08 01:35:16 +00:00
|
|
|
onStateChanged();
|
|
|
|
}
|
|
|
|
|
|
|
|
void SwitchComponent::onStateChanged()
|
|
|
|
{
|
2014-03-22 21:55:18 +00:00
|
|
|
mImage.setImage(mState ? ":/on.svg" : ":/off.svg");
|
2013-06-19 01:12:30 +00:00
|
|
|
}
|
2014-01-25 23:34:29 +00:00
|
|
|
|
|
|
|
std::vector<HelpPrompt> SwitchComponent::getHelpPrompts()
|
|
|
|
{
|
|
|
|
std::vector<HelpPrompt> prompts;
|
2014-03-24 01:33:27 +00:00
|
|
|
prompts.push_back(HelpPrompt("a", "change"));
|
2014-01-25 23:34:29 +00:00
|
|
|
return prompts;
|
|
|
|
}
|