Files
ytLlive/Models/Source.cs
T

146 lines
4.1 KiB
C#

using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using ytLive.Helpers;
namespace ytLive.Models;
public enum SourceType
{
DisplayCapture,
WindowCapture,
Webcam,
Background,
Image,
TextOverlay
}
public enum ClipShape
{
Traditional,
Round
}
public class Source : INotifyPropertyChanged
{
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); }
private bool _isEnabled = true;
public bool IsEnabled { get => _isEnabled; set => Set(ref _isEnabled, value); }
// Display/Window capture
private int? _monitorIndex;
public int? MonitorIndex { get => _monitorIndex; set => Set(ref _monitorIndex, value); }
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;
public string? AssetId
{
get => _assetId;
set
{
if (Set(ref _assetId, value))
{
_imageSource = ImageCache.Get(value ?? string.Empty);
Raise(nameof(ImageSource));
Raise(nameof(DisplaySource));
}
}
}
public ImageSource? ImageSource => _imageSource;
// Position/transform (per-scene usage)
private double _x;
public double X { get => _x; set => Set(ref _x, value); }
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); }
}