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

Merge pull request #93 from DarthAffe/Development

Merge Development to master
This commit is contained in:
DarthAffe 2019-12-01 15:58:17 +01:00 committed by GitHub
commit 0a378b3424
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
52 changed files with 1295 additions and 318 deletions

View File

@ -78,9 +78,10 @@ namespace RGB.NET.Core
/// <param name="color">The <see cref="Color"/> to be modified.</param> /// <param name="color">The <see cref="Color"/> to be modified.</param>
protected virtual Color ApplyDecorators(Rectangle rectangle, BrushRenderTarget renderTarget, Color color) protected virtual Color ApplyDecorators(Rectangle rectangle, BrushRenderTarget renderTarget, Color color)
{ {
foreach (IBrushDecorator decorator in Decorators) lock (Decorators)
if (decorator.IsEnabled) foreach (IBrushDecorator decorator in Decorators)
color = decorator.ManipulateColor(rectangle, renderTarget, color); if (decorator.IsEnabled)
color = decorator.ManipulateColor(rectangle, renderTarget, color);
return color; return color;
} }

View File

@ -11,11 +11,20 @@ namespace RGB.NET.Core
{ {
#region Properties & Fields #region Properties & Fields
private List<T> _decorators = new List<T>(); private readonly List<T> _decorators = new List<T>();
/// <summary> /// <summary>
/// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>. /// Gets a readonly-list of all <see cref="IDecorator"/> attached to this <see cref="IDecoratable{T}"/>.
/// </summary> /// </summary>
protected IReadOnlyCollection<T> Decorators => new ReadOnlyCollection<T>(_decorators); protected IReadOnlyCollection<T> Decorators { get; }
#endregion
#region Constructors
protected AbstractDecoratable()
{
Decorators = new ReadOnlyCollection<T>(_decorators);
}
#endregion #endregion
@ -24,8 +33,11 @@ namespace RGB.NET.Core
/// <inheritdoc /> /// <inheritdoc />
public void AddDecorator(T decorator) public void AddDecorator(T decorator)
{ {
_decorators.Add(decorator); lock (Decorators)
_decorators = _decorators.OrderByDescending(x => x.Order).ToList(); {
_decorators.Add(decorator);
_decorators.Sort((d1, d2) => d1.Order.CompareTo(d2.Order));
}
decorator.OnAttached(this); decorator.OnAttached(this);
} }
@ -33,7 +45,8 @@ namespace RGB.NET.Core
/// <inheritdoc /> /// <inheritdoc />
public void RemoveDecorator(T decorator) public void RemoveDecorator(T decorator)
{ {
_decorators.Remove(decorator); lock (Decorators)
_decorators.Remove(decorator);
decorator.OnDetached(this); decorator.OnDetached(this);
} }
@ -41,7 +54,12 @@ namespace RGB.NET.Core
/// <inheritdoc /> /// <inheritdoc />
public void RemoveAllDecorators() public void RemoveAllDecorators()
{ {
foreach (T decorator in Decorators.ToList()) IEnumerable<T> decorators;
lock (Decorators)
decorators = Decorators.ToList();
foreach (T decorator in decorators)
RemoveDecorator(decorator); RemoveDecorator(decorator);
} }

View File

@ -27,14 +27,6 @@ namespace RGB.NET.Core
/// <inheritdoc /> /// <inheritdoc />
IRGBDeviceInfo IRGBDevice.DeviceInfo => DeviceInfo; IRGBDeviceInfo IRGBDevice.DeviceInfo => DeviceInfo;
private Size _size = Size.Invalid;
/// <inheritdoc />
public Size Size
{
get => _size;
set => SetProperty(ref _size, value);
}
private Point _location = new Point(0, 0); private Point _location = new Point(0, 0);
/// <inheritdoc /> /// <inheritdoc />
public Point Location public Point Location
@ -43,6 +35,58 @@ namespace RGB.NET.Core
set => SetProperty(ref _location, value); set => SetProperty(ref _location, value);
} }
private Size _size = Size.Invalid;
/// <inheritdoc />
public Size Size
{
get => _size;
protected set
{
if (SetProperty(ref _size, value))
UpdateActualData();
}
}
private Size _actualSize;
/// <inheritdoc />
public Size ActualSize
{
get => _actualSize;
private set => SetProperty(ref _actualSize, value);
}
private Rectangle _deviceRectangle;
/// <inheritdoc />
public Rectangle DeviceRectangle
{
get => _deviceRectangle;
private set => SetProperty(ref _deviceRectangle, value);
}
private Scale _scale = new Scale(1);
/// <inheritdoc />
public Scale Scale
{
get => _scale;
set
{
if (SetProperty(ref _scale, value))
UpdateActualData();
}
}
private Rotation _rotation = new Rotation(0);
/// <inheritdoc />
public Rotation Rotation
{
get => _rotation;
set
{
if (SetProperty(ref _rotation, value))
UpdateActualData();
}
}
/// <summary> /// <summary>
/// Gets or sets if the device needs to be flushed on every update. /// Gets or sets if the device needs to be flushed on every update.
/// </summary> /// </summary>
@ -79,6 +123,12 @@ namespace RGB.NET.Core
#region Methods #region Methods
private void UpdateActualData()
{
ActualSize = Size * Scale;
DeviceRectangle = new Rectangle(Location, new Rectangle(new Rectangle(Location, ActualSize).Rotate(Rotation)).Size);
}
/// <inheritdoc /> /// <inheritdoc />
public virtual void Update(bool flushLeds = false) public virtual void Update(bool flushLeds = false)
{ {
@ -124,11 +174,21 @@ namespace RGB.NET.Core
/// <param name="ledId">The <see cref="LedId"/> to initialize.</param> /// <param name="ledId">The <see cref="LedId"/> to initialize.</param>
/// <param name="ledRectangle">The <see cref="Rectangle"/> representing the position of the <see cref="Led"/> to initialize.</param> /// <param name="ledRectangle">The <see cref="Rectangle"/> representing the position of the <see cref="Led"/> to initialize.</param>
/// <returns></returns> /// <returns></returns>
protected virtual Led InitializeLed(LedId ledId, Rectangle ledRectangle) [Obsolete("Use InitializeLed(LedId ledId, Point location, Size size) instead.")]
protected virtual Led InitializeLed(LedId ledId, Rectangle rectangle) => InitializeLed(ledId, rectangle.Location, rectangle.Size);
/// <summary>
/// Initializes the <see cref="Led"/> with the specified id.
/// </summary>
/// <param name="ledId">The <see cref="LedId"/> to initialize.</param>
/// <param name="location">The location of the <see cref="Led"/> to initialize.</param>
/// <param name="size">The size of the <see cref="Led"/> to initialize.</param>
/// <returns>The initialized led.</returns>
protected virtual Led InitializeLed(LedId ledId, Point location, Size size)
{ {
if ((ledId == LedId.Invalid) || LedMapping.ContainsKey(ledId)) return null; if ((ledId == LedId.Invalid) || LedMapping.ContainsKey(ledId)) return null;
Led led = new Led(this, ledId, ledRectangle, CreateLedCustomData(ledId)); Led led = new Led(this, ledId, location, size, CreateLedCustomData(ledId));
LedMapping.Add(ledId, led); LedMapping.Add(ledId, led);
return led; return led;
} }
@ -157,7 +217,7 @@ namespace RGB.NET.Core
DeviceLayout layout = DeviceLayout.Load(layoutPath); DeviceLayout layout = DeviceLayout.Load(layoutPath);
if (layout != null) if (layout != null)
{ {
string imageBasePath = string.IsNullOrWhiteSpace(layout.ImageBasePath) ? null : PathHelper.GetAbsolutePath(layout.ImageBasePath); string imageBasePath = string.IsNullOrWhiteSpace(layout.ImageBasePath) ? null : PathHelper.GetAbsolutePath(this, layout.ImageBasePath);
if ((imageBasePath != null) && !string.IsNullOrWhiteSpace(layout.DeviceImage) && (DeviceInfo != null)) if ((imageBasePath != null) && !string.IsNullOrWhiteSpace(layout.DeviceImage) && (DeviceInfo != null))
DeviceInfo.Image = new Uri(Path.Combine(imageBasePath, layout.DeviceImage), UriKind.Absolute); DeviceInfo.Image = new Uri(Path.Combine(imageBasePath, layout.DeviceImage), UriKind.Absolute);
@ -171,13 +231,12 @@ namespace RGB.NET.Core
if (Enum.TryParse(layoutLed.Id, true, out LedId ledId)) if (Enum.TryParse(layoutLed.Id, true, out LedId ledId))
{ {
if (!LedMapping.TryGetValue(ledId, out Led led) && createMissingLeds) if (!LedMapping.TryGetValue(ledId, out Led led) && createMissingLeds)
led = InitializeLed(ledId, new Rectangle()); led = InitializeLed(ledId, new Point(), new Size());
if (led != null) if (led != null)
{ {
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y); led.Location = new Point(layoutLed.X, layoutLed.Y);
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height); led.Size = new Size(layoutLed.Width, layoutLed.Height);
led.Shape = layoutLed.Shape; led.Shape = layoutLed.Shape;
led.ShapeData = layoutLed.ShapeData; led.ShapeData = layoutLed.ShapeData;

View File

@ -24,10 +24,31 @@ namespace RGB.NET.Core
Point Location { get; set; } Point Location { get; set; }
/// <summary> /// <summary>
/// Gets a copy of the <see cref="Size"/> of the whole <see cref="IRGBDevice"/>. /// Gets the <see cref="Size"/> of the <see cref="IRGBDevice"/>.
/// </summary> /// </summary>
Size Size { get; } Size Size { get; }
/// <summary>
/// Gets the actual <see cref="Size"/> of the <see cref="IRGBDevice"/>.
/// This includes the <see cref="Scale"/>.
/// </summary>
Size ActualSize { get; }
/// <summary>
/// Gets a <see cref="Rectangle"/> representing the logical location of the <see cref="DeviceRectangle"/> relative to the <see cref="RGBSurface"/>.
/// </summary>
Rectangle DeviceRectangle { get; }
/// <summary>
/// Gets or sets the scale of the <see cref="IRGBDevice"/>.
/// </summary>
Scale Scale { get; set; }
/// <summary>
/// Gets or sets the rotation of the <see cref="IRGBDevice"/>.
/// </summary>
Rotation Rotation { get; set; }
/// <summary> /// <summary>
/// Gets or sets the <see cref="DeviceUpdateMode"/> of the <see cref="IRGBDevice"/>. /// Gets or sets the <see cref="DeviceUpdateMode"/> of the <see cref="IRGBDevice"/>.
/// </summary> /// </summary>

View File

@ -0,0 +1,64 @@
using System;
namespace RGB.NET.Core
{
public class ResolvePathEventArgs : EventArgs
{
#region Properties & Fields
/// <summary>
/// Gets the filename used to resolve the path.
/// This has to be checked for null since it'S possible that only <see cref="FileName"/> is used.
/// Also check <see cref="RelativePath "/> before use.
/// </summary>
public string RelativePart { get; }
/// <summary>
/// Gets the filename used to resolve the path.
/// This has to be checked for null since it'S possible that only <see cref="RelativePart"/> is used.
/// Also check <see cref="RelativePath "/> before use.
/// </summary>
public string FileName { get; }
/// <summary>
/// Gets the relative path used to resolve the path.
/// If this is set <see cref="RelativePart" /> and <see cref="FileName" /> are unused.
/// </summary>
public string RelativePath { get; }
/// <summary>
/// Gets or sets the resolved path.
/// </summary>
public string FinalPath { get; set; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Corer.ResolvePathEventArgs" /> class.
/// </summary>
/// <param name="relativePart">The filename used to resolve the path.</param>
/// <param name="fileName">The filename used to resolve the path.</param>
/// <param name="finalPath">The relative part used to resolve the path.</param>
public ResolvePathEventArgs(string relativePart, string fileName, string finalPath)
{
this.RelativePart = relativePart;
this.FileName = fileName;
this.FinalPath = finalPath;
}
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Corer.ResolvePathEventArgs" /> class.
/// </summary>
/// <param name="relativePath">The relative path used to resolve the path.</param>
/// <param name="finalPath">The relative part used to resolve the path.</param>
public ResolvePathEventArgs(string relativePath, string finalPath)
{
this.RelativePath = relativePath;
this.FinalPath = finalPath;
}
#endregion
}
}

View File

@ -0,0 +1,37 @@
using System;
namespace RGB.NET.Core
{
public static class PointExtensions
{
#region Methods
/// <summary>
/// Moves the specified <see cref="Point"/> by the given amount.
/// </summary>
/// <param name="point">The <see cref="Point"/> to move.</param>
/// <param name="x">The x-ammount to move.</param>
/// <param name="y">The y-ammount to move.</param>
/// <returns>The new location of the point.</returns>
public static Point Translate(this Point point, double x = 0, double y = 0) => new Point(point.X + x, point.Y + y);
/// <summary>
/// Rotates the specified <see cref="Point"/> by the given amuont around the given origin.
/// </summary>
/// <param name="point">The <see cref="Point"/> to rotate.</param>
/// <param name="rotation">The rotation.</param>
/// <param name="origin">The origin to rotate around. [0,0] if not set.</param>
/// <returns>The new location of the point.</returns>
public static Point Rotate(this Point point, Rotation rotation, Point origin = new Point())
{
double sin = Math.Sin(rotation.Radians);
double cos = Math.Cos(rotation.Radians);
point = new Point(point.X - origin.X, point.Y - origin.Y);
point = new Point((point.X * cos) - (point.Y * sin), (point.X * sin) + (point.Y * cos));
return new Point(point.X + origin.X, point.Y + origin.Y); ;
}
#endregion
}
}

View File

@ -0,0 +1,169 @@
using System;
namespace RGB.NET.Core
{
public static class RectangleExtensions
{
#region Methods
/// <summary>
/// Sets the <see cref="Rectangle.Location"/> of the given rectangle.
/// </summary>
/// <param name="rect">The rectangle to modify.</param>
/// <param name="location">The new location of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetLocation(this Rectangle rect, Point location) => new Rectangle(location, rect.Size);
/// <summary>
/// Sets the <see cref="Point.X"/> of the <see cref="Rectangle.Location"/> of the given rectangle.
/// </summary>
/// <param name="rect">The rectangle to modify.</param>
/// <param name="x">The new x-location of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetX(this Rectangle rect, double x) => new Rectangle(new Point(x, rect.Location.Y), rect.Size);
/// <summary>
/// Sets the <see cref="Point.Y"/> of the <see cref="Rectangle.Location"/> of the given rectangle.
/// </summary>
/// <param name="rect">The rectangle to modify.</param>
/// <param name="y">The new y-location of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetY(this Rectangle rect, double y) => new Rectangle(new Point(rect.Location.X, y), rect.Size);
/// <summary>
/// Sets the <see cref="Rectangle.Size"/> of the given rectangle.
/// </summary>
/// <param name="rect">The rectangle to modify.</param>
/// <param name="size">The new size of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetSize(this Rectangle rect, Size size) => new Rectangle(rect.Location, size);
/// <summary>
/// Sets the <see cref="Size.Width"/> of the <see cref="Rectangle.Size"/> of the given rectangle.
/// </summary>
/// <param name="rect">The rectangle to modify.</param>
/// <param name="width">The new width of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetWidth(this Rectangle rect, double width) => new Rectangle(rect.Location, new Size(width, rect.Size.Height));
/// <summary>
/// Sets the <see cref="Size.Height"/> of the <see cref="Rectangle.Size"/> of the given rectangle.
/// </summary>
/// <param name="rect">The rectangle to modify.</param>
/// <param name="height">The new height of the rectangle.</param>
/// <returns>The modified <see cref="Rectangle"/>.</returns>
public static Rectangle SetHeight(this Rectangle rect, double height) => new Rectangle(rect.Location, new Size(rect.Size.Width, height));
/// <summary>
/// Calculates the percentage of intersection of a rectangle.
/// </summary>
/// <param name="intersectingRect">The intersecting rectangle.</param>
/// <returns>The percentage of intersection.</returns>
public static double CalculateIntersectPercentage(this Rectangle rect, Rectangle intersectingRect)
{
if (rect.IsEmpty || intersectingRect.IsEmpty) return 0;
Rectangle intersection = rect.CalculateIntersection(intersectingRect);
return (intersection.Size.Width * intersection.Size.Height) / (rect.Size.Width * rect.Size.Height);
}
/// <summary>
/// Calculates the <see cref="Rectangle"/> representing the intersection of this <see cref="Rectangle"/> and the one provided as parameter.
/// </summary>
/// <param name="intersectingRectangle">The intersecting <see cref="Rectangle"/></param>
/// <returns>A new <see cref="Rectangle"/> representing the intersection this <see cref="Rectangle"/> and the one provided as parameter.</returns>
public static Rectangle CalculateIntersection(this Rectangle rect, Rectangle intersectingRectangle)
{
double x1 = Math.Max(rect.Location.X, intersectingRectangle.Location.X);
double x2 = Math.Min(rect.Location.X + rect.Size.Width, intersectingRectangle.Location.X + intersectingRectangle.Size.Width);
double y1 = Math.Max(rect.Location.Y, intersectingRectangle.Location.Y);
double y2 = Math.Min(rect.Location.Y + rect.Size.Height, intersectingRectangle.Location.Y + intersectingRectangle.Size.Height);
if ((x2 >= x1) && (y2 >= y1))
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
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><c>true</c> if the rectangle contains the given point; otherwise <c>false</c>.</returns>
public static bool Contains(this Rectangle rect, Point point) => rect.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><c>true</c> if the rectangle contains the given coordinates; otherwise <c>false</c>.</returns>
public static bool Contains(this Rectangle rect, double x, double y) => (rect.Location.X <= x) && (x < (rect.Location.X + rect.Size.Width))
&& (rect.Location.Y <= y) && (y < (rect.Location.Y + rect.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><c>true</c> if the rectangle contains the given rect; otherwise <c>false</c>.</returns>
public static bool Contains(this Rectangle rect, Rectangle rect2) => (rect.Location.X <= rect2.Location.X) && ((rect2.Location.X + rect2.Size.Width) <= (rect.Location.X + rect.Size.Width))
&& (rect.Location.Y <= rect2.Location.Y) && ((rect2.Location.Y + rect2.Size.Height) <= (rect.Location.Y + rect.Size.Height));
/// <summary>
/// Moves the specified <see cref="Rectangle"/> by the given amount.
/// </summary>
/// <param name="rect">The <see cref="Rectangle"/> to move.</param>
/// <param name="point">The amount to move.</param>
/// <returns>The moved rectangle.</returns>
public static Rectangle Translate(this Rectangle rect, Point point) => rect.Translate(point.X, point.Y);
/// <summary>
/// Moves the specified <see cref="Rectangle"/> by the given amount.
/// </summary>
/// <param name="rect">The <see cref="Rectangle"/> to move.</param>
/// <param name="x">The x-ammount to move.</param>
/// <param name="y">The y-ammount to move.</param>
/// <returns>The moved rectangle.</returns>
public static Rectangle Translate(this Rectangle rect, double x = 0, double y = 0) => new Rectangle(rect.Location.Translate(x, y), rect.Size);
/// <summary>
/// Rotates the specified <see cref="Rectangle"/> by the given amuont around the given origin.
/// </summary>
/// <remarks>
/// The returned array of <see cref="Point"/> is filled with the new locations of the rectangle clockwise starting from the top left:
/// [0] = top left
/// [1] = top right
/// [2] = bottom right
/// [3] = bottom left
/// </remarks>
/// <param name="rect">The <see cref="Rectangle"/> to rotate.</param>
/// <param name="rotation">The rotation.</param>
/// <param name="origin">The origin to rotate around. [0,0] if not set.</param>
/// <returns>A array of <see cref="Point"/> containing the new locations of the corners of the original rectangle.</returns>
public static Point[] Rotate(this Rectangle rect, Rotation rotation, Point origin = new Point())
{
Point[] points = {
rect.Location, // top left
new Point(rect.Location.X + rect.Size.Width, rect.Location.Y), // top right
new Point(rect.Location.X + rect.Size.Width, rect.Location.Y + rect.Size.Height), // bottom right
new Point(rect.Location.X, rect.Location.Y + rect.Size.Height), // bottom right
};
double sin = Math.Sin(rotation.Radians);
double cos = Math.Cos(rotation.Radians);
for (int i = 0; i < points.Length; i++)
{
Point point = points[i];
point = new Point(point.X - origin.X, point.Y - origin.Y);
point = new Point((point.X * cos) - (point.Y * sin), (point.X * sin) + (point.Y * cos));
points[i] = new Point(point.X + origin.X, point.Y + origin.Y);
}
return points;
}
#endregion
}
}

View File

@ -1,4 +1,5 @@
using System.IO; using System;
using System.IO;
using System.Reflection; using System.Reflection;
namespace RGB.NET.Core namespace RGB.NET.Core
@ -8,20 +9,73 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
public static class PathHelper public static class PathHelper
{ {
#region Events
/// <summary>
/// Occurs when a path is resolving.
/// </summary>
public static event EventHandler<ResolvePathEventArgs> ResolvingAbsolutePath;
#endregion
#region Methods #region Methods
/// <summary> /// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly. /// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary> /// </summary>
/// <param name="relativePath">The relative part of the path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(string relativePath) => GetAbsolutePath((object)null, relativePath);
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="relativePath">The relative part of the path to convert.</param>
/// <param name="fileName">The file name of the path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(string relativePath, string fileName) => GetAbsolutePath(null, relativePath, fileName);
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="sender">The requester of this path. (Used for better control when using the event to override this behavior.)</param>
/// <param name="relativePath">The relative path to convert.</param>
/// <param name="fileName">The file name of the path to convert.</param>
/// <returns>The absolute path.</returns>
public static string GetAbsolutePath(object sender, string relativePath, string fileName)
{
string relativePart = Path.Combine(relativePath, fileName);
string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePart;
string directoryName = Path.GetDirectoryName(assemblyLocation);
string path = directoryName == null ? null : Path.Combine(directoryName, relativePart);
ResolvePathEventArgs args = new ResolvePathEventArgs(relativePath, fileName, path);
ResolvingAbsolutePath?.Invoke(sender, args);
return args.FinalPath;
}
/// <summary>
/// Returns an absolute path created from an relative path relatvie to the location of the executung assembly.
/// </summary>
/// <param name="sender">The requester of this path. (Used for better control when using the event to override this behavior.)</param>
/// <param name="relativePath">The relative path to convert.</param> /// <param name="relativePath">The relative path to convert.</param>
/// <returns>The absolute path.</returns> /// <returns>The absolute path.</returns>
public static string GetAbsolutePath(string relativePath) public static string GetAbsolutePath(object sender, string relativePath)
{ {
string assemblyLocation = Assembly.GetEntryAssembly()?.Location; string assemblyLocation = Assembly.GetEntryAssembly()?.Location;
if (assemblyLocation == null) return relativePath; if (assemblyLocation == null) return relativePath;
string directoryName = Path.GetDirectoryName(assemblyLocation); string directoryName = Path.GetDirectoryName(assemblyLocation);
return directoryName == null ? null : Path.Combine(directoryName, relativePath); string path = directoryName == null ? null : Path.Combine(directoryName, relativePath);
ResolvePathEventArgs args = new ResolvePathEventArgs(relativePath, path);
ResolvingAbsolutePath?.Invoke(sender, args);
return args.FinalPath;
} }
#endregion #endregion

View File

@ -1,6 +1,7 @@
// ReSharper disable MemberCanBePrivate.Global // ReSharper disable MemberCanBePrivate.Global
using System; using System;
using System.ComponentModel;
using System.Diagnostics; using System.Diagnostics;
namespace RGB.NET.Core namespace RGB.NET.Core
@ -44,15 +45,81 @@ namespace RGB.NET.Core
set => SetProperty(ref _shapeData, value); set => SetProperty(ref _shapeData, value);
} }
private Point _location;
/// <summary> /// <summary>
/// Gets a rectangle representing the physical location of the <see cref="Led"/> relative to the <see cref="Device"/>. /// Gets or sets the relative location of the <see cref="Led"/>.
/// </summary> /// </summary>
public Rectangle LedRectangle { get; } public Point Location
{
get => _location;
set
{
if (SetProperty(ref _location, value))
{
UpdateActualData();
UpdateAbsoluteData();
}
}
}
private Size _size;
/// <summary> /// <summary>
/// Gets a rectangle representing the physical location of the <see cref="Led"/> on the <see cref="RGBSurface"/>. /// Gets or sets the size of the <see cref="Led"/>.
/// </summary> /// </summary>
public Rectangle AbsoluteLedRectangle => (LedRectangle.Location + Device.Location) + new Size(LedRectangle.Size.Width, LedRectangle.Size.Height); public Size Size
{
get => _size;
set
{
if (SetProperty(ref _size, value))
{
UpdateActualData();
UpdateAbsoluteData();
}
}
}
private Point _actualLocation;
/// <summary>
/// Gets the actual location of the <see cref="Led"/>.
/// This includes device-scaling and rotation.
/// </summary>
public Point ActualLocation
{
get => _actualLocation;
private set => SetProperty(ref _actualLocation, value);
}
private Size _actualSize;
/// <summary>
/// Gets the actual size of the <see cref="Led"/>.
/// This includes device-scaling.
/// </summary>
public Size ActualSize
{
get => _actualSize;
private set => SetProperty(ref _actualSize, value);
}
private Rectangle _ledRectangle;
/// <summary>
/// Gets a rectangle representing the logical location of the <see cref="Led"/> relative to the <see cref="Device"/>.
/// </summary>
public Rectangle LedRectangle
{
get => _ledRectangle;
private set => SetProperty(ref _ledRectangle, value);
}
private Rectangle _absoluteLedRectangle;
/// <summary>
/// Gets a rectangle representing the logical location of the <see cref="Led"/> on the <see cref="RGBSurface"/>.
/// </summary>
public Rectangle AbsoluteLedRectangle
{
get => _absoluteLedRectangle;
private set => SetProperty(ref _absoluteLedRectangle, value);
}
/// <summary> /// <summary>
/// Indicates whether the <see cref="Led" /> is about to change it's color. /// Indicates whether the <see cref="Led" /> is about to change it's color.
@ -134,20 +201,61 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
/// <param name="device">The <see cref="IRGBDevice"/> the <see cref="Led"/> is associated with.</param> /// <param name="device">The <see cref="IRGBDevice"/> the <see cref="Led"/> is associated with.</param>
/// <param name="id">The <see cref="LedId"/> of the <see cref="Led"/>.</param> /// <param name="id">The <see cref="LedId"/> of the <see cref="Led"/>.</param>
/// <param name="ledRectangle">The <see cref="Rectangle"/> representing the physical location of the <see cref="Led"/> relative to the <see cref="Device"/>.</param> /// <param name="location">The physical location of the <see cref="Led"/> relative to the <see cref="Device"/>.</param>
/// <param name="size">The size of the <see cref="Led"/>.</param>
/// <param name="customData">The provider-specific data associated with this led.</param> /// <param name="customData">The provider-specific data associated with this led.</param>
internal Led(IRGBDevice device, LedId id, Rectangle ledRectangle, object customData = null) internal Led(IRGBDevice device, LedId id, Point location, Size size, object customData = null)
{ {
this.Device = device; this.Device = device;
this.Id = id; this.Id = id;
this.LedRectangle = ledRectangle; this.Location = location;
this.Size = size;
this.CustomData = customData; this.CustomData = customData;
device.PropertyChanged += DevicePropertyChanged;
} }
#endregion #endregion
#region Methods #region Methods
private void DevicePropertyChanged(object sender, PropertyChangedEventArgs e)
{
if ((e.PropertyName == nameof(IRGBDevice.Location)))
UpdateAbsoluteData();
else if (e.PropertyName == nameof(IRGBDevice.DeviceRectangle))
{
UpdateActualData();
UpdateAbsoluteData();
}
}
private void UpdateActualData()
{
ActualSize = Size * Device.Scale;
Point actualLocation = (Location * Device.Scale);
Rectangle ledRectangle = new Rectangle(Location * Device.Scale, Size * Device.Scale);
if (Device.Rotation.IsRotated)
{
Point deviceCenter = new Rectangle(Device.ActualSize).Center;
Point actualDeviceCenter = new Rectangle(Device.DeviceRectangle.Size).Center;
Point centerOffset = new Point(actualDeviceCenter.X - deviceCenter.X, actualDeviceCenter.Y - deviceCenter.Y);
actualLocation = actualLocation.Rotate(Device.Rotation, new Rectangle(Device.ActualSize).Center) + centerOffset;
ledRectangle = new Rectangle(ledRectangle.Rotate(Device.Rotation, new Rectangle(Device.ActualSize).Center)).Translate(centerOffset);
}
ActualLocation = actualLocation;
LedRectangle = ledRectangle;
}
private void UpdateAbsoluteData()
{
AbsoluteLedRectangle = LedRectangle.Translate(Device.Location);
}
/// <summary> /// <summary>
/// Converts the <see cref="Id"/> and the <see cref="Color"/> of this <see cref="Led"/> to a human-readable string. /// Converts the <see cref="Id"/> and the <see cref="Color"/> of this <see cref="Led"/> to a human-readable string.
/// </summary> /// </summary>
@ -155,7 +263,7 @@ namespace RGB.NET.Core
public override string ToString() => $"{Id} {Color}"; public override string ToString() => $"{Id} {Color}";
/// <summary> /// <summary>
/// Updates the <see cref="LedRectangle"/> to the requested <see cref="Core.Color"/>. /// Updates the <see cref="Led"/> to the requested <see cref="Core.Color"/>.
/// </summary> /// </summary>
internal void Update() internal void Update()
{ {
@ -169,7 +277,7 @@ namespace RGB.NET.Core
} }
/// <summary> /// <summary>
/// Resets the <see cref="LedRectangle"/> back to default. /// Resets the <see cref="Led"/> back to default.
/// </summary> /// </summary>
internal void Reset() internal void Reset()
{ {
@ -195,7 +303,7 @@ namespace RGB.NET.Core
/// Converts a <see cref="Led" /> to a <see cref="Rectangle" />. /// Converts a <see cref="Led" /> to a <see cref="Rectangle" />.
/// </summary> /// </summary>
/// <param name="led">The <see cref="Led"/> to convert.</param> /// <param name="led">The <see cref="Led"/> to convert.</param>
public static implicit operator Rectangle(Led led) => led?.LedRectangle; public static implicit operator Rectangle(Led led) => led?.LedRectangle ?? new Rectangle();
#endregion #endregion
} }

View File

@ -149,6 +149,14 @@ namespace RGB.NET.Core
return new Point(point1.X / point2.X, point1.Y / point2.Y); return new Point(point1.X / point2.X, point1.Y / point2.Y);
} }
/// <summary>
/// Returns a new <see cref="Point"/> representing the multiplication of the <see cref="Point"/> and the provided <see cref="Scale"/>.
/// </summary>
/// <param name="point">The <see cref="Point"/>.</param>
/// <param name="scale">The <see cref="Scale"/>.</param>
/// <returns>A new <see cref="Point"/> representing the multiplication of the <see cref="Point"/> and the provided <see cref="Scale"/>.</returns>
public static Point operator *(Point point, Scale scale) => new Point(point.X * scale.Horizontal, point.Y * scale.Vertical);
#endregion #endregion
} }
} }

View File

@ -8,168 +8,68 @@ using System.Linq;
namespace RGB.NET.Core namespace RGB.NET.Core
{ {
/// <inheritdoc />
/// <summary> /// <summary>
/// Represents a rectangle defined by it's position and it's size. /// Represents a rectangle defined by it's position and it's size.
/// </summary> /// </summary>
[DebuggerDisplay("[Location: {Location}, Size: {Size}]")] [DebuggerDisplay("[Location: {Location}, Size: {Size}]")]
public class Rectangle : AbstractBindable public struct Rectangle
{ {
#region Properties & Fields #region Properties & Fields
private double _x;
/// <summary> /// <summary>
/// Gets or sets the X-position of this <see cref="Rectangle"/>. /// Gets the <see cref="Point"/> representing the top-left corner of the <see cref="Rectangle"/>.
/// </summary> /// </summary>
public double X public Point Location { get; }
{
get => _x;
set
{
if (SetProperty(ref _x, value))
{
OnPropertyChanged(nameof(Location));
OnPropertyChanged(nameof(Center));
}
}
}
private double _y;
/// <summary>
/// Gets or sets the Y-position of this <see cref="Rectangle"/>.
/// </summary>
public double Y
{
get => _y;
set
{
if (SetProperty(ref _y, value))
{
OnPropertyChanged(nameof(Location));
OnPropertyChanged(nameof(Center));
}
}
}
private double _width;
/// <summary>
/// Gets or sets the width of this <see cref="Rectangle"/>.
/// </summary>
public double Width
{
get => _width;
set
{
if (SetProperty(ref _width, Math.Max(0, value)))
{
OnPropertyChanged(nameof(Size));
OnPropertyChanged(nameof(Center));
OnPropertyChanged(nameof(IsEmpty));
}
}
}
private double _height;
/// <summary>
/// Gets or sets the height of this <see cref="Rectangle"/>.
/// </summary>
public double Height
{
get => _height;
set
{
if (SetProperty(ref _height, Math.Max(0, value)))
{
OnPropertyChanged(nameof(Size));
OnPropertyChanged(nameof(Center));
OnPropertyChanged(nameof(IsEmpty));
}
}
}
/// <summary> /// <summary>
/// Gets or sets the <see cref="Point"/> representing the top-left corner of the <see cref="Rectangle"/>. /// Gets the <see cref="Size"/> of the <see cref="Rectangle"/>.
/// </summary> /// </summary>
public Point Location public Size Size { get; }
{
get => new Point(X, Y);
set
{
if (Location != value)
{
_x = value.X;
_y = value.Y;
OnPropertyChanged(nameof(Location));
OnPropertyChanged(nameof(Center));
}
}
}
/// <summary>
/// Gets or sets the <see cref="Size"/> of the <see cref="Rectangle"/>.
/// </summary>
public Size Size
{
get => new Size(Width, Height);
set
{
if (Size != value)
{
_width = value.Width;
_height = value.Height;
OnPropertyChanged(nameof(Size));
OnPropertyChanged(nameof(Center));
OnPropertyChanged(nameof(IsEmpty));
}
}
}
/// <summary> /// <summary>
/// Gets a new <see cref="Point"/> representing the center-point of the <see cref="Rectangle"/>. /// Gets a new <see cref="Point"/> representing the center-point of the <see cref="Rectangle"/>.
/// </summary> /// </summary>
public Point Center => new Point(X + (Width / 2.0), Y + (Height / 2.0)); public Point Center { get; }
/// <summary> /// <summary>
/// Gets a bool indicating if both, the width and the height of the rectangle is greater than zero. /// Gets a bool indicating if both, the width and the height of the rectangle is greater than zero.
/// <c>True</c> if the rectangle has a width or a height of zero; otherwise, <c>false</c>. /// <c>True</c> if the rectangle has a width or a height of zero; otherwise, <c>false</c>.
/// </summary> /// </summary>
public bool IsEmpty => (Width <= DoubleExtensions.TOLERANCE) || (Height <= DoubleExtensions.TOLERANCE); public bool IsEmpty => (Size.Width <= DoubleExtensions.TOLERANCE) || (Size.Height <= DoubleExtensions.TOLERANCE);
#endregion #endregion
#region Constructors #region Constructors
/// <inheritdoc />
/// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class.
/// </summary>
public Rectangle()
: this(new Point(), new Size())
{ }
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class using the provided values for <see cref="P:RGB.NET.Core.Rectangle.Location" /> ans <see cref="P:RGB.NET.Core.Rectangle.Size" />. /// Initializes a new instance of the <see cref="T:RGB.NET.Core.Rectangle" /> class using the provided values for <see cref="P:RGB.NET.Core.Rectangle.Location" /> ans <see cref="P:RGB.NET.Core.Rectangle.Size" />.
/// </summary> /// </summary>
/// <param name="x">The <see cref="P:RGB.NET.Core.Point.X" />-position of this <see cref="T:RGB.NET.Core.Rectangle" />.</param> /// <param name="x">The x-value of the <see cref="T:RGB.NET.Core.Location" /> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
/// <param name="y">The <see cref="P:RGB.NET.Core.Point.Y" />-position of this <see cref="T:RGB.NET.Core.Rectangle" />.</param> /// <param name="y">The y-value of the <see cref="T:RGB.NET.Core.Location" />-position of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
/// <param name="width">The <see cref="P:RGB.NET.Core.Size.Width" /> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param> /// <param name="width">The width of the <see cref="T:RGB.NET.Core.Size"/> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
/// <param name="height">The <see cref="P:RGB.NET.Core.Size.Height" /> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param> /// <param name="height">The height of the <see cref="T:RGB.NET.Core.Size"/> of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
public Rectangle(double x, double y, double width, double height) public Rectangle(double x, double y, double width, double height)
: this(new Point(x, y), new Size(width, height)) : this(new Point(x, y), new Size(width, height))
{ } { }
/// <summary>
/// Initializes a new instance of the <see cref="Rectangle"/> class using the <see cref="Location"/>(0,0) and the given <see cref="Core.Size"/>.
/// </summary>
/// <param name="size">The size of of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
public Rectangle(Size size) : this(new Point(), size)
{ }
/// <summary> /// <summary>
/// Initializes a new instance of the <see cref="Rectangle"/> class using the given <see cref="Point"/> and <see cref="Core.Size"/>. /// Initializes a new instance of the <see cref="Rectangle"/> class using the given <see cref="Point"/> and <see cref="Core.Size"/>.
/// </summary> /// </summary>
/// <param name="location"></param> /// <param name="location">The location of this of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
/// <param name="size"></param> /// <param name="size">The size of of this <see cref="T:RGB.NET.Core.Rectangle" />.</param>
public Rectangle(Point location, Size size) public Rectangle(Point location, Size size)
{ {
this.Location = location; this.Location = location;
this.Size = size; this.Size = size;
Center = new Point(Location.X + (Size.Width / 2.0), Location.Y + (Size.Height / 2.0));
} }
/// <inheritdoc /> /// <inheritdoc />
@ -205,10 +105,10 @@ namespace RGB.NET.Core
posY2 = Math.Max(posY2, rectangle.Location.Y + rectangle.Size.Height); posY2 = Math.Max(posY2, rectangle.Location.Y + rectangle.Size.Height);
} }
if (hasPoint) (Point location, Size size) = hasPoint ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) : InitializeFromPoints(new Point(0, 0), new Point(0, 0));
InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)); Location = location;
else Size = size;
InitializeFromPoints(new Point(0, 0), new Point(0, 0)); Center = new Point(Location.X + (Size.Width / 2.0), Location.Y + (Size.Height / 2.0));
} }
/// <inheritdoc /> /// <inheritdoc />
@ -246,82 +146,27 @@ namespace RGB.NET.Core
posY2 = Math.Max(posY2, point.Y); posY2 = Math.Max(posY2, point.Y);
} }
if (hasPoint) (Point location, Size size) = hasPoint ? InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2)) : InitializeFromPoints(new Point(0, 0), new Point(0, 0));
InitializeFromPoints(new Point(posX, posY), new Point(posX2, posY2));
else Location = location;
InitializeFromPoints(new Point(0, 0), new Point(0, 0)); Size = size;
Center = new Point(Location.X + (Size.Width / 2.0), Location.Y + (Size.Height / 2.0));
} }
#endregion #endregion
#region Methods #region Methods
private void InitializeFromPoints(Point point1, Point point2) private static (Point location, Size size) InitializeFromPoints(Point point1, Point point2)
{ {
double posX = Math.Min(point1.X, point2.X); double posX = Math.Min(point1.X, point2.X);
double posY = Math.Min(point1.Y, point2.Y); double posY = Math.Min(point1.Y, point2.Y);
double width = Math.Max(point1.X, point2.X) - posX; double width = Math.Max(point1.X, point2.X) - posX;
double height = Math.Max(point1.Y, point2.Y) - posY; double height = Math.Max(point1.Y, point2.Y) - posY;
Location = new Point(posX, posY); return (new Point(posX, posY), new Size(width, height));
Size = new Size(width, height);
} }
/// <summary>
/// Calculates the percentage of intersection of a rectangle.
/// </summary>
/// <param name="intersectingRect">The intersecting rectangle.</param>
/// <returns>The percentage of intersection.</returns>
public double CalculateIntersectPercentage(Rectangle intersectingRect)
{
if (IsEmpty || intersectingRect.IsEmpty) return 0;
Rectangle intersection = CalculateIntersection(intersectingRect);
return (intersection.Size.Width * intersection.Size.Height) / (Size.Width * Size.Height);
}
/// <summary>
/// Calculates the <see cref="Rectangle"/> representing the intersection of this <see cref="Rectangle"/> and the one provided as parameter.
/// </summary>
/// <param name="intersectingRectangle">The intersecting <see cref="Rectangle"/></param>
/// <returns>A new <see cref="Rectangle"/> representing the intersection this <see cref="Rectangle"/> and the one provided as parameter.</returns>
public Rectangle CalculateIntersection(Rectangle intersectingRectangle)
{
double x1 = Math.Max(Location.X, intersectingRectangle.Location.X);
double x2 = Math.Min(Location.X + Size.Width, intersectingRectangle.Location.X + intersectingRectangle.Size.Width);
double y1 = Math.Max(Location.Y, intersectingRectangle.Location.Y);
double y2 = Math.Min(Location.Y + Size.Height, intersectingRectangle.Location.Y + intersectingRectangle.Size.Height);
if ((x2 >= x1) && (y2 >= y1))
return new Rectangle(x1, y1, x2 - x1, y2 - y1);
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) => 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) => (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) => (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> /// <summary>
/// Converts the <see cref="Location"/>- and <see cref="Size"/>-position of this <see cref="Rectangle"/> to a human-readable string. /// Converts the <see cref="Location"/>- and <see cref="Size"/>-position of this <see cref="Rectangle"/> to a human-readable string.
/// </summary> /// </summary>
@ -338,9 +183,6 @@ namespace RGB.NET.Core
if (!(obj is Rectangle compareRect)) if (!(obj is Rectangle compareRect))
return false; return false;
if (ReferenceEquals(this, compareRect))
return true;
if (GetType() != compareRect.GetType()) if (GetType() != compareRect.GetType())
return false; return false;
@ -371,7 +213,7 @@ namespace RGB.NET.Core
/// <param name="rectangle1">The first <see cref="Rectangle" /> to compare.</param> /// <param name="rectangle1">The first <see cref="Rectangle" /> to compare.</param>
/// <param name="rectangle2">The second <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> /// <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) => rectangle1?.Equals(rectangle2) ?? ReferenceEquals(rectangle2, null); public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2) => rectangle1.Equals(rectangle2);
/// <summary> /// <summary>
/// Returns a value that indicates whether two specified <see cref="Rectangle" /> are equal. /// Returns a value that indicates whether two specified <see cref="Rectangle" /> are equal.

View File

@ -0,0 +1,162 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System;
using System.Diagnostics;
namespace RGB.NET.Core
{
/// <summary>
/// Represents an angular rotation.
/// </summary>
[DebuggerDisplay("[{Degrees}°]")]
public struct Rotation
{
#region Constants
private const double TWO_PI = Math.PI * 2.0;
private const double RADIANS_DEGREES_CONVERSION = 180.0 / Math.PI;
private const double DEGREES_RADIANS_CONVERSION = Math.PI / 180.0;
#endregion
#region Properties & Fields
/// <summary>
/// Gets the angle in degrees.
/// </summary>
public double Degrees { get; }
/// <summary>
/// Gets the angle in radians.
/// </summary>
public double Radians { get; }
/// <summary>
/// Gets a bool indicating if the rotation is > 0.
/// </summary>
public bool IsRotated => !Degrees.EqualsInTolerance(0);
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Rotation"/> class using the provided values.
/// </summary>
/// <param name="scale">The rotation in degrees.</param>
public Rotation(double degrees)
: this(degrees, degrees * DEGREES_RADIANS_CONVERSION)
{ }
private Rotation(double degrees, double radians)
{
this.Degrees = degrees % 360.0;
this.Radians = radians % TWO_PI;
}
#endregion
#region Methods
/// <summary>
/// Creates a new Rotation out of the given degree-angle.
/// </summary>
/// <param name="degrees">The angle in degrees.</param>
/// <returns>The new rotation.</returns>
public static Rotation FromDegrees(double degrees) => new Rotation(degrees);
/// <summary>
/// Creates a new Rotation out of the given radian-angle.
/// </summary>
/// <param name="degrees">The angle in radians.</param>
/// <returns>The new rotation.</returns>
public static Rotation FromRadians(double radians) => new Rotation(radians * RADIANS_DEGREES_CONVERSION, radians);
/// <summary>
/// Tests whether the specified <see cref="Rotation" /> is equivalent to this <see cref="Rotation" />.
/// </summary>
/// <param name="other">The rotation to test.</param>
/// <returns><c>true</c> if <paramref name="other" /> is equivalent to this <see cref="Rotation" />; otherwise, <c>false</c>.</returns>
public bool Equals(Rotation other) => Degrees.EqualsInTolerance(other.Degrees);
/// <summary>
/// Tests whether the specified object is a <see cref="Rotation" /> and is equivalent to this <see cref="Rotation" />.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Rotation" /> equivalent to this <see cref="Rotation" />; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj) => obj is Rotation other && Equals(other);
/// <summary>
/// Returns a hash code for this <see cref="Rotation" />.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="Rotation" />.</returns>
public override int GetHashCode() => Degrees.GetHashCode();
#endregion
#region Operators
/// <summary>
/// Returns a value that indicates whether two specified <see cref="Rotation" /> are equal.
/// </summary>
/// <param name="rotation1">The first <see cref="Rotation" /> to compare.</param>
/// <param name="rotation2">The second <see cref="Rotation" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="rotation1" /> and <paramref name="rotation2" /> are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(Rotation rotation1, Rotation rotation2) => rotation1.Equals(rotation2);
/// <summary>
/// Returns a value that indicates whether two specified <see cref="Rotation" /> are equal.
/// </summary>
/// <param name="rotation1">The first <see cref="Rotation" /> to compare.</param>
/// <param name="rotation2">The second <see cref="Rotation" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="rotation1" /> and <paramref name="rotation2" /> are not equal; otherwise, <c>false</c>.</returns>
public static bool operator !=(Rotation rotation1, Rotation rotation2) => !(rotation1 == rotation2);
/// <summary>
/// Returns a new <see cref="Rotation"/> representing the addition of the <see cref="Rotation"/> and the provided value.
/// </summary>
/// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <param name="value">The value to add.</param>
/// <returns>A new <see cref="Rotation"/> representing the addition of the <see cref="Rotation"/> and the provided value.</returns>
public static Rotation operator +(Rotation rotation, double value) => new Rotation(rotation.Degrees + value);
/// <summary>
/// Returns a new <see cref="Rotation"/> representing the subtraction of the <see cref="Rotation"/> and the provided value.
/// </summary>
/// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <param name="value">The value to substract.</param>
/// <returns>A new <see cref="Rotation"/> representing the subtraction of the <see cref="Rotation"/> and the provided value.</returns>
public static Rotation operator -(Rotation rotation, double value) => new Rotation(rotation.Degrees - value);
/// <summary>
/// Returns a new <see cref="Rotation"/> representing the multiplication of the <see cref="Rotation"/> and the provided value.
/// </summary>
/// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <param name="value">The value to multiply with.</param>
/// <returns>A new <see cref="Rotation"/> representing the multiplication of the <see cref="Rotation"/> and the provided value.</returns>
public static Rotation operator *(Rotation rotation, double value) => new Rotation(rotation.Degrees * value);
/// <summary>
/// Returns a new <see cref="Rotation"/> representing the division of the <see cref="Rotation"/> and the provided value.
/// </summary>
/// <param name="rotation">The <see cref="Rotation"/>.</param>
/// <param name="value">The value to device with.</param>
/// <returns>A new <see cref="Rotation"/> representing the division of the <see cref="Rotation"/> and the provided value.</returns>
public static Rotation operator /(Rotation rotation, double value) => value.EqualsInTolerance(0) ? new Rotation(0) : new Rotation(rotation.Degrees / value);
/// <summary>
/// Converts a double to a <see cref="Rotation" />.
/// </summary>
/// <param name="rotation">The rotation in degrees to convert.</param>
public static implicit operator Rotation(double rotation) => new Rotation(rotation);
/// <summary>
/// Converts <see cref="Rotation" /> to a double representing the rotation in degrees.
/// </summary>
/// <param name="rotation">The rotatio to convert.</param>
public static implicit operator double(Rotation rotation) => rotation.Degrees;
#endregion
}
}

View File

@ -0,0 +1,144 @@
// ReSharper disable MemberCanBePrivate.Global
// ReSharper disable UnusedMember.Global
using System.Diagnostics;
namespace RGB.NET.Core
{
/// <summary>
/// Represents a scaling.
/// </summary>
[DebuggerDisplay("[Horizontal: {Horizontal}, Vertical: {Vertical}]")]
public struct Scale
{
#region Properties & Fields
/// <summary>
/// Gets the horizontal scaling value.
/// </summary>
public double Horizontal { get; }
/// <summary>
/// Gets the vertical scaling value.
/// </summary>
public double Vertical { get; }
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="Scale"/> class using the provided values.
/// </summary>
/// <param name="scale">The value used for horizontal and vertical scaling. 0 if not set.</param>
public Scale(double scale = 1.0) : this(scale, scale)
{ }
/// <summary>
/// Initializes a new instance of the <see cref="Scale"/> class using the provided values.
/// </summary>
/// <param name="horizontal">The value used for horizontal scaling.</param>
/// <param name="vertical">The value used for vertical scaling.</param>
public Scale(double horizontal, double vertical)
{
this.Horizontal = horizontal;
this.Vertical = vertical;
}
#endregion
#region Methods
/// <summary>
/// Tests whether the specified <see cref="Scale"/> is equivalent to this <see cref="Scale" />.
/// </summary>
/// <param name="other">The scale to test.</param>
/// <returns><c>true</c> if <paramref name="other" /> is equivalent to this <see cref="Scale" />; otherwise, <c>false</c>.</returns>
public bool Equals(Scale other) => Horizontal.EqualsInTolerance(other.Horizontal) && Vertical.EqualsInTolerance(other.Vertical);
/// <summary>
/// Tests whether the specified object is a <see cref="Scale" /> and is equivalent to this <see cref="Scale" />.
/// </summary>
/// <param name="obj">The object to test.</param>
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Scale" /> equivalent to this <see cref="Scale" />; otherwise, <c>false</c>.</returns>
public override bool Equals(object obj) => obj is Scale other && Equals(other);
/// <summary>
/// Returns a hash code for this <see cref="Scale" />.
/// </summary>
/// <returns>An integer value that specifies the hash code for this <see cref="Scale" />.</returns>
public override int GetHashCode() { unchecked { return (Horizontal.GetHashCode() * 397) ^ Vertical.GetHashCode(); } }
/// <summary>
/// Deconstructs the scale into the horizontal and vertical value.
/// </summary>
/// <param name="horizontalScale">The horizontal scaling value.</param>
/// <param name="verticalScale">The vertical scaling value.</param>
public void Deconstruct(out double horizontalScale, out double verticalScale)
{
horizontalScale = Horizontal;
verticalScale = Vertical;
}
#endregion
#region Operators
/// <summary>
/// Returns a value that indicates whether two specified <see cref="Scale" /> are equal.
/// </summary>
/// <param name="scale1">The first <see cref="Scale" /> to compare.</param>
/// <param name="scale2">The second <see cref="Scale" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="scale1" /> and <paramref name="scale2" /> are equal; otherwise, <c>false</c>.</returns>
public static bool operator ==(Scale scale1, Scale scale2) => scale1.Equals(scale2);
/// <summary>
/// Returns a value that indicates whether two specified <see cref="Scale" /> are equal.
/// </summary>
/// <param name="scale1">The first <see cref="Scale" /> to compare.</param>
/// <param name="scale2">The second <see cref="Scale" /> to compare.</param>
/// <returns><c>true</c> if <paramref name="scale1" /> and <paramref name="scale2" /> are not equal; otherwise, <c>false</c>.</returns>
public static bool operator !=(Scale scale1, Scale scale2) => !(scale1 == scale2);
/// <summary>
/// Returns a new <see cref="Scale"/> representing the addition of the <see cref="Scale"/> and the provided value.
/// </summary>
/// <param name="scale">The <see cref="Scale"/>.</param>
/// <param name="value">The value to add.</param>
/// <returns>A new <see cref="Scale"/> representing the addition of the <see cref="Scale"/> and the provided value.</returns>
public static Scale operator +(Scale scale, double value) => new Scale(scale.Horizontal + value, scale.Vertical + value);
/// <summary>
/// Returns a new <see cref="Scale"/> representing the subtraction of the <see cref="Scale"/> and the provided value.
/// </summary>
/// <param name="scale">The <see cref="Scale"/>.</param>
/// <param name="value">The value to substract.</param>
/// <returns>A new <see cref="Scale"/> representing the subtraction of the <see cref="Scale"/> and the provided value.</returns>
public static Scale operator -(Scale scale, double value) => new Scale(scale.Horizontal - value, scale.Vertical - value);
/// <summary>
/// Returns a new <see cref="Scale"/> representing the multiplication of the <see cref="Scale"/> and the provided value.
/// </summary>
/// <param name="scale">The <see cref="Scale"/>.</param>
/// <param name="value">The value to multiply with.</param>
/// <returns>A new <see cref="Scale"/> representing the multiplication of the <see cref="Scale"/> and the provided value.</returns>
public static Scale operator *(Scale scale, double value) => new Scale(scale.Horizontal * value, scale.Vertical * value);
/// <summary>
/// Returns a new <see cref="Scale"/> representing the division of the <see cref="Scale"/> and the provided value.
/// </summary>
/// <param name="scale">The <see cref="Scale"/>.</param>
/// <param name="value">The value to device with.</param>
/// <returns>A new <see cref="Scale"/> representing the division of the <see cref="Scale"/> and the provided value.</returns>
public static Scale operator /(Scale scale, double value) => value.EqualsInTolerance(0) ? new Scale(0) : new Scale(scale.Horizontal / value, scale.Vertical / value);
/// <summary>
/// Converts a double to a <see cref="Scale" />.
/// </summary>
/// <param name="scale">The scale value to convert.</param>
public static implicit operator Scale(double scale) => new Scale(scale);
#endregion
}
}

View File

@ -94,6 +94,17 @@ namespace RGB.NET.Core
} }
} }
/// <summary>
/// Deconstructs the size into the width and height value.
/// </summary>
/// <param name="width">The width.</param>
/// <param name="height">The height.</param>
public void Deconstruct(out double width, out double height)
{
width = Width;
height = Height;
}
#endregion #endregion
#region Operators #region Operators
@ -172,6 +183,14 @@ namespace RGB.NET.Core
/// <returns>A new <see cref="Size"/> representing the division of the <see cref="Size"/> and the provided factor.</returns> /// <returns>A new <see cref="Size"/> representing the division of the <see cref="Size"/> and the provided factor.</returns>
public static Size operator /(Size size, double factor) => factor.EqualsInTolerance(0) ? Invalid : new Size(size.Width / factor, size.Height / factor); public static Size operator /(Size size, double factor) => factor.EqualsInTolerance(0) ? Invalid : new Size(size.Width / factor, size.Height / factor);
/// <summary>
/// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>.
/// </summary>
/// <param name="size">The <see cref="Size"/> to scale.</param>
/// <param name="scale">The scaling factor.</param>
/// <returns>A new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the given <see cref="Scale"/>.</returns>
public static Size operator *(Size size, Scale scale) => new Size(size.Width * scale.Horizontal, size.Height * scale.Vertical);
#endregion #endregion
} }
} }

