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