// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable UnusedMember.Global
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using CUE.NET.Devices;
using CUE.NET.Devices.Generic;
using CUE.NET.Devices.Generic.Enums;
using CUE.NET.Helper;
namespace CUE.NET.Groups
{
///
/// Represents a ledgroup containing LEDs which physically lay inside a rectangle.
///
public class RectangleLedGroup : AbstractLedGroup
{
#region Properties & Fields
private IList _ledCache;
private RectangleF _rectangle;
///
/// Gets or sets the rectangle the LEDs should be taken from.
///
public RectangleF Rectangle
{
get { return _rectangle; }
set
{
_rectangle = value;
_ledCache = null;
}
}
private float _minOverlayPercentage;
///
/// Gets or sets the minimal percentage overlay a LED must have with the to be taken into the ledgroup.
///
public float MinOverlayPercentage
{
get { return _minOverlayPercentage; }
set
{
_minOverlayPercentage = value;
_ledCache = null;
}
}
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The device this ledgroup belongs to.
/// They ID of the first LED to calculate the rectangle of this ledgroup from.
/// They ID of the second LED to calculate the rectangle of this ledgroup from.
/// (optional) The minimal percentage overlay a LED must have with the to be taken into the ledgroup. (default: 0.5f)
/// (optional) Specifies whether this group should be automatically attached or not. (default: true)
public RectangleLedGroup(ICueDevice device, CorsairLedId fromLed, CorsairLedId toLed, float minOverlayPercentage = 0.5f, bool autoAttach = true)
: this(device, device[fromLed], device[toLed], minOverlayPercentage, autoAttach)
{ }
///
/// Initializes a new instance of the class.
///
/// The device this ledgroup belongs to.
/// They first LED to calculate the rectangle of this ledgroup from.
/// They second LED to calculate the rectangle of this ledgroup from.
/// (optional) The minimal percentage overlay a LED must have with the to be taken into the ledgroup. (default: 0.5f)
/// (optional) Specifies whether this group should be automatically attached or not. (default: true)
public RectangleLedGroup(ICueDevice device, CorsairLed fromLed, CorsairLed toLed, float minOverlayPercentage = 0.5f, bool autoAttach = true)
: this(device, RectangleHelper.CreateRectangleFromRectangles(fromLed.LedRectangle, toLed.LedRectangle), minOverlayPercentage, autoAttach)
{ }
///
/// Initializes a new instance of the class.
///
/// The device this ledgroup belongs to.
/// They first point to calculate the rectangle of this ledgroup from.
/// They second point to calculate the rectangle of this ledgroup from.
/// (optional) The minimal percentage overlay a LED must have with the to be taken into the ledgroup. (default: 0.5f)
/// (optional) Specifies whether this group should be automatically attached or not. (default: true)
public RectangleLedGroup(ICueDevice device, PointF fromPoint, PointF toPoint, float minOverlayPercentage = 0.5f, bool autoAttach = true)
: this(device, RectangleHelper.CreateRectangleFromPoints(fromPoint, toPoint), minOverlayPercentage, autoAttach)
{ }
///
/// Initializes a new instance of the class.
///
/// The device this ledgroup belongs to.
/// The rectangle of this ledgroup.
/// (optional) The minimal percentage overlay a LED must have with the to be taken into the ledgroup. (default: 0.5f)
/// (optional) Specifies whether this group should be automatically attached or not. (default: true)
public RectangleLedGroup(ICueDevice device, RectangleF rectangle, float minOverlayPercentage = 0.5f, bool autoAttach = true)
: base(device, autoAttach)
{
this.Rectangle = rectangle;
this.MinOverlayPercentage = minOverlayPercentage;
}
#endregion
#region Methods
///
/// Gets a list containing all LEDs of this group.
///
/// The list containing all LEDs of this group.
public override IEnumerable GetLeds()
{
return _ledCache ?? (_ledCache = Device.Where(x => RectangleHelper.CalculateIntersectPercentage(x.LedRectangle, Rectangle) >= MinOverlayPercentage).ToList());
}
#endregion
}
}