87 lines
3.6 KiB
C++
87 lines
3.6 KiB
C++
#include <editor_component.hpp>
|
|
#include <open_engine.hpp>
|
|
|
|
namespace OpenEngine {
|
|
|
|
void TagOnImGuiRender(entt::registry& registry, entt::entity entity)
|
|
{
|
|
char buffer[256];
|
|
|
|
auto& tag = registry.get<TagComponent>(entity).tag;
|
|
std::memset(buffer, 0, sizeof(buffer));
|
|
std::strncpy(buffer, tag.c_str(), sizeof(buffer));
|
|
|
|
if (ImGui::InputText("##tagEditor", buffer, sizeof(buffer), ImGuiInputTextFlags_EnterReturnsTrue | ImGuiInputTextFlags_AutoSelectAll)
|
|
|| (!ImGui::IsItemActive() && ImGui::IsMouseClicked(0)))
|
|
tag = buffer;
|
|
};
|
|
|
|
void TransformOnImGuiRender(entt::registry& registry, entt::entity entity)
|
|
{
|
|
auto& transform = registry.get<TransformComponent>(entity);
|
|
DrawVec3Control("Position", transform.translation);
|
|
glm::vec3 rotation_comp = glm::degrees(transform.rotation);
|
|
DrawVec3Control("Rotation", rotation_comp);
|
|
transform.rotation = glm::radians(rotation_comp);
|
|
DrawVec3Control("Scale", transform.scale);
|
|
};
|
|
|
|
void SpriteOnImGuiRender(entt::registry& registry, entt::entity entity)
|
|
{
|
|
auto& sprite = registry.get<SpriteRendererComponent>(entity);
|
|
ImGui::ColorEdit4("color", glm::value_ptr(sprite.color));
|
|
};
|
|
|
|
void CameraOnImGuiRender(entt::registry& registry, entt::entity entity)
|
|
{
|
|
auto& camera_comp = registry.get<CameraComponent>(entity);
|
|
auto& camera = camera_comp.camera;
|
|
ImGui::Checkbox("Is primary", &camera_comp.primary);
|
|
const char* projection_type_strings[] = {"Perspective", "Orthographic"};
|
|
const char* current_projection_type = projection_type_strings[(int)camera.GetProjectionType()];
|
|
|
|
if (ImGui::BeginCombo("Projection", current_projection_type)) {
|
|
for (int i = 0; i < 2; i++) {
|
|
bool is_selected = current_projection_type == projection_type_strings[i];
|
|
if (ImGui::Selectable(projection_type_strings[i], is_selected)) {
|
|
current_projection_type = projection_type_strings[i];
|
|
camera.SetProjectionType((SceneCamera::ProjectionType)i);
|
|
}
|
|
|
|
if (is_selected)
|
|
ImGui::SetItemDefaultFocus();
|
|
}
|
|
ImGui::EndCombo();
|
|
}
|
|
|
|
if (camera.GetProjectionType() == SceneCamera::ProjectionType::Perspective) {
|
|
float fov = camera.GetVerticalFov();
|
|
if (ImGui::DragFloat("Fov", &fov, 0.1f))
|
|
camera.SetVerticalFov(fov);
|
|
|
|
float near_clip = camera.GetPerspectiveNearClip();
|
|
if (ImGui::DragFloat("Near clip", &near_clip, 0.1f))
|
|
camera.SetPerspectiveNearClip(near_clip);
|
|
|
|
float far_clip = camera.GetPerspectiveFarClip();
|
|
if (ImGui::DragFloat("Far clip", &far_clip, 0.1f))
|
|
camera.SetPerspectiveFarClip(far_clip);
|
|
}
|
|
else if (camera.GetProjectionType() == SceneCamera::ProjectionType::Orthographic) {
|
|
ImGui::Checkbox("Has fixed aspect ratio", &camera_comp.fixed_aspect_ratio);
|
|
float ortho_size = camera.GetOrthographicSize();
|
|
if (ImGui::DragFloat("Orthographic size", &ortho_size, 0.1f))
|
|
camera.SetOrthographicSize(ortho_size);
|
|
|
|
float near_clip = camera.GetOrthographicNearClip();
|
|
if (ImGui::DragFloat("Near clip", &near_clip, 0.1f))
|
|
camera.SetOrthographicNearClip(near_clip);
|
|
|
|
float far_clip = camera.GetOrthographicFarClip();
|
|
if (ImGui::DragFloat("Far clip", &far_clip, 0.1f))
|
|
camera.SetOrthographicFarClip(far_clip);
|
|
}
|
|
|
|
};
|
|
}
|