You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
109 lines
2.5 KiB
109 lines
2.5 KiB
/* $Id: font.c,v 1.10 2003/11/08 06:27:58 stpohle Exp $ */
|
|
// Using Fonts in SDL
|
|
|
|
#include <string.h>
|
|
#include <SDL.h>
|
|
|
|
#include "bomberclone.h"
|
|
|
|
_point font_lastsize; // so we can get the last size of the drawn font
|
|
_font font[3];
|
|
|
|
void
|
|
font_draw (int x, int y, char *text, int size)
|
|
{
|
|
int i,
|
|
c;
|
|
SDL_Rect src,
|
|
dest;
|
|
|
|
src.y = 0;
|
|
dest.w = src.w = font[size].size.x;
|
|
dest.h = src.h = font[size].size.y;
|
|
dest.x = x;
|
|
dest.y = y;
|
|
|
|
for (i = 0; text[i] != 0; i++) {
|
|
c = text[i];
|
|
src.x = font[size].size.x * (c & 15);
|
|
src.y = font[size].size.y * ((c & 240) >> 4);
|
|
SDL_BlitSurface (font[size].image, &src, gfx.screen, &dest);
|
|
dest.x += font[size].size.x;
|
|
}
|
|
|
|
font_lastsize = font[size].size;
|
|
};
|
|
|
|
|
|
void
|
|
font_gfxdraw (int x, int y, char *text, int size, int ypos)
|
|
{
|
|
int i,
|
|
c;
|
|
SDL_Rect src,
|
|
dest;
|
|
|
|
src.y = 0;
|
|
dest.w = src.w = font[size].size.x;
|
|
dest.h = src.h = font[size].size.y;
|
|
dest.x = x;
|
|
dest.y = y;
|
|
|
|
for (i = 0; text[i] != 0; i++) {
|
|
c = text[i];
|
|
src.x = font[size].size.x * (c & 15);
|
|
src.y = font[size].size.y * ((c & 240) >> 4);
|
|
gfx_blit (font[size].image, &src, gfx.screen, &dest, ypos);
|
|
dest.x += font[size].size.x;
|
|
}
|
|
|
|
font_lastsize = font[size].size;
|
|
};
|
|
|
|
|
|
|
|
void font_load () {
|
|
int i;
|
|
char filename[LEN_PATHFILENAME];
|
|
|
|
/* load the font */
|
|
for (i = 0; i < 3; i++) {
|
|
sprintf (filename, "%s/gfx/font%d.bmp", bman.datapath, i);
|
|
font[i].raw = SDL_LoadBMP (filename);
|
|
if (font[i].raw == NULL) {
|
|
printf ("Could not load font.\n");
|
|
exit (1);
|
|
}
|
|
SDL_SetColorKey (font[i].raw , SDL_SRCCOLORKEY, SDL_MapRGB (font[i].raw->format, 255, 255, 255));
|
|
font[i].image = SDL_DisplayFormat (font[i].raw);
|
|
SDL_SetColorKey (font[i].image , SDL_SRCCOLORKEY, SDL_MapRGB (font[i].image->format, 0,0,0));
|
|
font[i].size.x = font[i].raw->w / 16;
|
|
font[i].size.y = font[i].raw->h / 16;
|
|
}
|
|
};
|
|
|
|
|
|
void font_setcolor (unsigned char r, unsigned char g, unsigned char b, int size) {
|
|
SDL_FillRect (font[size].image, NULL, SDL_MapRGB (font[size].image->format, r,g,b));
|
|
SDL_BlitSurface (font[size].raw, NULL, font[size].image, NULL);
|
|
};
|
|
|
|
|
|
void font_free() {
|
|
int i;
|
|
|
|
for (i = 0; i < 3; i++) {
|
|
SDL_FreeSurface (font[i].image);
|
|
SDL_FreeSurface (font[i].raw);
|
|
font[i].image = NULL;
|
|
}
|
|
};
|
|
|
|
|
|
void font_drawbold (int x, int y, char *text, int size, int bold) {
|
|
font_draw (x - bold, y, text, size);
|
|
font_draw (x + bold, y, text, size);
|
|
font_draw (x, y - bold, text, size);
|
|
font_draw (x, y + bold, text, size);
|
|
};
|