SpiecsEngine
 
Loading...
Searching...
No Matches
ImguiHelper.cpp
Go to the documentation of this file.
1/**
2* @file ImguiHelper.cpp.
3* @brief The ImguiHelper Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "ImguiHelper.h"
9#include "Core/Library/FileLibrary.h"
10#include "Render/FrameInfo.h"
11#include "World/World/World.h"
12#include "Slate/SlateImage.h"
13#include "Render/Renderer/SpecificRenderer/SlateRenderer.h"
14
15// This file Only Can include once.
16#include <imgui.cpp>
17#include <imgui_internal.h>
18#include <imgui_widgets.cpp>
19#include <backends/imgui_impl_vulkan.cpp>
20
21namespace Spices {
22
24 {
26
27 /**
28 * @brief Set Dark Style.
29 */
30 ImGui::StyleColorsDark();
31
32 /**
33 * @brief Set Style.
34 */
35 ImGuiStyle& style = ImGui::GetStyle();
36 style.WindowRounding = 0.0f;
37 style.WindowBorderSize = 0.0f;
38 style.WindowPadding = ImVec2(3.0f, 3.0f);
39 style.ColorButtonPosition = ImGuiDir_Left;
40 style.FrameRounding = 4.0f;
41 style.FrameBorderSize = 0.0f;
42 style.FramePadding = ImVec2(2.0f, 2.0f);
43 style.GrabRounding = 4.0f;
44 style.IndentSpacing = 12.0f;
45 style.ItemSpacing = ImVec2(2.0f, 2.0f);
46 style.ScrollbarSize = 4.0f;
47 style.SeparatorTextAlign = ImVec2(0.0f, 0.5f);
48 style.SeparatorTextPadding = ImVec2(0.0f, 0.0f);
49 style.SeparatorTextBorderSize = 1.0f;
50 style.GrabMinSize = 2.0f;
51 style.Colors[ImGuiCol_WindowBg] = ImVec4(0.27f, 0.27f, 0.27f, 1.0f);
52 style.Colors[ImGuiCol_MenuBarBg] = style.Colors[ImGuiCol_WindowBg];
53 style.Colors[ImGuiCol_ScrollbarBg] = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
54 style.Colors[ImGuiCol_PopupBg] = ImVec4(0.135f, 0.135f, 0.135f, 1.0f);
55 style.Colors[ImGuiCol_Border] = ImVec4(0.141f, 0.129f, 0.121f, 1.0f);
56 style.Colors[ImGuiCol_FrameBg] = ImVec4(0.125f, 0.129f, 0.137f, 1.0f);
57 style.Colors[ImGuiCol_PopupBg] = ImVec4(0.22f, 0.231f, 0.239f, 1.0f);
58 style.Colors[ImGuiCol_TabUnfocused] = style.Colors[ImGuiCol_WindowBg];
59 style.Colors[ImGuiCol_TabActive] = style.Colors[ImGuiCol_WindowBg];
60 style.Colors[ImGuiCol_TabUnfocusedActive] = style.Colors[ImGuiCol_WindowBg];
61 style.Colors[ImGuiCol_TabHovered] = ImVec4(0.2f, 0.2f, 0.2f, 1.0f);
62
63 /**
64 * @brief Set Botton Style.
65 */
66 style.Colors[ImGuiCol_Button] = style.Colors[ImGuiCol_WindowBg];
67 style.Colors[ImGuiCol_ButtonActive] = style.Colors[ImGuiCol_FrameBg];
68 style.Colors[ImGuiCol_ButtonHovered]= ImVec4(0.3f, 0.3f, 0.3f, 1.0f);
69
70 /**
71 * @brief Set Normal Style.
72 */
73 constexpr ImVec4 normal_color(0.465f, 0.465f, 0.525f, 1.0f);
74 std::vector<ImGuiCol> to_change_nrm;
75 to_change_nrm.push_back(ImGuiCol_Header);
76 to_change_nrm.push_back(ImGuiCol_SliderGrab);
77 to_change_nrm.push_back(ImGuiCol_CheckMark);
78 to_change_nrm.push_back(ImGuiCol_ResizeGrip);
79 to_change_nrm.push_back(ImGuiCol_TextSelectedBg);
80 to_change_nrm.push_back(ImGuiCol_Separator);
81 to_change_nrm.push_back(ImGuiCol_FrameBgActive);
82 for (auto c : to_change_nrm)
83 {
84 style.Colors[c] = normal_color;
85 }
86
87 /**
88 * @brief Set Active Style.
89 */
90 constexpr ImVec4 active_color(0.365f, 0.365f, 0.425f, 1.0f);
91 std::vector<ImGuiCol> to_change_act;
92 to_change_act.push_back(ImGuiCol_HeaderActive);
93 to_change_act.push_back(ImGuiCol_SliderGrabActive);
94 to_change_act.push_back(ImGuiCol_ResizeGripActive);
95 to_change_act.push_back(ImGuiCol_SeparatorActive);
96 for (auto c : to_change_act)
97 {
98 style.Colors[c] = active_color;
99 }
100
101 /**
102 * @brief Set Hovered Style.
103 */
104 constexpr ImVec4 hovered_color(0.565f, 0.565f, 0.625f, 1.0f);
105 std::vector<ImGuiCol> to_change_hover;
106 to_change_hover.push_back(ImGuiCol_HeaderHovered);
107 to_change_hover.push_back(ImGuiCol_FrameBgHovered);
108 to_change_hover.push_back(ImGuiCol_ResizeGripHovered);
109 to_change_hover.push_back(ImGuiCol_SeparatorHovered);
110 for (auto c : to_change_hover)
111 {
112 style.Colors[c] = hovered_color;
113 }
114
115 style.Colors[ImGuiCol_TitleBgActive] = ImVec4(0.465f, 0.465f, 0.465f, 1.0f);
116 style.Colors[ImGuiCol_TitleBg] = ImVec4(0.125f, 0.125f, 0.125f, 1.0f);
117 style.Colors[ImGuiCol_Tab] = ImVec4(0.05f, 0.05f, 0.05f, 0.5f);
118 style.Colors[ImGuiCol_TabHovered] = ImVec4(0.465f, 0.495f, 0.525f, 1.0f);
119 style.Colors[ImGuiCol_TabActive] = ImVec4(0.282f, 0.290f, 0.302f, 1.0f);
120 style.Colors[ImGuiCol_ModalWindowDimBg] = ImVec4(0.465f, 0.465f, 0.465f, 0.350f);
121
122 //Colors_ext[ImGuiColExt_Warning] = ImVec4 (1.0f, 0.43f, 0.35f, 1.0f);
123
124 ImGui::SetColorEditOptions(ImGuiColorEditFlags_Float | ImGuiColorEditFlags_PickerHueWheel);
125 }
126
127 void ImGuiH::SetFonts(FontMode fontmode)
128 {
130
131 ImGuiIO& io = ImGui::GetIO();
132 const float high_dpi_scale = GetDPIScale();
133
134 /**
135 * @brief Set Nicer fonts.
136 */
137 ImFont* font = nullptr;
138 if (fontmode == FONT_MONOSPACED_SCALED)
139 {
140 if (font == nullptr)
141 {
142 const std::string p = R"(C:/Windows/Fonts/consola.ttf)";
144 {
145 font = io.Fonts->AddFontFromFileTTF(p.c_str(), 12.0f * high_dpi_scale);
146 }
147 }
148 }
149 else if (fontmode == FONT_PROPORTIONAL_SCALED)
150 {
151 const char* vk_path = getenv("VK_SDK_PATH");
152 if (vk_path)
153 {
154 const std::string p = std::string(vk_path) + R"(/Samples/Layer-Samples/data/FreeSans.ttf)";
155 if (FileLibrary::FileLibrary_Exists(p.c_str()))
156 font = io.Fonts->AddFontFromFileTTF(p.c_str(), 16.0f * high_dpi_scale);
157 }
158 if (font == nullptr)
159 {
160 const std::string p = R"(C:/Windows/Fonts/segoeui.ttf)";
161 if (FileLibrary::FileLibrary_Exists(p.c_str()))
162 font = io.Fonts->AddFontFromFileTTF(p.c_str(), 16.0f * high_dpi_scale);
163 }
164 }
165
166 if (font == nullptr)
167 {
168 ImFontConfig font_config = ImFontConfig();
169 font_config.SizePixels = 13.0f * ((fontmode == FONT_FIXED) ? 1 : high_dpi_scale); // 13 is the default font size
170 io.Fonts->AddFontDefault(&font_config);
171 }
172
173 float iconFontSize = 15.0f * high_dpi_scale;
174
175 // merge in icons from Font Awesome
176 static constexpr ImWchar icons_ranges[] = { ICON_MIN_MD, ICON_MAX_16_MD, 0 };
177 ImFontConfig icons_config;
178 icons_config.MergeMode = true;
179 icons_config.PixelSnapH = true;
180 icons_config.GlyphMinAdvanceX = iconFontSize;
181 icons_config.GlyphOffset.y = 3.0f;
182
183 std::stringstream ss;
184 ss << SPICES_ENGINE_ASSETS_PATH << "Fonts/" << FONT_ICON_FILE_NAME_MD;
185 if (FileLibrary::FileLibrary_Exists(ss.str().c_str()))
186 {
187 io.Fonts->AddFontFromFileTTF(ss.str().c_str(), iconFontSize, &icons_config, icons_ranges);
188 }
189 }
190
191 void ImGuiH::MainDockSpace(Side side, float alpha)
192 {
194
195 // Keeping the unique ID of the dock space
196 ImGuiID dockspaceID = ImGui::GetID("DockSpace");
197
198 // The dock need a dummy window covering the entire viewport.
199 const ImGuiViewport* viewport = ImGui::GetMainViewport();
200 ImGui::SetNextWindowPos(viewport->WorkPos);
201 ImGui::SetNextWindowSize(viewport->WorkSize);
202 ImGui::SetNextWindowViewport(viewport->ID);
203 // All flags to dummy window
204 ImGuiWindowFlags host_window_flags = 0;
205 host_window_flags |= ImGuiWindowFlags_NoTitleBar | ImGuiWindowFlags_NoCollapse | ImGuiWindowFlags_NoResize;
206 host_window_flags |= ImGuiWindowFlags_NoMove; //| ImGuiWindowFlags_NoDocking;
207 host_window_flags |= ImGuiWindowFlags_NoBringToFrontOnFocus | ImGuiWindowFlags_NoNavFocus;
208 host_window_flags |= ImGuiWindowFlags_NoBackground;
209 // Starting dummy window
210 char label[32];
211 ImFormatString(label, IM_ARRAYSIZE(label), "DockSpaceViewport_%08X", viewport->ID);
212 ImGui::Begin(label, NULL, host_window_flags);
213
214 // The central node is transparent, so that when UI is draw after, the image is visible
215 // Auto Hide Bar, no title of the panel
216 // Center is not dockable, that is for the scene
217 ImGuiDockNodeFlags dockspaceFlags =
218 ImGuiDockNodeFlags_PassthruCentralNode;
219 //ImGuiDockNodeFlags_AutoHideTabBar;
220 //ImGuiDockNodeFlags_NoDockingInCentralNode;
221
222 // Building the splitting of the dock space is done only once
223 if (!ImGui::DockBuilderGetNode(dockspaceID))
224 {
225
226 ImGui::DockBuilderRemoveNode(dockspaceID);
227 ImGui::DockBuilderAddNode(dockspaceID, ImGuiDockNodeFlags_DockSpace);
228
229 ImGuiID dock_main_id = dockspaceID;
230
231 // Slitting all 4 directions
232 ImGuiID id_left = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Left, 0.2f, nullptr, &dock_main_id);
233 ImGui::DockBuilderDockWindow(side == Side::Left ? "Docking Space" : "Dock_left", id_left);
234
235 ImGuiID id_right = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Right, 0.2f, nullptr, &dock_main_id);
236 ImGui::DockBuilderDockWindow(side == Side::Right ? "Docking Space" : "Dock_right", id_right);
237
238 ImGuiID id_up = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Up, 0.2f, nullptr, &dock_main_id);
239 ImGui::DockBuilderDockWindow(side == Side::Up ? "Docking Space" : "Dock_up", id_up);
240
241 ImGuiID id_down = ImGui::DockBuilderSplitNode(dock_main_id, ImGuiDir_Down, 0.2f, nullptr, &dock_main_id);
242 ImGui::DockBuilderDockWindow(side == Side::Down ? "Docking Space" : "Dock_down", id_down);
243
244 ImGui::DockBuilderDockWindow(side == Side::Scene ? "Docking Space" : "Scene", dock_main_id); // Center
245
246 ImGui::DockBuilderFinish(dock_main_id);
247 }
248
249 // Setting the panel to blend with alpha
250 ImVec4 col = ImGui::GetStyleColorVec4(ImGuiCol_WindowBg);
251 ImGui::PushStyleColor(ImGuiCol_WindowBg, ImVec4(col.x, col.y, col.z, alpha));
252
253 ImGui::DockSpace(dockspaceID, ImVec2(0.0f, 0.0f), dockspaceFlags);
254 ImGui::PopStyleColor();
255 ImGui::End();
256 }
257
258 ImVec2 ImGuiH::GetLineItemSize()
259 {
260 float x = ImGui::GetFont()->FontSize * ImGui::GetIO().FontGlobalScale + ImGui::GetStyle().FramePadding.y * 2.0f;
261 return ImVec2(x, x);
262 }
263
264 bool ImGuiH::DrawResetIcon(const bool& isMove)
265 {
266 bool IsReset = false;
267
268 if (isMove)
269 {
270 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetStyle().Colors[ImGuiCol_Button]);
271 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.31f, 0.49f, 0.62f, 1.0f));
272 IsReset = ImGui::Button(ICON_MD_SQUARE, ImGuiH::GetLineItemSize());
273 ImGui::PopStyleColor(2);
274 }
275 else
276 {
277 ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImGui::GetStyle().Colors[ImGuiCol_Button]);
278 ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImGui::GetStyle().Colors[ImGuiCol_Button]);
279 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.4f, 0.4f, 0.4f, 1.0f));
280 //ImGui::Button(ICON_MD_CROP_SQUARE, ImGuiH::GetLineItemSize());
281 ImGui::SetWindowFontScale(0.65f);
282 ImGui::Button(ICON_MD_STOP, ImGuiH::GetLineItemSize());
283 ImGui::SetWindowFontScale(1.0f);
284 ImGui::PopStyleColor(3);
285 }
286
287 return IsReset;
288 }
289
290 void ImGuiH::Checkbox(bool* isChecked)
291 {
292 ImGui::PushStyleColor(ImGuiCol_Text, ImVec4(0.6f, 0.6f, 0.6f, 1.0f));
293 if (ImGui::Button(*isChecked ? ICON_MD_CHECK_BOX : ICON_MD_SQUARE, ImGuiH::GetLineItemSize()))
294 {
295 *isChecked = !*isChecked;
296 }
297 ImGui::PopStyleColor();
298 }
299
301 {
302 ImGui::SetWindowFontScale(0.5f);
303 ImGui::SeparatorText("##");
304 ImGui::SetWindowFontScale(1.0f);
305 }
306
307 void ImGuiH::CustomMaterialImage(SlateImage* context, ImVec2 size)
308 {
310
311 ImGuiWindow* window = ImGui::GetCurrentWindow();
312 const ImRect bb(window->DC.CursorPos, window->DC.CursorPos + size);
313
314 ImDrawList* draw_list = ImGui::GetWindowDrawList();
315 draw_list->PushTextureID(context->GetTextureID());
316 draw_list->PrimReserve(6, 4);
317 draw_list->PrimRectUV(bb.Min, bb.Max, ImVec2(0.0f, 0.0f), ImVec2(1.0f, 1.0f), ImGui::GetColorU32(ImVec4(1.0f, 1.0f, 1.0f, 1.0f)));
318 draw_list->AddCallback([](const ImDrawList* drawList, const ImDrawCmd* cmd, const int global_idx_offset, const int global_vtx_offset) {
319
320 ImGui_ImplVulkan_RenderState* render_state = (ImGui_ImplVulkan_RenderState*)ImGui::GetPlatformIO().Renderer_RenderState;
321 auto set = reinterpret_cast<VkDescriptorSet>(cmd->GetTexID());
322 auto pipeline = static_cast<VulkanPipeline*>(cmd->UserCallbackData);
323
324 ImGui_ImplVulkan_Data* bd = ImGui_ImplVulkan_GetBackendData();
325 vkCmdBindDescriptorSets(render_state->CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, render_state->PipelineLayout, 0, 1, &set, 0, nullptr);
326
327 //vkCmdBindPipeline(render_state->CommandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pipeline->GetPipeline());
328
329 vkCmdDrawIndexed(render_state->CommandBuffer, cmd->ElemCount, 1, cmd->IdxOffset + global_idx_offset, cmd->VtxOffset + global_vtx_offset, 0);
330
331 }, SlateRenderer::GetPipeline(context->GetMaterial()->GetName()).get());
332 draw_list->PopTextureID();
333 draw_list->AddCallback(ImDrawCallback_ResetRenderState, nullptr);
334 }
335
336 void ImGuiH::DrawPropertyItem(
337 const std::string& itemName ,
338 float columeWidth ,
339 std::function<void()> nameFunc ,
340 std::function<void()> valFunc
341 )
342 {
343 SPICES_PROFILE_ZONEN("DrawPropertyItem");
344
345 ImGui::PushID(itemName.c_str());
346 ImGui::Columns(2, 0, false);
347
348 ImGui::SetColumnWidth(0, columeWidth);
349
350 if (nameFunc)
351 {
352 nameFunc();
353 }
354 else
355 {
356 ImGui::Text(itemName.c_str());
357 }
358
359 ImGui::NextColumn();
360
361 valFunc();
362
363 ImGui::Columns(1);
364 ImGui::PopID();
365 }
366
367 void ImGuiH::DrawTreeTitle(
368 const std::string& treeName ,
369 std::function<void()> optionFunc ,
370 std::function<void()> treeFunc
371 )
372 {
374
375 constexpr ImGuiTreeNodeFlags treeNodeFlags =
376 ImGuiTreeNodeFlags_DefaultOpen |
377 ImGuiTreeNodeFlags_AllowItemOverlap |
378 ImGuiTreeNodeFlags_Framed |
379 ImGuiTreeNodeFlags_FramePadding ;
380
381 ImGui::PushStyleColor(ImGuiCol_Header , ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
382 ImGui::PushStyleColor(ImGuiCol_HeaderHovered , ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
383 ImGui::PushStyleColor(ImGuiCol_HeaderActive , ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
384 ImGui::PushStyleColor(ImGuiCol_WindowBg , ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
385
386 ImGui::PushStyleVar(ImGuiStyleVar_FramePadding , ImVec2(2.0f, 6.0f));
387 const bool open = ImGui::TreeNodeEx(treeName.c_str(), treeNodeFlags, treeName.c_str());
388 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGuiH::GetLineItemSize().x);
389 ImGui::PushStyleColor(ImGuiCol_Button , ImVec4(0.16f, 0.16f, 0.16f, 1.0f));
390 ImGui::PushStyleColor(ImGuiCol_ButtonHovered , ImVec4(0.608f, 0.608f, 0.608f, 1.0f));
391 ImGui::PushStyleColor(ImGuiCol_ButtonActive , ImVec4(0.396f, 0.439f, 0.168f, 1.0f));
392 if (ImGui::Button(ICON_MD_FILTER_VINTAGE, ImGuiH::GetLineItemSize()))
393 {
394 ImGui::OpenPopup(treeName.c_str());
395 }
396 ImGui::PopStyleColor(3);
397 ImGui::PopStyleVar();
398 if (ImGui::BeginPopup(treeName.c_str()))
399 {
400 if (optionFunc)
401 {
402 optionFunc();
403 }
404 ImGui::EndPopup();
405 }
406 if (open)
407 {
408 if (treeFunc)
409 {
410 treeFunc();
411 }
412 ImGui::TreePop();
413 }
414
415 ImGui::PopStyleColor(4);
416 }
417
418 void ImGuiH::DrawTreeProgressBar(
419 const std::string& treeName,
420 std::function<void()> progressFunc,
421 std::function<void()> treeFunc
422 )
423 {
425
426 constexpr ImGuiTreeNodeFlags treeNodeFlags =
427 ImGuiTreeNodeFlags_DefaultOpen |
428 ImGuiTreeNodeFlags_AllowItemOverlap |
429 ImGuiTreeNodeFlags_Framed |
430 ImGuiTreeNodeFlags_Bullet |
431 ImGuiTreeNodeFlags_FramePadding ;
432
433 ImGui::PushStyleColor(ImGuiCol_Header , ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
434 ImGui::PushStyleColor(ImGuiCol_HeaderHovered , ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
435 ImGui::PushStyleColor(ImGuiCol_HeaderActive , ImVec4(0.164f, 0.18f, 0.184f, 1.0f));
436 ImGui::PushStyleColor(ImGuiCol_WindowBg , ImVec4(0.196f, 0.204f, 0.2f, 1.0f));
437
438 const bool open = ImGui::TreeNodeEx(treeName.c_str(), treeNodeFlags, treeName.c_str());
439
440 if (progressFunc)
441 {
442 ImGui::SameLine(ImGui::GetContentRegionAvail().x * 0.3f);
443 progressFunc();
444 }
445
446 if (open)
447 {
448 if (treeFunc)
449 {
450 treeFunc();
451 }
452 ImGui::TreePop();
453 }
454
455 ImGui::PopStyleColor(4);
456 }
457
459 const std::string& name ,
460 float width ,
461 const std::shared_ptr<Material>& material
462 )
463 {
465
466 ImGuiH::DrawTreeTitle(name, nullptr, [&]() {
467
468 material->GetConstantParams().for_each([&](const std::string& k, ConstantParams& v){
469 ImGuiH::DrawPropertyItem(k, width, nullptr, [&](){
470 if(v.value.paramType == "float")
471 {
472 if (ImGuiH::DrawMaterialConstParams<float>(material, ImGuiDataType_Float, 1, "%.3f", v))
473 {
474 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
475 }
476 }
477 else if(v.value.paramType == "float2")
478 {
479 if (ImGuiH::DrawMaterialConstParams<glm::vec2>(material, ImGuiDataType_Float, 2, "%.3f", v))
480 {
481 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
482 }
483 }
484 else if(v.value.paramType == "float3")
485 {
486 if (ImGuiH::DrawMaterialConstParams<glm::vec3>(material, ImGuiDataType_Float, 3, "%.3f", v))
487 {
488 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
489 }
490 }
491 else if(v.value.paramType == "float4")
492 {
493 if (ImGuiH::DrawMaterialConstParams<glm::vec4>(material, ImGuiDataType_Float, 4, "%.3f", v))
494 {
495 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
496 }
497 }
498 else if(v.value.paramType == "int")
499 {
500 if (ImGuiH::DrawMaterialConstParams<int>(material, ImGuiDataType_S32, 1, "%d", v))
501 {
502 FrameInfo::Get().m_World->Mark(World::NeedUpdateTLAS | World::FrushStableFrame);
503 }
504 }
505 else if (v.value.paramType == "bool")
506 {
507 bool f = std::any_cast<bool>(v.value.paramValue);
508 bool nf = f;
509 bool df = std::any_cast<bool>(v.defaultValue.paramValue);
510
511 const float seperatorWidthS = ImGuiH::GetLineItemSize().x - 3.0f * ImGui::GetStyle().IndentSpacing;
512 ImGuiH::Checkbox(&nf);
513 if (nf != f)
514 {
515 v.value.paramValue = nf;
516 material->UpdateMaterial();
517 }
518 ImGui::SameLine();
519 ImGui::PushItemWidth(100.0f);
520 ImGui::SeparatorText("##");
521 ImGui::PopItemWidth();
522 ImGui::SameLine(ImGui::GetContentRegionAvail().x - ImGui::GetStyle().ItemSpacing.x);
523 if (ImGuiH::DrawResetIcon(f != df))
524 {
525 v.value.paramValue = df;
526 material->UpdateMaterial();
527 }
528 }
529 });
530 return false;
531 });
532 });
533 }
534
535 bool ImGuiH::S_DragScalarN(
536 const char* label ,
537 ImGuiDataType data_type ,
538 void* p_data ,
539 int components ,
540 float v_speed ,
541 const void* p_min ,
542 const void* p_max ,
543 const char* format ,
544 ImGuiSliderFlags flags
545 )
546 {
547 using namespace ImGui;
548
549 ImGuiWindow* window = GetCurrentWindow();
550 if (window->SkipItems)
551 return false;
552
553 ImGuiContext& g = *GImGui;
554 bool value_changed = false;
555 BeginGroup();
556 PushID(label);
557 PushMultiItemsWidths(components, CalcItemWidth());
558 size_t type_size = GDataTypeInfo[data_type].Size;
559 for (int i = 0; i < components; i++)
560 {
561 PushID(i);
562 if (i > 0)
563 SameLine(0, g.Style.ItemInnerSpacing.x);
564 const void* cp_min = (float*)p_min + i;
565 const void* cp_mmx = (float*)p_max + i;
566 value_changed |= DragScalar("", data_type, p_data, v_speed, cp_min, cp_mmx, format, flags);
567 PopID();
568 PopItemWidth();
569 p_data = (void*)((char*)p_data + type_size);
570 }
571 PopID();
572
573 const char* label_end = FindRenderedTextEnd(label);
574 if (label != label_end)
575 {
576 SameLine(0, g.Style.ItemInnerSpacing.x);
577 TextEx(label, label_end);
578 }
579
580 EndGroup();
581 return value_changed;
582 }
583
585 {
587
588 // Cached DPI scale, so that this doesn't change after the first time code calls getDPIScale.
589 // A negative value indicates that the value hasn't been computed yet.
590 static float cached_dpi_scale = -1.0f;
591
592 if (cached_dpi_scale < 0.0f)
593 {
594 // Compute the product of the monitor DPI scale and any DPI scale
595 // set in the NVPRO_DPI_SCALE variable.
596 cached_dpi_scale = 1.0f;
597
598 GLFWmonitor* monitor = glfwGetPrimaryMonitor();
599 if (monitor != nullptr)
600 {
601 float y_scale;
602 glfwGetMonitorContentScale(monitor, &cached_dpi_scale, &y_scale);
603 }
604 // Otherwise, GLFW isn't initialized yet, but might be in the future.
605 // (Note that this code assumes all samples use GLFW.)
606
607 // Multiply by the value of the NVPRO_DPI_SCALE environment variable.
608 const char* dpi_env = getenv("NVPRO_DPI_SCALE");
609 if (dpi_env)
610 {
611 const float parsed_dpi_env = strtof(dpi_env, nullptr);
612 if (parsed_dpi_env != 0.0f)
613 {
614 cached_dpi_scale *= parsed_dpi_env;
615 }
616 }
617
618 cached_dpi_scale = (cached_dpi_scale > 0.0f ? cached_dpi_scale : 1.0f);
619 }
620
621 return cached_dpi_scale;
622 }
623}
624
625namespace ImGui {
626
627 void CenteredText(const char* label, const ImVec2& size_arg)
628 {
629 ImGuiWindow* window = GetCurrentWindow();
630
631 ImGuiContext& g = *GImGui;
632 const ImGuiStyle& style = g.Style;
633 const ImGuiID id = window->GetID(label);
634 const ImVec2 label_size = CalcTextSize(label, NULL, true);
635
636 ImVec2 pos = window->DC.CursorPos;
637 ImVec2 size = CalcItemSize(size_arg, label_size.x + style.FramePadding.x * 2.0f, label_size.y + style.FramePadding.y * 2.0f);
638
639 const ImVec2 pos2 = ImVec2((pos.x + size.x), (pos.y + size.y));
640 const ImRect bb(pos, pos2);
641
642 ItemSize(size, style.FramePadding.y);
643
644 const ImVec2 pos_min = ImVec2((bb.Min.x + style.FramePadding.x), (bb.Min.y + style.FramePadding.y));
645 const ImVec2 pos_max = ImVec2((bb.Max.x - style.FramePadding.x), (bb.Max.y - style.FramePadding.y));
646
647 RenderTextClipped(pos_min, pos_max, label, NULL, &label_size, style.ButtonTextAlign, &bb);
648 }
649}
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
static bool FileLibrary_Exists(const char *path)
Determine whether the given string is existing a file.
File Static Function Library.
Definition FileLibrary.h:49
static void SetFonts(FontMode fontmode=FontMode::FONT_PROPORTIONAL_SCALED)
Looking for TTF fonts, first on the VULKAN SDK, then Windows default fonts.
static void SetStyle()
Setting common style across samples.
static void MainMenuTitleSeparator()
Draw main menu titile separator.
static bool DrawResetIcon(const bool &isMove)
Draw Reset Icon.
static void DrawMaterial(const std::string &name, float width, const std::shared_ptr< Material > &material)
Draw a Material.
static void MainDockSpace(Side side=Side::Scene, float alpha=1.0f)
Begin a docking space.
static void Checkbox(bool *isChecked)
ImGuiHelper Style Checkbox.
static float GetDPIScale()
Get GLFW DPI Scale.
The ImGuiH Class. This class defines helper function for slate render.
Definition ImguiHelper.h:61
Material Class. This class contains a branch of parameter and shader, also descriptor.
Definition Material.h:62
Slate image draw context.
Definition SlateImage.h:18
void CenteredText(const char *label, const ImVec2 &size_arg)
Draw a center text.
Side
Where the slate's initialized pos.
Definition ImguiHelper.h:43
FontMode
Slate Font Mode.
Definition ImguiHelper.h:32
@ FONT_MONOSPACED_SCALED
Definition ImguiHelper.h:35
@ FONT_PROPORTIONAL_SCALED
Definition ImguiHelper.h:34