-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGUI.h
More file actions
98 lines (75 loc) · 2.05 KB
/
GUI.h
File metadata and controls
98 lines (75 loc) · 2.05 KB
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
#ifndef GUI_H
#define GUI_H
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <functional>
#include <vector>
#include "GameObject.h"
#include "Texture.h"
enum GUIType
{
GUI_BUTTON,
GUI_PANEL
};
class GUI : public GameObject
{
public:
typedef std::function<void()> call;
GUI(GUI* parent, float x, float y, float sx, float sy, std::string& textureFile, bool relativePos=true);
GUI(float x, float y, float sx, float sy, std::string& textureFile);
GUI();
virtual ~GUI();
virtual void update() = 0;
bool inBounds(glm::vec2 coords);
void render();
// return: [minX, maxX, minY, maxY]
glm::vec4 getBounds();
glm::vec2 getPosition() {return _position;}
glm::vec2 getScale() {return _scale;}
glm::vec2 getOrigin() {return _origin;}
Texture getTexture() {return _texture;}
GUI* getParent() {return _parent;}
GUIType getType() {return _type;}
bool getMouseOver() {return _mouseOver;}
bool isVisible() {return _visible;}
float getAlpha() {return _alpha;}
void addChild(GUI* child);
void setParent(GUI* parent) {
_parent = parent;
parent->addChild(this);
}
void setMouseOver(bool mouseOver) {_mouseOver = mouseOver;}
void setVisible(bool visible) {_visible = visible;}
void setAlpha(float alpha) {_alpha = alpha;}
//Callbacks
std::function<void()> callback() const {return eventCallback;}
template<typename T, typename F, typename... Args>
void subscribeEvent(T instance, F func, Args... args)
{
call temp = { std::bind(func, instance, args...) };
eventCallback = temp;
}
protected:
GUI* _parent;
GLuint _vaoID, _vboID;
glm::vec2 _position;
glm::vec2 _origin;
glm::vec2 _scale;
glm::vec4 _uv;
Texture _texture;
float _alpha = 1.0f;
GUIType _type;
bool _mouseOver;
bool _visible;
std::vector<GUI*> _children;
call eventCallback;
void createIDs();
float _vertices[10] = {
1,1,
1,-1,
-1,-1,
-1,1,
1,1
};
};
#endif