00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef FONT_H
00021 #define FONT_H
00022 #include <SDL.h>
00023 #include <SDL_ttf.h>
00024 #include <map>
00025 #include "../include/base.h"
00026 #include "colors.h"
00027 #include "surface.h"
00028
00029 class GameLoop;
00030
00031 class Font
00032 {
00033 private:
00034 typedef std::map<std::string, Surface>::value_type
00035 txt_sample;
00036 typedef std::map<std::string, Surface>::iterator
00037 txt_iterator;
00038 static const int FONT_SIZE[];
00039 static Font* FONT_ARRAY[6];
00040 static Font* FONT_ARRAY_BOLD[6];
00041 static Font* FONT_ARRAY_ITALIC[6];
00042
00043 std::map<std::string, Surface> surface_text_table;
00044 TTF_Font *m_font;
00045 void Write(const Point2i &pos, Surface &surface);
00046
00047 Font(int size);
00048
00049 public:
00050
00051 static const int FONT_HUGE;
00052 static const int FONT_LARGE;
00053 static const int FONT_BIG;
00054 static const int FONT_NORMAL;
00055 static const int FONT_SMALL;
00056 static const int FONT_TINY;
00057
00058 static const int NORMAL;
00059 static const int BOLD;
00060 static const int ITALIC;
00061
00062
00063 static Font* GetInstance(int type, int font_style = NORMAL);
00064
00065 ~Font();
00066
00067 bool Load (const std::string& filename, int size);
00068
00069 void WriteLeft(const Point2i &pos, const std::string &txt, const Color &color);
00070 void WriteLeftBottom(const Point2i &pos, const std::string &txt, const Color &color);
00071 void WriteRight(const Point2i &pos, const std::string &txt, const Color &color);
00072 void WriteCenterTop(const Point2i &pos, const std::string &txt, const Color &color);
00073 void WriteCenter(const Point2i &pos, const std::string &txt, const Color &color);
00074
00075 int GetWidth(const std::string &txt);
00076 int GetHeight();
00077 int GetHeight(const std::string &txt);
00078 Point2i GetSize(const std::string &txt);
00079
00080 Surface Render(const std::string &txt, const Color &color, bool cache=false);
00081 Surface CreateSurface(const std::string &txt, const Color &color);
00082 void SetBold();
00083 void SetItalic();
00084 };
00085
00086 #endif