1
0
mirror of https://github.com/DarthAffe/RGB.NET.git synced 2025-12-12 17:48:31 +00:00

Added even more basic stuff

This commit is contained in:
Darth Affe 2017-01-22 09:47:19 +01:00
parent 4e001d1087
commit 254bbc206e
27 changed files with 693 additions and 44 deletions

View File

@ -1,6 +1,6 @@
using RGB.NET.Core.Devices;
// ReSharper disable UnusedMember.Global
namespace RGB.NET.Core.Brushes
namespace RGB.NET.Core
{
/// <summary>
/// Contains a list of all brush calculation modes.

View File

@ -1,7 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
namespace RGB.NET.Core.Brushes
namespace RGB.NET.Core
{
/// <summary>
/// Represents a single target of a brush render.

View File

@ -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
{
/// <summary>
/// Represents a basic brush.

View File

@ -1,4 +1,6 @@
namespace RGB.NET.Core.ColorCorrection
// ReSharper disable UnusedMember.Global
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic color-correction.

View File

@ -0,0 +1,90 @@
using System.Collections;
using System.Collections.Generic;
using System.Linq;
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic RGB-device
/// </summary>
public abstract class AbstractRGBDevice : IRGBDevice
{
#region Properties & Fields
/// <summary>
/// Gets generic information about the <see cref="IRGBDevice"/>.
/// </summary>
public IRGBDeviceInfo DeviceInfo { get; }
/// <summary>
/// Gets the <see cref="Rectangle"/> representing the whole <see cref="IRGBDevice"/>.
/// </summary>
public Rectangle DeviceRectangle { get; }
/// <summary>
/// Gets a dictionary containing all <see cref="Led"/> of the <see cref="IRGBDevice"/>.
/// </summary>
protected Dictionary<ILedId, Led> LedMapping { get; } = new Dictionary<ILedId, Led>();
#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<Led> 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
/// <summary>
/// Returns an enumerator that iterates over all <see cref="Led"/> of the <see cref="IRGBDevice"/>.
/// </summary>
/// <returns>An enumerator for all <see cref="Led"/> of the <see cref="IRGBDevice"/>.</returns>
public IEnumerator<Led> GetEnumerator()
{
return LedMapping.Values.GetEnumerator();
}
/// <summary>
/// Returns an enumerator that iterates over all <see cref="Led"/> of the <see cref="IRGBDevice"/>.
/// </summary>
/// <returns>An enumerator for all <see cref="Led"/> of the <see cref="IRGBDevice"/>.</returns>
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
#endregion
#endregion
}
}

View File

@ -1,8 +1,65 @@
namespace RGB.NET.Core.Devices
using System.Collections.Generic;
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic RGB-device
/// </summary>
public interface IRGBDevice
{ }
public interface IRGBDevice : IEnumerable<Led>
{
#region Properties
/// <summary>
/// Gets generic information about the <see cref="IRGBDevice"/>.
/// </summary>
IRGBDeviceInfo DeviceInfo { get; }
/// <summary>
/// Gets the <see cref="Rectangle"/> representing the whole <see cref="IRGBDevice"/>.
/// </summary>
Rectangle DeviceRectangle { get; }
#endregion
#region Indexer
/// <summary>
/// Gets the <see cref="Led"/> with the specified <see cref="ILedId"/>.
/// </summary>
/// <param name="ledId">The <see cref="ILedId"/> of the <see cref="Led"/> to get.</param>
/// <returns>The <see cref="Led"/> with the specified <see cref="ILedId"/> or null if no <see cref="Led"/> is found.</returns>
Led this[ILedId ledId] { get; }
/// <summary>
/// Gets the <see cref="Led" /> at the given physical location.
/// </summary>
/// <param name="location">The <see cref="Point"/> to get the location from.</param>
/// <returns>The <see cref="Led"/> at the given <see cref="Point"/> or null if no location is found.</returns>
Led this[Point location] { get; }
/// <summary>
/// Gets a list of <see cref="Led" /> inside the given <see cref="Rectangle"/>.
/// </summary>
/// <param name="referenceRect">The <see cref="Rectangle"/> to check.</param>
/// <param name="minOverlayPercentage">The minimal percentage overlay a <see cref="Led"/> must have with the <see cref="Rectangle" /> to be taken into the list.</param>
/// <returns></returns>
IEnumerable<Led> this[Rectangle referenceRect, float minOverlayPercentage = 0.5f] { get; }
#endregion
#region Methods
/// <summary>
/// Initializes the <see cref="IRGBDevice"/>.
/// </summary>
void Initialize();
/// <summary>
/// Perform an update for all dirty <see cref="Led"/>, or all <see cref="Led"/> if flushLeds is set to true.
/// </summary>
/// <param name="flushLeds">Specifies whether all <see cref="Led"/> (including clean ones) should be updated.</param>
void Update(bool flushLeds = false);
#endregion
}
}

View File

@ -0,0 +1,10 @@
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic information for a <see cref="IRGBDevice"/>
/// </summary>
public interface IRGBDeviceInfo
{
}
}

