-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFontPicker.xaml.cs
More file actions
121 lines (108 loc) · 4.01 KB
/
FontPicker.xaml.cs
File metadata and controls
121 lines (108 loc) · 4.01 KB
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
using SimpleUsefulTimer.Properties;
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.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Drawing.Text;
using System.Collections.ObjectModel;
using System.ComponentModel;
namespace SimpleUsefulTimer
{
/// <summary>
/// Interaction logic for FontPicker.xaml
/// </summary>
public partial class FontPicker : INotifyPropertyChanged
{
public event PropertyChangedEventHandler? PropertyChanged;
protected void OnPropertyChanged(string name)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}
readonly private TimerControl tc;
readonly private ClockControl cc;
private enum ControlMode
{
TimerControlMode,
ClockControlMode,
}
private ControlMode whichControlMode = ControlMode.TimerControlMode;
// TimerControl is Control 0 and ClockControl is 1
readonly private Properties.Settings s = Properties.Settings.Default;
readonly public string defaultTimerFont;
private string _selectedFont = "";
public string SelectedFont { get { return _selectedFont; } set { _selectedFont = value; OnPropertyChanged("SelectedFont"); } }
private ObservableCollection<FontFamily> _userFonts = new();
public ObservableCollection<FontFamily> UserFonts { get { return _userFonts; } set { _userFonts = value; OnPropertyChanged("UserFonts"); } }
public FontPicker(ref TimerControl tc)
{
DataContext = this;
InitializeComponent();
whichControlMode = ControlMode.TimerControlMode;
defaultTimerFont = s.DefaultTimerFont;
this.tc = tc;
SelectedFont = tc.TimerCustomFont;
foreach (FontFamily fontFamily in Fonts.SystemFontFamilies)
{
// FontFamily.Source contains the font family name.
UserFonts.Add(fontFamily);
}
UserFonts = new ObservableCollection<FontFamily>(UserFonts.OrderBy(c=>c.Source));
}
//ClockControl version
public FontPicker(ref ClockControl cc)
{
DataContext = this;
InitializeComponent();
whichControlMode = ControlMode.ClockControlMode;
this.cc = cc;
SelectedFont = cc.ClockFont;
foreach (FontFamily fontFamily in Fonts.SystemFontFamilies)
{
// FontFamily.Source contains the font family name.
UserFonts.Add(fontFamily);
}
UserFonts = new ObservableCollection<FontFamily>(UserFonts.OrderBy(c => c.Source));
}
private void Button_Click(object sender, RoutedEventArgs e)
{
if (whichControlMode is ControlMode.TimerControlMode)
{
SelectedFont = defaultTimerFont;
tc.TimerCustomFont = SelectedFont;
s.TimerFont = SelectedFont;
}
else if (whichControlMode is ControlMode.ClockControlMode)
{
SelectedFont = defaultTimerFont;
cc.ClockFont = SelectedFont;
s.ClockFont = SelectedFont;
}
s.Save();
s.Reload();
}
private void SaveCustomFont_Click(object sender, RoutedEventArgs e)
{
if (whichControlMode is ControlMode.TimerControlMode)
{
tc.TimerCustomFont = SelectedFont;
s.TimerFont = SelectedFont;
}
else if (whichControlMode is ControlMode.ClockControlMode)
{
cc.ClockFont = SelectedFont;
s.ClockFont = SelectedFont;
}
s.Save();
s.Reload();
}
}
}