-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEvents.hpp
63 lines (51 loc) · 1.42 KB
/
Events.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
56
57
58
59
60
61
62
63
#pragma once
#include <vector>
#include <functional>
#include <cassert>
#include "vector2f.hpp"
#define SLOT_FUNC(macro_func) (static_cast<handler_t>(¯o_func))
namespace gGUI {
class Widget;
class Event {
public:
enum type_t {
None = 0,
Unsupported,
MousePress,
MouseRelease,
MouseMove,
};
type_t type;
g::vector2f pos;
g::vector2f prev;
bool leftButton;
uint64_t widgetID;
int curSlider;
Event(type_t t, g::vector2f pos = {0, 0}, g::vector2f prev = {0, 0}) : type(t), pos(pos), prev(prev) {}
Event(type_t t, g::vector2f pos, bool left) : type(t), pos(pos), prev(prev), leftButton(left) {}
Event& operator=(const Event &other)
{
type = other.type;
pos = other.pos;
return *this;
}
};
struct Signal;
typedef void (Widget::*handler_t)(Event);
struct Slot {
Widget *widget = NULL;
handler_t handler;
std::vector<Signal*> signals;
void disconnect(Signal &sig);
Slot() : widget(nullptr), handler(nullptr) {}
Slot(Widget *w, handler_t h) : widget(w), handler(h) {}
~Slot();
};
struct Signal {
std::vector<Slot*> slots;
void connect(Slot &slt);
void disconnect(Slot &slt);
void call(Event ev);
~Signal();
};
}