mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
Fixed missing update if the reactangle of a ledGroup is changed
This commit is contained in:
parent
3630e0f66f
commit
1f3213fa73
@ -3,6 +3,7 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
|
using System.ComponentModel;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
|
||||||
@ -25,9 +26,17 @@ namespace RGB.NET.Core
|
|||||||
get => _location;
|
get => _location;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
Point oldValue = _location;
|
||||||
if (SetProperty(ref _location, value))
|
if (SetProperty(ref _location, value))
|
||||||
// ReSharper disable once ExplicitCallerInfoArgument
|
{
|
||||||
OnPropertyChanged(nameof(Center));
|
if (oldValue != null)
|
||||||
|
oldValue.PropertyChanged -= LocationPropertyChanged;
|
||||||
|
|
||||||
|
if (_location != null)
|
||||||
|
_location.PropertyChanged += LocationPropertyChanged;
|
||||||
|
|
||||||
|
OnLocationChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,9 +49,17 @@ namespace RGB.NET.Core
|
|||||||
get => _size;
|
get => _size;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
|
Size oldValue = _size;
|
||||||
if (SetProperty(ref _size, value))
|
if (SetProperty(ref _size, value))
|
||||||
// ReSharper disable once ExplicitCallerInfoArgument
|
{
|
||||||
OnPropertyChanged(nameof(Center));
|
if (oldValue != null)
|
||||||
|
oldValue.PropertyChanged -= SizePropertyChanged;
|
||||||
|
|
||||||
|
if (_size != null)
|
||||||
|
_size.PropertyChanged += SizePropertyChanged;
|
||||||
|
|
||||||
|
OnSizeChanged();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -59,6 +76,14 @@ namespace RGB.NET.Core
|
|||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region Events
|
||||||
|
|
||||||
|
public event EventHandler LocationChanged;
|
||||||
|
public event EventHandler SizeChanged;
|
||||||
|
public event EventHandler Changed;
|
||||||
|
|
||||||
|
#endregion
|
||||||
|
|
||||||
#region Constructors
|
#region Constructors
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -219,10 +244,7 @@ namespace RGB.NET.Core
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="point">The <see cref="Point"/> to test.</param>
|
/// <param name="point">The <see cref="Point"/> to test.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Contains(Point point)
|
public bool Contains(Point point) => Contains(point.X, point.Y);
|
||||||
{
|
|
||||||
return Contains(point.X, point.Y);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines if the specified location is contained within this <see cref="Rectangle"/>.
|
/// Determines if the specified location is contained within this <see cref="Rectangle"/>.
|
||||||
@ -230,30 +252,21 @@ namespace RGB.NET.Core
|
|||||||
/// <param name="x">The X-location to test.</param>
|
/// <param name="x">The X-location to test.</param>
|
||||||
/// <param name="y">The Y-location to test.</param>
|
/// <param name="y">The Y-location to test.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Contains(double x, double y)
|
public bool Contains(double x, double y) => (Location.X <= x) && (x < (Location.X + Size.Width)) && (Location.Y <= y) && (y < (Location.Y + Size.Height));
|
||||||
{
|
|
||||||
return (Location.X <= x) && (x < (Location.X + Size.Width)) && (Location.Y <= y) && (y < (Location.Y + Size.Height));
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Determines if the specified <see cref="Rectangle"/> is contained within this <see cref="Rectangle"/>.
|
/// Determines if the specified <see cref="Rectangle"/> is contained within this <see cref="Rectangle"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="rect">The <see cref="Rectangle"/> to test.</param>
|
/// <param name="rect">The <see cref="Rectangle"/> to test.</param>
|
||||||
/// <returns></returns>
|
/// <returns></returns>
|
||||||
public bool Contains(Rectangle rect)
|
public bool Contains(Rectangle rect) => (Location.X <= rect.Location.X) && ((rect.Location.X + rect.Size.Width) <= (Location.X + Size.Width))
|
||||||
{
|
|
||||||
return (Location.X <= rect.Location.X) && ((rect.Location.X + rect.Size.Width) <= (Location.X + Size.Width))
|
|
||||||
&& (Location.Y <= rect.Location.Y) && ((rect.Location.Y + rect.Size.Height) <= (Location.Y + Size.Height));
|
&& (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>
|
||||||
/// <returns>A string that contains the <see cref="Location"/> and <see cref="Size"/> of this <see cref="Rectangle"/>. For example "[Location: [X: 100, Y: 10], Size: [Width: 20, Height: [40]]".</returns>
|
/// <returns>A string that contains the <see cref="Location"/> and <see cref="Size"/> of this <see cref="Rectangle"/>. For example "[Location: [X: 100, Y: 10], Size: [Width: 20, Height: [40]]".</returns>
|
||||||
public override string ToString()
|
public override string ToString() => $"[Location: {Location}, Size: {Size}]";
|
||||||
{
|
|
||||||
return $"[Location: {Location}, Size: {Size}]";
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Tests whether the specified object is a <see cref="Rectangle" /> and is equivalent to this <see cref="Rectangle" />.
|
/// Tests whether the specified object is a <see cref="Rectangle" /> and is equivalent to this <see cref="Rectangle" />.
|
||||||
@ -289,6 +302,24 @@ 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
|
#endregion
|
||||||
|
|
||||||
#region Operators
|
#region Operators
|
||||||
@ -299,10 +330,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)
|
public static bool operator ==(Rectangle rectangle1, Rectangle rectangle2) => ReferenceEquals(rectangle1, null) ? ReferenceEquals(rectangle2, null) : rectangle1.Equals(rectangle2);
|
||||||
{
|
|
||||||
return ReferenceEquals(rectangle1, null) ? ReferenceEquals(rectangle2, null) : 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.
|
||||||
@ -310,10 +338,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 not equal; otherwise, <c>false</c>.</returns>
|
/// <returns><c>true</c> if <paramref name="rectangle1" /> and <paramref name="rectangle2" /> are not equal; otherwise, <c>false</c>.</returns>
|
||||||
public static bool operator !=(Rectangle rectangle1, Rectangle rectangle2)
|
public static bool operator !=(Rectangle rectangle1, Rectangle rectangle2) => !(rectangle1 == rectangle2);
|
||||||
{
|
|
||||||
return !(rectangle1 == rectangle2);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,6 +2,7 @@
|
|||||||
// 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;
|
||||||
@ -26,10 +27,19 @@ namespace RGB.NET.Groups
|
|||||||
get => _rectangle;
|
get => _rectangle;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_rectangle = value;
|
Rectangle oldValue = _rectangle;
|
||||||
|
if (SetProperty(ref _rectangle, value))
|
||||||
|
{
|
||||||
|
if (oldValue != null)
|
||||||
|
oldValue.Changed -= RectangleChanged;
|
||||||
|
|
||||||
|
if (_rectangle != null)
|
||||||
|
_rectangle.Changed += RectangleChanged;
|
||||||
|
|
||||||
InvalidateCache();
|
InvalidateCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private double _minOverlayPercentage;
|
private double _minOverlayPercentage;
|
||||||
/// <summary>
|
/// <summary>
|
||||||
@ -40,7 +50,7 @@ namespace RGB.NET.Groups
|
|||||||
get => _minOverlayPercentage;
|
get => _minOverlayPercentage;
|
||||||
set
|
set
|
||||||
{
|
{
|
||||||
_minOverlayPercentage = value;
|
if (SetProperty(ref _minOverlayPercentage, value))
|
||||||
InvalidateCache();
|
InvalidateCache();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -100,35 +110,22 @@ namespace RGB.NET.Groups
|
|||||||
#region Methods
|
#region Methods
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnAttach()
|
public override void OnAttach() => RGBSurface.Instance.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged;
|
||||||
{
|
|
||||||
RGBSurface.Instance.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <inheritdoc />
|
/// <inheritdoc />
|
||||||
public override void OnDetach()
|
public override void OnDetach() => RGBSurface.Instance.SurfaceLayoutChanged -= RGBSurfaceOnSurfaceLayoutChanged;
|
||||||
{
|
|
||||||
RGBSurface.Instance.SurfaceLayoutChanged -= RGBSurfaceOnSurfaceLayoutChanged;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args)
|
private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args) => InvalidateCache();
|
||||||
{
|
|
||||||
InvalidateCache();
|
private void RectangleChanged(object sender, EventArgs eventArgs) => InvalidateCache();
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets a list containing all <see cref="Led"/> of this <see cref="RectangleLedGroup"/>.
|
/// Gets a list containing all <see cref="Led"/> of this <see cref="RectangleLedGroup"/>.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
/// <returns>The list containing all <see cref="Led"/> of this <see cref="RectangleLedGroup"/>.</returns>
|
/// <returns>The list containing all <see cref="Led"/> of this <see cref="RectangleLedGroup"/>.</returns>
|
||||||
public override IEnumerable<Led> GetLeds()
|
public override IEnumerable<Led> GetLeds() => _ledCache ?? (_ledCache = RGBSurface.Instance.Leds.Where(x => x.LedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList());
|
||||||
{
|
|
||||||
return _ledCache ?? (_ledCache = RGBSurface.Instance.Leds.Where(x => x.LedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void InvalidateCache()
|
private void InvalidateCache() => _ledCache = null;
|
||||||
{
|
|
||||||
_ledCache = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user