author | cavaliet |
Wed, 04 Nov 2009 16:28:01 +0100 | |
changeset 186 | 83615722dbab |
parent 169 | 3a407c966e57 |
child 190 | 619ca3ae13c7 |
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; |
|
143 | 8 |
using System.Windows.Input; |
10 | 9 |
using System.Windows.Media; |
10 |
using System.Windows.Media.Animation; |
|
11 |
using System.Windows.Navigation; |
|
34 | 12 |
using System.Windows.Controls.Primitives; |
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
13 |
using Microsoft.Surface.Presentation; |
34 | 14 |
using Microsoft.Surface.Presentation.Controls; |
15 |
using System.Windows.Threading; |
|
10 | 16 |
|
69 | 17 |
using FingersDance.Data; |
18 |
using FingersDance.ViewModels; |
|
143 | 19 |
using FingersDance.Views; |
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
20 |
using FingersDance.Control.Close; |
69 | 21 |
|
10 | 22 |
namespace FingersDance.Control.TimeLine |
23 |
{ |
|
24 |
public partial class UserControlTimeLine |
|
34 | 25 |
{ |
26 |
||
27 |
#region Variables |
|
28 |
private DispatcherTimer timer; |
|
29 |
private bool isDragging = false; |
|
30 |
private bool finishedDragging = false; |
|
31 |
#endregion |
|
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
32 |
|
34 | 33 |
public event EventHandler DragStarted; |
34 |
public event EventHandler DragCompleted; |
|
35 |
public event EventHandler TimerTick; |
|
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
160
diff
changeset
|
36 |
//SAR |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
160
diff
changeset
|
37 |
public event EventHandler OnSuccessAnnotation; |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
160
diff
changeset
|
38 |
//ENDSAR |
34 | 39 |
|
124 | 40 |
private double totalmilliseconds; |
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
41 |
|
143 | 42 |
private List<Annotation> AnnotList = new List<Annotation>(); |
166
33c2e634df13
update drag and drop for dragged annotation to be well displayed and avoid DnD problems
cavaliet
parents:
162
diff
changeset
|
43 |
private float AnnotWidth = 850 + 15; // The surfaceListBox adds 15 pixels between each item |
143 | 44 |
private CuttingViewModel CuttingVM; |
45 |
private Boolean AnnotWaiting = false; |
|
46 |
private float AnnotTcBegin; |
|
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
47 |
private Color CurrentColor; |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
48 |
|
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
49 |
private AnnotationViewModel canceledAnnotationVM; |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
50 |
|
34 | 51 |
#region Properties |
52 |
||
53 |
public SurfaceSlider Slider |
|
10 | 54 |
{ |
34 | 55 |
get |
56 |
{ |
|
57 |
return slider; |
|
10 | 58 |
} |
34 | 59 |
set |
60 |
{ |
|
61 |
slider = value; |
|
10 | 62 |
} |
63 |
} |
|
64 |
|
|
34 | 65 |
public bool IsDragging |
66 |
{ |
|
67 |
get |
|
68 |
{ |
|
69 |
return isDragging; |
|
70 |
} |
|
71 |
set |
|
72 |
{ |
|
73 |
isDragging = value; |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
public bool FinishedDragging |
|
78 |
{ |
|
79 |
get |
|
80 |
{ |
|
81 |
return finishedDragging; |
|
82 |
} |
|
83 |
set |
|
84 |
{ |
|
85 |
finishedDragging = value; |
|
86 |
} |
|
87 |
} |
|
88 |
||
89 |
public DispatcherTimer Timer |
|
90 |
{ |
|
91 |
get |
|
92 |
{ |
|
93 |
return timer; |
|
94 |
} |
|
95 |
set |
|
96 |
{ |
|
97 |
timer = value; |
|
98 |
} |
|
99 |
} |
|
100 |
#endregion |
|
101 |
||
102 |
||
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
103 |
#region Constructors |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
104 |
|
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
105 |
public UserControlTimeLine() |
143 | 106 |
{ |
10 | 107 |
this.InitializeComponent(); |
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
108 |
|
10 | 109 |
// Insert code required on object creation below this point. |
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
110 |
|
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
111 |
} |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
112 |
#endregion |
10 | 113 |
|
124 | 114 |
public void initslider(double totalmillisecondsPar) |
34 | 115 |
{ |
124 | 116 |
totalmilliseconds = totalmillisecondsPar; |
34 | 117 |
slider.Maximum = totalmilliseconds; |
124 | 118 |
// When the timeline is resized, we catch the resize event to define TimelineView's good scale |
119 |
this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged); |
|
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
120 |
|
143 | 121 |
tv.listview.PreviewContactDown += listview_PreviewContactDown; |
122 |
SurfaceDragDrop.AddDragCanceledHandler(tv.listview, onDragCanceled); |
|
123 |
||
124 |
UserControlTimeLine_SizeChanged(null, null); |
|
125 |
||
126 |
slider_ContactTapGesture(this, null); |
|
127 |
||
34 | 128 |
} |
129 |
||
124 | 130 |
void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e) |
131 |
{ |
|
132 |
// When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account. |
|
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
133 |
tv.ScaleX = (this.ActualWidth-30) / (totalmilliseconds / 1000); |
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
134 |
//tv.Width = this.ActualWidth - 30; |
124 | 135 |
|
136 |
} |
|
137 |
||
34 | 138 |
#region Timer |
186
83615722dbab
Debug data management for others panels to redisplay.
cavaliet
parents:
169
diff
changeset
|
139 |
public void initTimer(Color col, CuttingViewModel cutVMPar) |
34 | 140 |
{ |
141 |
timer = new DispatcherTimer(); |
|
142 |
timer.Interval = new TimeSpan(0, 0, 0, 0, 100); |
|
143 |
timer.Tick += new EventHandler(timer_Tick); |
|
150
569925b65604
Annotations are now colored with the same color as the pivot's button
cavaliet
parents:
146
diff
changeset
|
144 |
|
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
145 |
CurrentColor = col; |
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
146 |
|
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
147 |
// DATA BINDING from the cutting sent in parameter (initialised before by the userPanel with the global project) |
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
148 |
AnnotList = new List<Annotation>(); |
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
149 |
AnnotList.Add(new Annotation(0, 10, "Axe Cam 1", CurrentColor)); |
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
150 |
//AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2")); |
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
151 |
//AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3")); |
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
152 |
//AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4")); |
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
153 |
//AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5")); |
186
83615722dbab
Debug data management for others panels to redisplay.
cavaliet
parents:
169
diff
changeset
|
154 |
CuttingVM = new CuttingViewModel(new Cutting(cutVMPar.Title, AnnotList), AnnotWidth); |
83615722dbab
Debug data management for others panels to redisplay.
cavaliet
parents:
169
diff
changeset
|
155 |
cutVMPar = CuttingVM; |
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
156 |
tv.DataContext = CuttingVM; |
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
157 |
|
34 | 158 |
} |
159 |
||
160 |
public void timerStart() |
|
161 |
{ |
|
162 |
if (timer != null) |
|
163 |
timer.Start(); |
|
164 |
} |
|
165 |
void timer_Tick(object sender, EventArgs e) |
|
10 | 166 |
{ |
34 | 167 |
OnTimerTick(); |
168 |
if (!isDragging) |
|
169 |
{ |
|
170 |
//slider.Value = media.Position.TotalMilliseconds; |
|
171 |
} |
|
172 |
if (finishedDragging) |
|
173 |
{ |
|
174 |
//int SliderValue = (int)slider.Value; |
|
175 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue); |
|
176 |
// media.Position = ts; |
|
177 |
// media.Play(); |
|
178 |
// isDragging = false; |
|
179 |
//finishedDragging = false; |
|
180 |
} |
|
181 |
} |
|
182 |
protected virtual void OnTimerTick() |
|
183 |
{ |
|
184 |
if (TimerTick != null) |
|
185 |
TimerTick(this, new EventArgs()); |
|
10 | 186 |
} |
34 | 187 |
|
188 |
#endregion |
|
189 |
||
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
190 |
#region SliderDrag |
143 | 191 |
private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e) |
34 | 192 |
{ |
193 |
isDragging = true; |
|
194 |
OnDragStarted(); |
|
195 |
// media.Pause(); |
|
196 |
} |
|
197 |
protected virtual void OnDragStarted() |
|
198 |
{ |
|
199 |
if (DragStarted != null) |
|
200 |
DragStarted(this, new EventArgs()); |
|
201 |
} |
|
202 |
||
143 | 203 |
private void sliderPosition_DragCompleted(object sender, DragCompletedEventArgs e) |
34 | 204 |
{ |
205 |
finishedDragging = true; |
|
206 |
OnDragCompleted(); |
|
207 |
} |
|
208 |
protected virtual void OnDragCompleted() |
|
209 |
{ |
|
210 |
if (DragCompleted != null) |
|
211 |
DragCompleted(this, new EventArgs()); |
|
212 |
} |
|
213 |
||
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
214 |
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
|
215 |
{ |
143 | 216 |
//startOrEndAnnotation(); |
217 |
} |
|
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
218 |
#endregion |
143 | 219 |
|
168
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
220 |
public void thumbRotation(bool isplaying) |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
221 |
{ |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
222 |
//Templateslider.Style.Setters["Template"] |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
223 |
if(isplaying) |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
224 |
slider.Style = FindResource("FingersDance.Control.Slider") as Style; |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
225 |
else |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
226 |
slider.Style = FindResource("SurfaceSliderStylePause") as Style; |
d70ee2002f75
Thumb Timeline Rotation and Debug Closing Panels
ARIAS Santiago
parents:
162
diff
changeset
|
227 |
} |
143 | 228 |
public Boolean isAnnotationAccepted(AnnotationViewModel avm) |
229 |
{ |
|
230 |
Boolean annotOk = true; |
|
231 |
// We check if the annotation's begin and end timecodes allow a new annotation creation |
|
232 |
if (CuttingVM != null && AnnotWaiting == false) |
|
233 |
{ |
|
234 |
foreach (Annotation a in AnnotList) |
|
235 |
{ |
|
236 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
|
237 |
// Check begin TC |
|
238 |
if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur)) |
|
239 |
{ |
|
240 |
annotOk = false; |
|
241 |
} |
|
242 |
// Check end tc and if the new annotation will not cover any other |
|
243 |
float endTC = avm.TcBegin + avm.Dur; |
|
244 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
|
245 |
if (a.TcBegin <= endTC && endTC <= (a.TcBegin + a.Dur) || (avm.TcBegin < a.TcBegin && (a.TcBegin + a.Dur) < endTC)) |
|
246 |
{ |
|
247 |
annotOk = false; |
|
248 |
} |
|
249 |
} |
|
250 |
} |
|
251 |
else |
|
252 |
{ |
|
253 |
annotOk = false; |
|
254 |
} |
|
255 |
return annotOk; |
|
256 |
||
75
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
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 |
|
143 | 259 |
public void addAnnotation(AnnotationViewModel avm) |
75
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
260 |
{ |
143 | 261 |
//Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType); |
262 |
Boolean annotOk = true; |
|
263 |
// We check if the annotation's begin and end timecodes allow a new annotation creation |
|
264 |
if (CuttingVM != null && AnnotWaiting == false) |
|
265 |
{ |
|
266 |
foreach (Annotation a in AnnotList) |
|
267 |
{ |
|
268 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
|
269 |
// Check begin TC |
|
270 |
if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur)) |
|
271 |
{ |
|
272 |
annotOk = false; |
|
273 |
} |
|
274 |
// Check end tc and if the new annotation will not cover any other |
|
275 |
float endTC = avm.TcBegin + avm.Dur; |
|
276 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
|
277 |
if (a.TcBegin <= endTC && endTC <= (a.TcBegin + a.Dur) || (avm.TcBegin < a.TcBegin && (a.TcBegin + a.Dur) < endTC)) |
|
278 |
{ |
|
279 |
annotOk = false; |
|
280 |
} |
|
281 |
} |
|
282 |
// If everything's fine, we create the new one |
|
283 |
if (annotOk == true) |
|
284 |
{ |
|
150
569925b65604
Annotations are now colored with the same color as the pivot's button
cavaliet
parents:
146
diff
changeset
|
285 |
AnnotList.Add(new Annotation(avm.TcBegin, avm.Dur, avm.GestureType, avm.Color)); |
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
286 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
143 | 287 |
tv.DataContext = null; |
288 |
tv.DataContext = CuttingVM; |
|
289 |
AnnotWaiting = false; |
|
290 |
} |
|
291 |
||
292 |
} |
|
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
160
diff
changeset
|
293 |
//Raise Event to display Annotation in all Openned UserPanels |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
160
diff
changeset
|
294 |
if (annotOk) |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
160
diff
changeset
|
295 |
OnSuccessAnnotation(this, new EventArgs()); |
143 | 296 |
|
297 |
} |
|
298 |
||
299 |
public void startOrEndAnnotation() |
|
300 |
{ |
|
301 |
Boolean annotOk = true; |
|
302 |
// We open a new annotation |
|
303 |
if (CuttingVM != null && AnnotWaiting == false) |
|
124 | 304 |
{ |
143 | 305 |
AnnotTcBegin = (float)slider.Value / 1000; |
306 |
||
307 |
// First we check if the new annotation will not cover any |
|
308 |
foreach (Annotation a in AnnotList) |
|
309 |
{ |
|
310 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
|
311 |
if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur)) |
|
312 |
{ |
|
313 |
annotOk = false; |
|
314 |
} |
|
315 |
} |
|
316 |
// if not, we mark the beginning |
|
317 |
if (annotOk == true) |
|
318 |
{ |
|
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
319 |
AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString(), CurrentColor)); |
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
320 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
143 | 321 |
tv.DataContext = null; |
322 |
tv.DataContext = CuttingVM; |
|
323 |
AnnotWaiting = true; |
|
324 |
} |
|
325 |
} |
|
326 |
// We close the current opened annotation... |
|
327 |
else if (CuttingVM != null && AnnotWaiting == true && (((float)slider.Value/1000)>AnnotTcBegin)) |
|
328 |
{ |
|
329 |
// ... by setting setting the good beginning and the good duration |
|
330 |
float currentTC = (float)slider.Value / 1000; |
|
331 |
float currentDuration = currentTC - AnnotTcBegin; |
|
332 |
||
333 |
// First we check if the new annotation will not cover any (AnnotTcBegin was already checked) |
|
334 |
foreach (Annotation a in AnnotList) |
|
335 |
{ |
|
336 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
|
337 |
if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC)) |
|
338 |
{ |
|
339 |
annotOk = false; |
|
340 |
} |
|
341 |
} |
|
342 |
||
343 |
if (annotOk == true) |
|
344 |
{ |
|
345 |
AnnotList.RemoveAt(AnnotList.Count - 1); |
|
160
e940ca798fe3
Enhance color factory and send the current project (data) to the timeline instance in order to build the project's cutting's annotation list.
cavaliet
parents:
150
diff
changeset
|
346 |
AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString(), CurrentColor)); |
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
347 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
143 | 348 |
//Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth))); |
349 |
tv.DataContext = null; |
|
350 |
tv.DataContext = CuttingVM; |
|
351 |
AnnotWaiting = false; |
|
352 |
} |
|
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
353 |
//Raise Event to display Annotation in all Openned UserPanels |
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
354 |
if (annotOk) |
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
355 |
OnSuccessAnnotation(this, new EventArgs()); |
124 | 356 |
} |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
357 |
} |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
358 |
|
143 | 359 |
private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
360 |
{ |
|
361 |
FrameworkElement findSource = e.OriginalSource as FrameworkElement; |
|
362 |
SurfaceListBoxItem draggedElement = null; |
|
363 |
||
364 |
// Find the touched SurfaceListBoxItem object. |
|
365 |
while (draggedElement == null && findSource != null) |
|
366 |
{ |
|
367 |
if ((draggedElement = findSource as SurfaceListBoxItem) == null) |
|
368 |
{ |
|
369 |
findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement; |
|
370 |
} |
|
371 |
} |
|
372 |
||
373 |
if (draggedElement == null) |
|
374 |
{ |
|
375 |
return; |
|
376 |
} |
|
377 |
||
378 |
// Create the cursor visual. |
|
379 |
ContentControl cursorVisual = new ContentControl() |
|
380 |
{ |
|
381 |
Content = new TimelineAnnotationView() |
|
382 |
{ |
|
383 |
DataContext = findSource.DataContext |
|
384 |
} |
|
385 |
}; |
|
386 |
||
387 |
// We apply the current scale to the dragged annotation |
|
166
33c2e634df13
update drag and drop for dragged annotation to be well displayed and avoid DnD problems
cavaliet
parents:
162
diff
changeset
|
388 |
((TimelineAnnotationView)cursorVisual.Content).RenderTransform = new TransformGroup(); |
33c2e634df13
update drag and drop for dragged annotation to be well displayed and avoid DnD problems
cavaliet
parents:
162
diff
changeset
|
389 |
((TransformGroup)((TimelineAnnotationView)cursorVisual.Content).RenderTransform).Children.Add(tv.listview.RenderTransform); |
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
390 |
// We apply a translate transform to place correctly the dragged annotation |
166
33c2e634df13
update drag and drop for dragged annotation to be well displayed and avoid DnD problems
cavaliet
parents:
162
diff
changeset
|
391 |
((TransformGroup)((TimelineAnnotationView)cursorVisual.Content).RenderTransform).Children.Add(new TranslateTransform((AnnotWidth / 2) * (1 - ((ScaleTransform)tv.listview.RenderTransform).ScaleX), 0)); |
33c2e634df13
update drag and drop for dragged annotation to be well displayed and avoid DnD problems
cavaliet
parents:
162
diff
changeset
|
392 |
|
143 | 393 |
// Add a handler. This will enable the application to change the visual cues. (NOT USEFUL IN FINGERSDANCE CASE) |
394 |
//SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged); |
|
395 |
||
396 |
// Create a list of input devices. Add the contacts that |
|
397 |
// are currently captured within the dragged element and |
|
398 |
// the current contact (if it isn't already in the list). |
|
399 |
List<InputDevice> devices = new List<InputDevice>(); |
|
400 |
devices.Add(e.Contact); |
|
401 |
foreach (Contact contact in draggedElement.ContactsCapturedWithin) |
|
402 |
{ |
|
403 |
if (contact != e.Contact) |
|
404 |
{ |
|
405 |
devices.Add(contact); |
|
406 |
} |
|
407 |
} |
|
408 |
||
409 |
// Get the drag source object |
|
410 |
ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement); |
|
411 |
||
412 |
bool startDragOkay = |
|
413 |
SurfaceDragDrop.BeginDragDrop( |
|
414 |
dragSource, // The SurfaceListBox object that the cursor is dragged out from. |
|
415 |
draggedElement, // The SurfaceListBoxItem object that is dragged from the drag source. |
|
416 |
cursorVisual, // The visual element of the cursor. |
|
417 |
draggedElement.DataContext, // The data associated with the cursor. |
|
418 |
devices, // The input devices that start dragging the cursor. |
|
419 |
DragDropEffects.Move); // The allowed drag-and-drop effects of the operation. |
|
420 |
||
421 |
// If the drag began successfully, set e.Handled to true. |
|
422 |
// Otherwise SurfaceListBoxItem captures the contact |
|
423 |
// and causes the drag operation to fail. |
|
424 |
e.Handled = startDragOkay; |
|
425 |
} |
|
426 |
||
427 |
private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e) |
|
428 |
{ |
|
429 |
// We check if the annotation is well one of the current annotations |
|
430 |
if (CuttingVM != null) |
|
431 |
{ |
|
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
432 |
// e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
433 |
canceledAnnotationVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext; |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
434 |
confirmCancelPopup.Visibility = Visibility.Visible; |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
435 |
} |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
436 |
} |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
437 |
|
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
438 |
private void confirmCancelPopup_ConfirmYesOrNo(object sender, ConfirmEventArgs e) |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
439 |
{ |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
440 |
// We check if the annotation is well one of the current annotations |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
441 |
if (CuttingVM != null && canceledAnnotationVM != null && e.Confirmed == true) |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
442 |
{ |
143 | 443 |
foreach (Annotation a in AnnotList) |
444 |
{ |
|
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
445 |
// Check begin TcBegin, duration and gesture type |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
446 |
if (a.TcBegin == canceledAnnotationVM.TcBegin && a.Dur == canceledAnnotationVM.Dur && a.GestureType == canceledAnnotationVM.GestureType) |
143 | 447 |
{ |
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
448 |
// We found the good annotation so we can remove it |
143 | 449 |
AnnotList.Remove(a); |
450 |
// We redisplay the timeline |
|
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
451 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
143 | 452 |
tv.DataContext = null; |
453 |
tv.DataContext = CuttingVM; |
|
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
454 |
// We close the popup and return as soon as we removed the annotation to avoid an error on AnnotList, which is just modified |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
455 |
confirmCancelPopup.Visibility = Visibility.Hidden; |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
456 |
canceledAnnotationVM = null; |
143 | 457 |
return; |
458 |
} |
|
459 |
} |
|
460 |
} |
|
140
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
461 |
confirmCancelPopup.Visibility = Visibility.Hidden; |
fc7c12f9da30
Add a confirm dialog box before deleting an annotation by drag and drop. Now the UserControlClose is a generic confirm dialog box sending a ConfirmYesOrNo Event.
cavaliet
parents:
136
diff
changeset
|
462 |
canceledAnnotationVM = null; |
143 | 463 |
} |
464 |
||
465 |
||
10 | 466 |
} |
467 |
} |