Resolution Inertie du Pivot.
authorsarias
Tue, 15 Sep 2009 16:57:45 +0200
changeset 60 b4008a356f90
parent 59 1043e7c13ffc
child 61 9e2f007b19b3
Resolution Inertie du Pivot. Creation des Events pour les bouttons du Pivot
src/FingersDance.Control.Pivot/UserControlPivot.xaml
src/FingersDance.Control.Pivot/UserControlPivot.xaml.cs
src/FingersDance/MainSurfaceWindow.xaml
src/FingersDance/MainSurfaceWindow.xaml.cs
--- a/src/FingersDance.Control.Pivot/UserControlPivot.xaml	Tue Sep 15 16:09:45 2009 +0200
+++ b/src/FingersDance.Control.Pivot/UserControlPivot.xaml	Tue Sep 15 16:57:45 2009 +0200
@@ -38,8 +38,8 @@
 				</RadialGradientBrush>
 			</Ellipse.Fill>
 		</Ellipse>
-		<Custom:SurfaceButton BorderThickness="0,0,0,0" HorizontalAlignment="Center" x:Name="SurfaceButtonPlayer1" VerticalAlignment="Center" Content="" Background="{DynamicResource Color_8_#230FD2_xaml}"/>
-		<Custom:SurfaceButton Content="" HorizontalAlignment="Center" x:Name="SurfaceButtonPlayer2" VerticalAlignment="Center" Grid.Column="1" RenderTransformOrigin="0.5,0.5" Background="{DynamicResource Color_4_#FF0000_xaml}">
+		<Custom:SurfaceButton BorderThickness="0,0,0,0" HorizontalAlignment="Center" x:Name="SurfaceButtonPlayer1" VerticalAlignment="Center" Content="" Background="{DynamicResource Color_8_#230FD2_xaml}" ContactDown="SurfaceButtonPlayer1_ContactDown" Click="SurfaceButtonPlayer1_Click"/>
+		<Custom:SurfaceButton Content="" HorizontalAlignment="Center" x:Name="SurfaceButtonPlayer2" VerticalAlignment="Center" Grid.Column="1" RenderTransformOrigin="0.5,0.5" Background="{DynamicResource Color_4_#FF0000_xaml}" ContactDown="SurfaceButtonPlayer2_ContactDown" Click="SurfaceButtonPlayer2_Click">
 			<Custom:SurfaceButton.RenderTransform>
 				<TransformGroup>
 					<ScaleTransform ScaleX="-1" ScaleY="1"/>
@@ -49,7 +49,7 @@
 				</TransformGroup>
 			</Custom:SurfaceButton.RenderTransform>
 		</Custom:SurfaceButton>
-		<Custom:SurfaceButton Content="" HorizontalAlignment="Center" x:Name="SurfaceButtonPlayer3" VerticalAlignment="Center" Grid.Row="1" RenderTransformOrigin="0.5,0.5" Background="{DynamicResource Color_12_#00C800_xaml}" >
+		<Custom:SurfaceButton Content="" HorizontalAlignment="Center" x:Name="SurfaceButtonPlayer3" VerticalAlignment="Center" Grid.Row="1" RenderTransformOrigin="0.5,0.5" Background="{DynamicResource Color_12_#00C800_xaml}" ContactDown="SurfaceButtonPlayer3_ContactDown" Click="SurfaceButtonPlayer3_Click" >
 			<Custom:SurfaceButton.RenderTransform>
 				<TransformGroup>
 					<ScaleTransform ScaleX="1" ScaleY="-1"/>
@@ -59,7 +59,7 @@
 				</TransformGroup>
 			</Custom:SurfaceButton.RenderTransform>
 		</Custom:SurfaceButton>