View File

@ -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
{
/// <summary>
/// Represents a basic effect.

View File

@ -1,6 +1,6 @@
// ReSharper disable UnusedMember.Global
namespace RGB.NET.Core.Effects
namespace RGB.NET.Core
{
/// <summary>
/// Represents a basic effect-target.

View File

@ -0,0 +1,35 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
namespace RGB.NET.Core
{
/// <summary>
/// Represents the information supplied with an <see cref="IRGBSurface.Exception"/>-event.
/// </summary>
public class ExceptionEventArgs : EventArgs
{
#region Properties & Fields
/// <summary>
/// Gets the <see cref="System.Exception"/> which is responsible for the event-call.
/// </summary>
public Exception Exception { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="ExceptionEventArgs"/> class.
/// </summary>
/// <param name="exception">The <see cref="System.Exception"/> which is responsible for the event-call.</param>
public ExceptionEventArgs(Exception exception)
{
this.Exception = exception;
}
#endregion
}
}

View File

@ -0,0 +1,36 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
using System.Collections.Generic;
namespace RGB.NET.Core
{
/// <summary>
/// Represents the information supplied with an <see cref="IRGBSurface.LedsUpdated"/>-event.
/// </summary>
public class LedsUpdatedEventArgs : EventArgs
{
#region Properties & Fields
/// <summary>
/// Gets a list of <see cref="Led"/> which got updated.
/// </summary>
public IEnumerable<Led> UpdatedLeds { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="LedsUpdatedEventArgs"/> class.
/// </summary>
/// <param name="updatedLeds">The updated <see cref="Led"/>.</param>
public LedsUpdatedEventArgs(IEnumerable<Led> updatedLeds)
{
this.UpdatedLeds = updatedLeds;
}
#endregion
}
}

View File

@ -0,0 +1,36 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
using System.Collections.Generic;
namespace RGB.NET.Core
{
/// <summary>
/// Represents the information supplied with an <see cref="IRGBSurface.LedsUpdating"/>-event.
/// </summary>
public class LedsUpdatingEventArgs : EventArgs
{
#region Properties & Fields
/// <summary>
/// Gets a list of <see cref="Led"/> which are about to get updated.
/// </summary>
public ICollection<Led> UpdatingLeds { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="LedsUpdatingEventArgs"/> class.
/// </summary>
/// <param name="updatingLeds">The updating <see cref="Led"/>.</param>
public LedsUpdatingEventArgs(ICollection<Led> updatingLeds)
{
this.UpdatingLeds = updatingLeds;
}
#endregion
}
}

View File

@ -0,0 +1,10 @@
using System;
namespace RGB.NET.Core
{
/// <summary>
/// Represents the information supplied with an <see cref="IRGBSurface.Updated"/>-event.
/// </summary>
public class UpdatedEventArgs : EventArgs
{ }
}

View File

@ -0,0 +1,35 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedAutoPropertyAccessor.Global
using System;
namespace RGB.NET.Core
{
/// <summary>
/// Represents the information supplied with an <see cref="IRGBSurface.Updating"/>-event.
/// </summary>
public class UpdatingEventArgs : EventArgs
{
#region Properties & Fields
/// <summary>
/// Gets the elapsed time (in seconds) since the last update.
/// </summary>
public double DeltaTime { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="UpdatingEventArgs"/> class.
/// </summary>
/// <param name="deltaTime">The elapsed time (in seconds) since the last update.</param>
public UpdatingEventArgs(double deltaTime)
{
this.DeltaTime = deltaTime;
}
#endregion
}
}

View File

@ -1,7 +1,7 @@
using System;
using System.Runtime.CompilerServices;
namespace RGB.NET.Core.Extensions
namespace RGB.NET.Core
{
/// <summary>
/// Offers some extensions and helper-methods for the work with doubles

View File

@ -3,8 +3,6 @@
using System;
using System.Diagnostics;
using RGB.NET.Core.Extensions;
using RGB.NET.Core.MVVM;
namespace RGB.NET.Core
{

View File

@ -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
{

View File

@ -1,7 +1,7 @@
using System.ComponentModel;
using System.Runtime.CompilerServices;
namespace RGB.NET.Core.MVVM
namespace RGB.NET.Core
{
/// <summary>
/// Represents a basic bindable class which notifies when a property value changes.
@ -43,11 +43,11 @@ namespace RGB.NET.Core.MVVM
/// <returns><c>true</c> if the value was changed, <c>false</c> if the existing value matched the desired value.</returns>
protected virtual bool SetProperty<T>(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 <see cref="CallerMemberNameAttribute"/>.</param>
protected virtual void OnPropertyChanged([CallerMemberName] string propertyName = null)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
this.PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion

View File

@ -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
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Point" /> equivalent to this <see cref="Point" />; otherwise, <c>false</c>.</returns>
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);
}
/// <summary>

View File

@ -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();
}
/// <summary>
/// Determines if the specified <see cref="Point"/> is contained within this <see cref="Rectangle"/>.
/// </summary>
/// <param name="point">The <see cref="Point"/> to test.</param>
/// <returns></returns>
public bool Contains(Point point)
{
return Contains(point.X, point.Y);
}
/// <summary>
/// Determines if the specified location is contained within this <see cref="Rectangle"/>.
/// </summary>
/// <param name="x">The X-location to test.</param>
/// <param name="y">The Y-location to test.</param>
/// <returns></returns>
public bool Contains(double x, double y)
{
return (Location.X <= x) && (x < (Location.X + Size.Width)) && (Location.Y <= y) && (y < (Location.Y + Size.Height));
}
/// <summary>
/// Determines if the specified <see cref="Rectangle"/> is contained within this <see cref="Rectangle"/>.
/// </summary>
/// <param name="rect">The <see cref="Rectangle"/> to test.</param>
/// <returns></returns>
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));
}
/// <summary>
/// Converts the <see cref="Location"/>- and <see cref="Size"/>-position of this <see cref="Rectangle"/> to a human-readable string.
/// </summary>
/// <returns>A string that contains the <see cref="Location"/> and <see cref="Size"/> of this <see cref="Rectangle"/>. For example "[Location: [X: 100, Y: 10], Size: [Width: 20, Height: [40]]".</returns>
public override string ToString()
{
return $"[Location: {Location}, Size: {Size}]";
}
/// <summary>
/// Tests whether the specified object is a <see cref="Rectangle" /> and is equivalent to this <see cref="Rectangle" />.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Rectangle" /> equivalent to this <see cref="Rectangle" />; otherwise, <c>false</c>.</returns>
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);
}
/// <summary>
/// Returns a hash code for this <see cref="Rectangle" />.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="Rectangle" />.</returns>
public override int GetHashCode()
{
unchecked
{
int hashCode = Location.GetHashCode();
hashCode = (hashCode * 397) ^ Size.GetHashCode();
return hashCode;
}
}
#endregion
#region Operators
/// <summary>
/// Returns a value that indicates whether two specified <see cref="Rectangle" /> are equal.
/// </summary>
/// <param name="rectangle1">The first <see cref="Rectangle" /> to compare.</param>
/// <param name="rectangle2">The second <see cref="Rectangle" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="rectangle1" /> and <paramref name="rectangle2" /> are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2)
{
return ReferenceEquals(rectangle1, null) ? ReferenceEquals(rectangle2, null) : rectangle1.Equals(rectangle2);
}
/// <summary>
/// Returns a value that indicates whether two specified <see cref="Rectangle" /> are equal.
/// </summary>
/// <param name="rectangle1">The first <see cref="Rectangle" /> to compare.</param>
/// <param name="rectangle2">The second <see cref="Rectangle" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="rectangle1" /> and <paramref name="rectangle2" /> are not equal; otherwise, <c>false</c>.</returns>
public static bool operator !=(Rectangle rectangle1, Rectangle rectangle2)
{
return !(rectangle1 == rectangle2);
}
#endregion
}
}

View File

@ -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
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Size" /> equivalent to this <see cref="Size" />; otherwise, <c>false</c>.</returns>
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);
}
/// <summary>

