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
| #include <stdlib.h> /* alors voici ma logique mais jene sais pas si elle est bonne */
#include <stdio.h>
#include <SDL/SDL.h>
#include <string.h>
#include <sys/types.h>
#include <dirent.h>
void pause(int nombrePhoto);
void chargePhoto(int numeroPhoto);
int nombrePhoto = 8; /* longueur du tableau */
char *tableauPhoto[8] = {""};/* ={0}; //={"soleil.bmp","coucher.bmp","devant-maison.bmp","fleur.bmp","001.bmp"}; */
int i = 0, j = 0;
char repertoire[] = "nantes-bmp/";
char maPhoto[20] = "";
int main(int argc, char *argv[])
{
struct dirent *lecture;
DIR *rep;
rep = opendir("nantes-bmp");
while ((lecture = readdir(rep))) {
if (++i > 4)
j++;
tableauPhoto[j] = lecture->d_name;
}
closedir(rep);
nombrePhoto = j+1;
// printf(" %ld \n", nombrePhoto);
chargePhoto(0);
pause(nombrePhoto);
SDL_Quit();
return EXIT_SUCCESS;
}
void chargePhoto(int numeroPhoto)
{
SDL_Surface *ecran = NULL, *imageDeFond = NULL;
int width, height;
SDL_Rect positionFond;
positionFond.x = 0;
positionFond.y = 0;
SDL_Init(SDL_INIT_VIDEO);
/* maphoto = "fleur.bmp";
* la je veux concatener repertoire avec les valeur qui sont dans tableauPhoto
* imageDeFond = SDL_LoadBMP("nantes-bmp/003.bmp"); //tableauPhoto[numeroPhoto]); */
width = imageDeFond->w;
height = imageDeFond->h;
ecran = SDL_SetVideoMode(width, height, 32, SDL_HWSURFACE);
SDL_WM_SetCaption("nantes-bmp/003.bmp", NULL);/* tableauPhoto[numeroPhoto], NULL); */
/* Chargement d'une image Bitmap dans une surface */
/* On blitte par-dessus l'ecran */
SDL_BlitSurface(imageDeFond, NULL, ecran, &positionFond);
SDL_Flip(ecran);
SDL_FreeSurface(imageDeFond); /* On libere la surface */
}
void pause(int nombrePhoto)
{
int continuer = 1;
int increment=0;
SDL_Event event;
while (continuer) {
SDL_WaitEvent(&event);
switch(event.type) {
case SDL_QUIT:
continuer = 0;
break;
case SDL_KEYDOWN: // Si appui d'une touche
switch(event.key.keysym.sym) {
case SDLK_RIGHT: // Fleche droite
if (increment < (nombrePhoto - 1))
chargePhoto(++increment);
break;
case SDLK_LEFT: // Fleche droite
if (increment > 0)
chargePhoto(--increment);
break;
}
}
}
} |
Partager