/// <summary> /// Initializes a new instance of the <see cref="XInkPresenter"/> class /// </summary> /// <param name="inkCanvasView">the <see cref="InkCanvasView"/></param> internal XInkPresenter(IInkCanvasView inkCanvasView) { InkCanvasView = inkCanvasView ?? throw new ArgumentNullException(nameof(inkCanvasView)); UnprocessedInput = new XInkUnprocessedInput(this); StrokeContainer = new XInkStrokeContainer(); }
private void UpdateApex(IInkCanvasView inkCanvasView, EquirectangularStencil stencil) { if (Point1 == Point2) { return; } stencil.Apex = GetApex(inkCanvasView.CanvasHeight); inkCanvasView.InvalidateCanvas(false, true); }
/// <summary> /// Handle touch events to move the stencil points /// </summary> /// <param name="inkCanvasView">the ink canvas view</param> /// <param name="stencil">the equirectangular stencil</param> /// <param name="e">the touch event arguments</param> internal void Touch(IInkCanvasView inkCanvasView, EquirectangularStencil stencil, SKTouchEventArgs e) { if (inkCanvasView == null) { throw new ArgumentNullException(nameof(inkCanvasView)); } if (stencil == null || stencil.Mode != EquirectangularStencilMode.TwoPoint) { return; } if (e == null) { throw new ArgumentNullException(nameof(e)); } var location = inkCanvasView.GetCanvasPosition(e.Location); var deltaX = location.X - _startPoint.X; var deltaY = location.Y - _startPoint.Y; if (e.InContact) { switch (e.ActionType) { case SKTouchAction.Pressed: if (Distance(location, Point1) < Radius / inkCanvasView.ZoomFactor) { _touchingPoint = 1; _startPoint = location; e.Handled = true; } else if (Distance(location, Point2) < Radius / inkCanvasView.ZoomFactor) { _touchingPoint = 2; _startPoint = location; e.Handled = true; } else { _touchingPoint = 0; } break; case SKTouchAction.Moved: switch (_touchingPoint) { case 1: Point1 = Point1.Offset(deltaX, deltaY); e.Handled = true; UpdateApex(inkCanvasView, stencil); break; case 2: Point2 = Point2.Offset(deltaX, deltaY); e.Handled = true; UpdateApex(inkCanvasView, stencil); break; } _startPoint = location; break; } } else if (e.ActionType == SKTouchAction.Released) { switch (_touchingPoint) { case 1: Point1 = Point1.Offset(deltaX, deltaY); e.Handled = true; UpdateApex(inkCanvasView, stencil); break; case 2: Point2 = Point2.Offset(deltaX, deltaY); e.Handled = true; UpdateApex(inkCanvasView, stencil); break; } _touchingPoint = 0; } }