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
|
|
|
|
2021-09-23 22:05:32 +00:00
|
|
|
class ButtonComponent : public GuiComponent {
|
2013-08-22 20:29:50 +00:00
|
|
|
public:
|
2021-09-23 22:05:32 +00:00
|
|
|
ButtonComponent(Window *window,
|
|
|
|
const std::string &text = "",
|
|
|
|
const std::string &helpText = "",
|
|
|
|
const std::function<void()> &func = nullptr,
|
2021-09-17 19:25:21 +00:00
|
|
|
bool upperCase = true,
|
|
|
|
bool flatStyle = false);
|
|
|
|
|
|
|
|
void onSizeChanged() override;
|
2021-09-23 22:05:32 +00:00
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
void onFocusGained() override;
|
2021-09-23 22:05:32 +00:00
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
void onFocusLost() override;
|
|
|
|
|
2021-09-23 22:05:32 +00:00
|
|
|
void setText(const std::string &text, const std::string &helpText, bool upperCase = true);
|
|
|
|
|
|
|
|
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; }
|
2021-09-23 22:05:32 +00:00
|
|
|
|
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);
|
2021-09-23 22:05:32 +00:00
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
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; }
|
2021-09-23 22:05:32 +00:00
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
void setFlatColorUnfocused(unsigned int color) { mFlatColorUnfocused = color; }
|
2013-08-23 02:41:40 +00:00
|
|
|
|
2021-09-23 22:05:32 +00:00
|
|
|
const std::function<void()> &getPressedFunc() const { return mPressedFunc; }
|
2014-03-15 22:06:16 +00:00
|
|
|
|
2021-09-23 22:05:32 +00:00
|
|
|
bool input(InputConfig *config, Input input) override;
|
|
|
|
|
|
|
|
void render(const glm::mat4 &parentTrans) 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:
|
2021-09-17 19:25:21 +00:00
|
|
|
unsigned int getCurTextColor() const;
|
2021-09-23 22:05:32 +00:00
|
|
|
|
2021-09-17 19:25:21 +00:00
|
|
|
void updateImage();
|
|
|
|
|
|
|
|
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
|