src/graphic/font.h

Go to the documentation of this file.
00001 /******************************************************************************
00002  *  Wormux is a convivial mass murder game.
00003  *  Copyright (C) 2001-2004 Lawrence Azzoug.
00004  *
00005  *  This program is free software; you can redistribute it and/or modify
00006  *  it under the terms of the GNU General Public License as published by
00007  *  the Free Software Foundation; either version 2 of the License, or
00008  *  (at your option) any later version.
00009  *
00010  *  This program is distributed in the hope that it will be useful,
00011  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  *  GNU General Public License for more details.
00014  *
00015  *  You should have received a copy of the GNU General Public License
00016  *  along with this program; if not, write to the Free Software
00017  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
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   // Size
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   // Style
00058   static const int NORMAL;
00059   static const int BOLD;
00060   static const int ITALIC;
00061 
00062   // type: defined as static consts above
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

Generated on Mon Jan 1 13:10:56 2007 for Wormux by  doxygen 1.4.7