// ReSharper disable MemberCanBePrivate.Global using System.Diagnostics; namespace RGB.NET.Core; /// /// /// Represents a single LED of a RGB-device. /// [DebuggerDisplay("{Id} {Color}")] public sealed class Led : Placeable { #region Properties & Fields /// /// Gets the this is associated with. /// public IRGBDevice Device { get; } /// /// Gets the of the . /// public LedId Id { get; } private Shape _shape = Shape.Rectangle; /// /// Gets or sets the of the . /// public Shape Shape { get => _shape; set => SetProperty(ref _shape, value); } private string? _shapeData; /// /// Gets or sets the data used for by the -. /// public string? ShapeData { get => _shapeData; set => SetProperty(ref _shapeData, value); } private Rectangle _absoluteBoundary; /// /// Gets a rectangle representing the logical location of the on the . /// public Rectangle AbsoluteBoundary { get => _absoluteBoundary; private set => SetProperty(ref _absoluteBoundary, value); } /// /// Indicates whether the is about to change it's color. /// public bool IsDirty => RequestedColor.HasValue && (RequestedColor != Color); private Color? _requestedColor; /// /// Gets a copy of the the LED should be set to on the next update. /// Null if there is no update-request for the next update. /// public Color? RequestedColor { get => _requestedColor; private set { SetProperty(ref _requestedColor, value); // ReSharper disable once ExplicitCallerInfoArgument OnPropertyChanged(nameof(IsDirty)); } } private Color _color = Color.Transparent; /// /// Gets the current of the . Sets the for the next update. /// public Color Color { get => _color; set { if (RequestedColor.HasValue) RequestedColor = RequestedColor.Value + value; else RequestedColor = _color + value; } } /// /// Gets the provider-specific data associated with this led. /// public object? CustomData { get; } /// /// Gets or sets some custom metadata of this led. /// public object? LayoutMetadata { get; set; } #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The the is associated with. /// The of the . /// The physical location of the relative to the . /// The size of the . /// The provider-specific data associated with this led. internal Led(IRGBDevice device, LedId id, Point location, Size size, object? customData = null) : base(device) { this.Device = device; this.Id = id; this.Location = location; this.Size = size; this.CustomData = customData; } #endregion #region Methods /// protected override void UpdateActualPlaceableData() { base.UpdateActualPlaceableData(); AbsoluteBoundary = Boundary.Translate(Device.Location); } /// /// Converts the and the of this to a human-readable string. /// /// A string that contains the and the of this . For example "Enter [A: 255, R: 255, G: 0, B: 0]". public override string ToString() => $"{Id} {Color}"; /// /// Updates the to the requested . /// internal void Update() { if (!RequestedColor.HasValue) return; _color = RequestedColor.Value; RequestedColor = null; // ReSharper disable once ExplicitCallerInfoArgument OnPropertyChanged(nameof(Color)); } #endregion #region Operators /// /// Converts a to a . /// /// The to convert. public static implicit operator Color(Led led) => led.Color; /// /// Converts a to a . /// /// The to convert. public static implicit operator Rectangle(Led led) => led.Boundary; #endregion }