+InfoBoxLine::InfoBoxLine(char format_char, const std::string& text) : lineType(NORMAL), font(white_text), text(text), image(0)
+{
+ switch(format_char)
+ {
+ case ' ':
+ lineType = SMALL;
+ font = white_small_text;
+ break;
+ case '\t':
+ lineType = NORMAL;
+ font = white_text;
+ break;
+ case '-':
+ lineType = HEADING;
+ font = white_big_text;
+ break;
+ case '*':
+ lineType = REFERENCE;
+ font = blue_text;
+ break;
+ case '#':
+ lineType = NORMAL_LEFT;
+ font = white_text;
+ break;
+ case '!':
+ lineType = IMAGE;
+ image = new Surface(text);
+ break;
+ default:
+ log_warning << "Unknown format_char: '" << format_char << "'" << std::endl;
+ break;
+ }
+}
+
+InfoBoxLine::~InfoBoxLine()
+{
+ delete image;
+}
+
+const std::vector<InfoBoxLine*>
+InfoBoxLine::split(const std::string& text, int line_length)
+{
+ std::vector<InfoBoxLine*> lines;
+
+ std::string::size_type i = 0;
+ 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;
+
+ // extract one line
+ l = text.find("\n", i);
+ if (l == std::string::npos) l=text.size();
+ std::string s = text.substr(i, l-i);
+ i = l+1;
+
+ // if we are dealing with an image, just store the line
+ if (format_char == '!') {
+ lines.push_back(new InfoBoxLine(format_char, s));
+ continue;
+ }
+
+ // 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);
+
+ }
+
+ return lines;
+}
+
+void
+InfoBoxLine::draw(DrawingContext& context, const Vector& position, int layer)
+{
+ switch (lineType) {
+ case IMAGE:
+ context.draw_surface(image, Vector( (SCREEN_WIDTH - image->get_width()) / 2, position.y), layer);
+ break;
+ case NORMAL_LEFT:
+ context.draw_text(font, text, Vector(position.x, position.y), LEFT_ALLIGN, layer);
+ break;
+ default:
+ context.draw_text(font, text, Vector(SCREEN_WIDTH/2, position.y), CENTER_ALLIGN, layer);
+ break;
+ }
+}
+
+float
+InfoBoxLine::get_height()
+{
+ switch (lineType) {
+ case IMAGE:
+ return image->get_height() + ITEMS_SPACE;
+ case NORMAL_LEFT:
+ return font->get_height() + ITEMS_SPACE;
+ default:
+ return font->get_height() + ITEMS_SPACE;
+ }
+}