public CGRect AddPointOfType(PointType pointType, UITouch touch) { var previousPoint = Points.LastOrDefault (); var previousSequenceNumber = previousPoint != null ? previousPoint.SequenceNumber : -1; var point = new LinePoint (touch, previousSequenceNumber + 1, pointType); if (point.EstimationUpdateIndex != null && point.EstimatedPropertiesExpectingUpdates != 0) pointsWaitingForUpdatesByEstimationIndex [point.EstimationUpdateIndex] = point; Points.Add (point); return UpdateRectForLinePoint (point, previousPoint); }
public CGRect AddPointAtLocation (CGPoint location, CGPoint preciseLocation, nfloat force, double timestamp, PointType type) { var point = new LinePoint (timestamp, force, location, preciseLocation, type); var updateRect = UpdateRectForLinePoint (point); var last = points.LastOrDefault (); if (last != null) { var lastRect = UpdateRectForLinePoint (last); updateRect.UnionWith (lastRect); } points.Add (point); return updateRect; }
static CGRect UpdateRectForLinePoint (LinePoint point) { var rect = new CGRect (point.Location, CGSize.Empty); // The negative magnitude ensures an outset rectangle var magnitude = -3 * point.Magnitude - 2; rect = rect.Inset (magnitude, magnitude); return rect; }
static CGRect UpdateRectForLinePoint(LinePoint point, LinePoint previousPoint) { var rect = new CGRect (point.Location, CGSize.Empty); var pointMagnitude = point.Magnitude; if (previousPoint != null) { pointMagnitude = NMath.Max (pointMagnitude, previousPoint.Magnitude); rect = rect.UnionWith (new CGRect (previousPoint.Location, CGSize.Empty)); } // The negative magnitude ensures an outset rectangle. var magnitude = -3 * pointMagnitude - 2; rect = rect.Inset (magnitude, magnitude); return rect; }
public void DrawInContext(CGContext context, bool isDebuggingEnabled, bool usePreciseLocation) { LinePoint maybePriorPoint = null; foreach (var point in points) { if (maybePriorPoint == null) { maybePriorPoint = point; continue; } var priorPoint = maybePriorPoint; var color = UIColor.Black; if (isDebuggingEnabled) { if (point.Properties.Contains(PointType.Cancelled)) { color = UIColor.Red; } else if (point.Properties.Contains(PointType.NeedsUpdate)) { color = UIColor.Orange; } else if (point.Properties.Contains(PointType.Finger)) { color = UIColor.Purple; } else if (point.Properties.Contains(PointType.Coalesced)) { color = UIColor.Green; } else if (point.Properties.Contains(PointType.Predicted)) { color = UIColor.Blue; } } else { if (point.Properties.Contains(PointType.Cancelled)) { color = UIColor.Clear; } else if (point.Properties.Contains(PointType.Finger)) { color = UIColor.Purple; } if (point.Properties.Contains(PointType.Predicted) && !point.Properties.Contains(PointType.Cancelled)) { color = color.ColorWithAlpha(0.5f); } } var location = usePreciseLocation ? point.PreciseLocation : point.Location; var priorLocation = usePreciseLocation ? priorPoint.PreciseLocation : priorPoint.Location; context.SetStrokeColor(color.CGColor); context.BeginPath(); context.MoveTo(priorLocation.X, priorLocation.Y); context.AddLineToPoint(location.X, location.Y); context.SetLineWidth(point.Magnitude); context.StrokePath(); maybePriorPoint = point; } }