Example #1
0
        private Path CreateChildPath()
        {
            float bezierOffset = mChildOvalRadius * OVAL_BEZIER_FACTOR;

            Path path = new Path();

            path.MoveTo(mChildPosition[0], mChildPosition[1] - mChildOvalRadius);
            //left_top arc
            path.CubicTo(mChildPosition[0] - bezierOffset - mChildLeftXOffset, mChildPosition[1] - mChildOvalRadius, mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1] - bezierOffset + mChildLeftYOffset, mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1]);
            //left_bottom arc
            path.CubicTo(mChildPosition[0] - mChildOvalRadius - mChildLeftXOffset, mChildPosition[1] + bezierOffset - mChildLeftYOffset, mChildPosition[0] - bezierOffset - mChildLeftXOffset, mChildPosition[1] + mChildOvalRadius, mChildPosition[0], mChildPosition[1] + mChildOvalRadius);

            //right_bottom arc
            path.CubicTo(mChildPosition[0] + bezierOffset + mChildRightXOffset, mChildPosition[1] + mChildOvalRadius, mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1] + bezierOffset - mChildRightYOffset, mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1]);
            //right_top arc
            path.CubicTo(mChildPosition[0] + mChildOvalRadius + mChildRightXOffset, mChildPosition[1] - bezierOffset + mChildRightYOffset, mChildPosition[0] + bezierOffset + mChildRightXOffset, mChildPosition[1] - mChildOvalRadius, mChildPosition[0], mChildPosition[1] - mChildOvalRadius);

            return(path);
        }
