6237ab7a4866a57195b23d0e1003e24169de4b48
[supertux.git] / src / supertux / textscroller.hpp
1 //  SuperTux
2 //  Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 //  This program is free software: you can redistribute it and/or modify
5 //  it under the terms of the GNU General Public License as published by
6 //  the Free Software Foundation, either version 3 of the License, or
7 //  (at your option) any later version.
8 //
9 //  This program is distributed in the hope that it will be useful,
10 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
11 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12 //  GNU General Public License for more details.
13 //
14 //  You should have received a copy of the GNU General Public License
15 //  along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
17 #ifndef HEADER_SUPERTUX_SUPERTUX_TEXTSCROLLER_HPP
18 #define HEADER_SUPERTUX_SUPERTUX_TEXTSCROLLER_HPP
19
20 #include <map>
21 #include <memory>
22
23 #include "supertux/screen.hpp"
24 #include "video/color.hpp"
25
26 class DrawingContext;
27 class Surface;
28 class Font;
29
30 /**
31  * Helper class for InfoBox: Represents a line of text
32  */
33 class InfoBoxLine
34 {
35 public:
36   enum LineType { NORMAL, NORMAL_LEFT, SMALL, HEADING, REFERENCE, IMAGE};
37
38   InfoBoxLine(char format_char, const std::string& text);
39   ~InfoBoxLine();
40
41   void draw(DrawingContext& context, const Rect& bbox, int layer);
42   float get_height();
43
44   static const std::vector<InfoBoxLine*> split(const std::string& text, float width);
45
46 private:
47   InfoBoxLine::LineType lineType;
48   Font* font;
49   Color color;
50   std::string text;
51   Surface* image;
52 };
53
54 /** This class is displaying a box with information text inside the game
55  */
56 class InfoBox
57 {
58 public:
59   InfoBox(const std::string& text);
60   ~InfoBox();
61
62   void draw(DrawingContext& context);
63   void scrolldown();
64   void scrollup();
65   void pagedown();
66   void pageup();
67
68 private:
69   size_t firstline;
70   std::vector<InfoBoxLine*> lines;
71   std::map<std::string, Surface*> images;
72   Surface* arrow_scrollup;
73   Surface* arrow_scrolldown;
74 };
75
76 /**
77  * Screen that displays intro text, extro text, etc.
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   static Color small_color;
90   static Color heading_color;
91   static Color reference_color;
92   static Color normal_color;
93 private:
94   float defaultspeed;
95   float speed;
96   std::string music;
97   std::auto_ptr<Surface> background;
98   std::vector<InfoBoxLine*> lines;
99   float scroll;
100   bool fading;
101
102 private:
103   TextScroller(const TextScroller&);
104   TextScroller& operator=(const TextScroller&);
105 };
106
107 #endif
108
109 /* EOF */