-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.h
131 lines (70 loc) · 2.26 KB
/
menu.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
#ifndef menu_h
#define menu_h
#include "common.h"
#include "texture.h"
#include "gfx_glfw.h"
typedef void (*MCallback)( void* );
class MWidget
{
protected:
int2 min;
int2 span;
bool enabled;
public:
MWidget( int2 min, int2 max )
:min(min), span(max - min), enabled(true) { };
bool isEnabled( void ){ return enabled; };
void enable( void ){ enabled = true; };
void disable( void ){ enabled = false; };
virtual void draw( GLFWwindow* window ) = 0;
void redefine( int2 newMin, int2 newMax ){ min = newMin; span = newMax - newMin; };
};
class MWButton : public MWidget
{
protected:
MCallback callee;
void* userData;
Image* image;
public:
MWButton( int2 min, int2 max, MCallback callee, void* userData )
:MWidget(min, max), callee(callee), userData(userData), image(NULL) { };
MWButton( int2 min, int2 max, MCallback callee, void* userData, Image* image )
:MWidget(min, max), callee(callee), userData(userData), image(image) { };
void setData( void* userData){ this->userData = userData; };
void setCallback( MCallback callee ){ this->callee = callee; };
void setImage( Image* image ){ this->image = image; };
// Calls callback function
virtual void click( void ){ callee( userData ); };
// if coord is within the button's rectangle calls callback function and returns true.
bool attemptClick( int2 coord );
// Returns true if coord is within the button's rectangle. Does NOTHING else.
bool peek( int2 coord );
//Draws the button
virtual void draw( GLFWwindow* window ){};
};
class MWMenu : public MWidget
{
protected:
Image* image;
std::vector<MWButton*> buttons;
public:
MWMenu( int2 min, int2 max )
:MWidget(min, max), image(NULL) { };
MWMenu( int2 min, int2 max, Image* image )
:MWidget(min, max), image(image) { };
virtual void draw( GLFWwindow* window );
};
class MContainer
{
protected:
int2 min;
int2 span;
bool enabled;
Image* background;
public:
MContainer( int2 min, int2 max )
:min(min), span(max - min), background(NULL) { };
MContainer( int2 min, int2 max, Image* background )
:min(min), span(max - min), background(background) { };
};
#endif