View File

@ -33,8 +33,6 @@ namespace RGB.NET.Core
private readonly LinkedList<ILedGroup> _ledGroups = new LinkedList<ILedGroup>(); private readonly LinkedList<ILedGroup> _ledGroups = new LinkedList<ILedGroup>();
private readonly Rectangle _surfaceRectangle = new Rectangle();
// ReSharper restore InconsistentNaming // ReSharper restore InconsistentNaming
/// <summary> /// <summary>
@ -50,7 +48,7 @@ namespace RGB.NET.Core
/// <summary> /// <summary>
/// Gets a copy of the <see cref="Rectangle"/> representing this <see cref="RGBSurface"/>. /// Gets a copy of the <see cref="Rectangle"/> representing this <see cref="RGBSurface"/>.
/// </summary> /// </summary>
public Rectangle SurfaceRectangle => new Rectangle(_surfaceRectangle); public Rectangle SurfaceRectangle { get; private set; }
/// <summary> /// <summary>
/// Gets a list of all <see cref="Led"/> on this <see cref="RGBSurface"/>. /// Gets a list of all <see cref="Led"/> on this <see cref="RGBSurface"/>.
@ -162,12 +160,11 @@ namespace RGB.NET.Core
case BrushCalculationMode.Relative: case BrushCalculationMode.Relative:
Rectangle brushRectangle = new Rectangle(leds.Select(led => led.AbsoluteLedRectangle)); Rectangle brushRectangle = new Rectangle(leds.Select(led => led.AbsoluteLedRectangle));
Point offset = new Point(-brushRectangle.Location.X, -brushRectangle.Location.Y); Point offset = new Point(-brushRectangle.Location.X, -brushRectangle.Location.Y);
brushRectangle.Location = new Point(0, 0); brushRectangle = brushRectangle.SetLocation(new Point(0, 0));
brush.PerformRender(brushRectangle, brush.PerformRender(brushRectangle, leds.Select(led => new BrushRenderTarget(led, led.AbsoluteLedRectangle.Translate(offset))));
leds.Select(x => new BrushRenderTarget(x, GetDeviceLedLocation(x, offset))));
break; break;
case BrushCalculationMode.Absolute: case BrushCalculationMode.Absolute:
brush.PerformRender(SurfaceRectangle, leds.Select(x => new BrushRenderTarget(x, x.AbsoluteLedRectangle))); brush.PerformRender(SurfaceRectangle, leds.Select(led => new BrushRenderTarget(led, led.AbsoluteLedRectangle)));
break; break;
default: default:
throw new ArgumentException(); throw new ArgumentException();
@ -180,12 +177,6 @@ namespace RGB.NET.Core
renders.Key.Led.Color = renders.Value; renders.Key.Led.Color = renders.Value;
} }
private Rectangle GetDeviceLedLocation(Led led, Point extraOffset)
{
Rectangle absoluteRectangle = led.AbsoluteLedRectangle;
return (absoluteRectangle.Location + extraOffset) + absoluteRectangle.Size;
}
/// <summary> /// <summary>
/// Attaches the given <see cref="ILedGroup"/>. /// Attaches the given <see cref="ILedGroup"/>.
/// </summary> /// </summary>
@ -229,10 +220,8 @@ namespace RGB.NET.Core
private void UpdateSurfaceRectangle() private void UpdateSurfaceRectangle()
{ {
Rectangle devicesRectangle = new Rectangle(_devices.Select(d => new Rectangle(d.Location, d.Size))); Rectangle devicesRectangle = new Rectangle(_devices.Select(d => d.DeviceRectangle));
SurfaceRectangle = SurfaceRectangle.SetSize(new Size(devicesRectangle.Location.X + devicesRectangle.Size.Width, devicesRectangle.Location.Y + devicesRectangle.Size.Height));
_surfaceRectangle.Width = devicesRectangle.Location.X + devicesRectangle.Size.Width;
_surfaceRectangle.Height = devicesRectangle.Location.Y + devicesRectangle.Size.Height;
} }
/// <summary> /// <summary>

