mirror of
https://github.com/DarthAffe/RGB.NET.git
synced 2025-12-13 10:08:31 +00:00
commit
020f249f9a
@ -27,9 +27,9 @@ public abstract class AbstractBindable : IBindable
|
|||||||
/// <typeparam name="T">Type of the property.</typeparam>
|
/// <typeparam name="T">Type of the property.</typeparam>
|
||||||
/// <param name="storage">Reference to the backing-filed.</param>
|
/// <param name="storage">Reference to the backing-filed.</param>
|
||||||
/// <param name="value">Value to apply.</param>
|
/// <param name="value">Value to apply.</param>
|
||||||
/// <returns><c>true</c> if the value needs to be updated; otherweise <c>false</c>.</returns>
|
/// <returns><c>true</c> if the value needs to be updated; otherwise <c>false</c>.</returns>
|
||||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||||
protected virtual bool RequiresUpdate<T>(ref T storage, T value) => !EqualityComparer<T>.Default.Equals(storage, value);
|
protected bool RequiresUpdate<T>(ref T storage, T value) => !EqualityComparer<T>.Default.Equals(storage, value);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Checks if the property already matches the desired value and updates it if not.
|
/// Checks if the property already matches the desired value and updates it if not.
|
||||||
@ -40,7 +40,7 @@ public abstract class AbstractBindable : IBindable
|
|||||||
/// <param name="propertyName">Name of the property used to notify listeners. This value is optional
|
/// <param name="propertyName">Name of the property used to notify listeners. This value is optional
|
||||||
/// and can be provided automatically when invoked from compilers that support <see cref="CallerMemberNameAttribute"/>.</param>
|
/// and can be provided automatically when invoked from compilers that support <see cref="CallerMemberNameAttribute"/>.</param>
|
||||||
/// <returns><c>true</c> if the value was changed, <c>false</c> if the existing value matched the desired value.</returns>
|
/// <returns><c>true</c> if the value was changed, <c>false</c> if the existing value matched the desired value.</returns>
|
||||||
protected virtual bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string? propertyName = null)
|
protected bool SetProperty<T>(ref T storage, T value, [CallerMemberName] string? propertyName = null)
|
||||||
{
|
{
|
||||||
if (!RequiresUpdate(ref storage, value)) return false;
|
if (!RequiresUpdate(ref storage, value)) return false;
|
||||||
|
|
||||||
@ -55,7 +55,7 @@ public abstract class AbstractBindable : IBindable
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
/// <param name="propertyName">Name of the property used to notify listeners. This value is optional
|
/// <param name="propertyName">Name of the property used to notify listeners. This value is optional
|
||||||
/// and can be provided automatically when invoked from compilers that support <see cref="CallerMemberNameAttribute"/>.</param>
|
/// and can be provided automatically when invoked from compilers that support <see cref="CallerMemberNameAttribute"/>.</param>
|
||||||
protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
protected void OnPropertyChanged([CallerMemberName] string? propertyName = null)
|
||||||
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
=> PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -74,10 +74,14 @@ public abstract class AbstractBrush : AbstractDecoratable<IBrushDecorator>, IBru
|
|||||||
if (Decorators.Count == 0) return;
|
if (Decorators.Count == 0) return;
|
||||||
|
|
||||||
lock (Decorators)
|
lock (Decorators)
|
||||||
foreach (IBrushDecorator decorator in Decorators)
|
// ReSharper disable once ForCanBeConvertedToForeach - Sadly this does not get optimized reliably and causes allocations if foreached
|
||||||
|
for (int i = 0; i < Decorators.Count; i++)
|
||||||
|
{
|
||||||
|
IBrushDecorator decorator = Decorators[i];
|
||||||
if (decorator.IsEnabled)
|
if (decorator.IsEnabled)
|
||||||
decorator.ManipulateColor(rectangle, renderTarget, ref color);
|
decorator.ManipulateColor(rectangle, renderTarget, ref color);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets the color at an specific point assuming the brush is drawn into the specified rectangle.
|
/// Gets the color at an specific point assuming the brush is drawn into the specified rectangle.
|
||||||
|
|||||||
@ -32,6 +32,8 @@ public sealed class SolidColorBrush : AbstractBrush
|
|||||||
public SolidColorBrush(Color color)
|
public SolidColorBrush(Color color)
|
||||||
{
|
{
|
||||||
this.Color = color;
|
this.Color = color;
|
||||||
|
|
||||||
|
CalculationMode = RenderMode.Absolute;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
|
|
||||||
namespace RGB.NET.Core;
|
namespace RGB.NET.Core;
|
||||||
|
|
||||||
@ -41,7 +40,7 @@ public sealed class AverageColorSampler : ISampler<Color>
|
|||||||
{
|
{
|
||||||
ReadOnlySpan<Color> data = info[y];
|
ReadOnlySpan<Color> data = info[y];
|
||||||
|
|
||||||
fixed (Color* colorPtr = &MemoryMarshal.GetReference(data))
|
fixed (Color* colorPtr = data)
|
||||||
{
|
{
|
||||||
Color* current = colorPtr;
|
Color* current = colorPtr;
|
||||||
for (int i = 0; i < chunks; i++)
|
for (int i = 0; i < chunks; i++)
|
||||||
|
|||||||
@ -133,7 +133,7 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
|
|||||||
/// <summary>
|
/// <summary>
|
||||||
/// Stops the trigger.
|
/// Stops the trigger.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public async void Stop()
|
public virtual async void Stop()
|
||||||
{
|
{
|
||||||
if (!IsRunning) return;
|
if (!IsRunning) return;
|
||||||
|
|
||||||
@ -141,7 +141,9 @@ public class DeviceUpdateTrigger : AbstractUpdateTrigger, IDeviceUpdateTrigger
|
|||||||
|
|
||||||
UpdateTokenSource?.Cancel();
|
UpdateTokenSource?.Cancel();
|
||||||
if (UpdateTask != null)
|
if (UpdateTask != null)
|
||||||
await UpdateTask;
|
try { await UpdateTask.ConfigureAwait(false); }
|
||||||
|
catch (TaskCanceledException) { }
|
||||||
|
catch (OperationCanceledException) { }
|
||||||
|
|
||||||
UpdateTask?.Dispose();
|
UpdateTask?.Dispose();
|
||||||
UpdateTask = null;
|
UpdateTask = null;
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace RGB.NET.Presets.Textures.Sampler;
|
namespace RGB.NET.Presets.Textures.Sampler;
|
||||||
@ -42,7 +41,7 @@ public sealed class AverageByteSampler : ISampler<byte>
|
|||||||
{
|
{
|
||||||
ReadOnlySpan<byte> data = info[y];
|
ReadOnlySpan<byte> data = info[y];
|
||||||
|
|
||||||
fixed (byte* colorPtr = &MemoryMarshal.GetReference(data))
|
fixed (byte* colorPtr = data)
|
||||||
{
|
{
|
||||||
byte* current = colorPtr;
|
byte* current = colorPtr;
|
||||||
for (int i = 0; i < chunks; i++)
|
for (int i = 0; i < chunks; i++)
|
||||||
|
|||||||
@ -1,6 +1,5 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Numerics;
|
using System.Numerics;
|
||||||
using System.Runtime.InteropServices;
|
|
||||||
using RGB.NET.Core;
|
using RGB.NET.Core;
|
||||||
|
|
||||||
namespace RGB.NET.Presets.Textures.Sampler;
|
namespace RGB.NET.Presets.Textures.Sampler;
|
||||||
@ -33,7 +32,7 @@ public sealed class AverageFloatSampler : ISampler<float>
|
|||||||
{
|
{
|
||||||
ReadOnlySpan<float> data = info[y];
|
ReadOnlySpan<float> data = info[y];
|
||||||
|
|
||||||
fixed (float* colorPtr = &MemoryMarshal.GetReference(data))
|
fixed (float* colorPtr = data)
|
||||||
{
|
{
|
||||||
float* current = colorPtr;
|
float* current = colorPtr;
|
||||||
for (int i = 0; i < chunks; i++)
|
for (int i = 0; i < chunks; i++)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user