-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAppearanceSetting.cs
125 lines (109 loc) · 3.47 KB
/
AppearanceSetting.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
using System;
using System.ComponentModel;
using System.Drawing;
using System.Runtime.CompilerServices;
using Microsoft.Win32;
namespace AdvancedWindowsAppearence
{
public class AppearanceSetting : INotifyPropertyChanged
{
internal void NotifyPropertyChanged([CallerMemberName] string propertyName = "")
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
private bool _isEdited;
public bool IsEdited { get => _isEdited; set
{
if (_isEdited == value) return;
_isEdited = value;
NotifyPropertyChanged();
}
}
public string Name { get; set; }
private float? _size;
public float? Size
{
get => _size;
set
{
if (_size == value || value == null)
return;
IsEdited = true;
_size = value;
if(FontManager.DPI != -1f)
SizeWithDPI = value / (float)FontManager.DPI;
NotifyPropertyChanged();
}
}
private float? _sizeWithDPI;
public float? SizeWithDPI {
get => _sizeWithDPI;
set
{
_sizeWithDPI = value;
NotifyPropertyChanged();
}
}
public bool HasSize
{
get { return Size != null; }
}
public string ColorRegistryPath;
private Color? itemColor;
public event PropertyChangedEventHandler PropertyChanged;
public Color? ItemColor
{
get => itemColor;
set
{
itemColor = value;
IsEdited = true;
NotifyPropertyChanged();
}
}
public string ItemColorValue
{
get
{
if(!ItemColor.HasValue) return null;
return ConvertColorValuesToRegistry(ItemColor.Value);
}
}
public bool HasColor
{
get
{
return ItemColor.HasValue;
}
}
public string ConvertColorValuesToRegistry(Color color)
{
return color.R + " " + color.G + " " + color.B;
}
internal Color? GetColorFromRegistry(string registrypath)
{
if (registrypath == null || registrypath == "") return null;
RegistryKey registryKey = Registry.CurrentUser.OpenSubKey(@"Control Panel\Colors");
if (registryKey == null) return null;
var colorReg = registryKey.GetValue(registrypath);
registryKey.Close();
if (colorReg == null) return null;
var colorRegString = colorReg.ToString().Split(' ');
Color color = Color.FromArgb(int.Parse(colorRegString[0]), int.Parse(colorRegString[1]), int.Parse(colorRegString[2]));
return color;
}
internal void SaveColorToRegistry()
{
RegistryKey key = Registry.CurrentUser.OpenSubKey(@"Control Panel\Colors", true);
if (key == null)
{
Registry.CurrentUser.CreateSubKey(@"Control Panel\Colors");
}
if (ItemColor.HasValue)
{
key.SetValue(ColorRegistryPath, ItemColorValue, RegistryValueKind.String);
}
key.Close();
}
}
}