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 @@
+
-
-
+
+
\ No newline at end of file
diff --git a/Wins/SettingsWin.xaml.cs b/Wins/SettingsWin.xaml.cs
index 6870f49..91c3421 100644
--- a/Wins/SettingsWin.xaml.cs
+++ b/Wins/SettingsWin.xaml.cs
@@ -1,8 +1,11 @@
using System;
using System.Windows;
using System.Windows.Input;
+using System.Windows.Media;
+using MaterialDesignThemes.Wpf;
using Sheas_Cealer.Consts;
using Sheas_Cealer.Preses;
+using Sheas_Cealer.Props;
using Sheas_Cealer.Utils;
namespace Sheas_Cealer.Wins;
@@ -30,6 +33,27 @@ public partial class SettingsWin : Window
MessageBox.Show(SettingsConst._ChangeLangSuccessMsg);
}
+ private void ColorsButton_Click(object sender, RoutedEventArgs e)
+ {
+ Random random = new();
+
+ PaletteHelper paletteHelper = new();
+ Theme newTheme = paletteHelper.GetTheme();
+ Color newColor = Color.FromRgb((byte)random.Next(256), (byte)random.Next(256), (byte)random.Next(256));
+
+ newTheme.SetPrimaryColor(newColor);
+ paletteHelper.SetTheme(newTheme);
+
+ Color? foregroundColor = ForegroundGenerator.GetForeground(newColor.R, newColor.G, newColor.B);
+
+ if (foregroundColor.HasValue)
+ Application.Current.Resources["MaterialDesignBackground"] = new SolidColorBrush(foregroundColor.Value);
+ else
+ Application.Current.Resources.Remove("MaterialDesignBackground");
+
+ Settings.Default.PrimaryColor = System.Drawing.Color.FromArgb(newColor.A, newColor.R, newColor.G, newColor.B);
+ Settings.Default.Save();
+ }
private void SettingsWin_KeyDown(object sender, KeyEventArgs e)
{