Merge branch 'master' of gitlab.iut-clermont.uca.fr:maribemont/projet-tut

merge-requests/2/merge
thmaillarb 4 years ago
commit e923900ba7

@ -5,11 +5,11 @@
/*#include "../test/testButton.c"
#include "../test/testTextInput.c"
#include "../test/testConnectionMenu.c"*/
/*#include "../test/testMenuEndGame.c"
#include "../test/testMenuEndGame.c"
/*#include "../test/testGameInterface.c"
#include "../test/testConnectionMenu.c"*/
//#include "../test/testDrawMainMenu.c
#include "../test/testSettingsView.c"
//#include "../test/testSettingsView.c"
/*
This file is meant to be modified (used only to called other tests functions)
*/
@ -22,11 +22,11 @@ int main(int argc, char *argv[]) {
//testTextInput();
//testButtonTextureLoader();
//testConnectionMenu();
//testMenuEndGame();
testMenuEndGame();
//testGameInterface();
//testConnectionMenu();
//testDrawMainMenu();
testSettingsView();
//testSettingsView();
return 0;
}

@ -26,13 +26,13 @@
#define GENERATE_DYNAMIC_ARRAY(T) \
struct array_##T { \
T* elems; \
size_t arraySize; \
size_t arraySpace; \
size_t size; \
size_t space; \
}; \
\
/*Contruct an empty array*/\
inline struct array_##T array_##T##_Create() { \
struct array_##T array = {.elems=NULL, .arraySize=0, .arraySpace=0}; \
struct array_##T array = {.elems=NULL, .size=0, .space=0}; \
return array; \
} \
\
@ -40,44 +40,44 @@ inline struct array_##T array_##T##_Create() { \
inline void array_##T##_Free(struct array_##T* array) { \
free(array->elems); \
array->elems = NULL; \
array->arraySize = 0; \
array->arraySpace = 0; \
array->size = 0; \
array->space = 0; \
} \
\
/*Reserve space for an array*/\
inline void array_##T##_Reserve(struct array_##T* array, const size_t space) { \
array->arraySpace = space; \
array->elems = realloc(array->elems, sizeof(T)*(array->arraySpace)); \
array->space = space; \
array->elems = realloc(array->elems, sizeof(T)*(array->space)); \
if (array->elems == NULL) exit(errno); \
} \
\
/*Fit space to size for an array*/\
inline void array_##T##_FitToSize(struct array_##T* array) { \
array->arraySpace = array->arraySize; \
array->elems = realloc(array->elems, sizeof(T)*(array->arraySpace)); \
array->space = array->size; \
array->elems = realloc(array->elems, sizeof(T)*(array->space)); \
if (array->elems == NULL) exit(errno); \
} \
\
/*Add an element to an array*/\
inline void array_##T##_AddElement(struct array_##T* array, const T element) { \
++(array->arraySize); \
if (array->arraySize > array->arraySpace) { \
++(array->arraySpace); \
array->elems = realloc(array->elems, sizeof(T)*(array->arraySpace)); \
++(array->size); \
if (array->size > array->space) { \
++(array->space); \
array->elems = realloc(array->elems, sizeof(T)*(array->space)); \
if (array->elems == NULL) exit(errno); \
} \
\
array->elems[array->arraySize - 1] = element; \
array->elems[array->size - 1] = element; \
} \
\
/*Remove an element from an array*/\
inline bool array_##T##_RemoveElement(struct array_##T* array, const T element, bool (*areEqual)(const T, const T)) { \
for (size_t i=0; i<array->arraySize; ++i) { \
for (size_t i=0; i<array->size; ++i) { \
if (areEqual(array->elems[i], element)) { \
for (;i<array->arraySize-1; ++i) { \
for (;i<array->size-1; ++i) { \
array->elems[i] = array->elems[i+1]; \
} \
--(array->arraySize); \
--(array->size); \
return true; \
} \
} \
@ -86,7 +86,7 @@ inline bool array_##T##_RemoveElement(struct array_##T* array, const T element,
\
/*Check if an array contains an element*/\
inline bool array_##T##_Contains(const struct array_##T* const array, const T element, bool (*areEqual)(const T, const T)) { \
for (size_t i = 0; i < array->arraySize; i++) { \
for (size_t i = 0; i < array->size; i++) { \
if (areEqual(array->elems[i], element)) { \
return true; \
} \
@ -96,10 +96,20 @@ inline bool array_##T##_Contains(const struct array_##T* const array, const T el
\
/*Apply a function to each element in the array*/\
inline void array_##T##_Foreach(const struct array_##T* const array, void (*func)(const T)) { \
for(size_t i = 0; i<array->arraySize; ++i) { \
for(size_t i = 0; i<array->size; ++i) { \
func(array->elems[i]);\
}\
}
}\
\
/*Return last element*/\
inline T* array_##T##_First(const struct array_##T* const array) {\
return &array->elems[0];\
}\
\
/*Return last element*/\
inline T* array_##T##_Last(const struct array_##T* const array) {\
return &array->elems[array->size-1];\
}\

@ -3,8 +3,8 @@
#include <SDL2/SDL_pixels.h>
const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND = {225, 225, 225, 255};
const SDL_Color COLOR_GENERIC_BUTTON_BORDER = {10, 10, 10, 255};
extern const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND;
extern const SDL_Color COLOR_GENERIC_BUTTON_BORDER;
#endif

@ -0,0 +1,52 @@
/**
* \file GameInputProcessor.h
* \brief Define a structure, GameInputProcessor and functions to convert SDL_event to envent for Pontu
* \author Martin Rouault
* \date 06/12/2021
*/
#ifndef GAME_INPUT_PROCESSOR_INCLUDED
#define GAME_INPUT_PROCESSOR_INCLUDED
#include "engine/Button.h"
#include "engine/arrayButton.h"
#include "engine/InputElement.h"
#include "model/Coord.h"
/**
* \struct GameInputProcessor
* \brief Contains datas useful to handle input
*/
typedef struct
{
struct array_P_Button tabButton;
Coord selectedCase; ///< A case in Board (used to handle move actions) , (-1;-1) si inexistant
} GameInputProcessor;
/**
* \brief Create a new input processor
*
* \return A new input processor
*/
GameInputProcessor createGameInputProcessor();
/**
* \brief Convert a screen coord into a model Coord
*
* \param [in] point Screen coordinates
* \param [in] boardRect The game's board's rect
* \return Game coordinate from point
*/
Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect);
/**
* \brief Poll and convert SDL_Events into specific event for Pontu
*
* \param [in, out] GameinputProcessor The input processor which keeps a state of input in between calls
* \param [in] boardRect The game's board's rect
* \return InputElement : an event for Pontu
*/
InputElement proccessGameInput(GameInputProcessor* gameInputProcessor, const SDL_Rect* boardRect);
#endif // GAME_INPUT_PROCESSOR_INCLUDED

