using System.Collections.Generic; using System.Linq; using RGB.NET.Core; namespace RGB.NET.Devices.SteelSeries { /// /// /// /// Represents a SteelSeries-device. (keyboard, mouse, headset, mousepad). /// public class SteelSeriesRGBDevice : AbstractRGBDevice, ISteelSeriesRGBDevice, IUnknownDevice//TODO DarthAffe 18.04.2020: It's know which kind of device this is, but they would need to be separated { #region Properties & Fields private Dictionary _ledMapping; /// /// /// Gets information about the . /// public override SteelSeriesRGBDeviceInfo DeviceInfo { get; } /// /// Gets or sets the update queue performing updates for this device. /// // ReSharper disable once MemberCanBePrivate.Global protected UpdateQueue UpdateQueue { get; set; } #endregion #region Constructors /// /// Initializes a new instance of the class. /// /// The generic information provided by SteelSeries for the device. internal SteelSeriesRGBDevice(SteelSeriesRGBDeviceInfo info) { this.DeviceInfo = info; } #endregion #region Methods /// /// Initializes the device. /// void ISteelSeriesRGBDevice.Initialize(UpdateQueue updateQueue, Dictionary ledMapping) { _ledMapping = ledMapping; int counter = 0; foreach (KeyValuePair mapping in ledMapping) AddLed(mapping.Key, new Point((counter++) * 10, 0), new Size(10, 10)); if (Size == Size.Invalid) { Rectangle ledRectangle = new(this.Select(x => x.LedRectangle)); Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y); } UpdateQueue = updateQueue; } /// protected override object GetLedCustomData(LedId ledId) => _ledMapping[ledId]; /// protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); /// public override void Dispose() { try { UpdateQueue?.Dispose(); } catch { /* at least we tried */ } base.Dispose(); } #endregion } }