Modify TimelineView's scale on resize event
authorcavaliet
Fri, 25 Sep 2009 18:28:58 +0200
changeset 124 14b058fc64fc
parent 123 8af72b302e0a
child 125 fab494cd9da7
child 142 3d66ca73df55
Modify TimelineView's scale on resize event
src/FingersDance.Control.SyncSource/UserControlSyncSource.xaml
src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
src/FingersDance.Views/TimelineView.xaml
src/FingersDance/FingersDance.csproj
src/FingersDance/Resources/oneflat.png
src/FingersDance/Resources/videos.xml
--- a/src/FingersDance.Control.SyncSource/UserControlSyncSource.xaml	Fri Sep 25 03:38:22 2009 +0200
+++ b/src/FingersDance.Control.SyncSource/UserControlSyncSource.xaml	Fri Sep 25 18:28:58 2009 +0200
@@ -11,7 +11,7 @@
 
     <Grid x:Name="LayoutRoot" Height="{Binding Path=ActualHeight, ElementName=UserControl, Mode=Default}" Width="{Binding Path=ActualWidth, ElementName=UserControl, Mode=Default}">
         <Grid VerticalAlignment="Top" Height="100" x:Name="GridTimeLine">
-        	<FingersDance_Control_TimeLine:UserControlTimeLine Margin="40,0,108,0" x:Name="UCTimeLine" DragStarted="UserControlTimeLine_DragStarted" DragCompleted="UserControlTimeLine_DragCompleted" TimerTick="UserControlTimeLine_TimerTick" d:LayoutOverrides="Height" Background="{x:Null}" />
+        	<FingersDance_Control_TimeLine:UserControlTimeLine Margin="0,0,60,0" x:Name="UCTimeLine" DragStarted="UserControlTimeLine_DragStarted" DragCompleted="UserControlTimeLine_DragCompleted" TimerTick="UserControlTimeLine_TimerTick" d:LayoutOverrides="Height" Background="{x:Null}" />
         </Grid>
         <Grid HorizontalAlignment="Stretch" Width="Auto" Height="Auto" VerticalAlignment="Stretch" x:Name="GridPlayer" Margin="0,54,0,0">
         	<FingersDance_Control_Player:UserControlPlayer PlayerOpened="UserControlPlayer_PlayerOpened" x:Name="UserControlPlayer" VerticalAlignment="Stretch" d:LayoutOverrides="GridBox" Width="{Binding Path=ActualWidth, ElementName=GridPlayer, Mode=Default}" Margin="0,0,0,0" Height="{Binding Path=ActualHeight, ElementName=GridPlayer, Mode=Default}" />
--- a/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Fri Sep 25 03:38:22 2009 +0200
+++ b/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs	Fri Sep 25 18:28:58 2009 +0200
@@ -30,10 +30,11 @@
         public event EventHandler DragCompleted;
         public event EventHandler TimerTick;
 
+        private double totalmilliseconds;
+
         private List<Annotation> annotList = new List<Annotation>();
-        private float annotWidth = 40;
+        private float annotWidth = 40+1;
         private CuttingViewModel cutvm;
-        private int numAnnot = 1;
 
         #region Properties
 
@@ -97,32 +98,42 @@
             
 		}
 
-        public void initslider(double totalmilliseconds)
+        public void initslider(double totalmillisecondsPar)
         {
+            totalmilliseconds = totalmillisecondsPar;
             slider.Maximum = totalmilliseconds;
-
+            // When the timeline is resized, we catch the resize event to define TimelineView's good scale
+            this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged);
 
             // 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(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"));
             Cutting cut = new Cutting("titre de cutting", annotList);
             cutvm = new CuttingViewModel(cut);
             tv.DataContext = cutvm;
 
-            numAnnot = 6;
             slider_ContactTapGesture(this,null);
             /*
             cutvm.AnnotList.Add(new AnnotationViewModel(new Annotation(180 - (5 * annotWidth), 10, "6")));
             tv.DataContext = null;
             tv.DataContext = cutvm;
-            numAnnot = 7;
             */
         }
 
