Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

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

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

orxonox/trunk: some minor include stuff

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