Example #1
0
 private void OnStylusStuff(object sender, StylusEventArgs args)
 {
     if (args.RoutedEvent == UIElement.PreviewStylusUpEvent ||
         (args.RoutedEvent == UIElement.PreviewStylusDownEvent && args.Source == null) ||
         (args.RoutedEvent == UIElement.PreviewStylusMoveEvent && args.Source == null && args.InAir))
     {
         _pts.Remove(args.StylusDevice.Id);
         MultitouchWindow.ClearPhysicalReferenceFrame(args.StylusDevice);
         MultitouchWindow.RemoveStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
         _processor.ProcessUp((uint)args.StylusDevice.Id, ToDrawingPointF(args.GetPosition(_attachedElement)));
     }
     else if (args.RoutedEvent == UIElement.PreviewStylusDownEvent)
     {
         System.Windows.Point pt = args.GetPosition(_attachedElement);
         _pts.Add(args.StylusDevice.Id, pt);
         MultitouchWindow.PushPhysicalReferenceFrame(args.StylusDevice, this);
         MultitouchWindow.AddStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
         _processor.ProcessDown((uint)args.StylusDevice.Id, ToDrawingPointF(pt));
     }
     else if (args.RoutedEvent == UIElement.PreviewStylusMoveEvent)
     {
         if (!_pts.ContainsKey(-1))
         {
             return;
         }
         //_processor.ProcessMove((uint)args.StylusDevice.Id, ToDrawingPointF(args.GetPosition(_attachedElement)));
     }
 }
Example #2
0
        protected override void OnAttached()
        {
            base.OnAttached();

            attachedElement = (ScrollViewer)this.AssociatedObject;

            attachedElement.PreviewStylusDown += (s, e) =>
            {
                MultitouchWindow.SafeCaptureStylus(e.StylusDevice, attachedElement);
                _processor.ProcessDown((uint)e.StylusDevice.Id, ToDrawingPointF(e.GetPosition(attachedElement)));
            };
            attachedElement.PreviewStylusUp += (s, e) =>
            {
                MultitouchWindow.SafeCaptureStylus(e.StylusDevice, null);
                _processor.ProcessUp((uint)e.StylusDevice.Id, ToDrawingPointF(e.GetPosition(attachedElement)));
            };
            attachedElement.PreviewStylusMove += (s, e) =>
            {
                _processor.ProcessMove((uint)e.StylusDevice.Id, ToDrawingPointF(e.GetPosition(attachedElement)));
            };

            attachedElement.PreviewMouseDown += (s, e) =>
            {
                MultitouchWindow.SafeCaptureMouse(attachedElement);
                _processor.ProcessDown((uint)1 << 31, ToDrawingPointF(e.GetPosition(attachedElement)));
            };
            attachedElement.PreviewMouseUp += (s, e) =>
            {
                MultitouchWindow.SafeCaptureMouse(null);
                _processor.ProcessUp((uint)1 << 31, ToDrawingPointF(e.GetPosition(attachedElement)));
            };
            attachedElement.PreviewMouseMove += (s, e) =>
            {
                _processor.ProcessMove((uint)1 << 31, ToDrawingPointF(e.GetPosition(attachedElement)));
            };

            //Handle the ManipulationDelta and the gestures
            _processor.ManipulationDelta += ProcessManipulationDelta;
            _processor.PivotRadius        = 2;
        }