2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-21 12:25:28 +00:00
|
|
|
// SwitchComponent.h
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
2020-12-15 17:49:43 +00:00
|
|
|
// Basic on/off switch used in menus.
|
2020-06-06 14:48:05 +00:00
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_SWITCH_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_SWITCH_COMPONENT_H
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "GuiComponent.h"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "components/ImageComponent.h"
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2020-06-06 14:48:05 +00:00
|
|
|
// A simple "on/off" switch.
|
2013-06-19 01:12:30 +00:00
|
|
|
class SwitchComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2020-06-21 12:25:28 +00:00
|
|
|
SwitchComponent(Window* window, bool state = false);
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2021-07-07 18:31:46 +00:00
|
|
|
void onSizeChanged() override { mImage.setSize(mSize); }
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2021-10-25 16:39:58 +00:00
|
|
|
void setResize(float width, float height) override { setSize(width, height); }
|
2021-07-07 18:31:46 +00:00
|
|
|
bool getState() const { return mState; }
|
2020-06-21 12:25:28 +00:00
|
|
|
void setState(bool state);
|
2020-06-25 17:52:38 +00:00
|
|
|
std::string getValue() const override;
|
2020-06-21 12:25:28 +00:00
|
|
|
void setValue(const std::string& statestring) override;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setOriginalColor(unsigned int color) override { mColorOriginalValue = color; }
|
|
|
|
void setChangedColor(unsigned int color) override { mColorChangedValue = color; }
|
|
|
|
void setCallback(const std::function<void()>& callbackFunc) { mToggleCallback = callbackFunc; }
|
2020-07-15 15:44:27 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
unsigned char getOpacity() const override { return mImage.getOpacity(); }
|
|
|
|
void setOpacity(unsigned char opacity) override { mImage.setOpacity(opacity); }
|
2020-08-05 17:31:59 +00:00
|
|
|
// Multiply all pixels in the image by this color when rendering.
|
2021-07-07 18:31:46 +00:00
|
|
|
void setColorShift(unsigned int color) override { mImage.setColorShift(color); }
|
2020-08-05 17:31:59 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
unsigned int getColorShift() const override { return mImage.getColorShift(); }
|
2020-11-08 12:03:45 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
private:
|
2020-06-21 12:25:28 +00:00
|
|
|
void onStateChanged();
|
2014-03-08 01:35:16 +00:00
|
|
|
|
2020-06-21 12:25:28 +00:00
|
|
|
ImageComponent mImage;
|
|
|
|
bool mState;
|
2020-07-15 15:44:27 +00:00
|
|
|
bool mOriginalValue;
|
|
|
|
unsigned int mColorOriginalValue;
|
|
|
|
unsigned int mColorChangedValue;
|
2020-12-15 17:49:43 +00:00
|
|
|
std::function<void()> mToggleCallback;
|
2013-06-19 01:12:30 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_SWITCH_COMPONENT_H
|