Multi-scene webcam (schema v3/v4): singleton Webcam + per-scene WebcamSceneConfig, right-click OBS-style border/context menu, persisted round-to-rect restore + legacy-square 16:9 heal, dark MenuItem template, tests (25 passing)

This commit is contained in:
2026-08-07 08:24:18 -07:00
parent f31ce9fdb7
commit e037ba027b
23 changed files with 1405 additions and 287 deletions
+9 -89
View File
@@ -1,7 +1,4 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ytLive.Helpers;
namespace ytLive.Models;
@@ -10,7 +7,6 @@ public enum SourceType
{
DisplayCapture,
WindowCapture,
Webcam,
Background,
Image,
TextOverlay
@@ -22,26 +18,14 @@ public enum ClipShape
Round
}
public class Source : INotifyPropertyChanged
/// <summary>
/// A multi-instance scene object: image/background/text (screen/window later).
/// The webcam is NOT a Source — it's a singleton resource whose per-scene usage
/// is a <see cref="WebcamSceneConfig"/>. See the singleton-vs-multi-instance
/// discriminator in ai.md.
/// </summary>
public class Source : SceneElement
{
public event PropertyChangedEventHandler? PropertyChanged;
private void Raise([CallerMemberName] string? name = null)
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
private bool Set<T>(ref T field, T value, [CallerMemberName] string? name = null)
{
if (EqualityComparer<T>.Default.Equals(field, value)) return false;
field = value;
Raise(name);
return true;
}
public string Id { get; init; } = Guid.NewGuid().ToString();
private string _name = string.Empty;
public string Name { get => _name; set => Set(ref _name, value); }
private SourceType _type;
public SourceType Type { get => _type; set => Set(ref _type, value); }
@@ -55,58 +39,6 @@ public class Source : INotifyPropertyChanged
private IntPtr? _windowHandle;
public IntPtr? WindowHandle { get => _windowHandle; set => Set(ref _windowHandle, value); }
// Webcam
private string? _deviceId;
public string? DeviceId { get => _deviceId; set => Set(ref _deviceId, value); }
// Webcam live preview: the shared WriteableBitmap owned by CameraManager.
private WriteableBitmap? _videoImageSource;
public WriteableBitmap? VideoImageSource
{
get => _videoImageSource;
set
{
if (Set(ref _videoImageSource, value))
Raise(nameof(DisplaySource));
}
}
private ClipShape _clipShape = ClipShape.Traditional;
public ClipShape ClipShape
{
get => _clipShape;
set
{
if (Set(ref _clipShape, value))
Raise(nameof(ShapeButtonText));
}
}
private bool _isMirrored;
public bool IsMirrored
{
get => _isMirrored;
set
{
if (Set(ref _isMirrored, value))
{
Raise(nameof(MirrorScale));
Raise(nameof(MirrorButtonText));
}
}
}
public double MirrorScale => IsMirrored ? -1 : 1;
/// <summary>Mirror toggle label (mirrored → "Unmirror").</summary>
public string MirrorButtonText => IsMirrored ? "Unmirror" : "Mirror";
/// <summary>Clip-shape toggle label (round → "Rect").</summary>
public string ShapeButtonText => ClipShape == ClipShape.Round ? "Rect" : "Round";
/// <summary>What the preview shows: static image for image/background, live frames for webcam.</summary>
public ImageSource? DisplaySource => Type == SourceType.Webcam ? _videoImageSource : _imageSource;
// Image (asset stored in the layout database)
private string? _assetId;
private ImageSource? _imageSource;
@@ -127,19 +59,7 @@ public class Source : INotifyPropertyChanged
public ImageSource? ImageSource => _imageSource;
// Position/transform (per-scene usage)
private double _x;
public double X { get => _x; set => Set(ref _x, value); }
public override ImageSource? DisplaySource => _imageSource;
private double _y;
public double Y { get => _y; set => Set(ref _y, value); }
private double _width;
public double Width { get => _width; set => Set(ref _width, value); }
private double _height;
public double Height { get => _height; set => Set(ref _height, value); }
private double _opacity = 1.0;
public double Opacity { get => _opacity; set => Set(ref _opacity, value); }
public override bool IsImageSource => Type == SourceType.Image;
}