// ReSharper disable UnusedMember.Global using System.Collections.Generic; using System.Linq; namespace RGB.NET.Core { public static class SurfaceExtensions { #region Methods public static void Load(this RGBSurface surface, IRGBDeviceProvider deviceProvider, RGBDeviceType loadFilter = RGBDeviceType.All, bool throwExceptions = false) { if (!deviceProvider.IsInitialized) deviceProvider.Initialize(loadFilter, throwExceptions); surface.Attach(deviceProvider.Devices); } public static void Attach(this RGBSurface surface, IEnumerable devices) { foreach (IRGBDevice device in devices) surface.Attach(device); } public static void Detach(this RGBSurface surface, IEnumerable devices) { foreach (IRGBDevice device in devices) surface.Detach(device); } /// /// Gets all devices of a specific type. /// /// The type of devices to get. /// A collection of devices with the specified type. public static IEnumerable GetDevices(this RGBSurface surface) where T : class => surface.Devices.Where(x => x is T).Cast(); /// /// Gets all devices of the specified . /// /// The of the devices to get. /// A collection of devices matching the specified . public static IEnumerable GetDevices(this RGBSurface surface, RGBDeviceType deviceType) => surface.Devices.Where(d => deviceType.HasFlag(d.DeviceInfo.DeviceType)); /// /// Automatically aligns all devices to prevent overlaps. /// public static void AlignDevices(this RGBSurface surface) { float posX = 0; foreach (IRGBDevice device in surface.Devices) { device.Location += new Point(posX, 0); posX += device.ActualSize.Width + 1; } } #endregion } }