@ -9,8 +9,8 @@
#define INPUT_PROCESSOR_INCLUDED
#include "engine/Button.h"
#include "engine/arrayButton.h"
#include "engine/InputElement.h"
#include "model/Coord.h"
/**
* \struct InputProcessor
@ -18,26 +18,23 @@
*/
typedef struct
{
//ArrayButton tabButton;
Coord selectedCase; ///< A case in Board (used to handle move actions) , (-1;-1) si inexistant
struct array_P_Button tabButton;
} InputProcessor;
/**
* \brief Convert a screen coord into a model Coord
*
* \param [in] point Screen coordinates
* \param [in] boardRect The game's board's rect
* \return Game coordinate from point
* \brief Create a new input processor
*
* \return A new input processor
*/
Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect);
InputProcessor createInputProcessor();
/**
* \brief Poll and convert SDL_Events into specific event for Pontu
*
* \param [in, out] inputProcessor The input processor which keeps a state of input in between calls
* \param [in] boardRect The game's board's rect
* \return InputElement : an event for Pontu
*/
InputElement proccessInput(InputProcessor* inputProcessor, const SDL_Rect* boardRect);
InputElement proccessInput(InputProcessor* inputProcessor);
#endif // INPUT_PROCESSOR_INCLUDED

@ -0,0 +1,9 @@
#ifndef ARRAY_BUTTON_INCLUDED
#define ARRAY_BUTTON_INCLUDED
#include "engine/Button.h"
#include "engine/ArrayUtils.h"
GENERATE_DYNAMIC_ARRAY(P_Button)
#endif //ARRAY_BUTTON_INCLUDED

