src/FingersDance/MainSurfaceWindow.xaml.cs
changeset 143 9f157d9c725b
parent 119 7a370bfb4d77
child 146 dd8ed4d3beb6
equal deleted inserted replaced
142:3d66ca73df55 143:9f157d9c725b
    15 using Microsoft.Surface.Presentation;
    15 using Microsoft.Surface.Presentation;
    16 using Microsoft.Surface.Presentation.Controls;
    16 using Microsoft.Surface.Presentation.Controls;
    17 
    17 
    18 using FingersDance.Control.UserPanel;
    18 using FingersDance.Control.UserPanel;
    19 using FingersDance.Control.Screen;
    19 using FingersDance.Control.Screen;
       
    20 using FingersDance.Control.Close;
       
    21 using FingersDance.ViewModels;
       
    22 using FingersDance.Data;
    20 
    23 
    21 
    24 
    22 namespace FingersDance
    25 namespace FingersDance
    23 {
    26 {
    24     /// <summary>
    27     /// <summary>
    29         /// <summary>
    32         /// <summary>
    30         /// Default constructor.
    33         /// Default constructor.
    31         /// </summary>
    34         /// </summary>
    32         /// 
    35         /// 
    33         #region Variables
    36         #region Variables
       
    37 
    34         private UserControlUserPanel Panel1 = null;
    38         private UserControlUserPanel Panel1 = null;
    35         private UserControlUserPanel Panel2 = null;
    39         private UserControlUserPanel Panel2 = null;
    36         private UserControlUserPanel Panel3 = null;
    40         private UserControlUserPanel Panel3 = null;
    37         private UserControlUserPanel Panel4 = null;
    41         private UserControlUserPanel Panel4 = null;
       
    42         ActionFactory.ActionGenerator _Factory = new FingersDance.ActionFactory.ActionFactory().GetGenerator();
       
    43         private MainViewModel _mainviewmodel = new MainViewModel();      
       
    44 
    38         #endregion
    45         #endregion
    39 
    46 
    40         ActionFactory.ActionGenerator _Factory = new FingersDance.ActionFactory.ActionFactory().GetGenerator();
    47 
    41 
    48         #region Constructor
    42         public SurfaceWindow1()
    49         public SurfaceWindow1()
    43         {
    50         {
    44             InitializeComponent();
    51             InitializeComponent();
    45 
    52 
    46             //Permet d'initialiser l'inertie du Pivot une fois relaché.
    53             //Permet d'initialiser l'inertie du Pivot une fois relaché.
    48             //Permet d'initialiser les quand Grid à la position initiale du pivot
    55             //Permet d'initialiser les quand Grid à la position initiale du pivot
    49             InitGridPositions();
    56             InitGridPositions();
    50             // Add handlers for Application activation events
    57             // Add handlers for Application activation events
    51             AddActivationHandlers();
    58             AddActivationHandlers();
    52         }
    59         }
       
    60         #endregion
       
    61 
       
    62         #region Initialization
    53 
    63 
    54         private void InitPivotInertia()
    64         private void InitPivotInertia()
    55         {
    65         {
    56             try
    66             try
    57             {
    67             {
    80                 Grid4.Height = item.Center.Y;
    90                 Grid4.Height = item.Center.Y;
    81             }
    91             }
    82             catch (Exception ex) { }
    92             catch (Exception ex) { }
    83         }
    93         }
    84 
    94 
       
    95         #endregion
    85 
    96 
    86         /// <summary>
    97         /// <summary>
    87         /// Occurs when the window is about to close. 
    98         /// Occurs when the window is about to close. 
    88         /// </summary>
    99         /// </summary>
    89         /// <param name="e"></param>
   100         /// <param name="e"></param>
   123         /// <param name="sender"></param>
   134         /// <param name="sender"></param>
   124         /// <param name="e"></param>
   135         /// <param name="e"></param>
   125         private void OnApplicationActivated(object sender, EventArgs e)
   136         private void OnApplicationActivated(object sender, EventArgs e)
   126         {
   137         {
   127             //TODO: enable audio, animations here
   138             //TODO: enable audio, animations here
       
   139 
   128         }
   140         }
   129 
   141 
   130         /// <summary>
   142         /// <summary>
   131         /// This is called when application is in preview mode.
   143         /// This is called when application is in preview mode.
   132         /// </summary>
   144         /// </summary>
   147         private void OnApplicationDeactivated(object sender, EventArgs e)
   159         private void OnApplicationDeactivated(object sender, EventArgs e)
   148         {
   160         {
   149             //TODO: disable audio, animations here
   161             //TODO: disable audio, animations here
   150         }
   162         }
   151 
   163 
       
   164         /// <summary>
       
   165         ///  This is called when application has been loaded, we change the orientation
       
   166         ///  of the application
       
   167         /// </summary>
       
   168         /// <param name="sender"></param>
       
   169         /// <param name="e"></param>
       
   170         private void mainSurfaceWindow_Loaded(object sender, RoutedEventArgs e)
       
   171         {
       
   172 
       
   173             if (ApplicationLauncher.InitialOrientation == UserOrientation.Top)
       
   174             {
       
   175                 // Rotate the main canvas by 180 degrees.
       
   176                 this.MainGrid.LayoutTransform = new RotateTransform(180.0);
       
   177             }
       
   178             else
       
   179             {
       
   180                 // Remove the rotate transform on the main canvas.
       
   181                 this.MainGrid.LayoutTransform = null;
       
   182             }
       
   183             // Dismiss the loading screen.
       
   184             ApplicationLauncher.SignalApplicationLoadComplete();
       
   185         }
       
   186 
   152         private void scaterview_ContactChanged(object sender, ContactEventArgs e)
   187         private void scaterview_ContactChanged(object sender, ContactEventArgs e)
   153         {  }
   188         {  }
   154 
   189 
   155         private void ScatterViewItemPivot_ContactChanged(object sender, ContactEventArgs e)
   190         private void ScatterViewItemPivot_ContactChanged(object sender, ContactEventArgs e)
   156         {
   191         {
   226             catch (Exception) { }
   261             catch (Exception) { }
   227         }
   262         }
   228 
   263 
   229         private void UserControlPivot_EH_SurfaceButtonPlayer_ContactDown(object sender, EventArgs e)
   264         private void UserControlPivot_EH_SurfaceButtonPlayer_ContactDown(object sender, EventArgs e)
   230         {
   265         {
       
   266             //  Si aucune video n'a été sélectionnée et qu'une grid contient un élément (listvideo), on ne fait rien
       
   267             if (_mainviewmodel.Session.VideoPath.Equals("") && (Grid1.Children.Count == 2 || Grid2.Children.Count == 2 || Grid3.Children.Count == 2 || Grid4.Children.Count == 2))
       
   268                 return;
       
   269 
       
   270             //  Traitement du contact down sur le pivot (Création d'un screen ou suppression d'un panel
   231             switch ((int)sender)
   271             switch ((int)sender)
   232             {
   272             {
   233                 case 1:
   273                 case 1:
   234                     if (Panel1 == null)
   274                     if (Panel1 == null && Grid1.Children.Count == 1)
   235                     {
   275                     {
   236                         //1-Creation du control Screen
   276                         //1-Creation du control Screen
   237                         UserControlScreen Screen = new UserControlScreen(1);
   277                         UserControlScreen Screen = new UserControlScreen(1, _mainviewmodel);
   238                         Screen.Name = "Screen1";
   278                         Screen.Name = "Screen1";
   239                         Screen.contexteGrid = Grid1.Name.ToString();
   279                         Screen.contexteGrid = Grid1.Name.ToString();
   240                         //2-Rajout du screen dans la grid correspondante
   280                         //2-Rajout du screen dans la grid correspondante
   241                         Grid1.Children.Add(Screen);
   281                         Grid1.Children.Add(Screen);
   242 
   282 
   243                         Screen.UC_Screen_NewSession += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   283                         Screen.UC_Screen_NewSession += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   244                     }
   284                     }
       
   285                     else //Affichage du message de confirmation
       
   286                     {
       
   287                         if (Panel1 != null && Grid1.Children.Count == 2)
       
   288                         {
       
   289                             UserControlClose UCclose = new UserControlClose(1);
       
   290                             UCclose.Name = "CloseAlert1";
       
   291                             Grid1.Children.Add(UCclose);
       
   292                             UCclose.EH_SurfaceButtonClose_ContactDown += new EventHandler(CloseAlert_EH_SurfaceButton_ContactDown);
       
   293                         }
       
   294                     }
   245                     break;
   295                     break;
   246                 case 2:
   296                 case 2:
   247                     if (Panel2 == null)
   297                     if (Panel2 == null && Grid2.Children.Count == 1)
   248                     {
   298                     {
   249                         //1-Creation du control Screen
   299                         //1-Creation du control Screen
   250                         UserControlScreen Screen = new UserControlScreen(2);
   300                         UserControlScreen Screen = new UserControlScreen(2, _mainviewmodel);
   251                         Screen.Name = "Screen2";
   301                         Screen.Name = "Screen2";
   252                         Screen.contexteGrid = Grid2.Name.ToString();
   302                         Screen.contexteGrid = Grid2.Name.ToString();
   253                         //2-Rajout du screen dans la grid correspondante
   303                         //2-Rajout du screen dans la grid correspondante
   254                         Grid2.Children.Add(Screen);
   304                         Grid2.Children.Add(Screen);
   255 
   305 
   256                         Screen.UC_Screen_NewSession += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   306                         Screen.UC_Screen_NewSession += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   257                     }
   307                     }
       
   308                     else //Affichage du message de confirmation
       
   309                     {
       
   310                         if (Panel2 != null && Grid2.Children.Count == 2)
       
   311                         {
       
   312                             UserControlClose UCclose = new UserControlClose(2);
       
   313                             UCclose.Name = "CloseAlert2";
       
   314                             Grid2.Children.Add(UCclose);
       
   315                             UCclose.EH_SurfaceButtonClose_ContactDown += new EventHandler(CloseAlert_EH_SurfaceButton_ContactDown);
       
   316                         }
       
   317                     }
   258                     break;
   318                     break;
   259                 case 3:
   319                 case 3:
   260                     if (Panel3 == null)
   320                     if (Panel3 == null && Grid3.Children.Count == 1)
   261                     {
   321                     {
   262                         //1-Creation du control Screen
   322                         //1-Creation du control Screen
   263                         UserControlScreen Screen = new UserControlScreen(3);
   323                         UserControlScreen Screen = new UserControlScreen(3, _mainviewmodel);
   264                         Screen.Name = "Screen3";
   324                         Screen.Name = "Screen3";
   265                         Screen.contexteGrid = Grid3.Name.ToString();
   325                         Screen.contexteGrid = Grid3.Name.ToString();
   266                         //2-Rajout du screen dans la grid correspondante
   326                         //2-Rajout du screen dans la grid correspondante
   267                         Grid3.Children.Add(Screen);
   327                         Grid3.Children.Add(Screen);
   268 
   328 
   269                         Screen.UC_Screen_NewSession += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   329                         Screen.UC_Screen_NewSession += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   270                     }
   330                     }
       
   331                     else //Affichage du message de confirmation
       
   332                     {
       
   333                         if (Panel3 != null && Grid3.Children.Count == 2)
       
   334                         {
       
   335                             UserControlClose UCclose = new UserControlClose(3);
       
   336                             UCclose.Name = "CloseAlert3";
       
   337                             Grid3.Children.Add(UCclose);
       
   338                             UCclose.EH_SurfaceButtonClose_ContactDown += new EventHandler(CloseAlert_EH_SurfaceButton_ContactDown);
       
   339                         }
       
   340                     }
   271                     break;
   341                     break;
   272                 case 4:
   342                 case 4:
   273                     if (Panel4 == null)
   343                     if (Panel4 == null && Grid4.Children.Count == 1)
   274                     {
   344                     {
   275                         //1-Creation du control Screen
   345                         //1-Creation du control Screen
   276                         UserControlScreen Screen = new UserControlScreen(4);
   346                         UserControlScreen Screen = new UserControlScreen(4, _mainviewmodel);
   277                         Screen.Name = "Screen4";
   347                         Screen.Name = "Screen4";
   278                         Screen.contexteGrid = Grid4.Name.ToString();
   348                         Screen.contexteGrid = Grid4.Name.ToString();
   279                         //2-Rajout du screen dans la grid correspondante
   349                         //2-Rajout du screen dans la grid correspondante
   280                         Grid4.Children.Add(Screen);
   350                         Grid4.Children.Add(Screen);
   281 
   351 
   282                         Screen.UC_Screen_NewSession += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   352                         Screen.UC_Screen_NewSession += new System.EventHandler(this.SessionInput_EH_SurfaceButtonSubmit_ContactDown);
   283                     }
   353                     }
       
   354                     else //Affichage du message de confirmation
       
   355                     {
       
   356                         if (Panel4 != null && Grid4.Children.Count == 2)
       
   357                         {
       
   358                             UserControlClose UCclose = new UserControlClose(4);
       
   359                             UCclose.Name = "CloseAlert4";
       
   360                             Grid4.Children.Add(UCclose);
       
   361                             UCclose.EH_SurfaceButtonClose_ContactDown += new EventHandler(CloseAlert_EH_SurfaceButton_ContactDown);
       
   362                         }
       
   363                     }
   284                     break;
   364                     break;
   285             }
   365             }
   286                         
   366                         
   287         }
   367         }
   288 
   368 
   293             {
   373             {
   294                 //1-Suppression du UC Screen
   374                 //1-Suppression du UC Screen
   295                 Grid root = (Grid)(((UserControlScreen)sender).Parent);
   375                 Grid root = (Grid)(((UserControlScreen)sender).Parent);
   296                 root.Children.Remove(((UserControlScreen)sender));
   376                 root.Children.Remove(((UserControlScreen)sender));
   297                 //2-Creation du User Panel
   377                 //2-Creation du User Panel
       
   378                 Project newProject = _mainviewmodel.CreateProject(((UserControlScreen)sender).User);
       
   379 
       
   380                 if ((Panel1 != null && Panel1.Project.Equals(newProject)) || (Panel2 != null && Panel2.Project.Equals(newProject)) || (Panel3 != null && Panel3.Project.Equals(newProject)) || (Panel4 != null && Panel4.Project.Equals(newProject)))
       
   381                     return;
       
   382 
   298                 switch (((UserControlScreen)sender).id)
   383                 switch (((UserControlScreen)sender).id)
   299                 {
   384                 {
   300                     case 1:
   385                     case 1:
   301                         Panel1 = new UserControlUserPanel(((UserControlScreen)sender).Path);
   386                         Panel1 = new UserControlUserPanel(newProject, _mainviewmodel.Session.VideoPath);
   302                         Panel1.Name = "UserPanel1";
   387                         Panel1.Name = "UserPanel1";
   303                         //3-Rajout sur la Grid Root
   388                         //3-Rajout sur la Grid Root
   304                         root.Children.Add(Panel1);
   389                         root.Children.Add(Panel1);
   305                         break;
   390                         break;
   306                     case 2:
   391                     case 2:
   307                         Panel2 = new UserControlUserPanel(((UserControlScreen)sender).Path);
   392                         Panel2 = new UserControlUserPanel(newProject, _mainviewmodel.Session.VideoPath);
   308                         Panel2.Name = "UserPanel2";
   393                         Panel2.Name = "UserPanel2";
   309                         //3-Rajout sur la Grid Root
   394                         //3-Rajout sur la Grid Root
   310                         root.Children.Add(Panel2);
   395                         root.Children.Add(Panel2);
   311                         break;
   396                         break;
   312                     case 3:
   397                     case 3:
   313                         Panel3 = new UserControlUserPanel(((UserControlScreen)sender).Path);
   398                         Panel3 = new UserControlUserPanel(newProject, _mainviewmodel.Session.VideoPath);
   314                         Panel3.Name = "UserPanel3";
   399                         Panel3.Name = "UserPanel3";
   315                         //3-Rajout sur la Grid Root
   400                         //3-Rajout sur la Grid Root
   316                         root.Children.Add(Panel3);
   401                         root.Children.Add(Panel3);
   317                         break;
   402                         break;
   318                     case 4:
   403                     case 4:
   319                         Panel4 = new UserControlUserPanel(((UserControlScreen)sender).Path);
   404                         Panel4 = new UserControlUserPanel(newProject, _mainviewmodel.Session.VideoPath);
   320                         Panel4.Name = "UserPanel4";
   405                         Panel4.Name = "UserPanel4";
   321                         //3-Rajout sur la Grid Root
   406                         //3-Rajout sur la Grid Root
   322                         root.Children.Add(Panel4);
   407                         root.Children.Add(Panel4);
   323                         break;
   408                         break;
   324                 }
   409                 }
   325             }
   410             }
   326             catch (Exception ex) { }
   411             catch (Exception ex) { }
   327         }
   412         }
   328 
   413 
   329 
   414         //Actions du boutton Alert selon l'action close OK ou NON
       
   415         private void CloseAlert_EH_SurfaceButton_ContactDown(object sender, EventArgs e)
       
   416         {
       
   417             Grid root = (Grid)(((UserControlClose)sender).Parent);
       
   418             if(((UserControlClose) sender).close)
       
   419             {
       
   420                 switch(((UserControlClose)sender).Id)
       
   421                 {
       
   422                     case 1:
       
   423                         root.Children.Remove(Panel1);
       
   424                         Panel1 = null;
       
   425                         break;
       
   426                     case 2:
       
   427                         root.Children.Remove(Panel2);
       
   428                         Panel2 = null;
       
   429                         break;
       
   430                     case 3:
       
   431                         root.Children.Remove(Panel3);
       
   432                         Panel3 = null;
       
   433                         break;
       
   434                     case 4:
       
   435                         root.Children.Remove(Panel4);
       
   436                         Panel4 = null;
       
   437                         break;
       
   438                 }
       
   439             }
       
   440             root.Children.Remove(((UserControlClose)sender));
       
   441 
       
   442             //  S'il ne reste aucun panel d'ouvert, on ferme la session
       
   443             if (Panel1 == null && Panel2 == null && Panel3 == null && Panel4 == null)
       
   444                 _mainviewmodel.CloseSession();
       
   445         }
   330 
   446 
   331     }
   447     }
   332 }
   448 }