diff --git a/.gitignore b/.gitignore index 6da8ac7..09bd172 100644 --- a/.gitignore +++ b/.gitignore @@ -71,5 +71,27 @@ _deps ### binaries ### bin/ + + Documentation/doxygen/ + +### VisualStudioCode ### +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +*.code-workspace + +# Local History for Visual Studio Code +.history/ + +### VisualStudioCode Patch ### +# Ignore all local history of files +.history +.ionide + +# Support for Project snippet scope +!.vscode/*.code-snippets + diff --git a/Doxyfile b/Doxyfile index 9e5742f..a7443b0 100644 --- a/Doxyfile +++ b/Doxyfile @@ -889,7 +889,7 @@ EXCLUDE_SYMLINKS = NO # Note that the wildcards are matched against the file with absolute path, so to # exclude all test directories for example use the pattern */test/* -EXCLUDE_PATTERNS = +EXCLUDE_PATTERNS = */bin/* # The EXCLUDE_SYMBOLS tag can be used to specify one or more symbol names # (namespaces, classes, functions, etc.) that should be excluded from the diff --git a/Pontu/include/engine/Button.h b/Pontu/include/engine/Button.h index b23f15e..afd3e42 100644 --- a/Pontu/include/engine/Button.h +++ b/Pontu/include/engine/Button.h @@ -9,6 +9,7 @@ #define BUTTON_INCLUDED #include +#include /** * \struct P_Button @@ -36,7 +37,7 @@ P_Button createButton(SDL_Texture* texture, const int coordx, const int coordy, // texture: design du bouton, si rien n'est passer, le bouton sera générer dans la fonction. void changeButtonTexture(P_Button* button, const SDL_Texture* texture); -bool drawButtonOnRenderer(SDL_Renderer* renderer, P_Button* button); +bool drawButtonOnRenderer(SDL_Renderer* renderer, const P_Button* button); bool isHover(int x,int y); // dit si le bouton est survolé en donnant les coordonnées x,y #endif diff --git a/Pontu/include/engine/InputElement.h b/Pontu/include/engine/InputElement.h index 8e2254a..18ed0c5 100644 --- a/Pontu/include/engine/InputElement.h +++ b/Pontu/include/engine/InputElement.h @@ -4,13 +4,24 @@ * \author Martin Rouault * \date 06/12/2021 */ + #ifndef INPUT_ELEMENT_INCLUDED #define INPUT_ELEMENT_INCLUDED -#include "Coord.h" +#include "model/Coord.h" + +/** + * \enum InputType + * \brief Different types for input +*/ typedef enum {InputType_None, InputType_ClickGame, InputType_MoveGame, InputType_ActivateUI} InputType; + +/** + * \enum UIAction + * \brief Les differentes actions accessible via l'interface utilisateur +*/ typedef enum {UIAction_Validate, UIAction_Cancel, UIAction_Quit } UIAction; /** @@ -18,16 +29,20 @@ typedef enum {UIAction_Validate, UIAction_Cancel, UIAction_Quit } UIAction; * \brief Represent a input element */ typedef struct { - union + /** + * \union data + * \brief Either a coord, a starting and ending coords, or an action for general UI + */ + union data { - struct p_coord coord; ///< Coordinate for simple click on the board + Coord coord; ///< Coordinate for simple click on the board - struct { - struct p_coord start; - struct p_coord end; + struct move { + Coord start; + Coord end; } move; ///< Pair of coordinates for move on the board - UIAction uiAction; + UIAction uiAction; ///< L'action } data; ///< Informations about the input InputType type; ///< Type of input @@ -44,7 +59,20 @@ InputElement createInputElementNone(); * \return A quit input element */ InputElement createInputElementUIQuit(); -InputElement createInputElementClickBoard(const struct p_coord newCoord); -InputElement createInputElementMoveBoard(const struct p_coord start, const struct p_coord end); + +/** + * \brief Create a click on board input element + * \param [in] newCoord The board's square which is clicked + * \return A click on board input element +*/ +InputElement createInputElementClickBoard(const Coord newCoord); + +/** + * \brief Create a move on board input element + * \param [in] start The board's square where the movement starts + * \param [in] end The board's square where the movement ends + * \return A move on board input element +*/ +InputElement createInputElementMoveBoard(const Coord start, const Coord end); #endif // INPUT_ELEMENT_INCLUDED diff --git a/Pontu/include/engine/InputProcessor.h b/Pontu/include/engine/InputProcessor.h index b831dab..bf26767 100644 --- a/Pontu/include/engine/InputProcessor.h +++ b/Pontu/include/engine/InputProcessor.h @@ -1,18 +1,28 @@ +/** + * \file InputProcessor.h + * \brief Define a structure, InputProcessor and functions to convert SDL_event to envent for Pontu + * \author Martin Rouault + * \date 06/12/2021 + */ + #ifndef INPUT_PROCESSOR_INCLUDED #define INPUT_PROCESSOR_INCLUDED -#include "Button.h" +#include "engine/Button.h" +#include "engine/InputElement.h" #include "model/Coord.h" -#include "InputElement.h" +/** + * \struct + */ typedef struct { ArrayButton tabButton; - struct Coord selectedCase; ///< Board , (-1;-1) si inexistant + Coord selectedCase; ///< Board , (-1;-1) si inexistant } InputProcessor; -struct Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect); +Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect); -InputElement proccessInput(InputProcessor *inputProcessor, const SDL_Rect* boardRect); +InputElement proccessInput(InputProcessor* inputProcessor, const SDL_Rect* boardRect); -#endif //INPUT_PROCESSOR_INCLUDED +#endif // INPUT_PROCESSOR_INCLUDED diff --git a/Pontu/include/model/Coord.h b/Pontu/include/model/Coord.h index 3b9d8d8..4598cbe 100644 --- a/Pontu/include/model/Coord.h +++ b/Pontu/include/model/Coord.h @@ -16,12 +16,7 @@ typedef struct { } Coord; -bool coordValide(const Coord coord) { - return coord.x>=0 && coord.y>=0; -} - -bool coordEqual(const Coord a, const Coord b) { - return a.x == b.x && a.y == b.y; -} +bool coordValide(const Coord coord); +bool coordEqual(const Coord a, const Coord b); #endif //COORD_INCLUDED diff --git a/Pontu/src/engine/Button.c b/Pontu/src/engine/Button.c index 4526565..037dcc7 100644 --- a/Pontu/src/engine/Button.c +++ b/Pontu/src/engine/Button.c @@ -29,7 +29,8 @@ P_Button createButton(SDL_Texture* texture, const int coordx, return b; } -SDL_bool drawButtonOnRenderer(SDL_Renderer* renderer,const P_Button* button) +bool drawButtonOnRenderer(SDL_Renderer* renderer,const P_Button* button) { SDL_RenderCopy(renderer,button->texture,NULL,&(button->rect)); + return true; // Que doit retourner cette fonction ? } diff --git a/Pontu/src/engine/InputElement.c b/Pontu/src/engine/InputElement.c index 136382e..5076204 100644 --- a/Pontu/src/engine/InputElement.c +++ b/Pontu/src/engine/InputElement.c @@ -1,4 +1,4 @@ -#include "InputElement.h" +#include "engine/InputElement.h" @@ -13,12 +13,12 @@ InputElement createInputElementUIQuit() { return i; } -InputElement createInputElementClickBoard(const struct p_coord newCoord) { +InputElement createInputElementClickBoard(const Coord newCoord) { InputElement i = {.type=InputType_ClickGame, .data.coord = newCoord}; return i; } -InputElement createInputElementMoveBoard(const struct p_coord start, const struct p_coord end) { +InputElement createInputElementMoveBoard(const Coord start, const Coord end) { InputElement i = {.type=InputType_MoveGame, .data.move={.start=start, .end=end}}; return i; } diff --git a/Pontu/src/engine/InputProcessor.c b/Pontu/src/engine/InputProcessor.c index 2277427..644d76d 100644 --- a/Pontu/src/engine/InputProcessor.c +++ b/Pontu/src/engine/InputProcessor.c @@ -1,10 +1,11 @@ -#include "InputProcessor.h" +#include "engine/InputProcessor.h" -struct p_coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect){ - struct p_coord coord = { - coord.x = (point->x-boardRect->x)*9/boardRect->w; - coord.x = (point->y-boardRect->y)*9/boardRect->h; - } +Coord screenCoordToGameCoord(const SDL_Point* point, const SDL_Rect* boardRect){ + Coord coord = { + coord.x = (point->x-boardRect->x)*9/boardRect->w, + coord.x = (point->y-boardRect->y)*9/boardRect->h + }; + return coord; } @@ -25,7 +26,7 @@ InputElement proccessInput(InputProcessor *inputProcessor, const SDL_Rect* board const SDL_Point mousePoint = {.x = event.button.x, .y = event.button.y}; if (SDL_PointInRect(&mousePoint, boardRect)) { - inputProcessor->selectedCase = screenCoordToGameCoord(&mousePoint); + inputProcessor->selectedCase = screenCoordToGameCoord(&mousePoint, boardRect); } else { @@ -39,7 +40,7 @@ InputElement proccessInput(InputProcessor *inputProcessor, const SDL_Rect* board { if (coordValide(inputProcessor->selectedCase)) { - struct p_coord newCoord = screenCoordToGameCoord(&mousePoint); + Coord newCoord = screenCoordToGameCoord(&mousePoint, boardRect); if (coordEqual(inputProcessor->selectedCase, newCoord)) { return createInputElementClickBoard(newCoord); } @@ -52,12 +53,16 @@ InputElement proccessInput(InputProcessor *inputProcessor, const SDL_Rect* board else { for (size_t i = 0; itabButton.size; ++i) { - if (SDL_PointInRect(&mousePoint, &inputProcessor->tabButton.button[i].rect)) { - + if (SDL_PointInRect(&mousePoint, &inputProcessor->tabButton.buttons[i].rect)) { + // ... } } + return createInputElementNone(); + } + break; } } - } + + return createInputElementNone(); } diff --git a/Pontu/src/model/Coord.c b/Pontu/src/model/Coord.c new file mode 100644 index 0000000..7d50ead --- /dev/null +++ b/Pontu/src/model/Coord.c @@ -0,0 +1,12 @@ +#include "model/Coord.h" + + +bool coordValide(const Coord coord) +{ + return coord.x >= 0 && coord.y >= 0; +} + +bool coordEqual(const Coord a, const Coord b) +{ + return a.x == b.x && a.y == b.y; +}