Zoom: compose the box as a real 2x layer above the background (Unit: zoom layer + magnification proof)

Right-click now creates a transient ZoomSceneElement at z-index 1 whose pixels are a
genuine 2x magnified sample of the backdrop (live capture under art), composited into
stream/recording like any layer while the output crop stays the tier. All shapes are
centered on the click and clamped to frame; healed on load/scene-create, never persisted,
hidden from the layers list + element template (IsZoomLayer). BuildCompositorOptions is
now internal = always tier crop (test seam). ZoomFrameBuilder is a pure static sampler
(box/2 window centered on the box center, single-slot cache) proven by a banded-backdrop
test; LayerReorderPersistenceTests drag resolves rows by item since the collapsed zoom
row shifts container indices. Also books TASK 51 (webcam background Remove + Blur) and
syncs memory docs (HANDOFF, MyMistakes, indexes). Full suite: 405 passed, 0 warnings.
This commit is contained in:
2026-10-07 23:39:54 -07:00
parent 966e718f1e
commit 4b3d82ff0f
17 changed files with 734 additions and 210 deletions
+52 -16
View File
@@ -1,4 +1,5 @@
using System;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
@@ -11,12 +12,13 @@ using ytLive.ViewModels;
namespace ytLive.Tests;
/// <summary>
/// Verifies the zoom box created by a right-click in the live preview: each
/// ZoomView Shape procures the right bounding box (circle is square and
/// centered on the click, phone is a tall 9:16 rect, tablet a wide 16:9 rect
/// both anchored top-left at the click), the box stays fully inside the
/// 1920x1080 preview, and the UI renders the matching outline with the zoomed
/// region clipped to the shape.
/// Verifies the zoom box created by a right-click in the live preview: every
/// ZoomView shape procures the right bounding box CENTERED on the click (circle
/// square, phone 9:16, tablet 16:9), the box stays fully inside the 1920x1080
/// preview, and — because the box is now a real composited layer (TASK 51) —
/// a ZoomSceneElement placeholder sits at z-index 1 whose rect mirrors the box,
/// its Kind flips Dynamic only while active, and the output crop stays the tier
/// (the box is never the crop source).
/// </summary>
[Collection("RealApp")]
public sealed class ZoomBoxInteractionTests
@@ -29,7 +31,7 @@ public sealed class ZoomBoxInteractionTests
}
[Fact]
public void Zoom_Shape_Controls_Box_Aspect_Anchor_And_Render()
public void Zoom_Shape_Controls_Box_Aspect_Anchor_Layer_And_Render()
{
_app.Run(Run);
}
@@ -44,8 +46,12 @@ public sealed class ZoomBoxInteractionTests
{
window.Show();
window.UpdateLayout();
Assert.NotNull(vm.StagedScene);
// The healed zoom placeholder sits at z-index 1, inert.
var placeholder = (ZoomSceneElement)vm.StagedScene.Elements[1];
Assert.False(placeholder.IsZoomActive);
Assert.Equal(ElementKind.Static, placeholder.Kind);
// Same internal test seam as IsRecording allows ActivateZoom (IsEditMode goes false).
vm.IsRecording = true;
var pane = (UserControl)window.FindName("PreviewPane")!;
var zoomBox = (Grid)pane.FindName("ZoomBox")!;
@@ -59,6 +65,7 @@ public sealed class ZoomBoxInteractionTests
Assert.Equal(vm.ZoomState.Width, vm.ZoomState.Height, 3);
Assert.Equal(1000 - vm.ZoomState.Width / 2, vm.ZoomState.X, 3);
Assert.Equal(500 - vm.ZoomState.Height / 2, vm.ZoomState.Y, 3);
AssertTrueActiveLayer(vm);
window.UpdateLayout();
Assert.Equal(Visibility.Visible, zoomBox.Visibility);
@@ -66,26 +73,28 @@ public sealed class ZoomBoxInteractionTests
Assert.Equal(Visibility.Visible, circleOutline.Visibility);
Assert.Equal(Visibility.Collapsed, rectOutline.Visibility);
// Phone (vertical rectangle): tall 9:16 box, click point is the TOP-LEFT corner.
// Phone (vertical rectangle): tall 9:16 box, click point is the CENTER.
vm.ZoomShape = ZoomShape.VerticalRectangle;
vm.ActivateZoom(200, 100);
vm.ActivateZoom(960, 540);
Assert.True(vm.ZoomState.Height > vm.ZoomState.Width);
Assert.Equal(9.0 / 16.0, vm.ZoomState.Width / vm.ZoomState.Height, 3);
Assert.Equal(200, vm.ZoomState.X, 3);
Assert.Equal(100, vm.ZoomState.Y, 3);
Assert.Equal(960 - vm.ZoomState.Width / 2, vm.ZoomState.X, 3);
Assert.Equal(540 - vm.ZoomState.Height / 2, vm.ZoomState.Y, 3);
AssertTrueActiveLayer(vm);
window.UpdateLayout();
Assert.Null(zoomBox.Clip);
Assert.Equal(Visibility.Collapsed, circleOutline.Visibility);
Assert.Equal(Visibility.Visible, rectOutline.Visibility);
// Tablet (horizontal rectangle): wide 16:9 box, anchored top-left.
// Tablet (horizontal rectangle): wide 16:9 box, click point is the CENTER.
vm.ZoomShape = ZoomShape.HorizontalRectangle;
vm.ActivateZoom(200, 100);
vm.ActivateZoom(960, 540);
Assert.True(vm.ZoomState.Width > vm.ZoomState.Height);
Assert.Equal(16.0 / 9.0, vm.ZoomState.Width / vm.ZoomState.Height, 3);
Assert.Equal(200, vm.ZoomState.X, 3);
Assert.Equal(100, vm.ZoomState.Y, 3);
Assert.Equal(960 - vm.ZoomState.Width / 2, vm.ZoomState.X, 3);
Assert.Equal(540 - vm.ZoomState.Height / 2, vm.ZoomState.Y, 3);
AssertTrueActiveLayer(vm);
// Clamp keeps the box fully inside the 1920x1080 preview even for a
// corner click that would otherwise overhang it.
@@ -94,6 +103,20 @@ public sealed class ZoomBoxInteractionTests
Assert.True(vm.ZoomState.X >= 0 && vm.ZoomState.Y >= 0);
Assert.True(vm.ZoomState.X + vm.ZoomState.Width <= frameW);
Assert.True(vm.ZoomState.Y + vm.ZoomState.Height <= frameH);
AssertTrueActiveLayer(vm);
// The box is a composited layer, NEVER the crop: output stays the tier.
var opts = vm.BuildCompositorOptions();
Assert.True(opts.SourceRectWidth > vm.ZoomState.Width);
Assert.Equal((int)Math.Round(vm.OutputRectWidth), opts.SourceRectWidth);
Assert.Equal((int)Math.Round(vm.OutputRectHeight), opts.SourceRectHeight);
// Dismiss restores the inert placeholder (Kind back to Static).
vm.DismissZoom();
Assert.False(vm.IsZoomActive);
Assert.False(placeholder.IsZoomActive);
Assert.False(placeholder.IsVisible);
Assert.Equal(ElementKind.Static, placeholder.Kind);
}
finally
{
@@ -103,4 +126,17 @@ public sealed class ZoomBoxInteractionTests
try { System.IO.File.Delete(tempDb); } catch { }
}
}
private static void AssertTrueActiveLayer(MainViewModel vm)
{
var zoom = Assert.IsType<ZoomSceneElement>(vm.StagedScene!.Elements[1]);
Assert.True(zoom.IsZoomActive);
Assert.True(zoom.IsVisible);
Assert.Equal(ElementKind.Dynamic, zoom.Kind);
Assert.Equal(vm.ZoomState.X, zoom.X, 3);
Assert.Equal(vm.ZoomState.Y, zoom.Y, 3);
Assert.Equal(vm.ZoomState.Width, zoom.Width, 3);
Assert.Equal(vm.ZoomState.Height, zoom.Height, 3);
Assert.Equal(vm.ZoomShape == ZoomShape.Circle ? ClipShape.Round : ClipShape.Traditional, zoom.ClipShape);
}
}