Page principale | Liste des namespaces | Liste des classes | Liste des fichiers | Membres de namespace | Membres de classe | Membres de fichier

sofont.h

Aller à la documentation de ce fichier.
00001 /*
00002  * Xtratego - a network stratego game
00003  *
00004  * by Little Neo, 2003-2005
00005  *
00006  * this is Free Software, see COPYING file for details
00007  *
00008  */
00009 
00010 /*
00011  * This file is a *modified* version of SoFont.
00012  * It is mixed with SFont 1.71, and some parts are ported to c++.  
00013  * See below and README.sofont to learn about the original distribution.
00014  *
00015  */
00016 
00017 /*   
00018         SoFont - SDL Object Font Library
00019         
00020         This library is free software; you can redistribute it and/or
00021         modify it under the terms of the GNU Library General Public
00022         License as published by the Free Software Foundation; either
00023         version 2 of the License, or (at your option) any later version.
00024         
00025         This library is distributed in the hope that it will be useful,
00026         but WITHOUT ANY WARRANTY; without even the implied warranty of
00027         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00028         Library General Public License for more details.
00029         
00030         You should have received a copy of the GNU Library General Public
00031         License along with this library; if not, write to the Free
00032         Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00033         
00034 
00035         ChangeLog:
00036 
00037         Karl Bartel <karlb@gmx.net>:
00038                 * Wrote original SFont C library
00039         
00040         Luc-Olivier de Charriere:
00041                 * Copied into a C++ object to allow multiple fonts
00042 
00043         David Olofson <do@reologica.se>:
00044                 * Strings changed to 'const char *'
00045                 * Cursor tests first check if '|' is present.
00046                 * Shadowed variables fixed.
00047                 * Garbage data in spacing table fixed. (Thanks to
00048                   Andreas Spångberg for discovering this one!)
00049 */
00050 
00051 #ifndef __SOFONT_H
00052 #define __SOFONT_H
00053 
00054 #include "SDL.h"
00055 
00056 /*
00057 typedef struct {
00058         SDL_Surface *Surface;   
00059         int CharPos[512];
00060         int h;
00061 } SFont_FontInfo; // from SFont 1.71, finally not used - L N
00062 */
00063 
00064 class SoFont
00065 {
00066 public:
00067         SoFont();
00068         ~SoFont();
00069 
00070         bool load(SDL_Surface *FontSurface);
00071 
00072         // Blits a string to a surface
00073         //   Destination: the suface you want to blit to
00074         //   text: a string containing the text you want to blit.
00075         void PutString(SDL_Surface *Surface, int x, int y, const char *text, SDL_Rect *clip=NULL);
00076         void PutStringWithCursor(SDL_Surface *Surface, int x, int y, const char *text, int cursPos, SDL_Rect *clip=NULL, bool showCurs=true);
00077 
00078         // Returns the width of "text" in pixels
00079         int TextWidth(const char *text, int min=0, int max=255);
00080 
00081         int FontHeight()        { return height; }
00082 
00083         // Blits a string to with centered x position
00084         void XCenteredString(SDL_Surface *Surface, int y, const char *text, SDL_Rect* clip=NULL);
00085         // Blits a string to with centered x & y position
00086         void CenteredString(SDL_Surface *Surface, const char *text, SDL_Rect* clip=NULL);
00087         // Blits a string to with centered around x & y positions
00088         void CenteredString(SDL_Surface *Surface, int x, int y, const char *text, SDL_Rect* clip=NULL);
00089         
00090         // This was specially developped for GUI
00091         void PutStringCleverCursor(SDL_Surface *Surface, const char *text, int cursPos, SDL_Rect *r, SDL_Rect* clip=NULL, bool showCurs=true);
00092         
00093         // Gives the cursor position given a x-axix point in the text
00094         int TextCursorAt(const char *text, int px);
00095         int CleverTextCursorAt(const char *text, int px, int cursPos, SDL_Rect *r);
00096         
00097 #       define START_CHAR 33
00098         int getMinChar(){return START_CHAR;}
00099         int getMaxChar(){return max_i;}
00100 
00101         // the following functions come from SFont 1.71 // L N
00102         
00103         void InternalInput( SDL_Surface *Dest, int x, int y, int PixelWidth, char *text);
00104         void Input( SDL_Surface *Dest, int x, int y, int PixelWidth, char *text);
00105 
00106 protected:
00107         int height;
00108         SDL_Surface *picture;
00109         int *CharPos;
00110         int *Spacing;
00111         
00112         int max_i, spacew, cursShift;
00113         Uint32 background;
00114         bool DoStartNewChar(Sint32 x);
00115         void CleanSurface();
00116 };
00117 
00118 #endif



Little Neo, 2005 (+ doxygen)

  xtratego

  Accueil