From 2a8448cfbc4299bdc86dc73b14d261828f668062 Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Wed, 22 Apr 2026 14:53:24 +0800 Subject: [PATCH] refactor(new_editor): extract shell draw composer --- new_editor/CMakeLists.txt | 1 + .../Composition/EditorShellDrawComposer.cpp | 177 ++++++++++++++++++ .../app/Composition/EditorShellDrawComposer.h | 41 ++++ .../app/Composition/EditorShellRuntime.cpp | 169 ++--------------- .../app/Composition/EditorShellRuntime.h | 2 + 5 files changed, 235 insertions(+), 155 deletions(-) create mode 100644 new_editor/app/Composition/EditorShellDrawComposer.cpp create mode 100644 new_editor/app/Composition/EditorShellDrawComposer.h diff --git a/new_editor/CMakeLists.txt b/new_editor/CMakeLists.txt index c06e6139..5be1bbc2 100644 --- a/new_editor/CMakeLists.txt +++ b/new_editor/CMakeLists.txt @@ -220,6 +220,7 @@ if(XCENGINE_BUILD_XCUI_EDITOR_APP) set(XCUI_EDITOR_APP_COMPOSITION_SOURCES app/Composition/EditorShellAssetBuilder.cpp app/Composition/EditorContext.cpp + app/Composition/EditorShellDrawComposer.cpp app/Composition/EditorShellRuntime.cpp app/Composition/EditorWindowWorkspaceStore.cpp app/Composition/WorkspaceEventSync.cpp diff --git a/new_editor/app/Composition/EditorShellDrawComposer.cpp b/new_editor/app/Composition/EditorShellDrawComposer.cpp new file mode 100644 index 00000000..55c9fa5f --- /dev/null +++ b/new_editor/app/Composition/EditorShellDrawComposer.cpp @@ -0,0 +1,177 @@ +#include "Composition/EditorShellDrawComposer.h" + +#include "Features/ColorPicker/ColorPickerPanel.h" +#include "Features/Console/ConsolePanel.h" +#include "Features/Hierarchy/HierarchyPanel.h" +#include "Features/Inspector/InspectorPanel.h" +#include "Features/Project/ProjectPanel.h" +#include "Features/Scene/SceneViewportFeature.h" +#include "Rendering/Assets/BuiltInIcons.h" + +#include +#include +#include + +#include + +namespace XCEngine::UI::Editor::App { + +namespace { + +using ::XCEngine::UI::UIDrawData; +using ::XCEngine::UI::UIDrawList; + +UIEditorShellComposeModel BuildShellComposeModelFromFrame( + const UIEditorShellInteractionFrame& frame) { + UIEditorShellComposeModel model = {}; + model.menuBarItems = frame.request.menuBarItems; + model.toolbarButtons = frame.model.toolbarButtons; + model.statusSegments = frame.model.statusSegments; + model.workspacePresentations = frame.model.workspacePresentations; + return model; +} + +void AppendShellPopups( + UIDrawList& drawList, + const UIEditorShellInteractionFrame& frame, + const UIEditorShellInteractionPalette& palette, + const UIEditorShellInteractionMetrics& metrics) { + const std::size_t popupCount = + (std::min)(frame.request.popupRequests.size(), frame.popupFrames.size()); + for (std::size_t index = 0; index < popupCount; ++index) { + const UIEditorShellInteractionPopupRequest& popupRequest = + frame.request.popupRequests[index]; + const UIEditorShellInteractionPopupFrame& popupFrame = + frame.popupFrames[index]; + Widgets::AppendUIEditorMenuPopupBackground( + drawList, + popupRequest.layout, + popupRequest.widgetItems, + popupFrame.popupState, + palette.popupPalette, + metrics.popupMetrics); + Widgets::AppendUIEditorMenuPopupForeground( + drawList, + popupRequest.layout, + popupRequest.widgetItems, + popupFrame.popupState, + palette.popupPalette, + metrics.popupMetrics); + } +} + +template +void AppendDrawPacket( + UIDrawData& drawData, + std::string debugName, + AppendFn&& appendFn) { + UIDrawList drawList(std::move(debugName)); + appendFn(drawList); + if (!drawList.Empty()) { + drawData.AddDrawList(std::move(drawList)); + } +} + +} // namespace + +void EditorShellDrawComposer::Append( + const EditorShellDrawComposerContext& context, + UIDrawData& drawData) const { + const auto& metrics = ResolveUIEditorShellInteractionMetrics(); + const auto& palette = ResolveUIEditorShellInteractionPalette(); + const UIEditorShellComposeModel shellComposeModel = + BuildShellComposeModelFromFrame(context.shellFrame); + + AppendDrawPacket( + drawData, + "XCEditorShell.Compose.Base", + [&](UIDrawList& drawList) { + AppendUIEditorShellComposeBase( + drawList, + context.shellFrame.shellFrame, + shellComposeModel, + context.shellInteractionState.composeState, + palette.shellPalette, + metrics.shellMetrics, + &context.builtInIcons); + }); + AppendDrawPacket( + drawData, + "XCEditorShell.Compose.Workspace", + [&](UIDrawList& drawList) { + AppendUIEditorWorkspaceCompose( + drawList, + context.shellFrame.workspaceInteractionFrame.composeFrame, + palette.shellPalette.dockHostPalette, + metrics.shellMetrics.dockHostMetrics, + palette.shellPalette.viewportPalette, + metrics.shellMetrics.viewportMetrics, + UIEditorWorkspaceComposeAppendOptions{ + true, + false + }); + }); + AppendDrawPacket( + drawData, + "XCEditorShell.Compose.ViewportTextures", + [&](UIDrawList& drawList) { + AppendUIEditorWorkspaceComposeViewportTextures( + drawList, + context.shellFrame.workspaceInteractionFrame.composeFrame, + palette.shellPalette.viewportPalette); + }); + AppendDrawPacket( + drawData, + "XCEditorShell.Compose.StatusBar", + [&](UIDrawList& drawList) { + AppendUIEditorShellComposeStatusBar( + drawList, + context.shellFrame.shellFrame, + shellComposeModel, + context.shellInteractionState.composeState, + palette.shellPalette, + metrics.shellMetrics); + }); + AppendDrawPacket( + drawData, + "XCEditorPanel.Console", + [&](UIDrawList& drawList) { context.consolePanel.Append(drawList); }); + AppendDrawPacket( + drawData, + "XCEditorPanel.ColorPicker", + [&](UIDrawList& drawList) { context.colorPickerPanel.Append(drawList); }); + AppendDrawPacket( + drawData, + "XCEditorPanel.Hierarchy", + [&](UIDrawList& drawList) { context.hierarchyPanel.Append(drawList); }); + AppendDrawPacket( + drawData, + "XCEditorPanel.Inspector", + [&](UIDrawList& drawList) { context.inspectorPanel.Append(drawList); }); + AppendDrawPacket( + drawData, + "XCEditorPanel.Project", + [&](UIDrawList& drawList) { context.projectPanel.Append(drawList); }); + AppendDrawPacket( + drawData, + "XCEditorPanel.SceneOverlay", + [&](UIDrawList& drawList) { context.sceneViewportFeature.Append(drawList); }); + AppendDrawPacket( + drawData, + "XCEditorShell.Compose.Overlay", + [&](UIDrawList& drawList) { + AppendUIEditorShellComposeOverlay( + drawList, + context.shellFrame.workspaceInteractionFrame.composeFrame, + palette.shellPalette, + metrics.shellMetrics); + }); + AppendDrawPacket( + drawData, + "XCEditorShell.Popups", + [&](UIDrawList& drawList) { + AppendShellPopups(drawList, context.shellFrame, palette, metrics); + }); +} + +} // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Composition/EditorShellDrawComposer.h b/new_editor/app/Composition/EditorShellDrawComposer.h new file mode 100644 index 00000000..a3419fae --- /dev/null +++ b/new_editor/app/Composition/EditorShellDrawComposer.h @@ -0,0 +1,41 @@ +#pragma once + +#include + +namespace XCEngine::UI::Editor { + +struct UIEditorShellInteractionFrame; +struct UIEditorShellInteractionState; + +} // namespace XCEngine::UI::Editor + +namespace XCEngine::UI::Editor::App { + +class BuiltInIcons; +class ColorPickerPanel; +class ConsolePanel; +class HierarchyPanel; +class InspectorPanel; +class ProjectPanel; +class SceneViewportFeature; + +struct EditorShellDrawComposerContext { + const UIEditorShellInteractionFrame& shellFrame; + const UIEditorShellInteractionState& shellInteractionState; + const BuiltInIcons& builtInIcons; + const ConsolePanel& consolePanel; + const ColorPickerPanel& colorPickerPanel; + const HierarchyPanel& hierarchyPanel; + const InspectorPanel& inspectorPanel; + const ProjectPanel& projectPanel; + const SceneViewportFeature& sceneViewportFeature; +}; + +class EditorShellDrawComposer final { +public: + void Append( + const EditorShellDrawComposerContext& context, + ::XCEngine::UI::UIDrawData& drawData) const; +}; + +} // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Composition/EditorShellRuntime.cpp b/new_editor/app/Composition/EditorShellRuntime.cpp index 65203aa4..77a84817 100644 --- a/new_editor/app/Composition/EditorShellRuntime.cpp +++ b/new_editor/app/Composition/EditorShellRuntime.cpp @@ -210,166 +210,25 @@ bool EditorShellRuntime::HasInteractiveCapture() const { namespace XCEngine::UI::Editor::App { -using ::XCEngine::UI::UIDrawList; - -UIEditorShellComposeModel BuildShellComposeModelFromFrame( - const UIEditorShellInteractionFrame& frame) { - UIEditorShellComposeModel model = {}; - model.menuBarItems = frame.request.menuBarItems; - model.toolbarButtons = frame.model.toolbarButtons; - model.statusSegments = frame.model.statusSegments; - model.workspacePresentations = frame.model.workspacePresentations; - return model; -} - -void AppendShellPopups( - UIDrawList& drawList, - const UIEditorShellInteractionFrame& frame, - const UIEditorShellInteractionPalette& palette, - const UIEditorShellInteractionMetrics& metrics) { - const std::size_t popupCount = - (std::min)(frame.request.popupRequests.size(), frame.popupFrames.size()); - for (std::size_t index = 0; index < popupCount; ++index) { - const UIEditorShellInteractionPopupRequest& popupRequest = - frame.request.popupRequests[index]; - const UIEditorShellInteractionPopupFrame& popupFrame = - frame.popupFrames[index]; - Widgets::AppendUIEditorMenuPopupBackground( - drawList, - popupRequest.layout, - popupRequest.widgetItems, - popupFrame.popupState, - palette.popupPalette, - metrics.popupMetrics); - Widgets::AppendUIEditorMenuPopupForeground( - drawList, - popupRequest.layout, - popupRequest.widgetItems, - popupFrame.popupState, - palette.popupPalette, - metrics.popupMetrics); - } -} - -} // namespace XCEngine::UI::Editor::App - -namespace XCEngine::UI::Editor::App { - -using ::XCEngine::UI::UIDrawList; -using ::XCEngine::UI::UIDrawData; - -template -void AppendDrawPacket( - UIDrawData& drawData, - std::string debugName, - AppendFn&& appendFn) { - UIDrawList drawList(std::move(debugName)); - appendFn(drawList); - if (!drawList.Empty()) { - drawData.AddDrawList(std::move(drawList)); - } -} - void EditorShellRuntime::RenderRequestedViewports( const ::XCEngine::Rendering::RenderContext& renderContext) { m_viewportHostService.RenderRequestedViewports(renderContext); } -void EditorShellRuntime::Append(UIDrawData& drawData) const { - const auto& metrics = ResolveUIEditorShellInteractionMetrics(); - const auto& palette = ResolveUIEditorShellInteractionPalette(); - const UIEditorShellComposeModel shellComposeModel = - BuildShellComposeModelFromFrame(m_shellFrame); - AppendDrawPacket( - drawData, - "XCEditorShell.Compose.Base", - [&](UIDrawList& drawList) { - AppendUIEditorShellComposeBase( - drawList, - m_shellFrame.shellFrame, - shellComposeModel, - m_shellInteractionState.composeState, - palette.shellPalette, - metrics.shellMetrics, - &m_builtInIcons); - }); - AppendDrawPacket( - drawData, - "XCEditorShell.Compose.Workspace", - [&](UIDrawList& drawList) { - AppendUIEditorWorkspaceCompose( - drawList, - m_shellFrame.workspaceInteractionFrame.composeFrame, - palette.shellPalette.dockHostPalette, - metrics.shellMetrics.dockHostMetrics, - palette.shellPalette.viewportPalette, - metrics.shellMetrics.viewportMetrics, - UIEditorWorkspaceComposeAppendOptions{ - true, - false - }); - }); - AppendDrawPacket( - drawData, - "XCEditorShell.Compose.ViewportTextures", - [&](UIDrawList& drawList) { - AppendUIEditorWorkspaceComposeViewportTextures( - drawList, - m_shellFrame.workspaceInteractionFrame.composeFrame, - palette.shellPalette.viewportPalette); - }); - AppendDrawPacket( - drawData, - "XCEditorShell.Compose.StatusBar", - [&](UIDrawList& drawList) { - AppendUIEditorShellComposeStatusBar( - drawList, - m_shellFrame.shellFrame, - shellComposeModel, - m_shellInteractionState.composeState, - palette.shellPalette, - metrics.shellMetrics); - }); - AppendDrawPacket( - drawData, - "XCEditorPanel.Console", - [&](UIDrawList& drawList) { m_consolePanel.Append(drawList); }); - AppendDrawPacket( - drawData, - "XCEditorPanel.ColorPicker", - [&](UIDrawList& drawList) { m_colorPickerPanel.Append(drawList); }); - AppendDrawPacket( - drawData, - "XCEditorPanel.Hierarchy", - [&](UIDrawList& drawList) { m_hierarchyPanel.Append(drawList); }); - AppendDrawPacket( - drawData, - "XCEditorPanel.Inspector", - [&](UIDrawList& drawList) { m_inspectorPanel.Append(drawList); }); - AppendDrawPacket( - drawData, - "XCEditorPanel.Project", - [&](UIDrawList& drawList) { m_projectPanel.Append(drawList); }); - AppendDrawPacket( - drawData, - "XCEditorPanel.SceneOverlay", - [&](UIDrawList& drawList) { m_sceneViewportFeature.Append(drawList); }); - AppendDrawPacket( - drawData, - "XCEditorShell.Compose.Overlay", - [&](UIDrawList& drawList) { - AppendUIEditorShellComposeOverlay( - drawList, - m_shellFrame.workspaceInteractionFrame.composeFrame, - palette.shellPalette, - metrics.shellMetrics); - }); - AppendDrawPacket( - drawData, - "XCEditorShell.Popups", - [&](UIDrawList& drawList) { - AppendShellPopups(drawList, m_shellFrame, palette, metrics); - }); +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 diff --git a/new_editor/app/Composition/EditorShellRuntime.h b/new_editor/app/Composition/EditorShellRuntime.h index 7c301ce3..5e945564 100644 --- a/new_editor/app/Composition/EditorShellRuntime.h +++ b/new_editor/app/Composition/EditorShellRuntime.h @@ -1,5 +1,6 @@ #pragma once +#include "Composition/EditorShellDrawComposer.h" #include "Composition/EditorShellPointerInteraction.h" #include "Composition/EditorShellVariant.h" #include "Features/Console/ConsolePanel.h" @@ -113,6 +114,7 @@ private: UIEditorShellInteractionFrame m_shellFrame = {}; std::vector m_traceEntries = {}; UIEditorWorkspaceSplitterDragCorrectionState m_splitterDragCorrectionState = {}; + EditorShellDrawComposer m_drawComposer = {}; }; } // namespace XCEngine::UI::Editor::App