Refactor new editor boundaries and test ownership
This commit is contained in:
@@ -1,16 +1,18 @@
|
||||
#include "Platform/Win32/EditorWindow.h"
|
||||
#include "Platform/Win32/EditorWindowConstants.h"
|
||||
#include "Platform/Win32/EditorWindowFrameOrchestrator.h"
|
||||
#include "Platform/Win32/EditorWindowInputController.h"
|
||||
#include "Platform/Win32/EditorWindowInternalState.h"
|
||||
#include "Platform/Win32/EditorWindowRuntimeController.h"
|
||||
#include "Platform/Win32/EditorWindowRuntimeInternal.h"
|
||||
#include "Platform/Win32/EditorWindowStyle.h"
|
||||
#include "Composition/EditorShellPointerInteraction.h"
|
||||
#include "State/EditorContext.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
#include "Composition/EditorContext.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <cstdint>
|
||||
#include <sstream>
|
||||
#include <utility>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
@@ -19,56 +21,12 @@ using namespace EditorWindowInternal;
|
||||
using ::XCEngine::UI::UIDrawData;
|
||||
using ::XCEngine::UI::UIDrawList;
|
||||
using ::XCEngine::UI::UIInputEvent;
|
||||
using ::XCEngine::UI::UIInputEventType;
|
||||
using ::XCEngine::UI::UIInputModifiers;
|
||||
using ::XCEngine::UI::UIPoint;
|
||||
using ::XCEngine::UI::UIPointerButton;
|
||||
using ::XCEngine::UI::UIRect;
|
||||
|
||||
namespace {
|
||||
|
||||
std::string DescribeInputEventType(const UIInputEvent& event) {
|
||||
switch (event.type) {
|
||||
case UIInputEventType::PointerMove: return "PointerMove";
|
||||
case UIInputEventType::PointerEnter: return "PointerEnter";
|
||||
case UIInputEventType::PointerLeave: return "PointerLeave";
|
||||
case UIInputEventType::PointerButtonDown: return "PointerDown";
|
||||
case UIInputEventType::PointerButtonUp: return "PointerUp";
|
||||
case UIInputEventType::PointerWheel: return "PointerWheel";
|
||||
case UIInputEventType::KeyDown: return "KeyDown";
|
||||
case UIInputEventType::KeyUp: return "KeyUp";
|
||||
case UIInputEventType::Character: return "Character";
|
||||
case UIInputEventType::FocusGained: return "FocusGained";
|
||||
case UIInputEventType::FocusLost: return "FocusLost";
|
||||
default: return "Unknown";
|
||||
}
|
||||
}
|
||||
|
||||
bool HasPendingPointerStateReconciliationEvent(
|
||||
const std::vector<UIInputEvent>& events) {
|
||||
for (const UIInputEvent& event : events) {
|
||||
switch (event.type) {
|
||||
case UIInputEventType::PointerMove:
|
||||
case UIInputEventType::PointerEnter:
|
||||
case UIInputEventType::PointerButtonDown:
|
||||
case UIInputEventType::PointerButtonUp:
|
||||
case UIInputEventType::PointerWheel:
|
||||
case UIInputEventType::FocusLost:
|
||||
return true;
|
||||
case UIInputEventType::PointerLeave:
|
||||
case UIInputEventType::KeyDown:
|
||||
case UIInputEventType::KeyUp:
|
||||
case UIInputEventType::Character:
|
||||
case UIInputEventType::FocusGained:
|
||||
case UIInputEventType::None:
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
std::uint8_t ButtonMask(UIPointerButton button) {
|
||||
switch (button) {
|
||||
case UIPointerButton::Left: return 1u << 0u;
|
||||
@@ -129,7 +87,7 @@ std::uint8_t ResolveExpectedShellCaptureButtons(
|
||||
EditorWindowFrameTransferRequests EditorWindow::RenderFrame(
|
||||
EditorContext& editorContext,
|
||||
bool globalTabDragActive) {
|
||||
if (!m_state->render.ready || m_state->window.hwnd == nullptr) {
|
||||
if (!m_runtime->IsReady() || m_state->window.hwnd == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -154,19 +112,17 @@ EditorWindowFrameTransferRequests EditorWindow::RenderFrame(
|
||||
transferRequests =
|
||||
RenderRuntimeFrame(editorContext, globalTabDragActive, workspaceBounds, drawList);
|
||||
} else {
|
||||
RenderInvalidFrame(editorContext, drawList);
|
||||
m_frameOrchestrator->AppendInvalidFrame(editorContext, drawList);
|
||||
}
|
||||
|
||||
AppendBorderlessWindowChrome(drawList, width);
|
||||
|
||||
const Host::D3D12WindowRenderLoopPresentResult presentResult =
|
||||
m_state->render.windowRenderLoop.Present(drawData);
|
||||
const Host::D3D12WindowRenderLoopPresentResult presentResult = m_runtime->Present(drawData);
|
||||
if (!presentResult.warning.empty()) {
|
||||
LogRuntimeTrace("present", presentResult.warning);
|
||||
}
|
||||
|
||||
m_state->render.autoScreenshot.CaptureIfRequested(
|
||||
m_state->render.renderer,
|
||||
m_runtime->CaptureIfRequested(
|
||||
drawData,
|
||||
pixelWidth,
|
||||
pixelHeight,
|
||||
@@ -177,7 +133,7 @@ EditorWindowFrameTransferRequests EditorWindow::RenderFrame(
|
||||
EditorWindowFrameTransferRequests EditorWindow::OnPaintMessage(
|
||||
EditorContext& editorContext,
|
||||
bool globalTabDragActive) {
|
||||
if (!m_state->render.ready || m_state->window.hwnd == nullptr) {
|
||||
if (!m_runtime->IsReady() || m_state->window.hwnd == nullptr) {
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -212,163 +168,36 @@ EditorWindowFrameTransferRequests EditorWindow::RenderRuntimeFrame(
|
||||
const UIRect& workspaceBounds,
|
||||
UIDrawList& drawList) {
|
||||
SyncShellCapturedPointerButtonsFromSystemState();
|
||||
std::vector<UIInputEvent> frameEvents = std::move(m_state->input.pendingEvents);
|
||||
m_state->input.pendingEvents.clear();
|
||||
if (!frameEvents.empty() && IsVerboseRuntimeTraceEnabled()) {
|
||||
LogRuntimeTrace(
|
||||
"input",
|
||||
DescribeInputEvents(frameEvents) + " | " +
|
||||
editorContext.DescribeWorkspaceState(
|
||||
GetWorkspaceController(),
|
||||
m_state->composition.shellRuntime.GetShellInteractionState()));
|
||||
}
|
||||
|
||||
const Host::D3D12WindowRenderLoopFrameContext frameContext =
|
||||
m_state->render.windowRenderLoop.BeginFrame();
|
||||
if (!frameContext.warning.empty()) {
|
||||
LogRuntimeTrace("viewport", frameContext.warning);
|
||||
}
|
||||
|
||||
editorContext.AttachTextMeasurer(m_state->render.renderer);
|
||||
std::vector<UIInputEvent> frameEvents = m_inputController->TakePendingEvents();
|
||||
const bool useDetachedTitleBarTabStrip = ShouldUseDetachedTitleBarTabStrip();
|
||||
UIEditorWorkspaceController& workspaceController = GetMutableWorkspaceController();
|
||||
m_state->composition.shellRuntime.Update(
|
||||
editorContext,
|
||||
workspaceController,
|
||||
const EditorWindowFrameTransferRequests transferRequests =
|
||||
m_frameOrchestrator->UpdateAndAppend(
|
||||
editorContext,
|
||||
*m_runtime,
|
||||
workspaceBounds,
|
||||
frameEvents,
|
||||
BuildCaptureStatusText(),
|
||||
m_state->window.primary
|
||||
? EditorShellVariant::Primary
|
||||
: EditorShellVariant::DetachedWindow,
|
||||
m_runtime->BuildCaptureStatusText(),
|
||||
m_state->window.primary,
|
||||
globalTabDragActive,
|
||||
useDetachedTitleBarTabStrip,
|
||||
useDetachedTitleBarTabStrip ? kBorderlessTitleBarHeightDips : 0.0f);
|
||||
const UIEditorShellInteractionFrame& shellFrame =
|
||||
m_state->composition.shellRuntime.GetShellFrame();
|
||||
const UIEditorDockHostInteractionState& dockHostInteractionState =
|
||||
m_state->composition.shellRuntime
|
||||
.GetShellInteractionState()
|
||||
.workspaceInteractionState
|
||||
.dockHostInteractionState;
|
||||
|
||||
LogFrameInteractionTrace(editorContext, frameEvents, shellFrame);
|
||||
const EditorWindowFrameTransferRequests transferRequests =
|
||||
BuildShellTransferRequests(globalTabDragActive, dockHostInteractionState, shellFrame);
|
||||
drawList);
|
||||
|
||||
ApplyShellRuntimePointerCapture();
|
||||
for (const WorkspaceTraceEntry& entry :
|
||||
m_state->composition.shellRuntime.GetTraceEntries()) {
|
||||
LogRuntimeTrace(entry.channel, entry.message);
|
||||
}
|
||||
ApplyCurrentCursor();
|
||||
m_state->composition.shellRuntime.Append(drawList);
|
||||
if (frameContext.canRenderViewports) {
|
||||
m_state->composition.shellRuntime.RenderRequestedViewports(frameContext.renderContext);
|
||||
}
|
||||
return transferRequests;
|
||||
}
|
||||
|
||||
void EditorWindow::RenderInvalidFrame(
|
||||
EditorContext& editorContext,
|
||||
UIDrawList& drawList) const {
|
||||
drawList.AddText(
|
||||
UIPoint(28.0f, 28.0f),
|
||||
"Editor shell asset invalid.",
|
||||
EditorWindowInternal::kShellTextColor,
|
||||
16.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(28.0f, 54.0f),
|
||||
editorContext.GetValidationMessage().empty()
|
||||
? std::string("Unknown validation error.")
|
||||
: editorContext.GetValidationMessage(),
|
||||
EditorWindowInternal::kShellMutedTextColor,
|
||||
12.0f);
|
||||
}
|
||||
|
||||
void EditorWindow::LogFrameInteractionTrace(
|
||||
EditorContext& editorContext,
|
||||
const std::vector<UIInputEvent>& frameEvents,
|
||||
const UIEditorShellInteractionFrame& shellFrame) const {
|
||||
if (!IsVerboseRuntimeTraceEnabled() ||
|
||||
(frameEvents.empty() &&
|
||||
!shellFrame.result.workspaceResult.dockHostResult.layoutChanged &&
|
||||
!shellFrame.result.workspaceResult.dockHostResult.commandExecuted)) {
|
||||
return;
|
||||
}
|
||||
|
||||
std::ostringstream frameTrace = {};
|
||||
frameTrace << "result consumed="
|
||||
<< (shellFrame.result.consumed ? "true" : "false")
|
||||
<< " layoutChanged="
|
||||
<< (shellFrame.result.workspaceResult.dockHostResult.layoutChanged ? "true" : "false")
|
||||
<< " commandExecuted="
|
||||
<< (shellFrame.result.workspaceResult.dockHostResult.commandExecuted ? "true" : "false")
|
||||
<< " active="
|
||||
<< GetWorkspaceController().GetWorkspace().activePanelId
|
||||
<< " message="
|
||||
<< shellFrame.result.workspaceResult.dockHostResult.layoutResult.message;
|
||||
LogRuntimeTrace("frame", frameTrace.str());
|
||||
}
|
||||
|
||||
EditorWindowFrameTransferRequests EditorWindow::BuildShellTransferRequests(
|
||||
bool globalTabDragActive,
|
||||
const UIEditorDockHostInteractionState& dockHostInteractionState,
|
||||
const UIEditorShellInteractionFrame& shellFrame) const {
|
||||
EditorWindowFrameTransferRequests transferRequests = {};
|
||||
POINT screenPoint = {};
|
||||
const bool hasScreenPoint = GetCursorPos(&screenPoint) != FALSE;
|
||||
|
||||
if (!globalTabDragActive &&
|
||||
!dockHostInteractionState.activeTabDragNodeId.empty() &&
|
||||
!dockHostInteractionState.activeTabDragPanelId.empty() &&
|
||||
hasScreenPoint) {
|
||||
transferRequests.beginGlobalTabDrag = EditorWindowPanelTransferRequest{
|
||||
dockHostInteractionState.activeTabDragNodeId,
|
||||
dockHostInteractionState.activeTabDragPanelId,
|
||||
screenPoint,
|
||||
};
|
||||
}
|
||||
|
||||
if (shellFrame.result.workspaceResult.dockHostResult.detachRequested &&
|
||||
hasScreenPoint) {
|
||||
transferRequests.detachPanel = EditorWindowPanelTransferRequest{
|
||||
shellFrame.result.workspaceResult.dockHostResult.detachedNodeId,
|
||||
shellFrame.result.workspaceResult.dockHostResult.detachedPanelId,
|
||||
screenPoint,
|
||||
};
|
||||
}
|
||||
|
||||
return transferRequests;
|
||||
}
|
||||
|
||||
std::string EditorWindow::BuildCaptureStatusText() const {
|
||||
if (m_state->render.autoScreenshot.HasPendingCapture()) {
|
||||
return "Shot pending...";
|
||||
}
|
||||
|
||||
if (!m_state->render.autoScreenshot.GetLastCaptureError().empty()) {
|
||||
return TruncateText(m_state->render.autoScreenshot.GetLastCaptureError(), 38u);
|
||||
}
|
||||
|
||||
if (!m_state->render.autoScreenshot.GetLastCaptureSummary().empty()) {
|
||||
return TruncateText(m_state->render.autoScreenshot.GetLastCaptureSummary(), 38u);
|
||||
}
|
||||
|
||||
return {};
|
||||
}
|
||||
|
||||
void EditorWindow::SyncShellCapturedPointerButtonsFromSystemState() {
|
||||
m_state->input.modifierTracker.SyncFromSystemState();
|
||||
m_inputController->SyncInputModifiersFromSystemState();
|
||||
|
||||
const std::uint8_t expectedButtons =
|
||||
ResolveExpectedShellCaptureButtons(m_state->composition.shellRuntime);
|
||||
const std::uint8_t expectedButtons = ResolveExpectedShellCaptureButtons(
|
||||
m_runtime->GetShellRuntime());
|
||||
if (expectedButtons == 0u ||
|
||||
HasPendingPointerStateReconciliationEvent(m_state->input.pendingEvents)) {
|
||||
m_inputController->HasPendingPointerStateReconciliationEvent()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const UIInputModifiers modifiers =
|
||||
m_state->input.modifierTracker.GetCurrentModifiers();
|
||||
const UIInputModifiers modifiers = m_inputController->GetCurrentModifiers();
|
||||
if ((ButtonMaskFromModifiers(modifiers) & expectedButtons) == expectedButtons) {
|
||||
return;
|
||||
}
|
||||
@@ -377,8 +206,7 @@ void EditorWindow::SyncShellCapturedPointerButtonsFromSystemState() {
|
||||
}
|
||||
|
||||
void EditorWindow::ApplyShellRuntimePointerCapture() {
|
||||
const EditorShellPointerOwner owner =
|
||||
m_state->composition.shellRuntime.GetPointerOwner();
|
||||
const EditorShellPointerOwner owner = m_runtime->GetShellRuntime().GetPointerOwner();
|
||||
if (IsShellPointerOwner(owner)) {
|
||||
AcquirePointerCapture(EditorWindowPointerCaptureOwner::Shell);
|
||||
return;
|
||||
@@ -398,24 +226,4 @@ void EditorWindow::ApplyShellRuntimePointerCapture() {
|
||||
}
|
||||
}
|
||||
|
||||
std::string EditorWindow::DescribeInputEvents(
|
||||
const std::vector<UIInputEvent>& events) const {
|
||||
std::ostringstream stream = {};
|
||||
stream << "events=[";
|
||||
for (std::size_t index = 0; index < events.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
stream << " | ";
|
||||
}
|
||||
|
||||
const UIInputEvent& event = events[index];
|
||||
stream << DescribeInputEventType(event)
|
||||
<< '@'
|
||||
<< static_cast<int>(event.position.x)
|
||||
<< ','
|
||||
<< static_cast<int>(event.position.y);
|
||||
}
|
||||
stream << ']';
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
|
||||
Reference in New Issue
Block a user