1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
//--------------------------------------------------------------------------------------------------
// CFont.
// Font routines.
// Cone3D SDL font routines by Marius Andra 2002, http://cone3d.gamedev.net.
//--------------------------------------------------------------------------------------------------
#ifndef __CFONT_H__
#define __CFONT_H__
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>
#include <SDL.h>
// Structure to hold our font.
struct SDLFont
{
SDL_Surface *font; // The SDL Surface for the font image.
int width; // Width of the SDL Surface (same as the height because the image font is a square).
int charWidth; // Width of one block character in the font (fontWidth/16).
int *widths; // Real widths of all the fonts.
unsigned char *data; // The raw font data.
};
// This function initalizes a font.
SDLFont *initFont(const char *fontdir, float r, float g, float b, float a);
// Some overloaded functions to make your life easier.
inline SDLFont *initFont(const char *fontdir, float r, float g, float b) { return initFont(fontdir, r, g, b, 1); }
inline SDLFont *initFont(const char *fontdir) { return initFont(fontdir, 1, 1, 1, 1); }
// This function draws a string.
void drawString(SDL_Surface *screen, SDLFont *font, int x, int y,char *str,...);
// This function returns the width of a string.
int stringWidth(SDLFont *font, char *str,...);
// This function destroys the font.
void freeFont(SDLFont *font);
#endif /* __CFONT_H__ */
|