Esempio n. 1
0
 void add(const LineInfo& li) // override
 {
   m_li.push_back(li);
 }
Esempio n. 2
0
/** Feed the LineInfoList for the given text
  *
  * \param vText  The text to draw
  * \param vWidth The allowed width
  * \param vOut   The LineInfoList to feed
  * \param vWrap  The word wrap parameter
  *
  */
void RainbruRPG::OgreGui::Font::
processText( const std::string& vText, float vWidth, 
	     LineInfoList& vOut, bool vWrap)const{

  // Get the total size of the text
  unsigned int count = (unsigned int)vText.size( );

  // Stores pixel width of line and word
  float lineWidth = 0.0f;
  float wordWidth = 0.0f;

  // Stores current word
  std::string word;

  // Stores the current line
  std::string line;

  unsigned int x;
  for ( x = 0; x < count; x++ ){
    char c = vText[x];

    // Add the new character to the current word
    Glyph* gl=getGlyph(c);
    wordWidth += gl->getSpace();
    word += c;

    bool delim=isDelim(c);
    if ( delim || ( x == ( count-1 ) ) ){
      // Is this line too long to fit?
      if ( vWrap && ( lineWidth + wordWidth > vWidth ) ){
	// Save current line
	vOut.push_back( LineInfo( line, lineWidth ) );

	// Reset line width
	lineWidth = 0.0f;
	line = "";
      }
      if ( c == '\n' ){
	// Save current line
	vOut.push_back( LineInfo( line + word, lineWidth + wordWidth ) );

	// Reset line width
	lineWidth = 0.0f;
	wordWidth = 0.0f;

	line = "";
	word = "";
      }
      else{
	lineWidth += wordWidth;
	line += word;

	wordWidth = 0.0f;
	word = "";
      }
    }
  }
  
  // Push any remaining text onto list
  vOut.push_back( LineInfo( line + word, lineWidth + wordWidth ) );
}