#pragma once #include "IComponentEditor.h" #include "Core/IUndoManager.h" #include "UI/UI.h" #include namespace XCEngine { namespace Editor { class CameraComponentEditor : public IComponentEditor { public: const char* GetComponentTypeName() const override { return "Camera"; } const char* GetDisplayName() const override { return "Camera"; } bool Render(::XCEngine::Components::Component* component, IUndoManager* undoManager) override { auto* camera = dynamic_cast<::XCEngine::Components::CameraComponent*>(component); if (!camera) { return false; } constexpr const char* kUndoLabel = "Modify Camera"; int projectionType = static_cast(camera->GetProjectionType()); const char* projectionLabels[] = { "Perspective", "Orthographic" }; bool changed = false; const int newProjectionType = UI::DrawPropertyCombo("Projection", projectionType, projectionLabels, 2); changed |= UI::ApplyPropertyChange( newProjectionType != projectionType, undoManager, kUndoLabel, [&]() { camera->SetProjectionType(static_cast<::XCEngine::Components::CameraProjectionType>(newProjectionType)); }); if (camera->GetProjectionType() == ::XCEngine::Components::CameraProjectionType::Perspective) { float fieldOfView = camera->GetFieldOfView(); changed |= UI::ApplyPropertyChange( UI::DrawPropertySliderFloat("Field Of View", fieldOfView, 1.0f, 179.0f, "%.1f"), undoManager, kUndoLabel, [&]() { camera->SetFieldOfView(fieldOfView); }); } else { float orthographicSize = camera->GetOrthographicSize(); changed |= UI::ApplyPropertyChange( UI::DrawPropertyFloat("Orthographic Size", orthographicSize, 0.1f, 0.001f), undoManager, kUndoLabel, [&]() { camera->SetOrthographicSize(orthographicSize); }); } float nearClip = camera->GetNearClipPlane(); changed |= UI::ApplyPropertyChange( UI::DrawPropertyFloat("Near Clip", nearClip, 0.01f, 0.001f), undoManager, kUndoLabel, [&]() { camera->SetNearClipPlane(nearClip); }); float farClip = camera->GetFarClipPlane(); changed |= UI::ApplyPropertyChange( UI::DrawPropertyFloat("Far Clip", farClip, 0.1f, nearClip + 0.001f), undoManager, kUndoLabel, [&]() { camera->SetFarClipPlane(farClip); }); float depth = camera->GetDepth(); changed |= UI::ApplyPropertyChange( UI::DrawPropertyFloat("Depth", depth, 0.1f), undoManager, kUndoLabel, [&]() { camera->SetDepth(depth); }); bool primary = camera->IsPrimary(); changed |= UI::ApplyPropertyChange( UI::DrawPropertyBool("Primary", primary), undoManager, kUndoLabel, [&]() { camera->SetPrimary(primary); }); float clearColor[4] = { camera->GetClearColor().r, camera->GetClearColor().g, camera->GetClearColor().b, camera->GetClearColor().a }; changed |= UI::ApplyPropertyChange( UI::DrawPropertyColor4("Clear Color", clearColor), undoManager, kUndoLabel, [&]() { camera->SetClearColor(::XCEngine::Math::Color(clearColor[0], clearColor[1], clearColor[2], clearColor[3])); }); return changed; } bool CanAddTo(::XCEngine::Components::GameObject* gameObject) const override { return gameObject && !gameObject->GetComponent<::XCEngine::Components::CameraComponent>(); } const char* GetAddDisabledReason(::XCEngine::Components::GameObject* gameObject) const override { if (!gameObject) { return "Invalid"; } return gameObject->GetComponent<::XCEngine::Components::CameraComponent>() ? "Already Added" : nullptr; } bool CanRemove(::XCEngine::Components::Component* component) const override { return CanEdit(component); } }; } // namespace Editor } // namespace XCEngine