Skip to content
Snippets Groups Projects
Commit 064df4ed authored by llebasca's avatar llebasca
Browse files

button.c/h & window.c/h

parent b5eafe58
No related branches found
No related tags found
4 merge requests!9Modele,!8Modele,!7Modele,!6Modele
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
* \file button.h * \file button.h
* \brief Button Header File * \brief Button Header File
* \authors Lucile * \authors Lucile
* \version 1 * \version 2
* \date 28/03/2021 * \date 28/03/2021
* *
* Button structure definiton. * Button structure definiton.
...@@ -28,6 +28,11 @@ typedef struct { ...@@ -28,6 +28,11 @@ typedef struct {
int long_button; /**< Size : length */ int long_button; /**< Size : length */
int larg_button; /**< Size : width */ int larg_button; /**< Size : width */
char * image_button; /**< Source image of the button. */ char * image_button; /**< Source image of the button. */
int state; /**< Button's state : 1 if on, 0 if off */
} Button; } Button;
void init_button(Button * button, int x, int y, int length, int width, char * path);
int click(int x, int y, Button * button);
void unclick(Button * button);
#endif /*INSAGAME_BUTTON_H*/ #endif /*INSAGAME_BUTTON_H*/
/*
// Created by Lucile on 04/04/2021.
*/
/*!
* \file window.h
* \brief Window Header File
* \authors Lucile
* \version 2
* \date 04/04/2021
*
* Window structure definiton.
*
*/
#ifndef INSAGAME_WINDOW_H
#define INSAGAME_WINDOW_H
/*!
* \enum Window_number
* \brief Definiton of every window's number
*/
typedef enum {
LOADING_PAGE, /*!< 0 */
INTRO_PAGE, /*!< 1 */
LEVEL_PRESENTATION, /*!< 2 */
LEVEL, /*!< 3 */
WIN_PAGE, /*!< 4 */
FAIL_PAGE /*!< 5 */
} Window_number;
/*!
* \struct Window
* \brief Window structure
*/
typedef struct {
int level; /**< */
int time; /**< */
Window_number nb_window; /**< */
} Window;
void init_window(Window * window, int level, int time, int nb_window);
#endif /*INSAGAME_WINDOW_H*/
/*
// Created by Lucile on 04/04/2021.
*/
/*!
* \file button.c
* \brief Button Source File
* \authors Lucile
* \version 2
* \date 04/04/2021
*
* Button functions implementation.
*
*/
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "button.h"
/*!
* \fn void init_button(Button * button, int x, int y, int length, int width, char * path)
* \brief This function initializes a button : position of the button's top left corner (x,y), size (length, width), state (OFF by default) and also the path to the button's image.
*
* \param [in] button a pointer on a Button
* \param [in] x the button's abscissa
* \param [in] y the button's ordinate
* \param [in] length the button's length
* \param [in] width the button's width
* \param [in] path the path to the Teacher's image
*/
void init_button(Button * button, int x, int y, int length, int width, char * path){
button->x_button=x;
button->y_button=y;
button->long_button=length;
button->larg_button=width;
button->state=0;
button->image_button = malloc(strlen(path));
strcpy(button->image_button, path);
}
/*!
* \fn int click(int x, int y, Button * button)
* \brief Sets the button's state on ON if the mouse is clicking on it, stays at OFF otherwise.
*
* \param [in] x Mouse's abscissa
* \param [in] y Mouse's ordinate
* \param [in] button a pointer on a button
* \return The button's state : 1 if the mouse is on the button, 0 otherwise
*/
int click(int x, int y, Button * button) {
if (button->x_button < x && x < (button->x_button + button->long_button)
&& button->y_button < y && y < (button->y_button + button->larg_button)) {
button->state=1;
}
return button->state;
}
/*!
* \fn void unclick(Button * button)
* \brief Sets the button's state on OFF.
*
* \param [in] button a pointer on a button
*/
void unclick(Button * button){
button->state=0;
}
\ No newline at end of file
/*
// Created by Lucile on 04/04/2021.
*/
/*!
* \file window.c
* \brief Window Source File
* \authors Lucile
* \version 2
* \date 04/04/2021
*
* Window functions implementation.
*
*/
#include <stdio.h>
#include <SDL2/SDL.h>
#include <SDL2/SDL_image.h>
#include "window.h"
/*!
* \fn init_window(Window * window, int level, int time, int nb_window)
* \brief This function initializes a window.
*
* \param [in] window a pointer on a Window.
* \param [in] level Level's number, -1 if none.
* \param [in] time The level's time, -1 otherwise (no timing).
* \param [in] nb_window Window's type.
*/
void init_window(Window * window, int level, int time, int nb_window) {
window->nb_window=nb_window;
if(window->nb_window=LEVEL) {
window->level = level;
window->time = time;
} else {
window->level = -1;
window->time = -1;
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment