updating Nolok contrib templates
[supertux.git] / lib / video / 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_FONT_H
22 #define SUPERTUX_FONT_H
23
24 #include <string>
25 #include <stdint.h>
26
27 #include "video/surface.h"
28 #include "math/vector.h"
29
30 namespace SuperTux
31   {
32
33   enum FontAlignment {
34     LEFT_ALLIGN,
35     CENTER_ALLIGN,
36     RIGHT_ALLIGN
37     };
38
39   /// Font
40   class Font
41     {
42     public:
43       /// Kinds of texts.
44       enum FontType {
45         TEXT, // images for all characters
46         NUM   // only images for numbers
47       };
48
49       Font(const std::string& file, FontType type, int w, int h,
50           int shadowsize=2);
51       ~Font();
52
53       /** returns the width of a given text. (Note that I won't add a normal
54        * get_width function here, as we might switch to variable width fonts in the
55        * future.)
56        * Supports breaklines.
57        */
58       float get_text_width(const std::string& text) const;
59
60       /** returns the height of a given text. (Note that I won't add a normal
61        * get_width function here, as we might switch to variable width fonts in the
62        * future.)
63        * Supports breaklines.
64        * In case, you are positive that your text doesn't use break lines, you can
65        * just use get_height().
66        */
67       float get_text_height(const std::string& text) const;
68       /// returns the height of the font.
69       float get_height() const;
70
71       /** Draws the given text to the screen. Also needs the position.
72        * Type of alignment, drawing effect and alpha are optional. */
73       void draw(const std::string& text, const Vector& pos,
74           FontAlignment allignment = LEFT_ALLIGN,
75           uint32_t drawing_effect = NONE_EFFECT, uint8_t alpha = 255) const;
76
77     private:
78       friend class DrawingContext;
79
80       void draw_text(const std::string& text, const Vector& pos,
81           uint32_t drawing_effect = NONE_EFFECT, uint8_t alpha = 255) const;
82
83       void draw_chars(Surface* pchars, const std::string& text,
84           const Vector& position, uint32_t drawing_effect, uint8_t alpha) const;
85
86       Surface* chars;
87       Surface* shadow_chars;
88       FontType type;
89       int w;
90       int h;
91       int shadowsize;
92
93       /// the number of the first character that is represented in the font
94       int first_char;
95       /// the number of the last character that is represented in the font
96       int last_char;
97     };
98 } //namespace SuperTux
99
100 #endif /*SUPERTUX_FONT_H*/
101