|
0
|
1 |
using System; |
|
|
2 |
using System.Windows.Data; |
|
|
3 |
using System.Collections.Generic; |
|
|
4 |
using System.Linq; |
|
|
5 |
using System.Net; |
|
|
6 |
using System.Windows; |
|
|
7 |
using System.Windows.Controls; |
|
|
8 |
using System.Windows.Documents; |
|
|
9 |
using System.Windows.Input; |
|
|
10 |
using System.Windows.Media; |
|
|
11 |
using System.Windows.Media.Animation; |
|
|
12 |
using System.Windows.Shapes; |
|
|
13 |
using Iri.Modernisation.Data.Models; |
|
|
14 |
using Iri.Modernisation.Controls.ViewModel; |
|
|
15 |
using Iri.Modernisation.BaseMVVM.Commands; |
|
38
|
16 |
using System.IO; |
|
0
|
17 |
namespace Iri.Modernisation.Controls.View |
|
|
18 |
{ |
|
|
19 |
public partial class BookTimeLine : UserControl |
|
|
20 |
{ |
|
|
21 |
public BookTimeLine() |
|
|
22 |
{ |
|
|
23 |
InitializeComponent(); |
|
|
24 |
|
|
|
25 |
TimeStripsPanel.SizeChanged += new SizeChangedEventHandler(TimeStripsPanel_SizeChanged); |
|
38
|
26 |
BookTimeLineSlider.ThumbDragStarted += new EventHandler<EventArgs>(TimeSlider_ThumbDragCompleted); |
|
|
27 |
BookTimeLineSlider.ThumbDragCompleted += new EventHandler<EventArgs>(TimeSlider_ThumbDragCompleted); |
|
|
28 |
BookTimeLineSlider.MouseLeftButtonUp += new MouseButtonEventHandler(BookTimeLineSlider_MouseLeftButtonUp); |
|
|
29 |
saveAnnotationsButton.Click += new RoutedEventHandler(saveAnnotationsButton_Click); |
|
|
30 |
Commands.AnnotationMaker.NewAnnotationFinished.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(NewAnnotationFinished_Executed); |
|
24
|
31 |
} |
|
|
32 |
|
|
38
|
33 |
void saveAnnotationsButton_Click(object sender, RoutedEventArgs e) |
|
|
34 |
{ |
|
|
35 |
SaveFileDialog mySaveDialog = new SaveFileDialog(); |
|
|
36 |
mySaveDialog.Filter = "Ldt File (.ldt)|*.ldt|All Files|*.*"; |
|
|
37 |
bool? ret = mySaveDialog.ShowDialog(); |
|
|
38 |
if (ret == true) |
|
|
39 |
{ |
|
|
40 |
|
|
|
41 |
|
|
|
42 |
VideoBookUploader.UpdateAnnotation(((BookTimeLineVM)DataContext).SelectedBook, new StreamWriter(mySaveDialog.OpenFile())); |
|
|
43 |
|
|
|
44 |
} |
|
|
45 |
|
|
|
46 |
} |
|
|
47 |
private bool _saveVideoViewerState { get; set; } |
|
|
48 |
private void TimeSlider_ThumbDragCompleted(object sender, EventArgs e) |
|
|
49 |
{ |
|
|
50 |
if (_saveVideoViewerState) |
|
|
51 |
{ |
|
|
52 |
((BookTimeLineVM)DataContext).ViewModelVideoViewer.Play(); |
|
|
53 |
} |
|
|
54 |
} |
|
|
55 |
|
|
|
56 |
private void TimeSlider_ThumbDragStarted(object sender, EventArgs e) |
|
|
57 |
{ |
|
|
58 |
_saveVideoViewerState = ((BookTimeLineVM)DataContext).ViewModelVideoViewer.IsPLayed; |
|
|
59 |
((BookTimeLineVM)DataContext).ViewModelVideoViewer.Pause(); |
|
|
60 |
|
|
|
61 |
} |
|
|
62 |
private void NewAnnotationFinished_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e) |
|
|
63 |
{ |
|
|
64 |
Draw(); |
|
|
65 |
} |
|
|
66 |
|
|
|
67 |
private void BookTimeLineSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e) |
|
24
|
68 |
{ |
|
|
69 |
Commands.TimeChange.Execute(BookTimeLineSlider.Value,DataContext); |
|
0
|
70 |
} |
|
38
|
71 |
|
|
|
72 |
private void TimeStripsPanel_SizeChanged(object sender, SizeChangedEventArgs e) |
|
0
|
73 |
{ |
|
|
74 |
Draw(); |
|
|
75 |
} |
|
|
76 |
|
|
|
77 |
|
|
|
78 |
public void Draw() |
|
|
79 |
{ |
|
|
80 |
BookTimeLineVM VM = (BookTimeLineVM)DataContext; |
|
|
81 |
BookTimeLineElementPanel.Children.Clear(); |
|
18
|
82 |
BookTimeLineAnnotationPanel.Children.Clear(); |
|
0
|
83 |
foreach (List<SegmentIndex> LIndex in VM.SegmentIndex) |
|
|
84 |
{ |
|
|
85 |
foreach (SegmentIndex Index in LIndex) |
|
|
86 |
{ |
|
|
87 |
|
|
|
88 |
PolemicElementControl pol = new PolemicElementControl(); |
|
|
89 |
pol.SetValue(Canvas.ZIndexProperty, 10); |
|
|
90 |
pol.DataContext = new PolemicElementVM(Index); |
|
|
91 |
BookTimeLineElementPanel.Children.Add(pol); |
|
38
|
92 |
double timeleft = (double)((Index.TimerIn.TotalMilliseconds / BookTimeLineVM.ratioPixMs) * ScaleTimeLine.Value); |
|
|
93 |
Canvas.SetLeft(pol,timeleft); |
|
|
94 |
pol.Width = (Index.Duration.TotalMilliseconds / BookTimeLineVM.ratioPixMs) * ScaleTimeLine.Value; |
|
0
|
95 |
} |
|
|
96 |
} |
|
38
|
97 |
int basi = 0; |
|
0
|
98 |
foreach (List<Annotation> LAnnotation in VM.Annotations) |
|
|
99 |
{ |
|
|
100 |
foreach (Annotation Annotation in LAnnotation) |
|
|
101 |
{ |
|
|
102 |
PolemicElementControl pol = new PolemicElementControl(); |
|
|
103 |
pol.SetValue(Canvas.ZIndexProperty, 10); |
|
|
104 |
pol.DataContext = new PolemicElementVM(Annotation); |
|
38
|
105 |
|
|
|
106 |
Canvas.SetLeft(pol, (Annotation.TimerIn.TotalMilliseconds / BookTimeLineVM.ratioPixMs)* ScaleTimeLine.Value); |
|
|
107 |
|
|
|
108 |
/** It's TETRIS time **/ |
|
|
109 |
foreach (PolemicElementControl lockedControl in BookTimeLineAnnotationPanel.Children) |
|
|
110 |
{ |
|
|
111 |
if ( |
|
|
112 |
((PolemicElementVM)pol.DataContext).TimerIn >= ((PolemicElementVM)lockedControl.DataContext).TimerIn && ((PolemicElementVM)pol.DataContext).TimerIn <= ((PolemicElementVM)lockedControl.DataContext).TimerOut |
|
|
113 |
|| ((PolemicElementVM)pol.DataContext).TimerOut >= ((PolemicElementVM)lockedControl.DataContext).TimerIn && ((PolemicElementVM)pol.DataContext).TimerOut <= ((PolemicElementVM)lockedControl.DataContext).TimerOut |
|
|
114 |
|
|
|
115 |
) |
|
|
116 |
{ |
|
|
117 |
int actualTop = (int)Canvas.GetTop(lockedControl); |
|
|
118 |
if (basi <= actualTop) |
|
|
119 |
{ |
|
|
120 |
basi += 10; |
|
|
121 |
} |
|
|
122 |
|
|
|
123 |
} |
|
|
124 |
} |
|
|
125 |
|
|
0
|
126 |
Canvas.SetTop(pol, basi); |
|
38
|
127 |
/***********************/ |
|
|
128 |
|
|
|
129 |
|
|
|
130 |
// pol.Width = (Annotation.Duration.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration; |
|
|
131 |
pol.Width = (Annotation.Duration.TotalMilliseconds / BookTimeLineVM.ratioPixMs)* ScaleTimeLine.Value; |
|
|
132 |
BookTimeLineAnnotationPanel.Children.Add(pol); |
|
|
133 |
basi = 0; |
|
0
|
134 |
} |
|
|
135 |
} |
|
|
136 |
BookTimeLineElementPanel.UpdateLayout(); |
|
|
137 |
} |
|
|
138 |
|
|
38
|
139 |
|
|
7
|
140 |
|
|
0
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
|
145 |
} |
|
|
146 |
|
|
|
147 |
} |