Compare commits

..

No commits in common. "2e05d871ebebe53a40900fe8eb065e2a845095e1" and "77d1619b1cd043ed8c65bfd9c8f274bf1ca49566" have entirely different histories.

9 changed files with 127 additions and 217 deletions

View file

@ -129,6 +129,7 @@ cppcoreguidelines-pro-type-cstyle-cast,
cppcoreguidelines-pro-type-member-init, cppcoreguidelines-pro-type-member-init,
cppcoreguidelines-pro-type-reinterpret-cast, cppcoreguidelines-pro-type-reinterpret-cast,
cppcoreguidelines-pro-type-static-cast-downcast, cppcoreguidelines-pro-type-static-cast-downcast,
cppcoreguidelines-pro-type-union-access,
cppcoreguidelines-pro-type-vararg, cppcoreguidelines-pro-type-vararg,
cppcoreguidelines-rvalue-reference-param-not-moved, cppcoreguidelines-rvalue-reference-param-not-moved,
cppcoreguidelines-slicing, cppcoreguidelines-slicing,

View file

@ -13,17 +13,9 @@ class EditorLayer: public Layer
public: public:
EditorLayer(const std::string &name); EditorLayer(const std::string &name);
~EditorLayer() override; ~EditorLayer();
EditorLayer(EditorLayer &&) = delete; void on_update(float deltaTime) override;
EditorLayer(const EditorLayer &) = delete;
auto operator=(EditorLayer &&) const -> EditorLayer & = delete;
auto operator=(const EditorLayer &) const -> EditorLayer & = delete;
void on_update(float delta_time) override;
void on_render() override; void on_render() override;
@ -32,6 +24,7 @@ public:
private: private:
std::string m_scene_dir; std::string m_scene_dir;
// #todo: add camera controller class to the engine
glm::vec2 m_direction; glm::vec2 m_direction;
float m_speed = 1000.0f; float m_speed = 1000.0f;

View file

@ -27,9 +27,9 @@ private:
const std::filesystem::path m_assets_path; const std::filesystem::path m_assets_path;
float m_file_size = 128.0f; uint32_t m_file_size = 128u;
float m_file_padding = 8.0f; uint32_t m_file_padding = 8u;
Ref<Scene> m_active_scene; Ref<Scene> m_active_scene;

View file

@ -10,16 +10,18 @@ class PropertiesPanel: public Panel
public: public:
PropertiesPanel() = default; PropertiesPanel() = default;
~PropertiesPanel() = default;
void on_user_interface_update(); void on_user_interface_update();
void set_entity_context(const Entity &entity); void set_entity_context(Entity entity);
private: private:
void draw_vec3_control( void draw_vec3_control(
const std::string &label, const std::string &label,
glm::vec3 &values, glm::vec3 &values,
float reset_value = 0.0f, float resetValue = 0.0f,
float column_width = 100.0f float columnWidth = 100.0f
); );
template<typename ComponentType, typename UIFunction> template<typename ComponentType, typename UIFunction>

View file

