mirror of
https://git.ryujinx.app/ryubing/ryujinx.git
synced 2025-06-28 06:46:24 +02:00
misc: chore: Pass rainbow color by reference in the event instead of passing around a packed int.
This commit is contained in:
parent
023bd5f00f
commit
71d8cfd232
5 changed files with 67 additions and 10 deletions
58
src/Ryujinx.Common/Helpers/RefEvent.cs
Normal file
58
src/Ryujinx.Common/Helpers/RefEvent.cs
Normal file
|
@ -0,0 +1,58 @@
|
|||
using Gommon;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading;
|
||||
|
||||
namespace Ryujinx.Common.Helper
|
||||
{
|
||||
public class RefEvent<T>
|
||||
{
|
||||
public delegate void Handler(ref T arg);
|
||||
|
||||
private readonly Lock _subLock = new();
|
||||
private readonly List<Handler> _subscriptions = [];
|
||||
|
||||
public bool HasSubscribers
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_subLock)
|
||||
return _subscriptions.Count != 0;
|
||||
}
|
||||
}
|
||||
|
||||
public IReadOnlyList<Handler> Subscriptions
|
||||
{
|
||||
get
|
||||
{
|
||||
lock (_subLock)
|
||||
return _subscriptions;
|
||||
}
|
||||
}
|
||||
|
||||
public void Add(Handler subscriber)
|
||||
{
|
||||
Guard.Require(subscriber, nameof(subscriber));
|
||||
lock (_subLock)
|
||||
_subscriptions.Add(subscriber);
|
||||
}
|
||||
|
||||
public void Remove(Handler subscriber)
|
||||
{
|
||||
Guard.Require(subscriber, nameof(subscriber));
|
||||
lock (_subLock)
|
||||
_subscriptions.Remove(subscriber);
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
lock (_subLock)
|
||||
_subscriptions.Clear();
|
||||
}
|
||||
|
||||
public void Call(ref T arg)
|
||||
{
|
||||
foreach (Handler subscription in Subscriptions)
|
||||
subscription(ref arg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,4 +1,5 @@
|
|||
using Gommon;
|
||||
using Ryujinx.Common.Helper;
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Threading;
|
||||
|
@ -55,7 +56,7 @@ namespace Ryujinx.Common.Utilities
|
|||
{
|
||||
_color = HsbToRgb((_color.GetHue() + Speed) / 360);
|
||||
|
||||
_updatedHandler.Call(_color.ToArgb());
|
||||
_updatedHandler.Call(ref _color);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -67,13 +68,13 @@ namespace Ryujinx.Common.Utilities
|
|||
_color = Color.Blue;
|
||||
}
|
||||
|
||||
public static event Action<int> Updated
|
||||
public static event RefEvent<Color>.Handler Updated
|
||||
{
|
||||
add => _updatedHandler.Add(value);
|
||||
remove => _updatedHandler.Remove(value);
|
||||
}
|
||||
|
||||
private static readonly Event<int> _updatedHandler = new();
|
||||
private static readonly RefEvent<Color> _updatedHandler = new();
|
||||
|
||||
private static Color HsbToRgb(float hue, float saturation = 1, float brightness = 1)
|
||||
{
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue