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
|
Uint32 colorRGB(SDL_Surface *surface, Uint8 R, Uint8 G, Uint8 B)
{
return (SDL_MapRGB(surface->format, R, G, B));
}
void drawText(SDL_Surface* surface, char* string,
char* fontname, int size, int x, int y,
Uint32 pixel, int indent)
{
int w, h;
Uint8 fR, fG, fB;
SDL_GetRGB(pixel, surface->format, &fR, &fG, &fB);
TTF_Font* font = TTF_OpenFont(fontname, size);
if(font != NULL)
{
SDL_Color foregroundColor = { fR, fG, fB };
TTF_SizeText(font, string, &w, &h);
SDL_Surface* textSurface = TTF_RenderText_Solid(font, string, foregroundColor);
if(indent/3 == 0) y -= h/2;
else if(indent/3 == 2) y -= h;
if(indent%3 == 1) x -= w/2;
else if(indent%3 == 2) x -= w;
SDL_Rect textLocation = { x, y, 0, 0 };
SDL_BlitSurface(textSurface, NULL, surface, &textLocation);
SDL_FreeSurface(textSurface);
TTF_CloseFont(font);
}
}
|