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); } } } }
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); } }
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); } }
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 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); } } }
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); } } } }