Merged patch for issue 0000298: supertux fails to compile with gcc 4.3 (submitted...
[supertux.git] / src / textscroller.hpp
1 //  $Id$
2 //
3 //  SuperTux
4 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
5 //
6 //  This program is free software; you can redistribute it and/or
7 //  modify it under the terms of the GNU General Public License
8 //  as published by the Free Software Foundation; either version 2
9 //  of the License, or (at your option) any later version.
10 //
11 //  This program is distributed in the hope that it will be useful,
12 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 //  GNU General Public License for more details.
15 //
16 //  You should have received a copy of the GNU General Public License
17 //  along with this program; if not, write to the Free Software
18 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19 //  02111-1307, USA.
20
21 #ifndef __TEXTSCROLLER_H__
22 #define __TEXTSCROLLER_H__
23
24 #include <vector>
25 #include <string>
26 #include <map>
27 #include <memory>
28
29 #include "screen.hpp"
30 #include "math/vector.hpp"
31 #include "math/rect.hpp"
32
33 class DrawingContext;
34 class Surface;
35 class Font;
36
37 /**
38  * Helper class for InfoBox: Represents a line of text
39  */
40 class InfoBoxLine
41 {
42 public:
43   enum LineType { NORMAL, NORMAL_LEFT, SMALL, HEADING, REFERENCE, IMAGE};
44
45   InfoBoxLine(char format_char, const std::string& text);
46   ~InfoBoxLine();
47
48   void draw(DrawingContext& context, const Rect& bbox, int layer);
49   float get_height();
50
51   static const std::vector<InfoBoxLine*> split(const std::string& text, float width);
52
53 private:
54   InfoBoxLine::LineType lineType;
55   Font* font;
56   std::string text;
57   Surface* image;
58 };
59
60 /** This class is displaying a box with information text inside the game
61  */
62 class InfoBox
63 {
64 public:
65   InfoBox(const std::string& text);
66   ~InfoBox();
67
68   void draw(DrawingContext& context);
69   void scrolldown();
70   void scrollup();
71   void pagedown();
72   void pageup();
73
74 private:
75   size_t firstline;
76   std::vector<InfoBoxLine*> lines;
77   std::map<std::string, Surface*> images;
78   Surface* arrow_scrollup;
79   Surface* arrow_scrolldown;
80 };
81
82 /**
83  * Screen that displays intro text, extro text, etc.
84  */
85 class TextScroller : public Screen
86 {
87 public:
88   TextScroller(const std::string& file);
89   virtual ~TextScroller();
90
91   void setup();
92   void draw(DrawingContext& context);
93   void update(float elapsed_time);
94
95 private:
96   float defaultspeed;
97   float speed;
98   std::string music;
99   std::auto_ptr<Surface> background;
100   std::vector<InfoBoxLine*> lines;
101   float scroll;
102   bool fading;
103 };
104
105 #endif