Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
// 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;