-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainWindow.xaml.cs
More file actions
216 lines (172 loc) · 6.76 KB
/
MainWindow.xaml.cs
File metadata and controls
216 lines (172 loc) · 6.76 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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
using MahApps.Metro.Controls;
using System;
using System.Diagnostics;
using System.IO;
using System.Net;
using System.Windows;
using System.Windows.Input;
using System.Windows.Media;
using Forms = System.Windows.Forms;
using System.Net.Http;
using System.Threading.Tasks;
using ControlzEx.Standard;
using System.Configuration;
namespace NDI_Telestrator
{
public partial class MainWindow : MetroWindow
{
Double test = 1;
private object client;
private void requestNDI(object caller, object args)
{
ndi.requestFrameUpdate();
}
public static Color FromName(String name)
{
var color_props = typeof(Colors).GetProperties();
foreach (var c in color_props)
if (name.Equals(c.Name, StringComparison.OrdinalIgnoreCase))
return (Color)c.GetValue(new Color(), null);
return Colors.Transparent;
}
static async Task GetVmix(String url)
{
var client = new HttpClient();
var result = await client.GetAsync(url);
Console.WriteLine(result);
}
public MainWindow()
{
InitializeComponent();
InkControls.whiteboard = theWhiteboard;
optionsDialogue.whiteboard = theWhiteboard;
optionsDialogue.background = theBackground;
theWhiteboard.SetPenColour(Colors.Yellow);
theWhiteboard.SetPenColour(FromName(ConfigurationManager.AppSettings["Default_Pen_Color"]));
theWhiteboard.SetPenThickness(double.Parse(ConfigurationManager.AppSettings["Default_Pen_Size"]));
// Send background updates every 250ms
System.Windows.Threading.DispatcherTimer backgroundUpdateTimer = new System.Windows.Threading.DispatcherTimer();
backgroundUpdateTimer.Interval = TimeSpan.FromMilliseconds(250);
backgroundUpdateTimer.Tick += requestNDI;
// Send canvas updates every 10ms
System.Windows.Threading.DispatcherTimer canvasUpdateTimer = new System.Windows.Threading.DispatcherTimer();
canvasUpdateTimer.Interval = TimeSpan.FromMilliseconds(10);
canvasUpdateTimer.Tick += requestNDI;
// Switch from the canvas update timer to the background update timer after 1 second
System.Windows.Threading.DispatcherTimer backgroundUpdateTransitionTimer = new System.Windows.Threading.DispatcherTimer();
backgroundUpdateTransitionTimer.Interval = TimeSpan.FromSeconds(1);
backgroundUpdateTransitionTimer.Tick += (a, b) =>
{
backgroundUpdateTransitionTimer.Stop(); // Turn off after the tick
backgroundUpdateTimer.Start();
canvasUpdateTimer.Stop();
};
theWhiteboard.GotMouseCapture += (a, b) =>
{
backgroundUpdateTimer.Stop();
canvasUpdateTimer.Start();
};
theWhiteboard.LostMouseCapture += (a, b) => backgroundUpdateTransitionTimer.Start();
backgroundUpdateTimer.Start();
}
private void MainWindow_KeyDown(object sender, KeyEventArgs e)
{
switch (e.Key)
{
case Key.Z:
if ((Forms.Control.ModifierKeys & Forms.Keys.Control) == Forms.Keys.Control)
{
if ((Forms.Control.ModifierKeys & Forms.Keys.Shift) == Forms.Keys.Shift)
{
theWhiteboard.Redo();
}
else
{
theWhiteboard.Undo();
}
}
break;
case Key.Space:
theWhiteboard.Clear();
break;
case Key.Back:
theWhiteboard.Clear();
break;
case Key.Up:
test = test + 3.0;
theWhiteboard.SetPenThickness(test);
break;
case Key.Down:
if (test >= 2.0)
{
test = test - 3.0;
theWhiteboard.SetPenThickness(test);
break;
}
else
{
break;
}
case Key.R:
theWhiteboard.SetPenColour(Colors.Red);
break;
case Key.G:
theWhiteboard.SetPenColour(Colors.Green);
break;
case Key.B:
theWhiteboard.SetPenColour(Colors.Blue);
break;
case Key.P:
theWhiteboard.SetPenColour(Colors.Purple);
break;
case Key.Y:
theWhiteboard.SetPenColour(Colors.Yellow);
break;
case Key.D1:
String play = ConfigurationManager.AppSettings["Play-Pause"];
GetVmix(play);
Console.WriteLine("Play-Pause");
theWhiteboard.Clear();
break;
case Key.D2:
GetVmix(ConfigurationManager.AppSettings["Reverse"]);
Console.WriteLine("Reverse");
break;
}
}
#region Toolbar Events
private void Btn_Screenshot_Click(object sender, RoutedEventArgs e)
{
InkControls.Btn_Screenshot_Click(sender, e);
}
private void Btn_Delete_Click(object sender, RoutedEventArgs e)
{
InkControls.clearWhiteboard();
}
private void Btn_Undo_Click(object sender, RoutedEventArgs e)
{
InkControls.undo();
}
private void Btn_Redo_Click(object sender, RoutedEventArgs e)
{
InkControls.redo();
}
private void Btn_Options_Click(object sender, RoutedEventArgs e)
{
optionsDialogue.IsOpen = !optionsDialogue.IsOpen;
}
private void onClrPickPen(object sender, RoutedPropertyChangedEventArgs<Color?> e)
{
if (e.NewValue != null) InkControls.setPenColour((Color)e.NewValue);
}
private void onClrPickBackground(object sender, RoutedPropertyChangedEventArgs<Color?> e)
{
if (e.NewValue != null) InkControls.setBackgroundColour(new SolidColorBrush((Color)e.NewValue));
}
public ICommand handleSelectThickness
{
get => new SimpleCommand(o => InkControls.setPenThickness(double.Parse((string)o)));
}
#endregion
}
}