Rainbow LED
This commit is contained in:
parent
8a22d9a942
commit
e8025e175d
@ -12,6 +12,11 @@
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public bool TurnOffLed { get; set; }
|
public bool TurnOffLed { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Ignores the color and uses the rainbow color functionality for the LED.
|
||||||
|
/// </summary>
|
||||||
|
public bool UseRainbow { get; set; }
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Packed RGB int of the color
|
/// Packed RGB int of the color
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
76
src/Ryujinx.Common/Utilities/Rainbow.cs
Normal file
76
src/Ryujinx.Common/Utilities/Rainbow.cs
Normal file
@ -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));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -1,6 +1,7 @@
|
|||||||
using Ryujinx.Common.Configuration.Hid;
|
using Ryujinx.Common.Configuration.Hid;
|
||||||
using Ryujinx.Common.Configuration.Hid.Controller;
|
using Ryujinx.Common.Configuration.Hid.Controller;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
|
using Ryujinx.Common.Utilities;
|
||||||
using Ryujinx.HLE.HOS.Services.Hid;
|
using Ryujinx.HLE.HOS.Services.Hid;
|
||||||
using SDL2;
|
using SDL2;
|
||||||
using System;
|
using System;
|
||||||
@ -235,8 +236,11 @@ namespace Ryujinx.Input.SDL2
|
|||||||
{
|
{
|
||||||
if (_configuration.Led.TurnOffLed)
|
if (_configuration.Led.TurnOffLed)
|
||||||
(this as IGamepad).ClearLed();
|
(this as IGamepad).ClearLed();
|
||||||
|
else if (_configuration.Led.UseRainbow)
|
||||||
|
Rainbow.RainbowColorUpdated += clr => SetLed((uint)clr);
|
||||||
else
|
else
|
||||||
SetLed(_configuration.Led.LedColor);
|
SetLed(_configuration.Led.LedColor);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
_buttonsUserMapping.Clear();
|
_buttonsUserMapping.Clear();
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
using Ryujinx.Common.Configuration;
|
using Ryujinx.Common.Configuration;
|
||||||
using Ryujinx.Common.Logging;
|
using Ryujinx.Common.Logging;
|
||||||
|
using Ryujinx.Common.Utilities;
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Concurrent;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
@ -167,6 +168,8 @@ namespace Ryujinx.SDL2.Common
|
|||||||
HandleSDLEvent(ref evnt);
|
HandleSDLEvent(ref evnt);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Rainbow.Tick();
|
||||||
|
|
||||||
waitHandle.Wait(WaitTimeMs);
|
waitHandle.Wait(WaitTimeMs);
|
||||||
}
|
}
|
||||||
|
@ -7628,7 +7628,7 @@
|
|||||||
"ar_SA": "",
|
"ar_SA": "",
|
||||||
"de_DE": "",
|
"de_DE": "",
|
||||||
"el_GR": "",
|
"el_GR": "",
|
||||||
"en_US": "Custom LED",
|
"en_US": "LED",
|
||||||
"es_ES": "",
|
"es_ES": "",
|
||||||
"fr_FR": "",
|
"fr_FR": "",
|
||||||
"he_IL": "",
|
"he_IL": "",
|
||||||
@ -7672,6 +7672,31 @@
|
|||||||
"zh_TW": ""
|
"zh_TW": ""
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"ID": "ControllerSettingsLedColorRainbow",
|
||||||
|
"Translations": {
|
||||||
|
"ar_SA": "",
|
||||||
|
"de_DE": "",
|
||||||
|
"el_GR": "",
|
||||||
|
"en_US": "Rainbow",
|
||||||
|
"es_ES": "",
|
||||||
|
"fr_FR": "",
|
||||||
|
"he_IL": "",
|
||||||
|
"it_IT": "",
|
||||||
|
"ja_JP": "",
|
||||||
|
"ko_KR": "",
|
||||||
|
"no_NO": "",
|
||||||
|
"pl_PL": "",
|
||||||
|
"pt_BR": "",
|
||||||
|
"ru_RU": "",
|
||||||
|
"sv_SE": "",
|
||||||
|
"th_TH": "",
|
||||||
|
"tr_TR": "",
|
||||||
|
"uk_UA": "",
|
||||||
|
"zh_CN": "",
|
||||||
|
"zh_TW": ""
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"ID": "ControllerSettingsSave",
|
"ID": "ControllerSettingsSave",
|
||||||
"Translations": {
|
"Translations": {
|
||||||
@ -23023,4 +23048,4 @@
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -388,42 +388,6 @@ namespace Ryujinx.Ava.UI.Models.Input
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private bool _enableLedChanging;
|
|
||||||
|
|
||||||
public bool EnableLedChanging
|
|
||||||
{
|
|
||||||
get => _enableLedChanging;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_enableLedChanging = value;
|
|
||||||
OnPropertyChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _turnOffLed;
|
|
||||||
|
|
||||||
public bool TurnOffLed
|
|
||||||
{
|
|
||||||
get => _turnOffLed;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_turnOffLed = value;
|
|
||||||
OnPropertyChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Color _ledColor;
|
|
||||||
|
|
||||||
public Color LedColor
|
|
||||||
{
|
|
||||||
get => _ledColor;
|
|
||||||
set
|
|
||||||
{
|
|
||||||
_ledColor = value;
|
|
||||||
OnPropertyChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private bool _enableMotion;
|
private bool _enableMotion;
|
||||||
public bool EnableMotion
|
public bool EnableMotion
|
||||||
{
|
{
|
||||||
@ -445,6 +409,58 @@ namespace Ryujinx.Ava.UI.Models.Input
|
|||||||
OnPropertyChanged();
|
OnPropertyChanged();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private bool _enableLedChanging;
|
||||||
|
|
||||||
|
public bool EnableLedChanging
|
||||||
|
{
|
||||||
|
get => _enableLedChanging;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_enableLedChanging = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool ShowLedColorPicker => !TurnOffLed && !UseRainbowLed;
|
||||||
|
|
||||||
|
private bool _turnOffLed;
|
||||||
|
|
||||||
|
public bool TurnOffLed
|
||||||
|
{
|
||||||
|
get => _turnOffLed;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_turnOffLed = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
OnPropertyChanged(nameof(ShowLedColorPicker));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private bool _useRainbowLed;
|
||||||
|
|
||||||
|
public bool UseRainbowLed
|
||||||
|
{
|
||||||
|
get => _useRainbowLed;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_useRainbowLed = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
OnPropertyChanged(nameof(ShowLedColorPicker));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private Color _ledColor;
|
||||||
|
|
||||||
|
public Color LedColor
|
||||||
|
{
|
||||||
|
get => _ledColor;
|
||||||
|
set
|
||||||
|
{
|
||||||
|
_ledColor = value;
|
||||||
|
OnPropertyChanged();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public GamepadInputConfig(InputConfig config)
|
public GamepadInputConfig(InputConfig config)
|
||||||
{
|
{
|
||||||
@ -525,6 +541,7 @@ namespace Ryujinx.Ava.UI.Models.Input
|
|||||||
{
|
{
|
||||||
EnableLedChanging = controllerInput.Led.EnableLed;
|
EnableLedChanging = controllerInput.Led.EnableLed;
|
||||||
TurnOffLed = controllerInput.Led.TurnOffLed;
|
TurnOffLed = controllerInput.Led.TurnOffLed;
|
||||||
|
UseRainbowLed = controllerInput.Led.UseRainbow;
|
||||||
uint rawColor = controllerInput.Led.LedColor;
|
uint rawColor = controllerInput.Led.LedColor;
|
||||||
byte alpha = (byte)(rawColor >> 24);
|
byte alpha = (byte)(rawColor >> 24);
|
||||||
byte red = (byte)(rawColor >> 16);
|
byte red = (byte)(rawColor >> 16);
|
||||||
@ -593,6 +610,7 @@ namespace Ryujinx.Ava.UI.Models.Input
|
|||||||
{
|
{
|
||||||
EnableLed = EnableLedChanging,
|
EnableLed = EnableLedChanging,
|
||||||
TurnOffLed = this.TurnOffLed,
|
TurnOffLed = this.TurnOffLed,
|
||||||
|
UseRainbow = UseRainbowLed,
|
||||||
LedColor = LedColor.ToUInt32()
|
LedColor = LedColor.ToUInt32()
|
||||||
},
|
},
|
||||||
Version = InputConfig.CurrentVersion,
|
Version = InputConfig.CurrentVersion,
|
||||||
|
@ -495,19 +495,20 @@
|
|||||||
Margin="0,-1,0,0">
|
Margin="0,-1,0,0">
|
||||||
<Grid IsVisible="{Binding ParentModel.HasLed}">
|
<Grid IsVisible="{Binding ParentModel.HasLed}">
|
||||||
<Grid.ColumnDefinitions>
|
<Grid.ColumnDefinitions>
|
||||||
|
<ColumnDefinition Width="Auto" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="*" />
|
<ColumnDefinition Width="*" />
|
||||||
<ColumnDefinition Width="Auto" />
|
<ColumnDefinition Width="Auto" />
|
||||||
</Grid.ColumnDefinitions>
|
</Grid.ColumnDefinitions>
|
||||||
<CheckBox
|
<CheckBox
|
||||||
Margin="10"
|
Margin="10, 10, 5, 10"
|
||||||
MinWidth="0"
|
MinWidth="0"
|
||||||
Grid.Column="0"
|
Grid.Column="0"
|
||||||
IsChecked="{Binding Config.EnableLedChanging, Mode=TwoWay}">
|
IsChecked="{Binding Config.EnableLedChanging, Mode=TwoWay}">
|
||||||
<TextBlock Text="{ext:Locale ControllerSettingsLedColor}" />
|
<TextBlock Text="{ext:Locale ControllerSettingsLedColor}" />
|
||||||
</CheckBox>
|
</CheckBox>
|
||||||
<CheckBox
|
<CheckBox
|
||||||
Margin="10"
|
Margin="5, 10, 5, 10"
|
||||||
MinWidth="0"
|
MinWidth="0"
|
||||||
Grid.Column="1"
|
Grid.Column="1"
|
||||||
IsVisible="{Binding ParentModel.CanClearLed}"
|
IsVisible="{Binding ParentModel.CanClearLed}"
|
||||||
@ -515,10 +516,18 @@
|
|||||||
Command="{Binding LedDisabledChanged}">
|
Command="{Binding LedDisabledChanged}">
|
||||||
<TextBlock Text="{ext:Locale ControllerSettingsLedColorDisable}" />
|
<TextBlock Text="{ext:Locale ControllerSettingsLedColorDisable}" />
|
||||||
</CheckBox>
|
</CheckBox>
|
||||||
<ui:ColorPickerButton
|
<CheckBox
|
||||||
|
Margin="5, 10 5,10"
|
||||||
|
MinWidth="0"
|
||||||
Grid.Column="2"
|
Grid.Column="2"
|
||||||
IsEnabled="{Binding !Config.TurnOffLed}"
|
IsEnabled="{Binding !Config.TurnOffLed}"
|
||||||
Margin="10"
|
IsChecked="{Binding Config.UseRainbowLed, Mode=TwoWay}">
|
||||||
|
<TextBlock Text="Rainbow" />
|
||||||
|
</CheckBox>
|
||||||
|
<ui:ColorPickerButton
|
||||||
|
Grid.Column="3"
|
||||||
|
IsEnabled="{Binding Config.ShowLedColorPicker}"
|
||||||
|
Margin="5, 10, 10, 10"
|
||||||
IsMoreButtonVisible="False"
|
IsMoreButtonVisible="False"
|
||||||
UseColorPalette="False"
|
UseColorPalette="False"
|
||||||
UseColorTriangle="False"
|
UseColorTriangle="False"
|
||||||
|
@ -423,6 +423,7 @@ namespace Ryujinx.Ava.Utilities.Configuration
|
|||||||
{
|
{
|
||||||
EnableLed = false,
|
EnableLed = false,
|
||||||
TurnOffLed = false,
|
TurnOffLed = false,
|
||||||
|
UseRainbow = false,
|
||||||
LedColor = new Color(255, 5, 1, 253).ToUInt32()
|
LedColor = new Color(255, 5, 1, 253).ToUInt32()
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user