author | cavaliet |
Mon, 05 Oct 2009 18:23:10 +0200 | |
changeset 130 | 192da585bee5 |
parent 129 | 1f37ef03ebee |
child 135 | 84b3bf5ee3d2 |
permissions | -rw-r--r-- |
10 | 1 |
using System; |
69 | 2 |
using System.Collections.Generic; |
10 | 3 |
using System.IO; |
4 |
using System.Net; |
|
5 |
using System.Windows; |
|
6 |
using System.Windows.Controls; |
|
7 |
using System.Windows.Data; |
|
8 |
using System.Windows.Media; |
|
9 |
using System.Windows.Media.Animation; |
|
10 |
using System.Windows.Navigation; |
|
34 | 11 |
using System.Windows.Controls.Primitives; |
12 |
using Microsoft.Surface.Presentation.Controls; |
|
13 |
using System.Windows.Threading; |
|
10 | 14 |
|
69 | 15 |
using FingersDance.Data; |
16 |
using FingersDance.ViewModels; |
|
17 |
||
10 | 18 |
namespace FingersDance.Control.TimeLine |
19 |
{ |
|
20 |
public partial class UserControlTimeLine |
|
34 | 21 |
{ |
22 |
||
23 |
#region Variables |
|
24 |
private DispatcherTimer timer; |
|
25 |
private bool isDragging = false; |
|
26 |
private bool finishedDragging = false; |
|
27 |
#endregion |
|
28 |
||
29 |
public event EventHandler DragStarted; |
|
30 |
public event EventHandler DragCompleted; |
|
31 |
public event EventHandler TimerTick; |
|
32 |
||
124 | 33 |
private double totalmilliseconds; |
34 |
||
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
35 |
private List<Annotation> AnnotList = new List<Annotation>(); |
128
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
125
diff
changeset
|
36 |
private float AnnotWidth = 300 + 15; // The surfaceListBox adds 15 pixels between each item |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
37 |
private CuttingViewModel CuttingVM; |
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
38 |
private Boolean AnnotWaiting = false; |
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
39 |
private float AnnotTcBegin; |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
40 |
|
34 | 41 |
#region Properties |
42 |
||
43 |
public SurfaceSlider Slider |
|
10 | 44 |
{ |
34 | 45 |
get |
46 |
{ |
|
47 |
return slider; |
|
10 | 48 |
} |
34 | 49 |
set |
50 |
{ |
|
51 |
slider = value; |
|
10 | 52 |
} |
53 |
} |
|
54 |
|
|
34 | 55 |
public bool IsDragging |
56 |
{ |
|
57 |
get |
|
58 |
{ |
|
59 |
return isDragging; |
|
60 |
} |
|
61 |
set |
|
62 |
{ |
|
63 |
isDragging = value; |
|
64 |
} |
|
65 |
} |
|
66 |
||
67 |
public bool FinishedDragging |
|
68 |
{ |
|
69 |
get |
|
70 |
{ |
|
71 |
return finishedDragging; |
|
72 |
} |
|
73 |
set |
|
74 |
{ |
|
75 |
finishedDragging = value; |
|
76 |
} |
|
77 |
} |
|
78 |
||
79 |
public DispatcherTimer Timer |
|
80 |
{ |
|
81 |
get |
|
82 |
{ |
|
83 |
return timer; |
|
84 |
} |
|
85 |
set |
|
86 |
{ |
|
87 |
timer = value; |
|
88 |
} |
|
89 |
} |
|
90 |
#endregion |
|
91 |
|
|
92 |
||
93 |
||
94 |
|
|
10 | 95 |
public UserControlTimeLine() |
129
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
96 |
{ |
10 | 97 |
this.InitializeComponent(); |
98 |
||
99 |
// Insert code required on object creation below this point. |
|
69 | 100 |
|
10 | 101 |
} |
102 |
||
124 | 103 |
public void initslider(double totalmillisecondsPar) |
34 | 104 |
{ |
124 | 105 |
totalmilliseconds = totalmillisecondsPar; |
34 | 106 |
slider.Maximum = totalmilliseconds; |
124 | 107 |
// When the timeline is resized, we catch the resize event to define TimelineView's good scale |
108 |
this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged); |
|
69 | 109 |
|
110 |
// TEMP FOR DATA BINDING |
|
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
111 |
AnnotList = new List<Annotation>(); |
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
112 |
AnnotList.Add(new Annotation(0, 10, "Axe Cam 1")); |
128
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
125
diff
changeset
|
113 |
//AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2")); |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
125
diff
changeset
|
114 |
//AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3")); |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
125
diff
changeset
|
115 |
//AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4")); |
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
125
diff
changeset
|
116 |
//AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5")); |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
117 |
Cutting cut = new Cutting("titre de cutting", AnnotList); |
129
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
118 |
CuttingVM = new CuttingViewModel(cut, AnnotWidth); |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
119 |
tv.DataContext = CuttingVM; |
69 | 120 |
|
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
121 |
slider_ContactTapGesture(this,null); |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
122 |
|
34 | 123 |
} |
124 |
||
124 | 125 |
void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e) |
126 |
{ |
|
127 |
// When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account. |
|
129
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
128 |
Double futurScale = (this.ActualWidth-30) / (totalmilliseconds / 1000); |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
129 |
//Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS |
124 | 130 |
tv.RenderTransform = new ScaleTransform(futurScale,1); |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
131 |
//Console.WriteLine("futurScale = " + futurScale); |
124 | 132 |
|
133 |
} |
|
134 |
||
34 | 135 |
#region Timer |
136 |
public void initTimer() |
|
137 |
{ |
|
138 |
timer = new DispatcherTimer(); |
|
139 |
timer.Interval = new TimeSpan(0, 0, 0, 0, 100); |
|
140 |
timer.Tick += new EventHandler(timer_Tick); |
|
141 |
} |
|
142 |
||
143 |
public void timerStart() |
|
144 |
{ |
|
145 |
if (timer != null) |
|
146 |
timer.Start(); |
|
147 |
} |
|
148 |
void timer_Tick(object sender, EventArgs e) |
|
10 | 149 |
{ |
34 | 150 |
OnTimerTick(); |
151 |
if (!isDragging) |
|
152 |
{ |
|
153 |
//slider.Value = media.Position.TotalMilliseconds; |
|
154 |
} |
|
155 |
if (finishedDragging) |
|
156 |
{ |
|
157 |
//int SliderValue = (int)slider.Value; |
|
158 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue); |
|
159 |
// media.Position = ts; |
|
160 |
// media.Play(); |
|
161 |
// isDragging = false; |
|
162 |
//finishedDragging = false; |
|
163 |
} |
|
164 |
} |
|
165 |
protected virtual void OnTimerTick() |
|
166 |
{ |
|
167 |
if (TimerTick != null) |
|
168 |
TimerTick(this, new EventArgs()); |
|
10 | 169 |
} |
34 | 170 |
|
171 |
#endregion |
|
172 |
||
128
90c29e979ef4
Drag and drop of annotations from timeline, first step
cavaliet
parents:
125
diff
changeset
|
173 |
private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e) |
34 | 174 |
{ |
175 |
isDragging = true; |
|
176 |
OnDragStarted(); |
|
177 |
// media.Pause(); |
|
178 |
} |
|
179 |
protected virtual void OnDragStarted() |
|
180 |
{ |
|
181 |
if (DragStarted != null) |
|
182 |
DragStarted(this, new EventArgs()); |
|
183 |
} |
|
184 |
||
185 |
private void sliderPosition_DragCompleted( |
|
186 |
object sender, DragCompletedEventArgs e) |
|
187 |
{ |
|
188 |
finishedDragging = true; |
|
189 |
OnDragCompleted(); |
|
190 |
} |
|
191 |
protected virtual void OnDragCompleted() |
|
192 |
{ |
|
193 |
if (DragCompleted != null) |
|
194 |
DragCompleted(this, new EventArgs()); |
|
195 |
} |
|
196 |
||
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
197 |
private void slider_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
198 |
{ |
99 | 199 |
//addAnnotation(); |
75
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
200 |
} |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
201 |
|
75
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
202 |
public void addAnnotation() |
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
203 |
{ |
129
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
204 |
Boolean annotOk = true; |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
205 |
// We open a new annotation |
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
206 |
if (CuttingVM != null && AnnotWaiting == false) |
124 | 207 |
{ |
129
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
208 |
AnnotTcBegin = (float)slider.Value / 1000; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
209 |
|
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
210 |
// First we check if the new annotation will not cover any |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
211 |
foreach (Annotation a in AnnotList) |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
212 |
{ |
130
192da585bee5
debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents:
129
diff
changeset
|
213 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
129
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
214 |
if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur)) |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
215 |
{ |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
216 |
annotOk = false; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
217 |
} |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
218 |
} |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
219 |
// if not, we mark the beginning |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
220 |
if (annotOk == true) |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
221 |
{ |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
222 |
AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString())); |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
223 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth); |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
224 |
//Console.WriteLine("BEGIN currentTimecode = " + AnnotTcBegin + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth))); |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
225 |
tv.DataContext = null; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
226 |
tv.DataContext = CuttingVM; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
227 |
AnnotWaiting = true; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
228 |
} |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
229 |
} |
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
230 |
// We close the current opened annotation... |
130
192da585bee5
debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents:
129
diff
changeset
|
231 |
else if (CuttingVM != null && AnnotWaiting == true && (((float)slider.Value/1000)>AnnotTcBegin)) |
125
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
232 |
{ |
fab494cd9da7
Now to define an annotation we define its begin then its end.
cavaliet
parents:
124
diff
changeset
|
233 |
// ... by setting setting the good beginning and the good duration |
129
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
234 |
float currentTC = (float)slider.Value / 1000; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
235 |
float currentDuration = currentTC - AnnotTcBegin; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
236 |
|
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
237 |
// First we check if the new annotation will not cover any (AnnotTcBegin was already checked) |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
238 |
foreach (Annotation a in AnnotList) |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
239 |
{ |
130
192da585bee5
debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents:
129
diff
changeset
|
240 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
129
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
241 |
if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC)) |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
242 |
{ |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
243 |
annotOk = false; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
244 |
} |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
245 |
} |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
246 |
|
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
247 |
if (annotOk == true) |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
248 |
{ |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
249 |
AnnotList.RemoveAt(AnnotList.Count - 1); |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
250 |
AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString())); |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
251 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth); |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
252 |
//Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth))); |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
253 |
tv.DataContext = null; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
254 |
tv.DataContext = CuttingVM; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
255 |
AnnotWaiting = false; |
1f37ef03ebee
scale change improved and now annotations can not recover any of them.
cavaliet
parents:
128
diff
changeset
|
256 |
} |
124 | 257 |
} |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
258 |
} |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
259 |
|
10 | 260 |
} |
261 |
} |