-
Notifications
You must be signed in to change notification settings - Fork 0
/
element.h
94 lines (78 loc) · 1.98 KB
/
element.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
#pragma once
// pre-declares.
class Element;
class Tab;
class Form;
enum ElementFlags : size_t {
NONE = 0 << 0,
DRAW = 1 << 0,
CLICK = 1 << 1,
ACTIVE = 1 << 2,
SAVE = 1 << 3,
DEACIVATE = 1 << 4,
};
enum ElementTypes : size_t {
CHECKBOX = 1,
SLIDER,
KEYBIND,
DROPDOWN,
COLORPICKER,
MULTI_DROPDOWN,
EDIT,
BUTTON,
CUSTOM
};
using ToggleCallback_t = void(*)();
#define LABEL_OFFSET 20
class Element {
friend class GUI;
friend class Tab;
friend class Form;
friend class Config;
protected:
using ShowCallback_t = bool(*)();
using Callback_t = void(*)();
protected:
Point m_pos;
int m_w;
int m_h;
int m_base_h;
size_t m_col;
Form* m_parent;
std::string m_label;
std::string m_file_id;
size_t m_flags;
size_t m_type;
std::vector< ShowCallback_t > m_show_callbacks;
Callback_t m_callback;
bool m_show;
bool m_use_label;
public:
__forceinline Element() : m_pos{}, m_w{}, m_h{}, m_base_h{}, m_parent{ nullptr },
m_label{}, m_file_id{}, m_flags{}, m_type{}, m_use_label{},
m_show_callbacks{}, m_callback{}, m_show{} {}
__forceinline void setup(const std::string& label, const std::string& file_id) {
m_label = label;
m_file_id = file_id;
}
__forceinline void AddFlags(size_t flags) {
m_flags |= flags;
}
__forceinline void RemoveFlags(size_t flags) {
m_flags &= ~flags;
}
__forceinline void AddShowCallback(ShowCallback_t scb) {
m_show_callbacks.push_back(scb);
}
__forceinline void SetCallback(Callback_t cb) {
m_callback = cb;
}
__forceinline void SetPosition(int x, int y) {
m_pos.x = x;
m_pos.y = y;
}
protected:
virtual void draw() {};
virtual void think() {};
virtual void click() {};
};