refactor(new_editor/app): split window manager and editor context hotspots
This commit is contained in:
107
new_editor/app/Platform/Win32/EditorWindowManagerCreation.cpp
Normal file
107
new_editor/app/Platform/Win32/EditorWindowManagerCreation.cpp
Normal file
@@ -0,0 +1,107 @@
|
||||
#include "EditorWindowManager.h"
|
||||
|
||||
#include "State/EditorContext.h"
|
||||
#include "Bootstrap/EditorResources.h"
|
||||
#include "EditorWindow.h"
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace XCEngine::UI::Editor::App {
|
||||
|
||||
EditorWindow* EditorWindowManager::CreateEditorWindow(
|
||||
UIEditorWorkspaceController workspaceController,
|
||||
const CreateParams& params) {
|
||||
auto windowPtr = std::make_unique<EditorWindow>(
|
||||
params.windowId,
|
||||
params.title.empty() ? std::wstring(L"XCEngine Editor") : params.title,
|
||||
params.primary,
|
||||
std::move(workspaceController));
|
||||
EditorWindow* const rawWindow = windowPtr.get();
|
||||
m_windows.push_back(std::move(windowPtr));
|
||||
|
||||
const auto eraseRawWindow = [this, rawWindow]() {
|
||||
const auto it = std::find_if(
|
||||
m_windows.begin(),
|
||||
m_windows.end(),
|
||||
[rawWindow](const std::unique_ptr<EditorWindow>& candidate) {
|
||||
return candidate.get() == rawWindow;
|
||||
});
|
||||
if (it != m_windows.end()) {
|
||||
m_windows.erase(it);
|
||||
}
|
||||
};
|
||||
|
||||
m_pendingCreateWindow = rawWindow;
|
||||
const HWND hwnd = CreateWindowExW(
|
||||
WS_EX_APPWINDOW,
|
||||
m_hostConfig.windowClassName,
|
||||
rawWindow->GetTitle().c_str(),
|
||||
m_hostConfig.windowStyle,
|
||||
params.initialX,
|
||||
params.initialY,
|
||||
params.initialWidth,
|
||||
params.initialHeight,
|
||||
nullptr,
|
||||
nullptr,
|
||||
m_hostConfig.hInstance,
|
||||
m_hostConfig.windowUserData);
|
||||
m_pendingCreateWindow = nullptr;
|
||||
if (hwnd == nullptr) {
|
||||
eraseRawWindow();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (!rawWindow->HasHwnd()) {
|
||||
rawWindow->AttachHwnd(hwnd);
|
||||
}
|
||||
|
||||
auto failWindowInitialization = [&](std::string_view message) {
|
||||
LogRuntimeTrace("window", std::string(message));
|
||||
DestroyEditorWindow(*rawWindow);
|
||||
eraseRawWindow();
|
||||
return static_cast<EditorWindow*>(nullptr);
|
||||
};
|
||||
|
||||
const HICON bigIcon = static_cast<HICON>(
|
||||
LoadImageW(
|
||||
m_hostConfig.hInstance,
|
||||
MAKEINTRESOURCEW(IDI_APP_ICON),
|
||||
IMAGE_ICON,
|
||||
0,
|
||||
0,
|
||||
LR_DEFAULTSIZE));
|
||||
const HICON smallIcon = static_cast<HICON>(
|
||||
LoadImageW(
|
||||
m_hostConfig.hInstance,
|
||||
MAKEINTRESOURCEW(IDI_APP_ICON_SMALL),
|
||||
IMAGE_ICON,
|
||||
GetSystemMetrics(SM_CXSMICON),
|
||||
GetSystemMetrics(SM_CYSMICON),
|
||||
LR_DEFAULTCOLOR));
|
||||
if (bigIcon != nullptr) {
|
||||
SendMessageW(hwnd, WM_SETICON, ICON_BIG, reinterpret_cast<LPARAM>(bigIcon));
|
||||
}
|
||||
if (smallIcon != nullptr) {
|
||||
SendMessageW(hwnd, WM_SETICON, ICON_SMALL, reinterpret_cast<LPARAM>(smallIcon));
|
||||
}
|
||||
|
||||
if (!rawWindow->Initialize(
|
||||
m_repoRoot,
|
||||
m_editorContext,
|
||||
m_editorContext.GetShellAsset().captureRootPath,
|
||||
params.autoCaptureOnStartup)) {
|
||||
return failWindowInitialization("managed window initialization failed");
|
||||
}
|
||||
|
||||
ShowWindow(hwnd, params.showCommand);
|
||||
UpdateWindow(hwnd);
|
||||
return rawWindow;
|
||||
}
|
||||
|
||||
void EditorWindowManager::HandlePendingNativeWindowCreated(HWND hwnd) {
|
||||
if (m_pendingCreateWindow != nullptr && !m_pendingCreateWindow->HasHwnd()) {
|
||||
m_pendingCreateWindow->AttachHwnd(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
} // namespace XCEngine::UI::Editor::App
|
||||
Reference in New Issue
Block a user