-
Notifications
You must be signed in to change notification settings - Fork 45
/
Copy pathPeriscopeSiteOptions.cs
104 lines (102 loc) · 4.56 KB
/
PeriscopeSiteOptions.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
using Common;
using System;
using System.Linq;
using System.Windows;
using System.Windows.Media;
namespace PeriscopeSitePlugin
{
internal class PeriscopeSiteOptions : DynamicOptionsBase, IPeriscopeSiteOptions
{
public Color ItemCommentBackColor { get => GetValue(); set => SetValue(value); }
public Color ItemCommentForeColor { get => GetValue(); set => SetValue(value); }
public bool IsAutoSetNickname { get => GetValue(); set => SetValue(value); }
public bool IsShowJoinMessage { get => GetValue(); set => SetValue(value); }
public bool IsShowLeaveMessage { get => GetValue(); set => SetValue(value); }
protected override void Init()
{
Dict.Add(nameof(ItemCommentBackColor), new Item { DefaultValue = ColorFromArgb("#FFFFFFFF"), Predicate = c => true, Serializer = c => ColorToArgb(c), Deserializer = s => ColorFromArgb(s) });
Dict.Add(nameof(ItemCommentForeColor), new Item { DefaultValue = ColorFromArgb("#FFFF0000"), Predicate = c => true, Serializer = c => ColorToArgb(c), Deserializer = s => ColorFromArgb(s) });
Dict.Add(nameof(IsAutoSetNickname), new Item { DefaultValue = false, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) });
Dict.Add(nameof(IsShowJoinMessage), new Item { DefaultValue = false, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) });
Dict.Add(nameof(IsShowLeaveMessage), new Item { DefaultValue = false, Predicate = b => true, Serializer = b => b.ToString(), Deserializer = s => bool.Parse(s) });
}
internal PeriscopeSiteOptions Clone()
{
return DeepClone(this);
}
IPeriscopeSiteOptions ISiteOptions<IPeriscopeSiteOptions>.Clone()
{
return this.Clone();
}
internal void Set(PeriscopeSiteOptions changedOptions)
{
foreach (var src in changedOptions.Dict)
{
var v = src.Value;
SetValue(v.Value, src.Key);
}
}
public void Set(IPeriscopeSiteOptions t)
{
if(t is PeriscopeSiteOptions other)
{
this.Set(other);
}
}
#region Converters
private FontFamily FontFamilyFromString(string str)
{
return new FontFamily(str);
}
private string FontFamilyToString(FontFamily family)
{
return family.FamilyNames.Values.First();
}
private FontStyle FontStyleFromString(string str)
{
return (FontStyle)new FontStyleConverter().ConvertFromString(str);
}
private string FontStyleToString(FontStyle style)
{
return new FontStyleConverter().ConvertToString(style);
}
private FontWeight FontWeightFromString(string str)
{
return (FontWeight)new FontWeightConverter().ConvertFromString(str);
}
private string FontWeightToString(FontWeight weight)
{
return new FontWeightConverter().ConvertToString(weight);
}
private bool IsValidArgb(string argb)
{
const string pattern = "#(?<a>[0-9a-fA-F]{2})(?<r>[0-9a-fA-F]{2})(?<g>[0-9a-fA-F]{2})(?<b>[0-9a-fA-F]{2})";
return System.Text.RegularExpressions.Regex.IsMatch(argb, pattern);
}
private Color ColorFromArgb(string argb)
{
if (argb == null)
throw new ArgumentNullException("argb");
var pattern = "#(?<a>[0-9a-fA-F]{2})(?<r>[0-9a-fA-F]{2})(?<g>[0-9a-fA-F]{2})(?<b>[0-9a-fA-F]{2})";
var match = System.Text.RegularExpressions.Regex.Match(argb, pattern, System.Text.RegularExpressions.RegexOptions.Compiled);
if (!match.Success)
{
throw new ArgumentException("形式が不正");
}
else
{
var a = byte.Parse(match.Groups["a"].Value, System.Globalization.NumberStyles.HexNumber);
var r = byte.Parse(match.Groups["r"].Value, System.Globalization.NumberStyles.HexNumber);
var g = byte.Parse(match.Groups["g"].Value, System.Globalization.NumberStyles.HexNumber);
var b = byte.Parse(match.Groups["b"].Value, System.Globalization.NumberStyles.HexNumber);
return Color.FromArgb(a, r, g, b);
}
}
private string ColorToArgb(Color color)
{
var argb = color.ToString();
return argb;
}
#endregion
}
}