Added autocompletion for current root table /
[supertux.git] / src / textscroller.cpp
index 85b7c08..ecf8fc7 100644 (file)
@@ -263,7 +263,14 @@ InfoBoxLine::split(const std::string& text, int line_length)
   std::string::size_type l;
   char format_char = '#';
   while(i < text.size()) {
+    // take care of empty lines - represent them as blank lines of normal text
+    if (text[i] == '\n') {
+      lines.push_back(new InfoBoxLine('\t', ""));
+      i++;
+      continue;
+    }
 
+    // extract the format_char
     format_char = text[i];
     i++;
     if (i >= text.size()) break;
@@ -280,17 +287,12 @@ InfoBoxLine::split(const std::string& text, int line_length)
       continue;
     } 
 
-    // if we are dealing with text, wrap long lines
-    while ((int)s.length() > line_length) {
-      int split_at = line_length;
-      while ((split_at > 0) && (s[split_at] != ' ')) split_at--;
-      if (split_at == 0) split_at = line_length;
-
-      lines.push_back(new InfoBoxLine(format_char, s.substr(0, split_at)));
-      if (s[split_at] == ' ') split_at++;
-      s = s.substr(split_at);
-    }
-    lines.push_back(new InfoBoxLine(format_char, s));
+    // append wrapped parts of line into list
+    std::string overflow;
+    do { 
+      lines.push_back(new InfoBoxLine(format_char, Font::wrap_to_chars(s, line_length, &overflow))); 
+      s = overflow;
+    } while (s.length() > 0);
 
   }
 
@@ -301,7 +303,6 @@ void
 InfoBoxLine::draw(DrawingContext& context, const Vector& position, int layer)
 {
   switch (lineType) {
-    case SPACER:
     case IMAGE:
       context.draw_surface(image, Vector( (SCREEN_WIDTH - image->get_width()) / 2, position.y), layer);
       break;
@@ -318,8 +319,6 @@ float
 InfoBoxLine::get_height()
 {
   switch (lineType) {
-    case SPACER:
-      return font->get_height() + ITEMS_SPACE;    
     case IMAGE:
       return image->get_height() + ITEMS_SPACE;
     case NORMAL_LEFT: