src/FingersDance.GestureControl/GestureControl.cs
changeset 178 56041bd3761e
parent 176 0896f36b9d57
child 189 b37888f59cf2
equal deleted inserted replaced
177:89cbcb52b674 178:56041bd3761e
   108             this.angle = c.Contact.GetOrientation(this) - 270;
   108             this.angle = c.Contact.GetOrientation(this) - 270;
   109         }
   109         }
   110 
   110 
   111         protected void AreaStrokeCollected(object source, RoutedEventArgs e)
   111         protected void AreaStrokeCollected(object source, RoutedEventArgs e)
   112         {
   112         {
   113             if (inProgess == null)
   113             try
   114             {
   114             {
   115                 inProgess = new Thread(RunCapture);
   115                 if (inProgess == null)
   116                 inProgess.Start();
   116                 {
   117             }
   117                     inProgess = new Thread(RunCapture);
   118             else
   118                     inProgess.Start();
   119             {
   119                 }
   120                 inProgess.Abort();
   120                 else
   121                 inProgess = null;
   121                 {
   122                 inProgess = new Thread(RunCapture);
   122                     inProgess.Abort();
   123                 inProgess.Start();
   123                     inProgess = null;
   124             }
   124                     inProgess = new Thread(RunCapture);
   125             Debug.WriteLine("collected", "Stroke");
   125                     inProgess.Start();
   126             System.Windows.Controls.InkCanvasStrokeCollectedEventArgs tmp = e as System.Windows.Controls.InkCanvasStrokeCollectedEventArgs;
   126                 }
   127             // Apply a rotation with the angle of the first contact
   127                 Debug.WriteLine("collected", "Stroke");
   128             Matrix rot = Matrix.Identity;
   128                 System.Windows.Controls.InkCanvasStrokeCollectedEventArgs tmp = e as System.Windows.Controls.InkCanvasStrokeCollectedEventArgs;
   129             rot.Rotate(-this.angle);
   129                 // Apply a rotation with the angle of the first contact
   130             Stroke s = tmp.Stroke;
   130                 Matrix rot = Matrix.Identity;
   131             s.Transform(rot, true);
   131                 rot.Rotate(-this.angle);
   132             // Get a list of point from a Bezier curve
   132                 Stroke s = tmp.Stroke;
   133             StylusPointCollection tmp2 = s.GetBezierStylusPoints();
   133                 s.Transform(rot, true);
   134             // Generate a list of SurfaceGesturePoint, just X and Y but can be improve
   134                 // Get a list of point from a Bezier curve
   135             List<SurfaceGesturePoint> pointList = new List<SurfaceGesturePoint>();
   135                 StylusPointCollection tmp2 = s.GetBezierStylusPoints();
   136             foreach (StylusPoint p in tmp2)
   136                 // Generate a list of SurfaceGesturePoint, just X and Y but can be improve
   137                 pointList.Add(new SurfaceGesturePoint { X = p.X, Y = p.Y });
   137                 List<SurfaceGesturePoint> pointList = new List<SurfaceGesturePoint>();
   138             // create the gesture analyser and set the list
   138                 foreach (StylusPoint p in tmp2)
   139             SurfaceGesture gesture = new SurfaceGesture(pointList, 1);
   139                     pointList.Add(new SurfaceGesturePoint { X = p.X, Y = p.Y });
   140             // try to get a pattern from the list, if one, raise a event
   140                 // create the gesture analyser and set the list
   141             _Gestures.Add(gesture);
   141                 SurfaceGesture gesture = new SurfaceGesture(pointList, 1);
   142             SurfaceInkCanvas ink = e.OriginalSource as SurfaceInkCanvas;
   142                 // try to get a pattern from the list, if one, raise a event
   143             ink.Strokes.Clear();
   143                 _Gestures.Add(gesture);
       
   144                 SurfaceInkCanvas ink = e.OriginalSource as SurfaceInkCanvas;
       
   145                 ink.Strokes.Clear();
       
   146             }
       
   147             catch { }
   144         }
   148         }
   145 
   149 
   146         void RunCapture()
   150         void RunCapture()
   147         {
   151         {
   148             try
   152             try