Index: trunk/src/lib/graphics/text_engine/font.cc
===================================================================
--- trunk/src/lib/graphics/text_engine/font.cc	(revision 7449)
+++ trunk/src/lib/graphics/text_engine/font.cc	(revision 7450)
@@ -307,5 +307,5 @@
 
 /**
- * initializes the default font
+ * @brief initializes the default font
  */
 void Font::initDefaultFont()
@@ -316,5 +316,5 @@
 
 /**
- * deletes the default font
+ * @brief deletes the default font
  */
 void Font::removeDefaultFont()
@@ -334,5 +334,5 @@
     return TTF_FontHeight(this->fontTTF);
   else
-    return 0;
+    return 1;
 }
 
Index: trunk/src/lib/graphics/text_engine/font.h
===================================================================
--- trunk/src/lib/graphics/text_engine/font.h	(revision 7449)
+++ trunk/src/lib/graphics/text_engine/font.h	(revision 7450)
@@ -72,4 +72,8 @@
     inline TTF_Font* getTTF() const { return this->fontTTF; };
 
+    int getMaxHeight() const;
+    int getMaxAscent() const;
+    int getMaxDescent() const;
+
     /** @returns the default Font */
     inline static Font* getDefaultFont() { if (Font::defaultFont == NULL) initDefaultFont(); return Font::defaultFont; };
@@ -81,7 +85,4 @@
   private:
     void init();
-    int getMaxHeight() const;
-    int getMaxAscent() const;
-    int getMaxDescent() const;
     bool getGlyphMetrics(Glyph* glyph, Uint16 character);
 