+        void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
+        {
+            // When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account.
+            Double futurScale = this.ActualWidth / (totalmilliseconds / 1000);
+            //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP
+            tv.RenderTransform = new ScaleTransform(futurScale,1);
+            Console.WriteLine("futurScale = " + futurScale);
+            
+        }
+
         #region Timer
         public void initTimer()
         {
@@ -193,10 +204,14 @@
 
         public void addAnnotation()
         {
-            cutvm.AnnotList.Add(new AnnotationViewModel(new Annotation(180 + (numAnnot - 6) * 20 - ((numAnnot - 1) * annotWidth), 10, numAnnot.ToString())));
-            tv.DataContext = null;
-            tv.DataContext = cutvm;
-            numAnnot++; 
+            if (cutvm!=null)
+            {
+                float currentTimecode = (float)slider.Value / 1000;
+                cutvm.AnnotList.Add(new AnnotationViewModel(new Annotation(currentTimecode - (cutvm.AnnotList.Count * annotWidth), 10, cutvm.AnnotList.Count.ToString())));
+                Console.WriteLine("currentTimecode = " + currentTimecode + ", nb = " + cutvm.AnnotList.Count + ", res = " + (currentTimecode - (cutvm.AnnotList.Count * annotWidth)));
+                tv.DataContext = null;
+                tv.DataContext = cutvm;
+            }
         }
 
 	}
--- a/src/FingersDance.Views/TimelineView.xaml	Fri Sep 25 03:38:22 2009 +0200
+++ b/src/FingersDance.Views/TimelineView.xaml	Fri Sep 25 18:28:58 2009 +0200
@@ -5,7 +5,7 @@
     >
     <Grid>
         <ListView DataContext="{Binding Path=AnnotList}"
-                  ItemsSource="{Binding}" Background="{x:Null}" BorderThickness="0" x:Name="listview" >
+                  ItemsSource="{Binding}" Background="{x:Null}" BorderThickness="0" x:Name="listview" ScrollViewer.HorizontalScrollBarVisibility="Hidden">
 
             <ListView.ItemTemplate>
                 <DataTemplate>
--- a/src/FingersDance/FingersDance.csproj	Fri Sep 25 03:38:22 2009 +0200
+++ b/src/FingersDance/FingersDance.csproj	Fri Sep 25 18:28:58 2009 +0200
@@ -134,6 +134,8 @@
     <Content Include="Resources\Lake.wmv">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
+    <Resource Include="Resources\oneflat.png" />
+    <Content Include="Resources\oneflat.wmv" />
     <Content Include="Resources\videos.xml">
       <CopyToOutputDirectory>Always</CopyToOutputDirectory>
     </Content>
Binary file src/FingersDance/Resources/oneflat.png has changed
--- a/src/FingersDance/Resources/videos.xml	Fri Sep 25 03:38:22 2009 +0200
+++ b/src/FingersDance/Resources/videos.xml	Fri Sep 25 18:28:58 2009 +0200
@@ -2,12 +2,17 @@
 <ArrayOfListVideoItem xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <ListVideoItem>
     <Name>Butterfly</Name>
-    <Path>C:\Users\Piaf\Desktop\Développement\IRI\src\FingersDance\bin\Debug\Resources\Butterfly.wmv</Path>
-    <Preview>C:\Users\Piaf\Desktop\Développement\IRI\src\FingersDance\bin\Debug\Resources\Butterfly.jpg</Preview>
+    <Path>C:\Users\Public\Public Dev\fingersdance\src\FingersDance\Resources\Butterfly.wmv</Path>
+    <Preview>C:\Users\Public\Public Dev\fingersdance\src\FingersDance\Resources\Butterfly.jpg</Preview>
   </ListVideoItem>
   <ListVideoItem>
     <Name>Lake</Name>
-    <Path>C:\Users\Piaf\Desktop\Développement\IRI\src\FingersDance\bin\Debug\Resources\Lake.wmv</Path>
-    <Preview>C:\Users\Piaf\Desktop\Développement\IRI\src\FingersDance\bin\Debug\Resources\Lake.jpg</Preview>
+    <Path>C:\Users\Public\Public Dev\fingersdance\src\FingersDance\Resources\Lake.wmv</Path>
+    <Preview>C:\Users\Public\Public Dev\fingersdance\src\FingersDance\Resources\Lake.jpg</Preview>
+  </ListVideoItem>
+  <ListVideoItem>
+    <Name>One Flat Thing</Name>
+    <Path>C:\Users\Public\Public Dev\fingersdance\src\FingersDance\Resources\oneflat.wmv</Path>
+    <Preview>C:\Users\Public\Public Dev\fingersdance\src\FingersDance\Resources\oneflat.png</Preview>
   </ListVideoItem>
 </ArrayOfListVideoItem>
\ No newline at end of file