add include for gcc3 in trunk, too
[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
28 #include "screen.hpp"
29 #include "math/vector.hpp"
30 #include "math/rect.hpp"
31
32 class DrawingContext;
33 class Surface;
34 class Font;
35
36 /**
37  * Helper class for InfoBox: Represents a line of text
38  */
39 class InfoBoxLine
40 {
41 public:
42   enum LineType { NORMAL, NORMAL_LEFT, SMALL, HEADING, REFERENCE, IMAGE};
43
44   InfoBoxLine(char format_char, const std::string& text);
45   ~InfoBoxLine();
46
47   void draw(DrawingContext& context, const Rect& bbox, int layer);
48   float get_height();
49
50   static const std::vector<InfoBoxLine*> split(const std::string& text, float width);
51
52 private:
53   InfoBoxLine::LineType lineType;
54   Font* font;
55   std::string text;
56   Surface* image;
57 };
58
59 /** This class is displaying a box with information text inside the game
60  */
61 class InfoBox
62 {
63 public:
64   InfoBox(const std::string& text);
65   ~InfoBox();
66
67   void draw(DrawingContext& context);
68   void scrolldown();
69   void scrollup();
70   void pagedown();
71   void pageup();
72
73 private:
74   size_t firstline;
75   std::vector<InfoBoxLine*> lines;
76   std::map<std::string, Surface*> images;
77   Surface* arrow_scrollup;
78   Surface* arrow_scrolldown;
79 };
80
81 class TextScroller : public Screen
82 {
83 public:
84   TextScroller(const std::string& file);
85   virtual ~TextScroller();
86
87   void setup();
88   void draw(DrawingContext& context);
89   void update(float elapsed_time);
90
91 private:
92   float defaultspeed;
93   float speed;
94   std::string music;
95   std::auto_ptr<Surface> background;
96   std::vector<InfoBoxLine*> lines;
97   float scroll;
98   bool fading;
99 };
100
101 #endif