Line |
Branch |
Exec |
Source |
1 |
|
|
/* |
2 |
|
|
** EPITECH PROJECT, 2024 |
3 |
|
|
** zappy |
4 |
|
|
** File description: |
5 |
|
|
** button |
6 |
|
|
*/ |
7 |
|
|
|
8 |
|
|
#ifndef BUTTON_HPP_ |
9 |
|
|
#define BUTTON_HPP_ |
10 |
|
|
|
11 |
|
|
#include <SFML/Graphics.hpp> |
12 |
|
|
#include <functional> |
13 |
|
|
|
14 |
|
|
enum ButtonState { |
15 |
|
|
IDLE, |
16 |
|
|
HOVER, |
17 |
|
|
CLICKED, |
18 |
|
|
}; |
19 |
|
|
|
20 |
|
|
class Button { |
21 |
|
|
public: |
22 |
|
|
Button(sf::Vector2f pos, sf::Vector2f size, std::string text, sf::Font &font); |
23 |
|
✗ |
~Button() {}; |
24 |
|
|
|
25 |
|
|
bool update(sf::Event event, sf::RenderWindow &window); |
26 |
|
|
void draw(sf::RenderWindow &window); |
27 |
|
✗ |
void setCallBack(std::function<void()> event) { _event = event; } |
28 |
|
|
|
29 |
|
|
void setFontSize(int size) { |
30 |
|
|
_text.setCharacterSize(size); |
31 |
|
|
} |
32 |
|
|
|
33 |
|
✗ |
void setText(std::string text) { |
34 |
|
✗ |
_text.setString(text); |
35 |
|
✗ |
} |
36 |
|
|
|
37 |
|
✗ |
std::string getText() { |
38 |
|
✗ |
return _text.getString(); |
39 |
|
|
} |
40 |
|
|
|
41 |
|
|
void setPosition(sf::Vector2f pos) { |
42 |
|
✗ |
_text.setPosition(pos); |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
protected: |
46 |
|
|
private: |
47 |
|
|
sf::Text _text; |
48 |
|
|
ButtonState _state = IDLE; |
49 |
|
|
std::function<void()> _event; |
50 |
|
|
}; |
51 |
|
|
|
52 |
|
|
#endif /* !BUTTON_HPP_ */ |
53 |
|
|
|