2026-04-15 08:24:06 +08:00
|
|
|
#include <XCEditor/Viewport/UIEditorViewportShell.h>
|
2026-04-07 05:33:27 +08:00
|
|
|
|
|
|
|
|
namespace XCEngine::UI::Editor {
|
|
|
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
|
|
using Widgets::BuildUIEditorViewportSlotLayout;
|
|
|
|
|
using Widgets::UIEditorViewportSlotFrame;
|
|
|
|
|
using Widgets::UIEditorViewportSlotLayout;
|
|
|
|
|
using Widgets::UIEditorViewportSlotState;
|
|
|
|
|
|
2026-04-19 00:03:25 +08:00
|
|
|
bool ContainsPoint(
|
|
|
|
|
const ::XCEngine::UI::UIRect& rect,
|
|
|
|
|
const ::XCEngine::UI::UIPoint& point) {
|
|
|
|
|
return point.x >= rect.x &&
|
|
|
|
|
point.x <= rect.x + rect.width &&
|
|
|
|
|
point.y >= rect.y &&
|
|
|
|
|
point.y <= rect.y + rect.height;
|
|
|
|
|
}
|
|
|
|
|
|
2026-04-07 05:33:27 +08:00
|
|
|
UIEditorViewportSlotLayout BuildViewportShellLayout(
|
|
|
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
|
|
|
const UIEditorViewportShellSpec& spec,
|
|
|
|
|
const UIEditorViewportSlotFrame& frame,
|
|
|
|
|
const Widgets::UIEditorViewportSlotMetrics& metrics) {
|
|
|
|
|
return BuildUIEditorViewportSlotLayout(
|
|
|
|
|
bounds,
|
|
|
|
|
spec.chrome,
|
|
|
|
|
frame,
|
|
|
|
|
spec.toolItems,
|
|
|
|
|
spec.statusSegments,
|
|
|
|
|
metrics);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIEditorViewportSlotState BuildViewportShellSlotState(
|
|
|
|
|
const UIEditorViewportShellVisualState& visualState,
|
2026-04-19 00:03:25 +08:00
|
|
|
const UIEditorViewportInputBridgeFrame& inputFrame,
|
|
|
|
|
const UIEditorViewportSlotLayout& slotLayout) {
|
2026-04-07 05:33:27 +08:00
|
|
|
UIEditorViewportSlotState slotState = {};
|
|
|
|
|
slotState.focused = inputFrame.focused;
|
2026-04-19 00:03:25 +08:00
|
|
|
slotState.surfaceHovered =
|
|
|
|
|
inputFrame.hasPointerPosition &&
|
|
|
|
|
ContainsPoint(slotLayout.inputRect, inputFrame.screenPointerPosition);
|
2026-04-07 05:33:27 +08:00
|
|
|
slotState.surfaceActive = inputFrame.focused || inputFrame.captured;
|
|
|
|
|
slotState.inputCaptured = inputFrame.captured;
|
|
|
|
|
slotState.hoveredToolIndex = visualState.hoveredToolIndex;
|
|
|
|
|
slotState.activeToolIndex = visualState.activeToolIndex;
|
|
|
|
|
slotState.statusBarState = visualState.statusBarState;
|
|
|
|
|
slotState.statusBarState.focused =
|
|
|
|
|
slotState.statusBarState.focused || inputFrame.focused;
|
|
|
|
|
return slotState;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
|
|
|
|
|
UIEditorViewportShellRequest ResolveUIEditorViewportShellRequest(
|
|
|
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
|
|
|
const UIEditorViewportShellSpec& spec,
|
|
|
|
|
const Widgets::UIEditorViewportSlotMetrics& metrics) {
|
|
|
|
|
UIEditorViewportShellRequest request = {};
|
|
|
|
|
request.slotLayout = BuildViewportShellLayout(bounds, spec, {}, metrics);
|
|
|
|
|
request.requestedViewportSize = request.slotLayout.requestedSurfaceSize;
|
|
|
|
|
return request;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UIEditorViewportShellFrame UpdateUIEditorViewportShell(
|
|
|
|
|
UIEditorViewportShellState& state,
|
|
|
|
|
const ::XCEngine::UI::UIRect& bounds,
|
|
|
|
|
const UIEditorViewportShellModel& model,
|
|
|
|
|
const std::vector<::XCEngine::UI::UIInputEvent>& inputEvents,
|
2026-04-19 15:52:28 +08:00
|
|
|
const Widgets::UIEditorViewportSlotMetrics& metrics,
|
|
|
|
|
const UIEditorViewportInputBridgeRequest& inputRequest) {
|
2026-04-07 05:33:27 +08:00
|
|
|
UIEditorViewportShellFrame frame = {};
|
|
|
|
|
frame.slotLayout = BuildViewportShellLayout(bounds, model.spec, model.frame, metrics);
|
|
|
|
|
frame.requestedViewportSize = frame.slotLayout.requestedSurfaceSize;
|
|
|
|
|
frame.inputFrame = UpdateUIEditorViewportInputBridge(
|
|
|
|
|
state.inputBridgeState,
|
2026-04-19 00:03:25 +08:00
|
|
|
frame.slotLayout.bounds,
|
2026-04-07 05:33:27 +08:00
|
|
|
frame.slotLayout.inputRect,
|
|
|
|
|
inputEvents,
|
2026-04-19 15:52:28 +08:00
|
|
|
model.spec.inputBridgeConfig,
|
|
|
|
|
inputRequest);
|
2026-04-19 00:03:25 +08:00
|
|
|
frame.slotState =
|
|
|
|
|
BuildViewportShellSlotState(
|
|
|
|
|
model.spec.visualState,
|
|
|
|
|
frame.inputFrame,
|
|
|
|
|
frame.slotLayout);
|
2026-04-07 05:33:27 +08:00
|
|
|
return frame;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace XCEngine::UI::Editor
|