Refactor new editor boundaries and test ownership
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include "Platform/Win32/WindowManager/Internal.h"
|
||||
#include "Platform/Win32/WindowManager/TabDragDropTarget.h"
|
||||
|
||||
#include "State/EditorContext.h"
|
||||
#include "Composition/EditorContext.h"
|
||||
#include "Platform/Win32/EditorWindow.h"
|
||||
|
||||
#include <XCEditor/Docking/UIEditorDockHost.h>
|
||||
@@ -21,13 +22,6 @@ using ::XCEngine::UI::UIRect;
|
||||
constexpr LONG kFallbackDragHotspotX = 40;
|
||||
constexpr LONG kFallbackDragHotspotY = 12;
|
||||
|
||||
struct CrossWindowDockDropTarget {
|
||||
bool valid = false;
|
||||
std::string nodeId = {};
|
||||
UIEditorWorkspaceDockPlacement placement = UIEditorWorkspaceDockPlacement::Center;
|
||||
std::size_t insertionIndex = Widgets::UIEditorTabStripInvalidIndex;
|
||||
};
|
||||
|
||||
POINT BuildFallbackGlobalTabDragHotspot() {
|
||||
POINT hotspot = {};
|
||||
hotspot.x = kFallbackDragHotspotX;
|
||||
@@ -44,13 +38,6 @@ float ResolveWindowDpiScale(HWND hwnd) {
|
||||
return dpi == 0u ? 1.0f : static_cast<float>(dpi) / 96.0f;
|
||||
}
|
||||
|
||||
bool IsPointInsideRect(const UIRect& rect, const UIPoint& point) {
|
||||
return point.x >= rect.x &&
|
||||
point.x <= rect.x + rect.width &&
|
||||
point.y >= rect.y &&
|
||||
point.y <= rect.y + rect.height;
|
||||
}
|
||||
|
||||
bool CanStartGlobalTabDragFromWindow(
|
||||
const EditorWindow& sourceWindow,
|
||||
std::string_view sourceNodeId,
|
||||
@@ -74,100 +61,6 @@ bool IsLiveInteractiveWindow(const EditorWindow* window) {
|
||||
!window->IsClosing();
|
||||
}
|
||||
|
||||
std::size_t ResolveDropInsertionIndex(
|
||||
const Widgets::UIEditorDockHostTabStackLayout& tabStack,
|
||||
const UIPoint& point) {
|
||||
if (!IsPointInsideRect(tabStack.tabStripLayout.headerRect, point)) {
|
||||
return Widgets::UIEditorTabStripInvalidIndex;
|
||||
}
|
||||
|
||||
std::size_t insertionIndex = 0u;
|
||||
for (const UIRect& rect : tabStack.tabStripLayout.tabHeaderRects) {
|
||||
const float midpoint = rect.x + rect.width * 0.5f;
|
||||
if (point.x > midpoint) {
|
||||
++insertionIndex;
|
||||
}
|
||||
}
|
||||
return insertionIndex;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceDockPlacement ResolveDropPlacement(
|
||||
const Widgets::UIEditorDockHostTabStackLayout& tabStack,
|
||||
const UIPoint& point) {
|
||||
if (IsPointInsideRect(tabStack.tabStripLayout.headerRect, point)) {
|
||||
return UIEditorWorkspaceDockPlacement::Center;
|
||||
}
|
||||
|
||||
const float leftDistance = point.x - tabStack.bounds.x;
|
||||
const float rightDistance = tabStack.bounds.x + tabStack.bounds.width - point.x;
|
||||
const float topDistance = point.y - tabStack.bounds.y;
|
||||
const float bottomDistance = tabStack.bounds.y + tabStack.bounds.height - point.y;
|
||||
const float minHorizontalThreshold = tabStack.bounds.width * 0.25f;
|
||||
const float minVerticalThreshold = tabStack.bounds.height * 0.25f;
|
||||
const float nearestEdge = (std::min)(
|
||||
(std::min)(leftDistance, rightDistance),
|
||||
(std::min)(topDistance, bottomDistance));
|
||||
|
||||
if (nearestEdge == leftDistance && leftDistance <= minHorizontalThreshold) {
|
||||
return UIEditorWorkspaceDockPlacement::Left;
|
||||
}
|
||||
if (nearestEdge == rightDistance && rightDistance <= minHorizontalThreshold) {
|
||||
return UIEditorWorkspaceDockPlacement::Right;
|
||||
}
|
||||
if (nearestEdge == topDistance && topDistance <= minVerticalThreshold) {
|
||||
return UIEditorWorkspaceDockPlacement::Top;
|
||||
}
|
||||
if (nearestEdge == bottomDistance && bottomDistance <= minVerticalThreshold) {
|
||||
return UIEditorWorkspaceDockPlacement::Bottom;
|
||||
}
|
||||
|
||||
return UIEditorWorkspaceDockPlacement::Center;
|
||||
}
|
||||
|
||||
bool TryResolveCrossWindowDockDropTarget(
|
||||
const Widgets::UIEditorDockHostLayout& layout,
|
||||
const UIPoint& point,
|
||||
CrossWindowDockDropTarget& outTarget) {
|
||||
outTarget = {};
|
||||
if (!IsPointInsideRect(layout.bounds, point)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
const Widgets::UIEditorDockHostHitTarget hitTarget =
|
||||
Widgets::HitTestUIEditorDockHost(layout, point);
|
||||
for (const Widgets::UIEditorDockHostTabStackLayout& tabStack : layout.tabStacks) {
|
||||
if ((!hitTarget.nodeId.empty() && tabStack.nodeId != hitTarget.nodeId) ||
|
||||
!IsPointInsideRect(tabStack.bounds, point)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
outTarget.valid = true;
|
||||
outTarget.nodeId = tabStack.nodeId;
|
||||
outTarget.placement = ResolveDropPlacement(tabStack, point);
|
||||
if (outTarget.placement == UIEditorWorkspaceDockPlacement::Center) {
|
||||
outTarget.insertionIndex = ResolveDropInsertionIndex(tabStack, point);
|
||||
if (outTarget.insertionIndex == Widgets::UIEditorTabStripInvalidIndex) {
|
||||
outTarget.insertionIndex = tabStack.items.size();
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const Widgets::UIEditorDockHostTabStackLayout& tabStack : layout.tabStacks) {
|
||||
if (IsPointInsideRect(tabStack.bounds, point)) {
|
||||
outTarget.valid = true;
|
||||
outTarget.nodeId = tabStack.nodeId;
|
||||
outTarget.placement = ResolveDropPlacement(tabStack, point);
|
||||
if (outTarget.placement == UIEditorWorkspaceDockPlacement::Center) {
|
||||
outTarget.insertionIndex = tabStack.items.size();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
} // namespace
|
||||
|
||||
bool EditorWindowWorkspaceCoordinator::IsGlobalTabDragActive() const {
|
||||
@@ -303,9 +196,9 @@ void EditorWindowWorkspaceCoordinator::UpdateGlobalTabDragDropPreview() {
|
||||
targetWindow->ConvertScreenPixelsToClientDips(m_globalTabDragSession.screenPoint);
|
||||
const Widgets::UIEditorDockHostLayout& targetLayout =
|
||||
targetWindow->GetShellFrame().workspaceInteractionFrame.dockHostFrame.layout;
|
||||
CrossWindowDockDropTarget dropTarget = {};
|
||||
if (!TryResolveCrossWindowDockDropTarget(targetLayout, targetPoint, dropTarget) ||
|
||||
!dropTarget.valid) {
|
||||
const EditorWindowTabDragDropTarget dropTarget =
|
||||
ResolveEditorWindowTabDragDropTarget(targetLayout, targetPoint);
|
||||
if (!dropTarget.valid) {
|
||||
ClearGlobalTabDragDropPreview();
|
||||
return;
|
||||
}
|
||||
@@ -399,8 +292,9 @@ bool EditorWindowWorkspaceCoordinator::HandleGlobalTabDragPointerButtonUp(HWND h
|
||||
targetWindow->ConvertScreenPixelsToClientDips(screenPoint);
|
||||
const Widgets::UIEditorDockHostLayout& targetLayout =
|
||||
targetWindow->GetShellFrame().workspaceInteractionFrame.dockHostFrame.layout;
|
||||
CrossWindowDockDropTarget dropTarget = {};
|
||||
if (!TryResolveCrossWindowDockDropTarget(targetLayout, targetPoint, dropTarget)) {
|
||||
const EditorWindowTabDragDropTarget dropTarget =
|
||||
ResolveEditorWindowTabDragDropTarget(targetLayout, targetPoint);
|
||||
if (!dropTarget.valid) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user