protected virtual void OnStylusStuff(object sender, StylusEventArgs args)
        {
            if (Container == null)
            {
                Container = AssociatedObject;
            }
            Point pt = args.GetPosition(Container);

            if (args.RoutedEvent == UIElement.PreviewStylusUpEvent ||
                (args.RoutedEvent == UIElement.PreviewStylusDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.PreviewStylusMoveEvent && args.Source == null && args.InAir))
            {
                MultitouchWindow.RemoveStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
                ProcessPointUp(args.StylusDevice.Id, pt);
            }
            else if (args.RoutedEvent == UIElement.PreviewStylusDownEvent)
            {
                MultitouchWindow.AddStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
                ProcessPointDown(args.StylusDevice.Id, pt);
            }
            else if (args.RoutedEvent == UIElement.PreviewStylusMoveEvent)
            {
                ProcessPointMove(args.StylusDevice.Id, pt);
            }
        }
Exemple #2
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))
            {
                MultitouchWindow.RemoveStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
            }
            else if (args.RoutedEvent == UIElement.PreviewStylusDownEvent)
            {
                MultitouchWindow.AddStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
                _pts[args.StylusDevice.Id] = new FlickData()
                {
                    DownPoint = args.GetPosition(_attachedElement)
                };
            }
            else if (args.RoutedEvent == UIElement.PreviewStylusMoveEvent)
            {
                if (!_pts.ContainsKey(args.StylusDevice.Id))
                {
                    return;
                }

                Point current = args.GetPosition(_attachedElement);

                FlickData data   = _pts[args.StylusDevice.Id];
                Vector    change = Point.Subtract(current, data.DownPoint);
                double    delta  = change.Length;

                if (data.BeginTime == 0 &&
                    delta > BeginThreshold)
                {
                    data.BeginTime = args.Timestamp;
                }

                if (data.BeginTime != 0 &&
                    delta > EndThreshold &&
                    (args.Timestamp - data.BeginTime) < RequiredFlickSpeed.TotalMilliseconds)
                {
                    MultitouchWindow.RemoveStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);

                    _pts.Remove(args.StylusDevice.Id);

                    FlickEventArgs fargs = new FlickEventArgs(change / delta);

                    if (Flick != null)
                    {
                        Flick(_attachedElement, fargs);
                    }
                    if (fargs.AlignedDirection.X != 0 && HorizontalFlick != null)
                    {
                        HorizontalFlick(_attachedElement, fargs);
                    }
                    if (fargs.AlignedDirection.Y != 0 && VerticalFlick != null)
                    {
                        VerticalFlick(_attachedElement, fargs);
                    }
                }
            }
        }
Exemple #3
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)));
     }
 }
        private void OnStylusStuff(object sender, StylusEventArgs args)
        {
            if (args.RoutedEvent == UIElement.StylusUpEvent ||
                (args.RoutedEvent == UIElement.StylusDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.StylusMoveEvent && args.Source == null && args.InAir))
            {
                MultitouchWindow.RemoveStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);

                if (!_downpoint.ContainsKey(args.StylusDevice.Id))
                {
                    return;
                }

                //if (args.OriginalSource != _attachedElement) return;

                args.Handled = true;

                Point  current = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
                Vector jitter  = Point.Subtract(current, _downpoint[args.StylusDevice.Id]);
                if (jitter.Length < Threshold)
                {
                    if (Tap != null)
                    {
                        Tap.Invoke(_attachedElement, new TapEventArgs(args.StylusDevice, jitter));
                    }

                    if (_button != null)
                    {
                        _button.SetValue(TapBehavior.IsPressedProperty, true);
                        _button.RaiseEvent(new RoutedEventArgs(ButtonBase.ClickEvent));
                        ExecuteCommandSource(_button);
                    }

                    if ((args.Timestamp - _lasttap) < DoubleTapDelay.TotalMilliseconds && DoubleTap != null)
                    {
                        DoubleTap.Invoke(_attachedElement, new TapEventArgs(args.StylusDevice, jitter));
                    }

                    if (_attachedElement is Control)
                    {
                        ((Control)_attachedElement).RaiseEvent(
                            new MouseButtonEventArgs(Mouse.PrimaryDevice, args.Timestamp,
                                                     MouseButton.Left, args.StylusDevice)
                        {
                            RoutedEvent = Control.MouseDoubleClickEvent
                        });
                    }

                    _lasttap = args.Timestamp;
                }
            }
            else if (args.RoutedEvent == UIElement.StylusDownEvent)
            {
                MultitouchWindow.AddStylusListener(args.StylusDevice, _attachedElement, OnStylusStuff);
                _downpoint[args.StylusDevice.Id] = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);

                if (_button != null)
                {
                    _button.SetValue(TapBehavior.IsPressedProperty, true);
                }
            }
            else if (args.RoutedEvent == UIElement.StylusMoveEvent)
            {
                if (!_downpoint.ContainsKey(args.StylusDevice.Id))
                {
                    return;
                }

                Point current = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
                if (Point.Subtract(current, _downpoint[args.StylusDevice.Id]).Length > Threshold)
                {
                    _downpoint.Remove(args.StylusDevice.Id);

                    if (_button != null)
                    {
                        _button.SetValue(TapBehavior.IsPressedProperty, false);
                    }
                }
            }
        }