Drag and drop of annotations from timeline, first step
authorcavaliet
Fri, 02 Oct 2009 18:49:07 +0200
changeset 128 90c29e979ef4
parent 127 d2c42d42f504
child 129 1f37ef03ebee
Drag and drop of annotations from timeline, first step
src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
src/FingersDance.Views/FingersDance.Views.csproj
src/FingersDance.Views/TimelineAnnotationView.xaml
src/FingersDance.Views/TimelineAnnotationView.xaml.cs
src/FingersDance.Views/TimelineView.xaml
src/FingersDance.Views/TimelineView.xaml.cs
--- a/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Wed Sep 30 16:58:58 2009 +0200
+++ b/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Fri Oct 02 18:49:07 2009 +0200
@@ -33,7 +33,7 @@
         private double totalmilliseconds;
 
         private List<Annotation> AnnotList = new List<Annotation>();
-        private float AnnotWidth = 40+1;
+        private float AnnotWidth = 300 + 15; // The surfaceListBox adds 15 pixels between each item
         private CuttingViewModel CuttingVM;
         private Boolean AnnotWaiting = false;
         private float AnnotTcBegin;
@@ -111,10 +111,10 @@
             // TEMP FOR DATA BINDING
             AnnotList = new List<Annotation>();
             AnnotList.Add(new Annotation(0, 10, "Axe Cam 1"));
-            //annotList.Add(new Annotation(20 - (1 * annotWidth), 30, "Mvt Cam 2"));
-            //annotList.Add(new Annotation(50 - (2 * annotWidth), 60, "Saut 3"));
-            //annotList.Add(new Annotation(100 - (3 * annotWidth), 20, "Saut 4"));
-            //annotList.Add(new Annotation(120 - (4 * annotWidth), 50, "Saut 5"));
+            //AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2"));
+            //AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3"));
+            //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);
             tv.DataContext = CuttingVM;
@@ -171,8 +171,7 @@
 
         #endregion
 
