author | cavaliet |
Fri, 25 Sep 2009 18:28:58 +0200 | |
changeset 124 | 14b058fc64fc |
parent 115 | 1e87bcfec117 |
child 125 | fab494cd9da7 |
child 143 | 9f157d9c725b |
permissions | -rw-r--r-- |
10 | 1 |
using System; |
69 | 2 |
using System.Collections.Generic; |
10 | 3 |
using System.IO; |
4 |
using System.Net; |
|
5 |
using System.Windows; |
|
6 |
using System.Windows.Controls; |
|
7 |
using System.Windows.Data; |
|
8 |
using System.Windows.Media; |
|
9 |
using System.Windows.Media.Animation; |
|
10 |
using System.Windows.Navigation; |
|
34 | 11 |
using System.Windows.Controls.Primitives; |
12 |
using Microsoft.Surface.Presentation.Controls; |
|
13 |
using System.Windows.Threading; |
|
10 | 14 |
|
69 | 15 |
using FingersDance.Data; |
16 |
using FingersDance.ViewModels; |
|
17 |
||
10 | 18 |
namespace FingersDance.Control.TimeLine |
19 |
{ |
|
20 |
public partial class UserControlTimeLine |
|
34 | 21 |
{ |
22 |
||
23 |
#region Variables |
|
24 |
private DispatcherTimer timer; |
|
25 |
private bool isDragging = false; |
|
26 |
private bool finishedDragging = false; |
|
27 |
#endregion |
|
28 |
||
29 |
public event EventHandler DragStarted; |
|
30 |
public event EventHandler DragCompleted; |
|
31 |
public event EventHandler TimerTick; |
|
32 |
||
124 | 33 |
private double totalmilliseconds; |
34 |
||
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
35 |
private List<Annotation> annotList = new List<Annotation>(); |
124 | 36 |
private float annotWidth = 40+1; |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
37 |
private CuttingViewModel cutvm; |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
38 |
|
34 | 39 |
#region Properties |
40 |
||
41 |
public SurfaceSlider Slider |
|
10 | 42 |
{ |
34 | 43 |
get |
44 |
{ |
|
45 |
return slider; |
|
10 | 46 |
} |
34 | 47 |
set |
48 |
{ |
|
49 |
slider = value; |
|
10 | 50 |
} |
51 |
} |
|
52 |
|
|
34 | 53 |
public bool IsDragging |
54 |
{ |
|
55 |
get |
|
56 |
{ |
|
57 |
return isDragging; |
|
58 |
} |
|
59 |
set |
|
60 |
{ |
|
61 |
isDragging = value; |
|
62 |
} |
|
63 |
} |
|
64 |
||
65 |
public bool FinishedDragging |
|
66 |
{ |
|
67 |
get |
|
68 |
{ |
|
69 |
return finishedDragging; |
|
70 |
} |
|
71 |
set |
|
72 |
{ |
|
73 |
finishedDragging = value; |
|
74 |
} |
|
75 |
} |
|
76 |
||
77 |
public DispatcherTimer Timer |
|
78 |
{ |
|
79 |
get |
|
80 |
{ |
|
81 |
return timer; |
|
82 |
} |
|
83 |
set |
|
84 |
{ |
|
85 |
timer = value; |
|
86 |
} |
|
87 |
} |
|
88 |
#endregion |
|
89 |
|
|
90 |
||
91 |
||
92 |
|
|
10 | 93 |
public UserControlTimeLine() |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
94 |
{ |
10 | 95 |
this.InitializeComponent(); |
96 |
||
97 |
// Insert code required on object creation below this point. |
|
69 | 98 |
|
10 | 99 |
} |
100 |
||
124 | 101 |
public void initslider(double totalmillisecondsPar) |
34 | 102 |
{ |
124 | 103 |
totalmilliseconds = totalmillisecondsPar; |
34 | 104 |
slider.Maximum = totalmilliseconds; |
124 | 105 |
// When the timeline is resized, we catch the resize event to define TimelineView's good scale |
106 |
this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged); |
|
69 | 107 |
|
108 |
// TEMP FOR DATA BINDING |
|
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
109 |
annotList = new List<Annotation>(); |
69 | 110 |
annotList.Add(new Annotation(0, 10, "Axe Cam 1")); |
124 | 111 |
//annotList.Add(new Annotation(20 - (1 * annotWidth), 30, "Mvt Cam 2")); |
112 |
//annotList.Add(new Annotation(50 - (2 * annotWidth), 60, "Saut 3")); |
|
113 |
//annotList.Add(new Annotation(100 - (3 * annotWidth), 20, "Saut 4")); |
|
114 |
//annotList.Add(new Annotation(120 - (4 * annotWidth), 50, "Saut 5")); |
|
69 | 115 |
Cutting cut = new Cutting("titre de cutting", annotList); |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
116 |
cutvm = new CuttingViewModel(cut); |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
117 |
tv.DataContext = cutvm; |
69 | 118 |
|
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
119 |
slider_ContactTapGesture(this,null); |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
120 |
/* |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
121 |
cutvm.AnnotList.Add(new AnnotationViewModel(new Annotation(180 - (5 * annotWidth), 10, "6"))); |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
122 |
tv.DataContext = null; |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
123 |
tv.DataContext = cutvm; |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
124 |
*/ |
34 | 125 |
} |
126 |
||
124 | 127 |
void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e) |
128 |
{ |
|
129 |
// When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account. |
|
130 |
Double futurScale = this.ActualWidth / (totalmilliseconds / 1000); |
|
131 |
//Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP |
|
132 |
tv.RenderTransform = new ScaleTransform(futurScale,1); |
|
133 |
Console.WriteLine("futurScale = " + futurScale); |
|
134 |
|
|
135 |
} |
|
136 |
||
34 | 137 |
#region Timer |
138 |
public void initTimer() |
|
139 |
{ |
|
140 |
timer = new DispatcherTimer(); |
|
141 |
timer.Interval = new TimeSpan(0, 0, 0, 0, 100); |
|
142 |
timer.Tick += new EventHandler(timer_Tick); |
|
143 |
} |
|
144 |
||
145 |
public void timerStart() |
|
146 |
{ |
|
147 |
if (timer != null) |
|
148 |
timer.Start(); |
|
149 |
} |
|
150 |
void timer_Tick(object sender, EventArgs e) |
|
10 | 151 |
{ |
34 | 152 |
OnTimerTick(); |
153 |
if (!isDragging) |
|
154 |
{ |
|
155 |
//slider.Value = media.Position.TotalMilliseconds; |
|
156 |
} |
|
157 |
if (finishedDragging) |
|
158 |
{ |
|
159 |
//int SliderValue = (int)slider.Value; |
|
160 |
//TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue); |
|
161 |
// media.Position = ts; |
|
162 |
// media.Play(); |
|
163 |
// isDragging = false; |
|
164 |
//finishedDragging = false; |
|
165 |
} |
|
166 |
} |
|
167 |
protected virtual void OnTimerTick() |
|
168 |
{ |
|
169 |
if (TimerTick != null) |
|
170 |
TimerTick(this, new EventArgs()); |
|
10 | 171 |
} |
34 | 172 |
|
173 |
#endregion |
|
174 |
||
175 |
private void sliderPosition_DragStarted( |
|
176 |
object sender, DragStartedEventArgs e) |
|
177 |
{ |
|
178 |
isDragging = true; |
|
179 |
OnDragStarted(); |
|
180 |
// media.Pause(); |
|
181 |
} |
|
182 |
protected virtual void OnDragStarted() |
|
183 |
{ |
|
184 |
if (DragStarted != null) |
|
185 |
DragStarted(this, new EventArgs()); |
|
186 |
} |
|
187 |
||
188 |
private void sliderPosition_DragCompleted( |
|
189 |
object sender, DragCompletedEventArgs e) |
|
190 |
{ |
|
191 |
finishedDragging = true; |
|
192 |
OnDragCompleted(); |
|
193 |
} |
|
194 |
protected virtual void OnDragCompleted() |
|
195 |
{ |
|
196 |
if (DragCompleted != null) |
|
197 |
DragCompleted(this, new EventArgs()); |
|
198 |
} |
|
199 |
||
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
200 |
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
|
201 |
{ |
99 | 202 |
//addAnnotation(); |
75
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
203 |
} |
74
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
204 |
|
75
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
205 |
public void addAnnotation() |
99d003723474
data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents:
74
diff
changeset
|
206 |
{ |
124 | 207 |
if (cutvm!=null) |
208 |
{ |
|
209 |
float currentTimecode = (float)slider.Value / 1000; |
|
210 |
cutvm.AnnotList.Add(new AnnotationViewModel(new Annotation(currentTimecode - (cutvm.AnnotList.Count * annotWidth), 10, cutvm.AnnotList.Count.ToString()))); |
|
211 |
Console.WriteLine("currentTimecode = " + currentTimecode + ", nb = " + cutvm.AnnotList.Count + ", res = " + (currentTimecode - (cutvm.AnnotList.Count * annotWidth))); |
|
212 |
tv.DataContext = null; |
|
213 |
tv.DataContext = cutvm; |
|
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 |
} |
7ce946833eae
First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents:
69
diff
changeset
|
216 |
|
10 | 217 |
} |
218 |
} |