-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathButton.h
116 lines (96 loc) · 2.38 KB
/
Button.h
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#pragma once
#include <SDL_mouse.h>
#include "template.h"
class Menu;
namespace tmpl8
{
class Surface;
class Sprite;
}
enum class GameStates
{
always,
mainMenu,
settings,
game,
difficultySellect
};
class Button
{
public:
Button(tmpl8::Sprite* sprite, const tmpl8::vec2 pos = 0.0f, bool startOnButton = false, bool active = false) :
pos(pos),
sprite(sprite),
active(active),
startOnButton(startOnButton)
{}
virtual ~Button();
/**
* \brief The method that should run when the button gets clicked
* \param menu the menu the button is stored in
*/
virtual void OnClick(Menu* menu) {}
/**
* \brief mouse moved
* \param x the x axis
* \param y the y axis
*/
void MouseMove(int x, int y, SDL_Cursor&, SDL_Cursor&);
/**
* \brief render the button
* \param dst destination surface
*/
void Render(tmpl8::Surface* dst) const;
bool IsActive() const { return active; }
bool MouseOnButton() const { return onButton; }
tmpl8::vec2 GetPos() const { return pos; }
/**
* \brief Determines if the button will render
* \param state is the button active
*/
void SetActive(bool state);
/**
* \brief will change the button frame to look "pressed"
* \param state is the button "pressed"
*/
void SetState(bool state) { onButton = state; }
/**
* \brief for game controllers, method get called on d-pad press
*/
void Up();
/**
* \brief for game controllers, method get called on d-pad press
*/
void Down();
/**
* \brief for game controllers, method get called on d-pad press
*/
void Left();
/**
* \brief for game controllers, method get called on d-pad press
*/
void Right();
/**
* \brief for game controllers, method gets called on button press
* \param menu the menu the button is stored in
*/
void ButtonDown(Menu* menu);
void SetDirections(Button* up, Button* down, Button* left, Button* right) { this->up = up; this->down = down; this->left = left; this->right = right; }
private:
Button* up = nullptr;
Button* down = nullptr;
Button* left = nullptr;
Button* right = nullptr;
const tmpl8::vec2 pos;
tmpl8::Sprite* sprite;
/**
* \brief if the button needs to be rendered
*/
bool active;
/**
* \brief if the button needs to show in a "pressed" state
*/
bool onButton = false;
const bool startOnButton = false;
static Button* currentFocus;
};