// 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.Keyboard.Enums; using CUE.NET.Helper; namespace CUE.NET.Devices.Keyboard.Keys { /// /// Represents a keygroup containing keys which physically lay inside a rectangle. /// public class RectangleKeyGroup : BaseKeyGroup { #region Properties & Fields /// /// Gets or sets the rectangle the keys should be taken from. /// public RectangleF Rectangle { get; set; } /// /// Gets or sets the minimal percentage overlay a key must have with the to be taken into the keygroup. /// public float MinOverlayPercentage { get; set; } #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The keyboard this keygroup belongs to. /// They ID of the first key to calculate the rectangle of this keygroup from. /// They ID of the second key to calculate the rectangle of this keygroup from. /// (optional) The minimal percentage overlay a key must have with the to be taken into the keygroup. (default: 0.5f) /// (optional) Specifies whether this group should be automatically attached or not. (default: true) public RectangleKeyGroup(CorsairKeyboard keyboard, CorsairKeyboardKeyId fromKey, CorsairKeyboardKeyId toKey, float minOverlayPercentage = 0.5f, bool autoAttach = true) : this(keyboard, keyboard[fromKey], keyboard[toKey], minOverlayPercentage, autoAttach) { } /// /// Initializes a new instance of the class. /// /// The keyboard this keygroup belongs to. /// They first key to calculate the rectangle of this keygroup from. /// They second key to calculate the rectangle of this keygroup from. /// (optional) The minimal percentage overlay a key must have with the to be taken into the keygroup. (default: 0.5f) /// (optional) Specifies whether this group should be automatically attached or not. (default: true) public RectangleKeyGroup(CorsairKeyboard keyboard, CorsairKey fromKey, CorsairKey toKey, float minOverlayPercentage = 0.5f, bool autoAttach = true) : this(keyboard, RectangleHelper.CreateRectangleFromRectangles(fromKey.KeyRectangle, toKey.KeyRectangle), minOverlayPercentage, autoAttach) { } /// /// Initializes a new instance of the class. /// /// The keyboard this keygroup belongs to. /// They first point to calculate the rectangle of this keygroup from. /// They second point to calculate the rectangle of this keygroup from. /// (optional) The minimal percentage overlay a key must have with the to be taken into the keygroup. (default: 0.5f) /// (optional) Specifies whether this group should be automatically attached or not. (default: true) public RectangleKeyGroup(CorsairKeyboard keyboard, PointF fromPoint, PointF toPoint, float minOverlayPercentage = 0.5f, bool autoAttach = true) : this(keyboard, RectangleHelper.CreateRectangleFromPoints(fromPoint, toPoint), minOverlayPercentage, autoAttach) { } /// /// Initializes a new instance of the class. /// /// The keyboard this keygroup belongs to. /// The rectangle of this keygroup. /// (optional) The minimal percentage overlay a key must have with the to be taken into the keygroup. (default: 0.5f) /// (optional) Specifies whether this group should be automatically attached or not. (default: true) public RectangleKeyGroup(CorsairKeyboard keyboard, RectangleF rectangle, float minOverlayPercentage = 0.5f, bool autoAttach = true) : base(keyboard, autoAttach) { this.Rectangle = rectangle; this.MinOverlayPercentage = minOverlayPercentage; } #endregion #region Methods /// /// Gets a list containing the keys from this group. /// /// The list containing the keys. protected override IList GetGroupKeys() { return Keyboard.Where(x => RectangleHelper.CalculateIntersectPercentage(x.KeyRectangle, Rectangle) >= MinOverlayPercentage).ToList(); } #endregion } }