Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 3843 in orxonox.OLD for orxonox/trunk/src/lib/graphics


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

orxonox/trunk: alignment for text implemented

Location:
orxonox/trunk/src/lib/graphics
Files:
2 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}
  • orxonox/trunk/src/lib/graphics/text_engine.h

    r3833 r3843  
    2929template<class T> class tList;
    3030
     31//! An enumerator for the text alignment.
     32enum TEXT_ALIGNMENT {TEXT_ALIGN_LEFT, TEXT_ALIGN_RIGHT, TEXT_ALIGN_CENTER};
    3133
    3234/* some default values */
    3335#define FONT_DEFAULT_SIZE       50                   //!< default size of the Text
    34 #define FONT_DEFAULT_TEXT       "orxonox 1234567890" //!< some default text to display
    35 #define FONT_DEFAULT_COLOR_R    255                  //!< the default red part (color) of the text
    36 #define FONT_DEFAULT_COLOR_G    255                  //!< the default red green (color) of the text
    37 #define FONT_DEFAULT_COLOR_B    255                  //!< the default red blue (color) of the text
    38 #define FONT_NUM_COLORS         256                  //!< The number of colors.
     36#define FONT_DEFAULT_TEXT       "orxonox 1234567890" //!< default text to display
     37#define FONT_DEFAULT_COLOR_R    255                  //!< default red part (color) of the text
     38#define FONT_DEFAULT_COLOR_G    255                  //!< default red green (color) of the text
     39#define FONT_DEFAULT_COLOR_B    255                  //!< default red blue (color) of the text
     40#define FONT_NUM_COLORS         256                  //!< number of colors.
    3941
    4042#define FONT_HIGHEST_KNOWN_CHAR 128                  //!< The highest character known to the textEngine.
    4143
     44#define TEXT_DEFAULT_ALIGNMENT  TEXT_ALIGN_CENTER    //!< default alignment
    4245#define TEXT_STATIC             0                    //!< Static Text
    4346#define TEXT_DYNAMIC            1                    //!< Dynamic Text
     
    101104  void setText(const char* text);
    102105  void setPosition(int x, int y);
     106  void setAlignment(TEXT_ALIGNMENT alignemnt);
    103107  /** \param blending the blending intensity to set (between 0.0 and 1.0) */
    104108  inline void setBlending(float blending) {this->blending = blending;}
     
    107111  void setColor(Uint8 r, Uint8 g, Uint8 b);
    108112  void setStyle(char* renderStyle);
     113
    109114  void createTexture();
    110115
     
    121126  char* text;                    //!< The text to display
    122127  SDL_Color color;               //!< The color of the font.
     128  TEXT_ALIGNMENT alignment;      //!< The aignment of the text.
    123129  float blending;                //!< The blending intensity.
    124130  // placement in openGL
Note: See TracChangeset for help on using the changeset viewer.