-
Notifications
You must be signed in to change notification settings - Fork 5
/
FrmSettings.cs
153 lines (140 loc) · 5.18 KB
/
FrmSettings.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
using System;
using System.Diagnostics.CodeAnalysis;
using System.Drawing;
using System.Windows.Forms;
using Cyotek.Windows.Forms;
using Newtonsoft.Json;
namespace MusicBeePlugin
{
[SuppressMessage("ReSharper", "LocalizableElement")]
public partial class FrmSettings : Form
{
private Font _font = DefaultFont;
private readonly SettingsObj _settings;
private readonly ColorPickerDialog _colorDialog = new ColorPickerDialog();
public FrmSettings(SettingsObj settings)
{
InitializeComponent();
comboBoxGradientType.SelectedIndex = 0;
_settings = settings;
}
private void Settings_Load(object sender, EventArgs e)
{
try
{
_font = FontSerializationHelper.Deserialize(_settings.Font);
}
catch (Exception)
{
// ignored
}
try
{
btnFont.Text = _font.Name + " "+ _font.Size;
comboBoxGradientType.SelectedIndex = _settings.GradientType;
comboBoxAlignment.SelectedIndex = _settings.AlignmentType;
btnColor1.BackColor = _settings.Color1;
btnColor2.BackColor = _settings.Color2;
btnBorderColor.BackColor = _settings.BorderColor;
checkBoxPreserveSlash.Checked = _settings.PreserveSlash;
checkBoxAutoHide.Checked = _settings.AutoHide;
checkBoxNextLineWhenNoTranslation.Checked = _settings.NextLineWhenNoTranslation;
checkBoxHideWhenUnavailable.Checked = _settings.HideWhenUnavailable;
}
catch (Exception)
{
// ignored
}
}
private void btnFont_Click(object sender, EventArgs e)
{
dlgFont.Font = _font;
var res = dlgFont.ShowDialog();
if (res != DialogResult.OK && res != DialogResult.Yes) return;
var font = dlgFont.Font;
// Force point unit
_font = new Font(font.FontFamily, font.Size, font.Style, GraphicsUnit.Point, font.GdiCharSet);
btnFont.Text = _font.Name + " " + _font.Size;
}
private void btnColors_Click(object sender, EventArgs e)
{
var button = (Button) sender;
_colorDialog.Color = button.BackColor;
var res = _colorDialog.ShowDialog();
if (res == DialogResult.OK || res == DialogResult.Yes)
button.BackColor = _colorDialog.Color;
}
private void checkBoxPreserveSlash_CheckedChanged(object sender, EventArgs e)
{
_settings.PreserveSlash = checkBoxPreserveSlash.Checked;
}
private void checkBoxAutoHide_CheckedChanged(object sender, EventArgs e)
{
_settings.AutoHide = checkBoxAutoHide.Checked;
}
private void checkBoxNextLineWhenNoTranslation_CheckedChanged(object sender, EventArgs e)
{
_settings.NextLineWhenNoTranslation = checkBoxNextLineWhenNoTranslation.Checked;
}
private void Settings_FormClosed(object sender, FormClosedEventArgs e)
{
_settings.Font = FontSerializationHelper.Serialize(_font);
_settings.Color1 = btnColor1.BackColor;
_settings.Color2 = btnColor2.BackColor;
_settings.BorderColor = btnBorderColor.BackColor;
_settings.GradientType = comboBoxGradientType.SelectedIndex;
_settings.AlignmentType = comboBoxAlignment.SelectedIndex;
_settings.PreserveSlash = checkBoxPreserveSlash.Checked;
_settings.AutoHide = checkBoxAutoHide.Checked;
_settings.HideWhenUnavailable = checkBoxHideWhenUnavailable.Checked;
}
}
public class SettingsObj
{
public string Font;
public Color Color1;
public Color Color2;
public Color BorderColor;
public int GradientType;
public int AlignmentType;
public bool PreserveSlash;
public bool AutoHide;
public bool NextLineWhenNoTranslation;
public bool HideOnStartup;
public bool HideWhenUnavailable;
public int PosY = -1;
public int PosX = -1;
[JsonIgnore]
public Font FontActual
{
get => FontSerializationHelper.Deserialize(Font);
set => Font = FontSerializationHelper.Serialize(value);
}
public static SettingsObj GenerateDefault()
{
return new SettingsObj
{
BorderColor = Color.Black,
Color1 = Color.GhostWhite,
Color2 = Color.LightGray,
FontActual = new Font(FontFamily.GenericSansSerif, 34.0f, FontStyle.Regular, GraphicsUnit.Point),
GradientType = 1,
AlignmentType = 0,
};
}
}
// This corresponds to items of comboBoxGradientType!
public enum GradientType
{
NoGradient = 0,
DoubleColor = 1,
TripleColor = 2
}
// This corresponds to items of comboBoxAlignment!
public enum AlignmentType
{
Center = 0,
Left = 1,
Right = 2
}
}