# HG changeset patch # User Matti Hamalainen # Date 1349199181 -10800 # Node ID f16d102dbbac8c5fb8e12c83f6fe112ded85bc8f # Parent 7a59611f9d4fafcd6673f29b929961dc1ff29aa1 Add a function for setting bitmapped font palette. diff -r 7a59611f9d4f -r f16d102dbbac dmtext.h --- a/dmtext.h Tue Oct 02 20:26:08 2012 +0300 +++ b/dmtext.h Tue Oct 02 20:33:01 2012 +0300 @@ -52,6 +52,7 @@ int dmLoadBitmapFont(DMResource *res, DMBitmapFont **pfont); int dmSaveBitmapFont(DMResource *res, DMBitmapFont *font); int dmCreateBitmapFontFromImage(SDL_Surface *image, int width, int height, DMBitmapFont **pfont); +int dmSetBitmapFontPalette(DMBitmapFont *font, SDL_Color *pal, int start, int size); void dmDrawBMTextConst(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *str); void dmDrawBMTextVA(SDL_Surface *screen, DMBitmapFont *font, int mode, int xc, int yc, const char *fmt, va_list ap); diff -r 7a59611f9d4f -r f16d102dbbac dmtext_bm.c --- 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;