View File

@ -63,7 +63,7 @@ namespace RGB.NET.Core
foreach (IRGBDevice device in Devices) foreach (IRGBDevice device in Devices)
{ {
device.Location += new Point(posX, 0); device.Location += new Point(posX, 0);
posX += device.Size.Width + 1; posX += device.ActualSize.Width + 1;
} }
} }

View File

@ -53,12 +53,12 @@ namespace RGB.NET.Core
} }
} }
private AutoResetEvent _hasDataEvent = new AutoResetEvent(false); protected AutoResetEvent HasDataEvent = new AutoResetEvent(false);
private bool _isRunning; protected bool IsRunning;
private Task _updateTask; protected Task UpdateTask;
private CancellationTokenSource _updateTokenSource; protected CancellationTokenSource UpdateTokenSource;
private CancellationToken _updateToken; protected CancellationToken UpdateToken;
#endregion #endregion
@ -88,13 +88,13 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
public void Start() public void Start()
{ {
if (_isRunning) return; if (IsRunning) return;
_isRunning = true; IsRunning = true;
_updateTokenSource?.Dispose(); UpdateTokenSource?.Dispose();
_updateTokenSource = new CancellationTokenSource(); UpdateTokenSource = new CancellationTokenSource();
_updateTask = Task.Factory.StartNew(UpdateLoop, (_updateToken = _updateTokenSource.Token), TaskCreationOptions.LongRunning, TaskScheduler.Default); UpdateTask = Task.Factory.StartNew(UpdateLoop, (UpdateToken = UpdateTokenSource.Token), TaskCreationOptions.LongRunning, TaskScheduler.Default);
} }
/// <summary> /// <summary>
@ -102,22 +102,22 @@ namespace RGB.NET.Core
/// </summary> /// </summary>
public async void Stop() public async void Stop()
{ {
if (!_isRunning) return; if (!IsRunning) return;
_isRunning = false; IsRunning = false;
_updateTokenSource.Cancel(); UpdateTokenSource.Cancel();
await _updateTask; await UpdateTask;
_updateTask.Dispose(); UpdateTask.Dispose();
_updateTask = null; UpdateTask = null;
} }
private void UpdateLoop() protected virtual void UpdateLoop()
{ {
OnStartup(); OnStartup();
while (!_updateToken.IsCancellationRequested) while (!UpdateToken.IsCancellationRequested)
{ {
if (_hasDataEvent.WaitOne(Timeout)) if (HasDataEvent.WaitOne(Timeout))
{ {
long preUpdateTicks = Stopwatch.GetTimestamp(); long preUpdateTicks = Stopwatch.GetTimestamp();
@ -135,7 +135,7 @@ namespace RGB.NET.Core
} }
/// <inheritdoc /> /// <inheritdoc />
public void TriggerHasData() => _hasDataEvent.Set(); public void TriggerHasData() => HasDataEvent.Set();
private void UpdateUpdateFrequency() private void UpdateUpdateFrequency()
{ {

View File

@ -33,7 +33,7 @@ namespace RGB.NET.Devices.Asus
//TODO DarthAffe 21.10.2017: We don't know the model, how to save layouts and images? //TODO DarthAffe 21.10.2017: We don't know the model, how to save layouts and images?
//TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images?
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Drams\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Asus\Drams", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -32,7 +32,7 @@ namespace RGB.NET.Devices.Asus
InitializeLed(LedId.GraphicsCard1 + i, new Rectangle(i * 10, 0, 10, 10)); InitializeLed(LedId.GraphicsCard1 + i, new Rectangle(i * 10, 0, 10, 10));
//TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images?
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\GraphicsCards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Asus\GraphicsCards", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -32,7 +32,7 @@ namespace RGB.NET.Devices.Asus
InitializeLed(LedId.Headset1 + i, new Rectangle(i * 40, 0, 40, 8)); InitializeLed(LedId.Headset1 + i, new Rectangle(i * 40, 0, 40, 8));
//TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images?
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Headsets\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Asus\Headsets", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -32,12 +32,12 @@ namespace RGB.NET.Devices.Asus
InitializeLed(LedId.Keyboard_Escape + i, new Rectangle(i * 19, 0, 19, 19)); InitializeLed(LedId.Keyboard_Escape + i, new Rectangle(i * 19, 0, 19, 19));
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Keyboards\{model}\{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"), DeviceInfo.LogicalLayout.ToString()); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\Asus\Keyboards\{model}", $"{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"), DeviceInfo.LogicalLayout.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />
protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keyboard_Escape; protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keyboard_Escape;
#endregion #endregion
} }
} }

View File

@ -32,7 +32,7 @@ namespace RGB.NET.Devices.Asus
InitializeLed(LedId.Mainboard1 + i, new Rectangle(i * 40, 0, 40, 8)); InitializeLed(LedId.Mainboard1 + i, new Rectangle(i * 40, 0, 40, 8));
//TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images?
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Asus\Mainboards", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -31,7 +31,7 @@ namespace RGB.NET.Devices.Asus
for (int i = 0; i < ledCount; i++) for (int i = 0; i < ledCount; i++)
InitializeLed(LedId.Mouse1 + i, new Rectangle(i * 10, 0, 10, 10)); InitializeLed(LedId.Mouse1 + i, new Rectangle(i * 10, 0, 10, 10));
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Mouses\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Asus\Mouses", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -34,7 +34,7 @@ namespace RGB.NET.Devices.Asus
InitializeLed(LedId.GraphicsCard1 + i, new Rectangle(i * 10, 0, 10, 10)); InitializeLed(LedId.GraphicsCard1 + i, new Rectangle(i * 10, 0, 10, 10));
//TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images?
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\GraphicsCards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Asus\GraphicsCards", $"{ DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -34,12 +34,12 @@ namespace RGB.NET.Devices.Asus
InitializeLed(LedId.Keyboard_Escape + i, new Rectangle(i * 19, 0, 19, 19)); InitializeLed(LedId.Keyboard_Escape + i, new Rectangle(i * 19, 0, 19, 19));
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Keyboards\{model}\{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"), DeviceInfo.LogicalLayout.ToString()); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\Asus\Keyboards\{model}", $"{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"), DeviceInfo.LogicalLayout.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />
protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keyboard_Escape; protected override object CreateLedCustomData(LedId ledId) => (int)ledId - (int)LedId.Keyboard_Escape;
/// <inheritdoc /> /// <inheritdoc />
protected override Action<IntPtr, byte[]> GetUpdateColorAction() => _AsusSDK.SetClaymoreKeyboardColor; protected override Action<IntPtr, byte[]> GetUpdateColorAction() => _AsusSDK.SetClaymoreKeyboardColor;

View File

@ -34,7 +34,7 @@ namespace RGB.NET.Devices.Asus
InitializeLed(LedId.Mainboard1 + i, new Rectangle(i * 40, 0, 40, 8)); InitializeLed(LedId.Mainboard1 + i, new Rectangle(i * 40, 0, 40, 8));
//TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images? //TODO DarthAffe 07.10.2017: We don't know the model, how to save layouts and images?
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Mainboards\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Asus\Mainboards", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -33,7 +33,7 @@ namespace RGB.NET.Devices.Asus
for (int i = 0; i < ledCount; i++) for (int i = 0; i < ledCount; i++)
InitializeLed(LedId.Mouse1 + i, new Rectangle(i * 10, 0, 10, 10)); InitializeLed(LedId.Mouse1 + i, new Rectangle(i * 10, 0, 10, 10));
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Asus\Mouses\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Asus\Mouses", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -33,8 +33,8 @@ namespace RGB.NET.Devices.CoolerMaster
InitializeLed(led.Key, new Rectangle(led.Value.column * 19, led.Value.row * 19, 19, 19)); InitializeLed(led.Key, new Rectangle(led.Value.column * 19, led.Value.row * 19, 19, 19));
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath( ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\CoolerMaster\Keyboards\{model}", $"{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"),
$@"Layouts\CoolerMaster\Keyboards\{model}\{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"), DeviceInfo.LogicalLayout.ToString()); DeviceInfo.LogicalLayout.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -23,7 +23,7 @@ namespace RGB.NET.Devices.CoolerMaster
#endregion #endregion
#region Methods #region Methods
/// <inheritdoc /> /// <inheritdoc />
protected override void InitializeLayout() protected override void InitializeLayout()
{ {
@ -33,7 +33,7 @@ namespace RGB.NET.Devices.CoolerMaster
InitializeLed(led.Key, new Rectangle(led.Value.column * 19, led.Value.row * 19, 19, 19)); InitializeLed(led.Key, new Rectangle(led.Value.column * 19, led.Value.row * 19, 19, 19));
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\CoolerMaster\Mice\{model}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\CoolerMaster\Mice", $"{model}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -46,7 +46,7 @@ namespace RGB.NET.Devices.Corsair
} }
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Customs\{model}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Corsair\Customs", $"{model}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -32,7 +32,7 @@ namespace RGB.NET.Devices.Corsair
InitializeLed(LedId.Headset1, new Rectangle(0, 0, 10, 10)); InitializeLed(LedId.Headset1, new Rectangle(0, 0, 10, 10));
InitializeLed(LedId.Headset2, new Rectangle(10, 0, 10, 10)); InitializeLed(LedId.Headset2, new Rectangle(10, 0, 10, 10));
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Headsets\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Corsair\Headsets", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -51,9 +51,9 @@ namespace RGB.NET.Devices.Corsair
foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.LedId)) foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.LedId))
InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, ledPosition.ToRectangle()); InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, ledPosition.ToRectangle());
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\HeadsetStands\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Corsair\HeadsetStands", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />
protected override object CreateLedCustomData(LedId ledId) => HeadsetStandIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid; protected override object CreateLedCustomData(LedId ledId) => HeadsetStandIdMapping.DEFAULT.TryGetValue(ledId, out CorsairLedId id) ? id : CorsairLedId.Invalid;

