diff --git a/RGB.NET.Core/Brushes/BrushCalculationMode.cs b/RGB.NET.Core/Brushes/BrushCalculationMode.cs index 3713d8f..310f563 100644 --- a/RGB.NET.Core/Brushes/BrushCalculationMode.cs +++ b/RGB.NET.Core/Brushes/BrushCalculationMode.cs @@ -1,6 +1,6 @@ -using RGB.NET.Core.Devices; +// ReSharper disable UnusedMember.Global -namespace RGB.NET.Core.Brushes +namespace RGB.NET.Core { /// /// Contains a list of all brush calculation modes. diff --git a/RGB.NET.Core/Brushes/BrushRenderTarget.cs b/RGB.NET.Core/Brushes/BrushRenderTarget.cs index 1ba4a1b..e4934e8 100644 --- a/RGB.NET.Core/Brushes/BrushRenderTarget.cs +++ b/RGB.NET.Core/Brushes/BrushRenderTarget.cs @@ -1,7 +1,7 @@ // ReSharper disable MemberCanBePrivate.Global // ReSharper disable UnusedAutoPropertyAccessor.Global -namespace RGB.NET.Core.Brushes +namespace RGB.NET.Core { /// /// Represents a single target of a brush render. diff --git a/RGB.NET.Core/Brushes/IBrush.cs b/RGB.NET.Core/Brushes/IBrush.cs index 76de2e7..db0b9e6 100644 --- a/RGB.NET.Core/Brushes/IBrush.cs +++ b/RGB.NET.Core/Brushes/IBrush.cs @@ -3,10 +3,8 @@ // ReSharper disable ReturnTypeCanBeEnumerable.Global using System.Collections.Generic; -using RGB.NET.Core.ColorCorrection; -using RGB.NET.Core.Effects; -namespace RGB.NET.Core.Brushes +namespace RGB.NET.Core { /// /// Represents a basic brush. diff --git a/RGB.NET.Core/ColorCorrection/IColorCorrection.cs b/RGB.NET.Core/ColorCorrection/IColorCorrection.cs index b0268d1..034ac9f 100644 --- a/RGB.NET.Core/ColorCorrection/IColorCorrection.cs +++ b/RGB.NET.Core/ColorCorrection/IColorCorrection.cs @@ -1,4 +1,6 @@ -namespace RGB.NET.Core.ColorCorrection +// ReSharper disable UnusedMember.Global + +namespace RGB.NET.Core { /// /// Represents a generic color-correction. diff --git a/RGB.NET.Core/Devices/AbstractRGBDevice.cs b/RGB.NET.Core/Devices/AbstractRGBDevice.cs new file mode 100644 index 0000000..c0a58de --- /dev/null +++ b/RGB.NET.Core/Devices/AbstractRGBDevice.cs @@ -0,0 +1,90 @@ +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace RGB.NET.Core +{ + /// + /// Represents a generic RGB-device + /// + public abstract class AbstractRGBDevice : IRGBDevice + { + #region Properties & Fields + + /// + /// Gets generic information about the . + /// + public IRGBDeviceInfo DeviceInfo { get; } + + /// + /// Gets the representing the whole . + /// + public Rectangle DeviceRectangle { get; } + + /// + /// Gets a dictionary containing all of the . + /// + protected Dictionary LedMapping { get; } = new Dictionary(); + + #region Indexer + + Led IRGBDevice.this[ILedId ledId] + { + get + { + Led led; + return LedMapping.TryGetValue(ledId, out led) ? led : null; + } + } + + Led IRGBDevice.this[Point location] => LedMapping.Values.FirstOrDefault(x => x.LedRectangle.Contains(location)); + + IEnumerable IRGBDevice.this[Rectangle referenceRect, float minOverlayPercentage] + => LedMapping.Values.Where(x => referenceRect.CalculateIntersectPercentage(x.LedRectangle) >= minOverlayPercentage) + ; + + #endregion + + #endregion + + #region Constructors + + #endregion + + #region Methods + + public void Initialize() + { + throw new System.NotImplementedException(); + } + + public void Update(bool flushLeds = false) + { + throw new System.NotImplementedException(); + } + + #region Enumerator + + /// + /// Returns an enumerator that iterates over all of the . + /// + /// An enumerator for all of the . + public IEnumerator GetEnumerator() + { + return LedMapping.Values.GetEnumerator(); + } + + /// + /// Returns an enumerator that iterates over all of the . + /// + /// An enumerator for all of the . + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + #endregion + + #endregion + } +} diff --git a/RGB.NET.Core/Devices/IRGBDevice.cs b/RGB.NET.Core/Devices/IRGBDevice.cs index cb6d363..1538ef7 100644 --- a/RGB.NET.Core/Devices/IRGBDevice.cs +++ b/RGB.NET.Core/Devices/IRGBDevice.cs @@ -1,8 +1,65 @@ -namespace RGB.NET.Core.Devices +using System.Collections.Generic; + +namespace RGB.NET.Core { /// /// Represents a generic RGB-device /// - public interface IRGBDevice - { } + public interface IRGBDevice : IEnumerable + { + #region Properties + + /// + /// Gets generic information about the . + /// + IRGBDeviceInfo DeviceInfo { get; } + + /// + /// Gets the representing the whole . + /// + Rectangle DeviceRectangle { get; } + + #endregion + + #region Indexer + + /// + /// Gets the with the specified . + /// + /// The of the to get. + /// The with the specified or null if no is found. + Led this[ILedId ledId] { get; } + + /// + /// Gets the at the given physical location. + /// + /// The to get the location from. + /// The at the given or null if no location is found. + Led this[Point location] { get; } + + /// + /// Gets a list of inside the given . + /// + /// The to check. + /// The minimal percentage overlay a must have with the to be taken into the list. + /// + IEnumerable this[Rectangle referenceRect, float minOverlayPercentage = 0.5f] { get; } + + #endregion + + #region Methods + + /// + /// Initializes the . + /// + void Initialize(); + + /// + /// Perform an update for all dirty , or all if flushLeds is set to true. + /// + /// Specifies whether all (including clean ones) should be updated. + void Update(bool flushLeds = false); + + #endregion + } } diff --git a/RGB.NET.Core/Devices/IRGBDeviceInfo.cs b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs new file mode 100644 index 0000000..4860dd8 --- /dev/null +++ b/RGB.NET.Core/Devices/IRGBDeviceInfo.cs @@ -0,0 +1,10 @@ +namespace RGB.NET.Core +{ + /// + /// Represents a generic information for a + /// + public interface IRGBDeviceInfo + { + + } +} diff --git a/RGB.NET.Core/Effects/IEffect.cs b/RGB.NET.Core/Effects/IEffect.cs index 8919425..17129fa 100644 --- a/RGB.NET.Core/Effects/IEffect.cs +++ b/RGB.NET.Core/Effects/IEffect.cs @@ -2,9 +2,7 @@ // ReSharper disable UnusedMemberInSuper.Global // ReSharper disable UnusedParameter.Global -using RGB.NET.Core.Devices; - -namespace RGB.NET.Core.Effects +namespace RGB.NET.Core { /// /// Represents a basic effect. diff --git a/RGB.NET.Core/Effects/IEffectTarget.cs b/RGB.NET.Core/Effects/IEffectTarget.cs index 3866ee7..fa62948 100644 --- a/RGB.NET.Core/Effects/IEffectTarget.cs +++ b/RGB.NET.Core/Effects/IEffectTarget.cs @@ -1,6 +1,6 @@ // ReSharper disable UnusedMember.Global -namespace RGB.NET.Core.Effects +namespace RGB.NET.Core { /// /// Represents a basic effect-target. diff --git a/RGB.NET.Core/Events/ExceptionEventArgs.cs b/RGB.NET.Core/Events/ExceptionEventArgs.cs new file mode 100644 index 0000000..0f16e81 --- /dev/null +++ b/RGB.NET.Core/Events/ExceptionEventArgs.cs @@ -0,0 +1,35 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global + +using System; + +namespace RGB.NET.Core +{ + /// + /// Represents the information supplied with an -event. + /// + public class ExceptionEventArgs : EventArgs + { + #region Properties & Fields + + /// + /// Gets the which is responsible for the event-call. + /// + public Exception Exception { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The which is responsible for the event-call. + public ExceptionEventArgs(Exception exception) + { + this.Exception = exception; + } + + #endregion + } +} diff --git a/RGB.NET.Core/Events/LedsUpdatedEventArgs.cs b/RGB.NET.Core/Events/LedsUpdatedEventArgs.cs new file mode 100644 index 0000000..53a8a26 --- /dev/null +++ b/RGB.NET.Core/Events/LedsUpdatedEventArgs.cs @@ -0,0 +1,36 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global + +using System; +using System.Collections.Generic; + +namespace RGB.NET.Core +{ + /// + /// Represents the information supplied with an -event. + /// + public class LedsUpdatedEventArgs : EventArgs + { + #region Properties & Fields + + /// + /// Gets a list of which got updated. + /// + public IEnumerable UpdatedLeds { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The updated . + public LedsUpdatedEventArgs(IEnumerable updatedLeds) + { + this.UpdatedLeds = updatedLeds; + } + + #endregion + } +} diff --git a/RGB.NET.Core/Events/LedsUpdatingEventArgs.cs b/RGB.NET.Core/Events/LedsUpdatingEventArgs.cs new file mode 100644 index 0000000..4ddbe93 --- /dev/null +++ b/RGB.NET.Core/Events/LedsUpdatingEventArgs.cs @@ -0,0 +1,36 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global + +using System; +using System.Collections.Generic; + +namespace RGB.NET.Core +{ + /// + /// Represents the information supplied with an -event. + /// + public class LedsUpdatingEventArgs : EventArgs + { + #region Properties & Fields + + /// + /// Gets a list of which are about to get updated. + /// + public ICollection UpdatingLeds { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The updating . + public LedsUpdatingEventArgs(ICollection updatingLeds) + { + this.UpdatingLeds = updatingLeds; + } + + #endregion + } +} diff --git a/RGB.NET.Core/Events/UpdatedEventArgs.cs b/RGB.NET.Core/Events/UpdatedEventArgs.cs new file mode 100644 index 0000000..e9dd193 --- /dev/null +++ b/RGB.NET.Core/Events/UpdatedEventArgs.cs @@ -0,0 +1,10 @@ +using System; + +namespace RGB.NET.Core +{ + /// + /// Represents the information supplied with an -event. + /// + public class UpdatedEventArgs : EventArgs + { } +} diff --git a/RGB.NET.Core/Events/UpdatingEventArgs.cs b/RGB.NET.Core/Events/UpdatingEventArgs.cs new file mode 100644 index 0000000..f0fb5e5 --- /dev/null +++ b/RGB.NET.Core/Events/UpdatingEventArgs.cs @@ -0,0 +1,35 @@ +// ReSharper disable MemberCanBePrivate.Global +// ReSharper disable UnusedAutoPropertyAccessor.Global + +using System; + +namespace RGB.NET.Core +{ + /// + /// Represents the information supplied with an -event. + /// + public class UpdatingEventArgs : EventArgs + { + #region Properties & Fields + + /// + /// Gets the elapsed time (in seconds) since the last update. + /// + public double DeltaTime { get; } + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + /// The elapsed time (in seconds) since the last update. + public UpdatingEventArgs(double deltaTime) + { + this.DeltaTime = deltaTime; + } + + #endregion + } +} diff --git a/RGB.NET.Core/Extensions/DoubleExtensions.cs b/RGB.NET.Core/Extensions/DoubleExtensions.cs index 87e8876..964a205 100644 --- a/RGB.NET.Core/Extensions/DoubleExtensions.cs +++ b/RGB.NET.Core/Extensions/DoubleExtensions.cs @@ -1,7 +1,7 @@ using System; using System.Runtime.CompilerServices; -namespace RGB.NET.Core.Extensions +namespace RGB.NET.Core { /// /// Offers some extensions and helper-methods for the work with doubles diff --git a/RGB.NET.Core/Color.cs b/RGB.NET.Core/Leds/Color.cs similarity index 99% rename from RGB.NET.Core/Color.cs rename to RGB.NET.Core/Leds/Color.cs index e782750..9f2d46c 100644 --- a/RGB.NET.Core/Color.cs +++ b/RGB.NET.Core/Leds/Color.cs @@ -3,8 +3,6 @@ using System; using System.Diagnostics; -using RGB.NET.Core.Extensions; -using RGB.NET.Core.MVVM; namespace RGB.NET.Core { diff --git a/RGB.NET.Core/ILedId.cs b/RGB.NET.Core/Leds/ILedId.cs similarity index 100% rename from RGB.NET.Core/ILedId.cs rename to RGB.NET.Core/Leds/ILedId.cs diff --git a/RGB.NET.Core/Led.cs b/RGB.NET.Core/Leds/Led.cs similarity index 98% rename from RGB.NET.Core/Led.cs rename to RGB.NET.Core/Leds/Led.cs index 2840054..e13c937 100644 --- a/RGB.NET.Core/Led.cs +++ b/RGB.NET.Core/Leds/Led.cs @@ -1,6 +1,5 @@ using System.Diagnostics; -using RGB.NET.Core.Devices; -using RGB.NET.Core.MVVM; +// ReSharper disable MemberCanBePrivate.Global namespace RGB.NET.Core { diff --git a/RGB.NET.Core/MVVM/AbstractBindable.cs b/RGB.NET.Core/MVVM/AbstractBindable.cs index 29291dd..52a3cf6 100644 --- a/RGB.NET.Core/MVVM/AbstractBindable.cs +++ b/RGB.NET.Core/MVVM/AbstractBindable.cs @@ -1,7 +1,7 @@ using System.ComponentModel; using System.Runtime.CompilerServices; -namespace RGB.NET.Core.MVVM +namespace RGB.NET.Core { /// /// Represents a basic bindable class which notifies when a property value changes. @@ -43,11 +43,11 @@ namespace RGB.NET.Core.MVVM /// true if the value was changed, false if the existing value matched the desired value. protected virtual bool SetProperty(ref T storage, T value, [CallerMemberName] string propertyName = null) { - if (!RequiresUpdate(ref storage, value)) return false; + if (!this.RequiresUpdate(ref storage, value)) return false; storage = value; // ReSharper disable once ExplicitCallerInfoArgument - OnPropertyChanged(propertyName); + this.OnPropertyChanged(propertyName); return true; } @@ -58,7 +58,7 @@ namespace RGB.NET.Core.MVVM /// and can be provided automatically when invoked from compilers that support . protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null) { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); } #endregion diff --git a/RGB.NET.Core/Positioning/Point.cs b/RGB.NET.Core/Positioning/Point.cs index a099f52..b137060 100644 --- a/RGB.NET.Core/Positioning/Point.cs +++ b/RGB.NET.Core/Positioning/Point.cs @@ -2,8 +2,6 @@ // ReSharper disable UnusedMember.Global using System.Diagnostics; -using RGB.NET.Core.Extensions; -using RGB.NET.Core.MVVM; namespace RGB.NET.Core { @@ -76,17 +74,17 @@ namespace RGB.NET.Core /// true if is a equivalent to this ; otherwise, false. public override bool Equals(object obj) { - Point compareColor = obj as Point; - if (ReferenceEquals(compareColor, null)) + Point comparePoint = obj as Point; + if (ReferenceEquals(comparePoint, null)) return false; - if (ReferenceEquals(this, compareColor)) + if (ReferenceEquals(this, comparePoint)) return true; - if (GetType() != compareColor.GetType()) + if (GetType() != comparePoint.GetType()) return false; - return X.EqualsInTolerance(compareColor.X) && Y.EqualsInTolerance(compareColor.Y); + return X.EqualsInTolerance(comparePoint.X) && Y.EqualsInTolerance(comparePoint.Y); } /// diff --git a/RGB.NET.Core/Positioning/Rectangle.cs b/RGB.NET.Core/Positioning/Rectangle.cs index 92bb85f..e76f5b3 100644 --- a/RGB.NET.Core/Positioning/Rectangle.cs +++ b/RGB.NET.Core/Positioning/Rectangle.cs @@ -5,8 +5,6 @@ using System; using System.Collections.Generic; using System.Diagnostics; using System.Linq; -using RGB.NET.Core.Extensions; -using RGB.NET.Core.MVVM; namespace RGB.NET.Core { @@ -203,6 +201,107 @@ namespace RGB.NET.Core return new Rectangle(); } + /// + /// Determines if the specified is contained within this . + /// + /// The to test. + /// + public bool Contains(Point point) + { + return Contains(point.X, point.Y); + } + + /// + /// Determines if the specified location is contained within this . + /// + /// The X-location to test. + /// The Y-location to test. + /// + public bool Contains(double x, double y) + { + return (Location.X <= x) && (x < (Location.X + Size.Width)) && (Location.Y <= y) && (y < (Location.Y + Size.Height)); + } + + /// + /// Determines if the specified is contained within this . + /// + /// The to test. + /// + public bool Contains(Rectangle rect) + { + return (Location.X <= rect.Location.X) && ((rect.Location.X + rect.Size.Width) <= (Location.X + Size.Width)) + && (Location.Y <= rect.Location.Y) && ((rect.Location.Y + rect.Size.Height) <= (Location.Y + Size.Height)); + } + + /// + /// Converts the - and -position of this to a human-readable string. + /// + /// A string that contains the and of this . For example "[Location: [X: 100, Y: 10], Size: [Width: 20, Height: [40]]". + public override string ToString() + { + return $"[Location: {Location}, Size: {Size}]"; + } + + /// + /// Tests whether the specified object is a and is equivalent to this . + /// + /// The object to test. + /// true if is a equivalent to this ; otherwise, false. + public override bool Equals(object obj) + { + Rectangle compareRect = obj as Rectangle; + if (ReferenceEquals(compareRect, null)) + return false; + + if (ReferenceEquals(this, compareRect)) + return true; + + if (GetType() != compareRect.GetType()) + return false; + + return (Location == compareRect.Location) && (Size == compareRect.Size); + } + + /// + /// Returns a hash code for this . + /// + /// An integer value that specifies the hash code for this . + public override int GetHashCode() + { + unchecked + { + int hashCode = Location.GetHashCode(); + hashCode = (hashCode * 397) ^ Size.GetHashCode(); + return hashCode; + } + } + + #endregion + + #region Operators + + /// + /// Returns a value that indicates whether two specified are equal. + /// + /// The first to compare. + /// The second to compare. + /// true if and are equal; otherwise, false. + public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2) + { + return ReferenceEquals(rectangle1, null) ? ReferenceEquals(rectangle2, null) : rectangle1.Equals(rectangle2); + } + + /// + /// Returns a value that indicates whether two specified are equal. + /// + /// The first to compare. + /// The second to compare. + /// true if and are not equal; otherwise, false. + public static bool operator !=(Rectangle rectangle1, Rectangle rectangle2) + { + return !(rectangle1 == rectangle2); + } + #endregion } } diff --git a/RGB.NET.Core/Positioning/Size.cs b/RGB.NET.Core/Positioning/Size.cs index f3aa936..39abcb4 100644 --- a/RGB.NET.Core/Positioning/Size.cs +++ b/RGB.NET.Core/Positioning/Size.cs @@ -2,8 +2,6 @@ // ReSharper disable UnusedMember.Global using System.Diagnostics; -using RGB.NET.Core.Extensions; -using RGB.NET.Core.MVVM; namespace RGB.NET.Core { @@ -84,17 +82,17 @@ namespace RGB.NET.Core /// true if is a equivalent to this ; otherwise, false. public override bool Equals(object obj) { - Size compareColor = obj as Size; - if (ReferenceEquals(compareColor, null)) + Size compareSize = obj as Size; + if (ReferenceEquals(compareSize, null)) return false; - if (ReferenceEquals(this, compareColor)) + if (ReferenceEquals(this, compareSize)) return true; - if (GetType() != compareColor.GetType()) + if (GetType() != compareSize.GetType()) return false; - return Width.EqualsInTolerance(compareColor.Width) && Height.EqualsInTolerance(compareColor.Height); + return Width.EqualsInTolerance(compareSize.Width) && Height.EqualsInTolerance(compareSize.Height); } /// diff --git a/RGB.NET.Core/RGB.NET.Core.csproj b/RGB.NET.Core/RGB.NET.Core.csproj index d0c7cac..64fb4f6 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj +++ b/RGB.NET.Core/RGB.NET.Core.csproj @@ -46,18 +46,27 @@ + + - + + + + + + + - + - + + diff --git a/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings b/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings index 6965dd0..7ec5688 100644 --- a/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings +++ b/RGB.NET.Core/RGB.NET.Core.csproj.DotSettings @@ -1,2 +1,11 @@  - True \ No newline at end of file + True + True + True + True + True + True + True + True + True + True \ No newline at end of file diff --git a/RGB.NET.Core/Surfaces/IRGBSurface.cs b/RGB.NET.Core/Surfaces/IRGBSurface.cs new file mode 100644 index 0000000..042f796 --- /dev/null +++ b/RGB.NET.Core/Surfaces/IRGBSurface.cs @@ -0,0 +1,81 @@ +namespace RGB.NET.Core +{ + + #region EventHandler + + /// + /// Represents the event-handler of the -event. + /// + /// The sender of the event. + /// The arguments provided by the event. + public delegate void ExceptionEventHandler(object sender, ExceptionEventArgs args); + + /// + /// Represents the event-handler of the -event. + /// + /// The sender of the event. + /// The arguments provided by the event. + public delegate void UpdatingEventHandler(object sender, UpdatingEventArgs args); + + /// + /// Represents the event-handler of the -event. + /// + /// The sender of the event. + /// The arguments provided by the event. + public delegate void UpdatedEventHandler(object sender, UpdatedEventArgs args); + + /// + /// Represents the event-handler of the -event. + /// + /// The sender of the event. + /// The arguments provided by the event. + public delegate void LedsUpdatingEventHandler(object sender, LedsUpdatingEventArgs args); + + /// + /// Represents the event-handler of the -event. + /// + /// The sender of the event. + /// The arguments provided by the event. + public delegate void LedsUpdatedEventHandler(object sender, LedsUpdatedEventArgs args); + + #endregion + + /// + /// Represents a generic RGB-surface. + /// + public interface IRGBSurface + { + #region Events + + // ReSharper disable EventNeverSubscribedTo.Global + + /// + /// Occurs when a catched exception is thrown inside the . + /// + event ExceptionEventHandler Exception; + + /// + /// Occurs when the starts updating. + /// + event UpdatingEventHandler Updating; + + /// + /// Occurs when the update is done. + /// + event UpdatedEventHandler Updated; + + /// + /// Occurs when the starts to update the leds. + /// + event LedsUpdatingEventHandler LedsUpdating; + + /// + /// Occurs when the updated the leds. + /// + event LedsUpdatedEventHandler LedsUpdated; + + // ReSharper restore EventNeverSubscribedTo.Global + + #endregion + } +} diff --git a/RGB.NET.Core/Surfaces/RGBSurface.cs b/RGB.NET.Core/Surfaces/RGBSurface.cs new file mode 100644 index 0000000..2d46d62 --- /dev/null +++ b/RGB.NET.Core/Surfaces/RGBSurface.cs @@ -0,0 +1,144 @@ +using System; +using System.Collections.Generic; + +namespace RGB.NET.Core +{ + /// + /// Represents a generic RGB-surface. + /// + public class RGBSurface + { + #region Properties & Fields + + private DateTime _lastUpdate; + + #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 starts to update the . + /// + public event LedsUpdatingEventHandler LedsUpdating; + + /// + /// Occurs when the updated the . + /// + public event LedsUpdatedEventHandler LedsUpdated; + + // ReSharper restore EventNeverSubscribedTo.Global + + #endregion + + #region Constructors + + /// + /// Initializes a new instance of the class. + /// + public RGBSurface() + { + _lastUpdate = DateTime.Now; + } + + #endregion + + #region EventCaller + + /// + /// Handles the needed event-calls for an exception. + /// + /// The exception previously thrown. + protected virtual void OnException(Exception ex) + { + try + { + Exception?.Invoke(this, new ExceptionEventArgs(ex)); + } + catch + { + // Well ... that's not my fault + } + } + + /// + /// Handles the needed event-calls before updating. + /// + protected virtual void OnUpdating() + { + try + { + long lastUpdateTicks = _lastUpdate.Ticks; + _lastUpdate = DateTime.Now; + Updating?.Invoke(this, new UpdatingEventArgs((DateTime.Now.Ticks - lastUpdateTicks) / 10000000.0)); + } + catch + { + // Well ... that's not my fault + } + } + + /// + /// Handles the needed event-calls after an update. + /// + protected virtual void OnUpdated() + { + try + { + Updated?.Invoke(this, new UpdatedEventArgs()); + } + catch + { + // Well ... that's not my fault + } + } + + /// + /// Handles the needed event-calls before the are updated. + /// + protected virtual void OnLedsUpdating(ICollection updatingLeds) + { + try + { + LedsUpdating?.Invoke(this, new LedsUpdatingEventArgs(updatingLeds)); + } + catch + { + // Well ... that's not my fault + } + } + + /// + /// Handles the needed event-calls after the are updated. + /// + protected virtual void OnLedsUpdated(IEnumerable updatedLeds) + { + try + { + LedsUpdated?.Invoke(this, new LedsUpdatedEventArgs(updatedLeds)); + } + catch + { + // Well ... that's not my fault + } + } + + #endregion + } +} diff --git a/RGB.NET.sln.DotSettings b/RGB.NET.sln.DotSettings index 14b87f1..dad38e0 100644 --- a/RGB.NET.sln.DotSettings +++ b/RGB.NET.sln.DotSettings @@ -189,6 +189,7 @@ NotRequired Join Arithmetic, Shift, Relational, Equality, Bitwise, Conditional, Lowest + All True True True @@ -324,4 +325,10 @@ <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /> <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> - <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> \ No newline at end of file + <Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /> + True + True + True + True + True + True \ No newline at end of file