First step of deleting annotations from timeline by drag and drop
authorcavaliet
Fri, 09 Oct 2009 11:33:35 +0200
changeset 136 8b513df1b446
parent 135 84b3bf5ee3d2
child 138 61ba19954ed4
First step of deleting annotations from timeline by drag and drop
src/FingersDance.Control.Player/FingersDance.Control.Player.csproj
src/FingersDance.Control.Player/UserControlPlayer.xaml.cs
src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
src/FingersDance.ViewModel/AnnotationViewModel.cs
src/FingersDance.Views/TimelineView.xaml
src/FingersDance.Views/TimelineView.xaml.cs
--- a/src/FingersDance.Control.Player/FingersDance.Control.Player.csproj	Wed Oct 07 17:16:46 2009 +0200
+++ b/src/FingersDance.Control.Player/FingersDance.Control.Player.csproj	Fri Oct 09 11:33:35 2009 +0200
@@ -150,6 +150,10 @@
       <Project>{1E80D5A1-C45C-443B-8992-4A4D78D280FC}</Project>
       <Name>FingersDance.Actions</Name>
     </ProjectReference>
+    <ProjectReference Include="..\FingersDance.Control.TimeLine\FingersDance.Control.TimeLine.csproj">
+      <Project>{2BCEE1BF-D3AC-478C-A26B-DFDB7420E965}</Project>
+      <Name>FingersDance.Control.TimeLine</Name>
+    </ProjectReference>
     <ProjectReference Include="..\FingersDance.ViewModel\FingersDance.ViewModels.csproj">
       <Project>{E81BB080-0598-43AC-90CE-54D6570C4E9E}</Project>
       <Name>FingersDance.ViewModels</Name>
--- a/src/FingersDance.Control.Player/UserControlPlayer.xaml.cs	Wed Oct 07 17:16:46 2009 +0200
+++ b/src/FingersDance.Control.Player/UserControlPlayer.xaml.cs	Fri Oct 09 11:33:35 2009 +0200
@@ -16,6 +16,7 @@
 using Microsoft.Surface.Presentation.Controls;
 using FingersDance.ActionFactory;
 using FingersDance.Actions;
+using FingersDance.Control.TimeLine;
 using FingersDance.Views;
 using FingersDance.ViewModels;
 
@@ -183,7 +184,28 @@
         private void Play_Pause_area_DragEnter(object sender, SurfaceDragDropEventArgs e)
         {
             //Console.WriteLine("Enter");
-            Play_Pause_area.Opacity = 0.5;
+
+            // If the TimelineAnnotationView comes from a user control different from the current one, 
+            // it means that we want to add the annotation to the current list.
+            // So we check if the dragged annotation can be dragged or if it will recover any existant annotation (in this case it will not be accepted)
+            // e.Cursor.DragSource is the SurfaceListBox where the drag started from
+            SurfaceListBox slb = (SurfaceListBox)e.Cursor.DragSource;
+            // We get the instance of the UserControlSyncSource
+            UserControl syncSrc = (UserControl)((Grid)((Grid)this.Parent).Parent).Parent;
+            // and its UserControlTimeline
+            UserControlTimeLine tl = (UserControlTimeLine)((Grid)((Grid)syncSrc.Content).Children[0]).Children[0];
+            if (((Grid)((UserControl)((Grid)slb.Parent).Parent).Parent).Parent != tl)
+            {
+                // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
+                AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
+                Play_Pause_area.Background = tl.isAnnotationAccepted(annotationDataVM) ? new SolidColorBrush(Colors.Green) : new SolidColorBrush(Colors.Red);
+            }
+            else
+            {
+                Play_Pause_area.Background = new SolidColorBrush(Colors.White);
+            }
+            Play_Pause_area.Opacity = 0.3;
+
         }
 
         private void Play_Pause_area_DragLeave(object sender, SurfaceDragDropEventArgs e)
--- a/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Wed Oct 07 17:16:46 2009 +0200
+++ b/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Fri Oct 09 11:33:35 2009 +0200
@@ -5,11 +5,13 @@
 using System.Windows;
 using System.Windows.Controls;
 using System.Windows.Data;
+using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Animation;
 using System.Windows.Navigation;
 using System.Windows.Controls.Primitives;
 using Microsoft.Surface.Presentation.Controls;
+using Microsoft.Surface.Presentation;
 using System.Windows.Threading;
 
 using FingersDance.Data;
@@ -119,6 +121,9 @@
             CuttingVM = new CuttingViewModel(cut, AnnotWidth);
             tv.DataContext = CuttingVM;
 
