Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/trunk/src/lib/graphics/text_engine/text.h @ 5362

Last change on this file since 5362 was 5362, checked in by bensch, 19 years ago

oroxnox/trunk: gui extends element2D

File size: 3.3 KB
Line 
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_CENTER          //!< default alignment
21#define TEXT_DEFAULT_SIZE            20                         //!< default size of the Text
22
23
24// FORWARD DECLARATION
25class Font;
26
27/**
28 * STATIC means: a font, that is only one GL-face.
29 ** it is very fast, and can be used for all text
30 ** that does not have to be changed anymore, or if
31 ** the the text should look very nice
32 * DYNAMIC means: a very fast font, that will is build
33 ** from multiple quads.
34 ** Use this type, if you want to create fast changing
35 ** text like a counter.
36 */
37typedef enum TEXT_RENDER_TYPE
38{
39  TEXT_RENDER_STATIC      = 1,
40  TEXT_RENDER_DYNAMIC     = 2
41};
42
43//! A Struct to handel Texture Coordinates for quads
44struct TexCoord
45{
46  float    minU;              //!< The minimum U-Coordinate
47  float    maxU;              //!< The maximum U-Coordinate
48  float    minV;              //!< The minimum V-Coordinate
49  float    maxV;              //!< The maximum V-Coordinate
50};
51
52//! Represents one textElement.
53class Text : public Element2D
54{
55  public:
56    Text(const char* fontFile, unsigned int fontSize = TEXT_DEFAULT_SIZE, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
57    ~Text();
58    void init();
59
60    void setFont(const char* fontFile, unsigned int fontSize);
61
62    void setType(TEXT_RENDER_TYPE type);
63    void setText(const char* text, bool isExtern = false);
64    /** @returns the String this Text displays */
65    inline const char* getText() const { return (externText == NULL)?this->text:this->externText; };
66    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
67    inline void setBlending(float blending) { this->blending = blending; };
68    /** sets the Color of the Text to render (values in [0-1]) @param r red @param g green @param b blue */
69    void setColor(float r, float g, float b) { this->color = Vector(r,g,b); };
70
71    void createTexture();
72
73    virtual void draw() const;
74
75    void debug() const;
76
77  // helpers.
78    static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
79    static int powerOfTwo(int input);
80
81  private:
82    Font*             font;           //!< Font of this text
83
84    TEXT_RENDER_TYPE  type;           //!< The type of this Font.
85    char*             text;           //!< The text to display
86    const char*       externText;     //!< the text to Display from an external Source.
87    Vector            color;          //!< The color of the font.
88    float             blending;       //!< The blending intensity.
89
90  // placement in openGL
91    GLuint            texture;        //!< A GL-texture to hold the text (static Mode)
92    TexCoord          texCoord;       //!< Texture-coordinates @todo fix this to have a struct
93    float             height;
94    float             width;
95};
96
97#endif /* _TEXT_H */
Note: See TracBrowser for help on using the repository browser.