-
Notifications
You must be signed in to change notification settings - Fork 2
/
Themes.cs
166 lines (157 loc) · 6.56 KB
/
Themes.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
namespace Concursus
{
public class Themes
{
// To create a new theme, create a new enum for the ThemeOption, then insert the new enum alongside the
// new ThemeData object with the colors you want in the THEMES_TABLE
// (the display name will be the enum name split with a space before every capital letter)
// (so for example, "DarkMode" will look like "Dark Mode")
public enum ThemeOption
{
White,
PitchBlack,
DarkMode,
Naoto,
Invalid,
}
public struct ThemeData
{
public string mainBgColor;
public string mainTextColor;
public string mainTableBgColor;
public string mainTableTextColor;
public string buttonBgColor;
public string buttonTextColor;
public string textBoxBgColor;
public string textBoxTextColor;
}
public static ThemeOption CURRENT_THEME = GetOptionFromString(Properties.Settings.Default.App_Theme);
public static Dictionary<ThemeOption, ThemeData> THEMES_TABLE = new Dictionary<ThemeOption, ThemeData>() {
{
ThemeOption.White, new ThemeData {
mainBgColor = "#fff",
mainTextColor = "#000",
mainTableBgColor = "#F0F0F0",
mainTableTextColor = "#000",
buttonBgColor = "#fff",
buttonTextColor = "#000",
textBoxBgColor = "#fff",
textBoxTextColor = "#000"
}
},
{
ThemeOption.PitchBlack, new ThemeData
{
mainBgColor = "#000",
mainTextColor = "#fff",
mainTableBgColor = "#1A1A1A",
mainTableTextColor = "#000",
buttonBgColor = "#000",
buttonTextColor = "#fff",
textBoxBgColor = "#000",
textBoxTextColor = "#fff"
}
},
{
ThemeOption.DarkMode, new ThemeData
{
mainBgColor = "#1A1A1A",
mainTextColor = "#fff",
mainTableBgColor = "#222",
mainTableTextColor = "#000",
buttonBgColor = "#333",
buttonTextColor = "#fff",
textBoxBgColor = "#222",
textBoxTextColor = "#fff"
}
},
{
ThemeOption.Naoto, new ThemeData
{
mainBgColor = "#0E112A",
mainTextColor = "#FFFFFF",
mainTableBgColor = "#0E112A",
mainTableTextColor = "#000",
buttonBgColor = "#0E112A",
buttonTextColor = "#FFFFFF",
textBoxBgColor = "#0E112A",
textBoxTextColor = "#FFFFFF"
}
}
};
public static ThemeOption GetOptionFromString(string theme)
{
theme = string.Concat(theme.Split(' '));
ThemeOption res;
if (Enum.TryParse<ThemeOption>(theme, out res))
return res;
else
return ThemeOption.Invalid;
}
public static string GetStringFromOption(ThemeOption theme)
{
return string.Concat(Enum.GetName(theme.GetType(), theme).Select(x => Char.IsUpper(x) ? " " + x : x.ToString())).TrimStart(' ');
}
public static void UpdateForm(ThemeOption theme, Window window)
{
if (!THEMES_TABLE.ContainsKey(theme))
return;
ThemeData selected_theme = THEMES_TABLE[theme];
BrushConverter converter = new BrushConverter();
if (selected_theme.mainBgColor != String.Empty)
window.Background = (Brush)(converter.ConvertFrom(selected_theme.mainBgColor));
for (int i = 0; i < VisualTreeHelper.GetChildrenCount((DependencyObject)window.Content); i++)
{
Visual child = (Visual)VisualTreeHelper.GetChild((DependencyObject)window.Content, i);
UpdateColors(child, selected_theme, converter);
}
}
private static void UpdateColors(Visual vis, ThemeData selected_theme, BrushConverter converter)
{
switch (vis.GetType().Name)
{
case "Label":
if(selected_theme.mainTextColor != String.Empty)
((Label)vis).Foreground = (Brush)(converter.ConvertFrom(selected_theme.mainTextColor));
break;
case "Button":
if (selected_theme.buttonTextColor != String.Empty)
((Button)vis).Foreground = (Brush)(converter.ConvertFrom(selected_theme.buttonTextColor));
if (selected_theme.buttonBgColor != String.Empty)
((Button)vis).Background = (Brush)(converter.ConvertFrom(selected_theme.buttonBgColor));
break;
case "DataGrid":
if (selected_theme.mainTableBgColor != String.Empty)
((DataGrid)vis).Background = (Brush)(converter.ConvertFrom(selected_theme.mainTableBgColor));
if (selected_theme.mainTableTextColor != String.Empty)
((DataGrid)vis).Foreground = (Brush)(converter.ConvertFrom(selected_theme.mainTableTextColor));
break;
case "CheckBox":
if(selected_theme.mainTextColor != String.Empty)
((CheckBox)vis).Foreground = (Brush)(converter.ConvertFrom(selected_theme.mainTextColor));
break;
case "TextBox":
if(selected_theme.textBoxBgColor != String.Empty)
((TextBox)vis).Background = (Brush)(converter.ConvertFrom(selected_theme.textBoxBgColor));
if (selected_theme.textBoxTextColor != String.Empty)
((TextBox)vis).Foreground = (Brush)(converter.ConvertFrom(selected_theme.textBoxTextColor));
break;
default:
break;
}
for(int i = 0; i < VisualTreeHelper.GetChildrenCount(vis); i++)
{
Visual child = (Visual)VisualTreeHelper.GetChild(vis, i);
UpdateColors(child, selected_theme, converter); //so I can copy 18955
}
}
}
}