Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

Changeset 8538 in orxonox.OLD


Ignore:
Timestamp:
Jun 16, 2006, 4:36:12 PM (18 years ago)
Author:
bensch
Message:

limited text-lenght

Location:
branches/gui/src
Files:
3 edited
2 copied

Legend:

Unmodified
Added
Removed
  • branches/gui/src/defs/class_id.h

    r8518 r8538  
    287287  CL_TEXT                       =    0x00804000,
    288288  CL_MULTI_LINE_TEXT            =    0x00000840,
     289  CL_LIMITED_WIDTH_TEXT         =    0x00000841,
    289290
    290291  // Texutres.
  • branches/gui/src/lib/graphics/Makefile.am

    r8293 r8538  
    1515                           text_engine/text.cc \
    1616                           text_engine/multi_line_text.cc \
     17                           text_engine/limited_width_text.cc \
    1718                           text_engine/font.cc \
    1819                           \
     
    4041                 text_engine/text.h \
    4142                 text_engine/multi_line_text.h \
     43                 text_engine/limited_width_text.h \
    4244                 text_engine/font.h \
    4345                 text_engine/default_font.xpm \
  • branches/gui/src/lib/graphics/text_engine/limited_width_text.cc

    r8529 r8538  
    1616#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
    1717
    18 #include "multi_line_text.h"
     18#include "limited_width_text.h"
    1919#include "font.h"
    2020
     
    2424 * @param type The renderType to display this font in
    2525 */
    26 MultiLineText::MultiLineText(const std::string& fontFile, unsigned int textSize, float lineWidth)
    27   : Text(fontFile, textSize)
     26LimitedWidthText::LimitedWidthText(const std::string& fontFile, unsigned int textSize, float lineWidth, DotsPosition dotsPosition)
     27    : Text(fontFile, textSize)
    2828{
    29   this->setClassID(CL_MULTI_LINE_TEXT, "MultiLineText");
     29  this->setClassID(CL_LIMITED_WIDTH_TEXT, "LimitedWidthText");
    3030
    31   this->lineSpacing = 1.0;
    32   this->lineCount = 0;
     31  this->_dotsPosition = End;
    3332  this->setLineWidth(lineWidth);
    3433}
     
    3837 * @param lineWidth the maximum lineWidth.
    3938 */
    40 void MultiLineText::setLineWidth(float lineWidth)
     39void LimitedWidthText::setLineWidth(float lineWidth)
    4140{
    42   this->lineWidth = lineWidth;
     41  this->_lineWidth = lineWidth;
    4342  this->setSizeX2D(lineWidth);
    4443  this->setupTextWidth();
     
    4746
    4847/**
    49  * @param lineSpacing: the Spacing between the lines
    50  */
    51 void MultiLineText::setLineSpacing(float lineSpacing)
    52 {
    53    this->lineSpacing = lineSpacing;
    54    this->setupTextWidth();
    55 }
    56 
    57 
    58 /**
    5948 * @brief draws the Text
    6049 */
    61 void MultiLineText::draw() const
     50void LimitedWidthText::draw() const
    6251{
    63   if (unlikely(this->getText().empty()))
     52  if (unlikely(this->_dotedText.empty()))
    6453    return;
    6554  glPushMatrix();
    6655  glPushAttrib(GL_ENABLE_BIT);
    6756  // transform for alignment.
    68   // TODO make the Stuff with the alignment
    6957  if (this->getAlignment() == TEXT_ALIGN_RIGHT)
    7058    glTranslatef(-this->getSizeX2D(), 0, 0);
     
    7462  // drawing this Text.
    7563  // setting the Blending effects
     64  glColor4fv(&this->getColor()[0]);
     65
     66
    7667  glActiveTexture(GL_TEXTURE0);
    7768
    78   glColor4fv(&this->getColor()[0]);
    7969  glEnable(GL_BLEND);
    8070  glEnable(GL_TEXTURE_2D);
     
    8373
    8474  glBindTexture(GL_TEXTURE_2D, this->getFont()->getTexture());
    85   glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
     75  glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
    8676  glRotatef(this->getAbsDir2D(), 0, 0, 1);
    8777
    8878  Glyph* tmpGlyph;
    8979  float posX = 0.0f;
    90   float posY = 0.0f;
    91   unsigned int lineNumber = 0;
    92 
    9380  glBegin(GL_QUADS);
    94   for (unsigned int i = 0; i < this->getText().size(); ++i)
     81  for (unsigned int i = 0; i < this->_dotedText.size(); i++)
    9582  {
    96     if (unlikely(this->lineEnds.size() > lineNumber && i == this->lineEnds[lineNumber]))
    97     {
    98       // go to the next Line.
    99       ++lineNumber;
    100       posX = 0.0f;
    101       posY += this->lineSpacing + this->getSize(); //this->getFont()->getMaxHeight();
    102     }
    103 
    104     if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->getText()[i]]) != NULL))
     83    if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->_dotedText[i]]) != NULL))
    10584    {
    10685      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
    107       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY);
     86      glVertex2d(posX+tmpGlyph->maxX*this->getSize(), 0);
    10887
    10988      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
    110       glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY + this->getSize());
     89      glVertex2d(posX+tmpGlyph->maxX*this->getSize(), this->getSize());
    11190
    11291      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
    113       glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY+ this->getSize());
     92      glVertex2d(posX+tmpGlyph->minX*this->getSize(), this->getSize());
    11493
    11594      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
    116       glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY);
     95      glVertex2d(posX+tmpGlyph->minX*this->getSize(), 0);
    11796
    11897      posX += tmpGlyph->advance * this->getSize();
     
    128107 * @brief setting up the Text-Width if DYNAMIC
    129108 */
    130 void MultiLineText::setupTextWidth()
     109void LimitedWidthText::setupTextWidth()
    131110{
    132   this->lineEnds.clear();
     111  float dotsSize = this->getFont()->getGlyphArray()[46]->advance * 3.0;
     112
    133113  float width = 0.0f;
    134   float maxWidth = this->lineWidth / this->getSize();
     114  float maxWidth = this->_lineWidth / this->getSize();
    135115
    136   for (unsigned int i = 0; i < this->getText().size(); i++)
     116  switch (this->_dotsPosition)
    137117  {
    138     if (width > maxWidth || this->getText()[i] == '\n')
    139     {
    140       if (likely(i > 0))
     118    case End:
     119      for (unsigned int i = 0; i < this->getText().size(); i++)
    141120      {
    142         this->lineEnds.push_back( i -1 );
    143         width = this->getFont()->getGlyphArray()[this->getText()[i-1]]->advance;
     121        if (width + dotsSize > maxWidth )
     122        {
     123          this->_dotedText = this->getText().substr(0, i) + "...";
     124          width += dotsSize;
     125          break;
     126        }
     127        // Advance the Text.
     128        if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
     129          width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
    144130      }
    145       else
    146         width = 0.0f;
    147     }
    148 
    149     // Advance the Text.
    150     if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
    151       width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
     131      this->setSizeX2D(width);
     132      break;
     133    case Begin:
     134      for (unsigned int i = this->getText().size() - 1; i < 0; i--)
     135      {
     136        if (width + dotsSize > maxWidth )
     137        {
     138          this->_dotedText = std::string("...") + this->getText().substr(i);
     139          width += dotsSize;
     140          break;
     141        }
     142        // Advance the Text.
     143        if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
     144          width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
     145      }
     146      this->setSizeX2D(width);
     147      break;
    152148  }
    153   this->lineCount = lineEnds.size() + 1;
    154   this->setSizeY2D((this->lineEnds.size()+1) * (this->lineSpacing + this->getFont()->getMaxHeight()));
    155149}
    156150
     
    158152 * @brief print out some nice debug output
    159153 */
    160 void MultiLineText::debug() const
     154void LimitedWidthText::debug() const
    161155{
    162  printf("Debug %s::%s: %d lines\n", this->getClassName(), this->getName(), this->getLineCount());
    163 
    164  std::string tmpText = this->getText();
    165  std::vector<unsigned int> ends = this->lineEnds;
    166  ends.push_back(tmpText.size());
    167 
    168  unsigned int prev = 0;
    169   for (unsigned int i = 0; i < ends.size(); i++)
    170   {
    171     printf("Line %d: %s\n", i, tmpText.substr(prev, ends[i] - prev).c_str());
    172     prev = ends[i];
    173   }
     156  printf("Debug %s::%s \n", this->getClassName(), this->getName() );
    174157}
  • branches/gui/src/lib/graphics/text_engine/limited_width_text.h

    r8529 r8538  
    11/*!
    2  * @file multi_line_text.h
     2 * @file limited_width_text.h
    33 * @brief Definition of a text Class, that is able to render text.
    44 */
    55
    6 #ifndef _MULTI_LINE_TEXT_H
    7 #define _MULTI_LINE_TEXT_H
     6#ifndef _LIMITED_WIDTH_TEXT_H
     7#define _LIMITED_WIDTH_TEXT_H
    88
    99#include "text.h"
     
    1212
    1313//! Represents one textElement.
    14 class MultiLineText : public Text
     14class LimitedWidthText : public Text
    1515{
    1616  public:
    17     MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0);
     17    typedef enum {
     18      Begin,
     19      End,
     20    } DotsPosition;
     21
     22
     23  public:
     24    LimitedWidthText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE, float lineWidth = 100.0, DotsPosition dotsPosition = Begin);
    1825
    1926    // Setup:
    2027    void setLineWidth(float lineWidth);
    21     void setLineSpacing(float lineSpacing);
     28    void setDotsPosition(DotsPosition dotsPosition);
    2229
    2330    // Retrieve:
    2431    /** @returns the LineWidth (maximum distance from the left to the right */
    25     inline float getLineWidth() const { return this->lineWidth; };
    26     /** @returns the LineSpacing */
    27     inline float getLineSpacing() const { return this->lineSpacing; };
    28     inline unsigned int getLineCount() const { return this->lineCount; };
    29 
     32    inline float lineWidth() const { return this->_lineWidth; };
     33    /** @returns the dots position. */
     34    inline float dotsPosition() const { return this->_dotsPosition; };
    3035    virtual void draw() const;
    3136
     
    3641
    3742  private:
    38     float                      lineWidth;
    39     float                      lineSpacing;
    40     std::vector<unsigned int>  lineEnds;
    41     unsigned int               lineCount;
     43    std::string                _dotedText;
     44
     45    DotsPosition               _dotsPosition;
     46    float                      _lineWidth;
     47    unsigned int               _lineEnds;
    4248};
    4349
    44 #endif /* _MULTI_LINE_TEXT_H */
     50#endif /* _LIMITED_WIDTH_TEXT_H */
  • branches/gui/src/lib/gui/gl/glgui_defs.h

    r8448 r8538  
    2222  } Orientation;
    2323
     24  //! Names of Orientations
    2425  const std::string OrientationString[] = {
    2526    "Horizontal",
     
    3031  typedef enum {
    3132    Normal,           //!< Normal state of the GUI's Widgets.
    32     Active,           //!< If the widget is Active.
     33    Focused,           //!< If the widget is Active.
    3334    Selected,         //!< If the Widget is Selected.
    3435    Insensitive       //!< If the Widget is insensitive.
     
    3839#define GLGUI_DEFAULT_STYLE OrxGui::Normal
    3940
     41//! names of the States.
    4042  const std::string StateString[] =
    4143    {
    4244      "Normal",
    43       "Active",
     45      "Focused",
    4446      "Selected",
    4547      "Insensitive"
     
    5456    } FeaturePosition;
    5557
     58    //! Names of Feature-Positions
    5659    const std::string FeaturePositionString[] =
    5760    {
Note: See TracChangeset for help on using the changeset viewer.