/// <summary> /// Here when we've lost mouse capture. /// </summary> private void OnLostMouseCapture(object sender, MouseEventArgs e) { if (_isMouseCaptured) { _manipulationProcessor.ProcessManipulators(Timestamp, null); _isMouseCaptured = false; } }
/// <summary> /// Processes the manipulators. /// </summary> private void ProcessManipulators() { if (_contentManipulationProcessor == null) { return; } List <Manipulator2D> manipulators = new List <Manipulator2D>(); foreach (TouchDevice touch in TouchesCaptured) { Point position = touch.GetPosition(this); manipulators.Add(new Manipulator2D(touch.Id, (float)position.X, (float)position.Y)); } _contentManipulationProcessor.ProcessManipulators(DateTime.UtcNow.Ticks, manipulators); if (ScatterViewItem != null) { manipulators = new List <Manipulator2D>(); foreach (TouchDevice touch in ScatterViewItem.TouchesCaptured) { Point position = touch.GetPosition(ScatterViewItem); manipulators.Add(new Manipulator2D(touch.Id, (float)position.X, (float)position.Y)); } _scatterManipulationProcessor.ProcessManipulators(DateTime.UtcNow.Ticks, manipulators); } }
/******************************************************************************/ #region Private Methods /// <summary> /// Process a mouse event. /// </summary> /// <param name="mouse"></param> private void ProcessMouse(MouseDevice mouse) { if ((mouse.Captured == this)) { Point position = mouse.GetPosition(Container); List <Manipulator2D> manipulators = new List <Manipulator2D>(); manipulators.Add(new Manipulator2D( 0, (float)(position.X), (float)(position.Y))); // If translation is turned off and the pivot is turned on, // make it act like there's a manipulator on the pivot point, // to allow us to do scaling if (((SupportedManipulations & Manipulations2D.Translate) == Manipulations2D.None) && IsPivotActive) { manipulators.Add(new Manipulator2D( 1, (float)(Center.X), (float)(Center.Y))); } const Manipulations2D translateAndRotate = Manipulations2D.Translate | Manipulations2D.Rotate; if ((manipulators.Count == 1) && ((manipulationProcessor.SupportedManipulations & translateAndRotate) == translateAndRotate) && IsPivotActive) { dragCenter = position; } else { dragCenter.X = double.NaN; dragCenter.Y = double.NaN; } manipulationProcessor.ProcessManipulators( Timestamp, manipulators); } }
/// <summary> /// Handles contact events on the ScrollViewer. Keeps the ManipulationProcessor tracking any contacts on the ScrollViewer. /// </summary> /// <param name="sender">The sender.</param> /// <param name="e">The <see cref="System.Windows.Input.TouchEventArgs"/> instance containing the event data.</param> private void ScrollViewerTouchHandler(object sender, TouchEventArgs e) { List <Manipulator2D> manipulators = new List <Manipulator2D>(); foreach (TouchDevice touch in AssociatedObject.TouchesOver) { Point position = touch.GetTouchPoint(AssociatedObject).Position; manipulators.Add(new Manipulator2D(touch.Id, (float)position.X, (float)position.Y)); } _manipulationProcessor.ProcessManipulators(DateTime.UtcNow.Ticks, manipulators); }
private void OnCapturedTouchReported(object sender, TouchReportedEventArgs e) { var parent = AssociatedObject.Parent as UIElement; if (parent == null) { return; } var root = TouchHelper.GetRootElement(parent); if (root == null) { return; } List <Manipulator2D> manipulators = null; if (e.TouchPoints.FirstOrDefault() != null) { // Get transformation to convert positions to the parent's coordinate system. var transform = root.TransformToVisual(parent); foreach (var touchPoint in e.TouchPoints) { var position = touchPoint.Position; // Convert to the parent's coordinate system. position = transform.Transform(position); // Create a manipulator. var manipulator = new Manipulator2D( touchPoint.TouchDevice.Id, (float)(position.X), (float)(position.Y)); if (manipulators == null) { // Lazy initialization. manipulators = new List <Manipulator2D>(); } manipulators.Add(manipulator); } } // Process manipulations. _manipulationProcessor.ProcessManipulators(DateTime.UtcNow.Ticks, manipulators); }
// </Snippet_GamePiece_ProcessInertia> // <Snippet_GamePiece_UpdateFromMouse> #region UpdateFromMouse public bool UpdateFromMouse(MouseState mouseState) { if (mouseState.LeftButton == ButtonState.Released) { if (isMouseCaptured) { manipulationProcessor.CompleteManipulation(Timestamp); } isMouseCaptured = false; } if (isMouseCaptured || (mouseState.LeftButton == ButtonState.Pressed && bounds.Contains(mouseState.X, mouseState.Y))) { isMouseCaptured = true; Manipulator2D[] manipulators = new Manipulator2D[] { new Manipulator2D(0, mouseState.X, mouseState.Y) }; dragPoint.X = mouseState.X; dragPoint.Y = mouseState.Y; manipulationProcessor.ProcessManipulators(Timestamp, manipulators); } // If the right button is pressed, stop the piece and move it to the center. if (mouseState.RightButton == ButtonState.Pressed) { processInertia = false; X = viewport.Width / 2; Y = viewport.Height / 2; rotation = 0; } return(isMouseCaptured); }
private void drawingWnd_TouchDown(object sender, TouchEventArgs e) { TryAddManipulator(e.TouchDevice); _zoomManipProc.ProcessManipulators(this.Timestamp, _manipulators.Values); }