@ -1,4 +1,9 @@
#include <SDL2/SDL.h>
#include <stdbool.h>
#include "engine/TextLabel.h"
#include "engine/Button.h"
#include "engine/TextureLoader.h"
#include "engine/Colors.h"
#include "engine/FontUtils.h"
bool drawGameCreationMenu(SDL_Renderer* renderer, TTF_Font* font, int width, int height);

@ -7,6 +7,7 @@
#include "engine/Button.h"
#include "engine/TextureLoader.h"
#include "engine/GeneralState.h"
P_Button createButtonForEndGameMenu(SDL_Renderer* renderer, TTF_Font* font, const SDL_Rect* rect);

@ -0,0 +1,4 @@
#include "engine/Colors.h"
const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND = {225, 225, 225, 255};
const SDL_Color COLOR_GENERIC_BUTTON_BORDER = {10, 10, 10, 255};

@ -0,0 +1,87 @@
#include "engine/GameInputProcessor.h"
Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect){
Coord coord = {
coord.x = (point->x-boardRect->x)*9/boardRect->w,
coord.y = (point->y-boardRect->y)*9/boardRect->h
};
return coord;
}
GameInputProcessor createGameInputProcessor() {
GameInputProcessor gameInputProcessor = {
.selectedCase = {.x=-1, .y=-1},
.tabButton = array_P_Button_Create()
};
return gameInputProcessor;
}
InputElement proccessGameInput(GameInputProcessor *gameInputProcessor, const SDL_Rect* boardRect)
{
SDL_Event event;
if (!SDL_PollEvent(&event))
{
return createInputElementNone();
}
switch (event.type)
{
case SDL_QUIT:
return createInputElementUIQuit();
case SDL_MOUSEBUTTONDOWN:
{
const SDL_Point mousePoint = {.x = event.button.x, .y = event.button.y};
if (SDL_PointInRect(&mousePoint, boardRect))
{
if (!coordValid(gameInputProcessor->selectedCase)) {
gameInputProcessor->selectedCase = screenCoordToGameCoord(&mousePoint, boardRect);
}
}
else
{
}
break;
}
case SDL_MOUSEBUTTONUP:
{
const SDL_Point mousePoint = {.x = event.button.x, .y = event.button.y};
if (SDL_PointInRect(&mousePoint, boardRect))
{
if (coordValid(gameInputProcessor->selectedCase))
{
Coord newCoords = screenCoordToGameCoord(&mousePoint, boardRect);
if (coordEqual(gameInputProcessor->selectedCase, newCoords)) {
gameInputProcessor->selectedCase = newCoords;
return createInputElementClickBoard(newCoords);
}
else {
const Coord oldCoord = gameInputProcessor->selectedCase;
gameInputProcessor->selectedCase = newCoord(-1,-1);
return createInputElementMoveBoard(oldCoord, newCoords);
}
}
}
else
{
for (size_t i = 0; i<gameInputProcessor->tabButton.size; ++i) {
P_Button* b = &gameInputProcessor->tabButton.elems[i];
if (SDL_PointInRect(&mousePoint, &b->rect)) {
b->onClick(b);
}
}
return createInputElementNone();
}
break;
}
case SDL_MOUSEMOTION:
{
for (size_t i = 0; i<gameInputProcessor->tabButton.size; ++i) {
P_Button* b = &gameInputProcessor->tabButton.elems[i];
isHover(b, event.motion.x, event.motion.y);
}
}
}
return createInputElementNone();
}

