SpiecsEngine
 
Loading...
Searching...
No Matches
ImguiUtils.cpp
Go to the documentation of this file.
1/**
2* @file ImguiUtils.cpp.
3* @brief The ImguiUtils Class Implementation.
4* @author Spices.
5*/
6
7#include "Pchheader.h"
8#include "ImguiUtils.h"
9
10#include "Render/Vulkan/VulkanImage.h"
11
12namespace Spices {
13
14 void ImguiSlate::Begin(float alpha, ImGuiWindowFlags flags)
15 {
16 Begin(m_PanelName, alpha, flags);
17 }
18
19 void ImguiSlate::Begin(const std::string& panelName, float alpha, ImGuiWindowFlags flags)
20 {
22
23 m_WindowFlags |= flags;
24 m_WindowFlags |= ImGuiWindowFlags_NoCollapse;
25
26 // The panel
27 if (alpha < 1)
28 {
29 ImGui::SetNextWindowBgAlpha(alpha); // For when the panel becomes a floating window
30 }
31
32 ImGui::Begin(panelName.c_str(), &m_IsSlateOn, m_WindowFlags);
33
34 if (ImGui::BeginPopupContextItem())
35 {
36 if (ImGui::MenuItem("Close"))
37 m_IsSlateOn = false;
38 ImGui::EndPopup();
39 }
40
41 /**
42 * @brief Query Resize Event Condition.
43 */
44 QueryIsResizedThisFrame(ImGui::GetContentRegionAvail());
45
46 /**
47 * @brief Query Slate State, maybe implementate in parent.
48 */
49 {
50 SPICES_PROFILE_ZONEN("Query Slate State");
51
52 m_PanelPos = ImGui::GetWindowPos();
53 m_IsFocused = ImGui::IsWindowFocused();
54 m_IsHovered = ImGui::IsWindowHovered();
55 }
56 }
57
59 {
61
62 ImGui::End();
63 }
64
65 void ImguiSlate::LoadSlateIcon(ImTextureID& id, const std::string& iconFile)
66 {
68
69 auto rowPtr = ResourcePool<Texture>::Load<Texture2D>(iconFile, iconFile);
70 auto info = rowPtr->GetResource<VulkanImage>()->GetImageInfo();
71
72 id = reinterpret_cast<ImTextureID>(ImGui_ImplVulkan_AddTexture(info->sampler, info->imageView, info->imageLayout));
73 }
74
75 void ImguiSlate::QueryIsResizedThisFrame(const ImVec2& thisFrameSize)
76 {
78
79 if (m_PanelSize.x != thisFrameSize.x || m_PanelSize.y != thisFrameSize.y)
80 {
81 m_IsResized = true;
82 }
83 else
84 {
85 m_IsResized = false;
86 }
87
88 m_PanelSize = thisFrameSize;
89 }
90}
#define SPICES_PROFILE_ZONEN(...)
#define SPICES_PROFILE_ZONE
void Begin(float alpha=1.0f, ImGuiWindowFlags flags=0)
Begin a common slate.
void Begin(const std::string &panelName, float alpha=1.0f, ImGuiWindowFlags flags=0)
Begin a common slate with name.
void End()
End a slate.
virtual void QueryIsResizedThisFrame(const ImVec2 &thisFrameSize)
Query whether viewport is resized this frame.
void LoadSlateIcon(ImTextureID &id, const std::string &iconFile)
Load a Texture from ResourcePool.
bool m_IsResized
Boolean of whether resized this frame.
Definition ImguiUtils.h:186
This Class defines the basic behaves of specific slate. When we add an new Slate, we need inherit fro...
Definition ImguiUtils.h:27