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

merge-requests/2/merge
Mathis RIBEMONT 4 years ago
commit cdb8ae5a34

@ -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,9 +3,9 @@
#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;
extern const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND_HOVER;
#endif

@ -2,7 +2,6 @@
#define FONT_UTILS_INCLUDED
#include <SDL2/SDL_ttf.h>
#include <string.h>
int calculateStringPixelLenght(TTF_Font* font, char* str);

@ -0,0 +1,59 @@
/**
* \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 Free a game input processor
*
* @param gameInputProcessor the game input processor to free (do not use after freeing)
*/
void freeGameInputProcessor(GameInputProcessor* gameInputProcessor);
/**
* \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,31 @@
*/
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
* \brief Create a new input processor
*
* \return A new input processor
*/
InputProcessor createInputProcessor();
/**
* @brief Free a game input processor
*
* \param [in] point Screen coordinates
* \param [in] boardRect The game's board's rect
* \return Game coordinate from point
* @param inputProcessor the game input processor to free (do not use after freeing)
*/
Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect);
void freeInputProcessor(InputProcessor* inputProcessor);
/**
* \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,9 +7,19 @@
#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);
/**
* @brief Handle end game menu
*
* @param generalState The general state of the application (will be mutate to GS_MAIN_MENU)
* @param window Application's menu
* @param renderer Application's renderer
* @param fontHandler Application's fonts handler
* @param players An array of player with rank and elimination turn set
* @param nbPlayers number of player in players
*/
void endGameMenu(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, FontHandler* fontHandler, const Player players[], const size_t nbPlayers);
void drawEndGameMenu(SDL_Renderer* renderer, const Player players[], const size_t nbPlayers, const SDL_Rect* rect, FontHandler* fontHandler);
#endif // MENU_FIN_INCLUDED

@ -16,7 +16,7 @@
#include "engine/TextureLoader.h"
#include <SDL2/SDL_ttf.h>
#include "engine/TextLabel.h"
#include "engine/FontLoader.h"
/**
* \brief Generates a settings view
@ -24,7 +24,7 @@
* \param[in] ah The AudioHandler in use
* \return true if the view could be generated, else false
*/
bool settingsView(SDL_Renderer* renderer, AudioHandler* ah);
bool settingsView(SDL_Window* parent, AudioHandler* ah, const FontHandler* fh);
#endif // SETTINGS_H

@ -0,0 +1,5 @@
#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};
const SDL_Color COLOR_GENERIC_BUTTON_BACKGROUND_HOVER = {250, 250, 250, 255};

