mirror of
https://github.com/SpaceTimee/Sheas-Cealer.git
synced 2025-07-13 04:42:09 +08:00
1.1.3 -> 1.1.4 第50次更新
This commit is contained in:
parent
2b3ca3f3ee
commit
ef997ad840
@ -15,7 +15,7 @@ public partial class App : Application
|
||||
{
|
||||
protected override void OnStartup(StartupEventArgs e)
|
||||
{
|
||||
_ = new SettingsPres();
|
||||
SettingsPres settingsPres = new();
|
||||
|
||||
#region Primary Color
|
||||
PaletteHelper paletteHelper = new();
|
||||
@ -38,10 +38,12 @@ public partial class App : Application
|
||||
|
||||
#region Foreground Color
|
||||
Style newButtonStyle = new(typeof(Button), Current.Resources[typeof(Button)] as Style);
|
||||
Color? newForegroundColor = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
||||
(Color? newForegroundColor, Color newAccentForegroundColor) = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
||||
|
||||
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
|
||||
Current.Resources[typeof(Button)] = newButtonStyle;
|
||||
|
||||
settingsPres.AccentForegroundColor = newAccentForegroundColor;
|
||||
#endregion Foreground Color
|
||||
|
||||
new MainWin(e.Args).Show();
|
||||
|
18
Convs/AboutAccentButtonForegroundConv.cs
Normal file
18
Convs/AboutAccentButtonForegroundConv.cs
Normal file
@ -0,0 +1,18 @@
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Windows.Data;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace Sheas_Cealer.Convs;
|
||||
|
||||
internal class AboutAccentButtonForegroundConv : IValueConverter
|
||||
{
|
||||
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
|
||||
{
|
||||
Color accentForegroundColor = (Color)value;
|
||||
|
||||
return new SolidColorBrush(accentForegroundColor);
|
||||
}
|
||||
|
||||
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) => throw new NotImplementedException();
|
||||
}
|
@ -1,5 +1,6 @@
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using CommunityToolkit.Mvvm.ComponentModel;
|
||||
using MaterialDesignThemes.Wpf;
|
||||
using Sheas_Cealer.Props;
|
||||
@ -36,4 +37,7 @@ internal partial class GlobalPres : ObservableObject
|
||||
Settings.Default.IsLightTheme = (sbyte)(value.HasValue ? value.Value ? 1 : 0 : -1);
|
||||
Settings.Default.Save();
|
||||
}
|
||||
|
||||
[ObservableProperty]
|
||||
private static Color accentForegroundColor = (Color)ColorConverter.ConvertFromString("#2196f3");
|
||||
}
|
@ -5,16 +5,27 @@ namespace Sheas_Cealer.Utils;
|
||||
|
||||
internal static class ForegroundGenerator
|
||||
{
|
||||
internal static Color? GetForeground(int red, int green, int blue)
|
||||
internal static (Color?, Color) GetForeground(int red, int green, int blue)
|
||||
{
|
||||
double luminance = 0.2126 * GammaCorrect(red / 255.0) + 0.7152 * GammaCorrect(green / 255.0) + 0.0722 * GammaCorrect(blue / 255.0);
|
||||
|
||||
double blackContrast = (luminance + 0.05) / 0.05;
|
||||
double whiteContrast = 1.05 / (luminance + 0.05);
|
||||
|
||||
return blackContrast >= 4 && whiteContrast >= 3 ? null :
|
||||
blackContrast >= whiteContrast ? Color.FromRgb(0, 0, 0) : Color.FromRgb(255, 255, 255);
|
||||
double hue = GetHue(red / 255.0, green / 255.0, blue / 255.0);
|
||||
|
||||
double blueContrast = Math.Min(Math.Abs(hue - 206.57), 360 - Math.Abs(hue - 206.57));
|
||||
double redContrast = Math.Min(Math.Abs(hue), 360 - Math.Abs(hue));
|
||||
|
||||
return (blackContrast >= 4 && whiteContrast >= 3 ? null :
|
||||
blackContrast >= whiteContrast ? Color.FromRgb(0, 0, 0) : Color.FromRgb(255, 255, 255),
|
||||
blueContrast >= redContrast ? (Color)ColorConverter.ConvertFromString("#2196f3") : Color.FromRgb(255, 0, 0));
|
||||
}
|
||||
|
||||
private static double GammaCorrect(double c) => c <= 0.03928 ? c / 12.92 : Math.Pow((c + 0.055) / 1.055, 2.4);
|
||||
private static double GammaCorrect(double component) => component <= 0.03928 ? component / 12.92 : Math.Pow((component + 0.055) / 1.055, 2.4);
|
||||
|
||||
private static double GetHue(double redComponent, double greenComponent, double blueComponent) =>
|
||||
redComponent > greenComponent && redComponent > blueComponent ? 60 * ((greenComponent - blueComponent) / redComponent - Math.Min(greenComponent, blueComponent) + (greenComponent < blueComponent ? 6 : 0)) :
|
||||
greenComponent > blueComponent && greenComponent > redComponent ? 60 * ((blueComponent - redComponent) / greenComponent - Math.Min(blueComponent, redComponent) + 2) :
|
||||
blueComponent > redComponent && blueComponent > greenComponent ? 60 * ((redComponent - greenComponent) / blueComponent - Math.Min(redComponent, greenComponent) + 4) : 0;
|
||||
}
|
@ -22,11 +22,26 @@
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
|
||||
<Button Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" Foreground="#2196F3" Content="{Binding Source={x:Static consts:AboutConst.DeveloperButtonContent}, Mode=OneTime}" ToolTip="{Binding Source={x:Static consts:AboutConst.DeveloperButtonUrl}, Mode=OneTime}"
|
||||
Click="AboutButton_Click" />
|
||||
<Button x:Name="VersionButton"
|
||||
Grid.Row="1" Grid.Column="0" Margin="5" Foreground="#2196F3" ToolTip="{Binding Source={x:Static consts:AboutConst.VersionButtonUrl}, Mode=OneTime}"
|
||||
<Button Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Margin="5" d:Foreground="#2196F3" Content="{Binding Source={x:Static consts:AboutConst.DeveloperButtonContent}, Mode=OneTime}" ToolTip="{Binding Source={x:Static consts:AboutConst.DeveloperButtonUrl}, Mode=OneTime}"
|
||||
Click="AboutButton_Click">
|
||||
<Button.Foreground>
|
||||
<Binding Path="AccentForegroundColor">
|
||||
<Binding.Converter>
|
||||
<convs:AboutAccentButtonForegroundConv />
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</Button.Foreground>
|
||||
</Button>
|
||||
<Button x:Name="VersionButton"
|
||||
Grid.Row="1" Grid.Column="0" Margin="5" d:Foreground="#2196F3" ToolTip="{Binding Source={x:Static consts:AboutConst.VersionButtonUrl}, Mode=OneTime}"
|
||||
Click="AboutButton_Click">
|
||||
<Button.Foreground>
|
||||
<Binding Path="AccentForegroundColor">
|
||||
<Binding.Converter>
|
||||
<convs:AboutAccentButtonForegroundConv />
|
||||
</Binding.Converter>
|
||||
</Binding>
|
||||
</Button.Foreground>
|
||||
<Button.Content>
|
||||
<MultiBinding Mode="OneTime">
|
||||
<MultiBinding.Converter>
|
||||
|
@ -480,11 +480,13 @@ public partial class MainWin : Window
|
||||
BorderThemeSetter.SetBorderTheme(currentWindow, isLightTheme);
|
||||
|
||||
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
|
||||
Color? newForegroundColor = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
||||
(Color? newForegroundColor, Color newAccentForegroundColor) = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
||||
|
||||
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
|
||||
Application.Current.Resources[typeof(Button)] = newButtonStyle;
|
||||
|
||||
new GlobalPres().AccentForegroundColor = newAccentForegroundColor;
|
||||
|
||||
if (GameFlashInterval > 100)
|
||||
GameFlashInterval += random.Next(1, 4);
|
||||
|
||||
|
@ -45,11 +45,13 @@ public partial class SettingsWin : Window
|
||||
paletteHelper.SetTheme(newTheme);
|
||||
|
||||
Style newButtonStyle = new(typeof(Button), Application.Current.Resources[typeof(Button)] as Style);
|
||||
Color? newForegroundColor = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
||||
(Color? newForegroundColor, Color newAccentForegroundColor) = ForegroundGenerator.GetForeground(newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
||||
|
||||
newButtonStyle.Setters.Add(new Setter(Button.ForegroundProperty, newForegroundColor.HasValue ? new SolidColorBrush(newForegroundColor.Value) : new DynamicResourceExtension("MaterialDesignBackground")));
|
||||
Application.Current.Resources[typeof(Button)] = newButtonStyle;
|
||||
|
||||
new GlobalPres().AccentForegroundColor = newAccentForegroundColor;
|
||||
|
||||
Settings.Default.PrimaryColor = System.Drawing.Color.FromArgb(newPrimaryColor.A, newPrimaryColor.R, newPrimaryColor.G, newPrimaryColor.B);
|
||||
Settings.Default.Save();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user