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