src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
changeset 136 8b513df1b446
parent 135 84b3bf5ee3d2
child 140 fc7c12f9da30
equal deleted inserted replaced
135:84b3bf5ee3d2 136:8b513df1b446
     3 using System.IO;
     3 using System.IO;
     4 using System.Net;
     4 using System.Net;
     5 using System.Windows;
     5 using System.Windows;
     6 using System.Windows.Controls;
     6 using System.Windows.Controls;
     7 using System.Windows.Data;
     7 using System.Windows.Data;
       
     8 using System.Windows.Input;
     8 using System.Windows.Media;
     9 using System.Windows.Media;
     9 using System.Windows.Media.Animation;
    10 using System.Windows.Media.Animation;
    10 using System.Windows.Navigation;
    11 using System.Windows.Navigation;
    11 using System.Windows.Controls.Primitives;
    12 using System.Windows.Controls.Primitives;
    12 using Microsoft.Surface.Presentation.Controls;
    13 using Microsoft.Surface.Presentation.Controls;
       
    14 using Microsoft.Surface.Presentation;
    13 using System.Windows.Threading;
    15 using System.Windows.Threading;
    14 
    16 
    15 using FingersDance.Data;
    17 using FingersDance.Data;
    16 using FingersDance.ViewModels;
    18 using FingersDance.ViewModels;
    17 using FingersDance.Views;
    19 using FingersDance.Views;
   117             //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5"));
   119             //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5"));
   118             Cutting cut = new Cutting("titre de cutting", AnnotList);
   120             Cutting cut = new Cutting("titre de cutting", AnnotList);
   119             CuttingVM = new CuttingViewModel(cut, AnnotWidth);
   121             CuttingVM = new CuttingViewModel(cut, AnnotWidth);
   120             tv.DataContext = CuttingVM;
   122             tv.DataContext = CuttingVM;
   121 
   123 
       
   124             tv.listview.PreviewContactDown += listview_PreviewContactDown;
       
   125             SurfaceDragDrop.AddDragCanceledHandler(tv.listview, onDragCanceled);
       
   126 
   122             UserControlTimeLine_SizeChanged(null, null);
   127             UserControlTimeLine_SizeChanged(null, null);
   123 
   128 
   124             slider_ContactTapGesture(this, null);
   129             slider_ContactTapGesture(this, null);
   125             
   130             
   126 
   131 
   200         private void slider_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
   205         private void slider_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
   201         {
   206         {
   202             //startOrEndAnnotation();
   207             //startOrEndAnnotation();
   203         }
   208         }
   204 
   209 
       
   210         public Boolean isAnnotationAccepted(AnnotationViewModel avm)
       
   211         {
       
   212             Boolean annotOk = true;
       
   213             // We check if the annotation's begin and end timecodes allow a new annotation creation
       
   214             if (CuttingVM != null && AnnotWaiting == false)
       
   215             {
       
   216                 foreach (Annotation a in AnnotList)
       
   217                 {
       
   218                     //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
       
   219                     // Check begin TC
       
   220                     if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur))
       
   221                     {
       
   222                         annotOk = false;
       
   223                     }
       
   224                     // Check end tc and if the new annotation will not cover any other
       
   225                     float endTC = avm.TcBegin + avm.Dur;
       
   226                     //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC);
       
   227                     if (a.TcBegin <= endTC && endTC <= (a.TcBegin + a.Dur) || (avm.TcBegin < a.TcBegin && (a.TcBegin + a.Dur) < endTC))
       
   228                     {
       
   229                         annotOk = false;
       
   230                     }
       
   231                 }
       
   232             }
       
   233             else
       
   234             {
       
   235                 annotOk = false;
       
   236             }
       
   237             return annotOk;
       
   238 
       
   239         }
       
   240 
   205         public void addAnnotation(AnnotationViewModel avm)
   241         public void addAnnotation(AnnotationViewModel avm)
   206         {
   242         {
   207             Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType);
   243             //Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType);
   208             Boolean annotOk = true;
   244             Boolean annotOk = true;
   209             // We check if the annotation's begin and end timecodes allow a new annotation creation
   245             // We check if the annotation's begin and end timecodes allow a new annotation creation
   210             if (CuttingVM != null && AnnotWaiting == false)
   246             if (CuttingVM != null && AnnotWaiting == false)
   211             {
   247             {
   212                 foreach (Annotation a in AnnotList)
   248                 foreach (Annotation a in AnnotList)
   295                     AnnotWaiting = false;
   331                     AnnotWaiting = false;
   296                 }
   332                 }
   297             }
   333             }
   298         }
   334         }
   299 
   335 
       
   336 
       
   337         private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
       
   338         {
       
   339             FrameworkElement findSource = e.OriginalSource as FrameworkElement;
       
   340             SurfaceListBoxItem draggedElement = null;
       
   341 
       
   342             // Find the touched SurfaceListBoxItem object.
       
   343             while (draggedElement == null && findSource != null)
       
   344             {
       
   345                 if ((draggedElement = findSource as SurfaceListBoxItem) == null)
       
   346                 {
       
   347                     findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
       
   348                 }
       
   349             }
       
   350 
       
   351             if (draggedElement == null)
       
   352             {
       
   353                 return;
       
   354             }
       
   355 
       
   356             // Create the cursor visual.
       
   357             ContentControl cursorVisual = new ContentControl()
       
   358             {
       
   359                 Content = new TimelineAnnotationView()
       
   360                 {
       
   361                     DataContext = findSource.DataContext
       
   362                 }
       
   363             };
       
   364 
       
   365             // We apply the current scale to the dragged annotation
       
   366             ((TimelineAnnotationView)cursorVisual.Content).RenderTransform = this.RenderTransform;
       
   367 
       
   368             // Add a handler. This will enable the application to change the visual cues. (NOT USEFUL IN FINGERSDANCE CASE)
       
   369             //SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged);
       
   370 
       
   371             // Create a list of input devices. Add the contacts that
       
   372             // are currently captured within the dragged element and
       
   373             // the current contact (if it isn't already in the list).
       
   374             List<InputDevice> devices = new List<InputDevice>();
       
   375             devices.Add(e.Contact);
       
   376             foreach (Contact contact in draggedElement.ContactsCapturedWithin)
       
   377             {
       
   378                 if (contact != e.Contact)
       
   379                 {
       
   380                     devices.Add(contact);
       
   381                 }
       
   382             }
       
   383 
       
   384             // Get the drag source object
       
   385             ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);
       
   386 
       
   387             bool startDragOkay =
       
   388                 SurfaceDragDrop.BeginDragDrop(
       
   389                   dragSource,                 // The SurfaceListBox object that the cursor is dragged out from.
       
   390                   draggedElement,             // The SurfaceListBoxItem object that is dragged from the drag source.
       
   391                   cursorVisual,               // The visual element of the cursor.
       
   392                   draggedElement.DataContext, // The data associated with the cursor.
       
   393                   devices,                    // The input devices that start dragging the cursor.
       
   394                   DragDropEffects.Move);      // The allowed drag-and-drop effects of the operation.
       
   395 
       
   396             // If the drag began successfully, set e.Handled to true. 
       
   397             // Otherwise SurfaceListBoxItem captures the contact 
       
   398             // and causes the drag operation to fail.
       
   399             e.Handled = startDragOkay;
       
   400         }
       
   401 
       
   402         private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e)
       
   403         {
       
   404             Console.WriteLine("onDragCanceled = " + sender + ", ((ContentControl)e.Cursor.Visual).Content = " + ((ContentControl)e.Cursor.Visual).Content);
       
   405             // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
       
   406             AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
       
   407             // We check if the annotation is well one of the current annotations
       
   408             if (CuttingVM != null)
       
   409             {
       
   410                 foreach (Annotation a in AnnotList)
       
   411                 {
       
   412                     //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
       
   413                     // Check begin TC
       
   414                     if (a.TcBegin == annotationDataVM.TcBegin && a.Dur == annotationDataVM.Dur && a.GestureType==annotationDataVM.GestureType)
       
   415                     {
       
   416                         // We found the good annotation so we can delete it
       
   417                         AnnotList.Remove(a);
       
   418                         // We redisplay the timeline
       
   419                         CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
       
   420                         tv.DataContext = null;
       
   421                         tv.DataContext = CuttingVM;
       
   422                         return;
       
   423                     }
       
   424                 }
       
   425             }
       
   426         }
       
   427 
       
   428 
   300 	}
   429 	}
   301 }
   430 }