View File

@ -48,8 +48,8 @@ namespace RGB.NET.Devices.Corsair
} }
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath( ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, $@"Layouts\Corsair\Keyboards\{model}", $"{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"),
$@"Layouts\Corsair\Keyboards\{model}\{DeviceInfo.PhysicalLayout.ToString().ToUpper()}.xml"), DeviceInfo.LogicalLayout.ToString()); DeviceInfo.LogicalLayout.ToString());
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -48,7 +48,7 @@ namespace RGB.NET.Devices.Corsair
} }
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Memory\{model}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Corsair\Memory", $"{model}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -54,7 +54,7 @@ namespace RGB.NET.Devices.Corsair
throw new RGBDeviceException($"Can't initialize mouse with layout '{DeviceInfo.PhysicalLayout}'"); throw new RGBDeviceException($"Can't initialize mouse with layout '{DeviceInfo.PhysicalLayout}'");
} }
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Mice\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Corsair\Mice", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -51,7 +51,7 @@ namespace RGB.NET.Devices.Corsair
foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.LedId)) foreach (_CorsairLedPosition ledPosition in positions.OrderBy(p => p.LedId))
InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, ledPosition.ToRectangle()); InitializeLed(mapping.TryGetValue(ledPosition.LedId, out LedId ledId) ? ledId : LedId.Invalid, ledPosition.ToRectangle());
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Corsair\Mousepads\{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Corsair\Mousepads", $"{DeviceInfo.Model.Replace(" ", string.Empty).ToUpper()}.xml"), null);
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -67,7 +67,7 @@ namespace RGB.NET.Devices.Logitech
string layout = info.ImageLayout; string layout = info.ImageLayout;
string layoutPath = info.LayoutPath; string layoutPath = info.LayoutPath;
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Logitech\{layoutPath}.xml"), layout, true); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Logitech", $"{layoutPath}.xml"), layout, true);
} }
#endregion #endregion

