From: Matthias Braun Date: Mon, 26 Sep 2005 10:46:13 +0000 (+0000) Subject: some code to have images in scrolling text X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=74467e814cadd3f941e69e489afbf17f9741c4c2;p=supertux.git some code to have images in scrolling text SVN-Revision: 2788 --- diff --git a/data/images/credits/matze.jpg b/data/images/credits/matze.jpg new file mode 100644 index 000000000..71fa7a3e5 Binary files /dev/null and b/data/images/credits/matze.jpg differ diff --git a/data/images/credits/wansti.jpg b/data/images/credits/wansti.jpg new file mode 100644 index 000000000..346d57c00 Binary files /dev/null and b/data/images/credits/wansti.jpg differ diff --git a/src/textscroller.cpp b/src/textscroller.cpp index 066997dd6..d76342a06 100644 --- a/src/textscroller.cpp +++ b/src/textscroller.cpp @@ -66,6 +66,7 @@ void display_text_file(const std::string& filename) std::string text; std::string background_file; std::vector lines; + std::map images; lisp::Parser parser; try { @@ -90,6 +91,17 @@ void display_text_file(const std::string& filename) // Split text string lines into a vector split_text(text, lines); + for(size_t i = 0; i < lines.size(); ++i) { + const std::string& line = lines[i]; + if(line.size() == 0) + continue; + if(line[0] == '!') { + std::string imagename = line.substr(1, line.size()-1); + std::cout << "Imagename: " << imagename << "\n"; + images.insert(std::make_pair(imagename, new Surface(imagename, true))); + } + } + // load background image Surface* background = new Surface("images/background/" + background_file, false); @@ -138,6 +150,7 @@ void display_text_file(const std::string& filename) } const Font* font = 0; + const Surface* image = 0; bool center = true; switch(line[0]) { @@ -146,26 +159,38 @@ void display_text_file(const std::string& filename) case '-': font = heading_font; break; case '*': font = reference_font; break; case '#': font = normal_font; center = false; break; + case '!': { + std::string imagename = line.substr(1, line.size()-1); + image = images[imagename]; + break; + } default: std::cerr << "Warning: text contains an unformated line.\n"; font = normal_font; center = false; break; } - - if(center) { - context.draw_text(font, - line.substr(1, line.size()-1), - Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT + y - scroll), - CENTER_ALLIGN, LAYER_FOREGROUND1); - } else { - context.draw_text(font, - line.substr(1, line.size()-1), - Vector(left_border, SCREEN_HEIGHT + y - scroll), - LEFT_ALLIGN, LAYER_FOREGROUND1); + + if(font != 0) { + if(center) { + context.draw_text(font, + line.substr(1, line.size()-1), + Vector(SCREEN_WIDTH/2, SCREEN_HEIGHT + y - scroll), + CENTER_ALLIGN, LAYER_FOREGROUND1); + } else { + context.draw_text(font, + line.substr(1, line.size()-1), + Vector(left_border, SCREEN_HEIGHT + y - scroll), + LEFT_ALLIGN, LAYER_FOREGROUND1); + } + y += font->get_height() + ITEMS_SPACE; + } + if(image != 0) { + context.draw_surface(image, + Vector( (SCREEN_WIDTH - image->w) / 2, + SCREEN_HEIGHT + y - scroll), 255); + y += image->h + ITEMS_SPACE; } - - y += font->get_height() + ITEMS_SPACE; } context.do_drawing(); @@ -182,7 +207,11 @@ void display_text_file(const std::string& filename) SDL_Delay(10); } - + + for(std::map::iterator i = images.begin(); + i != images.end(); ++i) + delete i->second; + SDL_EnableKeyRepeat(0, 0); // disables key repeating delete background; }