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 | |
---|
11 | #include "glincl.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 Vector(1.0, 1.0, 1.0) //!< the default Color (white) |
---|
18 | #define TEXT_DEFAULT_BLENDING 1.0f //!< the default blending of the text, (no blending at all) |
---|
19 | |
---|
20 | #define TEXT_DEFAULT_ALIGNMENT TEXT_ALIGN_LEFT //!< default alignment |
---|
21 | #define TEXT_DEFAULT_SIZE 20 //!< default size of the Text |
---|
22 | |
---|
23 | |
---|
24 | // FORWARD DECLARATION |
---|
25 | class Font; |
---|
26 | struct SDL_Surface; |
---|
27 | |
---|
28 | //! A Struct to handel Texture Coordinates for quads |
---|
29 | struct TexCoord |
---|
30 | { |
---|
31 | float minU; //!< The minimum U-Coordinate |
---|
32 | float maxU; //!< The maximum U-Coordinate |
---|
33 | float minV; //!< The minimum V-Coordinate |
---|
34 | float maxV; //!< The maximum V-Coordinate |
---|
35 | }; |
---|
36 | |
---|
37 | //! Represents one textElement. |
---|
38 | class Text : public Element2D |
---|
39 | { |
---|
40 | public: |
---|
41 | Text(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE); |
---|
42 | virtual ~Text(); |
---|
43 | void init(); |
---|
44 | |
---|
45 | void setFont(const std::string& fontFile, unsigned int renderSize); |
---|
46 | |
---|
47 | void setText(const char* text, bool isExtern = false); |
---|
48 | |
---|
49 | /** @returns the String this Text displays */ |
---|
50 | inline const char* getText() const { return (externText == NULL)?this->text:this->externText; }; |
---|
51 | /** @param blending the blending intensity to set (between 0.0 and 1.0) */ |
---|
52 | inline void setBlending(float blending) { this->blending = blending; }; |
---|
53 | /** sets the Color of the Text to render (values in [0-1]) @param r red @param g green @param b blue */ |
---|
54 | void setColor(float r, float g, float b) { this->color = Vector(r, g, b); }; |
---|
55 | /** sets the Size of the Font */ |
---|
56 | void setSize(float size) { this->setSizeY2D(size); }; |
---|
57 | /** @returns the Size of the Text */ |
---|
58 | // void getSize(float &x, float& y) const { return this->size; }; |
---|
59 | |
---|
60 | virtual void draw() const; |
---|
61 | |
---|
62 | void debug() const; |
---|
63 | |
---|
64 | // helpers. |
---|
65 | static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord); |
---|
66 | static int powerOfTwo(int input); |
---|
67 | |
---|
68 | private: |
---|
69 | Font* font; //!< Font of this text |
---|
70 | |
---|
71 | char* text; //!< The text to display |
---|
72 | const char* externText; //!< the text to Display from an external Source. |
---|
73 | Vector color; //!< The color of the font. |
---|
74 | float blending; //!< The blending intensity. |
---|
75 | }; |
---|
76 | |
---|
77 | #endif /* _TEXT_H */ |
---|