annotate dmtext.h @ 105:d5d27f262227

Beging merging of dmsimple2-fork into the main "engine".
author Matti Hamalainen <ccr@tnsp.org>
date Wed, 03 Oct 2012 09:16:26 +0300
parents f16d102dbbac
children 67d2cba58a87
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
60
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /*
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * DMLib
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * -- Bitmap font support
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * Programmed and designed by Matti 'ccr' Hamalainen
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * (C) Copyright 2012 Tecnic Software productions (TNSP)
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 */
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 #ifndef DMFONT_H
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 #define DMFONT_H
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 #include "dmlib.h"
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 #include "dmres.h"
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 #ifdef DM_GFX_TTF_TEXT
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 #include <SDL_ttf.h>
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 #endif
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 #ifdef __cplusplus
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 extern "C" {
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 #endif
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 /* Bitmapped fonts and text
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 */
63
3d9da937db69 More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
23 #ifdef DM_GFX_BM_TEXT
75
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
24
89
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
25 // DMFONT format constants
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
26 #define DMFONT_MAGIC "DMFONT"
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
27 #define DMFONT_VERSION 0x0100
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
28
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
29 #define DMFONT_MIN_WIDTH 3
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
30 #define DMFONT_MIN_HEIGHT 3
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
31 #define DMFONT_MAX_WIDTH 128
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
32 #define DMFONT_MAX_HEIGHT 128
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
33 #define DMFONT_MAX_GLYPHS 1024
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
34
91
e1e308167991 Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
35 #define DMFONT_NPALETTE 256
e1e308167991 Various improvements in the bitmapped font loading and saving functions.
Matti Hamalainen <ccr@tnsp.org>
parents: 89
diff changeset
36
89
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
37 // Legacy TSFONT loading support
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
38 #define TSFONT_MAGIC "TSFONT"
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
39 #define TSFONT_VERSION 0x0205
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
40
75
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
41
60
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42 typedef struct
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 {
89
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
44 int width, height; // Dimensions
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
45 int nglyphs; // Size of glyphs array
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
46 SDL_Surface **glyphs; // NOTE! Not all glyphs may be allocated
60
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 } DMBitmapFont;
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49
89
b10884934aca Various improvements in bitmapped font support, and addition of legacy
Matti Hamalainen <ccr@tnsp.org>
parents: 75
diff changeset
50 DMBitmapFont *dmNewBitmapFont(int nglyphs, int width, int height);
65
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
51 int dmFreeBitmapFont(DMBitmapFont *font);
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
52 int dmLoadBitmapFont(DMResource *res, DMBitmapFont **pfont);
75
e6535609c161 Initial implementation of loading and saving of bitmap fonts.
Matti Hamalainen <ccr@tnsp.org>
parents: 65
diff changeset
53 int dmSaveBitmapFont(DMResource *res, DMBitmapFont *font);
65
03375aa0ef2b Implement some new functions for bitmapped font handling.
Matti Hamalainen <ccr@tnsp.org>
parents: 63
diff changeset
54 int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont);
100
f16d102dbbac Add a function for setting bitmapped font palette.
Matti Hamalainen <ccr@tnsp.org>
parents: 91
diff changeset
55 int dmSetBitmapFontPalette(DMBitmapFont *font, SDL_Color *pal, int start, int size);
60
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 void dmDrawBMTextConst(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *str);
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 void dmDrawBMTextVA(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap);
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 void dmDrawBMText(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, ...);
105
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
60
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
61
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
62 static inline SDL_Surface *dmGetBMGlyph(DMBitmapFont *font, int ch)
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
63 {
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
64 if (ch < 0 || ch >= font->nglyphs || ch == '\n' || ch == '\r')
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
65 ch = 32;
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
66
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
67 return font->glyphs[ch];
d5d27f262227 Beging merging of dmsimple2-fork into the main "engine".
Matti Hamalainen <ccr@tnsp.org>
parents: 100
diff changeset
68 }
63
3d9da937db69 More work on the text support.
Matti Hamalainen <ccr@tnsp.org>
parents: 60
diff changeset
69 #endif
60
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 /* TTF text drawing
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 */
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 #ifdef DM_GFX_TTF_TEXT
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75 void dmDrawTTFTextConst(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int x, int y, const char *fmt);
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 void dmDrawTTFTextVA(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int x, int y, const char *fmt, va_list ap);
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 void dmDrawTTFText(SDL_Surface *screen, TTF_Font *font, SDL_Color col, int x, int y, const char *fmt, ...);
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 #endif
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 #ifdef __cplusplus
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 }
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 #endif
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84
f28cd66356f6 Initial work for bitmapped fonts and text drawing. Also moved TTF header
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85 #endif // DMFONT_H