123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- // SuperTux
- // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
- //
- // This program is free software: you can redistribute it and/or modify
- // it under the terms of the GNU General Public License as published by
- // the Free Software Foundation, either version 3 of the License, or
- // (at your option) any later version.
- //
- // This program is distributed in the hope that it will be useful,
- // but WITHOUT ANY WARRANTY; without even the implied warranty of
- // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- // GNU General Public License for more details.
- //
- // You should have received a copy of the GNU General Public License
- // along with this program. If not, see <http://www.gnu.org/licenses/>.
- #include "supertux/info_box.hpp"
- #include "supertux/globals.hpp"
- #include "supertux/info_box_line.hpp"
- #include "util/log.hpp"
- #include "video/drawing_context.hpp"
- #include "video/surface.hpp"
- InfoBox::InfoBox(const std::string& text) :
- firstline(0),
- // Split text string lines into a vector
- lines(InfoBoxLine::split(text, 400)),
- images(),
- arrow_scrollup(),
- arrow_scrolldown()
- {
- try
- {
- // get the arrow sprites
- arrow_scrollup = Surface::from_file("images/engine/menu/scroll-up.png");
- arrow_scrolldown = Surface::from_file("images/engine/menu/scroll-down.png");
- }
- catch (std::exception& e)
- {
- log_warning << "Could not load scrolling images: " << e.what() << std::endl;
- arrow_scrollup.reset();
- arrow_scrolldown.reset();
- }
- }
- void
- InfoBox::draw(DrawingContext& context)
- {
- float x1 = context.get_width() / 2.0f - 200.0f;
- float y1 = context.get_height() / 2.0f - 200.0f;
- float width = 400.0f;
- float height = 200.0f;
- context.color().draw_filled_rect(Rectf(Vector(x1, y1),
- Sizef(width, height)),
- Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI - 1);
- float y = y1;
- bool linesLeft = false;
- for (size_t i = firstline; i < lines.size(); ++i) {
- if (y >= y1 + height) {
- linesLeft = true;
- break;
- }
- lines[i]->draw(context, Rectf(x1, y, x1+width, y), LAYER_GUI);
- y += lines[i]->get_height();
- }
- {
- // draw the scrolling arrows
- if (arrow_scrollup.get() && firstline > 0)
- context.color().draw_surface(arrow_scrollup,
- Vector(x1 + width - static_cast<float>(arrow_scrollup->get_width()), // top-right corner of box
- y1), LAYER_GUI);
- if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
- context.color().draw_surface(arrow_scrolldown,
- Vector(x1 + width - static_cast<float>(arrow_scrolldown->get_width()), // bottom-light corner of box
- y1 + height - static_cast<float>(arrow_scrolldown->get_height())),
- LAYER_GUI);
- }
- }
- void
- InfoBox::scrollup()
- {
- if (firstline > 0)
- firstline--;
- }
- void
- InfoBox::scrolldown()
- {
- if (firstline < lines.size()-1)
- firstline++;
- }
- void
- InfoBox::pageup()
- {
- }
- void
- InfoBox::pagedown()
- {
- }
- /* EOF */
|