internal static UIBezierPath GetRoundCornersPath(CGRect bounds, CornerRadius cornerRadius, float borderWidth = 0f)
        {
            if (cornerRadius.IsEmpty())
            {
                return(UIBezierPath.FromRect(bounds));
            }

            if (cornerRadius.IsAllRadius())
            {
                return(UIBezierPath.FromRoundedRect(bounds, InsetCorner(cornerRadius.TopLeft, borderWidth)));
            }

            var topLeft     = InsetCorner(cornerRadius.TopLeft, borderWidth);
            var topRight    = InsetCorner(cornerRadius.TopRight, borderWidth);
            var bottomLeft  = InsetCorner(cornerRadius.BottomLeft, borderWidth);
            var bottomRight = InsetCorner(cornerRadius.BottomRight, borderWidth);

            var bezierPath = new UIBezierPath();

            bezierPath.AddArc(new CGPoint((float)bounds.X + bounds.Width - topRight, (float)bounds.Y + topRight), topRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + bounds.Width - bottomRight, (float)bounds.Y + bounds.Height - bottomRight), bottomRight, 0, (float)(Math.PI * .5), true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + bottomLeft, (float)bounds.Y + bounds.Height - bottomLeft), bottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + topLeft, (float)bounds.Y + topLeft), topLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);
            bezierPath.ClosePath();

            return(bezierPath);
        }
