SpiecsEngine
 
Loading...
Searching...
No Matches
ImguiConsole.cpp
Go to the documentation of this file.
1/**
2* @file ImguiConsole.cpp
3* @brief The ImguiConsole Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "ImguiConsole.h"
9
10#include "Core/Log/Console.h"
11#include "Core/Library/FileLibrary.h"
12#include "Render/Vulkan/VulkanRenderBackend.h"
13#include "Core/Library/ProcessLibrary.h"
14
15namespace Spices {
16
18 const std::string& panelName ,
19 FrameInfo& frameInfo ,
20 std::shared_ptr<Console> console
21 )
22 : ImguiSlate(panelName, frameInfo)
24 {}
25
27 {
29
30 /**
31 * @brief Begin render Console.
32 */
33 Begin();
34
35 ImGui::Spacing();
36
37 /**
38 * @brief Render ClearConsoleIcon.
39 */
40 {
41 SPICES_PROFILE_ZONEN("Console ClearConsoleIcon");
42
43 if (ImGui::Button(ICON_MD_FORMAT_CLEAR, ImGuiH::GetLineItemSize()))
44 {
45 m_Console->Clear();
46 }
47 ImGui::SetItemTooltip("Clear Console");
48 }
49
50 /**
51 * @brief Render OpenLogFileIcon.
52 */
53 {
54 SPICES_PROFILE_ZONEN("Console OpenLogFileIcon");
55
56 ImGui::SameLine();
57 if (ImGui::Button(ICON_MD_EDIT_NOTE, ImGuiH::GetLineItemSize()))
58 {
59 std::stringstream ss;
60 ss << "C:/Windows/System32/notepad.exe " << m_Console->GetFilePath();
61
62 /**
63 * @brief Open Log file that in writtening.
64 */
65 ProcessLibrary::OpenProcess("C:/Windows/System32/notepad.exe ", ss.str().c_str());
66 }
67 ImGui::SetItemTooltip("Open Log File");
68 }
69
70 /**
71 * @brief Render OpenLogFolderIcon.
72 */
73 {
74 SPICES_PROFILE_ZONEN("Console OpenLogFolderIcon");
75
76 ImGui::SameLine();
77 if (ImGui::Button(ICON_MD_FOLDER, ImGuiH::GetLineItemSize()))
78 {
79 /**
80 * @brief Get Selected file in Explore.
81 */
82 std::string filepath = FileLibrary::FileLibrary_OpenInExplore(
83 "Spices Log (*.log)\0*.log\0",
84 glfwGetWin32Window((GLFWwindow*)VulkanRenderBackend::GetState().m_Windows)
85 );
86
87 if (!filepath.empty())
88 {
89 std::stringstream ss;
90 ss << "C:/Windows/System32/notepad.exe " << filepath;
91
92 /**
93 * @brief Open Log file that in writtening.
94 */
95 ProcessLibrary::OpenProcess("C:/Windows/System32/notepad.exe ", ss.str().c_str());
96 }
97 }
98 ImGui::SetItemTooltip("Open Log Folder");
99 }
100
101 /**
102 * @brief Render EnableCommandFieldIcon.
103 */
104 {
105 SPICES_PROFILE_ZONEN("Console EnableCommandFieldIcon");
106
107 ImGui::SameLine();
108 if (ImGui::Button(ICON_MD_TERMINAL, ImGuiH::GetLineItemSize())) m_EnableCmdInput = !m_EnableCmdInput;
109 ImGui::SetItemTooltip("Enable Command Field");
110 }
111
112 /**
113 * @brief Render FilterIcon.
114 */
115 {
116 SPICES_PROFILE_ZONEN("Console FilterIcon");
117
118 ImGui::SameLine(m_PanelSize.x - ImGuiH::GetLineItemSize().x * 5.7f - 220.0f);
119 if (ImGui::Button(ICON_MD_FILTER_ALT, ImGuiH::GetLineItemSize())) {}
120 ImGui::SetItemTooltip("Filter");
121 }
122
123 /**
124 * @brief Render VerboseIcon.
125 */
126 {
127 SPICES_PROFILE_ZONEN("Console VerboseIcon");
128
129 ImGui::SameLine();
130 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.83f, 0.83f, 0.83f, 1.0f));
131 if (ImGui::Button(ICON_MD_EMERGENCY, ImGuiH::GetLineItemSize())) m_Level = 0;
132 ImGui::PopStyleColor();
133 ImGui::SetItemTooltip("Verbose");
134 }
135
136 /**
137 * @brief Render InfoIcon.
138 */
139 {
140 SPICES_PROFILE_ZONEN("Console InfoIcon");
141
142 ImGui::SameLine();
143 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.574f, 0.829f, 1.0f, 1.0f));
144 if (ImGui::Button(ICON_MD_ERROR_OUTLINE, ImGuiH::GetLineItemSize())) m_Level = 1;
145 ImGui::PopStyleColor();
146 ImGui::SetItemTooltip("Info");
147 }
148
149 /**
150 * @brief Render WarningIcon.
151 */
152 {
153 SPICES_PROFILE_ZONEN("Console WarningIcon");
154
155 ImGui::SameLine();
156 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.974f, 0.896f, 0.39f, 1.0f));
157 if (ImGui::Button(ICON_MD_WARNING_AMBER, ImGuiH::GetLineItemSize())) m_Level = 2;
158 ImGui::PopStyleColor();
159 ImGui::SetItemTooltip("Warning");
160 ImGui::SameLine();
161 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.974f, 0.896f, 0.39f, 1.0f));
162 ImGui::Text(std::to_string(m_Console->GetInfos().m_WarnLogInfos.size()).c_str());
163 ImGui::PopStyleColor();
164 }
165
166 /**
167 * @brief Render ErrorIcon.
168 */
169 {
170 SPICES_PROFILE_ZONEN("Console ErrorIcon");
171
172 ImGui::SameLine();
173 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.641f, 0.59f, 1.0f));
174 if (ImGui::Button(ICON_MD_NEARBY_ERROR, ImGuiH::GetLineItemSize())) m_Level = 3;
175 ImGui::PopStyleColor();
176 ImGui::SetItemTooltip("Error");
177 ImGui::SameLine();
178 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(1.0f, 0.641f, 0.59f, 1.0f));
179 ImGui::Text(std::to_string(m_Console->GetInfos().m_ErrorLogInfos.size()).c_str());
180 ImGui::PopStyleColor();
181 }
182
183 /**
184 * @brief Search String.
185 */
186 static std::string searchString;
187 static bool isEnableSearch = false;
188
189 /**
190 * @brief Render Search Input Text.
191 */
192 {
193 SPICES_PROFILE_ZONEN("Console Search Input Text");
194
195 ImGui::SameLine();
196 ImGui::PushItemWidth(200);
197 static char search[128] = "";
198 if (ImGui::InputTextWithHint("##", ICON_TEXT(ICON_MD_SEARCH, Search), search, 128))
199 {
200 searchString = std::string(search);
201 if (searchString.size() == 0) isEnableSearch = false;
202 else isEnableSearch = true;
203 }
204 ImGui::PopItemWidth();
205 ImGui::Spacing();
206 ImGui::PushStyleColor(ImGuiCol_Separator, ImVec4(0.121f, 0.129f, 0.141f, 1.0f));
207 ImGui::Separator();
208 ImGui::PopStyleColor();
209 ImGui::Spacing();
210 }
211
212 /**
213 * @brief Render Console ScrollingRegion.
214 */
215 {
216 SPICES_PROFILE_ZONEN("Console ScrollingRegion");
217
218 ImGui::PushStyleColor(ImGuiCol_ChildBg, ImGui::GetStyleColorVec4(ImGuiCol_FrameBg));
219 ImGui::PushStyleColor(ImGuiCol_HeaderHovered, ImGui::GetStyleColorVec4(ImGuiCol_Border));
220
221 float itemHeight = m_EnableCmdInput ? 3.0f * ImGui::GetStyle().ItemSpacing.y + ImGui::GetFrameHeightWithSpacing() : ImGui::GetStyle().ItemSpacing.y;
222 if (ImGui::BeginChild("ScrollingRegion", ImVec2(0, -itemHeight), ImGuiChildFlags_None, ImGuiWindowFlags_HorizontalScrollbar))
223 {
224 ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2(4, 1));
225
226 bool isFiltered = m_Filter.IsActive();
227
228 switch (m_Level)
229 {
230 default:
231 break;
232 case 0:
233 for (auto it = m_Console->GetInfos().m_TraceLogInfos.rbegin(); it != m_Console->GetInfos().m_TraceLogInfos.rend(); ++it)
234 {
235 const InfoLevelHelper& helper = *it;
236
237 if (isEnableSearch)
238 {
239 if (helper.str.find(searchString) == std::string::npos) continue;
240 }
241
242 ImGui::PushStyleColor(ImGuiCol_Text, { helper.color.x, helper.color.y, helper.color.z, helper.color.w });
243 if (helper.level == "trace")
244 {
245 std::stringstream ss;
246 ss << ICON_MD_EMERGENCY << " " << helper.str;
247
248 ImGui::Selectable(ss.str().c_str(), false);
249 }
250 ImGui::PopStyleColor();
251 }
252 break;
253 case 1:
254 for (auto it = m_Console->GetInfos().m_InfoLogInfos.rbegin(); it != m_Console->GetInfos().m_InfoLogInfos.rend(); ++it)
255 {
256 const InfoLevelHelper& helper = *it;
257
258 if (isEnableSearch)
259 {
260 if (helper.str.find(searchString) == std::string::npos) continue;
261 }
262
263 ImGui::PushStyleColor(ImGuiCol_Text, { helper.color.x, helper.color.y, helper.color.z, helper.color.w });
264 if (helper.level == "info")
265 {
266 std::stringstream ss;
267 ss << ICON_MD_ERROR_OUTLINE << " " << helper.str;
268
269 ImGui::Selectable(ss.str().c_str(), false);
270 }
271 ImGui::PopStyleColor();
272 }
273 break;
274 case 2:
275 for (auto it = m_Console->GetInfos().m_WarnLogInfos.rbegin(); it != m_Console->GetInfos().m_WarnLogInfos.rend(); ++it)
276 {
277 const InfoLevelHelper& helper = *it;
278
279 if (isEnableSearch)
280 {
281 if (helper.str.find(searchString) == std::string::npos) continue;
282 }
283
284 ImGui::PushStyleColor(ImGuiCol_Text, { helper.color.x, helper.color.y, helper.color.z, helper.color.w });
285 if (helper.level == "warn")
286 {
287 std::stringstream ss;
288 ss << ICON_MD_WARNING_AMBER << " " << helper.str;
289
290 ImGui::Selectable(ss.str().c_str(), false);
291 }
292 ImGui::PopStyleColor();
293 }
294 break;
295 case 3:
296 for (auto it = m_Console->GetInfos().m_ErrorLogInfos.rbegin(); it != m_Console->GetInfos().m_ErrorLogInfos.rend(); ++it)
297 {
298 const InfoLevelHelper& helper = *it;
299
300 if (isEnableSearch)
301 {
302 if (helper.str.find(searchString) == std::string::npos) continue;
303 }
304
305 ImGui::PushStyleColor(ImGuiCol_Text, { helper.color.x, helper.color.y, helper.color.z, helper.color.w });
306 if (helper.level == "error")
307 {
308 std::stringstream ss;
309 ss << ICON_MD_NEARBY_ERROR << " " << helper.str;
310
311 ImGui::Selectable(ss.str().c_str(), false);
312 }
313 ImGui::PopStyleColor();
314 }
315 break;
316 }
317
318 ImGui::PopStyleVar();
319 }
320
321 ImGui::PopStyleColor(2);
322 ImGui::EndChild();
323 }
324
325 /**
326 * @brief Render Console Command-line.
327 */
328 {
330 {
331 SPICES_PROFILE_ZONEN("Console Command-line");
332
333 ImGui::Spacing();
334 ImGui::Separator();
335 ImGui::Spacing();
336 ImGui::PushItemWidth(-1);
337 bool reclaim_focus = false;
338 char InputBuf[512] = "";
339 ImGuiInputTextFlags input_text_flags =
340 ImGuiInputTextFlags_EnterReturnsTrue |
341 ImGuiInputTextFlags_EscapeClearsAll |
342 ImGuiInputTextFlags_CallbackCompletion |
343 ImGuiInputTextFlags_CallbackHistory |
344 ImGuiInputTextFlags_CallbackCharFilter ;
345 ImGui::InputTextWithHint(
346 "Cmd",
347 ICON_TEXT_ROW(" ", "Cmd"),
348 InputBuf,
349 IM_ARRAYSIZE(InputBuf),
350 input_text_flags,
351 &ImguiConsole::TextEditCallbackStub,
352 (void*)this
353 );
354 ImGui::PopItemWidth();
355 }
356 }
357
358 /**
359 * @brief End render Console.
360 */
361 End();
362 }
363
364 int ImguiConsole::TextEditCallbackStub(ImGuiInputTextCallbackData* data)
365 {
366 SPICES_CORE_INFO(data->Buf);
367
368 return 0;
369 }
370}
#define ICON_TEXT(icon, text)
Definition ImguiHelper.h:24
#define ICON_TEXT_ROW(icon, text)
Definition ImguiHelper.h:25
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
Console Entity Class.
Definition Console.h:82
FrameInfo Class. This class defines the FrameInfo data.
Definition FrameInfo.h:32
bool m_EnableCmdInput
The boolean of enable Cmd Input.
ImguiConsole(const std::string &panelName, FrameInfo &frameInfo, std::shared_ptr< Console > console)
Constructor Function.
virtual void OnRender() override
This interface is called On SlateRenderer Render.
int m_Level
The information level that console show.
The ImguiConsole Class. This class defines how to render a Console.
void End()
End a slate.
ImguiSlate(const std::string &panelName, FrameInfo &frameInfo)
Constructor Function. Init with Slate's name.
Definition ImguiUtils.h:35
This Class defines the basic behaves of specific slate. When we add an new Slate, we need inherit fro...
Definition ImguiUtils.h:27
static bool OpenProcess(const char *processPath, const char *commandLine="")
Open a Process with command.
Process Static Function Library.