mirror of
https://github.com/RetroDECK/ES-DE.git
synced 2024-11-30 10:05:39 +00:00
70d0057295
User changes are marked with blue and scraper changes with red.
92 lines
1.9 KiB
C++
92 lines
1.9 KiB
C++
//
|
|
// SwitchComponent.cpp
|
|
//
|
|
// Basic switch used in the menus.
|
|
//
|
|
|
|
#include "SwitchComponent.h"
|
|
|
|
#include "resources/Font.h"
|
|
|
|
SwitchComponent::SwitchComponent(
|
|
Window* window,
|
|
bool state)
|
|
: GuiComponent(window),
|
|
mImage(window),
|
|
mState(state),
|
|
mColorOriginalValue(DEFAULT_COLORSHIFT),
|
|
mColorChangedValue(DEFAULT_COLORSHIFT)
|
|
{
|
|
mImage.setImage(":/graphics/off.svg");
|
|
mImage.setResize(0, Font::get(FONT_SIZE_MEDIUM)->getLetterHeight());
|
|
mSize = mImage.getSize();
|
|
}
|
|
|
|
void SwitchComponent::onSizeChanged()
|
|
{
|
|
mImage.setSize(mSize);
|
|
}
|
|
|
|
bool SwitchComponent::input(InputConfig* config, Input input)
|
|
{
|
|
if (config->isMappedTo("a", input) && input.value) {
|
|
mState = !mState;
|
|
onStateChanged();
|
|
return true;
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void SwitchComponent::render(const Transform4x4f& parentTrans)
|
|
{
|
|
Transform4x4f trans = parentTrans * getTransform();
|
|
mImage.render(trans);
|
|
renderChildren(trans);
|
|
}
|
|
|
|
bool SwitchComponent::getState() const
|
|
{
|
|
return mState;
|
|
}
|
|
|
|
void SwitchComponent::setState(bool state)
|
|
{
|
|
mState = state;
|
|
onStateChanged();
|
|
}
|
|
|
|
std::string SwitchComponent::getValue() const
|
|
{
|
|
return mState ? "true" : "false";
|
|
}
|
|
|
|
void SwitchComponent::setValue(const std::string& statestring)
|
|
{
|
|
if (statestring == "true")
|
|
mState = true;
|
|
else
|
|
mState = false;
|
|
|
|
mOriginalValue = mState;
|
|
onStateChanged();
|
|
}
|
|
|
|
void SwitchComponent::onStateChanged()
|
|
{
|
|
mImage.setImage(mState ? ":/graphics/on.svg" : ":/graphics/off.svg");
|
|
|
|
// Change the color of the switch to reflect the changes.
|
|
if (mState == mOriginalValue)
|
|
mImage.setColorShift(mColorOriginalValue);
|
|
else
|
|
mImage.setColorShift(mColorChangedValue);
|
|
}
|
|
|
|
std::vector<HelpPrompt> SwitchComponent::getHelpPrompts()
|
|
{
|
|
std::vector<HelpPrompt> prompts;
|
|
prompts.push_back(HelpPrompt("a", "toggle"));
|
|
return prompts;
|
|
}
|