@ -1,15 +1,13 @@
#include "engine/InputProcessor.h"
Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect){
Coord coord = {
coord.x = (point->x-boardRect->x)*9/boardRect->w,
coord.y = (point->y-boardRect->y)*9/boardRect->h
InputProcessor createInputProcessor() {
InputProcessor inputProcessor = {
.tabButton = array_P_Button_Create()
};
return coord;
return inputProcessor;
}
InputElement proccessInput(InputProcessor *inputProcessor, const SDL_Rect* boardRect)
InputElement proccessInput(InputProcessor *inputProcessor)
{
SDL_Event event;
if (!SDL_PollEvent(&event))
@ -19,51 +17,27 @@ InputElement proccessInput(InputProcessor *inputProcessor, const SDL_Rect* board
switch (event.type)
{
case SDL_QUIT:
return createInputElementUIQuit();
case SDL_MOUSEBUTTONDOWN:
{
const SDL_Point mousePoint = {.x = event.button.x, .y = event.button.y};
if (SDL_PointInRect(&mousePoint, boardRect))
{
if (!coordValid(inputProcessor->selectedCase)) {
inputProcessor->selectedCase = screenCoordToGameCoord(&mousePoint, boardRect);
}
}
else
case SDL_QUIT:
return createInputElementUIQuit();
case SDL_MOUSEBUTTONUP:
{
}
break;
}
case SDL_MOUSEBUTTONUP:
{
const SDL_Point mousePoint = {.x = event.button.x, .y = event.button.y};
if (SDL_PointInRect(&mousePoint, boardRect))
{
if (coordValid(inputProcessor->selectedCase))
{
Coord newCoords = screenCoordToGameCoord(&mousePoint, boardRect);
if (coordEqual(inputProcessor->selectedCase, newCoords)) {
inputProcessor->selectedCase = newCoords;
return createInputElementClickBoard(newCoords);
}
else {
const Coord oldCoord = inputProcessor->selectedCase;
inputProcessor->selectedCase = newCoord(-1,-1);
return createInputElementMoveBoard(oldCoord, newCoords);
const SDL_Point mousePoint = {.x = event.button.x, .y = event.button.y};
for (size_t i = 0; i<inputProcessor->tabButton.size; ++i) {
P_Button* b = &inputProcessor->tabButton.elems[i];
if (SDL_PointInRect(&mousePoint, &b->rect)) {
b->onClick(b);
}
}
}
else
{
/*for (size_t i = 0; i<inputProcessor->tabButton.size; ++i) {
if (SDL_PointInRect(&mousePoint, &inputProcessor->tabButton.buttons[i].rect)) {
// ...
}
}*/
return createInputElementNone();
}
break;
case SDL_MOUSEMOTION:
{
for (size_t i = 0; i<inputProcessor->tabButton.size; ++i) {
P_Button* b = &inputProcessor->tabButton.elems[i];
isHover(b, event.motion.x, event.motion.y);
}
break;
}
}

@ -0,0 +1,68 @@
#include "view/GameCreationMenu.h"
bool drawGameCreationMenu(SDL_Renderer* renderer, TTF_Font* font, int width, int height)
{
// TextLabel for "Nombre de joueur.euse.s" creation
SDL_Point nbJoueurLabelPos = {.x=width*0.05, .y=height*0.05};
SDL_Color black = {0,0,0,255};
SDL_Color white = {225, 255, 255, 255};
TextLabel nbJoueurLabel = createTextLabel(
"Nombre de joueur.euse.s",
&nbJoueurLabelPos,
1,
&white,
font,
renderer,
POSX_LEFT,
POSY_TOP
);
// Incrementation Btn creation
P_Button incrementBtn = createButton(NULL, NULL, nbJoueurLabelPos.x+calculateStringPixelLenght(font, nbJoueurLabel.text)+32, nbJoueurLabelPos.y, 0, 0, NULL);
SDL_Texture* btnTexture = createGenericButtonTexture("+", font, 8,COLOR_GENERIC_BUTTON_BACKGROUND, COLOR_GENERIC_BUTTON_BORDER, 4, 8, &(incrementBtn.rect.w), &(incrementBtn.rect.h), renderer);
if(btnTexture == NULL)
{
fprintf(stderr, "WARNING: Can't create texture: %s\n", SDL_GetError());
return false;
}
SDL_Texture* btnHoveredTexture = createGenericButtonTexture("+", font, 8, COLOR_GENERIC_BUTTON_BORDER, COLOR_GENERIC_BUTTON_BACKGROUND, 4, 8, &(incrementBtn.rect.w), &(incrementBtn.rect.h), renderer);
if(btnHoveredTexture == NULL)
{
fprintf(stderr, "WARNING: Can't create hover texture: %s\n", SDL_GetError());
return false;
}
incrementBtn.texture = btnTexture;
incrementBtn.hoverTexture = btnHoveredTexture;
// Decrementation Btn creation
P_Button decrementBtn = createButton(NULL, NULL, nbJoueurLabelPos.x+calculateStringPixelLenght(font, nbJoueurLabel.text)+32, nbJoueurLabelPos.y, 0, 0, NULL);
btnTexture = createGenericButtonTexture("-", font, 8,COLOR_GENERIC_BUTTON_BACKGROUND, COLOR_GENERIC_BUTTON_BORDER, 4, 8, &(decrementBtn.rect.w), &(decrementBtn.rect.h), renderer);
if(btnTexture == NULL)
{
fprintf(stderr, "WARNING: Can't create texture: %s\n", SDL_GetError());
return false;
}
btnHoveredTexture = createGenericButtonTexture("-", font, 8, COLOR_GENERIC_BUTTON_BORDER, COLOR_GENERIC_BUTTON_BACKGROUND, 4, 8, &(decrementBtn.rect.w), &(decrementBtn.rect.h), renderer);
if(btnHoveredTexture == NULL)
{
fprintf(stderr, "WARNING: Can't create hover texture: %s\n", SDL_GetError());
return false;
}
decrementBtn.texture = btnTexture;
decrementBtn.hoverTexture = btnHoveredTexture;
//Draw everything
drawButtonOnRenderer(renderer, &incrementBtn);
drawButtonOnRenderer(renderer, &decrementBtn);
drawTextLabel(renderer, &nbJoueurLabel);
//free
freeTextLabel(&nbJoueurLabel);
freeButton(&incrementBtn);
return true;
}

@ -1,16 +1,26 @@
#include "view/MenuEndGame.h"
#include <SDL2/SDL_ttf.h>
#include "engine/TextLabel.h"
#include <errno.h>
#include "engine/Colors.h"
#include "engine/InputProcessor.h"
void nullFunc(P_Button* caller) {
}
P_Button createButtonForEndGameMenu(SDL_Renderer* renderer, TTF_Font* font, const SDL_Rect* rect) {
const SDL_Color black = {0,0,0,0};
const SDL_Color white = {255,255,255,255};
int sizeX;
int sizeY;
SDL_Texture* texture = createGenericButtonTexture("Retour menu", font, 14, black, white, 1, 4, &sizeX, &sizeY, renderer);
SDL_Texture* texture = createGenericButtonTexture("Retour menu", font, 50, COLOR_GENERIC_BUTTON_BORDER, COLOR_GENERIC_BUTTON_BACKGROUND, 1, 4, &sizeX, &sizeY, renderer);
return createButton(texture, texture, rect->x, rect->y, sizeX, sizeY, NULL);
if (texture == NULL) {
perror(SDL_GetError());
exit(errno);
}
return createButton(texture, NULL, rect->x, rect->y, sizeX, sizeY, nullFunc);
}
void drawTitle(SDL_Renderer* renderer, const SDL_Rect* rect, FontHandler* fontHandler) {
@ -91,3 +101,61 @@ void drawEndGameMenu(SDL_Renderer* renderer, const Player players[], const size_
drawPlayersScores(renderer, players, nbPlayers, rect, fontHandler);
}
void endGameMenu(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, const Player players[], const size_t nbPlayers) {
InputProcessor inputProcessor = createInputProcessor();
//récupère le numéro de l'écran
SDL_DisplayMode current;
const int i = SDL_GetWindowDisplayIndex(window);
SDL_GetCurrentDisplayMode(i, &current); //retourne current, structure avec vrai valeurs de taille de fenêtre
SDL_Rect rectMenuEndGme = {.x=current.w/20, .y=0, .w=current.w*4/5, .h=current.h};
array_P_Button_AddElement(&inputProcessor.tabButton, createButtonForEndGameMenu(renderer, fontHandler.fonts[FONT_retro], &rectMenuEndGme));
P_Button* buttonMenuEndGame = array_P_Button_Last(&inputProcessor.tabButton);
SDL_Color color = {0,0,0,0};
drawEndGameMenu(renderer, players, nbPlayers, &rectMenuEndGme, &fontHandler);
while(!quit)
{
{
InputElement inputElement;
while (InputType_None != (inputElement = proccessInput(&inputProcessor)).type) {
switch (inputElement.type)
{
case InputType_ActivateUI:
switch (inputElement.data.uiAction)
{
case UIAction_Quit:
quit = true;
break;
case UIAction_Validate:
break;
case UIAction_Cancel:
break;
default:
break;
}
break;
case InputType_MoveGame:
break;
case InputType_ClickGame:
break;
case InputType_None:
default:
break;
}
}
}
drawButtonOnRenderer(renderer, buttonMenuEndGame);
SDL_RenderPresent(renderer);
SDL_Delay(50);
}
}

@ -6,7 +6,6 @@
#include "engine/TextureHandler.h"
#include "model/Game.h"
#include "view/GameDrawer.h"
#include "engine/ArrayUtils.h"
#include "model/arrayCoord.h"
#include "debug/printer.h"
@ -37,7 +36,7 @@ int main(int argc, char* argv[])
goto Quit;
}
InputProcessor inputProcessor = {.selectedCase = {.x=-1, .y=-1}};
InputProcessor inputProcessor = createInputProcessor();
struct array_Coord interactiveCases = array_Coord_Create();
int wBoardRect=99*3, hBoardRect=99*3;

@ -0,0 +1,98 @@
#include <SDL2/SDL.h>
#include <stdio.h>
#include "view/GameCreationMenu.h"
#include "engine/FontLoader.h"
#include "engine/TextInput.h"
int testCreationMenu(void) {
SDL_Window *window = NULL;
SDL_Renderer *renderer = NULL;
SDL_Texture* picture;
TextInput textInput;
int statut = EXIT_FAILURE;
char* path = "rsrc/img/Lenna.png";
int i=0;
int w, h;
if(0 != SDL_Init(SDL_INIT_VIDEO))
{
fprintf(stderr, "Erreur SDL_INIT: %s\n", SDL_GetError());
goto Quit;
}
//fenetre
window = SDL_CreateWindow("Fenêtre", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640,480, SDL_WINDOW_SHOWN);
if(window == NULL)
{
fprintf(stderr, "Erreur SDL_CreateWindow: %s\n", SDL_GetError());
goto Quit;
}
//rendu
renderer = SDL_CreateRenderer(window, -1, SDL_RENDERER_ACCELERATED);
if(renderer == NULL)
{
fprintf(stderr, "Erreur SDL_CreateRenderer: %s\n", SDL_GetError());
goto Quit;
}
//Fonts
if(TTF_Init() == -1)
{
fprintf(stderr, "Erreur: TTF_Init: %s\n", TTF_GetError());
goto Quit;
}
if(0 != SDL_SetRenderDrawColor(renderer, 0,0,0,0)) //choisi la couleur avec laquelle travailler
{
fprintf(stderr, "Erreur SDL_SetRenderDrawColor: %s\n", SDL_GetError());
goto Quit;
}
if(0 != SDL_RenderClear(renderer)) //efface le rendu en le repeignant avec la couleur choisi
{
fprintf(stderr, "Erreur SDL_SetRenderDrawColor: %s\n", SDL_GetError());
goto Quit;
}
if(0 != SDL_SetRenderDrawColor(renderer, 255,255,255,255)) //choisi la couleur avec laquelle travailler
{
fprintf(stderr, "Erreur SDL_SetRenderDrawColor: %s\n", SDL_GetError());
goto Quit;
}
SDL_bool quit = SDL_FALSE;
SDL_Event event;
FontHandler fontHandler = loadFonts();
SDL_GetWindowSize(window, &w, &h);
while(!quit)
{
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
quit = SDL_TRUE;
break;
case SDL_MOUSEBUTTONUP:
break;
}
}
drawGameCreationMenu(renderer, fontHandler.fonts[FONT_retro], w, h);
SDL_RenderPresent(renderer);
SDL_Delay(20);
}
Quit:
freeFonts(fontHandler);
if(renderer != NULL)
SDL_DestroyRenderer(renderer);
if(window != NULL)
SDL_DestroyWindow(window);
TTF_Quit();
SDL_Quit();
return statut;
}

@ -3,9 +3,12 @@
#include "view/MenuEndGame.h"
#include "engine/FontLoader.h"
#include "model/Player.h"
#include "engine/InputProcessor.h"
#include "engine/InputElement.h"
void testMenuEndGame() {
SDL_Window *window = NULL;
SDL_Rect windowSize = {10, 10, 600, 600};
SDL_Renderer *renderer = NULL;
SDL_Texture* picture;
int statut = EXIT_FAILURE;
@ -17,7 +20,7 @@ void testMenuEndGame() {
}
//fenetre
window = SDL_CreateWindow("Fenêtre", SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED, 640,480, SDL_WINDOW_SHOWN);
window = SDL_CreateWindow("Fenêtre", windowSize.x, windowSize.y, windowSize.w, windowSize.h, SDL_WINDOW_SHOWN);
if(window == NULL)
{
fprintf(stderr, "Erreur SDL_CreateWindow: %s\n", SDL_GetError());
@ -63,36 +66,59 @@ void testMenuEndGame() {
SDL_RenderPresent(renderer);
InputProcessor inputProcessor = createInputProcessor();
SDL_Rect rectMenuEndGme = {.x=20, .y=0, .w=300, .h=480};
P_Button buttonMenuEndGame = createButtonForEndGameMenu(renderer, fontHandler.fonts[FONT_retro], &rectMenuEndGme);
array_P_Button_AddElement(&inputProcessor.tabButton, createButtonForEndGameMenu(renderer, fontHandler.fonts[FONT_retro], &rectMenuEndGme));
P_Button* buttonMenuEndGame = array_P_Button_Last(&inputProcessor.tabButton);
SDL_Color color = {0,0,0,0};
Player players[] = {newPlayer("Bépo", color), newPlayer("Azerty", color)};
players[0].eliminationTurn = 10;
players[1].eliminationTurn = 10;
players[0].rank = 1;
players[1].rank = 2;
drawEndGameMenu(renderer, players, 2, &rectMenuEndGme, &fontHandler);
while(!quit)
{
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
InputElement inputElement;
while (InputType_None != (inputElement = proccessInput(&inputProcessor)).type) {
switch (inputElement.type)
{
case SDL_QUIT:
fprintf(stderr, "Quit\n");
quit = true;
case InputType_ActivateUI:
switch (inputElement.data.uiAction)
{
case UIAction_Quit:
quit = true;
break;
case UIAction_Validate:
break;
case UIAction_Cancel:
break;
default:
break;
}
break;
case InputType_MoveGame:
break;
case InputType_ClickGame:
break;
case InputType_None:
default:
break;
}
}
}
SDL_SetRenderDrawColor(renderer, 255,255,255,255);
SDL_RenderClear(renderer);
SDL_Color color = {0,0,0,0};
Player players[] = {newPlayer("Bépo", color), newPlayer("Azerty", color)};
players[0].eliminationTurn = 10;
players[1].eliminationTurn = 10;
players[0].rank = 1;
players[1].rank = 2;
drawEndGameMenu(renderer, players, 2, &rectMenuEndGme, &fontHandler);
drawButtonOnRenderer(renderer, &buttonMenuEndGame);
drawButtonOnRenderer(renderer, buttonMenuEndGame);
SDL_RenderPresent(renderer);
SDL_Delay(50);
@ -100,7 +126,6 @@ void testMenuEndGame() {
Quit:
freeFonts(fontHandler);
SDL_DestroyTexture(buttonMenuEndGame.texture);
if(renderer != NULL)
SDL_DestroyRenderer(renderer);
if(window != NULL)

Loading…
Cancel
Save