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 { #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) InitializeLed(mapping.Key, new Rectangle((counter++) * 10, 0, 10, 10)); InitializeLayout(); if (Size == Size.Invalid) { Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle)); Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y); } UpdateQueue = updateQueue; } protected override object CreateLedCustomData(LedId ledId) => _ledMapping[ledId]; /// protected override void UpdateLeds(IEnumerable ledsToUpdate) => UpdateQueue.SetData(ledsToUpdate.Where(x => x.Color.A > 0)); /// /// Initializes the and of the device. /// protected virtual void InitializeLayout() { if (!(DeviceInfo is SteelSeriesRGBDeviceInfo info)) return; string layout = info.ImageLayout; string layoutPath = info.LayoutPath; ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\SteelSeries", $"{layoutPath}.xml"), layout, true); } #endregion } }