| [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" | 
|---|
| [8448] | 10 | #include "color.h" | 
|---|
| [1853] | 11 |  | 
|---|
| [5343] | 12 | #define  TEXT_ALIGN_LEFT             E2D_ALIGN_LEFT | 
|---|
|  | 13 | #define  TEXT_ALIGN_RIGHT            E2D_ALIGN_RIGHT | 
|---|
|  | 14 | #define  TEXT_ALIGN_CENTER           E2D_ALIGN_CENTER | 
|---|
|  | 15 | #define  TEXT_ALIGN_SCREEN_CENTER    E2D_ALIGN_SCREEN_CENTER | 
|---|
| [8448] | 16 | #define  TEXT_DEFAULT_COLOR          Color(1.0, 1.0, 1.0, 1.0f) //!< the default Color (white, fully visible) | 
|---|
| [5343] | 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); | 
|---|
| [7919] | 39 | void appendCharacter(char character); | 
|---|
| [7753] | 40 | const std::string& operator<<(const std::string& appendText); | 
|---|
| [7919] | 41 | void removeCharacters(unsigned int chars); | 
|---|
| [7753] | 42 |  | 
|---|
|  | 43 | /// SETUP | 
|---|
| [7221] | 44 | void setFont(const std::string& fontFile, unsigned int renderSize); | 
|---|
| [7450] | 45 | /** @param blending the blending intensity to set (between 0.0 and 1.0) */ | 
|---|
| [8448] | 46 | inline void setBlending(float blending) { this->color.a() = blending; }; | 
|---|
| [7450] | 47 | /** @param r red @param g green @param b blue @brief sets the Color of the Text to render (values in [0-1]) */ | 
|---|
| [8448] | 48 | void setColor(float r, float g, float b) { this->color = Color(r, g, b, this->color.a()); }; | 
|---|
|  | 49 | void setColor(float r, float g, float b, float a) { this->color = Color(r, g, b, a); }; | 
|---|
|  | 50 | void setColor(const Color& color) { this->color = color; }; | 
|---|
| [7453] | 51 | void setSize(float size); | 
|---|
| [5367] | 52 |  | 
|---|
| [7753] | 53 |  | 
|---|
| [7450] | 54 | /// RETRIEVE | 
|---|
| [7753] | 55 | /** @returns the String this Text displays */ | 
|---|
|  | 56 | inline const std::string& getText() const { return this->text; }; | 
|---|
|  | 57 |  | 
|---|
| [7450] | 58 | /** @returns the pointer to the stored Font (not changeable) */ | 
|---|
|  | 59 | inline const Font* const getFont() const { return this->font; }; | 
|---|
|  | 60 | /** @returns the Blending Value [0 invisible 1.0 full visible */ | 
|---|
| [8448] | 61 | inline float getBlending() const { return this->color.a(); }; | 
|---|
| [7450] | 62 | /** @returns: a Vector(r,g,b) @brief: retrieve a Vector holding the Color of the Text */ | 
|---|
| [8448] | 63 | inline const Color& getColor() const { return this->color; }; | 
|---|
| [5369] | 64 | /** @returns the Size of the Text */ | 
|---|
| [7453] | 65 | inline float getSize() const { return this->size; }; | 
|---|
| [5343] | 66 |  | 
|---|
|  | 67 | virtual void draw() const; | 
|---|
|  | 68 |  | 
|---|
|  | 69 | void debug() const; | 
|---|
|  | 70 |  | 
|---|
| [7450] | 71 | protected: | 
|---|
|  | 72 | virtual void setupTextWidth(); | 
|---|
| [7753] | 73 | private: | 
|---|
|  | 74 | void init(); | 
|---|
| [7453] | 75 |  | 
|---|
| [5343] | 76 | private: | 
|---|
|  | 77 | Font*             font;           //!< Font of this text | 
|---|
|  | 78 |  | 
|---|
| [7221] | 79 | std::string       text;           //!< The text to display | 
|---|
| [8448] | 80 | Color             color;          //!< The color of the font. | 
|---|
| [7453] | 81 | float             size;           //!< The size of the Text. | 
|---|
| [1853] | 82 | }; | 
|---|
|  | 83 |  | 
|---|
| [5343] | 84 | #endif /* _TEXT_H */ | 
|---|