-        private void sliderPosition_DragStarted(
-            object sender, DragStartedEventArgs e)
+        private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e)
         {
             isDragging = true;
             OnDragStarted();
@@ -208,6 +207,8 @@
             {
                 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;
@@ -221,6 +222,8 @@
                 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;
--- a/src/FingersDance.Views/FingersDance.Views.csproj	Wed Sep 30 16:58:58 2009 +0200
+++ b/src/FingersDance.Views/FingersDance.Views.csproj	Fri Oct 02 18:49:07 2009 +0200
@@ -3,7 +3,7 @@
   <PropertyGroup>
     <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
     <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
-    <ProductVersion>9.0.21022</ProductVersion>
+    <ProductVersion>9.0.30729</ProductVersion>
     <SchemaVersion>2.0</SchemaVersion>
     <ProjectGuid>{0B308B6E-7B1E-46C0-ACC7-0B7EFC4D0B2C}</ProjectGuid>
     <OutputType>Library</OutputType>
@@ -122,6 +122,12 @@
       <Generator>MSBuild:Compile</Generator>
     </Page>
   </ItemGroup>
+  <ItemGroup>
+    <ProjectReference Include="..\FingersDance.ViewModel\FingersDance.ViewModels.csproj">
+      <Project>{E81BB080-0598-43AC-90CE-54D6570C4E9E}</Project>
+      <Name>FingersDance.ViewModels</Name>
+    </ProjectReference>
+  </ItemGroup>
   <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
   <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 
        Other similar extension points exist, see Microsoft.Common.targets.
--- a/src/FingersDance.Views/TimelineAnnotationView.xaml	Wed Sep 30 16:58:58 2009 +0200
+++ b/src/FingersDance.Views/TimelineAnnotationView.xaml	Fri Oct 02 18:49:07 2009 +0200
@@ -8,13 +8,15 @@
 	x:Class="FingersDance.Views.TimelineAnnotationView"
     xmlns:vw="clr-namespace:FingersDance.Views"
 	x:Name="UserControl"
-	d:DesignWidth="640" d:DesignHeight="480" Width="40">
+	d:DesignWidth="640" d:DesignHeight="480" Width="300" Height="40">
     <UserControl.Resources>
         <vw:ThicknessSingleValueConverter x:Name="myThicknessSingleValueConverter" x:Key="myThicknessSingleValueConverter"/>
         <vw:VisibilityConverter x:Name="myVisibilityConverter" x:Key="myVisibilityConverter"/>
     </UserControl.Resources>
-    <Custom:SurfaceUserControl x:Name="LayoutRoot" Margin="{Binding Path=TcBegin, Converter={StaticResource myThicknessSingleValueConverter}}">
+    <Custom:SurfaceUserControl x:Name="LayoutRoot" Margin="{Binding Path=TcBegin, Converter={StaticResource myThicknessSingleValueConverter}}"
+                               >
         <Grid>
+            <Rectangle Fill="Black" HorizontalAlignment="Left" VerticalAlignment="Top" Width="{Binding Path=Dur}" Height="40" Opacity="0.0"/>
             <TextBox HorizontalAlignment="Left" Text="{Binding Path=GestureType}" Width="40" Margin="0,20,0,0" Visibility="{Binding Path=Dur, Converter={StaticResource myVisibilityConverter}}"/>
             <Ellipse Stroke="Green" Fill="{x:Null}" Margin="-3,16,0,0" Height="8" VerticalAlignment="Top" HorizontalAlignment="Left" Width="8"/>
             <Ellipse Fill="Green" Margin="-2,17,0,0" Height="6" VerticalAlignment="Top" HorizontalAlignment="Left" Width="6" Visibility="{Binding Path=Dur, Converter={StaticResource myVisibilityConverter}}" />
--- a/src/FingersDance.Views/TimelineAnnotationView.xaml.cs	Wed Sep 30 16:58:58 2009 +0200
+++ b/src/FingersDance.Views/TimelineAnnotationView.xaml.cs	Fri Oct 02 18:49:07 2009 +0200
@@ -11,6 +11,7 @@
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using Microsoft.Surface.Presentation;
 
 namespace FingersDance.Views
 {
--- a/src/FingersDance.Views/TimelineView.xaml	Wed Sep 30 16:58:58 2009 +0200
+++ b/src/FingersDance.Views/TimelineView.xaml	Fri Oct 02 18:49:07 2009 +0200
@@ -2,9 +2,27 @@
     xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
     xmlns:vw="clr-namespace:FingersDance.Views"
-    >
+    xmlns:Custom="http://schemas.microsoft.com/surface/2008">
+    <UserControl.Resources>
+        <DataTemplate x:Key="slbDataTemplate">
+            <vw:TimelineAnnotationView/>
+        </DataTemplate>
+        <ItemsPanelTemplate x:Key="slbItemsPanelTemplate">
+            <!--
+            <Grid></Grid>
+            <Canvas></Canvas>
+            -->
+            <StackPanel Orientation="Horizontal"/>
+
+        </ItemsPanelTemplate>
+    </UserControl.Resources>
     <Grid>
-        <ListView DataContext="{Binding Path=AnnotList}"
+        <Custom:SurfaceListBox Background="{x:Null}" x:Name="listview" 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}"
                   ItemsSource="{Binding}" Background="{x:Null}" BorderThickness="0" x:Name="listview" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
 
             <ListView.ItemTemplate>
@@ -18,21 +36,7 @@
                     <StackPanel Orientation="Horizontal"/>
                 </ItemsPanelTemplate>
             </ListView.ItemsPanel>
-            
-            <!--ListView.View>
-                <GridView>
-                    <GridViewColumn 
-                        Header="Gesture Type"
-                        DisplayMemberBinding="{Binding Path=GestureType}"/>
-                    <GridViewColumn 
-                        Header="Tc Begin"
-                        DisplayMemberBinding="{Binding Path=TcBegin}" />
-                    <GridViewColumn 
-                        Header="Dur"
-                        DisplayMemberBinding="{Binding Path=Dur}" />
-                </GridView>
-            </ListView.View-->
         </ListView>
-        <!--TextBlock Text="{Binding Path=Title}" Height="27" VerticalAlignment="Top" Margin="0,0,0,0" /-->
+        <TextBlock Text="{Binding Path=Title}" Height="27" VerticalAlignment="Top" Margin="0,0,0,0" /-->
     </Grid>
 </UserControl>
--- a/src/FingersDance.Views/TimelineView.xaml.cs	Wed Sep 30 16:58:58 2009 +0200
+++ b/src/FingersDance.Views/TimelineView.xaml.cs	Fri Oct 02 18:49:07 2009 +0200
@@ -11,6 +11,11 @@
 using System.Windows.Media.Imaging;
 using System.Windows.Navigation;
 using System.Windows.Shapes;
+using Microsoft.Surface.Presentation.Controls;
+using Microsoft.Surface.Presentation;
+
+using FingersDance.Views;
+using FingersDance.ViewModels;
 
 namespace FingersDance.Views
 {
@@ -23,5 +28,73 @@
         {
             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
+                }
+            };
+
+            // TO DO : apply the good scale to the TAV because the dragged one has scale at 1.
+
+
+            // 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;
+
+        }
+
+        
     }
 }