2020-09-21 17:17:34 +00:00
|
|
|
// SPDX-License-Identifier: MIT
|
2020-06-28 16:39:18 +00:00
|
|
|
//
|
2020-09-21 17:17:34 +00:00
|
|
|
// EmulationStation Desktop Edition
|
2020-06-28 16:39:18 +00:00
|
|
|
// SliderComponent.h
|
|
|
|
//
|
|
|
|
// Slider to set value in a predefined range.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_SLIDER_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_SLIDER_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"
|
2023-02-11 11:28:06 +00:00
|
|
|
#include "resources/Font.h"
|
2014-01-10 22:01:28 +00:00
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
// Slider to set value in a predefined range.
|
2013-06-19 01:12:30 +00:00
|
|
|
class SliderComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2021-09-18 09:49:39 +00:00
|
|
|
using GuiComponent::getValue;
|
|
|
|
using GuiComponent::setValue;
|
|
|
|
|
2022-01-19 17:01:54 +00:00
|
|
|
// Minimum and maximum values, how much to increment each step the knob is moved and
|
|
|
|
// an optional unit.
|
|
|
|
SliderComponent(float min, float max, float increment, const std::string& suffix = "");
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2023-02-11 11:28:06 +00:00
|
|
|
void setCallback(const std::function<void()>& callbackFunc)
|
|
|
|
{
|
|
|
|
mChangedValueCallback = callbackFunc;
|
|
|
|
}
|
|
|
|
|
2021-09-18 09:49:39 +00:00
|
|
|
void setValue(float value);
|
|
|
|
float getValue() { return mValue; }
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void update(int deltaTime) override;
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
void onSizeChanged() override;
|
2023-02-11 11:28:06 +00:00
|
|
|
void setOpacity(float opacity) override
|
|
|
|
{
|
|
|
|
mOpacity = opacity;
|
|
|
|
mTextCache->setOpacity(opacity);
|
|
|
|
}
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2022-01-18 16:40:47 +00:00
|
|
|
std::vector<HelpPrompt> getHelpPrompts() override;
|
2014-01-10 22:01:28 +00:00
|
|
|
|
2013-06-19 01:12:30 +00:00
|
|
|
private:
|
2020-06-28 16:39:18 +00:00
|
|
|
void onValueChanged();
|
2014-01-10 22:01:28 +00:00
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
Renderer* mRenderer;
|
2020-06-28 16:39:18 +00:00
|
|
|
float mMin, mMax;
|
|
|
|
float mValue;
|
|
|
|
float mSingleIncrement;
|
|
|
|
float mMoveRate;
|
2021-10-23 13:36:16 +00:00
|
|
|
float mBarHeight;
|
2023-01-24 17:32:28 +00:00
|
|
|
float mBarPosY;
|
2020-06-28 16:39:18 +00:00
|
|
|
int mMoveAccumulator;
|
2013-06-19 01:12:30 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
ImageComponent mKnob;
|
2023-02-11 11:28:06 +00:00
|
|
|
ImageComponent mKnobDisabled;
|
2014-03-08 00:16:08 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
std::string mSuffix;
|
|
|
|
std::shared_ptr<Font> mFont;
|
2021-10-24 12:48:42 +00:00
|
|
|
std::shared_ptr<TextCache> mTextCache;
|
2023-02-11 11:28:06 +00:00
|
|
|
std::function<void()> mChangedValueCallback;
|
2013-06-19 01:12:30 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_SLIDER_COMPONENT_H
|