Index: trunk/src/lib/graphics/text_engine/multi_line_text.cc
===================================================================
--- trunk/src/lib/graphics/text_engine/multi_line_text.cc	(revision 7450)
+++ trunk/src/lib/graphics/text_engine/multi_line_text.cc	(revision 7450)
@@ -0,0 +1,134 @@
+/*
+   orxonox - the future of 3D-vertical-scrollers
+
+   Copyright (C) 2004 orx
+
+   This program is free software; you can redistribute it and/or modify
+   it under the terms of the GNU General Public License as published by
+   the Free Software Foundation; either version 2, or (at your option)
+   any later version.
+
+   ### File Specific:
+   main-programmer: Benjamin Grauer
+   co-programmer: ...
+*/
+
+#define DEBUG_SPECIAL_MODULE DEBUG_MODULE_GRAPHICS
+
+#include "multi_line_text.h"
+#include "font.h"
+
+using namespace std;
+
+/**
+ * @brief creates a new Text Element
+ * @param fontFile the Font to render this text in
+ * @param type The renderType to display this font in
+ */
+MultiLineText::MultiLineText(const std::string& fontFile, unsigned int textSize)
+  : Text(fontFile, textSize)
+{
+  this->setClassID(CL_MULTI_LINE_TEXT, "MultiLineText");
+
+  this->lineSpacing = 1.0f;
+  this->lineWidth = 100.0f;
+  this->setupTextWidth();
+}
+
+/**
+ * @brief sets the maximum Line width
+ * @param lineWidth the maximum lineWidth.
+ */
+void MultiLineText::setLineWidth(float lineWidth)
+{
+  this->lineWidth = lineWidth;
+  this->setupTextWidth();
+}
+
+
+/**
+ * @brief draws the Text
+ */
+void MultiLineText::draw() const
+{
+  if (unlikely(this->getText().empty()))
+    return;
+  glPushMatrix();
+  // transform for alignment.
+  // TODO make the Stuff with the alignment
+  if (this->getAlignment() == TEXT_ALIGN_RIGHT)
+    glTranslatef(-this->getSizeX2D(), 0, 0);
+  else if (this->getAlignment() == TEXT_ALIGN_CENTER || this->getAlignment() == TEXT_ALIGN_SCREEN_CENTER)
+    glTranslatef(-this->getSizeX2D()/2, 0, 0);
+
+  // drawing this Text.
+  // setting the Blending effects
+  glColor4f(this->getColor().x, this->getColor().y, this->getColor().z, this->getBlending());
+  glEnable(GL_BLEND);
+  glEnable(GL_TEXTURE_2D);
+  glBlendFunc(GL_SRC_ALPHA, GL_ONE);
+  glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
+
+  glBindTexture(GL_TEXTURE_2D, this->getFont()->getTexture());
+  glTranslatef(this->getAbsCoor2D().x, this->getAbsCoor2D().y, 0);
+  glRotatef(this->getAbsDir2D(), 0, 0, 1);
+
+  Glyph* tmpGlyph;
+  float posX = 0.0f;
+  float posY = 0.0f;
+  unsigned int lineNumber = 0;
+
+  glBegin(GL_QUADS);
+  for (unsigned int i = 0; i < this->getText().size(); i++)
+  {
+    if (unlikely(tmpGlyph->character == '\n' || i == this->lineEnds[lineNumber]))
+    {
+    // go to the next Line.
+      lineNumber++;
+      posX = 0.0f;
+      posY += this->lineSpacing + this->getFont()->getMaxHeight();
+    }
+
+    if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->getText()[i]]) != NULL))
+    {
+      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
+      glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY);
+
+      glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
+      glVertex2d(posX+tmpGlyph->maxX*this->getSize(), posY + this->getSize());
+
+      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
+      glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY+ this->getSize());
+
+      glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
+      glVertex2d(posX+tmpGlyph->minX*this->getSize(), posY);
+
+      posX += tmpGlyph->advance * this->getSize();
+    }
+  }
+  glEnd();
+  glPopMatrix();
+}
+
+/**
+ * @brief setting up the Text-Width if DYNAMIC
+ */
+void MultiLineText::setupTextWidth()
+{
+  this->lineEnds.clear();
+  float width = 0.0f;
+  // TODO make size local to this (not using the one from Element2D.
+  float maxWidth = this->lineWidth / this->getSize();
+
+  for (unsigned int i = 0; i < this->getText().size(); i++)
+  {
+    if (width > maxWidth || this->getText()[i] == '\n')
+    {
+      this->lineEnds.push_back(i);
+      width = 0.0f;
+    }
+    // Advance the Text.
+    if(this->getFont()->getGlyphArray()[this->getText()[i]] != NULL)
+      width += this->getFont()->getGlyphArray()[this->getText()[i]]->advance;
+  }
+}
Index: trunk/src/lib/graphics/text_engine/multi_line_text.h
===================================================================
--- trunk/src/lib/graphics/text_engine/multi_line_text.h	(revision 7450)
+++ trunk/src/lib/graphics/text_engine/multi_line_text.h	(revision 7450)
@@ -0,0 +1,41 @@
+/*!
+ * @file multi_line_text.h
+ * @brief Definition of a text Class, that is able to render text.
+ */
+
+#ifndef _MULTI_LINE_TEXT_H
+#define _MULTI_LINE_TEXT_H
+
+#include "text.h"
+
+#include <vector>
+
+//! Represents one textElement.
+class MultiLineText : public Text
+{
+  public:
+    MultiLineText(const std::string& fontFile = "", unsigned int fontSize = TEXT_DEFAULT_SIZE);
+
+    // Setup:
+    void setLineWidth(float lineWidth);
+    /** @param lineSpacing: the Spacing between the lines */
+    void setLineSpacing(float lineSpacing) { this->lineSpacing = lineSpacing; };
+
+    // Retrieve:
+    /** @returns the LineWidth (maximum distance from the left to the right */
+    inline float getLineWidth() const { return this->lineWidth; };
+    /** @returns the LineSpacing */
+    inline float getLineSpacing() const { return this->lineSpacing; };
+
+    virtual void draw() const;
+
+  protected:
+    virtual void setupTextWidth();
+
+  private:
+    float                      lineWidth;
+    float                      lineSpacing;
+    std::vector<unsigned int>  lineEnds;
+};
+
+#endif /* _MULTI_LINE_TEXT_H */
Index: trunk/src/lib/graphics/text_engine/text.cc
===================================================================
--- trunk/src/lib/graphics/text_engine/text.cc	(revision 7449)
+++ trunk/src/lib/graphics/text_engine/text.cc	(revision 7450)
@@ -85,4 +85,6 @@
   if (oldFont != NULL && oldFont != Font::getDefaultFont())
     ResourceManager::getInstance()->unload(oldFont);
+
+  this->setupTextWidth();
 }
 
@@ -95,24 +97,5 @@
   this->text = text;
 
-  // setting up the Text-Width if DYNAMIC
-  //  if (this->type & TEXT_RENDER_DYNAMIC && this->getAlignment() != TEXT_ALIGN_LEFT && this->font != NULL)
-  const Font* calcSizeFont = this->font;
-  if (calcSizeFont != NULL || (calcSizeFont = Font::getDefaultFont()) != NULL)
-  {
-    Glyph** glyphArray = calcSizeFont->getGlyphArray();
-
-    float width = 0;
-    if (!this->text.empty())
-    {
-      for (unsigned int i = 0; i < this->text.size(); i++)
-      {
-        if(glyphArray[this->text[i]] != NULL)
-        {
-          width += glyphArray[this->text[i]]->advance;
-        }
-      }
-      this->setSizeX2D(width *this->getSizeY2D());
-    }
-  }
+  this->setupTextWidth();
 }
 
