ES-DE/es-core/src/components/ButtonComponent.h

52 lines
1.3 KiB
C
Raw Normal View History

2013-08-22 20:29:50 +00:00
#pragma once
#ifndef ES_CORE_COMPONENTS_BUTTON_COMPONENT_H
#define ES_CORE_COMPONENTS_BUTTON_COMPONENT_H
2013-08-22 20:29:50 +00:00
#include "components/NinePatchComponent.h"
2017-11-01 22:21:10 +00:00
#include "GuiComponent.h"
class TextCache;
2013-08-22 20:29:50 +00:00
class ButtonComponent : public GuiComponent
{
public:
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
void setPressedFunc(std::function<void()> f);
void setEnabled(bool enable);
2013-08-22 20:29:50 +00:00
bool input(InputConfig* config, Input input) override;
void render(const Transform4x4f& parentTrans) override;
2013-08-22 20:29:50 +00:00
void setText(const std::string& text, const std::string& helpText);
inline const std::string& getText() const { return mText; };
inline const std::function<void()>& getPressedFunc() const { return mPressedFunc; };
void onSizeChanged() override;
void onFocusGained() override;
void onFocusLost() override;
virtual std::vector<HelpPrompt> getHelpPrompts() override;
2013-08-22 20:29:50 +00:00
private:
std::shared_ptr<Font> mFont;
2013-08-22 20:29:50 +00:00
std::function<void()> mPressedFunc;
bool mFocused;
bool mEnabled;
unsigned int mTextColorFocused;
unsigned int mTextColorUnfocused;
unsigned int getCurTextColor() const;
void updateImage();
2013-08-22 20:29:50 +00:00
std::string mText;
std::string mHelpText;
2013-08-22 20:29:50 +00:00
std::unique_ptr<TextCache> mTextCache;
NinePatchComponent mBox;
2013-08-22 20:29:50 +00:00
};
#endif // ES_CORE_COMPONENTS_BUTTON_COMPONENT_H