7 #include <initializer_list>
12 #include "third_party/imgui/imgui.h"
13 #include "third_party/imgui/imgui_internal.h"
27 const std::function<std::optional<Picture>()>& picture_callback) {
32 RenderCapture(aiks_context.
GetContext()->capture);
38 if (ImGui::IsKeyPressed(ImGuiKey_Z)) {
39 wireframe_ = !wireframe_;
43 if (ImGui::IsKeyPressed(ImGuiKey_C)) {
44 capturing_ = !capturing_;
51 hovered_element_ =
nullptr;
52 selected_element_ =
nullptr;
54 std::optional<Picture> new_picture = picture_callback();
58 if (!new_picture.has_value() || new_picture->pass) {
59 last_picture_ = std::move(new_picture);
67 last_picture_.reset();
72 [](CaptureBooleanProperty& p) {
73 ImGui::Checkbox(p.label.c_str(), &p.value);
76 [](CaptureIntegerProperty& p) {
77 if (p.options.range.has_value()) {
78 ImGui::SliderInt(p.label.c_str(), &p.value,
79 static_cast<int>(p.options.range->min),
80 static_cast<int>(p.options.range->max));
83 ImGui::InputInt(p.label.c_str(), &p.value);
86 [](CaptureScalarProperty& p) {
87 if (p.options.range.has_value()) {
88 ImGui::SliderFloat(p.label.c_str(), &p.value, p.options.range->min,
89 p.options.range->max);
92 ImGui::DragFloat(p.label.c_str(), &p.value, 0.01);
95 [](CapturePointProperty& p) {
96 if (p.options.range.has_value()) {
97 ImGui::SliderFloat2(p.label.c_str(),
98 reinterpret_cast<float*
>(&p.value),
99 p.options.range->min, p.options.range->max);
102 ImGui::DragFloat2(p.label.c_str(),
reinterpret_cast<float*
>(&p.value),
106 [](CaptureVector3Property& p) {
107 if (p.options.range.has_value()) {
108 ImGui::SliderFloat3(p.label.c_str(),
109 reinterpret_cast<float*
>(&p.value),
110 p.options.range->min, p.options.range->max);
113 ImGui::DragFloat3(p.label.c_str(),
reinterpret_cast<float*
>(&p.value),
117 [](CaptureRectProperty& p) {
118 ImGui::DragFloat4(p.label.c_str(),
reinterpret_cast<float*
>(&p.value),
122 [](CaptureColorProperty& p) {
123 ImGui::ColorEdit4(p.label.c_str(),
124 reinterpret_cast<float*
>(&p.value));
127 [](CaptureMatrixProperty& p) {
128 float* pointer =
reinterpret_cast<float*
>(&p.value);
129 ImGui::DragFloat4((p.label +
" X basis").c_str(), pointer, 0.001);
130 ImGui::DragFloat4((p.label +
" Y basis").c_str(), pointer + 4, 0.001);
131 ImGui::DragFloat4((p.label +
" Z basis").c_str(), pointer + 8, 0.001);
132 ImGui::DragFloat4((p.label +
" Translation").c_str(), pointer + 12,
136 [](CaptureStringProperty& p) {
137 ImGui::InputTextEx(p.label.c_str(),
"",
139 const_cast<char*
>(p.value.c_str()), p.value.size(),
140 ImVec2(0, 0), ImGuiInputTextFlags_ReadOnly);
144 void AiksInspector::RenderCapture(CaptureContext& capture_context) {
155 ImGui::SetNextWindowBgAlpha(0.5);
156 ImGui::Begin(
"Capture");
157 auto dockspace_id = ImGui::GetID(
"CaptureDockspace");
158 if (!ImGui::DockBuilderGetNode(dockspace_id)) {
159 ImGui::SetWindowSize(ImVec2(370, 680));
160 ImGui::SetWindowPos(ImVec2(640, 55));
162 ImGui::DockBuilderRemoveNode(dockspace_id);
163 ImGui::DockBuilderAddNode(dockspace_id);
166 ImGuiID up_id = ImGui::DockBuilderSplitNode(dockspace_id, ImGuiDir_Up, 0.6,
167 nullptr, &opposite_id);
168 ImGuiID down_id = ImGui::DockBuilderSplitNode(opposite_id, ImGuiDir_Down,
169 0.0,
nullptr,
nullptr);
173 ImGui::DockBuilderFinish(dockspace_id);
175 ImGui::DockSpace(dockspace_id);
183 auto root_element = document.GetElement();
184 hovered_element_ =
nullptr;
186 RenderCaptureElement(*root_element);
190 if (selected_element_) {
197 selected_element_->
properties.Iterate([&](CaptureProperty& property) {
207 auto coverage_property =
208 selected_element_->
properties.FindFirstByLabel(
"Coverage");
209 if (coverage_property) {
210 auto coverage = coverage_property->AsRect();
211 if (coverage.has_value()) {
213 ImGui::GetBackgroundDrawList()->AddRect(
214 ImVec2(coverage->GetLeft() /
scale,
215 coverage->GetTop() /
scale),
216 ImVec2(coverage->GetRight() /
scale,
217 coverage->GetBottom() /
scale),
230 if (hovered_element_) {
231 auto coverage_property =
232 hovered_element_->
properties.FindFirstByLabel(
"Coverage");
233 if (coverage_property) {
234 auto coverage = coverage_property->AsRect();
235 if (coverage.has_value()) {
237 ImGui::GetBackgroundDrawList()->AddRect(
238 ImVec2(coverage->GetLeft() /
scale,
239 coverage->GetTop() /
scale),
240 ImVec2(coverage->GetRight() /
scale,
241 coverage->GetBottom() /
scale),
251 void AiksInspector::RenderCaptureElement(CaptureElement& element) {
252 ImGui::PushID(&element);
254 bool is_selected = selected_element_ == &element;
255 bool has_children = element.
children.Count() > 0;
257 bool opened = ImGui::TreeNodeEx(
258 element.label.c_str(), (is_selected ? ImGuiTreeNodeFlags_Selected : 0) |
259 (has_children ? 0 : ImGuiTreeNodeFlags_Leaf) |
260 ImGuiTreeNodeFlags_SpanFullWidth |
261 ImGuiTreeNodeFlags_OpenOnArrow |
262 ImGuiTreeNodeFlags_DefaultOpen);
263 if (ImGui::IsItemClicked()) {
264 selected_element_ = &element;
266 if (ImGui::IsItemHovered()) {
267 hovered_element_ = &element;
271 [&](CaptureElement& child) { RenderCaptureElement(child); });