@@ -139,5 +122,4 @@
   glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_COLOR, GL_MODULATE );
 
-  Glyph** glyphArray = this->font->getGlyphArray();
   glBindTexture(GL_TEXTURE_2D, font->getTexture());
   glTranslatef(getAbsCoor2D().x, getAbsCoor2D().y, 0);
@@ -149,19 +131,19 @@
   for (unsigned int i = 0; i < this->text.size(); i++)
   {
-    if(likely((tmpGlyph = glyphArray[this->text[i]]) != NULL))
+    if(likely((tmpGlyph = this->getFont()->getGlyphArray()[this->text[i]]) != NULL))
     {
       glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[2]);
-      glVertex2d(posX+tmpGlyph->maxX*this->getSizeY2D(), 0);
+      glVertex2d(posX+tmpGlyph->maxX*this->getSize(), 0);
 
       glTexCoord2f(tmpGlyph->texCoord[1], tmpGlyph->texCoord[3]);
-      glVertex2d(posX+tmpGlyph->maxX*this->getSizeY2D(), this->getSizeY2D());
+      glVertex2d(posX+tmpGlyph->maxX*this->getSize(), this->getSize());
 
       glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[3]);
-      glVertex2d(posX+tmpGlyph->minX*this->getSizeY2D(), this->getSizeY2D());
+      glVertex2d(posX+tmpGlyph->minX*this->getSize(), this->getSize());
 
       glTexCoord2f(tmpGlyph->texCoord[0], tmpGlyph->texCoord[2]);
-      glVertex2d(posX+tmpGlyph->minX*this->getSizeY2D(), 0);
+      glVertex2d(posX+tmpGlyph->minX*this->getSize(), 0);
 
-      posX += tmpGlyph->advance * this->getSizeY2D();
+      posX += tmpGlyph->advance * this->getSize();
     }
   }
@@ -170,4 +152,18 @@
 }
 
+
+/**
+ * @brief setting up the Text-Width.
+ */
+void Text::setupTextWidth()
+{
+  float width = 0;
+  for (unsigned int i = 0; i < this->text.size(); i++)
+    if(this->font->getGlyphArray()[this->text[i]] != NULL)
+      width += this->font->getGlyphArray()[this->text[i]]->advance;
+  this->setSizeX2D(width *this->getSize());
+}
+
+
 /**
  * @brief prints out some nice debug information about this text
@@ -175,107 +171,6 @@
 void Text::debug() const
 {
-  PRINT(0)("=== TEXT: %s ===\n", this->text.c_str());
+  PRINT(0)("=== TEXT: %s (with Font:'%s')  displaying %s ===\n", this->getName(), this->font->getName(), this->text.c_str());
   PRINT(0)("Color: %0.2f %0.2f %0.2f\n", this->color.x, this->color.y, this->color.z);
 }
 
-
-////////////
-/// UTIL ///
-////////////
-/**
- * @brief Loads a Font from an SDL_surface into a texture.
- * @param surface The surface to make the texture of
- * @param texCoord The texture coordinates of the 4 corners of the texture
- * @returns the ID of the texture
- */
-GLuint Text::loadTexture(SDL_Surface *surface, TexCoord* texCoord)
-{
-  GLuint texture;
-  int w, h;
-  SDL_Surface *image;
-  SDL_Rect area;
-  Uint32 saved_flags;
-  Uint8  saved_alpha;
-
-  /* Use the surface width and height expanded to powers of 2 */
-  w = powerOfTwo(surface->w);
-  h = powerOfTwo(surface->h);
-  if (texCoord != NULL)
-  {
-    texCoord->minU = 0.0f;
-    texCoord->minV = 0.0f;
-    texCoord->maxU = (GLfloat)surface->w / w;
-    texCoord->maxV = (GLfloat)surface->h / h;
-  }
-  image = SDL_CreateRGBSurface(SDL_SWSURFACE,
-                               w, h,
-                               32,
-#if SDL_BYTEORDER == SDL_LIL_ENDIAN /* OpenGL RGBA masks */
-                               0x000000FF,
-                               0x0000FF00,
-                               0x00FF0000,
-                               0xFF000000
-#else
-                               0xFF000000,
-                               0x00FF0000,
-                               0x0000FF00,
-                               0x000000FF
-#endif
-                              );
-  if ( image == NULL )
-  {
-    return 0;
-  }
-
-  /* Save the alpha blending attributes */
-  saved_flags = surface->flags&(SDL_SRCALPHA|SDL_RLEACCELOK);
-  saved_alpha = surface->format->alpha;
-  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
-  {
-    SDL_SetAlpha(surface, 0, 0);
-  }
-
-  /* Copy the surface into the GL texture image */
-  area.x = 0;
-  area.y = 0;
-  area.w = surface->w;
-  area.h = surface->h;
-  SDL_BlitSurface(surface, &area, image, &area);
-
-  /* Restore the alpha blending attributes */
-  if ( (saved_flags & SDL_SRCALPHA) == SDL_SRCALPHA )
-  {
-    SDL_SetAlpha(surface, saved_flags, saved_alpha);
-  }
-
-  /* Create an OpenGL texture for the image */
-  glGenTextures(1, &texture);
-  glBindTexture(GL_TEXTURE_2D, texture);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
-  glTexImage2D(GL_TEXTURE_2D,
-               0,
-               GL_RGBA,
-               w, h,
-               0,
-               GL_RGBA,
-               GL_UNSIGNED_BYTE,
-               image->pixels);
-  SDL_FreeSurface(image); /* No longer needed the data */
-
-  return texture;
-}
-
-/**
- * @brief Quick utility function for texture creation
- * @param input an integer
- * @returns the next bigger 2^n-integer than input
- */
-int Text::powerOfTwo(int input)
-{
-  int value = 1;
-
-  while ( value < input )
-    value <<= 1;
-  return value;
-}
Index: trunk/src/lib/graphics/text_engine/text.h
===================================================================
--- trunk/src/lib/graphics/text_engine/text.h	(revision 7449)
+++ trunk/src/lib/graphics/text_engine/text.h	(revision 7450)
@@ -8,6 +8,4 @@
 
 #include "element_2d.h"
