// ReSharper disable MemberCanBePrivate.Global using System.Diagnostics; namespace RGB.NET.Core { /// /// Represents a single LED of a RGB-device. /// [DebuggerDisplay("{Id} {Color}")] public class Led : AbstractBindable { #region Properties & Fields /// /// Gets the this is associated with. /// public IRGBDevice Device { get; } /// /// Gets the of the . /// public ILedId Id { get; } private Shape _shape = Shape.Rectangle; /// /// Gets or sets the of the . /// public Shape Shape { get { return _shape; } set { SetProperty(ref _shape, value); } } /// /// Gets a rectangle representing the physical location of the relative to the . /// public Rectangle LedRectangle { get; } /// /// Indicates whether the is about to change it's color. /// public bool IsDirty => RequestedColor != _color; private Color _requestedColor = Color.Transparent; /// /// Gets a copy of the the LED should be set to on the next update. /// public Color RequestedColor { get { return new Color(_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 { return _color; } set { if (!IsLocked) { // DarthAffe 26.01.2017: DON'T USE THE PROPERTY HERE! Working on the copy doesn't work! _requestedColor.Blend(value); // ReSharper disable ExplicitCallerInfoArgument OnPropertyChanged(nameof(RequestedColor)); OnPropertyChanged(nameof(IsDirty)); // ReSharper restore ExplicitCallerInfoArgument } } } private bool _isLocked; /// /// Gets or sets if the color of this LED can be changed. /// public bool IsLocked { get { return _isLocked; } set { SetProperty(ref _isLocked, value); } } #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The the is associated with. /// The of the . /// The representing the physical location of the relative to the . internal Led(IRGBDevice device, ILedId id, Rectangle ledRectangle) { this.Device = device; this.Id = id; this.LedRectangle = ledRectangle; } #endregion #region Methods /// /// 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() { return $"{Id} {Color}"; } /// /// Updates the to the requested . /// internal void Update() { _color = RequestedColor; // ReSharper disable once ExplicitCallerInfoArgument OnPropertyChanged(nameof(Color)); } /// /// Resets the back to default. /// internal void Reset() { _color = Color.Transparent; RequestedColor = Color.Transparent; IsLocked = false; // ReSharper disable once ExplicitCallerInfoArgument OnPropertyChanged(nameof(Color)); } #endregion #region Operators /// /// Converts a to a . /// /// The to convert. public static implicit operator Color(Led led) { return led?.Color; } /// /// Converts a to a . /// /// The to convert. public static implicit operator Rectangle(Led led) { return led?.LedRectangle; } #endregion } }