Refactor XCUI editor module layout

This commit is contained in:
2026-04-10 00:41:28 +08:00
parent 4b47764f26
commit 02a0e626fe
263 changed files with 12396 additions and 7592 deletions

View File

@@ -0,0 +1,31 @@
add_executable(editor_ui_object_field_basic_validation WIN32
main.cpp
)
target_include_directories(editor_ui_object_field_basic_validation PRIVATE
${CMAKE_SOURCE_DIR}/tests/UI/Editor/integration/shared/src
${CMAKE_SOURCE_DIR}/new_editor/include
${CMAKE_SOURCE_DIR}/new_editor/app
${CMAKE_SOURCE_DIR}/engine/include
)
target_compile_definitions(editor_ui_object_field_basic_validation PRIVATE
UNICODE
_UNICODE
XCENGINE_EDITOR_UI_TESTS_REPO_ROOT="${XCENGINE_EDITOR_UI_TESTS_REPO_ROOT_PATH}"
)
if(MSVC)
target_compile_options(editor_ui_object_field_basic_validation PRIVATE /utf-8 /FS)
set_property(TARGET editor_ui_object_field_basic_validation PROPERTY
MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>DLL")
endif()
target_link_libraries(editor_ui_object_field_basic_validation PRIVATE
XCUIEditorLib
XCUIEditorHost
)
set_target_properties(editor_ui_object_field_basic_validation PROPERTIES
OUTPUT_NAME "XCUIEditorObjectFieldBasicValidation"
)

View File

@@ -0,0 +1,736 @@
#ifndef NOMINMAX
#define NOMINMAX
#endif
#include <XCEditor/Foundation/UIEditorTheme.h>
#include <XCEditor/Fields/UIEditorObjectField.h>
#include <XCEditor/Fields/UIEditorObjectFieldInteraction.h>
#include "EditorValidationTheme.h"
#include "Host/AutoScreenshot.h"
#include "Host/NativeRenderer.h"
#include <XCEngine/Input/InputTypes.h>
#include <XCEngine/UI/DrawData.h>
#include <windows.h>
#include <windowsx.h>
#include <algorithm>
#include <filesystem>
#include <string>
#include <string_view>
#include <vector>
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
#endif
namespace {
using XCEngine::Input::KeyCode;
using XCEngine::UI::UIDrawData;
using XCEngine::UI::UIDrawList;
using XCEngine::UI::UIInputEvent;
using XCEngine::UI::UIInputEventType;
using XCEngine::UI::UIPoint;
using XCEngine::UI::UIPointerButton;
using XCEngine::UI::UIRect;
using XCEngine::UI::Editor::Host::AutoScreenshotController;
using XCEngine::UI::Editor::Host::NativeRenderer;
using XCEngine::UI::Editor::UIEditorObjectFieldInteractionFrame;
using XCEngine::UI::Editor::UIEditorObjectFieldInteractionResult;
using XCEngine::UI::Editor::UIEditorObjectFieldInteractionState;
using XCEngine::UI::Editor::UpdateUIEditorObjectFieldInteraction;
using XCEngine::UI::Editor::Widgets::AppendUIEditorObjectField;
using XCEngine::UI::Editor::Widgets::UIEditorObjectFieldHitTarget;
using XCEngine::UI::Editor::Widgets::UIEditorObjectFieldHitTargetKind;
using XCEngine::UI::Editor::Widgets::UIEditorObjectFieldSpec;
constexpr const wchar_t* kWindowClassName = L"XCUIEditorObjectFieldBasicValidation";
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | ObjectField Basic";
enum class ActionId : unsigned char {
Reset = 0,
Capture
};
struct ButtonLayout {
ActionId action = ActionId::Reset;
const char* label = "";
UIRect rect = {};
};
struct ScenarioLayout {
UIRect introRect = {};
UIRect controlRect = {};
UIRect stateRect = {};
UIRect previewRect = {};
UIRect fieldRect = {};
std::vector<ButtonLayout> buttons = {};
};
std::filesystem::path ResolveRepoRootPath() {
std::string root = XCENGINE_EDITOR_UI_TESTS_REPO_ROOT;
if (root.size() >= 2u && root.front() == '"' && root.back() == '"') {
root = root.substr(1u, root.size() - 2u);
}
return std::filesystem::path(root).lexically_normal();
}
bool ContainsPoint(const UIRect& rect, float x, float y) {
return x >= rect.x &&
x <= rect.x + rect.width &&
y >= rect.y &&
y <= rect.y + rect.height;
}
std::int32_t MapObjectFieldKey(UINT keyCode) {
switch (keyCode) {
case VK_SPACE:
return static_cast<std::int32_t>(KeyCode::Space);
case VK_RETURN:
return static_cast<std::int32_t>(KeyCode::Enter);
case VK_DELETE:
return static_cast<std::int32_t>(KeyCode::Delete);
case VK_BACK:
return static_cast<std::int32_t>(KeyCode::Backspace);
default:
return static_cast<std::int32_t>(KeyCode::None);
}
}
ScenarioLayout BuildScenarioLayout(
float width,
float height,
const XCEngine::Tests::EditorUI::EditorValidationShellMetrics& shellMetrics) {
const float margin = shellMetrics.margin;
constexpr float leftWidth = 440.0f;
const float gap = shellMetrics.gap;
ScenarioLayout layout = {};
layout.introRect = UIRect(margin, margin, leftWidth, 236.0f);
layout.controlRect = UIRect(margin, layout.introRect.y + layout.introRect.height + gap, leftWidth, 84.0f);
layout.stateRect = UIRect(
margin,
layout.controlRect.y + layout.controlRect.height + gap,
leftWidth,
(std::max)(232.0f, height - (layout.controlRect.y + layout.controlRect.height + gap) - margin));
layout.previewRect = UIRect(
leftWidth + margin * 2.0f,
margin,
(std::max)(420.0f, width - leftWidth - margin * 3.0f),
height - margin * 2.0f);
layout.fieldRect = UIRect(
layout.previewRect.x + 24.0f,
layout.previewRect.y + 82.0f,
(std::min)(440.0f, layout.previewRect.width - 48.0f),
22.0f);
const float buttonWidth = (layout.controlRect.width - 44.0f) * 0.5f;
const float buttonY = layout.controlRect.y + 32.0f;
layout.buttons = {
{ ActionId::Reset, "重置", UIRect(layout.controlRect.x + 14.0f, buttonY, buttonWidth, 36.0f) },
{ ActionId::Capture, "截图(F12)", UIRect(layout.controlRect.x + 26.0f + buttonWidth, buttonY, buttonWidth, 36.0f) }
};
return layout;
}
void DrawCard(
UIDrawList& drawList,
const UIRect& rect,
const XCEngine::Tests::EditorUI::EditorValidationShellPalette& shellPalette,
const XCEngine::Tests::EditorUI::EditorValidationShellMetrics& shellMetrics,
std::string_view title,
std::string_view subtitle = {}) {
drawList.AddFilledRect(rect, shellPalette.cardBackground, shellMetrics.cardRadius);
drawList.AddRectOutline(rect, shellPalette.cardBorder, 1.0f, shellMetrics.cardRadius);
drawList.AddText(
UIPoint(rect.x + 16.0f, rect.y + 14.0f),
std::string(title),
shellPalette.textPrimary,
shellMetrics.titleFontSize);
if (!subtitle.empty()) {
drawList.AddText(
UIPoint(rect.x + 16.0f, rect.y + 40.0f),
std::string(subtitle),
shellPalette.textMuted,
shellMetrics.bodyFontSize);
}
}
void DrawButton(
UIDrawList& drawList,
const ButtonLayout& button,
const XCEngine::Tests::EditorUI::EditorValidationShellPalette& shellPalette,
const XCEngine::Tests::EditorUI::EditorValidationShellMetrics& shellMetrics,
bool hovered) {
drawList.AddFilledRect(
button.rect,
hovered ? shellPalette.buttonHoverBackground : shellPalette.buttonBackground,
shellMetrics.buttonRadius);
drawList.AddRectOutline(button.rect, shellPalette.cardBorder, 1.0f, shellMetrics.buttonRadius);
drawList.AddText(
UIPoint(button.rect.x + 16.0f, button.rect.y + 10.0f),
button.label,
shellPalette.textPrimary,
shellMetrics.bodyFontSize);
}
std::string DescribeHitTarget(const UIEditorObjectFieldHitTarget& hitTarget) {
switch (hitTarget.kind) {
case UIEditorObjectFieldHitTargetKind::ValueBox:
return "value_box";
case UIEditorObjectFieldHitTargetKind::ClearButton:
return "clear_button";
case UIEditorObjectFieldHitTargetKind::PickerButton:
return "picker_button";
case UIEditorObjectFieldHitTargetKind::Row:
return "row";
case UIEditorObjectFieldHitTargetKind::None:
default:
return "none";
}
}
UIInputEvent MakePointerEvent(
UIInputEventType type,
const UIPoint& position,
UIPointerButton button = UIPointerButton::None) {
UIInputEvent event = {};
event.type = type;
event.position = position;
event.pointerButton = button;
return event;
}
UIInputEvent MakeFocusEvent(UIInputEventType type) {
UIInputEvent event = {};
event.type = type;
return event;
}
UIInputEvent MakeKeyEvent(std::int32_t keyCode) {
UIInputEvent event = {};
event.type = UIInputEventType::KeyDown;
event.keyCode = keyCode;
return event;
}
class ScenarioApp {
public:
int Run(HINSTANCE hInstance, int nCmdShow) {
if (!Initialize(hInstance, nCmdShow)) {
Shutdown();
return 1;
}
MSG message = {};
while (message.message != WM_QUIT) {
if (PeekMessageW(&message, nullptr, 0U, 0U, PM_REMOVE)) {
TranslateMessage(&message);
DispatchMessageW(&message);
continue;
}
RenderFrame();
Sleep(8);
}
Shutdown();
return static_cast<int>(message.wParam);
}
private:
static LRESULT CALLBACK WndProc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
if (message == WM_NCCREATE) {
const auto* createStruct = reinterpret_cast<CREATESTRUCTW*>(lParam);
auto* app = static_cast<ScenarioApp*>(createStruct->lpCreateParams);
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
return TRUE;
}
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
if (app == nullptr) {
return DefWindowProcW(hwnd, message, wParam, lParam);
}
return app->HandleMessage(hwnd, message, wParam, lParam);
}
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
m_hInstance = hInstance;
WNDCLASSEXW windowClass = {};
windowClass.cbSize = sizeof(windowClass);
windowClass.style = CS_HREDRAW | CS_VREDRAW;
windowClass.lpfnWndProc = &ScenarioApp::WndProc;
windowClass.hInstance = hInstance;
windowClass.hCursor = LoadCursorW(nullptr, IDC_ARROW);
windowClass.lpszClassName = kWindowClassName;
m_windowClassAtom = RegisterClassExW(&windowClass);
if (m_windowClassAtom == 0) {
return false;
}
m_hwnd = CreateWindowExW(
0,
kWindowClassName,
kWindowTitle,
WS_OVERLAPPEDWINDOW | WS_VISIBLE,
CW_USEDEFAULT,
CW_USEDEFAULT,
1360,
820,
nullptr,
nullptr,
hInstance,
this);
if (m_hwnd == nullptr) {
return false;
}
ShowWindow(m_hwnd, nCmdShow);
UpdateWindow(m_hwnd);
if (!m_renderer.Initialize(m_hwnd)) {
return false;
}
m_shellPalette = XCEngine::Tests::EditorUI::GetEditorValidationShellPalette();
m_shellMetrics = XCEngine::Tests::EditorUI::GetEditorValidationShellMetrics();
m_fieldMetrics = XCEngine::UI::Editor::ResolveUIEditorObjectFieldMetrics();
m_fieldPalette = XCEngine::UI::Editor::ResolveUIEditorObjectFieldPalette();
m_captureRoot =
ResolveRepoRootPath() / "tests/UI/Editor/integration/shell/object_field_basic/captures";
m_autoScreenshot.Initialize(m_captureRoot);
ResetScenario();
return true;
}
void Shutdown() {
m_autoScreenshot.Shutdown();
m_renderer.Shutdown();
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
DestroyWindow(m_hwnd);
}
m_hwnd = nullptr;
if (m_windowClassAtom != 0 && m_hInstance != nullptr) {
UnregisterClassW(kWindowClassName, m_hInstance);
m_windowClassAtom = 0;
}
}
void ResetScenario() {
m_spec = {};
m_spec.fieldId = "target";
m_spec.label = "Target";
m_spec.objectName = "Main Camera";
m_spec.objectTypeName = "Camera";
m_spec.emptyText = "None (GameObject)";
m_spec.hasValue = true;
m_spec.showClearButton = true;
m_spec.showPickerButton = true;
m_interactionState = {};
m_activateCount = 0u;
m_lastResult = "已重置到默认 ObjectField 状态";
m_hoveredAction = ActionId::Reset;
m_pressedAction = ActionId::Reset;
m_hasHoveredAction = false;
m_hasPressedAction = false;
}
ScenarioLayout GetLayout() const {
RECT clientRect = {};
GetClientRect(m_hwnd, &clientRect);
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));
return BuildScenarioLayout(width, height, m_shellMetrics);
}
void UpdateHoveredAction(const ScenarioLayout& layout, float x, float y) {
for (const ButtonLayout& button : layout.buttons) {
if (ContainsPoint(button.rect, x, y)) {
m_hoveredAction = button.action;
m_hasHoveredAction = true;
return;
}
}
m_hasHoveredAction = false;
}
const ButtonLayout* HitTestAction(const ScenarioLayout& layout, float x, float y) const {
for (const ButtonLayout& button : layout.buttons) {
if (ContainsPoint(button.rect, x, y)) {
return &button;
}
}
return nullptr;
}
void ApplyInteractionResult(const UIEditorObjectFieldInteractionResult& result) {
if (result.activateRequested) {
++m_activateCount;
m_lastResult = "已触发 activateRequested";
return;
}
if (result.clearRequested) {
m_spec.hasValue = false;
m_spec.objectName.clear();
m_spec.objectTypeName.clear();
m_lastResult = "已触发 clearRequested当前引用已清空";
return;
}
if (result.focusChanged) {
m_lastResult = std::string("焦点已切换: ") + (m_interactionState.fieldState.focused ? "focused" : "blurred");
return;
}
if (result.consumed) {
m_lastResult = "输入已消费";
return;
}
}
void QueueInput(UIInputEvent event) {
m_pendingInputEvents.push_back(std::move(event));
}
void ExecuteAction(ActionId action) {
switch (action) {
case ActionId::Reset:
ResetScenario();
break;
case ActionId::Capture:
m_autoScreenshot.RequestCapture("manual_button");
m_lastResult = "截图已排队,输出到 captures/latest.png";
break;
}
}
void HandleMouseMove(float x, float y) {
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
UpdateHoveredAction(layout, x, y);
TRACKMOUSEEVENT trackEvent = {};
trackEvent.cbSize = sizeof(trackEvent);
trackEvent.dwFlags = TME_LEAVE;
trackEvent.hwndTrack = m_hwnd;
TrackMouseEvent(&trackEvent);
QueueInput(MakePointerEvent(UIInputEventType::PointerMove, m_mousePosition));
}
void HandleMouseLeave() {
m_mousePosition = UIPoint(-1000.0f, -1000.0f);
m_hasHoveredAction = false;
QueueInput(MakePointerEvent(UIInputEventType::PointerLeave, m_mousePosition));
}
void HandleLeftButtonDown(float x, float y) {
SetFocus(m_hwnd);
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
UpdateHoveredAction(layout, x, y);
if (const ButtonLayout* button = HitTestAction(layout, x, y)) {
m_pressedAction = button->action;
m_hasPressedAction = true;
return;
}
m_hasPressedAction = false;
QueueInput(MakePointerEvent(
UIInputEventType::PointerButtonDown,
m_mousePosition,
UIPointerButton::Left));
}
void HandleLeftButtonUp(float x, float y) {
m_mousePosition = UIPoint(x, y);
const ScenarioLayout layout = GetLayout();
UpdateHoveredAction(layout, x, y);
if (const ButtonLayout* button = HitTestAction(layout, x, y)) {
if (m_hasPressedAction && m_pressedAction == button->action) {
ExecuteAction(button->action);
}
m_hasPressedAction = false;
return;
}
m_hasPressedAction = false;
QueueInput(MakePointerEvent(
UIInputEventType::PointerButtonUp,
m_mousePosition,
UIPointerButton::Left));
}
void HandleKeyDown(std::int32_t keyCode) {
QueueInput(MakeKeyEvent(keyCode));
}
void OnResize(UINT width, UINT height) {
if (width == 0u || height == 0u) {
return;
}
m_renderer.Resize(width, height);
}
void RenderFrame() {
if (m_hwnd == nullptr) {
return;
}
RECT clientRect = {};
GetClientRect(m_hwnd, &clientRect);
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 ScenarioLayout layout = BuildScenarioLayout(width, height, m_shellMetrics);
std::vector<UIInputEvent> events = std::move(m_pendingInputEvents);
m_pendingInputEvents.clear();
m_frame = UpdateUIEditorObjectFieldInteraction(
m_interactionState,
m_spec,
layout.fieldRect,
events,
m_fieldMetrics);
ApplyInteractionResult(m_frame.result);
UIDrawData drawData = {};
UIDrawList& drawList = drawData.EmplaceDrawList("EditorObjectFieldBasic");
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), m_shellPalette.windowBackground);
DrawCard(
drawList,
layout.introRect,
m_shellPalette,
m_shellMetrics,
"这个测试在验证什么功能?",
"验证 Unity 风格 ObjectField 的值框、类型标签、clear / picker 按钮,以及 focus、activate、clear 契约。");
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 72.0f),
"1. 点击 value box 或 picker 按钮,应触发 activateRequested。",
m_shellPalette.textPrimary,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 94.0f),
"2. 点击 clear 按钮,或 focused 时按 Delete / Backspace应清空当前对象。",
m_shellPalette.textPrimary,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 116.0f),
"3. focused 后按 Enter / Space应继续走 activate 契约。",
m_shellPalette.textPrimary,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 138.0f),
"4. 重点检查 Hover、Focused、Has Value、Activate Count、Result 是否同步。",
m_shellPalette.textPrimary,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.introRect.x + 16.0f, layout.introRect.y + 160.0f),
"5. 按 F12 或点击截图按钮,可导出当前窗口截图。",
m_shellPalette.textPrimary,
m_shellMetrics.bodyFontSize);
DrawCard(
drawList,
layout.controlRect,
m_shellPalette,
m_shellMetrics,
"操作",
"这里只保留当前场景需要的最小操作。");
for (const ButtonLayout& button : layout.buttons) {
DrawButton(
drawList,
button,
m_shellPalette,
m_shellMetrics,
m_hasHoveredAction && m_hoveredAction == button.action);
}
DrawCard(
drawList,
layout.stateRect,
m_shellPalette,
m_shellMetrics,
"状态摘要",
"重点检查 hit、focus、value、activate、result。");
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 74.0f),
"Hover: " + DescribeHitTarget(m_frame.result.hitTarget),
m_shellPalette.textPrimary,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 96.0f),
std::string("Focused: ") + (m_interactionState.fieldState.focused ? "" : ""),
m_interactionState.fieldState.focused ? m_shellPalette.textSuccess : m_shellPalette.textMuted,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 118.0f),
std::string("Has Value: ") + (m_spec.hasValue ? "" : ""),
m_spec.hasValue ? m_shellPalette.textSuccess : m_shellPalette.textMuted,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 140.0f),
"Value: " + (m_spec.hasValue ? m_spec.objectName : m_spec.emptyText),
m_shellPalette.textPrimary,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 162.0f),
"Type: " + (m_spec.objectTypeName.empty() ? std::string("(none)") : m_spec.objectTypeName),
m_shellPalette.textMuted,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 184.0f),
"Activate Count: " + std::to_string(m_activateCount),
m_shellPalette.textPrimary,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 206.0f),
"Result: " + m_lastResult,
m_shellPalette.textMuted,
m_shellMetrics.bodyFontSize);
drawList.AddText(
UIPoint(layout.stateRect.x + 16.0f, layout.stateRect.y + 232.0f),
m_autoScreenshot.HasPendingCapture()
? "截图排队中..."
: (m_autoScreenshot.GetLastCaptureSummary().empty()
? std::string("F12 -> tests/UI/Editor/integration/shell/object_field_basic/captures/")
: m_autoScreenshot.GetLastCaptureSummary()),
m_shellPalette.textWeak,
m_shellMetrics.bodyFontSize);
DrawCard(
drawList,
layout.previewRect,
m_shellPalette,
m_shellMetrics,
"ObjectField 预览",
"这里只放一个 Unity 风格 ObjectField不混入业务 Inspector。");
AppendUIEditorObjectField(
drawList,
layout.fieldRect,
m_spec,
m_interactionState.fieldState,
m_fieldPalette,
m_fieldMetrics);
const bool framePresented = m_renderer.Render(drawData);
m_autoScreenshot.CaptureIfRequested(
m_renderer,
drawData,
static_cast<unsigned int>(width),
static_cast<unsigned int>(height),
framePresented);
}
LRESULT HandleMessage(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam) {
switch (message) {
case WM_CLOSE:
DestroyWindow(hwnd);
return 0;
case WM_DESTROY:
m_hwnd = nullptr;
PostQuitMessage(0);
return 0;
case WM_SIZE:
if (wParam != SIZE_MINIMIZED) {
OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
}
return 0;
case WM_ERASEBKGND:
return 1;
case WM_MOUSEMOVE:
HandleMouseMove(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)));
return 0;
case WM_MOUSELEAVE:
HandleMouseLeave();
return 0;
case WM_LBUTTONDOWN:
HandleLeftButtonDown(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)));
return 0;
case WM_LBUTTONUP:
HandleLeftButtonUp(
static_cast<float>(GET_X_LPARAM(lParam)),
static_cast<float>(GET_Y_LPARAM(lParam)));
return 0;
case WM_SETFOCUS:
QueueInput(MakeFocusEvent(UIInputEventType::FocusGained));
return 0;
case WM_KILLFOCUS:
QueueInput(MakeFocusEvent(UIInputEventType::FocusLost));
return 0;
case WM_KEYDOWN:
case WM_SYSKEYDOWN:
if (wParam == VK_F12) {
m_autoScreenshot.RequestCapture("manual_f12");
m_lastResult = "截图已排队,输出到 captures/latest.png";
return 0;
}
if (const std::int32_t keyCode = MapObjectFieldKey(static_cast<UINT>(wParam));
keyCode != static_cast<std::int32_t>(KeyCode::None)) {
HandleKeyDown(keyCode);
return 0;
}
break;
default:
break;
}
return DefWindowProcW(hwnd, message, wParam, lParam);
}
HWND m_hwnd = nullptr;
HINSTANCE m_hInstance = nullptr;
ATOM m_windowClassAtom = 0;
NativeRenderer m_renderer = {};
AutoScreenshotController m_autoScreenshot = {};
std::filesystem::path m_captureRoot = {};
XCEngine::Tests::EditorUI::EditorValidationShellPalette m_shellPalette = {};
XCEngine::Tests::EditorUI::EditorValidationShellMetrics m_shellMetrics = {};
XCEngine::UI::Editor::Widgets::UIEditorObjectFieldPalette m_fieldPalette = {};
XCEngine::UI::Editor::Widgets::UIEditorObjectFieldMetrics m_fieldMetrics = {};
UIEditorObjectFieldSpec m_spec = {};
UIEditorObjectFieldInteractionState m_interactionState = {};
UIEditorObjectFieldInteractionFrame m_frame = {};
std::vector<UIInputEvent> m_pendingInputEvents = {};
UIPoint m_mousePosition = UIPoint(-1000.0f, -1000.0f);
ActionId m_hoveredAction = ActionId::Reset;
ActionId m_pressedAction = ActionId::Reset;
bool m_hasHoveredAction = false;
bool m_hasPressedAction = false;
std::string m_lastResult = {};
std::size_t m_activateCount = 0u;
};
} // namespace
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
return ScenarioApp().Run(hInstance, nCmdShow);
}