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
|
|
|
// ButtonComponent.h
|
|
|
|
//
|
|
|
|
// Basic on/off button.
|
|
|
|
//
|
|
|
|
|
2017-10-31 17:12:50 +00:00
|
|
|
#ifndef ES_CORE_COMPONENTS_BUTTON_COMPONENT_H
|
|
|
|
#define ES_CORE_COMPONENTS_BUTTON_COMPONENT_H
|
2013-08-22 20:29:50 +00:00
|
|
|
|
2017-11-01 22:21:10 +00:00
|
|
|
#include "GuiComponent.h"
|
2021-07-07 18:31:46 +00:00
|
|
|
#include "components/NinePatchComponent.h"
|
2017-11-01 22:21:10 +00:00
|
|
|
|
|
|
|
class TextCache;
|
2013-08-22 20:29:50 +00:00
|
|
|
|
|
|
|
class ButtonComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2021-07-07 18:31:46 +00:00
|
|
|
ButtonComponent(Window* window,
|
|
|
|
const std::string& text = "",
|
|
|
|
const std::string& helpText = "",
|
|
|
|
const std::function<void()>& func = nullptr);
|
2013-08-22 20:29:50 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
void setPressedFunc(std::function<void()> f) { mPressedFunc = f; }
|
2020-12-15 17:49:43 +00:00
|
|
|
void setEnabled(bool state) override;
|
2014-03-12 03:00:08 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
2021-08-15 17:30:31 +00:00
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2013-08-22 20:29:50 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
void setText(const std::string& text, const std::string& helpText);
|
2013-08-23 02:41:40 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::string& getText() const { return mText; }
|
|
|
|
const std::function<void()>& getPressedFunc() const { return mPressedFunc; }
|
2014-03-15 22:06:16 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
void onSizeChanged() override;
|
|
|
|
void onFocusGained() override;
|
|
|
|
void onFocusLost() override;
|
2013-08-23 02:41:40 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
private:
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
|
|
|
std::function<void()> mPressedFunc;
|
2013-08-22 20:29:50 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mFocused;
|
|
|
|
bool mEnabled;
|
|
|
|
unsigned int mTextColorFocused;
|
|
|
|
unsigned int mTextColorUnfocused;
|
2019-08-25 15:23:02 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
unsigned int getCurTextColor() const;
|
|
|
|
void updateImage();
|
2013-09-07 22:43:36 +00:00
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
std::string mText;
|
|
|
|
std::string mHelpText;
|
|
|
|
std::unique_ptr<TextCache> mTextCache;
|
|
|
|
NinePatchComponent mBox;
|
2013-08-22 20:29:50 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_BUTTON_COMPONENT_H
|