2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "supertux/info_box.hpp"
19 #include "supertux/globals.hpp"
20 #include "supertux/info_box_line.hpp"
21 #include "util/log.hpp"
22 #include "video/drawing_context.hpp"
23 #include "video/surface.hpp"
25 InfoBox::InfoBox(const std::string& text) :
32 // Split text string lines into a vector
33 lines = InfoBoxLine::split(text, 400);
37 // get the arrow sprites
38 arrow_scrollup = Surface::create("images/engine/menu/scroll-up.png");
39 arrow_scrolldown = Surface::create("images/engine/menu/scroll-down.png");
41 catch (std::exception& e)
43 log_warning << "Could not load scrolling images: " << e.what() << std::endl;
44 arrow_scrollup.reset();
45 arrow_scrolldown.reset();
51 for(std::vector<InfoBoxLine*>::iterator i = lines.begin();
52 i != lines.end(); i++)
57 InfoBox::draw(DrawingContext& context)
59 float x1 = SCREEN_WIDTH/2-200;
60 float y1 = SCREEN_HEIGHT/2-200;
64 context.draw_filled_rect(Vector(x1, y1), Vector(width, height),
65 Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI-1);
68 bool linesLeft = false;
69 for(size_t i = firstline; i < lines.size(); ++i) {
70 if(y >= y1 + height) {
75 lines[i]->draw(context, Rectf(x1, y, x1+width, y), LAYER_GUI);
76 y += lines[i]->get_height();
80 // draw the scrolling arrows
81 if (arrow_scrollup.get() && firstline > 0)
82 context.draw_surface(arrow_scrollup,
83 Vector( x1 + width - arrow_scrollup->get_width(), // top-right corner of box
86 if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
87 context.draw_surface(arrow_scrolldown,
88 Vector( x1 + width - arrow_scrolldown->get_width(), // bottom-light corner of box
89 y1 + height - arrow_scrolldown->get_height()),
102 InfoBox::scrolldown()
104 if(firstline < lines.size()-1)