src/FingersDance.Control.TimeLine/UserControlTimeLine.xaml.cs
author cavaliet
Fri, 09 Oct 2009 11:33:35 +0200
changeset 136 8b513df1b446
parent 135 84b3bf5ee3d2
child 140 fc7c12f9da30
permissions -rw-r--r--
First step of deleting annotations from timeline by drag and drop
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;
136
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
     8
using System.Windows.Input;
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
     9
using System.Windows.Media;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    10
using System.Windows.Media.Animation;
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    11
using System.Windows.Navigation;
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    12
using System.Windows.Controls.Primitives;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    13
using Microsoft.Surface.Presentation.Controls;
136
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
    14
using Microsoft.Surface.Presentation;
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    15
using System.Windows.Threading;
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    16
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
    17
using FingersDance.Data;
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
    18
using FingersDance.ViewModels;
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
    19
using FingersDance.Views;
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
    20
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    21
namespace FingersDance.Control.TimeLine
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    22
{
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    23
	public partial class UserControlTimeLine
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    24
    {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    25
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    26
        #region Variables
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    27
        private DispatcherTimer timer;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    28
        private bool isDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    29
        private bool finishedDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    30
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    31
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    32
        public event EventHandler DragStarted;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    33
        public event EventHandler DragCompleted;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    34
        public event EventHandler TimerTick;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    35
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
    36
        private double totalmilliseconds;
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
    37
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    38
        private List<Annotation> AnnotList = new List<Annotation>();
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
    39
        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
    40
        private CuttingViewModel CuttingVM;
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    41
        private Boolean AnnotWaiting = false;
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
    42
        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
    43
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    44
        #region Properties
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    45
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    46
        public SurfaceSlider Slider
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    47
        {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    48
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    49
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    50
                return slider;
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    51
            }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    52
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    53
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    54
                slider = value;
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    55
            }
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    56
        }
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    57
        
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    58
        public bool IsDragging
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    59
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    60
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    61
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    62
                return isDragging;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    63
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    64
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    65
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    66
                isDragging = value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    67
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    68
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    69
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    70
        public bool FinishedDragging
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    71
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    72
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    73
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    74
                return finishedDragging;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    75
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    76
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    77
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    78
                finishedDragging = value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    79
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    80
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    81
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    82
        public DispatcherTimer Timer
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    83
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    84
            get
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    85
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    86
                return timer;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    87
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    88
            set
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    89
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    90
                timer = value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    91
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    92
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    93
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    94
        
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    95
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    96
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
    97
        
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
    98
		public UserControlTimeLine()
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
    99
		{
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   100
			this.InitializeComponent();
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   101
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   102
			// Insert code required on object creation below this point.
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
   103
            
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   104
		}
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   105
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   106
        public void initslider(double totalmillisecondsPar)
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   107
        {
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   108
            totalmilliseconds = totalmillisecondsPar;
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   109
            slider.Maximum = totalmilliseconds;
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   110
            // 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
   111
            this.SizeChanged += new SizeChangedEventHandler(UserControlTimeLine_SizeChanged);
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
   112
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
   113
            // TEMP FOR DATA BINDING
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   114
            AnnotList = new List<Annotation>();
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   115
            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
   116
            //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
   117
            //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
   118
            //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
   119
            //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
   120
            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
   121
            CuttingVM = new CuttingViewModel(cut, AnnotWidth);
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   122
            tv.DataContext = CuttingVM;
69
a4c44555f205 First Data binding for annotations and timeline
cavaliet
parents: 34
diff changeset
   123
136
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   124
            tv.listview.PreviewContactDown += listview_PreviewContactDown;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   125
            SurfaceDragDrop.AddDragCanceledHandler(tv.listview, onDragCanceled);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   126
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   127
            UserControlTimeLine_SizeChanged(null, null);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   128
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   129
            slider_ContactTapGesture(this, null);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   130
            
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   131
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   132
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   133
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   134
        void UserControlTimeLine_SizeChanged(object sender, SizeChangedEventArgs e)
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   135
        {
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   136
            // 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
   137
            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
   138
            //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
   139
            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
   140
            //Console.WriteLine("futurScale = " + futurScale);
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   141
            
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   142
        }
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   143
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   144
        #region Timer
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   145
        public void initTimer()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   146
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   147
            timer = new DispatcherTimer();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   148
            timer.Interval = new TimeSpan(0, 0, 0, 0, 100);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   149
            timer.Tick += new EventHandler(timer_Tick);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   150
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   151
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   152
        public void timerStart()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   153
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   154
            if (timer != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   155
                timer.Start();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   156
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   157
        void timer_Tick(object sender, EventArgs e)
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   158
        {
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   159
            OnTimerTick();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   160
            if (!isDragging)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   161
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   162
                //slider.Value = media.Position.TotalMilliseconds;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   163
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   164
            if (finishedDragging)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   165
            {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   166
                //int SliderValue = (int)slider.Value;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   167
                //TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   168
               // media.Position = ts;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   169
               // media.Play();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   170
               // isDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   171
                //finishedDragging = false;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   172
            }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   173
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   174
        protected virtual void OnTimerTick()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   175
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   176
            if (TimerTick != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   177
                TimerTick(this, new EventArgs());
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   178
        }
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   179
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   180
        #endregion
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   181
128
90c29e979ef4 Drag and drop of annotations from timeline, first step
cavaliet
parents: 125
diff changeset
   182
        private void sliderPosition_DragStarted(object sender, DragStartedEventArgs e)
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   183
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   184
            isDragging = true;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   185
            OnDragStarted();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   186
           // media.Pause();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   187
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   188
        protected virtual void OnDragStarted()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   189
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   190
            if (DragStarted != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   191
                DragStarted(this, new EventArgs());
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   192
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   193
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   194
        private void sliderPosition_DragCompleted(object sender, DragCompletedEventArgs e)
34
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   195
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   196
            finishedDragging = true;
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   197
            OnDragCompleted();
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   198
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   199
        protected virtual void OnDragCompleted()
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   200
        {
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   201
            if (DragCompleted != null)
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   202
                DragCompleted(this, new EventArgs());
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   203
        }
9e222810f5b5 User Control Player
sarias
parents: 10
diff changeset
   204
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   205
        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
   206
        {
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   207
            //startOrEndAnnotation();
75
99d003723474 data binding second step. we can add annotation by clicking on menu buttons or timeline.
cavaliet
parents: 74
diff changeset
   208
        }
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   209
136
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   210
        public Boolean isAnnotationAccepted(AnnotationViewModel avm)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   211
        {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   212
            Boolean annotOk = true;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   213
            // We check if the annotation's begin and end timecodes allow a new annotation creation
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   214
            if (CuttingVM != null && AnnotWaiting == false)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   215
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   216
                foreach (Annotation a in AnnotList)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   217
                {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   218
                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   219
                    // Check begin TC
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   220
                    if (a.TcBegin <= avm.TcBegin && avm.TcBegin <= (a.TcBegin + a.Dur))
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   221
                    {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   222
                        annotOk = false;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   223
                    }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   224
                    // Check end tc and if the new annotation will not cover any other
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   225
                    float endTC = avm.TcBegin + avm.Dur;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   226
                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur) + ", AnnotTcBegin = " + AnnotTcBegin + ", currentTC = " + currentTC);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   227
                    if (a.TcBegin <= endTC && endTC <= (a.TcBegin + a.Dur) || (avm.TcBegin < a.TcBegin && (a.TcBegin + a.Dur) < endTC))
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   228
                    {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   229
                        annotOk = false;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   230
                    }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   231
                }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   232
            }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   233
            else
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   234
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   235
                annotOk = false;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   236
            }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   237
            return annotOk;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   238
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   239
        }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   240
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   241
        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
   242
        {
136
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   243
            //Console.WriteLine("addAnnotation = " + avm.TcBegin + ", " + avm.Dur + ", " + avm.GestureType);
135
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   244
            Boolean annotOk = true;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   245
            // 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
   246
            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
   247
            {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   248
                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
   249
                {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   250
                    //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
   251
                    // Check begin TC
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   252
                    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
   253
                    {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   254
                        annotOk = false;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   255
                    }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   256
                    // 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
   257
                    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
   258
                    //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
   259
                    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
   260
                    {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   261
                        annotOk = false;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   262
                    }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   263
                }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   264
                // 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
   265
                if (annotOk == true)
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   266
                {
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   267
                    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
   268
                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   269
                    tv.DataContext = null;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   270
                    tv.DataContext = CuttingVM;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   271
                    AnnotWaiting = false;
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   272
                }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   273
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   274
            }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   275
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   276
        }
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   277
84b3bf5ee3d2 First step of drag and drop annotation from a timeline to an other player
cavaliet
parents: 130
diff changeset
   278
        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
   279
        {
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   280
            Boolean annotOk = true;
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   281
            // We open a new annotation
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   282
            if (CuttingVM != null && AnnotWaiting == false)
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   283
            {
129
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   284
                AnnotTcBegin = (float)slider.Value / 1000;
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
                // 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
   287
                foreach (Annotation a in AnnotList)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   288
                {
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
   289
                    //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
   290
                    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
   291
                    {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   292
                        annotOk = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   293
                    }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   294
                }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   295
                // if not, we mark the beginning
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   296
                if (annotOk == true)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   297
                {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   298
                    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
   299
                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   300
                    //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
   301
                    tv.DataContext = null;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   302
                    tv.DataContext = CuttingVM;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   303
                    AnnotWaiting = true;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   304
                }
125
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   305
            }
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   306
            // 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
   307
            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
   308
            {
fab494cd9da7 Now to define an annotation we define its begin then its end.
cavaliet
parents: 124
diff changeset
   309
                // ... 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
   310
                float currentTC = (float)slider.Value / 1000;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   311
                float currentDuration = currentTC - AnnotTcBegin;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   312
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   313
                // 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
   314
                foreach (Annotation a in AnnotList)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   315
                {
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
   316
                    //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
   317
                    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
   318
                    {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   319
                        annotOk = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   320
                    }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   321
                }
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   322
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   323
                if (annotOk == true)
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   324
                {
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   325
                    AnnotList.RemoveAt(AnnotList.Count - 1);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   326
                    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
   327
                    CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   328
                    //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
   329
                    tv.DataContext = null;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   330
                    tv.DataContext = CuttingVM;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   331
                    AnnotWaiting = false;
1f37ef03ebee scale change improved and now annotations can not recover any of them.
cavaliet
parents: 128
diff changeset
   332
                }
124
14b058fc64fc Modify TimelineView's scale on resize event
cavaliet
parents: 115
diff changeset
   333
            }
74
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   334
        }