View File

@ -46,18 +46,27 @@
<Compile Include="Brushes\BrushRenderTarget.cs" />
<Compile Include="Brushes\IBrush.cs" />
<Compile Include="ColorCorrection\IColorCorrection.cs" />
<Compile Include="Devices\AbstractRGBDevice.cs" />
<Compile Include="Devices\IRGBDeviceInfo.cs" />
<Compile Include="Effects\IEffect.cs" />
<Compile Include="Effects\IEffectTarget.cs" />
<Compile Include="ILedId.cs" />
<Compile Include="Events\ExceptionEventArgs.cs" />
<Compile Include="Events\LedsUpdatedEventArgs.cs" />
<Compile Include="Events\LedsUpdatingEventArgs.cs" />
<Compile Include="Events\UpdatedEventArgs.cs" />
<Compile Include="Events\UpdatingEventArgs.cs" />
<Compile Include="Leds\ILedId.cs" />
<Compile Include="Surfaces\IRGBSurface.cs" />
<Compile Include="MVVM\AbstractBindable.cs" />
<Compile Include="Color.cs" />
<Compile Include="Leds\Color.cs" />
<Compile Include="Extensions\DoubleExtensions.cs" />
<Compile Include="Devices\IRGBDevice.cs" />
<Compile Include="Led.cs" />
<Compile Include="Leds\Led.cs" />
<Compile Include="Positioning\Point.cs" />
<Compile Include="Positioning\Size.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Positioning\Rectangle.cs" />
<Compile Include="Surfaces\RGBSurface.cs" />
</ItemGroup>
<ItemGroup />
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />

