Modified Doxyfile and document engine Input

merge-requests/1/merge
marouault 4 years ago
parent 6fd58d28b6
commit f39c5e0347

22
.gitignore vendored

@ -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

@ -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

@ -9,6 +9,7 @@
#define BUTTON_INCLUDED
#include <SDL2/SDL.h>
#include <stdbool.h>
/**
* \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

@ -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

@ -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

@ -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

@ -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 ?
}

@ -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;
}

@ -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; i<inputProcessor->tabButton.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();
}

@ -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;
}
Loading…
Cancel
Save