示例#2
0
        private void DrawBackground()
        {
            var element    = Element as ContentControl;
            var cornerPath = new UIBezierPath();

            cornerPath.AddArc(new CGPoint((float)Bounds.X + Bounds.Width - _topRight, (float)Bounds.Y + _topRight), _topRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
            cornerPath.AddArc(new CGPoint((float)Bounds.X + Bounds.Width - _bottomRight, (float)Bounds.Y + Bounds.Height - _bottomRight), _bottomRight, 0, (float)(Math.PI * .5), true);
            cornerPath.AddArc(new CGPoint((float)Bounds.X + _bottomLeft, (float)Bounds.Y + Bounds.Height - _bottomLeft), _bottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
            cornerPath.AddArc(new CGPoint((float)Bounds.X + _topLeft, (float)Bounds.Y + _topLeft), (float)_topLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);

            //draw background
            var maskLayer = new CAShapeLayer
            {
                Frame = Bounds,
                Path  = cornerPath.CGPath
            };

            _actualView.Layer.Mask          = maskLayer;
            _actualView.Layer.MasksToBounds = true;

            var shapeLayer = new CAShapeLayer
            {
                Frame         = Bounds,
                Path          = cornerPath.CGPath,
                MasksToBounds = true,
                FillColor     = _colorToRender.CGColor
            };

            AddOrRemoveLayer(shapeLayer, 0, _actualView);
        }
示例#3
0
        private void DrawBackground()
        {
            var pancake    = Element as PancakeView;
            var cornerPath = new UIBezierPath();

            cornerPath.AddArc(new CGPoint((float)Bounds.X + Bounds.Width - _topRight, (float)Bounds.Y + _topRight), _topRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
            cornerPath.AddArc(new CGPoint((float)Bounds.X + Bounds.Width - _bottomRight, (float)Bounds.Y + Bounds.Height - _bottomRight), _bottomRight, 0, (float)(Math.PI * .5), true);
            cornerPath.AddArc(new CGPoint((float)Bounds.X + _bottomLeft, (float)Bounds.Y + Bounds.Height - _bottomLeft), _bottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
            cornerPath.AddArc(new CGPoint((float)Bounds.X + _topLeft, (float)Bounds.Y + _topLeft), (float)_topLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);

            // The layer used to mask other layers we draw on the background.
            var maskLayer = new CAShapeLayer
            {
                Frame = Bounds,
                Path  = cornerPath.CGPath
            };

            _actualView.Layer.Mask          = maskLayer;
            _actualView.Layer.MasksToBounds = true;

            if ((pancake.BackgroundGradientStartColor != default(Color) && pancake.BackgroundGradientEndColor != default(Color)) || (pancake.BackgroundGradientStops != null && pancake.BackgroundGradientStops.Any()))
            {
                // Create a gradient layer that draws our background.
                var gradientLayer = CreateGradientLayer(pancake.BackgroundGradientAngle);

                if (pancake.BackgroundGradientStops != null)
                {
                    // A range of colors is given. Let's add them.
                    var orderedStops = pancake.BackgroundGradientStops.OrderBy(x => x.Offset).ToList();
                    gradientLayer.Colors    = orderedStops.Select(x => x.Color.ToCGColor()).ToArray();
                    gradientLayer.Locations = orderedStops.Select(x => new NSNumber(x.Offset)).ToArray();
                }
                else
                {
                    // Only two colors provided, use that.
                    gradientLayer.Colors = new CGColor[] { pancake.BackgroundGradientStartColor.ToCGColor(), pancake.BackgroundGradientEndColor.ToCGColor() };
                }

                AddOrRemoveLayer(gradientLayer, 0, _actualView);
            }
            else
            {
                // Create a shape layer that draws our background.
                var shapeLayer = new CAShapeLayer
                {
                    Frame         = Bounds,
                    Path          = cornerPath.CGPath,
                    MasksToBounds = true,
                    FillColor     = _colorToRender.CGColor
                };

                AddOrRemoveLayer(shapeLayer, 0, _actualView);
            }
        }
示例#4
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            Console.WriteLine("DrawingView draw!");
            CGContext context = UIGraphics.GetCurrentContext();

            // Create a path around the entire view
            UIBezierPath clipPath = UIBezierPath.FromRect(rect);

            // Add the transparent window to a sample rectangle
            CGRect       sampleRect = new CGRect(0f, 0f, rect.Width, rect.Height);
            UIBezierPath path       = UIBezierPath.FromRoundedRect(sampleRect, (System.nfloat)Device.CornerRadius);

            //Top left of notch
            path.MoveTo(new CGPoint(Device.NotchX - Device.NotchTopRadius, Device.NotchY));


            //Curve into notch
            path.AddArc(new CGPoint(Device.NotchX - Device.NotchTopRadius, Device.NotchTopRadius), (System.nfloat)(Device.NotchY + Device.NotchTopRadius), Top, Right, true);//Angles in Radians, relative to 90deg

            //Left side of notch
            path.AddLineTo(new CGPoint(Device.NotchX, Device.NotchHeight - Device.NotchBottomRadius));

            //Curve into bottom
            path.AddArc(new CGPoint(Device.NotchX + Device.NotchBottomRadius, Device.NotchY + Device.NotchHeight - Device.NotchBottomRadius), (System.nfloat)Device.NotchBottomRadius, Left, Bottom, false);

            //Bottom of notch
            path.AddLineTo(new CGPoint(Device.NotchX + Device.NotchWidth - Device.NotchBottomRadius, Device.NotchY + Device.NotchHeight));

            //Curve into right
            path.AddArc(new CGPoint(Device.NotchX + Device.NotchWidth - Device.NotchBottomRadius, Device.NotchY + Device.NotchHeight - Device.NotchBottomRadius), (System.nfloat)Device.NotchBottomRadius, Bottom, Right, false);

            //Right side of nothc
            path.AddLineTo(new CGPoint(Device.NotchX + Device.NotchWidth, Device.NotchY + Device.NotchTopRadius));


            //Curve out of notch
            path.AddArc(new CGPoint(Device.NotchX + Device.NotchWidth + Device.NotchTopRadius, Device.NotchTopRadius), (System.nfloat)(Device.NotchY + Device.NotchTopRadius), Left, Top, true);

            //finish path
            path.AddLineTo(new CGPoint(Device.NotchX - Device.NotchTopRadius, Device.NotchY));
            path.ClosePath();
            clipPath.AppendPath(path);

            // This sets the algorithm used to determine what gets filled and what doesn't
            clipPath.UsesEvenOddFillRule = true;


            context.SetFillColor(Device.NotchColor.ToUIColor().CGColor);

            clipPath.Fill();
        }
示例#5
0
        public static UIBezierPath CreateRoundedRectPath(CGRect rect, CornerRadius cornerRadius)
        {
            var path = new UIBezierPath();

            path.AddLineTo(new CGPoint(rect.Width - cornerRadius.TopRight, rect.Y));
            path.AddArc(new CGPoint((float)rect.X + rect.Width - cornerRadius.TopRight, (float)rect.Y + cornerRadius.TopRight), (nfloat)cornerRadius.TopRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
            path.AddLineTo(new CGPoint(rect.Width, rect.Height - cornerRadius.BottomRight));
            path.AddArc(new CGPoint((float)rect.X + rect.Width - cornerRadius.BottomRight, (float)rect.Y + rect.Height - cornerRadius.BottomRight), (nfloat)cornerRadius.BottomRight, 0, (float)(Math.PI * .5), true);
            path.AddLineTo(new CGPoint(cornerRadius.BottomLeft, rect.Height));
            path.AddArc(new CGPoint((float)rect.X + cornerRadius.BottomLeft, (float)rect.Y + rect.Height - cornerRadius.BottomLeft), (nfloat)cornerRadius.BottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
            path.AddLineTo(new CGPoint(rect.X, cornerRadius.TopLeft));
            path.AddArc(new CGPoint((float)rect.X + cornerRadius.TopLeft, (float)rect.Y + cornerRadius.TopLeft), (nfloat)cornerRadius.TopLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);
            path.ClosePath();
            return(path);
        }
        //// Drawing Methods

        public static void DrawTimer(CGRect frame, float percentage)
        {
            var context = UIGraphics.GetCurrentContext();

            var expression = 360.0f - percentage;

            var coverViewPath = UIBezierPath.FromOval(new CGRect(frame.GetMinX() + 5.0f, frame.GetMinY() + 4.0f, 230.0f, 230.0f));

            DemoStyleKit.Purple.SetFill();
            coverViewPath.Fill();


            context.SaveState();
            context.TranslateCTM(frame.GetMinX() + 120.0f, frame.GetMinY() + 119.0f);
            context.RotateCTM(-90.0f * NMath.PI / 180.0f);

            var completedViewRect = new CGRect(-115.0f, -115.0f, 230.0f, 230.0f);
            var completedViewPath = new UIBezierPath();

            completedViewPath.AddArc(new CGPoint(completedViewRect.GetMidX(), completedViewRect.GetMidY()), completedViewRect.Width / 2.0f, (nfloat)(-360.0f * NMath.PI / 180), (nfloat)(-expression * NMath.PI / 180.0f), true);
            completedViewPath.AddLineTo(new CGPoint(completedViewRect.GetMidX(), completedViewRect.GetMidY()));
            completedViewPath.ClosePath();

            DemoStyleKit.Green.SetFill();
            completedViewPath.Fill();

            context.RestoreState();

            var backgroundViewPath = UIBezierPath.FromOval(new CGRect(frame.GetMinX() + 10.0f, frame.GetMinY() + 9.0f, 220.0f, 220.0f));

            DemoStyleKit.Purple.SetFill();
            backgroundViewPath.Fill();
        }
示例#7
0
        private CGPath CreateCornerPath(PancakeView pancake, bool addBorderInset)
        {
            var cornerPath = new UIBezierPath();

            var insetBounds = addBorderInset ? this.Bounds.Inset(pancake.BorderThickness / 2, pancake.BorderThickness / 2) : this.Bounds;

            // Create arcs for the given corner radius.
            cornerPath.AddArc(new CGPoint((float)insetBounds.X + insetBounds.Width - pancake.CornerRadii.TopRight, (float)insetBounds.Y + pancake.CornerRadii.TopRight), (float)pancake.CornerRadii.TopRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
            cornerPath.AddArc(new CGPoint((float)insetBounds.X + insetBounds.Width - pancake.CornerRadii.BottomRight, (float)insetBounds.Y + insetBounds.Height - pancake.CornerRadii.BottomRight), (float)pancake.CornerRadii.BottomRight, 0, (float)(Math.PI * .5), true);
            cornerPath.AddArc(new CGPoint((float)insetBounds.X + pancake.CornerRadii.BottomLeft, (float)insetBounds.Y + insetBounds.Height - pancake.CornerRadii.BottomLeft), (float)pancake.CornerRadii.BottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
            cornerPath.AddArc(new CGPoint((float)insetBounds.X + pancake.CornerRadii.TopLeft, (float)insetBounds.Y + pancake.CornerRadii.TopLeft), (float)pancake.CornerRadii.TopLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);

            cornerPath.ClosePath();

            return(cornerPath.CGPath);
        }
        private void MakeCircularPath(
            double width,
            double height,
            CGColor trackColor,
            CGColor progressColor,
            double progress)
        {
            BackgroundColor    = UIColor.Clear;
            Layer.CornerRadius = (nfloat)(width / 2);

            var circlePath = new UIBezierPath();

            circlePath.AddArc(
                center: new CGPoint(x: width / 2, y: height / 2),
                radius: (nfloat)((width - 1.5) / 2),
                startAngle: (nfloat)(-0.5 * Math.PI),
                endAngle: (nfloat)(1.5 * Math.PI),
                clockWise: true
                );

            _trackLayer.Path        = circlePath.CGPath;
            _trackLayer.FillColor   = UIColor.Clear.CGColor;
            _trackLayer.StrokeColor = trackColor;
            _trackLayer.LineWidth   = (nfloat)8.0;
            _trackLayer.StrokeEnd   = (nfloat)1.0;
            Layer.AddSublayer(_trackLayer);

            _progressLayer.Path        = circlePath.CGPath;
            _progressLayer.FillColor   = UIColor.Clear.CGColor;
            _progressLayer.StrokeColor = progressColor;
            _progressLayer.LineWidth   = (nfloat)8.0;
            _progressLayer.StrokeEnd   = (nfloat)progress;
            Layer.AddSublayer(_progressLayer);
        }
        public CircleFrame(UIImageView image, CGRect frameRect, int percents = 0)
        {
            Frame = frameRect;
            var rect = frameRect;

            _image = image;
            AddSubview(_image);

            _sl             = new CAShapeLayer();
            _sl.Frame       = new CGRect(new CGPoint(0, 0), Frame.Size);
            _sl.LineWidth   = 2.0f;
            _sl.StrokeColor = UIColor.FromRGB(255, 17, 0).CGColor;
            _sl.FillColor   = UIColor.Clear.CGColor;
            _sl.LineCap     = CAShapeLayer.CapRound;
            _sl.LineJoin    = CAShapeLayer.CapRound;
            _sl.StrokeStart = 0.0f;
            _sl.StrokeEnd   = 0.0f;
            Layer.AddSublayer(_sl);

            var center     = new CGPoint(_sl.Frame.Width / 2, _sl.Frame.Height / 2);
            var startAngle = 3f * (float)Math.PI / 2f;

            _endPath = UIBezierPath.Create();
            _endPath.AddArc(center, _sl.Frame.Width / 2 - 1, startAngle, endAngle, true);

            _sl.Path = _endPath.CGPath;
            ChangePercents(percents);
        }
示例#10
0
        public override void Draw(RectangleF rect)
        {
            UIBezierPath bezierPath = new UIBezierPath();

            bezierPath.AddArc(new CoreGraphics.CGPoint(Bounds.X + Bounds.Width - _topRight, Bounds.Y + _topRight), _topRight, PIAndAHalf, TwoPI, true);
            bezierPath.AddArc(new CoreGraphics.CGPoint(Bounds.X + Bounds.Width - _bottomRight, Bounds.Y + Bounds.Height - _bottomRight), _bottomRight, 0, HalfPI, true);
            bezierPath.AddArc(new CoreGraphics.CGPoint(Bounds.X + _bottomLeft, Bounds.Y + Bounds.Height - _bottomLeft), _bottomLeft, HalfPI, PI, true);
            bezierPath.AddArc(new CoreGraphics.CGPoint(Bounds.X + _topLeft, Bounds.Y + _topLeft), _topLeft, PI, PIAndAHalf, true);

            _colorToRenderer.SetFill();
            bezierPath.Fill();

            base.Draw(rect);

            _previousSize = Bounds.Size;
        }
示例#11
0
文件: Renderer.cs 项目: t9mike/Mitten
        /// <summary>
        /// Creates a circular path.
        /// </summary>
        /// <param name="diameter">The diameter of the circle.</param>
        /// <param name="lineWidth">The line width, the default is 1.0.</param>
        /// <param name="startAngleAsRadians">The start angle for the circle as radians.</param>
        /// <param name="endAngleAsRadians">The end angle for the circle as radians.</param>
        /// <returns>A circular path.</returns>
        protected CGPath CreateCirclePath(
            nfloat diameter,
            nfloat lineWidth,
            nfloat startAngleAsRadians,
            nfloat endAngleAsRadians)
        {
            UIBezierPath path = new UIBezierPath();

            path.LineWidth = lineWidth;

            nfloat radius = diameter / 2.0f;

            if (lineWidth > 1.0f)
            {
                radius = radius - lineWidth / 2.0f;
            }

            path.AddArc(
                CGPoint.Empty,
                radius,
                startAngleAsRadians,
                endAngleAsRadians,
                clockWise: true);

            return(path.CGPath);
        }
示例#12
0
        public override void Draw(RectangleF rect)
        {
            UIBezierPath bezierPath = new UIBezierPath();

            bezierPath.AddArc(new CoreGraphics.CGPoint((float)Bounds.X + Bounds.Width - _topRight, (float)Bounds.Y + _topRight), _topRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
            bezierPath.AddArc(new CoreGraphics.CGPoint((float)Bounds.X + Bounds.Width - _bottomRight, (float)Bounds.Y + Bounds.Height - _bottomRight), _bottomRight, 0, (float)(Math.PI * .5), true);
            bezierPath.AddArc(new CoreGraphics.CGPoint((float)Bounds.X + _bottomLeft, (float)Bounds.Y + Bounds.Height - _bottomLeft), _bottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
            bezierPath.AddArc(new CoreGraphics.CGPoint((float)Bounds.X + _topLeft, (float)Bounds.Y + _topLeft), (float)_topLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);

            _colorToRenderer.SetFill();
            bezierPath.Fill();

            base.Draw(rect);

            _previousSize = Bounds.Size;
        }
示例#13
0
        public static void SetCornerRadius(this UIView view, CornerRadius cornerRadius)
        {
            if (cornerRadius.IsEmpty())
            {
                return;
            }

            CALayer currentLayer = view.FindLayerOfType <CAGradientLayer>();

            if (currentLayer == null)
            {
                currentLayer = view.Layer;
            }

            if (currentLayer == null)
            {
                return;
            }

            /*
             * Calculate the avg radius, and compare it with one.
             * If is the same with one then all corners have the same radius
             */
            if (cornerRadius.IsAllRadius())
            {
                currentLayer.CornerRadius = (float)cornerRadius.TopLeft;
                return;
            }

            var topLeft     = (float)cornerRadius.TopLeft;
            var topRight    = (float)cornerRadius.TopRight;
            var bottomLeft  = (float)cornerRadius.BottomLeft;
            var bottomRight = (float)cornerRadius.BottomRight;

            var bounds     = view.Bounds;
            var bezierPath = new UIBezierPath();

            bezierPath.AddArc(new CGPoint((float)bounds.X + bounds.Width - topRight, (float)bounds.Y + topRight), topRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + bounds.Width - bottomRight, (float)bounds.Y + bounds.Height - bottomRight), bottomRight, 0, (float)(Math.PI * .5), true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + bottomLeft, (float)bounds.Y + bounds.Height - bottomLeft), bottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + topLeft, (float)bounds.Y + topLeft), topLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);

            currentLayer.Mask?.Dispose();
            currentLayer.Mask = new CAShapeLayer {
                Frame = view.Bounds, Path = bezierPath.CGPath
            };
        }
示例#14
0
        /// <summary>
        /// Get an UIBezierPath based on BoxView CornerRadius property
        /// </summary>
        /// <param name="boxview">Xamarin Forms Boxview</param>
        /// <param name="bounds">Bounds of the native view</param>
        internal static UIBezierPath GetCornersPath(this BoxView boxview, CGRect bounds)
        {
            var cornerRadius = boxview.CornerRadius;
            var topLeft      = (float)cornerRadius.TopLeft;
            var topRight     = (float)cornerRadius.TopRight;
            var bottomLeft   = (float)cornerRadius.BottomLeft;
            var bottomRight  = (float)cornerRadius.BottomRight;

            var bezierPath = new UIBezierPath();

            bezierPath.AddArc(new CGPoint((float)bounds.X + bounds.Width - topRight, (float)bounds.Y + topRight), topRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + bounds.Width - bottomRight, (float)bounds.Y + bounds.Height - bottomRight), bottomRight, 0, (float)(Math.PI * .5), true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + bottomLeft, (float)bounds.Y + bounds.Height - bottomLeft), bottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
            bezierPath.AddArc(new CGPoint((float)bounds.X + topLeft, (float)bounds.Y + topLeft), (float)topLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);

            return(bezierPath);
        }
示例#15
0
        public static void SetBezierPathForCirlce(CGPoint rect, CGRect Bounds, nfloat endPointBar)
        {
            var bezierPath = new UIBezierPath();

            bezierPath.AddArc(rect, (nfloat)Math.Min(Bounds.Width, Bounds.Height) * 0.45f,
                              (nfloat)Math.PI * 1.5f, endPointBar / 100 * (nfloat)Math.PI * 2f, true);
            bezierPath.LineWidth = 40;
            bezierPath.Stroke();
        }
示例#16
0
        UIBezierPath LayoutPath()
        {
            nfloat       halfWidth = Frame.Width / 2f;
            CGPoint      pointMake = new CGPoint(halfWidth, halfWidth);
            UIBezierPath bezier    = new UIBezierPath();

            bezier.AddArc(pointMake, halfWidth - ShapeLayer.LineWidth, (nfloat)StartAngle, (nfloat)EndAngle, true);

            return(bezier);
        }
示例#17
0
        private CGPath CreateArcPath(nfloat diameter)
        {
            _textLayer.FontSize = Bounds.Height / 2.75f * 0.75f;

            var boundingRect = new CGRect(Bounds.Width / 2 - diameter / 2, Bounds.Height / 2 - diameter / 2, diameter, diameter);
            var path         = new UIBezierPath();

            path.AddArc(new CGPoint(Bounds.Width / 2, Bounds.Height / 2), diameter / 2, 1.5f * (float)Math.PI, 3.5f * (float)Math.PI, true);

            return(path.CGPath);
        }
示例#18
0
        public static UIBezierPath GetBezierPath(CGPoint point, nfloat lineWidth)
        {
            var path = new UIBezierPath();

            var endAngle = (float)Math.PI * 2;
            var dot      = new CGPoint(point.X, point.Y);

            path.AddArc(dot, lineWidth, startAngle: 0, endAngle, clockWise: true);

            return(path);
        }
        private double CreatePathAndReturnRadius()
        {
            var radius     = (Math.Min(Frame.Size.Width, Frame.Size.Height) - backgroundCircle.LineWidth - 2) / 2;
            var circlePath = new UIBezierPath();

            circlePath.AddArc(new CGPoint(Frame.Size.Width / 2, Frame.Size.Height / 2), (nfloat)radius, (nfloat)startAngle, (nfloat)(startAngle + 2 * Math.PI), true);
            backgroundCircle.Path      = circlePath.CGPath;
            indicatorCircle.Path       = circlePath.CGPath;
            backgroundCircle.StrokeEnd = new nfloat(1.0);
            indicatorCircle.StrokeEnd  = new nfloat(CalculateValue());
            return(radius);
        }
        public Stream GetArcPartFromSquareImage(Stream ms, int partNumber, int nbParts)
        {
            Stream result   = null;
            int    diameter = 0;

            using (UIImage image = UIImage.LoadFromData(NSData.FromStream(ms)))
            {
                diameter = (int)image.Size.Width;
            }

            float arcAngle = 360 / nbParts;
            float arcStart = 90 + (partNumber - 1) * arcAngle;

            if (nbParts > 2)
            {
                arcStart += (180 / nbParts);
            }

            float x = (float)(diameter / 2 - ((diameter * Math.Cos(DegreeToRadian(arcStart + arcAngle / 2)) + diameter) / 2)) / 2;
            float y = (float)(diameter / 2 - ((diameter * Math.Sin(DegreeToRadian(arcStart + arcAngle / 2)) + diameter) / 2)) / 2;

            float startX = (float)((diameter * Math.Cos(DegreeToRadian(arcStart)) + diameter) / 2);
            float startY = (float)((diameter * Math.Sin(DegreeToRadian(arcStart)) + diameter) / 2);

            ms.Seek(0, SeekOrigin.Begin);

            Stream moved = GetTranslated(ms, -x, y);

            using (UIImage temp = UIImage.LoadFromData(NSData.FromStream(moved)))
            {
                UIGraphics.BeginImageContext(new SizeF(temp.CGImage.Width, temp.CGImage.Height));

                using (UIBezierPath path = new UIBezierPath())
                {
                    path.MoveTo(new CGPoint(diameter / 2, diameter / 2));
                    path.AddLineTo(new CGPoint(startX, startY));
                    path.AddArc(new CGPoint(diameter / 2, diameter / 2), diameter / 2, DegreeToRadian(arcStart), DegreeToRadian(arcStart + arcAngle), true);
                    path.AddLineTo(new CGPoint(diameter / 2, diameter / 2));

                    path.AddClip();
                    temp.Draw(new Rectangle(0, 0, (int)temp.CGImage.Width, (int)temp.CGImage.Height));

                    var resultImage = UIGraphics.GetImageFromCurrentImageContext();
                    UIGraphics.EndImageContext();

                    NSData data = resultImage.AsPNG();
                    result = data.AsStream();
                }
            }

            return(result);
        }
        private void AddCornerRadius(PancakeView pancake)
        {
            if (pancake.CornerRadius.BottomLeft + pancake.CornerRadius.BottomRight + pancake.CornerRadius.TopLeft + pancake.CornerRadius.TopRight > 0)
            {
                var cornerPath = new UIBezierPath();

                // Create arcs for the given corner radius.
                cornerPath.AddArc(new CGPoint((float)Bounds.X + Bounds.Width - pancake.CornerRadius.TopRight, (float)Bounds.Y + pancake.CornerRadius.TopRight), (float)pancake.CornerRadius.TopRight, (float)(Math.PI * 1.5), (float)Math.PI * 2, true);
                cornerPath.AddArc(new CGPoint((float)Bounds.X + Bounds.Width - pancake.CornerRadius.BottomRight, (float)Bounds.Y + Bounds.Height - pancake.CornerRadius.BottomRight), (float)pancake.CornerRadius.BottomRight, 0, (float)(Math.PI * .5), true);
                cornerPath.AddArc(new CGPoint((float)Bounds.X + pancake.CornerRadius.BottomLeft, (float)Bounds.Y + Bounds.Height - pancake.CornerRadius.BottomLeft), (float)pancake.CornerRadius.BottomLeft, (float)(Math.PI * .5), (float)Math.PI, true);
                cornerPath.AddArc(new CGPoint((float)Bounds.X + pancake.CornerRadius.TopLeft, (float)Bounds.Y + pancake.CornerRadius.TopLeft), (float)pancake.CornerRadius.TopLeft, (float)Math.PI, (float)(Math.PI * 1.5), true);

                var maskLayer = new CAShapeLayer
                {
                    Frame = Bounds,
                    Path  = cornerPath.CGPath
                };

                Layer.Mask          = maskLayer;
                Layer.MasksToBounds = true;
            }
        }
示例#22
0
        public Wheel(CGPoint center, nfloat outerRadius, nfloat innerRadius, CGColor background)
        {
            var discPath = new UIBezierPath();

            discPath.AddArc(center, outerRadius, 0, (nfloat)FullCircle, true);
            var cutOutPath = new UIBezierPath();

            cutOutPath.AddArc(center, innerRadius, 0, (nfloat)FullCircle, true);
            discPath.AppendPath(cutOutPath.BezierPathByReversingPath());

            Path      = discPath.CGPath;
            FillColor = background;
        }
        public static UIBezierPath CreateBagelPath(PointF center, float startRadius, float endRadius, float startAngle, float endAngle)
        {
            var bagelPath = new UIBezierPath();

            var rotationShift = -HalfMathPi;

            var centerRadius     = (startRadius + endRadius) / 2f;
            var roundingArcWidth = (endRadius - startRadius) / 2f;

            bagelPath.AddArc(RotatePoint(center, centerRadius, startAngle + rotationShift),
                             roundingArcWidth, -HalfMathPi, -3f * HalfMathPi, true);

            bagelPath.AddArc(center, startRadius, startAngle + rotationShift, endAngle + rotationShift, true);

            bagelPath.AddArc(RotatePoint(center, centerRadius, endAngle + rotationShift),
                             roundingArcWidth, HalfMathPi + endAngle, 3f * HalfMathPi + endAngle, false);

            bagelPath.AddArc(center, endRadius, endAngle + rotationShift, startAngle + rotationShift, false);

            bagelPath.ClosePath();

            return(bagelPath);
        }
示例#24
0
        public static void DrawCircleShape(UIView view, nfloat radius)
        {
            var     circlePath = new UIBezierPath();
            CGPoint center     = new CGPoint(view.Frame.Width / 2.0, view.Frame.Height / 2.0);

            circlePath.AddArc(center, radius, 0, (nfloat)(2 * Math.PI), true);

            var shapeLayer = new CAShapeLayer();

            shapeLayer.Path      = circlePath.CGPath;
            shapeLayer.FillColor = UIColor.Red.CGColor;

            view.Layer.Mask = shapeLayer;
        }
示例#25
0
        UIBezierPath GetHeartOverlayPath(CGRect originalRect, float scale)
        {
            var scaledWidth  = (originalRect.Size.Width * scale);
            var scaledXValue = ((originalRect.Size.Width) - scaledWidth) / 2;
            var scaledHeight = (originalRect.Size.Height * scale);
            var scaledYValue = ((originalRect.Size.Height) - scaledHeight) / 2;

            var          scaledRect = new CGRect(x: scaledXValue, y: scaledYValue, width: scaledWidth, height: scaledHeight);
            UIBezierPath path       = new UIBezierPath();

            path.MoveTo(new CGPoint(x: originalRect.Size.Width / 2, y: scaledRect.Y + scaledRect.Size.Height));


            path.AddCurveToPoint(new CGPoint(x: scaledRect.X, y: scaledRect.Y + (scaledRect.Size.Height / 4)),
                                 controlPoint1: new CGPoint(x: scaledRect.X + (scaledRect.Size.Width / 2), y: scaledRect.Y + (scaledRect.Size.Height * 3 / 4)),
                                 controlPoint2: new CGPoint(x: scaledRect.X, y: scaledRect.Y + (scaledRect.Size.Height / 2)));

            path.AddArc(new CGPoint(scaledRect.X + (scaledRect.Size.Width / 4), scaledRect.Y + (scaledRect.Size.Height / 4)),
                        (scaledRect.Size.Width / 4),
                        (nfloat)Math.PI,
                        0,
                        true);

            path.AddArc(new CGPoint(scaledRect.X + (scaledRect.Size.Width * 3 / 4), scaledRect.Y + (scaledRect.Size.Height / 4)),
                        (scaledRect.Size.Width / 4),
                        (nfloat)Math.PI,
                        0,
                        true);

            path.AddCurveToPoint(new CGPoint(x: originalRect.Size.Width / 2, y: scaledRect.Y + scaledRect.Size.Height),
                                 controlPoint1: new CGPoint(x: scaledRect.X + scaledRect.Size.Width, y: scaledRect.Y + (scaledRect.Size.Height / 2)),
                                 controlPoint2: new CGPoint(x: scaledRect.X + (scaledRect.Size.Width / 2), y: scaledRect.Y + (scaledRect.Size.Height * 3 / 4)));

            path.ClosePath();

            return(path);
        }
示例#26
0
        public static void AsCircleWithTransparentCenter(this UIView _view, UIColor backgroundColor, float targetRadius)
        {
            var largeRadius = _view.Frame.Width * .5f;
            var path        = new UIBezierPath();

            path.AddArc(new CGPoint(_view.Bounds.GetMidX(), _view.Bounds.GetMidY()), (targetRadius + largeRadius) * .5f, 0f, (float)Math.PI * 2, true);
            var shape = new CAShapeLayer();

            shape.Frame       = _view.Bounds;
            shape.Path        = path.CGPath;
            shape.LineWidth   = largeRadius - targetRadius;
            shape.StrokeColor = backgroundColor.CGColor;
            shape.FillColor   = UIColor.Clear.CGColor;
            _view.Layer.AddSublayer(shape);
            _view.Layer.MasksToBounds = true;
        }
示例#27
0
        protected CALayer CreateWheelLayer(CGColor background)
        {
            var wheel    = new CAShapeLayer();
            var discPath = new UIBezierPath();

            discPath.AddArc(Center, Radius, 0, (nfloat)FullCircle, true);
            var cutOutPath = new UIBezierPath();

            cutOutPath.AddArc(Center, SmallRadius, 0, (nfloat)FullCircle, true);
            discPath.AppendPath(cutOutPath.BezierPathByReversingPath());

            wheel.Path      = discPath.CGPath;
            wheel.FillColor = background;

            return(wheel);
        }
示例#28
0
文件: Cap.cs 项目: xleon/mobileapp
        protected Cap(
            CGImage icon,
            Func <nfloat, nfloat> scale,
            nfloat iconHeight,
            nfloat iconWidth,
            ShadowDirection shadowDirection)
        {
            this.shadowDirection = shadowDirection;
            var center = new CGPoint(0, 0);

            var outerPath = new UIBezierPath();

            outerPath.AddArc(center, scale(outerRadius), 0, (nfloat)Math.FullCircle, false);

            Path = outerPath.CGPath;

            var innerPath = new UIBezierPath();

            innerPath.AddArc(center, scale(innerRadius), 0, (nfloat)Math.FullCircle, false);

            var circleLayer = new CAShapeLayer {
                Path = innerPath.CGPath, FillColor = ColorAssets.Background.CGColor
            };

            var imageFrame = new CGRect(
                x: center.X - scale(iconWidth) / 2f,
                y: center.Y - scale(iconHeight) / 2f,
                width: scale(iconWidth),
                height: scale(iconHeight));

            var maskLayer = new CALayer {
                Contents = icon, Frame = new CGRect(0, 0, scale(iconWidth), scale(iconHeight))
            };

            imageLayer = new CALayer {
                Mask = maskLayer, Frame = imageFrame
            };

            circleLayer.AddSublayer(imageLayer);

            AddSublayer(circleLayer);

            ShadowColor   = ColorAssets.Separator.CGColor;
            ShadowRadius  = 0.0f;
            ShadowPath    = Path;
            ShadowOpacity = 1.0f;
        }
示例#29
0
        public override void Draw(RectangleF rect)
        {
            base.Draw(rect);

            if (!string.IsNullOrEmpty(iText))
            {
                NSString text = new NSString(iText);
                UIFont   font = UIFont.SystemFontOfSize(iFontSize);
                SizeF    size = text.StringSize(font);
                iFontColour.SetColor();
                text.DrawString(new RectangleF(((Frame.Width * 0.5f) - 25) + 3, (Frame.Height - size.Height) * 0.5f, (25 * 2) - 3, size.Height),
                                font, UILineBreakMode.Clip, UITextAlignment.Center);
            }

            // render the % arc
            UIColor colour = new UIColor(71.0f / 255.0f, 172.0f / 255.0f, 220.0f / 255.0f, 255.0f / 255.0f);

            colour.SetStroke();

            UIBezierPath path = new UIBezierPath();

            path.LineWidth = 3.0f;
            if (iMaxValue != 0)
            {
                float angle = (float)((Math.PI * 0.5f) + ((iValue / (float)iMaxValue) * 2.0f * Math.PI));
                path.AddArc(new PointF(Frame.Width * 0.5f, Frame.Height * 0.5f), iInnerCircleRadius, (float)(Math.PI * 0.5f), angle, true);
                path.Stroke();
            }

            if (iPreviewEnabled)
            {
                // render the % preview arc
                colour = new UIColor(187.0f / 255.0f, 187.0f / 255.0f, 0.0f, 255.0f / 255.0f);
                colour.SetStroke();

                path           = new UIBezierPath();
                path.LineWidth = 3.0f;
                if (MaxValue != 0)
                {
                    float angle       = (float)((Math.PI * 0.5f) + ((Value / (float)MaxValue) * 2.0f * Math.PI));
                    float angleTarget = (float)((Math.PI * 0.5f) + ((iPreviewValue / (float)MaxValue) * 2.0f * Math.PI));
                    path.AddArc(new PointF(Frame.Width * 0.5f, Frame.Height * 0.5f), iInnerCircleRadius, angle, angleTarget, angle < angleTarget);
                    path.Stroke();
                }
            }
        }
示例#30
0
        private CAShapeLayer createChartSegment(nfloat offset, nfloat percent, CGColor color)
        {
            var startAngle = (nfloat)FullCircle * offset - (nfloat)QuarterOfCircle;
            var angle      = (nfloat)FullCircle * percent;
            var radius     = Chart.Bounds.Width / 2;
            var start      = new CGPoint(Chart.Center.X + (nfloat)Math.Cos(startAngle) * radius, Chart.Center.Y + (nfloat)Math.Sin(startAngle) * radius);

            var path = new UIBezierPath();

            path.MoveTo(Chart.Center);
            path.AddLineTo(start);
            path.AddArc(Chart.Center, radius, startAngle, startAngle + angle, true);
            path.ClosePath();

            var layer = new CAShapeLayer();

            layer.Path      = path.CGPath;
            layer.FillColor = color;
            return(layer);
        }
        void Draw(RectangleF rect)
        {
            //// Color Declarations

            //// Frames
            var bgFrame = new RectangleF(0, 0, rect.Width, rect.Height);

            //// Subframes
            var circleGroup = new RectangleF(bgFrame.GetMinX() + (float)Math.Floor(bgFrame.Width * 0.13437f + 0.5f), bgFrame.GetMinY() + (float)Math.Floor(bgFrame.Height * 0.12500f + 0.5f), (float)Math.Floor(bgFrame.Width * 0.85938f + 0.5f) - (float)Math.Floor(bgFrame.Width * 0.13437f + 0.5f), (float)Math.Floor(bgFrame.Height * 0.84688f + 0.5f) - (float)Math.Floor(bgFrame.Height * 0.12500f + 0.5f));

            //// Abstracted Attributes
            var progressOvalEndAngle = Progress;

            //// circleGroup
            {
                //// outerOval Drawing
                var outerOvalPath = UIBezierPath.FromOval(new RectangleF(circleGroup.GetMinX() + (float)Math.Floor(circleGroup.Width * 0.00216f) + 0.5f, circleGroup.GetMinY() + (float)Math.Floor(circleGroup.Height * 0.00000f + 0.5f), (float)Math.Floor(circleGroup.Width * 0.99784f) - (float)Math.Floor(circleGroup.Width * 0.00216f), (float)Math.Floor(circleGroup.Height * 1.00000f + 0.5f) - (float)Math.Floor(circleGroup.Height * 0.00000f + 0.5f)));
                OuterColor.SetFill();
                outerOvalPath.Fill();

                //// progressOval Drawing
                var progressOvalRect = new RectangleF(circleGroup.GetMinX() + (float)Math.Floor(circleGroup.Width * 0.00216f) + 0.5f, circleGroup.GetMinY() + (float)Math.Floor(circleGroup.Height * 0.00000f + 0.5f), (float)Math.Floor(circleGroup.Width * 0.99784f) - (float)Math.Floor(circleGroup.Width * 0.00216f), (float)Math.Floor(circleGroup.Height * 1.00000f + 0.5f) - (float)Math.Floor(circleGroup.Height * 0.00000f + 0.5f));
                var progressOvalPath = new UIBezierPath();
                progressOvalPath.AddArc(new PointF(progressOvalRect.GetMidX(), progressOvalRect.GetMidY()), progressOvalRect.Width / 2, (float)(270 * Math.PI / 180), (float)(progressOvalEndAngle * Math.PI / 180), true);
                progressOvalPath.AddLineTo(new PointF(progressOvalRect.GetMidX(), progressOvalRect.GetMidY()));
                progressOvalPath.ClosePath();

                InnerColor.SetFill();
                progressOvalPath.Fill();

                //// innerOval Drawing
                var innerOvalPath = UIBezierPath.FromOval(new RectangleF(circleGroup.GetMinX() + (float)Math.Floor(circleGroup.Width * 0.09052f + 0.5f), circleGroup.GetMinY() + (float)Math.Floor(circleGroup.Height * 0.09091f + 0.5f), (float)Math.Floor(circleGroup.Width * 0.90948f + 0.5f) - (float)Math.Floor(circleGroup.Width * 0.09052f + 0.5f), (float)Math.Floor(circleGroup.Height * 0.91342f + 0.5f) - (float)Math.Floor(circleGroup.Height * 0.09091f + 0.5f)));
                InsideColor.SetFill();
                innerOvalPath.Fill();
            }
        }
示例#32
0
        public static UIBezierPath BezierPathForBackButton(RectangleF rect, float radius)
        {
            var path = new UIBezierPath();
            var mPoint = new PointF(rect.Right - radius, rect.Y);
            var ctrlPoint = mPoint;
            path.MoveTo(mPoint);

            ctrlPoint.Y += radius;
            mPoint.X += radius;
            mPoint.Y += radius;
            if (radius > 0)
                path.AddArc(ctrlPoint, radius, (float)(Math.PI + Math.PI / 2), 0, true);

            mPoint.Y = rect.Bottom - radius;
            path.AddLineTo(mPoint);

            ctrlPoint = mPoint;
            mPoint.Y += radius;
            mPoint.X -= radius;
            ctrlPoint.X -= radius;
            if (radius > 0)
                path.AddArc(ctrlPoint, radius, 0, (float)(Math.PI / 2), true);

            mPoint.X = rect.X + 10f;
            path.AddLineTo(mPoint);

            path.AddLineTo(new PointF(rect.X, rect.Height / 2));

            mPoint.Y = rect.Y;
            path.AddLineTo(mPoint);

            path.ClosePath();
            return path;
        }