View File

@ -1,2 +1,11 @@
<wpf:ResourceDictionary xml:space="preserve" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml" xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=positioning/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=brushes/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=colorcorrection/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=devices/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=effects/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=events/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=extensions/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=leds/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=mvvm/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=positioning/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=surfaces/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>

View File

@ -0,0 +1,81 @@
namespace RGB.NET.Core
{
#region EventHandler
/// <summary>
/// Represents the event-handler of the <see cref="IRGBSurface.Exception"/>-event.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="args">The arguments provided by the event.</param>
public delegate void ExceptionEventHandler(object sender, ExceptionEventArgs args);
/// <summary>
/// Represents the event-handler of the <see cref="IRGBSurface.Updating"/>-event.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="args">The arguments provided by the event.</param>
public delegate void UpdatingEventHandler(object sender, UpdatingEventArgs args);
/// <summary>
/// Represents the event-handler of the <see cref="IRGBSurface.Updated"/>-event.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="args">The arguments provided by the event.</param>
public delegate void UpdatedEventHandler(object sender, UpdatedEventArgs args);
/// <summary>
/// Represents the event-handler of the <see cref="IRGBSurface.LedsUpdating"/>-event.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="args">The arguments provided by the event.</param>
public delegate void LedsUpdatingEventHandler(object sender, LedsUpdatingEventArgs args);
/// <summary>
/// Represents the event-handler of the <see cref="IRGBSurface.LedsUpdated"/>-event.
/// </summary>
/// <param name="sender">The sender of the event.</param>
/// <param name="args">The arguments provided by the event.</param>
public delegate void LedsUpdatedEventHandler(object sender, LedsUpdatedEventArgs args);
#endregion
/// <summary>
/// Represents a generic RGB-surface.
/// </summary>
public interface IRGBSurface
{
#region Events
// ReSharper disable EventNeverSubscribedTo.Global
/// <summary>
/// Occurs when a catched exception is thrown inside the <see cref="IRGBSurface"/>.
/// </summary>
event ExceptionEventHandler Exception;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> starts updating.
/// </summary>
event UpdatingEventHandler Updating;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> update is done.
/// </summary>
event UpdatedEventHandler Updated;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> starts to update the leds.
/// </summary>
event LedsUpdatingEventHandler LedsUpdating;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> updated the leds.
/// </summary>
event LedsUpdatedEventHandler LedsUpdated;
// ReSharper restore EventNeverSubscribedTo.Global
#endregion
}
}