7ce946833eae First step of data binding where we can add an annotation by clicking on the timeline
cavaliet
parents: 69
diff changeset
   335
136
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   336
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   337
        private void listview_PreviewContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   338
        {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   339
            FrameworkElement findSource = e.OriginalSource as FrameworkElement;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   340
            SurfaceListBoxItem draggedElement = null;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   341
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   342
            // Find the touched SurfaceListBoxItem object.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   343
            while (draggedElement == null && findSource != null)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   344
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   345
                if ((draggedElement = findSource as SurfaceListBoxItem) == null)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   346
                {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   347
                    findSource = VisualTreeHelper.GetParent(findSource) as FrameworkElement;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   348
                }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   349
            }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   350
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   351
            if (draggedElement == null)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   352
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   353
                return;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   354
            }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   355
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   356
            // Create the cursor visual.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   357
            ContentControl cursorVisual = new ContentControl()
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   358
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   359
                Content = new TimelineAnnotationView()
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   360
                {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   361
                    DataContext = findSource.DataContext
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   362
                }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   363
            };
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   364
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   365
            // We apply the current scale to the dragged annotation
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   366
            ((TimelineAnnotationView)cursorVisual.Content).RenderTransform = this.RenderTransform;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   367
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   368
            // Add a handler. This will enable the application to change the visual cues. (NOT USEFUL IN FINGERSDANCE CASE)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   369
            //SurfaceDragDrop.AddTargetChangedHandler(cursorVisual, OnTargetChanged);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   370
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   371
            // Create a list of input devices. Add the contacts that
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   372
            // are currently captured within the dragged element and
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   373
            // the current contact (if it isn't already in the list).
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   374
            List<InputDevice> devices = new List<InputDevice>();
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   375
            devices.Add(e.Contact);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   376
            foreach (Contact contact in draggedElement.ContactsCapturedWithin)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   377
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   378
                if (contact != e.Contact)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   379
                {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   380
                    devices.Add(contact);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   381
                }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   382
            }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   383
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   384
            // Get the drag source object
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   385
            ItemsControl dragSource = ItemsControl.ItemsControlFromItemContainer(draggedElement);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   386
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   387
            bool startDragOkay =
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   388
                SurfaceDragDrop.BeginDragDrop(
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   389
                  dragSource,                 // The SurfaceListBox object that the cursor is dragged out from.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   390
                  draggedElement,             // The SurfaceListBoxItem object that is dragged from the drag source.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   391
                  cursorVisual,               // The visual element of the cursor.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   392
                  draggedElement.DataContext, // The data associated with the cursor.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   393
                  devices,                    // The input devices that start dragging the cursor.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   394
                  DragDropEffects.Move);      // The allowed drag-and-drop effects of the operation.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   395
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   396
            // If the drag began successfully, set e.Handled to true. 
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   397
            // Otherwise SurfaceListBoxItem captures the contact 
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   398
            // and causes the drag operation to fail.
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   399
            e.Handled = startDragOkay;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   400
        }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   401
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   402
        private void onDragCanceled(Object sender, SurfaceDragDropEventArgs e)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   403
        {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   404
            Console.WriteLine("onDragCanceled = " + sender + ", ((ContentControl)e.Cursor.Visual).Content = " + ((ContentControl)e.Cursor.Visual).Content);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   405
            // e.Cursor.Visual is the ContentControl, so its Content is the dragged TimelineAnnotationView
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   406
            AnnotationViewModel annotationDataVM = (AnnotationViewModel)((TimelineAnnotationView)((ContentControl)e.Cursor.Visual).Content).DataContext;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   407
            // We check if the annotation is well one of the current annotations
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   408
            if (CuttingVM != null)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   409
            {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   410
                foreach (Annotation a in AnnotList)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   411
                {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   412
                    //Console.WriteLine("a.TcBegin = " + a.TcBegin + ", avm.TcBegin = " + avm.TcBegin + ", tcOut = " + (a.TcBegin + a.Dur));
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   413
                    // Check begin TC
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   414
                    if (a.TcBegin == annotationDataVM.TcBegin && a.Dur == annotationDataVM.Dur && a.GestureType==annotationDataVM.GestureType)
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   415
                    {
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   416
                        // We found the good annotation so we can delete it
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   417
                        AnnotList.Remove(a);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   418
                        // We redisplay the timeline
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   419
                        CuttingVM.setListFromAnnotations(AnnotList, AnnotWidth);
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   420
                        tv.DataContext = null;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   421
                        tv.DataContext = CuttingVM;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   422
                        return;
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   423
                    }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   424
                }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   425
            }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   426
        }
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   427
8b513df1b446 First step of deleting annotations from timeline by drag and drop
cavaliet
parents: 135
diff changeset
   428
10
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   429
	}
e8bfe1102e03 Modif sur ControlPlayer pour les videos.
sarias
parents:
diff changeset
   430
}