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