Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 5343 in orxonox.OLD for trunk/src/lib/graphics/text_engine/text.h


Ignore:
Timestamp:
Oct 10, 2005, 12:16:19 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: split open the text-engine

File:
1 copied

Legend:

Unmodified
Added
Removed
  • trunk/src/lib/graphics/text_engine/text.h

    r5330 r5343  
    11/*!
    2  * @file proto_class.h
    3  * @brief Definition of ...
     2 * @file text.h
     3 * @brief Definition of a text Class, that is able to render text.
    44*/
    55
    6 #ifndef _PROTO_CLASS_H
    7 #define _PROTO_CLASS_H
     6#ifndef _TEXT_H
     7#define _TEXT_H
    88
    9 #include "base_object.h"
     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
    1023
    1124// FORWARD DECLARATION
     25class Font;
    1226
    1327
     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.
     37 */typedef enum TEXT_RENDER_TYPE
     38{
     39  TEXT_RENDER_STATIC      = 1,
     40  TEXT_RENDER_DYNAMIC     = 2
     41};
    1442
    15 //! A class for ...
    16 class ProtoClass : public BaseObject {
    17 
    18  public:
    19   ProtoClass();
    20   virtual ~ProtoClass();
     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};
    2151
    2252
    23  private:
     53////////////
     54/// TEXT ///
     55////////////
     56//! Represents one textElement.
     57class Text : public Element2D
     58{
     59  friend class TextEngine;
     60  public:
     61    Text(const char* fontFile, unsigned int fontSize = TEXT_DEFAULT_SIZE, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
     62    ~Text();
    2463
     64    void init();
     65
     66    void setFont(const char* fontFile, unsigned int fontSize);
     67    void setType(TEXT_RENDER_TYPE type);
     68    void setText(const char* text, bool isExtern = false);
     69    /** @returns the String this Text displays */
     70    inline const char* getText() const { return (externText == NULL)?this->text:this->externText; };
     71    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
     72    inline void setBlending(float blending) { this->blending = blending; };
     73
     74    /** sets the Color of the Text to render (values in [0-1]) @param r red @param g green @param b blue */
     75    void setColor(float r, float g, float b) { this->color = Vector(r,g,b); };
     76
     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    Text(Font* font = NULL, TEXT_RENDER_TYPE type = TEXT_RENDER_DYNAMIC);
     89    void setFont(Font* font);
     90
     91
     92  private:
     93    Font*             font;           //!< Font of this text
     94
     95    TEXT_RENDER_TYPE  type;           //!< The type of this Font.
     96    char*             text;           //!< The text to display
     97    const char*       externText;     //!< the text to Display from an external Source.
     98    Vector            color;          //!< The color of the font.
     99    float             blending;       //!< The blending intensity.
     100
     101  // placement in openGL
     102    GLuint            texture;        //!< A GL-texture to hold the text
     103    TexCoord          texCoord;       //!< Texture-coordinates @todo fix this to have a struct
     104    float             height;
     105    float             width;
    25106};
    26107
    27 #endif /* _PROTO_CLASS_H */
     108#endif /* _TEXT_H */
Note: See TracChangeset for help on using the changeset viewer.