src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
changeset 129 1f37ef03ebee
parent 128 90c29e979ef4
child 130 192da585bee5
equal deleted inserted replaced
128:90c29e979ef4 129:1f37ef03ebee
    92         
    92         
    93 
    93 
    94 
    94 
    95         
    95         
    96 		public UserControlTimeLine()
    96 		public UserControlTimeLine()
    97 		{   
    97 		{
    98 			this.InitializeComponent();
    98 			this.InitializeComponent();
    99 
    99 
   100 			// Insert code required on object creation below this point.
   100 			// Insert code required on object creation below this point.
   101             
   101             
   102 		}
   102 		}
   114             //AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2"));
   114             //AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2"));
   115             //AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3"));
   115             //AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3"));
   116             //AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4"));
   116             //AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4"));
   117             //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5"));
   117             //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5"));
   118             Cutting cut = new Cutting("titre de cutting", AnnotList);
   118             Cutting cut = new Cutting("titre de cutting", AnnotList);
   119             CuttingVM = new CuttingViewModel(cut);
   119             CuttingVM = new CuttingViewModel(cut, AnnotWidth);
   120             tv.DataContext = CuttingVM;
   120             tv.DataContext = CuttingVM;
   121 
   121 
   122             slider_ContactTapGesture(this,null);
   122             slider_ContactTapGesture(this,null);
   123 
   123 
   124         }
   124         }
   125 
   125 
   126         void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
   126         void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
   127         {
   127         {
   128             // When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account.
   128             // When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account.
   129             Double futurScale = this.ActualWidth / (totalmilliseconds / 1000);
   129             Double futurScale = (this.ActualWidth-30) / (totalmilliseconds / 1000);
   130             //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS
   130             //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS
   131             tv.RenderTransform = new ScaleTransform(futurScale,1);
   131             tv.RenderTransform = new ScaleTransform(futurScale,1);
   132             //Console.WriteLine("futurScale = " + futurScale);
   132             //Console.WriteLine("futurScale = " + futurScale);
   133             
   133             
   134         }
   134         }
   200             //addAnnotation();
   200             //addAnnotation();
   201         }
   201         }
   202 
   202 
   203         public void addAnnotation()
   203         public void addAnnotation()
   204         {
   204         {
       
   205             Boolean annotOk = true;
   205             // We open a new annotation
   206             // We open a new annotation
   206             if (CuttingVM != null && AnnotWaiting == false)
   207             if (CuttingVM != null && AnnotWaiting == false)
   207             {
   208             {
   208                 AnnotTcBegin = (float)slider.Value;
   209                 AnnotTcBegin = (float)slider.Value / 1000;
   209                 lastAnnotVM = new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth), 0, CuttingVM.AnnotList.Count.ToString()));
   210 
   210                 //lastAnnotVM = new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000), 0, CuttingVM.AnnotList.Count.ToString()));
   211                 // First we check if the new annotation will not cover any
   211                 //lastAnnotVM = new AnnotationViewModel(new Annotation(0, 0, CuttingVM.AnnotList.Count.ToString()));
   212                 foreach (Annotation a in AnnotList)
   212                 CuttingVM.AnnotList.Add(lastAnnotVM);
   213                 {
   213                 Console.WriteLine("BEGIN currentTimecode = " + (AnnotTcBegin / 1000) + ", nb = " + CuttingVM.AnnotList.Count + ", res = " + ((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth)));
   214                     Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
   214                 tv.DataContext = null;
   215                     if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur))
   215                 tv.DataContext = CuttingVM;
   216                     {
   216                 AnnotWaiting = true;
   217                         annotOk = false;
       
   218                     }
       
   219                 }
       
   220                 // if not, we mark the beginning
       
   221                 if (annotOk == true)
       
   222                 {
       
   223                     AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString()));
       
   224                     //AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString()));
       
   225                     //AnnotList.Add(new Annotation(0, 0, AnnotList.Count.ToString()));
       
   226 
       
   227                     CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
       
   228                     //Console.WriteLine("BEGIN currentTimecode = " + AnnotTcBegin + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
       
   229                     tv.DataContext = null;
       
   230                     tv.DataContext = CuttingVM;
       
   231                     AnnotWaiting = true;
       
   232                 }
       
   233                 
   217             }
   234             }
   218             // We close the current opened annotation...
   235             // We close the current opened annotation...
   219             else if (CuttingVM != null && AnnotWaiting == true && ((float)slider.Value>AnnotTcBegin))
   236             else if (CuttingVM != null && AnnotWaiting == true && ((float)slider.Value>AnnotTcBegin))
   220             {
   237             {
   221                 // ... by setting setting the good beginning and the good duration
   238                 // ... by setting setting the good beginning and the good duration
   222                 float currentDuration = ((float)slider.Value - AnnotTcBegin) / 1000;
   239                 float currentTC = (float)slider.Value / 1000;
   223                 CuttingVM.AnnotList.RemoveAt(CuttingVM.AnnotList.Count - 1);
   240                 float currentDuration = currentTC - AnnotTcBegin;
   224                 CuttingVM.AnnotList.Add(new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth), currentDuration, CuttingVM.AnnotList.Count.ToString())));
   241 
   225                 //CuttingVM.AnnotList.Add(new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000), currentDuration, CuttingVM.AnnotList.Count.ToString())));
   242                 // First we check if the new annotation will not cover any (AnnotTcBegin was already checked)
   226                 //CuttingVM.AnnotList.Add(new AnnotationViewModel(new Annotation(0, currentDuration, CuttingVM.AnnotList.Count.ToString())));
   243                 foreach (Annotation a in AnnotList)
   227                 Console.WriteLine("currentTimecode = " + (AnnotTcBegin / 1000) + ", curDur = " + currentDuration + ", nb = " + CuttingVM.AnnotList.Count + ", res = " + ((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth)));
   244                 {
   228                 tv.DataContext = null;
   245                     Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC);
   229                 tv.DataContext = CuttingVM;
   246                     if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC))
   230                 AnnotWaiting = false;
   247                     {
       
   248                         annotOk = false;
       
   249                     }
       
   250                 }
       
   251 
       
   252                 if (annotOk == true)
       
   253                 {
       
   254                     AnnotList.RemoveAt(AnnotList.Count - 1);
       
   255                     AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString()));
       
   256                     //AnnotList.Add(new Annotation(AnnotTcBegin - (AnnotList.Count * AnnotWidth), currentDuration, AnnotList.Count.ToString()));
       
   257                     //AnnotList.Add(new Annotation((AnnotTcBegin / 1000), currentDuration, CuttingVM.AnnotList.Count.ToString()));
       
   258                     //AnnotList.Add(new Annotation(0, currentDuration, CuttingVM.AnnotList.Count.ToString()));
       
   259 
       
   260 
       
   261                     CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
       
   262                     //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
       
   263                     tv.DataContext = null;
       
   264                     tv.DataContext = CuttingVM;
       
   265                     AnnotWaiting = false;
       
   266                 }
   231             }
   267             }
   232         }
   268         }
   233 
   269 
   234 	}
   270 	}
   235 }
   271 }