#pragma once #ifndef NOMINMAX #define NOMINMAX #endif #include "Host/AutoScreenshot.h" #include "Host/InputModifierTracker.h" #include "Host/NativeRenderer.h" #include "Core/EditorShellAsset.h" #include #include #include #include #include #include #include #include #include #include #include #include namespace XCEngine::UI::Editor { struct StructuredEditorShellBinding { ::XCEngine::UI::Runtime::UIScreenAsset screenAsset = {}; UIEditorWorkspaceController workspaceController = {}; UIEditorShellInteractionDefinition shellDefinition = {}; UIEditorShortcutManager shortcutManager = {}; EditorShellAssetValidationResult assetValidation = {}; [[nodiscard]] bool IsValid() const { return assetValidation.IsValid(); } }; inline UIEditorShortcutManager BuildStructuredEditorShortcutManager( const EditorShellAsset& asset) { (void)asset; return UIEditorShortcutManager(UIEditorCommandRegistry{}); } inline StructuredEditorShellBinding BuildStructuredEditorShellBinding( const EditorShellAsset& asset) { StructuredEditorShellBinding binding = {}; binding.screenAsset.screenId = asset.screenId; binding.screenAsset.documentPath = asset.documentPath.string(); binding.screenAsset.themePath = asset.themePath.string(); binding.workspaceController = UIEditorWorkspaceController(asset.panelRegistry, asset.workspace, asset.workspaceSession); binding.shellDefinition = asset.shellDefinition; binding.shortcutManager = BuildStructuredEditorShortcutManager(asset); binding.assetValidation = ValidateEditorShellAsset(asset); return binding; } inline UIEditorShellInteractionServices BuildStructuredEditorShellServices( const StructuredEditorShellBinding& binding) { UIEditorShellInteractionServices services = {}; services.commandDispatcher = &binding.shortcutManager.GetCommandDispatcher(); services.shortcutManager = &binding.shortcutManager; return services; } class Application { public: Application(); int Run(HINSTANCE hInstance, int nCmdShow); private: struct TrackedFileState { std::filesystem::path path = {}; std::filesystem::file_time_type writeTime = {}; bool exists = false; }; static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam); bool Initialize(HINSTANCE hInstance, int nCmdShow); void Shutdown(); void RenderFrame(); void OnResize(UINT width, UINT height); 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 LoadStructuredScreen(const char* triggerReason); void RefreshStructuredScreen(); void RebuildTrackedFileStates(); bool DetectTrackedFileChange() const; void AppendRuntimeOverlay(::XCEngine::UI::UIDrawData& drawData, float width, float height) const; static std::filesystem::path ResolveRepoRootPath(); HWND m_hwnd = nullptr; HINSTANCE m_hInstance = nullptr; ATOM m_windowClassAtom = 0; ::XCEngine::UI::Editor::Host::NativeRenderer m_renderer; ::XCEngine::UI::Editor::Host::AutoScreenshotController m_autoScreenshot; ::XCEngine::UI::Runtime::UIDocumentScreenHost m_documentHost; ::XCEngine::UI::Runtime::UIScreenPlayer m_screenPlayer; ::XCEngine::UI::Runtime::UIScreenAsset m_screenAsset = {}; EditorShellAsset m_shellAssetDefinition = {}; StructuredEditorShellBinding m_structuredShell = {}; UIEditorShellInteractionServices m_shellServices = {}; std::vector m_trackedFiles = {}; std::chrono::steady_clock::time_point m_startTime = {}; std::chrono::steady_clock::time_point m_lastFrameTime = {}; std::chrono::steady_clock::time_point m_lastReloadPollTime = {}; std::uint64_t m_frameIndex = 0; std::vector<::XCEngine::UI::UIInputEvent> m_pendingInputEvents = {}; ::XCEngine::UI::Editor::Host::InputModifierTracker m_inputModifierTracker = {}; bool m_trackingMouseLeave = false; bool m_useStructuredScreen = false; std::string m_runtimeStatus = {}; std::string m_runtimeError = {}; }; int RunXCUIEditorApp(HINSTANCE hInstance, int nCmdShow); } // namespace XCEngine::UI::Editor