src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
changeset 129 1f37ef03ebee
parent 128 90c29e979ef4
child 130 192da585bee5
--- a/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Fri Oct 02 18:49:07 2009 +0200
+++ b/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Mon Oct 05 15:56:27 2009 +0200
@@ -94,7 +94,7 @@
 
         
 		public UserControlTimeLine()
-		{   
+		{
 			this.InitializeComponent();
 
 			// Insert code required on object creation below this point.
@@ -116,7 +116,7 @@
             //AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4"));
             //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5"));
             Cutting cut = new Cutting("titre de cutting", AnnotList);
-            CuttingVM = new CuttingViewModel(cut);
+            CuttingVM = new CuttingViewModel(cut, AnnotWidth);
             tv.DataContext = CuttingVM;
 
             slider_ContactTapGesture(this,null);
@@ -126,7 +126,7 @@
         void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
         {
             // When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account.
-            Double futurScale = this.ActualWidth / (totalmilliseconds / 1000);
+            Double futurScale = (this.ActualWidth-30) / (totalmilliseconds / 1000);
             //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS
             tv.RenderTransform = new ScaleTransform(futurScale,1);
             //Console.WriteLine("futurScale = " + futurScale);
@@ -202,32 +202,68 @@
 
         public void addAnnotation()
         {
+            Boolean annotOk = true;
             // We open a new annotation
             if (CuttingVM != null && AnnotWaiting == false)
             {
-                AnnotTcBegin = (float)slider.Value;
-                lastAnnotVM = new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth), 0, CuttingVM.AnnotList.Count.ToString()));
-                //lastAnnotVM = new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000), 0, CuttingVM.AnnotList.Count.ToString()));
-                //lastAnnotVM = new AnnotationViewModel(new Annotation(0, 0, CuttingVM.AnnotList.Count.ToString()));
-                CuttingVM.AnnotList.Add(lastAnnotVM);
-                Console.WriteLine("BEGIN currentTimecode = " + (AnnotTcBegin / 1000) + ", nb = " + CuttingVM.AnnotList.Count + ", res = " + ((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth)));
-                tv.DataContext = null;
-                tv.DataContext = CuttingVM;
-                AnnotWaiting = true;
+                AnnotTcBegin = (float)slider.Value / 1000;
+
+                // First we check if the new annotation will not cover any
+                foreach (Annotation a in AnnotList)
+                {
+                    Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
+                    if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur))
+                    {
+                        annotOk = false;
+                    }
+                }
+                // if not, we mark the beginning
+                if (annotOk == true)
+                {
+                    AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString()));
+                    //AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString()));
+                    //AnnotList.Add(new Annotation(0, 0, AnnotList.Count.ToString()));
+
+                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
+                    //Console.WriteLine("BEGIN currentTimecode = " + AnnotTcBegin + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
+                    tv.DataContext = null;
+                    tv.DataContext = CuttingVM;
+                    AnnotWaiting = true;
+                }
+                
             }
             // We close the current opened annotation...
             else if (CuttingVM != null && AnnotWaiting == true && ((float)slider.Value>AnnotTcBegin))
             {
                 // ... by setting setting the good beginning and the good duration
-                float currentDuration = ((float)slider.Value - AnnotTcBegin) / 1000;
-                CuttingVM.AnnotList.RemoveAt(CuttingVM.AnnotList.Count - 1);
-                CuttingVM.AnnotList.Add(new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth), currentDuration, CuttingVM.AnnotList.Count.ToString())));
-                //CuttingVM.AnnotList.Add(new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000), currentDuration, CuttingVM.AnnotList.Count.ToString())));
-                //CuttingVM.AnnotList.Add(new AnnotationViewModel(new Annotation(0, currentDuration, CuttingVM.AnnotList.Count.ToString())));
-                Console.WriteLine("currentTimecode = " + (AnnotTcBegin / 1000) + ", curDur = " + currentDuration + ", nb = " + CuttingVM.AnnotList.Count + ", res = " + ((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth)));
-                tv.DataContext = null;
-                tv.DataContext = CuttingVM;
-                AnnotWaiting = false;
+                float currentTC = (float)slider.Value / 1000;
+                float currentDuration = currentTC - AnnotTcBegin;
+
+                // First we check if the new annotation will not cover any (AnnotTcBegin was already checked)
+                foreach (Annotation a in AnnotList)
+                {
+                    Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC);
+                    if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC))
+                    {
+                        annotOk = false;
+                    }
+                }
+
+                if (annotOk == true)
+                {
+                    AnnotList.RemoveAt(AnnotList.Count - 1);
+                    AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString()));
+                    //AnnotList.Add(new Annotation(AnnotTcBegin - (AnnotList.Count * AnnotWidth), currentDuration, AnnotList.Count.ToString()));
+                    //AnnotList.Add(new Annotation((AnnotTcBegin / 1000), currentDuration, CuttingVM.AnnotList.Count.ToString()));
+                    //AnnotList.Add(new Annotation(0, currentDuration, CuttingVM.AnnotList.Count.ToString()));
+
+
+                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
+                    //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
+                    tv.DataContext = null;
+                    tv.DataContext = CuttingVM;
+                    AnnotWaiting = false;
+                }
             }
         }