109 lines
3.8 KiB
C++
109 lines
3.8 KiB
C++
#pragma once
|
|
|
|
#include "IComponentEditor.h"
|
|
#include "UI/UI.h"
|
|
|
|
#include <XCEngine/Components/CameraComponent.h>
|
|
|
|
namespace XCEngine {
|
|
namespace Editor {
|
|
|
|
class CameraComponentEditor : public IComponentEditor {
|
|
public:
|
|
const char* GetDisplayName() const override {
|
|
return "Camera";
|
|
}
|
|
|
|
bool CanEdit(::XCEngine::Components::Component* component) const override {
|
|
return dynamic_cast<::XCEngine::Components::CameraComponent*>(component) != nullptr;
|
|
}
|
|
|
|
bool Render(::XCEngine::Components::Component* component) override {
|
|
auto* camera = dynamic_cast<::XCEngine::Components::CameraComponent*>(component);
|
|
if (!camera) {
|
|
return false;
|
|
}
|
|
|
|
int projectionType = static_cast<int>(camera->GetProjectionType());
|
|
const char* projectionLabels[] = { "Perspective", "Orthographic" };
|
|
bool changed = false;
|
|
if (ImGui::Combo("Projection", &projectionType, projectionLabels, 2)) {
|
|
camera->SetProjectionType(static_cast<::XCEngine::Components::CameraProjectionType>(projectionType));
|
|
changed = true;
|
|
}
|
|
|
|
if (camera->GetProjectionType() == ::XCEngine::Components::CameraProjectionType::Perspective) {
|
|
float fieldOfView = camera->GetFieldOfView();
|
|
if (UI::DrawSliderFloat("Field Of View", fieldOfView, 1.0f, 179.0f, 100.0f, "%.1f")) {
|
|
camera->SetFieldOfView(fieldOfView);
|
|
changed = true;
|
|
}
|
|
} else {
|
|
float orthographicSize = camera->GetOrthographicSize();
|
|
if (UI::DrawFloat("Orthographic Size", orthographicSize, 100.0f, 0.1f, 0.001f)) {
|
|
camera->SetOrthographicSize(orthographicSize);
|
|
changed = true;
|
|
}
|
|
}
|
|
|
|
float nearClip = camera->GetNearClipPlane();
|
|
if (UI::DrawFloat("Near Clip", nearClip, 100.0f, 0.01f, 0.001f)) {
|
|
camera->SetNearClipPlane(nearClip);
|
|
changed = true;
|
|
}
|
|
|
|
float farClip = camera->GetFarClipPlane();
|
|
if (UI::DrawFloat("Far Clip", farClip, 100.0f, 0.1f, nearClip + 0.001f)) {
|
|
camera->SetFarClipPlane(farClip);
|
|
changed = true;
|
|
}
|
|
|
|
float depth = camera->GetDepth();
|
|
if (UI::DrawFloat("Depth", depth, 100.0f, 0.1f)) {
|
|
camera->SetDepth(depth);
|
|
changed = true;
|
|
}
|
|
|
|
bool primary = camera->IsPrimary();
|
|
if (UI::DrawBool("Primary", primary)) {
|
|
camera->SetPrimary(primary);
|
|
changed = true;
|
|
}
|
|
|
|
float clearColor[4] = {
|
|
camera->GetClearColor().r,
|
|
camera->GetClearColor().g,
|
|
camera->GetClearColor().b,
|
|
camera->GetClearColor().a
|
|
};
|
|
if (UI::DrawColor4("Clear Color", clearColor)) {
|
|
camera->SetClearColor(::XCEngine::Math::Color(clearColor[0], clearColor[1], clearColor[2], clearColor[3]));
|
|
changed = true;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
::XCEngine::Components::Component* AddTo(::XCEngine::Components::GameObject* gameObject) const override {
|
|
return gameObject ? gameObject->AddComponent<::XCEngine::Components::CameraComponent>() : nullptr;
|
|
}
|
|
|
|
bool CanRemove(::XCEngine::Components::Component* component) const override {
|
|
return CanEdit(component);
|
|
}
|
|
};
|
|
|
|
} // namespace Editor
|
|
} // namespace XCEngine
|