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 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214
|
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_ttf.h>
#include <SDL2/SDL_image.h>
void Pushletter(SDL_Surface*lettre,TTF_Font *font,char *commande)
{
SDL_Color color = {0xff, 0xff, 0xff, 0xff};
lettre = TTF_RenderText_Solid(font,commande,color);
printf("alo!");
}
int main(int argc, char *argv[]) {
SDL_Window *fenetre;
SDL_Surface *screen, *text,*lettre;
SDL_Rect position, cur,TextPos;
SDL_Event ev;
TTF_Font *font;
int running = 1, cpt_com=0;
char commande[41]={""};
position.x=0;
position.y=0;
position.w=640;
position.h=455;
//Position initiale du curseur de saisie
cur.x=0;
cur.y=455;
cur.w=0;
cur.h=25;
TextPos.x=20;
TextPos.y=200;
TextPos.w=620;
TextPos.h=132;
char *SAMPLETEXT =
"Bienvenu à Agrabah cité de la magie noire\n"
"Fiction Interactive par Kitsune.\n"
"Histoire basée à partir de l'histoire de Disney.\n\n"
"Entrez \"continuer\" pour débuter la partie...";
char *letter="";
// init SDL/TTF
SDL_Init(SDL_INIT_VIDEO);
//Initialise le module de police
TTF_Init();
// Create GUI
fenetre = SDL_CreateWindow("Example", SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
640, 480, SDL_WINDOW_SHOWN);
SDL_Renderer *renderer = SDL_CreateRenderer( fenetre, -1, SDL_RENDERER_ACCELERATED);
SDL_Texture* texture = IMG_LoadTexture(renderer, "title.jpg");
// Open and set up font
font = TTF_OpenFont("cour.ttf", 22);
if(font == NULL) {
fprintf(stderr, "Error: Les police de caractères sont introuvables.\n");
return 0;
}
TTF_SetFontStyle(font, TTF_STYLE_NORMAL);
/*
SDL_Surface* image = IMG_Load("title.jpg");
if(!image)
{
printf("Erreur de chargement de l'image : %s",SDL_GetError());
return 0;
}*/
// Grab GUI surface
screen = SDL_GetWindowSurface(fenetre);
// Clear screen black
// SDL_FillRect(screen, NULL, 0);
/* SDL_BlitSurface(image, NULL, screen, &position);
SDL_FreeSurface(image);*/
// Draw some text to screen
SDL_Color color = {0xff, 0xff, 0xff, 0xff};
text = TTF_RenderText_Blended_Wrapped(font, SAMPLETEXT, color,620);
SDL_Texture* Message = SDL_CreateTextureFromSurface(renderer, text);
lettre = TTF_RenderText_Solid(font, commande, color);
SDL_Texture* lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
/* position.x=100;
position.y=300;
position.w=100;
position.h=100;*/
//On positionne le texte sur le rectangle "position"
//SDL_BlitSurface(text, NULL, screen, &position);
while(running) { // Main loop
SDL_RenderClear(renderer);
SDL_RenderCopy(renderer, texture, NULL, &position);
SDL_RenderCopy(renderer, Message, NULL, &TextPos);
SDL_RenderCopy(renderer, lettre_text, NULL, &cur);
while(SDL_PollEvent(&ev)) {
switch(ev.type){
case SDL_QUIT:
running = 0;
break;
case SDL_KEYDOWN:
if(ev.key.keysym.sym == SDLK_BACKSPACE){
if(cpt_com!=0){
cur.w-=14;
cpt_com--;
commande[cpt_com]='\0';
lettre = TTF_RenderText_Blended(font, commande, color);
lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
SDL_Log("Vous venez d'effacer une lettre! %s",commande);
SDL_FillRect(screen, &cur, 0);}
}
else if(ev.key.keysym.sym == SDLK_a){
if(cpt_com<40){
SDL_Log("Vous venez de presser la lettre A!");
commande[cpt_com]='a';
//lettre = TTF_RenderText_Solid(font, commande, color);
Pushletter(lettre,font,commande);
lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
cur.w+=14;
cpt_com++;
}
else
SDL_Log("Vous avez atteinds le nombre de lettres maximum!");
}
else if(ev.key.keysym.sym == SDLK_b){
if(cpt_com<40){
SDL_Log("Vous venez de presser la lettre B!");
commande[cpt_com]='b';
lettre = TTF_RenderText_Solid(font, commande, color);
lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
cur.w+=14;
cpt_com++;
}
else
SDL_Log("Vous avez atteinds le nombre de lettres maximum!");
}
else if(ev.key.keysym.sym == SDLK_c){
if(cpt_com<40){
SDL_Log("Vous venez de presser la lettre C!");
commande[cpt_com]='c';
lettre = TTF_RenderText_Solid(font, commande, color);
lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
cur.w+=14;
cpt_com++;
}
else
SDL_Log("Vous avez atteinds le nombre de lettres maximum!");
}
else if(ev.key.keysym.sym == SDLK_d){
if(cpt_com<40){
SDL_Log("Vous venez de presser la lettre D!");
commande[cpt_com]='d';
lettre = TTF_RenderText_Solid(font, commande, color);
lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
cur.w+=14;
cpt_com++;
}
else
SDL_Log("Vous avez atteinds le nombre de lettres maximum!");
}
else if(ev.key.keysym.sym == SDLK_e){
if(cpt_com<40){
SDL_Log("Vous venez de presser la lettre E!");
commande[cpt_com]='e';
lettre = TTF_RenderText_Solid(font, commande, color);
lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
cur.w+=14;
cpt_com++;
}
else
SDL_Log("Vous avez atteinds le nombre de lettres maximum!");
}
else if(ev.key.keysym.sym == SDLK_f){
if(cpt_com<40){
SDL_Log("Vous venez de presser la lettre F!");
commande[cpt_com]='f';
lettre = TTF_RenderText_Solid(font, commande, color);
lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
cur.w+=14;
cpt_com++;
}
else
SDL_Log("Vous avez atteinds le nombre de lettres maximum!");
}
else if(ev.key.keysym.sym == SDLK_g){
if(cpt_com<40){
SDL_Log("Vous venez de presser la lettre G!");
commande[cpt_com]='g';
lettre = TTF_RenderText_Solid(font, commande, color);
lettre_text = SDL_CreateTextureFromSurface(renderer, lettre);
cur.w+=14;
cpt_com++;
}
else
SDL_Log("Vous avez atteinds le nombre de lettres maximum!");
}
break;
}
}
SDL_RenderPresent(renderer);
//SDL_UpdateWindowSurface(fenetre); // Refresh window
SDL_Delay(20); // Delay loop
}
;
// Destroy resources and quit
SDL_DestroyTexture(Message);
SDL_FreeSurface(text);
TTF_CloseFont(font);
TTF_Quit();
SDL_FreeSurface(text);
SDL_DestroyWindow(fenetre);
SDL_Quit();
return 0;
} |
Partager