2013-08-22 20:29:50 +00:00
|
|
|
#pragma once
|
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "GuiComponent.h"
|
2013-08-22 20:29:50 +00:00
|
|
|
#include <functional>
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "resources/Font.h"
|
|
|
|
#include "components/NinePatchComponent.h"
|
2013-08-22 20:29:50 +00:00
|
|
|
|
|
|
|
class ButtonComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
2014-03-12 03:00:08 +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
|
|
|
|
|
|
|
void setPressedFunc(std::function<void()> f);
|
|
|
|
|
2014-03-12 03:00:08 +00:00
|
|
|
void setEnabled(bool enable);
|
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
bool input(InputConfig* config, Input input) override;
|
2017-10-28 20:24:35 +00:00
|
|
|
void render(const Transform4x4f& parentTrans) override;
|
2013-08-22 20:29:50 +00:00
|
|
|
|
2014-03-08 17:48:47 +00:00
|
|
|
void setText(const std::string& text, const std::string& helpText);
|
2013-08-23 02:41:40 +00:00
|
|
|
|
2014-03-15 22:06:16 +00:00
|
|
|
inline const std::string& getText() const { return mText; };
|
|
|
|
inline const std::function<void()>& getPressedFunc() const { return mPressedFunc; };
|
|
|
|
|
2013-08-23 02:41:40 +00:00
|
|
|
void onSizeChanged() override;
|
2013-09-07 22:43:36 +00:00
|
|
|
void onFocusGained() override;
|
|
|
|
void onFocusLost() override;
|
2013-08-23 02:41:40 +00:00
|
|
|
|
2014-01-25 23:34:29 +00:00
|
|
|
virtual std::vector<HelpPrompt> getHelpPrompts() override;
|
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
private:
|
2014-03-15 18:39:19 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
2013-08-22 20:29:50 +00:00
|
|
|
std::function<void()> mPressedFunc;
|
|
|
|
|
2013-09-07 22:43:36 +00:00
|
|
|
bool mFocused;
|
2014-03-12 03:00:08 +00:00
|
|
|
bool mEnabled;
|
2013-09-07 22:43:36 +00:00
|
|
|
unsigned int mTextColorFocused;
|
|
|
|
unsigned int mTextColorUnfocused;
|
2014-03-08 17:48:47 +00:00
|
|
|
|
2013-09-07 22:43:36 +00:00
|
|
|
unsigned int getCurTextColor() const;
|
2014-03-12 03:00:08 +00:00
|
|
|
void updateImage();
|
2013-09-07 22:43:36 +00:00
|
|
|
|
2013-08-22 20:29:50 +00:00
|
|
|
std::string mText;
|
2014-01-25 23:34:29 +00:00
|
|
|
std::string mHelpText;
|
2013-08-22 20:29:50 +00:00
|
|
|
std::unique_ptr<TextCache> mTextCache;
|
2013-08-23 02:41:40 +00:00
|
|
|
NinePatchComponent mBox;
|
2013-08-22 20:29:50 +00:00
|
|
|
};
|