예제 #1
0
        public override void AppendPath(object backend, object otherBackend)
        {
            CGPath           dest = (CGPath)backend;
            CGContextBackend src  = otherBackend as CGContextBackend;

            if (src != null)
            {
                using (var path = src.Context.CopyPath())
                    dest.AddPath(path);
            }
            else
            {
                dest.AddPath((CGPath)otherBackend);
            }
        }
예제 #2
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                UIGraphics.BeginImageContext(new CGSize(this.Frame.Width, this.Frame.Height));

                CGPath currentPath = new CGPath();
                if (!CurrentPoint.IsEmpty)
                {
                    currentPath.MoveToPoint(FirstPoint.X, FirstPoint.Y);
                    currentPath.AddLineToPoint(CurrentPoint.X, CurrentPoint.Y);
                    Path.AddPath(currentPath);
                    AllPoints.Add(CurrentPoint);
                }

                UIColor.Black.SetStroke();
                g.SetLineWidth(10);
                g.SetLineCap(CGLineCap.Round);
                g.SetBlendMode(CGBlendMode.Normal);
                g.AddPath(Path);
                g.DrawPath(CGPathDrawingMode.FillStroke);

                UIGraphics.EndImageContext();
                FirstPoint = CurrentPoint;
            }
        }
예제 #3
0
        private CAShapeLayer GetMaskForRoundedCorners()
        {
            var roundedRectanglePath = UIBezierPath.FromRoundedRect(Bounds, RadiusCorner);
            var biggerRect           = Bounds.Copy().Grow(5);

            var maskPath = new UIBezierPath();

            maskPath.MoveTo(new CGPoint(biggerRect.GetMinX(), biggerRect.GetMinY()));
            maskPath.AddLineTo(new CGPoint(biggerRect.GetMinX(), biggerRect.GetMaxY()));
            maskPath.AddLineTo(new CGPoint(biggerRect.GetMaxX(), biggerRect.GetMaxY()));
            maskPath.AddLineTo(new CGPoint(biggerRect.GetMaxX(), biggerRect.GetMinY()));
            maskPath.AddLineTo(new CGPoint(biggerRect.GetMinX(), biggerRect.GetMinY()));
            maskPath.AppendPath(roundedRectanglePath);

            var maskForRoundedCorners = new CAShapeLayer();
            var newPath = new CGPath();

            newPath.AddRect(biggerRect);
            newPath.AddPath(maskPath.CGPath);
            maskForRoundedCorners.Path     = newPath;
            maskForRoundedCorners.FillRule = CAShapeLayer.FillRuleEvenOdd;

            newPath.Dispose();
            maskPath.Dispose();
            roundedRectanglePath.Dispose();

            return(maskForRoundedCorners);
        }
예제 #4
0
        CAShapeLayer CreateShapeLayerWithBezierPath(UIBezierPath bezierPath)
        {
            /* Expand the shape bounds, so when it scales down a bit in the beginning, we have some padding */
            var shapeBounds = Bounds.Inset(-Bounds.Width, -Bounds.Height);

            using (var mutablePath = new CGPath()) {
                mutablePath.AddRect(shapeBounds);

                /* Move the icon to the middle */
                var iconOffset = new CGPoint((Bounds.Width - bezierPath.Bounds.Width) / 2,
                                             (Bounds.Height - bezierPath.Bounds.Height) / 2);

                var iconTransform = CGAffineTransform.MakeTranslation(iconOffset.X, iconOffset.Y);

                mutablePath.AddPath(iconTransform, bezierPath.CGPath);

                var shapeLayer = (CAShapeLayer)CAShapeLayer.Create();
                shapeLayer.Bounds      = shapeBounds;
                shapeLayer.Position    = new CGPoint(Bounds.Width / 2, Bounds.Height / 2);
                shapeLayer.Path        = mutablePath;
                shapeLayer.AnchorPoint = new CGPoint(0.5, 0.5);
                shapeLayer.FillColor   = BackgroundViewColor.CGColor;

                return(shapeLayer);
            }
        }
예제 #5
0
 public void AddPath()
 {
     using (CGPath p1 = new CGPath())
         using (CGPath p2 = new CGPath()) {
             p1.MoveToPoint(0, 0);
             p2.AddPath(p1);
             Assert.IsFalse(p2.IsEmpty, "IsEmpty");
         }
 }
