tests: remove legacy test tree
This commit is contained in:
@@ -1,7 +0,0 @@
|
||||
add_subdirectory(panel_session_flow)
|
||||
add_subdirectory(panel_host_lifecycle)
|
||||
add_subdirectory(layout_persistence)
|
||||
add_subdirectory(shortcut_dispatch)
|
||||
if(EXISTS "${CMAKE_CURRENT_SOURCE_DIR}/viewport_input_bridge_basic/CMakeLists.txt")
|
||||
add_subdirectory(viewport_input_bridge_basic)
|
||||
endif()
|
||||
@@ -1,8 +0,0 @@
|
||||
add_executable(editor_ui_layout_persistence_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
xcengine_configure_editor_ui_integration_validation_target(
|
||||
editor_ui_layout_persistence_validation
|
||||
OUTPUT_NAME "XCUIEditorLayoutPersistenceValidation"
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,858 +0,0 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEditor/Workspace/UIEditorWorkspaceController.h>
|
||||
#include <XCEditor/Workspace/UIEditorWorkspaceLayoutPersistence.h>
|
||||
#include "Rendering/Native/AutoScreenshot.h"
|
||||
#include "Rendering/Native/NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <iomanip>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceSession;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceSplit;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceTabStack;
|
||||
using XCEngine::UI::Editor::CollectUIEditorWorkspaceVisiblePanels;
|
||||
using XCEngine::UI::Editor::FindUIEditorPanelSessionState;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceCommandStatusName;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceLayoutOperationStatusName;
|
||||
using XCEngine::UI::Editor::SerializeUIEditorWorkspaceLayoutSnapshot;
|
||||
using XCEngine::UI::Editor::UIEditorPanelRegistry;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommand;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandKind;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandResult;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandStatus;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceLayoutOperationResult;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceLayoutOperationStatus;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceLayoutSnapshot;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceModel;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceSession;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceSplitAxis;
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorLayoutPersistenceValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | Layout Persistence";
|
||||
|
||||
constexpr UIColor kWindowBg(0.14f, 0.14f, 0.14f, 1.0f);
|
||||
constexpr UIColor kCardBg(0.19f, 0.19f, 0.19f, 1.0f);
|
||||
constexpr UIColor kCardBorder(0.29f, 0.29f, 0.29f, 1.0f);
|
||||
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
|
||||
constexpr UIColor kTextMuted(0.70f, 0.70f, 0.70f, 1.0f);
|
||||
constexpr UIColor kAccent(0.82f, 0.82f, 0.82f, 1.0f);
|
||||
constexpr UIColor kSuccess(0.43f, 0.71f, 0.47f, 1.0f);
|
||||
constexpr UIColor kWarning(0.78f, 0.60f, 0.30f, 1.0f);
|
||||
constexpr UIColor kDanger(0.78f, 0.34f, 0.34f, 1.0f);
|
||||
constexpr UIColor kButtonEnabled(0.31f, 0.31f, 0.31f, 1.0f);
|
||||
constexpr UIColor kButtonDisabled(0.24f, 0.24f, 0.24f, 1.0f);
|
||||
constexpr UIColor kButtonBorder(0.42f, 0.42f, 0.42f, 1.0f);
|
||||
constexpr UIColor kPanelRowBg(0.17f, 0.17f, 0.17f, 1.0f);
|
||||
|
||||
enum class ActionId : unsigned char {
|
||||
HideActive = 0,
|
||||
SaveLayout,
|
||||
CloseDocB,
|
||||
LoadLayout,
|
||||
ActivateDetails,
|
||||
LoadInvalid,
|
||||
Reset
|
||||
};
|
||||
|
||||
struct ButtonState {
|
||||
ActionId action = ActionId::HideActive;
|
||||
std::string label = {};
|
||||
UIRect rect = {};
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
UIEditorPanelRegistry BuildPanelRegistry() {
|
||||
UIEditorPanelRegistry registry = {};
|
||||
registry.panels = {
|
||||
{ "doc-a", "Document A", {}, true, true, true },
|
||||
{ "doc-b", "Document B", {}, true, true, true },
|
||||
{ "details", "Details", {}, true, true, true }
|
||||
};
|
||||
return registry;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceModel BuildWorkspace() {
|
||||
UIEditorWorkspaceModel workspace = {};
|
||||
workspace.root = BuildUIEditorWorkspaceSplit(
|
||||
"root-split",
|
||||
UIEditorWorkspaceSplitAxis::Horizontal,
|
||||
0.66f,
|
||||
BuildUIEditorWorkspaceTabStack(
|
||||
"document-tabs",
|
||||
{
|
||||
BuildUIEditorWorkspacePanel("doc-a-node", "doc-a", "Document A", true),
|
||||
BuildUIEditorWorkspacePanel("doc-b-node", "doc-b", "Document B", true)
|
||||
},
|
||||
0u),
|
||||
BuildUIEditorWorkspacePanel("details-node", "details", "Details", true));
|
||||
workspace.activePanelId = "doc-a";
|
||||
return workspace;
|
||||
}
|
||||
|
||||
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::string JoinVisiblePanelIds(
|
||||
const UIEditorWorkspaceModel& workspace,
|
||||
const UIEditorWorkspaceSession& session) {
|
||||
const auto panels = CollectUIEditorWorkspaceVisiblePanels(workspace, session);
|
||||
if (panels.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
for (std::size_t index = 0; index < panels.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
stream << ", ";
|
||||
}
|
||||
stream << panels[index].panelId;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string DescribePanelState(
|
||||
const UIEditorWorkspaceSession& session,
|
||||
std::string_view panelId,
|
||||
std::string_view displayName) {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, panelId);
|
||||
if (state == nullptr) {
|
||||
return std::string(displayName) + ": missing";
|
||||
}
|
||||
|
||||
std::string visibility = {};
|
||||
if (!state->open) {
|
||||
visibility = "closed";
|
||||
} else if (!state->visible) {
|
||||
visibility = "hidden";
|
||||
} else {
|
||||
visibility = "visible";
|
||||
}
|
||||
|
||||
return std::string(displayName) + ": " + visibility;
|
||||
}
|
||||
|
||||
UIColor ResolvePanelStateColor(
|
||||
const UIEditorWorkspaceSession& session,
|
||||
std::string_view panelId) {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, panelId);
|
||||
if (state == nullptr) {
|
||||
return kDanger;
|
||||
}
|
||||
|
||||
if (!state->open) {
|
||||
return kDanger;
|
||||
}
|
||||
|
||||
if (!state->visible) {
|
||||
return kWarning;
|
||||
}
|
||||
|
||||
return kSuccess;
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string_view title,
|
||||
std::string_view subtitle = {}) {
|
||||
drawList.AddFilledRect(rect, kCardBg, 12.0f);
|
||||
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 12.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 16.0f), std::string(title), kTextPrimary, 17.0f);
|
||||
if (!subtitle.empty()) {
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 42.0f), std::string(subtitle), kTextMuted, 12.0f);
|
||||
}
|
||||
}
|
||||
|
||||
std::string BuildSerializedPreview(std::string_view serializedLayout) {
|
||||
if (serializedLayout.empty()) {
|
||||
return "尚未ä¿<EFBFBD>å˜å¸ƒå±€";
|
||||
}
|
||||
|
||||
std::istringstream stream{ std::string(serializedLayout) };
|
||||
std::ostringstream preview = {};
|
||||
std::string line = {};
|
||||
int lineCount = 0;
|
||||
while (std::getline(stream, line) && lineCount < 4) {
|
||||
if (!line.empty() && line.back() == '\r') {
|
||||
line.pop_back();
|
||||
}
|
||||
if (line.empty()) {
|
||||
continue;
|
||||
}
|
||||
if (lineCount > 0) {
|
||||
preview << " | ";
|
||||
}
|
||||
preview << line;
|
||||
++lineCount;
|
||||
}
|
||||
|
||||
return preview.str();
|
||||
}
|
||||
|
||||
std::string ReplaceActiveRecord(
|
||||
std::string serializedLayout,
|
||||
std::string_view replacementPanelId) {
|
||||
const std::size_t activeStart = serializedLayout.find("active ");
|
||||
if (activeStart == std::string::npos) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const std::size_t lineEnd = serializedLayout.find('\n', activeStart);
|
||||
std::ostringstream replacement = {};
|
||||
replacement << "active " << std::quoted(std::string(replacementPanelId));
|
||||
serializedLayout.replace(
|
||||
activeStart,
|
||||
lineEnd == std::string::npos ? serializedLayout.size() - activeStart : lineEnd - activeStart,
|
||||
replacement.str());
|
||||
return serializedLayout;
|
||||
}
|
||||
|
||||
UIColor ResolveCommandStatusColor(UIEditorWorkspaceCommandStatus status) {
|
||||
switch (status) {
|
||||
case UIEditorWorkspaceCommandStatus::Changed:
|
||||
return kSuccess;
|
||||
case UIEditorWorkspaceCommandStatus::NoOp:
|
||||
return kWarning;
|
||||
case UIEditorWorkspaceCommandStatus::Rejected:
|
||||
return kDanger;
|
||||
}
|
||||
|
||||
return kTextMuted;
|
||||
}
|
||||
|
||||
UIColor ResolveLayoutStatusColor(UIEditorWorkspaceLayoutOperationStatus status) {
|
||||
switch (status) {
|
||||
case UIEditorWorkspaceLayoutOperationStatus::Changed:
|
||||
return kSuccess;
|
||||
case UIEditorWorkspaceLayoutOperationStatus::NoOp:
|
||||
return kWarning;
|
||||
case UIEditorWorkspaceLayoutOperationStatus::Rejected:
|
||||
return kDanger;
|
||||
}
|
||||
|
||||
return kTextMuted;
|
||||
}
|
||||
|
||||
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 = reinterpret_cast<ScenarioApp*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
switch (message) {
|
||||
case WM_SIZE:
|
||||
if (app != nullptr && wParam != SIZE_MINIMIZED) {
|
||||
app->OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||
}
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
if (app != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
app->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandleClick(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (app != nullptr) {
|
||||
if (wParam == VK_F12) {
|
||||
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
} else {
|
||||
app->HandleShortcut(static_cast<UINT>(wParam));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
case WM_DESTROY:
|
||||
if (app != nullptr) {
|
||||
app->m_hwnd = nullptr;
|
||||
}
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_hInstance = hInstance;
|
||||
ResetScenario();
|
||||
|
||||
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,
|
||||
900,
|
||||
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_autoScreenshot.Initialize(
|
||||
(ResolveRepoRootPath() / "tests/UI/Editor/manual_validation/state/layout_persistence/captures")
|
||||
.lexically_normal());
|
||||
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_controller =
|
||||
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
|
||||
m_savedSnapshot = {};
|
||||
m_savedSerializedLayout.clear();
|
||||
m_hasSavedLayout = false;
|
||||
SetCustomResult(
|
||||
"ç‰å¾…æ“<EFBFBD>作",
|
||||
"Pending",
|
||||
"先点 `1 Hide Active`,å†<C3A5>ç‚?`2 Save Layout`ï¼›ä¿<C3A4>å˜å<CB9C>Žç»§ç»æ”¹çжæ€<C3A6>,å†<C3A5>用 `4 Load Layout` 检查æ<C2A5>¢å¤<C3A5>ã€?);
|
||||
}
|
||||
|
||||
void OnResize(UINT width, UINT height) {
|
||||
if (width == 0 || height == 0) {
|
||||
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));
|
||||
|
||||
UIDrawData drawData = {};
|
||||
BuildDrawData(drawData, width, height);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
drawData,
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
framePresented);
|
||||
}
|
||||
|
||||
void HandleClick(float x, float y) {
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
if (button.enabled && ContainsPoint(button.rect, x, y)) {
|
||||
DispatchAction(button.action);
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleShortcut(UINT keyCode) {
|
||||
switch (keyCode) {
|
||||
case '1':
|
||||
DispatchAction(ActionId::HideActive);
|
||||
break;
|
||||
case '2':
|
||||
DispatchAction(ActionId::SaveLayout);
|
||||
break;
|
||||
case '3':
|
||||
DispatchAction(ActionId::CloseDocB);
|
||||
break;
|
||||
case '4':
|
||||
DispatchAction(ActionId::LoadLayout);
|
||||
break;
|
||||
case '5':
|
||||
DispatchAction(ActionId::ActivateDetails);
|
||||
break;
|
||||
case '6':
|
||||
DispatchAction(ActionId::LoadInvalid);
|
||||
break;
|
||||
case 'R':
|
||||
DispatchAction(ActionId::Reset);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void DispatchAction(ActionId action) {
|
||||
switch (action) {
|
||||
case ActionId::HideActive: {
|
||||
UIEditorWorkspaceCommand command = {};
|
||||
command.kind = UIEditorWorkspaceCommandKind::HidePanel;
|
||||
command.panelId = m_controller.GetWorkspace().activePanelId;
|
||||
SetCommandResult("Hide Active", m_controller.Dispatch(command));
|
||||
return;
|
||||
}
|
||||
|
||||
case ActionId::SaveLayout:
|
||||
SaveLayout();
|
||||
return;
|
||||
|
||||
case ActionId::CloseDocB:
|
||||
SetCommandResult(
|
||||
"Close Doc B",
|
||||
m_controller.Dispatch({ UIEditorWorkspaceCommandKind::ClosePanel, "doc-b" }));
|
||||
return;
|
||||
|
||||
case ActionId::LoadLayout:
|
||||
LoadLayout();
|
||||
return;
|
||||
|
||||
case ActionId::ActivateDetails:
|
||||
SetCommandResult(
|
||||
"Activate Details",
|
||||
m_controller.Dispatch({ UIEditorWorkspaceCommandKind::ActivatePanel, "details" }));
|
||||
return;
|
||||
|
||||
case ActionId::LoadInvalid:
|
||||
LoadInvalidLayout();
|
||||
return;
|
||||
|
||||
case ActionId::Reset:
|
||||
SetCommandResult(
|
||||
"Reset",
|
||||
m_controller.Dispatch({ UIEditorWorkspaceCommandKind::ResetWorkspace, {} }));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void SaveLayout() {
|
||||
const auto validation = m_controller.ValidateState();
|
||||
if (!validation.IsValid()) {
|
||||
SetCustomResult(
|
||||
"Save Layout",
|
||||
"Rejected",
|
||||
"当å‰<EFBFBD> controller 状æ€<C3A6>é<EFBFBD>žæ³•,ä¸<C3A4>能ä¿<C3A4>å˜å¸ƒå±€ï¼? + validation.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const UIEditorWorkspaceLayoutSnapshot snapshot = m_controller.CaptureLayoutSnapshot();
|
||||
const std::string serialized = SerializeUIEditorWorkspaceLayoutSnapshot(snapshot);
|
||||
const bool changed = !m_hasSavedLayout || serialized != m_savedSerializedLayout;
|
||||
|
||||
m_savedSnapshot = snapshot;
|
||||
m_savedSerializedLayout = serialized;
|
||||
m_hasSavedLayout = true;
|
||||
SetCustomResult(
|
||||
"Save Layout",
|
||||
changed ? "Saved" : "NoOp",
|
||||
changed
|
||||
? "已更新ä¿<EFBFBD>å˜çš„布局快照。接下æ<EFBFBD>¥ç»§ç»æ”¹çжæ€<EFBFBD>,å†<EFBFBD>点 `Load Layout` 检查æ<C2A5>¢å¤<C3A5>ã€?
|
||||
: "ä¿<EFBFBD>å˜å†…容与当å‰<EFBFBD>å·²ä¿<EFBFBD>å˜å¸ƒå±€ä¸€è‡´ã€?);
|
||||
}
|
||||
|
||||
void LoadLayout() {
|
||||
if (!m_hasSavedLayout) {
|
||||
SetCustomResult("Load Layout", "Rejected", "当å‰<EFBFBD>还没有ä¿<EFBFBD>å˜è¿‡å¸ƒå±€ã€?);
|
||||
return;
|
||||
}
|
||||
|
||||
SetLayoutResult("Load Layout", m_controller.RestoreSerializedLayout(m_savedSerializedLayout));
|
||||
}
|
||||
|
||||
void LoadInvalidLayout() {
|
||||
const auto validation = m_controller.ValidateState();
|
||||
if (!validation.IsValid()) {
|
||||
SetCustomResult(
|
||||
"Load Invalid",
|
||||
"Rejected",
|
||||
"当å‰<EFBFBD> controller 状æ€<C3A6>é<EFBFBD>žæ³•ï¼Œæ— æ³•æž„é€?invalid payloadï¼? + validation.message);
|
||||
return;
|
||||
}
|
||||
|
||||
const std::string source =
|
||||
m_hasSavedLayout
|
||||
? m_savedSerializedLayout
|
||||
: SerializeUIEditorWorkspaceLayoutSnapshot(m_controller.CaptureLayoutSnapshot());
|
||||
const std::string invalidSerialized = ReplaceActiveRecord(source, "missing-panel");
|
||||
if (invalidSerialized.empty()) {
|
||||
SetCustomResult("Load Invalid", "Rejected", "构�invalid payload 失败�);
|
||||
return;
|
||||
}
|
||||
|
||||
SetLayoutResult("Load Invalid", m_controller.RestoreSerializedLayout(invalidSerialized));
|
||||
}
|
||||
|
||||
void SetCommandResult(
|
||||
std::string actionName,
|
||||
const UIEditorWorkspaceCommandResult& result) {
|
||||
m_lastActionName = std::move(actionName);
|
||||
m_lastStatusLabel = std::string(GetUIEditorWorkspaceCommandStatusName(result.status));
|
||||
m_lastMessage = result.message;
|
||||
m_lastStatusColor = ResolveCommandStatusColor(result.status);
|
||||
}
|
||||
|
||||
void SetLayoutResult(
|
||||
std::string actionName,
|
||||
const UIEditorWorkspaceLayoutOperationResult& result) {
|
||||
m_lastActionName = std::move(actionName);
|
||||
m_lastStatusLabel = std::string(GetUIEditorWorkspaceLayoutOperationStatusName(result.status));
|
||||
m_lastMessage = result.message;
|
||||
m_lastStatusColor = ResolveLayoutStatusColor(result.status);
|
||||
}
|
||||
|
||||
void SetCustomResult(
|
||||
std::string actionName,
|
||||
std::string statusLabel,
|
||||
std::string message) {
|
||||
m_lastActionName = std::move(actionName);
|
||||
m_lastStatusLabel = std::move(statusLabel);
|
||||
m_lastMessage = std::move(message);
|
||||
if (m_lastStatusLabel == "Rejected") {
|
||||
m_lastStatusColor = kDanger;
|
||||
} else if (m_lastStatusLabel == "NoOp") {
|
||||
m_lastStatusColor = kWarning;
|
||||
} else if (m_lastStatusLabel == "Pending") {
|
||||
m_lastStatusColor = kTextMuted;
|
||||
} else {
|
||||
m_lastStatusColor = kSuccess;
|
||||
}
|
||||
}
|
||||
|
||||
bool IsButtonEnabled(ActionId action) const {
|
||||
const UIEditorWorkspaceModel& workspace = m_controller.GetWorkspace();
|
||||
const UIEditorWorkspaceSession& session = m_controller.GetSession();
|
||||
|
||||
switch (action) {
|
||||
case ActionId::HideActive: {
|
||||
if (workspace.activePanelId.empty()) {
|
||||
return false;
|
||||
}
|
||||
const auto* state = FindUIEditorPanelSessionState(session, workspace.activePanelId);
|
||||
return state != nullptr && state->open && state->visible;
|
||||
}
|
||||
|
||||
case ActionId::SaveLayout:
|
||||
return m_controller.ValidateState().IsValid();
|
||||
|
||||
case ActionId::CloseDocB: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "doc-b");
|
||||
return state != nullptr && state->open;
|
||||
}
|
||||
|
||||
case ActionId::LoadLayout:
|
||||
return m_hasSavedLayout;
|
||||
|
||||
case ActionId::ActivateDetails: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "details");
|
||||
return state != nullptr &&
|
||||
state->open &&
|
||||
state->visible &&
|
||||
workspace.activePanelId != "details";
|
||||
}
|
||||
|
||||
case ActionId::LoadInvalid:
|
||||
return m_controller.ValidateState().IsValid();
|
||||
|
||||
case ActionId::Reset:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void DrawPanelStateRows(
|
||||
UIDrawList& drawList,
|
||||
float startX,
|
||||
float startY,
|
||||
float width,
|
||||
const UIEditorWorkspaceSession& session,
|
||||
std::string_view activePanelId) {
|
||||
const std::vector<std::pair<std::string, std::string>> panelDefs = {
|
||||
{ "doc-a", "Document A" },
|
||||
{ "doc-b", "Document B" },
|
||||
{ "details", "Details" }
|
||||
};
|
||||
|
||||
float rowY = startY;
|
||||
for (const auto& [panelId, label] : panelDefs) {
|
||||
const UIRect rowRect(startX, rowY, width, 54.0f);
|
||||
drawList.AddFilledRect(rowRect, kPanelRowBg, 8.0f);
|
||||
drawList.AddRectOutline(rowRect, kCardBorder, 1.0f, 8.0f);
|
||||
drawList.AddFilledRect(
|
||||
UIRect(rowRect.x + 12.0f, rowRect.y + 15.0f, 10.0f, 10.0f),
|
||||
ResolvePanelStateColor(session, panelId),
|
||||
5.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(rowRect.x + 32.0f, rowRect.y + 11.0f),
|
||||
DescribePanelState(session, panelId, label),
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
const bool active = activePanelId == panelId;
|
||||
drawList.AddText(
|
||||
UIPoint(rowRect.x + 32.0f, rowRect.y + 31.0f),
|
||||
active ? "active = true" : "active = false",
|
||||
active ? kAccent : kTextMuted,
|
||||
12.0f);
|
||||
rowY += 64.0f;
|
||||
}
|
||||
}
|
||||
|
||||
void BuildDrawData(UIDrawData& drawData, float width, float height) {
|
||||
const UIEditorWorkspaceModel& workspace = m_controller.GetWorkspace();
|
||||
const UIEditorWorkspaceSession& session = m_controller.GetSession();
|
||||
const auto validation = m_controller.ValidateState();
|
||||
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("Editor Layout Persistence");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
const float margin = 20.0f;
|
||||
const UIRect headerRect(margin, margin, width - margin * 2.0f, 178.0f);
|
||||
const UIRect actionRect(margin, headerRect.y + headerRect.height + 16.0f, 320.0f, height - 254.0f);
|
||||
const UIRect stateRect(actionRect.x + actionRect.width + 16.0f, actionRect.y, width - actionRect.width - margin * 2.0f - 16.0f, height - 254.0f);
|
||||
const UIRect footerRect(margin, height - 100.0f, width - margin * 2.0f, 80.0f);
|
||||
|
||||
DrawCard(drawList, headerRect, "测试功能:Editor Layout Persistence", "å<EFBFBD>ªéªŒè¯?Save / Load / Load Invalid / Reset 的布局æ<E282AC>¢å¤<C3A5>链路;ä¸<C3A4>验è¯<C3A8>业务é<C2A1>¢æ<C2A2>¿ã€?);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 70.0f), "1. ç‚?`1 Hide Active`,把 Document A éš<C3A9>è—<C3A8>ï¼›active 应切åˆ?`doc-b`,visible 应å<E2809D>˜æˆ?`doc-b, details`ã€?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 92.0f), "2. ç‚?`2 Save Layout` ä¿<C3A4>å˜å½“å‰<C3A5>布局;å<E280BA>³ä¾?Saved 摘è¦<C3A8>必须记录刚æ‰<C3A6>çš?active/visibleã€?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 114.0f), "3. å†<C3A5>点 `3 Close Doc B` æˆ?`5 Activate Details` 改状æ€<C3A6>,然å<C2B6>Žç‚?`4 Load Layout`;当å‰<C3A5>状æ€<C3A6>å¿…é¡»æ<C2BB>¢å¤<C3A5>到ä¿<C3A4>å˜æ—¶ã€?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 136.0f), "4. ç‚?`6 Load Invalid`,Result å¿…é¡»æ˜?Rejected,且当å‰<C3A5> active/visible ä¸<C3A4>得被污染ã€?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 158.0f), "5. `R Reset` 必须回到基线 active=doc-a;按 `F12` ä¿<C3A4>å˜å½“å‰<C3A5>窗å<E28094>£æˆªå›¾ã€?, kTextPrimary, 13.0f);
|
||||
|
||||
DrawCard(drawList, actionRect, "æ“<EFBFBD>作åŒ?, "这里å<EFBFBD>ªä¿<EFBFBD>留这一æ¥éœ€è¦<EFBFBD>检查的布局ä¿<EFBFBD>å˜/æ<EFBFBD>¢å¤<EFBFBD>动作ã€?);
|
||||
DrawCard(drawList, stateRect, "状æ€<EFBFBD>摘è¦?, "左侧çœ?Current,å<EFBFBD>³ä¾§çœ‹ Savedï¼›é‡<EFBFBD>点检æŸ?activeã€<EFBFBD>visible å’Œå<EFBFBD><EFBFBD>æ•°æ<EFBFBD>®æ<EFBFBD>¢å¤<EFBFBD>ã€?);
|
||||
DrawCard(drawList, footerRect, "最近结æž?, "显示最近一次æ“<EFBFBD>作ã€<EFBFBD>状æ€<EFBFBD>和当å‰<EFBFBD> validationã€?);
|
||||
|
||||
m_buttons.clear();
|
||||
const std::vector<std::pair<ActionId, std::string>> buttonDefs = {
|
||||
{ ActionId::HideActive, "1 Hide Active" },
|
||||
{ ActionId::SaveLayout, "2 Save Layout" },
|
||||
{ ActionId::CloseDocB, "3 Close Doc B" },
|
||||
{ ActionId::LoadLayout, "4 Load Layout" },
|
||||
{ ActionId::ActivateDetails, "5 Activate Details" },
|
||||
{ ActionId::LoadInvalid, "6 Load Invalid" },
|
||||
{ ActionId::Reset, "R Reset" }
|
||||
};
|
||||
|
||||
float buttonY = actionRect.y + 72.0f;
|
||||
for (const auto& [action, label] : buttonDefs) {
|
||||
ButtonState button = {};
|
||||
button.action = action;
|
||||
button.label = label;
|
||||
button.rect = UIRect(actionRect.x + 18.0f, buttonY, actionRect.width - 36.0f, 46.0f);
|
||||
button.enabled = IsButtonEnabled(action);
|
||||
m_buttons.push_back(button);
|
||||
|
||||
drawList.AddFilledRect(
|
||||
button.rect,
|
||||
button.enabled ? kButtonEnabled : kButtonDisabled,
|
||||
8.0f);
|
||||
drawList.AddRectOutline(button.rect, kButtonBorder, 1.0f, 8.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(button.rect.x + 14.0f, button.rect.y + 13.0f),
|
||||
button.label,
|
||||
button.enabled ? kTextPrimary : kTextMuted,
|
||||
13.0f);
|
||||
buttonY += 58.0f;
|
||||
}
|
||||
|
||||
const float columnGap = 20.0f;
|
||||
const float contentLeft = stateRect.x + 18.0f;
|
||||
const float columnWidth = (stateRect.width - 36.0f - columnGap) * 0.5f;
|
||||
const float rightColumnX = contentLeft + columnWidth + columnGap;
|
||||
|
||||
drawList.AddText(UIPoint(contentLeft, stateRect.y + 70.0f), "Current", kAccent, 15.0f);
|
||||
drawList.AddText(UIPoint(contentLeft, stateRect.y + 96.0f), "active panel", kTextMuted, 12.0f);
|
||||
drawList.AddText(UIPoint(contentLeft, stateRect.y + 116.0f), workspace.activePanelId.empty() ? "(none)" : workspace.activePanelId, kTextPrimary, 14.0f);
|
||||
drawList.AddText(UIPoint(contentLeft, stateRect.y + 148.0f), "visible panels", kTextMuted, 12.0f);
|
||||
drawList.AddText(UIPoint(contentLeft, stateRect.y + 168.0f), JoinVisiblePanelIds(workspace, session), kTextPrimary, 14.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(contentLeft, stateRect.y + 198.0f),
|
||||
validation.IsValid() ? "validation = OK" : "validation = " + validation.message,
|
||||
validation.IsValid() ? kSuccess : kDanger,
|
||||
12.0f);
|
||||
DrawPanelStateRows(drawList, contentLeft, stateRect.y + 236.0f, columnWidth, session, workspace.activePanelId);
|
||||
|
||||
drawList.AddText(UIPoint(rightColumnX, stateRect.y + 70.0f), "Saved", kAccent, 15.0f);
|
||||
if (!m_hasSavedLayout) {
|
||||
drawList.AddText(UIPoint(rightColumnX, stateRect.y + 104.0f), "尚未执行 Save Layout�, kTextMuted, 13.0f);
|
||||
drawList.AddText(UIPoint(rightColumnX, stateRect.y + 128.0f), "先把状æ€<EFBFBD>改掉,å†<EFBFBD>ä¿<EFBFBD>å˜ï¼Œè¿™æ · Load æ‰<C3A6>有æ<E280B0>¢å¤<C3A5>æ„<C3A6>义ã€?, kTextMuted, 12.0f);
|
||||
} else {
|
||||
drawList.AddText(UIPoint(rightColumnX, stateRect.y + 96.0f), "active panel", kTextMuted, 12.0f);
|
||||
drawList.AddText(UIPoint(rightColumnX, stateRect.y + 116.0f), m_savedSnapshot.workspace.activePanelId.empty() ? "(none)" : m_savedSnapshot.workspace.activePanelId, kTextPrimary, 14.0f);
|
||||
drawList.AddText(UIPoint(rightColumnX, stateRect.y + 148.0f), "visible panels", kTextMuted, 12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(rightColumnX, stateRect.y + 168.0f),
|
||||
JoinVisiblePanelIds(m_savedSnapshot.workspace, m_savedSnapshot.session),
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
drawList.AddText(UIPoint(rightColumnX, stateRect.y + 198.0f), "payload preview", kTextMuted, 12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(rightColumnX, stateRect.y + 220.0f),
|
||||
BuildSerializedPreview(m_savedSerializedLayout),
|
||||
kTextPrimary,
|
||||
12.0f);
|
||||
}
|
||||
|
||||
drawList.AddText(
|
||||
UIPoint(footerRect.x + 18.0f, footerRect.y + 28.0f),
|
||||
"Last operation: " + m_lastActionName + " | Result: " + m_lastStatusLabel,
|
||||
m_lastStatusColor,
|
||||
13.0f);
|
||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 48.0f), m_lastMessage, kTextPrimary, 12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(footerRect.x + 18.0f, footerRect.y + 66.0f),
|
||||
validation.IsValid() ? "Validation: OK" : "Validation: " + validation.message,
|
||||
validation.IsValid() ? kSuccess : kDanger,
|
||||
12.0f);
|
||||
|
||||
const std::string captureSummary =
|
||||
m_autoScreenshot.HasPendingCapture()
|
||||
? "截图排队�.."
|
||||
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||
? std::string("F12 -> tests/UI/Editor/manual_validation/state/layout_persistence/captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary());
|
||||
drawList.AddText(UIPoint(footerRect.x + 760.0f, footerRect.y + 66.0f), captureSummary, kTextMuted, 12.0f);
|
||||
}
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
HINSTANCE m_hInstance = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
NativeRenderer m_renderer = {};
|
||||
AutoScreenshotController m_autoScreenshot = {};
|
||||
UIEditorWorkspaceController m_controller = {};
|
||||
UIEditorWorkspaceLayoutSnapshot m_savedSnapshot = {};
|
||||
std::string m_savedSerializedLayout = {};
|
||||
bool m_hasSavedLayout = false;
|
||||
std::vector<ButtonState> m_buttons = {};
|
||||
std::string m_lastActionName = {};
|
||||
std::string m_lastStatusLabel = {};
|
||||
std::string m_lastMessage = {};
|
||||
UIColor m_lastStatusColor = kTextMuted;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
ScenarioApp app;
|
||||
return app.Run(hInstance, nCmdShow);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
add_executable(editor_ui_panel_host_lifecycle_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
xcengine_configure_editor_ui_integration_validation_target(
|
||||
editor_ui_panel_host_lifecycle_validation
|
||||
OUTPUT_NAME "XCUIEditorPanelHostLifecycleValidation"
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,664 +0,0 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEditor/Panels/UIEditorPanelHostLifecycle.h>
|
||||
#include <XCEditor/Workspace/UIEditorWorkspaceController.h>
|
||||
#include "Rendering/Native/AutoScreenshot.h"
|
||||
#include "Rendering/Native/NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceSplit;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceTabStack;
|
||||
using XCEngine::UI::Editor::CollectUIEditorWorkspaceVisiblePanels;
|
||||
using XCEngine::UI::Editor::FindUIEditorPanelHostState;
|
||||
using XCEngine::UI::Editor::GetUIEditorPanelHostLifecycleEventKindName;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceCommandStatusName;
|
||||
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||
using XCEngine::UI::Editor::UIEditorPanelHostLifecycleFrame;
|
||||
using XCEngine::UI::Editor::UIEditorPanelHostLifecycleRequest;
|
||||
using XCEngine::UI::Editor::UIEditorPanelHostLifecycleState;
|
||||
using XCEngine::UI::Editor::UIEditorPanelRegistry;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommand;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandKind;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceModel;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceSplitAxis;
|
||||
using XCEngine::UI::Editor::UpdateUIEditorPanelHostLifecycle;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorPanelHostLifecycleValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | Panel Host Lifecycle";
|
||||
|
||||
constexpr UIColor kWindowBg(0.12f, 0.12f, 0.12f, 1.0f);
|
||||
constexpr UIColor kCardBg(0.18f, 0.18f, 0.18f, 1.0f);
|
||||
constexpr UIColor kCardBorder(0.29f, 0.29f, 0.29f, 1.0f);
|
||||
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
|
||||
constexpr UIColor kTextMuted(0.72f, 0.72f, 0.72f, 1.0f);
|
||||
constexpr UIColor kTextWeak(0.56f, 0.56f, 0.56f, 1.0f);
|
||||
constexpr UIColor kSuccess(0.45f, 0.72f, 0.49f, 1.0f);
|
||||
constexpr UIColor kWarning(0.81f, 0.67f, 0.35f, 1.0f);
|
||||
constexpr UIColor kDanger(0.78f, 0.36f, 0.36f, 1.0f);
|
||||
constexpr UIColor kAccent(0.68f, 0.72f, 0.78f, 1.0f);
|
||||
constexpr UIColor kButtonBg(0.25f, 0.25f, 0.25f, 1.0f);
|
||||
constexpr UIColor kButtonHover(0.33f, 0.33f, 0.33f, 1.0f);
|
||||
constexpr UIColor kButtonBorder(0.46f, 0.46f, 0.46f, 1.0f);
|
||||
constexpr UIColor kPreviewCard(0.15f, 0.15f, 0.15f, 1.0f);
|
||||
constexpr UIColor kAttachedBorder(0.54f, 0.64f, 0.74f, 1.0f);
|
||||
constexpr UIColor kVisibleBorder(0.46f, 0.72f, 0.50f, 1.0f);
|
||||
constexpr UIColor kActiveBorder(0.86f, 0.76f, 0.46f, 1.0f);
|
||||
|
||||
enum class ActionId : unsigned char {
|
||||
HideActive = 0,
|
||||
CloseDocB,
|
||||
OpenDocB,
|
||||
ActivateDetails,
|
||||
FocusActive,
|
||||
ClearFocus,
|
||||
Reset,
|
||||
Capture
|
||||
};
|
||||
|
||||
struct ButtonState {
|
||||
ActionId action = ActionId::HideActive;
|
||||
std::string label = {};
|
||||
UIRect rect = {};
|
||||
bool hovered = false;
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
UIEditorPanelRegistry BuildPanelRegistry() {
|
||||
UIEditorPanelRegistry registry = {};
|
||||
registry.panels = {
|
||||
{ "doc-a", "Document A", {}, true, true, true },
|
||||
{ "doc-b", "Document B", {}, true, true, true },
|
||||
{ "details", "Details", {}, true, true, true }
|
||||
};
|
||||
return registry;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceModel BuildWorkspace() {
|
||||
UIEditorWorkspaceModel workspace = {};
|
||||
workspace.root = BuildUIEditorWorkspaceSplit(
|
||||
"root-split",
|
||||
UIEditorWorkspaceSplitAxis::Horizontal,
|
||||
0.66f,
|
||||
BuildUIEditorWorkspaceTabStack(
|
||||
"document-tabs",
|
||||
{
|
||||
BuildUIEditorWorkspacePanel("doc-a-node", "doc-a", "Document A", true),
|
||||
BuildUIEditorWorkspacePanel("doc-b-node", "doc-b", "Document B", true)
|
||||
},
|
||||
0u),
|
||||
BuildUIEditorWorkspacePanel("details-node", "details", "Details", true));
|
||||
workspace.activePanelId = "doc-a";
|
||||
return workspace;
|
||||
}
|
||||
|
||||
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::string JoinVisiblePanelIds(const UIEditorWorkspaceController& controller) {
|
||||
const auto panels =
|
||||
CollectUIEditorWorkspaceVisiblePanels(controller.GetWorkspace(), controller.GetSession());
|
||||
if (panels.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::ostringstream stream = {};
|
||||
for (std::size_t index = 0; index < panels.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
stream << ", ";
|
||||
}
|
||||
stream << panels[index].panelId;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string FormatBool(bool value) {
|
||||
return value ? "true" : "false";
|
||||
}
|
||||
|
||||
std::string FormatEvents(const UIEditorPanelHostLifecycleFrame& frame) {
|
||||
if (frame.events.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::ostringstream stream = {};
|
||||
for (std::size_t index = 0; index < frame.events.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
stream << " | ";
|
||||
}
|
||||
stream << GetUIEditorPanelHostLifecycleEventKindName(frame.events[index].kind)
|
||||
<< ":" << frame.events[index].panelId;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
UIColor ResolveFlagColor(bool value, const UIColor& onColor) {
|
||||
return value ? onColor : kTextWeak;
|
||||
}
|
||||
|
||||
UIColor ResolveHostBorderColor(bool attached, bool visible, bool active, bool focused) {
|
||||
if (focused) {
|
||||
return kActiveBorder;
|
||||
}
|
||||
if (active) {
|
||||
return kActiveBorder;
|
||||
}
|
||||
if (visible) {
|
||||
return kVisibleBorder;
|
||||
}
|
||||
if (attached) {
|
||||
return kAttachedBorder;
|
||||
}
|
||||
return kCardBorder;
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string_view title,
|
||||
std::string_view subtitle = {}) {
|
||||
drawList.AddFilledRect(rect, kCardBg, 12.0f);
|
||||
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 12.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 16.0f), std::string(title), kTextPrimary, 17.0f);
|
||||
if (!subtitle.empty()) {
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 42.0f), std::string(subtitle), kTextMuted, 12.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawButton(UIDrawList& drawList, const ButtonState& button) {
|
||||
drawList.AddFilledRect(button.rect, button.hovered ? kButtonHover : kButtonBg, 8.0f);
|
||||
drawList.AddRectOutline(button.rect, kButtonBorder, 1.0f, 8.0f);
|
||||
drawList.AddText(UIPoint(button.rect.x + 12.0f, button.rect.y + 10.0f), button.label, kTextPrimary, 12.0f);
|
||||
}
|
||||
|
||||
void DrawHostStateCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string_view title,
|
||||
const XCEngine::UI::Editor::UIEditorPanelHostState* state) {
|
||||
const bool attached = state != nullptr && state->attached;
|
||||
const bool visible = state != nullptr && state->visible;
|
||||
const bool active = state != nullptr && state->active;
|
||||
const bool focused = state != nullptr && state->focused;
|
||||
|
||||
drawList.AddFilledRect(rect, kPreviewCard, 10.0f);
|
||||
drawList.AddRectOutline(
|
||||
rect,
|
||||
ResolveHostBorderColor(attached, visible, active, focused),
|
||||
active || focused ? 2.0f : 1.0f,
|
||||
10.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 14.0f), std::string(title), kTextPrimary, 16.0f);
|
||||
|
||||
float lineY = rect.y + 48.0f;
|
||||
auto addFlag = [&](std::string_view label, bool value, const UIColor& color) {
|
||||
drawList.AddText(
|
||||
UIPoint(rect.x + 16.0f, lineY),
|
||||
std::string(label) + ": " + (value ? "true" : "false"),
|
||||
ResolveFlagColor(value, color),
|
||||
12.0f);
|
||||
lineY += 22.0f;
|
||||
};
|
||||
|
||||
addFlag("Attached", attached, kAccent);
|
||||
addFlag("Visible", visible, kSuccess);
|
||||
addFlag("Active", active, kWarning);
|
||||
addFlag("Focused", focused, kActiveBorder);
|
||||
|
||||
std::string footer = {};
|
||||
if (!attached) {
|
||||
footer = "host å·?detached";
|
||||
} else if (!visible) {
|
||||
footer = "host ä¿<C3A4>æŒ<C3A6> attached,但当å‰<C3A5>ä¸<C3A4>在å±<C3A5>幕ä¸?;
|
||||
} else if (focused) {
|
||||
footer = "当å‰<EFBFBD> host å·?visible + active + focused";
|
||||
} else if (active) {
|
||||
footer = "当å‰<EFBFBD> host å·?active,但还没 focus";
|
||||
} else {
|
||||
footer = "当å‰<EFBFBD> host å<>ªå¤„äº?attached/visible";
|
||||
}
|
||||
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + rect.height - 26.0f), footer, kTextMuted, 11.0f);
|
||||
}
|
||||
|
||||
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 = reinterpret_cast<ScenarioApp*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
switch (message) {
|
||||
case WM_SIZE:
|
||||
if (app != nullptr && wParam != SIZE_MINIMIZED) {
|
||||
app->OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||
}
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
if (app != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
app->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MOUSEMOVE:
|
||||
if (app != nullptr) {
|
||||
app->HandleMouseMove(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandleClick(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (app != nullptr && wParam == VK_F12) {
|
||||
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
case WM_DESTROY:
|
||||
if (app != nullptr) {
|
||||
app->m_hwnd = nullptr;
|
||||
}
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_hInstance = hInstance;
|
||||
ResetScenario();
|
||||
|
||||
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,
|
||||
1440,
|
||||
920,
|
||||
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_captureRoot =
|
||||
ResolveRepoRootPath() /
|
||||
"tests/UI/Editor/manual_validation/state/panel_host_lifecycle/captures";
|
||||
m_autoScreenshot.Initialize(m_captureRoot);
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
m_autoScreenshot.Shutdown();
|
||||
m_renderer.Shutdown();
|
||||
|
||||
if (m_hwnd != nullptr) {
|
||||
DestroyWindow(m_hwnd);
|
||||
m_hwnd = nullptr;
|
||||
}
|
||||
|
||||
if (m_windowClassAtom != 0) {
|
||||
UnregisterClassW(kWindowClassName, m_hInstance);
|
||||
m_windowClassAtom = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ResetScenario() {
|
||||
m_controller =
|
||||
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
|
||||
m_lifecycleState = {};
|
||||
m_focusRequestPanelId.clear();
|
||||
RefreshLifecycle(
|
||||
"Ready",
|
||||
"å·²é‡<EFBFBD>置。先çœ?doc-b:它默认æ˜?attachedï¼Œä½†å› ä¸ºä¸<C3A4>æ˜¯é€‰ä¸ tab,所ä»?visible=falseã€?);
|
||||
}
|
||||
|
||||
void RefreshLifecycle(std::string status, std::string message) {
|
||||
m_lifecycleFrame = UpdateUIEditorPanelHostLifecycle(
|
||||
m_lifecycleState,
|
||||
m_controller.GetPanelRegistry(),
|
||||
m_controller.GetWorkspace(),
|
||||
m_controller.GetSession(),
|
||||
UIEditorPanelHostLifecycleRequest{ m_focusRequestPanelId });
|
||||
m_lastStatus = std::move(status);
|
||||
m_lastMessage = std::move(message);
|
||||
}
|
||||
|
||||
void UpdateLayout() {
|
||||
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));
|
||||
|
||||
constexpr float padding = 20.0f;
|
||||
constexpr float leftWidth = 440.0f;
|
||||
m_introRect = UIRect(padding, padding, leftWidth, 208.0f);
|
||||
m_controlsRect = UIRect(padding, 244.0f, leftWidth, 244.0f);
|
||||
m_stateRect = UIRect(padding, 504.0f, leftWidth, height - 524.0f);
|
||||
m_previewRect = UIRect(leftWidth + padding * 2.0f, padding, width - leftWidth - padding * 3.0f, height - padding * 2.0f);
|
||||
|
||||
const float buttonLeft = m_controlsRect.x + 16.0f;
|
||||
const float buttonTop = m_controlsRect.y + 62.0f;
|
||||
const float buttonWidth = (m_controlsRect.width - 32.0f - 16.0f) * 0.5f;
|
||||
const float buttonHeight = 34.0f;
|
||||
const float rowGap = 10.0f;
|
||||
m_buttons = {
|
||||
{ ActionId::HideActive, "Hide Active", UIRect(buttonLeft, buttonTop, buttonWidth, buttonHeight), false },
|
||||
{ ActionId::CloseDocB, "Close Doc B", UIRect(buttonLeft + buttonWidth + 16.0f, buttonTop, buttonWidth, buttonHeight), false },
|
||||
{ ActionId::OpenDocB, "Open Doc B", UIRect(buttonLeft, buttonTop + buttonHeight + rowGap, buttonWidth, buttonHeight), false },
|
||||
{ ActionId::ActivateDetails, "Activate Details", UIRect(buttonLeft + buttonWidth + 16.0f, buttonTop + buttonHeight + rowGap, buttonWidth, buttonHeight), false },
|
||||
{ ActionId::FocusActive, "Focus Active", UIRect(buttonLeft, buttonTop + (buttonHeight + rowGap) * 2.0f, buttonWidth, buttonHeight), false },
|
||||
{ ActionId::ClearFocus, "Clear Focus", UIRect(buttonLeft + buttonWidth + 16.0f, buttonTop + (buttonHeight + rowGap) * 2.0f, buttonWidth, buttonHeight), false },
|
||||
{ ActionId::Reset, "Reset", UIRect(buttonLeft, buttonTop + (buttonHeight + rowGap) * 3.0f, buttonWidth, buttonHeight), false },
|
||||
{ ActionId::Capture, "Capture(F12)", UIRect(buttonLeft + buttonWidth + 16.0f, buttonTop + (buttonHeight + rowGap) * 3.0f, buttonWidth, buttonHeight), false }
|
||||
};
|
||||
|
||||
const float previewPadding = 24.0f;
|
||||
const float hostCardGap = 18.0f;
|
||||
const float docWidth = (m_previewRect.width - previewPadding * 2.0f - hostCardGap) * 0.56f;
|
||||
const float sideWidth = m_previewRect.width - previewPadding * 2.0f - hostCardGap - docWidth;
|
||||
const float cardTop = m_previewRect.y + 76.0f;
|
||||
const float cardHeight = (m_previewRect.height - 116.0f - hostCardGap) * 0.5f;
|
||||
m_docARect = UIRect(m_previewRect.x + previewPadding, cardTop, docWidth, cardHeight);
|
||||
m_docBRect = UIRect(m_previewRect.x + previewPadding, cardTop + cardHeight + hostCardGap, docWidth, cardHeight);
|
||||
m_detailsRect = UIRect(m_docARect.x + docWidth + hostCardGap, cardTop, sideWidth, cardHeight * 2.0f + hostCardGap);
|
||||
}
|
||||
|
||||
void OnResize(UINT width, UINT height) {
|
||||
m_renderer.Resize(width, height);
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void HandleMouseMove(float x, float y) {
|
||||
UpdateLayout();
|
||||
for (ButtonState& button : m_buttons) {
|
||||
button.hovered = ContainsPoint(button.rect, x, y);
|
||||
}
|
||||
}
|
||||
|
||||
void HandleClick(float x, float y) {
|
||||
UpdateLayout();
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
if (ContainsPoint(button.rect, x, y)) {
|
||||
ExecuteAction(button.action);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ExecuteAction(ActionId action) {
|
||||
if (action == ActionId::Reset) {
|
||||
ResetScenario();
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == ActionId::Capture) {
|
||||
m_autoScreenshot.RequestCapture("manual_button");
|
||||
m_lastStatus = "Ready";
|
||||
m_lastMessage =
|
||||
"截图已排队,输出�tests/UI/Editor/manual_validation/state/panel_host_lifecycle/captures/�;
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == ActionId::FocusActive) {
|
||||
m_focusRequestPanelId = m_controller.GetWorkspace().activePanelId;
|
||||
RefreshLifecycle(
|
||||
"Focus",
|
||||
m_focusRequestPanelId.empty()
|
||||
? "当å‰<EFBFBD>没有 active panel å<>?focusã€?
|
||||
: "已把 focus request 指å<E280A1>‘当å‰<C3A5> active panelã€?);
|
||||
return;
|
||||
}
|
||||
|
||||
if (action == ActionId::ClearFocus) {
|
||||
m_focusRequestPanelId.clear();
|
||||
RefreshLifecycle("Focus", "已清�focus request�);
|
||||
return;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceCommand command = {};
|
||||
switch (action) {
|
||||
case ActionId::HideActive:
|
||||
command.kind = UIEditorWorkspaceCommandKind::HidePanel;
|
||||
command.panelId = m_controller.GetWorkspace().activePanelId;
|
||||
break;
|
||||
case ActionId::CloseDocB:
|
||||
command.kind = UIEditorWorkspaceCommandKind::ClosePanel;
|
||||
command.panelId = "doc-b";
|
||||
break;
|
||||
case ActionId::OpenDocB:
|
||||
command.kind = UIEditorWorkspaceCommandKind::OpenPanel;
|
||||
command.panelId = "doc-b";
|
||||
break;
|
||||
case ActionId::ActivateDetails:
|
||||
command.kind = UIEditorWorkspaceCommandKind::ActivatePanel;
|
||||
command.panelId = "details";
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
const auto result = m_controller.Dispatch(command);
|
||||
RefreshLifecycle(
|
||||
std::string(GetUIEditorWorkspaceCommandStatusName(result.status)),
|
||||
result.message);
|
||||
}
|
||||
|
||||
void RenderFrame() {
|
||||
UpdateLayout();
|
||||
|
||||
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));
|
||||
|
||||
UIDrawData drawData = {};
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("PanelHostLifecycle");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
m_introRect,
|
||||
"这个测试验è¯<EFBFBD>什么功能?",
|
||||
"å<EFBFBD>ªéªŒè¯?Editor panel host lifecycle contract,ä¸<C3A4>å<EFBFBD>šä¸šåŠ¡é<C2A1>¢æ<C2A2>¿ã€?);
|
||||
drawList.AddText(UIPoint(m_introRect.x + 18.0f, m_introRect.y + 72.0f), "1. 验è¯<C3A8> attach/detach ç”?panel open/close 驱动,而ä¸<C3A4>是由 visible 驱动ã€?, kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(m_introRect.x + 18.0f, m_introRect.y + 94.0f), "2. 验è¯<C3A8>é<EFBFBD>žé€‰ä¸ tab ä¾<C3A4>ç„¶ attached,但 visible=falseã€?, kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(m_introRect.x + 18.0f, m_introRect.y + 116.0f), "3. 验è¯<C3A8> active å’?focused 是两层ä¸<C3A4>å<EFBFBD>Œçжæ€<C3A6>,focus 由外éƒ?request 决定ã€?, kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(m_introRect.x + 18.0f, m_introRect.y + 138.0f), "4. 验è¯<C3A8> hide/close/reopen/activate 会输出稳定的 lifecycle eventsã€?, kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(m_introRect.x + 18.0f, m_introRect.y + 164.0f), "建议æ“<EFBFBD>作:先çœ?doc-b 默认 attached ä½?hiddenï¼›å†<C3A5>ç‚?Hide Active / Focus Active / Close Doc B / Open Doc Bã€?, kTextWeak, 11.0f);
|
||||
|
||||
DrawCard(drawList, m_controlsRect, "æ“<EFBFBD>作", "å<EFBFBD>ªä¿<EFBFBD>留这ç»?contract å¿…è¦<C3A8>的按钮ã€?);
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
DrawButton(drawList, button);
|
||||
}
|
||||
|
||||
DrawCard(drawList, m_stateRect, "状æ€?, "é‡<EFBFBD>点检æŸ?host flags 和本å¸?lifecycle eventsã€?);
|
||||
float stateY = m_stateRect.y + 66.0f;
|
||||
auto addStateLine = [&](std::string label, std::string value, const UIColor& color, float fontSize = 12.0f) {
|
||||
drawList.AddText(UIPoint(m_stateRect.x + 18.0f, stateY), std::move(label) + ": " + std::move(value), color, fontSize);
|
||||
stateY += 20.0f;
|
||||
};
|
||||
|
||||
addStateLine("Active Panel", m_controller.GetWorkspace().activePanelId.empty() ? "(none)" : m_controller.GetWorkspace().activePanelId, kTextPrimary, 11.0f);
|
||||
addStateLine("Focus Request", m_focusRequestPanelId.empty() ? "(none)" : m_focusRequestPanelId, m_focusRequestPanelId.empty() ? kTextMuted : kWarning, 11.0f);
|
||||
addStateLine("Visible Panels", JoinVisiblePanelIds(m_controller), kTextPrimary, 11.0f);
|
||||
const UIColor resultColor =
|
||||
m_lastStatus == "Rejected" ? kDanger :
|
||||
(m_lastStatus == "Ready" ? kWarning : kSuccess);
|
||||
addStateLine("Result", m_lastStatus, resultColor);
|
||||
drawList.AddText(UIPoint(m_stateRect.x + 18.0f, stateY + 4.0f), m_lastMessage, kTextMuted, 11.0f);
|
||||
stateY += 32.0f;
|
||||
addStateLine("Events", FormatEvents(m_lifecycleFrame), kAccent, 11.0f);
|
||||
|
||||
const auto* docA = FindUIEditorPanelHostState(m_lifecycleFrame, "doc-a");
|
||||
const auto* docB = FindUIEditorPanelHostState(m_lifecycleFrame, "doc-b");
|
||||
const auto* details = FindUIEditorPanelHostState(m_lifecycleFrame, "details");
|
||||
auto formatHostLine = [](std::string_view panelId, const XCEngine::UI::Editor::UIEditorPanelHostState* state) {
|
||||
if (state == nullptr) {
|
||||
return std::string(panelId) + " missing";
|
||||
}
|
||||
return std::string(panelId) +
|
||||
" a=" + (state->attached ? "1" : "0") +
|
||||
" v=" + (state->visible ? "1" : "0") +
|
||||
" act=" + (state->active ? "1" : "0") +
|
||||
" f=" + (state->focused ? "1" : "0");
|
||||
};
|
||||
addStateLine("doc-a", formatHostLine("doc-a", docA), kTextWeak, 11.0f);
|
||||
addStateLine("doc-b", formatHostLine("doc-b", docB), kTextWeak, 11.0f);
|
||||
addStateLine("details", formatHostLine("details", details), kTextWeak, 11.0f);
|
||||
addStateLine(
|
||||
"Screenshot",
|
||||
m_autoScreenshot.HasPendingCapture()
|
||||
? "截图排队�.."
|
||||
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||
? std::string("F12 �Capture -> captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary()),
|
||||
kTextWeak,
|
||||
11.0f);
|
||||
|
||||
DrawCard(drawList, m_previewRect, "Preview", "这里ä¸<EFBFBD>是业务é<EFBFBD>¢æ<EFBFBD>¿ï¼Œå<EFBFBD>ªæŠ?host state 直接å<C2A5>¯è§†åŒ–ã€?);
|
||||
DrawHostStateCard(drawList, m_docARect, "Document A", docA);
|
||||
DrawHostStateCard(drawList, m_docBRect, "Document B", docB);
|
||||
DrawHostStateCard(drawList, m_detailsRect, "Details", details);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
drawData,
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
framePresented);
|
||||
}
|
||||
|
||||
HINSTANCE m_hInstance = nullptr;
|
||||
HWND m_hwnd = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
NativeRenderer m_renderer = {};
|
||||
AutoScreenshotController m_autoScreenshot = {};
|
||||
std::filesystem::path m_captureRoot = {};
|
||||
UIEditorWorkspaceController m_controller = {};
|
||||
UIEditorPanelHostLifecycleState m_lifecycleState = {};
|
||||
UIEditorPanelHostLifecycleFrame m_lifecycleFrame = {};
|
||||
std::string m_focusRequestPanelId = {};
|
||||
std::string m_lastStatus = {};
|
||||
std::string m_lastMessage = {};
|
||||
UIRect m_introRect = {};
|
||||
UIRect m_controlsRect = {};
|
||||
UIRect m_stateRect = {};
|
||||
UIRect m_previewRect = {};
|
||||
UIRect m_docARect = {};
|
||||
UIRect m_docBRect = {};
|
||||
UIRect m_detailsRect = {};
|
||||
std::vector<ButtonState> m_buttons = {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return ScenarioApp().Run(hInstance, nCmdShow);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
add_executable(editor_ui_panel_session_flow_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
xcengine_configure_editor_ui_integration_validation_target(
|
||||
editor_ui_panel_session_flow_validation
|
||||
OUTPUT_NAME "XCUIEditorPanelSessionFlowValidation"
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,648 +0,0 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEditor/Workspace/UIEditorWorkspaceController.h>
|
||||
#include "Rendering/Native/AutoScreenshot.h"
|
||||
#include "Rendering/Native/NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
|
||||
#ifndef XCENGINE_EDITOR_UI_TESTS_REPO_ROOT
|
||||
#define XCENGINE_EDITOR_UI_TESTS_REPO_ROOT "."
|
||||
#endif
|
||||
|
||||
namespace {
|
||||
|
||||
using XCEngine::UI::Editor::BuildDefaultUIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceSplit;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceTabStack;
|
||||
using XCEngine::UI::Editor::CollectUIEditorWorkspaceVisiblePanels;
|
||||
using XCEngine::UI::Editor::FindUIEditorPanelSessionState;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceCommandKindName;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceCommandStatusName;
|
||||
using XCEngine::UI::Editor::UIEditorPanelRegistry;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommand;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandKind;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandResult;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceModel;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceSession;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceSplitAxis;
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorPanelSessionFlowValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | Panel Session 状æ€<C3A6>æµ<C3A6>";
|
||||
|
||||
constexpr UIColor kWindowBg(0.15f, 0.15f, 0.15f, 1.0f);
|
||||
constexpr UIColor kCardBg(0.20f, 0.20f, 0.20f, 1.0f);
|
||||
constexpr UIColor kCardBorder(0.29f, 0.29f, 0.29f, 1.0f);
|
||||
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
|
||||
constexpr UIColor kTextMuted(0.72f, 0.72f, 0.72f, 1.0f);
|
||||
constexpr UIColor kAccent(0.33f, 0.55f, 0.84f, 1.0f);
|
||||
constexpr UIColor kSuccess(0.43f, 0.71f, 0.47f, 1.0f);
|
||||
constexpr UIColor kWarning(0.78f, 0.60f, 0.30f, 1.0f);
|
||||
constexpr UIColor kDanger(0.78f, 0.34f, 0.34f, 1.0f);
|
||||
constexpr UIColor kButtonEnabled(0.32f, 0.32f, 0.32f, 1.0f);
|
||||
constexpr UIColor kButtonDisabled(0.24f, 0.24f, 0.24f, 1.0f);
|
||||
constexpr UIColor kButtonBorder(0.44f, 0.44f, 0.44f, 1.0f);
|
||||
|
||||
enum class ActionId : unsigned char {
|
||||
HideActive = 0,
|
||||
ShowDocA,
|
||||
CloseDocB,
|
||||
OpenDocB,
|
||||
ActivateDetails,
|
||||
Reset
|
||||
};
|
||||
|
||||
struct ButtonState {
|
||||
ActionId action = ActionId::HideActive;
|
||||
std::string label = {};
|
||||
UIRect rect = {};
|
||||
bool enabled = false;
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
UIEditorPanelRegistry BuildPanelRegistry() {
|
||||
UIEditorPanelRegistry registry = {};
|
||||
registry.panels = {
|
||||
{ "doc-a", "Document A", {}, true, true, true },
|
||||
{ "doc-b", "Document B", {}, true, true, true },
|
||||
{ "details", "Details", {}, true, true, true }
|
||||
};
|
||||
return registry;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceModel BuildWorkspace() {
|
||||
UIEditorWorkspaceModel workspace = {};
|
||||
workspace.root = BuildUIEditorWorkspaceSplit(
|
||||
"root-split",
|
||||
UIEditorWorkspaceSplitAxis::Horizontal,
|
||||
0.66f,
|
||||
BuildUIEditorWorkspaceTabStack(
|
||||
"document-tabs",
|
||||
{
|
||||
BuildUIEditorWorkspacePanel("doc-a-node", "doc-a", "Document A", true),
|
||||
BuildUIEditorWorkspacePanel("doc-b-node", "doc-b", "Document B", true)
|
||||
},
|
||||
0u),
|
||||
BuildUIEditorWorkspacePanel("details-node", "details", "Details", true));
|
||||
workspace.activePanelId = "doc-a";
|
||||
return workspace;
|
||||
}
|
||||
|
||||
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::string JoinVisiblePanelIds(
|
||||
const UIEditorWorkspaceModel& workspace,
|
||||
const UIEditorWorkspaceSession& session) {
|
||||
const auto panels = CollectUIEditorWorkspaceVisiblePanels(workspace, session);
|
||||
if (panels.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
for (std::size_t index = 0; index < panels.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
stream << ", ";
|
||||
}
|
||||
stream << panels[index].panelId;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
std::string DescribePanelState(
|
||||
const UIEditorWorkspaceSession& session,
|
||||
std::string_view panelId,
|
||||
std::string_view displayName) {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, panelId);
|
||||
if (state == nullptr) {
|
||||
return std::string(displayName) + ": missing";
|
||||
}
|
||||
|
||||
std::string visibility = {};
|
||||
if (!state->open) {
|
||||
visibility = "closed";
|
||||
} else if (!state->visible) {
|
||||
visibility = "hidden";
|
||||
} else {
|
||||
visibility = "visible";
|
||||
}
|
||||
|
||||
return std::string(displayName) + ": " + visibility;
|
||||
}
|
||||
|
||||
UIColor ResolvePanelStateColor(
|
||||
const UIEditorWorkspaceSession& session,
|
||||
std::string_view panelId) {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, panelId);
|
||||
if (state == nullptr) {
|
||||
return kDanger;
|
||||
}
|
||||
|
||||
if (!state->open) {
|
||||
return kDanger;
|
||||
}
|
||||
|
||||
if (!state->visible) {
|
||||
return kWarning;
|
||||
}
|
||||
|
||||
return kSuccess;
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string_view title,
|
||||
std::string_view subtitle = {}) {
|
||||
drawList.AddFilledRect(rect, kCardBg, 12.0f);
|
||||
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 12.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 16.0f), std::string(title), kTextPrimary, 17.0f);
|
||||
if (!subtitle.empty()) {
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 42.0f), std::string(subtitle), kTextMuted, 12.0f);
|
||||
}
|
||||
}
|
||||
|
||||
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 = reinterpret_cast<ScenarioApp*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
switch (message) {
|
||||
case WM_SIZE:
|
||||
if (app != nullptr && wParam != SIZE_MINIMIZED) {
|
||||
app->OnResize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||
}
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
if (app != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
app->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandleClick(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (app != nullptr) {
|
||||
if (wParam == VK_F12) {
|
||||
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
} else {
|
||||
app->HandleShortcut(static_cast<UINT>(wParam));
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
case WM_DESTROY:
|
||||
if (app != nullptr) {
|
||||
app->m_hwnd = nullptr;
|
||||
}
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_hInstance = hInstance;
|
||||
ResetScenario();
|
||||
|
||||
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,
|
||||
1320,
|
||||
860,
|
||||
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_autoScreenshot.Initialize(
|
||||
(ResolveRepoRootPath() / "tests/UI/Editor/manual_validation/state/panel_session_flow/captures")
|
||||
.lexically_normal());
|
||||
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_controller =
|
||||
BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
|
||||
m_hasLastCommandResult = false;
|
||||
m_lastActionSummary = "ç‰å¾…æ“<EFBFBD>作:先ç‚?Hide Active,确认命令结果为 Changed,并检æŸ?active/visible 状æ€<C3A6>è<EFBFBD>”动ã€?;
|
||||
}
|
||||
|
||||
void OnResize(UINT width, UINT height) {
|
||||
if (width == 0 || height == 0) {
|
||||
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));
|
||||
|
||||
UIDrawData drawData = {};
|
||||
BuildDrawData(drawData, width, height);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
drawData,
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
framePresented);
|
||||
}
|
||||
|
||||
void HandleClick(float x, float y) {
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
if (button.enabled && ContainsPoint(button.rect, x, y)) {
|
||||
DispatchAction(button.action);
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void HandleShortcut(UINT keyCode) {
|
||||
switch (keyCode) {
|
||||
case '1':
|
||||
DispatchAction(ActionId::HideActive);
|
||||
break;
|
||||
case '2':
|
||||
DispatchAction(ActionId::ShowDocA);
|
||||
break;
|
||||
case '3':
|
||||
DispatchAction(ActionId::CloseDocB);
|
||||
break;
|
||||
case '4':
|
||||
DispatchAction(ActionId::OpenDocB);
|
||||
break;
|
||||
case '5':
|
||||
DispatchAction(ActionId::ActivateDetails);
|
||||
break;
|
||||
case 'R':
|
||||
DispatchAction(ActionId::Reset);
|
||||
break;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
void DispatchAction(ActionId action) {
|
||||
std::string label = {};
|
||||
UIEditorWorkspaceCommand command = {};
|
||||
|
||||
switch (action) {
|
||||
case ActionId::HideActive:
|
||||
label = "Hide Active";
|
||||
command.kind = UIEditorWorkspaceCommandKind::HidePanel;
|
||||
command.panelId = m_controller.GetWorkspace().activePanelId;
|
||||
break;
|
||||
case ActionId::ShowDocA:
|
||||
label = "Show Doc A";
|
||||
command.kind = UIEditorWorkspaceCommandKind::ShowPanel;
|
||||
command.panelId = "doc-a";
|
||||
break;
|
||||
case ActionId::CloseDocB:
|
||||
label = "Close Doc B";
|
||||
command.kind = UIEditorWorkspaceCommandKind::ClosePanel;
|
||||
command.panelId = "doc-b";
|
||||
break;
|
||||
case ActionId::OpenDocB:
|
||||
label = "Open Doc B";
|
||||
command.kind = UIEditorWorkspaceCommandKind::OpenPanel;
|
||||
command.panelId = "doc-b";
|
||||
break;
|
||||
case ActionId::ActivateDetails:
|
||||
label = "Activate Details";
|
||||
command.kind = UIEditorWorkspaceCommandKind::ActivatePanel;
|
||||
command.panelId = "details";
|
||||
break;
|
||||
case ActionId::Reset:
|
||||
label = "Reset";
|
||||
command.kind = UIEditorWorkspaceCommandKind::ResetWorkspace;
|
||||
break;
|
||||
}
|
||||
|
||||
m_lastCommandResult = m_controller.Dispatch(command);
|
||||
m_hasLastCommandResult = true;
|
||||
m_lastActionSummary =
|
||||
label + " -> " +
|
||||
std::string(GetUIEditorWorkspaceCommandStatusName(m_lastCommandResult.status));
|
||||
}
|
||||
|
||||
bool IsButtonEnabled(ActionId action) const {
|
||||
const UIEditorWorkspaceModel& workspace = m_controller.GetWorkspace();
|
||||
const UIEditorWorkspaceSession& session = m_controller.GetSession();
|
||||
switch (action) {
|
||||
case ActionId::HideActive: {
|
||||
if (workspace.activePanelId.empty()) {
|
||||
return false;
|
||||
}
|
||||
const auto* state = FindUIEditorPanelSessionState(session, workspace.activePanelId);
|
||||
return state != nullptr && state->open && state->visible;
|
||||
}
|
||||
case ActionId::ShowDocA: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "doc-a");
|
||||
return state != nullptr && state->open && !state->visible;
|
||||
}
|
||||
case ActionId::CloseDocB: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "doc-b");
|
||||
return state != nullptr && state->open;
|
||||
}
|
||||
case ActionId::OpenDocB: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "doc-b");
|
||||
return state != nullptr && !state->open;
|
||||
}
|
||||
case ActionId::ActivateDetails: {
|
||||
const auto* state = FindUIEditorPanelSessionState(session, "details");
|
||||
return state != nullptr &&
|
||||
state->open &&
|
||||
state->visible &&
|
||||
workspace.activePanelId != "details";
|
||||
}
|
||||
case ActionId::Reset:
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void BuildDrawData(UIDrawData& drawData, float width, float height) {
|
||||
const UIEditorWorkspaceModel& workspace = m_controller.GetWorkspace();
|
||||
const UIEditorWorkspaceSession& session = m_controller.GetSession();
|
||||
const auto validation = m_controller.ValidateState();
|
||||
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("Editor Panel Session Flow");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
const float margin = 20.0f;
|
||||
const UIRect headerRect(margin, margin, width - margin * 2.0f, 170.0f);
|
||||
const UIRect actionRect(margin, headerRect.y + headerRect.height + 16.0f, 320.0f, height - 246.0f);
|
||||
const UIRect stateRect(actionRect.x + actionRect.width + 16.0f, actionRect.y, width - actionRect.width - margin * 2.0f - 16.0f, height - 246.0f);
|
||||
const UIRect footerRect(margin, height - 96.0f, width - margin * 2.0f, 76.0f);
|
||||
|
||||
DrawCard(drawList, headerRect, "测试功能:Editor Command Dispatch + Workspace Controller", "å<EFBFBD>ªéªŒè¯<EFBFBD>命令分å<EFBFBD>‘ã€<EFBFBD>状æ€<EFBFBD>å<EFBFBD>˜æ›´ç»“果和 panel session è<>”动;ä¸<C3A4>验è¯<C3A8>业务é<C2A1>¢æ<C2A2>¿ã€?);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 70.0f), "1. ç‚?`1 Hide Active`,Result 应是 Changed,active ä»?doc-a 切到 doc-b,selected tab 也å<C5B8>Œæ¥åˆ° Bã€?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 92.0f), "2. å†<C3A5>点 `1 Hide Active`,如果当å‰?panel å·?hidden,Result 应å<E2809D>˜æˆ?NoOp,而ä¸<C3A4>是乱改状æ€<C3A6>ã€?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 114.0f), "3. ç‚?`3 Close Doc B` å<>Žå†<C3A5>ç‚?`5 Activate Details` / `4 Open Doc B`,检æŸ?Changed / Rejected / NoOp 是å<C2AF>¦ç¬¦å<C2A6>ˆæ<CB86><C3A6>示ã€?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 136.0f), "4. `R Reset` 必须把状æ€<C3A6>拉回基线;æŒ?`F12` ä¿<C3A4>å˜å½“å‰<C3A5>窗å<E28094>£æˆªå›¾ã€?, kTextPrimary, 13.0f);
|
||||
|
||||
DrawCard(drawList, actionRect, "æ“<EFBFBD>作åŒ?, "æ¯<EFBFBD>个按钮都会先生æˆ?command,å†<EFBFBD>交给 Workspace Controller 分å<EFBFBD>‘ã€?);
|
||||
DrawCard(drawList, stateRect, "状æ€<EFBFBD>摘è¦?, "é‡<EFBFBD>点检æŸ?active panelã€<EFBFBD>visible panelsã€<EFBFBD>selected tab index å’Œæ¯<EFBFBD>ä¸?panel session 状æ€<EFBFBD>ã€?);
|
||||
DrawCard(drawList, footerRect, "最近结æž?, "è¿™å<EFBFBD>—显示 last commandã€<EFBFBD>statusã€<EFBFBD>message 与当å‰?validationã€?);
|
||||
|
||||
m_buttons.clear();
|
||||
const std::vector<std::pair<ActionId, std::string>> buttonDefs = {
|
||||
{ ActionId::HideActive, "1 Hide Active" },
|
||||
{ ActionId::ShowDocA, "2 Show Doc A" },
|
||||
{ ActionId::CloseDocB, "3 Close Doc B" },
|
||||
{ ActionId::OpenDocB, "4 Open Doc B" },
|
||||
{ ActionId::ActivateDetails, "5 Activate Details" },
|
||||
{ ActionId::Reset, "R Reset" }
|
||||
};
|
||||
|
||||
float buttonY = actionRect.y + 72.0f;
|
||||
for (const auto& [action, label] : buttonDefs) {
|
||||
ButtonState button = {};
|
||||
button.action = action;
|
||||
button.label = label;
|
||||
button.rect = UIRect(actionRect.x + 18.0f, buttonY, actionRect.width - 36.0f, 46.0f);
|
||||
button.enabled = IsButtonEnabled(action);
|
||||
m_buttons.push_back(button);
|
||||
|
||||
drawList.AddFilledRect(
|
||||
button.rect,
|
||||
button.enabled ? kButtonEnabled : kButtonDisabled,
|
||||
8.0f);
|
||||
drawList.AddRectOutline(button.rect, kButtonBorder, 1.0f, 8.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(button.rect.x + 14.0f, button.rect.y + 13.0f),
|
||||
button.label,
|
||||
button.enabled ? kTextPrimary : kTextMuted,
|
||||
13.0f);
|
||||
buttonY += 58.0f;
|
||||
}
|
||||
|
||||
const float leftX = stateRect.x + 18.0f;
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 70.0f), "Current active panel:", kTextMuted, 12.0f);
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 90.0f), workspace.activePanelId.empty() ? "(none)" : workspace.activePanelId, kAccent, 15.0f);
|
||||
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 124.0f), "Visible panels:", kTextMuted, 12.0f);
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 144.0f), JoinVisiblePanelIds(workspace, session), kTextPrimary, 14.0f);
|
||||
|
||||
drawList.AddText(UIPoint(leftX, stateRect.y + 178.0f), "Selected tab index:", kTextMuted, 12.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(leftX, stateRect.y + 198.0f),
|
||||
std::to_string(workspace.root.children.front().selectedTabIndex),
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
|
||||
const float pillX = leftX;
|
||||
const float pillY = stateRect.y + 244.0f;
|
||||
const std::vector<std::pair<std::string, std::string>> panelDefs = {
|
||||
{ "doc-a", "Document A" },
|
||||
{ "doc-b", "Document B" },
|
||||
{ "details", "Details" }
|
||||
};
|
||||
|
||||
float rowY = pillY;
|
||||
for (const auto& [panelId, label] : panelDefs) {
|
||||
const UIRect rowRect(leftX, rowY, stateRect.width - 36.0f, 54.0f);
|
||||
drawList.AddFilledRect(rowRect, UIColor(0.17f, 0.17f, 0.17f, 1.0f), 8.0f);
|
||||
drawList.AddRectOutline(rowRect, kCardBorder, 1.0f, 8.0f);
|
||||
drawList.AddFilledRect(
|
||||
UIRect(rowRect.x + 12.0f, rowRect.y + 15.0f, 10.0f, 10.0f),
|
||||
ResolvePanelStateColor(session, panelId),
|
||||
5.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(rowRect.x + 32.0f, rowRect.y + 11.0f),
|
||||
DescribePanelState(session, panelId, label),
|
||||
kTextPrimary,
|
||||
14.0f);
|
||||
const bool active = workspace.activePanelId == panelId;
|
||||
drawList.AddText(
|
||||
UIPoint(rowRect.x + 32.0f, rowRect.y + 31.0f),
|
||||
active ? "active = true" : "active = false",
|
||||
active ? kAccent : kTextMuted,
|
||||
12.0f);
|
||||
rowY += 64.0f;
|
||||
}
|
||||
|
||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 28.0f), m_lastActionSummary, kTextPrimary, 13.0f);
|
||||
if (m_hasLastCommandResult) {
|
||||
drawList.AddText(
|
||||
UIPoint(footerRect.x + 18.0f, footerRect.y + 48.0f),
|
||||
"Last command: " +
|
||||
std::string(GetUIEditorWorkspaceCommandKindName(m_lastCommandResult.kind)) +
|
||||
" | Status: " +
|
||||
std::string(GetUIEditorWorkspaceCommandStatusName(m_lastCommandResult.status)) +
|
||||
" | " +
|
||||
m_lastCommandResult.message,
|
||||
m_lastCommandResult.status == XCEngine::UI::Editor::UIEditorWorkspaceCommandStatus::Rejected
|
||||
? kDanger
|
||||
: (m_lastCommandResult.status == XCEngine::UI::Editor::UIEditorWorkspaceCommandStatus::NoOp
|
||||
? kWarning
|
||||
: kSuccess),
|
||||
12.0f);
|
||||
}
|
||||
drawList.AddText(
|
||||
UIPoint(footerRect.x + 18.0f, footerRect.y + 66.0f),
|
||||
validation.IsValid() ? "Validation: OK" : "Validation: " + validation.message,
|
||||
validation.IsValid() ? kSuccess : kDanger,
|
||||
12.0f);
|
||||
|
||||
const std::string captureSummary =
|
||||
m_autoScreenshot.HasPendingCapture()
|
||||
? "截图排队�.."
|
||||
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||
? std::string("F12 -> tests/UI/Editor/manual_validation/state/panel_session_flow/captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary());
|
||||
drawList.AddText(UIPoint(footerRect.x + 530.0f, footerRect.y + 66.0f), captureSummary, kTextMuted, 12.0f);
|
||||
}
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
HINSTANCE m_hInstance = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
NativeRenderer m_renderer = {};
|
||||
AutoScreenshotController m_autoScreenshot = {};
|
||||
UIEditorWorkspaceController m_controller = {};
|
||||
std::vector<ButtonState> m_buttons = {};
|
||||
UIEditorWorkspaceCommandResult m_lastCommandResult = {};
|
||||
bool m_hasLastCommandResult = false;
|
||||
std::string m_lastActionSummary = {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
ScenarioApp app;
|
||||
return app.Run(hInstance, nCmdShow);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
add_executable(editor_ui_shortcut_dispatch_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
xcengine_configure_editor_ui_integration_validation_target(
|
||||
editor_ui_shortcut_dispatch_validation
|
||||
OUTPUT_NAME "XCUIEditorShortcutDispatchValidation"
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,641 +0,0 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEditor/Foundation/UIEditorShortcutManager.h>
|
||||
#include "Rendering/Native/AutoScreenshot.h"
|
||||
#include "Platform/Win32/InputModifierTracker.h"
|
||||
#include "Rendering/Native/NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/Input/InputTypes.h>
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#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::Editor::BuildDefaultUIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspacePanel;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceSplit;
|
||||
using XCEngine::UI::Editor::BuildUIEditorWorkspaceTabStack;
|
||||
using XCEngine::UI::Editor::CollectUIEditorWorkspaceVisiblePanels;
|
||||
using XCEngine::UI::Editor::FindUIEditorPanelSessionState;
|
||||
using XCEngine::UI::Editor::GetUIEditorShortcutDispatchStatusName;
|
||||
using XCEngine::UI::Editor::GetUIEditorWorkspaceCommandStatusName;
|
||||
using XCEngine::UI::Editor::UIEditorCommandPanelSource;
|
||||
using XCEngine::UI::Editor::UIEditorCommandRegistry;
|
||||
using XCEngine::UI::Editor::UIEditorPanelRegistry;
|
||||
using XCEngine::UI::Editor::UIEditorShortcutDispatchResult;
|
||||
using XCEngine::UI::Editor::UIEditorShortcutDispatchStatus;
|
||||
using XCEngine::UI::Editor::UIEditorShortcutManager;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceCommandKind;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceController;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceModel;
|
||||
using XCEngine::UI::Editor::UIEditorWorkspaceSplitAxis;
|
||||
using XCEngine::UI::UIColor;
|
||||
using XCEngine::UI::UIDrawData;
|
||||
using XCEngine::UI::UIDrawList;
|
||||
using XCEngine::UI::UIInputEvent;
|
||||
using XCEngine::UI::UIInputEventType;
|
||||
using XCEngine::UI::UIPoint;
|
||||
using XCEngine::UI::UIRect;
|
||||
using XCEngine::UI::UIShortcutBinding;
|
||||
using XCEngine::UI::UIShortcutContext;
|
||||
using XCEngine::UI::UIShortcutScope;
|
||||
using XCEngine::UI::Editor::Host::AutoScreenshotController;
|
||||
using XCEngine::UI::Editor::Host::InputModifierTracker;
|
||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorShortcutDispatchValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI Editor | Shortcut Dispatch";
|
||||
|
||||
constexpr XCEngine::UI::UIElementId kWindowOwnerId = 1u;
|
||||
constexpr XCEngine::UI::UIElementId kDocumentsPanelOwnerId = 11u;
|
||||
constexpr XCEngine::UI::UIElementId kDetailsPanelOwnerId = 22u;
|
||||
|
||||
constexpr UIColor kWindowBg(0.14f, 0.14f, 0.14f, 1.0f);
|
||||
constexpr UIColor kCardBg(0.19f, 0.19f, 0.19f, 1.0f);
|
||||
constexpr UIColor kCardBorder(0.29f, 0.29f, 0.29f, 1.0f);
|
||||
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
|
||||
constexpr UIColor kTextMuted(0.70f, 0.70f, 0.70f, 1.0f);
|
||||
constexpr UIColor kAccent(0.82f, 0.82f, 0.82f, 1.0f);
|
||||
constexpr UIColor kSuccess(0.43f, 0.71f, 0.47f, 1.0f);
|
||||
constexpr UIColor kWarning(0.78f, 0.60f, 0.30f, 1.0f);
|
||||
constexpr UIColor kDanger(0.78f, 0.34f, 0.34f, 1.0f);
|
||||
|
||||
enum class ActionId : unsigned char {
|
||||
ToggleTextInput = 0,
|
||||
ResetScenario
|
||||
};
|
||||
|
||||
struct ButtonState {
|
||||
ActionId action = ActionId::ToggleTextInput;
|
||||
std::string label = {};
|
||||
UIRect rect = {};
|
||||
};
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
UIEditorPanelRegistry BuildPanelRegistry() {
|
||||
UIEditorPanelRegistry registry = {};
|
||||
registry.panels = {
|
||||
{ "doc-a", "Document A", {}, true, true, true },
|
||||
{ "doc-b", "Document B", {}, true, true, true },
|
||||
{ "details", "Details", {}, true, true, true }
|
||||
};
|
||||
return registry;
|
||||
}
|
||||
|
||||
UIEditorWorkspaceModel BuildWorkspace() {
|
||||
UIEditorWorkspaceModel workspace = {};
|
||||
workspace.root = BuildUIEditorWorkspaceSplit(
|
||||
"root-split",
|
||||
UIEditorWorkspaceSplitAxis::Horizontal,
|
||||
0.66f,
|
||||
BuildUIEditorWorkspaceTabStack(
|
||||
"document-tabs",
|
||||
{
|
||||
BuildUIEditorWorkspacePanel("doc-a-node", "doc-a", "Document A", true),
|
||||
BuildUIEditorWorkspacePanel("doc-b-node", "doc-b", "Document B", true)
|
||||
},
|
||||
0u),
|
||||
BuildUIEditorWorkspacePanel("details-node", "details", "Details", true));
|
||||
workspace.activePanelId = "doc-a";
|
||||
return workspace;
|
||||
}
|
||||
|
||||
UIEditorCommandRegistry BuildCommandRegistry() {
|
||||
UIEditorCommandRegistry registry = {};
|
||||
registry.commands = {
|
||||
{
|
||||
"workspace.hide_active",
|
||||
"Hide Active",
|
||||
{ UIEditorWorkspaceCommandKind::HidePanel, UIEditorCommandPanelSource::ActivePanel, {} }
|
||||
},
|
||||
{
|
||||
"workspace.close_doc_b",
|
||||
"Close Doc B",
|
||||
{ UIEditorWorkspaceCommandKind::ClosePanel, UIEditorCommandPanelSource::FixedPanelId, "doc-b" }
|
||||
},
|
||||
{
|
||||
"workspace.open_doc_b",
|
||||
"Open Doc B",
|
||||
{ UIEditorWorkspaceCommandKind::OpenPanel, UIEditorCommandPanelSource::FixedPanelId, "doc-b" }
|
||||
},
|
||||
{
|
||||
"workspace.activate_details",
|
||||
"Activate Details",
|
||||
{ UIEditorWorkspaceCommandKind::ActivatePanel, UIEditorCommandPanelSource::FixedPanelId, "details" }
|
||||
},
|
||||
{
|
||||
"workspace.reset",
|
||||
"Reset Workspace",
|
||||
{ UIEditorWorkspaceCommandKind::ResetWorkspace, UIEditorCommandPanelSource::None, {} }
|
||||
}
|
||||
};
|
||||
return registry;
|
||||
}
|
||||
|
||||
UIShortcutBinding MakeBinding(
|
||||
std::string commandId,
|
||||
UIShortcutScope scope,
|
||||
XCEngine::UI::UIElementId ownerId,
|
||||
KeyCode keyCode) {
|
||||
UIShortcutBinding binding = {};
|
||||
binding.commandId = std::move(commandId);
|
||||
binding.scope = scope;
|
||||
binding.ownerId = ownerId;
|
||||
binding.triggerEventType = UIInputEventType::KeyDown;
|
||||
binding.chord.keyCode = static_cast<std::int32_t>(keyCode);
|
||||
binding.chord.modifiers.control = true;
|
||||
return binding;
|
||||
}
|
||||
|
||||
UIEditorShortcutManager BuildShortcutManager() {
|
||||
UIEditorShortcutManager manager(BuildCommandRegistry());
|
||||
manager.RegisterBinding(MakeBinding("workspace.hide_active", UIShortcutScope::Global, 0u, KeyCode::H));
|
||||
manager.RegisterBinding(MakeBinding("workspace.close_doc_b", UIShortcutScope::Global, 0u, KeyCode::W));
|
||||
manager.RegisterBinding(MakeBinding("workspace.open_doc_b", UIShortcutScope::Global, 0u, KeyCode::O));
|
||||
manager.RegisterBinding(MakeBinding("workspace.reset", UIShortcutScope::Global, 0u, KeyCode::R));
|
||||
manager.RegisterBinding(MakeBinding("workspace.activate_details", UIShortcutScope::Panel, kDocumentsPanelOwnerId, KeyCode::P));
|
||||
manager.RegisterBinding(MakeBinding("workspace.reset", UIShortcutScope::Panel, kDetailsPanelOwnerId, KeyCode::P));
|
||||
return manager;
|
||||
}
|
||||
|
||||
std::int32_t MapVirtualKeyToUIKeyCode(WPARAM wParam) {
|
||||
switch (wParam) {
|
||||
case 'H': return static_cast<std::int32_t>(KeyCode::H);
|
||||
case 'O': return static_cast<std::int32_t>(KeyCode::O);
|
||||
case 'P': return static_cast<std::int32_t>(KeyCode::P);
|
||||
case 'R': return static_cast<std::int32_t>(KeyCode::R);
|
||||
case 'T': return static_cast<std::int32_t>(KeyCode::T);
|
||||
case 'W': return static_cast<std::int32_t>(KeyCode::W);
|
||||
case VK_CONTROL: return static_cast<std::int32_t>(KeyCode::LeftCtrl);
|
||||
case VK_F12: return static_cast<std::int32_t>(KeyCode::F12);
|
||||
default: return static_cast<std::int32_t>(KeyCode::None);
|
||||
}
|
||||
}
|
||||
|
||||
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::string JoinVisiblePanels(const UIEditorWorkspaceController& controller) {
|
||||
const auto panels = CollectUIEditorWorkspaceVisiblePanels(
|
||||
controller.GetWorkspace(),
|
||||
controller.GetSession());
|
||||
if (panels.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::ostringstream stream;
|
||||
for (std::size_t index = 0; index < panels.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
stream << ", ";
|
||||
}
|
||||
stream << panels[index].panelId;
|
||||
}
|
||||
return stream.str();
|
||||
}
|
||||
|
||||
XCEngine::UI::UIElementId ResolveCurrentPanelOwnerId(std::string_view activePanelId) {
|
||||
return activePanelId == "details" ? kDetailsPanelOwnerId : kDocumentsPanelOwnerId;
|
||||
}
|
||||
|
||||
std::string DescribeCurrentScope(std::string_view activePanelId) {
|
||||
return activePanelId == "details" ? "Details Panel Scope" : "Documents Panel Scope";
|
||||
}
|
||||
|
||||
UIColor ResolveShortcutStatusColor(UIEditorShortcutDispatchStatus status) {
|
||||
switch (status) {
|
||||
case UIEditorShortcutDispatchStatus::Dispatched: return kSuccess;
|
||||
case UIEditorShortcutDispatchStatus::Suppressed: return kWarning;
|
||||
case UIEditorShortcutDispatchStatus::Rejected: return kDanger;
|
||||
case UIEditorShortcutDispatchStatus::NoMatch:
|
||||
default:
|
||||
return kTextMuted;
|
||||
}
|
||||
}
|
||||
|
||||
UIColor ResolveCommandStatusColor(UIEditorWorkspaceController& controller, const UIEditorShortcutDispatchResult& result) {
|
||||
(void)controller;
|
||||
if (!result.commandExecuted) {
|
||||
return kTextMuted;
|
||||
}
|
||||
|
||||
switch (result.commandResult.status) {
|
||||
case XCEngine::UI::Editor::UIEditorWorkspaceCommandStatus::Changed: return kSuccess;
|
||||
case XCEngine::UI::Editor::UIEditorWorkspaceCommandStatus::NoOp: return kWarning;
|
||||
case XCEngine::UI::Editor::UIEditorWorkspaceCommandStatus::Rejected: return kDanger;
|
||||
}
|
||||
|
||||
return kTextMuted;
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string_view title,
|
||||
std::string_view subtitle = {}) {
|
||||
drawList.AddFilledRect(rect, kCardBg, 12.0f);
|
||||
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 12.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 16.0f), std::string(title), kTextPrimary, 17.0f);
|
||||
if (!subtitle.empty()) {
|
||||
drawList.AddText(UIPoint(rect.x + 18.0f, rect.y + 42.0f), std::string(subtitle), kTextMuted, 12.0f);
|
||||
}
|
||||
}
|
||||
|
||||
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 = reinterpret_cast<ScenarioApp*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
switch (message) {
|
||||
case WM_SIZE:
|
||||
if (app != nullptr && wParam != SIZE_MINIMIZED) {
|
||||
app->m_renderer.Resize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||
}
|
||||
return 0;
|
||||
case WM_PAINT:
|
||||
if (app != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
app->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandleClick(static_cast<float>(GET_X_LPARAM(lParam)), static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (app != nullptr) {
|
||||
if (wParam == VK_F12) {
|
||||
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
} else {
|
||||
app->HandleKey(UIInputEventType::KeyDown, wParam, lParam);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
if (app != nullptr) {
|
||||
app->HandleKey(UIInputEventType::KeyUp, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_hInstance = hInstance;
|
||||
ResetScenario();
|
||||
|
||||
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,
|
||||
1340,
|
||||
860,
|
||||
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_autoScreenshot.Initialize(
|
||||
(ResolveRepoRootPath() / "tests/UI/Editor/manual_validation/state/shortcut_dispatch/captures").lexically_normal());
|
||||
return true;
|
||||
}
|
||||
|
||||
void Shutdown() {
|
||||
m_autoScreenshot.Shutdown();
|
||||
m_renderer.Shutdown();
|
||||
if (m_hwnd != nullptr && IsWindow(m_hwnd)) {
|
||||
DestroyWindow(m_hwnd);
|
||||
}
|
||||
if (m_windowClassAtom != 0 && m_hInstance != nullptr) {
|
||||
UnregisterClassW(kWindowClassName, m_hInstance);
|
||||
}
|
||||
}
|
||||
|
||||
void ResetScenario() {
|
||||
m_controller = BuildDefaultUIEditorWorkspaceController(BuildPanelRegistry(), BuildWorkspace());
|
||||
m_shortcutManager = BuildShortcutManager();
|
||||
m_textInputActive = false;
|
||||
m_inputModifierTracker.Reset();
|
||||
m_lastAction = "遲牙セ<EFBFBD>桃菴<EFBFBD>";
|
||||
m_lastShortcutStatus = "Pending";
|
||||
m_lastCommandStatus = "(none)";
|
||||
m_lastMessage = "蜈域潔 Ctrl+P<>悟<EFBFBD>逵?Shortcut result 蜥?Command result 譏ッ荳肴弍蛻<E5BC8D>悪蜿伜喧縲?;
|
||||
m_lastShortcutColor = kTextMuted;
|
||||
m_lastCommandColor = kTextMuted;
|
||||
}
|
||||
|
||||
UIShortcutContext BuildShortcutContext() const {
|
||||
UIShortcutContext context = {};
|
||||
const auto panelOwnerId = ResolveCurrentPanelOwnerId(m_controller.GetWorkspace().activePanelId);
|
||||
context.commandScope.path = { kWindowOwnerId, panelOwnerId };
|
||||
context.commandScope.windowId = kWindowOwnerId;
|
||||
context.commandScope.panelId = panelOwnerId;
|
||||
context.textInputActive = m_textInputActive;
|
||||
return context;
|
||||
}
|
||||
|
||||
void HandleClick(float x, float y) {
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
if (!ContainsPoint(button.rect, x, y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (button.action == ActionId::ToggleTextInput) {
|
||||
m_textInputActive = !m_textInputActive;
|
||||
m_lastAction = "Toggle Text Input";
|
||||
m_lastShortcutStatus = "Changed";
|
||||
m_lastCommandStatus = "(none)";
|
||||
m_lastMessage = m_textInputActive
|
||||
? "text input active = true縲ら鴫蝨ィ謖<EFBDA8> Ctrl+H / Ctrl+P<>郡hortcut result 蠎比クコ Suppressed縲?
|
||||
: "text input active = false縲ょソォ謐キ髞ョ諱「螟肴ュ」蟶ク dispatch縲?;
|
||||
m_lastShortcutColor = kSuccess;
|
||||
m_lastCommandColor = kTextMuted;
|
||||
} else {
|
||||
ResetScenario();
|
||||
}
|
||||
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void HandleKey(UIInputEventType type, WPARAM wParam, LPARAM lParam) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
event.keyCode = MapVirtualKeyToUIKeyCode(wParam);
|
||||
event.modifiers = m_inputModifierTracker.ApplyKeyMessage(type, wParam, lParam);
|
||||
event.repeat = (static_cast<std::uint32_t>(lParam) & 0x40000000u) != 0u;
|
||||
|
||||
if (type == UIInputEventType::KeyUp || event.keyCode == static_cast<std::int32_t>(KeyCode::None)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.keyCode == static_cast<std::int32_t>(KeyCode::T) &&
|
||||
!event.modifiers.control &&
|
||||
!event.modifiers.alt &&
|
||||
!event.modifiers.super) {
|
||||
m_textInputActive = !m_textInputActive;
|
||||
m_lastAction = "T";
|
||||
m_lastShortcutStatus = "Changed";
|
||||
m_lastCommandStatus = "(none)";
|
||||
m_lastMessage = m_textInputActive
|
||||
? "text input active = true縲ゆク倶ク谺?Ctrl 蠢ォ謐キ髞ョ蠎碑「?Suppressed縲?
|
||||
: "text input active = false縲ゆク倶ク谺?Ctrl 蠢ォ謐キ髞ョ蠎疲ュ」蟶ク dispatch縲?;
|
||||
m_lastShortcutColor = kSuccess;
|
||||
m_lastCommandColor = kTextMuted;
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
return;
|
||||
}
|
||||
|
||||
if (event.keyCode == static_cast<std::int32_t>(KeyCode::LeftCtrl)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const UIEditorShortcutDispatchResult result =
|
||||
m_shortcutManager.Dispatch(event, BuildShortcutContext(), m_controller);
|
||||
m_lastAction = DescribeKey(event.keyCode);
|
||||
m_lastShortcutStatus = std::string(GetUIEditorShortcutDispatchStatusName(result.status));
|
||||
m_lastShortcutColor = ResolveShortcutStatusColor(result.status);
|
||||
if (result.commandExecuted) {
|
||||
m_lastCommandStatus = std::string(GetUIEditorWorkspaceCommandStatusName(result.commandResult.status));
|
||||
m_lastCommandColor = ResolveCommandStatusColor(m_controller, result);
|
||||
m_lastMessage = result.message + " | " + result.commandDisplayName + " -> " + result.commandResult.message;
|
||||
} else {
|
||||
m_lastCommandStatus = "(none)";
|
||||
m_lastCommandColor = kTextMuted;
|
||||
m_lastMessage = result.message;
|
||||
}
|
||||
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
}
|
||||
|
||||
std::string DescribeKey(std::int32_t keyCode) const {
|
||||
if (keyCode == static_cast<std::int32_t>(KeyCode::H)) return "Ctrl+H";
|
||||
if (keyCode == static_cast<std::int32_t>(KeyCode::O)) return "Ctrl+O";
|
||||
if (keyCode == static_cast<std::int32_t>(KeyCode::P)) return "Ctrl+P";
|
||||
if (keyCode == static_cast<std::int32_t>(KeyCode::R)) return "Ctrl+R";
|
||||
if (keyCode == static_cast<std::int32_t>(KeyCode::W)) return "Ctrl+W";
|
||||
return "Key";
|
||||
}
|
||||
|
||||
void RenderFrame() {
|
||||
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 auto validation = m_controller.ValidateState();
|
||||
const auto shortcutValidation = m_shortcutManager.ValidateConfiguration();
|
||||
const auto shortcutContext = BuildShortcutContext();
|
||||
|
||||
UIDrawData drawData = {};
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("Shortcut Dispatch");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
const float margin = 20.0f;
|
||||
const UIRect headerRect(margin, margin, width - margin * 2.0f, 178.0f);
|
||||
const UIRect leftRect(margin, headerRect.y + headerRect.height + 16.0f, 320.0f, height - 254.0f);
|
||||
const UIRect rightRect(leftRect.x + leftRect.width + 16.0f, leftRect.y, width - leftRect.width - margin * 2.0f - 16.0f, height - 254.0f);
|
||||
const UIRect footerRect(margin, height - 100.0f, width - margin * 2.0f, 80.0f);
|
||||
|
||||
DrawCard(drawList, headerRect, "豬玖ッ募粥閭ス<EFBFBD>哘ditor Shortcut Dispatch", "蜿ェ鬪瑚ッ?shortcut match -> editor command -> workspace command dispatch縲?);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 70.0f), "1. 蛻晏ァ<E6998F> active=doc-a<>梧潔 Ctrl+P<>悟ス灘<EFBDBD>?documents scope 蠎泌多荳?Activate Details縲?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 92.0f), "2. active=details 蜷主<E89CB7>謖?Ctrl+P<>悟酔荳荳?chord 蠎泌多荳ュ蜿ヲ荳譚?panel binding<6E>悟ケカ謇ァ陦<EFBDA7> Reset縲?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 114.0f), "3. 謖?Ctrl+H<>碁ェ瑚ッ?ActivePanel 蜿よ焚貅撰シ帶<EFBDBC>?Ctrl+W / Ctrl+O<>碁ェ瑚ッ∝崋螳?panel 蜻ス莉、縲?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 136.0f), "4. 轤?Toggle Text Input 謌匁潔 T<>悟<EFBFBD>謖?Ctrl+H / Ctrl+P<>郡hortcut result 蠢<>。サ蜿俶<E89CBF> Suppressed縲?, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(headerRect.x + 18.0f, headerRect.y + 158.0f), "5. F12 菫晏ュ俶穐蝗セ縲よウィ諢冗恚 Footer 驥?Shortcut result 蜥?Command result 譏ッ荳、螻ら憾諤√?, kTextPrimary, 13.0f);
|
||||
|
||||
DrawCard(drawList, leftRect, "謫堺ス懷<EFBFBD>?, "霑咎㈹蜿ェ謾セ霎<EFBFBD>勧謖蛾聴<EFBFBD>帷悄豁」逧<EFBFBD>ェ瑚ッ∝<EFBFBD>蜿」譏ッ髞ョ逶伜ソォ謐キ髞ョ縲?);
|
||||
DrawCard(drawList, rightRect, "迥カ諤∵遭隕?, "逵句ス灘<EFBFBD>?scope縲》ext input縲『orkspace 迥カ諤∝柱 bindings縲?);
|
||||
DrawCard(drawList, footerRect, "譛霑醍サ捺<EFBFBD>?, "Shortcut result 荳咲ュ我コ?Command result縲?);
|
||||
|
||||
m_buttons = {
|
||||
{ ActionId::ToggleTextInput, m_textInputActive ? "Toggle Text Input: On" : "Toggle Text Input: Off", UIRect(leftRect.x + 18.0f, leftRect.y + 74.0f, leftRect.width - 36.0f, 46.0f) },
|
||||
{ ActionId::ResetScenario, "Reset Scenario", UIRect(leftRect.x + 18.0f, leftRect.y + 132.0f, leftRect.width - 36.0f, 46.0f) }
|
||||
};
|
||||
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
drawList.AddFilledRect(button.rect, kCardBorder, 8.0f);
|
||||
drawList.AddRectOutline(button.rect, kTextMuted, 1.0f, 8.0f);
|
||||
drawList.AddText(UIPoint(button.rect.x + 14.0f, button.rect.y + 13.0f), button.label, kTextPrimary, 13.0f);
|
||||
}
|
||||
|
||||
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 210.0f), "Bindings", kAccent, 15.0f);
|
||||
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 236.0f), "Ctrl+P documents -> Activate Details", kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 256.0f), "Ctrl+P details -> Reset Workspace", kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 276.0f), "Ctrl+H global -> Hide Active", kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 296.0f), "Ctrl+W global -> Close Doc B", kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 316.0f), "Ctrl+O global -> Open Doc B", kTextPrimary, 12.0f);
|
||||
drawList.AddText(UIPoint(leftRect.x + 18.0f, leftRect.y + 336.0f), "Ctrl+R global -> Reset Workspace", kTextPrimary, 12.0f);
|
||||
|
||||
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 74.0f), "Active panel: " + m_controller.GetWorkspace().activePanelId, kTextPrimary, 14.0f);
|
||||
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 98.0f), "Visible panels: " + JoinVisiblePanels(m_controller), kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 122.0f), "Current panel scope: " + DescribeCurrentScope(m_controller.GetWorkspace().activePanelId), kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 146.0f), "Panel owner id: " + std::to_string(shortcutContext.commandScope.panelId), kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 170.0f), std::string("Text input active: ") + (m_textInputActive ? "true" : "false"), m_textInputActive ? kWarning : kSuccess, 13.0f);
|
||||
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 194.0f), validation.IsValid() ? "Workspace validation: OK" : "Workspace validation: " + validation.message, validation.IsValid() ? kSuccess : kDanger, 12.0f);
|
||||
drawList.AddText(UIPoint(rightRect.x + 18.0f, rightRect.y + 216.0f), shortcutValidation.IsValid() ? "Shortcut manager validation: OK" : "Shortcut manager validation: " + shortcutValidation.message, shortcutValidation.IsValid() ? kSuccess : kDanger, 12.0f);
|
||||
|
||||
const std::vector<std::pair<std::string, std::string>> panelDefs = {
|
||||
{ "doc-a", "Document A" },
|
||||
{ "doc-b", "Document B" },
|
||||
{ "details", "Details" }
|
||||
};
|
||||
float rowY = rightRect.y + 260.0f;
|
||||
for (const auto& [panelId, label] : panelDefs) {
|
||||
const auto* state = FindUIEditorPanelSessionState(m_controller.GetSession(), panelId);
|
||||
std::string stateText = state == nullptr
|
||||
? "missing"
|
||||
: (!state->open ? "closed" : (!state->visible ? "hidden" : "visible"));
|
||||
drawList.AddText(
|
||||
UIPoint(rightRect.x + 18.0f, rowY),
|
||||
label + ": " + stateText + (m_controller.GetWorkspace().activePanelId == panelId ? " | active" : ""),
|
||||
ResolveCurrentPanelOwnerId(panelId) == shortcutContext.commandScope.panelId && panelId == "details"
|
||||
? kAccent
|
||||
: (ResolveCurrentPanelOwnerId(panelId) == shortcutContext.commandScope.panelId && panelId != "details" ? kAccent : kTextPrimary),
|
||||
13.0f);
|
||||
rowY += 22.0f;
|
||||
}
|
||||
|
||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 20.0f), "Last action: " + m_lastAction, kTextPrimary, 13.0f);
|
||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 40.0f), "Shortcut result: " + m_lastShortcutStatus, m_lastShortcutColor, 12.0f);
|
||||
drawList.AddText(UIPoint(footerRect.x + 260.0f, footerRect.y + 40.0f), "Command result: " + m_lastCommandStatus, m_lastCommandColor, 12.0f);
|
||||
drawList.AddText(UIPoint(footerRect.x + 18.0f, footerRect.y + 60.0f), m_lastMessage, kTextPrimary, 12.0f);
|
||||
|
||||
const std::string captureSummary =
|
||||
m_autoScreenshot.HasPendingCapture()
|
||||
? "謌ェ蝗セ謗帝弌荳?.."
|
||||
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||
? std::string("F12 -> tests/UI/Editor/manual_validation/state/shortcut_dispatch/captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary());
|
||||
drawList.AddText(UIPoint(footerRect.x + 870.0f, footerRect.y + 60.0f), captureSummary, kTextMuted, 12.0f);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
drawData,
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
framePresented);
|
||||
}
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
HINSTANCE m_hInstance = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
NativeRenderer m_renderer = {};
|
||||
AutoScreenshotController m_autoScreenshot = {};
|
||||
InputModifierTracker m_inputModifierTracker = {};
|
||||
UIEditorWorkspaceController m_controller = {};
|
||||
UIEditorShortcutManager m_shortcutManager = {};
|
||||
bool m_textInputActive = false;
|
||||
std::vector<ButtonState> m_buttons = {};
|
||||
std::string m_lastAction = {};
|
||||
std::string m_lastShortcutStatus = {};
|
||||
std::string m_lastCommandStatus = {};
|
||||
std::string m_lastMessage = {};
|
||||
UIColor m_lastShortcutColor = kTextMuted;
|
||||
UIColor m_lastCommandColor = kTextMuted;
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
ScenarioApp app;
|
||||
return app.Run(hInstance, nCmdShow);
|
||||
}
|
||||
@@ -1,8 +0,0 @@
|
||||
add_executable(editor_ui_viewport_input_bridge_basic_validation WIN32
|
||||
main.cpp
|
||||
)
|
||||
|
||||
xcengine_configure_editor_ui_integration_validation_target(
|
||||
editor_ui_viewport_input_bridge_basic_validation
|
||||
OUTPUT_NAME "XCUIEditorViewportInputBridgeBasicValidation"
|
||||
)
|
||||
@@ -1 +0,0 @@
|
||||
|
||||
@@ -1,866 +0,0 @@
|
||||
#ifndef NOMINMAX
|
||||
#define NOMINMAX
|
||||
#endif
|
||||
|
||||
#include <XCEditor/Viewport/UIEditorViewportInputBridge.h>
|
||||
#include <XCEditor/Viewport/UIEditorViewportSlot.h>
|
||||
#include "Rendering/Native/AutoScreenshot.h"
|
||||
#include "Platform/Win32/InputModifierTracker.h"
|
||||
#include "Rendering/Native/NativeRenderer.h"
|
||||
|
||||
#include <XCEngine/Input/InputTypes.h>
|
||||
#include <XCEngine/UI/DrawData.h>
|
||||
|
||||
#include <windows.h>
|
||||
#include <windowsx.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <filesystem>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
#include <string_view>
|
||||
#include <utility>
|
||||
#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::UIColor;
|
||||
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::InputModifierTracker;
|
||||
using XCEngine::UI::Editor::Host::NativeRenderer;
|
||||
using XCEngine::UI::Editor::IsUIEditorViewportInputBridgeKeyDown;
|
||||
using XCEngine::UI::Editor::IsUIEditorViewportInputBridgePointerButtonDown;
|
||||
using XCEngine::UI::Editor::UIEditorViewportInputBridgeFrame;
|
||||
using XCEngine::UI::Editor::UIEditorViewportInputBridgeState;
|
||||
using XCEngine::UI::Editor::UpdateUIEditorViewportInputBridge;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorViewportSlotBackground;
|
||||
using XCEngine::UI::Editor::Widgets::AppendUIEditorViewportSlotForeground;
|
||||
using XCEngine::UI::Editor::Widgets::BuildUIEditorViewportSlotLayout;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarSegment;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorStatusBarSlot;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorViewportSlotChrome;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorViewportSlotFrame;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorViewportSlotLayout;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorViewportSlotState;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorViewportSlotToolItem;
|
||||
using XCEngine::UI::Editor::Widgets::UIEditorViewportSlotToolSlot;
|
||||
|
||||
constexpr const wchar_t* kWindowClassName = L"XCUIEditorViewportInputBridgeBasicValidation";
|
||||
constexpr const wchar_t* kWindowTitle = L"XCUI 编辑å™?| 视å<E280A0>£è¾“入桥接";
|
||||
|
||||
constexpr UIColor kWindowBg(0.12f, 0.12f, 0.12f, 1.0f);
|
||||
constexpr UIColor kCardBg(0.18f, 0.18f, 0.18f, 1.0f);
|
||||
constexpr UIColor kCardBorder(0.29f, 0.29f, 0.29f, 1.0f);
|
||||
constexpr UIColor kTextPrimary(0.94f, 0.94f, 0.94f, 1.0f);
|
||||
constexpr UIColor kTextMuted(0.72f, 0.72f, 0.72f, 1.0f);
|
||||
constexpr UIColor kTextWeak(0.56f, 0.56f, 0.56f, 1.0f);
|
||||
constexpr UIColor kButtonBg(0.25f, 0.25f, 0.25f, 1.0f);
|
||||
constexpr UIColor kButtonBorder(0.47f, 0.47f, 0.47f, 1.0f);
|
||||
constexpr UIColor kPreviewBg(0.15f, 0.15f, 0.15f, 1.0f);
|
||||
|
||||
enum class ActionId : unsigned char {
|
||||
Reset = 0,
|
||||
Capture
|
||||
};
|
||||
|
||||
struct ButtonState {
|
||||
ActionId action = ActionId::Reset;
|
||||
std::string label = {};
|
||||
UIRect rect = {};
|
||||
};
|
||||
|
||||
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::string BoolText(bool value) {
|
||||
return value ? "å¼€" : "å…?;
|
||||
}
|
||||
|
||||
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) + ")";
|
||||
}
|
||||
|
||||
std::string DescribeKeyCode(std::int32_t keyCode) {
|
||||
switch (static_cast<KeyCode>(keyCode)) {
|
||||
case KeyCode::A: return "A";
|
||||
case KeyCode::D: return "D";
|
||||
case KeyCode::F: return "F";
|
||||
case KeyCode::Q: return "Q";
|
||||
case KeyCode::S: return "S";
|
||||
case KeyCode::W: return "W";
|
||||
case KeyCode::Space: return "Space";
|
||||
case KeyCode::LeftShift: return "LeftShift";
|
||||
case KeyCode::LeftCtrl: return "LeftCtrl";
|
||||
case KeyCode::LeftAlt: return "LeftAlt";
|
||||
case KeyCode::Escape: return "Escape";
|
||||
case KeyCode::Enter: return "Enter";
|
||||
case KeyCode::Left: return "Left";
|
||||
case KeyCode::Right: return "Right";
|
||||
case KeyCode::Up: return "Up";
|
||||
case KeyCode::Down: return "Down";
|
||||
case KeyCode::F12: return "F12";
|
||||
case KeyCode::None:
|
||||
default:
|
||||
return std::to_string(keyCode);
|
||||
}
|
||||
}
|
||||
|
||||
std::string FormatKeyCodes(const std::vector<std::int32_t>& keyCodes) {
|
||||
if (keyCodes.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::string result = {};
|
||||
for (std::size_t index = 0u; index < keyCodes.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
result += ", ";
|
||||
}
|
||||
|
||||
result += DescribeKeyCode(keyCodes[index]);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::string DescribeButtonStates(const UIEditorViewportInputBridgeState& state) {
|
||||
return std::string("L=") +
|
||||
BoolText(IsUIEditorViewportInputBridgePointerButtonDown(state, UIPointerButton::Left)) +
|
||||
" R=" +
|
||||
BoolText(IsUIEditorViewportInputBridgePointerButtonDown(state, UIPointerButton::Right)) +
|
||||
" M=" +
|
||||
BoolText(IsUIEditorViewportInputBridgePointerButtonDown(state, UIPointerButton::Middle));
|
||||
}
|
||||
|
||||
std::string DescribeKeyStates(const UIEditorViewportInputBridgeState& state) {
|
||||
return std::string("W=") +
|
||||
BoolText(IsUIEditorViewportInputBridgeKeyDown(state, static_cast<std::int32_t>(KeyCode::W))) +
|
||||
" A=" +
|
||||
BoolText(IsUIEditorViewportInputBridgeKeyDown(state, static_cast<std::int32_t>(KeyCode::A))) +
|
||||
" F=" +
|
||||
BoolText(IsUIEditorViewportInputBridgeKeyDown(state, static_cast<std::int32_t>(KeyCode::F))) +
|
||||
" Space=" +
|
||||
BoolText(IsUIEditorViewportInputBridgeKeyDown(state, static_cast<std::int32_t>(KeyCode::Space)));
|
||||
}
|
||||
|
||||
std::string DescribeCharacters(const UIEditorViewportInputBridgeFrame& frame) {
|
||||
if (frame.characters.empty()) {
|
||||
return "(none)";
|
||||
}
|
||||
|
||||
std::string result = {};
|
||||
for (std::size_t index = 0u; index < frame.characters.size(); ++index) {
|
||||
if (index > 0u) {
|
||||
result += ", ";
|
||||
}
|
||||
|
||||
const std::uint32_t character = frame.characters[index];
|
||||
if (character >= 32u && character < 127u) {
|
||||
result.push_back(static_cast<char>(character));
|
||||
} else {
|
||||
result += "U+" + std::to_string(character);
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
std::int32_t MapVirtualKeyToUIKeyCode(WPARAM wParam) {
|
||||
switch (wParam) {
|
||||
case 'A': return static_cast<std::int32_t>(KeyCode::A);
|
||||
case 'D': return static_cast<std::int32_t>(KeyCode::D);
|
||||
case 'F': return static_cast<std::int32_t>(KeyCode::F);
|
||||
case 'Q': return static_cast<std::int32_t>(KeyCode::Q);
|
||||
case 'S': return static_cast<std::int32_t>(KeyCode::S);
|
||||
case 'W': return static_cast<std::int32_t>(KeyCode::W);
|
||||
case VK_SPACE: return static_cast<std::int32_t>(KeyCode::Space);
|
||||
case VK_SHIFT: return static_cast<std::int32_t>(KeyCode::LeftShift);
|
||||
case VK_CONTROL: return static_cast<std::int32_t>(KeyCode::LeftCtrl);
|
||||
case VK_MENU: return static_cast<std::int32_t>(KeyCode::LeftAlt);
|
||||
case VK_ESCAPE: return static_cast<std::int32_t>(KeyCode::Escape);
|
||||
case VK_RETURN: return static_cast<std::int32_t>(KeyCode::Enter);
|
||||
case VK_UP: return static_cast<std::int32_t>(KeyCode::Up);
|
||||
case VK_DOWN: return static_cast<std::int32_t>(KeyCode::Down);
|
||||
case VK_LEFT: return static_cast<std::int32_t>(KeyCode::Left);
|
||||
case VK_RIGHT: return static_cast<std::int32_t>(KeyCode::Right);
|
||||
case VK_F12: return static_cast<std::int32_t>(KeyCode::F12);
|
||||
default: return static_cast<std::int32_t>(KeyCode::None);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawCard(
|
||||
UIDrawList& drawList,
|
||||
const UIRect& rect,
|
||||
std::string_view title,
|
||||
std::string_view subtitle = {}) {
|
||||
drawList.AddFilledRect(rect, kCardBg, 10.0f);
|
||||
drawList.AddRectOutline(rect, kCardBorder, 1.0f, 10.0f);
|
||||
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 14.0f), std::string(title), kTextPrimary, 17.0f);
|
||||
if (!subtitle.empty()) {
|
||||
drawList.AddText(UIPoint(rect.x + 16.0f, rect.y + 38.0f), std::string(subtitle), kTextMuted, 12.0f);
|
||||
}
|
||||
}
|
||||
|
||||
void DrawButton(UIDrawList& drawList, const ButtonState& button) {
|
||||
drawList.AddFilledRect(button.rect, kButtonBg, 8.0f);
|
||||
drawList.AddRectOutline(button.rect, kButtonBorder, 1.0f, 8.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(button.rect.x + 12.0f, button.rect.y + 10.0f),
|
||||
button.label,
|
||||
kTextPrimary,
|
||||
12.0f);
|
||||
}
|
||||
|
||||
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 = reinterpret_cast<ScenarioApp*>(createStruct->lpCreateParams);
|
||||
SetWindowLongPtrW(hwnd, GWLP_USERDATA, reinterpret_cast<LONG_PTR>(app));
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
auto* app = reinterpret_cast<ScenarioApp*>(GetWindowLongPtrW(hwnd, GWLP_USERDATA));
|
||||
switch (message) {
|
||||
case WM_SIZE:
|
||||
if (app != nullptr && wParam != SIZE_MINIMIZED) {
|
||||
app->m_renderer.Resize(static_cast<UINT>(LOWORD(lParam)), static_cast<UINT>(HIWORD(lParam)));
|
||||
}
|
||||
return 0;
|
||||
case WM_MOUSEMOVE:
|
||||
if (app != nullptr) {
|
||||
app->QueuePointerEvent(UIInputEventType::PointerMove, UIPointerButton::None, wParam, lParam);
|
||||
TRACKMOUSEEVENT event = {};
|
||||
event.cbSize = sizeof(event);
|
||||
event.dwFlags = TME_LEAVE;
|
||||
event.hwndTrack = hwnd;
|
||||
TrackMouseEvent(&event);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MOUSELEAVE:
|
||||
if (app != nullptr) {
|
||||
app->QueuePointerLeaveEvent();
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONDOWN:
|
||||
if (app != nullptr) {
|
||||
SetFocus(hwnd);
|
||||
app->HandlePointerDown(UIPointerButton::Left, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_LBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandlePointerUp(UIPointerButton::Left, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_RBUTTONDOWN:
|
||||
if (app != nullptr) {
|
||||
SetFocus(hwnd);
|
||||
app->HandlePointerDown(UIPointerButton::Right, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_RBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandlePointerUp(UIPointerButton::Right, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MBUTTONDOWN:
|
||||
if (app != nullptr) {
|
||||
SetFocus(hwnd);
|
||||
app->HandlePointerDown(UIPointerButton::Middle, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MBUTTONUP:
|
||||
if (app != nullptr) {
|
||||
app->HandlePointerUp(UIPointerButton::Middle, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_MOUSEWHEEL:
|
||||
if (app != nullptr) {
|
||||
app->QueuePointerWheelEvent(GET_WHEEL_DELTA_WPARAM(wParam), wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_SETFOCUS:
|
||||
if (app != nullptr) {
|
||||
app->m_inputModifierTracker.SyncFromSystemState();
|
||||
app->QueueFocusEvent(UIInputEventType::FocusGained);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KILLFOCUS:
|
||||
if (app != nullptr) {
|
||||
if (GetCapture() == hwnd) {
|
||||
ReleaseCapture();
|
||||
}
|
||||
app->m_inputModifierTracker.Reset();
|
||||
app->QueueFocusEvent(UIInputEventType::FocusLost);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYDOWN:
|
||||
case WM_SYSKEYDOWN:
|
||||
if (app != nullptr) {
|
||||
if (wParam == VK_F12) {
|
||||
app->m_autoScreenshot.RequestCapture("manual_f12");
|
||||
InvalidateRect(hwnd, nullptr, FALSE);
|
||||
UpdateWindow(hwnd);
|
||||
return 0;
|
||||
}
|
||||
app->QueueKeyEvent(UIInputEventType::KeyDown, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_KEYUP:
|
||||
case WM_SYSKEYUP:
|
||||
if (app != nullptr) {
|
||||
app->QueueKeyEvent(UIInputEventType::KeyUp, wParam, lParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_CHAR:
|
||||
if (app != nullptr) {
|
||||
app->QueueCharacterEvent(wParam);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_PAINT:
|
||||
if (app != nullptr) {
|
||||
PAINTSTRUCT paintStruct = {};
|
||||
BeginPaint(hwnd, &paintStruct);
|
||||
app->RenderFrame();
|
||||
EndPaint(hwnd, &paintStruct);
|
||||
return 0;
|
||||
}
|
||||
break;
|
||||
case WM_ERASEBKGND:
|
||||
return 1;
|
||||
case WM_DESTROY:
|
||||
PostQuitMessage(0);
|
||||
return 0;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return DefWindowProcW(hwnd, message, wParam, lParam);
|
||||
}
|
||||
|
||||
bool Initialize(HINSTANCE hInstance, int nCmdShow) {
|
||||
m_captureRoot =
|
||||
ResolveRepoRootPath() / "tests/UI/Editor/manual_validation/state/viewport_input_bridge_basic/captures";
|
||||
m_autoScreenshot.Initialize(m_captureRoot);
|
||||
|
||||
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,
|
||||
1520,
|
||||
940,
|
||||
nullptr,
|
||||
nullptr,
|
||||
hInstance,
|
||||
this);
|
||||
if (m_hwnd == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!m_renderer.Initialize(m_hwnd)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ShowWindow(m_hwnd, nCmdShow);
|
||||
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) {
|
||||
UnregisterClassW(kWindowClassName, GetModuleHandleW(nullptr));
|
||||
m_windowClassAtom = 0;
|
||||
}
|
||||
}
|
||||
|
||||
void ResetScenario() {
|
||||
m_inputModifierTracker.Reset();
|
||||
m_bridgeState = {};
|
||||
m_bridgeFrame = {};
|
||||
m_pendingEvents.clear();
|
||||
m_lastResult = "就绪";
|
||||
}
|
||||
|
||||
void QueuePointerEvent(UIInputEventType type, UIPointerButton button, WPARAM wParam, LPARAM lParam) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
event.pointerButton = button;
|
||||
event.position = UIPoint(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
event.modifiers = m_inputModifierTracker.BuildPointerModifiers(static_cast<std::size_t>(wParam));
|
||||
m_pendingEvents.push_back(event);
|
||||
}
|
||||
|
||||
void QueuePointerLeaveEvent() {
|
||||
UIInputEvent event = {};
|
||||
event.type = UIInputEventType::PointerLeave;
|
||||
if (m_hwnd != nullptr) {
|
||||
POINT clientPoint = {};
|
||||
GetCursorPos(&clientPoint);
|
||||
ScreenToClient(m_hwnd, &clientPoint);
|
||||
event.position = UIPoint(static_cast<float>(clientPoint.x), static_cast<float>(clientPoint.y));
|
||||
}
|
||||
m_pendingEvents.push_back(event);
|
||||
}
|
||||
|
||||
void QueuePointerWheelEvent(short wheelDelta, WPARAM wParam, LPARAM lParam) {
|
||||
if (m_hwnd == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
POINT screenPoint = {
|
||||
GET_X_LPARAM(lParam),
|
||||
GET_Y_LPARAM(lParam)
|
||||
};
|
||||
ScreenToClient(m_hwnd, &screenPoint);
|
||||
|
||||
UIInputEvent event = {};
|
||||
event.type = UIInputEventType::PointerWheel;
|
||||
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_pendingEvents.push_back(event);
|
||||
}
|
||||
|
||||
void QueueKeyEvent(UIInputEventType type, WPARAM wParam, LPARAM lParam) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
event.keyCode = MapVirtualKeyToUIKeyCode(wParam);
|
||||
event.modifiers = m_inputModifierTracker.ApplyKeyMessage(type, wParam, lParam);
|
||||
event.repeat = (static_cast<std::uint32_t>(lParam) & 0x40000000u) != 0u;
|
||||
m_pendingEvents.push_back(event);
|
||||
}
|
||||
|
||||
void QueueCharacterEvent(WPARAM wParam) {
|
||||
UIInputEvent event = {};
|
||||
event.type = UIInputEventType::Character;
|
||||
event.character = static_cast<std::uint32_t>(wParam);
|
||||
event.modifiers = m_inputModifierTracker.GetCurrentModifiers();
|
||||
m_pendingEvents.push_back(event);
|
||||
}
|
||||
|
||||
void QueueFocusEvent(UIInputEventType type) {
|
||||
UIInputEvent event = {};
|
||||
event.type = type;
|
||||
event.modifiers = m_inputModifierTracker.GetCurrentModifiers();
|
||||
m_pendingEvents.push_back(event);
|
||||
}
|
||||
|
||||
void HandlePointerDown(UIPointerButton button, WPARAM wParam, LPARAM lParam) {
|
||||
QueuePointerEvent(UIInputEventType::PointerButtonDown, button, wParam, lParam);
|
||||
const UIPoint point(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
if (ContainsPoint(m_layout.inputRect, point.x, point.y)) {
|
||||
SetCapture(m_hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
void HandlePointerUp(UIPointerButton button, WPARAM wParam, LPARAM lParam) {
|
||||
QueuePointerEvent(UIInputEventType::PointerButtonUp, button, wParam, lParam);
|
||||
|
||||
const UIPoint point(
|
||||
static_cast<float>(GET_X_LPARAM(lParam)),
|
||||
static_cast<float>(GET_Y_LPARAM(lParam)));
|
||||
for (const ButtonState& buttonState : m_buttons) {
|
||||
if (!ContainsPoint(buttonState.rect, point.x, point.y)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (buttonState.action == ActionId::Reset) {
|
||||
ResetScenario();
|
||||
m_lastResult = "场景已é‡<EFBFBD>ç½?;
|
||||
} else {
|
||||
m_autoScreenshot.RequestCapture("manual_button");
|
||||
InvalidateRect(m_hwnd, nullptr, FALSE);
|
||||
UpdateWindow(m_hwnd);
|
||||
m_lastResult = "æˆªå›¾å·²åŠ å…¥é˜Ÿåˆ?;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
if (GetCapture() == m_hwnd) {
|
||||
ReleaseCapture();
|
||||
}
|
||||
}
|
||||
|
||||
UIEditorViewportSlotChrome BuildChrome() const {
|
||||
UIEditorViewportSlotChrome chrome = {};
|
||||
chrome.title = "场景视图";
|
||||
chrome.subtitle = "视å<EFBFBD>£è¾“入桥接验è¯<EFBFBD>";
|
||||
chrome.showTopBar = true;
|
||||
chrome.showBottomBar = true;
|
||||
chrome.topBarHeight = 40.0f;
|
||||
chrome.bottomBarHeight = 28.0f;
|
||||
return chrome;
|
||||
}
|
||||
|
||||
UIEditorViewportSlotFrame BuildFrame() const {
|
||||
UIEditorViewportSlotFrame frame = {};
|
||||
frame.hasTexture = true;
|
||||
frame.texture = { 1u, 1280u, 720u };
|
||||
frame.presentedSize = { 1280.0f, 720.0f };
|
||||
frame.statusText = "模拟视å<EFBFBD>£å¸?;
|
||||
return frame;
|
||||
}
|
||||
|
||||
std::vector<UIEditorViewportSlotToolItem> BuildToolItems() const {
|
||||
return {
|
||||
{ "mode", "é€<EFBFBD>视", UIEditorViewportSlotToolSlot::Leading, true, true, 98.0f },
|
||||
{ "input", "输入", UIEditorViewportSlotToolSlot::Trailing, true, true, 58.0f }
|
||||
};
|
||||
}
|
||||
|
||||
std::vector<UIEditorStatusBarSegment> BuildStatusSegments() const {
|
||||
return {
|
||||
{ "hover", std::string("悬å<EFBFBD>œ ") + BoolText(m_bridgeFrame.hovered), UIEditorStatusBarSlot::Leading, {}, true, true, 96.0f },
|
||||
{ "focus", std::string("焦点 ") + BoolText(m_bridgeFrame.focused), UIEditorStatusBarSlot::Leading, {}, true, false, 92.0f },
|
||||
{ "capture", std::string("æ<EFBFBD>•获 ") + BoolText(m_bridgeFrame.captured), UIEditorStatusBarSlot::Trailing, {}, true, true, 110.0f },
|
||||
{ "wheel", "滚轮 " + FormatFloat(m_bridgeFrame.wheelDelta), UIEditorStatusBarSlot::Trailing, {}, true, false, 86.0f }
|
||||
};
|
||||
}
|
||||
|
||||
void UpdateLayoutForCurrentWindow() {
|
||||
if (m_hwnd == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
RECT clientRect = {};
|
||||
GetClientRect(m_hwnd, &clientRect);
|
||||
const float width = static_cast<float>((std::max)(1L, clientRect.right - clientRect.left));
|
||||
const float height = static_cast<float>((std::max)(1L, clientRect.bottom - clientRect.top));
|
||||
|
||||
const float leftColumnWidth = 440.0f;
|
||||
const float outerPadding = 20.0f;
|
||||
m_introRect = UIRect(outerPadding, outerPadding, leftColumnWidth, 246.0f);
|
||||
m_controlsRect = UIRect(outerPadding, 286.0f, leftColumnWidth, 144.0f);
|
||||
m_stateRect = UIRect(outerPadding, 450.0f, leftColumnWidth, height - 470.0f);
|
||||
m_previewRect = UIRect(
|
||||
leftColumnWidth + outerPadding * 2.0f,
|
||||
outerPadding,
|
||||
width - leftColumnWidth - outerPadding * 3.0f,
|
||||
height - outerPadding * 2.0f);
|
||||
m_slotRect = UIRect(
|
||||
m_previewRect.x + 18.0f,
|
||||
m_previewRect.y + 18.0f,
|
||||
m_previewRect.width - 36.0f,
|
||||
m_previewRect.height - 36.0f);
|
||||
|
||||
const float buttonHeight = 34.0f;
|
||||
m_buttons = {
|
||||
{ ActionId::Reset, "é‡<EFBFBD>ç½®", UIRect(m_controlsRect.x + 16.0f, m_controlsRect.y + 54.0f, m_controlsRect.width - 32.0f, buttonHeight) },
|
||||
{ ActionId::Capture, "截图", UIRect(m_controlsRect.x + 16.0f, m_controlsRect.y + 98.0f, m_controlsRect.width - 32.0f, buttonHeight) }
|
||||
};
|
||||
|
||||
m_layout = BuildUIEditorViewportSlotLayout(
|
||||
m_slotRect,
|
||||
BuildChrome(),
|
||||
BuildFrame(),
|
||||
BuildToolItems(),
|
||||
BuildStatusSegments());
|
||||
}
|
||||
|
||||
void RenderFrame() {
|
||||
if (m_hwnd == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
RECT clientRect = {};
|
||||
GetClientRect(m_hwnd, &clientRect);
|
||||
const float width = static_cast<float>((std::max)(1L, clientRect.right - clientRect.left));
|
||||
const float height = static_cast<float>((std::max)(1L, clientRect.bottom - clientRect.top));
|
||||
|
||||
UpdateLayoutForCurrentWindow();
|
||||
|
||||
std::vector<UIInputEvent> frameEvents = std::move(m_pendingEvents);
|
||||
m_pendingEvents.clear();
|
||||
m_bridgeFrame = UpdateUIEditorViewportInputBridge(
|
||||
m_bridgeState,
|
||||
m_layout.inputRect,
|
||||
frameEvents);
|
||||
if (m_bridgeFrame.focusLost) {
|
||||
m_lastResult = "焦点丢失";
|
||||
} else if (m_bridgeFrame.focusGained) {
|
||||
m_lastResult = "获得焦点";
|
||||
} else if (m_bridgeFrame.captureStarted) {
|
||||
m_lastResult = "开始æ<EFBFBD>•èŽ?;
|
||||
} else if (m_bridgeFrame.captureEnded) {
|
||||
m_lastResult = "结æ<EFBFBD>Ÿæ<EFBFBD>•获";
|
||||
} else if (!m_bridgeFrame.characters.empty()) {
|
||||
m_lastResult = "å—符 " + DescribeCharacters(m_bridgeFrame);
|
||||
} else if (!m_bridgeFrame.pressedKeyCodes.empty()) {
|
||||
m_lastResult = "按键按下 " + FormatKeyCodes(m_bridgeFrame.pressedKeyCodes);
|
||||
} else if (!m_bridgeFrame.releasedKeyCodes.empty()) {
|
||||
m_lastResult = "按键抬起 " + FormatKeyCodes(m_bridgeFrame.releasedKeyCodes);
|
||||
} else if (m_bridgeFrame.wheelDelta != 0.0f) {
|
||||
m_lastResult = "滚轮 " + std::to_string(static_cast<int>(m_bridgeFrame.wheelDelta));
|
||||
} else if (m_bridgeFrame.pointerPressedInside) {
|
||||
m_lastResult = "内部按下";
|
||||
} else if (m_bridgeFrame.pointerReleasedInside) {
|
||||
m_lastResult = "内部抬起";
|
||||
}
|
||||
|
||||
UIEditorViewportSlotState slotState = {};
|
||||
slotState.focused = m_bridgeFrame.focused;
|
||||
slotState.surfaceHovered = m_bridgeFrame.hovered;
|
||||
slotState.surfaceActive = m_bridgeFrame.focused || m_bridgeFrame.captured;
|
||||
slotState.inputCaptured = m_bridgeFrame.captured;
|
||||
|
||||
UIDrawData drawData = {};
|
||||
UIDrawList& drawList = drawData.EmplaceDrawList("ViewportInputBridgeBasic");
|
||||
drawList.AddFilledRect(UIRect(0.0f, 0.0f, width, height), kWindowBg);
|
||||
|
||||
DrawCard(
|
||||
drawList,
|
||||
m_introRect,
|
||||
"测试功能:ViewportInputBridge",
|
||||
"å<EFBFBD>ªéªŒè¯?Editor viewport 输入桥接,ä¸<C3A4>æ··å…¥ Scene/Game 业务ã€?);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 66.0f),
|
||||
"检查:hover / focus / capture / local å<><C3A5>æ ‡ã€?,
|
||||
kTextMuted,
|
||||
11.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 86.0f),
|
||||
"检查:surface 内左键按下å<E280B9>Žï¼ŒFocus + Capture 进入ã€?,
|
||||
kTextMuted,
|
||||
11.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 106.0f),
|
||||
"检查:drag å‡?surface å<>Žï¼ŒCapture ä¿<C3A4>留,Local Pos ç»§ç»æ›´æ–°ã€?,
|
||||
kTextMuted,
|
||||
11.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 126.0f),
|
||||
"检查:release å<>Žï¼ŒCapture 必须释放ã€?,
|
||||
kTextMuted,
|
||||
11.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 146.0f),
|
||||
"检查:滚轮 / 按键 / å—符å<C2A6>ªåœ¨ Focus 下进å…?frameã€?,
|
||||
kTextMuted,
|
||||
11.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 166.0f),
|
||||
"æ“<EFBFBD>作:hoverã€<EFBFBD>clickã€<EFBFBD>dragã€<EFBFBD>wheelã€<EFBFBD>A/W/F/Space,并输入å—符ã€?,
|
||||
kTextMuted,
|
||||
11.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 186.0f),
|
||||
"æ“<EFBFBD>作:点å‡?surface 外部,验è¯?clear focusã€?,
|
||||
kTextMuted,
|
||||
11.0f);
|
||||
drawList.AddText(
|
||||
UIPoint(m_introRect.x + 16.0f, m_introRect.y + 210.0f),
|
||||
"结果:左侧状æ€<EFBFBD>ã€<EFBFBD>底部æ<EFBFBD>¡ã€<EFBFBD>surface 边框必须å<C2BB>Œæ¥ã€?,
|
||||
kTextWeak,
|
||||
11.0f);
|
||||
|
||||
DrawCard(drawList, m_controlsRect, "æ“<EFBFBD>作", "å<EFBFBD>ªä¿<EFBFBD>ç•?Reset / 截图 两个辅助æ“<C3A6>作ã€?);
|
||||
for (const ButtonState& button : m_buttons) {
|
||||
DrawButton(drawList, button);
|
||||
}
|
||||
|
||||
DrawCard(drawList, m_stateRect, "状æ€?, "é‡<EFBFBD>点看桥æŽ?frameã€<EFBFBD>按键边沿ã€<EFBFBD>å—符与 modifiersã€?);
|
||||
float stateY = m_stateRect.y + 66.0f;
|
||||
auto addStateLine = [&](std::string text, const UIColor& color = kTextPrimary) {
|
||||
drawList.AddText(UIPoint(m_stateRect.x + 16.0f, stateY), std::move(text), color, 12.0f);
|
||||
stateY += 22.0f;
|
||||
};
|
||||
addStateLine("Hover: " + BoolText(m_bridgeFrame.hovered));
|
||||
addStateLine("Focus: " + BoolText(m_bridgeFrame.focused));
|
||||
addStateLine("Capture: " + BoolText(m_bridgeFrame.captured));
|
||||
addStateLine("Pointer Inside: " + BoolText(m_bridgeFrame.pointerInside));
|
||||
addStateLine("Screen Pos: " + FormatPoint(m_bridgeFrame.screenPointerPosition));
|
||||
addStateLine("Local Pos: " + FormatPoint(m_bridgeFrame.localPointerPosition));
|
||||
addStateLine("Delta: " + FormatPoint(m_bridgeFrame.pointerDelta));
|
||||
addStateLine("Wheel: " + FormatFloat(m_bridgeFrame.wheelDelta));
|
||||
addStateLine("Buttons Down: " + DescribeButtonStates(m_bridgeState));
|
||||
addStateLine("Keys Down: " + DescribeKeyStates(m_bridgeState));
|
||||
addStateLine(
|
||||
"Edges: pressIn " + BoolText(m_bridgeFrame.pointerPressedInside) +
|
||||
" | releaseIn " + BoolText(m_bridgeFrame.pointerReleasedInside));
|
||||
addStateLine(
|
||||
"Focus/Capture Edges: gain " + BoolText(m_bridgeFrame.focusGained) +
|
||||
" | lost " + BoolText(m_bridgeFrame.focusLost) +
|
||||
" | cap+ " + BoolText(m_bridgeFrame.captureStarted) +
|
||||
" | cap- " + BoolText(m_bridgeFrame.captureEnded));
|
||||
addStateLine(
|
||||
std::string("Modifiers: Ctrl ") + BoolText(m_bridgeFrame.modifiers.control) +
|
||||
" Shift " + BoolText(m_bridgeFrame.modifiers.shift) +
|
||||
" Alt " + BoolText(m_bridgeFrame.modifiers.alt));
|
||||
addStateLine("Characters: " + DescribeCharacters(m_bridgeFrame), kTextMuted);
|
||||
const std::string captureSummary =
|
||||
m_autoScreenshot.HasPendingCapture()
|
||||
? "截图排队�.."
|
||||
: (m_autoScreenshot.GetLastCaptureSummary().empty()
|
||||
? std::string("截图:F12 或按�-> viewport_input_bridge_basic/captures/")
|
||||
: m_autoScreenshot.GetLastCaptureSummary());
|
||||
addStateLine("Result: " + m_lastResult, kTextMuted);
|
||||
addStateLine(captureSummary, kTextWeak);
|
||||
|
||||
DrawCard(drawList, m_previewRect, "预览", "这里å<EFBFBD>ªæ”¾ä¸€ä¸?ViewportSlot,用它承载输入边界ã€?);
|
||||
drawList.AddFilledRect(
|
||||
UIRect(
|
||||
m_previewRect.x + 12.0f,
|
||||
m_previewRect.y + 44.0f,
|
||||
m_previewRect.width - 24.0f,
|
||||
m_previewRect.height - 56.0f),
|
||||
kPreviewBg,
|
||||
10.0f);
|
||||
|
||||
const auto chrome = BuildChrome();
|
||||
const auto frame = BuildFrame();
|
||||
const auto toolItems = BuildToolItems();
|
||||
const auto statusSegments = BuildStatusSegments();
|
||||
m_layout = BuildUIEditorViewportSlotLayout(
|
||||
m_slotRect,
|
||||
chrome,
|
||||
frame,
|
||||
toolItems,
|
||||
statusSegments);
|
||||
AppendUIEditorViewportSlotBackground(
|
||||
drawList,
|
||||
m_layout,
|
||||
toolItems,
|
||||
statusSegments,
|
||||
slotState);
|
||||
AppendUIEditorViewportSlotForeground(
|
||||
drawList,
|
||||
m_layout,
|
||||
chrome,
|
||||
frame,
|
||||
toolItems,
|
||||
statusSegments,
|
||||
slotState);
|
||||
|
||||
const bool framePresented = m_renderer.Render(drawData);
|
||||
m_autoScreenshot.CaptureIfRequested(
|
||||
m_renderer,
|
||||
drawData,
|
||||
static_cast<unsigned int>(width),
|
||||
static_cast<unsigned int>(height),
|
||||
framePresented);
|
||||
}
|
||||
|
||||
HWND m_hwnd = nullptr;
|
||||
ATOM m_windowClassAtom = 0;
|
||||
NativeRenderer m_renderer = {};
|
||||
AutoScreenshotController m_autoScreenshot = {};
|
||||
InputModifierTracker m_inputModifierTracker = {};
|
||||
std::filesystem::path m_captureRoot = {};
|
||||
std::vector<UIInputEvent> m_pendingEvents = {};
|
||||
std::vector<ButtonState> m_buttons = {};
|
||||
UIEditorViewportInputBridgeState m_bridgeState = {};
|
||||
UIEditorViewportInputBridgeFrame m_bridgeFrame = {};
|
||||
UIRect m_introRect = {};
|
||||
UIRect m_controlsRect = {};
|
||||
UIRect m_stateRect = {};
|
||||
UIRect m_previewRect = {};
|
||||
UIRect m_slotRect = {};
|
||||
UIEditorViewportSlotLayout m_layout = {};
|
||||
std::string m_lastResult = {};
|
||||
};
|
||||
|
||||
} // namespace
|
||||
|
||||
int WINAPI wWinMain(HINSTANCE hInstance, HINSTANCE, LPWSTR, int nCmdShow) {
|
||||
return ScenarioApp().Run(hInstance, nCmdShow);
|
||||
}
|
||||
Reference in New Issue
Block a user