forked from Ryubing/Ryujinx
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add option to change controller LED color (Ryubing#572)
This allows the user to change the controller LED while using Ryujinx. Useful for PS4 and PS5 controllers as an example. You can also use a spectrum-cycling Rainbow color option, or turn the LED off for DualSense controllers. --------- Co-authored-by: Evan Husted <greem@greemdev.net>
- Loading branch information
1 parent
534ea15
commit 97d8720
Showing
24 changed files
with
389 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
using System; | ||
using System.Drawing; | ||
|
||
namespace Ryujinx.Common.Utilities | ||
{ | ||
public class Rainbow | ||
{ | ||
public const float Speed = 1; | ||
|
||
public static Color Color { get; private set; } = Color.Blue; | ||
|
||
public static void Tick() | ||
{ | ||
Color = HsbToRgb( | ||
(Color.GetHue() + Speed) / 360, | ||
1, | ||
1 | ||
); | ||
|
||
RainbowColorUpdated?.Invoke(Color.ToArgb()); | ||
} | ||
|
||
public static event Action<int> RainbowColorUpdated; | ||
|
||
private static Color HsbToRgb(float hue, float saturation, float brightness) | ||
{ | ||
int r = 0, g = 0, b = 0; | ||
if (saturation == 0) | ||
{ | ||
r = g = b = (int)(brightness * 255.0f + 0.5f); | ||
} | ||
else | ||
{ | ||
float h = (hue - (float)Math.Floor(hue)) * 6.0f; | ||
float f = h - (float)Math.Floor(h); | ||
float p = brightness * (1.0f - saturation); | ||
float q = brightness * (1.0f - saturation * f); | ||
float t = brightness * (1.0f - (saturation * (1.0f - f))); | ||
switch ((int)h) | ||
{ | ||
case 0: | ||
r = (int)(brightness * 255.0f + 0.5f); | ||
g = (int)(t * 255.0f + 0.5f); | ||
b = (int)(p * 255.0f + 0.5f); | ||
break; | ||
case 1: | ||
r = (int)(q * 255.0f + 0.5f); | ||
g = (int)(brightness * 255.0f + 0.5f); | ||
b = (int)(p * 255.0f + 0.5f); | ||
break; | ||
case 2: | ||
r = (int)(p * 255.0f + 0.5f); | ||
g = (int)(brightness * 255.0f + 0.5f); | ||
b = (int)(t * 255.0f + 0.5f); | ||
break; | ||
case 3: | ||
r = (int)(p * 255.0f + 0.5f); | ||
g = (int)(q * 255.0f + 0.5f); | ||
b = (int)(brightness * 255.0f + 0.5f); | ||
break; | ||
case 4: | ||
r = (int)(t * 255.0f + 0.5f); | ||
g = (int)(p * 255.0f + 0.5f); | ||
b = (int)(brightness * 255.0f + 0.5f); | ||
break; | ||
case 5: | ||
r = (int)(brightness * 255.0f + 0.5f); | ||
g = (int)(p * 255.0f + 0.5f); | ||
b = (int)(q * 255.0f + 0.5f); | ||
break; | ||
} | ||
} | ||
return Color.FromArgb(Convert.ToByte(255), Convert.ToByte(r), Convert.ToByte(g), Convert.ToByte(b)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.