/*! * @file text.h * @brief Definition of a text Class, that is able to render text. */ #ifndef _TEXT_H #define _TEXT_H #include "element_2d.h" #include "color.h" #define TEXT_ALIGN_LEFT E2D_ALIGN_LEFT #define TEXT_ALIGN_RIGHT E2D_ALIGN_RIGHT #define TEXT_ALIGN_CENTER E2D_ALIGN_CENTER #define TEXT_ALIGN_SCREEN_CENTER E2D_ALIGN_SCREEN_CENTER #define TEXT_DEFAULT_COLOR Color(1.0, 1.0, 1.0, 1.0f) //!< the default Color (white, fully visible) #define TEXT_DEFAULT_ALIGNMENT TEXT_ALIGN_LEFT //!< default alignment #define TEXT_DEFAULT_SIZE 20 //!< default size of the Text // FORWARD DECLARATION class Font; struct SDL_Surface; //! Represents one textElement. class Text : public Element2D { public: Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE); Text(const Text& text); virtual ~Text(); bool operator==(const Text& text) const; bool operator==(const std::string& text) const; Text& operator=(const Text& text); /// Final Interfacing. void setText(const std::string& text); void append(const std::string& appendText); void appendCharacter(char character); const std::string& operator<<(const std::string& appendText); void removeCharacters(unsigned int chars); void clear(); /// SETUP void setFont(const std::string& fontFile, unsigned int renderSize); /** @param blending the blending intensity to set (between 0.0 and 1.0) */ inline void setBlending(float blending) { this->_color.a() = blending; }; /** @param r red @param g green @param b blue @brief sets the Color of the Text to render (values in [0-1]) */ void setColor(float r, float g, float b) { this->_color = Color(r, g, b, this->_color.a()); }; void setColor(float r, float g, float b, float a) { this->_color = Color(r, g, b, a); }; void setColor(const Color& color) { this->_color = color; }; void setSize(float size); /// RETRIEVE /** @returns the String this Text displays */ inline const std::string& text() const { return this->_text; }; /** @returns the pointer to the stored Font (not changeable) */ inline const Font* const font() const { return this->_font; }; /** @returns the Blending Value [0 invisible 1.0 full visible */ inline float blending() const { return this->_color.a(); }; /** @returns: a Vector(r,g,b) @brief: retrieve a Vector holding the Color of the Text */ inline const Color& color() const { return this->_color; }; /** @returns the Size of the Text */ inline float size() const { return this->_size; }; virtual void draw() const; void debug() const; protected: virtual void setupTextWidth(); private: void init(); private: Font* _font; //!< Font of this text std::string _text; //!< The text to display Color _color; //!< The color of the font. float _size; //!< The size of the Text. }; #endif /* _TEXT_H */