From: Ivan Hernanez Date: Fri, 1 Jun 2012 23:25:34 +0000 (-0500) Subject: added font class I forgot to commit X-Git-Url: http://git.mmlx.us/?a=commitdiff_plain;h=f0e248595eb472d716087b599280cf96c0e6a8c7;p=IvanGame.git added font class I forgot to commit --- diff --git a/Font.cpp b/Font.cpp new file mode 100644 index 0000000..08dd95f --- /dev/null +++ b/Font.cpp @@ -0,0 +1,36 @@ +#include "Font.h" +#include +#include +#include "fns.h" +#include +using namespace std; + + +Font::Font( FontType t, int s ) : type(t), size(s), count(1){ + // Load a font + fontFile = type==English ? "FreeSans.ttf" : "Japanese.ttf"; + font = TTF_OpenFont(fontFile.c_str(), size); + if(!font) + cerr << "TTF_OpenFont() Failed: " << TTF_GetError() << endl; +} + +Font::Font( int s ) : type(English), size(s), count(1){ + // Load a font + fontFile = "FreeSans.ttf"; + font = TTF_OpenFont(fontFile.c_str(), size); + + if(!font) + cerr << "TTF_OpenFont() Failed: " << TTF_GetError() << endl; + +} + +Font::~Font(){ + TTF_CloseFont(font); +} + +void Font::setSize(int s){ + if(s!=size){ + TTF_CloseFont(font); + font = TTF_OpenFont(fontFile.c_str(), s); + } +} diff --git a/Font.h b/Font.h new file mode 100644 index 0000000..21033ba --- /dev/null +++ b/Font.h @@ -0,0 +1,45 @@ +#ifndef __FONT_H__ +#define __FONT_H__ +#include +#include +#include +#include +#include "SDL_ttf.h" +#include "fns.h" +using namespace std; + +/** + Font for rendering text + + This class is tasked with the following: + - Holding and loading a font + */ +class Font +{ + public: + ///The font itself + TTF_Font* font; + ///Type for the font en, jp, jpw/ruby + FontType type; + ///Filename of the font + string fontFile; + ///Font size + int size; + ///The count of Texts using this font + int count; + /** + Create the font with size s + \param s Font size + */ + Font(int s = 24); + /** + Create the font with size s and type t + \param s Font size + \param t Type of font + */ + Font(FontType t, int s = 24); + ~Font(); + //closes the font and changes the size + void setSize(int s); +}; +#endif