IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

SDL Discussion :

Afficher le contenu d'un fichier texte


Sujet :

SDL

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Sénégal

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2014
    Messages : 5
    Par défaut Afficher le contenu d'un fichier texte
    Salut !! je suis nouveau en programmation avec le langage C et notre professeur nous a demander de lui faire un glossaire informatique avec la sdl. J'ai réussi la partie graphique. Maintenant il me faut afficher mon glossaire qui est dans un fichier texte sur l'écran que j'ai alloué pour ca!! pourriez vous m'aider svp je ne sais pas comment faire!!

  2. #2
    Expert confirmé
    Avatar de Kannagi
    Homme Profil pro
    cyber-paléontologue
    Inscrit en
    Mai 2010
    Messages
    3 226
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cyber-paléontologue

    Informations forums :
    Inscription : Mai 2010
    Messages : 3 226
    Par défaut
    Bon vu que tu es débutant la solution la plus simple , il faut utiliser SDL_ttf pour afficher un texte donc tu charge un .ttf , t'afficheun texte quand t'as réussi ça .
    Ben après ça sera facile tu lis ton fichier tu récupère une chaine de caractère et tu l'affiche avec SDL_ttf (me rappelle plus du nom de la fonction mais elle attend une chaine de caractère).

  3. #3
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Sénégal

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2014
    Messages : 5
    Par défaut
    j'ai la ttf et j'arrive à écrire sur les écrans(même si quand je supprime je n'arrive plus à écrire je ne sais pas pourquoi)!! mon problème s'est d'insérer un fichier texte dans le graphique!!

  4. #4
    Expert confirmé
    Avatar de Kannagi
    Homme Profil pro
    cyber-paléontologue
    Inscrit en
    Mai 2010
    Messages
    3 226
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cyber-paléontologue

    Informations forums :
    Inscription : Mai 2010
    Messages : 3 226
    Par défaut
    Faudra détailler parce je vois pas c'est quoi le souci , fopen , fgetc/fgets ?
    Je sais pas je lirai avec fgets vu que c'est un devoir école pas besoin d'analyser trop le texte d'affiche chaque ligne et voila.

  5. #5
    Nouveau membre du Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Avril 2014
    Messages
    5
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 36
    Localisation : Sénégal

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Avril 2014
    Messages : 5
    Par défaut
    voici mon programme !! je veux insérer un fichier texte mais je n'ai pas d'idée sur comment m'y prendre.

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    473
    474
    475
    476
    477
    478
    479
    480
    481
    482
    483
    484
    485
    486
    487
    488
    489
    490
    491
    492
    493
    494
    495
    496
    497
    498
    499
    500
    501
    #include<stdio.h>
    #include<stdlib.h>
    #include<SDL/SDL.h>
    #include<SDL/SDL_ttf.h>
     
     
    int main( int argc, char* args[] ) {
     
    SDL_Surface *ecran= NULL, *ecranmot=NULL,*ajouter=NULL, *ecrandef=NULL, *ajout= NULL, *supprime=NULL, *sauver=NULL, *ajour=NULL,
                 *zonerech=NULL,*motdef=NULL,*defmot=NULL,*recherche=NULL, *texajout=NULL, *texsuppr=NULL, *texsauver=NULL,
                *texajour=NULL,*texajouter=NULL,*texdefmot=NULL ,*texrecherche=NULL, *texmotdef=NULL, *zoneaffichage=NULL,
                *supprimer=NULL,*texsupprimer=NULL, *tex=NULL;// Les pointeurs pour l'écran et les autres surfaces
     
    SDL_Rect posajout, possup,pozajouter, possauver, posajour, poszonerech, posrecherch, poszonafich,pozmot,pozdef,poztex
                      ,pozsupprimer,pozmotdef,pozdefmot;//déclaration des positions pour chaque espace
     
     
    int newecran=0;
    int continuer = 1, i=0, j=0;
     
    TTF_Font *police=NULL, *police1=NULL;
    SDL_Color noir={0, 0, 0};//pour avoir la couleur noire
    SDL_Color blanche={255, 255, 255};
    char mot[18]={0};
     
    SDL_Init( SDL_INIT_VIDEO);// Démarrer la SDL
    TTF_Init();               //Démarre la TTF
    SDL_EnableKeyRepeat(70, 70);
     
    ecran = SDL_SetVideoMode(960, 600, 32, SDL_HWSURFACE|SDL_RESIZABLE|SDL_DOUBLEBUF);// On ouvre une fenêtre
    if (ecran == NULL) // Si l'ouverture a échoué, on le note et on arrête
         {
              fprintf(stderr, "Impossible de charger le mode vidéo:%s\n", SDL_GetError());
              exit(EXIT_FAILURE);
              }
     
    SDL_WM_SetCaption("Dictionnaire Graphique", NULL);
    police = TTF_OpenFont("Bookos.ttf",20);
    police1 = TTF_OpenFont("Bookos.ttf",20);
    TTF_SetFontStyle(police, TTF_STYLE_ITALIC | TTF_STYLE_UNDERLINE);
    texajout = TTF_RenderText_Blended(police, "AJOUTER", noir);
    texsuppr = TTF_RenderText_Blended(police, "SUPPRIMER", noir);
    texsauver = TTF_RenderText_Blended(police,"SAUVEGARDER", noir);
    texajour = TTF_RenderText_Blended(police, "MISE A JOUR", noir);
    texrecherche = TTF_RenderText_Blended(police, "RECHERCHER", noir);
    texmotdef = TTF_RenderText_Blended(police, "ECRIRE LE MOT",blanche);
    texdefmot = TTF_RenderText_Blended(police, "DEFINIR LE MOT",blanche);
    texajouter = TTF_RenderText_Blended(police, "Ajouter Mot",blanche);
    texsupprimer = TTF_RenderText_Blended(police, "Supprimer Mot",blanche);
     
     
    ajout = SDL_CreateRGBSurface(SDL_HWSURFACE, 105,30,32,0,0,0,0);
    posajout.x= 15;
    posajout.y= 15;
    SDL_FillRect(ajout, NULL, SDL_MapRGB(ecran->format, 255,255,255));
    posajout.x= 16;
    posajout.y= 20;
     
    supprime = SDL_CreateRGBSurface(SDL_HWSURFACE, 130,30,32,0,0,0,0);
    possup.x= 140;
    possup.y= 15;
    SDL_FillRect(supprime, NULL, SDL_MapRGB(ecran->format, 255,255,255));
    possup.x= 142;
    possup.y= 20;
    sauver = SDL_CreateRGBSurface(SDL_HWSURFACE, 160,30,32,0,0,0,0);
    possauver.x= 290;
    possauver.y= 15;
    SDL_FillRect(sauver, NULL, SDL_MapRGB(ecran->format, 255,255,255));
    possauver.x = 290;
    possauver.y = 20;
    ajour = SDL_CreateRGBSurface(SDL_HWSURFACE, 150,30,32,0,0,0,0);
    posajour.x= 465;
    posajour.y= 15;
    SDL_FillRect(ajour, NULL, SDL_MapRGB(ecran->format, 255,255,255));
    posajour.x = 470;
    posajour.y = 20;
    recherche = SDL_CreateRGBSurface(SDL_HWSURFACE, 153,30,32,0,0,0,0);
    posrecherch.x= 795;
    posrecherch.y= 70;
    SDL_FillRect(recherche, NULL, SDL_MapRGB(ecran->format, 255,255,255));
    posrecherch.x = 800;
    posrecherch.y = 72;
    zonerech = SDL_CreateRGBSurface(SDL_HWSURFACE, 223,30,32,0,0,0,0);
    poszonerech.x= 570;
    poszonerech.y= 70;
    SDL_FillRect(zonerech, NULL, SDL_MapRGB(ecran->format, 255,255,255));
    zoneaffichage = SDL_CreateRGBSurface(SDL_HWSURFACE, 800,445,32,0,0,0,0);
    poszonafich.x= 15;
    poszonafich.y= 140;
    SDL_FillRect(zoneaffichage, NULL, SDL_MapRGB(ecran->format, 255,255,255));
    tex=TTF_RenderText_Solid(police1,mot,noir);
    poztex.x=poszonerech.x;
    poztex.y=poszonerech.y;
     
    while (continuer){
    SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0, 0, 0));
    if(newecran==0){
     
     
    SDL_BlitSurface(ajout, NULL, ecran, &posajout);
    SDL_BlitSurface(texajout, NULL, ecran, &posajout);
    SDL_BlitSurface(supprime, NULL, ecran, &possup);
    SDL_BlitSurface(texsuppr, NULL, ecran, &possup);
    SDL_BlitSurface(sauver, NULL, ecran, &possauver);
    SDL_BlitSurface(texsauver, NULL, ecran, &possauver);
    SDL_BlitSurface(ajour, NULL, ecran, &posajour);
    SDL_BlitSurface(texajour, NULL, ecran, &posajour);
    SDL_BlitSurface(zonerech, NULL, ecran, &poszonerech);
     
    SDL_BlitSurface(recherche, NULL, ecran, &posrecherch);
    SDL_BlitSurface(texrecherche, NULL, ecran, &posrecherch);
    SDL_BlitSurface(zoneaffichage, NULL, ecran, &poszonafich);
    SDL_BlitSurface(tex,NULL,ecran, &poztex);
     
    SDL_Flip(ecran);//Mise à jour de l'écran avec sa nouvelle couleur
     
      SDL_Event event;//pour gerer les événements
     
                           SDL_WaitEvent(&event);
                           char c;
                                     switch (event.type){
                                             case SDL_QUIT    :
                                                 continuer = 0;break;
                                             case SDL_KEYDOWN : switch(event.key.keysym.sym){
                                                                                                    case SDLK_ESCAPE   :
                                                                                                            continuer=0; break;
                                                                                                    case SDLK_SPACE :
                                                                                                           c = ' '; mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_a :
                                                                                                           c = 'Q'; mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_b :
                                                                                                           c = 'B'; mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_c :
                                                                                                        c = 'C'; mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_d :
                                                                                                        c = 'D';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_e :
                                                                                                        c = 'E';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_f :
                                                                                                        c = 'F';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_g :
                                                                                                        c = 'G';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_h :
                                                                                                        c = 'H';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_i :
                                                                                                        c = 'I';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_j :
                                                                                                        c = 'J';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_k :
                                                                                                        c = 'K';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_l :
                                                                                                           c = 'L';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_m :
                                                                                                           c = 'M';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_n :
                                                                                                           c = 'N';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_o :
                                                                                                           c = 'O';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_p :
                                                                                                           c = 'P';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_q :
                                                                                                           c = 'A';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_r :
                                                                                                           c = 'R';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_s :
                                                                                                           c = 'S';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_t :
                                                                                                           c = 'T';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_u :c = 'U';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_v :
                                                                                                           c = 'V';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_w :
                                                                                                           c = 'Z';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_x :
                                                                                                           c = 'X';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_y :
                                                                                                           c = 'Y';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
     
                                                                                                    case SDLK_z :
                                                                                                           c = 'W';mot[j++]=c;
                                                                                                         tex = TTF_RenderText_Blended(police1,mot,noir);
     
                                                                                                         break;
                                                                                                     case SDLK_BACKSPACE :
                                                                                                            if (strlen(mot) >=1){
                                                                                                                mot[strlen(mot)-1]=0;
                                                                                                                tex = TTF_RenderText_Blended(police1,mot,noir);
                                                                                                                            };break;
                                                                                                     default : continuer=1;break;
     
                                                                };break;
     
     
                                             case SDL_MOUSEBUTTONUP:
                                                  if (event.button.button == SDL_BUTTON_LEFT)
                                                  {
                                                    if (((event.button.x >= posajout.x ) && (event.button.x <= posajout.x + 105))
                                                        && ((event.button.y >= posajout.y) && (event.button.y <= posajout.y + 30))) //Lorsque l'on se trouve au niveau du bouton ajouter
                                                              newecran=1;
                                                    if (((event.button.x >= possup.x ) && (event.button.x <= possup.x + 130))
                                                        && ((event.button.y >= possup.y) && (event.button.y <= possup.y + 30)))  //Lorsque l'on se trouve au niveau du bouton supprimer
                                                            newecran=2;
                                                    if (((event.button.x >= possauver.x ) && (event.button.x <= possauver.x + 160))
                                                        && ((event.button.y >= possauver.y) && (event.button.y <= possauver.y + 30))) //Lorsque l'on se trouve au niveau du bouton sauvegarder
                                                            continuer=0;
                                                    if (((event.button.x >= posajour.x ) && (event.button.x <= posajour.x + 150))
                                                        && ((event.button.y >= posajour.y) && (event.button.y <= posajour.y + 30))) //Lorsque l'on se trouve au niveau du bouton mise à jour
                                                            continuer=0;
     
                                                    if (((event.button.x >= posrecherch.x ) && (event.button.x <= posrecherch.x + 143))
                                                        && ((event.button.y >= posrecherch.y) && (event.button.y <= posrecherch.y + 30))) //Lorsque l'on se trouve au niveau du bouton rechercher
                                                            continuer=0;
                                                  };break;
                                                }
     
     
    }
     
          if(newecran==1){
            SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0,0,0));
            SDL_BlitSurface(ajout, NULL, ecran, &posajout);
            SDL_BlitSurface(texajout, NULL, ecran, &posajout);
     
            motdef = SDL_CreateRGBSurface(SDL_HWSURFACE, 165,30,32,0,0,0,0);
            pozmotdef.x= 15;
            pozmotdef.y= 70;
            SDL_FillRect(motdef, NULL, SDL_MapRGB(ecran->format, 12,19,45));
            SDL_BlitSurface(motdef, NULL, ecran, &pozmotdef);
            pozmotdef.x = 16;
            pozmotdef.y = 72;
            SDL_BlitSurface(texmotdef, NULL, ecran, &pozmotdef);
     
            defmot = SDL_CreateRGBSurface(SDL_HWSURFACE, 174,30,32,0,0,0,0);
            pozdefmot.x= 350;
            pozdefmot.y= 70;
            SDL_FillRect(defmot, NULL, SDL_MapRGB(ecran->format, 12,19,45));
            SDL_BlitSurface(defmot, NULL, ecran, &pozdefmot);
            pozmotdef.x = 292;
            pozmotdef.y = 72;
            SDL_BlitSurface(texdefmot, NULL, ecran, &pozdefmot);
     
            ecranmot = SDL_CreateRGBSurface(SDL_HWSURFACE, 200,45,32,0,0,0,0);
            pozmot.x= 15;
            pozmot.y= 120;
            SDL_FillRect(ecranmot, NULL, SDL_MapRGB(ecran->format, 255,255,255));
            SDL_BlitSurface(ecranmot, NULL, ecran, &pozmot);
     
            ecrandef = SDL_CreateRGBSurface(SDL_HWSURFACE, 300,150,32,0,0,0,0);
            pozdef.x= 350;
            pozdef.y= 120;
            SDL_FillRect(ecrandef, NULL, SDL_MapRGB(ecran->format, 255,255,255));
            SDL_BlitSurface(ecrandef, NULL, ecran, &pozdef);
     
            ajouter = SDL_CreateRGBSurface(SDL_HWSURFACE, 140,30,32,0,0,0,0);
            pozajouter.x= 700;
            pozajouter.y= 70;
            SDL_FillRect(ajouter, NULL, SDL_MapRGB(ecran->format, 12,19,45));
            SDL_BlitSurface(ajouter, NULL, ecran, &pozajouter);
            pozajouter.x = 702;
            pozajouter.y = 72;
            SDL_BlitSurface(texajouter, NULL, ecran, &pozajouter);
     
            SDL_Flip(ecran);
     
              SDL_Event event;
              SDL_WaitEvent(&event);
               switch (event.type)
                    {
     
                    case SDL_QUIT : continuer = 0; break;
     
                    case SDL_KEYDOWN : switch(event.key.keysym.sym)
                                            {
                                                case SDLK_ESCAPE   :
                                                    continuer=0; break;
                                                case SDLK_BACKSPACE:
                                                    newecran=0;break;
                                                default :
                                                    continuer=1;break;
                                            }
     
                    case SDL_MOUSEBUTTONUP : if (event.button.button == SDL_BUTTON_LEFT)
                                                {
                                                if(((event.button.x>=pozajouter.x ) &&(event.button.x <= pozajouter.x + 140))
                                                   &&((event.button.y>=pozajouter.y ) &&(event.button.y <= pozajouter.y + 30)))
                                                    newecran=0;
                                                } break;
     
                    }
          }
     
            if(newecran==2){
                SDL_FillRect(ecran, NULL, SDL_MapRGB(ecran->format, 0,0,0));
            SDL_BlitSurface(supprime, NULL, ecran, &possup);
            SDL_BlitSurface(texsuppr, NULL, ecran, &possup);
     
            motdef = SDL_CreateRGBSurface(SDL_HWSURFACE, 165,30,32,0,0,0,0);
            pozmotdef.x= 15;
            pozmotdef.y= 70;
            SDL_FillRect(motdef, NULL, SDL_MapRGB(ecran->format, 12,19,45));
            SDL_BlitSurface(motdef, NULL, ecran, &pozmotdef);
            pozmotdef.x = 16;
            pozmotdef.y = 72;
            SDL_BlitSurface(texmotdef, NULL, ecran, &pozmotdef);
     
            defmot = SDL_CreateRGBSurface(SDL_HWSURFACE, 174,30,32,0,0,0,0);
            pozdefmot.x= 350;
            pozdefmot.y= 70;
            SDL_FillRect(defmot, NULL, SDL_MapRGB(ecran->format, 12,19,45));
            SDL_BlitSurface(defmot, NULL, ecran, &pozdefmot);
            pozmotdef.x = 292;
            pozmotdef.y = 72;
            SDL_BlitSurface(texdefmot, NULL, ecran, &pozdefmot);
     
            ecranmot = SDL_CreateRGBSurface(SDL_HWSURFACE, 200,45,32,0,0,0,0);
            pozmot.x= 15;
            pozmot.y= 120;
            SDL_FillRect(ecranmot, NULL, SDL_MapRGB(ecran->format, 255,255,255));
            SDL_BlitSurface(ecranmot, NULL, ecran, &pozmot);
     
            ecrandef = SDL_CreateRGBSurface(SDL_HWSURFACE, 300,150,32,0,0,0,0);
            pozdef.x= 350;
            pozdef.y= 120;
            SDL_FillRect(ecrandef, NULL, SDL_MapRGB(ecran->format, 255,255,255));
            SDL_BlitSurface(ecrandef, NULL, ecran, &pozdef);
     
            supprimer = SDL_CreateRGBSurface(SDL_HWSURFACE, 155,30,32,0,0,0,0);
            pozsupprimer.x= 700;
            pozsupprimer.y= 70;
            SDL_FillRect(supprimer, NULL, SDL_MapRGB(ecran->format, 12,19,45));
            SDL_BlitSurface(supprimer, NULL, ecran, &pozsupprimer);
            pozsupprimer.x = 702;
            pozsupprimer.y = 72;
            SDL_BlitSurface(texsupprimer, NULL, ecran, &pozsupprimer);
     
            SDL_Flip(ecran);
     
              SDL_Event event;
              SDL_WaitEvent(&event);
               switch (event.type)
                    {
     
                    case SDL_QUIT : continuer = 0; break;
     
                    case SDL_KEYDOWN : switch(event.key.keysym.sym)
                                            {
                                                case SDLK_ESCAPE   :
                                                    continuer=0; break;
                                                case SDLK_BACKSPACE:
                                                    newecran=0;break;
                                                default :
                                                    continuer=1;
                                            }
     
                    case SDL_MOUSEBUTTONUP : if (event.button.button == SDL_BUTTON_LEFT)
                                                {
                                                if(((event.button.x>=pozsupprimer.x ) &&(event.button.x <= pozsupprimer.x + 140))
                                                   &&((event.button.y>=pozsupprimer.y ) &&(event.button.y <= pozsupprimer.y + 30)))
                                                    newecran=0;
                                                } break;
     
                    }
            }
     
     
    }
     
     
    SDL_FreeSurface(ajout);
    SDL_FreeSurface(ajouter);
    SDL_FreeSurface(supprime);
    SDL_FreeSurface(sauver);
    SDL_FreeSurface(ajour);
    SDL_FreeSurface(zonerech);
    SDL_FreeSurface(recherche);
    SDL_FreeSurface(zoneaffichage);
    SDL_FreeSurface(ecranmot);
    SDL_FreeSurface(ecrandef);
    SDL_FreeSurface(motdef);
    SDL_FreeSurface(defmot);
    SDL_FreeSurface(supprimer);
    SDL_FreeSurface(tex);
    SDL_FreeSurface(texsupprimer);
    SDL_FreeSurface(texajout);
    SDL_FreeSurface(texajouter);
    SDL_FreeSurface(texsuppr);
    SDL_FreeSurface(texsauver);
    SDL_FreeSurface(texajour);
    SDL_FreeSurface(texrecherche);
    SDL_FreeSurface(texmotdef);
    SDL_FreeSurface(texdefmot);
     
     
    TTF_CloseFont(police);
    TTF_Quit();
    SDL_Quit();
    return EXIT_SUCCESS;
    }
    Fichiers attachés Fichiers attachés
    • Type de fichier : c main.c (28,1 Ko, 147 affichages)

  6. #6
    Expert confirmé
    Avatar de Kannagi
    Homme Profil pro
    cyber-paléontologue
    Inscrit en
    Mai 2010
    Messages
    3 226
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 37
    Localisation : France, Bouches du Rhône (Provence Alpes Côte d'Azur)

    Informations professionnelles :
    Activité : cyber-paléontologue

    Informations forums :
    Inscription : Mai 2010
    Messages : 3 226
    Par défaut
    C'est rien de mechant , mais personnellement je trouve cela assez dérangeant de lire chaqu'une de tes phrases finissant avec un point exclamation.
    le second tu peux effacer ton post , je pense que le mieux c'est de laisser seulement en fichier attaché main.c

    Alors le code est horrible , et j'ai pas vraiment le temps de faire apprendre le C (enfin normalement tu l'apprend) et comment on utilise correctement la SDL (et non le SdZ sur ce coup n'est pas un référence).

    Donc tu en gros t'aura ta chaine de caractère ça donnera ça

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
     
    SDL_Surface *image = TTF_RenderText_Blended(police, recup_texte, couleur);
    SDL_BlitSurface(image, NULL, ecran, &position);
    SDL_FreeSurface(image);
    et après tu enregistre avec fopen ect.


    Alors le code source n’espère même pas que je t'aide a rajouter sur ce torchon code , il y a de grosse erreur déjà une assez grave y 'a des fuite de mémoire.
    Par exemple :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    case SDLK_z :
    c = 'W';mot[j++]=c;
     tex = TTF_RenderText_Blended(police1,mot,noir);
    tex n'est jamais libere donc fuite de mémoire , l'algo est mal pensé aussi , il faut un peu réfléchir avant de coder je sais pas comment note ton prof mais si moi je devais corriger un truc comme ça je lui mettrais pas plus de 5 que ça fonctionne ou pas.
    ->récupérer une chaine de caractère et ensuite afficher avec TTF_RenderText , t'as que des avantage , un c'est plus rapide tu appelle que une fois (en faite a chaque ligne) TTF_RenderText et c'est plus facile a gerer.

    Je rajouterai pas plus , y a vraiment tout le code a revoir , cela ce voit que tu code sans vraiment savoir ce que tu fait.

    Pour résumer tu dois pas afficher caractère par caractère mais seulement avec les événements une chaine de caractère , ensuite cette chaine tu écris ton un fichier , le chargement c'est pareil.
    Et pour qu'on se comprenne bien , c'est un petit projet certes mais qui demande une certaine organisation et d'aller par étape et donc avec un code pareil tu vas pas aller tres loin , il faut un minimum de fonction pour que le code soit facile a faire , c'est possible de hardcoder mais en plus du t'y prend mal , tu pourrait par exemple faire un tableau et tu préfère écrire toute tes variables.

  7. #7
    Futur Membre du Club
    Homme Profil pro
    ébéniste
    Inscrit en
    Mai 2014
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 31
    Localisation : France, Vienne (Poitou Charente)

    Informations professionnelles :
    Activité : ébéniste
    Secteur : Bâtiment Travaux Publics

    Informations forums :
    Inscription : Mai 2014
    Messages : 3
    Par défaut
    je te conseille d'utiliser ses fonctions :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    /* Create a 32-bit ARGB surface and render the given text at high quality,
       using alpha blending to dither the font with the given color.
       Text is wrapped to multiple lines on line endings and on word boundaries
       if it extends beyond wrapLength in pixels.
       This function returns the new surface, or NULL if there was an error.
    */
    extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderText_Blended_Wrapped(TTF_Font *font,
                    const char *text, SDL_Color fg, Uint32 wrapLength);
    extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUTF8_Blended_Wrapped(TTF_Font *font,
                    const char *text, SDL_Color fg, Uint32 wrapLength);
    extern DECLSPEC SDL_Surface * SDLCALL TTF_RenderUNICODE_Blended_Wrapped(TTF_Font *font,
                    const Uint16 *text, SDL_Color fg, Uint32 wrapLength);
    elles ne sont pas dans la doc, (pas à jour je pense)

    elles te permettent d'afficher tout un texte. tu lui fournis un ton buffer avec tout ton texte. et elle t'affiche le texte en sautant les lignes a chaque "\n" et quand la largeur donnée est atteinte. c'est magique tu verras !

Discussions similaires

  1. Réponses: 4
    Dernier message: 31/08/2009, 11h37
  2. Afficher le contenu d'un fichier texte sous GWT
    Par ben38360 dans le forum GWT et Vaadin
    Réponses: 3
    Dernier message: 27/10/2008, 11h30
  3. Afficher le contenu d'un fichier TEXT dans une edit
    Par darkman13130 dans le forum C++Builder
    Réponses: 1
    Dernier message: 06/06/2008, 16h41
  4. Afficher le contenu d'un fichier text
    Par cmon_compte dans le forum VB 6 et antérieur
    Réponses: 6
    Dernier message: 30/04/2008, 16h25
  5. Réponses: 1
    Dernier message: 12/02/2003, 09h36

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo