mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Changed Point and Size to be an immutable value-types
This commit is contained in:
parent
302ff7743f
commit
1865b4d83e
@ -24,30 +24,20 @@ namespace RGB.NET.Core
|
||||
/// <inheritdoc />
|
||||
IRGBDeviceInfo IRGBDevice.DeviceInfo => DeviceInfo;
|
||||
|
||||
private Size _size = Size.Invalid;
|
||||
/// <inheritdoc />
|
||||
public Size Size => new Size(InternalSize?.Width ?? 0, InternalSize?.Height ?? 0);
|
||||
|
||||
private Size _internalSize;
|
||||
/// <summary>
|
||||
/// Gets the <see cref="Size"/> of the whole <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
protected Size InternalSize
|
||||
public Size Size
|
||||
{
|
||||
get => _internalSize;
|
||||
set
|
||||
{
|
||||
// ReSharper disable once ExplicitCallerInfoArgument
|
||||
if (SetProperty(ref _internalSize, value))
|
||||
OnPropertyChanged(nameof(Size));
|
||||
}
|
||||
get => _size;
|
||||
set => SetProperty(ref _size, value);
|
||||
}
|
||||
|
||||
private Point _location = new Point();
|
||||
private Point _location = new Point(0, 0);
|
||||
/// <inheritdoc />
|
||||
public Point Location
|
||||
{
|
||||
get => _location;
|
||||
set => SetProperty(ref _location, value ?? new Point());
|
||||
set => SetProperty(ref _location, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@ -454,7 +454,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="value">The value value to add.</param>
|
||||
/// <returns>The new color after the modification.</returns>
|
||||
public Color AddHSV(int a, double hue, double saturation, double value)
|
||||
=> Color.FromHSV(A + a, Hue + hue, Saturation + saturation, Value + value);
|
||||
=> FromHSV(A + a, Hue + hue, Saturation + saturation, Value + value);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given alpha value to this color.
|
||||
|
||||
@ -5,45 +5,37 @@ using System.Diagnostics;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a point consisting of a X- and a Y-position.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("[X: {X}, Y: {Y}]")]
|
||||
public class Point : AbstractBindable
|
||||
public struct Point
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Gets a [NaN,NaN]-Point.
|
||||
/// </summary>
|
||||
public static Point Invalid => new Point(double.NaN, double.NaN);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
private double _x;
|
||||
/// <summary>
|
||||
/// Gets or sets the X-position of this <see cref="Point"/>.
|
||||
/// Gets the X-position of this <see cref="Point"/>.
|
||||
/// </summary>
|
||||
public double X
|
||||
{
|
||||
get => _x;
|
||||
set => SetProperty(ref _x, value);
|
||||
}
|
||||
public double X { get; }
|
||||
|
||||
private double _y;
|
||||
/// <summary>
|
||||
/// Gets or sets the Y-position of this <see cref="Point"/>.
|
||||
/// Gets the Y-position of this <see cref="Point"/>.
|
||||
/// </summary>
|
||||
public double Y
|
||||
{
|
||||
get => _y;
|
||||
set => SetProperty(ref _y, value);
|
||||
}
|
||||
public double Y { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Point"/> class.
|
||||
/// </summary>
|
||||
public Point()
|
||||
{ }
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Point"/> class using the provided values.
|
||||
/// </summary>
|
||||
@ -63,10 +55,7 @@ namespace RGB.NET.Core
|
||||
/// Converts the <see cref="X"/>- and <see cref="Y"/>-position of this <see cref="Point"/> to a human-readable string.
|
||||
/// </summary>
|
||||
/// <returns>A string that contains the <see cref="X"/> and <see cref="Y"/> of this <see cref="Point"/>. For example "[X: 100, Y: 20]".</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[X: {X}, Y: {Y}]";
|
||||
}
|
||||
public override string ToString() => $"[X: {X}, Y: {Y}]";
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Point" /> and is equivalent to this <see cref="Point" />.
|
||||
@ -75,16 +64,9 @@ namespace RGB.NET.Core
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Point" /> equivalent to this <see cref="Point" />; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
Point comparePoint = obj as Point;
|
||||
if (ReferenceEquals(comparePoint, null))
|
||||
return false;
|
||||
|
||||
if (ReferenceEquals(this, comparePoint))
|
||||
return true;
|
||||
|
||||
if (GetType() != comparePoint.GetType())
|
||||
return false;
|
||||
if (!(obj is Point)) return false;
|
||||
|
||||
Point comparePoint = (Point)obj;
|
||||
return X.EqualsInTolerance(comparePoint.X) && Y.EqualsInTolerance(comparePoint.Y);
|
||||
}
|
||||
|
||||
@ -112,10 +94,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="point1">The first <see cref="Point" /> to compare.</param>
|
||||
/// <param name="point2">The second <see cref="Point" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="point1" /> and <paramref name="point2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(Point point1, Point point2)
|
||||
{
|
||||
return ReferenceEquals(point1, null) ? ReferenceEquals(point2, null) : point1.Equals(point2);
|
||||
}
|
||||
public static bool operator ==(Point point1, Point point2) => point1.Equals(point2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Point" /> are equal.
|
||||
@ -123,10 +102,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="point1">The first <see cref="Point" /> to compare.</param>
|
||||
/// <param name="point2">The second <see cref="Point" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="point1" /> and <paramref name="point2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(Point point1, Point point2)
|
||||
{
|
||||
return !(point1 == point2);
|
||||
}
|
||||
public static bool operator !=(Point point1, Point point2) => !(point1 == point2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the addition of the two provided <see cref="Point"/>.
|
||||
@ -134,10 +110,15 @@ namespace RGB.NET.Core
|
||||
/// <param name="point1">The first <see cref="Point"/>.</param>
|
||||
/// <param name="point2">The second <see cref="Point"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the addition of the two provided <see cref="Point"/>.</returns>
|
||||
public static Point operator +(Point point1, Point point2)
|
||||
{
|
||||
return new Point(point1.X + point2.X, point1.Y + point2.Y);
|
||||
}
|
||||
public static Point operator +(Point point1, Point point2) => new Point(point1.X + point2.X, point1.Y + point2.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rectangle"/> created from the provided <see cref="Point"/> and <see cref="Size"/>.
|
||||
/// </summary>
|
||||
/// <param name="point">The <see cref="Point"/> of the rectangle.</param>
|
||||
/// <param name="size">The <see cref="Size"/> of the rectangle.</param>
|
||||
/// <returns>The rectangle created from the provided <see cref="Point"/> and <see cref="Size"/>.</returns>
|
||||
public static Rectangle operator +(Point point, Size size) => new Rectangle(point, size);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the subtraction of the two provided <see cref="Point"/>.
|
||||
@ -145,10 +126,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="point1">The first <see cref="Point"/>.</param>
|
||||
/// <param name="point2">The second <see cref="Point"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the subtraction of the two provided <see cref="Point"/>.</returns>
|
||||
public static Point operator -(Point point1, Point point2)
|
||||
{
|
||||
return new Point(point1.X - point2.X, point1.Y - point2.Y);
|
||||
}
|
||||
public static Point operator -(Point point1, Point point2) => new Point(point1.X - point2.X, point1.Y - point2.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the multiplication of the two provided <see cref="Point"/>.
|
||||
@ -156,10 +134,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="point1">The first <see cref="Point"/>.</param>
|
||||
/// <param name="point2">The second <see cref="Point"/>.</param>
|
||||
/// <returns>A new <see cref="Point"/> representing the multiplication of the two provided <see cref="Point"/>.</returns>
|
||||
public static Point operator *(Point point1, Point point2)
|
||||
{
|
||||
return new Point(point1.X * point2.X, point1.Y * point2.Y);
|
||||
}
|
||||
public static Point operator *(Point point1, Point point2) => new Point(point1.X * point2.X, point1.Y * point2.Y);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Point"/> representing the division of the two provided <see cref="Point"/>.
|
||||
@ -169,7 +144,7 @@ namespace RGB.NET.Core
|
||||
/// <returns>A new <see cref="Point"/> representing the division of the two provided <see cref="Point"/>.</returns>
|
||||
public static Point operator /(Point point1, Point point2)
|
||||
{
|
||||
if (point2.X.EqualsInTolerance(0) || point2.Y.EqualsInTolerance(0)) return new Point();
|
||||
if (point2.X.EqualsInTolerance(0) || point2.Y.EqualsInTolerance(0)) return Invalid;
|
||||
return new Point(point1.X / point2.X, point1.Y / point2.Y);
|
||||
}
|
||||
|
||||
|
||||
@ -3,7 +3,6 @@
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
|
||||
@ -18,48 +17,111 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private Point _location;
|
||||
private double _x;
|
||||
/// <summary>
|
||||
/// Gets or sets the X-position of this <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
public double X
|
||||
{
|
||||
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>
|
||||
/// Gets or sets the <see cref="Point"/> representing the top-left corner of the <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
public Point Location
|
||||
{
|
||||
get => _location;
|
||||
get => new Point(X, Y);
|
||||
set
|
||||
{
|
||||
Point oldValue = _location;
|
||||
if (SetProperty(ref _location, value))
|
||||
if (Location != value)
|
||||
{
|
||||
if (oldValue != null)
|
||||
oldValue.PropertyChanged -= LocationPropertyChanged;
|
||||
_x = value.X;
|
||||
_y = value.Y;
|
||||
|
||||
if (_location != null)
|
||||
_location.PropertyChanged += LocationPropertyChanged;
|
||||
|
||||
OnLocationChanged();
|
||||
OnPropertyChanged(nameof(Location));
|
||||
OnPropertyChanged(nameof(Center));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Size _size;
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="Size"/> of the <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
public Size Size
|
||||
{
|
||||
get => _size;
|
||||
get => new Size(Width, Height);
|
||||
set
|
||||
{
|
||||
Size oldValue = _size;
|
||||
if (SetProperty(ref _size, value))
|
||||
if (Size != value)
|
||||
{
|
||||
if (oldValue != null)
|
||||
oldValue.PropertyChanged -= SizePropertyChanged;
|
||||
_width = value.Width;
|
||||
_height = value.Height;
|
||||
|
||||
if (_size != null)
|
||||
_size.PropertyChanged += SizePropertyChanged;
|
||||
|
||||
OnSizeChanged();
|
||||
OnPropertyChanged(nameof(Size));
|
||||
OnPropertyChanged(nameof(Center));
|
||||
OnPropertyChanged(nameof(IsEmpty));
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -67,37 +129,16 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Gets a new <see cref="Point"/> representing the center-point of the <see cref="Rectangle"/>.
|
||||
/// </summary>
|
||||
public Point Center => new Point(Location.X + (Size.Width / 2.0), Location.Y + (Size.Height / 2.0));
|
||||
public Point Center => new Point(X + (Width / 2.0), Y + (Height / 2.0));
|
||||
|
||||
/// <summary>
|
||||
/// 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>.
|
||||
/// </summary>
|
||||
public bool IsEmpty => (Size.Width <= DoubleExtensions.TOLERANCE) || (Size.Height <= DoubleExtensions.TOLERANCE);
|
||||
public bool IsEmpty => (Width <= DoubleExtensions.TOLERANCE) || (Height <= DoubleExtensions.TOLERANCE);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Events
|
||||
// ReSharper disable EventNeverSubscribedTo.Global
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a the <see cref="Location"/> of the <see cref="Rectangle"/> changes.
|
||||
/// </summary>
|
||||
public event EventHandler LocationChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when a the <see cref="Size"/> of the <see cref="Rectangle"/> changes.
|
||||
/// </summary>
|
||||
public event EventHandler SizeChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when the <see cref="Location"/> or the <see cref="Size"/> of the <see cref="Rectangle"/> changes.
|
||||
/// </summary>
|
||||
public event EventHandler Changed;
|
||||
|
||||
// ReSharper restore EventNeverSubscribedTo.Global
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -321,24 +362,6 @@ namespace RGB.NET.Core
|
||||
}
|
||||
}
|
||||
|
||||
private void LocationPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) => OnLocationChanged();
|
||||
private void OnLocationChanged()
|
||||
{
|
||||
// ReSharper disable once ExplicitCallerInfoArgument
|
||||
OnPropertyChanged(nameof(Center));
|
||||
LocationChanged?.Invoke(this, new EventArgs());
|
||||
Changed?.Invoke(this, new EventArgs());
|
||||
}
|
||||
|
||||
private void SizePropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs) => OnSizeChanged();
|
||||
private void OnSizeChanged()
|
||||
{
|
||||
// ReSharper disable once ExplicitCallerInfoArgument
|
||||
OnPropertyChanged(nameof(Center));
|
||||
SizeChanged?.Invoke(this, new EventArgs());
|
||||
Changed?.Invoke(this, new EventArgs());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Operators
|
||||
|
||||
@ -5,45 +5,37 @@ using System.Diagnostics;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a size consisting of a width and a height.
|
||||
/// </summary>
|
||||
[DebuggerDisplay("[Width: {Width}, Height: {Height}]")]
|
||||
public class Size : AbstractBindable
|
||||
public struct Size
|
||||
{
|
||||
#region Constants
|
||||
|
||||
/// <summary>
|
||||
/// Gets a [NaN,NaN]-Size.
|
||||
/// </summary>
|
||||
public static Size Invalid => new Size(double.NaN, double.NaN);
|
||||
|
||||
#endregion
|
||||
|
||||
#region Properties & Fields
|
||||
|
||||
private double _width;
|
||||
/// <summary>
|
||||
/// Gets or sets the width component value of this <see cref="Size"/>.
|
||||
/// </summary>
|
||||
public double Width
|
||||
{
|
||||
get => _width;
|
||||
set => SetProperty(ref _width, value);
|
||||
}
|
||||
public double Width { get; }
|
||||
|
||||
private double _height;
|
||||
/// <summary>
|
||||
/// Gets or sets the height component value of this <see cref="Size"/>.
|
||||
/// </summary>
|
||||
public double Height
|
||||
{
|
||||
get => _height;
|
||||
set => SetProperty(ref _height, value);
|
||||
}
|
||||
public double Height { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="Size"/> class.
|
||||
/// </summary>
|
||||
public Size()
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Core.Size" /> using the provided size to define a square.
|
||||
@ -72,10 +64,7 @@ namespace RGB.NET.Core
|
||||
/// Converts the <see cref="Width"/> and <see cref="Height"/> of this <see cref="Size"/> to a human-readable string.
|
||||
/// </summary>
|
||||
/// <returns>A string that contains the <see cref="Width"/> and <see cref="Height"/> of this <see cref="Size"/>. For example "[Width: 100, Height: 20]".</returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return $"[Width: {Width}, Height: {Height}]";
|
||||
}
|
||||
public override string ToString() => $"[Width: {Width}, Height: {Height}]";
|
||||
|
||||
/// <summary>
|
||||
/// Tests whether the specified object is a <see cref="Size" /> and is equivalent to this <see cref="Size" />.
|
||||
@ -84,16 +73,9 @@ namespace RGB.NET.Core
|
||||
/// <returns><c>true</c> if <paramref name="obj" /> is a <see cref="Size" /> equivalent to this <see cref="Size" />; otherwise, <c>false</c>.</returns>
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
Size compareSize = obj as Size;
|
||||
if (ReferenceEquals(compareSize, null))
|
||||
return false;
|
||||
|
||||
if (ReferenceEquals(this, compareSize))
|
||||
return true;
|
||||
|
||||
if (GetType() != compareSize.GetType())
|
||||
return false;
|
||||
if (!(obj is Size)) return false;
|
||||
|
||||
Size compareSize = (Size)obj;
|
||||
return Width.EqualsInTolerance(compareSize.Width) && Height.EqualsInTolerance(compareSize.Height);
|
||||
}
|
||||
|
||||
@ -121,10 +103,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="size1">The first <see cref="Size" /> to compare.</param>
|
||||
/// <param name="size2">The second <see cref="Size" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="size1" /> and <paramref name="size2" /> are equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator ==(Size size1, Size size2)
|
||||
{
|
||||
return ReferenceEquals(size1, null) ? ReferenceEquals(size2, null) : size1.Equals(size2);
|
||||
}
|
||||
public static bool operator ==(Size size1, Size size2) => size1.Equals(size2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a value that indicates whether two specified <see cref="Size" /> are equal.
|
||||
@ -132,10 +111,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="size1">The first <see cref="Size" /> to compare.</param>
|
||||
/// <param name="size2">The second <see cref="Size" /> to compare.</param>
|
||||
/// <returns><c>true</c> if <paramref name="size1" /> and <paramref name="size2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||
public static bool operator !=(Size size1, Size size2)
|
||||
{
|
||||
return !(size1 == size2);
|
||||
}
|
||||
public static bool operator !=(Size size1, Size size2) => !(size1 == size2);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the addition of the two provided <see cref="Size"/>.
|
||||
@ -143,10 +119,15 @@ namespace RGB.NET.Core
|
||||
/// <param name="size1">The first <see cref="Size"/>.</param>
|
||||
/// <param name="size2">The second <see cref="Size"/>.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the addition of the two provided <see cref="Size"/>.</returns>
|
||||
public static Size operator +(Size size1, Size size2)
|
||||
{
|
||||
return new Size(size1.Width + size2.Width, size1.Height + size2.Height);
|
||||
}
|
||||
public static Size operator +(Size size1, Size size2) => new Size(size1.Width + size2.Width, size1.Height + size2.Height);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Rectangle"/> created from the provided <see cref="Point"/> and <see cref="Size"/>.
|
||||
/// </summary>
|
||||
/// <param name="size">The <see cref="Size"/> of the rectangle.</param>
|
||||
/// <param name="point">The <see cref="Point"/> of the rectangle.</param>
|
||||
/// <returns>The rectangle created from the provided <see cref="Point"/> and <see cref="Size"/>.</returns>
|
||||
public static Rectangle operator +(Size size, Point point) => new Rectangle(point, size);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the subtraction of the two provided <see cref="Size"/>.
|
||||
@ -154,10 +135,7 @@ namespace RGB.NET.Core
|
||||
/// <param name="size1">The first <see cref="Size"/>.</param>
|
||||
/// <param name="size2">The second <see cref="Size"/>.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the subtraction of the two provided <see cref="Size"/>.</returns>
|
||||
public static Size operator -(Size size1, Size size2)
|
||||
{
|
||||
return new Size(size1.Width - size2.Width, size1.Height - size2.Height);
|
||||
}
|
||||
public static Size operator -(Size size1, Size size2) => new Size(size1.Width - size2.Width, size1.Height - size2.Height);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the multiplication of the two provided <see cref="Size"/>.
|
||||
@ -165,10 +143,15 @@ namespace RGB.NET.Core
|
||||
/// <param name="size1">The first <see cref="Size"/>.</param>
|
||||
/// <param name="size2">The second <see cref="Size"/>.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the multiplication of the two provided <see cref="Size"/>.</returns>
|
||||
public static Size operator *(Size size1, Size size2)
|
||||
{
|
||||
return new Size(size1.Width * size2.Width, size1.Height * size2.Height);
|
||||
}
|
||||
public static Size operator *(Size size1, Size size2) => new Size(size1.Width * size2.Width, size1.Height * size2.Height);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the provided factor.
|
||||
/// </summary>
|
||||
/// <param name="size">The <see cref="Size"/>.</param>
|
||||
/// <param name="factor">The factor by which the <see cref="Size"/> should be multiplied.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the multiplication of the <see cref="Size"/> and the provided factor.</returns>
|
||||
public static Size operator *(Size size, double factor) => new Size(size.Width * factor, size.Height * factor);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the division of the two provided <see cref="Size"/>.
|
||||
@ -177,10 +160,16 @@ namespace RGB.NET.Core
|
||||
/// <param name="size2">The second <see cref="Size"/>.</param>
|
||||
/// <returns>A new <see cref="Size"/> representing the division of the two provided <see cref="Size"/>.</returns>
|
||||
public static Size operator /(Size size1, Size size2)
|
||||
{
|
||||
if (size2.Width.EqualsInTolerance(0) || size2.Height.EqualsInTolerance(0)) return new Size();
|
||||
return new Size(size1.Width / size2.Width, size1.Height / size2.Height);
|
||||
}
|
||||
=> size2.Width.EqualsInTolerance(0) || size2.Height.EqualsInTolerance(0)
|
||||
? Invalid : new Size(size1.Width / size2.Width, size1.Height / size2.Height);
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="Size"/> representing the division of the <see cref="Size"/> and the provided factor.
|
||||
/// </summary>
|
||||
/// <param name="size">The <see cref="Size"/>.</param>
|
||||
/// <param name="factor">The factor by which the <see cref="Size"/> should be divided.</param>
|
||||
/// <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);
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -125,10 +125,9 @@ namespace RGB.NET.Core
|
||||
switch (brush.BrushCalculationMode)
|
||||
{
|
||||
case BrushCalculationMode.Relative:
|
||||
Rectangle brushRectangle = new Rectangle(leds.Select(x => GetDeviceLedLocation(x)));
|
||||
Rectangle brushRectangle = new Rectangle(leds.Select(GetDeviceLedLocation));
|
||||
Point offset = new Point(-brushRectangle.Location.X, -brushRectangle.Location.Y);
|
||||
brushRectangle.Location.X = 0;
|
||||
brushRectangle.Location.Y = 0;
|
||||
brushRectangle.Location = new Point(0, 0);
|
||||
brush.PerformRender(brushRectangle,
|
||||
leds.Select(x => new BrushRenderTarget(x, GetDeviceLedLocation(x, offset))));
|
||||
break;
|
||||
@ -146,12 +145,9 @@ namespace RGB.NET.Core
|
||||
renders.Key.Led.Color = renders.Value;
|
||||
}
|
||||
|
||||
private Rectangle GetDeviceLedLocation(Led led, Point extraOffset = null)
|
||||
{
|
||||
return extraOffset != null
|
||||
? new Rectangle(led.LedRectangle.Location + led.Device.Location + extraOffset, new Size(led.LedRectangle.Size.Width, led.LedRectangle.Size.Height))
|
||||
: new Rectangle(led.LedRectangle.Location + led.Device.Location, new Size(led.LedRectangle.Size.Width, led.LedRectangle.Size.Height));
|
||||
}
|
||||
private Rectangle GetDeviceLedLocation(Led led) => (led.LedRectangle.Location + led.Device.Location) + new Size(led.LedRectangle.Size.Width, led.LedRectangle.Size.Height);
|
||||
|
||||
private Rectangle GetDeviceLedLocation(Led led, Point extraOffset) => (led.LedRectangle.Location + led.Device.Location + extraOffset) + new Size(led.LedRectangle.Size.Width, led.LedRectangle.Size.Height);
|
||||
|
||||
/// <summary>
|
||||
/// Attaches the given <see cref="ILedGroup"/>.
|
||||
@ -198,8 +194,8 @@ namespace RGB.NET.Core
|
||||
{
|
||||
Rectangle devicesRectangle = new Rectangle(_devices.Select(d => new Rectangle(d.Location, d.Size)));
|
||||
|
||||
_surfaceRectangle.Size.Width = devicesRectangle.Location.X + devicesRectangle.Size.Width;
|
||||
_surfaceRectangle.Size.Height = devicesRectangle.Location.Y + devicesRectangle.Size.Height;
|
||||
_surfaceRectangle.Width = devicesRectangle.Location.X + devicesRectangle.Size.Width;
|
||||
_surfaceRectangle.Height = devicesRectangle.Location.Y + devicesRectangle.Size.Height;
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -30,7 +30,6 @@ namespace RGB.NET.Core
|
||||
addedDevices.Add(device);
|
||||
|
||||
device.PropertyChanged += DeviceOnPropertyChanged;
|
||||
device.Location.PropertyChanged += DeviceLocationOnPropertyChanged;
|
||||
_devices.Add(device);
|
||||
}
|
||||
}
|
||||
@ -50,23 +49,12 @@ namespace RGB.NET.Core
|
||||
double posX = 0;
|
||||
foreach (IRGBDevice device in Devices)
|
||||
{
|
||||
device.Location.X = posX;
|
||||
device.Location += new Point(posX, 0);
|
||||
posX += device.Size.Width + 1;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
|
||||
{
|
||||
if (string.Equals(propertyChangedEventArgs.PropertyName, nameof(IRGBDevice.Location)))
|
||||
{
|
||||
UpdateSurfaceRectangle();
|
||||
SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(new[] { sender as IRGBDevice }, false, true));
|
||||
|
||||
((IRGBDevice)sender).Location.PropertyChanged += DeviceLocationOnPropertyChanged;
|
||||
}
|
||||
}
|
||||
|
||||
private void DeviceLocationOnPropertyChanged(object sender, PropertyChangedEventArgs propertyChangedEventArgs)
|
||||
{
|
||||
UpdateSurfaceRectangle();
|
||||
SurfaceLayoutChanged?.Invoke(new SurfaceLayoutChangedEventArgs(new[] { sender as IRGBDevice }, false, true));
|
||||
|
||||
@ -53,10 +53,10 @@ namespace RGB.NET.Devices.Asus
|
||||
{
|
||||
InitializeLayout();
|
||||
|
||||
if (InternalSize == null)
|
||||
if (Size == Size.Invalid)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
}
|
||||
|
||||
ColorData = new byte[LedMapping.Count * 3];
|
||||
@ -80,7 +80,7 @@ namespace RGB.NET.Devices.Asus
|
||||
{
|
||||
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
InternalSize = new Size(layout.Width, layout.Height);
|
||||
Size = new Size(layout.Width, layout.Height);
|
||||
|
||||
if (layout.Leds != null)
|
||||
foreach (LedLayout layoutLed in layout.Leds)
|
||||
@ -89,10 +89,8 @@ namespace RGB.NET.Devices.Asus
|
||||
{
|
||||
if (LedMapping.TryGetValue(new AsusLedId(this, ledId), out Led led))
|
||||
{
|
||||
led.LedRectangle.Location.X = layoutLed.X;
|
||||
led.LedRectangle.Location.Y = layoutLed.Y;
|
||||
led.LedRectangle.Size.Width = layoutLed.Width;
|
||||
led.LedRectangle.Size.Height = layoutLed.Height;
|
||||
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
|
||||
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
|
||||
|
||||
led.Shape = layoutLed.Shape;
|
||||
led.ShapeData = layoutLed.ShapeData;
|
||||
|
||||
@ -48,10 +48,10 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
{
|
||||
InitializeLayout();
|
||||
|
||||
if (InternalSize == null)
|
||||
if (Size == Size.Invalid)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
{
|
||||
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
InternalSize = new Size(layout.Width, layout.Height);
|
||||
Size = new Size(layout.Width, layout.Height);
|
||||
|
||||
if (layout.Leds != null)
|
||||
foreach (LedLayout layoutLed in layout.Leds)
|
||||
@ -82,10 +82,8 @@ namespace RGB.NET.Devices.CoolerMaster
|
||||
{
|
||||
if (LedMapping.TryGetValue(new CoolerMasterLedId(this, ledId), out Led led))
|
||||
{
|
||||
led.LedRectangle.Location.X = layoutLed.X;
|
||||
led.LedRectangle.Location.Y = layoutLed.Y;
|
||||
led.LedRectangle.Size.Width = layoutLed.Width;
|
||||
led.LedRectangle.Size.Height = layoutLed.Height;
|
||||
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
|
||||
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
|
||||
|
||||
led.Shape = layoutLed.Shape;
|
||||
led.ShapeData = layoutLed.ShapeData;
|
||||
|
||||
@ -49,10 +49,10 @@ namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
InitializeLayout();
|
||||
|
||||
if (InternalSize == null)
|
||||
if (Size == Size.Invalid)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,7 +74,7 @@ namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
InternalSize = new Size(layout.Width, layout.Height);
|
||||
Size = new Size(layout.Width, layout.Height);
|
||||
|
||||
if (layout.Leds != null)
|
||||
foreach (LedLayout layoutLed in layout.Leds)
|
||||
@ -83,10 +83,8 @@ namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
if (LedMapping.TryGetValue(new CorsairLedId(this, ledId), out Led led))
|
||||
{
|
||||
led.LedRectangle.Location.X = layoutLed.X;
|
||||
led.LedRectangle.Location.Y = layoutLed.Y;
|
||||
led.LedRectangle.Size.Width = layoutLed.Width;
|
||||
led.LedRectangle.Size.Height = layoutLed.Height;
|
||||
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
|
||||
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
|
||||
|
||||
led.Shape = layoutLed.Shape;
|
||||
led.ShapeData = layoutLed.ShapeData;
|
||||
|
||||
@ -46,10 +46,10 @@ namespace RGB.NET.Devices.Logitech
|
||||
{
|
||||
InitializeLayout();
|
||||
|
||||
if (InternalSize == null)
|
||||
if (Size == Size.Invalid)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -78,7 +78,7 @@ namespace RGB.NET.Devices.Logitech
|
||||
{
|
||||
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
InternalSize = new Size(layout.Width, layout.Height);
|
||||
Size = new Size(layout.Width, layout.Height);
|
||||
|
||||
if (layout.Leds != null)
|
||||
foreach (LedLayout layoutLed in layout.Leds)
|
||||
@ -89,10 +89,8 @@ namespace RGB.NET.Devices.Logitech
|
||||
if (!LedMapping.TryGetValue(id, out Led led))
|
||||
led = InitializeLed(id, new Rectangle());
|
||||
|
||||
led.LedRectangle.Location.X = layoutLed.X;
|
||||
led.LedRectangle.Location.Y = layoutLed.Y;
|
||||
led.LedRectangle.Size.Width = layoutLed.Width;
|
||||
led.LedRectangle.Size.Height = layoutLed.Height;
|
||||
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
|
||||
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
|
||||
|
||||
led.Shape = layoutLed.Shape;
|
||||
led.ShapeData = layoutLed.ShapeData;
|
||||
|
||||
@ -48,10 +48,10 @@ namespace RGB.NET.Devices.Msi
|
||||
{
|
||||
InitializeLayout();
|
||||
|
||||
if (InternalSize == null)
|
||||
if (Size == Size.Invalid)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -73,7 +73,7 @@ namespace RGB.NET.Devices.Msi
|
||||
{
|
||||
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
InternalSize = new Size(layout.Width, layout.Height);
|
||||
Size = new Size(layout.Width, layout.Height);
|
||||
|
||||
if (layout.Leds != null)
|
||||
foreach (LedLayout layoutLed in layout.Leds)
|
||||
@ -82,10 +82,8 @@ namespace RGB.NET.Devices.Msi
|
||||
{
|
||||
if (LedMapping.TryGetValue(new MsiLedId(this, ledId), out Led led))
|
||||
{
|
||||
led.LedRectangle.Location.X = layoutLed.X;
|
||||
led.LedRectangle.Location.Y = layoutLed.Y;
|
||||
led.LedRectangle.Size.Width = layoutLed.Width;
|
||||
led.LedRectangle.Size.Height = layoutLed.Height;
|
||||
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
|
||||
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
|
||||
|
||||
led.Shape = layoutLed.Shape;
|
||||
led.ShapeData = layoutLed.ShapeData;
|
||||
|
||||
@ -54,10 +54,10 @@ namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
InitializeLayout();
|
||||
|
||||
if (InternalSize == null)
|
||||
if (Size == Size.Invalid)
|
||||
{
|
||||
Rectangle ledRectangle = new Rectangle(this.Select(x => x.LedRectangle));
|
||||
InternalSize = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
Size = ledRectangle.Size + new Size(ledRectangle.Location.X, ledRectangle.Location.Y);
|
||||
}
|
||||
}
|
||||
|
||||
@ -79,7 +79,7 @@ namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
LedImageLayout ledImageLayout = layout.LedImageLayouts.FirstOrDefault(x => string.Equals(x.Layout, imageLayout, StringComparison.OrdinalIgnoreCase));
|
||||
|
||||
InternalSize = new Size(layout.Width, layout.Height);
|
||||
Size = new Size(layout.Width, layout.Height);
|
||||
|
||||
if (layout.Leds != null)
|
||||
foreach (LedLayout layoutLed in layout.Leds)
|
||||
@ -88,10 +88,8 @@ namespace RGB.NET.Devices.Novation
|
||||
{
|
||||
if (LedMapping.TryGetValue(new NovationLedId(this, ledId), out Led led))
|
||||
{
|
||||
led.LedRectangle.Location.X = layoutLed.X;
|
||||
led.LedRectangle.Location.Y = layoutLed.Y;
|
||||
led.LedRectangle.Size.Width = layoutLed.Width;
|
||||
led.LedRectangle.Size.Height = layoutLed.Height;
|
||||
led.LedRectangle.Location = new Point(layoutLed.X, layoutLed.Y);
|
||||
led.LedRectangle.Size = new Size(layoutLed.Width, layoutLed.Height);
|
||||
|
||||
led.Shape = layoutLed.Shape;
|
||||
led.ShapeData = layoutLed.ShapeData;
|
||||
|
||||
@ -32,10 +32,10 @@ namespace RGB.NET.Groups
|
||||
if (SetProperty(ref _rectangle, value))
|
||||
{
|
||||
if (oldValue != null)
|
||||
oldValue.Changed -= RectangleChanged;
|
||||
oldValue.PropertyChanged -= RectangleChanged;
|
||||
|
||||
if (_rectangle != null)
|
||||
_rectangle.Changed += RectangleChanged;
|
||||
_rectangle.PropertyChanged += RectangleChanged;
|
||||
|
||||
InvalidateCache();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user