isButtonEntry pour l'entrée du curseur dans le bouton + bruit au bouton hover

origin/fixingSettings
Mathis RIBEMONT 4 years ago
parent 2a194aa4fd
commit f0c2995733

@ -37,16 +37,17 @@ int main(int argc, char const *argv[]) {
exit(2); exit(2);
} }
FontHandler fontHandler = loadFonts(); FontHandler fontHandler = loadFonts();
AudioHandler audioHandler = newAudioHandler(128, 128, 128);
generalState = GS_MainMenu; generalState = GS_MainMenu;
while(generalState != GS_Quit){ while(generalState != GS_Quit){
switch (generalState) { switch (generalState) {
case GS_MainMenu: case GS_MainMenu:
mainMenu(renderer,window,&generalState, fontHandler); mainMenu(renderer,window,&generalState, fontHandler, audioHandler);
break; break;
case GS_EndOfGameMenu:// Coupler avec le menu de jeu /*case GS_EndOfGameMenu:// Coupler avec le menu de jeu
endGameMenu(&generalState, window, renderer, fontHandler, NULL, 0); endGameMenu(&generalState, window, renderer, fontHandler, NULL, 0);
break; break;*/
} }
} }

@ -31,7 +31,8 @@
* \sa #MACRO_FOR_ALL_MUSICS(M) * \sa #MACRO_FOR_ALL_MUSICS(M)
*/ */
#define MACRO_FOR_ALL_SFX(M) \ #define MACRO_FOR_ALL_SFX(M) \
M(testClick) M(testClick) \
M(menu_sound_effect)
/** /**
* Macro used to generate the entries for the musics in #EnumAudios. * Macro used to generate the entries for the musics in #EnumAudios.

@ -58,7 +58,9 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button);
* \param[in] y y of the point * \param[in] y y of the point
* \return SDL_TRUE if the point is on the button * \return SDL_TRUE if the point is on the button
*/ */
bool isHover(P_Button* button, int x,int y);// dit si le bouton est survolé en donnant les coordonnées x,y bool isHover(P_Button* button);// dit si le bouton est survolé en donnant les coordonnées x,y
bool isButtonEntry(P_Button * button,const int x,const int y);
/** /**
* \brief Free the texture of a button. * \brief Free the texture of a button.

@ -7,9 +7,10 @@
#include "engine/TextureLoader.h" #include "engine/TextureLoader.h"
#include "engine/FontLoader.h" #include "engine/FontLoader.h"
#include "engine/GeneralState.h" #include "engine/GeneralState.h"
#include "engine/AudioHandler.h"
P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize); P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, unsigned int* nb, const SDL_Rect* windowSize);
int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler); int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler);
#endif #endif

@ -2,7 +2,7 @@
// A channel represents the number of SFX we can play at the same time. // A channel represents the number of SFX we can play at the same time.
// We normally should use only 1 channel, and we add one for safety. // We normally should use only 1 channel, and we add one for safety.
#define NBCHANNELS 2 #define NBCHANNELS 10
// Local functions // Local functions
@ -196,4 +196,3 @@ void playSFX(EnumAudios sfx, AudioHandler audioHandler) {
return; return;
} }
} }

@ -27,12 +27,8 @@ bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button)
return true; return true;
} }
bool isHover(P_Button* button,const int x,const int y) bool isHover(P_Button* button)
{ {
SDL_Point coord;
coord.x = x;
coord.y = y;
button->hover = SDL_PointInRect(&coord,&(button->rect));
return button->hover && button->drawn; return button->hover && button->drawn;
} }
@ -60,3 +56,15 @@ void freeButton(P_Button * button){
SDL_DestroyTexture(button->texture); SDL_DestroyTexture(button->texture);
SDL_DestroyTexture(button->hoverTexture); SDL_DestroyTexture(button->hoverTexture);
} }
bool isButtonEntry(P_Button * button,const int x,const int y){
SDL_Point coord;
coord.x = x;
coord.y = y;
if(isHover(button)){
button->hover = SDL_PointInRect(&coord,&(button->rect));
return false;
}
button->hover = SDL_PointInRect(&coord,&(button->rect));
return button->hover;
}

@ -81,11 +81,10 @@ InputElement proccessGameInput(GameInputProcessor *gameInputProcessor, const SDL
{ {
for (size_t i = 0; i<gameInputProcessor->tabButton.size; ++i) { for (size_t i = 0; i<gameInputProcessor->tabButton.size; ++i) {
P_Button* b = &gameInputProcessor->tabButton.elems[i]; P_Button* b = &gameInputProcessor->tabButton.elems[i];
isHover(b, event.motion.x, event.motion.y); isButtonEntry(b, event.motion.x, event.motion.y);
} }
} }
} }
return createInputElementNone(); return createInputElementNone();
} }

@ -39,7 +39,7 @@ InputElement proccessInput(InputProcessor *inputProcessor)
{ {
for (size_t i = 0; i<inputProcessor->tabButton.size; ++i) { for (size_t i = 0; i<inputProcessor->tabButton.size; ++i) {
P_Button* b = &inputProcessor->tabButton.elems[i]; P_Button* b = &inputProcessor->tabButton.elems[i];
isHover(b, event.motion.x, event.motion.y); isButtonEntry(b, event.motion.x, event.motion.y);
} }
break; break;
} }
@ -47,4 +47,3 @@ InputElement proccessInput(InputProcessor *inputProcessor)
return createInputElementNone(); return createInputElementNone();
} }

@ -63,7 +63,7 @@ P_Button* drawMainMenu(SDL_Renderer* renderer,const FontHandler fontHandler, uns
return buttons; return buttons;
} }
int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler){ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * generalState,FontHandler fontHandler, AudioHandler audioHandler){
int statut = EXIT_FAILURE; int statut = EXIT_FAILURE;
char* path = "../rsrc/img/Lenna.png"; char* path = "../rsrc/img/Lenna.png";
//Initialisation //Initialisation
@ -92,17 +92,20 @@ int mainMenu(SDL_Renderer * renderer,SDL_Window * window, GeneralState * general
*generalState = GS_Quit; *generalState = GS_Quit;
break; break;
case SDL_MOUSEBUTTONUP: case SDL_MOUSEBUTTONUP:
if(isHover(buttons,event.button.x,event.button.y)) if(isHover(buttons))
printf("Nouvelle partie\n"); printf("Nouvelle partie\n");
if(isHover(&(buttons[2]),event.motion.x,event.motion.y)){ if(isHover(&(buttons[2]))){
buttons[2].onClick(&(buttons[2])); buttons[2].onClick(&(buttons[2]));
break; break;
} }
break; break;
case SDL_MOUSEMOTION: case SDL_MOUSEMOTION:
isHover(&(buttons[0]),event.motion.x,event.motion.y); if(isButtonEntry(&(buttons[0]),event.motion.x,event.motion.y) ||
isHover(&(buttons[1]),event.motion.x,event.motion.y); isButtonEntry(&(buttons[1]),event.motion.x,event.motion.y) ||
isHover(&(buttons[2]),event.motion.x,event.motion.y); isButtonEntry(&(buttons[2]),event.motion.x,event.motion.y)){
playSFX(SFX_menu_sound_effect, audioHandler);
printf("True\n");
}
break; break;
default: default:
break; break;

Loading…
Cancel
Save