using System;
using System.Collections.Generic;
using System.Linq;
using RGB.NET.Core;
using RGB.NET.Devices.CoolerMaster.Native;
namespace RGB.NET.Devices.CoolerMaster
{
///
///
///
/// Represents a generic CoolerMaster-device. (keyboard, mouse, headset, mousepad).
///
public abstract class CoolerMasterRGBDevice : AbstractRGBDevice, ICoolerMasterRGBDevice
where TDeviceInfo : CoolerMasterRGBDeviceInfo
{
#region Properties & Fields
///
///
/// Gets information about the .
///
public override TDeviceInfo DeviceInfo { get; }
///
/// Gets or sets the update queue performing updates for this device.
///
// ReSharper disable once MemberCanBePrivate.Global
protected CoolerMasterUpdateQueue UpdateQueue { get; set; }
#endregion
#region Constructors
///
/// Initializes a new instance of the class.
///
/// The generic information provided by CoolerMaster for the device.
protected CoolerMasterRGBDevice(TDeviceInfo info)
{
this.DeviceInfo = info;
}
#endregion
#region Methods
///
/// Initializes the device.
///
public void Initialize(IDeviceUpdateTrigger updateTrigger)
{
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 = new CoolerMasterUpdateQueue(updateTrigger, DeviceInfo.DeviceIndex);
}
///
/// Initializes the and of the device.
///
protected abstract void InitializeLayout();
///
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 */ }
_CoolerMasterSDK.EnableLedControl(false, DeviceInfo.DeviceIndex);
base.Dispose();
}
#endregion
}
}