@ -1,4 +1,5 @@
#include "engine/FontUtils.h"
#include <string.h>
int calculateStringPixelLenght(TTF_Font* font, char* str)
{

@ -0,0 +1,91 @@
#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;
}
void freeGameInputProcessor(GameInputProcessor* gameInputProcessor) {
array_P_Button_Free(&gameInputProcessor->tabButton);
}
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,17 @@
#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;
}
void freeInputProcessor(InputProcessor* inputProcessor) {
array_P_Button_Free(&inputProcessor->tabButton);
}
InputElement proccessInput(InputProcessor *inputProcessor, const SDL_Rect* boardRect)
InputElement proccessInput(InputProcessor *inputProcessor)
{
SDL_Event event;
if (!SDL_PollEvent(&event))
@ -19,51 +21,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,29 +1,80 @@
#include "view/MenuEndGame.h"
#include <SDL2/SDL_ttf.h>
#include "engine/TextLabel.h"
#include <errno.h>
#include "engine/Colors.h"
#include "engine/InputProcessor.h"
/**
* @brief Button handle which set a generalState to GS_MainMenu
*
* @param caller The button clicked
*/
void setStateToMainMenu(P_Button* caller) {
*((GeneralState*)caller->arg) = GS_MainMenu;
}
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};
/**
* @brief Create button For EndGameMenu
*
* @param renderer The renderer where buttons will be drawn
* @param font Font used by buttons
* @param rect Rect in which the endGameMenu is drawn
* @param state generalState which will be attached to the button
* @return P_Button
*/
P_Button createButtonForEndGameMenu(SDL_Renderer* renderer, TTF_Font* font, const SDL_Rect* rect, GeneralState* state) {
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, 4, 4, &sizeX, &sizeY, renderer);
if (texture == NULL) {
perror(SDL_GetError());
exit(errno);
}
SDL_Texture* textureHover = createGenericButtonTexture("Retour menu", font, 50, COLOR_GENERIC_BUTTON_BORDER, COLOR_GENERIC_BUTTON_BACKGROUND_HOVER, 8, 4, &sizeX, &sizeY, renderer);
if (textureHover == NULL) {
perror(SDL_GetError());
exit(errno);
}
return createButton(texture, texture, rect->x, rect->y, sizeX, sizeY, NULL);
P_Button buttonMenuEndGame = createButton(texture, textureHover, rect->x, rect->y, sizeX, sizeY, &setStateToMainMenu);
buttonMenuEndGame.arg = state;
buttonMenuEndGame.rect.y = rect->h*8/10;
buttonMenuEndGame.rect.x = rect->x + rect->w/2-buttonMenuEndGame.rect.w/2;
return buttonMenuEndGame;
}
void drawTitle(SDL_Renderer* renderer, const SDL_Rect* rect, FontHandler* fontHandler) {
/**
* @brief Draw title for End Game
*
* @param renderer The renderer where title will be drawn
* @param rect Rect in which the endGameMenu is drawn
* @param font Font used for title
*/
void drawTitle(SDL_Renderer* renderer, const SDL_Rect* rect, TTF_Font* font) {
SDL_Point pos = {rect->x+rect->w/2, rect->y+rect->h/100};
SDL_Color color = {0,0,0,0};
TextLabel titre = createTextLabel("Scores", &pos, 2, &color, fontHandler->fonts[FONT_retro], renderer, POSX_CENTER, POSY_TOP);
TextLabel titre = createTextLabel("Scores", &pos, 4, &color, font, renderer, POSX_CENTER, POSY_TOP);
drawTextLabel(renderer, &titre);
freeTextLabel(&titre);
}
/**
* @brief Draw Pseudo and rank for end game menu
*
* @param renderer The renderer where pseudo and rank will be drawn
* @param rect Rect in which the endGameMenu is drawn
* @param height Height of line in score table
* @param font Font used for pseudo and rank
* @param color Color used for pseudo and rank
* @param rank
* @param pseudo
*/
void drawPseudoAndRank(SDL_Renderer* renderer, const SDL_Rect* rect, const int height, TTF_Font* font, const SDL_Color* color, const size_t rank, const char *const pseudo) {
const SDL_Point posRangPseudo = {
.x = rect->x+rect->w*0.05,
@ -70,14 +121,14 @@ void drawEliminationTurn(SDL_Renderer* renderer, const SDL_Rect* rect, const int
}
void drawPlayersScores(SDL_Renderer* renderer, const Player players[], const size_t nbPlayers, const SDL_Rect* rect, FontHandler* fontHandler) {
void drawPlayersScores(SDL_Renderer* renderer, const Player players[], const size_t nbPlayers, const SDL_Rect* rect, TTF_Font* font) {
SDL_Color black = {0,0,0,0};
for (size_t i=0; i<nbPlayers; ++i) {
const int height = rect->y+(players[i].rank+1)*rect->h/10+rect->y+rect->h/100;
drawPseudoAndRank(renderer, rect, height, fontHandler->fonts[FONT_retro], &black, i, players[i].pseudo);
drawPseudoAndRank(renderer, rect, height, font, &black, i, players[i].pseudo);
drawEliminationTurn(renderer, rect, height, fontHandler->fonts[FONT_retro], &black, players[i].eliminationTurn);
drawEliminationTurn(renderer, rect, height, font, &black, players[i].eliminationTurn);
}
}
@ -86,8 +137,65 @@ void drawEndGameMenu(SDL_Renderer* renderer, const Player players[], const size_
SDL_SetRenderDrawColor(renderer, 220,220,220,255);
SDL_RenderFillRect(renderer, rect);
drawTitle(renderer, rect, fontHandler);
drawTitle(renderer, rect, fontHandler->fonts[FONT_retro]);
drawPlayersScores(renderer, players, nbPlayers, rect, fontHandler);
drawPlayersScores(renderer, players, nbPlayers, rect, fontHandler->fonts[FONT_retro]);
}
void endGameMenu(GeneralState* generalState, SDL_Window* window, SDL_Renderer* renderer, FontHandler* fontHandler, const Player players[], const size_t nbPlayers) {
int windowW;
int windowH;
SDL_GetWindowSize(window, &windowW, &windowH);
SDL_Rect rectMenuEndGame = {
.x=windowW/10,
.y=0,
.w=windowW*80/100,
.h=windowH
};
InputProcessor inputProcessor = createInputProcessor();
array_P_Button_AddElement(&inputProcessor.tabButton, createButtonForEndGameMenu(renderer, fontHandler->fonts[FONT_retro], &rectMenuEndGame, generalState));
P_Button* buttonMenuEndGame = array_P_Button_Last(&inputProcessor.tabButton);
drawEndGameMenu(renderer, players, nbPlayers, &rectMenuEndGame, fontHandler);
while(*generalState == GS_EndOfGameMenu)
{
{
InputElement inputElement;
while (InputType_None != (inputElement = proccessInput(&inputProcessor)).type) {
switch (inputElement.type)
{
case InputType_ActivateUI:
switch (inputElement.data.uiAction)
{
case UIAction_Quit:
*generalState = GS_MainMenu;
break;
case UIAction_Validate:
break;
case UIAction_Cancel:
break;
default:
break;
}
break;
default:
break;
}
}
}
drawButtonOnRenderer(renderer, buttonMenuEndGame);
SDL_RenderPresent(renderer);
SDL_Delay(50);
}
freeInputProcessor(&inputProcessor);
}

@ -1,31 +1,116 @@
#include "view/Settings.h"
void onClick(P_Button* buttonCaller) {
printf("j'ai perdu %d\n",buttonCaller->rect.x);
}
// Global functions
bool settingsView(SDL_Renderer* renderer, AudioHandler* ah) {
SDL_Rect bg_area = {150,0,300,600};
SDL_Rect title_area = {150,0,300,50};
SDL_Color white = {255,255,255,255};
SDL_Color blue = {52,158,235,255};
SDL_Color black = {0,0,0,255};
SDL_Texture* bg = NULL;
TextLabel tmp_textLabel;
bool settingsView(SDL_Window* parent, AudioHandler* ah, const FontHandler* fh) {
SDL_Window* window;
SDL_Renderer* renderer;
if (0 != SDL_CreateWindowAndRenderer(300,600,SDL_WINDOW_SHOWN, &window, &renderer)) {
fprintf(stderr,"Error when trying to create window or renderer: %s\n", SDL_GetError());
return false;
}
SDL_Rect title_area = {0,0,300,50};
SDL_Point title_point = {150,25};
SDL_Point masterVolTitle_point = {150,75};
SDL_Color white = {255,255,255,255};
SDL_Color blue = {52,158,235,255};
SDL_Color black = {0,0,0,255};
int hMinus, wMinus, hPlus, wPlus;
TextLabel* arr_textLabel = (TextLabel*)malloc(7*sizeof(TextLabel));
SDL_Texture** arr_textures = (SDL_Texture**)malloc(2*sizeof(SDL_Texture*));
P_Button tmp_button;
char tmp_str[3];
if (arr_textLabel == NULL) {
fprintf(stderr, "Can't allocate memory for text labels\n");
return false;
}
if (arr_textures == NULL) {
fprintf(stderr,"Can't allocate memory for button textures");
return false;
}
if (0!=SDL_SetWindowModalFor(window, parent)) {
fprintf(stderr,"Warning: Can't set window as modal: %s\n",SDL_GetError());
}
SDL_SetRenderDrawColor(renderer, white.r, white.g, white.b, white.a);
SDL_RenderClear(renderer);
SDL_SetRenderDrawColor(renderer, blue.r, blue.g, blue.b, blue.a);
SDL_RenderFillRect(renderer,&title_area);
arr_textLabel[0] = createTextLabel("Parametres", &title_point, 2.0, &black,
fh->fonts[FONT_retro], renderer, POSX_CENTER, POSY_CENTER);
drawTextLabel(renderer, &arr_textLabel[0]);
arr_textures[0] = createGenericButtonTexture("-",fh->fonts[FONT_retro],32,black,blue, 0, 5, &wMinus, &hMinus, renderer);
arr_textures[1] = createGenericButtonTexture("+",fh->fonts[FONT_retro],32,black,blue, 0, 5, &wPlus, &hPlus, renderer);
/* Master volume */
// Title
arr_textLabel[1] = createTextLabel("Volume principal", &masterVolTitle_point, 1.25, &black,
fh->fonts[FONT_retro], renderer, POSX_CENTER, POSY_CENTER);
drawTextLabel(renderer,&arr_textLabel[1]);
// - button
tmp_button = createButton(arr_textures[0], NULL, 0, arr_textLabel[1].textZone.y+arr_textLabel[1].textZone.h+20, wMinus, hMinus, onClick);
drawButtonOnRenderer(renderer, &tmp_button);
SDL_CreateTexture(renderer, SDL_PIXELFORMAT_RGB888, SDL_TEXTUREACCESS_TARGET, 300,600);
SDL_SetRenderTarget(renderer, bg);
SDL_SetRenderDrawColor(renderer, white.r, white.g, white.b, white.a);
SDL_RenderFillRect(renderer,&bg_area);
// + button
tmp_button = createButton(arr_textures[1], NULL, 270, arr_textLabel[1].textZone.y+arr_textLabel[1].textZone.h+20, wPlus, hPlus, onClick);
drawButtonOnRenderer(renderer, &tmp_button);
SDL_SetRenderDrawColor(renderer, blue.r, blue.g, blue.b, blue.a);
SDL_RenderFillRect(renderer,&title_area);
tmp_textLabel = createTextLabel("Paramètres", &((SDL_Point) {150,50}), 1, &black,
FONT_Curvilingus, renderer, POSX_CENTER, POSY_CENTER);
// Current value
sprintf(tmp_str, "%d", ah->masterVol);
arr_textLabel[2] = createTextLabel(tmp_str, &((SDL_Point) {150, tmp_button.rect.y+tmp_button.rect.h/2}), 1.5, &black, fh->fonts[FONT_retro], renderer, POSX_CENTER, POSY_CENTER);
drawTextLabel(renderer, &arr_textLabel[2]);
/* Music volume */
// Title
arr_textLabel[3] = createTextLabel("Volume musique", &((SDL_Point) {150, tmp_button.rect.y+tmp_button.rect.h+20}), 1.5, &black,
fh->fonts[FONT_retro], renderer, POSX_CENTER, POSY_CENTER);
drawTextLabel(renderer, &arr_textLabel[3]);
// - button
tmp_button = createButton(arr_textures[0], NULL, 0, arr_textLabel[3].textZone.y+arr_textLabel[3].textZone.h+20, wMinus, hMinus, onClick);
drawButtonOnRenderer(renderer, &tmp_button);
SDL_RenderCopy(renderer, bg, NULL, &bg_area);
SDL_SetRenderTarget(renderer, NULL);
SDL_RenderPresent(renderer);
// + button
tmp_button = createButton(arr_textures[1], NULL, 270, arr_textLabel[3].textZone.y+arr_textLabel[3].textZone.h+20, wPlus, hPlus, onClick);
drawButtonOnRenderer(renderer, &tmp_button);
// Current value
sprintf(tmp_str, "%d", ah->volMusic);
arr_textLabel[4] = createTextLabel(tmp_str, &((SDL_Point) {150, tmp_button.rect.y+tmp_button.rect.h/2}), 1.5, &black, fh->fonts[FONT_retro], renderer, POSX_CENTER, POSY_CENTER);
drawTextLabel(renderer, &arr_textLabel[4]);
/* SFX Volume */
// Title
arr_textLabel[5] = createTextLabel("Volume sons", &((SDL_Point) {150, tmp_button.rect.y+tmp_button.rect.h + 20}), 1.5, &black,
fh->fonts[FONT_retro], renderer, POSX_CENTER, POSY_CENTER);
drawTextLabel(renderer, &arr_textLabel[5]);
// - button
tmp_button = createButton(arr_textures[0], NULL, 0, arr_textLabel[5].textZone.y+arr_textLabel[5].textZone.h+20, wMinus, hMinus, onClick);
drawButtonOnRenderer(renderer, &tmp_button);
// + button
tmp_button = createButton(arr_textures[1], NULL, 270, arr_textLabel[5].textZone.y+arr_textLabel[5].textZone.h+20, wPlus, hPlus, onClick);
drawButtonOnRenderer(renderer, &tmp_button);
// Current value
sprintf(tmp_str, "%d", ah->volSFX);
arr_textLabel[6] = createTextLabel(tmp_str, &((SDL_Point) {150, tmp_button.rect.y+tmp_button.rect.h/2}), 1.5, &black, fh->fonts[FONT_retro], renderer, POSX_CENTER, POSY_CENTER);
drawTextLabel(renderer, &arr_textLabel[6]);
SDL_RenderPresent(renderer);
return true;
}

@ -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,12 +3,13 @@
#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, 1100, 600};
SDL_Renderer *renderer = NULL;
SDL_Texture* picture;
int statut = EXIT_FAILURE;
if(0 != SDL_Init(SDL_INIT_VIDEO))
{
@ -17,7 +18,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());
@ -57,50 +58,23 @@ void testMenuEndGame() {
goto Quit;
}
bool quit = false;
FontHandler fontHandler = loadFonts();
SDL_RenderPresent(renderer);
GeneralState generalState = GS_EndOfGameMenu;
SDL_Rect rectMenuEndGme = {.x=20, .y=0, .w=300, .h=480};
P_Button buttonMenuEndGame = createButtonForEndGameMenu(renderer, fontHandler.fonts[FONT_retro], &rectMenuEndGme);
SDL_Color color = {0,0,0,0};
Player players[2] = {newPlayer("Bépo", color), newPlayer("Azerty", color)};
players[0].eliminationTurn = 10;
players[1].eliminationTurn = 10;
players[0].rank = 1;
players[1].rank = 2;
while(!quit)
{
{
SDL_Event event;
while(SDL_PollEvent(&event))
{
switch(event.type)
{
case SDL_QUIT:
fprintf(stderr, "Quit\n");
quit = true;
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);
SDL_RenderPresent(renderer);
SDL_Delay(50);
}
endGameMenu(&generalState, window, renderer, &fontHandler, players, 2);
Quit:
freeFonts(fontHandler);
SDL_DestroyTexture(buttonMenuEndGame.texture);
if(renderer != NULL)
SDL_DestroyRenderer(renderer);
if(window != NULL)

@ -9,6 +9,7 @@ void testSettingsView(void) {
SDL_Renderer* renderer = NULL;
SDL_Texture* background = NULL;
AudioHandler ah;
FontHandler fh;
if (0 != SDL_Init(SDL_INIT_VIDEO)) {
fprintf(stderr,"Error when initializing SDL: %s\n",SDL_GetError());
@ -26,11 +27,13 @@ void testSettingsView(void) {
}
ah = newAudioHandler(10,100,100);
fh = loadFonts();
SDL_SetRenderDrawColor(renderer,255,140,0,255);
printf("%s\n",SDL_GetError());
SDL_RenderClear(renderer);
SDL_RenderPresent(renderer);
settingsView(renderer,&ah);
settingsView(window, &ah,&fh);
SDL_Delay(5000);
@ -42,4 +45,4 @@ void testSettingsView(void) {
TTF_Quit();
SDL_Quit();
}
}

Loading…
Cancel
Save