src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
changeset 125 fab494cd9da7
parent 124 14b058fc64fc
child 128 90c29e979ef4
equal deleted inserted replaced
124:14b058fc64fc 125:fab494cd9da7
    30         public event EventHandler DragCompleted;
    30         public event EventHandler DragCompleted;
    31         public event EventHandler TimerTick;
    31         public event EventHandler TimerTick;
    32 
    32 
    33         private double totalmilliseconds;
    33         private double totalmilliseconds;
    34 
    34 
    35         private List<Annotation> annotList = new List<Annotation>();
    35         private List<Annotation> AnnotList = new List<Annotation>();
    36         private float annotWidth = 40+1;
    36         private float AnnotWidth = 40+1;
    37         private CuttingViewModel cutvm;
    37         private CuttingViewModel CuttingVM;
       
    38         private Boolean AnnotWaiting = false;
       
    39         private float AnnotTcBegin;
       
    40         private AnnotationViewModel lastAnnotVM;
    38 
    41 
    39         #region Properties
    42         #region Properties
    40 
    43 
    41         public SurfaceSlider Slider
    44         public SurfaceSlider Slider
    42         {
    45         {
   104             slider.Maximum = totalmilliseconds;
   107             slider.Maximum = totalmilliseconds;
   105             // When the timeline is resized, we catch the resize event to define TimelineView's good scale
   108             // When the timeline is resized, we catch the resize event to define TimelineView's good scale
   106             this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged);
   109             this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged);
   107 
   110 
   108             // TEMP FOR DATA BINDING
   111             // TEMP FOR DATA BINDING
   109             annotList = new List<Annotation>();
   112             AnnotList = new List<Annotation>();
   110             annotList.Add(new Annotation(0, 10, "Axe Cam 1"));
   113             AnnotList.Add(new Annotation(0, 10, "Axe Cam 1"));
   111             //annotList.Add(new Annotation(20 - (1 * annotWidth), 30, "Mvt Cam 2"));
   114             //annotList.Add(new Annotation(20 - (1 * annotWidth), 30, "Mvt Cam 2"));
   112             //annotList.Add(new Annotation(50 - (2 * annotWidth), 60, "Saut 3"));
   115             //annotList.Add(new Annotation(50 - (2 * annotWidth), 60, "Saut 3"));
   113             //annotList.Add(new Annotation(100 - (3 * annotWidth), 20, "Saut 4"));
   116             //annotList.Add(new Annotation(100 - (3 * annotWidth), 20, "Saut 4"));
   114             //annotList.Add(new Annotation(120 - (4 * annotWidth), 50, "Saut 5"));
   117             //annotList.Add(new Annotation(120 - (4 * annotWidth), 50, "Saut 5"));
   115             Cutting cut = new Cutting("titre de cutting", annotList);
   118             Cutting cut = new Cutting("titre de cutting", AnnotList);
   116             cutvm = new CuttingViewModel(cut);
   119             CuttingVM = new CuttingViewModel(cut);
   117             tv.DataContext = cutvm;
   120             tv.DataContext = CuttingVM;
   118 
   121 
   119             slider_ContactTapGesture(this,null);
   122             slider_ContactTapGesture(this,null);
   120             /*
   123 
   121             cutvm.AnnotList.Add(new AnnotationViewModel(new Annotation(180 - (5 * annotWidth), 10, "6")));
       
   122             tv.DataContext = null;
       
   123             tv.DataContext = cutvm;
       
   124             */
       
   125         }
   124         }
   126 
   125 
   127         void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
   126         void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
   128         {
   127         {
   129             // When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account.
   128             // When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account.
   130             Double futurScale = this.ActualWidth / (totalmilliseconds / 1000);
   129             Double futurScale = this.ActualWidth / (totalmilliseconds / 1000);
   131             //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP
   130             //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS
   132             tv.RenderTransform = new ScaleTransform(futurScale,1);
   131             tv.RenderTransform = new ScaleTransform(futurScale,1);
   133             Console.WriteLine("futurScale = " + futurScale);
   132             //Console.WriteLine("futurScale = " + futurScale);
   134             
   133             
   135         }
   134         }
   136 
   135 
   137         #region Timer
   136         #region Timer
   138         public void initTimer()
   137         public void initTimer()
   202             //addAnnotation();
   201             //addAnnotation();
   203         }
   202         }
   204 
   203 
   205         public void addAnnotation()
   204         public void addAnnotation()
   206         {
   205         {
   207             if (cutvm!=null)
   206             // We open a new annotation
   208             {
   207             if (CuttingVM != null && AnnotWaiting == false)
   209                 float currentTimecode = (float)slider.Value / 1000;
   208             {
   210                 cutvm.AnnotList.Add(new AnnotationViewModel(new Annotation(currentTimecode - (cutvm.AnnotList.Count * annotWidth), 10, cutvm.AnnotList.Count.ToString())));
   209                 AnnotTcBegin = (float)slider.Value;
   211                 Console.WriteLine("currentTimecode = " + currentTimecode + ", nb = " + cutvm.AnnotList.Count + ", res = " + (currentTimecode - (cutvm.AnnotList.Count * annotWidth)));
   210                 lastAnnotVM = new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth), 0, CuttingVM.AnnotList.Count.ToString()));
       
   211                 CuttingVM.AnnotList.Add(lastAnnotVM);
       
   212                 Console.WriteLine("BEGIN currentTimecode = " + (AnnotTcBegin / 1000) + ", nb = " + CuttingVM.AnnotList.Count + ", res = " + ((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth)));
   212                 tv.DataContext = null;
   213                 tv.DataContext = null;
   213                 tv.DataContext = cutvm;
   214                 tv.DataContext = CuttingVM;
       
   215                 AnnotWaiting = true;
       
   216             }
       
   217             // We close the current opened annotation...
       
   218             else if (CuttingVM != null && AnnotWaiting == true && ((float)slider.Value>AnnotTcBegin))
       
   219             {
       
   220                 // ... by setting setting the good beginning and the good duration
       
   221                 float currentDuration = ((float)slider.Value - AnnotTcBegin) / 1000;
       
   222                 CuttingVM.AnnotList.RemoveAt(CuttingVM.AnnotList.Count - 1);
       
   223                 CuttingVM.AnnotList.Add(new AnnotationViewModel(new Annotation((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth), currentDuration, CuttingVM.AnnotList.Count.ToString())));
       
   224                 Console.WriteLine("currentTimecode = " + (AnnotTcBegin / 1000) + ", curDur = " + currentDuration + ", nb = " + CuttingVM.AnnotList.Count + ", res = " + ((AnnotTcBegin / 1000) - (CuttingVM.AnnotList.Count * AnnotWidth)));
       
   225                 tv.DataContext = null;
       
   226                 tv.DataContext = CuttingVM;
       
   227                 AnnotWaiting = false;
   214             }
   228             }
   215         }
   229         }
   216 
   230 
   217 	}
   231 	}
   218 }
   232 }