예제 #6
0
            public override void DrawInContext(CoreGraphics.CGContext ctx)
            {
                CGRect       rect       = this.BoundsRect();
                CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();

                nfloat [] colors = new nfloat[] {
                    0.42f, 0.66f, 0.31f, 1.0f,
                    0.95f, 0.76f, 0.20f, 1.0f,
                    0.80f, 0.25f, 0.15f, 1.0f
                };

                CGGradient gradient = new CGGradient(colorSpace, colors, null);

                nuint tickSpaces  = this.Axis.MajorTickCount - 1;
                nuint pointsCount = 5;

                if (this.Chart.Frame.Size.Height < this.Chart.Frame.Size.Width)
                {
                    pointsCount = 3;
                }

                nfloat diameter           = 8;
                nfloat spaceHeight        = rect.Size.Height / tickSpaces;
                nfloat spacing            = (spaceHeight - (pointsCount * diameter)) / (pointsCount + 1);
                nuint  allPointsCount     = pointsCount * tickSpaces;
                CGPath multipleCirclePath = new CGPath();
                double y = rect.GetMinY() + diameter / 2.0f + spacing;

                for (uint i = 1; i <= allPointsCount; i++)
                {
                    CGPoint center = new CGPoint(rect.GetMidX(), y);
                    CGPath  path   = new CGPath();
                    path.AddArc(center.X, center.Y, (nfloat)diameter / 2.0f, 0, (nfloat)Math.PI * 2, true);
                    multipleCirclePath.AddPath(path);
                    y += spacing + diameter;
                    if (i % pointsCount == 0)
                    {
                        y += spacing;
                    }
                }

                ctx.SaveState();
                ctx.AddPath(multipleCirclePath);
                ctx.Clip();
                CGPoint startPoint = new CGPoint(rect.GetMidX(), rect.GetMinY());
                CGPoint endPoint   = new CGPoint(rect.GetMidX(), rect.GetMaxY());

                ctx.DrawLinearGradient(gradient, startPoint, endPoint, 0);
                ctx.RestoreState();

                base.DrawInContext(ctx);
            }
예제 #7
0
        public void Transform(IMatrix matrix)
        {
            if (transform == null)
            {
                transform = matrix;
            }
            else
            {
                transform.Prepend(matrix);
            }
            var path = new CGPath();

            path.AddPath(matrix.ToCG(), Control);
            Control = path;
        }
예제 #8
0
			public override void DrawInContext (CoreGraphics.CGContext ctx)
			{
				CGRect rect = this.BoundsRect();
				CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
				nfloat [] colors = new nfloat[] {
					0.42f, 0.66f, 0.31f, 1.0f,
					0.95f, 0.76f, 0.20f, 1.0f,
					0.80f, 0.25f, 0.15f, 1.0f
				};

				CGGradient gradient = new CGGradient (colorSpace, colors, null);

				nuint tickSpaces = this.Axis.MajorTickCount - 1;
				nuint pointsCount = 5;
				if (this.Chart.Frame.Size.Height < this.Chart.Frame.Size.Width) {
					pointsCount = 3;
				}

				nfloat diameter = 8;
				nfloat spaceHeight = rect.Size.Height / tickSpaces;
				nfloat spacing = (spaceHeight - (pointsCount * diameter)) / (pointsCount + 1);
				nuint allPointsCount = pointsCount * tickSpaces;
				CGPath multipleCirclePath = new CGPath ();
				double y = rect.GetMinY() +  diameter / 2.0f  + spacing;

				for (uint i = 1; i <= allPointsCount; i++) {
					CGPoint center = new CGPoint (rect.GetMidX (), y);
					CGPath path = new CGPath ();
					path.AddArc (center.X, center.Y, (nfloat)diameter/2.0f, 0, (nfloat)Math.PI * 2, true);
					multipleCirclePath.AddPath (path);
					y += spacing + diameter;
					if (i % pointsCount == 0) {
						y += spacing;
					}
				}

				ctx.SaveState ();
				ctx.AddPath (multipleCirclePath);
				ctx.Clip ();
				CGPoint startPoint = new CGPoint (rect.GetMidX (), rect.GetMinY ());
				CGPoint endPoint = new CGPoint (rect.GetMidX (), rect.GetMaxY());
				ctx.DrawLinearGradient (gradient, startPoint, endPoint, 0);
				ctx.RestoreState ();

				base.DrawInContext (ctx);
			}
예제 #9
0
        /// <summary>
        /// Gets the poly path for a polygon.
        /// </summary>
        /// <returns>The path.</returns>
        /// <param name="polygon">Polygon to get the path for.</param>
        public CGPath PolyPath(MKPolygon polygon)
        {
            var path = new CGPath();

            foreach (var item in polygon.InteriorPolygons)
            {
                var interiorPath = this.PolyPath(item);
                path.AddPath(interiorPath);
            }

            var relativePoint = PointForMapPoint(polygon.Points[0]);

            path.MoveToPoint(relativePoint);
            foreach (var point in polygon.Points)
            {
                path.AddLineToPoint(this.PointForMapPoint(point));
            }

            return(path);
        }
