src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
author cavaliet
Mon, 05 Oct 2009 15:56:27 +0200
changeset 129 1f37ef03ebee
parent 128 90c29e979ef4
child 130 192da585bee5
permissions -rw-r--r--
scale change improved and now annotations can not recover any of them.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     1
using System;
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
     2
using System.Collections.Generic;
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     3
using System.IO;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     4
using System.Net;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     5
using System.Windows;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     6
using System.Windows.Controls;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     7
using System.Windows.Data;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     8
using System.Windows.Media;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     9
using System.Windows.Media.Animation;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    10
using System.Windows.Navigation;
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    11
using System.Windows.Controls.Primitives;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    12
using Microsoft.Surface.Presentation.Controls;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    13
using System.Windows.Threading;
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    14
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
    15
using FingersDance.Data;
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
    16
using FingersDance.ViewModels;
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
    17
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    18
namespace FingersDance.Control.TimeLine
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    19
{
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    20
	public partial class UserControlTimeLine
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    21
    {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    22
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    23
        #region Variables
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    24
        private DispatcherTimer timer;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    25
        private bool isDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    26
        private bool finishedDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    27
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    28
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    29
        public event EventHandler DragStarted;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    30
        public event EventHandler DragCompleted;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    31
        public event EventHandler TimerTick;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    32
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
    33
        private double totalmilliseconds;
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
    34
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    35
        private List<Annotation> AnnotList = new List<Annotation>();
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
    36
        private float AnnotWidth = 300 + 15; // The surfaceListBox adds 15 pixels between each item
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    37
        private CuttingViewModel CuttingVM;
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    38
        private Boolean AnnotWaiting = false;
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    39
        private float AnnotTcBegin;
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    40
        private AnnotationViewModel lastAnnotVM;
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
    41
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    42
        #region Properties
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    43
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    44
        public SurfaceSlider Slider
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    45
        {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    46
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    47
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    48
                return slider;
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    49
            }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    50
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    51
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    52
                slider = value;
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    53
            }
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    54
        }
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    55
        
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    56
        public bool IsDragging
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    57
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    58
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    59
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    60
                return isDragging;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    61
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    62
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    63
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    64
                isDragging = value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    65
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    66
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    67
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    68
        public bool FinishedDragging
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    69
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    70
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    71
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    72
                return finishedDragging;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    73
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    74
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    75
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    76
                finishedDragging = value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    77
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    78
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    79
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    80
        public DispatcherTimer Timer
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    81
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    82
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    83
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    84
                return timer;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    85
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    86
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    87
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    88
                timer = value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    89
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    90
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    91
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    92
        
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    93
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    94
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    95
        
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    96
		public UserControlTimeLine()
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
    97
		{
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    98
			this.InitializeComponent();
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    99
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   100
			// Insert code required on object creation below this point.
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
   101
            
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   102
		}
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   103
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   104
        public void initslider(double totalmillisecondsPar)
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   105
        {
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   106
            totalmilliseconds = totalmillisecondsPar;
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   107
            slider.Maximum = totalmilliseconds;
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   108
            // When the timeline is resized, we catch the resize event to define TimelineView's good scale
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   109
            this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged);
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
   110
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
   111
            // TEMP FOR DATA BINDING
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   112
            AnnotList = new List<Annotation>();
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   113
            AnnotList.Add(new Annotation(0, 10, "Axe Cam 1"));
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
   114
            //AnnotList.Add(new Annotation(100 - (1 * AnnotWidth), 70, "Mvt Cam 2"));
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
   115
            //AnnotList.Add(new Annotation(200 - (2 * AnnotWidth), 50, "Saut 3"));
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
   116
            //AnnotList.Add(new Annotation(100 - (3 * AnnotWidth), 20, "Saut 4"));
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
   117
            //AnnotList.Add(new Annotation(120 - (4 * AnnotWidth), 50, "Saut 5"));
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   118
            Cutting cut = new Cutting("titre de cutting", AnnotList);
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   119
            CuttingVM = new CuttingViewModel(cut, AnnotWidth);
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   120
            tv.DataContext = CuttingVM;
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
   121
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   122
            slider_ContactTapGesture(this,null);
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   123
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   124
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   125
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   126
        void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   127
        {
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   128
            // When scaleX = 1, 1 second = 1 pixel. To calculate the new scale, we take the real width in account.
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   129
            Double futurScale = (this.ActualWidth-30) / (totalmilliseconds / 1000);
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   130
            //Double futurScale = this.ActualWidth / ((totalmilliseconds<30000) ? (totalmilliseconds/10) : (totalmilliseconds / 1000)); // TEMP FOR SHORT CONTENTS
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   131
            tv.RenderTransform = new ScaleTransform(futurScale,1);
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   132
            //Console.WriteLine("futurScale = " + futurScale);
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   133
            
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   134
        }
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   135
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   136
        #region Timer
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   137
        public void initTimer()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   138
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   139
            timer = new DispatcherTimer();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   140
            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   141
            timer.Tick += new EventHandler(timer_Tick);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   142
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   143
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   144
        public void timerStart()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   145
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   146
            if (timer != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   147
                timer.Start();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   148
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   149
        void timer_Tick(object sender, EventArgs e)
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   150
        {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   151
            OnTimerTick();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   152
            if (!isDragging)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   153
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   154
                //slider.Value = media.Position.TotalMilliseconds;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   155
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   156
            if (finishedDragging)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   157
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   158
                //int SliderValue = (int)slider.Value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   159
                //TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   160
               // media.Position = ts;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   161
               // media.Play();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   162
               // isDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   163
                //finishedDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   164
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   165
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   166
        protected virtual void OnTimerTick()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   167
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   168
            if (TimerTick != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   169
                TimerTick(this, new EventArgs());
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   170
        }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   171
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   172
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   173
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
   174
        private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e)
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   175
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   176
            isDragging = true;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   177
            OnDragStarted();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   178
           // media.Pause();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   179
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   180
        protected virtual void OnDragStarted()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   181
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   182
            if (DragStarted != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   183
                DragStarted(this, new EventArgs());
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   184
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   185
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   186
        private void sliderPosition_DragCompleted(
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   187
            object sender, DragCompletedEventArgs e)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   188
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   189
            finishedDragging = true;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   190
            OnDragCompleted();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   191
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   192
        protected virtual void OnDragCompleted()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   193
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   194
            if (DragCompleted != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   195
                DragCompleted(this, new EventArgs());
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   196
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   197
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   198
        private void slider_ContactTapGesture(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   199
        {
99
5a49507c8159 Debug Player
sarias
parents: 75
diff changeset
   200
            //addAnnotation();
75
99d003723474 data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents: 74
diff changeset
   201
        }
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   202
75
99d003723474 data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents: 74
diff changeset
   203
        public void addAnnotation()
99d003723474 data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents: 74
diff changeset
   204
        {
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   205
            Boolean annotOk = true;
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   206
            // We open a new annotation
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   207
            if (CuttingVM != null && AnnotWaiting == false)
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   208
            {
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   209
                AnnotTcBegin = (float)slider.Value / 1000;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   210
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   211
                // First we check if the new annotation will not cover any
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   212
                foreach (Annotation a in AnnotList)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   213
                {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   214
                    Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   215
                    if (a.TcBegin <= AnnotTcBegin && AnnotTcBegin <= (a.TcBegin + a.Dur))
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   216
                    {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   217
                        annotOk = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   218
                    }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   219
                }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   220
                // if not, we mark the beginning
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   221
                if (annotOk == true)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   222
                {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   223
                    AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString()));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   224
                    //AnnotList.Add(new Annotation(AnnotTcBegin, 0, AnnotList.Count.ToString()));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   225
                    //AnnotList.Add(new Annotation(0, 0, AnnotList.Count.ToString()));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   226
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   227
                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   228
                    //Console.WriteLine("BEGIN currentTimecode = " + AnnotTcBegin + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   229
                    tv.DataContext = null;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   230
                    tv.DataContext = CuttingVM;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   231
                    AnnotWaiting = true;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   232
                }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   233
                
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   234
            }
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   235
            // We close the current opened annotation...
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   236
            else if (CuttingVM != null && AnnotWaiting == true && ((float)slider.Value>AnnotTcBegin))
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   237
            {
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   238
                // ... by setting setting the good beginning and the good duration
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   239
                float currentTC = (float)slider.Value / 1000;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   240
                float currentDuration = currentTC - AnnotTcBegin;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   241
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   242
                // First we check if the new annotation will not cover any (AnnotTcBegin was already checked)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   243
                foreach (Annotation a in AnnotList)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   244
                {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   245
                    Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   246
                    if (a.TcBegin <= currentTC && currentTC <= (a.TcBegin + a.Dur) || (AnnotTcBegin < a.TcBegin && (a.TcBegin + a.Dur) < currentTC))
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   247
                    {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   248
                        annotOk = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   249
                    }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   250
                }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   251
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   252
                if (annotOk == true)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   253
                {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   254
                    AnnotList.RemoveAt(AnnotList.Count - 1);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   255
                    AnnotList.Add(new Annotation(AnnotTcBegin, currentDuration, AnnotList.Count.ToString()));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   256
                    //AnnotList.Add(new Annotation(AnnotTcBegin - (AnnotList.Count * AnnotWidth), currentDuration, AnnotList.Count.ToString()));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   257
                    //AnnotList.Add(new Annotation((AnnotTcBegin / 1000), currentDuration, CuttingVM.AnnotList.Count.ToString()));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   258
                    //AnnotList.Add(new Annotation(0, currentDuration, CuttingVM.AnnotList.Count.ToString()));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   259
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   260
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   261
                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   262
                    //Console.WriteLine("currentTimecode = " + AnnotTcBegin + ", curDur = " + currentDuration + ", nb = " + AnnotList.Count + ", res = " + (AnnotTcBegin - (AnnotList.Count * AnnotWidth)));
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   263
                    tv.DataContext = null;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   264
                    tv.DataContext = CuttingVM;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   265
                    AnnotWaiting = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   266
                }
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   267
            }
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   268
        }
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   269
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   270
	}
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   271
}