src/FingersDance/MainSurfaceWindow.xaml.cs
author sarias
Thu, 17 Sep 2009 08:31:15 +0200
changeset 72 f1ca0958c992
parent 60 b4008a356f90
child 73 bda95242e600
permissions -rw-r--r--
Travail sur le control List Video et comunication entre ListVideo et FingersDance

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;

using FingersDance.Control.UserPanel;
using FingersDance.Control.ListVideo;
using FingersDance.Control.SessionInput;

namespace FingersDance
{
    /// <summary>
    /// Interaction logic for SurfaceWindow1.xaml
    /// </summary>
    public partial class SurfaceWindow1 : SurfaceWindow
    {
        /// <summary>
        /// Default constructor.
        /// </summary>
        /// 
        #region Variables
        private bool isCreatedP1 = false;
        private bool isCreatedP2 = false;
        private bool isCreatedP3 = false;
        private bool isCreatedP4 = false;
        #endregion

        ActionFactory.ActionGenerator _Factory = new FingersDance.ActionFactory.ActionFactory().GetGenerator();

        public SurfaceWindow1()
        {
            InitializeComponent();

            //Permet d'initialiser l'inertie du Pivot une fois relach�.
            InitPivotInertia();
            //Permet d'initialiser les quand Grid � la position initiale du pivot
            InitGridPositions();
            // Add handlers for Application activation events
            AddActivationHandlers();
        }

        private void InitPivotInertia()
        {
            try
            {
                ScatterViewItem item = (ScatterViewItem)ScaterView.Items.GetItemAt(0);
                item.DecelerationRate = double.NaN;
            }
            catch (Exception ex) { }
        }

        private void InitGridPositions()
        {
            //Initialise les 4 Grids � la positions initiale du Pivot.   
            try
            {
                ScatterViewItem item = (ScatterViewItem)ScaterView.Items.GetItemAt(0);
                Grid1.Width =item.Center.X;
                Grid1.Height = item.Center.Y;
                
                Grid2.Width = item.Center.X;
                Grid2.Height = 768 - item.Center.Y;

                Grid3.Width = 1024 - item.Center.X;
                Grid3.Height = 768 - item.Center.Y;

                Grid4.Width = 1024 - item.Center.X;
                Grid4.Height = item.Center.Y;
            }
            catch (Exception ex) { }
        }


        /// <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 ScaterView_ContactChanged(object sender, ContactEventArgs e)
        {
            //Permet la MAJ des 4 Grids � la position du pivot
            try
            {
                Grid1.Width = e.GetPosition(mainSurfaceWindow).X;
                Grid1.Height = e.GetPosition(mainSurfaceWindow).Y;

                Grid3.Width = e.GetPosition(mainSurfaceWindow).X;
                Grid3.Height = 768 - e.GetPosition(mainSurfaceWindow).Y;

                Grid4.Width = 1024 - e.GetPosition(mainSurfaceWindow).X;
                Grid4.Height = 768 - e.GetPosition(mainSurfaceWindow).Y;

                Grid2.Width = 1024 - e.GetPosition(mainSurfaceWindow).X;
                Grid2.Height = e.GetPosition(mainSurfaceWindow).Y;
            }
            catch (Exception ex) { }
        }

        private void UserControlPivot_EH_SurfaceButtonPlayer1_ContactDown(object sender, EventArgs e)
        {
            
            if (!isCreatedP1)
            {
                UserControlListVideo ListVideo1 = new UserControlListVideo();
                ListVideo1.Name = "ListVideo1";
                Grid1.Children.Add(ListVideo1);
                ListVideo1.EH_ItemVideo1_ContactDown += new System.EventHandler(this.ListVideo1_EH_ItemVideo1_ContactDown);
                ListVideo1.EH_ItemVideo2_ContactDown += new System.EventHandler(this.ListVideo1_EH_ItemVideo2_ContactDown);
                /*
                UserControlUserPanel UserPanel1 = new UserControlUserPanel();
                UserPanel1.Name = "UserPanel1";
                Grid1.Children.Add(UserPanel1);
                isCreatedP1 = true;*/
            }            
        }

        private void UserControlPivot_EH_SurfaceButtonPlayer2_ContactDown(object sender, EventArgs e)
        {
            if (!isCreatedP2)
            {
                UserControlUserPanel UserPanel2 = new UserControlUserPanel();
                UserPanel2.Name = "UserPanel2";
                Grid2.Children.Add(UserPanel2);
                isCreatedP2 = true;
            } 
        }

        private void UserControlPivot_EH_SurfaceButtonPlayer3_ContactDown(object sender, EventArgs e)
        {
            if (!isCreatedP3)
            {
                UserControlUserPanel UserPanel3 = new UserControlUserPanel();
                UserPanel3.Name = "UserPanel3";
                Grid3.Children.Add(UserPanel3);
                isCreatedP3 = true;
            } 
        }

        private void UserControlPivot_EH_SurfaceButtonPlayer4_ContactDown(object sender, EventArgs e)
        {
            if (!isCreatedP4)
            {
                UserControlUserPanel UserPanel4 = new UserControlUserPanel();
                UserPanel4.Name = "UserPanel4";
                Grid4.Children.Add(UserPanel4);
                isCreatedP4 = true;
            } 
        }

        private void ListVideo1_EH_ItemVideo1_ContactDown(object sender, EventArgs e)
        {
            //Creation d'une nouvelle seance.
            if (!isCreatedP1)
            {
                //
                UserControlUserPanel UserPanel1 = new UserControlUserPanel();
                UserPanel1.Name = "UserPanel1";
                UserControlSessionInput SessionInput = new UserControlSessionInput();
                SessionInput.Name = "SessionInput";
                try{
                    Grid actualGrid = (Grid)(((UserControlListVideo)sender).Parent);
                    actualGrid.Children.Add(UserPanel1);
                    actualGrid.Children.Add(SessionInput);
                    actualGrid.Children.Remove((UserControlListVideo)sender);
                }
                catch (Exception ex) { }

                //ActualGrid.Children.Add(UserPanel1);
                isCreatedP1 = true;
            }
        }

        private void ListVideo1_EH_ItemVideo2_ContactDown(object sender, EventArgs e)
        {
            //Creation d'une nouvelle seance.
            UserControlSessionInput SessionInput = new UserControlSessionInput();

            UserControlUserPanel UserPanel1 = new UserControlUserPanel();
            UserPanel1.Name = "UserPanel1";
            //ActualGrid.Children.Add(UserPanel1);
            isCreatedP1 = true;
        }
    }
}