-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathLoadInfo.xaml.cs
More file actions
96 lines (80 loc) · 3.57 KB
/
LoadInfo.xaml.cs
File metadata and controls
96 lines (80 loc) · 3.57 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
using System;
using System.Windows.Controls;
namespace LoadRetimer {
/// <summary>
/// Interaction logic for LoadInfo.xaml
/// </summary>
public partial class LoadInfo : UserControl {
public long frameStart = -1;
public long frameEnd = -1;
private bool isInclusive = false;
public LoadInfo() {
InitializeComponent();
TryCalculate();
}
public LoadInfo(string name) {
InitializeComponent();
SetName(name);
TryCalculate();
}
public void SetName(string s) {
LoadName.Text = s;
}
public void MakeUnchangable() {
LoadName.IsReadOnly = true;
}
public void MakeNonInclusive() {
isInclusive = true;
}
public void Rename(String newName) {
SetName(newName);
}
public void SetBegin(TimeSpan begin) {
frameStart = (long) Math.Round(begin.TotalSeconds * MainWindow.frameRate);
TryCalculate();
}
public void SetEnd(TimeSpan begin) {
frameEnd = (long)Math.Round(begin.TotalSeconds * MainWindow.frameRate);
TryCalculate();
}
private void TryCalculate() {
LoadFrameDurationF.Content = "---";
LoadFrameDurationS.Content = "---";
if (frameStart > -1) {
TimeSpan tmp = new TimeSpan((long)(frameStart / MainWindow.frameRate * 10_000_000));
LoadFrameBeginS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(tmp));
}
if (frameEnd > -1) {
TimeSpan tmp = new TimeSpan((long)(frameEnd / MainWindow.frameRate * 10_000_000));
LoadFrameEndS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(tmp));
}
if (frameStart > -1 && frameEnd > -1) {
int frameDuration = FrameDuration();
LoadFrameDurationF.Content = String.Format("{0} frames", frameDuration);
TimeSpan tmp = new TimeSpan((long)(frameDuration / MainWindow.frameRate * 10_000_000));
LoadFrameDurationS.Content = String.Format("{0:hh\\:mm\\:ss\\.fff}", Helper.RoundTimeSpanMillis(tmp));
}
}
public int FrameDuration() {
if (frameStart > -1 && frameEnd > -1) {
long addEnd = (isInclusive) ? 0 : 1;
return (int)(frameEnd - frameStart + addEnd); // get inclusive length
} else {
return 0;
}
}
private void LoadFrameBeginS_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) {
MainWindow parentWindow = (MainWindow)MainWindow.GetWindow(this);
if (parentWindow == null) return;
TimeSpan tmp = new TimeSpan((long)(frameStart / MainWindow.frameRate * 10_000_000));
parentWindow.Video.Position = Helper.CeilTimeSpanMillis(tmp + parentWindow.Video.PlaybackStartTime.GetValueOrDefault());
}
private void LoadFrameEndS_MouseUp(object sender, System.Windows.Input.MouseButtonEventArgs e) {
MainWindow parentWindow = (MainWindow)MainWindow.GetWindow(this);
if (parentWindow == null) return;
TimeSpan tmp = new TimeSpan((long)(frameEnd / MainWindow.frameRate * 10_000_000));
// not exactly sure why I can't just round here...
parentWindow.Video.Position = Helper.CeilTimeSpanMillis(tmp + parentWindow.Video.PlaybackStartTime.GetValueOrDefault());
}
}
}