Files
XCEngine/new_editor/app/Application.h

128 lines
5.2 KiB
C++

#pragma once
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <Host/AutoScreenshot.h>
#include <Host/BorderlessWindowChrome.h>
#include <Host/BorderlessWindowFrame.h>
#include <Host/D3D12WindowRenderer.h>
#include <Host/D3D12WindowRenderLoop.h>
#include <Host/HostRuntimeState.h>
#include <Host/InputModifierTracker.h>
#include <Host/NativeRenderer.h>
#include "Core/ProductEditorContext.h"
#include "Workspace/ProductEditorWorkspace.h"
#include <XCEditor/Shell/UIEditorShellInteraction.h>
#include <windows.h>
#include <windowsx.h>
#include <cstdint>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
namespace XCEngine::UI::Editor::Host {
class WindowMessageDispatcher;
}
namespace XCEngine::UI::Editor {
class Application {
public:
Application() = default;
int Run(HINSTANCE hInstance, int nCmdShow);
private:
friend class ::XCEngine::UI::Editor::Host::WindowMessageDispatcher;
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam);
bool Initialize(HINSTANCE hInstance, int nCmdShow);
void Shutdown();
void RenderFrame();
void OnPaintMessage();
void OnResize(UINT width, UINT height);
void OnEnterSizeMove();
void OnExitSizeMove();
void OnDpiChanged(UINT dpi, const RECT& suggestedRect);
bool ApplyWindowResize(UINT width, UINT height);
bool QueryCurrentClientPixelSize(UINT& outWidth, UINT& outHeight) const;
bool ResolveRenderClientPixelSize(UINT& outWidth, UINT& outHeight) const;
bool IsPointerInsideClientArea() const;
bool ApplyCurrentCursor() const;
LPCWSTR ResolveCurrentCursorResource() const;
float GetDpiScale() const;
float PixelsToDips(float pixels) const;
::XCEngine::UI::UIPoint ConvertClientPixelsToDips(LONG x, LONG y) const;
std::string BuildCaptureStatusText() const;
void LogRuntimeTrace(std::string_view channel, std::string_view message) const;
void ApplyHostCaptureRequests(const UIEditorShellInteractionResult& result);
void ApplyHostedContentCaptureRequests();
bool HasInteractiveCaptureState() const;
std::string DescribeInputEvents(
const std::vector<::XCEngine::UI::UIInputEvent>& events) const;
void QueuePointerEvent(
::XCEngine::UI::UIInputEventType type,
::XCEngine::UI::UIPointerButton button,
WPARAM wParam,
LPARAM lParam);
void QueuePointerLeaveEvent();
void QueuePointerWheelEvent(short wheelDelta, WPARAM wParam, LPARAM lParam);
void QueueKeyEvent(::XCEngine::UI::UIInputEventType type, WPARAM wParam, LPARAM lParam);
void QueueCharacterEvent(WPARAM wParam, LPARAM lParam);
void QueueWindowFocusEvent(::XCEngine::UI::UIInputEventType type);
bool IsBorderlessWindowEnabled() const;
LRESULT HandleBorderlessWindowNcCalcSize(WPARAM wParam, LPARAM lParam) const;
Host::BorderlessWindowChromeHitTarget HitTestBorderlessWindowChrome(LPARAM lParam) const;
bool UpdateBorderlessWindowChromeHover(LPARAM lParam);
bool HandleBorderlessWindowChromeButtonDown(LPARAM lParam);
bool HandleBorderlessWindowChromeButtonUp(LPARAM lParam);
bool HandleBorderlessWindowChromeDoubleClick(LPARAM lParam);
void ClearBorderlessWindowChromeState();
Host::BorderlessWindowResizeEdge HitTestBorderlessWindowResizeEdge(LPARAM lParam) const;
bool UpdateBorderlessWindowResizeHover(LPARAM lParam);
bool HandleBorderlessWindowResizeButtonDown(LPARAM lParam);
bool HandleBorderlessWindowResizeButtonUp();
bool HandleBorderlessWindowResizePointerMove();
void ClearBorderlessWindowResizeState();
void ForceClearBorderlessWindowResizeState();
void ApplyBorderlessWindowResizeCursorHoverPriority();
void AppendBorderlessWindowChrome(
::XCEngine::UI::UIDrawList& drawList,
float clientWidthDips) const;
void ExecuteBorderlessWindowChromeAction(Host::BorderlessWindowChromeHitTarget target);
Host::BorderlessWindowChromeLayout ResolveBorderlessWindowChromeLayout(
float clientWidthDips) const;
void InvalidateHostWindow() const;
static std::filesystem::path ResolveRepoRootPath();
static LONG WINAPI HandleUnhandledException(EXCEPTION_POINTERS* exceptionInfo);
static bool IsVerboseRuntimeTraceEnabled();
HWND m_hwnd = nullptr;
HINSTANCE m_hInstance = nullptr;
ATOM m_windowClassAtom = 0;
::XCEngine::UI::Editor::Host::NativeRenderer m_renderer = {};
::XCEngine::UI::Editor::Host::D3D12WindowRenderer m_windowRenderer = {};
::XCEngine::UI::Editor::Host::D3D12WindowRenderLoop m_windowRenderLoop = {};
::XCEngine::UI::Editor::Host::AutoScreenshotController m_autoScreenshot = {};
::XCEngine::UI::Editor::Host::InputModifierTracker m_inputModifierTracker = {};
App::ProductEditorContext m_editorContext = {};
App::ProductEditorWorkspace m_editorWorkspace = {};
std::vector<::XCEngine::UI::UIInputEvent> m_pendingInputEvents = {};
bool m_trackingMouseLeave = false;
bool m_renderReady = false;
::XCEngine::UI::Editor::Host::BorderlessWindowChromeState m_borderlessWindowChromeState = {};
::XCEngine::UI::Editor::Host::HostRuntimeState m_hostRuntime = {};
};
int RunXCUIEditorApp(HINSTANCE hInstance, int nCmdShow);
} // namespace XCEngine::UI::Editor