Example #1
0
		public Rect TransformRect (Rect rect)
		{
			var bbb = new BoundingBoxBuilder ();
			bbb.Add (TransformPoint (rect.TopLeft));
			bbb.Add (TransformPoint (rect.BottomLeft));
			bbb.Add (TransformPoint (rect.BottomRight));
			bbb.Add (TransformPoint (rect.TopRight));
			return bbb.BoundingBox;
		}
Example #2
0
        public Rect TransformRect(Rect rect)
        {
            var bbb = new BoundingBoxBuilder();

            bbb.Add(TransformPoint(rect.TopLeft));
            bbb.Add(TransformPoint(rect.BottomLeft));
            bbb.Add(TransformPoint(rect.BottomRight));
            bbb.Add(TransformPoint(rect.TopRight));
            return(bbb.BoundingBox);
        }
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            using (var path = new GraphicsPath ()) {

                var bb = new BoundingBoxBuilder ();

                var position = Point.Zero;

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        position = p;
                        bb.Add (p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        path.AddLine (Conversions.GetPointF (position), Conversions.GetPointF (p));
                        position = p;
                        bb.Add (p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null) {
                        var p = at.Point;
                        path.AddLine (Conversions.GetPointF (position), Conversions.GetPointF (p));
                        position = p;
                        bb.Add (p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.AddBezier (Conversions.GetPointF (position), Conversions.GetPointF (c1),
                            Conversions.GetPointF (c2), Conversions.GetPointF (p));
                        position = p;
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null) {
                        path.CloseFigure ();
                        continue;
                    }

                    throw new NotSupportedException ("Path Op " + op);
                }

                var frame = bb.BoundingBox;
                if (brush != null) {
                    graphics.FillPath (brush.GetBrush (frame), path);
                }
                if (pen != null) {
                    var r = Conversions.GetRectangleF (frame);
                    graphics.DrawPath (pen.GetPen (), path);
                }
            }
        }
