Refactor editor windowing and update renderer regression

This commit is contained in:
2026-04-26 03:41:58 +08:00
parent 68993c46bb
commit 4fcaac81d6
39 changed files with 1181 additions and 872 deletions

View File

@@ -70,6 +70,20 @@ namespace XCEngine::UI::Editor::App {
using namespace EditorWindowSupport;
using ::XCEngine::UI::UIPoint;
POINT EditorWindow::ToNativePoint(const EditorWindowScreenPoint& screenPoint) {
return POINT{
static_cast<LONG>(screenPoint.x),
static_cast<LONG>(screenPoint.y),
};
}
EditorWindowScreenPoint EditorWindow::FromNativePoint(const POINT& screenPoint) {
EditorWindowScreenPoint point = {};
point.x = screenPoint.x;
point.y = screenPoint.y;
return point;
}
EditorWindow::EditorWindow(
std::string windowId,
std::wstring title,
@@ -135,6 +149,11 @@ bool EditorWindow::IsDestroyed() const {
return m_session->IsDestroyed();
}
bool EditorWindow::HasLiveHostWindow() const {
const HWND hwnd = m_session->GetHwnd();
return hwnd != nullptr && IsWindow(hwnd);
}
bool EditorWindow::IsRenderReady() const {
return m_runtime->IsReady();
}
@@ -204,6 +223,12 @@ void EditorWindow::SetTitle(std::wstring title) {
m_session->SetTitle(std::move(title));
}
void EditorWindow::ApplyHostWindowTitle() {
if (HasLiveHostWindow()) {
SetWindowTextW(m_session->GetHwnd(), GetTitle().c_str());
}
}
void EditorWindow::RefreshWorkspaceProjection(EditorWorkspaceWindowProjection projection) {
EditorWindowWorkspaceBinding* workspaceBinding = m_runtime->TryGetWorkspaceBinding();
assert(workspaceBinding != nullptr);
@@ -343,8 +368,9 @@ UIPoint EditorWindow::ConvertClientPixelsToDips(LONG x, LONG y) const {
PixelsToDips(static_cast<float>(y)));
}
UIPoint EditorWindow::ConvertScreenPixelsToClientDips(const POINT& screenPoint) const {
POINT clientPoint = screenPoint;
UIPoint EditorWindow::ConvertScreenPixelsToClientDips(
const EditorWindowScreenPoint& screenPoint) const {
POINT clientPoint = ToNativePoint(screenPoint);
if (const HWND hwnd = m_session->GetHwnd();
hwnd != nullptr) {
ScreenToClient(hwnd, &clientPoint);
@@ -363,8 +389,8 @@ UIPoint EditorWindow::ConvertScreenPixelsToClientDips(const POINT& screenPoint)
bool EditorWindow::TryResolveDockTabDragHotspot(
std::string_view nodeId,
std::string_view panelId,
const POINT& screenPoint,
POINT& outHotspot) const {
const EditorWindowScreenPoint& screenPoint,
EditorWindowScreenPoint& outHotspot) const {
const EditorWindowDockHostBinding* dockHostBinding = m_runtime->TryGetDockHostBinding();
if (dockHostBinding == nullptr) {
outHotspot = {};
@@ -383,13 +409,13 @@ bool EditorWindow::TryResolveDockTabDragHotspot(
}
const float dpiScale = GetDpiScale();
outHotspot.x = static_cast<LONG>(std::lround(hotspotDips.x * dpiScale));
outHotspot.y = static_cast<LONG>(std::lround(hotspotDips.y * dpiScale));
outHotspot.x = static_cast<std::int32_t>(std::lround(hotspotDips.x * dpiScale));
outHotspot.y = static_cast<std::int32_t>(std::lround(hotspotDips.y * dpiScale));
return true;
}
bool EditorWindow::TryResolveDockTabDropTarget(
const POINT& screenPoint,
const EditorWindowScreenPoint& screenPoint,
UIEditorDockHostTabDropTarget& outTarget) const {
const EditorWindowDockHostBinding* dockHostBinding = m_runtime->TryGetDockHostBinding();
if (dockHostBinding == nullptr) {
@@ -402,6 +428,57 @@ bool EditorWindow::TryResolveDockTabDropTarget(
return outTarget.valid;
}
bool EditorWindow::TryGetHostScreenRect(EditorWindowScreenRect& outRect) const {
outRect = {};
RECT nativeRect = {};
if (!HasLiveHostWindow() || !GetWindowRect(m_session->GetHwnd(), &nativeRect)) {
return false;
}
outRect.left = nativeRect.left;
outRect.top = nativeRect.top;
outRect.right = nativeRect.right;
outRect.bottom = nativeRect.bottom;
return true;
}
void EditorWindow::SetHostScreenPosition(const EditorWindowScreenPoint& screenPoint) {
if (!HasLiveHostWindow()) {
return;
}
SetWindowPos(
m_session->GetHwnd(),
nullptr,
screenPoint.x,
screenPoint.y,
0,
0,
SWP_NOSIZE | SWP_NOZORDER | SWP_NOACTIVATE);
}
void EditorWindow::FocusHostWindow() {
if (!HasLiveHostWindow()) {
return;
}
ShowWindow(m_session->GetHwnd(), SW_RESTORE);
SetForegroundWindow(m_session->GetHwnd());
}
void EditorWindow::PostCloseToHost() {
if (HasLiveHostWindow()) {
PostMessageW(m_session->GetHwnd(), WM_CLOSE, 0, 0);
}
}
void EditorWindow::DestroyHostWindow() {
if (HasLiveHostWindow()) {
DestroyWindow(m_session->GetHwnd());
}
}
bool EditorWindow::OnResize(UINT width, UINT height) {
const bool matchedPresentedPrediction =
m_chromeController->ConsumePresentedPredictedClientPixelSizeMatch(width, height);