@ -3,10 +3,7 @@
namespace Light { namespace Light {
EditorLayer::EditorLayer(const std::string &name) EditorLayer::EditorLayer(const std::string &name): Layer(name), m_scene_dir("")
: Layer(name)
, m_scene_dir("")
, m_direction { 0.0, 0.0 }
{ {
m_scene = create_ref<Scene>(); m_scene = create_ref<Scene>();
@ -14,14 +11,7 @@ EditorLayer::EditorLayer(const std::string &name)
m_sceneHierarchyPanel = create_ref<SceneHierarchyPanel>(m_scene, m_properties_panel); m_sceneHierarchyPanel = create_ref<SceneHierarchyPanel>(m_scene, m_properties_panel);
m_content_browser_panel = create_ref<AssetBrowserPanel>(m_scene); m_content_browser_panel = create_ref<AssetBrowserPanel>(m_scene);
m_framebuffer = Framebuffer::create( m_framebuffer = Framebuffer::create({ 1, 1, 1 }, GraphicsContext::get_shared_context());
{
.width = 1,
.height = 1,
.samples = 1,
},
GraphicsContext::get_shared_context()
);
if (m_scene_dir.empty()) if (m_scene_dir.empty())
{ {
@ -54,43 +44,23 @@ EditorLayer::~EditorLayer()
} }
} }
void EditorLayer::on_update(float delta_time) void EditorLayer::on_update(float deltaTime)
{ {
m_scene->on_update(delta_time); m_scene->on_update(deltaTime);
if (Input::get_keyboard_key(Key::A)) m_direction.x = Input::get_keyboard_key(Key::A) ? -1.0f :
{ Input::get_keyboard_key(Key::D) ? 1.0f :
m_direction.x = -1.0; 0.0f;
}
else if (Input::get_keyboard_key(Key::D))
{
m_direction.x = 1.0f;
}
else
{
m_direction.x = 0.0;
}
if (Input::get_keyboard_key(Key::S)) m_direction.y = Input::get_keyboard_key(Key::S) ? -1.0f :
{ Input::get_keyboard_key(Key::W) ? 1.0f :
m_direction.y = -1.0; 0.0f;
}
else if (Input::get_keyboard_key(Key::W))
{
m_direction.y = 1.0f;
}
else
{
m_direction.y = 0.0;
}
auto &translation = m_camera_entity.get_component<TransformComponent>().translation; auto &cameraTranslation = m_camera_entity.get_component<TransformComponent>().translation;
translation += glm::vec3 { m_direction * m_speed * delta_time, 0.0f }; cameraTranslation += glm::vec3(m_direction * m_speed * deltaTime, 0.0f);
if (Input::get_keyboard_key(Key::Escape)) if (Input::get_keyboard_key(Key::Escape))
{
Application::quit(); Application::quit();
}
} }
void EditorLayer::on_render() void EditorLayer::on_render()
@ -106,33 +76,26 @@ void EditorLayer::on_user_interface_update()
if (ImGui::Begin("Game")) if (ImGui::Begin("Game"))
{ {
Input::receive_game_events(ImGui::IsWindowFocused()); Input::receive_game_events(ImGui::IsWindowFocused());
auto available_region = ImGui::GetContentRegionAvail(); auto regionAvail = ImGui::GetContentRegionAvail();
if (m_available_content_region_prev != available_region) if (m_available_content_region_prev != regionAvail)
{ {
m_framebuffer->resize({ available_region.x, available_region.y }); m_framebuffer->resize({ regionAvail.x, regionAvail.y });
auto &camera = m_camera_entity.get_component<CameraComponent>().camera; auto &camera = m_camera_entity.get_component<CameraComponent>().camera;
camera.set_viewport_size( camera.set_viewport_size(regionAvail.x, regionAvail.y);
static_cast<uint32_t>(available_region.x),
static_cast<uint32_t>(available_region.y)
);
m_available_content_region_prev = available_region; m_available_content_region_prev = regionAvail;
} }
if (GraphicsContext::get_graphics_api() == GraphicsAPI::DirectX) if (GraphicsContext::get_graphics_api() == GraphicsAPI::DirectX)
{ ImGui::Image(m_framebuffer->get_color_attachment(), regionAvail);
ImGui::Image(m_framebuffer->get_color_attachment(), available_region);
}
else else
{
ImGui::Image( ImGui::Image(
m_framebuffer->get_color_attachment(), m_framebuffer->get_color_attachment(),
available_region, regionAvail,
ImVec2(0, 1), ImVec2(0, 1),
ImVec2(1, 0) ImVec2(1, 0)
); );
}
} }
ImGui::End(); ImGui::End();

View file

@ -27,9 +27,9 @@ public:
} }
}; };
auto create_application() -> Light::Scope<Application> auto create_application() -> Application *
{ {
return Light::create_scope<Mirror>(); return new Mirror();
} }
} // namespace Light } // namespace Light

View file