-
-#include "glincl.h"
 
 #define  TEXT_ALIGN_LEFT             E2D_ALIGN_LEFT
@@ -21,17 +19,7 @@
 #define  TEXT_DEFAULT_SIZE           20                         //!< default size of the Text
 
-
 // FORWARD DECLARATION
 class Font;
 struct SDL_Surface;
-
-//! A Struct to handel Texture Coordinates for quads
-struct TexCoord
-{
-  float    minU;              //!< The minimum U-Coordinate
-  float    maxU;              //!< The maximum U-Coordinate
-  float    minV;              //!< The minimum V-Coordinate
-  float    maxV;              //!< The maximum V-Coordinate
-};
 
 //! Represents one textElement.
@@ -42,18 +30,25 @@
     virtual ~Text();
 
+    // SETUP
     void setFont(const std::string& fontFile, unsigned int renderSize);
+    void setText(const std::string& text);
+    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
+    inline void setBlending(float blending) { this->blending = blending; };
+    /** @param r red @param g green @param b blue @brief sets the Color of the Text to render (values in [0-1]) */
+    void setColor(float r, float g, float b) { this->color = Vector(r, g, b); };
+    /** @param size the Size of the Text @brief sets the Size of the Font */
+    inline void setSize(float size) { this->setSizeY2D(size); };
 
-    void setText(const std::string& text);
-
+    /// RETRIEVE
+    /** @returns the pointer to the stored Font (not changeable) */
+    inline const Font* const getFont() const { return this->font; };
     /** @returns the String this Text displays */
     inline const std::string& getText() const { return this->text; };
-    /** @param blending the blending intensity to set (between 0.0 and 1.0) */
-    inline void setBlending(float blending) { this->blending = blending; };
-    /** sets the Color of the Text to render (values in [0-1]) @param r red @param g green @param b blue */
-    void setColor(float r, float g, float b) { this->color = Vector(r, g, b); };
-    /** sets the Size of the Font */
-    void setSize(float size) { this->setSizeY2D(size); };
+    /** @returns the Blending Value [0 invisible 1.0 full visible */
+    inline float getBlending() const { return this->blending; };
+    /** @returns: a Vector(r,g,b) @brief: retrieve a Vector holding the Color of the Text */
+    inline const Vector& getColor() const { return this->color; };
     /** @returns the Size of the Text */
-//    void getSize(float &x, float& y) const { return this->size; };
+    inline float getSize() const { return this->getSizeY2D(); };
 
     virtual void draw() const;
@@ -61,8 +56,6 @@
     void debug() const;
 
-  // helpers.
-    static GLuint loadTexture(SDL_Surface* surface, TexCoord* texCoord);
-    static int powerOfTwo(int input);
-
+  protected:
+    virtual void setupTextWidth();
   private:
     Font*             font;           //!< Font of this text
