From c42fd4d48b305051e93c4a719b8ec4da531ea52e Mon Sep 17 00:00:00 2001 From: ssdfasd <2156608475@qq.com> Date: Wed, 22 Apr 2026 16:34:28 +0800 Subject: [PATCH] new_editor: reduce app shell capture plumbing --- .../EditorShellHostedPanelCoordinator.cpp | 95 +------------------ .../EditorShellHostedPanelCoordinator.h | 6 -- .../EditorShellPointerInteraction.h | 27 ------ .../app/Composition/EditorShellRuntime.cpp | 23 +---- .../app/Composition/EditorShellRuntime.h | 4 - .../app/Features/Hierarchy/HierarchyPanel.cpp | 8 -- .../app/Features/Hierarchy/HierarchyPanel.h | 2 - .../app/Features/Project/ProjectPanel.cpp | 12 --- .../app/Features/Project/ProjectPanel.h | 2 - .../app/Platform/Win32/EditorWindow.cpp | 6 +- .../Shell/UIEditorShellCapturePolicy.h | 14 +++ .../src/Shell/UIEditorShellCapturePolicy.cpp | 76 +++++++++++++++ 12 files changed, 101 insertions(+), 174 deletions(-) delete mode 100644 new_editor/app/Composition/EditorShellPointerInteraction.h diff --git a/new_editor/app/Composition/EditorShellHostedPanelCoordinator.cpp b/new_editor/app/Composition/EditorShellHostedPanelCoordinator.cpp index 4cc0bbd4..2634a923 100644 --- a/new_editor/app/Composition/EditorShellHostedPanelCoordinator.cpp +++ b/new_editor/app/Composition/EditorShellHostedPanelCoordinator.cpp @@ -10,14 +10,13 @@ #include "Features/Scene/SceneViewportFeature.h" #include +#include #include namespace XCEngine::UI::Editor::App { namespace { -using ::XCEngine::UI::UIInputEvent; - const UIEditorHostedPanelDispatchEntry& ResolveHostedPanelDispatchEntry( const UIEditorHostedPanelDispatchFrame& dispatchFrame, std::string_view panelId) { @@ -31,102 +30,16 @@ const UIEditorHostedPanelDispatchEntry& ResolveHostedPanelDispatchEntry( return kEmptyEntry; } -bool ShouldHostedContentYieldPointerStream( - const UIEditorShellInteractionFrame& shellFrame, - bool shellInteractiveCaptureActive) { - if (shellInteractiveCaptureActive || - shellFrame.result.requestPointerCapture || - shellFrame.result.releasePointerCapture) { - return true; - } - - return shellFrame.result.workspaceResult.dockHostResult.hitTarget.kind == - Widgets::UIEditorDockHostHitTargetKind::SplitterHandle; -} - -std::vector FilterHostedContentInputEventsForShellOwnership( - const std::vector& inputEvents, - bool shellOwnsPointerStream) { - if (!shellOwnsPointerStream) { - return inputEvents; - } - - std::vector filteredEvents = {}; - filteredEvents.reserve(inputEvents.size() + 1u); - - bool strippedPointerInput = false; - UIInputEvent lastPointerEvent = {}; - for (const UIInputEvent& event : inputEvents) { - if (event.type == ::XCEngine::UI::UIInputEventType::PointerMove || - event.type == ::XCEngine::UI::UIInputEventType::PointerEnter || - event.type == ::XCEngine::UI::UIInputEventType::PointerLeave || - event.type == ::XCEngine::UI::UIInputEventType::PointerButtonDown || - event.type == ::XCEngine::UI::UIInputEventType::PointerButtonUp || - event.type == ::XCEngine::UI::UIInputEventType::PointerWheel) { - strippedPointerInput = true; - lastPointerEvent = event; - continue; - } - - filteredEvents.push_back(event); - } - - if (strippedPointerInput) { - UIInputEvent leaveEvent = {}; - leaveEvent.type = ::XCEngine::UI::UIInputEventType::PointerLeave; - leaveEvent.position = lastPointerEvent.position; - leaveEvent.modifiers = lastPointerEvent.modifiers; - filteredEvents.push_back(leaveEvent); - } - - return filteredEvents; -} - } // namespace -EditorShellPointerOwner EditorShellHostedPanelCoordinator::ResolvePointerOwner( - const UIEditorShellInteractionState& shellInteractionState, - const HierarchyPanel& hierarchyPanel, - const ProjectPanel& projectPanel) const { - const auto& dockHostInteractionState = - shellInteractionState.workspaceInteractionState.dockHostInteractionState; - if (dockHostInteractionState.splitterDragState.active || - !dockHostInteractionState.activeTabDragNodeId.empty()) { - return EditorShellPointerOwner::DockHost; - } - - for (const auto& panelState : - shellInteractionState.workspaceInteractionState.composeState.panelStates) { - if (!panelState.viewportShellState.inputBridgeState.captured) { - continue; - } - - if (panelState.panelId == kGamePanelId) { - return EditorShellPointerOwner::GameViewport; - } - - return EditorShellPointerOwner::SceneViewport; - } - - if (hierarchyPanel.HasActivePointerCapture()) { - return EditorShellPointerOwner::HierarchyPanel; - } - - if (projectPanel.HasActivePointerCapture()) { - return EditorShellPointerOwner::ProjectPanel; - } - - return EditorShellPointerOwner::None; -} - void EditorShellHostedPanelCoordinator::Update( const EditorShellHostedPanelCoordinatorContext& context) const { const bool shellOwnsHostedContentPointerStream = - ShouldHostedContentYieldPointerStream( + ShouldYieldUIEditorHostedContentPointerStream( context.shellFrame, context.shellInteractiveCaptureActive); - const std::vector hostedContentEvents = - FilterHostedContentInputEventsForShellOwnership( + const std::vector<::XCEngine::UI::UIInputEvent> hostedContentEvents = + FilterUIEditorHostedContentInputEvents( context.inputEvents, shellOwnsHostedContentPointerStream); diff --git a/new_editor/app/Composition/EditorShellHostedPanelCoordinator.h b/new_editor/app/Composition/EditorShellHostedPanelCoordinator.h index a92e6de8..b9d6a643 100644 --- a/new_editor/app/Composition/EditorShellHostedPanelCoordinator.h +++ b/new_editor/app/Composition/EditorShellHostedPanelCoordinator.h @@ -1,7 +1,5 @@ #pragma once -#include "Composition/EditorShellPointerInteraction.h" - #include namespace XCEngine::UI { @@ -43,10 +41,6 @@ struct EditorShellHostedPanelCoordinatorContext { class EditorShellHostedPanelCoordinator final { public: - EditorShellPointerOwner ResolvePointerOwner( - const UIEditorShellInteractionState& shellInteractionState, - const HierarchyPanel& hierarchyPanel, - const ProjectPanel& projectPanel) const; void Update(const EditorShellHostedPanelCoordinatorContext& context) const; }; diff --git a/new_editor/app/Composition/EditorShellPointerInteraction.h b/new_editor/app/Composition/EditorShellPointerInteraction.h deleted file mode 100644 index f802f049..00000000 --- a/new_editor/app/Composition/EditorShellPointerInteraction.h +++ /dev/null @@ -1,27 +0,0 @@ -#pragma once - -#include - -namespace XCEngine::UI::Editor::App { - -enum class EditorShellPointerOwner : std::uint8_t { - None = 0, - DockHost, - SceneViewport, - GameViewport, - HierarchyPanel, - ProjectPanel, -}; - -constexpr bool IsShellPointerOwner(EditorShellPointerOwner owner) { - return owner == EditorShellPointerOwner::DockHost || - owner == EditorShellPointerOwner::SceneViewport || - owner == EditorShellPointerOwner::GameViewport; -} - -constexpr bool IsHostedContentPointerOwner(EditorShellPointerOwner owner) { - return owner == EditorShellPointerOwner::HierarchyPanel || - owner == EditorShellPointerOwner::ProjectPanel; -} - -} // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Composition/EditorShellRuntime.cpp b/new_editor/app/Composition/EditorShellRuntime.cpp index 4b9d33b3..a49fae7a 100644 --- a/new_editor/app/Composition/EditorShellRuntime.cpp +++ b/new_editor/app/Composition/EditorShellRuntime.cpp @@ -3,6 +3,7 @@ #include "Ports/ViewportRenderPort.h" #include "Composition/EditorContext.h" #include "Composition/EditorPanelIds.h" +#include #include namespace XCEngine::UI::Editor::App { @@ -127,31 +128,17 @@ UIEditorDockHostTabDropTarget EditorShellRuntime::ResolveDockTabDropTarget( point); } -EditorShellPointerOwner EditorShellRuntime::GetPointerOwner() const { - return m_hostedPanelCoordinator.ResolvePointerOwner( - m_shellInteractionState, - m_hierarchyPanel, - m_projectPanel); -} - -bool EditorShellRuntime::WantsHostPointerCapture() const { - return IsHostedContentPointerOwner(GetPointerOwner()); -} - -bool EditorShellRuntime::WantsHostPointerRelease() const { - return !IsHostedContentPointerOwner(GetPointerOwner()); -} - bool EditorShellRuntime::HasHostedContentCapture() const { - return IsHostedContentPointerOwner(GetPointerOwner()); + return m_hierarchyPanel.HasActivePointerCapture() || + m_projectPanel.HasActivePointerCapture(); } bool EditorShellRuntime::HasShellInteractiveCapture() const { - return IsShellPointerOwner(GetPointerOwner()); + return HasActiveUIEditorShellInteractiveCapture(m_shellInteractionState); } bool EditorShellRuntime::HasInteractiveCapture() const { - return GetPointerOwner() != EditorShellPointerOwner::None; + return HasHostedContentCapture() || HasShellInteractiveCapture(); } } // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Composition/EditorShellRuntime.h b/new_editor/app/Composition/EditorShellRuntime.h index c67e1f9d..deb97394 100644 --- a/new_editor/app/Composition/EditorShellRuntime.h +++ b/new_editor/app/Composition/EditorShellRuntime.h @@ -3,7 +3,6 @@ #include "Composition/EditorShellDrawComposer.h" #include "Composition/EditorShellHostedPanelCoordinator.h" #include "Composition/EditorShellInteractionEngine.h" -#include "Composition/EditorShellPointerInteraction.h" #include "Composition/EditorShellSessionCoordinator.h" #include "Composition/EditorShellVariant.h" #include "Features/Console/ConsolePanel.h" @@ -95,9 +94,6 @@ public: ::XCEngine::UI::UIPoint& outHotspot) const; UIEditorDockHostTabDropTarget ResolveDockTabDropTarget( const ::XCEngine::UI::UIPoint& point) const; - EditorShellPointerOwner GetPointerOwner() const; - bool WantsHostPointerCapture() const; - bool WantsHostPointerRelease() const; bool HasHostedContentCapture() const; bool HasShellInteractiveCapture() const; bool HasInteractiveCapture() const; diff --git a/new_editor/app/Features/Hierarchy/HierarchyPanel.cpp b/new_editor/app/Features/Hierarchy/HierarchyPanel.cpp index 0371113e..ae22116a 100644 --- a/new_editor/app/Features/Hierarchy/HierarchyPanel.cpp +++ b/new_editor/app/Features/Hierarchy/HierarchyPanel.cpp @@ -368,14 +368,6 @@ UIRect HierarchyPanel::BuildRenameBounds( hostedMetrics); } -bool HierarchyPanel::WantsHostPointerCapture() const { - return m_dragState.requestPointerCapture; -} - -bool HierarchyPanel::WantsHostPointerRelease() const { - return m_dragState.requestPointerRelease; -} - bool HierarchyPanel::HasActivePointerCapture() const { return TreeDrag::HasActivePointerCapture(m_dragState); } diff --git a/new_editor/app/Features/Hierarchy/HierarchyPanel.h b/new_editor/app/Features/Hierarchy/HierarchyPanel.h index 4ac86c15..7aebff4e 100644 --- a/new_editor/app/Features/Hierarchy/HierarchyPanel.h +++ b/new_editor/app/Features/Hierarchy/HierarchyPanel.h @@ -48,8 +48,6 @@ public: const UIEditorHostedPanelDispatchEntry& dispatchEntry, const std::vector<::XCEngine::UI::UIInputEvent>& inputEvents); void Append(::XCEngine::UI::UIDrawList& drawList) const; - bool WantsHostPointerCapture() const; - bool WantsHostPointerRelease() const; bool HasActivePointerCapture() const; const std::vector& GetFrameEvents() const; UIEditorHostCommandEvaluationResult EvaluateEditCommand( diff --git a/new_editor/app/Features/Project/ProjectPanel.cpp b/new_editor/app/Features/Project/ProjectPanel.cpp index be42100a..eb14ce13 100644 --- a/new_editor/app/Features/Project/ProjectPanel.cpp +++ b/new_editor/app/Features/Project/ProjectPanel.cpp @@ -384,18 +384,6 @@ ProjectPanel::CursorKind ProjectPanel::GetCursorKind() const { return (m_splitterHovered || m_splitterDragging) ? CursorKind::ResizeEW : CursorKind::Arrow; } -bool ProjectPanel::WantsHostPointerCapture() const { - return m_requestPointerCapture || - m_assetDragState.requestPointerCapture || - m_treeDragState.requestPointerCapture; -} - -bool ProjectPanel::WantsHostPointerRelease() const { - return m_requestPointerRelease || - m_assetDragState.requestPointerRelease || - m_treeDragState.requestPointerRelease; -} - bool ProjectPanel::HasActivePointerCapture() const { return m_splitterDragging || GridDrag::HasActivePointerCapture(m_assetDragState) || diff --git a/new_editor/app/Features/Project/ProjectPanel.h b/new_editor/app/Features/Project/ProjectPanel.h index 658a0fda..053a3d08 100644 --- a/new_editor/app/Features/Project/ProjectPanel.h +++ b/new_editor/app/Features/Project/ProjectPanel.h @@ -93,8 +93,6 @@ public: void Append(::XCEngine::UI::UIDrawList& drawList) const; CursorKind GetCursorKind() const; - bool WantsHostPointerCapture() const; - bool WantsHostPointerRelease() const; bool HasActivePointerCapture() const; const std::vector& GetFrameEvents() const; UIEditorHostCommandEvaluationResult EvaluateAssetCommand( diff --git a/new_editor/app/Platform/Win32/EditorWindow.cpp b/new_editor/app/Platform/Win32/EditorWindow.cpp index 18d68969..89098be6 100644 --- a/new_editor/app/Platform/Win32/EditorWindow.cpp +++ b/new_editor/app/Platform/Win32/EditorWindow.cpp @@ -13,7 +13,6 @@ #include #include #include -#include "Composition/EditorShellPointerInteraction.h" #include #include #include @@ -730,13 +729,12 @@ void EditorWindow::SyncShellCapturedPointerButtonsFromSystemState() { } void EditorWindow::ApplyShellRuntimePointerCapture() { - const EditorShellPointerOwner owner = m_runtime->GetShellRuntime().GetPointerOwner(); - if (IsShellPointerOwner(owner)) { + if (m_runtime->GetShellRuntime().HasShellInteractiveCapture()) { AcquirePointerCapture(EditorWindowPointerCaptureOwner::Shell); return; } - if (IsHostedContentPointerOwner(owner)) { + if (m_runtime->GetShellRuntime().HasHostedContentCapture()) { AcquirePointerCapture(EditorWindowPointerCaptureOwner::HostedContent); return; } diff --git a/new_editor/include/XCEditor/Shell/UIEditorShellCapturePolicy.h b/new_editor/include/XCEditor/Shell/UIEditorShellCapturePolicy.h index 14883c98..b9f72ba2 100644 --- a/new_editor/include/XCEditor/Shell/UIEditorShellCapturePolicy.h +++ b/new_editor/include/XCEditor/Shell/UIEditorShellCapturePolicy.h @@ -3,13 +3,27 @@ #include namespace XCEngine::UI { + +struct UIInputEvent; struct UIPoint; + } namespace XCEngine::UI::Editor { +bool HasActiveUIEditorShellInteractiveCapture( + const UIEditorShellInteractionState& shellInteractionState); + bool ShouldStartImmediateUIEditorShellPointerCapture( const UIEditorShellInteractionFrame& shellFrame, const ::XCEngine::UI::UIPoint& clientPoint); +bool ShouldYieldUIEditorHostedContentPointerStream( + const UIEditorShellInteractionFrame& shellFrame, + bool shellInteractiveCaptureActive); + +std::vector<::XCEngine::UI::UIInputEvent> FilterUIEditorHostedContentInputEvents( + const std::vector<::XCEngine::UI::UIInputEvent>& inputEvents, + bool shellOwnsPointerStream); + } // namespace XCEngine::UI::Editor diff --git a/new_editor/src/Shell/UIEditorShellCapturePolicy.cpp b/new_editor/src/Shell/UIEditorShellCapturePolicy.cpp index b542935a..b8440598 100644 --- a/new_editor/src/Shell/UIEditorShellCapturePolicy.cpp +++ b/new_editor/src/Shell/UIEditorShellCapturePolicy.cpp @@ -7,6 +7,8 @@ namespace XCEngine::UI::Editor { namespace { using Widgets::UIEditorDockHostHitTargetKind; +using ::XCEngine::UI::UIInputEvent; +using ::XCEngine::UI::UIInputEventType; bool ContainsPoint( const ::XCEngine::UI::UIRect& rect, @@ -17,8 +19,36 @@ bool ContainsPoint( point.y <= rect.y + rect.height; } +bool IsHostedContentPointerEvent(const UIInputEvent& event) { + return event.type == UIInputEventType::PointerMove || + event.type == UIInputEventType::PointerEnter || + event.type == UIInputEventType::PointerLeave || + event.type == UIInputEventType::PointerButtonDown || + event.type == UIInputEventType::PointerButtonUp || + event.type == UIInputEventType::PointerWheel; +} + } // namespace +bool HasActiveUIEditorShellInteractiveCapture( + const UIEditorShellInteractionState& shellInteractionState) { + const auto& dockHostInteractionState = + shellInteractionState.workspaceInteractionState.dockHostInteractionState; + if (dockHostInteractionState.splitterDragState.active || + !dockHostInteractionState.activeTabDragNodeId.empty()) { + return true; + } + + for (const UIEditorWorkspacePanelPresentationState& panelState : + shellInteractionState.workspaceInteractionState.composeState.panelStates) { + if (panelState.viewportShellState.inputBridgeState.captured) { + return true; + } + } + + return false; +} + bool ShouldStartImmediateUIEditorShellPointerCapture( const UIEditorShellInteractionFrame& shellFrame, const ::XCEngine::UI::UIPoint& clientPoint) { @@ -47,4 +77,50 @@ bool ShouldStartImmediateUIEditorShellPointerCapture( return false; } +bool ShouldYieldUIEditorHostedContentPointerStream( + const UIEditorShellInteractionFrame& shellFrame, + bool shellInteractiveCaptureActive) { + if (shellInteractiveCaptureActive || + shellFrame.result.requestPointerCapture || + shellFrame.result.releasePointerCapture) { + return true; + } + + return shellFrame.result.workspaceResult.dockHostResult.hitTarget.kind == + UIEditorDockHostHitTargetKind::SplitterHandle; +} + +std::vector FilterUIEditorHostedContentInputEvents( + const std::vector& inputEvents, + bool shellOwnsPointerStream) { + if (!shellOwnsPointerStream) { + return inputEvents; + } + + std::vector filteredEvents = {}; + filteredEvents.reserve(inputEvents.size() + 1u); + + bool strippedPointerInput = false; + UIInputEvent lastPointerEvent = {}; + for (const UIInputEvent& event : inputEvents) { + if (IsHostedContentPointerEvent(event)) { + strippedPointerInput = true; + lastPointerEvent = event; + continue; + } + + filteredEvents.push_back(event); + } + + if (strippedPointerInput) { + UIInputEvent leaveEvent = {}; + leaveEvent.type = UIInputEventType::PointerLeave; + leaveEvent.position = lastPointerEvent.position; + leaveEvent.modifiers = lastPointerEvent.modifiers; + filteredEvents.push_back(leaveEvent); + } + + return filteredEvents; +} + } // namespace XCEngine::UI::Editor