src/supertux/info_box.cpp

Go to the documentation of this file.
00001 //  SuperTux
00002 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
00003 //
00004 //  This program is free software: you can redistribute it and/or modify
00005 //  it under the terms of the GNU General Public License as published by
00006 //  the Free Software Foundation, either version 3 of the License, or
00007 //  (at your option) any later version.
00008 //
00009 //  This program is distributed in the hope that it will be useful,
00010 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00011 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00012 //  GNU General Public License for more details.
00013 //
00014 //  You should have received a copy of the GNU General Public License
00015 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
00016 
00017 #include "supertux/info_box.hpp"
00018 
00019 #include "supertux/globals.hpp"
00020 #include "supertux/info_box_line.hpp"
00021 #include "util/log.hpp"
00022 #include "video/drawing_context.hpp"
00023 #include "video/surface.hpp"
00024 
00025 InfoBox::InfoBox(const std::string& text) :
00026   firstline(0),
00027   lines(),
00028   images(),
00029   arrow_scrollup(),
00030   arrow_scrolldown()
00031 {
00032   // Split text string lines into a vector
00033   lines = InfoBoxLine::split(text, 400);
00034 
00035   try
00036   {
00037     // get the arrow sprites
00038     arrow_scrollup   = Surface::create("images/engine/menu/scroll-up.png");
00039     arrow_scrolldown = Surface::create("images/engine/menu/scroll-down.png");
00040   }
00041   catch (std::exception& e)
00042   {
00043     log_warning << "Could not load scrolling images: " << e.what() << std::endl;
00044     arrow_scrollup.reset();
00045     arrow_scrolldown.reset();
00046   }
00047 }
00048 
00049 InfoBox::~InfoBox()
00050 {
00051   for(std::vector<InfoBoxLine*>::iterator i = lines.begin();
00052       i != lines.end(); i++)
00053     delete *i;
00054 }
00055 
00056 void
00057 InfoBox::draw(DrawingContext& context)
00058 {
00059   float x1 = SCREEN_WIDTH/2-200;
00060   float y1 = SCREEN_HEIGHT/2-200;
00061   float width = 400;
00062   float height = 200;
00063 
00064   context.draw_filled_rect(Vector(x1, y1), Vector(width, height),
00065                            Color(0.6f, 0.7f, 0.8f, 0.5f), LAYER_GUI-1);
00066 
00067   float y = y1;
00068   bool linesLeft = false;
00069   for(size_t i = firstline; i < lines.size(); ++i) {
00070     if(y >= y1 + height) {
00071       linesLeft = true;
00072       break;
00073     }
00074 
00075     lines[i]->draw(context, Rectf(x1, y, x1+width, y), LAYER_GUI);
00076     y += lines[i]->get_height();
00077   }
00078 
00079   {
00080     // draw the scrolling arrows
00081     if (arrow_scrollup.get() && firstline > 0)
00082       context.draw_surface(arrow_scrollup,
00083                            Vector( x1 + width  - arrow_scrollup->get_width(),  // top-right corner of box
00084                                    y1), LAYER_GUI);
00085 
00086     if (arrow_scrolldown.get() && linesLeft && firstline < lines.size()-1)
00087       context.draw_surface(arrow_scrolldown,
00088                            Vector( x1 + width  - arrow_scrolldown->get_width(),  // bottom-light corner of box
00089                                    y1 + height - arrow_scrolldown->get_height()),
00090                            LAYER_GUI);
00091   }
00092 }
00093 
00094 void
00095 InfoBox::scrollup()
00096 {
00097   if(firstline > 0)
00098     firstline--;
00099 }
00100 
00101 void
00102 InfoBox::scrolldown()
00103 {
00104   if(firstline < lines.size()-1)
00105     firstline++;
00106 }
00107 
00108 void
00109 InfoBox::pageup()
00110 {
00111 }
00112 
00113 void
00114 InfoBox::pagedown()
00115 {
00116 }
00117 
00118 /* EOF */

Generated on Mon Jun 9 03:38:22 2014 for SuperTux by  doxygen 1.5.1