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