forked from h33p/m0dular-menu
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmenu.cpp
140 lines (111 loc) · 3.99 KB
/
menu.cpp
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
#include "menu.h"
#include "imgui/imgui.h"
void Menu::InitializeStyle()
{
// Setup Dear ImGui style
ImGui::StyleColorsDark();
ImGuiStyle& style = ImGui::GetStyle();
ImVec4* colors = style.Colors;
style.WindowPadding = ImVec2(8, 8);
style.FramePadding = ImVec2(4, 4);
style.ItemSpacing = ImVec2(8, 4);
style.ItemInnerSpacing = ImVec2(4, 5);
style.ScrollbarSize = 16;
style.GrabMinSize = 18;
style.WindowBorderSize = 0;
style.ChildBorderSize = 0;
style.PopupBorderSize = 0;
style.FrameBorderSize = 0;
style.TabBorderSize = 0;
style.WindowRounding = 0;
style.ChildRounding = 0;
style.FrameRounding = 0;
style.PopupRounding = 0;
style.ScrollbarRounding = 12;
style.GrabRounding = 0;
style.TabRounding = 4;
static constexpr ImGuiCol_ colorsStandard[] = {
ImGuiCol_Button,
ImGuiCol_Header,
ImGuiCol_ResizeGrip,
ImGuiCol_Tab,
ImGuiCol_FrameBg,
ImGuiCol_ScrollbarGrabActive,
};
static constexpr ImGuiCol_ colorsHovered[] = {
ImGuiCol_ButtonHovered,
ImGuiCol_HeaderHovered,
ImGuiCol_ResizeGripHovered,
ImGuiCol_TabHovered,
ImGuiCol_FrameBgHovered,
ImGuiCol_ScrollbarGrabHovered,
};
static constexpr ImGuiCol_ colorsActive[] = {
ImGuiCol_ButtonActive,
ImGuiCol_HeaderActive,
ImGuiCol_ResizeGripActive,
ImGuiCol_TabActive,
ImGuiCol_FrameBgActive,
ImGuiCol_ScrollbarGrab,
};
ImVec4 mainColor = ImVec4(0.08f, 0.42f, 0.70f, 1.00f);
ImVec4 mainColorHovered = ImVec4(0.1f, 0.5f, 0.84f, 1.00f);
ImVec4 mainColorActive = ImVec4(0.05f, 0.64f, 0.99f, 1.00f);
colors[ImGuiCol_WindowBg] = ImVec4(0.16f, 0.16f, 0.16f, 0.95f);
colors[ImGuiCol_ChildBg] = ImVec4(0.16f, 0.16f, 0.16f, 0.90f);
colors[ImGuiCol_Border] = ImVec4(0.13f, 0.13f, 0.13f, 0.90f);
colors[ImGuiCol_FrameBg] = ImVec4(0.10f, 0.51f, 0.84f, 1.00f);
colors[ImGuiCol_FrameBgHovered] = ImVec4(0.05f, 0.64f, 0.99f, 1.00f);
colors[ImGuiCol_FrameBgActive] = ImVec4(0.08f, 0.42f, 0.70f, 1.00f);
colors[ImGuiCol_TitleBg] = ImVec4(0.08f, 0.08f, 0.08f, 1.00f);
colors[ImGuiCol_TitleBgActive] = ImVec4(0.12f, 0.12f, 0.12f, 1.00f);
colors[ImGuiCol_ScrollbarBg] = ImVec4(0.20f, 0.23f, 0.24f, 1.00f);
colors[ImGuiCol_SliderGrab] = ImVec4(0.26f, 0.68f, 0.99f, 1.00f);
colors[ImGuiCol_SliderGrabActive] = ImVec4(0.07f, 0.44f, 0.75f, 1.00f);
colors[ImGuiCol_PlotLines]= ImVec4(0.39f, 0.71f, 1.00f, 1.00f);
colors[ImGuiCol_PlotHistogram] = ImVec4(0.39f, 0.71f, 1.00f, 1.00f);
colors[ImGuiCol_PlotHistogramHovered] = ImVec4(0.89f, 0.50f, 0.19f, 1.00f);
colors[ImGuiCol_CheckMark] = ImVec4(0.55f, 0.78f, 0.98f, 1.00f);
for (auto& i : colorsStandard)
colors[i] = mainColor;
for (auto& i : colorsHovered)
colors[i] = mainColorHovered;
for (auto& i : colorsActive)
colors[i] = mainColorActive;
}
void Menu::InitializeFonts()
{
ImGuiIO& io = ImGui::GetIO();
ImFont* font = io.Fonts->AddFontFromFileTTF("OpenSans-Regular.ttf", 40.0f);
IM_ASSERT(font != NULL);
font->Scale *= 0.5f;
//TODO: Put this somewhere else
io.IniFilename = nullptr;
}
size_t selectedTab = 0;
void Menu::Render(const MenuTab* tabs, size_t tabCount)
{
ImGuiIO& io = ImGui::GetIO();
float scale = io.FontGlobalScale;
ImGui::SetNextWindowSize(ImVec2(1000 * scale, 700 * scale), ImGuiCond_Always);
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_WindowPadding, ImVec2(0, 0));
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(6, 8));
if (ImGui::Begin("m0dular.cc Genesis", nullptr, ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize)) {
//Pop FramePadding
ImGui::PopStyleVar(1);
for (size_t i = 0; i < tabCount; i++) {
if (i)
ImGui::SameLine();
ImGui::PushStyleColor(ImGuiCol_Button, ImGui::GetStyle().Colors[i == selectedTab ? ImGuiCol_ButtonActive : ImGuiCol_Button]);
if (ImGui::Button(tabs[i].name, ImVec2(scale * 1000 / tabCount, 0)))
selectedTab = i;
ImGui::PopStyleColor();
}
ImGui::PopStyleVar(2);
if (selectedTab < tabCount && tabs[selectedTab].Callback)
tabs[selectedTab].Callback(tabs[selectedTab].passData);
ImGui::End();
} else
ImGui::PopStyleVar(3);
}