refactor(new_editor): tighten app dependency boundaries

This commit is contained in:
2026-04-19 02:48:41 +08:00
parent 7429f22fb1
commit c59cd83c38
86 changed files with 1754 additions and 1077 deletions

View File

@@ -1,4 +1,5 @@
#include "Platform/Win32/EditorWindow.h"
#include "Platform/Win32/EditorWindowInternalState.h"
#include <XCEngine/Input/InputTypes.h>
#include <XCEngine/UI/Types.h>
@@ -128,59 +129,59 @@ bool EditorWindow::ApplyCurrentCursor() const {
bool EditorWindow::HasInteractiveCaptureState() const {
return m_composition.shellRuntime.HasInteractiveCapture() ||
m_chrome.runtime.IsBorderlessWindowDragRestoreArmed() ||
m_chrome.runtime.IsBorderlessResizeActive() ||
m_input.pointerCaptureOwner != EditorWindowPointerCaptureOwner::None;
return m_state->composition.shellRuntime.HasInteractiveCapture() ||
m_state->chrome.runtime.IsBorderlessWindowDragRestoreArmed() ||
m_state->chrome.runtime.IsBorderlessResizeActive() ||
m_state->input.pointerCaptureOwner != EditorWindowPointerCaptureOwner::None;
}
EditorWindowPointerCaptureOwner EditorWindow::GetPointerCaptureOwner() const {
return m_input.pointerCaptureOwner;
return m_state->input.pointerCaptureOwner;
}
bool EditorWindow::OwnsPointerCapture(EditorWindowPointerCaptureOwner owner) const {
return m_input.pointerCaptureOwner == owner;
return m_state->input.pointerCaptureOwner == owner;
}
void EditorWindow::AcquirePointerCapture(EditorWindowPointerCaptureOwner owner) {
if (owner == EditorWindowPointerCaptureOwner::None ||
m_window.hwnd == nullptr ||
!IsWindow(m_window.hwnd)) {
m_state->window.hwnd == nullptr ||
!IsWindow(m_state->window.hwnd)) {
return;
}
m_input.pointerCaptureOwner = owner;
if (GetCapture() != m_window.hwnd) {
SetCapture(m_window.hwnd);
m_state->input.pointerCaptureOwner = owner;
if (GetCapture() != m_state->window.hwnd) {
SetCapture(m_state->window.hwnd);
}
}
void EditorWindow::ReleasePointerCapture(EditorWindowPointerCaptureOwner owner) {
if (m_input.pointerCaptureOwner != owner) {
if (m_state->input.pointerCaptureOwner != owner) {
return;
}
m_input.pointerCaptureOwner = EditorWindowPointerCaptureOwner::None;
if (m_window.hwnd != nullptr && GetCapture() == m_window.hwnd) {
m_state->input.pointerCaptureOwner = EditorWindowPointerCaptureOwner::None;
if (m_state->window.hwnd != nullptr && GetCapture() == m_state->window.hwnd) {
ReleaseCapture();
}
}
void EditorWindow::ForceReleasePointerCapture() {
m_input.pointerCaptureOwner = EditorWindowPointerCaptureOwner::None;
if (m_window.hwnd != nullptr && GetCapture() == m_window.hwnd) {
m_state->input.pointerCaptureOwner = EditorWindowPointerCaptureOwner::None;
if (m_state->window.hwnd != nullptr && GetCapture() == m_state->window.hwnd) {
ReleaseCapture();
}
}
void EditorWindow::ClearPointerCaptureOwner() {
m_input.pointerCaptureOwner = EditorWindowPointerCaptureOwner::None;
m_state->input.pointerCaptureOwner = EditorWindowPointerCaptureOwner::None;
}
void EditorWindow::TryStartImmediateShellPointerCapture(LPARAM lParam) {
if (m_window.hwnd == nullptr ||
!IsWindow(m_window.hwnd) ||
GetCapture() == m_window.hwnd) {
if (m_state->window.hwnd == nullptr ||
!IsWindow(m_state->window.hwnd) ||
GetCapture() == m_state->window.hwnd) {
return;
}
@@ -188,7 +189,7 @@ void EditorWindow::TryStartImmediateShellPointerCapture(LPARAM lParam) {
GET_X_LPARAM(lParam),
GET_Y_LPARAM(lParam));
if (!ShouldStartImmediateUIEditorShellPointerCapture(
m_composition.shellRuntime.GetShellFrame(),
m_state->composition.shellRuntime.GetShellFrame(),
clientPoint)) {
return;
}
@@ -207,16 +208,16 @@ void EditorWindow::QueuePointerEvent(
event.position = ConvertClientPixelsToDips(
GET_X_LPARAM(lParam),
GET_Y_LPARAM(lParam));
event.modifiers = m_input.modifierTracker.ApplyPointerMessage(
event.modifiers = m_state->input.modifierTracker.ApplyPointerMessage(
type,
button,
static_cast<std::size_t>(wParam));
m_input.pendingEvents.push_back(event);
m_state->input.pendingEvents.push_back(event);
}
void EditorWindow::QueueSyntheticPointerStateSyncEvent(
const ::XCEngine::UI::UIInputModifiers& modifiers) {
if (m_window.hwnd == nullptr || !IsWindow(m_window.hwnd)) {
if (m_state->window.hwnd == nullptr || !IsWindow(m_state->window.hwnd)) {
return;
}
@@ -224,7 +225,7 @@ void EditorWindow::QueueSyntheticPointerStateSyncEvent(
if (!GetCursorPos(&screenPoint)) {
return;
}
if (!ScreenToClient(m_window.hwnd, &screenPoint)) {
if (!ScreenToClient(m_state->window.hwnd, &screenPoint)) {
return;
}
@@ -232,24 +233,24 @@ void EditorWindow::QueueSyntheticPointerStateSyncEvent(
event.type = UIInputEventType::PointerMove;
event.position = ConvertClientPixelsToDips(screenPoint.x, screenPoint.y);
event.modifiers = modifiers;
m_input.pendingEvents.push_back(event);
m_state->input.pendingEvents.push_back(event);
}
void EditorWindow::QueuePointerLeaveEvent() {
UIInputEvent event = {};
event.type = UIInputEventType::PointerLeave;
if (m_window.hwnd != nullptr) {
if (m_state->window.hwnd != nullptr) {
POINT clientPoint = {};
GetCursorPos(&clientPoint);
ScreenToClient(m_window.hwnd, &clientPoint);
ScreenToClient(m_state->window.hwnd, &clientPoint);
event.position = ConvertClientPixelsToDips(clientPoint.x, clientPoint.y);
}
event.modifiers = m_input.modifierTracker.GetCurrentModifiers();
m_input.pendingEvents.push_back(event);
event.modifiers = m_state->input.modifierTracker.GetCurrentModifiers();
m_state->input.pendingEvents.push_back(event);
}
void EditorWindow::QueuePointerWheelEvent(short wheelDelta, WPARAM wParam, LPARAM lParam) {
if (m_window.hwnd == nullptr) {
if (m_state->window.hwnd == nullptr) {
return;
}
@@ -257,56 +258,56 @@ void EditorWindow::QueuePointerWheelEvent(short wheelDelta, WPARAM wParam, LPARA
GET_X_LPARAM(lParam),
GET_Y_LPARAM(lParam)
};
ScreenToClient(m_window.hwnd, &screenPoint);
ScreenToClient(m_state->window.hwnd, &screenPoint);
UIInputEvent event = {};
event.type = UIInputEventType::PointerWheel;
event.position = ConvertClientPixelsToDips(screenPoint.x, screenPoint.y);
event.wheelDelta = static_cast<float>(wheelDelta);
event.modifiers = m_input.modifierTracker.ApplyPointerMessage(
event.modifiers = m_state->input.modifierTracker.ApplyPointerMessage(
UIInputEventType::PointerWheel,
UIPointerButton::None,
static_cast<std::size_t>(wParam));
m_input.pendingEvents.push_back(event);
m_state->input.pendingEvents.push_back(event);
}
void EditorWindow::QueueKeyEvent(UIInputEventType type, WPARAM wParam, LPARAM lParam) {
UIInputEvent event = {};
event.type = type;
event.keyCode = MapVirtualKeyToUIKeyCode(wParam);
event.modifiers = m_input.modifierTracker.ApplyKeyMessage(type, wParam, lParam);
event.modifiers = m_state->input.modifierTracker.ApplyKeyMessage(type, wParam, lParam);
event.repeat = IsRepeatKeyMessage(lParam);
m_input.pendingEvents.push_back(event);
m_state->input.pendingEvents.push_back(event);
}
void EditorWindow::QueueCharacterEvent(WPARAM wParam, LPARAM) {
UIInputEvent event = {};
event.type = UIInputEventType::Character;
event.character = static_cast<std::uint32_t>(wParam);
event.modifiers = m_input.modifierTracker.GetCurrentModifiers();
m_input.pendingEvents.push_back(event);
event.modifiers = m_state->input.modifierTracker.GetCurrentModifiers();
m_state->input.pendingEvents.push_back(event);
}
void EditorWindow::QueueWindowFocusEvent(UIInputEventType type) {
UIInputEvent event = {};
event.type = type;
m_input.pendingEvents.push_back(event);
m_state->input.pendingEvents.push_back(event);
}
void EditorWindow::SyncInputModifiersFromSystemState() {
m_input.modifierTracker.SyncFromSystemState();
m_state->input.modifierTracker.SyncFromSystemState();
}
void EditorWindow::ResetInputModifiers() {
m_input.modifierTracker.Reset();
m_state->input.modifierTracker.Reset();
}
void EditorWindow::RequestManualScreenshot() {
m_render.autoScreenshot.RequestCapture("manual_f12");
m_state->render.autoScreenshot.RequestCapture("manual_f12");
}
bool EditorWindow::IsPointerInsideClientArea() const {
if (m_window.hwnd == nullptr || !IsWindow(m_window.hwnd)) {
if (m_state->window.hwnd == nullptr || !IsWindow(m_state->window.hwnd)) {
return false;
}
@@ -315,26 +316,26 @@ bool EditorWindow::IsPointerInsideClientArea() const {
return false;
}
if (!IsScreenPointOverWindow(m_window.hwnd, screenPoint)) {
if (!IsScreenPointOverWindow(m_state->window.hwnd, screenPoint)) {
return false;
}
const LPARAM pointParam = MAKELPARAM(
static_cast<SHORT>(screenPoint.x),
static_cast<SHORT>(screenPoint.y));
return SendMessageW(m_window.hwnd, WM_NCHITTEST, 0, pointParam) == HTCLIENT;
return SendMessageW(m_state->window.hwnd, WM_NCHITTEST, 0, pointParam) == HTCLIENT;
}
LPCWSTR EditorWindow::ResolveCurrentCursorResource() const {
const Host::BorderlessWindowResizeEdge borderlessResizeEdge =
m_chrome.runtime.IsBorderlessResizeActive()
? m_chrome.runtime.GetBorderlessResizeEdge()
: m_chrome.runtime.GetHoveredBorderlessResizeEdge();
m_state->chrome.runtime.IsBorderlessResizeActive()
? m_state->chrome.runtime.GetBorderlessResizeEdge()
: m_state->chrome.runtime.GetHoveredBorderlessResizeEdge();
if (borderlessResizeEdge != Host::BorderlessWindowResizeEdge::None) {
return Host::ResolveBorderlessWindowResizeCursor(borderlessResizeEdge);
}
switch (m_composition.shellRuntime.GetHostedContentCursorKind()) {
switch (m_state->composition.shellRuntime.GetHostedContentCursorKind()) {
case ProjectPanel::CursorKind::ResizeEW:
return IDC_SIZEWE;
case ProjectPanel::CursorKind::Arrow:
@@ -342,7 +343,7 @@ LPCWSTR EditorWindow::ResolveCurrentCursorResource() const {
break;
}
switch (m_composition.shellRuntime.GetDockCursorKind()) {
switch (m_state->composition.shellRuntime.GetDockCursorKind()) {
case Widgets::UIEditorDockHostCursorKind::ResizeEW:
return IDC_SIZEWE;
case Widgets::UIEditorDockHostCursorKind::ResizeNS: