Planet
navi homePPSaboutscreenshotsdownloaddevelopmentforum

source: orxonox.OLD/orxonox/branches/textEngine/src/lib/graphics/font/font.cc @ 3681

Last change on this file since 3681 was 3681, checked in by bensch, 19 years ago

orxonox/branches/textEngine: merged trunk here.
merged with command:
svn merge ../trunk textEngine -r 3467:HEAD
no conflicts

File size: 1.6 KB
Line 
1/*
2Copyright (C) 2004 Lion Vollnhals
3Copyright (C) 2003 Matthias Braun
4
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation; either version 2 of the License, or
8(at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15You should have received a copy of the GNU General Public License
16along with this program; if not, write to the Free Software
17Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18*/
19#ifndef __LIB_2D_FONT_HPP__
20#define __LIB_2D_FONT_HPP__
21
22#include <string>
23#include <stdexcept>
24#include "SFont.h"
25
26/** A thin c++ wrapper around my custom SFont version */
27class SFont
28{
29public:
30        int getHeight() const
31        { return SFont_TextHeight(font); }
32
33        int getTextWidth(const char* text) const
34        { return SFont_TextWidth(font, text); }
35        int getTextWidth(const std::string& text) const
36        { return getTextWidth(text.c_str()); }
37
38        void write(SDL_Surface* surface, const char* text, int x, int y) const
39        { SFont_Write(surface, font, x, y, text); }
40       
41        void write(SDL_Surface* surface, const std::string& text, int x, int y) const
42        { Write(surface, text.c_str(), x, y); }
43
44        Font(SDL_Surface* surface)
45        {
46                font = SFont_InitFont(surface);
47                if(!font)
48                        throw std::runtime_error("Couldn't initialize font.");
49        }
50        ~Font()
51        { SFont_FreeFont(font); }
52       
53private:
54        SFont_Font* font;
55};
56
57#endif
58
59
Note: See TracBrowser for help on using the repository browser.