src/FingersDance.Control.UserPanel/SurfaceUserPanelTest.xaml.cs
changeset 34 9e222810f5b5
child 35 ed77793b767a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/FingersDance.Control.UserPanel/SurfaceUserPanelTest.xaml.cs	Sun Aug 09 18:29:41 2009 +0200
@@ -0,0 +1,146 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Windows;
+using System.Windows.Controls;
+using System.Windows.Data;
+using System.Windows.Documents;
+using System.Windows.Input;
+using System.Windows.Media;
+using System.Windows.Media.Imaging;
+using System.Windows.Shapes;
+using System.Windows.Threading;
+using Microsoft.Surface;
+using Microsoft.Surface.Presentation;
+using Microsoft.Surface.Presentation.Controls;
+
+namespace FingersDance.Control.UserPanel
+{
+    /// <summary>
+    /// Interaction logic for SurfaceWindow1.xaml
+    /// </summary>
+    public partial class SurfaceWindow1 : SurfaceWindow
+    {
+        /// <summary>
+        /// Default constructor.
+        /// </summary>
+        public SurfaceWindow1()
+        {
+            InitializeComponent();
+
+            // Add handlers for Application activation events
+            AddActivationHandlers();
+        }
+
+
+        /// <summary>
+        /// Occurs when the window is about to close. 
+        /// </summary>
+        /// <param name="e"></param>
+        protected override void OnClosed(EventArgs e)
+        {
+            base.OnClosed(e);
+
+            // Remove handlers for Application activation events
+            RemoveActivationHandlers();
+        }
+
+        /// <summary>
+        /// Adds handlers for Application activation events.
+        /// </summary>
+        private void AddActivationHandlers()
+        {
+            // Subscribe to surface application activation events
+            ApplicationLauncher.ApplicationActivated += OnApplicationActivated;
+            ApplicationLauncher.ApplicationPreviewed += OnApplicationPreviewed;
+            ApplicationLauncher.ApplicationDeactivated += OnApplicationDeactivated;
+        }
+
+        /// <summary>
+        /// Removes handlers for Application activation events.
+        /// </summary>
+        private void RemoveActivationHandlers()
+        {
+            // Unsubscribe from surface application activation events
+            ApplicationLauncher.ApplicationActivated -= OnApplicationActivated;
+            ApplicationLauncher.ApplicationPreviewed -= OnApplicationPreviewed;
+            ApplicationLauncher.ApplicationDeactivated -= OnApplicationDeactivated;
+        }
+
+        /// <summary>
+        /// This is called when application has been activated.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void OnApplicationActivated(object sender, EventArgs e)
+        {
+            //TODO: enable audio, animations here
+        }
+
+        /// <summary>
+        /// This is called when application is in preview mode.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void OnApplicationPreviewed(object sender, EventArgs e)
+        {
+            //TODO: Disable audio here if it is enabled
+
+            //TODO: optionally enable animations here
+        }
+
+        /// <summary>
+        ///  This is called when application has been deactivated.
+        /// </summary>
+        /// <param name="sender"></param>
+        /// <param name="e"></param>
+        private void OnApplicationDeactivated(object sender, EventArgs e)
+        {
+            //TODO: disable audio, animations here
+        }
+
+        private void UserControlPlayer_PlayerOpened(object sender, EventArgs e)
+        {
+            //Initialisation du slider
+            UserControlTimeLine.initslider(UserControlPlayer.TotalMilliseconds);
+            //Demarrage du Timer
+            UserControlTimeLine.timerStart();
+
+        }
+
+        private void SurfaceWindow_Activated(object sender, EventArgs e)
+        {
+            //initialisation du Timer
+            UserControlTimeLine.initTimer();
+        }
+
+        private void UserControlTimeLine_DragStarted(object sender, EventArgs e)
+        {
+            UserControlPlayer.playerPause();
+        }
+
+        private void UserControlTimeLine_DragCompleted(object sender, EventArgs e)
+        {
+        }
+
+        private void UserControlTimeLine_TimerTick(object sender, EventArgs e)
+        {
+            if (!UserControlTimeLine.IsDragging)
+            {
+                UserControlTimeLine.Slider.Value = UserControlPlayer.Player.Position.TotalMilliseconds;
+            }
+            if (UserControlTimeLine.FinishedDragging)
+            {
+                int SliderValue = (int)UserControlTimeLine.Slider.Value;
+                TimeSpan ts = new TimeSpan(0, 0, 0, 0, SliderValue);
+
+                UserControlPlayer.Player.Position = ts;
+                UserControlPlayer.playerPlay();
+
+                UserControlTimeLine.IsDragging = false;
+                UserControlTimeLine.FinishedDragging = false;
+            }
+        }
+    }
+}
\ No newline at end of file