refactor(new_editor/app): split window manager and editor context hotspots

This commit is contained in:
2026-04-15 08:37:07 +08:00
parent ecb7f24794
commit f049d9d29e
8 changed files with 380 additions and 325 deletions

View File

@@ -1,8 +1,6 @@
#include "Platform/Win32/EditorWindow.h"
#include "Platform/Win32/EditorWindowConstants.h"
#include <algorithm>
#include <windowsx.h>
namespace XCEngine::UI::Editor::App {
@@ -132,93 +130,6 @@ bool EditorWindow::HandleBorderlessWindowChromeDoubleClick(
return true;
}
bool EditorWindow::HandleBorderlessWindowChromeDragRestorePointerMove(
EditorContext& editorContext,
bool globalTabDragActive) {
if (!m_chrome.runtime.IsBorderlessWindowDragRestoreArmed() || m_window.hwnd == nullptr) {
return false;
}
POINT currentScreenPoint = {};
if (!GetCursorPos(&currentScreenPoint)) {
return true;
}
const POINT initialScreenPoint =
m_chrome.runtime.GetBorderlessWindowDragRestoreInitialScreenPoint();
const int dragThresholdX = (std::max)(GetSystemMetrics(SM_CXDRAG), 1);
const int dragThresholdY = (std::max)(GetSystemMetrics(SM_CYDRAG), 1);
const LONG deltaX = currentScreenPoint.x - initialScreenPoint.x;
const LONG deltaY = currentScreenPoint.y - initialScreenPoint.y;
if (std::abs(deltaX) < dragThresholdX &&
std::abs(deltaY) < dragThresholdY) {
return true;
}
RECT restoreRect = {};
RECT currentRect = {};
RECT workAreaRect = {};
if (!m_chrome.runtime.TryGetBorderlessWindowRestoreRect(restoreRect) ||
!QueryCurrentWindowRect(currentRect) ||
!QueryBorderlessWindowWorkAreaRect(workAreaRect)) {
ClearBorderlessWindowChromeDragRestoreState();
return true;
}
const int restoreWidth = restoreRect.right - restoreRect.left;
const int restoreHeight = restoreRect.bottom - restoreRect.top;
const int currentWidth = currentRect.right - currentRect.left;
if (restoreWidth <= 0 || restoreHeight <= 0 || currentWidth <= 0) {
ClearBorderlessWindowChromeDragRestoreState();
return true;
}
const float pointerRatio =
static_cast<float>(currentScreenPoint.x - currentRect.left) /
static_cast<float>(currentWidth);
const float clampedPointerRatio = (std::clamp)(pointerRatio, 0.0f, 1.0f);
const int newLeft =
(std::clamp)(
currentScreenPoint.x -
static_cast<int>(clampedPointerRatio * static_cast<float>(restoreWidth)),
workAreaRect.left,
workAreaRect.right - restoreWidth);
const int titleBarHeightPixels =
static_cast<int>(kBorderlessTitleBarHeightDips * GetDpiScale());
const int newTop =
(std::clamp)(
currentScreenPoint.y - (std::max)(titleBarHeightPixels / 2, 1),
workAreaRect.top,
workAreaRect.bottom - restoreHeight);
const RECT targetRect = {
newLeft,
newTop,
newLeft + restoreWidth,
newTop + restoreHeight
};
m_chrome.runtime.SetBorderlessWindowMaximized(false);
ApplyPredictedWindowRectTransition(
editorContext,
globalTabDragActive,
targetRect);
ClearBorderlessWindowChromeDragRestoreState();
ReleaseCapture();
SendMessageW(m_window.hwnd, WM_NCLBUTTONDOWN, HTCAPTION, 0);
return true;
}
void EditorWindow::ClearBorderlessWindowChromeDragRestoreState() {
if (!m_chrome.runtime.IsBorderlessWindowDragRestoreArmed()) {
return;
}
m_chrome.runtime.EndBorderlessWindowDragRestore();
if (GetCapture() == m_window.hwnd) {
ReleaseCapture();
}
}
void EditorWindow::ClearBorderlessWindowChromeState() {
if (m_chrome.chromeState.hoveredTarget ==
Host::BorderlessWindowChromeHitTarget::None &&