Files
XCEngine/new_editor/app/Composition/EditorShellRuntime.cpp

230 lines
8.1 KiB
C++

#include "Composition/EditorShellRuntime.h"
#include "Ports/TexturePort.h"
#include "Ports/ViewportRenderPort.h"
#include "Composition/EditorContext.h"
#include "Composition/EditorPanelIds.h"
#include <XCEditor/Shell/UIEditorShellCapturePolicy.h>
#include <XCEngine/Rendering/RenderContext.h>
namespace XCEngine::UI::Editor::App {
void EditorShellRuntime::Initialize(
const std::filesystem::path& repoRoot,
Ports::TexturePort& textureHost,
UIEditorTextMeasurer& textMeasurer) {
m_textureHost = &textureHost;
m_builtInIcons.Initialize(textureHost);
m_sceneViewportFeature.Initialize(
repoRoot,
textureHost,
&m_builtInIcons,
m_viewportHostService);
m_hierarchyPanel.SetBuiltInIcons(&m_builtInIcons);
m_projectPanel.SetBuiltInIcons(&m_builtInIcons);
m_projectPanel.SetTextMeasurer(&textMeasurer);
m_hierarchyPanel.Initialize();
}
void EditorShellRuntime::AttachViewportWindowRenderer(Ports::ViewportRenderPort& renderer) {
m_viewportHostService.AttachWindowRenderer(renderer);
}
void EditorShellRuntime::DetachViewportWindowRenderer() {
m_viewportHostService.DetachWindowRenderer();
}
void EditorShellRuntime::SetViewportSurfacePresentationEnabled(bool enabled) {
m_viewportHostService.SetSurfacePresentationEnabled(enabled);
}
void EditorShellRuntime::Shutdown() {
m_shellFrame = {};
m_shellInteractionState = {};
m_splitterDragCorrectionState = {};
m_traceEntries.clear();
m_sceneEditCommandRoute = {};
if (m_textureHost != nullptr) {
m_sceneViewportFeature.Shutdown(*m_textureHost, m_viewportHostService);
m_builtInIcons.Shutdown();
m_textureHost = nullptr;
} else {
m_builtInIcons.Shutdown();
}
m_viewportHostService.Shutdown();
}
void EditorShellRuntime::ResetInteractionState() {
m_shellFrame = {};
m_shellInteractionState = {};
m_splitterDragCorrectionState = {};
m_traceEntries.clear();
m_sceneViewportFeature.ResetInteractionState();
m_hierarchyPanel.ResetInteractionState();
m_colorPickerPanel.ResetInteractionState();
m_projectPanel.ResetInteractionState();
}
const UIEditorShellInteractionFrame& EditorShellRuntime::GetShellFrame() const {
return m_shellFrame;
}
const UIEditorShellInteractionState& EditorShellRuntime::GetShellInteractionState() const {
return m_shellInteractionState;
}
const std::vector<WorkspaceTraceEntry>& EditorShellRuntime::GetTraceEntries() const {
return m_traceEntries;
}
const std::string& EditorShellRuntime::GetBuiltInIconError() const {
return m_builtInIcons.GetLastError();
}
void EditorShellRuntime::SetExternalDockHostDropPreview(
const Widgets::UIEditorDockHostDropPreviewState& preview) {
m_shellInteractionState.workspaceInteractionState.dockHostInteractionState
.dockHostState.dropPreview = preview;
}
void EditorShellRuntime::ClearExternalDockHostDropPreview() {
m_shellInteractionState.workspaceInteractionState.dockHostInteractionState
.dockHostState.dropPreview = {};
}
ProjectPanel::CursorKind EditorShellRuntime::GetHostedContentCursorKind() const {
return m_projectPanel.GetCursorKind();
}
Widgets::UIEditorDockHostCursorKind EditorShellRuntime::GetDockCursorKind() const {
return Widgets::ResolveUIEditorDockHostCursorKind(
m_shellFrame.workspaceInteractionFrame.dockHostFrame.layout);
}
bool EditorShellRuntime::TryResolveDockTabDragHotspot(
std::string_view nodeId,
std::string_view panelId,
const ::XCEngine::UI::UIPoint& point,
::XCEngine::UI::UIPoint& outHotspot) const {
return TryResolveUIEditorDockHostTabDragHotspot(
m_shellFrame.workspaceInteractionFrame.dockHostFrame.layout,
nodeId,
panelId,
point,
outHotspot);
}
UIEditorDockHostTabDropTarget EditorShellRuntime::ResolveDockTabDropTarget(
const ::XCEngine::UI::UIPoint& point) const {
return ResolveUIEditorDockHostTabDropTarget(
m_shellFrame.workspaceInteractionFrame.dockHostFrame.layout,
point);
}
bool EditorShellRuntime::HasHostedContentCapture() const {
return m_hierarchyPanel.HasActivePointerCapture() ||
m_projectPanel.HasActivePointerCapture();
}
bool EditorShellRuntime::HasShellInteractiveCapture() const {
return HasActiveUIEditorShellInteractiveCapture(m_shellInteractionState);
}
bool EditorShellRuntime::HasInteractiveCapture() const {
return HasHostedContentCapture() || HasShellInteractiveCapture();
}
} // namespace XCEngine::UI::Editor::App
namespace XCEngine::UI::Editor::App {
void EditorShellRuntime::RenderRequestedViewports(
const ::XCEngine::Rendering::RenderContext& renderContext) {
m_viewportHostService.RenderRequestedViewports(renderContext);
}
void EditorShellRuntime::Append(::XCEngine::UI::UIDrawData& drawData) const {
m_drawComposer.Append(
EditorShellDrawComposerContext{
.shellFrame = m_shellFrame,
.shellInteractionState = m_shellInteractionState,
.builtInIcons = m_builtInIcons,
.consolePanel = m_consolePanel,
.colorPickerPanel = m_colorPickerPanel,
.hierarchyPanel = m_hierarchyPanel,
.inspectorPanel = m_inspectorPanel,
.projectPanel = m_projectPanel,
.sceneViewportFeature = m_sceneViewportFeature,
},
drawData);
}
} // namespace XCEngine::UI::Editor::App
namespace XCEngine::UI::Editor::App {
void EditorShellRuntime::Update(
EditorContext& context,
UIEditorWorkspaceController& workspaceController,
const ::XCEngine::UI::UIRect& bounds,
const std::vector<::XCEngine::UI::UIInputEvent>& inputEvents,
std::string_view captureText,
EditorShellVariant shellVariant,
bool useDetachedTitleBarTabStrip,
float detachedTitleBarTabHeight,
float detachedWindowChromeHeight) {
const auto buildDefinition = [&]() {
return m_sessionCoordinator.PrepareShellDefinition(
EditorShellSessionCoordinatorContext{
.context = context,
.workspaceController = workspaceController,
.captureText = captureText,
.shellVariant = shellVariant,
.hierarchyPanel = m_hierarchyPanel,
.inspectorPanel = m_inspectorPanel,
.projectPanel = m_projectPanel,
.sceneEditCommandRoute = m_sceneEditCommandRoute,
.sceneViewportFeature = m_sceneViewportFeature,
});
};
m_interactionEngine.Update(
EditorShellInteractionEngineContext{
.shellInteractionState = m_shellInteractionState,
.shellFrame = m_shellFrame,
.splitterDragCorrectionState = m_splitterDragCorrectionState,
.workspaceController = workspaceController,
.bounds = bounds,
.inputEvents = inputEvents,
.shellServices = context.GetShellServices(),
.buildDefinition = buildDefinition,
.hostedContentCaptureActive = HasHostedContentCapture(),
.useDetachedTitleBarTabStrip = useDetachedTitleBarTabStrip,
.detachedTitleBarTabHeight = detachedTitleBarTabHeight,
.detachedWindowChromeHeight = detachedWindowChromeHeight,
.viewportHostService = m_viewportHostService,
});
m_sessionCoordinator.FinalizeFrame(context, workspaceController, m_shellFrame.result);
m_hostedPanelCoordinator.Update(
EditorShellHostedPanelCoordinatorContext{
.context = context,
.shellFrame = m_shellFrame,
.shellInteractionState = m_shellInteractionState,
.inputEvents = inputEvents,
.shellInteractiveCaptureActive = HasShellInteractiveCapture(),
.consolePanel = m_consolePanel,
.colorPickerPanel = m_colorPickerPanel,
.hierarchyPanel = m_hierarchyPanel,
.inspectorPanel = m_inspectorPanel,
.projectPanel = m_projectPanel,
.sceneViewportFeature = m_sceneViewportFeature,
});
m_traceEntries = SyncWorkspaceEvents(
context,
m_hierarchyPanel.GetFrameEvents(),
m_projectPanel.GetFrameEvents());
}
} // namespace XCEngine::UI::Editor::App