Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Ignore:
Timestamp:
Apr 17, 2005, 12:27:53 AM (19 years ago)
Author:
bensch
Message:

orxonox/trunk: alignment for text implemented

File:
1 edited

Legend:

Unmodified
Added
Removed
  • orxonox/trunk/src/lib/graphics/text_engine.cc

    r3840 r3843  
    5757  this->font = font;
    5858  this->text = NULL;
     59  this->alignment = TEXT_DEFAULT_ALIGNMENT;
    5960  this->texture = 0;
    6061  this->blending = 1.0f;
     
    101102  this->text = new char[strlen(text)+1];
    102103  strcpy(this->text, text);
     104
     105
     106  // setting up the Text-Width if DYNAMIC
     107  if (this->type == TEXT_DYNAMIC)
     108    {
     109      Glyph** glyphArray = this->font->getGlyphArray();
     110
     111      int width = 0;
     112      char* tmpText = this->text;
     113      while (*tmpText != '\0')
     114        {
     115          if(glyphArray[*tmpText])
     116            {
     117              width += glyphArray[*tmpText]->width;
     118            }
     119          tmpText++;
     120        }
     121      this->posSize.w = width;
     122    }
    103123}
    104124
     
    112132  this->posSize.x = x;
    113133  this->posSize.y = y;
     134}
     135
     136/**
     137   \brief sets the text-alignment
     138   \param alignment the alignment to set
     139*/
     140void Text::setAlignment(TEXT_ALIGNMENT alignemnt)
     141{
     142  this->alignment = alignment;
    114143}
    115144
     
    188217  glColor4f(1.0f,1.0f,1.0f, this->blending);
    189218  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
     219
     220  glPushMatrix();
     221  // transform for alignment.
     222  if (this->alignment == TEXT_ALIGN_RIGHT)
     223    glTranslatef(-this->posSize.w, 0, 0);
     224  else   if (this->alignment == TEXT_ALIGN_CENTER)
     225    glTranslatef(-this->posSize.w/2, 0, 0);
    190226
    191227  // drawing this Text.
     
    229265        }
    230266    }
     267  glPopMatrix();
    231268  GraphicsEngine::leave2DMode();
    232269}
Note: See TracChangeset for help on using the changeset viewer.