Example #4
0
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            DrawElement(() => {
                var bb = new BoundingBoxBuilder();

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        if (!IsValid(p.X) || !IsValid(p.Y))
                        {
                            continue;
                        }
                        context.MoveTo((nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        if (!IsValid(p.X) || !IsValid(p.Y))
                        {
                            continue;
                        }
                        context.AddLineToPoint((nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null)
                    {
                        var p = at.Point;
                        if (!IsValid(p.X) || !IsValid(p.Y))
                        {
                            continue;
                        }
                        var pp = Conversions.GetPoint(context.GetPathCurrentPoint());
                        if (pp == p)
                        {
                            continue;
                        }
                        Point c1, c2;
                        at.GetCircles(pp, out c1, out c2);

                        var circleCenter = (at.LargeArc ^ at.SweepClockwise) ? c1 : c2;

                        var startAngle = (float)Math.Atan2(pp.Y - circleCenter.Y, pp.X - circleCenter.X);
                        var endAngle   = (float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X);

                        if (!IsValid(circleCenter.X) || !IsValid(circleCenter.Y) || !IsValid(startAngle) || !IsValid(endAngle))
                        {
                            context.MoveTo((nfloat)p.X, (nfloat)p.Y);
                            continue;
                        }

                        var clockwise = !at.SweepClockwise;

                        context.AddArc((nfloat)circleCenter.X, (nfloat)circleCenter.Y, (nfloat)at.Radius.Min, startAngle, endAngle, clockwise);

                        bb.Add(p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p = ct.Point;
                        if (!IsValid(p.X) || !IsValid(p.Y))
                        {
                            continue;
                        }
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        if (!IsValid(c1.X) || !IsValid(c1.Y) || !IsValid(c2.X) || !IsValid(c2.Y))
                        {
                            context.MoveTo((nfloat)p.X, (nfloat)p.Y);
                            continue;
                        }
                        context.AddCurveToPoint((nfloat)c1.X, (nfloat)c1.Y, (nfloat)c2.X, (nfloat)c2.Y, (nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null)
                    {
                        context.ClosePath();
                        continue;
                    }

                    throw new NotSupportedException("Path Op " + op);
                }

                return(bb.BoundingBox);
            }, pen, brush);
        }
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            using (var path = new global::Android.Graphics.Path()) {
                var bb = new BoundingBoxBuilder();

                Point?prevPoint = null;

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        path.MoveTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        prevPoint = p;
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        path.LineTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        prevPoint = p;
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null)
                    {
                        var p = at.Point;

                        if (!prevPoint.HasValue)
                        {
                            throw new NotSupportedException("Cannot begin path with Arc.");
                        }

                        var pp = prevPoint.Value;

                        Point c1, c2;
                        at.GetCircles(pp, out c1, out c2);

                        var circleCenter = at.LargeArc ^ !at.SweepClockwise ? c2 : c1;
                        var rect         = new Rect(circleCenter - at.Radius, at.Radius * 2);

                        var startAngle = Conversions.RadToDeg((float)Math.Atan2(pp.Y - circleCenter.Y, pp.X - circleCenter.X));
                        var endAngle   = Conversions.RadToDeg((float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X));

                        var sweepAngle = endAngle - startAngle;

                        if (at.SweepClockwise && sweepAngle < 0)
                        {
                            // If we want to go CW, sweepAngle needs to be positive
                            sweepAngle += 360.0f;
                        }
                        else if (!at.SweepClockwise && sweepAngle > 0)
                        {
                            // If we want to go CCW, sweepAngle needs to be negative
                            sweepAngle -= 360.0f;
                        }

                        path.AddArc(Conversions.GetRectF(rect), startAngle, sweepAngle);

                        bb.Add(p);
                        prevPoint = p;
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p  = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        prevPoint = p;
                        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 paint = GetBrushPaint(brush, frame);
                    graphics.DrawPath(path, paint);
                }
                if (pen != null)
                {
                    var paint = GetPenPaint(pen);
                    graphics.DrawPath(path, paint);
                }
            }
        }
Example #6
0
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            using (var path = new GraphicsPath()) {
                var bb = new BoundingBoxBuilder();

                var position = Point.Zero;

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        position = p;
                        bb.Add(p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        path.AddLine(Conversions.GetPointF(position), Conversions.GetPointF(p));
                        position = p;
                        bb.Add(p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null)
                    {
                        var p = at.Point;
                        path.AddLine(Conversions.GetPointF(position), Conversions.GetPointF(p));
                        position = p;
                        bb.Add(p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p  = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.AddBezier(Conversions.GetPointF(position), Conversions.GetPointF(c1),
                                       Conversions.GetPointF(c2), Conversions.GetPointF(p));
                        position = p;
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null)
                    {
                        path.CloseFigure();
                        continue;
                    }

                    throw new NotSupportedException("Path Op " + op);
                }

                var frame = bb.BoundingBox;
                if (brush != null)
                {
                    graphics.FillPath(brush.GetBrush(frame), path);
                }
                if (pen != null)
                {
                    graphics.DrawPath(pen.GetPen(), path);
                }
            }
        }
Example #7
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            using (var path = new global::Android.Graphics.Path ()) {

                var bb = new BoundingBoxBuilder ();

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        path.MoveTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        path.LineTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        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 ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo ((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        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 paint = GetBrushPaint (brush, frame);
                    graphics.DrawPath (path, paint);
                }
                if (pen != null) {
                    var paint = GetPenPaint (pen);
                    graphics.DrawPath (path, paint);
                }
            }
        }
Example #8
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            DrawElement (() => {

                var bb = new BoundingBoxBuilder ();

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        context.MoveTo ((nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        context.AddLineToPoint ((nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null) {
                        var p = at.Point;
                        var pp = Conversions.GetPoint (context.GetPathCurrentPoint ());
                        Point c1, c2;
                        at.GetCircles (pp, out c1, out c2);

                        var circleCenter = at.LargeArc ^ !at.SweepClockwise ? c2 : c1;

                        var startAngle = (float)Math.Atan2(pp.Y - circleCenter.Y, pp.X - circleCenter.X);
                        var endAngle = (float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X);

                        context.AddArc((nfloat)circleCenter.X, (nfloat)circleCenter.Y, (nfloat)at.Radius.Min, startAngle, endAngle, at.SweepClockwise);

                        bb.Add (p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        context.AddCurveToPoint ((nfloat)c1.X, (nfloat)c1.Y, (nfloat)c2.X, (nfloat)c2.Y, (nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null) {
                        context.ClosePath ();
                        continue;
                    }

                    throw new NotSupportedException ("Path Op " + op);
                }

                return bb.BoundingBox;

            }, pen, brush);
        }
Example #9
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            var bb = new BoundingBoxBuilder ();
            var s = new D2D1.PathGeometry (factories.D2DFactory);
            var figureDepth = 0;
            using (var sink = s.Open ()) {
                foreach (var op in ops) {
                    if (op is MoveTo) {
                        while (figureDepth > 0) {
                            sink.EndFigure (D2D1.FigureEnd.Open);
                            figureDepth--;
                        }
                        var mt = ((MoveTo)op);
                        sink.BeginFigure (Conversions.ToVector2 (mt.Point), D2D1.FigureBegin.Filled);
                        figureDepth++;
                        bb.Add (mt.Point);
                    }
                    else if (op is LineTo) {
                        var lt = ((LineTo)op);
                        sink.AddLine (Conversions.ToVector2 (lt.Point));
                        bb.Add (lt.Point);
                    }
                    else if (op is ArcTo) {
                        var ar = ((ArcTo)op);
                        // TODO: Direct2D Arcs
                        //sink.AddArc (new D2D1.ArcSegment {
                        //	Size = Conversions.ToSize2F (ar.Radius),
                        //	Point = Conversions.ToVector2 (ar.Point),
                        //	SweepDirection = ar.SweepClockwise ? D2D1.SweepDirection.Clockwise : D2D1.SweepDirection.CounterClockwise,
                        //});
                        sink.AddLine (Conversions.ToVector2 (ar.Point));
                        bb.Add (ar.Point);
                    }
                    else if (op is CurveTo) {
                        var ct = ((CurveTo)op);
                        sink.AddBezier (new D2D1.BezierSegment {
                            Point1 = Conversions.ToVector2 (ct.Control1),
                            Point2 = Conversions.ToVector2 (ct.Control2),
                            Point3 = Conversions.ToVector2 (ct.Point),
                        });
                        bb.Add (ct.Point);
                        bb.Add (ct.Control1);
                        bb.Add (ct.Control2);
                    }
                    else if (op is ClosePath) {
                        sink.EndFigure (D2D1.FigureEnd.Closed);
                        figureDepth--;
                    }
                    else {
                        // TODO: More path operations
                    }
                }
                while (figureDepth > 0) {
                    sink.EndFigure (D2D1.FigureEnd.Open);
                    figureDepth--;
                }
                sink.Close ();
            }

            var p = GetBrush (pen);
            var b = GetBrush (bb.BoundingBox, brush);

            if (b != null) {
                renderTarget.FillGeometry (s, b);
            }
            if (p != null) {
                renderTarget.DrawGeometry (s, p, (float)pen.Width, GetStrokeStyle (pen));
            }
        }
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            var bb          = new BoundingBoxBuilder();
            var s           = new D2D1.PathGeometry(factories.D2DFactory);
            var figureDepth = 0;

            using (var sink = s.Open()) {
                foreach (var op in ops)
                {
                    if (op is MoveTo)
                    {
                        while (figureDepth > 0)
                        {
                            sink.EndFigure(D2D1.FigureEnd.Open);
                            figureDepth--;
                        }
                        var mt = ((MoveTo)op);
                        sink.BeginFigure(Conversions.ToVector2(mt.Point), D2D1.FigureBegin.Filled);
                        figureDepth++;
                        bb.Add(mt.Point);
                    }
                    else if (op is LineTo)
                    {
                        var lt = ((LineTo)op);
                        sink.AddLine(Conversions.ToVector2(lt.Point));
                        bb.Add(lt.Point);
                    }
                    else if (op is ArcTo)
                    {
                        var ar = ((ArcTo)op);
                        // TODO: Direct2D Arcs
                        //sink.AddArc (new D2D1.ArcSegment {
                        //	Size = Conversions.ToSize2F (ar.Radius),
                        //	Point = Conversions.ToVector2 (ar.Point),
                        //	SweepDirection = ar.SweepClockwise ? D2D1.SweepDirection.Clockwise : D2D1.SweepDirection.CounterClockwise,
                        //});
                        sink.AddLine(Conversions.ToVector2(ar.Point));
                        bb.Add(ar.Point);
                    }
                    else if (op is CurveTo)
                    {
                        var ct = ((CurveTo)op);
                        sink.AddBezier(new D2D1.BezierSegment {
                            Point1 = Conversions.ToVector2(ct.Control1),
                            Point2 = Conversions.ToVector2(ct.Control2),
                            Point3 = Conversions.ToVector2(ct.Point),
                        });
                        bb.Add(ct.Point);
                        bb.Add(ct.Control1);
                        bb.Add(ct.Control2);
                    }
                    else if (op is ClosePath)
                    {
                        sink.EndFigure(D2D1.FigureEnd.Closed);
                        figureDepth--;
                    }
                    else
                    {
                        // TODO: More path operations
                    }
                }
                while (figureDepth > 0)
                {
                    sink.EndFigure(D2D1.FigureEnd.Open);
                    figureDepth--;
                }
                sink.Close();
            }

            var p = GetBrush(pen);
            var b = GetBrush(bb.BoundingBox, brush);

            if (b != null)
            {
                renderTarget.FillGeometry(s, b);
            }
            if (p != null)
            {
                renderTarget.DrawGeometry(s, p, (float)pen.Width, GetStrokeStyle(pen));
            }
        }
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            using (var path = new global::Android.Graphics.Path()) {
                var bb = new BoundingBoxBuilder();

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        path.MoveTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        path.LineTo((float)p.X, (float)p.Y);
                        bb.Add(p);
                        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 ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p  = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        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 paint = GetBrushPaint(brush, frame);
                    graphics.DrawPath(path, paint);
                }
                if (pen != null)
                {
                    var paint = GetPenPaint(pen);
                    graphics.DrawPath(path, paint);
                }
            }
        }
Example #12
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            using (var path = new global::Android.Graphics.Path ()) {

                var bb = new BoundingBoxBuilder ();

                Point? prevPoint = null;

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        path.MoveTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        prevPoint = p;
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        path.LineTo ((float)p.X, (float)p.Y);
                        bb.Add (p);
                        prevPoint = p;
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null) {
                        var p = at.Point;

                        if (!prevPoint.HasValue) {
                            throw new NotSupportedException("Cannot begin path with Arc.");
                        }

                        var pp = prevPoint.Value;

                        Point c1, c2;
                        at.GetCircles(pp, out c1, out c2);

                        var circleCenter = at.LargeArc ^ !at.SweepClockwise ? c2 : c1;
                        var rect = new Rect(circleCenter - at.Radius, at.Radius * 2);

                        var startAngle = Conversions.RadToDeg((float)Math.Atan2(pp.Y - circleCenter.Y, pp.X - circleCenter.X));
                        var endAngle = Conversions.RadToDeg((float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X));

                        var sweepAngle = endAngle - startAngle;

                        if (at.SweepClockwise && sweepAngle < 0) {
                            // If we want to go CW, sweepAngle needs to be positive
                            sweepAngle += 360.0f;
                        }
                        else if (!at.SweepClockwise && sweepAngle > 0) {
                            // If we want to go CCW, sweepAngle needs to be negative
                            sweepAngle -= 360.0f;
                        }

                        path.AddArc(Conversions.GetRectF(rect), startAngle, sweepAngle);

                        bb.Add (p);
                        prevPoint = p;
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.CubicTo ((float)c1.X, (float)c1.Y, (float)c2.X, (float)c2.Y, (float)p.X, (float)p.Y);
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        prevPoint = p;
                        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 paint = GetBrushPaint (brush, frame);
                    graphics.DrawPath (path, paint);
                }
                if (pen != null) {
                    var paint = GetPenPaint (pen);
                    graphics.DrawPath (path, paint);
                }
            }
        }
