// ReSharper disable MemberCanBePrivate.Global
using System;
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 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);
}
///
/// Gets a rectangle representing the physical location of the relative to the .
///
public Rectangle LedRectangle { get; }
///
/// Gets a rectangle representing the physical location of the on the .
///
public Rectangle AbsoluteLedRectangle => (LedRectangle.Location + Device.Location) + new Size(LedRectangle.Size.Width, LedRectangle.Size.Height);
///
/// 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 => _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 (!IsLocked)
RequestedColor += value;
}
}
private bool _isLocked;
///
/// Gets or sets if the color of this LED can be changed.
///
public bool IsLocked
{
get => _isLocked;
set => SetProperty(ref _isLocked, value);
}
///
/// Gets the URI of an image of the or null if there is no image.
///
public Uri Image { get; set; }
///
/// Gets the provider-specific data associated with this led.
///
public object CustomData { get; }
#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 .
/// The provider-specific data associated with this led.
internal Led(IRGBDevice device, LedId id, Rectangle ledRectangle, object customData = null)
{
this.Device = device;
this.Id = id;
this.LedRectangle = ledRectangle;
this.CustomData = customData;
}
#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() => $"{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) => led?.Color ?? Color.Transparent;
///
/// Converts a to a .
///
/// The to convert.
public static implicit operator Rectangle(Led led) => led?.LedRectangle;
#endregion
}
}