95 lines
1.9 KiB
C++
95 lines
1.9 KiB
C++
/*
|
|
* TextArea.h
|
|
*
|
|
* Created on: Nov 27, 2016
|
|
* Author: tibi
|
|
*/
|
|
|
|
#ifndef GUI_PRIMITIVES_TEXTAREA_H_
|
|
#define GUI_PRIMITIVES_TEXTAREA_H_
|
|
|
|
#include <gui/primitives/UIElement.h>
|
|
|
|
#include <vector>
|
|
|
|
namespace farmlands {
|
|
namespace gui {
|
|
namespace widgets {
|
|
|
|
enum class TextAlign
|
|
{
|
|
TopLeft,
|
|
TopCenter,
|
|
TopRight,
|
|
MiddleLeft,
|
|
MiddleCenter,
|
|
MiddleRight,
|
|
BottomLeft,
|
|
BottomCenter,
|
|
BottomRight,
|
|
};
|
|
|
|
enum class TextHorizontalWrapping
|
|
{
|
|
Overflow,
|
|
Wrap,
|
|
Trim,
|
|
Ellipsis
|
|
};
|
|
|
|
enum class TextVerticalWrapping
|
|
{
|
|
Overflow,
|
|
Trim
|
|
};
|
|
|
|
class TextArea: public primitives::UIElement
|
|
{
|
|
public:
|
|
TextArea();
|
|
virtual ~TextArea();
|
|
|
|
virtual void render(RenderContext& context) override;
|
|
|
|
// Getters and setters
|
|
inline std::string text() const { return m_text; }
|
|
inline int font() const { return m_fontId; }
|
|
inline int textSize() const { return m_fontSize; }
|
|
inline SDL_Color color() const { return m_color; }
|
|
inline TextAlign alignment() const { return m_align; }
|
|
inline TextHorizontalWrapping horizontalWrap() const { return m_horWrap; }
|
|
inline TextVerticalWrapping verticalWrap() const { return m_verWrap; }
|
|
|
|
void setText(const std::string& text);
|
|
void setFont(int fontId);
|
|
void setTextSize(int size);
|
|
void setColor(SDL_Color color);
|
|
void setColor(float r, float g, float b, float a = 1.0f);
|
|
void setAlignment(TextAlign align);
|
|
void setHorizontalWrap(TextHorizontalWrapping wrap);
|
|
void setVerticalWrap(TextVerticalWrapping wrap);
|
|
|
|
private:
|
|
void wrapText(TTF_Font* font);
|
|
void renderLines(RenderContext& context, TTF_Font* font);
|
|
|
|
std::string m_text;
|
|
std::string m_wrappedText;
|
|
|
|
bool m_textChanged;
|
|
int m_fontId;
|
|
int m_fontSize;
|
|
SDL_Color m_color;
|
|
TextAlign m_align;
|
|
TextHorizontalWrapping m_horWrap;
|
|
TextVerticalWrapping m_verWrap;
|
|
|
|
std::vector<SDL_Texture*> m_renderedLines;
|
|
};
|
|
|
|
} /* namespace primitives */
|
|
} /* namespace gui */
|
|
} /* namespace farmlands */
|
|
|
|
#endif /* GUI_PRIMITIVES_TEXTAREA_H_ */
|