Files
XCEngine/new_editor/app/Platform/Win32/EditorWindowInitialization.cpp

129 lines
4.5 KiB
C++
Raw Normal View History

#include "Platform/Win32/EditorWindow.h"
#include "Bootstrap/EditorResources.h"
#include "Platform/Win32/EditorWindowPlatformSupport.h"
#include "Platform/Win32/EditorWindowRuntimeSupport.h"
#include <algorithm>
#include <sstream>
namespace XCEngine::UI::Editor::App {
using namespace EditorWindowSupport;
bool EditorWindow::Initialize(
const std::filesystem::path& repoRoot,
EditorContext& editorContext,
const std::filesystem::path& captureRoot,
bool autoCaptureOnStartup) {
if (m_window.hwnd == nullptr) {
LogRuntimeTrace("app", "window initialize skipped: hwnd is null");
return false;
}
Host::RefreshBorderlessWindowDwmDecorations(m_window.hwnd);
m_chrome.runtime.Reset();
m_chrome.runtime.SetWindowDpi(QueryWindowDpi(m_window.hwnd));
m_render.renderer.SetDpiScale(GetDpiScale());
std::ostringstream dpiTrace = {};
dpiTrace << "initial dpi=" << m_chrome.runtime.GetWindowDpi()
<< " scale=" << GetDpiScale();
LogRuntimeTrace("window", dpiTrace.str());
if (!m_render.renderer.Initialize(m_window.hwnd)) {
LogRuntimeTrace("app", "renderer initialization failed");
return false;
}
RECT clientRect = {};
GetClientRect(m_window.hwnd, &clientRect);
const int clientWidth = (std::max)(clientRect.right - clientRect.left, 1L);
const int clientHeight = (std::max)(clientRect.bottom - clientRect.top, 1L);
if (!m_render.windowRenderer.Initialize(m_window.hwnd, clientWidth, clientHeight)) {
LogRuntimeTrace("app", "d3d12 window renderer initialization failed");
m_render.renderer.Shutdown();
return false;
}
const Host::D3D12WindowRenderLoopAttachResult attachResult =
m_render.windowRenderLoop.Attach(m_render.renderer, m_render.windowRenderer);
if (!attachResult.interopWarning.empty()) {
LogRuntimeTrace("app", attachResult.interopWarning);
}
editorContext.AttachTextMeasurer(m_render.renderer);
m_composition.shellRuntime.Initialize(repoRoot, m_render.renderer);
m_composition.shellRuntime.AttachViewportWindowRenderer(m_render.windowRenderer);
m_composition.shellRuntime.SetViewportSurfacePresentationEnabled(
attachResult.hasViewportSurfacePresentation);
std::string titleBarLogoError = {};
if (!LoadEmbeddedPngTexture(
m_render.renderer,
IDR_PNG_LOGO_ICON,
m_render.titleBarLogoIcon,
titleBarLogoError)) {
LogRuntimeTrace("icons", "titlebar logo_icon.png: " + titleBarLogoError);
}
if (!m_composition.shellRuntime.GetBuiltInIconError().empty()) {
LogRuntimeTrace("icons", m_composition.shellRuntime.GetBuiltInIconError());
}
LogRuntimeTrace(
"app",
"shell runtime initialized: " +
editorContext.DescribeWorkspaceState(
m_composition.workspaceController,
m_composition.shellRuntime.GetShellInteractionState()));
m_render.ready = true;
m_render.autoScreenshot.Initialize(captureRoot);
if (autoCaptureOnStartup && IsAutoCaptureOnStartupEnabled()) {
m_render.autoScreenshot.RequestCapture("startup");
editorContext.SetStatus("Capture", "Startup capture requested.");
}
return true;
}
void EditorWindow::Shutdown() {
if (GetCapture() == m_window.hwnd) {
ReleaseCapture();
}
m_render.ready = false;
m_render.autoScreenshot.Shutdown();
m_composition.shellRuntime.Shutdown();
m_render.renderer.ReleaseTexture(m_render.titleBarLogoIcon);
m_render.windowRenderLoop.Detach();
m_render.windowRenderer.Shutdown();
m_render.renderer.Shutdown();
m_input.pendingEvents.clear();
m_chrome.chromeState = {};
m_chrome.runtime.Reset();
m_pendingDetachRequest = {};
m_pendingTabDragStart = {};
}
void EditorWindow::ResetInteractionState() {
if (GetCapture() == m_window.hwnd) {
ReleaseCapture();
}
m_input.pendingEvents.clear();
m_input.trackingMouseLeave = false;
m_input.modifierTracker.Reset();
m_composition.shellRuntime.ResetInteractionState();
m_chrome.chromeState = {};
m_chrome.runtime.EndBorderlessResize();
m_chrome.runtime.EndBorderlessWindowDragRestore();
m_chrome.runtime.EndInteractiveResize();
m_chrome.runtime.SetHoveredBorderlessResizeEdge(Host::BorderlessWindowResizeEdge::None);
m_chrome.runtime.ClearPredictedClientPixelSize();
m_pendingDetachRequest = {};
m_pendingTabDragStart = {};
}
} // namespace XCEngine::UI::Editor::App