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
|
#include ...
#define EcranLarg 800
#define EcranHaut 600
#define couleurTexteVert (SDL_Color){0,255,0,0}
#define couleurTexteRouge (SDL_Color){250,0,0,0}
void initSDL(SDL_Surface **ecran)
{ ... }
void EcrireTexte(SDL_Surface *ecran, TTF_Font *police,char *mot, int positionY)
{
SDL_Surface *texte=TTF_RenderText_Blended(police, mot, couleurTexteVert);
SDL_Rect positionTexte= {100, positionY, 0, 0};//centrage du mot dans la zone de bouton
SDL_BlitSurface(texte, NULL, ecran, &positionTexte);
SDL_Flip(ecran);
SDL_FreeSurface(texte);
}
void EcrireTexteRacourci(SDL_Surface *ecran, TTF_Font *police,char *mot, int positionY)
{
SDL_Rect positionTexte= {100, positionY, 0, 0};//centrage du mot dans la zone de bouton
SDL_BlitSurface(TTF_RenderText_Blended(police, mot, couleurTexteVert), NULL, ecran, &positionTexte);
SDL_Flip(ecran);
}
void EcrireTexteDecompose(SDL_Surface *ecran, TTF_Font *police,char *motDebut,char *motFin, int positionY)
{
SDL_Surface *texteDebut=TTF_RenderText_Blended(police, motDebut, couleurTexteVert);
SDL_Surface *texteFin=TTF_RenderText_Blended(police, motFin, couleurTexteRouge);
SDL_Rect positionTexteDebut= {400, positionY, 0, 0};//centrage du mot dans la zone de bouton
SDL_Rect positionTexteFin= {400, positionY, 0, 0};//centrage du mot dans la zone de bouton
if(strcmp(motDebut,"")==0)
positionTexteFin.x= positionTexteDebut.x;
else
positionTexteFin.x= positionTexteDebut.x+texteDebut->w;//centrage du mot dans la zone de bouton
SDL_BlitSurface(texteDebut, NULL, ecran, &positionTexteDebut);
SDL_BlitSurface(texteFin, NULL, ecran, &positionTexteFin);
SDL_Flip(ecran);
SDL_FreeSurface(texteDebut);
SDL_FreeSurface(texteFin);
}
void EcrireTexteEntierCaractere(SDL_Surface *ecran, TTF_Font *police,int NbMax, int positionY)
{
int i;
char texte[10];
SDL_Surface *texteAAfficher=NULL;
SDL_Rect positionTexte= {400, positionY, 0, 0};//centrage du mot dans la zone de bouton
for (i=0; i<10; i++)
{
sprintf(texte, "%d", i);
texteAAfficher=TTF_RenderText_Blended(police, texte, couleurTexteVert);
positionTexte.x=positionTexte.x+texteAAfficher->w;
SDL_BlitSurface(texteAAfficher, NULL, ecran, &positionTexte);
}
SDL_Flip(ecran);
SDL_FreeSurface(texteAAfficher);
}
int main(int argc, char **argv)
{
SDL_Surface *ecran=NULL;
TTF_Font *police = NULL;//declaration de la police d'ecriture
initSDL(&ecran);
police = TTF_OpenFont("times.ttf", 30);//chargement de la police d'ecriture et de la taille
if(police == NULL)
{
fprintf(stderr, "Erreur de police");
}
EcrireTexte(ecran, police, "Bonjour",100);//chargement du style et de la taille d'ecriture
EcrireTexteRacourci(ecran, police, "Salut",200);//chargement du style et de la taille d'ecriture
EcrireTexteDecompose(ecran, police, "Bien","tot",100);//chargement du style et de la taille d'ecriture
EcrireTexteDecompose(ecran, police, "","Bravo",200);//chargement du style et de la taille d'ecriture
EcrireTexteEntierCaractere(ecran, police,10,300);
SDL_Delay(3000);
TTF_CloseFont(police); // Fermeture de la police, doit être fermée avant TTF_Quit()
TTF_Quit();
SDL_Quit();
return EXIT_SUCCESS;//on quitte le jeu avec succes
} |
Partager