git repos / blockattack-game

blame: source/code/SFont.h

normal view · raw

09a3b41b sago007 2008-09-06 22:44 1
/*  SFont: a simple font-library that uses special bitmaps as fonts
09a3b41b sago007 2008-09-06 22:44 2
    Copyright (C) 2003 Karl Bartel
09a3b41b sago007 2008-09-06 22:44 3
09a3b41b sago007 2008-09-06 22:44 4
    License: GPL or LGPL (at your choice)
09a3b41b sago007 2008-09-06 22:44 5
    WWW: http://www.linux-games.com/sfont/
09a3b41b sago007 2008-09-06 22:44 6
09a3b41b sago007 2008-09-06 22:44 7
    This program is free software; you can redistribute it and/or modify
09a3b41b sago007 2008-09-06 22:44 8
    it under the terms of the GNU General Public License as published by
09a3b41b sago007 2008-09-06 22:44 9
    the Free Software Foundation; either version 2 of the License, or
09a3b41b sago007 2008-09-06 22:44 10
    (at your option) any later version.
09a3b41b sago007 2008-09-06 22:44 11
09a3b41b sago007 2008-09-06 22:44 12
    This program is distributed in the hope that it will be useful,
09a3b41b sago007 2008-09-06 22:44 13
    but WITHOUT ANY WARRANTY; without even the implied warranty of
09a3b41b sago007 2008-09-06 22:44 14
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
09a3b41b sago007 2008-09-06 22:44 15
    GNU General Public License for more details.
09a3b41b sago007 2008-09-06 22:44 16
09a3b41b sago007 2008-09-06 22:44 17
    You should have received a copy of the GNU General Public License
09a3b41b sago007 2008-09-06 22:44 18
    along with this program; if not, write to the Free Software
09a3b41b sago007 2008-09-06 22:44 19
    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
09a3b41b sago007 2008-09-06 22:44 20
09a3b41b sago007 2008-09-06 22:44 21
    Karl Bartel
09a3b41b sago007 2008-09-06 22:44 22
    Cecilienstr. 14
09a3b41b sago007 2008-09-06 22:44 23
    12307 Berlin
09a3b41b sago007 2008-09-06 22:44 24
    GERMANY
09a3b41b sago007 2008-09-06 22:44 25
    karlb@gmx.net
09a3b41b sago007 2008-09-06 22:44 26
*/
09a3b41b sago007 2008-09-06 22:44 27
09a3b41b sago007 2008-09-06 22:44 28
/************************************************************************
09a3b41b sago007 2008-09-06 22:44 29
*    SFONT - SDL Font Library by Karl Bartel <karlb@gmx.net>            *
09a3b41b sago007 2008-09-06 22:44 30
*                                                                       *
09a3b41b sago007 2008-09-06 22:44 31
*  All functions are explained below. For further information, take a   *
09a3b41b sago007 2008-09-06 22:44 32
*  look at the example files, the links at the SFont web site, or       *
09a3b41b sago007 2008-09-06 22:44 33
*  contact me, if you problem isn' addressed anywhere.                  *
09a3b41b sago007 2008-09-06 22:44 34
*                                                                       *
09a3b41b sago007 2008-09-06 22:44 35
************************************************************************/
09a3b41b sago007 2008-09-06 22:44 36
#ifndef SFONT_H
09a3b41b sago007 2008-09-06 22:44 37
#define SFONT_H
09a3b41b sago007 2008-09-06 22:44 38
09a3b41b sago007 2008-09-06 22:44 39
#include <SDL.h>
09a3b41b sago007 2008-09-06 22:44 40
09a3b41b sago007 2008-09-06 22:44 41
#ifdef __cplusplus
09a3b41b sago007 2008-09-06 22:44 42
extern "C" {
09a3b41b sago007 2008-09-06 22:44 43
#endif
09a3b41b sago007 2008-09-06 22:44 44
09a3b41b sago007 2008-09-06 22:44 45
// Delcare one variable of this type for each font you are using.
09a3b41b sago007 2008-09-06 22:44 46
// To load the fonts, load the font image into YourFont->Surface
09a3b41b sago007 2008-09-06 22:44 47
// and call InitFont( YourFont );
09a3b41b sago007 2008-09-06 22:44 48
    typedef struct {
09a3b41b sago007 2008-09-06 22:44 49
        SDL_Surface *Surface;
09a3b41b sago007 2008-09-06 22:44 50
        int CharPos[512];
09a3b41b sago007 2008-09-06 22:44 51
        int MaxPos;
09a3b41b sago007 2008-09-06 22:44 52
    } SFont_Font;
09a3b41b sago007 2008-09-06 22:44 53
09a3b41b sago007 2008-09-06 22:44 54
// Initializes the font
09a3b41b sago007 2008-09-06 22:44 55
// Font: this contains the suface with the font.
09a3b41b sago007 2008-09-06 22:44 56
//       The Surface must be loaded before calling this function
09a3b41b sago007 2008-09-06 22:44 57
    SFont_Font* SFont_InitFont (SDL_Surface *Font);
09a3b41b sago007 2008-09-06 22:44 58
09a3b41b sago007 2008-09-06 22:44 59
// Frees the font
09a3b41b sago007 2008-09-06 22:44 60
// Font: The font to free
09a3b41b sago007 2008-09-06 22:44 61
//       The font must be loaded before using this function.
09a3b41b sago007 2008-09-06 22:44 62
    void SFont_FreeFont(SFont_Font* Font);
09a3b41b sago007 2008-09-06 22:44 63
09a3b41b sago007 2008-09-06 22:44 64
// Blits a string to a surface
09a3b41b sago007 2008-09-06 22:44 65
// Destination: the suface you want to blit to
09a3b41b sago007 2008-09-06 22:44 66
// text: a string containing the text you want to blit.
09a3b41b sago007 2008-09-06 22:44 67
    void SFont_Write(SDL_Surface *Surface, const SFont_Font *Font, int x, int y,
09a3b41b sago007 2008-09-06 22:44 68
                     const char *text);
09a3b41b sago007 2008-09-06 22:44 69
09a3b41b sago007 2008-09-06 22:44 70
// Returns the width of "text" in pixels
09a3b41b sago007 2008-09-06 22:44 71
    int SFont_TextWidth(const SFont_Font* Font, const char *text);
09a3b41b sago007 2008-09-06 22:44 72
// Returns the height of "text" in pixels (which is always equal to Font->Surface->h)
09a3b41b sago007 2008-09-06 22:44 73
    int SFont_TextHeight(const SFont_Font* Font);
09a3b41b sago007 2008-09-06 22:44 74
09a3b41b sago007 2008-09-06 22:44 75
// Blits a string to Surface with centered x position
09a3b41b sago007 2008-09-06 22:44 76
    void SFont_WriteCenter(SDL_Surface *Surface, const SFont_Font* Font, int y,
09a3b41b sago007 2008-09-06 22:44 77
                           const char *text);
09a3b41b sago007 2008-09-06 22:44 78
09a3b41b sago007 2008-09-06 22:44 79
#ifdef __cplusplus
09a3b41b sago007 2008-09-06 22:44 80
}
09a3b41b sago007 2008-09-06 22:44 81
#endif
09a3b41b sago007 2008-09-06 22:44 82
09a3b41b sago007 2008-09-06 22:44 83
#endif /* SFONT_H */
1970-01-01 00:00 84