sculpto
scene_hierarchy_window.cpp
Go to the documentation of this file.
1/*!****************************************************************//*!*
2 * \file scene_hierarchy_window.cpp
3 * \brief Scene hierarchy GUI window class implementation module.
4 *
5 * \author Sabitov Kirill
6 * \date 09 July 2022
7 *********************************************************************/
8
9#include "sclpch.h"
10
11#include <imgui.h>
12#include <imgui_internal.h>
13
16
17scl::scene_hierarchy_window::scene_hierarchy_window(scene *Scene, const std::function<void(scene_object)> &OnObjectSelect) :
18 Scene(Scene), OnObjectSelect(OnObjectSelect) {}
19
21{
22 if (Scene == nullptr) return;
23
24 ImGui::Begin("Scene Hierarchy");
25 ImGuiTreeNodeFlags node_flags = ImGuiTreeNodeFlags_OpenOnArrow
26 | ImGuiTreeNodeFlags_OpenOnDoubleClick
27 | ImGuiTreeNodeFlags_SpanAvailWidth;
28 for (auto &&[entity, tag] : Scene->Registry.view<name_component>().each())
29 {
30 if (ImGui::Selectable(tag.Name.c_str(), entity == SelectedObject, ImGuiSelectableFlags_None,
31 { entity == SelectedObject ? ImGui::GetWindowWidth() * 0.6f - 10 : 0, 20 }))
32 {
33 SelectedObject = scene_object { entity, Scene };
34 OnObjectSelect(SelectedObject);
35 }
36
37 if (entity == SelectedObject)
38 {
39 ImGui::SameLine(ImGui::GetWindowWidth() * 0.6f + 5);
40 if (ImGui::Button("Delete##delete_object", { ImGui::GetWindowWidth() * 0.4f - 10, 0 }))
41 Scene->RemoveObject(SelectedObject);
42 }
43 }
44
45 ImGui::SetNextItemWidth(ImGui::GetWindowWidth() * 0.6f - 5);
46 ImGui::InputText("##adding_object_name", ObjectCreationNameTextBuffer, 128);
47 ImGui::SameLine(ImGui::GetWindowWidth() * 0.6f + 5);
48 if (ImGui::Button("Add new object", { ImGui::GetWindowWidth() * 0.4f - 10, 0 }))
49 Scene->CreateObject(std::string(ObjectCreationNameTextBuffer)), memset(ObjectCreationNameTextBuffer, 0, 128);
50 ImGui::End();
51}
scene_hierarchy_window(scene *Scene, const std::function< void(scene_object)> &OnObjectSelect)
scene_object CreateObject(const std::string &Name="")
Definition: scene.cpp:107
void RemoveObject(scene_object &Object)
Definition: scene.cpp:126
Application scene objects system components include module.
Sculpto library prehompiled header. Defines common definitions, includes commonly used modules.