src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
changeset 160 e940ca798fe3
parent 150 569925b65604
child 162 0b9f989bcb37
equal deleted inserted replaced
157:0fd2b41ab402 160:e940ca798fe3
    33         public event EventHandler DragStarted;
    33         public event EventHandler DragStarted;
    34         public event EventHandler DragCompleted;
    34         public event EventHandler DragCompleted;
    35         public event EventHandler TimerTick;
    35         public event EventHandler TimerTick;
    36 
    36 
    37         private double totalmilliseconds;
    37         private double totalmilliseconds;
    38 
    38         
    39         private List<Annotation> AnnotList = new List<Annotation>();
    39         private List<Annotation> AnnotList = new List<Annotation>();
    40         private float AnnotWidth = 300 + 15; // The surfaceListBox adds 15 pixels between each item
    40         private float AnnotWidth = 300 + 15; // The surfaceListBox adds 15 pixels between each item
    41         private CuttingViewModel CuttingVM;
    41         private CuttingViewModel CuttingVM;
    42         private Boolean AnnotWaiting = false;
    42         private Boolean AnnotWaiting = false;
    43         private float AnnotTcBegin;
    43         private float AnnotTcBegin;
    44         private UInt32 IntColor;
    44         private Color CurrentColor;
    45 
    45 
    46         private AnnotationViewModel canceledAnnotationVM;
    46         private AnnotationViewModel canceledAnnotationVM;
    47 
    47 
    48         #region Properties
    48         #region Properties
    49 
    49 
   112             totalmilliseconds = totalmillisecondsPar;
   112             totalmilliseconds = totalmillisecondsPar;
   113             slider.Maximum = totalmilliseconds;
   113             slider.Maximum = totalmilliseconds;
   114             // When the timeline is resized, we catch the resize event to define TimelineView's good scale
   114             // When the timeline is resized, we catch the resize event to define TimelineView's good scale
   115             this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged);
   115             this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged);
   116 
   116 
   117             // TEMP FOR DATA BINDING
   117 
       
   118             tv.listview.PreviewContactDown += listview_PreviewContactDown;
       
   119             SurfaceDragDrop.AddDragCanceledHandler(tv.listview, onDragCanceled);
       
   120 
       
   121             UserControlTimeLine_SizeChanged(null, null);
       
   122 
       
   123             slider_ContactTapGesture(this, null);
       
   124 
       
   125         }
       
   126 
       
   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-30) / (totalmilliseconds / 1000);
       
   131             //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS
       
   132             tv.RenderTransform = new ScaleTransform(futurScale,1);
       
   133             //tv.Width = this.ActualWidth - 30;
       
   134             
       
   135         }
       
   136 
       
   137         #region Timer
       
   138         public void initTimer(Color col, Cutting cutPar)
       
   139         {
       
   140             timer = new DispatcherTimer();
       
   141             timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
       
   142             timer.Tick += new EventHandler(timer_Tick);
       
   143 
       
   144             CurrentColor = col;
       
   145             
       
   146             // DATA BINDING from the cutting sent in parameter (initialised before by the userPanel with the global project)
   118             AnnotList = new List<Annotation>();
   147             AnnotList = new List<Annotation>();
   119             AnnotList.Add(new Annotation(0, 10, "Axe Cam 1", IntColor));
   148             AnnotList.Add(new Annotation(0, 10, "Axe Cam 1", CurrentColor));
   120             //AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2"));
   149             //AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2"));
   121             //AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3"));
   150             //AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3"));
   122             //AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4"));
   151             //AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4"));
   123             //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5"));
   152             //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5"));
   124             Cutting cut = new Cutting("titre de cutting", AnnotList);
   153             cutPar = new Cutting("titre de cutting", AnnotList);
   125             CuttingVM = new CuttingViewModel(cut, AnnotWidth);
   154             CuttingVM = new CuttingViewModel(cutPar, AnnotWidth);
   126             tv.DataContext = CuttingVM;
   155             tv.DataContext = CuttingVM;
   127 
   156 
   128             tv.listview.PreviewContactDown += listview_PreviewContactDown;
       
   129             SurfaceDragDrop.AddDragCanceledHandler(tv.listview, onDragCanceled);
       
   130 
       
   131             UserControlTimeLine_SizeChanged(null, null);
       
   132 
       
   133             slider_ContactTapGesture(this, null);
       
   134             
       
   135 
       
   136         }
       
   137 
       
   138         void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
       
   139         {
       
   140             // When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account.
       
   141             Double futurScale = (this.ActualWidth-30) / (totalmilliseconds / 1000);
       
   142             //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS
       
   143             tv.RenderTransform = new ScaleTransform(futurScale,1);
       
   144             //Console.WriteLine("futurScale = " + futurScale);
       
   145             
       
   146         }
       
   147 
       
   148         #region Timer
       
   149         public void initTimer(UInt32 intColorPar)
       
   150         {
       
   151             timer = new DispatcherTimer();
       
   152             timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
       
   153             timer.Tick += new EventHandler(timer_Tick);
       
   154 
       
   155             IntColor = intColorPar;
       
   156         }
   157         }
   157 
   158 
   158         public void timerStart()
   159         public void timerStart()
   159         {
   160         {
   160             if (timer != null)
   161             if (timer != null)
   183                 TimerTick(this, new EventArgs());
   184                 TimerTick(this, new EventArgs());
   184         }
   185         }
   185 
   186 
   186         #endregion
   187         #endregion
   187 
   188 
       
   189         #region SliderDrag
   188         private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e)
   190         private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e)
   189         {
   191         {
   190             isDragging = true;
   192             isDragging = true;
   191             OnDragStarted();
   193             OnDragStarted();
   192            // media.Pause();
   194            // media.Pause();
   210 
   212 
   211         private void slider_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
   213         private void slider_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
   212         {
   214         {
   213             //startOrEndAnnotation();
   215             //startOrEndAnnotation();
   214         }
   216         }
       
   217         #endregion
   215 
   218 
   216         public Boolean isAnnotationAccepted(AnnotationViewModel avm)
   219         public Boolean isAnnotationAccepted(AnnotationViewModel avm)
   217         {
   220         {
   218             Boolean annotOk = true;
   221             Boolean annotOk = true;
   219             // We check if the annotation's begin and end timecodes allow a new annotation creation
   222             // We check if the annotation's begin and end timecodes allow a new annotation creation
   299                     }
   302                     }
   300                 }
   303                 }
   301                 // if not, we mark the beginning
   304                 // if not, we mark the beginning
   302                 if (annotOk == true)
   305                 if (annotOk == true)
   303                 {
   306                 {
   304                     AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString(), IntColor));
   307                     AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString(), CurrentColor));
   305                     CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
   308                     CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
   306                     //Console.WriteLine("BEGIN currentTimecode = " + AnnotTcBegin + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
       
   307                     tv.DataContext = null;
   309                     tv.DataContext = null;
   308                     tv.DataContext = CuttingVM;
   310                     tv.DataContext = CuttingVM;
   309                     AnnotWaiting = true;
   311                     AnnotWaiting = true;
   310                 }
   312                 }
   311             }
   313             }
   327                 }
   329                 }
   328 
   330 
   329                 if (annotOk == true)
   331                 if (annotOk == true)
   330                 {
   332                 {
   331                     AnnotList.RemoveAt(AnnotList.Count - 1);
   333                     AnnotList.RemoveAt(AnnotList.Count - 1);
   332                     AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString(), IntColor));
   334                     AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString(), CurrentColor));
   333                     CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
   335                     CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
   334                     //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
   336                     //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
   335                     tv.DataContext = null;
   337                     tv.DataContext = null;
   336                     tv.DataContext = CuttingVM;
   338                     tv.DataContext = CuttingVM;
   337                     AnnotWaiting = false;
   339                     AnnotWaiting = false;
   338                 }
   340                 }
   339             }
   341             }
   340         }
   342         }
   341 
       
   342 
   343 
   343         private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
   344         private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
   344         {
   345         {
   345             FrameworkElement findSource = e.OriginalSource as FrameworkElement;
   346             FrameworkElement findSource = e.OriginalSource as FrameworkElement;
   346             SurfaceListBoxItem draggedElement = null;
   347             SurfaceListBoxItem draggedElement = null;
   405             e.Handled = startDragOkay;
   406             e.Handled = startDragOkay;
   406         }
   407         }
   407 
   408 
   408         private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e)
   409         private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e)
   409         {
   410         {
   410             Console.WriteLine("onDragCanceled = " + sender + ", ((ContentControl)e.Cursor.Visual).Content = " + ((ContentControl)e.Cursor.Visual).Content);
       
   411             // We check if the annotation is well one of the current annotations
   411             // We check if the annotation is well one of the current annotations
   412             if (CuttingVM != null)
   412             if (CuttingVM != null)
   413             {
   413             {
   414                 // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
   414                 // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
   415                 canceledAnnotationVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
   415                 canceledAnnotationVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
   417             }
   417             }
   418         }
   418         }
   419 
   419 
   420         private void confirmCancelPopup_ConfirmYesOrNo(object sender, ConfirmEventArgs e)
   420         private void confirmCancelPopup_ConfirmYesOrNo(object sender, ConfirmEventArgs e)
   421         {
   421         {
   422             //Consolenfirm = " + e.Confirmed);
       
   423             // We check if the annotation is well one of the current annotations
   422             // We check if the annotation is well one of the current annotations
   424             if (CuttingVM != null && canceledAnnotationVM != null && e.Confirmed == true)
   423             if (CuttingVM != null && canceledAnnotationVM != null && e.Confirmed == true)
   425             {
   424             {
   426                 foreach (Annotation a in AnnotList)
   425                 foreach (Annotation a in AnnotList)
   427                 {
   426                 {