Example #2
0
        private Path CreateLinkPath()
        {
            Path  path         = new Path();
            float bezierOffset = mMotherOvalHalfWidth * OVAL_BEZIER_FACTOR;

            float distance = (float)Math.Sqrt(Math.Pow(mMotherPosition[0] - mChildPosition[0], 2.0f) + Math.Pow(mMotherPosition[1] - mChildPosition[1], 2.0f));

            if (distance <= mMotherOvalHalfWidth + mChildOvalRadius * 1.2f && distance >= mMotherOvalHalfWidth - mChildOvalRadius * 1.2f)
            {
                float maxOffsetY = 2 * mChildOvalRadius * 1.2f;
                float offsetRate = (distance - (mMotherOvalHalfWidth - mChildOvalRadius * 1.2f)) / maxOffsetY;

                float mMotherOvalOffsetY = mMotherOvalHalfHeight - offsetRate * (mMotherOvalHalfHeight - mChildOvalRadius) * 0.85f;

                mMotherOvalPath.AddOval(new RectF(mMotherPosition[0] - mMotherOvalHalfWidth, mMotherPosition[1] - mMotherOvalOffsetY, mMotherPosition[0] + mMotherOvalHalfWidth, mMotherPosition[1] + mMotherOvalOffsetY), Path.Direction.Cw);

                float mMotherXOffset     = distance - mMotherOvalHalfWidth + mChildOvalRadius;
                float distanceUltraLeft  = (float)Math.Sqrt(Math.Pow(mMotherPosition[0] - mMotherOvalHalfWidth - mChildPosition[0], 2.0f) + Math.Pow(mMotherPosition[1] - mChildPosition[1], 2.0f));
                float distanceUltraRight = (float)Math.Sqrt(Math.Pow(mMotherPosition[0] + mMotherOvalHalfWidth - mChildPosition[0], 2.0f) + Math.Pow(mMotherPosition[1] - mChildPosition[1], 2.0f));

                path.MoveTo(mMotherPosition[0], mMotherPosition[1] + mMotherOvalOffsetY);
                if (distanceUltraRight < distanceUltraLeft)
                {
                    //right_bottom arc
                    path.CubicTo(mMotherPosition[0] + bezierOffset + mMotherXOffset, mMotherPosition[1] + mMotherOvalOffsetY, mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1] + mChildOvalRadius * 1.5f, mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1]);
                    //right_top arc
                    path.CubicTo(mMotherPosition[0] + distance + mChildOvalRadius, mMotherPosition[1] - mChildOvalRadius * 1.5f, mMotherPosition[0] + bezierOffset + mMotherXOffset, mMotherPosition[1] - mMotherOvalOffsetY, mMotherPosition[0], mMotherPosition[1] - mMotherOvalOffsetY);
                }
                else
                {
                    //left_bottom arc
                    path.CubicTo(mMotherPosition[0] - bezierOffset - mMotherXOffset, mMotherPosition[1] + mMotherOvalOffsetY, mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1] + mChildOvalRadius * 1.5f, mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1]);
                    //left_top arc
                    path.CubicTo(mMotherPosition[0] - distance - mChildOvalRadius, mMotherPosition[1] - mChildOvalRadius * 1.5f, mMotherPosition[0] - bezierOffset - mMotherXOffset, mMotherPosition[1] - mMotherOvalOffsetY, mMotherPosition[0], mMotherPosition[1] - mMotherOvalOffsetY);
                }
                path.LineTo(mMotherPosition[0], mMotherPosition[1] + mMotherOvalOffsetY);
            }

            return(path);
        }
        /// <summary>
        /// Coordinates are approximate, you have better cooperate with the designer's design draft
        /// </summary>
        private Path CreateBalloonPath(RectF balloonRect, float progress)
        {
            Path path = new Path();

            path.MoveTo(balloonRect.CenterX(), balloonRect.Bottom);

            float progressWidth  = balloonRect.Width() * progress;
            float progressHeight = balloonRect.Height() * progress;
            //draw left half
            float leftIncrementX1 = progressWidth * -0.48f;
            float leftIncrementY1 = progressHeight * 0.75f;
            float leftIncrementX2 = progressWidth * -0.03f;
            float leftIncrementY2 = progressHeight * -1.6f;
            float leftIncrementX3 = progressWidth * 0.9f;
            float leftIncrementY3 = progressHeight * -1.0f;

            path.CubicTo(balloonRect.Left + balloonRect.Width() * 0.25f + leftIncrementX1, balloonRect.CenterY() - balloonRect.Height() * 0.4f + leftIncrementY1, balloonRect.Left - balloonRect.Width() * 0.20f + leftIncrementX2, balloonRect.CenterY() + balloonRect.Height() * 1.15f + leftIncrementY2, balloonRect.Left - balloonRect.Width() * 0.4f + leftIncrementX3, balloonRect.Bottom + leftIncrementY3);

            //        the results of the left final transformation
            //        path.cubicTo(balloonRect.left - balloonRect.width() * 0.13f, balloonRect.CenterY() + balloonRect.height() * 0.35f,
            //                balloonRect.left - balloonRect.width() * 0.23f, balloonRect.CenterY() - balloonRect.height() * 0.45f,
            //                balloonRect.left + balloonRect.width() * 0.5f, balloonRect.bottom - balloonRect.height());

            //draw right half
            float rightIncrementX1 = progressWidth * 1.51f;
            float rightIncrementY1 = progressHeight * -0.05f;
            float rightIncrementX2 = progressWidth * 0.03f;
            float rightIncrementY2 = progressHeight * 0.5f;
            float rightIncrementX3 = 0.0f;
            float rightIncrementY3 = 0.0f;

            path.CubicTo(balloonRect.Left - balloonRect.Width() * 0.38f + rightIncrementX1, balloonRect.CenterY() - balloonRect.Height() * 0.4f + rightIncrementY1, balloonRect.Left + balloonRect.Width() * 1.1f + rightIncrementX2, balloonRect.CenterY() - balloonRect.Height() * 0.15f + rightIncrementY2, balloonRect.Left + balloonRect.Width() * 0.5f + rightIncrementX3, balloonRect.Bottom + rightIncrementY3);

            //        the results of the right final transformation
            //        path.cubicTo(balloonRect.left + balloonRect.width() * 1.23f, balloonRect.CenterY() - balloonRect.height() * 0.45f,
            //                balloonRect.left + balloonRect.width() * 1.13f, balloonRect.CenterY() + balloonRect.height() * 0.35f,
            //                balloonRect.left + balloonRect.width() * 0.5f, balloonRect.bottom);

            return(path);
        }
Example #4
0
		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);
		}
Example #5
0
        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);
        }
