Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 2, 2005, 11:24:45 PM (20 years ago)
Author:
bensch
Message:

orxonox/branches/textEngine: packed some parameters for texts into a Struct, to build a List of texts.

Location:
orxonox/branches/textEngine/src/lib/graphics/font
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.cc

    r3713 r3714  
    7171GLFont::~GLFont(void)
    7272{
     73  delete this->currentText;
     74
    7375  if (this->font)
    7476    TTF_CloseFont(this->font);
     
    8284  if (!GLFont::ttfInitialized)
    8385    {
    84       if(TTF_Init()==-1) {
     86      if(TTF_Init()==-1)
    8587        PRINTF(1)("TTF_Init: %s\n", TTF_GetError());
    86         exit(2);
    87       }
     88
    8889      GLFont::checkVersion();
    8990      GLFont::ttfInitialized = true;
     
    124125  this->font = NULL;
    125126  this->fontFile = NULL;
    126   this->text = NULL;
    127   this->texture = 0;
     127
     128  this->currentText = new Text;
     129
     130  this->currentText->text = NULL;
     131  this->currentText->texture = 0;
    128132 
    129133  this->setSize(fontSize);
    130134 
    131   this->renderStyle = TTF_STYLE_NORMAL;
     135  this->currentText->renderStyle = TTF_STYLE_NORMAL;
    132136
    133137  this->setFont(fontFile);
     
    173177void GLFont::setText(const char* text)
    174178{
    175   if (this->text)
    176     delete []this->text;
    177   this->text = new char[strlen(text)+1];
    178   strcpy(this->text, text);
     179  if (this->currentText->text)
     180    delete []this->currentText->text;
     181  this->currentText->text = new char[strlen(text)+1];
     182  strcpy(this->currentText->text, text);
    179183}
    180184
     
    186190void GLFont::setStyle(char* renderStyle)
    187191{
    188   this->renderStyle = TTF_STYLE_NORMAL;
     192  this->currentText->renderStyle = TTF_STYLE_NORMAL;
    189193 
    190194  for (int i = 0; i < strlen(renderStyle); i++)
    191195    if (strncmp(renderStyle+i, "b", 1) == 0)
    192       this->renderStyle |= TTF_STYLE_BOLD;
     196      this->currentText->renderStyle |= TTF_STYLE_BOLD;
    193197    else if (strncmp(renderStyle+i, "i", 1) == 0)
    194       this->renderStyle |= TTF_STYLE_ITALIC;
     198      this->currentText->renderStyle |= TTF_STYLE_ITALIC;
    195199    else if (strncmp(renderStyle+i, "u", 1) == 0)
    196       this->renderStyle |= TTF_STYLE_UNDERLINE;
     200      this->currentText->renderStyle |= TTF_STYLE_UNDERLINE;
    197201
    198202  if (this->font)
    199     TTF_SetFontStyle(this->font, this->renderStyle);
     203    TTF_SetFontStyle(this->font, this->currentText->renderStyle);
    200204  else
    201205    PRINTF(2)("Font was not initialized, please do so before setting the Font-Style.\n");
     
    219223void GLFont::setColor(Uint8 r, Uint8 g, Uint8 b)
    220224{
    221   this->color.r = r;
    222   this->color.g = g;
    223   this->color.b = b;
     225  this->currentText->color.r = r;
     226  this->currentText->color.g = g;
     227  this->currentText->color.b = b;
    224228}
    225229
     
    231235void GLFont::setPosition(int x, int y)
    232236{
    233   this->textPosSize.x = x;
    234   this->textPosSize.y = y;
     237  this->currentText->textPosSize.x = x;
     238  this->currentText->textPosSize.y = y;
    235239}
    236240
     
    242246{
    243247  this->enter2DMode();
    244   glBindTexture(GL_TEXTURE_2D, texture);
     248
     249  glBindTexture(GL_TEXTURE_2D, this->currentText->texture);
    245250  glEnable(GL_TEXTURE_2D);
    246251  glBegin(GL_QUADS);
    247   glTexCoord2f(this->texCoord.minU, this->texCoord.minV); glVertex2i(20,   20  );
    248   glTexCoord2f(this->texCoord.maxU, this->texCoord.minV); glVertex2i(20+this->textPosSize.w, 20  );
    249   glTexCoord2f(this->texCoord.maxU, this->texCoord.maxV); glVertex2i(20+this->textPosSize.w, 20+this->textPosSize.h);
    250   glTexCoord2f(this->texCoord.minU, this->texCoord.maxV); glVertex2i(20, 20+this->textPosSize.h);
     252
     253  glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.minV);
     254  glVertex2i(20,   20  );
     255
     256  glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.minV);
     257  glVertex2i(20+this->currentText->textPosSize.w, 20  );
     258
     259  glTexCoord2f(this->currentText->texCoord.maxU, this->currentText->texCoord.maxV);
     260  glVertex2i(20+this->currentText->textPosSize.w, 20+this->currentText->textPosSize.h);
     261
     262  glTexCoord2f(this->currentText->texCoord.minU, this->currentText->texCoord.maxV);
     263  glVertex2i(20, 20+this->currentText->textPosSize.h);
     264
    251265  glEnd();
     266
    252267  this->leave2DMode();
    253 
    254 }
    255 
     268}
    256269
    257270/**
     
    263276{
    264277  SDL_Surface* tmpSurf;
    265   if (this->texture)
    266     glDeleteTextures(1, &this->texture);
    267   tmpSurf = TTF_RenderText_Blended(this->font, this->text, this->color);
     278  if (this->currentText->texture)
     279    glDeleteTextures(1, &this->currentText->texture);
     280  tmpSurf = TTF_RenderText_Blended(this->font,
     281                                   this->currentText->text,
     282                                   this->currentText->color);
    268283  if (tmpSurf)
    269     this->texture = loadTexture(tmpSurf, &texCoord);
    270 
    271   this->textPosSize.w = tmpSurf->w;
    272   this->textPosSize.h = tmpSurf->h;
     284    this->currentText->texture = loadTexture(tmpSurf, &this->currentText->texCoord);
     285
     286  this->currentText->textPosSize.w = tmpSurf->w;
     287  this->currentText->textPosSize.h = tmpSurf->h;
    273288  SDL_FreeSurface(tmpSurf);
    274289}
  • orxonox/branches/textEngine/src/lib/graphics/font/glfont.h

    r3707 r3714  
    1010#include "SDL_ttf.h"
    1111
     12// FORWARD DECLARATION
     13template<class T> class tList;
    1214
    1315/* some default values */
     
    7476  TTF_Font* font;                  //!< The font we use for this.
    7577  char* fontFile;                  //!< The fontfile from whitch the font was loaded.
    76   char* text;                      //!< The text to display
    77   unsigned int fontSize;           //!< The size of the font in pixels
    78   SDL_Color color;                 //!< The color of the font.
     78  unsigned int fontSize;           //!< The size of the font in pixels. each Font has one size.
    7979
    80   // placement in openGL
    81   GLuint texture;                  //!< A GL-texture to hold the text
    82   SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
    83   int renderStyle;                 //!< The Renderstyle
    84   TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
     80  //! Represents one textElement.
     81  struct Text
     82  {
     83    char* text;                      //!< The text to display
     84    SDL_Color color;                 //!< The color of the font.
     85    // placement in openGL
     86    GLuint texture;                  //!< A GL-texture to hold the text
     87    TexCoord texCoord;               //!< Texture-coordinates \todo fix this to have a struct
     88    SDL_Rect textPosSize;            //!< An SDL-Rectangle representing the position and size of the Text on the screen.
     89    int renderStyle;                 //!< The Renderstyle
     90  };
     91  tList<Text>* textList;
     92  Text* currentText;
    8593
    8694  bool init(const char* fontFile, unsigned int fontSize = FONT_DEFAULT_SIZE);
Note: See TracChangeset for help on using the changeset viewer.