client/src/Iri.Modernisation.Controls/View/BookTimeLine/BookTimeLine.xaml.cs
changeset 38 bd33267300aa
parent 24 c031f1132dde
child 41 b51a10574e7f
--- a/client/src/Iri.Modernisation.Controls/View/BookTimeLine/BookTimeLine.xaml.cs	Wed Jan 27 10:55:59 2010 +0100
+++ b/client/src/Iri.Modernisation.Controls/View/BookTimeLine/BookTimeLine.xaml.cs	Thu Feb 04 16:38:04 2010 +0100
@@ -13,6 +13,7 @@
 using Iri.Modernisation.Data.Models;
 using Iri.Modernisation.Controls.ViewModel;
 using Iri.Modernisation.BaseMVVM.Commands;
+using System.IO;
 namespace Iri.Modernisation.Controls.View
 {
     public partial class BookTimeLine : UserControl
@@ -22,15 +23,53 @@
             InitializeComponent();
        
             TimeStripsPanel.SizeChanged += new SizeChangedEventHandler(TimeStripsPanel_SizeChanged);
-            BookTimeLineSlider.MouseLeftButtonUp += new MouseButtonEventHandler(BookTimeLineSlider_MouseLeftButtonUp); 
+            BookTimeLineSlider.ThumbDragStarted += new EventHandler<EventArgs>(TimeSlider_ThumbDragCompleted);
+            BookTimeLineSlider.ThumbDragCompleted += new EventHandler<EventArgs>(TimeSlider_ThumbDragCompleted);
+            BookTimeLineSlider.MouseLeftButtonUp += new MouseButtonEventHandler(BookTimeLineSlider_MouseLeftButtonUp);
+            saveAnnotationsButton.Click += new RoutedEventHandler(saveAnnotationsButton_Click);
+            Commands.AnnotationMaker.NewAnnotationFinished.Executed += new EventHandler<SLExtensions.Input.ExecutedEventArgs>(NewAnnotationFinished_Executed);
         }
 
-        void BookTimeLineSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
+        void saveAnnotationsButton_Click(object sender, RoutedEventArgs e)
+        {
+            SaveFileDialog mySaveDialog = new SaveFileDialog();
+            mySaveDialog.Filter = "Ldt File (.ldt)|*.ldt|All Files|*.*";
+            bool? ret = mySaveDialog.ShowDialog();
+            if (ret == true)
+            {
+
+
+                VideoBookUploader.UpdateAnnotation(((BookTimeLineVM)DataContext).SelectedBook, new StreamWriter(mySaveDialog.OpenFile()));
+               
+            }
+    
+        }
+        private bool _saveVideoViewerState { get; set; }
+        private void TimeSlider_ThumbDragCompleted(object sender, EventArgs e)
+        {
+            if (_saveVideoViewerState)
+            {
+                ((BookTimeLineVM)DataContext).ViewModelVideoViewer.Play();
+            }
+        }
+
+        private void TimeSlider_ThumbDragStarted(object sender, EventArgs e)
+        {
+            _saveVideoViewerState = ((BookTimeLineVM)DataContext).ViewModelVideoViewer.IsPLayed;
+            ((BookTimeLineVM)DataContext).ViewModelVideoViewer.Pause();
+
+        }
+        private void NewAnnotationFinished_Executed(object sender, SLExtensions.Input.ExecutedEventArgs e)
+        {
+            Draw();
+        }
+
+        private void BookTimeLineSlider_MouseLeftButtonUp(object sender, MouseButtonEventArgs e)
         {
             Commands.TimeChange.Execute(BookTimeLineSlider.Value,DataContext);
         }
-		
-        void TimeStripsPanel_SizeChanged(object sender, SizeChangedEventArgs e)
+
+        private void TimeStripsPanel_SizeChanged(object sender, SizeChangedEventArgs e)
         {
             Draw();
         }
@@ -47,16 +86,15 @@
                 {
                    
                     PolemicElementControl pol = new PolemicElementControl();
-                    
                     pol.SetValue(Canvas.ZIndexProperty, 10);
                     pol.DataContext = new PolemicElementVM(Index);
                     BookTimeLineElementPanel.Children.Add(pol);
-                  
-                    Canvas.SetLeft(pol, (Index.TimerIn.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration);
-                    pol.Width = (Index.Duration.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration;
+                    double timeleft = (double)((Index.TimerIn.TotalMilliseconds  / BookTimeLineVM.ratioPixMs) * ScaleTimeLine.Value);
+                    Canvas.SetLeft(pol,timeleft);
+                    pol.Width = (Index.Duration.TotalMilliseconds / BookTimeLineVM.ratioPixMs) * ScaleTimeLine.Value;
                 }
             }
-            int basi = 30;
+            int basi = 0;
             foreach (List<Annotation> LAnnotation in VM.Annotations)
             {
                 foreach (Annotation Annotation in LAnnotation)
@@ -64,21 +102,41 @@
                     PolemicElementControl pol = new PolemicElementControl();
                     pol.SetValue(Canvas.ZIndexProperty, 10);
                     pol.DataContext = new PolemicElementVM(Annotation);
-                    BookTimeLineAnnotationPanel.Children.Add(pol);
-                    Canvas.SetLeft(pol, (Annotation.TimerIn.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration);
+                    
+                    Canvas.SetLeft(pol, (Annotation.TimerIn.TotalMilliseconds / BookTimeLineVM.ratioPixMs)* ScaleTimeLine.Value);
+                   
+                    /** It's TETRIS time **/
+                    foreach (PolemicElementControl lockedControl in BookTimeLineAnnotationPanel.Children)
+                    {
+                        if (
+                            ((PolemicElementVM)pol.DataContext).TimerIn >= ((PolemicElementVM)lockedControl.DataContext).TimerIn && ((PolemicElementVM)pol.DataContext).TimerIn <= ((PolemicElementVM)lockedControl.DataContext).TimerOut
+                            || ((PolemicElementVM)pol.DataContext).TimerOut >= ((PolemicElementVM)lockedControl.DataContext).TimerIn && ((PolemicElementVM)pol.DataContext).TimerOut <= ((PolemicElementVM)lockedControl.DataContext).TimerOut
+                           
+                           )
+                        {
+                            int actualTop = (int)Canvas.GetTop(lockedControl);
+                            if (basi <= actualTop)
+                           {
+                                basi += 10;
+                           }
+                            
+                        }
+                    }
+
                     Canvas.SetTop(pol, basi);
-                    basi += 10;
-                    pol.Width = (Annotation.Duration.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration;
+                  /***********************/
+                    
+                    
+                 //   pol.Width = (Annotation.Duration.TotalMilliseconds * ScaleTimeLine.Value) / VM.TotalDuration;
+                    pol.Width = (Annotation.Duration.TotalMilliseconds / BookTimeLineVM.ratioPixMs)* ScaleTimeLine.Value;
+                    BookTimeLineAnnotationPanel.Children.Add(pol);
+                    basi = 0;
                 }
             }
             BookTimeLineElementPanel.UpdateLayout();
         }
 
-        private void BookTimeLineSlider_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
-        {
-            MessageBox.Show("Change");
-            BookTimeLineSlider.Value = (e.GetPosition(BookTimeLineSlider).X) * BookTimeLineSlider.Maximum / BookTimeLineSlider.Width;
-        }
+