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

            if (args.RoutedEvent == UIElement.PreviewMouseLeftButtonUpEvent ||
                (args.RoutedEvent == UIElement.PreviewMouseLeftButtonDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.PreviewMouseMoveEvent && args.Source == null && args.LeftButton == MouseButtonState.Released))
            {
                MultitouchWindow.RemoveMouseListener(_attachedElement, OnMouseStuff);
                ProcessPointUp(-1, pt);
            }
            else if (args.RoutedEvent == UIElement.PreviewMouseLeftButtonDownEvent)
            {
                MultitouchWindow.AddMouseListener(_attachedElement, OnMouseStuff);
                ProcessPointDown(-1, pt);
            }
            else if (args.RoutedEvent == UIElement.PreviewMouseMoveEvent)
            {
                ProcessPointMove(-1, pt);
            }
        }
Exemple #2
0
        private void OnMouseStuff(object sender, MouseEventArgs args)
        {
            if (args.RoutedEvent == UIElement.PreviewMouseUpEvent ||
                (args.RoutedEvent == UIElement.PreviewMouseDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.PreviewMouseMoveEvent && args.Source == null && args.LeftButton == MouseButtonState.Released))
            {
                MultitouchWindow.RemoveMouseListener(_attachedElement, OnMouseStuff);
            }
            else if (args.RoutedEvent == UIElement.PreviewMouseDownEvent)
            {
                MultitouchWindow.AddMouseListener(_attachedElement, OnMouseStuff);
                _pts[-1] = new FlickData()
                {
                    DownPoint = args.GetPosition(_attachedElement)
                };
            }
            else if (args.RoutedEvent == UIElement.PreviewMouseMoveEvent)
            {
                if (!_pts.ContainsKey(-1))
                {
                    return;
                }

                Point current = args.GetPosition(_attachedElement);

                FlickData data   = _pts[-1];
                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.RemoveMouseListener(_attachedElement, OnMouseStuff);

                    _pts.Remove(-1);

                    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 OnMouseStuff(object sender, MouseEventArgs args)
        {
            if (args.RoutedEvent == UIElement.PreviewMouseUpEvent ||
                (args.RoutedEvent == UIElement.PreviewMouseLeftButtonDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.PreviewMouseMoveEvent && args.Source == null && args.LeftButton == MouseButtonState.Released))
            {
                if (!_pts.ContainsKey(-1))
                {
                    return;
                }

                _pts.Remove(-1);
                MultitouchWindow.RemoveMouseListener(_attachedElement, OnMouseStuff);
                MultitouchWindow.ClearPhysicalReferenceFrame(args.MouseDevice);
                _processor.ProcessUp(unchecked ((uint)-1), ToDrawingPointF(args.GetPosition(_attachedElement)));
            }
            else if (args.RoutedEvent == UIElement.PreviewMouseDownEvent)
            {
                _pts[-1] = args.GetPosition(_attachedElement);
                MultitouchWindow.AddMouseListener(_attachedElement, OnMouseStuff);
                MultitouchWindow.PushPhysicalReferenceFrame(args.MouseDevice, this);
                _processor.ProcessDown(unchecked ((uint)-1), ToDrawingPointF(_pts[-1]));
            }
            else if (args.RoutedEvent == UIElement.PreviewMouseMoveEvent)
            {
                if (!_pts.ContainsKey(-1))
                {
                    return;
                }

                //_processor.ProcessMove(unchecked((uint)-1), ToDrawingPointF(args.GetPosition(_attachedElement)));
            }
        }
        private void OnMouseStuff(object sender, MouseEventArgs args)
        {
            if (args.RoutedEvent == UIElement.MouseUpEvent ||
                (args.RoutedEvent == UIElement.MouseLeftButtonDownEvent && args.Source == null) ||
                (args.RoutedEvent == UIElement.MouseMoveEvent && args.Source == null && args.LeftButton == MouseButtonState.Released))
            {
                MultitouchWindow.RemoveMouseListener(_attachedElement, OnMouseStuff);

                if (!_downpoint.ContainsKey(-1))
                {
                    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[-1]);
                if (jitter.Length < Threshold)
                {
                    if (Tap != null)
                    {
                        Tap.Invoke(_attachedElement, new TapEventArgs(args.MouseDevice, jitter));
                    }

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

                    if (_attachedElement is Control)
                    {
                        ((Control)_attachedElement).RaiseEvent(
                            new MouseButtonEventArgs(args.MouseDevice, args.Timestamp,
                                                     ((MouseButtonEventArgs)args).ChangedButton)
                        {
                            RoutedEvent = Control.MouseDoubleClickEvent
                        });
                    }

                    _lasttap = args.Timestamp;
                }
            }
            else if (args.RoutedEvent == UIElement.MouseDownEvent)
            {
                MultitouchWindow.AddMouseListener(_attachedElement, OnMouseStuff);
                _downpoint[-1] = args.GetPosition(args.Device.ActiveSource.RootVisual as IInputElement);
            }
            else if (args.RoutedEvent == UIElement.MouseMoveEvent)
            {
                if (!_downpoint.ContainsKey(-1))
                {
                    return;
                }

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