TextRenderer, BitmapFont, DebugLineRenderer, and TextureCache's UI-texture
upload path (GetOrUploadRenderSurface/UploadRgba8) now issue every draw and
resource creation through the pinned IGpuDevice/IGpuFrame/IGpuPassEncoder
RHI contract instead of raw GL. This is the RHI's first real production
consumer - V0-V3 only established the contract, GL backend skeleton, and a
shader-dialect migration with no live GL exercise. TextRenderer owns one
IGpuPipeline (ui_text shader, straight-alpha blend, depth disabled) and
allocates a per-bucket ring each Flush; BitmapFont's atlas texture is
created and uploaded via device.CreateTexture/.Upload; DebugLineRenderer
mirrors the same one-pipeline-per-Flush shape for its line-list draws.
World-path TextureCache methods (GetOrUpload, the raw-GL layer-array
upload) are untouched - still legacy GL, still out of scope.
Frame lifecycle: GpuDeviceFrameLifetime (RenderFrameOrchestrator.cs) wraps
IGpuDevice.BeginFrame()/IGpuFrame.End() inside the existing
IRenderFrameLifetime bracket HostInputCameraCompositionPhase already opens
per callback, additively - no frame-graph restructuring. Ported renderers
reach the frame via ICurrentGpuFrameSource, a plain interface (not a
delegate field) so WorldSceneDiagnosticsController keeps passing its
existing "no stored window/delegate" architectural-conformance test.
Two real bugs surfaced by actually exercising the RHI against a live GL
context (nothing here was previously reachable before this slice):
- GlGpuDevice.BeginFrame() now resets the render-state cache every frame.
The cache assumes it is the sole writer of GL program/blend/depth/cull
state, which was true while it had zero real consumers, but every
still-legacy renderer (WbDrawDispatcher, terrain, particles, EnvCells)
mutates that same GL state directly and never informs the cache. Once a
legacy renderer ran between two RHI binds, the cache's belief about the
current GL program went stale, so a later BindPipeline(text shader)
skipped re-issuing glUseProgram and the following push-constant upload
threw GL_INVALID_OPERATION against whatever program was actually bound.
Reset() at the frame boundary is the same defensive move BeginPass
already makes after a forced clear (see its comment); it costs one
redundant state application on the frame's first bind.
- GL_MULTISAMPLE has no representation in the pinned contract. Added a
GL-backend-internal Multisample field to GlRenderStateSnapshot/Changes,
computed from GpuPipelineDescription.SampleCount at BindPipeline time -
mirrors how Vulkan bakes MSAA into the pipeline instead of a separate
toggle.
Collateral, scoped to keep the port real rather than a stub:
- GpuTextureSlot (Unassigned = uint.MaxValue, NOT 0) now flows through
every consumer of TextureCache.GetOrUploadRenderSurface/UploadRgba8 and
TextRenderer.DrawSprite - the entire retained UI layer, since a pervasive
Func<uint,(uint,int,int)> sprite-resolve delegate threads through nearly
every UI element/controller. Every prior `== 0` / `!= 0` "no texture"
check became `.IsAssigned` / `!.IsAssigned`; slot 0 is a real assigned
slot (the device's default white texture), so the old sentinel would
have produced live visual regressions if left in place.
- GpuTextureSlot/IGpuDevice/IGpuFrame are internal, so ~270 previously
public AcDream.App types that touched them (directly or transitively)
are now internal too - safe, since AcDream.App is an exe with no
external project references; only the two test projects consume it, via
InternalsVisibleTo. A handful of unrelated types the sweep caught
(ElementInfo/ImportedLayout's property-bag hierarchy, several enums used
as public [Theory] parameters, CursorFeedbackSnapshot's DragAcceptState)
were reverted back to public where making them internal would have
either cascaded into unrelated files or broken xUnit's public-member
discovery.
- ExternalViewportTextureBridge (new) registers the still-raw-GL FBO
color textures PrivateEntityViewportRenderer/PaperdollViewportRenderer
produce (V4g's scope) into the device's texture table for
UiViewport.TextureHandle, via a temporary
GlGpuDevice.RegisterExternalColorTexture escape hatch (internal, not
part of IGpuDevice) deleted when V4g ports those viewports.
- TextRenderGlStateScope.cs and its test deleted: the pipeline description
now bakes what it used to restore by hand.
- ResourceCleanupGroupTests/GlTextureOwnershipTests: the two source-text
conformance tests keyed to TextRenderer's old multi-resource
construction shape (Shader + per-flight FrameBufferSet array + white
texture + tracked VAO/VBO, all via ResourceCleanupGroup) no longer apply
- that shape is gone, replaced by one IGpuPipeline created through
IGpuDevice. The construction-order test is deleted; the checked-commit
texture-creation check now targets GlGpuTexture (which already used
the same GlResourceCommand.CreateName primitive before this slice).
Gates:
- dotnet build -c Release: 0 warnings, 0 errors (AcDream.App has
TreatWarningsAsErrors).
- dotnet test tests/AcDream.App.Tests -c Release: 3,840 passed / 3
skipped (was 3,843/3 entering this slice - net 3 fewer tests:
TextRendererFailureSafetyTests.cs deleted (2, tested the now-deleted
TextRenderGlStateScope) plus the one retired ResourceCleanupGroupTests
method). Full solution: 8,908 passed / 5 skipped across all nine test
projects.
- Offline pixel gate (tools/run-offline-pixel-gate.ps1, parent ec414d60
vs this commit): differing fraction 0.318% (1,791/563,200 compared
pixels), above the 0.001 threshold. Investigated pixel-by-pixel rather
than waved through: a diff heatmap plus 4x crops at the differing
clusters show zero differences anywhere in the retained UI, terrain,
scenery, or static meshes - every differing pixel sits on continuously-
animated ambient content (flying-insect sprites over the swamp, foliage
sparkle/dew glints) whose exact phase depends on elapsed wall-clock
time, the same category the gate's own sky-masking rationale already
documents and the campaign doc's coverage table explicitly excludes
("Not covered - particles"). Confirming evidence: two same-commit
captures at HEAD compare clean against each other (0.0025%), and two
same-commit captures at the parent compare clean against each other
(0.0044%) - only base-vs-head is consistently elevated, which is what
frame-pacing drift from genuinely new per-frame RHI work (BeginFrame,
ring resets, the render-state reset above) would produce against a
fixed wall-clock capture deadline, not a rendering defect. Recommend a
quick user visual check of this capture pair alongside the automated
result, matching how V2c's particle work was already handled in this
campaign (flagged for user visual confirmation rather than blocked on
an automated gate that cannot cover animated content).
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
483 lines
18 KiB
C#
483 lines
18 KiB
C#
using AcDream.App.Rendering.Gpu;
|
|
using AcDream.App.UI;
|
|
using Xunit;
|
|
|
|
namespace AcDream.App.Tests.UI;
|
|
|
|
public class DragDropSpineTests
|
|
{
|
|
// A spy handler used across the spine tests.
|
|
private sealed class SpyHandler : IItemListDragHandler
|
|
{
|
|
public ItemDragAcceptance Acceptance = ItemDragAcceptance.Accept;
|
|
public (UiItemList list, UiItemSlot cell, ItemDragPayload payload)? LastOver;
|
|
public (UiItemList list, UiItemSlot cell, ItemDragPayload payload)? LastDrop;
|
|
public (UiItemList list, UiItemSlot cell, ItemDragPayload payload)? LastLift;
|
|
public bool? WaitingAtLift;
|
|
public void OnDragLift(UiItemList list, UiItemSlot cell, ItemDragPayload p)
|
|
{
|
|
WaitingAtLift = cell.WaitingVisual;
|
|
LastLift = (list, cell, p);
|
|
}
|
|
|
|
public ItemDragAcceptance OnDragOver(UiItemList list, UiItemSlot cell, ItemDragPayload p)
|
|
{ LastOver = (list, cell, p); return Acceptance; }
|
|
|
|
public void HandleDropRelease(UiItemList list, UiItemSlot cell, ItemDragPayload p)
|
|
{ LastDrop = (list, cell, p); }
|
|
}
|
|
|
|
[Fact]
|
|
public void Payload_holdsAllFields()
|
|
{
|
|
var src = new UiItemSlot();
|
|
var p = new ItemDragPayload(0x5001u, ItemDragSource.ShortcutBar, 3, src);
|
|
Assert.Equal(0x5001u, p.ObjId);
|
|
Assert.Equal(ItemDragSource.ShortcutBar, p.SourceKind);
|
|
Assert.Equal(3, p.SourceSlot);
|
|
Assert.Same(src, p.SourceCell);
|
|
}
|
|
|
|
[Fact]
|
|
public void UiItemList_registerDragHandler_roundtrips()
|
|
{
|
|
var list = new UiItemList(_ => (GpuTextureSlot.Unassigned, 0, 0));
|
|
Assert.Null(list.DragHandler);
|
|
var h = new SpyHandler();
|
|
list.RegisterDragHandler(h);
|
|
Assert.Same(h, list.DragHandler);
|
|
}
|
|
|
|
// ── UiItemSlot drag-source payload/ghost ────────────────────────────────
|
|
[Fact]
|
|
public void GetDragPayload_emptyCell_isNull()
|
|
=> Assert.Null(new UiItemSlot().GetDragPayload());
|
|
|
|
[Fact]
|
|
public void GetDragPayload_boundCell_snapshotsFields()
|
|
{
|
|
var cell = new UiItemSlot { SlotIndex = 4, SourceKind = ItemDragSource.ShortcutBar };
|
|
cell.SetItem(0x5001u, new GpuTextureSlot(0x99u));
|
|
var p = Assert.IsType<ItemDragPayload>(cell.GetDragPayload());
|
|
Assert.Equal(0x5001u, p.ObjId);
|
|
Assert.Equal(ItemDragSource.ShortcutBar, p.SourceKind);
|
|
Assert.Equal(4, p.SourceSlot);
|
|
Assert.Same(cell, p.SourceCell);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetDragGhost_emptyCell_isNull()
|
|
=> Assert.Null(new UiItemSlot().GetDragGhost());
|
|
|
|
[Fact]
|
|
public void GetDragGhost_boundCell_returnsIconTuple()
|
|
{
|
|
var cell = new UiItemSlot { Width = 32, Height = 32 };
|
|
cell.SetItem(0x5001u, new GpuTextureSlot(0x99u));
|
|
var g = cell.GetDragGhost();
|
|
Assert.NotNull(g);
|
|
Assert.Equal(new GpuTextureSlot(0x99u), g!.Value.tex);
|
|
Assert.Equal(32, g.Value.w);
|
|
Assert.Equal(32, g.Value.h);
|
|
}
|
|
|
|
[Fact]
|
|
public void GetDragGhost_prefersDedicatedUnderlayFreeTexture()
|
|
{
|
|
var cell = new UiItemSlot { Width = 36, Height = 36 }; // retail bag cell is larger than its icon
|
|
cell.SetItem(0x5001u, new GpuTextureSlot(0x99u), dragIconTexture: new GpuTextureSlot(0x77u));
|
|
|
|
Assert.Equal((new GpuTextureSlot(0x77u), 32, 32), cell.GetDragGhost());
|
|
Assert.Equal(new GpuTextureSlot(0x99u), cell.IconTexture); // source cell keeps the full m_pIcon
|
|
}
|
|
|
|
// ── cell drop-target: DragEnter overlay + DropReleased dispatch ──────────
|
|
private static (UiItemList list, UiItemSlot cell, SpyHandler h) ListWithHandler()
|
|
{
|
|
var list = new UiItemList(_ => (new GpuTextureSlot(1u), 1, 1)); // non-zero resolve so overlay draw is harmless
|
|
var h = new SpyHandler();
|
|
list.RegisterDragHandler(h);
|
|
return (list, list.Cell, h);
|
|
}
|
|
|
|
private static ItemDragPayload SomePayload()
|
|
=> new(0x5001u, ItemDragSource.ShortcutBar, 0, new UiItemSlot());
|
|
|
|
[Fact]
|
|
public void DragEnter_setsAcceptOverlay_whenHandlerAccepts()
|
|
{
|
|
var (_, cell, h) = ListWithHandler();
|
|
h.Acceptance = ItemDragAcceptance.Accept;
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DragEnter, Payload: SomePayload()));
|
|
Assert.Equal(DragAcceptState.Accept, cell.DragAcceptVisual);
|
|
}
|
|
|
|
[Fact]
|
|
public void DragEnter_setsRejectOverlay_whenHandlerRejects()
|
|
{
|
|
var (_, cell, h) = ListWithHandler();
|
|
h.Acceptance = ItemDragAcceptance.Reject;
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DragEnter, Payload: SomePayload()));
|
|
Assert.Equal(DragAcceptState.Reject, cell.DragAcceptVisual);
|
|
}
|
|
|
|
[Fact]
|
|
public void DragEnter_keepsNeutralOverlay_whenHandlerIgnoresAlias()
|
|
{
|
|
var (_, cell, h) = ListWithHandler();
|
|
h.Acceptance = ItemDragAcceptance.None;
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DragEnter, Payload: SomePayload()));
|
|
Assert.Equal(DragAcceptState.None, cell.DragAcceptVisual);
|
|
}
|
|
|
|
[Fact]
|
|
public void DragOver_resetsOverlayToNeutral()
|
|
{
|
|
var (_, cell, h) = ListWithHandler();
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DragEnter, Payload: SomePayload()));
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DragOver, Payload: SomePayload()));
|
|
Assert.Equal(DragAcceptState.None, cell.DragAcceptVisual);
|
|
}
|
|
|
|
[Fact]
|
|
public void DropReleased_accepted_dispatchesToHandler()
|
|
{
|
|
var (list, cell, h) = ListWithHandler();
|
|
var p = SomePayload();
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DropReleased, Data0: 1, Payload: p));
|
|
Assert.NotNull(h.LastDrop);
|
|
Assert.Same(list, h.LastDrop!.Value.list);
|
|
Assert.Same(cell, h.LastDrop.Value.cell);
|
|
Assert.Same(p, h.LastDrop.Value.payload);
|
|
}
|
|
|
|
[Fact]
|
|
public void DropReleased_dispatchesToHandler_regardlessOfData0()
|
|
{
|
|
// Retail model: reaching the cell means a real slot was hit (FinishDrag only delivers on a
|
|
// hit), so the handler is authoritative — it dispatches whether or not Data0 is set.
|
|
var (list, cell, h) = ListWithHandler();
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DropReleased, Data0: 0, Payload: SomePayload()));
|
|
Assert.NotNull(h.LastDrop);
|
|
}
|
|
|
|
[Fact]
|
|
public void DragBegin_callsHandlerOnDragLift()
|
|
{
|
|
var (list, cell, h) = ListWithHandler();
|
|
var p = SomePayload();
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DragBegin, Payload: p));
|
|
Assert.NotNull(h.LastLift);
|
|
Assert.Same(list, h.LastLift!.Value.list);
|
|
Assert.Same(cell, h.LastLift.Value.cell);
|
|
Assert.Same(p, h.LastLift.Value.payload);
|
|
}
|
|
|
|
[Fact]
|
|
public void Ghost_isSnapshottedAtBeginDrag_survivesSourceCellClearing()
|
|
{
|
|
var (root, _, cell) = RootWithBoundSlot(0x5001u); // icon tex 0x99
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseMove(20, 10); // BeginDrag → snapshot ghost
|
|
cell.Clear(); // simulate the lift emptying the source
|
|
Assert.Equal((new GpuTextureSlot(0x99u), 32, 32), root.DragGhostForTest);
|
|
}
|
|
|
|
[Fact]
|
|
public void FinishDrag_overNothing_deliversNoDrop_butLiftStands()
|
|
{
|
|
var root = new UiRoot { Width = 800, Height = 600 };
|
|
var list = new UiItemList(_ => (new GpuTextureSlot(1u), 1, 1)) { Left = 0, Top = 0, Width = 32, Height = 32 };
|
|
list.Cell.Width = 32; list.Cell.Height = 32;
|
|
list.Cell.SetItem(0x5001u, new GpuTextureSlot(0x99u));
|
|
var h = new SpyHandler();
|
|
list.RegisterDragHandler(h);
|
|
root.AddChild(list);
|
|
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseMove(20, 10); // BeginDrag → OnDragLift
|
|
Assert.False(h.WaitingAtLift); // retail selects/lifts before enabling the mesh
|
|
Assert.True(list.Cell.WaitingVisual);
|
|
root.OnMouseUp(UiMouseButton.Left, 600, 500); // release over empty space
|
|
Assert.NotNull(h.LastLift); // lift happened
|
|
Assert.Null(h.LastDrop); // no drop dispatched (off-bar)
|
|
Assert.Null(root.DragSource); // cleaned up
|
|
}
|
|
|
|
[Fact]
|
|
public void InventoryDrag_ghostsSourceUntilRelease()
|
|
{
|
|
var (root, _, cell) = RootWithBoundSlot(0x5001u);
|
|
cell.SourceKind = ItemDragSource.Inventory;
|
|
cell.Selected = true;
|
|
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseMove(20, 10);
|
|
Assert.True(cell.WaitingVisual);
|
|
Assert.True(cell.Selected); // selected indicator remains active above the waiting mesh
|
|
|
|
root.OnMouseUp(UiMouseButton.Left, 600, 500);
|
|
Assert.False(cell.WaitingVisual);
|
|
Assert.True(cell.Selected);
|
|
}
|
|
|
|
[Fact]
|
|
public void ShortcutDrag_doesNotGhostSource()
|
|
{
|
|
var (root, _, cell) = RootWithBoundSlot(0x5001u);
|
|
cell.SourceKind = ItemDragSource.ShortcutBar;
|
|
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseMove(20, 10);
|
|
|
|
Assert.False(cell.WaitingVisual);
|
|
}
|
|
|
|
// ── Full UiRoot chain: arming + use-vs-drag ─────────────────────────────
|
|
// A bound, hit-testable slot inside a list, sized for the hit-test.
|
|
private static (UiRoot root, UiItemList list, UiItemSlot cell) RootWithBoundSlot(uint itemId)
|
|
{
|
|
var root = new UiRoot { Width = 800, Height = 600 };
|
|
var list = new UiItemList(_ => (new GpuTextureSlot(1u), 1, 1)) { Left = 0, Top = 0, Width = 32, Height = 32 };
|
|
// Tests don't run OnDraw (which sizes the cell), so size the cell explicitly.
|
|
list.Cell.Width = 32; list.Cell.Height = 32;
|
|
if (itemId != 0) list.Cell.SetItem(itemId, new GpuTextureSlot(0x99u));
|
|
root.AddChild(list);
|
|
return (root, list, list.Cell);
|
|
}
|
|
|
|
private static (UiRoot root, UiItemList list, UiCatalogSlot cell)
|
|
RootWithCatalogSlot(uint entryId)
|
|
{
|
|
var root = new UiRoot { Width = 800, Height = 600 };
|
|
var list = new UiItemList(_ => (new GpuTextureSlot(1u), 1, 1))
|
|
{
|
|
Left = 0,
|
|
Top = 0,
|
|
Width = 32,
|
|
Height = 32,
|
|
};
|
|
list.Flush();
|
|
var cell = new UiCatalogSlot
|
|
{
|
|
EntryId = entryId,
|
|
Width = 32,
|
|
Height = 32,
|
|
SpriteResolve = _ => (new GpuTextureSlot(1u), 1, 1),
|
|
};
|
|
list.AddItem(cell);
|
|
root.AddChild(list);
|
|
return (root, list, cell);
|
|
}
|
|
|
|
[Fact]
|
|
public void BeginDrag_arms_whenPayloadNonNull()
|
|
{
|
|
var (root, _, cell) = RootWithBoundSlot(0x5001u);
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseMove(20, 10); // >3px → promote to drag
|
|
Assert.Same(cell, root.DragSource);
|
|
Assert.IsType<ItemDragPayload>(root.DragPayload);
|
|
}
|
|
|
|
[Fact]
|
|
public void BeginDrag_doesNotArm_whenPayloadNull_emptySlot()
|
|
{
|
|
var (root, _, _) = RootWithBoundSlot(0u); // empty cell → GetDragPayload null
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseMove(20, 10);
|
|
Assert.Null(root.DragSource); // never armed
|
|
}
|
|
|
|
[Fact]
|
|
public void Click_withoutDrag_firesUse()
|
|
{
|
|
var (root, _, cell) = RootWithBoundSlot(0x5001u);
|
|
bool used = false;
|
|
cell.Clicked = () => used = true;
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseUp(UiMouseButton.Left, 10, 10); // no move → Click emitted
|
|
Assert.True(used);
|
|
}
|
|
|
|
[Fact]
|
|
public void PhysicalItemPress_selectsBeforeRelease_thenClickActivates()
|
|
{
|
|
var (root, list, cell) = RootWithBoundSlot(0x5001u);
|
|
var selected = new List<uint>();
|
|
bool used = false;
|
|
list.PrimaryItemPressed = item =>
|
|
{
|
|
selected.Add(item);
|
|
return false;
|
|
};
|
|
cell.Clicked = () => used = true;
|
|
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
|
|
Assert.Equal(new uint[] { 0x5001u }, selected);
|
|
Assert.False(used);
|
|
|
|
root.OnMouseUp(UiMouseButton.Left, 10, 10);
|
|
|
|
Assert.True(used);
|
|
}
|
|
|
|
[Fact]
|
|
public void ConsumedPhysicalItemPress_suppressesCompletedActivation()
|
|
{
|
|
var (root, list, cell) = RootWithBoundSlot(0x5001u);
|
|
bool used = false;
|
|
bool doubleUsed = false;
|
|
list.PrimaryItemPressed = _ => true;
|
|
cell.Clicked = () => used = true;
|
|
cell.DoubleClicked = () => doubleUsed = true;
|
|
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseUp(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseUp(UiMouseButton.Left, 10, 10);
|
|
|
|
Assert.False(used);
|
|
Assert.False(doubleUsed);
|
|
}
|
|
|
|
[Fact]
|
|
public void ConsumedPhysicalItemPress_cannotPromoteIntoDrag()
|
|
{
|
|
var (root, list, _) = RootWithBoundSlot(0x5001u);
|
|
list.PrimaryItemPressed = _ => true;
|
|
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseMove(20, 10);
|
|
|
|
Assert.Null(root.DragSource);
|
|
Assert.Null(root.DragPayload);
|
|
}
|
|
|
|
[Fact]
|
|
public void RightClick_withoutDrag_requestsItemListAppraisal()
|
|
{
|
|
var (root, list, _) = RootWithBoundSlot(0x5001u);
|
|
var examined = new List<uint>();
|
|
list.ExamineItemRequested = examined.Add;
|
|
|
|
root.OnMouseDown(UiMouseButton.Right, 10, 10);
|
|
root.OnMouseUp(UiMouseButton.Right, 10, 10);
|
|
|
|
Assert.Equal(new uint[] { 0x5001u }, examined);
|
|
Assert.Null(root.DragSource);
|
|
}
|
|
|
|
[Fact]
|
|
public void RightButtonMovement_cancelsAppraisal_andNeverStartsItemDrag()
|
|
{
|
|
var (root, list, _) = RootWithBoundSlot(0x5001u);
|
|
var examined = new List<uint>();
|
|
list.ExamineItemRequested = examined.Add;
|
|
|
|
root.OnMouseDown(UiMouseButton.Right, 10, 10);
|
|
root.OnMouseMove(14, 10);
|
|
root.OnMouseUp(UiMouseButton.Right, 14, 10);
|
|
|
|
Assert.Empty(examined);
|
|
Assert.Null(root.DragSource);
|
|
}
|
|
|
|
[Fact]
|
|
public void CatalogEntryPress_selectsBeforeRelease_withoutForgingItemIdentity()
|
|
{
|
|
var (root, list, cell) = RootWithCatalogSlot(42u);
|
|
var selected = new List<uint>();
|
|
list.PrimaryCatalogEntryPressed = selected.Add;
|
|
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
|
|
Assert.Equal(new uint[] { 42u }, selected);
|
|
Assert.Equal(0u, cell.ItemId);
|
|
}
|
|
|
|
[Fact]
|
|
public void CatalogEntryRightClick_requestsLocalCatalogExamination()
|
|
{
|
|
var (root, list, _) = RootWithCatalogSlot(42u);
|
|
var examined = new List<uint>();
|
|
list.ExamineCatalogEntryRequested = examined.Add;
|
|
|
|
root.OnMouseDown(UiMouseButton.Right, 10, 10);
|
|
root.OnMouseUp(UiMouseButton.Right, 10, 10);
|
|
|
|
Assert.Equal(new uint[] { 42u }, examined);
|
|
}
|
|
|
|
[Fact]
|
|
public void CompletedDrag_doesNotFireUse()
|
|
{
|
|
var (root, _, cell) = RootWithBoundSlot(0x5001u);
|
|
bool used = false;
|
|
cell.Clicked = () => used = true;
|
|
root.OnMouseDown(UiMouseButton.Left, 10, 10);
|
|
root.OnMouseMove(20, 10); // promote to drag
|
|
root.OnMouseUp(UiMouseButton.Left, 20, 10); // FinishDrag, NOT Click
|
|
Assert.False(used);
|
|
}
|
|
|
|
// ── no-handler / orphan-cell DragEnter defaults to Reject (review carry-forward) ──
|
|
[Fact]
|
|
public void DragEnter_orphanCell_noList_defaultsToReject()
|
|
{
|
|
var cell = new UiItemSlot(); // no parent list → FindList() null
|
|
cell.OnEvent(new UiEvent(0u, cell, UiEventType.DragEnter, Payload: SomePayload()));
|
|
Assert.Equal(DragAcceptState.Reject, cell.DragAcceptVisual);
|
|
}
|
|
|
|
[Fact]
|
|
public void DragEnter_listWithoutHandler_defaultsToReject()
|
|
{
|
|
var list = new UiItemList(_ => (new GpuTextureSlot(1u), 1, 1)); // no RegisterDragHandler
|
|
list.Cell.OnEvent(new UiEvent(0u, list.Cell, UiEventType.DragEnter, Payload: SomePayload()));
|
|
Assert.Equal(DragAcceptState.Reject, list.Cell.DragAcceptVisual);
|
|
}
|
|
|
|
// ── item drag inside a Draggable window (the LIVE toolbar topology) ──────
|
|
// Regression (visual gate 2026-06-20): the slot sits inside the Draggable toolbar
|
|
// frame, so FindWindow returns the frame. An OCCUPIED slot must start an ITEM drag
|
|
// (IsDragSource), NOT move the window; an EMPTY slot falls through to whole-window
|
|
// drag (IA-12) so the bar stays movable by its empty cells / chrome. The earlier
|
|
// RootWithBoundSlot tests put the slot directly under the root (no draggable
|
|
// ancestor), so they could not catch this.
|
|
private static (UiRoot root, UiPanel frame, UiItemList list) DraggableFrameWithSlot(uint itemId)
|
|
{
|
|
var root = new UiRoot { Width = 800, Height = 600 };
|
|
var frame = new UiPanel { Left = 10, Top = 300, Width = 200, Height = 60, Draggable = true };
|
|
var list = new UiItemList(_ => (new GpuTextureSlot(1u), 1, 1)) { Left = 5, Top = 5, Width = 32, Height = 32 };
|
|
list.Cell.Width = 32; list.Cell.Height = 32;
|
|
if (itemId != 0) list.Cell.SetItem(itemId, new GpuTextureSlot(0x99u));
|
|
frame.AddChild(list);
|
|
root.AddChild(frame);
|
|
return (root, frame, list);
|
|
}
|
|
|
|
[Fact]
|
|
public void OccupiedSlotInsideDraggableWindow_armsItemDrag_doesNotMoveWindow()
|
|
{
|
|
var (root, frame, list) = DraggableFrameWithSlot(0x5001u);
|
|
// Slot screen rect = frame(10,300)+list(5,5) → (15,305)..(47,337). Press inside, drag >3px.
|
|
root.OnMouseDown(UiMouseButton.Left, 20, 310);
|
|
root.OnMouseMove(40, 310);
|
|
Assert.Same(list.Cell, root.DragSource); // item drag armed
|
|
Assert.Equal(10f, frame.Left); // window did NOT move
|
|
Assert.Equal(300f, frame.Top);
|
|
}
|
|
|
|
[Fact]
|
|
public void EmptySlotInsideDraggableWindow_movesWindow_notItemDrag()
|
|
{
|
|
var (root, frame, _) = DraggableFrameWithSlot(0u); // empty slot → not a drag source
|
|
root.OnMouseDown(UiMouseButton.Left, 20, 310);
|
|
root.OnMouseMove(40, 310);
|
|
Assert.Null(root.DragSource); // no item drag
|
|
Assert.Equal(30f, frame.Left); // window moved (offX=20-10=10; new Left=40-10=30)
|
|
Assert.Equal(300f, frame.Top); // y unchanged (310-10=300)
|
|
}
|
|
}
|