From ecbcb3afe875ce6c3b74ef12b138a5cb275fecab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Rib=C3=A9mont?= Date: Mon, 31 Jan 2022 09:36:53 +0100 Subject: [PATCH 1/4] freeTexture --- Pontu/include/engine/Button.h | 16 +++------------- Pontu/src/engine/Button.c | 5 +++++ 2 files changed, 8 insertions(+), 13 deletions(-) diff --git a/Pontu/include/engine/Button.h b/Pontu/include/engine/Button.h index 55ec0f3..1e7be9c 100644 --- a/Pontu/include/engine/Button.h +++ b/Pontu/include/engine/Button.h @@ -61,19 +61,9 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button); bool isHover(P_Button* button, int x,int y);// dit si le bouton est survolé en donnant les coordonnées x,y /** - * \brief Change the texture of the button - * \param[in] button the button target - * \param[in] texture the texture you want to apply to the button - * \return false if the texture is NULL - */ -bool changeButtonTexture(P_Button* button, SDL_Texture* texture); - -/** - * \brief Change the texture to use when the button is hovered - * \param[in] button the button target - * \param[in] texture the texture you want to apply to the button - * \return false if the texture is NULL + * \brief Free the texture of a button. + * \param[in] button the button you want to destroy the texture */ -bool changeButtonHoverTexture(P_Button* button, SDL_Texture* texture); +void freeButton(P_Button * button); #endif diff --git a/Pontu/src/engine/Button.c b/Pontu/src/engine/Button.c index 25dc168..2b0f9b2 100644 --- a/Pontu/src/engine/Button.c +++ b/Pontu/src/engine/Button.c @@ -55,3 +55,8 @@ bool changeButtonHoverTexture(P_Button* button, SDL_Texture* texture) button->hoverTexture = texture; return true; } + +void freeButton(P_Button * button){ + SDL_DestroyTexture(button->texture); + SDL_DestroyTexture(button->textureHover); +} From 247e365eeaf82579122118bab8c6bb10b2a9e707 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Rib=C3=A9mont?= Date: Mon, 31 Jan 2022 09:40:09 +0100 Subject: [PATCH 2/4] correct mistake --- Pontu/src/engine/Button.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Pontu/src/engine/Button.c b/Pontu/src/engine/Button.c index 2b0f9b2..d2cbe4c 100644 --- a/Pontu/src/engine/Button.c +++ b/Pontu/src/engine/Button.c @@ -58,5 +58,5 @@ bool changeButtonHoverTexture(P_Button* button, SDL_Texture* texture) void freeButton(P_Button * button){ SDL_DestroyTexture(button->texture); - SDL_DestroyTexture(button->textureHover); + SDL_DestroyTexture(button->hoverTexture); } From 0fe213d648e4e2cd8088d440f6d4daeee9ff990a Mon Sep 17 00:00:00 2001 From: Allan POINT Date: Mon, 31 Jan 2022 09:46:12 +0100 Subject: [PATCH 3/4] Add commons collors --- Pontu/src/engine/Colors.h | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 Pontu/src/engine/Colors.h diff --git a/Pontu/src/engine/Colors.h b/Pontu/src/engine/Colors.h new file mode 100644 index 0000000..f90f370 --- /dev/null +++ b/Pontu/src/engine/Colors.h @@ -0,0 +1,11 @@ +#ifndef COLORS_H_INCLUDED +#define COLORS_H_INCLUDED + +#include + +const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND = {225, 225, 225, 255}; +const SDL_Color COLOR_GENERIC_BUTTON_BORDER = {10, 10, 10, 255}; + + +#endif + From 63b9f0a9a6300f2e43212e22179fa1f67f98fdcc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mathis=20Rib=C3=A9mont?= Date: Mon, 31 Jan 2022 09:46:50 +0100 Subject: [PATCH 4/4] maine menu avec lenna bg --- Pontu/src/view/MainMenu.c | 24 +++++++++++++++++------- Pontu/test/testDrawMainMenu.c | 19 +++++++++---------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/Pontu/src/view/MainMenu.c b/Pontu/src/view/MainMenu.c index b2d972c..4394f9a 100644 --- a/Pontu/src/view/MainMenu.c +++ b/Pontu/src/view/MainMenu.c @@ -10,38 +10,48 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns *nb = 0; SDL_Color lightBlue = {.r = 0,.g = 195,.b = 255,.a = 0}; //0, 195, 255 SDL_Color darkBlue = {.r = 0,.g = 123,.b = 161,.a = 0}; //0, 123, 161 + char* path = "../rsrc/img/Lenna.png"; SDL_SetRenderTarget(renderer, NULL); TTF_Font* font = fontHandler.fonts[FONT_retro]; int fontSize = 80; - *nb = (*nb)+1; + *nb = 3; buttons = (P_Button*)malloc(sizeof(P_Button)*(*nb)); buttons[0] = createButton(NULL,NULL,20, 20, 20, 20, NULL); - SDL_Texture* newGameButtonTexture = createGenericButtonTexture("Nouvelle Partie",font,fontSize,darkBlue,lightBlue,3, 3,&(buttons[0].rect.w),&(buttons[0].rect.h),renderer); - SDL_Texture* newGameButtonTextureHover = createGenericButtonTexture("Nouvelle Partie",font,fontSize,lightBlue,darkBlue,3, 3,NULL,NULL,renderer); + SDL_Texture* newGameButtonTexture = createGenericButtonTexture("Nouvelle Partie",font,fontSize,darkBlue,lightBlue,5, 10,&(buttons[0].rect.w),&(buttons[0].rect.h),renderer); + SDL_Texture* newGameButtonTextureHover = createGenericButtonTexture("Nouvelle Partie",font,fontSize,lightBlue,darkBlue,5, 10,NULL,NULL,renderer); buttons[0].texture = newGameButtonTexture; buttons[0].hoverTexture = newGameButtonTextureHover; + buttons[0].rect.x = (windowSize->w/2)-(buttons[0].rect.w/2); + buttons[1] = createButton(NULL,NULL,20, buttons[0].rect.y+buttons[0].rect.h+20, 20, 20, NULL); - SDL_Texture* optionButtonTexture = createGenericButtonTexture("Option",font,fontSize,darkBlue,lightBlue,3, 3,&(buttons[1].rect.w),&(buttons[1].rect.h),renderer); - SDL_Texture* optionButtonTextureHover = createGenericButtonTexture("Option",font,fontSize,lightBlue,darkBlue,3, 3,NULL,NULL,renderer); + SDL_Texture* optionButtonTexture = createGenericButtonTexture("Options",font,fontSize,darkBlue,lightBlue,5, 10,&(buttons[1].rect.w),&(buttons[1].rect.h),renderer); + SDL_Texture* optionButtonTextureHover = createGenericButtonTexture("Options",font,fontSize,lightBlue,darkBlue,5, 10,NULL,NULL,renderer); buttons[1].texture = optionButtonTexture; buttons[1].hoverTexture = optionButtonTextureHover; + buttons[1].rect.x = (windowSize->w/2)-(buttons[1].rect.w/2); buttons[2] = createButton(NULL,NULL,20, buttons[1].rect.y+buttons[1].rect.h+20, 20, 20, quit); - SDL_Texture* quitButtonTexture = createGenericButtonTexture("Quitter",font,fontSize,darkBlue,lightBlue,3, 3,&(buttons[2].rect.w),&(buttons[2].rect.h),renderer); - SDL_Texture* quitButtonTextureHover = createGenericButtonTexture("Quitter",font,fontSize,lightBlue,darkBlue,3, 3,NULL,NULL,renderer); + SDL_Texture* quitButtonTexture = createGenericButtonTexture("Quitter",font,fontSize,darkBlue,lightBlue,5, 10,&(buttons[2].rect.w),&(buttons[2].rect.h),renderer); + SDL_Texture* quitButtonTextureHover = createGenericButtonTexture("Quitter",font,fontSize,lightBlue,darkBlue,5, 10,NULL,NULL,renderer); buttons[2].texture = quitButtonTexture; buttons[2].hoverTexture = quitButtonTextureHover; + buttons[2].rect.x = (windowSize->w/2)-(buttons[2].rect.w/2); + + SDL_SetRenderTarget(renderer,NULL); + SDL_Texture* picture = createTextureFromPath(renderer, path); + SDL_RenderCopy(renderer, picture, NULL, NULL); + SDL_RenderPresent(renderer); return buttons; } diff --git a/Pontu/test/testDrawMainMenu.c b/Pontu/test/testDrawMainMenu.c index 5395ee4..6308809 100644 --- a/Pontu/test/testDrawMainMenu.c +++ b/Pontu/test/testDrawMainMenu.c @@ -9,6 +9,7 @@ int testDrawMainMenu(){ SDL_Window *window = NULL; SDL_Renderer *renderer = NULL; int statut = EXIT_FAILURE; + char* path = "../rsrc/img/Lenna.png"; if(0 != SDL_Init(SDL_INIT_VIDEO)) { @@ -43,17 +44,20 @@ int testDrawMainMenu(){ unsigned int nb = 0; FontHandler fontHandler = loadFonts(); - int window_w, window_h; - SDL_GetWindowSize(window,&window_w,&window_h); + //récupère le numéro de l'écran + SDL_DisplayMode current; + int i = SDL_GetWindowDisplayIndex(window); + SDL_GetCurrentDisplayMode(i, ¤t); //retourne current, structure avec vrai valeurs de taille de fenêtre - SDL_Rect rect = {.x = 0, .y = 0, .w = window_w, .h = window_h}; + SDL_SetRenderDrawColor(renderer, 0,0,0,0); + SDL_RenderClear(renderer); + + SDL_Rect rect = {.x = 0, .y = 0, .w = current.w, .h = current.h}; if(!(buttons = drawMainMenu(renderer,fontHandler,&nb,&rect))){ fprintf(stderr, "Le menu principale ne s'est pas déssiné correctement\n"); return statut; } - SDL_SetRenderDrawColor(renderer, 0,0,0,0); - SDL_RenderClear(renderer); bool quit = false; SDL_Event event; buttons[2].arg = &quit; @@ -82,11 +86,6 @@ int testDrawMainMenu(){ break; } } - - /*for(int i=0;i