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
141
142
143
144
145
146
147
|
#include "EditorResources.hpp"
#include "EditorCore.hpp"
#include "EditorNotification.hpp"
#include "EditorUtils.hpp"
#include "Macros.hpp"
#include "ScopeGuard.hpp"
#include "Shader.hpp"
#include <imgui.h>
#include <misc/cpp/imgui_stdlib.h>
#include <cstdlib>
#include <limits>
#include <string>
#include <string_view>
using namespace std::literals;
EditorContentBrowser::EditorContentBrowser(EditorInstance* editor)
: mEditor{ editor } {
}
EditorContentBrowser::~EditorContentBrowser() {
}
void EditorContentBrowser::Show(bool* open) {
ImGuiWindowFlags windowFlags;
if (docked) {
// Center window horizontally, align bottom vertically
auto& viewportSize = ImGui::GetMainViewport()->Size;
ImGui::SetNextWindowPos(ImVec2(viewportSize.x / 2, viewportSize.y), ImGuiCond_Always, ImVec2(0.5f, 1.0f));
ImGui::SetNextWindowSizeRelScreen(0.8f, 0.5f);
windowFlags = ImGuiWindowFlags_NoMove | ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse;
} else {
windowFlags = 0;
}
ImGui::Begin("Content Browser", open, windowFlags);
ImGui::Splitter(true, kSplitterThickness, &splitterLeft, &splitterRight, kLeftPaneMinWidth, kRightPaneMinWidth);
ImGui::BeginChild("LeftPane", ImVec2(splitterLeft - kPadding, 0.0f));
{
if (ImGui::Selectable("Settings", mPane == P_Settings)) {
mPane = P_Settings;
}
if (ImGui::Selectable("Shaders", mPane == P_Shader)) {
mPane = P_Shader;
}
if (ImGui::Selectable("Materials", mPane == P_Material)) {
mPane = P_Material;
}
}
ImGui::EndChild();
ImGui::SameLine(0.0f, kPadding + kSplitterThickness + kPadding);
ImGui::BeginChild("RightPane"); // Fill remaining space
{
switch (mPane) {
case P_Settings: {
ImGui::Checkbox("Docked", &docked);
} break;
case P_Shader: {
if (ImGui::Button("Refresh")) {
// TODO reload shaders while keeping existing references working
}
ImGui::SameLine();
if (ImGui::Button("Save all")) {
auto& shaders = ShaderManager::instance->GetShaders();
for (auto&& [DISCARD, shader] : shaders) {
auto info = shader->GetInfo();
if (info) {
info->SaveToFile(shader->GetDesignatedMetadataPath());
}
}
}
auto& shaders = ShaderManager::instance->GetShaders();
for (auto it = shaders.begin(); it != shaders.end(); ++it) {
auto shader = it->second.Get();
auto& name = shader->GetName();
shader->GatherInfoIfAbsent();
auto details = shader->GetInfo();
bool selected = mEditor->GetSelectedItPtr() == shader;
if (ImGui::Selectable(name.c_str(), selected)) {
mEditor->SelectIt(shader, EditorInstance::ITT_Shader);
}
if (ImGui::BeginDragDropSource()) {
// Reason: intentionally using pointer as Fpayload
ImGui::SetDragDropPayload(BRUSSEL_DRAG_DROP_SHADER, &shader, sizeof(shader)); // NOLINT(bugprone-sizeof-expression)
ImGui::Text("Shader '%s'", name.c_str());
ImGui::EndDragDropSource();
}
}
} break;
case P_Material: {
if (ImGui::Button("New")) {
int n = std::rand();
auto mat = new Material(nullptr, "Unnamed Material " + std::to_string(n));
auto guard = GuardDeletion(mat);
auto [DISCARD, inserted] = MaterialManager::instance->SaveMaterial(mat);
if (inserted) {
guard.Dismiss();
} else {
ImGui::AddNotification(ImGuiToast(ImGuiToastType_Error, "Failed to create material."));
}
}
ImGui::SameLine();
if (ImGui::Button("Refresh")) {
// TODO
}
ImGui::SameLine();
if (ImGui::Button("Save all")) {
auto& mats = MaterialManager::instance->GetMaterials();
for (auto&& [DISCARD, mat] : mats) {
mat->SaveToFile(mat->GetDesignatedPath());
}
}
auto& mats = MaterialManager::instance->GetMaterials();
for (auto it = mats.begin(); it != mats.end(); ++it) {
auto mat = it->second.Get();
auto& name = mat->GetName();
bool selected = mEditor->GetSelectedItPtr() == mat;
if (ImGui::Selectable(name.c_str(), selected)) {
mEditor->SelectIt(mat, EditorInstance::ITT_Material);
}
if (ImGui::BeginDragDropSource()) {
// Reason: intentionally using pointer as payload
ImGui::SetDragDropPayload(BRUSSEL_DRAG_DROP_MATERIAL, &mat, sizeof(mat)); // NOLINT(bugprone-sizeof-expression)
ImGui::Text("Material '%s'", name.c_str());
ImGui::EndDragDropSource();
}
}
} break;
}
}
ImGui::EndChild();
ImGui::End();
}
|