-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerView.xaml.cs
More file actions
176 lines (153 loc) · 6.42 KB
/
TimerView.xaml.cs
File metadata and controls
176 lines (153 loc) · 6.42 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
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
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Linq;
using System.Runtime.CompilerServices;
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.Navigation;
using System.Windows.Shapes;
using Color = System.Windows.Media.Color;
using System.Configuration;
using Wpf.Ui.Controls;
using System.Security.Cryptography;
using System.Diagnostics;
namespace SimpleUsefulTimer
{
/// <summary>
/// Interaction logic for TimerView.xaml
/// </summary>
public partial class TimerView : Window
{
private TimerControl timerControl;
private Properties.Settings s = Properties.Settings.Default;
public TimerView(ref TimerControl tc)
{
InitializeComponent();
timerControl = tc;
DataContext = tc;
timerControl.TimerFontSize = s.TimerFontSize == 0 ? s.DefaultTimerFontSize : s.TimerFontSize;
var position = (s.LastTimerWindowPosition.IsEmpty ? s.DefaultWindowPosition:s.LastTimerWindowPosition);
this.Top = position.Y;
this.Left = position.X;
var background = ((s.TimerBackground.IsEmpty) ? s.DefaultTimerBackground:s.TimerBackground);
timerControl.MainTimerBackground = TimerControl.ConvertColorToBrush(background);
if (background == s.DefaultTimerBackground)
timerControl.IsBackgroundDefault = true;
else if (background == System.Drawing.Color.Transparent)
timerControl.IsBackgroundTransparent = true;
else
{
timerControl.IsBackgroundTransparent = false;
timerControl.IsBackgroundDefault = false;
timerControl.BackgroundHexColorInput.Text = TimerControl.ColorToHex(background).TrimStart('#');
}
System.Drawing.Color foreground;
if (s.UseCustomTimerForeground)
{
timerControl.UseCustomForeground = true;
foreground = s.TimerForeground;
}
else
{
timerControl.UseCustomForeground = false;
foreground = s.DefaultTimerForeground;
}
timerControl.ForegroundHexColorInput.Text = TimerControl.ColorToHex(foreground).TrimStart('#');
if ( s.UseTimerForegroundGradient)
{
timerControl.UseCustomForegroundGradientCheck.IsChecked = true;
timerControl.ForegroundGradient = TimerControl.ConvertColorToBrush(s.TimerForegroundGradient);
timerControl.GradientHexColorInput.Text = TimerControl.ColorToHex(s.TimerForegroundGradient);
timerControl.MainTimerForeground = (s.UseTimerForegroundGradient ? TimerControl.GetGradientFrom(s.TimerForeground, s.TimerForegroundGradient): TimerControl.ConvertColorToBrush(s.DefaultTimerForeground));
}
else
timerControl.MainTimerForeground = TimerControl.ConvertColorToBrush(foreground);
if (s.TimerFont != "")
tc.TimerCustomFont = s.TimerFont;
else
tc.TimerCustomFont = s.DefaultTimerFont;
tc.MsFieldAlignment = s.MsFieldAlignment;
Width = s.WindowWidth;
Height = s.WindowHeight;
this.UpdateLayout();
}
public void SaveConfig()
{
var s = Properties.Settings.Default;
Properties.Settings.Default.Save();
Properties.Settings.Default.Reload();
}
private void Window_Closed(object sender, EventArgs e)
{
int currentLeft = (Int32)this.Left;
int currentTop = (Int32)this.Top;
var lastKnownLocation = new System.Drawing.Point(x: currentLeft, y: currentTop);
s.LastTimerWindowPosition = lastKnownLocation;
s.MsFieldAlignment = timerControl.MsFieldControl.SelectedIndex;
s.EnableSystemClock = timerControl.SystemTimeControl.SelectedIndex;
s.WindowHeight = (int)Height;
s.WindowWidth = (int)Width;
s.Save();
SaveConfig();
Application.Current.Shutdown(0);
}
private void TimerViewWindow_MouseRightButtonUp(object sender, MouseButtonEventArgs e)
{
/*if (e.ChangedButton != MouseButton.Right)
return;*/
RightClickActionContainer.Placement = System.Windows.Controls.Primitives.PlacementMode.MousePoint;
RightClickActionContainer.Show();
//timerControl.Visibility = ((timerControl.Visibility is Visibility.Hidden) ? Visibility.Visible : Visibility.Hidden);
}
private void Window_MouseDown(object sender, MouseButtonEventArgs e)
{
if (e.ChangedButton == MouseButton.Left) {
this.DragMove();
}
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
if (s.DidReadWelcomeMessage)
return;
var w = new Welcome();
w.ShowDialog();
}
private void MainTimerMs_IsVisibleChanged(object sender, DependencyPropertyChangedEventArgs e)
{
if (!MainTimerMs.IsVisible)
{
TimerViewContainer.Background = Brushes.Transparent;
}
else
{
var backgroundBinding = new Binding("MainTimerBackground")
{
Source = timerControl
};
TimerViewContainer.SetBinding(StackPanel.BackgroundProperty, backgroundBinding);
}
}
private void CloseTimerAction_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
private void OpenTimerConfigAction_Click(object sender, RoutedEventArgs e)
{
timerControl.Visibility = ((timerControl.Visibility is Visibility.Hidden) ? Visibility.Visible : Visibility.Hidden);
RightClickActionContainer.Hide();
}
private void Github_Click(object sender, RoutedEventArgs e)
{
Process.Start(new ProcessStartInfo("https://github.com/Bo0sted/SimpleUsefulTimer") { UseShellExecute = true });
}
}
}