View File

@ -30,6 +30,7 @@ namespace RGB.NET.Devices.Logitech.HID
("G19", RGBDeviceType.Keyboard, 0xC228, 0, "DE", @"Keyboards\G19\UK"), ("G19", RGBDeviceType.Keyboard, 0xC228, 0, "DE", @"Keyboards\G19\UK"),
("G19s", RGBDeviceType.Keyboard, 0xC229, 0, "DE", @"Keyboards\G19s\UK"), ("G19s", RGBDeviceType.Keyboard, 0xC229, 0, "DE", @"Keyboards\G19s\UK"),
("G502", RGBDeviceType.Mouse, 0xC332, 0, "default", @"Mice\G502"), ("G502", RGBDeviceType.Mouse, 0xC332, 0, "default", @"Mice\G502"),
("G502 HERO", RGBDeviceType.Mouse, 0xC08B, 0, "default", @"Mice\G502"),
("G600", RGBDeviceType.Mouse, 0xC24A, 0, "default", @"Mice\G600"), ("G600", RGBDeviceType.Mouse, 0xC24A, 0, "default", @"Mice\G600"),
("G300s", RGBDeviceType.Mouse, 0xC246, 0, "default", @"Mice\G300s"), ("G300s", RGBDeviceType.Mouse, 0xC246, 0, "default", @"Mice\G300s"),
("G510", RGBDeviceType.Keyboard, 0xC22D, 0, "DE", @"Keyboards\G510\UK"), ("G510", RGBDeviceType.Keyboard, 0xC22D, 0, "DE", @"Keyboards\G510\UK"),

