-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbutton.hpp
55 lines (43 loc) · 1.43 KB
/
button.hpp
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
#ifndef PANZERTOY_BUTTON_HPP
#define PANZERTOY_BUTTON_HPP
#include <string>
#include <glm/glm.hpp>
#include "text.hpp"
class Game;
typedef void (*BtnCallback)(Game& game);
/**
* @class Button
*
* @brief Represents a clickable Text object
* @see Text
* @todo Add Sprite buttons (this is the reason why Button doesn't inherit from Text)
*/
class Button {
public:
Button() { _text.set_color(glm::vec3(0.0f, 1.0f, 0.0f)); };
Button(TextRenderInfos* render) { set_render(render); };
Button(TextRenderInfos* render, const std::string& text) : Button(render) { set_text(text); };
Button(
TextRenderInfos* render,
const std::string& text,
const glm::ivec2& pos
) : Button(render, text) {
set_pos(pos);
};
void draw(Game& game);
void process_click(Game& game) const;
void calculate_metrics() { _text.calculate_metrics(); };
int get_height() const { return _text.get_height(); };
int get_width() const { return _text.get_width(); };
void set_callback(BtnCallback fun) { _callback = fun; };
void set_pos(const glm::ivec2& pos) { _text.set_pos(pos); };
void set_flags(short flags) { _text.set_flags(flags); };
void set_render(TextRenderInfos* render) { _text.set_text_render(render); };
void set_text(const std::string& text) { _text.set_text(text); };
private:
bool _is_mouse_over(const glm::vec2& cursor_pos) const;
bool _cursor_has_entered = true;
BtnCallback _callback = nullptr;
Text _text;
};
#endif // PANZERTOY_BUTTON_HPP