This repository was archived by the owner on Jul 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathmodals.cpp
More file actions
53 lines (44 loc) · 1.72 KB
/
modals.cpp
File metadata and controls
53 lines (44 loc) · 1.72 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
#include "modals.hpp"
void modalManager::Run(std::function<void()> func, ImVec2 size, std::string naming)
{
m_bShow = true;
m_v2Size = size;
m_fContent = func;
name = naming;
}
void modalManager::Instance()
{
if (!m_bShow)
return;
ImGui::Begin("MODAL", 0, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoMove);
{
ImGui::SetWindowPos(ImVec2(0, 0));
ImGui::SetWindowSize(ImGui::GetIO().DisplaySize);
auto pos = ImGui::GetWindowPos();
auto draw = ImGui::GetWindowDrawList();
auto windowSize = ImGui::GetWindowSize();
draw->AddRectFilled(pos, pos + windowSize, ImColor(35, 35, 35, int(210)));
ImGui::SetCursorPos(ImVec2(windowSize / 2 - ImVec2((m_v2Size.x) / 2, (m_v2Size.y) / 2)));
ImGui::BeginChild("MODAL_CONTENT", ImVec2(m_v2Size.x, m_v2Size.y), false, ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration);
{
auto pos_internal = ImGui::GetWindowPos();
auto draw_internal = ImGui::GetWindowDrawList();
draw_internal->AddRectFilled(pos_internal, pos_internal + ImVec2(m_v2Size.x, m_v2Size.y), ImColor(65, 65, 65, 255), 6);
draw_internal->AddRectFilled(pos_internal, pos_internal + ImVec2(m_v2Size.x, 30), ImColor(45, 45, 45, 255), 6, ImDrawCornerFlags_Top);
draw_internal->AddText(pos_internal + ImVec2(10, 8), ImColor(240, 240, 240), name.c_str());
ImGui::SetCursorPos({ 10, 40 });
ImGui::BeginGroup();
{
m_fContent();
}
ImGui::EndGroup();
if (!ImGui::IsMouseHoveringRect(
pos + windowSize / 2 - m_v2Size / 2 - ImVec2(15, 15),
pos + windowSize / 2 + m_v2Size / 2 + ImVec2(15, 15)
) && ImGui::IsMouseClicked(0) && !ImGui::IsPopupOpen("", ImGuiPopupFlags_AnyPopupId))
m_bShow = false;
}
ImGui::EndChild();
}
ImGui::End();
}