Main Page | Namespace List | Class Hierarchy | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

CSFont.h

Go to the documentation of this file.
00001 #ifndef CSFONT_H
00002 #define CSFONT_H
00003 
00004 // USES SDL_Surface
00005 
00006 #include "SDL.h"
00007 #include "CSPicture.h"
00008 #include "CSLoadable.h"
00009 #include "CSLog.h"
00010 #include <map>
00011 
00012 #ifdef WIN32
00013 #pragma warning(disable : 4786 )
00014 #endif
00015 
00016 class CSFont;
00017 class CSFontLoader;
00018 typedef std::vector<CSFont *> CSFonts;
00019 
00020 typedef std::map<int, SDL_Surface *> ColorFontMap;
00021 
00022 const int FONT_STYLE_NONE = 0;
00023 const int FONT_STYLE_UNDERLINE = 1;
00024 const int FONT_STYLE_BOLD = 2;
00025 const int FONT_STYLE_ITALIC = 4;
00026 
00027 class CSFontData
00028 {
00029     public:
00030         char *id;
00031         char *filename;     //!< of bitmap file
00032         int monospaced;
00033         CSFontData()
00034         {
00035             id = 0;
00036             filename = 0;
00037             monospaced = 0;
00038         }
00039 
00040         ~CSFontData()
00041         {
00042             if (id != 0) 
00043             {
00044                 free(id);
00045                 id = 0;
00046             }
00047             if (filename != 0) 
00048             {
00049                 free(filename);
00050                 filename = 0;
00051             }
00052         }
00053 };
00054 
00055 class CSFont
00056 {
00057     friend CSFontLoader;
00058     private:
00059         static CSFonts mAllFonts;
00060         static void addFont(CSFont *font);
00061         static void removeFont(CSFont *font);
00062 
00063         ColorFontMap mColorFontMap;
00064         char *mId;
00065         char *mFilename;
00066         CSPicture *mPicture;
00067         int mKey;
00068         int mSpaceWidth;
00069         int mCharPos[512];
00070         int mMonoSpaced;
00071         int mH;
00072         int mR;
00073         int mG;
00074         int mB;
00075         CSFont(const std::string &filename);
00076         virtual void initialize(const CSFontData &data);
00077         static void loadFontData(const std::string &filename, CSFontData &data);
00078         void buildSigns(void);
00079         void deleteColorFonts()
00080         {
00081             ColorFontMap::iterator iter = mColorFontMap.begin();
00082             while (iter != mColorFontMap.end())
00083             {
00084                 SDLMain::freeSurface(iter->second);
00085                 iter++;
00086             }
00087             mColorFontMap.clear();
00088         }
00089     
00090     public:
00091         CSFont(const CSFont &font) {}; // not available!
00092         virtual ~CSFont();
00093         static const char *CLASS;
00094         virtual std::string getType() {return (std::string) CLASS;}
00095         static void resetSurfaces();                            //!< resets all surfaces
00096         void resetSurface();        //!< converts current surface to display surface
00097                                     //!< used (e.g.) upon fullscreen-toggle
00098 
00099         void setSolid(bool b);
00100         int getHeight() {return mH;}
00101         
00102         //! Returns the width of "text" in pixels
00103         int getWidth(const char *text);
00104         int getWidth(const std::string &text) {return getWidth(text.c_str());}
00105 
00106         //! Blits a string to a surface
00107         //! Destination: the suface you want to blit to
00108         //! text: a string containing the text you want to blit.
00109         void putString(SDL_Surface *surface, int x, int y, const char *text);
00110         void putString(SDL_Surface *surface, int x, int y, const std::string &text)
00111             {putString(surface, x, y, text.c_str());}
00112         
00113         void putString(int x, int y, const char *text) 
00114             {putString(SDLMain::getScreen(), x, y, text);}
00115         void putString(int x, int y, const std::string &text) 
00116             {putString(SDLMain::getScreen(), x, y, text.c_str());}
00117 
00118         void putString(SDL_Surface *surface, int x, int y, int color, const char *text, int style=0);
00119         void putString(SDL_Surface *surface, int x, int y, int color, const std::string &text, int style = 0)
00120             {putString(surface, x, y, color, text.c_str(), style);}
00121         
00122         void putString(int x, int y, int color, const char *text) 
00123             {putString(SDLMain::getScreen(), x, y, color, text);}
00124         void putString(int x, int y, int color, const std::string &text) 
00125             {putString(SDLMain::getScreen(), x, y, color, text.c_str());}
00126 
00127         //! Blits a string to with centered x position
00128         void xCenteredString(SDL_Surface *surface, int y, const char *text);
00129         void xCenteredString(SDL_Surface *surface, int y, const std::string &text)
00130             {xCenteredString(surface, y, text.c_str());}
00131         void xCenteredString(int y, const char *text) 
00132             {xCenteredString(SDLMain::getScreen(), y, text);}
00133         void xCenteredString(int y, const std::string &text) 
00134             {xCenteredString(SDLMain::getScreen(), y, text.c_str());}
00135 
00136         //! Allows the user to enter text
00137         //! Width: What is the maximum width of the text (in pixels)
00138         //! text: This string contains the text which was entered by the user
00139         void inputText(SDL_Surface *Destination, int x, int y, int w, char *text);
00140         void inputText(int x, int y, int w, char *text) 
00141             {inputText(SDLMain::getScreen(), x, y, w, text);}
00142 };
00143 
00144 class CSFontLoader : public Loadable<CSFont>
00145 {
00146     
00147     protected:
00148         virtual CSFont *create(const std::string &filename)
00149         {
00150             return new CSFont(filename);
00151         }
00152 
00153     public:
00154         static CSFontLoader INSTANCE;
00155 };
00156 
00157 
00158 #endif CSFONT_H

Generated on Wed Jul 14 00:43:29 2004 for CSLib by doxygen 1.3.6