예제 #10
0
        public void AddPath(IGraphicsPath path, bool connect = false)
        {
            if (path.IsEmpty)
            {
                return;
            }

            var handler = path.ToHandler();

            if (connect && handler.startPoint != null && !handler.firstFigureClosed)
            {
                var first = true;
                handler.Control.Apply(element => {
                    switch (element.Type)
                    {
                    case CGPathElementType.AddCurveToPoint:
                        if (first)
                        {
                            ConnectTo(element.Point3.ToEto());
                        }
                        this.AddCurveToPoint(element.Point1.ToEto(), element.Point2.ToEto(), element.Point3.ToEto());
                        break;

                    case CGPathElementType.AddLineToPoint:
                        if (first)
                        {
                            ConnectTo(element.Point1.ToEto());
                        }
                        Control.AddLineToPoint(element.Point1);
                        break;

                    case CGPathElementType.AddQuadCurveToPoint:
                        if (first)
                        {
                            ConnectTo(element.Point2.ToEto());
                        }
                        Control.AddQuadCurveToPoint(element.Point1.X, element.Point1.Y, element.Point2.X, element.Point2.Y);
                        break;

                    case CGPathElementType.CloseSubpath:
                        Control.CloseSubpath();
                        break;

                    case CGPathElementType.MoveToPoint:
                        if (first)
                        {
                            ConnectTo(element.Point1.ToEto());
                        }
                        else
                        {
                            Control.MoveToPoint(element.Point1);
                        }
                        break;
                    }
                    first = false;
                });
            }
            else
            {
                Control.AddPath(handler.Control);
            }
            startFigure = handler.startFigure;
        }
예제 #11
0
        void setupTextLayer(string l)
        {
            clearLayer();

            var singleLetter = l.Length == 1;

            var fontSize = singleLetter ? letterFontSize : messageFontSize;

            var font = new CTFont(new CTFontDescriptor(new CTFontDescriptorAttributes {
                Name = UIFont.SystemFontOfSize(fontSize).Name, Size = (float?)fontSize
            }), fontSize);

            var attrStr = new NSAttributedString(l, singleLetter ? letterStringAttributes : messageStringAttributes);

            var line = new CTLine(attrStr);

            var runArray = line.GetGlyphRuns();

            var letters = new CGPath();

            for (int runIndex = 0; runIndex < runArray.Length; runIndex++)
            {
                var run = runArray [runIndex];

                for (int runGlyphIndex = 0; runGlyphIndex < run.GlyphCount; runGlyphIndex++)
                {
                    var thisGlyphRange = new NSRange(runGlyphIndex, 1);

                    var glyph = run.GetGlyphs(thisGlyphRange).FirstOrDefault();

                    var position = run.GetPositions(thisGlyphRange).FirstOrDefault();

                    var letter = font.GetPathForGlyph(glyph);

                    var t = CGAffineTransform.MakeTranslation(position.X, position.Y);

                    if (letter != null)
                    {
                        letters.AddPath(t, letter);
                    }
                }
            }

            var path = new UIBezierPath();

            path.MoveTo(CGPoint.Empty);

            path.AppendPath(UIBezierPath.FromPath(letters));

            var layer = new CAShapeLayer();

            layer.Frame           = new CGRect(((animationLayer.Bounds.Width - path.Bounds.Width) / 2) - 10, (animationLayer.Bounds.Height - path.Bounds.Height) / 2, path.Bounds.Width, path.Bounds.Height);
            layer.GeometryFlipped = true;
            layer.Path            = path.CGPath;
            layer.StrokeColor     = UIColor.Blue.CGColor;
            layer.FillColor       = null;
            layer.LineWidth       = 3;
            layer.LineJoin        = CAShapeLayer.JoinBevel;

            animationLayer?.AddSublayer(layer);

            pathLayer = layer;
        }
예제 #12
0
        /// <summary>
        /// Gets the poly path for a polygon.
        /// </summary>
        /// <returns>The path.</returns>
        /// <param name="polygon">Polygon to get the path for.</param>
        public CGPath PolyPath(MKPolygon polygon)
        {
            var path = new CGPath();

            foreach (var item in polygon.InteriorPolygons)
            {
                var interiorPath = this.PolyPath(item);
                path.AddPath(interiorPath);
            }

            var relativePoint = PointForMapPoint(polygon.Points[0]);
            path.MoveToPoint(relativePoint);
            foreach (var point in polygon.Points)
            {
                path.AddLineToPoint(this.PointForMapPoint(point));
            }

            return path;
        }