Add new editor product shell baseline
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
#include "Application.h"
|
||||
|
||||
#include "Shell/ProductShellAsset.h"
|
||||
|
||||
#include <XCEditor/Foundation/UIEditorTheme.h>
|
||||
|
||||
#include <XCEngine/Input/InputTypes.h>
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <chrono>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <cctype>
|
||||
#include <cstdlib>
|
||||
#include <string>
|
||||
#include <system_error>
|
||||
#include <unordered_set>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCUIEDITOR_REPO_ROOT
|
||||
#define XCUIEDITOR_REPO_ROOT "."
|
||||
@@ -19,6 +20,7 @@ namespace XCEngine::UI::Editor {
|
||||
|
||||
namespace {
|
||||
|
||||
using ::XCEngine::Input::KeyCode;
|
||||
using ::XCEngine::UI::UIColor;
|
||||
using ::XCEngine::UI::UIDrawData;
|
||||
using ::XCEngine::UI::UIDrawList;
|
||||
@@ -27,19 +29,11 @@ using ::XCEngine::UI::UIInputEventType;
|
||||
using ::XCEngine::UI::UIPoint;
|
||||
using ::XCEngine::UI::UIPointerButton;
|
||||
using ::XCEngine::UI::UIRect;
|
||||
using ::XCEngine::UI::Runtime::UIScreenFrameInput;
|
||||
using ::XCEngine::Input::KeyCode;
|
||||
using App::BuildProductShellAsset;
|
||||
using App::BuildProductShellInteractionDefinition;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorShellHost";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor";
|
||||
constexpr auto kReloadPollInterval = std::chrono::milliseconds(150);
|
||||
|
||||
constexpr UIColor kOverlayBgColor(0.10f, 0.10f, 0.10f, 0.95f);
|
||||
constexpr UIColor kOverlayBorderColor(0.25f, 0.25f, 0.25f, 1.0f);
|
||||
constexpr UIColor kOverlayTextPrimary(0.93f, 0.93f, 0.93f, 1.0f);
|
||||
constexpr UIColor kOverlayTextMuted(0.70f, 0.70f, 0.70f, 1.0f);
|
||||
constexpr UIColor kOverlaySuccess(0.82f, 0.82f, 0.82f, 1.0f);
|
||||
constexpr UIColor kOverlayFallback(0.56f, 0.56f, 0.56f, 1.0f);
|
||||
constexpr const wchar_t* kWindowClassName = L"XCEditorShellHost";
|
||||
constexpr const wchar_t* kWindowTitle = L"Main Scene * - Main.xx - XCEngine Editor";
|
||||
|
||||
Application* GetApplicationFromWindow(HWND hwnd) {
|
||||
return reinterpret_cast<Application*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
@@ -51,46 +45,30 @@ std::string TruncateText(const std::string& text, std::size_t maxLength) {
|
||||
}
|
||||
|
||||
if (maxLength <= 3u) {
|
||||
return text.substr(0, maxLength);
|
||||
return text.substr(0u, maxLength);
|
||||
}
|
||||
|
||||
return text.substr(0, maxLength - 3u) + "...";
|
||||
return text.substr(0u, maxLength - 3u) + "...";
|
||||
}
|
||||
|
||||
std::string ExtractStateKeyTail(const std::string& stateKey) {
|
||||
if (stateKey.empty()) {
|
||||
return "-";
|
||||
bool IsAutoCaptureOnStartupEnabled() {
|
||||
const char* value = std::getenv("XCUI_AUTO_CAPTURE_ON_STARTUP");
|
||||
if (value == nullptr || value[0] == '\0') {
|
||||
return false;
|
||||
}
|
||||
|
||||
const std::size_t separator = stateKey.find_last_of('/');
|
||||
if (separator == std::string::npos || separator + 1u >= stateKey.size()) {
|
||||
return stateKey;
|
||||
}
|
||||
|
||||
return stateKey.substr(separator + 1u);
|
||||
}
|
||||
|
||||
std::string FormatFloat(float value) {
|
||||
std::ostringstream stream;
|
||||
stream.setf(std::ios::fixed, std::ios::floatfield);
|
||||
stream.precision(1);
|
||||
stream << value;
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string FormatPoint(const UIPoint& point) {
|
||||
return "(" + FormatFloat(point.x) + ", " + FormatFloat(point.y) + ")";
|
||||
}
|
||||
|
||||
void AppendErrorMessage(std::string& target, const std::string& message) {
|
||||
if (message.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!target.empty()) {
|
||||
target += " | ";
|
||||
}
|
||||
target += message;
|
||||
std::string normalized = value;
|
||||
std::transform(
|
||||
normalized.begin(),
|
||||
normalized.end(),
|
||||
normalized.begin(),
|
||||
[](unsigned char character) {
|
||||
return static_cast<char>(std::tolower(character));
|
||||
});
|
||||
return normalized != "0" &&
|
||||
normalized != "false" &&
|
||||
normalized != "off" &&
|
||||
normalized != "no";
|
||||
}
|
||||
|
||||
std::int32_t MapVirtualKeyToUIKeyCode(WPARAM wParam) {
|
||||
@@ -170,10 +148,6 @@ bool IsRepeatKeyMessage(LPARAM lParam) {
|
||||
|
||||
} // namespace
|
||||
|
||||
Application::Application()
|
||||
: m_screenPlayer(m_documentHost) {
|
||||
}
|
||||
|
||||
int Application::Run(HINSTANCE hInstance, int nCmdShow) {
|
||||
if (!Initialize(hInstance, nCmdShow)) {
|
||||
Shutdown();
|
||||
@@ -198,10 +172,24 @@ int Application::Run(HINSTANCE hInstance, int nCmdShow) {
|
||||
|
||||
bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_hInstance = hInstance;
|
||||
m_shellAssetDefinition = BuildDefaultEditorShellAsset(ResolveRepoRootPath());
|
||||
m_structuredShell = BuildStructuredEditorShellBinding(m_shellAssetDefinition);
|
||||
m_shellServices = BuildStructuredEditorShellServices(m_structuredShell);
|
||||
m_screenAsset = m_structuredShell.screenAsset;
|
||||
m_shellAsset = BuildProductShellAsset(ResolveRepoRootPath());
|
||||
m_shellValidation = ValidateEditorShellAsset(m_shellAsset);
|
||||
m_validationMessage = m_shellValidation.message;
|
||||
if (!m_shellValidation.IsValid()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_workspaceController = UIEditorWorkspaceController(
|
||||
m_shellAsset.panelRegistry,
|
||||
m_shellAsset.workspace,
|
||||
m_shellAsset.workspaceSession);
|
||||
m_shortcutManager = BuildEditorShellShortcutManager(m_shellAsset);
|
||||
m_shortcutManager.SetHostCommandHandler(this);
|
||||
m_shellServices = {};
|
||||
m_shellServices.commandDispatcher = &m_shortcutManager.GetCommandDispatcher();
|
||||
m_shellServices.shortcutManager = &m_shortcutManager;
|
||||
m_lastStatus = "Ready";
|
||||
m_lastMessage = "Old editor shell baseline loaded.";
|
||||
|
||||
WNDCLASSEXW windowClass = {};
|
||||
windowClass.cbSize = sizeof(windowClass);
|
||||
@@ -210,7 +198,6 @@ bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
windowClass.hInstance = hInstance;
|
||||
windowClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
|
||||
windowClass.lpszClassName = kWindowClassName;
|
||||
|
||||
m_windowClassAtom = RegisterClassExW(&windowClass);
|
||||
if (m_windowClassAtom == 0) {
|
||||
return false;
|
||||
@@ -223,8 +210,8 @@ bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
|
||||
CW_USEDEFAULT,
|
||||
CW_USEDEFAULT,
|
||||
1440,
|
||||
900,
|
||||
1540,
|
||||
940,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
@@ -240,23 +227,21 @@ bool Application::Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
return false;
|
||||
}
|
||||
|
||||
m_startTime = std::chrono::steady_clock::now();
|
||||
m_lastFrameTime = m_startTime;
|
||||
m_autoScreenshot.Initialize(m_shellAssetDefinition.captureRootPath);
|
||||
LoadStructuredScreen("startup");
|
||||
m_autoScreenshot.Initialize(m_shellAsset.captureRootPath);
|
||||
if (IsAutoCaptureOnStartupEnabled()) {
|
||||
m_autoScreenshot.RequestCapture("startup");
|
||||
m_lastStatus = "Capture";
|
||||
m_lastMessage = "Startup capture requested.";
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void Application::Shutdown() {
|
||||
m_autoScreenshot.Shutdown();
|
||||
m_screenPlayer.Unload();
|
||||
m_trackedFiles.clear();
|
||||
m_screenAsset = {};
|
||||
m_useStructuredScreen = false;
|
||||
m_runtimeStatus.clear();
|
||||
m_runtimeError.clear();
|
||||
m_frameIndex = 0;
|
||||
if (GetCapture() == m_hwnd) {
|
||||
ReleaseCapture();
|
||||
}
|
||||
|
||||
m_autoScreenshot.Shutdown();
|
||||
m_renderer.Shutdown();
|
||||
|
||||
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
|
||||
@@ -280,47 +265,48 @@ void Application::RenderFrame() {
|
||||
const float width = static_cast<float>((std::max)(clientRect.right - clientRect.left, 1L));
|
||||
const float height = static_cast<float>((std::max)(clientRect.bottom - clientRect.top, 1L));
|
||||
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
double deltaTimeSeconds = std::chrono::duration<double>(now - m_lastFrameTime).count();
|
||||
if (deltaTimeSeconds <= 0.0) {
|
||||
deltaTimeSeconds = 1.0 / 60.0;
|
||||
}
|
||||
m_lastFrameTime = now;
|
||||
|
||||
RefreshStructuredScreen();
|
||||
std::vector<UIInputEvent> frameEvents = std::move(m_pendingInputEvents);
|
||||
m_pendingInputEvents.clear();
|
||||
|
||||
UIDrawData drawData = {};
|
||||
const bool hasAuthoredScreenDocument = !m_screenAsset.documentPath.empty();
|
||||
if (hasAuthoredScreenDocument && m_useStructuredScreen && m_screenPlayer.IsLoaded()) {
|
||||
UIScreenFrameInput input = {};
|
||||
input.viewportRect = UIRect(0.0f, 0.0f, width, height);
|
||||
input.events = std::move(frameEvents);
|
||||
input.deltaTimeSeconds = deltaTimeSeconds;
|
||||
input.frameIndex = ++m_frameIndex;
|
||||
input.focused = GetForegroundWindow() == m_hwnd;
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("XCEditorShell");
|
||||
drawList.AddFilledRect(
|
||||
UIRect(0.0f, 0.0f, width, height),
|
||||
UIColor(0.10f, 0.10f, 0.10f, 1.0f));
|
||||
|
||||
const auto& frame = m_screenPlayer.Update(input);
|
||||
for (const auto& drawList : frame.drawData.GetDrawLists()) {
|
||||
drawData.AddDrawList(drawList);
|
||||
}
|
||||
if (m_shellValidation.IsValid()) {
|
||||
const auto& metrics = ResolveUIEditorShellInteractionMetrics();
|
||||
const auto& palette = ResolveUIEditorShellInteractionPalette();
|
||||
const UIEditorShellInteractionDefinition definition = BuildShellDefinition();
|
||||
std::vector<UIInputEvent> frameEvents = std::move(m_pendingInputEvents);
|
||||
m_pendingInputEvents.clear();
|
||||
|
||||
m_runtimeStatus = "XCUI Editor Shell";
|
||||
m_runtimeError = frame.errorMessage;
|
||||
} else if (!hasAuthoredScreenDocument) {
|
||||
++m_frameIndex;
|
||||
m_runtimeStatus = "XCUI Editor Shell | Code-driven";
|
||||
m_runtimeError.clear();
|
||||
m_shellFrame = UpdateUIEditorShellInteraction(
|
||||
m_shellInteractionState,
|
||||
m_workspaceController,
|
||||
UIRect(0.0f, 0.0f, width, height),
|
||||
definition,
|
||||
frameEvents,
|
||||
m_shellServices,
|
||||
metrics);
|
||||
ApplyHostCaptureRequests(m_shellFrame.result);
|
||||
UpdateLastStatus(m_shellFrame.result);
|
||||
AppendUIEditorShellInteraction(
|
||||
drawList,
|
||||
m_shellFrame,
|
||||
m_shellInteractionState,
|
||||
palette,
|
||||
metrics);
|
||||
} else {
|
||||
m_runtimeStatus = "Editor Shell | Load Error";
|
||||
if (m_runtimeError.empty() && !m_screenPlayer.IsLoaded()) {
|
||||
m_runtimeError = m_screenPlayer.GetLastError();
|
||||
}
|
||||
drawList.AddText(
|
||||
UIPoint(28.0f, 28.0f),
|
||||
"Editor shell asset invalid.",
|
||||
UIColor(0.92f, 0.92f, 0.92f, 1.0f),
|
||||
16.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(28.0f, 54.0f),
|
||||
m_validationMessage.empty() ? std::string("Unknown validation error.") : m_validationMessage,
|
||||
UIColor(0.72f, 0.72f, 0.72f, 1.0f),
|
||||
12.0f);
|
||||
}
|
||||
|
||||
AppendRuntimeOverlay(drawData, width, height);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
@@ -338,7 +324,113 @@ void Application::OnResize(UINT width, UINT height) {
|
||||
m_renderer.Resize(width, height);
|
||||
}
|
||||
|
||||
void Application::QueuePointerEvent(UIInputEventType type, UIPointerButton button, WPARAM wParam, LPARAM lParam) {
|
||||
void Application::ApplyHostCaptureRequests(const UIEditorShellInteractionResult& result) {
|
||||
if (result.requestPointerCapture && GetCapture() != m_hwnd) {
|
||||
SetCapture(m_hwnd);
|
||||
}
|
||||
if (result.releasePointerCapture && GetCapture() == m_hwnd) {
|
||||
ReleaseCapture();
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::HasInteractiveCaptureState() const {
|
||||
if (m_shellInteractionState.workspaceInteractionState.dockHostInteractionState.splitterDragState.active) {
|
||||
return true;
|
||||
}
|
||||
|
||||
for (const auto& panelState : m_shellInteractionState.workspaceInteractionState.composeState.panelStates) {
|
||||
if (panelState.viewportShellState.inputBridgeState.captured) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
UIEditorShellInteractionDefinition Application::BuildShellDefinition() const {
|
||||
std::string statusText = m_lastStatus;
|
||||
if (!m_lastMessage.empty()) {
|
||||
statusText += statusText.empty() ? m_lastMessage : ": " + m_lastMessage;
|
||||
}
|
||||
|
||||
std::string captureText = {};
|
||||
if (m_autoScreenshot.HasPendingCapture()) {
|
||||
captureText = "Shot pending...";
|
||||
} else if (!m_autoScreenshot.GetLastCaptureError().empty()) {
|
||||
captureText = TruncateText(m_autoScreenshot.GetLastCaptureError(), 38u);
|
||||
} else if (!m_autoScreenshot.GetLastCaptureSummary().empty()) {
|
||||
captureText = TruncateText(m_autoScreenshot.GetLastCaptureSummary(), 38u);
|
||||
}
|
||||
|
||||
return BuildProductShellInteractionDefinition(
|
||||
m_shellAsset,
|
||||
m_workspaceController,
|
||||
statusText,
|
||||
captureText);
|
||||
}
|
||||
|
||||
void Application::UpdateLastStatus(const UIEditorShellInteractionResult& result) {
|
||||
if (result.commandDispatched) {
|
||||
m_lastStatus = std::string(GetUIEditorCommandDispatchStatusName(result.commandDispatchResult.status));
|
||||
m_lastMessage = result.commandDispatchResult.message.empty()
|
||||
? result.commandDispatchResult.displayName
|
||||
: result.commandDispatchResult.message;
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.workspaceResult.dockHostResult.layoutChanged) {
|
||||
m_lastStatus = "Layout";
|
||||
m_lastMessage = result.workspaceResult.dockHostResult.layoutResult.message;
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.workspaceResult.dockHostResult.commandExecuted) {
|
||||
m_lastStatus = "Workspace";
|
||||
m_lastMessage = result.workspaceResult.dockHostResult.commandResult.message;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!result.viewportPanelId.empty()) {
|
||||
m_lastStatus = result.viewportPanelId;
|
||||
if (result.viewportInputFrame.captureStarted) {
|
||||
m_lastMessage = "Viewport capture started.";
|
||||
} else if (result.viewportInputFrame.captureEnded) {
|
||||
m_lastMessage = "Viewport capture ended.";
|
||||
} else if (result.viewportInputFrame.focusGained) {
|
||||
m_lastMessage = "Viewport focused.";
|
||||
} else if (result.viewportInputFrame.focusLost) {
|
||||
m_lastMessage = "Viewport focus lost.";
|
||||
} else if (result.viewportInputFrame.pointerPressedInside) {
|
||||
m_lastMessage = "Viewport pointer down.";
|
||||
} else if (result.viewportInputFrame.pointerReleasedInside) {
|
||||
m_lastMessage = "Viewport pointer up.";
|
||||
} else if (result.viewportInputFrame.pointerMoved) {
|
||||
m_lastMessage = "Viewport pointer move.";
|
||||
} else if (result.viewportInputFrame.wheelDelta != 0.0f) {
|
||||
m_lastMessage = "Viewport wheel.";
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (result.menuMutation.changed) {
|
||||
if (!result.itemId.empty() && !result.menuMutation.openedPopupId.empty()) {
|
||||
m_lastStatus = "Menu";
|
||||
m_lastMessage = result.itemId + " opened child popup.";
|
||||
} else if (!result.menuId.empty() && !result.menuMutation.openedPopupId.empty()) {
|
||||
m_lastStatus = "Menu";
|
||||
m_lastMessage = result.menuId + " opened.";
|
||||
} else {
|
||||
m_lastStatus = "Menu";
|
||||
m_lastMessage = "Popup chain dismissed.";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Application::QueuePointerEvent(
|
||||
UIInputEventType type,
|
||||
UIPointerButton button,
|
||||
WPARAM wParam,
|
||||
LPARAM lParam) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
event.pointerButton = button;
|
||||
@@ -356,7 +448,9 @@ void Application::QueuePointerLeaveEvent() {
|
||||
POINT clientPoint = {};
|
||||
GetCursorPos(&clientPoint);
|
||||
ScreenToClient(m_hwnd, &clientPoint);
|
||||
event.position = UIPoint(static_cast<float>(clientPoint.x), static_cast<float>(clientPoint.y));
|
||||
event.position = UIPoint(
|
||||
static_cast<float>(clientPoint.x),
|
||||
static_cast<float>(clientPoint.y));
|
||||
}
|
||||
m_pendingInputEvents.push_back(event);
|
||||
}
|
||||
@@ -374,7 +468,9 @@ void Application::QueuePointerWheelEvent(short wheelDelta, WPARAM wParam, LPARAM
|
||||
|
||||
UIInputEvent event = {};
|
||||
event.type = UIInputEventType::PointerWheel;
|
||||
event.position = UIPoint(static_cast<float>(screenPoint.x), static_cast<float>(screenPoint.y));
|
||||
event.position = UIPoint(
|
||||
static_cast<float>(screenPoint.x),
|
||||
static_cast<float>(screenPoint.y));
|
||||
event.wheelDelta = static_cast<float>(wheelDelta);
|
||||
event.modifiers = m_inputModifierTracker.BuildPointerModifiers(static_cast<std::size_t>(wParam));
|
||||
m_pendingInputEvents.push_back(event);
|
||||
@@ -403,209 +499,6 @@ void Application::QueueWindowFocusEvent(UIInputEventType type) {
|
||||
m_pendingInputEvents.push_back(event);
|
||||
}
|
||||
|
||||
bool Application::LoadStructuredScreen(const char* triggerReason) {
|
||||
(void)triggerReason;
|
||||
m_screenAsset = m_structuredShell.screenAsset;
|
||||
const EditorShellAssetValidationResult& shellAssetValidation =
|
||||
m_structuredShell.assetValidation;
|
||||
const auto shortcutValidation = m_structuredShell.shortcutManager.ValidateConfiguration();
|
||||
const bool hasAuthoredScreenDocument = !m_screenAsset.documentPath.empty();
|
||||
const bool loaded =
|
||||
hasAuthoredScreenDocument ? m_screenPlayer.Load(m_screenAsset) : shellAssetValidation.IsValid();
|
||||
m_useStructuredScreen = hasAuthoredScreenDocument && loaded;
|
||||
m_runtimeStatus =
|
||||
hasAuthoredScreenDocument
|
||||
? (loaded ? "XCUI Editor Shell" : "Editor Shell | Load Error")
|
||||
: "XCUI Editor Shell | Code-driven";
|
||||
m_runtimeError.clear();
|
||||
if (hasAuthoredScreenDocument && !loaded) {
|
||||
AppendErrorMessage(m_runtimeError, m_screenPlayer.GetLastError());
|
||||
}
|
||||
if (!shellAssetValidation.IsValid()) {
|
||||
AppendErrorMessage(
|
||||
m_runtimeError,
|
||||
"Editor shell asset invalid: " + shellAssetValidation.message);
|
||||
}
|
||||
if (!shortcutValidation.IsValid()) {
|
||||
AppendErrorMessage(
|
||||
m_runtimeError,
|
||||
"Structured shell shortcut manager invalid: " + shortcutValidation.message);
|
||||
}
|
||||
RebuildTrackedFileStates();
|
||||
return loaded;
|
||||
}
|
||||
|
||||
void Application::RefreshStructuredScreen() {
|
||||
const auto now = std::chrono::steady_clock::now();
|
||||
if (m_lastReloadPollTime.time_since_epoch().count() != 0 &&
|
||||
now - m_lastReloadPollTime < kReloadPollInterval) {
|
||||
return;
|
||||
}
|
||||
|
||||
m_lastReloadPollTime = now;
|
||||
if (DetectTrackedFileChange()) {
|
||||
LoadStructuredScreen("reload");
|
||||
}
|
||||
}
|
||||
|
||||
void Application::RebuildTrackedFileStates() {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
m_trackedFiles.clear();
|
||||
std::unordered_set<std::string> seenPaths = {};
|
||||
std::error_code errorCode = {};
|
||||
|
||||
auto appendTrackedPath = [&](const std::string& rawPath) {
|
||||
if (rawPath.empty()) {
|
||||
return;
|
||||
}
|
||||
|
||||
const fs::path normalizedPath = fs::path(rawPath).lexically_normal();
|
||||
const std::string key = normalizedPath.string();
|
||||
if (!seenPaths.insert(key).second) {
|
||||
return;
|
||||
}
|
||||
|
||||
TrackedFileState state = {};
|
||||
state.path = normalizedPath;
|
||||
state.exists = fs::exists(normalizedPath, errorCode);
|
||||
errorCode.clear();
|
||||
if (state.exists) {
|
||||
state.writeTime = fs::last_write_time(normalizedPath, errorCode);
|
||||
errorCode.clear();
|
||||
}
|
||||
m_trackedFiles.push_back(std::move(state));
|
||||
};
|
||||
|
||||
appendTrackedPath(m_screenAsset.documentPath);
|
||||
|
||||
if (const auto* document = m_screenPlayer.GetDocument(); document != nullptr) {
|
||||
for (const std::string& dependency : document->dependencies) {
|
||||
appendTrackedPath(dependency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Application::DetectTrackedFileChange() const {
|
||||
namespace fs = std::filesystem;
|
||||
|
||||
std::error_code errorCode = {};
|
||||
for (const TrackedFileState& trackedFile : m_trackedFiles) {
|
||||
const bool existsNow = fs::exists(trackedFile.path, errorCode);
|
||||
errorCode.clear();
|
||||
if (existsNow != trackedFile.exists) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!existsNow) {
|
||||
continue;
|
||||
}
|
||||
|
||||
const auto writeTimeNow = fs::last_write_time(trackedFile.path, errorCode);
|
||||
errorCode.clear();
|
||||
if (writeTimeNow != trackedFile.writeTime) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Application::AppendRuntimeOverlay(UIDrawData& drawData, float width, float height) const {
|
||||
const bool authoredMode =
|
||||
!m_screenAsset.documentPath.empty() && m_useStructuredScreen && m_screenPlayer.IsLoaded();
|
||||
const float panelWidth = authoredMode ? 430.0f : 380.0f;
|
||||
std::vector<std::string> detailLines = {};
|
||||
detailLines.push_back(
|
||||
authoredMode
|
||||
? "Hot reload watches editor shell document and dependencies."
|
||||
: "Editor shell is composed directly from fixed code definitions.");
|
||||
detailLines.push_back(
|
||||
authoredMode
|
||||
? "Document: " + std::filesystem::path(m_screenAsset.documentPath).filename().string()
|
||||
: "Document: (none)");
|
||||
|
||||
if (authoredMode) {
|
||||
const auto& inputDebug = m_documentHost.GetInputDebugSnapshot();
|
||||
detailLines.push_back(
|
||||
"Hover | Focus: " +
|
||||
ExtractStateKeyTail(inputDebug.hoveredStateKey) +
|
||||
" | " +
|
||||
ExtractStateKeyTail(inputDebug.focusedStateKey));
|
||||
detailLines.push_back(
|
||||
"Active | Capture: " +
|
||||
ExtractStateKeyTail(inputDebug.activeStateKey) +
|
||||
" | " +
|
||||
ExtractStateKeyTail(inputDebug.captureStateKey));
|
||||
if (!inputDebug.lastEventType.empty()) {
|
||||
const std::string eventPosition = inputDebug.lastEventType == "KeyDown" ||
|
||||
inputDebug.lastEventType == "KeyUp" ||
|
||||
inputDebug.lastEventType == "Character" ||
|
||||
inputDebug.lastEventType == "FocusGained" ||
|
||||
inputDebug.lastEventType == "FocusLost"
|
||||
? std::string()
|
||||
: " at " + FormatPoint(inputDebug.pointerPosition);
|
||||
detailLines.push_back(
|
||||
"Last input: " +
|
||||
inputDebug.lastEventType +
|
||||
eventPosition);
|
||||
detailLines.push_back(
|
||||
"Route: " +
|
||||
inputDebug.lastTargetKind +
|
||||
" -> " +
|
||||
ExtractStateKeyTail(inputDebug.lastTargetStateKey));
|
||||
detailLines.push_back(
|
||||
"Last event result: " +
|
||||
(inputDebug.lastResult.empty() ? std::string("n/a") : inputDebug.lastResult));
|
||||
}
|
||||
}
|
||||
|
||||
if (m_autoScreenshot.HasPendingCapture()) {
|
||||
detailLines.push_back("Shot pending...");
|
||||
} else if (!m_autoScreenshot.GetLastCaptureSummary().empty()) {
|
||||
detailLines.push_back(TruncateText(m_autoScreenshot.GetLastCaptureSummary(), 78u));
|
||||
} else {
|
||||
detailLines.push_back("Screenshots: F12 -> new_editor/captures/");
|
||||
}
|
||||
|
||||
if (!m_runtimeError.empty()) {
|
||||
detailLines.push_back(TruncateText(m_runtimeError, 78u));
|
||||
} else if (!m_autoScreenshot.GetLastCaptureError().empty()) {
|
||||
detailLines.push_back(TruncateText(m_autoScreenshot.GetLastCaptureError(), 78u));
|
||||
} else if (!authoredMode) {
|
||||
detailLines.push_back("No authored XCUI document is used by the editor shell host.");
|
||||
}
|
||||
|
||||
const float panelHeight = 38.0f + static_cast<float>(detailLines.size()) * 18.0f;
|
||||
const UIRect panelRect(width - panelWidth - 16.0f, height - panelHeight - 42.0f, panelWidth, panelHeight);
|
||||
|
||||
UIDrawList& overlay = drawData.EmplaceDrawList("XCUI Editor Runtime Overlay");
|
||||
overlay.AddFilledRect(panelRect, kOverlayBgColor, 10.0f);
|
||||
overlay.AddRectOutline(panelRect, kOverlayBorderColor, 1.0f, 10.0f);
|
||||
overlay.AddFilledRect(
|
||||
UIRect(panelRect.x + 12.0f, panelRect.y + 14.0f, 8.0f, 8.0f),
|
||||
authoredMode ? kOverlaySuccess : kOverlayFallback,
|
||||
4.0f);
|
||||
overlay.AddText(
|
||||
UIPoint(panelRect.x + 28.0f, panelRect.y + 10.0f),
|
||||
m_runtimeStatus.empty() ? "XCUI Editor Shell" : m_runtimeStatus,
|
||||
kOverlayTextPrimary,
|
||||
14.0f);
|
||||
|
||||
float detailY = panelRect.y + 30.0f;
|
||||
for (std::size_t index = 0; index < detailLines.size(); ++index) {
|
||||
const bool lastLine = index + 1u == detailLines.size();
|
||||
overlay.AddText(
|
||||
UIPoint(panelRect.x + 28.0f, detailY),
|
||||
detailLines[index],
|
||||
lastLine && (!m_runtimeError.empty() || !m_autoScreenshot.GetLastCaptureError().empty())
|
||||
? kOverlayFallback
|
||||
: kOverlayTextMuted,
|
||||
12.0f);
|
||||
detailY += 18.0f;
|
||||
}
|
||||
}
|
||||
|
||||
std::filesystem::path Application::ResolveRepoRootPath() {
|
||||
std::string root = XCUIEDITOR_REPO_ROOT;
|
||||
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
|
||||
@@ -614,6 +507,70 @@ std::filesystem::path Application::ResolveRepoRootPath() {
|
||||
return std::filesystem::path(root).lexically_normal();
|
||||
}
|
||||
|
||||
UIEditorHostCommandEvaluationResult Application::EvaluateHostCommand(
|
||||
std::string_view commandId) const {
|
||||
UIEditorHostCommandEvaluationResult result = {};
|
||||
if (commandId == "file.exit") {
|
||||
result.executable = true;
|
||||
result.message = "Exit command is ready.";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (commandId == "help.about") {
|
||||
result.executable = true;
|
||||
result.message = "About placeholder is ready.";
|
||||
return result;
|
||||
}
|
||||
|
||||
if (commandId.rfind("file.", 0u) == 0u) {
|
||||
result.message = "Document command bridge is not attached yet.";
|
||||
return result;
|
||||
}
|
||||
if (commandId.rfind("edit.", 0u) == 0u) {
|
||||
result.message = "Edit route bridge is not attached yet.";
|
||||
return result;
|
||||
}
|
||||
if (commandId.rfind("assets.", 0u) == 0u) {
|
||||
result.message = "Asset pipeline bridge is not attached yet.";
|
||||
return result;
|
||||
}
|
||||
if (commandId.rfind("run.", 0u) == 0u) {
|
||||
result.message = "Runtime bridge is not attached yet.";
|
||||
return result;
|
||||
}
|
||||
if (commandId.rfind("scripts.", 0u) == 0u) {
|
||||
result.message = "Script pipeline bridge is not attached yet.";
|
||||
return result;
|
||||
}
|
||||
|
||||
result.message = "Host command is not attached yet.";
|
||||
return result;
|
||||
}
|
||||
|
||||
UIEditorHostCommandDispatchResult Application::DispatchHostCommand(
|
||||
std::string_view commandId) {
|
||||
UIEditorHostCommandDispatchResult result = {};
|
||||
if (commandId == "file.exit") {
|
||||
result.commandExecuted = true;
|
||||
result.message = "Exit requested.";
|
||||
if (m_hwnd != nullptr) {
|
||||
PostMessageW(m_hwnd, WM_CLOSE, 0, 0);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
if (commandId == "help.about") {
|
||||
result.commandExecuted = true;
|
||||
result.message = "About dialog will be wired after modal layer lands.";
|
||||
m_lastStatus = "About";
|
||||
m_lastMessage = result.message;
|
||||
return result;
|
||||
}
|
||||
|
||||
result.message = "Host command dispatch rejected.";
|
||||
return result;
|
||||
}
|
||||
|
||||
LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
|
||||
if (message == WM_NCCREATE) {
|
||||
const auto* createStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
|
||||
@@ -649,7 +606,11 @@ LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT message, WPARAM wParam, LP
|
||||
application->m_trackingMouseLeave = true;
|
||||
}
|
||||
}
|
||||
application->QueuePointerEvent(UIInputEventType::PointerMove, UIPointerButton::None, wParam, lParam);
|
||||
application->QueuePointerEvent(
|
||||
UIInputEventType::PointerMove,
|
||||
UIPointerButton::None,
|
||||
wParam,
|
||||
lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
@@ -663,17 +624,21 @@ LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT message, WPARAM wParam, LP
|
||||
case WM_LBUTTONDOWN:
|
||||
if (application != nullptr) {
|
||||
SetFocus(hwnd);
|
||||
SetCapture(hwnd);
|
||||
application->QueuePointerEvent(UIInputEventType::PointerButtonDown, UIPointerButton::Left, wParam, lParam);
|
||||
application->QueuePointerEvent(
|
||||
UIInputEventType::PointerButtonDown,
|
||||
UIPointerButton::Left,
|
||||
wParam,
|
||||
lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (application != nullptr) {
|
||||
if (GetCapture() == hwnd) {
|
||||
ReleaseCapture();
|
||||
}
|
||||
application->QueuePointerEvent(UIInputEventType::PointerButtonUp, UIPointerButton::Left, wParam, lParam);
|
||||
application->QueuePointerEvent(
|
||||
UIInputEventType::PointerButtonUp,
|
||||
UIPointerButton::Left,
|
||||
wParam,
|
||||
lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
@@ -697,6 +662,14 @@ LRESULT CALLBACK Application::WndProc(HWND hwnd, UINT message, WPARAM wParam, LP
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_CAPTURECHANGED:
|
||||
if (application != nullptr &&
|
||||
reinterpret_cast<HWND>(lParam) != hwnd &&
|
||||
application->HasInteractiveCaptureState()) {
|
||||
application->QueueWindowFocusEvent(UIInputEventType::FocusLost);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (application != nullptr) {
|
||||
|
||||
Reference in New Issue
Block a user