Example #13
0
        public void DrawPath(IEnumerable<PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
                return;

            DrawElement (() => {

                var bb = new BoundingBoxBuilder ();

                foreach (var op in ops) {
                    var mt = op as MoveTo;
                    if (mt != null) {
                        var p = mt.Point;
                        context.MoveTo ((nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null) {
                        var p = lt.Point;
                        context.AddLineToPoint ((nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null) {
                        var p = at.Point;
                        var pp = Conversions.GetPoint (context.GetPathCurrentPoint ());
                        Point c1, c2;
                        at.GetCircles (pp, out c1, out c2);
                        context.AddLineToPoint ((nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null) {
                        var p = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        context.AddCurveToPoint ((nfloat)c1.X, (nfloat)c1.Y, (nfloat)c2.X, (nfloat)c2.Y, (nfloat)p.X, (nfloat)p.Y);
                        bb.Add (p);
                        bb.Add (c1);
                        bb.Add (c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null) {
                        context.ClosePath ();
                        continue;
                    }

                    throw new NotSupportedException ("Path Op " + op);
                }

                return bb.BoundingBox;

            }, pen, brush);
        }
Example #14
0
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            using (var path = new GraphicsPath()) {
                var bb = new BoundingBoxBuilder();

                var position = Point.Zero;

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        position = p;
                        bb.Add(p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        path.AddLine(Conversions.GetPointF(position), Conversions.GetPointF(p));
                        position = p;
                        bb.Add(p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null)
                    {
                        var p = at.Point;

                        Point c1, c2;
                        at.GetCircles(position, out c1, out c2);

                        var circleCenter = (at.LargeArc ^ at.SweepClockwise) ? c1 : c2;
                        var rect         = new Rect(circleCenter - at.Radius, at.Radius * 2);

                        var startAngle = Conversions.RadToDeg((float)Math.Atan2(position.Y - circleCenter.Y, position.X - circleCenter.X));
                        var endAngle   = Conversions.RadToDeg((float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X));

                        var sweepAngle = endAngle - startAngle;

                        if (at.SweepClockwise && sweepAngle < 0)
                        {
                            // If we want to go CW, sweepAngle needs to be positive
                            sweepAngle += 360.0f;
                        }
                        else if (!at.SweepClockwise && sweepAngle > 0)
                        {
                            // If we want to go CCW, sweepAngle needs to be negative
                            sweepAngle -= 360.0f;
                        }

                        path.AddArc(Conversions.GetRectangleF(rect), startAngle, sweepAngle);
                        position = p;
                        bb.Add(p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p  = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        path.AddBezier(Conversions.GetPointF(position), Conversions.GetPointF(c1),
                                       Conversions.GetPointF(c2), Conversions.GetPointF(p));
                        position = p;
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null)
                    {
                        path.CloseFigure();
                        continue;
                    }

                    throw new NotSupportedException("Path Op " + op);
                }

                var frame = bb.BoundingBox;
                if (brush != null)
                {
                    graphics.FillPath(brush.GetBrush(frame), path);
                }
                if (pen != null)
                {
                    graphics.DrawPath(pen.GetPen(), path);
                }
            }
        }
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            DrawElement(() => {
                var bb = new BoundingBoxBuilder();

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        context.MoveTo((nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        context.AddLineToPoint((nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null)
                    {
                        var p  = at.Point;
                        var pp = Conversions.GetPoint(context.GetPathCurrentPoint());
                        Point c1, c2;
                        at.GetCircles(pp, out c1, out c2);
                        context.AddLineToPoint((nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p  = ct.Point;
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        context.AddCurveToPoint((nfloat)c1.X, (nfloat)c1.Y, (nfloat)c2.X, (nfloat)c2.Y, (nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null)
                    {
                        context.ClosePath();
                        continue;
                    }

                    throw new NotSupportedException("Path Op " + op);
                }

                return(bb.BoundingBox);
            }, pen, brush);
        }