Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members | Related Pages

bfont.h

Go to the documentation of this file.
00001 
00002 /************************************************************
00003 
00004    BFONT v. 1.0.2 - Billi Font Library by Diego Billi
00005    BFONT++ C++ port by Gianluigi Davassi
00006 ************************************************************/
00007 
00008 #ifndef __BFONT_HEADER_H__
00009 #define __BFONT_HEADER_H__
00010 
00011 #include <iostream>
00012 #include <SDL/SDL.h>
00013 
00014 class BFont
00015 {
00016     int h;                  // font height
00017     SDL_Surface *Surface;   // font surface
00018     SDL_Rect Chars[256];    // characters width
00019     const char* name;       // font name
00020 
00021     BFont(const BFont&);
00022 
00023     void InitFont();
00024     int count(const char *text);
00025 public:
00026 
00027     BFont(const char *__filename) // generator bill
00028         : name(__filename)
00029     { LoadFont(__filename); }
00030 
00031     ~BFont()
00032         { SDL_FreeSurface(Surface); } // screen must be free by application
00033 
00034     int FontHeight () // Returns the font height
00035     { return h; }
00036 
00037     void SetFontHeight (int height) // Change the font height
00038     { h = height ; }
00039 
00040     int CharWidth (char c) // Returns the character width of the specified font
00041     { return Chars[c].w; }
00042 
00043     void LoadFont      (const char *filename);     // Load and store le font in the BFont structure
00044     int PutChar        (SDL_Surface *screen, int x, int y, char c);     // Write a single character on the "Surface" with the current font
00045     int TextWidth      (const char *text );        // Returns the width, in pixels, of the text calculated with the current font
00046 
00047     BFont *SetFontColor(Uint8 r, Uint8 g, Uint8 b); // Returns a new font colored with the color (r,g,b)
00048 
00049     void PutString          ( SDL_Surface *screen, int x, int y, const char *text); // Write a string on the "Surface" with the specified font
00050     void LeftPutString      ( SDL_Surface *screen, int y, const char *text);  // Write a left-aligned string on the "Surface" with the specified font
00051     void CenteredPutString  ( SDL_Surface *screen, int y, const char *text);  // Write a center-aligned string on the "Surface" with the specified font
00052     void RightPutString     ( SDL_Surface *screen, int y, const char *text);  // Write a right-aligned string on the "Surface" with the specified font
00053     void JustifiedPutString ( SDL_Surface *screen, int y, const char *text);  // Write a justify-aligned string on the "Surface" with the specified font
00054 
00055     // The following functions do the same task but have the classic "printf" sintax
00056     void PrintString              ( SDL_Surface *screen, int x, int y, char *fmt, ...);
00057     void CenteredPrintString      ( SDL_Surface *screen, int y,  char *fmt, ...);
00058     void RightPrintString         ( SDL_Surface *screen, int y, char *fmt, ...);
00059     void LeftPrintString          ( SDL_Surface *screen, int y, char *fmt, ...);
00060     void JustifiedPrintString     ( SDL_Surface *screen, int y, char *fmt, ...);
00061 
00062 private:
00063     Uint32 GetPixel( Sint32 X, Sint32 Y);
00064         Uint32 xGetPixel(SDL_Surface *surface, int x, int y);
00065     void   PutPixel( SDL_Surface *,int x, int y, Uint32 pixel);
00066 
00067 };
00068 
00069 #endif // __BFONT_HEADER_H__
00070 

Generated on Sat Nov 5 16:17:24 2005 for OPIE by  doxygen 1.4.2