diff --git a/new_editor/CMakeLists.txt b/new_editor/CMakeLists.txt index a6e614c0..3c76eebb 100644 --- a/new_editor/CMakeLists.txt +++ b/new_editor/CMakeLists.txt @@ -215,7 +215,7 @@ target_link_libraries(XCUIEditorHost PRIVATE if(XCENGINE_BUILD_XCUI_EDITOR_APP) set(XCUI_EDITOR_APP_BOOTSTRAP_SOURCES app/Bootstrap/EditorApp.rc - app/Bootstrap/main.cpp + app/main.cpp app/Bootstrap/ApplicationBootstrap.cpp app/Bootstrap/ApplicationLifecycle.cpp app/Bootstrap/ApplicationRunLoop.cpp @@ -287,6 +287,7 @@ if(XCENGINE_BUILD_XCUI_EDITOR_APP) app/Platform/Win32/EditorWindowManagerLifecycle.cpp app/Platform/Win32/EditorWindowManagerLookup.cpp app/Platform/Win32/EditorWindowManagerWindowSet.cpp + app/Platform/Win32/EditorWindowManagerWindowSynchronization.cpp app/Platform/Win32/EditorWindowManagerTabDrag.cpp app/Platform/Win32/EditorWindowManagerDetach.cpp app/Platform/Win32/EditorWindowManagerCrossWindowDrop.cpp @@ -329,16 +330,14 @@ if(XCENGINE_BUILD_XCUI_EDITOR_APP) add_test( NAME xcui_editor_app_smoke - COMMAND ${CMAKE_COMMAND} -E env - XCUIEDITOR_SMOKE_TEST=1 - XCUIEDITOR_SMOKE_TEST_FRAME_LIMIT=4 - XCUI_AUTO_CAPTURE_ON_STARTUP=0 - $ + COMMAND $ ) set_tests_properties(xcui_editor_app_smoke PROPERTIES TIMEOUT 20 RUN_SERIAL TRUE WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + ENVIRONMENT + "XCUIEDITOR_SMOKE_TEST=1;XCUIEDITOR_SMOKE_TEST_FRAME_LIMIT=4;XCUI_AUTO_CAPTURE_ON_STARTUP=0" ) endif() diff --git a/new_editor/app/Platform/Win32/EditorWindowManagerWindowSet.cpp b/new_editor/app/Platform/Win32/EditorWindowManagerWindowSet.cpp index adb2da26..57075cf7 100644 --- a/new_editor/app/Platform/Win32/EditorWindowManagerWindowSet.cpp +++ b/new_editor/app/Platform/Win32/EditorWindowManagerWindowSet.cpp @@ -3,8 +3,6 @@ #include "State/EditorContext.h" #include "EditorWindow.h" -#include - namespace XCEngine::UI::Editor::App { UIEditorWindowWorkspaceSet EditorWindowManager::BuildWindowWorkspaceSet( @@ -51,121 +49,4 @@ UIEditorWorkspaceController EditorWindowManager::BuildWorkspaceControllerForWind windowState.session); } -std::wstring EditorWindowManager::BuildWindowTitle( - const UIEditorWorkspaceController& workspaceController) const { - const std::string& activePanelId = workspaceController.GetWorkspace().activePanelId; - if (const UIEditorPanelDescriptor* descriptor = - FindUIEditorPanelDescriptor( - workspaceController.GetPanelRegistry(), - activePanelId); - descriptor != nullptr && - !descriptor->defaultTitle.empty()) { - const std::string titleText = descriptor->defaultTitle + " - XCEngine Editor"; - return std::wstring(titleText.begin(), titleText.end()); - } - - return std::wstring(L"XCEngine Editor"); -} - -RECT EditorWindowManager::BuildDetachedWindowRect(const POINT& screenPoint) const { - RECT rect = { - screenPoint.x - 420, - screenPoint.y - 24, - screenPoint.x - 420 + 960, - screenPoint.y - 24 + 720 - }; - - const HMONITOR monitor = MonitorFromPoint(screenPoint, MONITOR_DEFAULTTONEAREST); - MONITORINFO monitorInfo = {}; - monitorInfo.cbSize = sizeof(monitorInfo); - if (monitor != nullptr && GetMonitorInfoW(monitor, &monitorInfo)) { - const RECT& workArea = monitorInfo.rcWork; - const LONG width = rect.right - rect.left; - const LONG height = rect.bottom - rect.top; - rect.left = (std::max)(workArea.left, (std::min)(rect.left, workArea.right - width)); - rect.top = (std::max)(workArea.top, (std::min)(rect.top, workArea.bottom - height)); - rect.right = rect.left + width; - rect.bottom = rect.top + height; - } - - return rect; -} - -bool EditorWindowManager::SynchronizeWindowsFromWindowSet( - const UIEditorWindowWorkspaceSet& windowSet, - std::string_view preferredNewWindowId, - const POINT& preferredScreenPoint) { - std::vector windowIdsInSet = {}; - windowIdsInSet.reserve(windowSet.windows.size()); - - for (const UIEditorWindowWorkspaceState& entry : windowSet.windows) { - windowIdsInSet.push_back(entry.windowId); - if (EditorWindow* existingWindow = FindWindow(entry.windowId); - existingWindow != nullptr) { - existingWindow->ReplaceWorkspaceController(BuildWorkspaceControllerForWindow(entry)); - existingWindow->ResetInteractionState(); - if (!existingWindow->IsPrimary()) { - existingWindow->SetTitle( - BuildWindowTitle(existingWindow->GetWorkspaceController())); - if (existingWindow->GetHwnd() != nullptr) { - SetWindowTextW(existingWindow->GetHwnd(), existingWindow->GetTitle().c_str()); - } - } - continue; - } - - CreateParams createParams = {}; - createParams.windowId = entry.windowId; - createParams.primary = entry.windowId == windowSet.primaryWindowId; - createParams.title = - createParams.primary - ? std::wstring( - m_hostConfig.primaryWindowTitle != nullptr && - m_hostConfig.primaryWindowTitle[0] != L'\0' - ? m_hostConfig.primaryWindowTitle - : L"XCEngine Editor") - : BuildWindowTitle(BuildWorkspaceControllerForWindow(entry)); - if (entry.windowId == preferredNewWindowId) { - const RECT detachedRect = BuildDetachedWindowRect(preferredScreenPoint); - createParams.initialX = detachedRect.left; - createParams.initialY = detachedRect.top; - createParams.initialWidth = detachedRect.right - detachedRect.left; - createParams.initialHeight = detachedRect.bottom - detachedRect.top; - } - - if (CreateEditorWindow(BuildWorkspaceControllerForWindow(entry), createParams) == nullptr) { - return false; - } - } - - for (const std::unique_ptr& window : m_windows) { - if (window == nullptr || - window->GetHwnd() == nullptr || - window->IsPrimary()) { - continue; - } - - const bool existsInWindowSet = - std::find( - windowIdsInSet.begin(), - windowIdsInSet.end(), - window->GetWindowId()) != windowIdsInSet.end(); - if (!existsInWindowSet) { - PostMessageW(window->GetHwnd(), WM_CLOSE, 0, 0); - } - } - - return true; -} - -bool EditorWindowManager::SynchronizeWindowsFromController( - const UIEditorWindowWorkspaceController& windowWorkspaceController, - std::string_view preferredNewWindowId, - const POINT& preferredScreenPoint) { - return SynchronizeWindowsFromWindowSet( - windowWorkspaceController.GetWindowSet(), - preferredNewWindowId, - preferredScreenPoint); -} - } // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Platform/Win32/EditorWindowManagerWindowSynchronization.cpp b/new_editor/app/Platform/Win32/EditorWindowManagerWindowSynchronization.cpp new file mode 100644 index 00000000..1b07b833 --- /dev/null +++ b/new_editor/app/Platform/Win32/EditorWindowManagerWindowSynchronization.cpp @@ -0,0 +1,127 @@ +#include "EditorWindowManager.h" + +#include "State/EditorContext.h" +#include "EditorWindow.h" + +#include + +namespace XCEngine::UI::Editor::App { + +std::wstring EditorWindowManager::BuildWindowTitle( + const UIEditorWorkspaceController& workspaceController) const { + const std::string& activePanelId = workspaceController.GetWorkspace().activePanelId; + if (const UIEditorPanelDescriptor* descriptor = + FindUIEditorPanelDescriptor( + workspaceController.GetPanelRegistry(), + activePanelId); + descriptor != nullptr && + !descriptor->defaultTitle.empty()) { + const std::string titleText = descriptor->defaultTitle + " - XCEngine Editor"; + return std::wstring(titleText.begin(), titleText.end()); + } + + return std::wstring(L"XCEngine Editor"); +} + +RECT EditorWindowManager::BuildDetachedWindowRect(const POINT& screenPoint) const { + RECT rect = { + screenPoint.x - 420, + screenPoint.y - 24, + screenPoint.x - 420 + 960, + screenPoint.y - 24 + 720 + }; + + const HMONITOR monitor = MonitorFromPoint(screenPoint, MONITOR_DEFAULTTONEAREST); + MONITORINFO monitorInfo = {}; + monitorInfo.cbSize = sizeof(monitorInfo); + if (monitor != nullptr && GetMonitorInfoW(monitor, &monitorInfo)) { + const RECT& workArea = monitorInfo.rcWork; + const LONG width = rect.right - rect.left; + const LONG height = rect.bottom - rect.top; + rect.left = (std::max)(workArea.left, (std::min)(rect.left, workArea.right - width)); + rect.top = (std::max)(workArea.top, (std::min)(rect.top, workArea.bottom - height)); + rect.right = rect.left + width; + rect.bottom = rect.top + height; + } + + return rect; +} + +bool EditorWindowManager::SynchronizeWindowsFromWindowSet( + const UIEditorWindowWorkspaceSet& windowSet, + std::string_view preferredNewWindowId, + const POINT& preferredScreenPoint) { + std::vector windowIdsInSet = {}; + windowIdsInSet.reserve(windowSet.windows.size()); + + for (const UIEditorWindowWorkspaceState& entry : windowSet.windows) { + windowIdsInSet.push_back(entry.windowId); + if (EditorWindow* existingWindow = FindWindow(entry.windowId); + existingWindow != nullptr) { + existingWindow->ReplaceWorkspaceController(BuildWorkspaceControllerForWindow(entry)); + existingWindow->ResetInteractionState(); + if (!existingWindow->IsPrimary()) { + existingWindow->SetTitle( + BuildWindowTitle(existingWindow->GetWorkspaceController())); + if (existingWindow->GetHwnd() != nullptr) { + SetWindowTextW(existingWindow->GetHwnd(), existingWindow->GetTitle().c_str()); + } + } + continue; + } + + CreateParams createParams = {}; + createParams.windowId = entry.windowId; + createParams.primary = entry.windowId == windowSet.primaryWindowId; + createParams.title = + createParams.primary + ? std::wstring( + m_hostConfig.primaryWindowTitle != nullptr && + m_hostConfig.primaryWindowTitle[0] != L'\0' + ? m_hostConfig.primaryWindowTitle + : L"XCEngine Editor") + : BuildWindowTitle(BuildWorkspaceControllerForWindow(entry)); + if (entry.windowId == preferredNewWindowId) { + const RECT detachedRect = BuildDetachedWindowRect(preferredScreenPoint); + createParams.initialX = detachedRect.left; + createParams.initialY = detachedRect.top; + createParams.initialWidth = detachedRect.right - detachedRect.left; + createParams.initialHeight = detachedRect.bottom - detachedRect.top; + } + + if (CreateEditorWindow(BuildWorkspaceControllerForWindow(entry), createParams) == nullptr) { + return false; + } + } + + for (const std::unique_ptr& window : m_windows) { + if (window == nullptr || + window->GetHwnd() == nullptr || + window->IsPrimary()) { + continue; + } + + const bool existsInWindowSet = + std::find( + windowIdsInSet.begin(), + windowIdsInSet.end(), + window->GetWindowId()) != windowIdsInSet.end(); + if (!existsInWindowSet) { + PostMessageW(window->GetHwnd(), WM_CLOSE, 0, 0); + } + } + + return true; +} + +bool EditorWindowManager::SynchronizeWindowsFromController( + const UIEditorWindowWorkspaceController& windowWorkspaceController, + std::string_view preferredNewWindowId, + const POINT& preferredScreenPoint) { + return SynchronizeWindowsFromWindowSet( + windowWorkspaceController.GetWindowSet(), + preferredNewWindowId, + preferredScreenPoint); +} + +} // namespace XCEngine::UI::Editor::App diff --git a/new_editor/app/Bootstrap/main.cpp b/new_editor/app/main.cpp similarity index 100% rename from new_editor/app/Bootstrap/main.cpp rename to new_editor/app/main.cpp