00b50418424930de8964feabfc0985d532585021
[supertux.git] / src / screen / font.h
1 //  $Id$
2 // 
3 //  SuperTux
4 //  Copyright (C) 2004 Tobias Glaesser <tobi.web@gmx.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 SUPERTUX_TEXT_H
22 #define SUPERTUX_TEXT_H
23
24 #include <string>
25 #include "texture.h"
26 #include "vector.h"
27
28 void display_text_file(const std::string& file, const std::string& surface, float scroll_speed);
29 void display_text_file(const std::string& file, Surface* surface, float scroll_speed);
30
31 /* Text type */
32 class Font
33 {
34 public:
35   /* Kinds of texts. */
36   enum FontType {
37     TEXT, // images for all characters
38     NUM   // only images for numbers
39   };
40   
41   Font(const std::string& file, FontType type, int w, int h, int shadowsize=2);
42   ~Font();
43
44   /** returns the height of the font */
45   float get_height() const;
46   /** returns the width of a given text. (Note that I won't add a normal
47    * get_width function here, as we might switch to variable width fonts in the
48    * future.
49    */
50   float get_text_width(const std::string& text) const;
51
52 private:
53   friend class DrawingContext;
54   
55   void draw(const std::string& text, const Vector& pos);
56   void draw_chars(Surface* pchars, const std::string& text, 
57       const Vector& position);
58
59   Surface* chars;
60   Surface* shadow_chars;
61   FontType type;
62   int w;
63   int h;
64   int shadowsize;
65
66   /// the number of the first character that is represented in the font
67   int first_char;
68   /// the number of the last character that is represented in the font
69   int last_char;
70 };
71
72 #endif /*SUPERTUX_TEXT_H*/
73