-
Notifications
You must be signed in to change notification settings - Fork 5
/
FrmSettings.cs
131 lines (119 loc) · 4.37 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
using System;
using System.Drawing;
using System.IO;
using System.Windows.Forms;
using Cyotek.Windows.Forms;
using Newtonsoft.Json;
namespace MusicBeePlugin
{
public partial class FrmSettings : Form
{
private Font _font = DefaultFont;
private SettingsObj _settings;
private readonly ColorPickerDialog _colorDialog = new ColorPickerDialog();
public FrmSettings(SettingsObj settings)
{
InitializeComponent();
cbxGradientType.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;
cbxGradientType.SelectedIndex = _settings.GradientType;
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)
{
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 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 = cbxGradientType.SelectedIndex;
_settings.PreserveSlash = checkBoxPreserveSlash.Checked;
_settings.AutoHide = checkBoxAutoHide.Checked;
_settings.HideWhenUnavailable = checkBoxHideWhenUnavailable.Checked;
}
private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
_settings.PreserveSlash = checkBoxPreserveSlash.Checked;
}
private void checkBoxAutoHide_CheckedChanged(object sender, EventArgs e)
{
_settings.AutoHide = checkBoxAutoHide.Checked;
}
public SettingsObj Settings => _settings;
private void checkBoxNextLineWhenNoTranslation_CheckedChanged(object sender, EventArgs e)
{
_settings.NextLineWhenNoTranslation = checkBoxNextLineWhenNoTranslation.Checked;
}
}
public class SettingsObj
{
public string Font;
public Color Color1;
public Color Color2;
public Color BorderColor;
public int GradientType;
public bool PreserveSlash = false;
public bool AutoHide = false;
public bool NextLineWhenNoTranslation = false;
public bool HideOnStartup = false;
public bool HideWhenUnavailable = false;
public int PosY = -1;
public int PosX = -1;
[JsonIgnore]
public Font FontActual
{
get => FontSerializationHelper.Deserialize(Font);
set => Font = FontSerializationHelper.Serialize(value);
}
}
public enum GredientType
{
NoGrendient = 0,
DoubleColor = 1,
TripleColor = 2
}
}