| 1 | /* | 
|---|
| 2 | Copyright (C) 2004 Lion Vollnhals | 
|---|
| 3 | Copyright (C) 2003 Matthias Braun | 
|---|
| 4 |  | 
|---|
| 5 | This program is free software; you can redistribute it and/or modify | 
|---|
| 6 | it under the terms of the GNU General Public License as published by | 
|---|
| 7 | the Free Software Foundation; either version 2 of the License, or | 
|---|
| 8 | (at your option) any later version. | 
|---|
| 9 |  | 
|---|
| 10 | This program is distributed in the hope that it will be useful, | 
|---|
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | 
|---|
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the | 
|---|
| 13 | GNU General Public License for more details. | 
|---|
| 14 |  | 
|---|
| 15 | You should have received a copy of the GNU General Public License | 
|---|
| 16 | along with this program; if not, write to the Free Software | 
|---|
| 17 | Foundation, 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 */ | 
|---|
| 27 | class SFont | 
|---|
| 28 | { | 
|---|
| 29 | public: | 
|---|
| 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 |          | 
|---|
| 53 | private: | 
|---|
| 54 |         SFont_Font* font; | 
|---|
| 55 | }; | 
|---|
| 56 |  | 
|---|
| 57 | #endif | 
|---|
| 58 |  | 
|---|
| 59 |  | 
|---|