using System.Collections.Generic; using System.ComponentModel; using System.Linq; namespace RGB.NET.Core { public partial class RGBSurface { #region Methods // ReSharper disable once UnusedMember.Global /// /// Loads all devices the given is able to provide. /// /// The to load the devices from. /// Specifies which types of devices to load. /// Specifies whether the application should request exclusive access of possible or not. /// Specifies whether exception during the initialization sequence should be thrown or not. public void LoadDevices(IRGBDeviceProvider deviceProvider, RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false) { if (_deviceProvider.Contains(deviceProvider) || _deviceProvider.Any(x => x.GetType() == deviceProvider.GetType())) return; List addedDevices = new List(); if (deviceProvider.IsInitialized || deviceProvider.Initialize(loadFilter, exclusiveAccessIfPossible, throwExceptions)) { _deviceProvider.Add(deviceProvider); foreach (IRGBDevice device in deviceProvider.Devices) { if (_devices.Contains(device)) continue; addedDevices.Add(device); device.PropertyChanged += DeviceOnPropertyChanged; _devices.Add(device); } } if (addedDevices.Any()) { UpdateSurfaceRectangle(); SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(addedDevices, true, false)); } } /// /// Automatically aligns all devices to prevent overlaps. /// public void AlignDevies() { double posX = 0; foreach (IRGBDevice device in Devices) { device.Location += new Point(posX, 0); posX += device.Size.Width + 1; } } private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) { UpdateSurfaceRectangle(); SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(new[] { sender as IRGBDevice }, false, true)); } #endregion } }