Compare commits
2 commits
77d1619b1c
...
2e05d871eb
Author | SHA1 | Date | |
---|---|---|---|
2e05d871eb | |||
31880d7291 |
9 changed files with 217 additions and 127 deletions
|
@ -129,7 +129,6 @@ 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,
|
||||||
|
|
|
@ -13,9 +13,17 @@ class EditorLayer: public Layer
|
||||||
public:
|
public:
|
||||||
EditorLayer(const std::string &name);
|
EditorLayer(const std::string &name);
|
||||||
|
|
||||||
~EditorLayer();
|
~EditorLayer() override;
|
||||||
|
|
||||||
void on_update(float deltaTime) override;
|
EditorLayer(EditorLayer &&) = delete;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
@ -24,7 +32,6 @@ 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;
|
||||||
|
|
|
@ -27,9 +27,9 @@ private:
|
||||||
|
|
||||||
const std::filesystem::path m_assets_path;
|
const std::filesystem::path m_assets_path;
|
||||||
|
|
||||||
uint32_t m_file_size = 128u;
|
float m_file_size = 128.0f;
|
||||||
|
|
||||||
uint32_t m_file_padding = 8u;
|
float m_file_padding = 8.0f;
|
||||||
|
|
||||||
Ref<Scene> m_active_scene;
|
Ref<Scene> m_active_scene;
|
||||||
|
|
||||||
|
|
|
@ -10,18 +10,16 @@ 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(Entity entity);
|
void set_entity_context(const 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 resetValue = 0.0f,
|
float reset_value = 0.0f,
|
||||||
float columnWidth = 100.0f
|
float column_width = 100.0f
|
||||||
);
|
);
|
||||||
|
|
||||||
template<typename ComponentType, typename UIFunction>
|
template<typename ComponentType, typename UIFunction>
|
||||||
|
|
|
@ -3,7 +3,10 @@
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
EditorLayer::EditorLayer(const std::string &name): Layer(name), m_scene_dir("")
|
EditorLayer::EditorLayer(const std::string &name)
|
||||||
|
: Layer(name)
|
||||||
|
, m_scene_dir("")
|
||||||
|
, m_direction { 0.0, 0.0 }
|
||||||
{
|
{
|
||||||
m_scene = create_ref<Scene>();
|
m_scene = create_ref<Scene>();
|
||||||
|
|
||||||
|
@ -11,7 +14,14 @@ EditorLayer::EditorLayer(const std::string &name): Layer(name), m_scene_dir("")
|
||||||
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({ 1, 1, 1 }, GraphicsContext::get_shared_context());
|
m_framebuffer = Framebuffer::create(
|
||||||
|
{
|
||||||
|
.width = 1,
|
||||||
|
.height = 1,
|
||||||
|
.samples = 1,
|
||||||
|
},
|
||||||
|
GraphicsContext::get_shared_context()
|
||||||
|
);
|
||||||
|
|
||||||
if (m_scene_dir.empty())
|
if (m_scene_dir.empty())
|
||||||
{
|
{
|
||||||
|
@ -44,23 +54,43 @@ EditorLayer::~EditorLayer()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditorLayer::on_update(float deltaTime)
|
void EditorLayer::on_update(float delta_time)
|
||||||
{
|
{
|
||||||
m_scene->on_update(deltaTime);
|
m_scene->on_update(delta_time);
|
||||||
|
|
||||||
m_direction.x = Input::get_keyboard_key(Key::A) ? -1.0f :
|
if (Input::get_keyboard_key(Key::A))
|
||||||
Input::get_keyboard_key(Key::D) ? 1.0f :
|
{
|
||||||
0.0f;
|
m_direction.x = -1.0;
|
||||||
|
}
|
||||||
|
else if (Input::get_keyboard_key(Key::D))
|
||||||
|
{
|
||||||
|
m_direction.x = 1.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_direction.x = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
m_direction.y = Input::get_keyboard_key(Key::S) ? -1.0f :
|
if (Input::get_keyboard_key(Key::S))
|
||||||
Input::get_keyboard_key(Key::W) ? 1.0f :
|
{
|
||||||
0.0f;
|
m_direction.y = -1.0;
|
||||||
|
}
|
||||||
|
else if (Input::get_keyboard_key(Key::W))
|
||||||
|
{
|
||||||
|
m_direction.y = 1.0f;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
m_direction.y = 0.0;
|
||||||
|
}
|
||||||
|
|
||||||
auto &cameraTranslation = m_camera_entity.get_component<TransformComponent>().translation;
|
auto &translation = m_camera_entity.get_component<TransformComponent>().translation;
|
||||||
cameraTranslation += glm::vec3(m_direction * m_speed * deltaTime, 0.0f);
|
translation += glm::vec3 { m_direction * m_speed * delta_time, 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()
|
||||||
|
@ -76,27 +106,34 @@ 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 regionAvail = ImGui::GetContentRegionAvail();
|
auto available_region = ImGui::GetContentRegionAvail();
|
||||||
|
|
||||||
if (m_available_content_region_prev != regionAvail)
|
if (m_available_content_region_prev != available_region)
|
||||||
{
|
{
|
||||||
m_framebuffer->resize({ regionAvail.x, regionAvail.y });
|
m_framebuffer->resize({ available_region.x, available_region.y });
|
||||||
auto &camera = m_camera_entity.get_component<CameraComponent>().camera;
|
auto &camera = m_camera_entity.get_component<CameraComponent>().camera;
|
||||||
camera.set_viewport_size(regionAvail.x, regionAvail.y);
|
camera.set_viewport_size(
|
||||||
|
static_cast<uint32_t>(available_region.x),
|
||||||
|
static_cast<uint32_t>(available_region.y)
|
||||||
|
);
|
||||||
|
|
||||||
m_available_content_region_prev = regionAvail;
|
m_available_content_region_prev = available_region;
|
||||||
}
|
}
|
||||||
|
|
||||||
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(),
|
||||||
regionAvail,
|
available_region,
|
||||||
ImVec2(0, 1),
|
ImVec2(0, 1),
|
||||||
ImVec2(1, 0)
|
ImVec2(1, 0)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
// Panels
|
// Panels
|
||||||
|
|
|
@ -27,9 +27,9 @@ public:
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
auto create_application() -> Application *
|
auto create_application() -> Light::Scope<Application>
|
||||||
{
|
{
|
||||||
return new Mirror();
|
return Light::create_scope<Mirror>();
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
|
@ -34,37 +34,47 @@ void AssetBrowserPanel::on_user_interface_update()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
auto regionAvail = ImGui::GetContentRegionAvail();
|
const auto available_region = ImGui::GetContentRegionAvail();
|
||||||
auto cellSize = m_file_size + m_file_padding;
|
const auto cell_size = m_file_size + m_file_padding;
|
||||||
auto columnCount = std::clamp(
|
const auto column_count = std::clamp(
|
||||||
static_cast<uint32_t>(std::floor(regionAvail.x / cellSize)),
|
static_cast<uint32_t>(std::floor(available_region.x / cell_size)),
|
||||||
1u,
|
1u,
|
||||||
64u
|
64u
|
||||||
);
|
);
|
||||||
|
|
||||||
if (ImGui::BeginTable("ContentBrowser", columnCount))
|
if (ImGui::BeginTable("ContentBrowser", static_cast<int>(column_count)))
|
||||||
{
|
{
|
||||||
m_directory_texture->bind(0u);
|
m_directory_texture->bind(0u);
|
||||||
for (const auto &dirEntry : std::filesystem::directory_iterator(m_current_directory))
|
for (const auto &directory_entry : std::filesystem::directory_iterator(m_current_directory))
|
||||||
{
|
{
|
||||||
const auto &path = dirEntry.path();
|
const auto &path = directory_entry.path();
|
||||||
auto extension = dirEntry.path().extension().string();
|
auto extension = directory_entry.path().extension().string();
|
||||||
|
|
||||||
// TODO: Tidy up
|
auto asset_type = AssetType {};
|
||||||
auto assetType = AssetType {};
|
|
||||||
assetType = extension.empty() ? AssetType::directory :
|
|
||||||
|
|
||||||
extension == ".txt" ? AssetType::text :
|
if (extension.empty())
|
||||||
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 (assetType == AssetType::none)
|
if (asset_type == AssetType::none)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -72,7 +82,7 @@ void AssetBrowserPanel::on_user_interface_update()
|
||||||
// Button
|
// Button
|
||||||
ImGui::TableNextColumn();
|
ImGui::TableNextColumn();
|
||||||
ImGui::PushID(path.c_str());
|
ImGui::PushID(path.c_str());
|
||||||
switch (assetType)
|
switch (asset_type)
|
||||||
{
|
{
|
||||||
// Directory
|
// Directory
|
||||||
case AssetType::directory:
|
case AssetType::directory:
|
||||||
|
@ -142,7 +152,7 @@ void AssetBrowserPanel::on_user_interface_update()
|
||||||
default: break;
|
default: break;
|
||||||
}
|
}
|
||||||
// Label
|
// Label
|
||||||
ImGui::Text("%s", path.filename().c_str());
|
ImGui::TextUnformatted(fmt::format("{}", path.filename().string()).c_str());
|
||||||
ImGui::PopID();
|
ImGui::PopID();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -32,7 +32,9 @@ 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"))
|
||||||
{
|
{
|
||||||
|
@ -41,20 +43,24 @@ void PropertiesPanel::on_user_interface_update()
|
||||||
false,
|
false,
|
||||||
m_entity_context.has_component<SpriteRendererComponent>() ?
|
m_entity_context.has_component<SpriteRendererComponent>() ?
|
||||||
ImGuiSelectableFlags_Disabled :
|
ImGuiSelectableFlags_Disabled :
|
||||||
NULL
|
ImGuiSelectableFlags {}
|
||||||
))
|
))
|
||||||
|
{
|
||||||
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 :
|
||||||
NULL
|
ImGuiSelectableFlags {}
|
||||||
))
|
))
|
||||||
|
{
|
||||||
m_entity_context.add_component<CameraComponent>();
|
m_entity_context.add_component<CameraComponent>();
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::EndPopup();
|
ImGui::EndPopup();
|
||||||
}
|
}
|
||||||
|
@ -82,68 +88,82 @@ void PropertiesPanel::on_user_interface_update()
|
||||||
[&](auto &cameraComponent) {
|
[&](auto &cameraComponent) {
|
||||||
auto &camera = cameraComponent.camera;
|
auto &camera = cameraComponent.camera;
|
||||||
|
|
||||||
auto projectionType = camera.get_projection_type();
|
auto projection_type = camera.get_projection_type();
|
||||||
auto projectionTypesString = std::array<const char *, 2> {
|
auto projection_types_str = std::array<const char *, 2> {
|
||||||
"Orthographic",
|
"Orthographic",
|
||||||
"Perspective",
|
"Perspective",
|
||||||
};
|
};
|
||||||
|
|
||||||
if (ImGui::BeginCombo("ProjectionType", projectionTypesString[(int)projectionType]))
|
if (ImGui::BeginCombo("ProjectionType", projection_types_str[(int)projection_type]))
|
||||||
{
|
{
|
||||||
for (int i = 0; i < 2; i++)
|
for (auto idx = 0; idx < 2; idx++)
|
||||||
{
|
{
|
||||||
const auto isSelected = (int)projectionType == i;
|
const auto is_selected = static_cast<int>(projection_type) == idx;
|
||||||
if (ImGui::Selectable(projectionTypesString[i], isSelected))
|
if (ImGui::Selectable(projection_types_str[idx], is_selected))
|
||||||
{
|
{
|
||||||
projectionType = (SceneCamera::ProjectionType)i;
|
projection_type = static_cast<SceneCamera::ProjectionType>(idx);
|
||||||
camera.set_projection_type(projectionType);
|
camera.set_projection_type(projection_type);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isSelected)
|
if (is_selected)
|
||||||
|
{
|
||||||
ImGui::SetItemDefaultFocus();
|
ImGui::SetItemDefaultFocus();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
ImGui::EndCombo();
|
ImGui::EndCombo();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (projectionType == SceneCamera::ProjectionType::Orthographic)
|
if (projection_type == SceneCamera::ProjectionType::Orthographic)
|
||||||
{
|
{
|
||||||
auto orthoSize = float {};
|
auto ortho_size = float {};
|
||||||
auto nearPlane = float {};
|
auto near_plane = float {};
|
||||||
auto farPlane = float {};
|
auto far_plane = float {};
|
||||||
|
|
||||||
orthoSize = camera.get_orthographic_size();
|
ortho_size = camera.get_orthographic_size();
|
||||||
nearPlane = camera.get_orthographic_near_plane();
|
near_plane = camera.get_orthographic_near_plane();
|
||||||
farPlane = camera.get_orthographic_far_plane();
|
far_plane = camera.get_orthographic_far_plane();
|
||||||
|
|
||||||
if (ImGui::DragFloat("Orthographic Size", &orthoSize))
|
if (ImGui::DragFloat("Orthographic Size", &ortho_size))
|
||||||
camera.set_orthographic_size(orthoSize);
|
{
|
||||||
|
camera.set_orthographic_size(ortho_size);
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::DragFloat("Near Plane", &nearPlane))
|
if (ImGui::DragFloat("Near Plane", &near_plane))
|
||||||
camera.set_orthographic_near_plane(nearPlane);
|
{
|
||||||
|
camera.set_orthographic_near_plane(near_plane);
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::DragFloat("Far Plane", &farPlane))
|
if (ImGui::DragFloat("Far Plane", &far_plane))
|
||||||
camera.set_orthographic_far_plane(farPlane);
|
{
|
||||||
|
camera.set_orthographic_far_plane(far_plane);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else // perspective
|
else // perspective
|
||||||
{
|
{
|
||||||
auto verticalFOV = float {};
|
auto vertical_fov = float {};
|
||||||
auto nearPlane = float {};
|
auto near_plane = float {};
|
||||||
auto farPlane = float {};
|
auto far_plane = float {};
|
||||||
|
|
||||||
verticalFOV = glm::degrees(camera.get_perspective_vertical_fov());
|
vertical_fov = glm::degrees(camera.get_perspective_vertical_fov());
|
||||||
nearPlane = camera.get_perspective_near_plane();
|
near_plane = camera.get_perspective_near_plane();
|
||||||
farPlane = camera.get_perspective_far_plane();
|
far_plane = camera.get_perspective_far_plane();
|
||||||
|
|
||||||
if (ImGui::DragFloat("Vertical FOV", &verticalFOV))
|
if (ImGui::DragFloat("Vertical FOV", &vertical_fov))
|
||||||
camera.set_perspective_vertical_fov(glm::radians(verticalFOV));
|
{
|
||||||
|
camera.set_perspective_vertical_fov(glm::radians(vertical_fov));
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::DragFloat("Near Plane", &nearPlane))
|
if (ImGui::DragFloat("Near Plane", &near_plane))
|
||||||
camera.set_perspective_near_plane(nearPlane);
|
{
|
||||||
|
camera.set_perspective_near_plane(near_plane);
|
||||||
|
}
|
||||||
|
|
||||||
if (ImGui::DragFloat("Far Plane", &farPlane))
|
if (ImGui::DragFloat("Far Plane", &far_plane))
|
||||||
camera.set_perspective_far_plane(farPlane);
|
{
|
||||||
|
camera.set_perspective_far_plane(far_plane);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ImGui::Separator();
|
ImGui::Separator();
|
||||||
|
@ -154,7 +174,7 @@ void PropertiesPanel::on_user_interface_update()
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void PropertiesPanel::set_entity_context(Entity entity)
|
void PropertiesPanel::set_entity_context(const Entity &entity)
|
||||||
{
|
{
|
||||||
m_entity_context = entity;
|
m_entity_context = entity;
|
||||||
}
|
}
|
||||||
|
@ -162,31 +182,33 @@ void PropertiesPanel::set_entity_context(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 resetValue /*= 0.0f*/,
|
float reset_value,
|
||||||
float columnWidth /*= 100.0f*/
|
float column_width
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
auto &io = ImGui::GetIO();
|
auto &io = ImGui::GetIO();
|
||||||
|
|
||||||
auto boldFont = io.Fonts->Fonts[0];
|
auto *bold_font = io.Fonts->Fonts[0];
|
||||||
|
|
||||||
ImGui::Columns(2);
|
ImGui::Columns(2);
|
||||||
ImGui::SetColumnWidth(0, columnWidth);
|
ImGui::SetColumnWidth(0, column_width);
|
||||||
ImGui::Text(label.c_str());
|
ImGui::TextUnformatted(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 lineHeight = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
auto line_height = GImGui->Font->FontSize + GImGui->Style.FramePadding.y * 2.0f;
|
||||||
auto buttonSize = ImVec2 { lineHeight + 3.0f, lineHeight };
|
auto button_size = ImVec2 { line_height + 3.0f, line_height };
|
||||||
|
|
||||||
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(boldFont);
|
ImGui::PushFont(bold_font);
|
||||||
if (ImGui::Button("X", buttonSize))
|
if (ImGui::Button("X", button_size))
|
||||||
values.x = resetValue;
|
{
|
||||||
|
values.x = reset_value;
|
||||||
|
}
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
@ -198,9 +220,11 @@ 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(boldFont);
|
ImGui::PushFont(bold_font);
|
||||||
if (ImGui::Button("Y", buttonSize))
|
if (ImGui::Button("Y", button_size))
|
||||||
values.y = resetValue;
|
{
|
||||||
|
values.y = reset_value;
|
||||||
|
}
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
@ -213,9 +237,11 @@ 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(boldFont);
|
ImGui::PushFont(bold_font);
|
||||||
if (ImGui::Button("Z", buttonSize))
|
if (ImGui::Button("Z", button_size))
|
||||||
values.z = resetValue;
|
{
|
||||||
|
values.z = reset_value;
|
||||||
|
}
|
||||||
ImGui::PopFont();
|
ImGui::PopFont();
|
||||||
ImGui::PopStyleColor(3);
|
ImGui::PopStyleColor(3);
|
||||||
|
|
||||||
|
@ -232,16 +258,19 @@ 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 userInterfaceFunction
|
UIFunction user_interface_function
|
||||||
)
|
)
|
||||||
{
|
{
|
||||||
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 regionAvail = ImGui::GetContentRegionAvail();
|
auto available_region = 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;
|
||||||
|
@ -250,27 +279,34 @@ 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(regionAvail.x - lineHeight * .5f);
|
ImGui::SameLine(available_region.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();
|
||||||
}
|
}
|
||||||
|
|
||||||
userInterfaceFunction(component);
|
user_interface_function(component);
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
{
|
||||||
ImGui::PopStyleVar();
|
ImGui::PopStyleVar();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
} // namespace Light
|
} // namespace Light
|
||||||
|
|
|
@ -6,17 +6,13 @@
|
||||||
|
|
||||||
namespace Light {
|
namespace Light {
|
||||||
|
|
||||||
SceneHierarchyPanel::SceneHierarchyPanel()
|
SceneHierarchyPanel::SceneHierarchyPanel(): m_context(nullptr), m_properties_panel_context(nullptr)
|
||||||
: m_context(nullptr)
|
|
||||||
, m_properties_panel_context(nullptr)
|
|
||||||
, m_selection_context()
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
SceneHierarchyPanel::
|
SceneHierarchyPanel::SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> properties_panel)
|
||||||
SceneHierarchyPanel(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel /* = nullptr */)
|
: m_context(std::move(context))
|
||||||
: m_context(context)
|
, m_properties_panel_context(std::move(properties_panel))
|
||||||
, m_properties_panel_context(propertiesPanel)
|
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,22 +37,29 @@ void SceneHierarchyPanel::on_user_interface_update()
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> propertiesPanel)
|
void SceneHierarchyPanel::set_context(Ref<Scene> context, Ref<PropertiesPanel> properties_panel)
|
||||||
{
|
{
|
||||||
if (propertiesPanel)
|
if (properties_panel)
|
||||||
m_properties_panel_context = propertiesPanel;
|
{
|
||||||
|
m_properties_panel_context = std::move(properties_panel);
|
||||||
|
}
|
||||||
|
|
||||||
m_context = context;
|
m_context = std::move(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
|
void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
|
||||||
{
|
{
|
||||||
auto flags = (m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : NULL)
|
auto flags = ImGuiTreeNodeFlags {
|
||||||
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth;
|
// NOLINTNEXTLINE
|
||||||
|
(m_selection_context == entity ? ImGuiTreeNodeFlags_Selected : ImGuiTreeNodeFlags {})
|
||||||
|
| ImGuiTreeNodeFlags_OpenOnArrow | ImGuiTreeNodeFlags_SpanFullWidth
|
||||||
|
};
|
||||||
|
|
||||||
|
// NOLINTNEXTLINE
|
||||||
const auto expanded = ImGui::TreeNodeEx(
|
const auto expanded = ImGui::TreeNodeEx(
|
||||||
(void *)(uint64_t)(uint32_t)(entity),
|
std::bit_cast<void *>(static_cast<uint64_t>(entity)),
|
||||||
flags,
|
flags,
|
||||||
|
"%s",
|
||||||
label.c_str()
|
label.c_str()
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -68,7 +71,7 @@ void SceneHierarchyPanel::draw_node(Entity entity, const std::string &label)
|
||||||
|
|
||||||
if (expanded)
|
if (expanded)
|
||||||
{
|
{
|
||||||
ImGui::Text("TEST_OPENED_TREE!");
|
ImGui::TextUnformatted("TEST_OPENED_TREE!");
|
||||||
ImGui::TreePop();
|
ImGui::TreePop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue