Jypeli  5
The simple game programming library
TouchPanelState.cs
Siirry tämän tiedoston dokumentaatioon.
1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 
6 #if WINDOWS_PHONE
7 using Microsoft.Xna.Framework.Input.Touch;
8 using Microsoft.Xna.Framework;
9 #endif
10 
11 namespace Jypeli.WP7
12 {
13  public class TouchPanelState
14  {
18  public List<Touch> ActiveTouches;
19 
23  public List<Gesture> ActiveGestures;
24 
25 #if WINDOWS_PHONE
26  internal List<GestureSample> samples = new List<GestureSample>();
27 #endif
28 
29  public TouchPanelState()
30  {
31  ActiveTouches = new List<Touch>( 5 );
32  ActiveGestures = new List<Gesture>( 5 );
33  }
34 
35  internal Touch GetObjectByChannel( int channel )
36  {
37  // TODO: Specific gesture handlers
38  Touch touch;
39  int touches = ActiveTouches.Count;
40 
41  if ( channel >= touches )
42  {
43  // Gesture
44  return ActiveGestures[channel - touches];
45  }
46 
47  // Normal touch
48  return ActiveTouches[channel];
49  }
50 
51 #if WINDOWS_PHONE
52  public TouchPanelState( TouchCollection touchCollection, List<GestureSample> samples, TouchPanelState prevState )
53  {
54  ActiveTouches = new List<Touch>();
55  ActiveGestures = new List<Gesture>( 5 );
56  this.samples = samples;
57 
58  for ( int i = 0; i < touchCollection.Count; i++ )
59  {
60  GetTouchObject( touchCollection[i], prevState );
61  }
62 
63  for ( int i = 0; i < samples.Count; i++ )
64  {
65  GetGestureObject( samples[i] );
66  }
67  }
68 
69  private Touch GetGestureObject( GestureSample gestureSample )
70  {
71  Gesture gesture = new Gesture( gestureSample.Position, gestureSample.Delta, gestureSample.Position2, gestureSample.Delta2 );
72  ActiveGestures.Add( gesture );
73  return gesture;
74  }
75 
76  private Touch GetTouchObject( TouchLocation location, TouchPanelState prevState )
77  {
78  Touch touch = null;
79 
80  for ( int i = 0; i < prevState.ActiveTouches.Count; i++ )
81  {
82  if ( location.Id == prevState.ActiveTouches[i].Id )
83  {
84  touch = prevState.ActiveTouches[i];
85  touch.Update( location.Position, location.State );
86 
87  ActiveTouches.Add( touch );
88  return touch;
89  }
90  }
91 
92  touch = new Touch( location.Id, location.Position, location.State );
93  ActiveTouches.Add( touch );
94 
95  return touch;
96  }
97 #endif
98  }
99 }
List< Gesture > ActiveGestures
Aktiiviset eleet ruudulla
Kosketuspaneelin kosketus.
Definition: Touch.cs:16
List< Touch > ActiveTouches
Aktiiviset kosketukset ruudulla