View File

@ -114,7 +114,7 @@ namespace RGB.NET.Devices.Logitech
try try
{ {
if (DeviceChecker.IsPerDeviceDeviceConnected) if (DeviceChecker.IsPerKeyDeviceConnected)
{ {
(string model, RGBDeviceType deviceType, int _, int _, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData; (string model, RGBDeviceType deviceType, int _, int _, string imageLayout, string layoutPath) = DeviceChecker.PerKeyDeviceData;
if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter if (loadFilter.HasFlag(deviceType)) //TODO DarthAffe 07.12.2017: Check if it's worth to try another device if the one returned doesn't match the filter

View File

@ -47,7 +47,7 @@ namespace RGB.NET.Devices.Novation
} }
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Novation\Launchpads\{model.ToUpper()}.xml"), "Default"); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Novation\Launchpads", $"{model.ToUpper()}.xml"), "Default");
} }
/// <inheritdoc /> /// <inheritdoc />

View File

@ -31,7 +31,7 @@ namespace RGB.NET.Devices.Razer
protected override void InitializeLayout() protected override void InitializeLayout()
{ {
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Razer\ChromaLink\{model}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Razer\ChromaLink", $"{model}.xml"), null);
if (LedMapping.Count == 0) if (LedMapping.Count == 0)
for (int i = 0; i < _Defines.CHROMALINK_MAX_LEDS; i++) for (int i = 0; i < _Defines.CHROMALINK_MAX_LEDS; i++)

View File

@ -31,7 +31,7 @@ namespace RGB.NET.Devices.Razer
protected override void InitializeLayout() protected override void InitializeLayout()
{ {
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Razer\Headset\{model}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Razer\Headset", $"{model}.xml"), null);
if (LedMapping.Count == 0) if (LedMapping.Count == 0)
for (int i = 0; i < _Defines.HEADSET_MAX_LEDS; i++) for (int i = 0; i < _Defines.HEADSET_MAX_LEDS; i++)

View File

@ -31,7 +31,7 @@ namespace RGB.NET.Devices.Razer
protected override void InitializeLayout() protected override void InitializeLayout()
{ {
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Razer\Keypad\{model}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Razer\Keypad", $"{model}.xml"), null);
if (LedMapping.Count == 0) if (LedMapping.Count == 0)
{ {

View File

@ -31,7 +31,7 @@ namespace RGB.NET.Devices.Razer
protected override void InitializeLayout() protected override void InitializeLayout()
{ {
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Razer\Mice\{model}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Razer\Mice", $"{model}.xml"), null);
if (LedMapping.Count == 0) if (LedMapping.Count == 0)
{ {

View File

@ -31,7 +31,7 @@ namespace RGB.NET.Devices.Razer
protected override void InitializeLayout() protected override void InitializeLayout()
{ {
string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper(); string model = DeviceInfo.Model.Replace(" ", string.Empty).ToUpper();
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\Razer\Mousepad\{model}.xml"), null); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\Razer\Mousepad", $"{model}.xml"), null);
if (LedMapping.Count == 0) if (LedMapping.Count == 0)
for (int i = 0; i < _Defines.MOUSEPAD_MAX_LEDS; i++) for (int i = 0; i < _Defines.MOUSEPAD_MAX_LEDS; i++)

View File

@ -27,6 +27,18 @@
SevenZone, SevenZone,
[APIName("rgb-8-zone")] [APIName("rgb-8-zone")]
EightZone EightZone,
[APIName("rgb-12-zone")]
TwelveZone,
[APIName("rgb-17-zone")]
SeventeenZone,
[APIName("rgb-24-zone")]
TwentyfourZone,
[APIName("rgb-103-zone")]
OneHundredAndThreeZone
} }
} }

View File

@ -22,6 +22,192 @@
ZoneNine, ZoneNine,
[APIName("ten")] [APIName("ten")]
ZoneTen, ZoneTen,
[APIName("eleven")]
ZoneEleven,
[APIName("twelve")]
ZoneTwelve,
[APIName("thirteen")]
ZoneThirteen,
[APIName("fourteen")]
ZoneFourteen,
[APIName("fifteen")]
ZoneFifteen,
[APIName("sixteen")]
ZoneSixteen,
[APIName("seventeen")]
ZoneSeventeen,
[APIName("eighteen")]
ZoneEighteen,
[APIName("nineteen")]
ZoneNineteen,
[APIName("twenty")]
ZoneTwenty,
[APIName("twenty-one")]
ZoneTwentyOne,
[APIName("twenty-two")]
ZoneTwentyTwo,
[APIName("twenty-three")]
ZoneTwentyThree,
[APIName("twenty-four")]
ZoneTwentyFour,
[APIName("twenty-five")]
ZoneTwentyFive,
[APIName("twenty-six")]
ZoneTwentySix,
[APIName("twenty-seven")]
ZoneTwentySeven,
[APIName("twenty-eight")]
ZoneTwentyEight,
[APIName("twenty-nine")]
ZoneTwentyNine,
[APIName("thirty")]
ZoneThirty,
[APIName("thirty-one")]
ZoneThirtyOne,
[APIName("thirty-two")]
ZoneThirtyTwo,
[APIName("thirty-three")]
ZoneThirtyThree,
[APIName("thirty-four")]
ZoneThirtyFour,
[APIName("thirty-five")]
ZoneThirtyFive,
[APIName("thirty-six")]
ZoneThirtySix,
[APIName("thirty-seven")]
ZoneThirtySeven,
[APIName("thirty-eight")]
ZoneThirtyEight,
[APIName("thirty-nine")]
ZoneThirtyNine,
[APIName("forty")]
ZoneForty,
[APIName("forty-one")]
ZoneFortyOne,
[APIName("forty-two")]
ZoneFortyTwo,
[APIName("forty-three")]
ZoneFortyThree,
[APIName("forty-four")]
ZoneFortyFour,
[APIName("forty-five")]
ZoneFortyFive,
[APIName("forty-six")]
ZoneFortySix,
[APIName("forty-seven")]
ZoneFortySeven,
[APIName("forty-eight")]
ZoneFortyEight,
[APIName("forty-nine")]
ZoneFortyNine,
[APIName("fifty")]
ZoneFifty,
[APIName("fifty-one")]
ZoneFiftyOne,
[APIName("fifty-two")]
ZoneFiftyTwo,
[APIName("fifty-three")]
ZoneFiftyThree,
[APIName("fifty-four")]
ZoneFiftyFour,
[APIName("fifty-five")]
ZoneFiftyFive,
[APIName("fifty-six")]
ZoneFiftySix,
[APIName("fifty-seven")]
ZoneFiftySeven,
[APIName("fifty-eight")]
ZoneFiftyEight,
[APIName("fifty-nine")]
ZoneFiftyNine,
[APIName("sixty")]
ZoneSixty,
[APIName("sixty-one")]
ZoneSixtyOne,
[APIName("sixty-two")]
ZoneSixtyTwo,
[APIName("sixty-three")]
ZoneSixtyThree,
[APIName("sixty-four")]
ZoneSixtyFour,
[APIName("sixty-five")]
ZoneSixtyFive,
[APIName("sixty-six")]
ZoneSixtySix,
[APIName("sixty-seven")]
ZoneSixtySeven,
[APIName("sixty-eight")]
ZoneSixtyEight,
[APIName("sixty-nine")]
ZoneSixtyNine,
[APIName("seventy")]
ZoneSeventy,
[APIName("seventy-one")]
ZoneSeventyOne,
[APIName("seventy-two")]
ZoneSeventyTwo,
[APIName("seventy-three")]
ZoneSeventyThree,
[APIName("seventy-four")]
ZoneSeventyFour,
[APIName("seventy-five")]
ZoneSeventyFive,
[APIName("seventy-six")]
ZoneSeventySix,
[APIName("seventy-seven")]
ZoneSeventySeven,
[APIName("seventy-eight")]
ZoneSeventyEight,
[APIName("seventy-nine")]
ZoneSeventyNine,
[APIName("eighty")]
ZoneEighty,
[APIName("eighty-one")]
ZoneEightyOne,
[APIName("eighty-two")]
ZoneEightyTwo,
[APIName("eighty-three")]
ZoneEightyThree,
[APIName("eighty-four")]
ZoneEightyFour,
[APIName("eighty-five")]
ZoneEightyFive,
[APIName("eighty-six")]
ZoneEightySix,
[APIName("eighty-seven")]
ZoneEightySeven,
[APIName("eighty-eight")]
ZoneEightyEight,
[APIName("eighty-nine")]
ZoneEightyNine,
[APIName("ninety")]
ZoneNinety,
[APIName("ninety-one")]
ZoneNinetyOne,
[APIName("ninety-two")]
ZoneNinetyTwo,
[APIName("ninety-three")]
ZoneNinetyThree,
[APIName("ninety-four")]
ZoneNinetyFour,
[APIName("ninety-five")]
ZoneNinetyFive,
[APIName("ninety-six")]
ZoneNinetySix,
[APIName("ninety-seven")]
ZoneNinetySeven,
[APIName("ninety-eight")]
ZoneNinetyEight,
[APIName("ninety-nine")]
ZoneNinetyNine,
[APIName("one-hundred")]
ZoneOneHundred,
[APIName("one-hundred-one")]
ZoneOneHundredOne,
[APIName("one-hundred-two")]
ZoneOneHundredTwo,
[APIName("one-hundred-three")]
ZoneOneHundredThree,
[APIName("logo")] [APIName("logo")]
Logo, Logo,

View File

@ -15,6 +15,7 @@ namespace RGB.NET.Devices.SteelSeries
#region Properties & Fields #region Properties & Fields
private string _deviceType; private string _deviceType;
private Dictionary<object, Color> _lastDataSet;
#endregion #endregion
@ -35,9 +36,21 @@ namespace RGB.NET.Devices.SteelSeries
#region Methods #region Methods
protected override void OnUpdate(object sender, CustomUpdateData customData)
{
if ((customData != null) && (customData["refresh"] as bool? ?? false))
{
if ((_lastDataSet != null) && (_lastDataSet.Count != 0))
Update(_lastDataSet);
}
else
base.OnUpdate(sender, customData);
}
/// <inheritdoc /> /// <inheritdoc />
protected override void Update(Dictionary<object, Color> dataSet) protected override void Update(Dictionary<object, Color> dataSet)
{ {
_lastDataSet = dataSet;
SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToDictionary(x => ((SteelSeriesLedId)x.Key).GetAPIName(), x => x.Value.ToIntArray())); SteelSeriesSDK.UpdateLeds(_deviceType, dataSet.ToDictionary(x => ((SteelSeriesLedId)x.Key).GetAPIName(), x => x.Value.ToIntArray()));
} }

View File

@ -0,0 +1,82 @@
// ReSharper disable MemberCanBePrivate.Global
using System;
using System.Diagnostics;
using System.Threading;
using RGB.NET.Core;
namespace RGB.NET.Devices.SteelSeries
{
/// <summary>
/// Represents an update-trigger used to update SteelSeries devices
/// </summary>
public class SteelSeriesDeviceUpdateTrigger : DeviceUpdateTrigger
{
#region Constants
private const long FLUSH_TIMER = 5 * 1000 * TimeSpan.TicksPerMillisecond; // flush the device every 5 seconds to prevent timeouts
#endregion
#region Properties & Fields
private long _lastUpdateTimestamp;
#endregion
#region Constructors
/// <summary>
/// Initializes a new instance of the <see cref="SteelSeriesDeviceUpdateTrigger"/> class.
/// </summary>
public SteelSeriesDeviceUpdateTrigger()
{ }
/// <summary>
/// Initializes a new instance of the <see cref="SteelSeriesDeviceUpdateTrigger"/> class.
/// </summary>
/// <param name="updateRateHardLimit">The hard limit of the update rate of this trigger.</param>
public SteelSeriesDeviceUpdateTrigger(double updateRateHardLimit)
: base(updateRateHardLimit)
{ }
#endregion
#region Methods
/// <inheritdoc />
protected override void UpdateLoop()
{
OnStartup();
while (!UpdateToken.IsCancellationRequested)
{
if (HasDataEvent.WaitOne(Timeout))
{
long preUpdateTicks = Stopwatch.GetTimestamp();
OnUpdate();
if (UpdateFrequency > 0)
{
double lastUpdateTime = ((_lastUpdateTimestamp - preUpdateTicks) / (double)TimeSpan.TicksPerMillisecond);
int sleep = (int)((UpdateFrequency * 1000.0) - lastUpdateTime);
if (sleep > 0)
Thread.Sleep(sleep);
}
}
else if ((_lastUpdateTimestamp > 0) && ((Stopwatch.GetTimestamp() - _lastUpdateTimestamp) > FLUSH_TIMER))
OnUpdate(new CustomUpdateData(("refresh", true)));
}
}
/// <inheritdoc />
protected override void OnUpdate(CustomUpdateData updateData = null)
{
base.OnUpdate(updateData);
_lastUpdateTimestamp = Stopwatch.GetTimestamp();
}
#endregion
}
}

View File

@ -80,7 +80,7 @@ namespace RGB.NET.Devices.SteelSeries
string layout = info.ImageLayout; string layout = info.ImageLayout;
string layoutPath = info.LayoutPath; string layoutPath = info.LayoutPath;
ApplyLayoutFromFile(PathHelper.GetAbsolutePath($@"Layouts\SteelSeries\{layoutPath}.xml"), layout, true); ApplyLayoutFromFile(PathHelper.GetAbsolutePath(this, @"Layouts\SteelSeries", $"{layoutPath}.xml"), layout, true);
} }
#endregion #endregion

View File

@ -37,9 +37,9 @@ namespace RGB.NET.Devices.SteelSeries
public IEnumerable<IRGBDevice> Devices { get; private set; } public IEnumerable<IRGBDevice> Devices { get; private set; }
/// <summary> /// <summary>
/// The <see cref="DeviceUpdateTrigger"/> used to trigger the updates for SteelSeries devices. /// The <see cref="SteelSeriesDeviceUpdateTrigger"/> used to trigger the updates for SteelSeries devices.
/// </summary> /// </summary>
public DeviceUpdateTrigger UpdateTrigger { get; } public SteelSeriesDeviceUpdateTrigger UpdateTrigger { get; }
#endregion #endregion
@ -54,7 +54,7 @@ namespace RGB.NET.Devices.SteelSeries
if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}"); if (_instance != null) throw new InvalidOperationException($"There can be only one instance of type {nameof(SteelSeriesDeviceProvider)}");
_instance = this; _instance = this;
UpdateTrigger = new DeviceUpdateTrigger(); UpdateTrigger = new SteelSeriesDeviceUpdateTrigger();
} }
#endregion #endregion

View File

@ -2,7 +2,6 @@
// ReSharper disable AutoPropertyCanBeMadeGetOnly.Global // ReSharper disable AutoPropertyCanBeMadeGetOnly.Global
// ReSharper disable UnusedMember.Global // ReSharper disable UnusedMember.Global
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using RGB.NET.Core; using RGB.NET.Core;
@ -28,17 +27,8 @@ namespace RGB.NET.Groups
get => _rectangle; get => _rectangle;
set set
{ {
Rectangle oldValue = _rectangle;
if (SetProperty(ref _rectangle, value)) if (SetProperty(ref _rectangle, value))
{
if (oldValue != null)
oldValue.PropertyChanged -= RectangleChanged;
if (_rectangle != null)
_rectangle.PropertyChanged += RectangleChanged;
InvalidateCache(); InvalidateCache();
}
} }
} }
@ -110,14 +100,12 @@ namespace RGB.NET.Groups
private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args) => InvalidateCache(); private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args) => InvalidateCache();
private void RectangleChanged(object sender, EventArgs eventArgs) => InvalidateCache();
/// <inheritdoc /> /// <inheritdoc />
/// <summary> /// <summary>
/// Gets a list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />. /// Gets a list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.
/// </summary> /// </summary>
/// <returns>The list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.</returns> /// <returns>The list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.</returns>
public override IEnumerable<Led> GetLeds() => _ledCache ?? (_ledCache = RGBSurface.Instance.Leds.Where(x => x.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList()); public override IEnumerable<Led> GetLeds() => _ledCache ??= RGBSurface.Instance.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList();
private void InvalidateCache() => _ledCache = null; private void InvalidateCache() => _ledCache = null;