// ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedAutoPropertyAccessor.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global using System.Diagnostics; using System.Drawing; using CUE.NET.Devices.Generic.Enums; using CUE.NET.Helper; namespace CUE.NET.Devices.Generic { /// /// Represents a single LED of a CUE-device. /// [DebuggerDisplay("{Id} {Color}")] public class CorsairLed { #region Properties & Fields /// /// Gets the key-ID of the Led. /// public CorsairLedId Id { get; set; } /// /// Gets a rectangle representing the physical location of the led. /// public RectangleF LedRectangle { get; } /// /// Indicates whether the LED has changed an internal state. /// public bool IsDirty => RequestedColor != _color; /// /// Gets the Color the LED should be set to on the next update. /// public CorsairColor RequestedColor { get; private set; } = CorsairColor.Transparent; private CorsairColor _color = CorsairColor.Transparent; /// /// Gets the current color of the LED. Sets the for the next update. />. /// public CorsairColor Color { get { return _color; } set { if (!IsLocked) RequestedColor = RequestedColor.Blend(value); } } /// /// Gets or sets if the color of this LED can be changed. /// public bool IsLocked { get; set; } #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The ID of the LED /// The rectangle representing the physical location of the LED. internal CorsairLed(CorsairLedId id, RectangleF ledRectangle) { this.Id = id; this.LedRectangle = ledRectangle; } #endregion #region Methods /// /// Converts the Id and the of this to a human-readable string. /// /// A string that contains the Id and the of this . For example "Enter [A: 255, R: 255, G: 0, B: 0]". public override string ToString() { return $"{Id} {Color}"; } /// /// Updates the LED to the requested color. /// internal void Update() { _color = RequestedColor; } /// /// Resets the LED back to default /// internal void Reset() { _color = CorsairColor.Transparent; RequestedColor = CorsairColor.Transparent; IsLocked = false; } #endregion #region Operators /// /// Converts a to a . /// /// The to convert. public static implicit operator CorsairLedId(CorsairLed led) { return led?.Id ?? CorsairLedId.Invalid; } /// /// Converts a to a . /// /// The to convert. public static implicit operator CorsairColor(CorsairLed led) { return led?.Color; } #endregion } }