-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.cpp
More file actions
180 lines (119 loc) · 6.82 KB
/
custom.cpp
File metadata and controls
180 lines (119 loc) · 6.82 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
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
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
#include "custom.hpp"
using namespace ImGui;
void c_custom::render_arrows_for_horizontal_bar( ImVec2 pos, float alpha, float width, float height ) {
auto draw = GetWindowDrawList();
draw->AddRect( pos, pos + ImVec2( width, height ), ImColor( 0.f, 0.f, 0.f, alpha * GetStyle( ).Alpha ), 4 );
}
bool c_custom::expand_button( const char* label, bool selected, float rounding, ImDrawFlags flags ) {
ImGuiWindow* window = GetCurrentWindow( );
ImGuiID id = window->GetID( label );
ImVec2 label_size = CalcTextSize( label, 0, 1 );
ImVec2 icon_size = GetIO( ).Fonts->Fonts[1]->CalcTextSizeA( GetIO( ).Fonts->Fonts[1]->FontSize - 2, FLT_MAX, 0, "A" );
ImVec2 pos = window->DC.CursorPos;
auto draw = window->DrawList;
ImRect rect( pos, pos + ImVec2( GetWindowWidth( ), 45 ) );
ItemAdd( rect, id );
ItemSize( rect, GetStyle( ).FramePadding.y );
bool hovered, held;
bool pressed = ButtonBehavior( rect, id, &hovered, &held, NULL );
static std::unordered_map < ImGuiID, float > values;
auto value = values.find( id );
if ( value == values.end( ) ) {
values.insert( { id, 0.f } );
value = values.find( id );
}
value->second = ImLerp( value->second, ( selected ? 1.f : 0.f ), 0.035f );
draw->AddRectFilled( rect.Min, rect.Max, ImColor( 1.f, 1.f, 1.f, 0.025f * value->second ), rounding, flags );
draw->AddText( GetIO( ).Fonts->Fonts[1], GetIO( ).Fonts->Fonts[1]->FontSize - 2, ImVec2( rect.Min.x + 50 / 2 - icon_size.x / 2, rect.GetCenter( ).y - icon_size.y / 2 ), GetColorU32( ImGuiCol_Text, ( value->second > 0.3f ? value->second : 0.3f ) ), "A" );
draw->AddText( ImVec2( rect.Min.x + 50, rect.GetCenter( ).y - label_size.y / 2 ), GetColorU32( ImGuiCol_Text, ( value->second > 0.3f ? value->second : 0.3f ) ), label );
return pressed;
}
bool c_custom::tab( const char* icon, const char* label, bool selected ) {
ImGuiWindow* window = GetCurrentWindow( );
ImGuiID id = window->GetID( label );
ImVec2 label_size = CalcTextSize( label, 0, 1 );
ImVec2 icon_size = GetIO( ).Fonts->Fonts[1]->CalcTextSizeA( GetIO( ).Fonts->Fonts[1]->FontSize, FLT_MAX, 0, icon );
ImVec2 pos = window->DC.CursorPos;
auto draw = window->DrawList;
ImRect rect( pos, pos + ImVec2( GetWindowWidth( ), 40 ) );
ItemAdd( rect, id );
ItemSize( rect, GetStyle( ).FramePadding.y );
bool hovered, held;
bool pressed = ButtonBehavior( rect, id, &hovered, &held, NULL );
static std::unordered_map < ImGuiID, float > values;
auto value = values.find( id );
if ( value == values.end( ) ) {
values.insert( { id, 0.f } );
value = values.find( id );
}
value->second = ImLerp( value->second, ( selected || hovered ? 1.f : 0.f ), 0.035f );
draw->AddText( GetIO( ).Fonts->Fonts[1], GetIO( ).Fonts->Fonts[1]->FontSize, ImVec2( rect.Min.x + 50 / 2 - icon_size.x / 2, rect.GetCenter( ).y - icon_size.y / 2 ), GetColorU32( ImGuiCol_Text, ( value->second > 0.3f ? value->second : 0.3f ) ), icon );
draw->AddText( ImVec2( rect.Min.x + 50, rect.GetCenter( ).y - label_size.y / 2 ), GetColorU32( ImGuiCol_Text, ( value->second > 0.3f ? value->second : 0.3f ) ), label );
return pressed;
}
bool c_custom::sub_tab( const char* label, bool selected ) {
ImGuiWindow* window = GetCurrentWindow( );
ImGuiID id = window->GetID( label );
ImVec2 label_size = CalcTextSize( label, 0, 1 );
ImVec2 pos = window->DC.CursorPos;
auto draw = window->DrawList;
ImRect rect( pos, pos + label_size );
ItemAdd( rect, id );
ItemSize( ImVec4( rect.Min.x, rect.Min.y, rect.Max.x + 15, rect.Max.y ), GetStyle( ).FramePadding.y );
bool hovered, held;
bool pressed = ButtonBehavior( rect, id, &hovered, &held, NULL );
static std::unordered_map < ImGuiID, float > values;
auto value = values.find( id );
if ( value == values.end( ) ) {
values.insert( { id, 0.f } );
value = values.find( id );
}
value->second = ImLerp( value->second, ( selected ? 1.f : 0.f ), 0.035f );
draw->AddText( rect.Min, GetColorU32( ImGuiCol_Text, ( value->second > 0.3f ? value->second : 0.3f ) ), label );
draw->AddCircleFilled( ImVec2( rect.GetCenter( ).x, rect.Max.y + 10 ), 3 * value->second, custom.get_accent_color( value->second * GetStyle( ).Alpha ) );
return pressed;
}
struct tab_area_structure {
bool hovered, should_expand;
float width;
};
void c_custom::tab_area( const char* str_id, ImVec2 size, std::function < void ( ) > content ) {
static std::unordered_map < std::string, tab_area_structure > values;
auto value = values.find( std::string( str_id ) );
if ( value == values.end( ) ) {
values.insert( { std::string( str_id ), { false, false, size.x } } );
value = values.find( std::string( str_id ) );
}
value->second.width = ImLerp( value->second.width, ( value->second.should_expand && value->second.hovered ) ? size.x + 60 : size.x, 0.08f );
if ( ( value->second.should_expand && value->second.hovered ) )
GetForegroundDrawList( )->AddRectFilled( GetWindowPos( ) + ImVec2( value->second.width, 0 ), GetWindowPos( ) + GetWindowSize( ), ImColor( 0.f, 0.f, 0.f, 0.2f ), GetStyle( ).WindowRounding );
PushStyleVar( ImGuiStyleVar_ItemSpacing, ImVec2( 0, 0 ) );
BeginChild( std::string( str_id ).append( ".child" ).c_str( ), ImVec2( value->second.width, size.y ) );
value->second.hovered = IsMouseHoveringRect( GetCurrentWindow( )->Pos, GetCurrentWindow( )->Pos + ImVec2( value->second.width, size.y ) ); // could use IsWindowHovered( ); , but it bugs
GetWindowDrawList( )->AddRectFilled( GetCurrentWindow( )->Pos, GetCurrentWindow( )->Pos + GetCurrentWindow( )->Size, ImColor( 28, 30, 36 ), GetStyle( ).WindowRounding, ImDrawFlags_RoundCornersTopLeft );
if ( expand_button( "Expand", value->second.should_expand, GetStyle( ).WindowRounding, ImDrawFlags_RoundCornersTopLeft ) )
value->second.should_expand = !value->second.should_expand;
content( );
EndChild( );
PopStyleVar( );
}
void c_custom::begin_child( const char* name, ImVec2 size ) {
ImGuiContext& g = *GImGui;
ImGuiWindow* window = GetCurrentWindow( );
ImVec2 pos = window->DC.CursorPos;
BeginChild( std::string( name ).append( ".main" ).c_str( ), size, false, ImGuiWindowFlags_NoScrollbar );
GetWindowDrawList( )->AddRectFilled( pos, pos + size, to_vec4( 28, 30, 36, custom.m_anim ), 4 );
GetWindowDrawList( )->AddText( pos + ImVec2( 10, 8 ), custom.get_accent_color( custom.m_anim ), name, FindRenderedTextEnd( name ) );
SetCursorPosY( 30 );
BeginChild( name, { size.x, size.y - 30 } );
SetCursorPosX( 10 );
BeginGroup( );
PushStyleVar( ImGuiStyleVar_Alpha, custom.m_anim );
PushStyleVar( ImGuiStyleVar_ItemSpacing, { 8, 8 } );
}
void c_custom::end_child( ) {
PopStyleVar( 2 );
EndGroup( );
EndChild( );
EndChild( );
}