1 | /*! |
---|
2 | * @file text.h |
---|
3 | * @brief Definition of a text Class, that is able to render text. |
---|
4 | */ |
---|
5 | |
---|
6 | #ifndef _TEXT_H |
---|
7 | #define _TEXT_H |
---|
8 | |
---|
9 | #include "element_2d.h" |
---|
10 | #include "color.h" |
---|
11 | #include "font.h" |
---|
12 | |
---|
13 | #define TEXT_ALIGN_LEFT E2D_ALIGN_LEFT |
---|
14 | #define TEXT_ALIGN_RIGHT E2D_ALIGN_RIGHT |
---|
15 | #define TEXT_ALIGN_CENTER E2D_ALIGN_CENTER |
---|
16 | #define TEXT_ALIGN_SCREEN_CENTER E2D_ALIGN_SCREEN_CENTER |
---|
17 | #define TEXT_DEFAULT_COLOR Color(1.0, 1.0, 1.0, 1.0f) //!< the default Color (white, fully visible) |
---|
18 | |
---|
19 | #define TEXT_DEFAULT_ALIGNMENT TEXT_ALIGN_LEFT //!< default alignment |
---|
20 | #define TEXT_DEFAULT_SIZE 20 //!< default size of the Text |
---|
21 | |
---|
22 | // FORWARD DECLARATION |
---|
23 | struct SDL_Surface; |
---|
24 | |
---|
25 | //! Represents one textElement. |
---|
26 | class Text : public Element2D |
---|
27 | { |
---|
28 | public: |
---|
29 | Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE); |
---|
30 | Text(const Text& text); |
---|
31 | virtual ~Text(); |
---|
32 | bool operator==(const Text& text) const; |
---|
33 | bool operator==(const std::string& text) const; |
---|
34 | Text& operator=(const Text& text); |
---|
35 | |
---|
36 | /// Final Interfacing. |
---|
37 | void setText(const std::string& text); |
---|
38 | void append(const std::string& appendText); |
---|
39 | void appendCharacter(char character); |
---|
40 | const std::string& operator<<(const std::string& appendText); |
---|
41 | void removeCharacters(unsigned int chars); |
---|
42 | void clear(); |
---|
43 | |
---|
44 | /// SETUP |
---|
45 | void setFont(const std::string& fontFile, unsigned int renderSize); |
---|
46 | void setFont(const Font& font); |
---|
47 | /** @param blending the blending intensity to set (between 0.0 and 1.0) */ |
---|
48 | inline void setBlending(float blending) { this->_font.setTransparency(blending); }; |
---|
49 | /** @param r red @param g green @param b blue @brief sets the Color of the Text to render (values in [0-1]) */ |
---|
50 | void setColor(float r, float g, float b) { this->_font.setDiffuseColor(Color(r, g, b, this->blending())); }; |
---|
51 | void setColor(float r, float g, float b, float a) { this->_font.setDiffuseColor(Color(r, g, b, a)); }; |
---|
52 | void setColor(const Color& color) { this->_font.setDiffuseColor(color); }; |
---|
53 | void setSize(float size); |
---|
54 | |
---|
55 | |
---|
56 | /// RETRIEVE |
---|
57 | /** @returns the String this Text displays */ |
---|
58 | inline const std::string& text() const { return this->_text; }; |
---|
59 | |
---|
60 | /** @returns the pointer to the stored Font (not changeable) */ |
---|
61 | inline const Font& font() const { return this->_font; }; |
---|
62 | /** @returns the Blending Value [0 invisible 1.0 full visible */ |
---|
63 | inline float blending() const { return this->_font.diffuseColor().a(); }; |
---|
64 | /** @returns: a Vector(r,g,b) @brief: retrieve a Vector holding the Color of the Text */ |
---|
65 | inline const Color& color() const { return this->_font.diffuseColor(); }; |
---|
66 | /** @returns the Size of the Text */ |
---|
67 | inline float size() const { return this->_size; }; |
---|
68 | |
---|
69 | virtual void draw() const; |
---|
70 | |
---|
71 | void debug() const; |
---|
72 | |
---|
73 | protected: |
---|
74 | virtual void setupTextWidth(); |
---|
75 | private: |
---|
76 | void init(); |
---|
77 | |
---|
78 | private: |
---|
79 | Font _font; //!< Font of this text |
---|
80 | |
---|
81 | std::string _text; //!< The text to display |
---|
82 | float _size; //!< The size of the Text. |
---|
83 | }; |
---|
84 | |
---|
85 | #endif /* _TEXT_H */ |
---|