+            tv.listview.PreviewContactDown += listview_PreviewContactDown;
+            SurfaceDragDrop.AddDragCanceledHandler(tv.listview, onDragCanceled);
+
             UserControlTimeLine_SizeChanged(null, null);
 
             slider_ContactTapGesture(this, null);
@@ -202,9 +207,40 @@
             //startOrEndAnnotation();
         }
 
+        public Boolean isAnnotationAccepted(AnnotationViewModel avm)
+        {
+            Boolean annotOk = true;
+            // We check if the annotation's begin and end timecodes allow a new annotation creation
+            if (CuttingVM != null && AnnotWaiting == false)
+            {
+                foreach (Annotation a in AnnotList)
+                {
+                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
+                    // Check begin TC
+                    if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur))
+                    {
+                        annotOk = false;
+                    }
+                    // Check end tc and if the new annotation will not cover any other
+                    float endTC = avm.TcBegin + avm.Dur;
+                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC);
+                    if (a.TcBegin <= endTC && endTC <= (a.TcBegin + a.Dur) || (avm.TcBegin < a.TcBegin && (a.TcBegin + a.Dur) < endTC))
+                    {
+                        annotOk = false;
+                    }
+                }
+            }
+            else
+            {
+                annotOk = false;
+            }
+            return annotOk;
+
+        }
+
         public void addAnnotation(AnnotationViewModel avm)
         {
-            Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType);
+            //Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType);
             Boolean annotOk = true;
             // We check if the annotation's begin and end timecodes allow a new annotation creation
             if (CuttingVM != null && AnnotWaiting == false)
@@ -297,5 +333,98 @@
             }
         }
 
+
+        private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
+        {
+            FrameworkElement findSource = e.OriginalSource as FrameworkElement;
+            SurfaceListBoxItem draggedElement = null;
+
+            // Find the touched SurfaceListBoxItem object.
+            while (draggedElement == null && findSource != null)
+            {
+                if ((draggedElement = findSource as SurfaceListBoxItem) == null)
+                {
+                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
+                }
+            }
+
+            if (draggedElement == null)
+            {
+                return;
+            }
+
+            // Create the cursor visual.
+            ContentControl cursorVisual = new ContentControl()
+            {
+                Content = new TimelineAnnotationView()
+                {
+                    DataContext = findSource.DataContext
+                }
+            };
+
+            // We apply the current scale to the dragged annotation
+            ((TimelineAnnotationView)cursorVisual.Content).RenderTransform = this.RenderTransform;
+
+            // Add a handler. This will enable the application to change the visual cues. (NOT USEFUL IN FINGERSDANCE CASE)
+            //SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged);
+
+            // Create a list of input devices. Add the contacts that
+            // are currently captured within the dragged element and
+            // the current contact (if it isn't already in the list).
+            List<InputDevice> devices = new List<InputDevice>();
+            devices.Add(e.Contact);
+            foreach (Contact contact in draggedElement.ContactsCapturedWithin)
+            {
+                if (contact != e.Contact)
+                {
+                    devices.Add(contact);
+                }
+            }
+
+            // Get the drag source object
+            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);
+
+            bool startDragOkay =
+                SurfaceDragDrop.BeginDragDrop(
+                  dragSource,                 // The SurfaceListBox object that the cursor is dragged out from.
+                  draggedElement,             // The SurfaceListBoxItem object that is dragged from the drag source.
+                  cursorVisual,               // The visual element of the cursor.
+                  draggedElement.DataContext, // The data associated with the cursor.
+                  devices,                    // The input devices that start dragging the cursor.
+                  DragDropEffects.Move);      // The allowed drag-and-drop effects of the operation.
+
+            // If the drag began successfully, set e.Handled to true. 
+            // Otherwise SurfaceListBoxItem captures the contact 
+            // and causes the drag operation to fail.
+            e.Handled = startDragOkay;
+        }
+
+        private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e)
+        {
+            Console.WriteLine("onDragCanceled = " + sender + ", ((ContentControl)e.Cursor.Visual).Content = " + ((ContentControl)e.Cursor.Visual).Content);
+            // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
+            AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
+            // We check if the annotation is well one of the current annotations
+            if (CuttingVM != null)
+            {
+                foreach (Annotation a in AnnotList)
+                {
+                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
+                    // Check begin TC
+                    if (a.TcBegin == annotationDataVM.TcBegin && a.Dur == annotationDataVM.Dur && a.GestureType==annotationDataVM.GestureType)
+                    {
+                        // We found the good annotation so we can delete it
+                        AnnotList.Remove(a);
+                        // We redisplay the timeline
+                        CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
+                        tv.DataContext = null;
+                        tv.DataContext = CuttingVM;
+                        return;
+                    }
+                }
+            }
+        }
+
+
 	}
 }
