Refactor editor rendering contracts
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
#include "Scene/SceneViewportController.h"
|
||||
|
||||
#include "Viewport/ViewportObjectPickerService.h"
|
||||
#include "Viewport/EditorViewportPicking.h"
|
||||
#include "EditorSceneRuntime.h"
|
||||
#include "State/EditorCommandFocusService.h"
|
||||
|
||||
@@ -136,17 +136,15 @@ void ApplySceneViewportToggleButton(
|
||||
|
||||
} // namespace
|
||||
|
||||
void SceneViewportController::Initialize(
|
||||
const std::filesystem::path& repoRoot,
|
||||
Rendering::Host::UiTextureHost& renderer,
|
||||
const BuiltInIcons* builtInIcons) {
|
||||
m_toolOverlay.Initialize(repoRoot, renderer);
|
||||
m_sceneOverlay.SetBuiltInIcons(builtInIcons);
|
||||
void SceneViewportController::Initialize(const EditorIconService* iconService) {
|
||||
m_toolOverlay.SetIconService(iconService);
|
||||
m_sceneOverlay.SetIconService(iconService);
|
||||
ResetInteractionState();
|
||||
}
|
||||
|
||||
void SceneViewportController::Shutdown(Rendering::Host::UiTextureHost& renderer) {
|
||||
m_toolOverlay.Shutdown(renderer);
|
||||
void SceneViewportController::Shutdown() {
|
||||
m_toolOverlay.SetIconService(nullptr);
|
||||
m_sceneOverlay.SetIconService(nullptr);
|
||||
ResetInteractionState();
|
||||
}
|
||||
|
||||
|
||||
@@ -10,32 +10,18 @@
|
||||
#include <XCEngine/UI/Types.h>
|
||||
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
class EditorCommandFocusService;
|
||||
class BuiltInIcons;
|
||||
class EditorIconService;
|
||||
class EditorSceneRuntime;
|
||||
class IViewportObjectPickerService;
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
namespace XCEngine::UI::Editor::Rendering::Host {
|
||||
|
||||
class UiTextureHost;
|
||||
|
||||
} // namespace XCEngine::UI::Editor::Rendering::Host
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
class SceneViewportController {
|
||||
public:
|
||||
void Initialize(
|
||||
const std::filesystem::path& repoRoot,
|
||||
Rendering::Host::UiTextureHost& renderer,
|
||||
const BuiltInIcons* builtInIcons);
|
||||
void Shutdown(Rendering::Host::UiTextureHost& renderer);
|
||||
void Initialize(const EditorIconService* iconService);
|
||||
void Shutdown();
|
||||
void ResetInteractionState();
|
||||
void SetCommandFocusService(EditorCommandFocusService* commandFocusService);
|
||||
|
||||
|
||||
@@ -1,33 +1,20 @@
|
||||
#include "Scene/SceneViewportFeature.h"
|
||||
|
||||
#include "Panels/EditorPanelIds.h"
|
||||
#include "UiTextureHost.h"
|
||||
#include "Viewport/SceneViewportResourcePaths.h"
|
||||
#include "Viewport/ViewportHostService.h"
|
||||
#include "EditorSceneRuntime.h"
|
||||
#include "State/EditorCommandFocusService.h"
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
void SceneViewportFeature::Initialize(
|
||||
const std::filesystem::path& repoRoot,
|
||||
Rendering::Host::UiTextureHost& textureHost,
|
||||
const BuiltInIcons* builtInIcons,
|
||||
ViewportHostService& viewportHostService) {
|
||||
m_renderService.Initialize(BuildSceneViewportShaderPaths(repoRoot));
|
||||
viewportHostService.SetContentRenderer(
|
||||
kScenePanelId,
|
||||
&m_renderService,
|
||||
SceneViewportRenderService::GetViewportResourceRequirements());
|
||||
m_controller.Initialize(repoRoot, textureHost, builtInIcons);
|
||||
const EditorIconService* iconService,
|
||||
EditorSceneViewportRuntime& sceneViewportRuntime) {
|
||||
m_sceneViewportRuntime = &sceneViewportRuntime;
|
||||
m_controller.Initialize(iconService);
|
||||
}
|
||||
|
||||
void SceneViewportFeature::Shutdown(
|
||||
Rendering::Host::UiTextureHost& textureHost,
|
||||
ViewportHostService& viewportHostService) {
|
||||
viewportHostService.SetContentRenderer(kScenePanelId, nullptr, {});
|
||||
m_controller.Shutdown(textureHost);
|
||||
m_renderService.Shutdown();
|
||||
void SceneViewportFeature::Shutdown() {
|
||||
m_controller.Shutdown();
|
||||
m_sceneViewportRuntime = nullptr;
|
||||
}
|
||||
|
||||
void SceneViewportFeature::ResetInteractionState() {
|
||||
@@ -40,17 +27,23 @@ void SceneViewportFeature::SetCommandFocusService(
|
||||
}
|
||||
|
||||
void SceneViewportFeature::SyncRenderRequest(EditorSceneRuntime& sceneRuntime) {
|
||||
m_renderService.SetRenderRequest(
|
||||
sceneRuntime.BuildSceneViewportRenderRequest());
|
||||
if (m_sceneViewportRuntime != nullptr) {
|
||||
m_sceneViewportRuntime->SetRenderRequest(
|
||||
sceneRuntime.BuildSceneViewportRenderRequest());
|
||||
}
|
||||
}
|
||||
|
||||
void SceneViewportFeature::Update(
|
||||
EditorSceneRuntime& sceneRuntime,
|
||||
const UIEditorWorkspaceComposeState& composeState,
|
||||
const UIEditorWorkspaceComposeFrame& composeFrame) {
|
||||
if (m_sceneViewportRuntime == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_controller.Update(
|
||||
sceneRuntime,
|
||||
m_renderService,
|
||||
m_sceneViewportRuntime->GetObjectPicker(),
|
||||
composeState,
|
||||
composeFrame);
|
||||
SyncRenderRequest(sceneRuntime);
|
||||
|
||||
@@ -1,42 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "Assets/EditorIconService.h"
|
||||
#include "Scene/SceneViewportController.h"
|
||||
#include "Viewport/SceneViewportRenderService.h"
|
||||
#include "Viewport/EditorViewportRuntimeServices.h"
|
||||
|
||||
#include <XCEditor/Workspace/UIEditorWorkspaceCompose.h>
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <filesystem>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
class EditorCommandFocusService;
|
||||
class BuiltInIcons;
|
||||
class EditorSceneRuntime;
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
namespace XCEngine::UI::Editor::Rendering::Host {
|
||||
|
||||
class UiTextureHost;
|
||||
|
||||
} // namespace XCEngine::UI::Editor::Rendering::Host
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
class ViewportHostService;
|
||||
|
||||
class SceneViewportFeature {
|
||||
public:
|
||||
void Initialize(
|
||||
const std::filesystem::path& repoRoot,
|
||||
Rendering::Host::UiTextureHost& textureHost,
|
||||
const BuiltInIcons* builtInIcons,
|
||||
ViewportHostService& viewportHostService);
|
||||
void Shutdown(
|
||||
Rendering::Host::UiTextureHost& textureHost,
|
||||
ViewportHostService& viewportHostService);
|
||||
const EditorIconService* iconService,
|
||||
EditorSceneViewportRuntime& sceneViewportRuntime);
|
||||
void Shutdown();
|
||||
void ResetInteractionState();
|
||||
void SetCommandFocusService(EditorCommandFocusService* commandFocusService);
|
||||
void SyncRenderRequest(EditorSceneRuntime& sceneRuntime);
|
||||
@@ -47,7 +29,7 @@ public:
|
||||
void Append(::XCEngine::UI::UIDrawList& drawList) const;
|
||||
|
||||
private:
|
||||
SceneViewportRenderService m_renderService = {};
|
||||
EditorSceneViewportRuntime* m_sceneViewportRuntime = nullptr;
|
||||
SceneViewportController m_controller = {};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#include "Scene/SceneViewportSceneOverlay.h"
|
||||
|
||||
#include "Scene/SceneViewportTransformGizmoSupport.h"
|
||||
#include "Assets/BuiltInIcons.h"
|
||||
#include "Assets/EditorIconService.h"
|
||||
#include "EditorSceneRuntime.h"
|
||||
|
||||
#include <XCEngine/Components/CameraComponent.h>
|
||||
@@ -68,14 +68,14 @@ SceneViewportGizmoSupport::SceneViewportOverlayData BuildOverlayData(
|
||||
return overlay;
|
||||
}
|
||||
|
||||
::XCEngine::UI::UITextureHandle ResolveCameraIcon(const BuiltInIcons* icons) {
|
||||
::XCEngine::UI::UITextureHandle ResolveCameraIcon(const EditorIconService* icons) {
|
||||
return icons != nullptr
|
||||
? icons->Resolve(BuiltInIconKind::CameraGizmo)
|
||||
: ::XCEngine::UI::UITextureHandle();
|
||||
}
|
||||
|
||||
::XCEngine::UI::UITextureHandle ResolveLightIcon(
|
||||
const BuiltInIcons* icons,
|
||||
const EditorIconService* icons,
|
||||
const LightComponent& light) {
|
||||
if (icons == nullptr) {
|
||||
return {};
|
||||
@@ -95,7 +95,7 @@ SceneViewportGizmoSupport::SceneViewportOverlayData BuildOverlayData(
|
||||
|
||||
} // namespace
|
||||
|
||||
void SceneViewportSceneOverlay::SetBuiltInIcons(const BuiltInIcons* icons) {
|
||||
void SceneViewportSceneOverlay::SetIconService(const EditorIconService* icons) {
|
||||
m_icons = icons;
|
||||
if (m_icons == nullptr) {
|
||||
ResetFrame();
|
||||
|
||||
@@ -7,8 +7,8 @@
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
class BuiltInIcons;
|
||||
class EditorSceneRuntime;
|
||||
class EditorIconService;
|
||||
|
||||
class SceneViewportSceneOverlay {
|
||||
public:
|
||||
@@ -21,7 +21,7 @@ public:
|
||||
}
|
||||
};
|
||||
|
||||
void SetBuiltInIcons(const BuiltInIcons* icons);
|
||||
void SetIconService(const EditorIconService* icons);
|
||||
void ResetFrame();
|
||||
void Refresh(
|
||||
EditorSceneRuntime& sceneRuntime,
|
||||
@@ -42,7 +42,7 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
const BuiltInIcons* m_icons = nullptr;
|
||||
const EditorIconService* m_icons = nullptr;
|
||||
Frame m_frame = {};
|
||||
};
|
||||
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
#include "Scene/SceneViewportToolOverlay.h"
|
||||
|
||||
#include "UiTextureHost.h"
|
||||
|
||||
#include <XCEditor/Widgets/UIEditorTextLayout.h>
|
||||
|
||||
#include <algorithm>
|
||||
@@ -39,16 +37,16 @@ constexpr float kToggleMinWidth = 60.0f;
|
||||
struct ToolButtonSpec {
|
||||
SceneToolMode mode = SceneToolMode::View;
|
||||
const char* label = "";
|
||||
const char* inactiveFile = "";
|
||||
const char* activeFile = "";
|
||||
BuiltInIconKind inactiveIcon = BuiltInIconKind::ViewMoveTool;
|
||||
BuiltInIconKind activeIcon = BuiltInIconKind::ViewMoveToolActive;
|
||||
};
|
||||
|
||||
constexpr std::array<ToolButtonSpec, 5> kToolButtonSpecs = {{
|
||||
{ SceneToolMode::View, "View", "view_move_tool.png", "view_move_tool_on.png" },
|
||||
{ SceneToolMode::Translate, "Move", "move_tool.png", "move_tool_on.png" },
|
||||
{ SceneToolMode::Rotate, "Rotate", "rotate_tool.png", "rotate_tool_on.png" },
|
||||
{ SceneToolMode::Scale, "Scale", "scale_tool.png", "scale_tool_on.png" },
|
||||
{ SceneToolMode::Transform, "Transform", "transform_tool.png", "transform_tool_on.png" }
|
||||
{ SceneToolMode::View, "View", BuiltInIconKind::ViewMoveTool, BuiltInIconKind::ViewMoveToolActive },
|
||||
{ SceneToolMode::Translate, "Move", BuiltInIconKind::MoveTool, BuiltInIconKind::MoveToolActive },
|
||||
{ SceneToolMode::Rotate, "Rotate", BuiltInIconKind::RotateTool, BuiltInIconKind::RotateToolActive },
|
||||
{ SceneToolMode::Scale, "Scale", BuiltInIconKind::ScaleTool, BuiltInIconKind::ScaleToolActive },
|
||||
{ SceneToolMode::Transform, "Transform", BuiltInIconKind::TransformTool, BuiltInIconKind::TransformToolActive }
|
||||
}};
|
||||
|
||||
bool ContainsPoint(const UIRect& rect, const UIPoint& point) {
|
||||
@@ -198,47 +196,10 @@ UIRect BuildToggleButtonRect(
|
||||
return kToggleIdle;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool SceneViewportToolOverlay::Initialize(
|
||||
const std::filesystem::path& repoRoot,
|
||||
Rendering::Host::UiTextureHost& renderer) {
|
||||
Shutdown(renderer);
|
||||
|
||||
const std::filesystem::path iconRoot =
|
||||
(repoRoot / "editor" / "resources" / "Icons").lexically_normal();
|
||||
bool loadedAnyTexture = false;
|
||||
for (std::size_t index = 0; index < kToolButtonSpecs.size(); ++index) {
|
||||
const ToolButtonSpec& path = kToolButtonSpecs[index];
|
||||
ToolTextureSet& textureSet = m_toolTextures[index];
|
||||
textureSet = {};
|
||||
textureSet.mode = path.mode;
|
||||
textureSet.label = path.label;
|
||||
|
||||
std::string error = {};
|
||||
loadedAnyTexture =
|
||||
renderer.LoadTextureFromFile(
|
||||
iconRoot / path.inactiveFile,
|
||||
textureSet.inactiveTexture,
|
||||
error) || loadedAnyTexture;
|
||||
error.clear();
|
||||
loadedAnyTexture =
|
||||
renderer.LoadTextureFromFile(
|
||||
iconRoot / path.activeFile,
|
||||
textureSet.activeTexture,
|
||||
error) || loadedAnyTexture;
|
||||
}
|
||||
|
||||
return loadedAnyTexture;
|
||||
}
|
||||
|
||||
void SceneViewportToolOverlay::Shutdown(Rendering::Host::UiTextureHost& renderer) {
|
||||
for (ToolTextureSet& textureSet : m_toolTextures) {
|
||||
renderer.ReleaseTexture(textureSet.inactiveTexture);
|
||||
renderer.ReleaseTexture(textureSet.activeTexture);
|
||||
textureSet = {};
|
||||
}
|
||||
|
||||
void SceneViewportToolOverlay::SetIconService(const EditorIconService* iconService) {
|
||||
m_iconService = iconService;
|
||||
ResetFrame();
|
||||
}
|
||||
|
||||
@@ -305,7 +266,6 @@ void SceneViewportToolOverlay::BuildFrame(
|
||||
|
||||
for (std::size_t index = 0; index < m_frame.buttons.size(); ++index) {
|
||||
const ToolButtonSpec& spec = kToolButtonSpecs[index];
|
||||
const ToolTextureSet& textureSet = m_toolTextures[index];
|
||||
SceneViewportToolOverlayButtonFrame& button = m_frame.buttons[index];
|
||||
button = {};
|
||||
button.mode = spec.mode;
|
||||
@@ -314,9 +274,10 @@ void SceneViewportToolOverlay::BuildFrame(
|
||||
button.active = spec.mode == activeMode;
|
||||
button.hovered = index == hoveredIndex;
|
||||
button.pressed = index == pressedIndex;
|
||||
button.texture = spec.mode == activeMode
|
||||
? textureSet.activeTexture
|
||||
: textureSet.inactiveTexture;
|
||||
if (m_iconService != nullptr) {
|
||||
button.texture = m_iconService->Resolve(
|
||||
spec.mode == activeMode ? spec.activeIcon : spec.inactiveIcon);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "SceneToolState.h"
|
||||
#include "HostFwd.h"
|
||||
#include "Assets/EditorIconService.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
#include <XCEngine/UI/Types.h>
|
||||
@@ -9,7 +9,6 @@
|
||||
#include <array>
|
||||
#include <cstddef>
|
||||
#include <cstdint>
|
||||
#include <filesystem>
|
||||
#include <string>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
@@ -57,10 +56,7 @@ struct SceneViewportToolOverlayFrame {
|
||||
|
||||
class SceneViewportToolOverlay {
|
||||
public:
|
||||
bool Initialize(
|
||||
const std::filesystem::path& repoRoot,
|
||||
Rendering::Host::UiTextureHost& renderer);
|
||||
void Shutdown(Rendering::Host::UiTextureHost& renderer);
|
||||
void SetIconService(const EditorIconService* iconService);
|
||||
void ResetFrame();
|
||||
|
||||
void BuildFrame(
|
||||
@@ -82,15 +78,8 @@ public:
|
||||
const SceneViewportToolOverlayFrame& GetFrame() const;
|
||||
|
||||
private:
|
||||
struct ToolTextureSet {
|
||||
SceneToolMode mode = SceneToolMode::View;
|
||||
const char* label = "";
|
||||
::XCEngine::UI::UITextureHandle inactiveTexture = {};
|
||||
::XCEngine::UI::UITextureHandle activeTexture = {};
|
||||
};
|
||||
|
||||
std::array<ToolTextureSet, 5> m_toolTextures = {};
|
||||
SceneViewportToolOverlayFrame m_frame = {};
|
||||
const EditorIconService* m_iconService = nullptr;
|
||||
};
|
||||
|
||||
void AppendSceneViewportToolOverlay(
|
||||
|
||||
Reference in New Issue
Block a user