2013-06-14 15:48:13 +00:00
|
|
|
#ifndef _TEXTCOMPONENT_H_
|
|
|
|
#define _TEXTCOMPONENT_H_
|
|
|
|
|
2014-06-20 01:30:09 +00:00
|
|
|
#include "GuiComponent.h"
|
|
|
|
#include "resources/Font.h"
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2013-11-25 20:49:02 +00:00
|
|
|
class ThemeData;
|
|
|
|
|
2014-01-24 22:21:10 +00:00
|
|
|
// Used to display text.
|
|
|
|
// TextComponent::setSize(x, y) works a little differently than most components:
|
|
|
|
// * (0, 0) - will automatically calculate a size that fits the text on one line (expand horizontally)
|
|
|
|
// * (x != 0, 0) - wrap text so that it does not reach beyond x. Will automatically calculate a vertical size (expand vertically).
|
|
|
|
// * (x != 0, y <= fontHeight) - will truncate text so it fits within this box.
|
2013-06-14 15:48:13 +00:00
|
|
|
class TextComponent : public GuiComponent
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
TextComponent(Window* window);
|
2014-03-21 19:51:25 +00:00
|
|
|
TextComponent(Window* window, const std::string& text, const std::shared_ptr<Font>& font, unsigned int color = 0x000000FF, Alignment align = ALIGN_LEFT,
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector3f pos = Vector3f::Zero(), Vector2f size = Vector2f::Zero(), unsigned int bgcolor = 0x00000000);
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2014-03-08 01:35:16 +00:00
|
|
|
void setFont(const std::shared_ptr<Font>& font);
|
2014-05-03 19:51:50 +00:00
|
|
|
void setUppercase(bool uppercase);
|
2013-07-10 11:29:43 +00:00
|
|
|
void onSizeChanged() override;
|
2013-06-14 15:48:13 +00:00
|
|
|
void setText(const std::string& text);
|
|
|
|
void setColor(unsigned int color);
|
2017-08-15 02:34:34 +00:00
|
|
|
void setHorizontalAlignment(Alignment align);
|
|
|
|
void setVerticalAlignment(Alignment align);
|
2014-05-14 22:01:40 +00:00
|
|
|
void setLineSpacing(float spacing);
|
2017-03-13 21:11:07 +00:00
|
|
|
void setBackgroundColor(unsigned int color);
|
2017-05-01 02:54:27 +00:00
|
|
|
void setRenderBackground(bool render);
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2017-10-28 20:24:35 +00:00
|
|
|
void render(const Transform4x4f& parentTrans) override;
|
2013-06-14 15:48:13 +00:00
|
|
|
|
2013-08-14 12:16:49 +00:00
|
|
|
std::string getValue() const override;
|
|
|
|
void setValue(const std::string& value) override;
|
2013-10-10 21:14:33 +00:00
|
|
|
|
|
|
|
unsigned char getOpacity() const override;
|
|
|
|
void setOpacity(unsigned char opacity) override;
|
2013-08-14 12:16:49 +00:00
|
|
|
|
2014-03-08 01:35:16 +00:00
|
|
|
inline std::shared_ptr<Font> getFont() const { return mFont; }
|
2013-09-19 23:41:14 +00:00
|
|
|
|
2014-01-01 05:39:22 +00:00
|
|
|
virtual void applyTheme(const std::shared_ptr<ThemeData>& theme, const std::string& view, const std::string& element, unsigned int properties) override;
|
|
|
|
|
2013-09-19 23:41:14 +00:00
|
|
|
private:
|
2013-06-19 01:12:30 +00:00
|
|
|
void calculateExtent();
|
|
|
|
|
2013-08-22 01:08:36 +00:00
|
|
|
void onTextChanged();
|
2013-10-10 21:14:33 +00:00
|
|
|
void onColorChanged();
|
2013-08-22 01:08:36 +00:00
|
|
|
|
2013-06-14 15:48:13 +00:00
|
|
|
unsigned int mColor;
|
2017-03-13 21:11:07 +00:00
|
|
|
unsigned int mBgColor;
|
|
|
|
unsigned char mColorOpacity;
|
|
|
|
unsigned char mBgColorOpacity;
|
2017-05-01 02:54:27 +00:00
|
|
|
bool mRenderBackground;
|
2017-03-13 21:11:07 +00:00
|
|
|
|
2013-07-03 07:54:55 +00:00
|
|
|
std::shared_ptr<Font> mFont;
|
2014-05-03 19:51:50 +00:00
|
|
|
bool mUppercase;
|
2017-10-28 20:24:35 +00:00
|
|
|
Vector2i mAutoCalcExtent;
|
2013-06-14 15:48:13 +00:00
|
|
|
std::string mText;
|
2013-09-19 23:41:14 +00:00
|
|
|
std::shared_ptr<TextCache> mTextCache;
|
2017-08-15 02:34:34 +00:00
|
|
|
Alignment mHorizontalAlignment;
|
|
|
|
Alignment mVerticalAlignment;
|
2014-05-14 22:01:40 +00:00
|
|
|
float mLineSpacing;
|
2013-06-14 15:48:13 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|