Mercurial > hg > dmlib
diff dmtext_bm.c @ 100:f16d102dbbac
Add a function for setting bitmapped font palette.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Oct 2012 20:33:01 +0300 |
parents | e1e308167991 |
children | 8bba97252d85 |
line wrap: on
line diff
--- a/dmtext_bm.c Tue Oct 02 20:26:08 2012 +0300 +++ b/dmtext_bm.c Tue Oct 02 20:33:01 2012 +0300 @@ -110,6 +110,34 @@ } +/* Set the palette for each glyph. While the function allows you to + * specify 'start' and 'end' indices and palette array freely, you should + * typically use DMFONT_NPALETTE size palette starting at index 0. + */ +int dmSetBitmapFontPalette(DMBitmapFont *font, SDL_Color *pal, int start, int size) +{ + int i; + + if (font == NULL) + return DMERR_NULLPTR; + + if (start < 0 || end < start) + return DMERR_INVALID_ARGS; + + for (i = 0; i < font->nglyphs; i++) + { + SDL_Surface *glyph = font->glyphs[i]; + if (glyph != NULL) + { + if (glyph->format->BitsPerPixel == 8) + SDL_SetColors(glyph, pal, start, end); + } + } + + return DMERR_OK; +} + + int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont) { int nglyph, xc, yc, xglyphs, yglyphs;