@ -34,47 +34,37 @@ void AssetBrowserPanel::on_user_interface_update()
} }
} }
const auto available_region = ImGui::GetContentRegionAvail(); auto regionAvail = ImGui::GetContentRegionAvail();
const auto cell_size = m_file_size + m_file_padding; auto cellSize = m_file_size + m_file_padding;
const auto column_count = std::clamp( auto columnCount = std::clamp(
static_cast<uint32_t>(std::floor(available_region.x / cell_size)), static_cast<uint32_t>(std::floor(regionAvail.x / cellSize)),
1u, 1u,
64u 64u
); );
if (ImGui::BeginTable("ContentBrowser", static_cast<int>(column_count))) if (ImGui::BeginTable("ContentBrowser", columnCount))
{ {
m_directory_texture->bind(0u); m_directory_texture->bind(0u);
for (const auto &directory_entry : std::filesystem::directory_iterator(m_current_directory)) for (const auto &dirEntry : std::filesystem::directory_iterator(m_current_directory))
{ {
const auto &path = directory_entry.path(); const auto &path = dirEntry.path();
auto extension = directory_entry.path().extension().string(); auto extension = dirEntry.path().extension().string();
auto asset_type = AssetType {}; // TODO: Tidy up
auto assetType = AssetType {};
assetType = extension.empty() ? AssetType::directory :
if (extension.empty()) extension == ".txt" ? AssetType::text :
{ extension == ".glsl" ? AssetType::text :
asset_type = AssetType::directory;
} extension == ".png" ? AssetType::image :
else if (extension == ".txt" || extension == ".glsl")
{ extension == ".scene" ? AssetType::scene :
asset_type = AssetType::text;
} AssetType::none;
else if (extension == ".png")
{
asset_type = AssetType::image;
}
else if (extension == ".scene")
{
asset_type = AssetType::scene;
}
else
{
asset_type = AssetType::none;
}
// Extension not supported // Extension not supported
if (asset_type == AssetType::none) if (assetType == AssetType::none)
{ {
continue; continue;
} }
@ -82,7 +72,7 @@ void AssetBrowserPanel::on_user_interface_update()
// Button // Button
ImGui::TableNextColumn(); ImGui::TableNextColumn();
ImGui::PushID(path.c_str()); ImGui::PushID(path.c_str());
switch (asset_type) switch (assetType)
{ {
// Directory // Directory
case AssetType::directory: case AssetType::directory:
@ -152,7 +142,7 @@ void AssetBrowserPanel::on_user_interface_update()
default: break; default: break;
} }
// Label // Label
ImGui::TextUnformatted(fmt::format("{}", path.filename().string()).c_str()); ImGui::Text("%s", path.filename().c_str());
ImGui::PopID(); ImGui::PopID();
} }

View file

@ -32,9 +32,7 @@ void PropertiesPanel::on_user_interface_update()
ImGui::PushItemWidth(-1); ImGui::PushItemWidth(-1);
if (ImGui::Button("Add component")) if (ImGui::Button("Add component"))
{
ImGui::OpenPopup("Components"); ImGui::OpenPopup("Components");
}
if (ImGui::BeginPopup("Components")) if (ImGui::BeginPopup("Components"))
{ {
@ -43,24 +41,20 @@ void PropertiesPanel::on_user_interface_update()
false, false,
m_entity_context.has_component<SpriteRendererComponent>() ? m_entity_context.has_component<SpriteRendererComponent>() ?
ImGuiSelectableFlags_Disabled : ImGuiSelectableFlags_Disabled :
ImGuiSelectableFlags {} NULL
)) ))
{
m_entity_context.add_component<SpriteRendererComponent>( m_entity_context.add_component<SpriteRendererComponent>(
Light::ResourceManager::get_texture("awesomeface") Light::ResourceManager::get_texture("awesomeface")
); );
}
if (ImGui::Selectable( if (ImGui::Selectable(
"Camera", "Camera",
false, false,
m_entity_context.has_component<CameraComponent>() ? m_entity_context.has_component<CameraComponent>() ?
ImGuiSelectableFlags_Disabled : ImGuiSelectableFlags_Disabled :
ImGuiSelectableFlags {} NULL
)) ))
{
m_entity_context.add_component<CameraComponent>(); m_entity_context.add_component<CameraComponent>();
}
ImGui::EndPopup(); ImGui::EndPopup();
} }
@ -88,82 +82,68 @@ void PropertiesPanel::on_user_interface_update()
[&](auto &cameraComponent) { [&](auto &cameraComponent) {
auto &camera = cameraComponent.camera; auto &camera = cameraComponent.camera;
auto projection_type = camera.get_projection_type(); auto projectionType = camera.get_projection_type();
auto projection_types_str = std::array<const char *, 2> { auto projectionTypesString = std::array<const char *, 2> {
"Orthographic", "Orthographic",
"Perspective", "Perspective",
}; };
if (ImGui::BeginCombo("ProjectionType", projection_types_str[(int)projection_type])) if (ImGui::BeginCombo("ProjectionType", projectionTypesString[(int)projectionType]))
{ {
for (auto idx = 0; idx < 2; idx++) for (int i = 0; i < 2; i++)
{ {
const auto is_selected = static_cast<int>(projection_type) == idx; const auto isSelected = (int)projectionType == i;
if (ImGui::Selectable(projection_types_str[idx], is_selected)) if (ImGui::Selectable(projectionTypesString[i], isSelected))
{ {
projection_type = static_cast<SceneCamera::ProjectionType>(idx); projectionType = (SceneCamera::ProjectionType)i;
camera.set_projection_type(projection_type); camera.set_projection_type(projectionType);
} }
if (is_selected) if (isSelected)
{
ImGui::SetItemDefaultFocus(); ImGui::SetItemDefaultFocus();
}
} }
ImGui::EndCombo(); ImGui::EndCombo();
} }
if (projection_type == SceneCamera::ProjectionType::Orthographic) if (projectionType == SceneCamera::ProjectionType::Orthographic)
{ {
auto ortho_size = float {}; auto orthoSize = float {};
auto near_plane = float {}; auto nearPlane = float {};
auto far_plane = float {}; auto farPlane = float {};
ortho_size = camera.get_orthographic_size(); orthoSize = camera.get_orthographic_size();
near_plane = camera.get_orthographic_near_plane(); nearPlane = camera.get_orthographic_near_plane();
far_plane = camera.get_orthographic_far_plane(); farPlane = camera.get_orthographic_far_plane();
if (ImGui::DragFloat("Orthographic Size", &ortho_size)) if (ImGui::DragFloat("Orthographic Size", &orthoSize))
{ camera.set_orthographic_size(orthoSize);
camera.set_orthographic_size(ortho_size);
}
if (ImGui::DragFloat("Near Plane", &near_plane)) if (ImGui::DragFloat("Near Plane", &nearPlane))
{ camera.set_orthographic_near_plane(nearPlane);
camera.set_orthographic_near_plane(near_plane);
}
if (ImGui::DragFloat("Far Plane", &far_plane)) if (ImGui::DragFloat("Far Plane", &farPlane))
{ camera.set_orthographic_far_plane(farPlane);
camera.set_orthographic_far_plane(far_plane);
}
} }
else // perspective else // perspective
{ {
auto vertical_fov = float {}; auto verticalFOV = float {};
auto near_plane = float {}; auto nearPlane = float {};
auto far_plane = float {}; auto farPlane = float {};
vertical_fov = glm::degrees(camera.get_perspective_vertical_fov()); verticalFOV = glm::degrees(camera.get_perspective_vertical_fov());
near_plane = camera.get_perspective_near_plane(); nearPlane = camera.get_perspective_near_plane();
far_plane = camera.get_perspective_far_plane(); farPlane = camera.get_perspective_far_plane();
if (ImGui::DragFloat("Vertical FOV", &vertical_fov)) if (ImGui::DragFloat("Vertical FOV", &verticalFOV))
{ camera.set_perspective_vertical_fov(glm::radians(verticalFOV));
camera.set_perspective_vertical_fov(glm::radians(vertical_fov));
}
if (ImGui::DragFloat("Near Plane", &near_plane)) if (ImGui::DragFloat("Near Plane", &nearPlane))
{ camera.set_perspective_near_plane(nearPlane);
camera.set_perspective_near_plane(near_plane);
}
if (ImGui::DragFloat("Far Plane", &far_plane)) if (ImGui::DragFloat("Far Plane", &farPlane))
{ camera.set_perspective_far_plane(farPlane);
camera.set_perspective_far_plane(far_plane);
}
} }
ImGui::Separator(); ImGui::Separator();
@ -174,7 +154,7 @@ void PropertiesPanel::on_user_interface_update()
ImGui::End(); ImGui::End();
} }
void PropertiesPanel::set_entity_context(const Entity &entity) void PropertiesPanel::set_entity_context(Entity entity)
{ {
m_entity_context = entity; m_entity_context = entity;
} }
@ -182,33 +162,31 @@ void PropertiesPanel::set_entity_context(const Entity &entity)
void PropertiesPanel::draw_vec3_control( void PropertiesPanel::draw_vec3_control(
const std::string &label, const std::string &label,
glm::vec3 &values, glm::vec3 &values,
float reset_value, float resetValue /*= 0.0f*/,
float column_width float columnWidth /*= 100.0f*/
) )
{ {
auto &io = ImGui::GetIO(); auto &io = ImGui::GetIO();
auto *bold_font = io.Fonts->Fonts[0]; auto boldFont = io.Fonts->Fonts[0];
ImGui::Columns(2); ImGui::Columns(2);
ImGui::SetColumnWidth(0, column_width); ImGui::SetColumnWidth(0, columnWidth);
ImGui::TextUnformatted(label.c_str()); ImGui::Text(label.c_str());
ImGui::NextColumn(); ImGui::NextColumn();
ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth()); ImGui::PushMultiItemsWidths(3, ImGui::CalcItemWidth());
ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2 { 0, 0 }); ImGui::PushStyleVar(ImGuiStyleVar_ItemSpacing, ImVec2 { 0, 0 });
auto line_height = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f; auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
auto button_size = ImVec2 { line_height + 3.0f, line_height }; auto buttonSize = ImVec2 { lineHeight + 3.0f, lineHeight };
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.1f, 0.15f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.8f, 0.1f, 0.15f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.9f, 0.2f, 0.2f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.9f, 0.2f, 0.2f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.8f, 0.1f, 0.15f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.8f, 0.1f, 0.15f, 1.0f));
ImGui::PushFont(bold_font); ImGui::PushFont(boldFont);
if (ImGui::Button("X", button_size)) if (ImGui::Button("X", buttonSize))
{ values.x = resetValue;
values.x = reset_value;
}
ImGui::PopFont(); ImGui::PopFont();
ImGui::PopStyleColor(3); ImGui::PopStyleColor(3);
@ -220,11 +198,9 @@ void PropertiesPanel::draw_vec3_control(
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.7f, 0.2f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.2f, 0.7f, 0.2f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.3f, 0.8f, 0.3f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.3f, 0.8f, 0.3f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.2f, 0.7f, 0.2f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.2f, 0.7f, 0.2f, 1.0f));
ImGui::PushFont(bold_font); ImGui::PushFont(boldFont);
if (ImGui::Button("Y", button_size)) if (ImGui::Button("Y", buttonSize))
{ values.y = resetValue;
values.y = reset_value;
}
ImGui::PopFont(); ImGui::PopFont();
ImGui::PopStyleColor(3); ImGui::PopStyleColor(3);
@ -237,11 +213,9 @@ void PropertiesPanel::draw_vec3_control(
ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.1f, 0.25f, 0.8f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_Button, ImVec4(0.1f, 0.25f, 0.8f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.35f, 0.9f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonHovered, ImVec4(0.2f, 0.35f, 0.9f, 1.0f));
ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.25f, 0.8f, 1.0f)); ImGui::PushStyleColor(ImGuiCol_ButtonActive, ImVec4(0.1f, 0.25f, 0.8f, 1.0f));
ImGui::PushFont(bold_font); ImGui::PushFont(boldFont);
if (ImGui::Button("Z", button_size)) if (ImGui::Button("Z", buttonSize))
{ values.z = resetValue;
values.z = reset_value;
}
ImGui::PopFont(); ImGui::PopFont();
ImGui::PopStyleColor(3); ImGui::PopStyleColor(3);
@ -258,19 +232,16 @@ template<typename ComponentType, typename UIFunction>
void PropertiesPanel::draw_component( void PropertiesPanel::draw_component(
const std::string &name, const std::string &name,
Entity entity, Entity entity,
UIFunction user_interface_function UIFunction userInterfaceFunction
) )
{ {
if (!entity.has_component<ComponentType>()) if (!entity.has_component<ComponentType>())
{
return; return;
}
auto &component = entity.get_component<ComponentType>(); auto &component = entity.get_component<ComponentType>();
auto available_region = ImGui::GetContentRegionAvail(); auto regionAvail = ImGui::GetContentRegionAvail();
// NOLINTNEXTLINE
auto flags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth auto flags = ImGuiTreeNodeFlags_DefaultOpen | ImGuiTreeNodeFlags_SpanAvailWidth
| ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_AllowItemOverlap | ImGuiTreeNodeFlags_Framed | ImGuiTreeNodeFlags_AllowItemOverlap
| ImGuiTreeNodeFlags_FramePadding; | ImGuiTreeNodeFlags_FramePadding;
@ -279,34 +250,27 @@ void PropertiesPanel::draw_component(
auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f; auto lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
ImGui::Separator(); ImGui::Separator();
// NOLINTNEXTLINE
if (ImGui::TreeNodeEx((void *)typeid(ComponentType).hash_code(), flags, name.c_str())) if (ImGui::TreeNodeEx((void *)typeid(ComponentType).hash_code(), flags, name.c_str()))
{ {
ImGui::PopStyleVar(); ImGui::PopStyleVar();
ImGui::SameLine(available_region.x - lineHeight * .5f); ImGui::SameLine(regionAvail.x - lineHeight * .5f);
if (ImGui::Button("+", { lineHeight, lineHeight })) if (ImGui::Button("+", { lineHeight, lineHeight }))
{
ImGui::OpenPopup("ComponentSettings"); ImGui::OpenPopup("ComponentSettings");
}
if (ImGui::BeginPopup("ComponentSettings")) if (ImGui::BeginPopup("ComponentSettings"))
{ {
if (ImGui::Selectable("Remove component")) if (ImGui::Selectable("Remove component"))
{
entity.remove_component<ComponentType>(); entity.remove_component<ComponentType>();
}
ImGui::EndPopup(); ImGui::EndPopup();
} }
user_interface_function(component); userInterfaceFunction(component);
ImGui::TreePop(); ImGui::TreePop();
} }
else else
{
ImGui::PopStyleVar(); ImGui::PopStyleVar();
}
} }
} // namespace Light } // namespace Light