-		<Custom:SurfaceButton Content=""  Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="SurfaceButtonPlayer4" RenderTransformOrigin="0.5,0.5" Background="{DynamicResource Color_2_#FFC800_xaml}">
+		<Custom:SurfaceButton Content=""  Grid.Row="1" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" x:Name="SurfaceButtonPlayer4" RenderTransformOrigin="0.5,0.5" Background="{DynamicResource Color_2_#FFC800_xaml}" ContactDown="SurfaceButtonPlayer4_ContactDown" Click="SurfaceButtonPlayer4_Click">
 			<Custom:SurfaceButton.RenderTransform>
 				<TransformGroup>
 					<ScaleTransform ScaleX="-1" ScaleY="-1"/>
--- a/src/FingersDance.Control.Pivot/UserControlPivot.xaml.cs	Tue Sep 15 16:09:45 2009 +0200
+++ b/src/FingersDance.Control.Pivot/UserControlPivot.xaml.cs	Tue Sep 15 16:57:45 2009 +0200
@@ -12,11 +12,60 @@
 {
 	public partial class UserControlPivot
 	{
+        public event EventHandler EH_SurfaceButtonPlayer1_ContactDown;
+        public event EventHandler EH_SurfaceButtonPlayer2_ContactDown;
+        public event EventHandler EH_SurfaceButtonPlayer3_ContactDown;
+        public event EventHandler EH_SurfaceButtonPlayer4_ContactDown;
+
 		public UserControlPivot()
 		{
 			this.InitializeComponent();
 
 			// Insert code required on object creation below this point.
 		}
+
+        private void SurfaceButtonPlayer1_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
+        {
+            if(EH_SurfaceButtonPlayer1_ContactDown!=null)
+                EH_SurfaceButtonPlayer1_ContactDown(this, new EventArgs());
+        }
+
+        private void SurfaceButtonPlayer2_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
+        {
+            if (EH_SurfaceButtonPlayer2_ContactDown != null)
+                EH_SurfaceButtonPlayer2_ContactDown(this, new EventArgs());
+        }
+
+        private void SurfaceButtonPlayer3_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
+        {
+            if (EH_SurfaceButtonPlayer3_ContactDown != null)
+                EH_SurfaceButtonPlayer3_ContactDown(this, new EventArgs());
+        }
+
+        private void SurfaceButtonPlayer4_ContactDown(object sender, Microsoft.Surface.Presentation.ContactEventArgs e)
+        {
+            if (EH_SurfaceButtonPlayer4_ContactDown != null)
+                EH_SurfaceButtonPlayer4_ContactDown(this, new EventArgs());
+        }
+
+        private void SurfaceButtonPlayer1_Click(object sender, RoutedEventArgs e)
+        {
+            SurfaceButtonPlayer1_ContactDown(this,null);
+        }
+
+        private void SurfaceButtonPlayer2_Click(object sender, RoutedEventArgs e)
+        {
+            SurfaceButtonPlayer2_ContactDown(this, null);
+        }
+
+        private void SurfaceButtonPlayer3_Click(object sender, RoutedEventArgs e)
+        {
+            SurfaceButtonPlayer3_ContactDown(this, null);
+        }
+
+        private void SurfaceButtonPlayer4_Click(object sender, RoutedEventArgs e)
+        {
+            SurfaceButtonPlayer4_ContactDown(this, null);
+        }
 	}
 }
\ No newline at end of file
--- a/src/FingersDance/MainSurfaceWindow.xaml	Tue Sep 15 16:09:45 2009 +0200
+++ b/src/FingersDance/MainSurfaceWindow.xaml	Tue Sep 15 16:57:45 2009 +0200
@@ -31,10 +31,10 @@
   				<TranslateTransform X="0" Y="0"/>
   			</TransformGroup>
   		</Grid.RenderTransform>
-  		<FingersDance_Control_UserPanel:UserControlUserPanel/>
+  		
   		<Rectangle Fill="{x:Null}" Stroke="#FFFFFFFF"/>
   	</Grid>
-  	<Grid HorizontalAlignment="Right" Margin="0,0,0,0" x:Name="Grid4" VerticalAlignment="Top" Width="100" Height="100" Background="{x:Null}" RenderTransformOrigin="0.5,0.5">
+  	<Grid HorizontalAlignment="Right" Margin="0,0,0,0" x:Name="Grid2" VerticalAlignment="Top" Width="100" Height="100" Background="{x:Null}" RenderTransformOrigin="0.5,0.5">
   		<Grid.RenderTransform>
   			<TransformGroup>
   				<ScaleTransform ScaleX="-1" ScaleY="-1"/>
@@ -43,14 +43,10 @@
   				<TranslateTransform X="0" Y="0"/>
   			</TransformGroup>
   		</Grid.RenderTransform>
-  		<FingersDance_Control_UserPanel:UserControlUserPanel/>
+  		
   		<Rectangle Fill="{x:Null}" Stroke="#FFFFFFFF"/>
   	</Grid>
-  	<Grid HorizontalAlignment="Right" Margin="0,0,0,0" x:Name="Grid3" VerticalAlignment="Bottom" Width="100" Height="100" Background="{x:Null}">
-  		<FingersDance_Control_UserPanel:UserControlUserPanel/>
-  		<Rectangle Fill="{x:Null}" Stroke="#FFFFFFFF"/>
-  	</Grid>
-  	<Grid RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="Grid2" VerticalAlignment="Bottom" Width="100" Height="100" Background="{x:Null}">
+  	<Grid RenderTransformOrigin="0.5,0.5" HorizontalAlignment="Left" Margin="0,0,0,0" x:Name="Grid3" VerticalAlignment="Bottom" Width="100" Height="100" Background="{x:Null}">
   		<Grid.RenderTransform>
   			<TransformGroup>
   				<ScaleTransform ScaleX="1" ScaleY="1"/>
@@ -60,11 +56,15 @@
   			</TransformGroup>
   		</Grid.RenderTransform>
   		<Rectangle Fill="{x:Null}" Stroke="#FFFFFFFF"/>
-  		<FingersDance_Control_UserPanel:UserControlUserPanel/>
+  		
+  	</Grid>
+  	<Grid HorizontalAlignment="Right" Margin="0,0,0,0" x:Name="Grid4" VerticalAlignment="Bottom" Width="100" Height="100" Background="{x:Null}">
+  		
+  		<Rectangle Fill="{x:Null}" Stroke="#FFFFFFFF"/>
   	</Grid>
   	<s:ScatterView x:Name="ScaterView"  ContactChanged="ScaterView_ContactChanged">
-  		<s:ScatterViewItem  Center="512,384" CanMove="True" CanRotate="False" CanScale="False" Background="{x:Null}" x:Name="ScatterViewItemPivot" >
-  			<FingersDance_Control_Pivot:UserControlPivot x:Name="UserControlPivot"/>
+  		<s:ScatterViewItem   Center="512,384" CanMove="True" CanRotate="False" CanScale="False" Background="{x:Null}" x:Name="ScatterViewItemPivot" >
+  			<FingersDance_Control_Pivot:UserControlPivot x:Name="UserControlPivot" EH_SurfaceButtonPlayer1_ContactDown="UserControlPivot_EH_SurfaceButtonPlayer1_ContactDown" EH_SurfaceButtonPlayer2_ContactDown="UserControlPivot_EH_SurfaceButtonPlayer2_ContactDown" EH_SurfaceButtonPlayer3_ContactDown="UserControlPivot_EH_SurfaceButtonPlayer3_ContactDown" EH_SurfaceButtonPlayer4_ContactDown="UserControlPivot_EH_SurfaceButtonPlayer4_ContactDown"/>
   		</s:ScatterViewItem>
   	</s:ScatterView>
 
--- a/src/FingersDance/MainSurfaceWindow.xaml.cs	Tue Sep 15 16:09:45 2009 +0200
+++ b/src/FingersDance/MainSurfaceWindow.xaml.cs	Tue Sep 15 16:57:45 2009 +0200
@@ -15,6 +15,8 @@
 using Microsoft.Surface.Presentation;
 using Microsoft.Surface.Presentation.Controls;
 
+using FingersDance.Control.UserPanel;
+
 namespace FingersDance
 {
     /// <summary>
@@ -26,6 +28,12 @@
         /// 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();
 
@@ -33,12 +41,24 @@
         {
             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.   
@@ -135,16 +155,60 @@
                 Grid1.Width = e.GetPosition(mainSurfaceWindow).X;
                 Grid1.Height = e.GetPosition(mainSurfaceWindow).Y;
 
-                Grid2.Width = e.GetPosition(mainSurfaceWindow).X;
-                Grid2.Height = 768 - e.GetPosition(mainSurfaceWindow).Y;
-
-                Grid3.Width = 1024 - e.GetPosition(mainSurfaceWindow).X;
+                Grid3.Width = e.GetPosition(mainSurfaceWindow).X;
                 Grid3.Height = 768 - e.GetPosition(mainSurfaceWindow).Y;
 
                 Grid4.Width = 1024 - e.GetPosition(mainSurfaceWindow).X;
-                Grid4.Height = e.GetPosition(mainSurfaceWindow).Y;
+                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)
+            {
+                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;
+            } 
+        }
     }
 }
\ No newline at end of file