Example #6
0
        private Path CreateChildMovePath()
        {
            Path path = new Path();

            float CenterX           = mCurrentBounds.CenterX();
            float CenterY           = mCurrentBounds.CenterY();
            float currentPathLength = 0.0f;

            //start
            path.MoveTo(CenterX, CenterY);
            //pre forward top left
            path.LineTo(CenterX + mMotherOvalHalfWidth * 0.75f, CenterY);
            mStageChildPreForwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildPreForwardTopLeftLength;
            //forward top left
            path.QuadTo(CenterX - mMotherOvalHalfWidth * 0.5f, CenterY, CenterX - mMotherOvalHalfWidth * 2.0f, CenterY - mMotherOvalHalfHeight);
            mStageChildForwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildForwardTopLeftLength;
            //pre backward top left
            path.LineTo(CenterX - mMotherOvalHalfWidth * 2.0f + mMotherOvalHalfWidth * 0.2f, CenterY - mMotherOvalHalfHeight);
            path.QuadTo(CenterX - mMotherOvalHalfWidth * 2.5f, CenterY - mMotherOvalHalfHeight * 2, CenterX - mMotherOvalHalfWidth * 1.5f, CenterY - mMotherOvalHalfHeight * 2.25f);
            mStageChildPreBackwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildPreBackwardTopLeftLength;
            //backward top left
            path.QuadTo(CenterX - mMotherOvalHalfWidth * 0.2f, CenterY - mMotherOvalHalfHeight * 2.25f, CenterX, CenterY);
            mStageChildBackwardTopLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildBackwardTopLeftLength;
            //forward bottom left
            path.CubicTo(CenterX, CenterY + mMotherOvalHalfHeight, CenterX - mMotherOvalHalfWidth, CenterY + mMotherOvalHalfHeight * 2.5f, CenterX - mMotherOvalHalfWidth * 1.5f, CenterY + mMotherOvalHalfHeight * 2.5f);
            mStageChildForwardBottomLeftLength = GetRestLength(path, currentPathLength);
            currentPathLength += mStageChildForwardBottomLeftLength;
            //backward bottom left
            path.CubicTo(CenterX - mMotherOvalHalfWidth * 2.0f, CenterY + mMotherOvalHalfHeight * 2.5f, CenterX - mMotherOvalHalfWidth * 3.0f, CenterY + mMotherOvalHalfHeight * 0.8f, CenterX, CenterY);
            mStageChildBackwardBottomLeftLength = GetRestLength(path, currentPathLength);

            return(path);
        }
        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();
        }
Example #8
0
        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);
            }
              }
        }
