private void OnTouch(object sender, SKTouchEventArgs e) { SKPoint absoluteTouchLocation = new SKPoint((int)Math.Floor(e.Location.X), (int)Math.Floor(e.Location.Y)); SKPoint aspectTouchLocation = anArtBoard.MatrixToAspectCoordinates().MapPoint(absoluteTouchLocation); switch (e.ActionType) { case SKTouchAction.Pressed: // the user added a finger aBezierHandle = new BezierHandle(aspectTouchLocation); bezierHandlePreviewCanvasView.InvalidateSurface(); break; case SKTouchAction.Moved: // the user moved a finger if (e.InContact) { aBezierHandle.MouseControlPoint = aspectTouchLocation; if (aBezierHandle.Magnitude <= bezierHandleThresholdSlider.Value) { aBezierHandle.MouseControlPoint = aBezierHandle.AnchorPoint; } } bezierHandlePreviewCanvasView.InvalidateSurface(); break; case SKTouchAction.Released: // the user removed a finger aBezierHandle.MouseControlPoint = aspectTouchLocation; if (aBezierHandle.Magnitude <= bezierHandleThresholdSlider.Value) { aBezierHandle.MouseControlPoint = aBezierHandle.AnchorPoint; } bezierHandlePreviewCanvasView.InvalidateSurface(); break; case SKTouchAction.Cancelled: // the user removed a finger aBezierHandle = null; bezierHandlePreviewCanvasView.InvalidateSurface(); break; } // the location (in pixels) of the finger on the screen //var pos = e.Location; // set Handled to true if we handled the event // if we don't, then parent views may also respond e.Handled = true; }
public void GenerateBezierPath(PathPreviewAlgorithms pathPreview) { BezierHandle prevBezierHandle = null; bool firstMove = true; foreach (var aBezierHandle in this.BezierHandleList) { if (prevBezierHandle == null) { prevBezierHandle = aBezierHandle; continue; } if (firstMove) { this.InProgressPath.MoveTo(prevBezierHandle.AnchorPoint); firstMove = false; } this.InProgressPath.CubicTo( prevBezierHandle.MouseControlPoint, aBezierHandle.TheOtherControlPoint, aBezierHandle.AnchorPoint); prevBezierHandle = aBezierHandle; } if (pathPreview == PathPreviewAlgorithms.LinearClose) { this.InProgressPath.Close(); } else if (pathPreview == PathPreviewAlgorithms.Close) { this.InProgressPath.CubicTo( this.BezierHandleList.Last().MouseControlPoint, this.BezierHandleList.First().TheOtherControlPoint, this.BezierHandleList.First().AnchorPoint); this.InProgressPath.Close(); } }