mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-12 17:48:31 +00:00
Removed static RGBSurface and DeviceSpecialParts
This commit is contained in:
parent
53c4b8188d
commit
5bc945c4f7
@ -8,6 +8,8 @@
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
protected RGBSurface Surface { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets if the <see cref="AbstractUpdateAwareDecorator"/> should call <see cref="Update"/> even if the Decorator is disabled.
|
||||
/// </summary>
|
||||
@ -21,8 +23,9 @@
|
||||
/// Initializes a new instance of the <see cref="AbstractUpdateAwareDecorator"/> class.
|
||||
/// </summary>
|
||||
/// <param name="updateIfDisabled">Bool indicating if the <see cref="AbstractUpdateAwareDecorator"/> should call <see cref="Update"/> even if the Decorator is disabled.</param>
|
||||
protected AbstractUpdateAwareDecorator(bool updateIfDisabled = false)
|
||||
protected AbstractUpdateAwareDecorator(RGBSurface surface, bool updateIfDisabled = false)
|
||||
{
|
||||
this.Surface = surface;
|
||||
this.UpdateIfDisabled = updateIfDisabled;
|
||||
}
|
||||
|
||||
@ -34,7 +37,7 @@
|
||||
public override void OnAttached(IDecoratable decoratable)
|
||||
{
|
||||
if (DecoratedObjects.Count == 0)
|
||||
RGBSurface.Instance.Updating += OnSurfaceUpdating;
|
||||
Surface.Updating += OnSurfaceUpdating;
|
||||
|
||||
base.OnAttached(decoratable);
|
||||
}
|
||||
@ -45,7 +48,7 @@
|
||||
base.OnDetached(decoratable);
|
||||
|
||||
if (DecoratedObjects.Count == 0)
|
||||
RGBSurface.Instance.Updating -= OnSurfaceUpdating;
|
||||
Surface.Updating -= OnSurfaceUpdating;
|
||||
}
|
||||
|
||||
private void OnSurfaceUpdating(UpdatingEventArgs args)
|
||||
|
||||
@ -104,11 +104,6 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
protected Dictionary<LedId, Led> LedMapping { get; } = new Dictionary<LedId, Led>();
|
||||
|
||||
/// <summary>
|
||||
/// Gets a dictionary containing all <see cref="IRGBDeviceSpecialPart"/> associated with this <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
protected Dictionary<Type, IRGBDeviceSpecialPart> SpecialDeviceParts { get; } = new Dictionary<Type, IRGBDeviceSpecialPart>();
|
||||
|
||||
#region Indexer
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -149,13 +144,12 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
protected virtual IEnumerable<Led> GetLedsToUpdate(bool flushLeds) => ((RequiresFlush || flushLeds) ? LedMapping.Values : LedMapping.Values.Where(x => x.IsDirty));
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void Dispose()
|
||||
{
|
||||
try
|
||||
{
|
||||
SpecialDeviceParts.Clear();
|
||||
LedMapping.Clear();
|
||||
}
|
||||
catch { /* this really shouldn't happen */ }
|
||||
@ -196,7 +190,7 @@ namespace RGB.NET.Core
|
||||
LedMapping.Add(ledId, led);
|
||||
return led;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Applies the given layout.
|
||||
/// </summary>
|
||||
@ -248,16 +242,6 @@ namespace RGB.NET.Core
|
||||
/// <param name="ledId">The <see cref="LedId"/>.</param>
|
||||
protected virtual object CreateLedCustomData(LedId ledId) => null;
|
||||
|
||||
/// <inheritdoc />
|
||||
public void AddSpecialDevicePart<T>(T specialDevicePart)
|
||||
where T : class, IRGBDeviceSpecialPart
|
||||
=> SpecialDeviceParts[typeof(T)] = specialDevicePart;
|
||||
|
||||
/// <inheritdoc />
|
||||
public T GetSpecialDevicePart<T>()
|
||||
where T : class, IRGBDeviceSpecialPart
|
||||
=> SpecialDeviceParts.TryGetValue(typeof(T), out IRGBDeviceSpecialPart devicePart) ? (T)devicePart : default;
|
||||
|
||||
#region Enumerator
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -89,21 +89,6 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
/// <param name="flushLeds">Specifies whether all <see cref="Led"/> (including clean ones) should be updated.</param>
|
||||
void Update(bool flushLeds = false);
|
||||
|
||||
/// <summary>
|
||||
/// Adds the given <see cref="IRGBDeviceSpecialPart"/> to the device.
|
||||
/// This will override existing <see cref="IRGBDeviceSpecialPart"/> of the same type.
|
||||
/// </summary>
|
||||
/// <param name="specialDevicePart">The <see cref="IRGBDeviceSpecialPart"/> to add.</param>
|
||||
/// <typeparam name="T">The generic typeof of the <see cref="IRGBDeviceSpecialPart"/> to add.</typeparam>
|
||||
void AddSpecialDevicePart<T>(T specialDevicePart) where T : class, IRGBDeviceSpecialPart;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the requested <see cref="IRGBDeviceSpecialPart"/> if available on this <see cref="IRGBDevice"/>.
|
||||
/// </summary>
|
||||
/// <typeparam name="T">The generic type of the requested <see cref="IRGBDeviceSpecialPart"/>.</typeparam>
|
||||
/// <returns>The requested <see cref="IRGBDeviceSpecialPart"/> or null if not available in this <see cref="IRGBDevice"/>.</returns>
|
||||
T GetSpecialDevicePart<T>() where T : class, IRGBDeviceSpecialPart;
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -39,7 +39,7 @@ namespace RGB.NET.Core
|
||||
bool Initialize(RGBDeviceType loadFilter = RGBDeviceType.All, bool exclusiveAccessIfPossible = false, bool throwExceptions = false);
|
||||
|
||||
/// <summary>
|
||||
/// Resets all handled <see cref="IRGBDevice"/> back top default.
|
||||
/// Resets all handled <see cref="IRGBDevice"/> back to default.
|
||||
/// </summary>
|
||||
void ResetDevices();
|
||||
|
||||
|
||||
@ -1,11 +0,0 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace RGB.NET.Core
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a special part of a <see cref="T:RGB.NET.Core.IRGBDevice" />.
|
||||
/// </summary>
|
||||
public interface IRGBDeviceSpecialPart : IEnumerable<Led>
|
||||
{ }
|
||||
}
|
||||
@ -11,6 +11,8 @@ namespace RGB.NET.Core
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
public RGBSurface? Surface { get; private set; }
|
||||
|
||||
/// <inheritdoc />
|
||||
public IBrush Brush { get; set; }
|
||||
|
||||
@ -24,11 +26,9 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="AbstractLedGroup"/> class.
|
||||
/// </summary>
|
||||
/// <param name="autoAttach">Specifies whether this <see cref="AbstractLedGroup"/> should be automatically attached or not.</param>
|
||||
protected AbstractLedGroup(bool autoAttach)
|
||||
protected AbstractLedGroup(RGBSurface? attachTo)
|
||||
{
|
||||
if (autoAttach)
|
||||
RGBSurface.Instance.AttachLedGroup(this);
|
||||
attachTo?.AttachLedGroup(this);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -39,12 +39,16 @@ namespace RGB.NET.Core
|
||||
public abstract IList<Led> GetLeds();
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void OnAttach()
|
||||
{ }
|
||||
public virtual void OnAttach(RGBSurface surface)
|
||||
{
|
||||
Surface = surface;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public virtual void OnDetach()
|
||||
{ }
|
||||
public virtual void OnDetach(RGBSurface surface)
|
||||
{
|
||||
Surface = null;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
|
||||
@ -11,6 +11,8 @@ namespace RGB.NET.Core
|
||||
/// </summary>
|
||||
public interface ILedGroup : IDecoratable<ILedGroupDecorator>
|
||||
{
|
||||
public RGBSurface? Surface { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets the <see cref="IBrush"/> which should be drawn over this <see cref="ILedGroup"/>.
|
||||
/// </summary>
|
||||
@ -30,11 +32,11 @@ namespace RGB.NET.Core
|
||||
/// <summary>
|
||||
/// Called when the <see cref="ILedGroup"/> is attached to the <see cref="RGBSurface"/>.
|
||||
/// </summary>
|
||||
void OnAttach();
|
||||
void OnAttach(RGBSurface surface);
|
||||
|
||||
/// <summary>
|
||||
/// Called when the <see cref="ILedGroup"/> is detached from the <see cref="RGBSurface"/>.
|
||||
/// </summary>
|
||||
void OnDetach();
|
||||
void OnDetach(RGBSurface surface);
|
||||
}
|
||||
}
|
||||
|
||||
@ -18,7 +18,7 @@ namespace RGB.NET.Core
|
||||
public class RGBSurface : AbstractBindable, IDisposable
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
|
||||
private Stopwatch _deltaTimeCounter;
|
||||
|
||||
private IList<IRGBDeviceProvider> _deviceProvider = new List<IRGBDeviceProvider>();
|
||||
@ -66,7 +66,7 @@ namespace RGB.NET.Core
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region EventHandler
|
||||
|
||||
/// <summary>
|
||||
@ -254,7 +254,7 @@ namespace RGB.NET.Core
|
||||
if (_ledGroups.Contains(ledGroup)) return false;
|
||||
|
||||
_ledGroups.AddLast(ledGroup);
|
||||
ledGroup.OnAttach();
|
||||
ledGroup.OnAttach(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -275,7 +275,7 @@ namespace RGB.NET.Core
|
||||
if (node == null) return false;
|
||||
|
||||
_ledGroups.Remove(node);
|
||||
node.Value.OnDetach();
|
||||
node.Value.OnDetach(this);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -443,7 +443,7 @@ namespace RGB.NET.Core
|
||||
}
|
||||
catch { /* Well ... that's not my fault */ }
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
||||
@ -74,6 +74,14 @@ namespace RGB.NET.Decorators.Brush
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
public FlashDecorator(RGBSurface surface, bool updateIfDisabled = false)
|
||||
: base(surface, updateIfDisabled)
|
||||
{ }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
|
||||
@ -45,7 +45,8 @@ namespace RGB.NET.Decorators.Gradient
|
||||
/// <see cref="T:RGB.NET.Brushes.Gradients.RainbowGradient" />: 1 unit = 1 degree.</param>
|
||||
/// <param name="direction">The direction the <see cref="T:RGB.NET.Brushes.Gradients.IGradient" /> is moved.
|
||||
/// True leads to an offset-increment (normaly moving to the right), false to an offset-decrement (normaly moving to the left).</param>
|
||||
public MoveGradientDecorator(double speed = 180.0, bool direction = true)
|
||||
public MoveGradientDecorator(RGBSurface surface, double speed = 180.0, bool direction = true)
|
||||
: base(surface)
|
||||
{
|
||||
this.Speed = speed;
|
||||
this.Direction = direction;
|
||||
|
||||
@ -150,7 +150,6 @@ namespace RGB.NET.Devices.Corsair
|
||||
deviceUpdateQueue = new CorsairDeviceUpdateQueue(UpdateTrigger, info.CorsairDeviceIndex);
|
||||
|
||||
device.Initialize(deviceUpdateQueue);
|
||||
AddSpecialParts(device);
|
||||
|
||||
error = LastError;
|
||||
if (error != CorsairError.Success)
|
||||
@ -265,12 +264,6 @@ namespace RGB.NET.Devices.Corsair
|
||||
return CorsairLedId.Invalid;
|
||||
}
|
||||
|
||||
private void AddSpecialParts(ICorsairRGBDevice device)
|
||||
{
|
||||
if (device.DeviceInfo.Model.Equals("K95 RGB Platinum", StringComparison.OrdinalIgnoreCase))
|
||||
device.AddSpecialDevicePart(new LightbarSpecialPart(device));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public void ResetDevices()
|
||||
{
|
||||
|
||||
@ -1,79 +0,0 @@
|
||||
// ReSharper disable UnusedMember.Global
|
||||
// ReSharper disable MemberCanBePrivate.Global
|
||||
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Linq;
|
||||
using RGB.NET.Core;
|
||||
|
||||
namespace RGB.NET.Devices.Corsair
|
||||
{
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Represents a lightbar attached to a <see cref="T:RGB.NET.Core.IRGBDevice" />
|
||||
/// </summary>
|
||||
public class LightbarSpecialPart : IRGBDeviceSpecialPart
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private List<Led> _leds;
|
||||
/// <summary>
|
||||
/// Gets a readonly collection of all <see cref="Led"/> of this <see cref="LightbarSpecialPart"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<Led> Leds => new ReadOnlyCollection<Led>(_leds);
|
||||
|
||||
private List<Led> _left;
|
||||
/// <summary>
|
||||
/// Gets a readonly collection of all <see cref="Led"/> in the left half of this <see cref="LightbarSpecialPart"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<Led> Left => new ReadOnlyCollection<Led>(_left);
|
||||
|
||||
private List<Led> _right;
|
||||
/// <summary>
|
||||
/// Gets a readonly collection of all <see cref="Led"/> in the right half of this <see cref="LightbarSpecialPart"/>.
|
||||
/// </summary>
|
||||
public IEnumerable<Led> Right => new ReadOnlyCollection<Led>(_right);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the Center <see cref="Led"/> of this <see cref="LightbarSpecialPart"/>.
|
||||
/// </summary>
|
||||
public Led Center { get; }
|
||||
|
||||
#endregion
|
||||
|
||||
#region Constructors
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="LightbarSpecialPart"/> class.
|
||||
/// </summary>
|
||||
/// <param name="device">The device associated with this <see cref="IRGBDeviceSpecialPart"/>.</param>
|
||||
public LightbarSpecialPart(IRGBDevice device)
|
||||
{
|
||||
_leds = device.Where(led => ((CorsairLedId)led.CustomData >= CorsairLedId.Lightbar1) && ((CorsairLedId)led.CustomData <= CorsairLedId.Lightbar19)).ToList();
|
||||
_left = _leds.Where(led => (CorsairLedId)led.CustomData < CorsairLedId.Lightbar10).ToList();
|
||||
_right = _leds.Where(led => (CorsairLedId)led.CustomData > CorsairLedId.Lightbar10).ToList();
|
||||
Center = _leds.FirstOrDefault(led => (CorsairLedId)led.CustomData == CorsairLedId.Lightbar10);
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all <see cref="T:RGB.NET.Core.Led" /> of the <see cref="T:RGB.NET.Core.IRGBDeviceSpecialPart" />.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all <see cref="T:RGB.NET.Core.Led" /> of the <see cref="T:RGB.NET.Core.IRGBDeviceSpecialPart" />.</returns>
|
||||
public IEnumerator<Led> GetEnumerator() => _leds.GetEnumerator();
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Returns an enumerator that iterates over all <see cref="T:RGB.NET.Core.Led" /> of the <see cref="T:RGB.NET.Core.IRGBDeviceSpecialPart" />.
|
||||
/// </summary>
|
||||
/// <returns>An enumerator for all <see cref="T:RGB.NET.Core.Led" /> of the <see cref="T:RGB.NET.Core.IRGBDeviceSpecialPart" />.</returns>
|
||||
IEnumerator IEnumerable.GetEnumerator() => GetEnumerator();
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@ -20,12 +20,13 @@ namespace RGB.NET.Groups
|
||||
// ReSharper disable once InvertIf
|
||||
if (!(ledGroup is ListLedGroup listLedGroup))
|
||||
{
|
||||
bool wasAttached = ledGroup.Detach();
|
||||
listLedGroup = new ListLedGroup(wasAttached, ledGroup.GetLeds()) { Brush = ledGroup.Brush };
|
||||
if (ledGroup.Surface != null)
|
||||
ledGroup.Detach(ledGroup.Surface);
|
||||
listLedGroup = new ListLedGroup(ledGroup.Surface, ledGroup.GetLeds()) { Brush = ledGroup.Brush };
|
||||
}
|
||||
return listLedGroup;
|
||||
}
|
||||
|
||||
|
||||
/// <summary>
|
||||
/// Returns a new <see cref="ListLedGroup" /> which contains all <see cref="Led"/> from the given <see cref="ILedGroup"/> excluding the specified ones.
|
||||
/// </summary>
|
||||
@ -46,13 +47,13 @@ namespace RGB.NET.Groups
|
||||
/// </summary>
|
||||
/// <param name="ledGroup">The <see cref="ILedGroup"/> to attach.</param>
|
||||
/// <returns><c>true</c> if the <see cref="ILedGroup"/> could be attached; otherwise, <c>false</c>.</returns>
|
||||
public static bool Attach(this ILedGroup ledGroup) => RGBSurface.Instance.AttachLedGroup(ledGroup);
|
||||
public static bool Attach(this ILedGroup ledGroup, RGBSurface surface) => surface.AttachLedGroup(ledGroup);
|
||||
|
||||
/// <summary>
|
||||
/// Detaches the given <see cref="ILedGroup"/> from the <see cref="RGBSurface"/>.
|
||||
/// </summary>
|
||||
/// <param name="ledGroup">The <see cref="ILedGroup"/> to attach.</param>
|
||||
/// <returns><c>true</c> if the <see cref="ILedGroup"/> could be detached; otherwise, <c>false</c>.</returns>
|
||||
public static bool Detach(this ILedGroup ledGroup) => RGBSurface.Instance.DetachLedGroup(ledGroup);
|
||||
public static bool Detach(this ILedGroup ledGroup, RGBSurface surface) => surface.DetachLedGroup(ledGroup);
|
||||
}
|
||||
}
|
||||
|
||||
@ -28,36 +28,18 @@ namespace RGB.NET.Groups
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Groups.ListLedGroup" /> class.
|
||||
/// </summary>
|
||||
/// <param name="autoAttach">Specifies whether this <see cref="T:RGB.NET.Groups.ListLedGroup" /> should be automatically attached or not.</param>
|
||||
public ListLedGroup(bool autoAttach = true)
|
||||
: base(autoAttach)
|
||||
public ListLedGroup(RGBSurface? surface)
|
||||
: base(surface)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Groups.ListLedGroup" /> class.
|
||||
/// </summary>
|
||||
/// <param name="leds">The initial <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.ListLedGroup" />.</param>
|
||||
public ListLedGroup(params Led[] leds)
|
||||
: this(true, leds)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Groups.ListLedGroup" /> class.
|
||||
/// </summary>
|
||||
/// <param name="leds">The initial <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.ListLedGroup" />.</param>
|
||||
public ListLedGroup(IEnumerable<Led> leds)
|
||||
: this(true, leds)
|
||||
{ }
|
||||
|
||||
|
||||
/// <inheritdoc />
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="T:RGB.NET.Groups.ListLedGroup" /> class.
|
||||
/// </summary>
|
||||
/// <param name="autoAttach">Specifies whether this <see cref="T:RGB.NET.Groups.ListLedGroup" /> should be automatically attached or not.</param>
|
||||
/// <param name="leds">The initial <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.ListLedGroup" />.</param>
|
||||
public ListLedGroup(bool autoAttach, IEnumerable<Led> leds)
|
||||
: base(autoAttach)
|
||||
public ListLedGroup(RGBSurface? surface, IEnumerable<Led> leds)
|
||||
: base(surface)
|
||||
{
|
||||
AddLeds(leds);
|
||||
}
|
||||
@ -68,8 +50,8 @@ namespace RGB.NET.Groups
|
||||
/// </summary>
|
||||
/// <param name="autoAttach">Specifies whether this <see cref="T:RGB.NET.Groups.ListLedGroup" /> should be automatically attached or not.</param>
|
||||
/// <param name="leds">The initial <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.ListLedGroup" />.</param>
|
||||
public ListLedGroup(bool autoAttach, params Led[] leds)
|
||||
: base(autoAttach)
|
||||
public ListLedGroup(RGBSurface? surface, params Led[] leds)
|
||||
: base(surface)
|
||||
{
|
||||
AddLeds(leds);
|
||||
}
|
||||
|
||||
@ -16,7 +16,7 @@ namespace RGB.NET.Groups
|
||||
{
|
||||
#region Properties & Fields
|
||||
|
||||
private IList<Led> _ledCache;
|
||||
private IList<Led>? _ledCache;
|
||||
|
||||
private Rectangle _rectangle;
|
||||
/// <summary>
|
||||
@ -58,8 +58,8 @@ namespace RGB.NET.Groups
|
||||
/// <param name="toLed">They second <see cref="T:RGB.NET.Core.Led" /> to calculate the <see cref="T:RGB.NET.Core.Rectangle" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" /> from.</param>
|
||||
/// <param name="minOverlayPercentage">(optional) The minimal percentage overlay a <see cref="T:RGB.NET.Core.Led" /> must have with the <see cref="P:RGB.NET.Groups.RectangleLedGroup.Rectangle" /> to be taken into the <see cref="T:RGB.NET.Groups.RectangleLedGroup" />. (default: 0.5)</param>
|
||||
/// <param name="autoAttach">(optional) Specifies whether this <see cref="T:RGB.NET.Groups.RectangleLedGroup" /> should be automatically attached or not. (default: true)</param>
|
||||
public RectangleLedGroup(Led fromLed, Led toLed, double minOverlayPercentage = 0.5, bool autoAttach = true)
|
||||
: this(new Rectangle(fromLed.LedRectangle, toLed.LedRectangle), minOverlayPercentage, autoAttach)
|
||||
public RectangleLedGroup(RGBSurface? surface, Led fromLed, Led toLed, double minOverlayPercentage = 0.5)
|
||||
: this(surface, new Rectangle(fromLed.LedRectangle, toLed.LedRectangle), minOverlayPercentage)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -70,8 +70,8 @@ namespace RGB.NET.Groups
|
||||
/// <param name="toPoint">They second point to calculate the <see cref="T:RGB.NET.Core.Rectangle" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" /> from.</param>
|
||||
/// <param name="minOverlayPercentage">(optional) The minimal percentage overlay a <see cref="T:RGB.NET.Core.Led" /> must have with the <see cref="P:RGB.NET.Groups.RectangleLedGroup.Rectangle" /> to be taken into the <see cref="T:RGB.NET.Groups.RectangleLedGroup" />. (default: 0.5)</param>
|
||||
/// <param name="autoAttach">(optional) Specifies whether this <see cref="T:RGB.NET.Groups.RectangleLedGroup" /> should be automatically attached or not. (default: true)</param>
|
||||
public RectangleLedGroup(Point fromPoint, Point toPoint, double minOverlayPercentage = 0.5, bool autoAttach = true)
|
||||
: this(new Rectangle(fromPoint, toPoint), minOverlayPercentage, autoAttach)
|
||||
public RectangleLedGroup(RGBSurface? surface, Point fromPoint, Point toPoint, double minOverlayPercentage = 0.5)
|
||||
: this(surface, new Rectangle(fromPoint, toPoint), minOverlayPercentage)
|
||||
{ }
|
||||
|
||||
/// <inheritdoc />
|
||||
@ -81,8 +81,8 @@ namespace RGB.NET.Groups
|
||||
/// <param name="rectangle">The <see cref="T:RGB.NET.Core.Rectangle" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.</param>
|
||||
/// <param name="minOverlayPercentage">(optional) The minimal percentage overlay a <see cref="T:RGB.NET.Core.Led" /> must have with the <see cref="P:RGB.NET.Groups.RectangleLedGroup.Rectangle" /> to be taken into the <see cref="T:RGB.NET.Groups.RectangleLedGroup" />. (default: 0.5)</param>
|
||||
/// <param name="autoAttach">(optional) Specifies whether this <see cref="T:RGB.NET.Groups.RectangleLedGroup" /> should be automatically attached or not. (default: true)</param>
|
||||
public RectangleLedGroup(Rectangle rectangle, double minOverlayPercentage = 0.5, bool autoAttach = true)
|
||||
: base(autoAttach)
|
||||
public RectangleLedGroup(RGBSurface? surface, Rectangle rectangle, double minOverlayPercentage = 0.5)
|
||||
: base(surface)
|
||||
{
|
||||
this.Rectangle = rectangle;
|
||||
this.MinOverlayPercentage = minOverlayPercentage;
|
||||
@ -93,10 +93,22 @@ namespace RGB.NET.Groups
|
||||
#region Methods
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnAttach() => RGBSurface.Instance.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged;
|
||||
public override void OnAttach(RGBSurface surface)
|
||||
{
|
||||
base.OnAttach(surface);
|
||||
|
||||
if (Surface != null)
|
||||
Surface.SurfaceLayoutChanged += RGBSurfaceOnSurfaceLayoutChanged;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnDetach() => RGBSurface.Instance.SurfaceLayoutChanged -= RGBSurfaceOnSurfaceLayoutChanged;
|
||||
public override void OnDetach(RGBSurface surface)
|
||||
{
|
||||
if (Surface != null)
|
||||
Surface.SurfaceLayoutChanged -= RGBSurfaceOnSurfaceLayoutChanged;
|
||||
|
||||
base.OnDetach(surface);
|
||||
}
|
||||
|
||||
private void RGBSurfaceOnSurfaceLayoutChanged(SurfaceLayoutChangedEventArgs args) => InvalidateCache();
|
||||
|
||||
@ -105,7 +117,7 @@ namespace RGB.NET.Groups
|
||||
/// Gets a list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.
|
||||
/// </summary>
|
||||
/// <returns>The list containing all <see cref="T:RGB.NET.Core.Led" /> of this <see cref="T:RGB.NET.Groups.RectangleLedGroup" />.</returns>
|
||||
public override IList<Led> GetLeds() => _ledCache ??= RGBSurface.Instance.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList();
|
||||
public override IList<Led> GetLeds() => _ledCache ??= (Surface?.Leds.Where(led => led.AbsoluteLedRectangle.CalculateIntersectPercentage(Rectangle) >= MinOverlayPercentage).ToList() ?? new());
|
||||
|
||||
private void InvalidateCache() => _ledCache = null;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user