public override void TouchesEnded(NSSet touches, UIEvent evt) { // obtain the location of the touch var touch = touches.AnyObject as UITouch; var touchLocation = touch.LocationInView(this); // something may have happened (clear) during the stroke if (currentPath != null) { if (HasMovedFarEnough(currentPath, touchLocation.X, touchLocation.Y)) { // add it to the current path currentPath.Path.AddLineTo(touchLocation); currentPath.GetPoints().Add(touchLocation); } // obtain the smoothed path, and add it to the old paths var smoothed = PathSmoothing.SmoothedPathWithGranularity(currentPath, 4); paths.Add(smoothed); } // clear the current path currentPath = null; // update the dirty rectangle UpdateBounds(touchLocation); SetNeedsDisplay(); // we are done with drawing OnStrokeCompleted(); }
private void OnPointerReleased(object sender, PointerRoutedEventArgs e) { if (!IsInputEnabled) { return; } OnPointerMoved(sender, e); // add the current path and points to their respective lists. var smoothed = PathSmoothing.SmoothedPathWithGranularity(currentPath, 4); paths.Add(smoothed); // reset the drawing currentPath = null; tempPathShape.Tag = null; tempPathShape.Data = new GeometryGroup(); // replace the temp path with a smoothed one var pathShape = new Path { Data = smoothed.Path, Tag = smoothed }; SetPathProperties(pathShape); Children.Add(pathShape); // we are done with drawing OnStrokeCompleted(); }
public static IEnumerable <Point> GetPoints(this InkStroke stroke) { var empty = new Point(); var segments = stroke.GetRenderingSegments(); if (segments.Any(s => s.BezierControlPoint1 != empty || s.BezierControlPoint2 != empty)) { // we assume strokes with bezier controls are generated by the inking // so we know that the detail will be low - thus we smooth return(PathSmoothing.BezierToLinear(segments, 0.1f)); } return(segments.Select(p => p.Position)); }
private void OnMouseLost(object sender, MouseEventArgs e) { var curr = currentStroke; if (curr != null) { var smoothed = PathSmoothing.SmoothedPathWithGranularity(curr, 20); // swap the old path with the smoothed one inkPresenter.Strokes.Remove(curr); inkPresenter.Strokes.Add(smoothed); currentStroke = null; } OnStrokeCompleted(); }
private void TouchesEnded(MotionEvent e) { TouchesMoved(e, false); // add the current path and points to their respective lists. var smoothed = PathSmoothing.SmoothedPathWithGranularity(currentPath, 20); paths.Add(smoothed); // reset the drawing currentPath = null; // update the dirty rectangle Invalidate(DirtyRect); // we are done with drawing OnStrokeCompleted(); }
private void TouchesEnded(MotionEvent e) { // something may have happened (clear) during the stroke if (currentPath != null) { TouchesMoved(e, false); // add the current path and points to their respective lists. var smoothed = PathSmoothing.SmoothedPathWithGranularity(currentPath, 2); paths.Add(smoothed); } // reset the drawing currentPath = null; // update the dirty rectangle Invalidate(DirtyRect); // we are done with drawing OnStrokeCompleted(); // allow the event to propagate Parent?.RequestDisallowInterceptTouchEvent(false); }
public override async void TouchesEnded(NSSet touches, UIEvent evt) { // obtain the location of the touch var touch = touches.AnyObject as UITouch; var touchLocation = touch.LocationInView(this); // something may have happened (clear) during the stroke if (currentPath != null) { if (HasMovedFarEnough(currentPath, touchLocation.X, touchLocation.Y)) { // add it to the current path currentPath.Path.AddLineTo(touchLocation); currentPath.GetPoints().Add(touchLocation); } else if (touch.TapCount == 1) { // Single Tap singleTapNeeded = true; await Task.Delay(300); if (singleTapNeeded) { //CGRect r = new CGRect (touchLocation.X, touchLocation.Y, StrokeWidth, StrokeWidth); //var c = UIBezierPath.FromOval (r); var s = new InkStroke(new UIBezierPath(), new List <CGPoint> (), StrokeColor, StrokeWidth); s.Path.MoveTo(touchLocation); s.GetPoints().Add(touchLocation); var dest = new CGPoint(touchLocation.X + StrokeWidth, touchLocation.Y + StrokeWidth); s.Path.AddLineTo(dest); s.GetPoints().Add(dest); paths.Add(s); s = new InkStroke(new UIBezierPath(), new List <CGPoint> (), StrokeColor, StrokeWidth); var src = new CGPoint(touchLocation.X + StrokeWidth, touchLocation.Y); s.Path.MoveTo(src); s.GetPoints().Add(src); dest = new CGPoint(touchLocation.X, touchLocation.Y + StrokeWidth); s.Path.AddLineTo(dest); s.GetPoints().Add(dest); paths.Add(s); } ; } // obtain the smoothed path, and add it to the old paths if (currentPath != null) { var smoothed = PathSmoothing.SmoothedPathWithGranularity(currentPath, 4); paths.Add(smoothed); } } // clear the current path currentPath = null; // update the dirty rectangle UpdateBounds(touchLocation); SetNeedsDisplay(); // we are done with drawing OnStrokeCompleted(); }