author | cavaliet |
Thu, 22 Oct 2009 14:48:43 +0200 | |
changeset 167 | 206f07a8d887 |
parent 166 | 33c2e634df13 |
child 169 | 3a407c966e57 |
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 |
||
103 |
||
104 |
|
|
10 | 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. |
69 | 110 |
|
10 | 111 |
} |
112 |
||
124 | 113 |
public void initslider(double totalmillisecondsPar) |
34 | 114 |
{ |
124 | 115 |
totalmilliseconds = totalmillisecondsPar; |
34 | 116 |
slider.Maximum = totalmilliseconds; |
124 | 117 |
// When the timeline is resized, we catch the resize event to define TimelineView's good scale |
118 |
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
|
119 |
|
143 | 120 |
tv.listview.PreviewContactDown += listview_PreviewContactDown; |
121 |
SurfaceDragDrop.AddDragCanceledHandler(tv.listview, onDragCanceled); |
|
122 |
||
123 |
UserControlTimeLine_SizeChanged(null, null); |
|
124 |
||
125 |
slider_ContactTapGesture(this, null); |
|
126 |
||
34 | 127 |
} |
128 |
||
124 | 129 |
void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e) |
130 |
{ |
|
131 |
// 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
|
132 |
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
|
133 |
//tv.Width = this.ActualWidth - 30; |
124 | 134 |
|
135 |
} |
|
136 |
||
34 | 137 |
#region Timer |
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
|
138 |
public void initTimer(Color col, Cutting cutPar) |
34 | 139 |
{ |
140 |
timer = new DispatcherTimer(); |
|
141 |
timer.Interval = new TimeSpan(0, 0, 0, 0, 100); |
|
142 |
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
|
143 |
|
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
|
144 |
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
|
145 |
|
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 |
// 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
|
147 |
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
|
148 |
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
|
149 |
//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
|
150 |
//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
|
151 |
//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
|
152 |
//AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5")); |
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 |
cutPar = new Cutting("titre de cutting", AnnotList); |
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
|
154 |
CuttingVM = new CuttingViewModel(cutPar, AnnotWidth); |
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
|
155 |
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
|
156 |
|
34 | 157 |
} |
158 |
||
159 |
public void timerStart() |
|
160 |
{ |
|
161 |
if (timer != null) |
|
162 |
timer.Start(); |
|
163 |
} |
|
164 |
void timer_Tick(object sender, EventArgs e) |
|
10 | 165 |
{ |
34 | 166 |
OnTimerTick(); |
167 |
if (!isDragging) |
|
168 |
{ |
|
169 |
//slider.Value = media.Position.TotalMilliseconds; |
|
170 |
} |
|
171 |
if (finishedDragging) |
|
172 |
{ |
|
173 |
//int SliderValue = (int)slider.Value; |
|
174 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue); |
|
175 |
// media.Position = ts; |
|
176 |
// media.Play(); |
|
177 |
// isDragging = false; |
|
178 |
//finishedDragging = false; |
|
179 |
} |
|
180 |
} |
|
181 |
protected virtual void OnTimerTick() |
|
182 |
{ |
|
183 |
if (TimerTick != null) |
|
184 |
TimerTick(this, new EventArgs()); |
|
10 | 185 |
} |
34 | 186 |
|
187 |
#endregion |
|
188 |
||
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
|
189 |
#region SliderDrag |
143 | 190 |
private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e) |
34 | 191 |
{ |
192 |
isDragging = true; |
|
193 |
OnDragStarted(); |
|
194 |
// media.Pause(); |
|
195 |
} |
|
196 |
protected virtual void OnDragStarted() |
|
197 |
{ |
|
198 |
if (DragStarted != null) |
|
199 |
DragStarted(this, new EventArgs()); |
|
200 |
} |
|
201 |
||
143 | 202 |
private void sliderPosition_DragCompleted(object sender, DragCompletedEventArgs e) |
34 | 203 |
{ |
204 |
finishedDragging = true; |
|
205 |
OnDragCompleted(); |
|
206 |
} |
|
207 |
protected virtual void OnDragCompleted() |
|
208 |
{ |
|
209 |
if (DragCompleted != null) |
|
210 |
DragCompleted(this, new EventArgs()); |
|
211 |
} |
|
212 |
||
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
213 |
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
|
214 |
{ |
143 | 215 |
//startOrEndAnnotation(); |
216 |
} |
|
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
|
217 |
#endregion |
143 | 218 |
|
219 |
public Boolean isAnnotationAccepted(AnnotationViewModel avm) |
|
220 |
{ |
|
221 |
Boolean annotOk = true; |
|
222 |
// We check if the annotation's begin and end timecodes allow a new annotation creation |
|
223 |
if (CuttingVM != null && AnnotWaiting == false) |
|
224 |
{ |
|
225 |
foreach (Annotation a in AnnotList) |
|
226 |
{ |
|
227 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
|
228 |
// Check begin TC |
|
229 |
if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur)) |
|
230 |
{ |
|
231 |
annotOk = false; |
|
232 |
} |
|
233 |
// Check end tc and if the new annotation will not cover any other |
|
234 |
float endTC = avm.TcBegin + avm.Dur; |
|
235 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
|
236 |
if (a.TcBegin <= endTC && endTC <= (a.TcBegin + a.Dur) || (avm.TcBegin < a.TcBegin && (a.TcBegin + a.Dur) < endTC)) |
|
237 |
{ |
|
238 |
annotOk = false; |
|
239 |
} |
|
240 |
} |
|
241 |
} |
|
242 |
else |
|
243 |
{ |
|
244 |
annotOk = false; |
|
245 |
} |
|
246 |
return annotOk; |
|
247 |
||
75
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
248 |
} |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
249 |
|
143 | 250 |
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
|
251 |
{ |
143 | 252 |
//Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType); |
253 |
Boolean annotOk = true; |
|
254 |
// We check if the annotation's begin and end timecodes allow a new annotation creation |
|
255 |
if (CuttingVM != null && AnnotWaiting == false) |
|
256 |
{ |
|
257 |
foreach (Annotation a in AnnotList) |
|
258 |
{ |
|
259 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
|
260 |
// Check begin TC |
|
261 |
if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur)) |
|
262 |
{ |
|
263 |
annotOk = false; |
|
264 |
} |
|
265 |
// Check end tc and if the new annotation will not cover any other |
|
266 |
float endTC = avm.TcBegin + avm.Dur; |
|
267 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
|
268 |
if (a.TcBegin <= endTC && endTC <= (a.TcBegin + a.Dur) || (avm.TcBegin < a.TcBegin && (a.TcBegin + a.Dur) < endTC)) |
|
269 |
{ |
|
270 |
annotOk = false; |
|
271 |
} |
|
272 |
} |
|
273 |
// If everything's fine, we create the new one |
|
274 |
if (annotOk == true) |
|
275 |
{ |
|
150
569925b65604
Annotations are now colored with the same color as the pivot's button
cavaliet
parents:
146
diff
changeset
|
276 |
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
|
277 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
143 | 278 |
tv.DataContext = null; |
279 |
tv.DataContext = CuttingVM; |
|
280 |
AnnotWaiting = false; |
|
281 |
} |
|
282 |
||
283 |
} |
|
162
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
160
diff
changeset
|
284 |
//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
|
285 |
if (annotOk) |
0b9f989bcb37
Display annotations in all opened UserPanels with the user's color
sarias
parents:
160
diff
changeset
|
286 |
OnSuccessAnnotation(this, new EventArgs()); |
143 | 287 |
|
288 |
} |
|
289 |
||
290 |
public void startOrEndAnnotation() |
|
291 |
{ |
|
292 |
Boolean annotOk = true; |
|
293 |
// We open a new annotation |
|
294 |
if (CuttingVM != null && AnnotWaiting == false) |
|
124 | 295 |
{ |
143 | 296 |
AnnotTcBegin = (float)slider.Value / 1000; |
297 |
||
298 |
// First we check if the new annotation will not cover any |
|
299 |
foreach (Annotation a in AnnotList) |
|
300 |
{ |
|
301 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); |
|
302 |
if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur)) |
|
303 |
{ |
|
304 |
annotOk = false; |
|
305 |
} |
|
306 |
} |
|
307 |
// if not, we mark the beginning |
|
308 |
if (annotOk == true) |
|
309 |
{ |
|
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
|
310 |
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
|
311 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
143 | 312 |
tv.DataContext = null; |
313 |
tv.DataContext = CuttingVM; |
|
314 |
AnnotWaiting = true; |
|
315 |
} |
|
316 |
} |
|
317 |
// We close the current opened annotation... |
|
318 |
else if (CuttingVM != null && AnnotWaiting == true && (((float)slider.Value/1000)>AnnotTcBegin)) |
|
319 |
{ |
|
320 |
// ... by setting setting the good beginning and the good duration |
|
321 |
float currentTC = (float)slider.Value / 1000; |
|
322 |
float currentDuration = currentTC - AnnotTcBegin; |
|
323 |
||
324 |
// First we check if the new annotation will not cover any (AnnotTcBegin was already checked) |
|
325 |
foreach (Annotation a in AnnotList) |
|
326 |
{ |
|
327 |
//Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); |
|
328 |
if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC)) |
|
329 |
{ |
|
330 |
annotOk = false; |
|
331 |
} |
|
332 |
} |
|
333 |
||
334 |
if (annotOk == true) |
|
335 |
{ |
|
336 |
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
|
337 |
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
|
338 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
143 | 339 |
//Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth))); |
340 |
tv.DataContext = null; |
|
341 |
tv.DataContext = CuttingVM; |
|
342 |
AnnotWaiting = false; |
|
343 |
} |
|
167
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
344 |
//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
|
345 |
if (annotOk) |
206f07a8d887
Annotation's scale is now still visually at one, whatever the timeline's scale.
cavaliet
parents:
166
diff
changeset
|
346 |
OnSuccessAnnotation(this, new EventArgs()); |
124 | 347 |
} |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
348 |
} |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
349 |
|
143 | 350 |
private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e) |
351 |
{ |
|
352 |
FrameworkElement findSource = e.OriginalSource as FrameworkElement; |
|
353 |
SurfaceListBoxItem draggedElement = null; |
|
354 |
||
355 |
// Find the touched SurfaceListBoxItem object. |
|
356 |
while (draggedElement == null && findSource != null) |
|
357 |
{ |
|
358 |
if ((draggedElement = findSource as SurfaceListBoxItem) == null) |
|
359 |
{ |
|
360 |
findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement; |
|
361 |
} |
|
362 |
} |
|
363 |
||
364 |
if (draggedElement == null) |
|
365 |
{ |
|
366 |
return; |
|
367 |
} |
|
368 |
||
369 |
// Create the cursor visual. |
|
370 |
ContentControl cursorVisual = new ContentControl() |
|
371 |
{ |
|
372 |
Content = new TimelineAnnotationView() |
|
373 |
{ |
|
374 |
DataContext = findSource.DataContext |
|
375 |
} |
|
376 |
}; |
|
377 |
||
378 |
// 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
|
379 |
((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
|
380 |
((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
|
381 |
// 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
|
382 |
((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
|
383 |
|
143 | 384 |
// Add a handler. This will enable the application to change the visual cues. (NOT USEFUL IN FINGERSDANCE CASE) |
385 |
//SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged); |
|
386 |
||
387 |
// Create a list of input devices. Add the contacts that |
|
388 |
// are currently captured within the dragged element and |
|
389 |
// the current contact (if it isn't already in the list). |
|
390 |
List<InputDevice> devices = new List<InputDevice>(); |
|
391 |
devices.Add(e.Contact); |
|
392 |
foreach (Contact contact in draggedElement.ContactsCapturedWithin) |
|
393 |
{ |
|
394 |
if (contact != e.Contact) |
|
395 |
{ |
|
396 |
devices.Add(contact); |
|
397 |
} |
|
398 |
} |
|
399 |
||
400 |
// Get the drag source object |
|
401 |
ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement); |
|
402 |
||
403 |
bool startDragOkay = |
|
404 |
SurfaceDragDrop.BeginDragDrop( |
|
405 |
dragSource, // The SurfaceListBox object that the cursor is dragged out from. |
|
406 |
draggedElement, // The SurfaceListBoxItem object that is dragged from the drag source. |
|
407 |
cursorVisual, // The visual element of the cursor. |
|
408 |
draggedElement.DataContext, // The data associated with the cursor. |
|
409 |
devices, // The input devices that start dragging the cursor. |
|
410 |
DragDropEffects.Move); // The allowed drag-and-drop effects of the operation. |
|
411 |
||
412 |
// If the drag began successfully, set e.Handled to true. |
|
413 |
// Otherwise SurfaceListBoxItem captures the contact |
|
414 |
// and causes the drag operation to fail. |
|
415 |
e.Handled = startDragOkay; |
|
416 |
} |
|
417 |
||
418 |
private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e) |
|
419 |
{ |
|
420 |
// We check if the annotation is well one of the current annotations |
|
421 |
if (CuttingVM != null) |
|
422 |
{ |
|
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
|
423 |
// 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
|
424 |
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
|
425 |
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
|
426 |
} |
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
|
427 |
} |
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
|
428 |
|
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
|
429 |
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
|
430 |
{ |
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
|
431 |
// 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
|
432 |
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
|
433 |
{ |
143 | 434 |
foreach (Annotation a in AnnotList) |
435 |
{ |
|
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
|
436 |
// 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
|
437 |
if (a.TcBegin == canceledAnnotationVM.TcBegin && a.Dur == canceledAnnotationVM.Dur && a.GestureType == canceledAnnotationVM.GestureType) |
143 | 438 |
{ |
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
|
439 |
// We found the good annotation so we can remove it |
143 | 440 |
AnnotList.Remove(a); |
441 |
// 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
|
442 |
CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth, tv.ScaleX); |
143 | 443 |
tv.DataContext = null; |
444 |
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
|
445 |
// 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
|
446 |
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
|
447 |
canceledAnnotationVM = null; |
143 | 448 |
return; |
449 |
} |
|
450 |
} |
|
451 |
} |
|
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
|
452 |
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
|
453 |
canceledAnnotationVM = null; |
143 | 454 |
} |
455 |
||
456 |
||
10 | 457 |
} |
458 |
} |