added font class I forgot to commit
authorIvan Hernanez <iturtleman128@gmail.com>
Fri, 1 Jun 2012 23:25:34 +0000 (18:25 -0500)
committerIvan Hernanez <iturtleman128@gmail.com>
Fri, 1 Jun 2012 23:25:34 +0000 (18:25 -0500)
Font.cpp [new file with mode: 0644]
Font.h [new file with mode: 0644]

diff --git a/Font.cpp b/Font.cpp
new file mode 100644 (file)
index 0000000..08dd95f
--- /dev/null
+++ b/Font.cpp
@@ -0,0 +1,36 @@
+#include "Font.h"
+#include <iostream>
+#include <string>
+#include "fns.h"
+#include <GL/gl.h>
+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 (file)
index 0000000..21033ba
--- /dev/null
+++ b/Font.h
@@ -0,0 +1,45 @@
+#ifndef __FONT_H__
+#define __FONT_H__
+#include <stdio.h>
+#include <stdlib.h>
+#include <string>
+#include <SDL/SDL.h>
+#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