From 590695437814a4d3095319b116cb3d0057a9411b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 24 Mar 2022 16:41:33 +0100 Subject: [PATCH 1/7] new save --- model.c | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/model.c b/model.c index 151ba1a..0ac9d4e 100644 --- a/model.c +++ b/model.c @@ -29,6 +29,7 @@ #define WIN "win.mp3" #define FONT "Roboto-Regular.ttf" #define NB_MUSIC 10 +#define NB_BUTTONS 5 #define FONTSIZE 200 #ifdef __ANDROID__ @@ -92,17 +93,20 @@ struct Env_t { SDL_Texture** text_undo; SDL_Texture** text_redo; SDL_Texture** text_solve; + SDL_Texture** text_save; bool pressed_restart; bool pressed_undo; bool pressed_redo; bool pressed_solve; + bool pressed_save; SDL_Texture* victory; SDL_Texture* move_to_quit; + SDL_Rect* rec_game; // rectangle of the grid SDL_Rect* rec_redo; // rectangle of each buttons SDL_Rect* rec_undo; SDL_Rect* rec_restart; SDL_Rect* rec_solve; - SDL_Rect* rec_game; // rectangle of the grid + SDL_Rect* rec_save; Mix_Music** lb_music; uint lb_music_cpt; Mix_Music** err_music; @@ -396,21 +400,24 @@ void render(SDL_Window* win, SDL_Renderer* ren, Env* env) { env->rec_game->w = size_rec * game_nb_cols(env->g); // buttons SDL_Rect buttons; - buttons.w = w / 5; - buttons.h = h / 10 / 1.5; + buttons.w = w / NB_BUTTONS + 1; + buttons.h = h / 10 / 1.5; // 1.5 = use to keep margin around buttons buttons.y = (h / 10 - buttons.h) / 2 + marge_h; - buttons.x = (w / 4 - w / 5) / 2 + marge_w; + buttons.x = (w / NB_BUTTONS - w / NB_BUTTONS + 1) / 2 + marge_w; *(env->rec_undo) = buttons; SDL_RenderCopy(ren, env->text_undo[env->pressed_undo ? 1 : 0], NULL, &buttons); - buttons.x = buttons.x + buttons.w + (w / 4 - w / 5); + buttons.x += buttons.w + (w / NB_BUTTONS - w / NB_BUTTONS + 1); *(env->rec_redo) = buttons; SDL_RenderCopy(ren, env->text_redo[env->pressed_redo ? 1 : 0], NULL, &buttons); - buttons.x = buttons.x + buttons.w + (w / 4 - w / 5); + buttons.x += buttons.w + (w / NB_BUTTONS - w / NB_BUTTONS + 1); *(env->rec_restart) = buttons; SDL_RenderCopy(ren, env->text_restart[env->pressed_restart ? 1 : 0], NULL, &buttons); - buttons.x = buttons.x + buttons.w + (w / 4 - w / 5); + buttons.x += buttons.w + (w / NB_BUTTONS - w / NB_BUTTONS + 1); *(env->rec_solve) = buttons; SDL_RenderCopy(ren, env->text_solve[env->pressed_solve ? 1 : 0], NULL, &buttons); + buttons.x += buttons.w + (w / NB_BUTTONS - w / NB_BUTTONS + 1); + *(env->rec_save) = buttons; + SDL_RenderCopy(ren, env->text_save[env->pressed_save ? 1 : 0], NULL, &buttons); // render cases for (uint i = 0; i < game_nb_rows(env->g); i++) { for (uint j = 0; j < game_nb_cols(env->g); j++) { From 89d623fb0bfd21687b8289d94b846d2db595e4be Mon Sep 17 00:00:00 2001 From: Mohamed Fatih Date: Thu, 24 Mar 2022 17:14:24 +0100 Subject: [PATCH 2/7] opti clean --- README.md | 1 + model.c | 112 +++++++++++++++++++++++++++--------------------------- 2 files changed, 57 insertions(+), 56 deletions(-) diff --git a/README.md b/README.md index d1d8123..009dbbe 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,4 @@ Projet Techno :warning: LE PREMIER QUI COMMIT DU CODE QUI COMPILE PAS JE L'ATTRAPE :warning: +FONCTIONNEMENT INTERFACE GRAPHIQUE: diff --git a/model.c b/model.c index e70f00b..1f23615 100644 --- a/model.c +++ b/model.c @@ -15,19 +15,19 @@ /* **************************************************************** */ -#define LIGHTBULB_WHITE "lightbulb_white.png" -#define LIGHTBULB_RED "lightbulb_red.png" -#define LB1 "lb1.mp3" -#define LB2 "lb2.mp3" -#define LB3 "lb3.mp3" -#define ERR1 "error1.mp3" -#define ERR2 "error2.mp3" -#define ERR3 "error3.mp3" -#define MARK1 "mark1.wav" -#define MARK2 "mark2.wav" -#define MARK3 "mark3.wav" -#define WIN "win.mp3" -#define FONT "Roboto-Regular.ttf" +#define LIGHTBULB_WHITE "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lightbulb_white.png" +#define LIGHTBULB_RED "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lightbulb_red.png" +#define LB1 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lb1.mp3" +#define LB2 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lb2.mp3" +#define LB3 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lb3.mp3" +#define ERR1 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/error1.mp3" +#define ERR2 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/error2.mp3" +#define ERR3 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/error3.mp3" +#define MARK1 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/mark1.wav" +#define MARK2 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/mark2.wav" +#define MARK3 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/mark3.wav" +#define WIN "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/win.mp3" +#define FONT "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/Roboto-Regular.ttf" #define NB_MUSIC 10 #define FONTSIZE 200 @@ -522,19 +522,19 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb env->pressed_redo = false; env->pressed_solve = false; } else if (SDL_PointInRect(&mouse, env->rec_undo)) { - if ((*nb_coups) > 0) { + if ((*nb_coups) <= 0) { env->pressed_undo = true; + env->pressed_restart = false; + env->pressed_redo = false; + env->pressed_solve = false; } - env->pressed_restart = false; - env->pressed_redo = false; - env->pressed_solve = false; } else if (SDL_PointInRect(&mouse, env->rec_redo)) { - if ((*nb_undo) > 0) { + if ((*nb_undo) <= 0) { env->pressed_redo = true; + env->pressed_undo = false; + env->pressed_restart = false; + env->pressed_solve = false; } - env->pressed_undo = false; - env->pressed_restart = false; - env->pressed_solve = false; } else if (SDL_PointInRect(&mouse, env->rec_solve)) { env->pressed_solve = true; env->pressed_undo = false; @@ -609,44 +609,44 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb } /* **************************************************************** */ +/* +void init_musics(Mix_Music**** music_to_load, char** path_to_musics, uint nb_music, uint nb_music_per_array) { + for (uint i = 0; i < nb_music / nb_music_per_array; i++) { + *(music_to_load[i]) = malloc(sizeof(Mix_Music*) * nb_music_per_array); + for (uint j = 0; j < nb_music_per_array; j++) { + (*(music_to_load[i]))[j] = Mix_LoadMUS(path_to_musics[i * nb_music_per_array + j]); + if ((*(music_to_load[i]))[j] == NULL) + ERROR("Cannot load music %s\n", path_to_musics[i * nb_music_per_array + j]); + } + } +}*/ +void clean_destroy(SDL_Texture** tab[], uint sizePerArray, uint size_tab) { + for (uint i = 0; i < size_tab; i++) { + for (uint j = 0; j < sizePerArray; j++) { + SDL_DestroyTexture(tab[i][j]); + } + free(tab[i]); + } +} + +void freeall(SDL_Rect* tab[], uint size_tab) { + for (uint i = 0; i < size_tab; i++) { + free(tab[i]); + } +} void clean(Env* env) { game_delete(env->g); - SDL_DestroyTexture(env->zero[0]); - SDL_DestroyTexture(env->zero[1]); - free(env->zero); - SDL_DestroyTexture(env->one[0]); - SDL_DestroyTexture(env->one[1]); - free(env->one); - SDL_DestroyTexture(env->two[0]); - SDL_DestroyTexture(env->two[1]); - free(env->two); - SDL_DestroyTexture(env->three[0]); - SDL_DestroyTexture(env->three[1]); - free(env->three); - SDL_DestroyTexture(env->four[0]); - SDL_DestroyTexture(env->four[1]); - free(env->four); - SDL_DestroyTexture(env->lightbulb[0]); - SDL_DestroyTexture(env->lightbulb[1]); - free(env->lightbulb); - SDL_DestroyTexture(env->text_restart[0]); - SDL_DestroyTexture(env->text_restart[1]); - free(env->text_restart); - SDL_DestroyTexture(env->text_undo[0]); - SDL_DestroyTexture(env->text_undo[1]); - free(env->text_undo); - SDL_DestroyTexture(env->text_redo[0]); - SDL_DestroyTexture(env->text_redo[1]); - free(env->text_redo); - SDL_DestroyTexture(env->text_solve[0]); - SDL_DestroyTexture(env->text_solve[1]); - free(env->text_solve); - free(env->rec_redo); - free(env->rec_undo); - free(env->rec_restart); - free(env->rec_solve); - free(env->rec_game); + // destroy all array of array + SDL_Texture** env_tab[] = {env->zero, env->one, env->two, env->three, env->four, + env->lightbulb, env->text_redo, env->text_restart, env->text_solve, env->text_undo}; + + clean_destroy(env_tab, 2, sizeof(env_tab) / sizeof(env_tab[0])); + + SDL_Rect* free_tab[] = {env->rec_game, env->rec_redo, env->rec_restart, env->rec_solve, env->rec_undo}; + + freeall(free_tab, sizeof(free_tab) / sizeof(free_tab[0])); + for (uint i = 0; i < 3; i++) { Mix_FreeMusic(env->lb_music[i]); } From b1060ad48c210bcf9c15a063f98af6a111715ce5 Mon Sep 17 00:00:00 2001 From: Mohamed Fatih Date: Thu, 24 Mar 2022 17:21:03 +0100 Subject: [PATCH 3/7] add save in init --- model.c | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/model.c b/model.c index 68c4bcf..d4261b6 100644 --- a/model.c +++ b/model.c @@ -179,6 +179,7 @@ Env* init(SDL_Renderer* ren, int argc, char* argv[]) { env->pressed_undo = false; env->pressed_redo = false; env->pressed_solve = false; + env->pressed_save = false; PRINT("%s", "To win the game, you must satisfy the following conditions:\n\n"); PRINT("%s", "-All non-black squares are lit.\n-No light is lit by another light.\n-Each numbered black square must be orthogonally adjacent to exactly the given " @@ -192,16 +193,16 @@ Env* init(SDL_Renderer* ren, int argc, char* argv[]) { } else { usage(argv); } - void** env_tab[] = {(void**)&(env->zero), (void**)&(env->one), (void**)&(env->two), (void**)&(env->three), - (void**)&(env->four), (void**)&(env->lightbulb), (void**)&(env->text_redo), (void**)&(env->text_restart), - (void**)&(env->text_solve), (void**)&(env->text_undo), (void**)&(env->rec_game), (void**)&(env->rec_redo), - (void**)&(env->rec_restart), (void**)&(env->rec_solve), (void**)&(env->rec_undo), (void**)&(env->victory), - (void**)&(env->move_to_quit)}; + void** env_tab[] = {(void**)&(env->zero), (void**)&(env->one), (void**)&(env->two), (void**)&(env->three), + (void**)&(env->four), (void**)&(env->lightbulb), (void**)&(env->text_redo), (void**)&(env->text_restart), + (void**)&(env->text_solve), (void**)&(env->text_undo), (void**)&(env->text_save), (void**)&(env->rec_game), + (void**)&(env->rec_redo), (void**)&(env->rec_restart), (void**)&(env->rec_solve), (void**)&(env->rec_undo), + (void**)&(env->victory), (void**)&(env->move_to_quit), (void**)&(env->rec_save)}; unsigned long sizeof_env_tab[] = {sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, - sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Rect), sizeof(SDL_Rect), - sizeof(SDL_Rect), sizeof(SDL_Rect), sizeof(SDL_Rect), sizeof(SDL_Texture*), - sizeof(SDL_Texture*)}; + sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Texture*) * 2, sizeof(SDL_Rect), + sizeof(SDL_Rect), sizeof(SDL_Rect), sizeof(SDL_Rect), sizeof(SDL_Rect), + sizeof(SDL_Texture*), sizeof(SDL_Texture*), sizeof(SDL_Rect)}; init_malloc(env_tab, sizeof_env_tab, sizeof(env_tab) / sizeof(env_tab[0])); // if the case has not error env->lightbulb[0] = IMG_LoadTexture(ren, LIGHTBULB_WHITE); From 03d339c92f9d52cc72bd6cf7784dc967a16f9469 Mon Sep 17 00:00:00 2001 From: Mohamed Fatih Date: Thu, 24 Mar 2022 17:23:58 +0100 Subject: [PATCH 4/7] delete commentaires --- model.c | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/model.c b/model.c index d4261b6..fd284c1 100644 --- a/model.c +++ b/model.c @@ -620,17 +620,7 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb } /* **************************************************************** */ -/* -void init_musics(Mix_Music**** music_to_load, char** path_to_musics, uint nb_music, uint nb_music_per_array) { - for (uint i = 0; i < nb_music / nb_music_per_array; i++) { - *(music_to_load[i]) = malloc(sizeof(Mix_Music*) * nb_music_per_array); - for (uint j = 0; j < nb_music_per_array; j++) { - (*(music_to_load[i]))[j] = Mix_LoadMUS(path_to_musics[i * nb_music_per_array + j]); - if ((*(music_to_load[i]))[j] == NULL) - ERROR("Cannot load music %s\n", path_to_musics[i * nb_music_per_array + j]); - } - } -}*/ + void clean_destroy(SDL_Texture** tab[], uint sizePerArray, uint size_tab) { for (uint i = 0; i < size_tab; i++) { for (uint j = 0; j < sizePerArray; j++) { From a516dbbca5749d22a7d61f662562f7c4913f3fe9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 24 Mar 2022 18:11:31 +0100 Subject: [PATCH 5/7] forgot priority --- model.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/model.c b/model.c index 0ac9d4e..bcec154 100644 --- a/model.c +++ b/model.c @@ -400,22 +400,22 @@ void render(SDL_Window* win, SDL_Renderer* ren, Env* env) { env->rec_game->w = size_rec * game_nb_cols(env->g); // buttons SDL_Rect buttons; - buttons.w = w / NB_BUTTONS + 1; + buttons.w = w / (NB_BUTTONS + 1); buttons.h = h / 10 / 1.5; // 1.5 = use to keep margin around buttons buttons.y = (h / 10 - buttons.h) / 2 + marge_h; - buttons.x = (w / NB_BUTTONS - w / NB_BUTTONS + 1) / 2 + marge_w; + buttons.x = (w / NB_BUTTONS - w / (NB_BUTTONS + 1)) / 2 + marge_w; *(env->rec_undo) = buttons; SDL_RenderCopy(ren, env->text_undo[env->pressed_undo ? 1 : 0], NULL, &buttons); - buttons.x += buttons.w + (w / NB_BUTTONS - w / NB_BUTTONS + 1); + buttons.x += buttons.w + (w / NB_BUTTONS - w / (NB_BUTTONS + 1)); *(env->rec_redo) = buttons; SDL_RenderCopy(ren, env->text_redo[env->pressed_redo ? 1 : 0], NULL, &buttons); - buttons.x += buttons.w + (w / NB_BUTTONS - w / NB_BUTTONS + 1); + buttons.x += buttons.w + (w / NB_BUTTONS - w / (NB_BUTTONS + 1)); *(env->rec_restart) = buttons; SDL_RenderCopy(ren, env->text_restart[env->pressed_restart ? 1 : 0], NULL, &buttons); - buttons.x += buttons.w + (w / NB_BUTTONS - w / NB_BUTTONS + 1); + buttons.x += buttons.w + (w / NB_BUTTONS - w / (NB_BUTTONS + 1)); *(env->rec_solve) = buttons; SDL_RenderCopy(ren, env->text_solve[env->pressed_solve ? 1 : 0], NULL, &buttons); - buttons.x += buttons.w + (w / NB_BUTTONS - w / NB_BUTTONS + 1); + buttons.x += buttons.w + (w / NB_BUTTONS - w / (NB_BUTTONS + 1)); *(env->rec_save) = buttons; SDL_RenderCopy(ren, env->text_save[env->pressed_save ? 1 : 0], NULL, &buttons); // render cases From 95d8756d30565dff21a86fa956bb6e743c4c83dd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 24 Mar 2022 18:14:57 +0100 Subject: [PATCH 6/7] save button --- model.c | 34 +++++++++++++++++----------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/model.c b/model.c index 739f700..dbebc89 100644 --- a/model.c +++ b/model.c @@ -15,19 +15,19 @@ /* **************************************************************** */ -#define LIGHTBULB_WHITE "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lightbulb_white.png" -#define LIGHTBULB_RED "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lightbulb_red.png" -#define LB1 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lb1.mp3" -#define LB2 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lb2.mp3" -#define LB3 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/lb3.mp3" -#define ERR1 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/error1.mp3" -#define ERR2 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/error2.mp3" -#define ERR3 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/error3.mp3" -#define MARK1 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/mark1.wav" -#define MARK2 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/mark2.wav" -#define MARK3 "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/mark3.wav" -#define WIN "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/win.mp3" -#define FONT "/autofs/unitytravail/travail/mfatih001/projets2/lightup-07c/build/Roboto-Regular.ttf" +#define LIGHTBULB_WHITE "lightbulb_white.png" +#define LIGHTBULB_RED "lightbulb_red.png" +#define LB1 "lb1.mp3" +#define LB2 "lb2.mp3" +#define LB3 "lb3.mp3" +#define ERR1 "error1.mp3" +#define ERR2 "error2.mp3" +#define ERR3 "error3.mp3" +#define MARK1 "mark1.wav" +#define MARK2 "mark2.wav" +#define MARK3 "mark3.wav" +#define WIN "win.mp3" +#define FONT "Roboto-Regular.ttf" #define NB_MUSIC 10 #define NB_BUTTONS 5 #define FONTSIZE 200 @@ -235,13 +235,13 @@ Env* init(SDL_Renderer* ren, int argc, char* argv[]) { SDL_Color color_r = {255, 50, 50, 255}; /* blue color in RGBA */ SDL_Color color_b = {0, 0, 0, 255}; /* black color in RGBA*/ - char* tab_texts_double[] = {"0", "1", "2", "3", "4", "Restart", "Undo", "Redo", "Solve"}; + char* tab_texts_double[] = {"0", "1", "2", "3", "4", "Restart", "Undo", "Redo", "Solve", "Save"}; - SDL_Texture** tab_textures_double[] = {env->zero, env->one, env->two, env->three, env->four, - env->text_restart, env->text_undo, env->text_redo, env->text_solve}; + SDL_Texture** tab_textures_double[] = {env->zero, env->one, env->two, env->three, env->four, + env->text_restart, env->text_undo, env->text_redo, env->text_solve, env->text_save}; SDL_Color color_tab[] = {color_w, color_r}; - for (uint i = 0; i < 9; i++) { + for (uint i = 0; i < sizeof(tab_textures_double) / sizeof(tab_textures_double[0]); i++) { if (i > 4) { color_tab[1] = color_b; } From 966440045cf7f5235a6e14baf8c0fe12457eaf5d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophyl=20Hoguet?= Date: Thu, 24 Mar 2022 18:43:45 +0100 Subject: [PATCH 7/7] button save + effect --- model.c | 61 +++++++++++++++++++++++++++++---------------------------- 1 file changed, 31 insertions(+), 30 deletions(-) diff --git a/model.c b/model.c index dbebc89..bd76eed 100644 --- a/model.c +++ b/model.c @@ -481,6 +481,14 @@ void play_mark(uint i, uint j, Env* env) { } } +void update_pressed(Env* env, bool undo, bool redo, bool restart, bool solve, bool save) { + env->pressed_undo = undo; + env->pressed_redo = redo; + env->pressed_restart = restart; + env->pressed_solve = solve; + env->pressed_save = save; +} + bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb_coups, int* nb_undo) { int w, h; SDL_GetWindowSize(win, &w, &h); @@ -492,13 +500,17 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb if (state[SDL_SCANCODE_F11]) { ToggleFullscreen(win); } else if (state[SDL_SCANCODE_Z]) { - game_undo(env->g); - (*nb_undo)++; - (*nb_coups)--; + if ((*nb_coups) <= 0) { + game_undo(env->g); + (*nb_undo)++; + (*nb_coups)--; + } } else if (state[SDL_SCANCODE_Y]) { - game_redo(env->g); - (*nb_undo)--; - (*nb_coups)++; + if ((*nb_undo) <= 0) { + game_redo(env->g); + (*nb_undo)--; + (*nb_coups)++; + } } else if (state[SDL_SCANCODE_S]) { game_solve(env->g); (*nb_undo) = 0; @@ -528,34 +540,23 @@ bool process(SDL_Window* win, Env* env, SDL_Event* e, SDL_Event* prec_e, int* nb mouse.y = e->tfinger.y; } if (SDL_PointInRect(&mouse, env->rec_restart)) { - env->pressed_restart = true; - env->pressed_undo = false; - env->pressed_redo = false; - env->pressed_solve = false; + update_pressed(env, false, false, true, false, false); } else if (SDL_PointInRect(&mouse, env->rec_undo)) { - if ((*nb_coups) <= 0) { - env->pressed_undo = true; - env->pressed_restart = false; - env->pressed_redo = false; - env->pressed_solve = false; - } + if ((*nb_coups) <= 0) + update_pressed(env, true, false, false, false, false); + update_pressed(env, false, false, false, false, false); } else if (SDL_PointInRect(&mouse, env->rec_redo)) { - if ((*nb_undo) <= 0) { - env->pressed_redo = true; - env->pressed_undo = false; - env->pressed_restart = false; - env->pressed_solve = false; - } + if ((*nb_undo) <= 0) + update_pressed(env, false, true, false, false, false); + update_pressed(env, false, false, false, false, false); + } else if (SDL_PointInRect(&mouse, env->rec_solve)) { - env->pressed_solve = true; - env->pressed_undo = false; - env->pressed_redo = false; - env->pressed_restart = false; + update_pressed(env, false, false, false, true, false); + + } else if (SDL_PointInRect(&mouse, env->rec_save)) { + update_pressed(env, false, false, false, false, true); } else { - env->pressed_restart = false; - env->pressed_undo = false; - env->pressed_redo = false; - env->pressed_solve = false; + update_pressed(env, false, false, false, false, false); } #ifdef _ANDROID_ if (SDL_PointInRect(&mouse, env->rec_game)) {