Example #9
0
        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);
        }
		public DrawerArrowDrawable(Resources resources, Boolean rounded1) {
			rounded = rounded1;
			float density = resources.DisplayMetrics.Density;
			float strokeWidthPixel = STROKE_WIDTH_DP * density;
			halfStrokeWidthPixel = strokeWidthPixel / 2;

			linePaint = new Paint(Android.Graphics.PaintFlags.SubpixelText | Android.Graphics.PaintFlags.AntiAlias);
			linePaint.StrokeCap=rounded ? Android.Graphics.Paint.Cap.Round : Android.Graphics.Paint.Cap.Butt;
			linePaint.Color=Android.Graphics.Color.Black;
			linePaint.SetStyle (Android.Graphics.Paint.Style.Stroke);
			linePaint.StrokeWidth=strokeWidthPixel;

			int dimen = (int) (DIMEN_DP * density);
			bounds = new Rect(0, 0, dimen, dimen);

			Path first, second;
			JoinedPath joinedA, joinedB;

			// Top
			first = new Path();
			first.MoveTo(5.042f, 20f);
			first.RCubicTo(8.125f, -16.317f, 39.753f, -27.851f, 55.49f, -2.765f);
			second = new Path();
			second.MoveTo(60.531f, 17.235f);
			second.RCubicTo(11.301f, 18.015f, -3.699f, 46.083f, -23.725f, 43.456f);
			scalePath(first, density);
			scalePath(second, density);
			joinedA = new JoinedPath(first, second);

			first = new Path();
			first.MoveTo(64.959f, 20f);
			first.RCubicTo(4.457f, 16.75f, 1.512f, 37.982f, -22.557f, 42.699f);
			second = new Path();
			second.MoveTo(42.402f, 62.699f);
			second.CubicTo(18.333f, 67.418f, 8.807f, 45.646f, 8.807f, 32.823f);
			scalePath(first, density);
			scalePath(second, density);
			joinedB = new JoinedPath(first, second);
			topLine = new BridgingLine(joinedA, joinedB);

			// Middle
			first = new Path();
			first.MoveTo(5.042f, 35f);
			first.CubicTo(5.042f, 20.333f, 18.625f, 6.791f, 35f, 6.791f);
			second = new Path();
			second.MoveTo(35f, 6.791f);
			second.RCubicTo(16.083f, 0f, 26.853f, 16.702f, 26.853f, 28.209f);
			scalePath(first, density);
			scalePath(second, density);
			joinedA = new JoinedPath(first, second);

			first = new Path();
			first.MoveTo(64.959f, 35f);
			first.RCubicTo(0f, 10.926f, -8.709f, 26.416f, -29.958f, 26.416f);
			second = new Path();
			second.MoveTo(35f, 61.416f);
			second.RCubicTo(-7.5f, 0f, -23.946f, -8.211f, -23.946f, -26.416f);
			scalePath(first, density);
			scalePath(second, density);
			joinedB = new JoinedPath(first, second);
			middleLine = new BridgingLine(joinedA, joinedB);

			// Bottom
			first = new Path();
			first.MoveTo(5.042f, 50f);
			first.CubicTo(2.5f, 43.312f, 0.013f, 26.546f, 9.475f, 17.346f);
			second = new Path();
			second.MoveTo(9.475f, 17.346f);
			second.RCubicTo(9.462f, -9.2f, 24.188f, -10.353f, 27.326f, -8.245f);
			scalePath(first, density);
			scalePath(second, density);
			joinedA = new JoinedPath(first, second);

			first = new Path();
			first.MoveTo(64.959f, 50f);
			first.RCubicTo(-7.021f, 10.08f, -20.584f, 19.699f, -37.361f, 12.74f);
			second = new Path();
			second.MoveTo(27.598f, 62.699f);
			second.RCubicTo(-15.723f, -6.521f, -18.8f, -23.543f, -18.8f, -25.642f);
			scalePath(first, density);
			scalePath(second, density);
			joinedB = new JoinedPath(first, second);
			bottomLine = new BridgingLine(joinedA, joinedB);
		}
Example #11
0
        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);
                }
            }
        }
Example #12
0
        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);
        }
Example #13
0
        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)
        {
            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;
            }
        }
Example #15
0
        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);
        }
Example #16
0
		void drawLines (Canvas canvas, Paint paint)
		{
			float x, y;

			// Draw curved graph line
			var whiteAlpha25 = Color.Argb (64, 255, 255, 255);
			//var whiteAlpha70 = Color.Argb (64, 255, 255, 255);

			var start = new PointF ();
			var end = new PointF ();

			using (Path path = new Path ()) {


				var count = hourly ? HourlyTemps.Count : (Forecasts.Count * 2);

				for (int i = 0; i < count; i++) {

					// adjusted index
					var ai = i;

					double temp;

					if (hourly) {

						temp = HourlyTemps [ai];

					} else {

						// reset start when switching from highs to lows
						if (i == Forecasts.Count) start = new PointF ();

						var highs = i < Forecasts.Count;

						ai = highs ? i : i - Forecasts.Count;

						temp = highs ? HighTemps [ai] : LowTemps [ai];
					}

					var percent = ((float)temp - scaleLow) / scaleRange;


					x = padding + inset + (ai * scaleX);

					y = graphRect.Bottom - (graphRect.Height () * percent);


					end = new PointF (x, y);


					if (!hourly) {

						path.AddCircle (end.X - lineWidth, end.Y - lineWidth, lineWidth / 2, Path.Direction.Cw);
					}


					if (start.IsEmpty ()) {

						path.MoveTo (end);

					} else {

						path.MoveTo (start);

						if (hourly) {

							path.LineTo (end);

						} else {

							var diff = (end.X - start.X) / 2;

							path.CubicTo (end.X - diff, start.Y, start.X + diff, end.Y, end.X, end.Y);
						}
					}

					start = end;
				}

				paint.Color = whiteAlpha25;
				paint.StrokeWidth = lineWidth;

				paint.SetStyle (Paint.Style.Stroke);

				canvas.DrawPath (path, paint);
			}
		}