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