From 038e9fe7e7c5ec3a6d377033634dc8b0845b6027 Mon Sep 17 00:00:00 2001 From: Space Time Date: Fri, 6 Dec 2024 23:59:26 +0800 Subject: [PATCH] =?UTF-8?q?1.1.3=20->=201.1.4=20=E7=AC=AC28=E6=AC=A1?= =?UTF-8?q?=E6=9B=B4=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- App.xaml.cs | 19 ++++++++++++++++++ Consts/SettingsMultilangConst.Designer.cs | 20 ++++++++++++++++++- Consts/SettingsMultilangConst.resx | 8 +++++++- Consts/SettingsMultilangConst.zh.resx | 8 +++++++- Props/Settings.Designer.cs | 12 ++++++++++++ Props/Settings.settings | 3 +++ Utils/ForegroundGenerator.cs | 20 +++++++++++++++++++ Wins/SettingsWin.xaml | 8 ++++++-- Wins/SettingsWin.xaml.cs | 24 +++++++++++++++++++++++ 9 files changed, 117 insertions(+), 5 deletions(-) create mode 100644 Utils/ForegroundGenerator.cs diff --git a/App.xaml.cs b/App.xaml.cs index e47a33a..f8a878d 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,6 +1,10 @@ using System.Windows; +using System.Windows.Media; using System.Windows.Threading; +using MaterialDesignThemes.Wpf; using Sheas_Cealer.Preses; +using Sheas_Cealer.Props; +using Sheas_Cealer.Utils; using Sheas_Cealer.Wins; namespace Sheas_Cealer; @@ -10,6 +14,21 @@ public partial class App : Application protected override void OnStartup(StartupEventArgs e) { _ = new SettingsPres(); + + PaletteHelper paletteHelper = new(); + Theme newTheme = paletteHelper.GetTheme(); + System.Drawing.Color newColor = Settings.Default.PrimaryColor; + + newTheme.SetPrimaryColor(Color.FromRgb(newColor.R, newColor.G, newColor.B)); + paletteHelper.SetTheme(newTheme); + + Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B); + + if (foregroundColor.HasValue) + Current.Resources["MaterialDesignBackground"] = new SolidColorBrush(foregroundColor.Value); + else + Current.Resources.Remove("MaterialDesignBackground"); + new MainWin(e.Args).Show(); } diff --git a/Consts/SettingsMultilangConst.Designer.cs b/Consts/SettingsMultilangConst.Designer.cs index 53a59b4..6594b50 100644 --- a/Consts/SettingsMultilangConst.Designer.cs +++ b/Consts/SettingsMultilangConst.Designer.cs @@ -69,6 +69,24 @@ namespace Sheas_Cealer.Consts { } } + /// + /// 查找类似 Switch Color (Fully random) 的本地化字符串。 + /// + public static string ColorsButtonContent { + get { + return ResourceManager.GetString("ColorsButtonContent", resourceCulture); + } + } + + /// + /// 查找类似 Click to switch colors 的本地化字符串。 + /// + public static string ColorsButtonToolTip { + get { + return ResourceManager.GetString("ColorsButtonToolTip", resourceCulture); + } + } + /// /// 查找类似 Switch Lang (中文 → En) 的本地化字符串。 /// @@ -97,7 +115,7 @@ namespace Sheas_Cealer.Consts { } /// - /// 查找类似 点击切换界面语言 的本地化字符串。 + /// 查找类似 Click to switch langs 的本地化字符串。 /// public static string LangsButtonToolTip { get { diff --git a/Consts/SettingsMultilangConst.resx b/Consts/SettingsMultilangConst.resx index 4ad3bd6..9a82887 100644 --- a/Consts/SettingsMultilangConst.resx +++ b/Consts/SettingsMultilangConst.resx @@ -97,6 +97,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Switch Color (Fully random) + + + Click to switch colors + Switch Lang (中文 → En) @@ -107,7 +113,7 @@ Switch Lang (Auto → 中文) - 点击切换界面语言 + Click to switch langs Switch Theme (Dark → Light) diff --git a/Consts/SettingsMultilangConst.zh.resx b/Consts/SettingsMultilangConst.zh.resx index ed8688c..1068c78 100644 --- a/Consts/SettingsMultilangConst.zh.resx +++ b/Consts/SettingsMultilangConst.zh.resx @@ -97,6 +97,12 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.3500.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + 切换颜色 (全随机) + + + 点击切换按钮颜色 + 切换语言 (中文 → En) @@ -107,7 +113,7 @@ 切换语言 (系统 → 中文) - Click to switch langs + 点击切换界面语言 切换主题 (暗色 → 亮色) diff --git a/Props/Settings.Designer.cs b/Props/Settings.Designer.cs index 2ec3182..debb854 100644 --- a/Props/Settings.Designer.cs +++ b/Props/Settings.Designer.cs @@ -82,5 +82,17 @@ namespace Sheas_Cealer.Props { this["IsEnglishLang"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("Red")] + public global::System.Drawing.Color PrimaryColor { + get { + return ((global::System.Drawing.Color)(this["PrimaryColor"])); + } + set { + this["PrimaryColor"] = value; + } + } } } diff --git a/Props/Settings.settings b/Props/Settings.settings index 9a650fb..7d39a95 100644 --- a/Props/Settings.settings +++ b/Props/Settings.settings @@ -17,5 +17,8 @@ -1 + + Red + \ No newline at end of file diff --git a/Utils/ForegroundGenerator.cs b/Utils/ForegroundGenerator.cs new file mode 100644 index 0000000..a9fec4a --- /dev/null +++ b/Utils/ForegroundGenerator.cs @@ -0,0 +1,20 @@ +using System; +using System.Windows.Media; + +namespace Sheas_Cealer.Utils; + +internal static class ForegroundGenerator +{ + internal static 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 >= 3.9 && whiteContrast >= 2.9 ? null : + blackContrast >= whiteContrast ? Color.FromRgb(0, 0, 0) : Color.FromRgb(255, 255, 255); + } + + private static double GammaCorrect(double c) => c <= 0.03928 ? c / 12.92 : Math.Pow((c + 0.055) / 1.055, 2.4); +} \ No newline at end of file diff --git a/Wins/SettingsWin.xaml b/Wins/SettingsWin.xaml index d1c5a68..55f1dba 100644 --- a/Wins/SettingsWin.xaml +++ b/Wins/SettingsWin.xaml @@ -13,13 +13,14 @@ + - - + +