public static CGPath ToCGPath(this NSBezierPath nsPath)
        {
            var cgPath = new CGPath();
            var points = null as CGPoint[];

            for (int i = 0; i < nsPath.ElementCount; i++)
            {
                var type = nsPath.ElementAt(i, out points);

                switch (type)
                {
                case NSBezierPathElement.MoveTo:
                    cgPath.MoveToPoint(points[0]);
                    break;

                case NSBezierPathElement.LineTo:
                    cgPath.AddLineToPoint(points[0]);
                    break;

                case NSBezierPathElement.CurveTo:
                    cgPath.AddCurveToPoint(cp1: points[0], cp2: points[1], point: points[2]);
                    break;

                case NSBezierPathElement.ClosePath:
                    cgPath.CloseSubpath();
                    break;
                }
            }

            return(cgPath);
        }
        public static CGPath ToCGPath(this NSBezierPath bezierPath)
        {
            var path = new CGPath();

            for (var i = 0; i < bezierPath.ElementCount; i++)
            {
                var type = bezierPath.ElementAt(i, out var points);

                switch (type)
                {
                case NSBezierPathElement.MoveTo:
                    path.MoveToPoint(points[0]);
                    break;

                case NSBezierPathElement.LineTo:
                    path.AddLineToPoint(points[0]);
                    break;

                case NSBezierPathElement.CurveTo:
                    path.AddCurveToPoint(points[0], points[1], points[2]);
                    break;

                case NSBezierPathElement.ClosePath:
                    path.CloseSubpath();
                    break;
                }
            }

            return(path);
        }
Esempio n. 3
0
        public static CGPath ToCGPath(this NSBezierPath path, bool closePath)
        {
            int i, numElements;

            // Need to begin a path here.
            CGPath cgpath = new CGPath();

            // Then draw the path elements.
            numElements = (int)path.ElementCount;

            if (numElements > 0)
            {
                CGPoint [] points       = new CGPoint [3];
                bool       didClosePath = true;

                for (i = 0; i < numElements; i++)
                {
                    switch (path.ElementAt(i, out points))
                    {
                    case NSBezierPathElement.MoveTo:
                        cgpath.MoveToPoint(points [0].X, points [0].Y);
                        break;

                    case NSBezierPathElement.LineTo:
                        cgpath.AddLineToPoint(points [0].X, points [0].Y);
                        didClosePath = false;
                        break;

                    case NSBezierPathElement.CurveTo:
                        cgpath.AddCurveToPoint(points [0], points [1], points [2]);
                        didClosePath = false;
                        break;

                    case NSBezierPathElement.ClosePath:
                        cgpath.CloseSubpath();
                        didClosePath = true;
                        break;
                    }
                }

                // Be sure the path is closed or Quartz may not do valid hit detection.
                if (!didClosePath && closePath)
                {
                    cgpath.CloseSubpath();
                }
            }

            return(cgpath);
        }
Esempio n. 4
0
        //TODO: we should move this to a shared place
        public static CGPath ToCGPath(this NSBezierPath path)
        {
            var numElements = path.ElementCount;

            if (numElements == 0)
            {
                return(null);
            }

            CGPath result       = new CGPath();
            bool   didClosePath = true;


            for (int i = 0; i < numElements; i++)
            {
                CGPoint[] points;
                var       element = path.ElementAt(i, out points);
                if (element == NSBezierPathElement.MoveTo)
                {
                    result.MoveToPoint(points[0].X, points[0].Y);
                }
                else if (element == NSBezierPathElement.LineTo)
                {
                    result.AddLineToPoint(points[0].X, points[0].Y);
                    didClosePath = false;
                }
                else if (element == NSBezierPathElement.CurveTo)
                {
                    result.AddCurveToPoint(points[0].X, points[0].Y,
                                           points[1].X, points[1].Y,
                                           points[2].X, points[2].Y);
                    didClosePath = false;
                }
                else if (element == NSBezierPathElement.ClosePath)
                {
                    result.CloseSubpath();
                }
            }

            // Be sure the path is closed or Quartz may not do valid hit detection.
            if (!didClosePath)
            {
                result.CloseSubpath();
            }
            return(result);
        }