View File

@ -0,0 +1,144 @@
using System;
using System.Collections.Generic;
namespace RGB.NET.Core
{
/// <summary>
/// Represents a generic RGB-surface.
/// </summary>
public class RGBSurface
{
#region Properties & Fields
private DateTime _lastUpdate;
#endregion
#region Events
// ReSharper disable EventNeverSubscribedTo.Global
/// <summary>
/// Occurs when a catched exception is thrown inside the <see cref="IRGBSurface"/>.
/// </summary>
public event ExceptionEventHandler Exception;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> starts updating.
/// </summary>
public event UpdatingEventHandler Updating;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> update is done.
/// </summary>
public event UpdatedEventHandler Updated;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> starts to update the <see cref="Led"/>.
/// </summary>
public event LedsUpdatingEventHandler LedsUpdating;
/// <summary>
/// Occurs when the <see cref="IRGBSurface"/> updated the <see cref="Led"/>.
/// </summary>
public event LedsUpdatedEventHandler LedsUpdated;
// ReSharper restore EventNeverSubscribedTo.Global
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="RGBSurface"/> class.
/// </summary>
public RGBSurface()
{
_lastUpdate = DateTime.Now;
}
#endregion
#region EventCaller
/// <summary>
/// Handles the needed event-calls for an exception.
/// </summary>
/// <param name="ex">The exception previously thrown.</param>
protected virtual void OnException(Exception ex)
{
try
{
Exception?.Invoke(this, new ExceptionEventArgs(ex));
}
catch
{
// Well ... that's not my fault
}
}
/// <summary>
/// Handles the needed event-calls before updating.
/// </summary>
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
}
}
/// <summary>
/// Handles the needed event-calls after an update.
/// </summary>
protected virtual void OnUpdated()
{
try
{
Updated?.Invoke(this, new UpdatedEventArgs());
}
catch
{
// Well ... that's not my fault
}
}
/// <summary>
/// Handles the needed event-calls before the <see cref="Led"/> are updated.
/// </summary>
protected virtual void OnLedsUpdating(ICollection<Led> updatingLeds)
{
try
{
LedsUpdating?.Invoke(this, new LedsUpdatingEventArgs(updatingLeds));
}
catch
{
// Well ... that's not my fault
}
}
/// <summary>
/// Handles the needed event-calls after the <see cref="Led"/> are updated.
/// </summary>
protected virtual void OnLedsUpdated(IEnumerable<Led> updatedLeds)
{
try
{
LedsUpdated?.Invoke(this, new LedsUpdatedEventArgs(updatedLeds));
}
catch
{
// Well ... that's not my fault
}
}
#endregion
}
}

View File

@ -189,6 +189,7 @@
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/BRACES_FOR_USING/@EntryValue">NotRequired</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/FORCE_ATTRIBUTE_STYLE/@EntryValue">Join</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/PARENTHESES_NON_OBVIOUS_OPERATIONS/@EntryValue">Arithmetic, Shift, Relational, Equality, Bitwise, Conditional, Lowest</s:String>
<s:String x:Key="/Default/CodeStyle/CodeFormatting/CSharpCodeStyle/ThisQualifier/INSTANCE_MEMBERS_QUALIFY_MEMBERS/@EntryValue">All</s:String>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_FIRST_ARG_BY_PAREN/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_LINQ_QUERY/@EntryValue">True</s:Boolean>
<s:Boolean x:Key="/Default/CodeStyle/CodeFormatting/CSharpFormat/ALIGN_MULTILINE_ARGUMENT/@EntryValue">True</s:Boolean>
@ -324,4 +325,10 @@
<s:String x:Key="/Default/CodeStyle/Naming/WebNaming/UserRules/=ASP_005FTAG_005FPREFIX/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=NAMESPACE_005FALIAS/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="aaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FFIELD/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String></wpf:ResourceDictionary>
<s:String x:Key="/Default/CodeStyle/Naming/XamlNaming/UserRules/=XAML_005FRESOURCE/@EntryIndexedValue">&lt;Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /&gt;</s:String>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsParsFormattingSettingsUpgrader/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsWrapperSettingsUpgrader/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>