diff --git a/RGB.NET.Core/RGBSurface.cs b/RGB.NET.Core/RGBSurface.cs
index 31edaf8..e5ce505 100644
--- a/RGB.NET.Core/RGBSurface.cs
+++ b/RGB.NET.Core/RGBSurface.cs
@@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
+using System.ComponentModel;
using System.Diagnostics;
using System.Linq;
@@ -14,15 +15,10 @@ namespace RGB.NET.Core
///
/// Represents a RGB-surface containing multiple devices.
///
- public partial class RGBSurface : AbstractBindable, IDisposable
+ public class RGBSurface : AbstractBindable, IDisposable
{
#region Properties & Fields
-
- ///
- /// Gets the singelot-instance of the class.
- ///
- public static RGBSurface Instance { get; } = new RGBSurface();
-
+
private Stopwatch _deltaTimeCounter;
private IList _deviceProvider = new List();
@@ -69,6 +65,62 @@ namespace RGB.NET.Core
}
}
+ #endregion
+
+ #region EventHandler
+
+ ///
+ /// Represents the event-handler of the -event.
+ ///
+ /// The arguments provided by the event.
+ public delegate void ExceptionEventHandler(ExceptionEventArgs args);
+
+ ///
+ /// Represents the event-handler of the -event.
+ ///
+ /// The arguments provided by the event.
+ public delegate void UpdatingEventHandler(UpdatingEventArgs args);
+
+ ///
+ /// Represents the event-handler of the -event.
+ ///
+ /// The arguments provided by the event.
+ public delegate void UpdatedEventHandler(UpdatedEventArgs args);
+
+ ///
+ /// Represents the event-handler of the -event.
+ ///
+ ///
+ public delegate void SurfaceLayoutChangedEventHandler(SurfaceLayoutChangedEventArgs args);
+
+ #endregion
+
+ #region Events
+
+ // ReSharper disable EventNeverSubscribedTo.Global
+
+ ///
+ /// Occurs when a catched exception is thrown inside the .
+ ///
+ public event ExceptionEventHandler Exception;
+
+ ///
+ /// Occurs when the starts updating.
+ ///
+ public event UpdatingEventHandler Updating;
+
+ ///
+ /// Occurs when the update is done.
+ ///
+ public event UpdatedEventHandler Updated;
+
+ ///
+ /// Occurs when the layout of this changed.
+ ///
+ public event SurfaceLayoutChangedEventHandler SurfaceLayoutChanged;
+
+ // ReSharper restore EventNeverSubscribedTo.Global
+
#endregion
#region Constructors
@@ -76,7 +128,7 @@ namespace RGB.NET.Core
///
/// Initializes a new instance of the class.
///
- private RGBSurface()
+ public RGBSurface()
{
_deltaTimeCounter = Stopwatch.StartNew();
}
@@ -108,7 +160,7 @@ namespace RGB.NET.Core
lock (_devices)
{
OnUpdating(updateTrigger, customData);
-
+
if (render)
lock (_ledGroups)
{
@@ -228,6 +280,75 @@ namespace RGB.NET.Core
return true;
}
}
+ // ReSharper disable UnusedMember.Global
+ ///
+ /// Loads all devices the given by the provided by the give .
+ ///
+ /// The which provides 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(IRGBDeviceProviderLoader deviceProviderLoader, RGBDeviceType loadFilter = RGBDeviceType.All,
+ bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
+ => LoadDevices(deviceProviderLoader.GetDeviceProvider(), loadFilter, exclusiveAccessIfPossible, throwExceptions);
+
+ ///
+ /// 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)
+ {
+ lock (_deviceProvider)
+ {
+ 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);
+ lock (_devices)
+ 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 AlignDevices()
+ {
+ double posX = 0;
+ foreach (IRGBDevice device in Devices)
+ {
+ device.Location += new Point(posX, 0);
+ posX += device.ActualSize.Width + 1;
+ }
+ }
+
+ // ReSharper restore UnusedMember.Global
+
+ private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
+ {
+ UpdateSurfaceRectangle();
+ SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(new[] { sender as IRGBDevice }, false, true));
+ }
private void UpdateSurfaceRectangle()
{
@@ -284,6 +405,45 @@ namespace RGB.NET.Core
updateTrigger.Update -= Update;
}
+ ///
+ /// Handles the needed event-calls for an exception.
+ ///
+ /// The exception previously thrown.
+ private void OnException(Exception ex)
+ {
+ try
+ {
+ Exception?.Invoke(new ExceptionEventArgs(ex));
+ }
+ catch { /* Well ... that's not my fault */ }
+ }
+
+ ///
+ /// Handles the needed event-calls before updating.
+ ///
+ private void OnUpdating(IUpdateTrigger trigger, CustomUpdateData customData)
+ {
+ try
+ {
+ double deltaTime = _deltaTimeCounter.Elapsed.TotalSeconds;
+ _deltaTimeCounter.Restart();
+ Updating?.Invoke(new UpdatingEventArgs(deltaTime, trigger, customData));
+ }
+ catch { /* Well ... that's not my fault */ }
+ }
+
+ ///
+ /// Handles the needed event-calls after an update.
+ ///
+ private void OnUpdated()
+ {
+ try
+ {
+ Updated?.Invoke(new UpdatedEventArgs());
+ }
+ catch { /* Well ... that's not my fault */ }
+ }
+
#endregion
}
}
diff --git a/RGB.NET.Core/RGBSurfaceDeviceEvents.cs b/RGB.NET.Core/RGBSurfaceDeviceEvents.cs
deleted file mode 100644
index 8af4f06..0000000
--- a/RGB.NET.Core/RGBSurfaceDeviceEvents.cs
+++ /dev/null
@@ -1,106 +0,0 @@
-using System;
-
-namespace RGB.NET.Core
-{
- public partial class RGBSurface
- {
- #region EventHandler
-
- ///
- /// Represents the event-handler of the -event.
- ///
- /// The arguments provided by the event.
- public delegate void ExceptionEventHandler(ExceptionEventArgs args);
-
- ///
- /// Represents the event-handler of the -event.
- ///
- /// The arguments provided by the event.
- public delegate void UpdatingEventHandler(UpdatingEventArgs args);
-
- ///
- /// Represents the event-handler of the -event.
- ///
- /// The arguments provided by the event.
- public delegate void UpdatedEventHandler(UpdatedEventArgs args);
-
- ///
- /// Represents the event-handler of the -event.
- ///
- ///
- public delegate void SurfaceLayoutChangedEventHandler(SurfaceLayoutChangedEventArgs args);
-
- #endregion
-
- #region Events
-
- // ReSharper disable EventNeverSubscribedTo.Global
-
- ///
- /// Occurs when a catched exception is thrown inside the .
- ///
- public event ExceptionEventHandler Exception;
-
- ///
- /// Occurs when the starts updating.
- ///
- public event UpdatingEventHandler Updating;
-
- ///
- /// Occurs when the update is done.
- ///
- public event UpdatedEventHandler Updated;
-
- ///
- /// Occurs when the layout of this changed.
- ///
- public event SurfaceLayoutChangedEventHandler SurfaceLayoutChanged;
-
- // ReSharper restore EventNeverSubscribedTo.Global
-
- #endregion
-
- #region Methods
-
- ///
- /// Handles the needed event-calls for an exception.
- ///
- /// The exception previously thrown.
- private void OnException(Exception ex)
- {
- try
- {
- Exception?.Invoke(new ExceptionEventArgs(ex));
- }
- catch { /* Well ... that's not my fault */ }
- }
-
- ///
- /// Handles the needed event-calls before updating.
- ///
- private void OnUpdating(IUpdateTrigger trigger, CustomUpdateData customData)
- {
- try
- {
- double deltaTime = _deltaTimeCounter.Elapsed.TotalSeconds;
- _deltaTimeCounter.Restart();
- Updating?.Invoke(new UpdatingEventArgs(deltaTime, trigger, customData));
- }
- catch { /* Well ... that's not my fault */ }
- }
-
- ///
- /// Handles the needed event-calls after an update.
- ///
- private void OnUpdated()
- {
- try
- {
- Updated?.Invoke(new UpdatedEventArgs());
- }
- catch { /* Well ... that's not my fault */ }
- }
-
- #endregion
- }
-}
diff --git a/RGB.NET.Core/RGBSurfaceDeviceLoader.cs b/RGB.NET.Core/RGBSurfaceDeviceLoader.cs
deleted file mode 100644
index df760c3..0000000
--- a/RGB.NET.Core/RGBSurfaceDeviceLoader.cs
+++ /dev/null
@@ -1,83 +0,0 @@
-using System.Collections.Generic;
-using System.ComponentModel;
-using System.Linq;
-
-namespace RGB.NET.Core
-{
- public partial class RGBSurface
- {
- #region Methods
-
- // ReSharper disable UnusedMember.Global
- ///
- /// Loads all devices the given by the provided by the give .
- ///
- /// The which provides 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(IRGBDeviceProviderLoader deviceProviderLoader, RGBDeviceType loadFilter = RGBDeviceType.All,
- bool exclusiveAccessIfPossible = false, bool throwExceptions = false)
- => LoadDevices(deviceProviderLoader.GetDeviceProvider(), loadFilter, exclusiveAccessIfPossible, throwExceptions);
-
- ///
- /// 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)
- {
- lock (_deviceProvider)
- {
- 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);
- lock (_devices)
- 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 AlignDevices()
- {
- double posX = 0;
- foreach (IRGBDevice device in Devices)
- {
- device.Location += new Point(posX, 0);
- posX += device.ActualSize.Width + 1;
- }
- }
-
- // ReSharper restore UnusedMember.Global
-
- private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
- {
- UpdateSurfaceRectangle();
- SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(new[] { sender as IRGBDevice }, false, true));
- }
-
- #endregion
- }
-}