-
Notifications
You must be signed in to change notification settings - Fork 6
/
form.h
95 lines (77 loc) · 2.21 KB
/
form.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
#pragma once
class Form {
friend class GUI;
friend class Element;
friend class Dropdown;
friend class MultiDropdown;
friend class Colorpicker;
friend class Edit;
friend class Config;
public:
bool m_open;
float m_opacity;
int m_alpha;
private:
int m_key;
int m_x;
int m_y;
int m_width;
int m_height;
int m_tick;
std::vector< Tab* > m_tabs;
Tab* m_active_tab;
Element* m_active_element;
public:
__forceinline Form( ) : m_open{ true }, m_opacity{}, m_alpha{}, m_key{ -1 }, m_x{}, m_y{}, m_width{}, m_height{}, m_tick{}, m_tabs{}, m_active_tab{}, m_active_element{} {}
__forceinline void SetPosition( int x, int y ) {
m_x = x;
m_y = y;
}
__forceinline void SetSize( int w, int h ) {
m_width = w;
m_height = h;
}
__forceinline void SetToggle( int key ) {
m_key = key;
}
// adds a new tab.
__forceinline void RegisterTab( Tab* tab ) {
// if this is the first tab, set the active tab.
if( !m_tabs.size( ) )
m_active_tab = tab;
// this form is the owner of the tab.
tab->m_parent = this;
// add the tab to our container.
m_tabs.push_back( tab );
}
// get specific tab based off name.
__forceinline Tab* GetTabByName( const std::string& name ) const {
auto it = std::find_if( m_tabs.begin( ), m_tabs.end( ),
[ &name ]( Tab* tab ) {
return !tab->m_title.compare( name );
} );
if( it != m_tabs.end( ) )
return *it;
return nullptr;
}
// toggles the form.
__forceinline void toggle( ) {
m_open = !m_open;
}
// get the click-able area.
__forceinline Rect GetClientRect( ) const {
return { m_x + 6, m_y + 6, m_width - 12, m_height - 12 };
}
__forceinline Rect GetFormRect( ) const {
return { m_x, m_y, m_width, m_height };
}
__forceinline Rect GetTabsRect( ) const {
return { m_x + 20, m_y + 20, 100, m_height - 40 };
}
__forceinline Rect GetElementsRect( ) const {
Rect tabs_area = GetTabsRect( );
return { tabs_area.x + tabs_area.w + 20, m_y + 20, m_width - tabs_area.w - 60, m_height - 40 };
}
public:
void draw( );
};