protected void DrawShape(Canvas canvas) { Paint paint = new Paint(); paint.Color = Color; switch (Shape) { case ShapeEnum.RectangleShape: canvas.DrawRect(0, 0, ShapeWidth, ShapeHeight, paint); break; case ShapeEnum.OvalShape: canvas.DrawOval(new RectF(0, 0, ShapeWidth, ShapeHeight), paint); break; case ShapeEnum.TriangleShape: Path path = new Path(); path.MoveTo(ShapeWidth / 2, 0); path.LineTo(ShapeWidth, ShapeHeight); path.LineTo(0,ShapeHeight); path.Close(); canvas.DrawPath(path, paint); break; default: canvas.DrawCircle(ShapeWidth / 2, ShapeHeight / 2, ShapeWidth / 2, paint); break; } }
public void EndFigure(bool close) { if (close) { path.Close(); } }
public override void Draw(Android.Graphics.Canvas canvas) { base.Draw(canvas); var rect = new RectF(0,0,300,300); switch (TheShape) { case Shape.Circle: canvas.DrawOval(rect, new Paint() { Color = Color.Aqua }); break; case Shape.Square: canvas.DrawRect(rect, new Paint() { Color = Color.Red }); break; case Shape.Triangle: var path = new Path(); path.MoveTo(rect.CenterX(), 0); path.LineTo(0, rect.Height()); path.LineTo(rect.Width(), rect.Height()); path.Close(); var paint = new Paint() {Color = Color.Magenta}; paint.SetStyle(Paint.Style.Fill); canvas.DrawPath(path, paint); break; default: throw new ArgumentOutOfRangeException(); } }
protected override void OnDraw(Android.Graphics.Canvas canvas) { var rect = new RectF(0, 0, 300, 300); switch (Shape) { case Shape.Circle: canvas.DrawOval(rect, new Paint() { Color = Color.CornflowerBlue }); break; case Shape.Square: canvas.DrawRect(rect, new Paint() { Color = Color.Crimson }); break; case Shape.Triangle: var path = new Path(); path.MoveTo(rect.CenterX(), rect.Top); path.LineTo(rect.Left, rect.Bottom); path.LineTo(rect.Right, rect.Bottom); path.Close(); var paint = new Paint() {Color = Color.Crimson}; paint.Color = Color.Gold; paint.SetStyle(Paint.Style.Fill); canvas.DrawPath(path, paint); break; default: throw new ArgumentOutOfRangeException(); } }
void CreatePath() { droidGraphics.Path path = null; if (points != null && points.Count > 1) { path = new droidGraphics.Path(); path.SetFillType(fillType); path.MoveTo(pixelsPerDip * (float)points[0].X, pixelsPerDip * (float)points[0].Y); for (int index = 1; index < points.Count; index++) { path.LineTo(pixelsPerDip * (float)points[index].X, pixelsPerDip * (float)points[index].Y); } if (this is PolygonDrawableView) { path.Close(); } } Path = path; }
public void Initialize() { _minuteHand = new Path(); _minuteHand.MoveTo(0, 10); _minuteHand.LineTo(0, -55); _minuteHand.Close(); _secondHand = new Path(); _secondHand.MoveTo(0, -80); _secondHand.LineTo(0, 15); _secondHand.Close(); }
private void AndroidDrawPath(GraphicsPath p) { var path = new Android.Graphics.Path(); float d = density; for (int i = 0; i < p._segments.Count; i++) { { var ln = p._segments[i] as GraphicsPath._LineSegment; if (ln != null) { if (i == 0) { path.MoveTo(ln.x1 * d, ln.y1 * d); } else { path.LineTo(ln.x1 * d, ln.y1 * d); } path.LineTo(ln.x2 * d, ln.y2 * d); continue; } } { var bz = p._segments[i] as GraphicsPath._BezierSegment; if (bz != null) { if (i == 0) { path.MoveTo(bz.x1 * d, bz.y1 * d); } else { path.LineTo(bz.x1 * d, bz.y1 * d); } path.CubicTo( bz.x2 * d, bz.y2 * d, bz.x3 * d, bz.y3 * d, bz.x4 * d, bz.y4 * d); continue; } } } if (p._closed) { path.Close(); } canvas.DrawPath(path, paint); }
/// <Docs>The Canvas to which the View is rendered.</Docs> /// <summary> /// BoxViewのカスタマイズはDrawで行う /// </summary> /// <param name="canvas">Canvas.</param> public override void Draw(Android.Graphics.Canvas canvas) { // 2重に描画してしまうので、baseは描画しない //base.Draw(canvas); // ElementをキャストしてFormsで定義したCustomBoxViewを取得 var formsBox = (CustomBoxView)Element; // Androidの描画はPaintを使用 using (var paint = new Paint()) { // 塗りつぶし色の設定 paint.Color = formsBox.FillColor.ToAndroid(); // 吹き出し部分の設定 // パスの生成 var path = new Path(); // スタート地点の設定 path.MoveTo(0, 0); // 経由地点の設定 path.LineTo(100, 10); path.LineTo(100, 100); // パスを繋げる path.Close(); // 描画 canvas.DrawPath(path, paint); // 角の丸い四角の設定 // 角丸の直径を決める // widthとheightを比較して小さい方を基準にする var minSize = Math.Min(Width, Height); // 指定するのは直径なので、指定半径を2倍する var diameter = formsBox.Radius * 2; // 角丸の直径はminSize以下でなければならない if (diameter > minSize) diameter = minSize; // 描画領域の設定 var rect = new RectF(0, 0, (float)Width, (float)Height); //四角形描画 canvas.DrawRoundRect(rect, diameter, diameter, paint); } }
void Initialize () { // Create Paint for all drawing paint = new Paint (); // All paths are based on 100-unit clock radius // centered at (0, 0). // Define circle for tick marks. tickMarks = new Path (); tickMarks.AddCircle (0, 0, 90, Path.Direction.Cw); // Hour, minute, second hands defined to point straight up. // Define hour hand. hourHand = new Path (); hourHand.MoveTo (0, -60); hourHand.CubicTo (0, -30, 20, -30, 5, -20); hourHand.LineTo (5, 0); hourHand.CubicTo (5, 7.5f, -5, 7.5f, -5, 0); hourHand.LineTo (-5, -20); hourHand.CubicTo (-20, -30, 0, -30, 0, -60); hourHand.Close (); // Define minute hand. minuteHand = new Path (); minuteHand.MoveTo (0, -80); minuteHand.CubicTo (0, -75, 0, -70, 2.5f, -60); minuteHand.LineTo (2.5f, 0); minuteHand.CubicTo (2.5f, 5, -2.5f, 5, -2.5f, 0); minuteHand.LineTo (-2.5f, -60); minuteHand.CubicTo (0, -70, 0, -75, 0, -80); minuteHand.Close (); // Define second hand. secondHand = new Path (); secondHand.MoveTo (0, 10); secondHand.LineTo (0, -80); }
public void DrawPath(IEnumerable <PathOperation> ops, Pen pen = null, BaseBrush brush = null) { using (var path = new Path()) { var bb = new BoundingBoxBuilder(); foreach (var op in ops) { var moveTo = op as MoveTo; if (moveTo != null) { var start = moveTo.Start; var end = moveTo.End; path.MoveTo((float)start.X, (float)start.Y); bb.Add(start); bb.Add(end); continue; } var lineTo = op as LineTo; if (lineTo != null) { var start = lineTo.Start; var end = lineTo.End; path.LineTo((float)start.X, (float)start.Y); path.LineTo((float)end.X, (float)end.Y); bb.Add(start); bb.Add(end); continue; } var at = op as ArcTo; if (at != null) { var p = at.Point; path.LineTo((float)p.X, (float)p.Y); bb.Add(p); continue; } var curveTo = op as CurveTo; if (curveTo != null) { var end = curveTo.End; var firstControlPoint = curveTo.FirstControlPoint; var secondControlPoint = curveTo.SecondControlPoint; path.CubicTo((float)firstControlPoint.X, (float)firstControlPoint.Y, (float)secondControlPoint.X, (float)secondControlPoint.Y, (float)end.X, (float)end.Y); bb.Add(firstControlPoint); bb.Add(secondControlPoint); bb.Add(end); continue; } var cp = op as ClosePath; if (cp != null) { path.Close(); continue; } throw new NotSupportedException("Path Op " + op); } var frame = bb.BoundingBox; if (brush != null) { var solidBrush = brush as SolidBrush; if (solidBrush != null) { path.SetFillType(GetPathFillType(((SolidBrush)brush).FillMode)); } var brushPaint = GetBrushPaint(brush, frame); graphics.DrawPath(path, brushPaint); } if (pen != null) { var penPaint = GetPenPaint(pen); graphics.DrawPath(path, penPaint); } } }
public void DrawPath(IEnumerable<PathOperation> ops, Pen pen = null, BaseBrush brush = null) { using (var path = new Path()) { var bb = new BoundingBoxBuilder(); foreach (var op in ops) { var moveTo = op as MoveTo; if (moveTo != null) { var start = moveTo.Start; var end = moveTo.End; path.MoveTo((float) start.X, (float) start.Y); bb.Add(start); bb.Add(end); continue; } var lineTo = op as LineTo; if (lineTo != null) { var start = lineTo.Start; var end = lineTo.End; path.LineTo((float) start.X, (float) start.Y); path.LineTo((float) end.X, (float) end.Y); bb.Add(start); bb.Add(end); continue; } var at = op as ArcTo; if (at != null) { var p = at.Point; path.LineTo((float) p.X, (float) p.Y); bb.Add(p); continue; } var curveTo = op as CurveTo; if (curveTo != null) { var end = curveTo.End; var firstControlPoint = curveTo.FirstControlPoint; var secondControlPoint = curveTo.SecondControlPoint; path.CubicTo((float) firstControlPoint.X, (float) firstControlPoint.Y, (float) secondControlPoint.X, (float) secondControlPoint.Y, (float) end.X, (float) end.Y); bb.Add(firstControlPoint); bb.Add(secondControlPoint); bb.Add(end); continue; } var cp = op as ClosePath; if (cp != null) { path.Close(); continue; } throw new NotSupportedException("Path Op " + op); } var frame = bb.BoundingBox; if (brush != null) { var solidBrush = brush as SolidBrush; if (solidBrush != null) { path.SetFillType(GetPathFillType(((SolidBrush)brush).FillMode)); } var brushPaint = GetBrushPaint(brush, frame); graphics.DrawPath(path, brushPaint); } if (pen != null) { var penPaint = GetPenPaint(pen); graphics.DrawPath(path, penPaint); } } }
public static APath ToAPath(this Geometry geometry, Context context) { APath path = new APath(); float density = context.Resources.DisplayMetrics.Density; if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; path.MoveTo( density * (float)lineGeometry.StartPoint.X, density * (float)lineGeometry.StartPoint.Y); path.LineTo( density * (float)lineGeometry.EndPoint.X, density * (float)lineGeometry.EndPoint.Y); } else if (geometry is RectangleGeometry) { FormsRectangle rect = (geometry as RectangleGeometry).Rect; path.AddRect( density * (float)rect.Left, density * (float)rect.Top, density * (float)rect.Right, density * (float)rect.Bottom, APath.Direction.Cw); } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; path.AddOval(new RectF( density * (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX), density * (float)(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY), density * (float)(ellipseGeometry.Center.X + ellipseGeometry.RadiusX), density * (float)(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)), APath.Direction.Cw); } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; path.SetFillType(geometryGroup.FillRule == FillRule.Nonzero ? APath.FillType.Winding : APath.FillType.EvenOdd); foreach (Geometry child in geometryGroup.Children) { APath childPath = child.ToAPath(context); path.AddPath(childPath); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; path.SetFillType(pathGeometry.FillRule == FillRule.Nonzero ? APath.FillType.Winding : APath.FillType.EvenOdd); foreach (PathFigure pathFigure in pathGeometry.Figures) { path.MoveTo( density * (float)pathFigure.StartPoint.X, density * (float)pathFigure.StartPoint.Y); Point lastPoint = pathFigure.StartPoint; foreach (PathSegment pathSegment in pathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; path.LineTo( density * (float)lineSegment.Point.X, density * (float)lineSegment.Point.Y); lastPoint = lineSegment.Point; } // PolylineSegment else if (pathSegment is PolyLineSegment) { PolyLineSegment polylineSegment = pathSegment as PolyLineSegment; PointCollection points = polylineSegment.Points; for (int i = 0; i < points.Count; i++) { path.LineTo( density * (float)points[i].X, density * (float)points[i].Y); } lastPoint = points[points.Count - 1]; } // BezierSegment else if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; path.CubicTo( density * (float)bezierSegment.Point1.X, density * (float)bezierSegment.Point1.Y, density * (float)bezierSegment.Point2.X, density * (float)bezierSegment.Point2.Y, density * (float)bezierSegment.Point3.X, density * (float)bezierSegment.Point3.Y); lastPoint = bezierSegment.Point3; } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; PointCollection points = polyBezierSegment.Points; if (points.Count >= 3) { for (int i = 0; i < points.Count; i += 3) { path.CubicTo( density * (float)points[i + 0].X, density * (float)points[i + 0].Y, density * (float)points[i + 1].X, density * (float)points[i + 1].Y, density * (float)points[i + 2].X, density * (float)points[i + 2].Y); } } lastPoint = points[points.Count - 1]; } // QuadraticBezierSegment else if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment bezierSegment = pathSegment as QuadraticBezierSegment; path.QuadTo( density * (float)bezierSegment.Point1.X, density * (float)bezierSegment.Point1.Y, density * (float)bezierSegment.Point2.X, density * (float)bezierSegment.Point2.Y); lastPoint = bezierSegment.Point2; } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyBezierSegment = pathSegment as PolyQuadraticBezierSegment; PointCollection points = polyBezierSegment.Points; if (points.Count >= 2) { for (int i = 0; i < points.Count; i += 2) { path.QuadTo( density * (float)points[i + 0].X, density * (float)points[i + 0].Y, density * (float)points[i + 1].X, density * (float)points[i + 1].Y); } } lastPoint = points[points.Count - 1]; } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; List <Point> points = new List <Point>(); GeometryHelper.FlattenArc( points, lastPoint, arcSegment.Point, arcSegment.Size.Width, arcSegment.Size.Height, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection == SweepDirection.CounterClockwise, 1); for (int i = 0; i < points.Count; i++) { path.LineTo( density * (float)points[i].X, density * (float)points[i].Y); } if (points.Count > 0) { lastPoint = points[points.Count - 1]; } } } if (pathFigure.IsClosed) { path.Close(); } } } return(path); }
void DrawWater(Canvas canvas) { canvas.Save (); var circle = new Path (); circle.AddCircle (Width / 2, Height / 2, Height / 2, Path.Direction.Ccw); circle.Close (); canvas.ClipPath (circle); wavy.Draw (canvas); canvas.Restore (); }
public object ConvertToNative(Geometry geometry) { // TODO: Can we keep this object around and reset it? droidGraphics.Path path = new droidGraphics.Path(); // TODO: Might we also save a non-transformed path and a transformed path? -- No, that fails for GeometryGroup // Determine what type of Geometry we're dealing with if (geometry is LineGeometry) { LineGeometry lineGeometry = geometry as LineGeometry; path.MoveTo(PixelsPerDip * (float)lineGeometry.StartPoint.X, PixelsPerDip * (float)lineGeometry.StartPoint.Y); path.LineTo(PixelsPerDip * (float)lineGeometry.EndPoint.X, PixelsPerDip * (float)lineGeometry.EndPoint.Y); } else if (geometry is RectangleGeometry) { Rect rect = (geometry as RectangleGeometry).Rect; path.AddRect(PixelsPerDip * (float)rect.Left, PixelsPerDip * (float)rect.Top, PixelsPerDip * (float)rect.Right, PixelsPerDip * (float)rect.Bottom, droidGraphics.Path.Direction.Cw); // TODO: Check for compatibility! } else if (geometry is EllipseGeometry) { EllipseGeometry ellipseGeometry = geometry as EllipseGeometry; path.AddOval(new droidGraphics.RectF( PixelsPerDip * (float)(ellipseGeometry.Center.X - ellipseGeometry.RadiusX), PixelsPerDip * (float)(ellipseGeometry.Center.Y - ellipseGeometry.RadiusY), PixelsPerDip * (float)(ellipseGeometry.Center.X + ellipseGeometry.RadiusX), PixelsPerDip * (float)(ellipseGeometry.Center.Y + ellipseGeometry.RadiusY)), droidGraphics.Path.Direction.Cw); // TODO: Check for compatibility! } else if (geometry is GeometryGroup) { GeometryGroup geometryGroup = geometry as GeometryGroup; SetFillRule(path, geometryGroup.FillRule); foreach (Geometry child in geometryGroup.Children) { droidGraphics.Path childPath = ConvertToNative(child) as droidGraphics.Path; path.AddPath(childPath); } } else if (geometry is PathGeometry) { PathGeometry pathGeometry = geometry as PathGeometry; SetFillRule(path, pathGeometry.FillRule); foreach (PathFigure pathFigure in pathGeometry.Figures) { path.MoveTo(PixelsPerDip * (float)pathFigure.StartPoint.X, PixelsPerDip * (float)pathFigure.StartPoint.Y); Point lastPoint = pathFigure.StartPoint; foreach (PathSegment pathSegment in pathFigure.Segments) { // LineSegment if (pathSegment is LineSegment) { LineSegment lineSegment = pathSegment as LineSegment; path.LineTo(PixelsPerDip * (float)lineSegment.Point.X, PixelsPerDip * (float)lineSegment.Point.Y); lastPoint = lineSegment.Point; } // PolylineSegment else if (pathSegment is PolyLineSegment) { PolyLineSegment polylineSegment = pathSegment as PolyLineSegment; PointCollection points = polylineSegment.Points; for (int i = 0; i < points.Count; i++) { path.LineTo(PixelsPerDip * (float)points[i].X, PixelsPerDip * (float)points[i].Y); } lastPoint = points[points.Count - 1]; } // BezierSegment else if (pathSegment is BezierSegment) { BezierSegment bezierSegment = pathSegment as BezierSegment; path.CubicTo(PixelsPerDip * (float)bezierSegment.Point1.X, PixelsPerDip * (float)bezierSegment.Point1.Y, PixelsPerDip * (float)bezierSegment.Point2.X, PixelsPerDip * (float)bezierSegment.Point2.Y, PixelsPerDip * (float)bezierSegment.Point3.X, PixelsPerDip * (float)bezierSegment.Point3.Y); lastPoint = bezierSegment.Point3; } // PolyBezierSegment else if (pathSegment is PolyBezierSegment) { PolyBezierSegment polyBezierSegment = pathSegment as PolyBezierSegment; PointCollection points = polyBezierSegment.Points; for (int i = 0; i < points.Count; i += 3) { path.CubicTo(PixelsPerDip * (float)points[i + 0].X, PixelsPerDip * (float)points[i + 0].Y, PixelsPerDip * (float)points[i + 1].X, PixelsPerDip * (float)points[i + 1].Y, PixelsPerDip * (float)points[i + 2].X, PixelsPerDip * (float)points[i + 2].Y); } lastPoint = points[points.Count - 1]; } // QuadraticBezierSegment else if (pathSegment is QuadraticBezierSegment) { QuadraticBezierSegment bezierSegment = pathSegment as QuadraticBezierSegment; path.QuadTo(PixelsPerDip * (float)bezierSegment.Point1.X, PixelsPerDip * (float)bezierSegment.Point1.Y, PixelsPerDip * (float)bezierSegment.Point2.X, PixelsPerDip * (float)bezierSegment.Point2.Y); lastPoint = bezierSegment.Point2; } // PolyQuadraticBezierSegment else if (pathSegment is PolyQuadraticBezierSegment) { PolyQuadraticBezierSegment polyBezierSegment = pathSegment as PolyQuadraticBezierSegment; PointCollection points = polyBezierSegment.Points; for (int i = 0; i < points.Count; i += 2) { path.QuadTo(PixelsPerDip * (float)points[i + 0].X, PixelsPerDip * (float)points[i + 0].Y, PixelsPerDip * (float)points[i + 1].X, PixelsPerDip * (float)points[i + 1].Y); } lastPoint = points[points.Count - 1]; } // ArcSegment else if (pathSegment is ArcSegment) { ArcSegment arcSegment = pathSegment as ArcSegment; List <Point> points = new List <Point>(); Xamarin.Forms.Shapes.Shapes.FlattenArc(points, lastPoint, arcSegment.Point, arcSegment.Size.Width, arcSegment.Size.Height, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection == SweepDirection.Counterclockwise, 1); for (int i = 0; i < points.Count; i++) { path.LineTo(PixelsPerDip * (float)points[i].X, PixelsPerDip * (float)points[i].Y); } lastPoint = points[points.Count - 1]; } } if (pathFigure.IsClosed) { path.Close(); } } } // Apply transform if (geometry.Transform != null) { path.Transform((droidGraphics.Matrix)geometry.Transform.GetNativeObject()); } return(path); }
public static Bitmap ToTransformedCorners(Bitmap source, double topLeftCornerSize, double topRightCornerSize, double bottomLeftCornerSize, double bottomRightCornerSize, CornerTransformType cornersTransformType, double cropWidthRatio, double cropHeightRatio) { double sourceWidth = source.Width; double sourceHeight = source.Height; double desiredWidth = sourceWidth; double desiredHeight = sourceHeight; double desiredRatio = cropWidthRatio / cropHeightRatio; double currentRatio = sourceWidth / sourceHeight; if (currentRatio > desiredRatio) { desiredWidth = (cropWidthRatio * sourceHeight / cropHeightRatio); } else if (currentRatio < desiredRatio) { desiredHeight = (cropHeightRatio * sourceWidth / cropWidthRatio); } topLeftCornerSize = topLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100; topRightCornerSize = topRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100; bottomLeftCornerSize = bottomLeftCornerSize * (desiredWidth + desiredHeight) / 2 / 100; bottomRightCornerSize = bottomRightCornerSize * (desiredWidth + desiredHeight) / 2 / 100; float cropX = (float)((sourceWidth - desiredWidth) / 2); float cropY = (float)((sourceHeight - desiredHeight) / 2); Bitmap bitmap = Bitmap.CreateBitmap((int)desiredWidth, (int)desiredHeight, Bitmap.Config.Argb8888); using (Canvas canvas = new Canvas(bitmap)) using (Paint paint = new Paint()) using (BitmapShader shader = new BitmapShader(source, Shader.TileMode.Clamp, Shader.TileMode.Clamp)) using (Matrix matrix = new Matrix()) using (var path = new Path()) { if (cropX != 0 || cropY != 0) { matrix.SetTranslate(-cropX, -cropY); shader.SetLocalMatrix(matrix); } paint.SetShader(shader); paint.AntiAlias = true; // TopLeft if (cornersTransformType.HasFlag(CornerTransformType.TopLeftCut)) { path.MoveTo(0, (float)topLeftCornerSize); path.LineTo((float)topLeftCornerSize, 0); } else if (cornersTransformType.HasFlag(CornerTransformType.TopLeftRounded)) { path.MoveTo(0, (float)topLeftCornerSize); path.QuadTo(0, 0, (float)topLeftCornerSize, 0); } else { path.MoveTo(0, 0); } // TopRight if (cornersTransformType.HasFlag(CornerTransformType.TopRightCut)) { path.LineTo((float)(desiredWidth - topRightCornerSize), 0); path.LineTo((float)desiredWidth, (float)topRightCornerSize); } else if (cornersTransformType.HasFlag(CornerTransformType.TopRightRounded)) { path.LineTo((float)(desiredWidth - topRightCornerSize), 0); path.QuadTo((float)desiredWidth, 0, (float)desiredWidth, (float)topRightCornerSize); } else { path.LineTo((float)desiredWidth ,0); } // BottomRight if (cornersTransformType.HasFlag(CornerTransformType.BottomRightCut)) { path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize)); path.LineTo((float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight); } else if (cornersTransformType.HasFlag(CornerTransformType.BottomRightRounded)) { path.LineTo((float)desiredWidth, (float)(desiredHeight - bottomRightCornerSize)); path.QuadTo((float)desiredWidth, (float)desiredHeight, (float)(desiredWidth - bottomRightCornerSize), (float)desiredHeight); } else { path.LineTo((float)desiredWidth, (float)desiredHeight); } // BottomLeft if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftCut)) { path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight); path.LineTo(0, (float)(desiredHeight - bottomLeftCornerSize)); } else if (cornersTransformType.HasFlag(CornerTransformType.BottomLeftRounded)) { path.LineTo((float)bottomLeftCornerSize, (float)desiredHeight); path.QuadTo(0, (float)desiredHeight, 0, (float)(desiredHeight - bottomLeftCornerSize)); } else { path.LineTo(0, (float)desiredHeight); } path.Close(); canvas.DrawPath(path, paint); return bitmap; } }
protected override void OnDraw(Canvas canvas) { canvas.DrawColor(Color.Transparent); paint.Reset(); paint.AntiAlias = true; float midX, midY, radius, innerRadius; path.Reset(); float currentAngle = 270; float currentSweep; float totalValue = 0; float padding = 2; midX = Width / 2; midY = Height/2; if (midX < midY){ radius = midX; } else { radius = midY; } radius -= padding; innerRadius = radius - thickness; foreach (PieSlice slice in slices) { totalValue += slice.getValue(); } int count = 0; foreach (PieSlice slice in slices) { Path p = new Path(); paint.Color = slice.getColor (); currentSweep = (slice.getValue()/totalValue)*(360); p.ArcTo(new RectF(midX-radius, midY-radius, midX+radius, midY+radius), currentAngle+padding, currentSweep - padding); p.ArcTo(new RectF(midX-innerRadius, midY-innerRadius, midX+innerRadius, midY+innerRadius), (currentAngle+padding) + (currentSweep - padding), -(currentSweep-padding)); p.Close (); slice.setPath(p); slice.setRegion(new Region((int)(midX-radius), (int)(midY-radius), (int)(midX+radius), (int)(midY+radius))); canvas.DrawPath(p, paint); if (indexSelected == count && listener != null){ path.Reset(); paint.Color = slice.getColor (); paint.Color = Color.ParseColor ("#33B5E5"); paint.Alpha=100; if (slices.Count > 1) { path.ArcTo(new RectF(midX-radius-(padding*2), midY-radius-(padding*2), midX+radius+(padding*2), midY+radius+(padding*2)), currentAngle, currentSweep+padding); path.ArcTo(new RectF(midX-innerRadius+(padding*2), midY-innerRadius+(padding*2), midX+innerRadius-(padding*2), midY+innerRadius-(padding*2)), currentAngle + currentSweep + padding, -(currentSweep + padding)); path.Close(); } else { path.AddCircle(midX, midY, radius+padding, Android.Graphics.Path.Direction.Cw); } canvas.DrawPath(path, paint); paint.Alpha=255; } currentAngle = currentAngle+currentSweep; count++; } }
protected override void OnDraw(Canvas canvas) { base.OnDraw (canvas); if (mViewPager == null) { return; } int count = mViewPager.Adapter.Count; if (count == 0) { return; } //Calculate views bounds var bounds = CalculateAllBounds(mPaintText); int boundsSize = bounds.Count; //Make sure we're on a page that still exists if (mCurrentPage >= boundsSize) { SetCurrentItem(boundsSize - 1); return; } int countMinusOne = count - 1; float halfWidth = Width / 2f; int left = Left; float leftClip = left + mClipPadding; int width = Width; int height = Height; int right = left + width; float rightClip = right - mClipPadding; int page = mCurrentPage; float offsetPercent; if (mCurrentOffset <= halfWidth) { offsetPercent = 1.0f * mCurrentOffset / width; } else { page += 1; offsetPercent = 1.0f * (width - mCurrentOffset) / width; } bool currentSelected = (offsetPercent <= SELECTION_FADE_PERCENTAGE); bool currentBold = (offsetPercent <= BOLD_FADE_PERCENTAGE); float selectedPercent = (SELECTION_FADE_PERCENTAGE - offsetPercent) / SELECTION_FADE_PERCENTAGE; //Verify if the current view must be clipped to the screen RectF curPageBound = bounds[mCurrentPage]; float curPageWidth = curPageBound.Right - curPageBound.Left; if (curPageBound.Left < leftClip) { //Try to clip to the screen (left side) ClipViewOnTheLeft(curPageBound, curPageWidth, left); } if (curPageBound.Right > rightClip) { //Try to clip to the screen (right side) ClipViewOnTheRight(curPageBound, curPageWidth, right); } //Left views starting from the current position if (mCurrentPage > 0) { for (int i = mCurrentPage - 1; i >= 0; i--) { RectF bound = bounds[i]; //Is left side is outside the screen if (bound.Left < leftClip) { float w = bound.Right - bound.Left; //Try to clip to the screen (left side) ClipViewOnTheLeft(bound, w, left); //Except if there's an intersection with the right view RectF rightBound = bounds[i + 1]; //Intersection if (bound.Right + mTitlePadding > rightBound.Left) { bound.Left = rightBound.Left - w - mTitlePadding; bound.Right = bound.Left + w; } } } } //Right views starting from the current position if (mCurrentPage < countMinusOne) { for (int i = mCurrentPage + 1 ; i < count; i++) { RectF bound = bounds[i]; //If right side is outside the screen if (bound.Right > rightClip) { float w = bound.Right - bound.Left; //Try to clip to the screen (right side) ClipViewOnTheRight(bound, w, right); //Except if there's an intersection with the left view RectF leftBound = bounds[i - 1]; //Intersection if (bound.Left - mTitlePadding < leftBound.Right) { bound.Left = leftBound.Right + mTitlePadding; bound.Right = bound.Left + w; } } } } //Now draw views //int colorTextAlpha = mColorText >>> 24; int colorTextAlpha = mColorText >> 24; for (int i = 0; i < count; i++) { //Get the title RectF bound = bounds[i]; //Only if one side is visible if ((bound.Left > left && bound.Left < right) || (bound.Right > left && bound.Right < right)) { bool currentPage = (i == page); //Only set bold if we are within bounds mPaintText.FakeBoldText = (currentPage && currentBold && mBoldText); //Draw text as unselected mPaintText.Color = (mColorText); if(currentPage && currentSelected) { //Fade out/in unselected text as the selected text fades in/out mPaintText.Alpha = (colorTextAlpha - (int)(colorTextAlpha * selectedPercent)); } canvas.DrawText(mTitleProvider.GetTitle(i), bound.Left, bound.Bottom + mTopPadding, mPaintText); //If we are within the selected bounds draw the selected text if (currentPage && currentSelected) { mPaintText.Color = mColorSelected; mPaintText.Alpha = ((int)((mColorSelected >> 24) * selectedPercent)); canvas.DrawText(mTitleProvider.GetTitle(i), bound.Left, bound.Bottom + mTopPadding, mPaintText); } } } //Draw the footer line mPath = new Path(); mPath.MoveTo(0, height - mFooterLineHeight / 2f); mPath.LineTo(width, height - mFooterLineHeight / 2f); mPath.Close(); canvas.DrawPath(mPath, mPaintFooterLine); switch (mFooterIndicatorStyle) { case IndicatorStyle.Triangle: mPath = new Path(); mPath.MoveTo(halfWidth, height - mFooterLineHeight - mFooterIndicatorHeight); mPath.LineTo(halfWidth + mFooterIndicatorHeight, height - mFooterLineHeight); mPath.LineTo(halfWidth - mFooterIndicatorHeight, height - mFooterLineHeight); mPath.Close(); canvas.DrawPath(mPath, mPaintFooterIndicator); break; case IndicatorStyle.Underline: if (!currentSelected || page >= boundsSize) { break; } RectF underlineBounds = bounds[page]; mPath = new Path(); mPath.MoveTo(underlineBounds.Left - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight); mPath.LineTo(underlineBounds.Right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight); mPath.LineTo(underlineBounds.Right + mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight); mPath.LineTo(underlineBounds.Left - mFooterIndicatorUnderlinePadding, height - mFooterLineHeight - mFooterIndicatorHeight); mPath.Close(); mPaintFooterIndicator.Alpha = ((int)(0xFF * selectedPercent)); canvas.DrawPath(mPath, mPaintFooterIndicator); mPaintFooterIndicator.Alpha = (0xFF); break; } }
protected override void OnDraw(Canvas canvas) { base.OnDraw(canvas); switch(mShape) { case Shape.TRIANGLE: { if (mIsLoading) { mAnimPercent += 0.1611113f; Path path = new Path(); path.MoveTo(RelativeXFromView(0.5f), RelativeYFromView(0.5f)); if (mAnimPercent >= 1) { mShape = Shape.CIRCLE; mIsLoading = false; mAnimPercent = 1; } float controlX = mControlX - RelativeXFromView(mAnimPercent * triangle2Circle) * genhao3; float controlY = mControlY - RelativeYFromView(mAnimPercent * triangle2Circle); path.QuadTo(RelativeXFromView(1) - controlX, controlY, RelativeXFromView(0.5f + genhao3 / 4), RelativeYFromView(0.75f)); path.QuadTo(RelativeXFromView(0.5f), RelativeYFromView(0.75f + 2 * mAnimPercent * triangle2Circle), RelativeXFromView(0.5f - genhao3 / 4), RelativeYFromView(0.75f)); path.QuadTo(controlX, controlY, RelativeXFromView(0.5f), RelativeYFromView(0f)); path.Close(); canvas.DrawPath(path, mPaint); Invalidate(); } else { Path path = new Path(); mPaint.Color = Resources.GetColor(Resource.Color.triangle); path.MoveTo(RelativeXFromView(0.5f), RelativeYFromView(0f)); path.LineTo(RelativeXFromView(1), RelativeYFromView(genhao3 / 2f)); path.LineTo(RelativeXFromView(0), RelativeYFromView(genhao3 / 2f)); mControlX = RelativeXFromView(0.5f - genhao3 / 8f); mControlY = RelativeYFromView(3 / 8f); mAnimPercent = 0; path.Close(); canvas.DrawPath(path, mPaint); } } break; case Shape.CIRCLE: { if(mIsLoading) { float magicNumber = mMagicNumber + mAnimPercent; mAnimPercent += 0.12f; if(magicNumber + mAnimPercent > 1.9f) { mShape = Shape.RECT; mIsLoading = false; } Path path = new Path(); path.MoveTo(RelativeXFromView(0.5f), RelativeYFromView(0f)); path.CubicTo(RelativeXFromView(0.5f + magicNumber / 2), RelativeYFromView(0f), RelativeXFromView(1), RelativeYFromView(0.5f - magicNumber / 2), RelativeXFromView(1f), RelativeYFromView(0.5f)); path.CubicTo(RelativeXFromView(1), RelativeXFromView(0.5f + magicNumber / 2), RelativeXFromView(0.5f + mMagicNumber / 2), RelativeYFromView(1f), RelativeXFromView(0.5f), RelativeYFromView(1f)); path.CubicTo(RelativeXFromView(0.5f - magicNumber / 2), RelativeXFromView(1f), RelativeXFromView(0), RelativeYFromView(0.5f + magicNumber / 2), RelativeXFromView(0f), RelativeYFromView(0.5f)); path.CubicTo(RelativeXFromView(0f), RelativeXFromView(0.5f - magicNumber / 2), RelativeXFromView(0.5f - magicNumber / 2), RelativeYFromView(0), RelativeXFromView(0.5f), RelativeYFromView(0f)); path.Close(); canvas.DrawPath(path, mPaint); Invalidate(); } else { mPaint.Color = Resources.GetColor(Resource.Color.circle); Path path = new Path(); float magicNumber = mMagicNumber; path.MoveTo(RelativeXFromView(0.5f), RelativeYFromView(0f)); path.CubicTo(RelativeXFromView(0.5f + magicNumber / 2), 0, RelativeXFromView(1), RelativeYFromView(magicNumber / 2), RelativeXFromView(1f), RelativeYFromView(0.5f)); path.CubicTo( RelativeXFromView(1), RelativeXFromView(0.5f + magicNumber / 2), RelativeXFromView(0.5f + magicNumber / 2), RelativeYFromView(1f), RelativeXFromView(0.5f), RelativeYFromView(1f)); path.CubicTo(RelativeXFromView(0.5f - magicNumber / 2), RelativeXFromView(1f), RelativeXFromView(0), RelativeYFromView(0.5f + magicNumber / 2), RelativeXFromView(0f), RelativeYFromView(0.5f)); path.CubicTo(RelativeXFromView(0f), RelativeXFromView(0.5f - magicNumber / 2), RelativeXFromView(0.5f - magicNumber / 2), RelativeYFromView(0), RelativeXFromView(0.5f), RelativeYFromView(0f)); mAnimPercent = 0; path.Close(); canvas.DrawPath(path, mPaint); } } break; case Shape.RECT: { if(mIsLoading) { mAnimPercent += 0.15f; if(mAnimPercent >= 1) { mShape = Shape.TRIANGLE; mIsLoading = false; mAnimPercent = 1; } Path path = new Path(); path.MoveTo(RelativeXFromView(0.5f * mAnimPercent), 0); path.LineTo(RelativeYFromView(1 - 0.5f * mAnimPercent), 0); float distanceX = (mControlX) * mAnimPercent; float distanceY = (RelativeYFromView(1f) - mControlY) * mAnimPercent; path.LineTo(RelativeXFromView(1f) - distanceX, RelativeYFromView(1f) - distanceY); path.LineTo(RelativeXFromView(0f) + distanceX, RelativeYFromView(1f) - distanceY); path.Close(); canvas.DrawPath(path, mPaint); Invalidate(); } else { mPaint.Color = Resources.GetColor(Resource.Color.rect); mControlX = RelativeXFromView(0.5f - genhao3 / 4); mControlY = RelativeYFromView(0.75f); Path path = new Path(); path.MoveTo(RelativeXFromView(0f), RelativeYFromView(0f)); path.LineTo(RelativeXFromView(1f), RelativeYFromView(0f)); path.LineTo(RelativeXFromView(1f), RelativeYFromView(1f)); path.LineTo(RelativeXFromView(0f), RelativeYFromView(1f)); path.Close(); mAnimPercent = 0; canvas.DrawPath(path, mPaint); } } break; } }
public static APath AsAndroidPath(this PathF path) { var nativePath = new APath(); int pointIndex = 0; int arcAngleIndex = 0; int arcClockwiseIndex = 0; foreach (var operation in path.PathOperations) { if (operation == PathOperation.MoveTo) { var point = path[pointIndex++]; nativePath.MoveTo(point.X, point.Y); } else if (operation == PathOperation.Line) { var point = path[pointIndex++]; nativePath.LineTo(point.X, point.Y); } else if (operation == PathOperation.Quad) { var controlPoint = path[pointIndex++]; var point = path[pointIndex++]; nativePath.QuadTo(controlPoint.X, controlPoint.Y, point.X, point.Y); } else if (operation == PathOperation.Cubic) { var controlPoint1 = path[pointIndex++]; var controlPoint2 = path[pointIndex++]; var point = path[pointIndex++]; nativePath.CubicTo(controlPoint1.X, controlPoint1.Y, controlPoint2.X, controlPoint2.Y, point.X, point.Y); } else if (operation == PathOperation.Arc) { var topLeft = path[pointIndex++]; var bottomRight = path[pointIndex++]; var startAngle = path.GetArcAngle(arcAngleIndex++); var endAngle = path.GetArcAngle(arcAngleIndex++); var clockwise = path.IsArcClockwise(arcClockwiseIndex++); while (startAngle < 0) { startAngle += 360; } while (endAngle < 0) { endAngle += 360; } var rect = new RectF(topLeft.X, topLeft.Y, bottomRight.X, bottomRight.Y); var sweep = GraphicsOperations.GetSweep(startAngle, endAngle, clockwise); startAngle *= -1; if (!clockwise) { sweep *= -1; } nativePath.ArcTo(rect, startAngle, sweep); } else if (operation == PathOperation.Close) { nativePath.Close(); } } return(nativePath); }
protected override void OnDraw(Canvas ca) { if (fullImage == null || shouldUpdate) { fullImage = Bitmap.CreateBitmap (Width, Height, Bitmap.Config.Argb8888); Canvas canvas = new Canvas(fullImage); String max = (int)maxY+"";// used to display max String min = (int)minY+"";// used to display min paint.Reset (); Path path = new Path(); float bottomPadding = 1, topPadding = 0; float sidePadding = 10; if (this.showMinAndMax) sidePadding = txtPaint.MeasureText(max); float usableHeight = Height - bottomPadding - topPadding; float usableWidth = Width - sidePadding*2; float lineSpace = usableHeight/10; int lineCount = 0; foreach (Line line in lines) { int count = 0; float lastXPixels = 0, newYPixels; float lastYPixels = 0, newXPixels; float maxYd = getMaxY (); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); if (lineCount == lineToFill){ paint.Color = Color.White; paint.Alpha = 30; paint.StrokeWidth = 2; for (int i = 10; i-Width < Height; i = i+20){ canvas.DrawLine(i, Height-bottomPadding, 0, Height-bottomPadding-i, paint); } paint.Reset(); paint.SetXfermode (new PorterDuffXfermode (Android.Graphics.PorterDuff.Mode.Clear)); foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY()-minY)/(maxYd - minYd); float xPercent = (p.getX()-minX)/(maxXd - minXd); if (count == 0){ lastXPixels = sidePadding + (xPercent*usableWidth); lastYPixels = Height - bottomPadding - (usableHeight*yPercent); path.MoveTo(lastXPixels, lastYPixels); } else { newXPixels = sidePadding + (xPercent*usableWidth); newYPixels = Height - bottomPadding - (usableHeight*yPercent); path.LineTo(newXPixels, newYPixels); Path pa = new Path(); pa.MoveTo(lastXPixels, lastYPixels); pa.LineTo(newXPixels, newYPixels); pa.LineTo(newXPixels, 0); pa.LineTo(lastXPixels, 0); pa.Close(); canvas.DrawPath(pa, paint); lastXPixels = newXPixels; lastYPixels = newYPixels; } count++; } path.Reset(); path.MoveTo(0, Height-bottomPadding); path.LineTo(sidePadding, Height-bottomPadding); path.LineTo(sidePadding, 0); path.LineTo(0, 0); path.Close(); canvas.DrawPath(path, paint); path.Reset(); path.MoveTo(Width, Height-bottomPadding); path.LineTo(Width-sidePadding, Height-bottomPadding); path.LineTo(Width-sidePadding, 0); path.LineTo(Width, 0); path.Close(); canvas.DrawPath(path, paint); } lineCount++; } paint.Reset(); paint.Color = Color.White; //paint.setColor(this.gridColor); paint.Alpha = 50; paint.AntiAlias = true; canvas.DrawLine(sidePadding, Height - bottomPadding, Width, Height-bottomPadding, paint); if(this.showHorizontalGrid1) for(int i=1;i<=10;i++) { canvas.DrawLine(sidePadding, Height - bottomPadding-(i*lineSpace), Width, Height-bottomPadding-(i*lineSpace), paint); } paint.Alpha = 255; foreach (Line line in lines) { int count = 0; float lastXPixels = 0, newYPixels; float lastYPixels = 0, newXPixels; float maxYd = getMaxY(); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); paint.Color = Color.Yellow; //paint.setColor(line.getColor()); paint.StrokeWidth = 6; foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY()-minY)/(maxYd - minYd); float xPercent = (p.getX()-minX)/(maxXd - minXd); if (count == 0){ lastXPixels = sidePadding + (xPercent*usableWidth); lastYPixels = Height - bottomPadding - (usableHeight*yPercent); } else { newXPixels = sidePadding + (xPercent*usableWidth); newYPixels = Height - bottomPadding - (usableHeight*yPercent); canvas.DrawLine(lastXPixels, lastYPixels, newXPixels, newYPixels, paint); lastXPixels = newXPixels; lastYPixels = newYPixels; } count++; } } int pointCount = 0; foreach (Line line in lines) { float maxYd = getMaxY(); float minYd = getMinY(); float maxXd = getMaxX(); float minXd = getMinX(); paint.Color = Color.Yellow; //paint.setColor(line.getColor()); paint.StrokeWidth = 6; paint.StrokeCap = Paint.Cap.Round; if (line.isShowingPoints()){ foreach (LinePoint p in line.getPoints()) { float yPercent = (p.getY()-minYd)/(maxYd - minYd); float xPercent = (p.getX()-minXd)/(maxXd - minXd); float xPixels = sidePadding + (xPercent*usableWidth); float yPixels = Height - bottomPadding - (usableHeight*yPercent); paint.Color = Color.Gray; canvas.DrawCircle(xPixels, yPixels, 10, paint); paint.Color = Color.White; canvas.DrawCircle(xPixels, yPixels, 5, paint); Path path2 = new Path(); path2.AddCircle(xPixels, yPixels, 30, Android.Graphics.Path.Direction.Cw); p.setPath(path2); p.setRegion(new Region((int)(xPixels-30), (int)(yPixels-30), (int)(xPixels+30), (int)(yPixels+30))); if (indexSelected == pointCount && listener != null){ paint.Color=Color.ParseColor("#33B5E5"); paint.Alpha = 100; canvas.DrawPath(p.getPath(), paint); paint.Alpha = 255; } pointCount++; } } } shouldUpdate = false; if (this.showMinAndMax) { ca.DrawText(max, 0, txtPaint.TextSize, txtPaint); ca.DrawText(min,0,this.Height,txtPaint); } } ca.DrawBitmap(fullImage, 0, 0, null); }
public override void Draw(Canvas canvas) { var w = width / (Count - 2); var path = new Path (); path.MoveTo (0, height - u1 [0]); for (int i = 1; i < Count; i += 3) { path.CubicTo (i * w, height - u1 [Math.Min (Count - 1, i)], (i + 1) * w, height - u1 [Math.Min (Count - 1, i + 1)], (i + 2) * w, height - u1 [Math.Min (Count - 1, i + 2)]); } path.LineTo (width, height); path.LineTo (0, height); path.Close (); canvas.DrawPath (path, paint); if (bubblesEnabled) DrawBubbles (canvas, w); }
protected override void OnDraw(Canvas canvas) { var rect = new Rect(); this.GetDrawingRect(rect); var path = new Android.Graphics.Path(); var lastPoint = new PointF(); foreach (var command in PathDataParser.Parse(Element.Data)) { switch (command.Type) { case PathDataParser.CommandType.MoveTo: lastPoint = new PointF(command.Arguments[0], command.Arguments[1]); path.MoveTo(lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.LineTo: lastPoint = new PointF(command.Arguments[0], command.Arguments[1]); path.LineTo(lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.LineHor: lastPoint = new PointF(command.Arguments[0], lastPoint.Y); path.LineTo(lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.LineVer: lastPoint = new PointF(lastPoint.X, command.Arguments[0]); path.LineTo(lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.RelativeLineHor: lastPoint = new PointF(command.Arguments[0] + lastPoint.X, lastPoint.Y); path.LineTo(lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.RelativeLineVer: lastPoint = new PointF(lastPoint.X, lastPoint.Y + command.Arguments[0]); path.LineTo(lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.RelativeLineTo: lastPoint = new PointF(lastPoint.X + command.Arguments[0], lastPoint.Y + command.Arguments[1]); path.LineTo(lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.RelativeMoveTo: lastPoint = new PointF(lastPoint.X + command.Arguments[0], lastPoint.Y + command.Arguments[1]); path.MoveTo(lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.QBezier: path.QuadTo(command.Arguments[0], command.Arguments[1], command.Arguments[2], command.Arguments[3]); lastPoint = new PointF(command.Arguments[2], command.Arguments[3]); break; case PathDataParser.CommandType.Bezier: path.CubicTo( command.Arguments[0], command.Arguments[1], command.Arguments[2], command.Arguments[3], command.Arguments[4], command.Arguments[5]); lastPoint = new PointF(command.Arguments[4], command.Arguments[5]); break; case PathDataParser.CommandType.RelativeBezier: var p1 = new PointF(lastPoint.X + command.Arguments[0], lastPoint.Y + command.Arguments[1]); var p2 = new PointF(p1.X + command.Arguments[2], p1.Y + command.Arguments[3]); lastPoint = new PointF(p2.X + command.Arguments[4], p2.Y + command.Arguments[5]); path.CubicTo(p1.X, p1.Y, p2.X, p2.Y, lastPoint.X, lastPoint.Y); break; case PathDataParser.CommandType.Close: path.Close(); break; } } var paint = new Paint(PaintFlags.AntiAlias); paint.StrokeWidth = Element.StrokeThickness; paint.StrokeMiter = 10f; canvas.Save(); paint.SetStyle(Paint.Style.Stroke); paint.Color = Element.Stroke.ToAndroid(); canvas.DrawPath(path, paint); canvas.Restore(); }
public void triangle(double x1, double y1, double x2, double y2, double x3, double y3) { var path = new Path (); path.MoveTo ((float) x3, (float) y3); path.LineTo ((float) x1, (float) y1); path.LineTo ((float) x2, (float) y2); path.LineTo ((float) x3, (float) y3); path.Close (); Host.DrawPath (path, HostPaint); }