Partage
  • Partager sur Facebook
  • Partager sur Twitter

Colorier une surface

    29 février 2020 à 19:12:51

    Bonjour tout le monde,

    Comme l'indique le titre j'essaye de colorier une surface avec putpixel mais ça ne marche pas, voici le code (attention, il est assez copieux) :

    #include <stdio.h>
    #include <stdlib.h>
    #include <stdbool.h>
    #include <windows.h>
    #include <inttypes.h>
    #include <io.h>
    #include <SDL/SDL.h>
    #include <SDL/SDL_ttf.h>
    #include <SDL/SDL_image.h>
    #include <SDL/SDL_rotozoom.h>
    #include <SDL/SDL_framerate.h>
    #include <SDL/SDL_gfxPrimitives.h>
    #include "function.h"
    #include "barre_des_taches.h"
    #include "saisie_des_touches.h"
    #include "creation_image.h"
    #include "test.h"
    #include "boutons.h"
    
    int main ( int argc, char** argv )
    {
        if ( SDL_Init( SDL_INIT_VIDEO ) < 0 )
        {
            printf( "Unable to init SDL: %s\n", SDL_GetError() );
            return 1;
        }
        if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) == -1 )
        {
            fprintf(stderr,"Erreur lors de l'initialisation de la SDL\n");
            return -1;
        }
        Detect detect1;
        TTF_Init();
        if(TTF_Init()==-1)
        {
            fprintf(stderr, "Erreur d'initialisation de TTF_Init : %s\n", TTF_GetError());
            exit(EXIT_FAILURE);
        }
    
        IMG_Init(IMG_INIT_PNG);
        Uint8 *key = SDL_GetKeyState( NULL );
    
        //atexit(SDL_Quit);
    
        const SDL_VideoInfo*resolution=NULL;
        resolution=SDL_GetVideoInfo();
        int W=resolution->current_w;
        int H=resolution->current_h;
        putenv("SDL_VIDEO_WINDOW_POS=0,26");
        SDL_Surface* screen = SDL_SetVideoMode(W, H-50, 32, SDL_HWSURFACE|SDL_DOUBLEBUF|SDL_RESIZABLE);
        if ( !screen )
        {
            printf("Unable to set 640x480 video: %s\n", SDL_GetError());
            return 1;
        }
        SDL_WM_SetCaption("Editeur 2D",NULL);
        SDL_Surface *texte=NULL;
        SDL_Surface *texte2=NULL;
        SDL_Surface *texte3=NULL;
        SDL_Surface *texte4=NULL;
        SDL_Surface *texte5=NULL;
        TTF_Font *Texte=NULL;
        Texte=TTF_OpenFont("police.ttf",20);
        SDL_Color noir={0,0,0};
        SDL_Color blanc={255,255,255};
    
        bool done = false;
        char chaine[max_length]="";
        char chaine2[max_length]="";
        char chaine3[max_length]="";
        char chaine4[max_length]="";
        char chaine5[max_length]="";
        char chaine6[max_length]="";
        char char_name_image[max_length]="";
        char char_name_file[max_length]="";
        detect1.value=0;
        detect1.tag=0;
        detect1.check=malloc(nb_window*sizeof(int));
        detect1.check[0]=0;
        detect1.check[1]=0;
        detect1.check[2]=0;
        detect1.check[3]=0;
        detect1.check[4]=0;
        detect1.check[5]=0;
        SDL_Rect curseur={0,0,1,1};
        SDL_Surface *window=NULL,*window2=NULL,*roue_chromatique=NULL,*barre=NULL;
        SDL_Surface**bouton_fermer=malloc(sizeof(SDL_Surface)*nb_window);////////////////
        window=SDL_LoadBMP("images/fenetre.bmp");
        window2=SDL_LoadBMP("images/fenetre2.bmp");
        roue_chromatique=IMG_Load("images/roue_chromatique.bmp");
        barre=SDL_LoadBMP("images/barre.bmp");
        for(int i=0;i<nb_window;i++)
        {
            bouton_fermer[i]=SDL_LoadBMP("images/bouton_fermer.bmp");
        }
    
        SDL_Rect fenetre={screen->w/2-500/2,screen->h/2-200/2,500,200};
        SDL_Rect fenetre2={screen->w/2-window2->w/2,screen->h/2-200/2,500,200};
    
        TTF_Font *ttf_texte=NULL;
        ttf_texte=TTF_OpenFont("police.ttf",20);
    
        SDL_Color gris_clair={235,235,235};
        SDL_Surface *Donner_nom_projet=NULL;
        Donner_nom_projet=TTF_RenderText_Shaded(ttf_texte,"Donner le nom du projet",noir,gris_clair);
        SDL_Surface *Donner_nom_tileset=NULL;
        Donner_nom_tileset=TTF_RenderText_Shaded(ttf_texte,"Donner le nom du dossier où enregistrer le tileset",noir,gris_clair);
        SDL_Surface *Donner_w_tileset=NULL;
        Donner_w_tileset=TTF_RenderText_Shaded(ttf_texte,"Donner le nombre de tiles en largeur",noir,gris_clair);
        SDL_Surface *Donner_h_tileset=NULL;
        Donner_h_tileset=TTF_RenderText_Shaded(ttf_texte,"Donner le nombre de tiles en hauteur",noir,gris_clair);
        SDL_Surface *Donner_w_tile=NULL;
        Donner_w_tile=TTF_RenderText_Shaded(ttf_texte,"Donner la largeur des tiles",noir,gris_clair);
        SDL_Surface *Donner_h_tile=NULL;
        Donner_h_tile=TTF_RenderText_Shaded(ttf_texte,"Donner la hauteur des tiles",noir,gris_clair);
        SDL_Surface *nom_a_charger=NULL;
        nom_a_charger=TTF_RenderText_Shaded(ttf_texte,"Donner le nom du projet à ouvrir",noir,gris_clair);
        SDL_Surface *tileset=NULL;
        SDL_Surface *largeur_tilemap=NULL;
        largeur_tilemap=TTF_RenderText_Shaded(ttf_texte,"Donner le nombre de tiles en largeur",noir,gris_clair);
        SDL_Surface *hauteur_tilemap=NULL;
        hauteur_tilemap=TTF_RenderText_Shaded(ttf_texte,"Donner le nombre de tiles en hauteur",noir,gris_clair);
        SDL_Surface *Donner_nom_image=NULL;
        Donner_nom_image=TTF_RenderText_Shaded(ttf_texte,"Donner le nom de l'image",noir,gris_clair);
        SDL_Surface *Donner_w_image=NULL;
        Donner_w_image=TTF_RenderText_Shaded(ttf_texte,"Donner la largeur de l'image",noir,gris_clair);
        SDL_Surface *Donner_h_image=NULL;
        Donner_h_image=TTF_RenderText_Shaded(ttf_texte,"Donner la hauteur de l'image",noir,gris_clair);
        SDL_Surface *Donner_nom_dossier=NULL;
        Donner_nom_dossier=TTF_RenderText_Shaded(ttf_texte,"Donner le nom du dossier où enregistrer l'image",noir,gris_clair);
        SDL_Surface *Donner_nom_tilemap=NULL;
        Donner_nom_tilemap=TTF_RenderText_Shaded(ttf_texte,"Donner le nom du dossier où enregistrer la tilemap",noir,gris_clair);
    
        SDL_Rect BARRE_EDITION={fenetre.x+fenetre.w/2-200/2,fenetre.y+fenetre.h/2-20/2,200,20};
        SDL_Rect CHAINE={BARRE_EDITION.x,BARRE_EDITION.y,100,20};
        SDL_Rect NOM_PROJET={BARRE_EDITION.x,BARRE_EDITION.y-BARRE_EDITION.h,Donner_nom_projet->w,Donner_nom_projet->h};
        SDL_Rect BARRE_EDITION2={fenetre.x+fenetre.w/2-200/2,fenetre.y+40+fenetre.h/2-20/2,200,20};
        SDL_Rect CHAINE2={BARRE_EDITION2.x,BARRE_EDITION2.y,100,20};
        SDL_Rect NOM_PROJET2={BARRE_EDITION2.x,BARRE_EDITION2.y-BARRE_EDITION2.h,Donner_w_tileset->w,Donner_w_tileset->h}; // texte
        SDL_Rect BARRE_EDITION3={fenetre.x+fenetre.w/2-200/2,fenetre.y+80+fenetre.h/2-20/2,200,20};
        SDL_Rect CHAINE3={BARRE_EDITION3.x,BARRE_EDITION3.y,100,20};
        SDL_Rect NOM_PROJET3={BARRE_EDITION3.x,BARRE_EDITION3.y-BARRE_EDITION3.h,Donner_h_tileset->w,Donner_h_tileset->h};
        SDL_Rect BARRE_EDITION4={fenetre.x+fenetre.w/2-200/2,fenetre.y+120+fenetre.h/2-20/2,200,20};
        SDL_Rect CHAINE4={BARRE_EDITION4.x,BARRE_EDITION4.y,100,20};
        SDL_Rect NOM_PROJET4={BARRE_EDITION4.x,BARRE_EDITION4.y-BARRE_EDITION4.h,Donner_w_tile->w,Donner_w_tile->h};
        SDL_Rect BARRE_EDITION5={fenetre.x+fenetre.w/2-200/2,fenetre.y+160+fenetre.h/2-20/2,200,20};
        SDL_Rect CHAINE5={BARRE_EDITION5.x,BARRE_EDITION5.y,100,20};
        SDL_Rect NOM_PROJET5={BARRE_EDITION5.x,BARRE_EDITION5.y-BARRE_EDITION5.h,Donner_h_tile->w,Donner_h_tile->h};
        SDL_Rect BARRE={810,505,40,20};
        SDL_Rect VISU_BARRE={0,0,40,20};
    
        SDL_SetColorKey(roue_chromatique,SDL_SRCCOLORKEY,SDL_MapRGB(roue_chromatique->format,255,255,255));
        int cnt=-1;
        int cnt2=-1;
        int cnt3=-1;
        int cnt4=-1;
        int cnt5=-1;
        int champ1_selected=1;
        int champ2_selected=0;
        int champ3_selected=0;
        int champ4_selected=0;
        int champ5_selected=0;
        int cnt_ani=0;
        int nbcolonnes=0;
        int tiles_hauteur=0;
        int nblignes=0;
        int tiles_largeur=0;
        int w_image=0;
        int h_image=0;
        int nb_tiles_largeur=0;
        int nb_tiles_hauteur=0;
        FILE* fichier = NULL;
        unsigned int ** tableau2d = malloc(nb_tiles_hauteur*sizeof(int));
        /*Image *sprite1;
        sprite1=(int)malloc(10*sizeof(int));
        sprite1[0].x=22;
        sprite1[0].y=10;
        sprite1[0].color=SDL_MapRGB(screen->format,0,255,255);
        printf("\nx:%d",sprite1[0].x);
        printf("\ny:%d",sprite1[0].y);
        printf("\ncolor:%lu",(unsigned long)sprite1[0].color);*/
    
        SDL_Rect ROUE_CHROMATIQUE={screen->w/2-roue_chromatique->w/2,screen->h/2-roue_chromatique->h/2,roue_chromatique->w,roue_chromatique->h};
    
        Image pipette;
    
        //SDL_Surface*rotation=NULL;
        Cercle cercle1;
        SDL_Rect*BOUTON_FERMER=(SDL_Rect*)malloc(nb_window*sizeof(SDL_Rect));
    
        BOUTON_FERMER[0].x=fenetre.x+fenetre.w-bouton_fermer[0]->w/2-3;
        BOUTON_FERMER[0].y=fenetre.y+3;
        BOUTON_FERMER[0].w=bouton_fermer[0]->w;
        BOUTON_FERMER[0].h=bouton_fermer[0]->h;
    
        SDL_Rect*ANIM_FERMER=(SDL_Rect*)malloc(nb_window*sizeof(SDL_Rect));
    
        for(int i=0;i<nb_window;i++)
        {
            ANIM_FERMER[i].x=0;
            ANIM_FERMER[i].y=0;
            ANIM_FERMER[i].w=bouton_fermer[i]->w/2;
            ANIM_FERMER[i].h=bouton_fermer[i]->h;
        }
    
        SDL_Surface *color_window=NULL;
        color_window=SDL_LoadBMP("images/fenetre_couleur.bmp");
        SDL_Rect COLOR={screen->w-color_window->w-1,38,color_window->w,color_window->h};
    
        BOUTON_FERMER[1].x=fenetre2.x+fenetre2.w-bouton_fermer[1]->w/2-3;
        BOUTON_FERMER[1].y=fenetre2.y+3;
        BOUTON_FERMER[1].w=bouton_fermer[1]->w;
        BOUTON_FERMER[1].h=bouton_fermer[1]->h;
    
        pipette.color=SDL_MapRGB(screen->format,255,255,255);
    
        BOUTON_FERMER[2].x=fenetre.x+fenetre.w-bouton_fermer[0]->w/2-3;
        BOUTON_FERMER[2].y=fenetre.y+3;
        BOUTON_FERMER[2].w=bouton_fermer[2]->w;
        BOUTON_FERMER[2].h=bouton_fermer[2]->h;
    
        SDL_Surface*cadre_couleur=SDL_LoadBMP("images/cadre_couleur.bmp");
        SDL_Rect CADRE_COULEUR={COLOR.x+COLOR.w-40,99,cadre_couleur->w,cadre_couleur->h};
    
        int nb_image=0;
        int nb_tileset=0;
    
        load_image *tab_image=malloc(1*sizeof(load_image));
        load_image *tab_image2=malloc(1*sizeof(load_image));
    
        while (!done)
        {
    
            ROUE_CHROMATIQUE.x=COLOR.x+3;
            ROUE_CHROMATIQUE.y=COLOR.y+3;
            cercle1.x=ROUE_CHROMATIQUE.x+ROUE_CHROMATIQUE.w/2;
            cercle1.y=ROUE_CHROMATIQUE.y+ROUE_CHROMATIQUE.h/2;
            cercle1.rayon=ROUE_CHROMATIQUE.w/2;
            SDL_FillRect(screen, 0, SDL_MapRGB(screen->format, 200, 200, 200));
            freopen("CON", "w", stdout);
            freopen("CON", "r", stdin);
            freopen("CON", "w", stderr);
            SDL_Event event;
            SDL_PollEvent(&event);
    
            switch (event.type)
            {
            case SDL_QUIT:
                done = true;
                break;
    
            case SDL_MOUSEBUTTONDOWN:
                if (event.button.button == SDL_BUTTON_LEFT)
                    detect1.value = 1;
                    break;
            case SDL_MOUSEBUTTONUP:
                if (event.button.button == SDL_BUTTON_LEFT)
                    detect1.value = 0;
                    break;
    
            case SDL_MOUSEMOTION:
                curseur.x=event.motion.x;
                curseur.y=event.motion.y;
                break;
    
            }
    
            SDL_Surface *Tableau_de_surface[5]={window,screen,texte,Donner_nom_projet,bouton_fermer[0]};
            SDL_Rect Tableau_de_rect[7]={fenetre,BARRE_EDITION,CHAINE,NOM_PROJET,curseur,BOUTON_FERMER[0],ANIM_FERMER[0]};
            Bouton1(&detect1,key,chaine,Texte,Tableau_de_surface,Tableau_de_rect);
    
            pipette.x=event.motion.x;
            pipette.y=event.motion.y;
            SDL_BlitSurface(color_window,NULL,screen,&COLOR); // fond de la palette de couleurs
            SDL_BlitSurface(roue_chromatique,NULL,screen,&ROUE_CHROMATIQUE);
            SDL_BlitSurface(cadre_couleur,NULL,screen,&CADRE_COULEUR);
            if((CollisionCercle(event.motion.x,event.motion.y,&cercle1))&&(detect1.value==1))
            {
                pipette.color=getpixel(screen,pipette.x,pipette.y);
                SDL_LockSurface(color_window);
                //putpixel(color_window,2,2,pipette.color);
                SDL_UnlockSurface(color_window);
                //SDL_SaveBMP(color_window,"test.bmp");
            }
            for(int i=0;i<8;i++)
            {
                for(int j=0;j<8;j++)
                {
                    putpixel(screen,COLOR.x+COLOR.w-31-j,101+i,(unsigned long)pipette.color);
                }
            }
    
            if(detect1.check[1]==1)
            {
                SDL_BlitSurface(window2,NULL,screen,&fenetre2); // fond des zones de textes
                anim(0,20,50,100,cnt_ani,VISU_BARRE);
                if(Collision(&curseur,&BARRE_EDITION)&&detect1.value==1)
                {
                    Champ(1,0,0,0,505,&champ1_selected,&champ2_selected,&champ3_selected,&champ4_selected,&BARRE);
                }
                if(Collision(&curseur,&BARRE_EDITION2)&&detect1.value==1)
                {
                    Champ(0,1,0,0,545,&champ1_selected,&champ2_selected,&champ3_selected,&champ4_selected,&BARRE);
                }
                if(Collision(&curseur,&BARRE_EDITION3)&&detect1.value==1)
                {
                    Champ(0,0,1,0,585,&champ1_selected,&champ2_selected,&champ3_selected,&champ4_selected,&BARRE);
                }
                if(Collision(&curseur,&BARRE_EDITION4)&&detect1.value==1)
                {
                    Champ(0,0,0,1,625,&champ1_selected,&champ2_selected,&champ3_selected,&champ4_selected,&BARRE);
                }
                champ_chain(&champ1_selected,cnt,max_length,key,chaine);
                champ_chain(&champ2_selected,cnt2,max_length,key,chaine2);
                champ_chain(&champ3_selected,cnt3,max_length,key,chaine3);
                champ_chain(&champ4_selected,cnt4,max_length,key,chaine4);
                text(texte,Texte,chaine,screen,BARRE_EDITION,CHAINE,Donner_nom_image,NOM_PROJET);
                text(texte2,Texte,chaine2,screen,BARRE_EDITION2,CHAINE2,Donner_w_image,NOM_PROJET2);
                text(texte3,Texte,chaine3,screen,BARRE_EDITION3,CHAINE3,Donner_h_image,NOM_PROJET3);
                text(texte4,Texte,chaine4,screen,BARRE_EDITION4,CHAINE4,Donner_nom_dossier,NOM_PROJET4);
                if(Collision(&curseur,&BOUTON_FERMER[1]))
                {
                    ANIM_FERMER[1].x=40;
                    if(detect1.value==1)
                    {
                        detect1.check[1]=0;
                        cnt=0;
                        strcpy(chaine,"");
                        strcpy(chaine2,"");
                        strcpy(chaine3,"");
                        strcpy(chaine4,"");
                        cnt=0;
                        cnt2=0;
                        cnt3=0;
                        cnt4=0;
                        Champ(1,0,0,0,505,&champ1_selected,&champ2_selected,&champ3_selected,&champ4_selected,&BARRE);
                    }
                }
                else
                {
                    ANIM_FERMER[1].x=0;
                }
                SDL_BlitSurface(bouton_fermer[1],&ANIM_FERMER[1],screen,&BOUTON_FERMER[1]); // bouton pour quitter
                SDL_BlitSurface(barre,&VISU_BARRE,screen,&BARRE);
                if(key[SDLK_RETURN])
                {
                    strcat(char_name_image,chaine);
                    strcat(char_name_file,chaine4);
                    w_image=atoi(chaine2);
                    h_image=atoi(chaine3);
                    tab_image[nb_image]=create_image(screen,w_image,h_image,char_name_image,char_name_file,tab_image[nb_image]);
                    nb_image+=1;
                    tab_image=(load_image*)realloc(tab_image,nb_image*sizeof(load_image));
                    detect1.check[1]=0;
                    strcpy(chaine,"");
                    strcpy(chaine2,"");
                    strcpy(chaine3,"");
                    strcpy(chaine4,"");
                    strcpy(char_name_image,"");
                    strcpy(char_name_file,"");
                    cnt=0;
                    cnt2=0;
                    cnt3=0;
                    Champ(1,0,0,0,505,&champ1_selected,&champ2_selected,&champ3_selected,&champ4_selected,&BARRE);
                    key[SDLK_RETURN]=0;
                }
            }
            for(int i=0;i<nb_image;i++)
            {
                if(tab_image[i].check==1)
                {
                    charge_image(screen,tab_image[i].path);
                }
            }

    Ces fichiers.h :

    #ifndef BOUTONS_H_INCLUDED
    #define BOUTONS_H_INCLUDED
    
    void Bouton1(Detect* detect,Uint8 *key,char chaine[max_length],TTF_Font *Texte,SDL_Surface* surface_table[5],SDL_Rect rect_table[7])
    {
        int cnt=-1;
        Texte=TTF_OpenFont("police.ttf",20);
        SDL_Color noir={0,0,0};
        SDL_Color blanc={255,255,255};
        if(detect->check[0]==1)
        {
            SDL_BlitSurface(surface_table[0],NULL,surface_table[1],&rect_table[0]);
            if(cnt<max_length)
            {
                if(touches(key,chaine))
                {
                    cnt+=1;
                }
            }
            surface_table[2]=TTF_RenderText_Shaded(Texte,chaine,noir,blanc);
            SDL_FillRect(surface_table[1],&rect_table[1],SDL_MapRGB(surface_table[1]->format,255,255,255));
            SDL_BlitSurface(surface_table[2],NULL,surface_table[1],&rect_table[2]);
            SDL_BlitSurface(surface_table[3],NULL,surface_table[1],&rect_table[3]);
            char cmd1[255]="cd projects & md ";
            if(Collision(&rect_table[4],&rect_table[5]))
            {
                rect_table[6].x=40;
                if(detect->value==1)
                {
                    detect->check[0]=0;
                    strcpy(cmd1,"");
                    strcpy(chaine,"");
                    cnt=0;
                }
            }
            else
            {
                rect_table[6].x=0;
            }
            SDL_BlitSurface(surface_table[4],&rect_table[6],surface_table[1],&rect_table[5]);
            if(key[SDLK_BACKSPACE])
            {
                strcpy(chaine,"");
                cnt=0;
            }
            if(key[SDLK_RETURN])
            {
                detect->check[0]=0;
                strcat(cmd1,chaine);
                system(cmd1);
                strcpy(cmd1,"");
                strcpy(chaine,"");
                cnt=0;
            }
        }
        TTF_CloseFont(Texte);
    }
    
    void Champ(int a,int b,int c,int d,int e,int *champ1,int *champ2,int *champ3,int *champ4,SDL_Rect *rect)
    {
        *champ1=a;
        *champ2=b;
        *champ3=c;
        *champ4=d;
        rect->y=e;
    }
    
    void Champ2(int a,int b,int c,int d,int e,int f,int *champ1,int *champ2,int *champ3,int *champ4,int *champ5,SDL_Rect *rect)
    {
        *champ1=a;
        *champ2=b;
        *champ3=c;
        *champ4=d;
        *champ5=e;
        rect->y=f;
    }
    
    void Champ3(int a,int b,int c,int d,int *champ1,int *champ2,int *champ3,SDL_Rect *rect)
    {
        *champ1=a;
        *champ2=b;
        *champ3=c;
        rect->y=d;
    }
    
    void anim(int a,int b,int c,int d,int cnt,SDL_Rect rect)
    {
        if(cnt>a && cnt<=c)
        {
            rect.y=b;
        }
        if(cnt>c && cnt<=d)
        {
            rect.y=a;
        }
        if(cnt>d)
        {
            cnt=a;
        }
        cnt++;
    }
    
    void champ_chain(int *champ,int cnt,int nb,Uint8 *key,char chaine[max_length])
    {
        if(*champ==1)
        {
            if(cnt<nb)
            {
                if(touches(key,chaine))
                {
                    cnt+=1;
                }
            }
            if(key[SDLK_BACKSPACE])
            {
                strcpy(chaine,"");
                cnt=0;
            }
        }
    }
    
    void text(SDL_Surface *texte,TTF_Font *Texte,char chaine[max_length],SDL_Surface *screen,SDL_Rect rect,SDL_Rect rect2,SDL_Surface *surface2,SDL_Rect rect3)
    {
        SDL_Color noir={0,0,0};
        SDL_Color blanc={255,255,255};
        texte=TTF_RenderText_Shaded(Texte,chaine,noir,blanc);
        SDL_FillRect(screen,&rect,SDL_MapRGB(screen->format,255,255,255)); // zone de texte à remplir
        SDL_BlitSurface(texte,NULL,screen,&rect2);
        SDL_BlitSurface(surface2,NULL,screen,&rect3);
    }
    
    #endif // BOUTONS_H_INCLUDED
    
    
    #ifndef TEST_H_INCLUDED
    #define TEST_H_INCLUDED
    
    load_image create_image(SDL_Surface*screen,int largeur,int hauteur,char name[100],char name2[100],load_image image)
    {
        SDL_Surface*test=NULL;
        int nb=largeur*hauteur;
        int cnt=0;
        SDL_Rect *tab=(SDL_Rect*)malloc(nb*sizeof(SDL_Rect));
        for(int i=0;i<largeur;i++)
        {
            for(int j=0;j<hauteur;j++)
            {
                tab[cnt].x=i;
                tab[cnt].y=j;
                tab[cnt].w=1;
                tab[cnt].h=1;
                cnt++;
            }
        }
        Uint32 *color=(Uint32*)malloc(nb*sizeof(Uint32));
        for(int i=0;i<nb;i++)
        {
            color[i]=SDL_MapRGB(screen->format,255,255,255);//blanc
        }
        test=SDL_CreateRGBSurface(SDL_HWSURFACE,largeur,hauteur,32,0,0,0,0);
        SDL_Rect TEST={screen->w/2-test->w/2,screen->h/2-test->h/2,test->w,test->h};
        for(int i=0;i<nb;i++)
        {
            SDL_FillRect(test,&tab[i],color[i]);
            SDL_FillRect(screen,&tab[i],color[i]);
        }
        SDL_BlitSurface(test,NULL,screen,&TEST);
        char path_directory[20]="projects/";
        char slash[20]="/";
        char extension[20]=".bmp";
        strcat(path_directory,name2);
        int dossier=access(path_directory,0);
        if(dossier==0)
        {
            strcat(path_directory,slash);
            strcat(path_directory,name);
            strcat(path_directory,extension);
            SDL_SaveBMP(test,path_directory);
            image.check=1;
            strcpy(image.path,path_directory);
        }
        if(dossier!=0)
        {
    
        }
        strcpy(path_directory,"");
        return image;
    }
    
    char charge_image(SDL_Surface*screen,char name[1000])
    {
        SDL_Surface* surface1;
        surface1=screen;
        SDL_Surface*temp=SDL_LoadBMP(name);
        if(SDL_LoadBMP(name)==-1)
        {
            fprintf(stderr,"Erreur");
            return 1;
        }
        else
        {
            SDL_Rect dstrect;
            dstrect.x=surface1->w/2-temp->w/2;
            dstrect.y=surface1->h/2-temp->h/2;
            dstrect.w=temp->w;
            dstrect.h=temp->h;
            SDL_BlitSurface(temp,NULL,surface1,&dstrect);
            SDL_FreeSurface(temp);
            printf("\n%s",name);
            return 0;
        }
    }
    
    #endif // TEST_H_INCLUDED
    
    #ifndef BARRE_DES_TACHES_H_INCLUDED
    #define BARRE_DES_TACHES_H_INCLUDED
    
    void barre_des_taches(SDL_Surface*screen,SDL_Rect curseur,Detect *detect)
    {
        TTF_Font *ttf_texte=NULL;
    
        ttf_texte=TTF_OpenFont("police.ttf",20);
    
        SDL_Color noir={0,0,0};
        SDL_Color gris_clair={235,235,235};
        SDL_Color cyan={217,255,255};
    
        SDL_Surface *texte[14] = {NULL};
    
        const char* texteFichier=         " Fichier  ";
        const char* texteEdition=         " Edition ";
        const char* texteAffichage=       " Affichage ";
        const char* texteOutils=          " Outils ";
        const char* textecreer_un_dossier=" Créer un projet  ";
        const char* textecreer_une_image= " Créer une image ";
        const char* texteouvrir_un_projet=" Ouvrir un projet ";
        const char* texteouvrir_une_image=" Ouvrir une image";
        const char* texteenregistrer=     " Enregistrer       ";
        const char* texteenregistrer_sous=" Enregistrer sous";
        const char* textequitter=         " Quitter             ";
        const char* textecreer_la_tilemap=" Créer une tilemap    ";
        const char* textecreer_les_tiles= " Création des tiles    ";
        const char* texteediter_la_tilemap= " Editer une tilemap   ";
    
        texte[0]=TTF_RenderText_Shaded(ttf_texte,texteFichier,noir,gris_clair);
        texte[1]=TTF_RenderText_Shaded(ttf_texte,texteEdition,noir,gris_clair);
        texte[2]=TTF_RenderText_Shaded(ttf_texte,texteAffichage,noir,gris_clair);
        texte[3]=TTF_RenderText_Shaded(ttf_texte,texteOutils,noir,gris_clair);
        texte[4]=TTF_RenderText_Shaded(ttf_texte,textecreer_un_dossier,noir,gris_clair);
        texte[5]=TTF_RenderText_Shaded(ttf_texte,textecreer_une_image,noir,gris_clair);
        texte[6]=TTF_RenderText_Shaded(ttf_texte,texteouvrir_un_projet,noir,gris_clair);
        texte[7]=TTF_RenderText_Shaded(ttf_texte,texteouvrir_une_image,noir,gris_clair);
        texte[8]=TTF_RenderText_Shaded(ttf_texte,texteenregistrer,noir,gris_clair);
        texte[9]=TTF_RenderText_Shaded(ttf_texte,texteenregistrer_sous,noir,gris_clair);
        texte[10]=TTF_RenderText_Shaded(ttf_texte,textequitter,noir,gris_clair);
        texte[11]=TTF_RenderText_Shaded(ttf_texte,textecreer_la_tilemap,noir,gris_clair);
        texte[12]=TTF_RenderText_Shaded(ttf_texte,textecreer_les_tiles,noir,gris_clair);
        texte[13]=TTF_RenderText_Shaded(ttf_texte,texteediter_la_tilemap,noir,gris_clair);
    
        SDL_Rect TEXTE1={0,10,texte[0]->w,texte[0]->h};
        SDL_Rect TEXTE2={TEXTE1.w+2,TEXTE1.y,texte[1]->w,texte[1]->h};
        SDL_Rect TEXTE3={TEXTE2.x+TEXTE2.w+2,TEXTE1.y,texte[2]->w,texte[2]->h};
        SDL_Rect TEXTE4={TEXTE3.x+TEXTE3.w+2,TEXTE1.y,texte[3]->w,texte[3]->h};
    
        SDL_Rect TEXTE5={0,27,texte[4]->w,texte[4]->h};
        SDL_Rect TEXTE6={0,TEXTE5.y+texte[4]->h,texte[5]->w,texte[5]->h};
        SDL_Rect TEXTE7={0,TEXTE6.y+texte[5]->h,texte[6]->w,texte[6]->h};
        SDL_Rect TEXTE8={0,TEXTE7.y+texte[6]->h,texte[7]->w,texte[7]->h};
        SDL_Rect TEXTE9={0,TEXTE8.y+texte[7]->h,texte[8]->w,texte[8]->h};
        SDL_Rect TEXTE10={0,TEXTE9.y+texte[8]->h,texte[9]->w,texte[9]->h};
        SDL_Rect TEXTE11={0,TEXTE10.y+texte[9]->h,texte[10]->w,texte[10]->h};
    
        SDL_Rect TEXTE12={47,TEXTE5.y,texte[11]->w,texte[11]->h};
        SDL_Rect TEXTE13={47,TEXTE5.y+texte[11]->h,texte[12]->w,texte[12]->h};
        SDL_Rect TEXTE14={47,TEXTE13.y+texte[12]->h,texte[13]->w,texte[13]->h};
    
        SDL_Rect fond={0,0,2000,20+17};
        //SDL_Rect background_edition={47,10,109,34};
        SDL_Rect background_edition2={TEXTE12.x,TEXTE12.y,texte[12]->w,texte[11]->h+texte[12]->h+texte[13]->h};
    
        if(Collision(&curseur,&TEXTE1))
        {
            texte[0]=TTF_RenderText_Shaded(ttf_texte,texteFichier,noir,cyan);
            if(detect->value==1)
            {
                detect->tag=1;
            }
        }
        if(Collision(&curseur,&TEXTE2))
        {
            texte[1]=TTF_RenderText_Shaded(ttf_texte,texteEdition,noir,cyan);
            if(detect->value==1)
            {
                detect->tag=2;
            }
        }
    
        if((!Collision(&curseur,&TEXTE1))&&(!Collision(&curseur,&TEXTE5))&&(!Collision(&curseur,&TEXTE6))&&(!Collision(&curseur,&TEXTE7))&&(!Collision(&curseur,&TEXTE8))&&(!Collision(&curseur,&TEXTE9))&&(!Collision(&curseur,&TEXTE10))&&(!Collision(&curseur,&TEXTE11))&&(detect->tag==1))
        {
            detect->tag=0;
        }
        if((!Collision(&curseur,&TEXTE2))&&(!Collision(&curseur,&TEXTE12))&&(!Collision(&curseur,&TEXTE13))&&(!Collision(&curseur,&TEXTE14))&&(detect->tag==2))
        {
            detect->tag=0;
        }
    
        if(detect->tag==1)
        {
            SDL_SetAlpha(texte[4],SDL_SRCALPHA,255); // Opaque
            SDL_SetAlpha(texte[5],SDL_SRCALPHA,255);
            SDL_SetAlpha(texte[6],SDL_SRCALPHA,255);
            SDL_SetAlpha(texte[7],SDL_SRCALPHA,255);
            SDL_SetAlpha(texte[8],SDL_SRCALPHA,255);
            SDL_SetAlpha(texte[9],SDL_SRCALPHA,255);
            SDL_SetAlpha(texte[10],SDL_SRCALPHA,255);
            SDL_SetAlpha(texte[11],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[12],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[13],SDL_SRCALPHA,0);
        }
        if(detect->tag==2)
        {
            SDL_FillRect(screen,&background_edition2,SDL_MapRGB(screen->format,235,235,235));
            SDL_SetAlpha(texte[4],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[5],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[6],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[7],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[8],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[9],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[10],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[11],SDL_SRCALPHA,255);
            SDL_SetAlpha(texte[12],SDL_SRCALPHA,255);
            SDL_SetAlpha(texte[13],SDL_SRCALPHA,255);
    
        }
        if(detect->tag==0)
        {
            SDL_SetAlpha(texte[4],SDL_SRCALPHA,0); // Transparent
            SDL_SetAlpha(texte[5],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[6],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[7],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[8],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[9],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[10],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[11],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[12],SDL_SRCALPHA,0);
            SDL_SetAlpha(texte[13],SDL_SRCALPHA,0);
        }
        if(Collision(&curseur,&TEXTE3))
        {
            texte[2]=TTF_RenderText_Shaded(ttf_texte,texteAffichage,noir,cyan);
        }
        if(Collision(&curseur,&TEXTE4))
        {
            texte[3]=TTF_RenderText_Shaded(ttf_texte,texteOutils,noir,cyan);
        }
        if((Collision(&curseur,&TEXTE5))&&(detect->tag==1))
        {
            texte[4]=TTF_RenderText_Shaded(ttf_texte,textecreer_un_dossier,noir,cyan);
            if(detect->value==1)
            {
                detect->check[0]=1;
                detect->tag=0;
            }
        }
        if((Collision(&curseur,&TEXTE6))&&(detect->tag==1))
        {
            texte[5]=TTF_RenderText_Shaded(ttf_texte,textecreer_une_image,noir,cyan);
            if(detect->value==1)
            {
                detect->check[1]=1;
                detect->tag=0;
            }
        }
        if((Collision(&curseur,&TEXTE7))&&(detect->tag==1))
        {
            texte[6]=TTF_RenderText_Shaded(ttf_texte,texteouvrir_un_projet,noir,cyan);
            if(detect->value==1)
            {
                detect->check[3]=1;
                detect->tag=0;
            }
        }
        if((Collision(&curseur,&TEXTE8))&&(detect->tag==1))
        {
            texte[7]=TTF_RenderText_Shaded(ttf_texte,texteouvrir_une_image,noir,cyan);
            if(detect->value==1)
            {
                detect->tag=0;
            }
        }
        if((Collision(&curseur,&TEXTE9))&&(detect->tag==1))
        {
            texte[8]=TTF_RenderText_Shaded(ttf_texte,texteenregistrer,noir,cyan);
            if(detect->value==1)
            {
                detect->tag=0;
            }
        }
        if((Collision(&curseur,&TEXTE10))&&(detect->tag==1))
        {
            texte[9]=TTF_RenderText_Shaded(ttf_texte,texteenregistrer_sous,noir,cyan);
            if(detect->value==1)
            {
                detect->tag=0;
            }
        }
        if((Collision(&curseur,&TEXTE11))&&(detect->tag==1))
        {
            texte[10]=TTF_RenderText_Shaded(ttf_texte,textequitter,noir,cyan);
            if(detect->value==1)
            {
                detect->tag=0;
                SDL_Quit();
                TTF_Quit();
                printf("\n%s",Accent("Merci d'avoir utilisé ce logiciel."));
    
            }
        }
        if((Collision(&curseur,&TEXTE12))&&(detect->tag==2))
        {
            texte[11]=TTF_RenderText_Shaded(ttf_texte,textecreer_la_tilemap,noir,cyan);
            if(detect->value==1)
            {
                detect->check[4]=1;
                detect->tag=0;
            }
        }
        if((Collision(&curseur,&TEXTE13))&&(detect->tag==2))
        {
            texte[12]=TTF_RenderText_Shaded(ttf_texte,textecreer_les_tiles,noir,cyan);
            if(detect->value==1)
            {
                detect->check[2]=1;
                detect->tag=0;
            }
        }
        if((Collision(&curseur,&TEXTE14))&&(detect->tag==2))
        {
            texte[13]=TTF_RenderText_Shaded(ttf_texte,texteediter_la_tilemap,noir,cyan);
            if(detect->value==1)
            {
                detect->check[5]=1;
                detect->tag=0;
            }
        }
    
        SDL_FillRect(screen,&fond,SDL_MapRGB(screen->format,210,210,210));
        if(detect->tag==1)
            boxRGBA(screen,0,27,0+90,146,235,235,235,255);
    
        SDL_BlitSurface(texte[0],NULL,screen,&TEXTE1);
        SDL_BlitSurface(texte[1],NULL,screen,&TEXTE2);
        SDL_BlitSurface(texte[2],NULL,screen,&TEXTE3);
        SDL_BlitSurface(texte[3],NULL,screen,&TEXTE4);
        SDL_BlitSurface(texte[4],NULL,screen,&TEXTE5);
        SDL_BlitSurface(texte[5],NULL,screen,&TEXTE6);
        SDL_BlitSurface(texte[6],NULL,screen,&TEXTE7);
        SDL_BlitSurface(texte[7],NULL,screen,&TEXTE8);
        SDL_BlitSurface(texte[8],NULL,screen,&TEXTE9);
        SDL_BlitSurface(texte[9],NULL,screen,&TEXTE10);
        SDL_BlitSurface(texte[10],NULL,screen,&TEXTE11);
        SDL_BlitSurface(texte[11],NULL,screen,&TEXTE12);
        SDL_BlitSurface(texte[12],NULL,screen,&TEXTE13);
        SDL_BlitSurface(texte[13],NULL,screen,&TEXTE14);
        SDL_FreeSurface(texte[0]);
        SDL_FreeSurface(texte[1]);
        SDL_FreeSurface(texte[2]);
        SDL_FreeSurface(texte[3]);
        SDL_FreeSurface(texte[4]);
        SDL_FreeSurface(texte[5]);
        SDL_FreeSurface(texte[6]);
        SDL_FreeSurface(texte[7]);
        SDL_FreeSurface(texte[8]);
        SDL_FreeSurface(texte[9]);
        SDL_FreeSurface(texte[10]);
        SDL_FreeSurface(texte[11]);
        SDL_FreeSurface(texte[12]);
        SDL_FreeSurface(texte[13]);
        TTF_CloseFont(ttf_texte);
        //printf("\ntag:%d",detect->tag);
        //printf("\nvalue:%d",detect->value);
    }
    
    #endif // BARRE_DES_TACHES_H_INCLUDED
    
    #ifndef FUNCTION_H_INCLUDED
    #define FUNCTION_H_INCLUDED
    
    #define max_length 30
    #define nb_window 5
    
    typedef struct
    {
        char path[1000];
        int check;
    }load_image;
    
    typedef struct
    {
       int x,y;
       int rayon;
    }Cercle;
    
    typedef struct
    {
        int tag;
        int value;
        int *check;
    }   Detect;
    
    typedef struct
    {
        int x;
        int y;
        Uint32 color;
    }Image;
    
    bool CollisionCercle(int x,int y,Cercle *C)
    {
        float norme = sqrt((x-C->x)*(x-C->x) + (y-C->y)*(y-C->y));
        if(norme<=C->rayon)
        {
            return 1;
        }
        else
        {
            return 0;
        }
    }
    
    int Collision(SDL_Rect* m,SDL_Rect* n)
    {
    	if((m->x >= n->x + n->w)||(m->x + m->w <= n->x)||(m->y >= n->y + n->h)||(m->y + m->h <= n->y))
    		return 0;
    	return 1;
    }
    
    char * Accent(const char * mess)
    {
        static char retour [80];
        CharToOem (mess,retour);
        return retour;
    }
    
    void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
    {
        int bpp = surface->format->BytesPerPixel;
        // Here p is the address to the pixel we want to set
        Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
    
        switch(bpp) {
        case 1:
            *p = pixel;
            break;
    
        case 2:
            *(Uint16 *)p = pixel;
            break;
    
        case 3:
            if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
                p[0] = (pixel >> 16) & 0xff;
                p[1] = (pixel >> 8) & 0xff;
                p[2] = pixel & 0xff;
            } else {
                p[0] = pixel & 0xff;
                p[1] = (pixel >> 8) & 0xff;
                p[2] = (pixel >> 16) & 0xff;
            }
            break;
    
        case 4:
            *(Uint32 *)p = pixel;
            break;
        }
    }
    
    Uint32 getpixel(SDL_Surface* surface, int x, int y)
    {
      int bpp = surface->format->BytesPerPixel;
    
      Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
    
      switch(bpp)
      {
         case 1:
              return *p;
         case 2:
              return *(Uint16 *)p;
         case 3:
             if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
                 return p[0] << 16 | p[1] << 8 | p[2];
             else
                 return p[0] | p[1] << 8 | p[2] << 16;
         case 4:
              return *(Uint32 *)p;
         default:
              return 0;
      }
    }
    
    /*void Scroll(SDL_Surface* ecran,SDL_Surface* TILESET,unsigned int table[][NB_BLOCS_LARGEUR],int nombre_blocs_largeur,int nombre_blocs_hauteur,SDL_Rect *rect)
    {
    	int i,j;
    	SDL_Rect Rect_dest;
    	SDL_Rect Rect_source;
    	Rect_source.w = LARGEUR_TILE;
    	Rect_source.h = HAUTEUR_TILE;
    	Rect_dest.w = LARGEUR_TILE;
    	Rect_dest.h = HAUTEUR_TILE;
    	for(i=0;i<nombre_blocs_largeur;i++)
    	{
    		for(j=0;j<nombre_blocs_hauteur;j++)
    		{
    			Rect_dest.x = i*LARGEUR_TILE - rect->x;
    			Rect_dest.y = j*HAUTEUR_TILE - rect->y;
    			Rect_source.x = (table[j][i])*LARGEUR_TILE;
    			Rect_source.y = 0;
    			SDL_BlitSurface(TILESET,&Rect_source,ecran,&Rect_dest);
    		}
    	}
    }
    void Afficher(SDL_Surface* ecran,SDL_Surface* TILESET,unsigned int table[][NB_BLOCS_LARGEUR],int nombre_blocs_largeur,int nombre_blocs_hauteur)
    {
    	int i,j;
    	SDL_Rect Rect_dest;
    	SDL_Rect Rect_source;
    	Rect_source.w = LARGEUR_TILE;
    	Rect_source.h = HAUTEUR_TILE;
    	//Rect_dest.w = LARGEUR_TILE;
    	//Rect_dest.h = HAUTEUR_TILE;
    	for(i=0;i<nombre_blocs_largeur;i++)
    	{
    		for(j=0;j<nombre_blocs_hauteur;j++)
    		{
    			Rect_dest.x = i*LARGEUR_TILE;// - rect->x;
    			Rect_dest.y = j*HAUTEUR_TILE;// - rect->y;
    			Rect_source.x = (table[j][i])*LARGEUR_TILE;
    			Rect_source.y = 0;
    			SDL_BlitSurface(TILESET,&Rect_source,ecran,&Rect_dest);
    		}
    	}
    }
    
    void ChargerTable(unsigned int table[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR], unsigned int tableACharger[NB_BLOCS_LARGEUR][NB_BLOCS_HAUTEUR])
    {
        int i,j;
        for(i = 0; i < NB_BLOCS_LARGEUR; i++)
        {
            for(j = 0; j < NB_BLOCS_HAUTEUR; j++){
                table[i][j] = tableACharger[i][j];
            }
        }
    }*/
    
    #endif // FUNCTION_H_INCLUDED
    
    #ifndef SAISIE_DES_TOUCHES_H_INCLUDED
    #define SAISIE_DES_TOUCHES_H_INCLUDED
    
    char touches(Uint8 *key,char chaine[max_length])
    {
        if(key[SDLK_q])
        {
            const char *lettre;
            lettre="a";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_q]=0;
            return 1;
        }
        if(key[SDLK_a])
        {
            const char *lettre;
            lettre="q";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_a]=0;
            return 1;
        }
        if(key[SDLK_b])
        {
            const char *lettre;
            lettre="b";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_b]=0;
            return 1;
        }
        if(key[SDLK_c])
        {
            const char *lettre;
            lettre="c";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_c]=0;
            return 1;
        }
        if(key[SDLK_d])
        {
            const char *lettre;
            lettre="d";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_d]=0;
            return 1;
        }
        if(key[SDLK_e])
        {
            const char *lettre;
            lettre="e";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_e]=0;
            return 1;
        }
        if(key[SDLK_f])
        {
            const char *lettre;
            lettre="f";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_f]=0;
            return 1;
        }
        if(key[SDLK_g])
        {
            const char *lettre;
            lettre="g";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_g]=0;
            return 1;
        }
        if(key[SDLK_h])
        {
            const char *lettre;
            lettre="h";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_h]=0;
            return 1;
        }
    
        if(key[SDLK_i])
        {
            const char *lettre;
            lettre="i";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_i]=0;
            return 1;
        }
        if(key[SDLK_j])
        {
            const char *lettre;
            lettre="j";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_j]=0;
            return 1;
        }
        if(key[SDLK_k])
        {
            const char *lettre;
            lettre="k";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_k]=0;
            return 1;
        }
        if(key[SDLK_l])
        {
            const char *lettre;
            lettre="l";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_l]=0;
            return 1;
        }
        if(key[SDLK_SEMICOLON])
        {
            const char *lettre;
            lettre="m";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_SEMICOLON]=0;
            return 1;
        }
        if(key[SDLK_n])
        {
            const char *lettre;
            lettre="n";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_n]=0;
            return 1;
        }
        if(key[SDLK_o])
        {
            const char *lettre;
            lettre="o";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_o]=0;
            return 1;
        }
        if(key[SDLK_p])
        {
            const char *lettre;
            lettre="p";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_p]=0;
            return 1;
        }
        if(key[SDLK_q])
        {
            const char *lettre;
            lettre="q";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_q]=0;
            return 1;
        }
        if(key[SDLK_r])
        {
            const char *lettre;
            lettre="r";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_r]=0;
            return 1;
        }
        if(key[SDLK_s])
        {
            const char *lettre;
            lettre="s";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_s]=0;
            return 1;
        }
        if(key[SDLK_t])
        {
            const char *lettre;
            lettre="t";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_t]=0;
            return 1;
        }
        if(key[SDLK_u])
        {
            const char *lettre;
            lettre="u";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_u]=0;
            return 1;
        }
        if(key[SDLK_v])
        {
            const char *lettre;
            lettre="v";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_v]=0;
            return 1;
        }
        if(key[SDLK_w])
        {
            const char *lettre;
            lettre="z";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_w]=0;
            return 1;
        }
        if(key[SDLK_x])
        {
            const char *lettre;
            lettre="x";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_x]=0;
            return 1;
        }
        if(key[SDLK_y])
        {
            const char *lettre;
            lettre="y";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_y]=0;
            return 1;
        }
        if(key[SDLK_z])
        {
            const char *lettre;
            lettre="w";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_z]=0;
            return 1;
        }
        if(key[SDLK_SPACE])
        {
            const char *lettre;
            lettre=" ";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_SPACE]=0;
            return 1;
        }
        if(key[SDLK_0])
        {
            const char *lettre;
            lettre="0";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_0]=0;
            return 1;
        }
        if(key[SDLK_1])
        {
            const char *lettre;
            lettre="1";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_1]=0;
            return 1;
        }
        if(key[SDLK_2])
        {
            const char *lettre;
            lettre="2";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_2]=0;
            return 1;
        }
        if(key[SDLK_3])
        {
            const char *lettre;
            lettre="3";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_3]=0;
            return 1;
        }
        if(key[SDLK_4])
        {
            const char *lettre;
            lettre="4";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_4]=0;
            return 1;
        }
        if(key[SDLK_5])
        {
            const char *lettre;
            lettre="5";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_5]=0;
            return 1;
        }
        if(key[SDLK_6])
        {
            const char *lettre;
            lettre="6";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_6]=0;
            return 1;
        }
        if(key[SDLK_7])
        {
            const char *lettre;
            lettre="7";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_7]=0;
            return 1;
        }
        if(key[SDLK_8])
        {
            const char *lettre;
            lettre="8";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_8]=0;
            return 1;
        }
        if(key[SDLK_9])
        {
            const char *lettre;
            lettre="9";
            strcat(chaine,lettre);
            //printf("\n%s",chaine);
            key[SDLK_9]=0;
            return 1;
        }
        return 0;
    }
    
    #endif // SAISIE_DES_TOUCHES_H_INCLUDED
    
    #ifndef CREATION_IMAGE_H_INCLUDED
    #define CREATION_IMAGE_H_INCLUDED
    
    int creation_image(SDL_Surface*screen,SDL_Rect *curseur,Detect *detect)
    {
        TTF_Font *ttf_texte=TTF_OpenFont("police.ttf",20);
        SDL_Color noir={0,0,0};
        SDL_Color gris_clair={235,235,235};
        //SDL_Color cyan={217,255,255};
        Uint32 blanc=SDL_MapRGB(screen->format,255,255,255);
        SDL_Surface*fenetre=SDL_LoadBMP("images/fenetre_couleur.bmp");
        SDL_Surface*largeur=NULL,*hauteur=NULL,*nom=NULL;
        largeur=TTF_RenderText_Shaded(ttf_texte,"Largeur :",noir,gris_clair);
        hauteur=TTF_RenderText_Shaded(ttf_texte,"Hauteur :",noir,gris_clair);
        nom=TTF_RenderText_Shaded(ttf_texte,"Nom de l'image :",noir,gris_clair);
        SDL_Rect*tab=(SDL_Rect*)malloc(10*sizeof(SDL_Rect));
        tab[0].x=screen->w/2-fenetre->w/2;
        tab[0].y=screen->h/2-fenetre->h/2;
        tab[0].w=fenetre->w;
        tab[0].h=fenetre->h;
        tab[1].x=tab[0].x+tab[0].w/2-100/2;
        tab[1].y=tab[0].y+tab[0].h/4-20/4;
        tab[1].w=100;
        tab[1].h=20;
        tab[2].x=tab[1].x;
        tab[2].y=tab[1].y-tab[1].h;
        tab[2].w=nom->w;
        tab[2].h=nom->h;
    
        tab[3].x=tab[1].x;
        tab[3].y=tab[1].y+tab[1].h*3;
        tab[3].w=100;
        tab[3].h=20;
        tab[4].x=tab[3].x;
        tab[4].y=tab[3].y-tab[3].h;
        tab[4].w=largeur->w;
        tab[4].h=largeur->h;
    
        tab[5].x=tab[3].x;
        tab[5].y=tab[3].y+tab[3].h*3;
        tab[5].w=100;
        tab[5].h=20;
        tab[6].x=tab[5].x;
        tab[6].y=tab[5].y-tab[5].h;
        tab[6].w=hauteur->w;
        tab[6].h=hauteur->h;
    
        SDL_BlitSurface(fenetre,NULL,screen,&tab[0]);
        SDL_FillRect(screen,&tab[1],blanc);
        SDL_BlitSurface(nom,NULL,screen,&tab[2]);
    
        SDL_FillRect(screen,&tab[3],blanc);
        SDL_BlitSurface(largeur,NULL,screen,&tab[4]);
    
        SDL_FillRect(screen,&tab[5],blanc);
        SDL_BlitSurface(hauteur,NULL,screen,&tab[6]);
    
    
        TTF_CloseFont(ttf_texte);
        free(tab);
        return 0;
    }
    
    #endif // CREATION_IMAGE_H_INCLUDED
    

    Pour faire simple, ce code permet de créer dynamiquement une surface de n'importe quelle dimension, une fois créée, je souhaiterais pouvoir dessiner sur cette nouvelle image (surface) qui sera par la suite enregistrée.

    Le problème est le suivant : l'image est bien créée et enregistrée correctement mais impossible de dessiner dessus.

    Je ne sais vraiment pas comment résoudre ce problème, ce qui est assez problématique car il m'empêche de poursuivre le développement du code.

    Si vous avez compris pourquoi ça ne marche pas, c'est que vous n'êtes pas des balais comme moi...

    • Partager sur Facebook
    • Partager sur Twitter
      25 mars 2020 à 0:27:58

      Salut ! Honnetement c'est trop indegeste ! Je te conseille de synthétiser un maximum de reduire tes fonctions en creant des structures pointeurs sur structures, ce sera plus lisible et tu trouvera ton erreur !

      Bonne chance à toi ! ^^

      • Partager sur Facebook
      • Partager sur Twitter

      Comprendre, Testez, Rater, Réussir.

        25 mars 2020 à 9:55:33

        Bonjour,

        Cela ne m’étonne pas que tu ais du mal à t’y retrouver !

        Tu as bien réalisé des fonctions mais la partie où tu utilises putpixel()(ligne 289) est un empilage de plus de 300 lignes de code sans décomposition de fonctionnalité.

        Là aussi, il faudrait faire des fonctions avec des paramètres d’entrée et des résultats de sortie pour pouvoir TESTER le fonctionnement de chacune ; éviter aussi les « chiffres magiques » dans les paramètres d’une fonction comme 31 et 101 pour :

        putpixel(screen,COLOR.x+COLOR.w-31-j,101+i,(unsigned long)pipette.color);

        Il ne s’agit pas d’être ou non des balais, il s’agit de faire et de pouvoir TESTER ce que l’on a fait.

        Autre chose : tu utilises mal SDL_PollEvent(&event);(ligne 244)

        Il faut tester le retour avec une boucle while car sinon (en particulier si tu veux faire une bascule dans le switch) cela ne peut pas marcher.

        Pour plus d’info :

        http://www.siteduzero.com/forum/sujet/comprehension-de-la-fonction-pollevent

        (à la fin du post les 2 façons de faire que tu pourras TESTER par toi-même)

        Une fois que tu as des fonctions qui marchent, le développement du code n’est plus un problème.

        • Partager sur Facebook
        • Partager sur Twitter
        Architecture SDL                     Multithreading         

        Colorier une surface

        × Après avoir cliqué sur "Répondre" vous serez invité à vous connecter pour que votre message soit publié.
        × Attention, ce sujet est très ancien. Le déterrer n'est pas forcément approprié. Nous te conseillons de créer un nouveau sujet pour poser ta question.
        • Editeur
        • Markdown