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:
|
2022-01-19 17:01:54 +00:00
|
|
|
ButtonComponent(const std::string& text = "",
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::string& helpText = "",
|
2021-09-17 19:25:21 +00:00
|
|
|
const std::function<void()>& func = nullptr,
|
|
|
|
bool upperCase = true,
|
|
|
|
bool flatStyle = false);
|
|
|
|
|
|
|
|
void onSizeChanged() override;
|
|
|
|
void onFocusGained() override;
|
|
|
|
void onFocusLost() override;
|
|
|
|
|
2023-07-27 11:06:07 +00:00
|
|
|
void setText(const std::string& text,
|
|
|
|
const std::string& helpText,
|
|
|
|
bool upperCase = true,
|
|
|
|
bool resize = true);
|
2021-09-17 19:25:21 +00:00
|
|
|
const std::string& getText() const { return mText; }
|
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
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
void setPadding(const glm::vec4 padding);
|
|
|
|
glm::vec4 getPadding() { return mPadding; }
|
2013-08-22 20:29:50 +00:00
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
void setFlatColorFocused(unsigned int color) { mFlatColorFocused = color; }
|
|
|
|
void setFlatColorUnfocused(unsigned int color) { mFlatColorUnfocused = color; }
|
2013-08-23 02:41:40 +00:00
|
|
|
|
2021-07-07 18:31:46 +00:00
|
|
|
const std::function<void()>& getPressedFunc() const { return mPressedFunc; }
|
2014-03-15 22:06:16 +00:00
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
|
|
|
void render(const glm::mat4& parentTrans) override;
|
2013-08-23 02:41:40 +00:00
|
|
|
|
2022-01-18 16:40:47 +00:00
|
|
|
std::vector<HelpPrompt> getHelpPrompts() override;
|
2014-01-25 23:34:29 +00:00
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
private:
|
2021-09-17 19:25:21 +00:00
|
|
|
unsigned int getCurTextColor() const;
|
|
|
|
void updateImage();
|
|
|
|
|
2022-03-14 18:51:48 +00:00
|
|
|
Renderer* mRenderer;
|
2021-09-17 19:25:21 +00:00
|
|
|
NinePatchComponent mBox;
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
2021-09-17 19:25:21 +00:00
|
|
|
std::unique_ptr<TextCache> mTextCache;
|
2020-06-28 16:39:18 +00:00
|
|
|
std::function<void()> mPressedFunc;
|
2013-08-22 20:29:50 +00:00
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
glm::vec4 mPadding;
|
|
|
|
|
|
|
|
std::string mText;
|
|
|
|
std::string mHelpText;
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
bool mFocused;
|
|
|
|
bool mEnabled;
|
2021-09-17 19:25:21 +00:00
|
|
|
bool mFlatStyle;
|
|
|
|
|
2020-06-28 16:39:18 +00:00
|
|
|
unsigned int mTextColorFocused;
|
|
|
|
unsigned int mTextColorUnfocused;
|
2021-09-17 19:25:21 +00:00
|
|
|
unsigned int mFlatColorFocused;
|
|
|
|
unsigned int mFlatColorUnfocused;
|
2013-08-22 20:29:50 +00:00
|
|
|
};
|
2017-10-31 17:12:50 +00:00
|
|
|
|
|
|
|
#endif // ES_CORE_COMPONENTS_BUTTON_COMPONENT_H
|