# HG changeset patch # User cavaliet # Date 1254750987 -7200 # Node ID 1f37ef03ebee995c5f880192cd1f75ea1cb60a65 # Parent 90c29e979ef4c0f1725ddc8f59a909ec776dbce1 scale change improved and now annotations can not recover any of them. diff -r 90c29e979ef4 -r 1f37ef03ebee src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs --- a/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs Fri Oct 02 18:49:07 2009 +0200 +++ b/src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs Mon Oct 05 15:56:27 2009 +0200 @@ -94,7 +94,7 @@ public UserControlTimeLine() - { + { this.InitializeComponent(); // Insert code required on object creation below this point. @@ -116,7 +116,7 @@ //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); + CuttingVM = new CuttingViewModel(cut, AnnotWidth); tv.DataContext = CuttingVM; slider_ContactTapGesture(this,null); @@ -126,7 +126,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-30) / (totalmilliseconds / 1000); //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS tv.RenderTransform = new ScaleTransform(futurScale,1); //Console.WriteLine("futurScale = " + futurScale); @@ -202,32 +202,68 @@ public void addAnnotation() { + Boolean annotOk = true; // We open a new annotation if (CuttingVM != null && AnnotWaiting == false) { - 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; - tv.DataContext = CuttingVM; - AnnotWaiting = true; + AnnotTcBegin = (float)slider.Value / 1000; + + // First we check if the new annotation will not cover any + foreach (Annotation a in AnnotList) + { + Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur)); + if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur)) + { + annotOk = false; + } + } + // if not, we mark the beginning + if (annotOk == true) + { + AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString())); + //AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString())); + //AnnotList.Add(new Annotation(0, 0, AnnotList.Count.ToString())); + + CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth); + //Console.WriteLine("BEGIN currentTimecode = " + AnnotTcBegin + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth))); + tv.DataContext = null; + tv.DataContext = CuttingVM; + AnnotWaiting = true; + } + } // We close the current opened annotation... else if (CuttingVM != null && AnnotWaiting == true && ((float)slider.Value>AnnotTcBegin)) { // ... by setting setting the good beginning and the good duration - 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; - AnnotWaiting = false; + float currentTC = (float)slider.Value / 1000; + float currentDuration = currentTC - AnnotTcBegin; + + // First we check if the new annotation will not cover any (AnnotTcBegin was already checked) + foreach (Annotation a in AnnotList) + { + Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC); + if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC)) + { + annotOk = false; + } + } + + if (annotOk == true) + { + AnnotList.RemoveAt(AnnotList.Count - 1); + AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString())); + //AnnotList.Add(new Annotation(AnnotTcBegin - (AnnotList.Count * AnnotWidth), currentDuration, AnnotList.Count.ToString())); + //AnnotList.Add(new Annotation((AnnotTcBegin / 1000), currentDuration, CuttingVM.AnnotList.Count.ToString())); + //AnnotList.Add(new Annotation(0, currentDuration, CuttingVM.AnnotList.Count.ToString())); + + + CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth); + //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth))); + tv.DataContext = null; + tv.DataContext = CuttingVM; + AnnotWaiting = false; + } } } diff -r 90c29e979ef4 -r 1f37ef03ebee src/FingersDance.ViewModel/AnnotationViewModel.cs --- a/src/FingersDance.ViewModel/AnnotationViewModel.cs Fri Oct 02 18:49:07 2009 +0200 +++ b/src/FingersDance.ViewModel/AnnotationViewModel.cs Mon Oct 05 15:56:27 2009 +0200 @@ -13,10 +13,15 @@ private float _dur; private String _gestureType; - public AnnotationViewModel(Annotation a) { + private float _marginLeft; + + public AnnotationViewModel(Annotation a, float marginLeft) { this._tcBegin = a.TcBegin; this._dur = a.Dur; this._gestureType = a.GestureType; + this._marginLeft = marginLeft; + + Console.WriteLine("_tcBegin = " + _tcBegin + ", _marginLeft = " + _marginLeft); } public float TcBegin @@ -51,6 +56,17 @@ base.OnPropertyChanged("GestureType"); } } + public float MarginLeft + { + get { return _marginLeft; } + set + { + if (value == _marginLeft || float.IsNaN(value)) + return; + _marginLeft = value; + base.OnPropertyChanged("MarginLeft"); + } + } } } diff -r 90c29e979ef4 -r 1f37ef03ebee src/FingersDance.ViewModel/CuttingViewModel.cs --- a/src/FingersDance.ViewModel/CuttingViewModel.cs Fri Oct 02 18:49:07 2009 +0200 +++ b/src/FingersDance.ViewModel/CuttingViewModel.cs Mon Oct 05 15:56:27 2009 +0200 @@ -12,12 +12,16 @@ private string _title; private List _annotList = new List(); - public CuttingViewModel(Cutting c) { + public CuttingViewModel(Cutting c, float annotWidth) { this._title = c.Title; this._annotList = new List(); + int i = 0; foreach (Annotation annot in c.AnnotList) - this._annotList.Add(new AnnotationViewModel(annot)); + { + this._annotList.Add(new AnnotationViewModel(annot, annot.TcBegin - (i * annotWidth))); + i++; + } } @@ -41,5 +45,18 @@ base.OnPropertyChanged("AnnotList"); } } + + public void setListFromAnnotations(List annotList, float annotWidth) + { + + this._annotList = new List(); + int i = 0; + foreach (Annotation annot in annotList) + { + this._annotList.Add(new AnnotationViewModel(annot, annot.TcBegin - (i * annotWidth))); + i++; + } + + } } } diff -r 90c29e979ef4 -r 1f37ef03ebee src/FingersDance.Views/TimelineAnnotationView.xaml --- a/src/FingersDance.Views/TimelineAnnotationView.xaml Fri Oct 02 18:49:07 2009 +0200 +++ b/src/FingersDance.Views/TimelineAnnotationView.xaml Mon Oct 05 15:56:27 2009 +0200 @@ -13,7 +13,7 @@ -