1// SuperTux
2// Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3//
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.
8//
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.
13//
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/>.
16
17#include "supertux/info_box.hpp"
18
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"
24
25InfoBox::InfoBox(const std::string& text) :
26 firstline(0),
27 // Split text string lines into a vector
28 lines(InfoBoxLine::split(text, 400)),
29 images(),
30 arrow_scrollup(),
31 arrow_scrolldown()
32{
33 try
34 {
35 // get the arrow sprites
36 arrow_scrollup = Surface::from_file("images/engine/menu/scroll-up.png");
37 arrow_scrolldown = Surface::from_file("images/engine/menu/scroll-down.png");
38 }
39 catch (std::exception& e)
40 {
41 log_warning << "Could not load scrolling images: " << e.what() << std::endl;
42 arrow_scrollup.reset();
43 arrow_scrolldown.reset();
44 }
45}
46
47void
48InfoBox::draw(DrawingContext& context)
49{
50 float x1 = static_cast<float>(context.get_width()) / 2.0f - 200.0f;
51 float y1 = static_cast<float>(context.get_height()) / 2.0f - 200.0f;
52 float width = 400.0f;
53 float height = 200.0f;
54
55 context.color().draw_filled_rect(Rectf(Vector(x1, y1),
56 Sizef(width, height)),
57 Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI - 1);
58
59 float y = y1;
60 bool linesLeft = false;
61 for (size_t i = firstline; i < lines.size(); ++i) {
62 if (y >= y1 + height) {
63 linesLeft = true;
64 break;
65 }
66
67 lines[i]->draw(context, Rectf(x1, y, x1+width, y), LAYER_GUI);
68 y += lines[i]->get_height();
69 }
70
71 {
72 // draw the scrolling arrows
73 if (arrow_scrollup.get() && firstline > 0)
74 context.color().draw_surface(arrow_scrollup,
75 Vector(x1 + width - static_cast<float>(arrow_scrollup->get_width()), // top-right corner of box
76 y1), LAYER_GUI);
77
78 if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
79 context.color().draw_surface(arrow_scrolldown,
80 Vector(x1 + width - static_cast<float>(arrow_scrolldown->get_width()), // bottom-light corner of box
81 y1 + height - static_cast<float>(arrow_scrolldown->get_height())),
82 LAYER_GUI);
83 }
84}
85
86void
87InfoBox::scrollup()
88{
89 if (firstline > 0)
90 firstline--;
91}
92
93void
94InfoBox::scrolldown()
95{
96 if (firstline < lines.size()-1)
97 firstline++;
98}
99
100void
101InfoBox::pageup()
102{
103}
104
105void
106InfoBox::pagedown()
107{
108}
109
110/* EOF */
111