Back to index

supertuxkart  0.5+dfsg1
font.hpp
Go to the documentation of this file.
00001 //  $Id: font.hpp 907 2007-02-04 01:38:54Z coz $
00002 //
00003 //  SuperTuxKart - a fun racing game with go-kart
00004 //  Copyright (C) 2006 Joerg Henrichs
00005 //
00006 //  This program is free software; you can redistribute it and/or
00007 //  modify it under the terms of the GNU General Public License
00008 //  as published by the Free Software Foundation; either version 2
00009 //  of the License, or (at your option) any later version.
00010 //
00011 //  This program is distributed in the hope that it will be useful,
00012 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00013 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014 //  GNU General Public License for more details.
00015 //
00016 //  You should have received a copy of the GNU General Public License
00017 //  along with this program; if not, write to the Free Software
00018 //  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00019 
00020 #ifndef HEADER_FONT_H
00021 #define HEADER_FONT_H
00022 
00023 #include <string>
00024 
00025 #include <plib/fnt.h>
00026 
00027 class Font
00028 {
00029 private:
00030     fntTexFont  *m_fnt;
00031     fntRenderer *m_text_out;
00032 
00033 public:
00034     //CENTER_OF_SCREEN has to be bigger or smaller than Widget::MAX_SCROLL
00035     const static int CENTER_OF_SCREEN=-1000001;
00036     enum FontSize      {SMALL=18,   MEDIUM=24,   LARGE=30    };
00037     Font(const char* fontname);
00038     Font(const std::string &fontname) { Font(fontname.c_str()); }
00039     ~Font();
00040     void getBBox(const std::string &text, int size, bool italic,
00041                  float *left, float *right, float *bot, float *top);
00042     void getBBoxMultiLine(const std::string &text, int size, bool italic,
00043                           float *left, float *right, float *bot, float *top);
00044 
00045     // The actual main function which does everything
00046     // ----------------------------------------------
00047     void Print(      const char *text, int size,
00048                      int x, int y,
00049                      const GLfloat* color = NULL,
00050                      float scale_x=1.0f, float scale_y=1.0f,
00051                      int left=-1, int right=-1, int top=-1, int bottom=-1,
00052                      bool doShadow=false);
00053     void Print(      std::string const &text, int size,
00054                      int x, int y,
00055                      const GLfloat* color = NULL,
00056                      float scale_x=1.0f, float scale_y=1.0f,
00057                      int left=-1, int right=-1, int top=-1, int bottom=-1,
00058                      bool doShadow=false)
00059     {
00060         Print(text.c_str(), size, x, y,
00061               color, scale_x, scale_y, left, right, top, bottom,
00062               doShadow);
00063     }
00064 
00065     void PrintShadow(const char *text, int size,
00066                      int x, int y,
00067                      const GLfloat* color = NULL,
00068                      float scale_x=1.0f, float scale_y=1.0f,
00069                      int left=-1, int right=-1, int top=-1, int bottom=-1)
00070     {
00071                      Print(text, size, x, y,
00072                            color, scale_x, scale_y,
00073                            left, right, top, bottom, true);
00074     }
00075     void PrintBold(  std::string const &text, int size,
00076                      int x, int y,
00077                      const GLfloat* color = NULL,
00078                      float scale_x=1.0f, float scale_y=1.0f,
00079                      int left=-1, int right=-1, int top=-1, int bottom=-1);
00080 };
00081 
00082 int init_fonts();
00083 int delete_fonts();
00084 
00085 extern Font* font_gui;
00086 extern Font* font_race;
00087 
00088 #endif