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 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106
| /* --------------------------------------------------------------------------
Create_text
--------------------------------------------------------------------------
Fonction privee de creation de texte.
--------------------------------------------------------------------------
E: Pointeur de la surface sur laquelle rendre le texte.
E: Position X du texte.
E: Position Y du texte.
E: Taille de la police.
E: Couleur de la police (a creer avec la fonction SDL_MapRGB).
E: Nom de la police a utiliser.
E: Texte a rendre.
S:
-------------------------------------------------------------------------- */
static void Create_text (SDL_Surface * p_screen,
short x, short y,
short font_size, Uint32 i_color,
const char * p_font_face, const char * p_message)
{
TTF_Font * p_font = NULL;
SDL_Surface * s_text = NULL;
SDL_Rect rect_dest;
SDL_Color color;
/* ----- Initialisation de SDL_ttf ----- */
if (TTF_Init () < 0)
{
ERROR_MSG (
"draw_text",
"Impossible d'initialiser SDL_ttf !\n"
);
return;
}
/* ----- */
/* ----- Chargement de toutes les donnees necessaires ----- */
/* Recuperation des informations de couleurs. */
color.r = (i_color & SDL_MapRGB (p_screen->format, 255, 0, 0)) >> 16;
color.g = (i_color & SDL_MapRGB (p_screen->format, 0, 255, 0)) >> 8;
color.b = (i_color & SDL_MapRGB (p_screen->format, 0, 0, 255));
/* Chargement de la police */
p_font = TTF_OpenFont (p_font_face, font_size);
if (! p_font)
{
ERROR_MSG (
"draw_text",
"Impossible de charger la police !\n"
);
return;
}
/* ----- */
/* ----- Rendu du texte ----- */
s_text = TTF_RenderText_Solid (p_font, p_message, color);
/* Mise en place du message sur la surface de jeu */
if (s_text == NULL)
{
ERROR_MSG (
"draw_text",
"Impossible de rendre le texte !\n"
);
}
else if (s_text != NULL)
{
rect_dest.x = x;
rect_dest.y = y;
rect_dest.w = s_text->w;
rect_dest.h = s_text->h;
/* On blit la surface a l'ecran */
SDL_BlitSurface (s_text, NULL, p_screen, & rect_dest);
SDL_FreeSurface (s_text);
}
/* Fermeture de la police */
TTF_CloseFont (p_font);
/* ----- */
return;
} |
Partager