View file

@ -6,13 +6,17 @@
namespace Light { namespace Light {
SceneHierarchyPanel::SceneHierarchyPanel(): m_context(nullptr), m_properties_panel_context(nullptr) SceneHierarchyPanel::SceneHierarchyPanel()
: m_context(nullptr)
, m_properties_panel_context(nullptr)
, m_selection_context()
{ {
} }
SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> properties_panel) SceneHierarchyPanel::
: m_context(std::move(context)) SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
, m_properties_panel_context(std::move(properties_panel)) : m_context(context)
, m_properties_panel_context(propertiesPanel)
{ {
} }
@ -37,29 +41,22 @@ void SceneHierarchyPanel::on_user_interface_update()
ImGui::End(); ImGui::End();
} }
void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> properties_panel) void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel)
{ {
if (properties_panel) if (propertiesPanel)
{ m_properties_panel_context = propertiesPanel;
m_properties_panel_context = std::move(properties_panel);
}
m_context = std::move(context); m_context = context;
} }
void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label) void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
{ {
auto flags = ImGuiTreeNodeFlags { auto flags = (m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : NULL)
// NOLINTNEXTLINE | ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
(m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : ImGuiTreeNodeFlags {})
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth
};
// NOLINTNEXTLINE
const auto expanded = ImGui::TreeNodeEx( const auto expanded = ImGui::TreeNodeEx(
std::bit_cast<void *>(static_cast<uint64_t>(entity)), (void *)(uint64_t)(uint32_t)(entity),
flags, flags,
"%s",
label.c_str() label.c_str()
); );
@ -71,7 +68,7 @@ void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
if (expanded) if (expanded)
{ {
ImGui::TextUnformatted("TEST_OPENED_TREE!"); ImGui::Text("TEST_OPENED_TREE!");
ImGui::TreePop(); ImGui::TreePop();
} }
} }