src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
author cavaliet
Wed, 07 Oct 2009 17:16:46 +0200
changeset 135 84b3bf5ee3d2
parent 130 192da585bee5
child 136 8b513df1b446
permissions -rw-r--r--
First step of drag and drop annotation from a timeline to an other player
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;
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
    17
using FingersDance.Views;
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
    18
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    19
namespace FingersDance.Control.TimeLine
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    20
{
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    21
	public partial class UserControlTimeLine
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    22
    {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    23
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    24
        #region Variables
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    25
        private DispatcherTimer timer;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    26
        private bool isDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    27
        private bool finishedDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    28
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    29
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    30
        public event EventHandler DragStarted;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    31
        public event EventHandler DragCompleted;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    32
        public event EventHandler TimerTick;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    33
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
    34
        private double totalmilliseconds;
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
    35
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    36
        private List<Annotation> AnnotList = new List<Annotation>();
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
    37
        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
    38
        private CuttingViewModel CuttingVM;
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    39
        private Boolean AnnotWaiting = false;
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    40
        private float AnnotTcBegin;
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
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   122
            UserControlTimeLine_SizeChanged(null, null);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   123
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   124
            slider_ContactTapGesture(this, null);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   125
            
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   126
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   127
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   128
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   129
        void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   130
        {
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   131
            // 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
   132
            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
   133
            //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
   134
            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
   135
            //Console.WriteLine("futurScale = " + futurScale);
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   136
            
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   137
        }
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   138
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   139
        #region Timer
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   140
        public void initTimer()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   141
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   142
            timer = new DispatcherTimer();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   143
            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   144
            timer.Tick += new EventHandler(timer_Tick);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   145
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   146
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   147
        public void timerStart()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   148
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   149
            if (timer != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   150
                timer.Start();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   151
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   152
        void timer_Tick(object sender, EventArgs e)
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   153
        {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   154
            OnTimerTick();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   155
            if (!isDragging)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   156
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   157
                //slider.Value = media.Position.TotalMilliseconds;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   158
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   159
            if (finishedDragging)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   160
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   161
                //int SliderValue = (int)slider.Value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   162
                //TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   163
               // media.Position = ts;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   164
               // media.Play();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   165
               // isDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   166
                //finishedDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   167
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   168
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   169
        protected virtual void OnTimerTick()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   170
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   171
            if (TimerTick != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   172
                TimerTick(this, new EventArgs());
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   173
        }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   174
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   175
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   176
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
   177
        private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e)
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   178
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   179
            isDragging = true;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   180
            OnDragStarted();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   181
           // media.Pause();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   182
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   183
        protected virtual void OnDragStarted()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   184
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   185
            if (DragStarted != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   186
                DragStarted(this, new EventArgs());
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   187
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   188
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   189
        private void sliderPosition_DragCompleted(object sender, DragCompletedEventArgs e)
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   190
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   191
            finishedDragging = true;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   192
            OnDragCompleted();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   193
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   194
        protected virtual void OnDragCompleted()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   195
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   196
            if (DragCompleted != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   197
                DragCompleted(this, new EventArgs());
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   198
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   199
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   200
        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
   201
        {
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   202
            //startOrEndAnnotation();
75
99d003723474 data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents: 74
diff changeset
   203
        }
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   204
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   205
        public void addAnnotation(AnnotationViewModel avm)
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   206
        {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   207
            Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   208
            Boolean annotOk = true;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   209
            // We check if the annotation's begin and end timecodes allow a new annotation creation
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   210
            if (CuttingVM != null && AnnotWaiting == false)
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   211
            {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   212
                foreach (Annotation a in AnnotList)
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   213
                {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   214
                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   215
                    // Check begin TC
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   216
                    if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur))
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   217
                    {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   218
                        annotOk = false;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   219
                    }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   220
                    // Check end tc and if the new annotation will not cover any other
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   221
                    float endTC = avm.TcBegin + avm.Dur;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   222
                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   223
                    if (a.TcBegin <= endTC && endTC <= (a.TcBegin + a.Dur) || (avm.TcBegin < a.TcBegin && (a.TcBegin + a.Dur) < endTC))
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   224
                    {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   225
                        annotOk = false;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   226
                    }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   227
                }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   228
                // If everything's fine, we create the new one
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   229
                if (annotOk == true)
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   230
                {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   231
                    AnnotList.Add(new Annotation(avm.TcBegin, avm.Dur, avm.GestureType));
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   232
                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   233
                    tv.DataContext = null;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   234
                    tv.DataContext = CuttingVM;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   235
                    AnnotWaiting = false;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   236
                }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   237
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   238
            }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   239
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   240
        }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   241
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   242
        public void startOrEndAnnotation()
75
99d003723474 data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents: 74
diff changeset
   243
        {
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   244
            Boolean annotOk = true;
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   245
            // We open a new annotation
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   246
            if (CuttingVM != null && AnnotWaiting == false)
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   247
            {
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   248
                AnnotTcBegin = (float)slider.Value / 1000;
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
                // 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
   251
                foreach (Annotation a in AnnotList)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   252
                {
130
192da585bee5 debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents: 129
diff changeset
   253
                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", AnnotTcBegin = " + AnnotTcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   254
                    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
   255
                    {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   256
                        annotOk = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   257
                    }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   258
                }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   259
                // if not, we mark the beginning
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   260
                if (annotOk == true)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   261
                {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   262
                    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
   263
                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   264
                    //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
   265
                    tv.DataContext = null;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   266
                    tv.DataContext = CuttingVM;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   267
                    AnnotWaiting = true;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   268
                }
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   269
            }
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   270
            // We close the current opened annotation...
130
192da585bee5 debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents: 129
diff changeset
   271
            else if (CuttingVM != null && AnnotWaiting == true && (((float)slider.Value/1000)>AnnotTcBegin))
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   272
            {
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   273
                // ... 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
   274
                float currentTC = (float)slider.Value / 1000;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   275
                float currentDuration = currentTC - AnnotTcBegin;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   276
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   277
                // 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
   278
                foreach (Annotation a in AnnotList)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   279
                {
130
192da585bee5 debug for adding annotations on timeline. Data AnnotationViewModel and TimelineAnnotationView changed to keep annotation TcBegin from visual margin.
cavaliet
parents: 129
diff changeset
   280
                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC);
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   281
                    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
   282
                    {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   283
                        annotOk = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   284
                    }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   285
                }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   286
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   287
                if (annotOk == true)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   288
                {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   289
                    AnnotList.RemoveAt(AnnotList.Count - 1);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   290
                    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
   291
                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   292
                    //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
   293
                    tv.DataContext = null;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   294
                    tv.DataContext = CuttingVM;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   295
                    AnnotWaiting = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   296
                }
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   297
            }
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   298
        }
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   299
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   300
	}
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   301
}