\ No newline at end of file
--- a/src/FingersDance.ViewModel/AnnotationViewModel.cs	Wed Oct 07 17:16:46 2009 +0200
+++ b/src/FingersDance.ViewModel/AnnotationViewModel.cs	Fri Oct 09 11:33:35 2009 +0200
@@ -20,8 +20,6 @@
             this._dur = a.Dur;
             this._gestureType = a.GestureType;
             this._marginLeft = marginLeft;
-
-            Console.WriteLine("_tcBegin = " + _tcBegin + ", _marginLeft = " + _marginLeft);
         }
 
         public float TcBegin
--- a/src/FingersDance.Views/TimelineView.xaml	Wed Oct 07 17:16:46 2009 +0200
+++ b/src/FingersDance.Views/TimelineView.xaml	Fri Oct 09 11:33:35 2009 +0200
@@ -17,9 +17,9 @@
         </ItemsPanelTemplate>
     </UserControl.Resources>
     <Grid>
-        <Custom:SurfaceListBox Background="{x:Null}" x:Name="listview" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="2"
+        <Custom:SurfaceListBox Background="{x:Null}" x:Name="listview" x:FieldModifier="public" ScrollViewer.HorizontalScrollBarVisibility="Hidden" BorderThickness="2"
                                ItemsSource="{Binding Path=AnnotList}" ItemTemplate="{StaticResource slbDataTemplate}" ItemsPanel="{StaticResource slbItemsPanelTemplate}"
-                               PreviewContactDown="listview_PreviewContactDown">
+                               >
             
         </Custom:SurfaceListBox>
         <!--ListView DataContext="{Binding Path=AnnotList}"
--- a/src/FingersDance.Views/TimelineView.xaml.cs	Wed Oct 07 17:16:46 2009 +0200
+++ b/src/FingersDance.Views/TimelineView.xaml.cs	Fri Oct 09 11:33:35 2009 +0200
@@ -6,13 +6,10 @@
 using System.Windows.Controls;
 using System.Windows.Data;
 using System.Windows.Documents;
-using System.Windows.Input;
 using System.Windows.Media;
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
-using Microsoft.Surface.Presentation.Controls;
-using Microsoft.Surface.Presentation;
 
 using FingersDance.Data;
 using FingersDance.ViewModels;
@@ -25,76 +22,15 @@
     /// </summary>
     public partial class TimelineView : UserControl
     {
+
+        private Boolean hasDragCanceledHandler = false;
+
         public TimelineView()
         {
             InitializeComponent();
         }
 
-        private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
-        {
-            FrameworkElement findSource = e.OriginalSource as FrameworkElement;
-            SurfaceListBoxItem draggedElement = null;
-
-            // Find the touched SurfaceListBoxItem object.
-            while (draggedElement == null && findSource != null)
-            {
-                if ((draggedElement = findSource as SurfaceListBoxItem) == null)
-                {
-                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
-                }
-            }
-
-            if (draggedElement == null)
-            {
-                return;
-            }
-
-            // Create the cursor visual.
-            ContentControl cursorVisual = new ContentControl()
-            {
-                Content = new TimelineAnnotationView()
-                {
-                    DataContext = findSource.DataContext
-                }
-            };
-
-            // We apply the current scale to the dragged annotation
-            ((TimelineAnnotationView)cursorVisual.Content).RenderTransform = this.RenderTransform;
-
-            // Add a handler. This will enable the application to change the visual cues.
-            //SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged);
-
-            // Create a list of input devices. Add the contacts that
-            // are currently captured within the dragged element and
-            // the current contact (if it isn't already in the list).
-            List<InputDevice> devices = new List<InputDevice>();
-            devices.Add(e.Contact);
-            foreach (Contact contact in draggedElement.ContactsCapturedWithin)
-            {
-                if (contact != e.Contact)
-                {
-                    devices.Add(contact);
-                }
-            }
-
-            // Get the drag source object
-            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);
-
-            bool startDragOkay =
-                SurfaceDragDrop.BeginDragDrop(
-                  dragSource,                 // The SurfaceListBox object that the cursor is dragged out from.
-                  draggedElement,             // The SurfaceListBoxItem object that is dragged from the drag source.
-                  cursorVisual,               // The visual element of the cursor.
-                  draggedElement.DataContext, // The data associated with the cursor.
-                  devices,                    // The input devices that start dragging the cursor.
-                  DragDropEffects.Move);      // The allowed drag-and-drop effects of the operation.
-
-            // If the drag began successfully, set e.Handled to true. 
-            // Otherwise SurfaceListBoxItem captures the contact 
-            // and causes the drag operation to fail.
-            e.Handled = startDragOkay;
-
-        }
+        
 
     }
 }