public static UIBezierPath ToUIKit(this Polygon polygon, IViewport viewport)
        {
            var group = new UIBezierPath();

            group.UsesEvenOddFillRule = true;
            group.AppendPath(ToUIKit(polygon.ExteriorRing, viewport));
            group.AppendPath(ToUIKit(polygon.InteriorRings, viewport));
            return(group);
        }
        public static UIBezierPath ToUIKit(this LinearRing linearRing, IViewport viewport)
        {
            var pathGeometry = new UIBezierPath();

            pathGeometry.AppendPath(CreatePathFigure(linearRing, viewport));
            return(pathGeometry);
        }
Esempio n. 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);
        }
Esempio n. 4
0
        public void UpdatePath()
        {
            UIBezierPath path = UIBezierPath.FromRoundedRect(new CGRect(Frame.X, Frame.Y, this.Frame.Width, this.Frame.Height), 0);

            path.AppendPath(OverlayShape == OverlayShape.Circle ? GetCircularOverlayPath() : GetHeartOverlayPath(path.Bounds, 0.95f));

            overlayLayer.Path = path.CGPath;
        }
        public static UIBezierPath ToUIKit(this MultiLineString multiLineString, IViewport viewport)
        {
            var group = new UIBezierPath();

            foreach (LineString lineString in multiLineString)
            {
                group.AppendPath(ToUIKit(lineString, viewport));
            }
            return(group);
        }
        public static UIBezierPath ToUIKit(this IEnumerable <LinearRing> linearRings, IViewport viewport)
        {
            var pathGeometry = new UIBezierPath();

            foreach (var linearRing in linearRings)
            {
                pathGeometry.AppendPath(CreatePathFigure(linearRing, viewport));
            }
            return(pathGeometry);
        }
        public static UIBezierPath ToUIKit(this MultiPolygon geometry, IViewport viewport)
        {
            var group = new UIBezierPath();

            foreach (var polygon in geometry.Polygons)
            {
                group.AppendPath(ToUIKit(polygon, viewport));
            }

            return(group);
        }
Esempio n. 8
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();
        }
Esempio n. 9
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;
        }
Esempio n. 10
0
        private CGPath GetShadowPath(CGRect biggerRect)
        {
            var shadowPath = new UIBezierPath();

            shadowPath.MoveTo(new CGPoint(biggerRect.GetMinX(), biggerRect.GetMinY()));
            shadowPath.AddLineTo(new CGPoint(biggerRect.GetMinX(), biggerRect.GetMaxY()));
            shadowPath.AddLineTo(new CGPoint(biggerRect.GetMaxX(), biggerRect.GetMaxY()));
            shadowPath.AddLineTo(new CGPoint(biggerRect.GetMaxX(), biggerRect.GetMinY()));
            shadowPath.AddLineTo(new CGPoint(biggerRect.GetMinX(), biggerRect.GetMinY()));;
            shadowPath.AppendPath(UIBezierPath.FromRoundedRect(Bounds, RadiusCorner));
            shadowPath.UsesEvenOddFillRule = true;

            return(shadowPath.CGPath);
        }
Esempio n. 11
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);
        }
Esempio n. 12
0
        public void AddOverlayLayer()
        {
            UIBezierPath path = UIBezierPath.FromRoundedRect(new CGRect(Frame.X, Frame.Y, this.Frame.Width, this.Frame.Height), 0);


            path.AppendPath(OverlayShape == OverlayShape.Circle ? GetCircularOverlayPath() : GetHeartOverlayPath(path.Bounds, 0.95f));

            path.UsesEvenOddFillRule = true;

            CAShapeLayer fillLayer = new CAShapeLayer();

            fillLayer.Path      = path.CGPath;
            fillLayer.FillRule  = CAShapeLayer.FillRuleEvenOdd;
            fillLayer.FillColor = OverlayBackgroundColor.CGColor;
            fillLayer.Opacity   = Opacity;
            overlayLayer        = fillLayer;
            Layer.AddSublayer(fillLayer);
        }
Esempio n. 13
0
        public override void DrawRect(RectangleF area, UIViewPrintFormatter formatter)
        {
            base.DrawRect(area, formatter);

            //General Declarations
            CGContext context = UIGraphics.GetCurrentContext();

            // Color Declarations
            UIColor mmFill = new UIColor(0F, 0F, 0F, 0.196F);
            UIColor shape1DropShadowColor  = new UIColor(1F, 1F, 1F, 0.4F);
            UIColor shape1InnerShadowColor = new UIColor(0F, 0F, 0F, 0.392F);

            // Shadow Declarations
            UIColor mmDropShadow            = shape1DropShadowColor;
            SizeF   mmDropShadowOffset      = new SizeF(0.1F, 1.1F);
            Single  mmDropShadowBlurRadius  = 0;
            UIColor mmInnerShadow           = shape1InnerShadowColor;
            SizeF   mmInnerShadowOffset     = new SizeF(0.1F, 1.1F);
            Single  mmInnerShadowBlurRadius = 0;

            // Frames
            RectangleF frame = this.Bounds;

            // mmGroup
            {
                // mmShape Drawing
                UIBezierPath mmShapePath = new UIBezierPath();
                mmShapePath.MoveTo(new PointF(frame.GetMinX() + 0.51759F * frame.Width, frame.GetMinY() + 0.96761F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.37558F * frame.Width, frame.GetMinY() + 0.91398F * frame.Height),
                    new PointF(frame.GetMinX() + 0.46395F * frame.Width, frame.GetMinY() + 0.96761F * frame.Height),
                    new PointF(frame.GetMinX() + 0.41351F * frame.Width, frame.GetMinY() + 0.94854F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.31759F * frame.Width, frame.GetMinY() + 0.76824F * frame.Height),
                    new PointF(frame.GetMinX() + 0.33346F * frame.Width, frame.GetMinY() + 0.87556F * frame.Height),
                    new PointF(frame.GetMinX() + 0.31234F * frame.Width, frame.GetMinY() + 0.82249F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.31904F * frame.Width, frame.GetMinY() + 0.75325F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.30262F * frame.Width, frame.GetMinY() + 0.75459F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.28470F * frame.Width, frame.GetMinY() + 0.75535F * frame.Height),
                    new PointF(frame.GetMinX() + 0.29666F * frame.Width, frame.GetMinY() + 0.75510F * frame.Height),
                    new PointF(frame.GetMinX() + 0.29065F * frame.Width, frame.GetMinY() + 0.75535F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.14274F * frame.Width, frame.GetMinY() + 0.70173F * frame.Height),
                    new PointF(frame.GetMinX() + 0.23106F * frame.Width, frame.GetMinY() + 0.75535F * frame.Height),
                    new PointF(frame.GetMinX() + 0.18067F * frame.Width, frame.GetMinY() + 0.73625F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.14274F * frame.Width, frame.GetMinY() + 0.44291F * frame.Height),
                    new PointF(frame.GetMinX() + 0.06451F * frame.Width, frame.GetMinY() + 0.63038F * frame.Height),
                    new PointF(frame.GetMinX() + 0.06451F * frame.Width, frame.GetMinY() + 0.51425F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.45528F * frame.Width, frame.GetMinY() + 0.15799F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.48085F * frame.Width, frame.GetMinY() + 0.14832F * frame.Height),
                    new PointF(frame.GetMinX() + 0.46207F * frame.Width, frame.GetMinY() + 0.15176F * frame.Height),
                    new PointF(frame.GetMinX() + 0.47120F * frame.Width, frame.GetMinY() + 0.14832F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.50639F * frame.Width, frame.GetMinY() + 0.15799F * frame.Height),
                    new PointF(frame.GetMinX() + 0.49051F * frame.Width, frame.GetMinY() + 0.14832F * frame.Height),
                    new PointF(frame.GetMinX() + 0.49957F * frame.Width, frame.GetMinY() + 0.15176F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.50639F * frame.Width, frame.GetMinY() + 0.20462F * frame.Height),
                    new PointF(frame.GetMinX() + 0.52050F * frame.Width, frame.GetMinY() + 0.17087F * frame.Height),
                    new PointF(frame.GetMinX() + 0.52050F * frame.Width, frame.GetMinY() + 0.19177F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.19390F * frame.Width, frame.GetMinY() + 0.48951F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.19386F * frame.Width, frame.GetMinY() + 0.65510F * frame.Height),
                    new PointF(frame.GetMinX() + 0.14397F * frame.Width, frame.GetMinY() + 0.53518F * frame.Height),
                    new PointF(frame.GetMinX() + 0.14397F * frame.Width, frame.GetMinY() + 0.60942F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.28476F * frame.Width, frame.GetMinY() + 0.68936F * frame.Height),
                    new PointF(frame.GetMinX() + 0.21821F * frame.Width, frame.GetMinY() + 0.67720F * frame.Height),
                    new PointF(frame.GetMinX() + 0.25047F * frame.Width, frame.GetMinY() + 0.68936F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.37557F * frame.Width, frame.GetMinY() + 0.65514F * frame.Height),
                    new PointF(frame.GetMinX() + 0.31904F * frame.Width, frame.GetMinY() + 0.68936F * frame.Height),
                    new PointF(frame.GetMinX() + 0.35128F * frame.Width, frame.GetMinY() + 0.67720F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.68812F * frame.Width, frame.GetMinY() + 0.37025F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.71365F * frame.Width, frame.GetMinY() + 0.36056F * frame.Height),
                    new PointF(frame.GetMinX() + 0.69491F * frame.Width, frame.GetMinY() + 0.36401F * frame.Height),
                    new PointF(frame.GetMinX() + 0.70403F * frame.Width, frame.GetMinY() + 0.36056F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.73923F * frame.Width, frame.GetMinY() + 0.37025F * frame.Height),
                    new PointF(frame.GetMinX() + 0.72332F * frame.Width, frame.GetMinY() + 0.36056F * frame.Height),
                    new PointF(frame.GetMinX() + 0.73241F * frame.Width, frame.GetMinY() + 0.36401F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.73923F * frame.Width, frame.GetMinY() + 0.41681F * frame.Height),
                    new PointF(frame.GetMinX() + 0.75333F * frame.Width, frame.GetMinY() + 0.38310F * frame.Height),
                    new PointF(frame.GetMinX() + 0.75333F * frame.Width, frame.GetMinY() + 0.40399F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.42673F * frame.Width, frame.GetMinY() + 0.70173F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.42670F * frame.Width, frame.GetMinY() + 0.86737F * frame.Height),
                    new PointF(frame.GetMinX() + 0.37681F * frame.Width, frame.GetMinY() + 0.74744F * frame.Height),
                    new PointF(frame.GetMinX() + 0.37681F * frame.Width, frame.GetMinY() + 0.82172F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.51759F * frame.Width, frame.GetMinY() + 0.90159F * frame.Height),
                    new PointF(frame.GetMinX() + 0.45104F * frame.Width, frame.GetMinY() + 0.88944F * frame.Height),
                    new PointF(frame.GetMinX() + 0.48328F * frame.Width, frame.GetMinY() + 0.90159F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.60840F * frame.Width, frame.GetMinY() + 0.86743F * frame.Height),
                    new PointF(frame.GetMinX() + 0.55183F * frame.Width, frame.GetMinY() + 0.90159F * frame.Height),
                    new PointF(frame.GetMinX() + 0.58413F * frame.Width, frame.GetMinY() + 0.88944F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.92092F * frame.Width, frame.GetMinY() + 0.58246F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.94646F * frame.Width, frame.GetMinY() + 0.57284F * frame.Height),
                    new PointF(frame.GetMinX() + 0.92773F * frame.Width, frame.GetMinY() + 0.57623F * frame.Height),
                    new PointF(frame.GetMinX() + 0.93682F * frame.Width, frame.GetMinY() + 0.57284F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.97208F * frame.Width, frame.GetMinY() + 0.58246F * frame.Height),
                    new PointF(frame.GetMinX() + 0.95617F * frame.Width, frame.GetMinY() + 0.57284F * frame.Height),
                    new PointF(frame.GetMinX() + 0.96523F * frame.Width, frame.GetMinY() + 0.57623F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.97208F * frame.Width, frame.GetMinY() + 0.62912F * frame.Height),
                    new PointF(frame.GetMinX() + 0.98615F * frame.Width, frame.GetMinY() + 0.59535F * frame.Height),
                    new PointF(frame.GetMinX() + 0.98615F * frame.Width, frame.GetMinY() + 0.61626F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.65956F * frame.Width, frame.GetMinY() + 0.91398F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.51759F * frame.Width, frame.GetMinY() + 0.96761F * frame.Height),
                    new PointF(frame.GetMinX() + 0.62160F * frame.Width, frame.GetMinY() + 0.94854F * frame.Height),
                    new PointF(frame.GetMinX() + 0.57117F * frame.Width, frame.GetMinY() + 0.96761F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.51759F * frame.Width, frame.GetMinY() + 0.96761F * frame.Height));
                mmShapePath.ClosePath();
                mmShapePath.MoveTo(new PointF(frame.GetMinX() + 0.51965F * frame.Width, frame.GetMinY() + 0.81940F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.49408F * frame.Width, frame.GetMinY() + 0.80982F * frame.Height),
                    new PointF(frame.GetMinX() + 0.50999F * frame.Width, frame.GetMinY() + 0.81940F * frame.Height),
                    new PointF(frame.GetMinX() + 0.50091F * frame.Width, frame.GetMinY() + 0.81600F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.49408F * frame.Width, frame.GetMinY() + 0.76313F * frame.Height),
                    new PointF(frame.GetMinX() + 0.48000F * frame.Width, frame.GetMinY() + 0.79686F * frame.Height),
                    new PointF(frame.GetMinX() + 0.48000F * frame.Width, frame.GetMinY() + 0.77600F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.80659F * frame.Width, frame.GetMinY() + 0.47824F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.80662F * frame.Width, frame.GetMinY() + 0.31264F * frame.Height),
                    new PointF(frame.GetMinX() + 0.85650F * frame.Width, frame.GetMinY() + 0.43259F * frame.Height),
                    new PointF(frame.GetMinX() + 0.85650F * frame.Width, frame.GetMinY() + 0.35831F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.71574F * frame.Width, frame.GetMinY() + 0.27840F * frame.Height),
                    new PointF(frame.GetMinX() + 0.78226F * frame.Width, frame.GetMinY() + 0.29053F * frame.Height),
                    new PointF(frame.GetMinX() + 0.75001F * frame.Width, frame.GetMinY() + 0.27840F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.62493F * frame.Width, frame.GetMinY() + 0.31260F * frame.Height),
                    new PointF(frame.GetMinX() + 0.68146F * frame.Width, frame.GetMinY() + 0.27840F * frame.Height),
                    new PointF(frame.GetMinX() + 0.64921F * frame.Width, frame.GetMinY() + 0.29053F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.31239F * frame.Width, frame.GetMinY() + 0.59752F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.28684F * frame.Width, frame.GetMinY() + 0.60718F * frame.Height),
                    new PointF(frame.GetMinX() + 0.30556F * frame.Width, frame.GetMinY() + 0.60378F * frame.Height),
                    new PointF(frame.GetMinX() + 0.29644F * frame.Width, frame.GetMinY() + 0.60718F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.26125F * frame.Width, frame.GetMinY() + 0.59752F * frame.Height),
                    new PointF(frame.GetMinX() + 0.27718F * frame.Width, frame.GetMinY() + 0.60718F * frame.Height),
                    new PointF(frame.GetMinX() + 0.26808F * frame.Width, frame.GetMinY() + 0.60378F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.26125F * frame.Width, frame.GetMinY() + 0.55093F * frame.Height),
                    new PointF(frame.GetMinX() + 0.24715F * frame.Width, frame.GetMinY() + 0.58467F * frame.Height),
                    new PointF(frame.GetMinX() + 0.24715F * frame.Width, frame.GetMinY() + 0.56377F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.57377F * frame.Width, frame.GetMinY() + 0.26601F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.57380F * frame.Width, frame.GetMinY() + 0.10041F * frame.Height),
                    new PointF(frame.GetMinX() + 0.62368F * frame.Width, frame.GetMinY() + 0.22029F * frame.Height),
                    new PointF(frame.GetMinX() + 0.62368F * frame.Width, frame.GetMinY() + 0.14606F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.48291F * frame.Width, frame.GetMinY() + 0.06617F * frame.Height),
                    new PointF(frame.GetMinX() + 0.54946F * frame.Width, frame.GetMinY() + 0.07832F * frame.Height),
                    new PointF(frame.GetMinX() + 0.51721F * frame.Width, frame.GetMinY() + 0.06617F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.39208F * frame.Width, frame.GetMinY() + 0.10040F * frame.Height),
                    new PointF(frame.GetMinX() + 0.44863F * frame.Width, frame.GetMinY() + 0.06617F * frame.Height),
                    new PointF(frame.GetMinX() + 0.41637F * frame.Width, frame.GetMinY() + 0.07832F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.07956F * frame.Width, frame.GetMinY() + 0.38530F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.05400F * frame.Width, frame.GetMinY() + 0.39496F * frame.Height),
                    new PointF(frame.GetMinX() + 0.07274F * frame.Width, frame.GetMinY() + 0.39149F * frame.Height),
                    new PointF(frame.GetMinX() + 0.06365F * frame.Width, frame.GetMinY() + 0.39496F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.02841F * frame.Width, frame.GetMinY() + 0.38530F * frame.Height),
                    new PointF(frame.GetMinX() + 0.04434F * frame.Width, frame.GetMinY() + 0.39496F * frame.Height),
                    new PointF(frame.GetMinX() + 0.03525F * frame.Width, frame.GetMinY() + 0.39149F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.02841F * frame.Width, frame.GetMinY() + 0.33867F * frame.Height),
                    new PointF(frame.GetMinX() + 0.01434F * frame.Width, frame.GetMinY() + 0.37241F * frame.Height),
                    new PointF(frame.GetMinX() + 0.01434F * frame.Width, frame.GetMinY() + 0.35151F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.34095F * frame.Width, frame.GetMinY() + 0.05378F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.48291F * frame.Width, frame.GetMinY() + 0.00013F * frame.Height),
                    new PointF(frame.GetMinX() + 0.37888F * frame.Width, frame.GetMinY() + 0.01919F * frame.Height),
                    new PointF(frame.GetMinX() + 0.42931F * frame.Width, frame.GetMinY() + 0.00013F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.62491F * frame.Width, frame.GetMinY() + 0.05378F * frame.Height),
                    new PointF(frame.GetMinX() + 0.53657F * frame.Width, frame.GetMinY() + 0.00013F * frame.Height),
                    new PointF(frame.GetMinX() + 0.58700F * frame.Width, frame.GetMinY() + 0.01919F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.68292F * frame.Width, frame.GetMinY() + 0.19950F * frame.Height),
                    new PointF(frame.GetMinX() + 0.66705F * frame.Width, frame.GetMinY() + 0.09219F * frame.Height),
                    new PointF(frame.GetMinX() + 0.68815F * frame.Width, frame.GetMinY() + 0.14529F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.68143F * frame.Width, frame.GetMinY() + 0.21454F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.69786F * frame.Width, frame.GetMinY() + 0.21318F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.71580F * frame.Width, frame.GetMinY() + 0.21244F * frame.Height),
                    new PointF(frame.GetMinX() + 0.70379F * frame.Width, frame.GetMinY() + 0.21269F * frame.Height),
                    new PointF(frame.GetMinX() + 0.70984F * frame.Width, frame.GetMinY() + 0.21244F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.85774F * frame.Width, frame.GetMinY() + 0.26604F * frame.Height),
                    new PointF(frame.GetMinX() + 0.76941F * frame.Width, frame.GetMinY() + 0.21244F * frame.Height),
                    new PointF(frame.GetMinX() + 0.81981F * frame.Width, frame.GetMinY() + 0.23147F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.85774F * frame.Width, frame.GetMinY() + 0.52485F * frame.Height),
                    new PointF(frame.GetMinX() + 0.93599F * frame.Width, frame.GetMinY() + 0.33738F * frame.Height),
                    new PointF(frame.GetMinX() + 0.93599F * frame.Width, frame.GetMinY() + 0.45349F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.54521F * frame.Width, frame.GetMinY() + 0.80977F * frame.Height));
                mmShapePath.AddCurveToPoint(
                    new PointF(frame.GetMinX() + 0.51965F * frame.Width, frame.GetMinY() + 0.81940F * frame.Height),
                    new PointF(frame.GetMinX() + 0.53840F * frame.Width, frame.GetMinY() + 0.81600F * frame.Height),
                    new PointF(frame.GetMinX() + 0.52930F * frame.Width, frame.GetMinY() + 0.81940F * frame.Height));
                mmShapePath.AddLineTo(new PointF(frame.GetMinX() + 0.51965F * frame.Width, frame.GetMinY() + 0.81940F * frame.Height));
                mmShapePath.ClosePath();
                context.SaveState();
                context.SetShadowWithColor(mmDropShadowOffset, mmDropShadowBlurRadius, mmDropShadow.CGColor);
                context.SetBlendMode(CGBlendMode.Overlay);
                mmFill.SetFill();
                mmShapePath.Fill();

                RectangleF mmShapeBorderRect = RectangleF.Inflate(mmShapePath.Bounds, mmInnerShadowBlurRadius, mmInnerShadowBlurRadius);
                mmShapeBorderRect.Offset(mmInnerShadowOffset.Width, mmInnerShadowOffset.Height);
                mmShapeBorderRect.UnionWith(mmShapePath.Bounds);

                UIBezierPath mmShapeNegativePath = UIBezierPath.FromRect(mmShapeBorderRect);
                mmShapeNegativePath.AppendPath(mmShapePath);
                mmShapeNegativePath.UsesEvenOddFillRule = true;

                context.SaveState();
                {
                    Single xOffset = mmInnerShadowOffset.Width + (float)Math.Round(mmShapeBorderRect.Size.Width);
                    Single yOffset = mmInnerShadowOffset.Height;
                    context.SetShadowWithColor(new SizeF(xOffset + CopySign(0.1F, xOffset), yOffset + CopySign(0.1F, yOffset)), mmInnerShadowBlurRadius, mmInnerShadow.CGColor);
                    mmShapePath.AddClip();
                    CGAffineTransform transform = CGAffineTransform.MakeTranslation((float)-Math.Round(mmShapeBorderRect.Size.Width), 0F);
                    mmShapeNegativePath.ApplyTransform(transform);
                    UIColor.Gray.SetFill();
                    mmShapeNegativePath.Fill();
                }
                context.RestoreState();
                context.RestoreState();
            }
        }
Esempio n. 14
0
        void DisplayLayout( )
        {
            // scale the image to match the view's width
            ScreenToImageScalar = (float)SourceImage.Size.Width / (float)ImageView.Bounds.Width;

            // get the scaled dimensions, maintaining aspect ratio
            float scaledImageWidth  = (float)SourceImage.Size.Width * (1.0f / ScreenToImageScalar);
            float scaledImageHeight = (float)SourceImage.Size.Height * (1.0f / ScreenToImageScalar);

            // if the image's scaled down height would be greater than the device height,
            // recalc based on the height.
            if (scaledImageHeight > ImageView.Frame.Height)
            {
                ScreenToImageScalar = (float)SourceImage.Size.Height / (float)ImageView.Bounds.Height;

                scaledImageWidth  = (float)SourceImage.Size.Width * (1.0f / ScreenToImageScalar);
                scaledImageHeight = (float)SourceImage.Size.Height * (1.0f / ScreenToImageScalar);
            }


            // calculate the image's starting X / Y location
            nfloat imageStartX = (ImageView.Frame.Width - scaledImageWidth) / 2;
            nfloat imageStartY = (ImageView.Frame.Height - scaledImageHeight) / 2;


            // now calculate the size of the cropper
            nfloat cropperWidth  = scaledImageWidth;
            nfloat cropperHeight = scaledImageHeight;


            // get the image's aspect ratio so we can shrink down the cropper correctly
            nfloat aspectRatio = SourceImage.Size.Width / SourceImage.Size.Height;

            // if the cropper should be wider than it is tall (or square)
            if (CropAspectRatio <= 1.0f)
            {
                // then if the image is wider than it is tall, scale down the cropper's width
                if (aspectRatio > 1.0f)
                {
                    cropperWidth *= 1 / aspectRatio;
                }

                // and the height should be scaled down from the width
                cropperHeight = cropperWidth * CropAspectRatio;
            }
            else
            {
                // the cropper should be taller than it is wide

                // so if the image is taller than it is wide, scale down the cropper's height
                if (aspectRatio < 1.0f)
                {
                    cropperWidth *= 1 / aspectRatio;
                }

                // and the width should be scaled down from the height. (Invert CropAspectRatio since it was Width based)
                cropperWidth = cropperHeight * (1 / CropAspectRatio);
            }

            // set the crop bounds
            CropView.Frame = new CGRect(ImageView.Frame.X, ImageView.Frame.Y, cropperWidth, cropperHeight);


            // Now set the min / max movement bounds for the cropper
            CropViewMinPos = new CGPoint(imageStartX, imageStartY);

            CropViewMaxPos = new CGPoint((imageStartX + scaledImageWidth) - cropperWidth,
                                         (imageStartY + scaledImageHeight) - cropperHeight);

            // center the cropview
            CropView.Layer.Position = new CGPoint(0, 0);
            MoveCropView(new CGPoint(ImageView.Bounds.Width / 2, ImageView.Bounds.Height / 2));



            // setup the mask that will reveal only the part of the image that will be cropped
            FullscreenBlocker.Layer.Opacity = 0.00f;
            UIBezierPath viewFill = UIBezierPath.FromRect(FullscreenBlocker.Bounds);
            UIBezierPath cropMask = UIBezierPath.FromRoundedRect(new CGRect((FullscreenBlocker.Bounds.Width - CropView.Bounds.Width) / 2,
                                                                            (FullscreenBlocker.Bounds.Height - CropView.Bounds.Height) / 2,
                                                                            CropView.Bounds.Width,
                                                                            CropView.Bounds.Height), 4);

            viewFill.AppendPath(cropMask);
            FullscreenBlockerMask.Path = viewFill.CGPath;

            // and set our source image
            ImageView.Image = SourceImage;
        }
Esempio n. 15
0
        void DrawRect(CGRect rect)
        {
            // Draw two appropriate corners, with cornerBackgroundColor behind them.
            if (CornerRadius > 0)
            {
                nfloat       maxX = Bounds.GetMaxX();
                nfloat       maxY = Bounds.GetMaxY();
                UIBezierPath path = UIBezierPath.Create();
                CGPoint      pt   = CGPoint.Empty;
                switch (CornersPosition)
                {
                case MGCornersPosition.LeadingVertical:                         // top of screen for a left/right split
                    path.MoveTo(pt);
                    pt.Y += CornerRadius;
                    path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, DegreesToRadians(90), 0, true));
                    pt.X += CornerRadius;
                    pt.Y -= CornerRadius;
                    path.AddLineTo(pt);
                    path.AddLineTo(CGPoint.Empty);
                    path.ClosePath();

                    pt.X = maxX - CornerRadius;
                    pt.Y = 0;
                    path.MoveTo(pt);
                    pt.Y = maxY;
                    path.AddLineTo(pt);
                    pt.X += CornerRadius;
                    path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, DegreesToRadians(180), DegreesToRadians(90), true));
                    pt.Y -= CornerRadius;
                    path.AddLineTo(pt);
                    pt.X -= CornerRadius;
                    path.AddLineTo(pt);
                    path.ClosePath();

                    break;

                case MGCornersPosition.TrailingVertical:                         // bottom of screen for a left/right split
                    pt.Y = maxY;
                    path.MoveTo(pt);
                    pt.Y -= CornerRadius;
                    path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, DegreesToRadians(270), DegreesToRadians(360), false));
                    pt.X += CornerRadius;
                    pt.Y += CornerRadius;
                    path.AddLineTo(pt);
                    pt.X -= CornerRadius;
                    path.AddLineTo(pt);
                    path.ClosePath();

                    pt.X = maxX - CornerRadius;
                    pt.Y = maxY;
                    path.MoveTo(pt);
                    pt.Y -= CornerRadius;
                    path.AddLineTo(pt);
                    pt.X += CornerRadius;
                    path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, DegreesToRadians(180), DegreesToRadians(270), false));
                    pt.Y += CornerRadius;
                    path.AddLineTo(pt);
                    pt.X -= CornerRadius;
                    path.AddLineTo(pt);
                    path.ClosePath();

                    break;

                case MGCornersPosition.LeadingHorizontal:                         // left of screen for a top/bottom split
                    pt.X = 0;
                    pt.Y = CornerRadius;
                    path.MoveTo(pt);
                    pt.Y -= CornerRadius;
                    path.AddLineTo(pt);
                    pt.X += CornerRadius;
                    path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, DegreesToRadians(180), DegreesToRadians(270), false));
                    pt.Y += CornerRadius;
                    path.AddLineTo(pt);
                    pt.X -= CornerRadius;
                    path.AddLineTo(pt);
                    path.ClosePath();

                    pt.X = 0;
                    pt.Y = maxY - CornerRadius;
                    path.MoveTo(pt);
                    pt.Y = maxY;
                    path.AddLineTo(pt);
                    pt.X += CornerRadius;
                    path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, DegreesToRadians(180), DegreesToRadians(90), true));
                    pt.Y -= CornerRadius;
                    path.AddLineTo(pt);
                    pt.X -= CornerRadius;
                    path.AddLineTo(pt);
                    path.ClosePath();

                    break;

                case MGCornersPosition.TrailingHorizontal:                         // right of screen for a top/bottom split
                    pt.Y = CornerRadius;
                    path.MoveTo(pt);
                    pt.Y -= CornerRadius;
                    path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, DegreesToRadians(270), DegreesToRadians(360), false));
                    pt.X += CornerRadius;
                    pt.Y += CornerRadius;
                    path.AddLineTo(pt);
                    pt.X -= CornerRadius;
                    path.AddLineTo(pt);
                    path.ClosePath();

                    pt.Y = maxY - CornerRadius;
                    path.MoveTo(pt);
                    pt.Y += CornerRadius;
                    path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, DegreesToRadians(90), 0, true));
                    pt.X += CornerRadius;
                    pt.Y -= CornerRadius;
                    path.AddLineTo(pt);
                    pt.X -= CornerRadius;
                    path.AddLineTo(pt);
                    path.ClosePath();

                    break;

                default:
                    break;
                }

                CornerBackgroundColor.SetColor();
                path.Fill();
            }
        }
Esempio n. 16
0
        public override void Draw(CGRect rect)
        {
            // Draw two appropriate corners, with cornerBackgroundColor behind them.
            if (CornerRadius < 0)
            {
                return;
            }

            var maxX = Bounds.GetMaxX();
            var maxY = Bounds.GetMaxY();
            var path = new UIBezierPath();
            var pt   = CGPoint.Empty;

            switch (Position)
            {
            case CornersPosition.LeadingVertical:                     // top of screen for a left/right split
                path.MoveTo(pt);
                pt.Y += CornerRadius;
                path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, Deg2Rad(90), 0f, true));
                pt.X += CornerRadius;
                pt.Y -= CornerRadius;
                path.AddLineTo(pt);
                path.AddLineTo(CGPoint.Empty);
                path.ClosePath();

                pt.X = maxX - CornerRadius;
                pt.Y = 0;
                path.MoveTo(pt);
                pt.Y = maxY;
                path.AddLineTo(pt);
                pt.X += CornerRadius;
                path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, Deg2Rad(180f), Deg2Rad(90), true));
                pt.Y -= CornerRadius;
                path.AddLineTo(pt);
                pt.X -= CornerRadius;
                path.AddLineTo(pt);
                path.ClosePath();
                break;

            case CornersPosition.TrailingVertical:                     // bottom of screen for a left/right split
                pt.Y = maxY;
                path.MoveTo(pt);
                pt.Y -= CornerRadius;
                path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, Deg2Rad(270f), Deg2Rad(360), false));
                pt.X += CornerRadius;
                pt.Y += CornerRadius;
                path.AddLineTo(pt);
                pt.X -= CornerRadius;
                path.AddLineTo(pt);
                path.ClosePath();

                pt.X = maxX - CornerRadius;
                pt.Y = maxY;
                path.MoveTo(pt);
                pt.Y -= CornerRadius;
                path.AddLineTo(pt);
                pt.X += CornerRadius;
                path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, Deg2Rad(180f), Deg2Rad(270f), false));
                pt.Y += CornerRadius;
                path.AddLineTo(pt);
                pt.X -= CornerRadius;
                path.AddLineTo(pt);
                path.ClosePath();
                break;

            case CornersPosition.LeadingHorizontal:                     // left of screen for a top/bottom split
                pt.X = 0;
                pt.Y = CornerRadius;
                path.MoveTo(pt);
                pt.Y -= CornerRadius;
                path.AddLineTo(pt);
                pt.X += CornerRadius;
                path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, Deg2Rad(180), Deg2Rad(270), false));
                pt.Y += CornerRadius;
                path.AddLineTo(pt);
                pt.X -= CornerRadius;
                path.AddLineTo(pt);
                path.ClosePath();

                pt.X = 0;
                pt.Y = maxY - CornerRadius;
                path.MoveTo(pt);
                pt.Y = maxY;
                path.AddLineTo(pt);
                pt.X += CornerRadius;
                path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, Deg2Rad(180f), Deg2Rad(90f), true));
                pt.Y -= CornerRadius;
                path.AddLineTo(pt);
                pt.X -= CornerRadius;
                path.AddLineTo(pt);
                path.ClosePath();
                break;

            case CornersPosition.TrailingHorizontal:                     // right of screen for a top/bottom split
                pt.Y = CornerRadius;
                path.MoveTo(pt);
                pt.Y -= CornerRadius;
                path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, Deg2Rad(270f), Deg2Rad(360f), false));
                pt.X += CornerRadius;
                pt.Y += CornerRadius;
                path.AddLineTo(pt);
                pt.X -= CornerRadius;
                path.AddLineTo(pt);
                path.ClosePath();

                pt.Y = maxY - CornerRadius;
                path.MoveTo(pt);
                pt.Y += CornerRadius;
                path.AppendPath(UIBezierPath.FromArc(pt, CornerRadius, Deg2Rad(90), 0f, true));
                pt.X += CornerRadius;
                pt.Y -= CornerRadius;
                path.AddLineTo(pt);
                pt.X -= CornerRadius;
                path.AddLineTo(pt);
                path.ClosePath();
                break;
            }

            CornerBackgroundColor.SetFill();
            CornerBackgroundColor.SetStroke();
            path.Fill();
        }
Esempio n. 17
0
        public override void generatePointsForDrawing(CGRect Bounds)
        {
            if (this.startConnectable == null || this.endConnectable == null)
            {
                return;
            }

            //////////////////
            // prepare data //
            //////////////////

            var startPoints = this.startConnectable.attachmentPoints(this.startDir);
            var endPoints   = this.endConnectable.attachmentPoints(this.endDir);


            var myConvertedStartPoints = new Tuple <CGPoint, CGPoint>(
                this.ConvertPointFromView(startPoints.Item1, fromView: this.start),
                this.ConvertPointFromView(startPoints.Item2, fromView: this.start));

            var myConvertedEndPoints = new Tuple <CGPoint, CGPoint> (
                this.ConvertPointFromView(endPoints.Item1, fromView: this.end),
                this.ConvertPointFromView(endPoints.Item2, fromView: this.end));


            if (this.startDir == this.endDir)
            {
                var tempPoint = myConvertedStartPoints.Item1;
                myConvertedStartPoints = new Tuple <CGPoint, CGPoint>(
                    myConvertedStartPoints.Item2,
                    tempPoint);
            }

            var path = CreateMutablePath();// new CGPath();

            path.MoveToPoint(myConvertedStartPoints.Item1.X, myConvertedStartPoints.Item1.Y);
            path.AddLineToPoint(myConvertedEndPoints.Item2.X, myConvertedEndPoints.Item2.Y);
            path.AddLineToPoint(myConvertedEndPoints.Item1.X, myConvertedEndPoints.Item1.Y);
            path.AddLineToPoint(myConvertedStartPoints.Item2.X, myConvertedStartPoints.Item2.Y);
            path.CloseSubpath();


            // for now, assuming axis-aligned attachment points;
            var isVertical = (this.startDir == Direction.Up || this.startDir == Direction.Down) &&
                             (this.endDir == Direction.Up || this.endDir == Direction.Down);


            CGFloat midpoint;

            if (isVertical)
            {
                midpoint = myConvertedStartPoints.Item1.Y + (myConvertedEndPoints.Item2.Y - myConvertedStartPoints.Item1.Y) / 2;
            }
            else
            {
                midpoint = myConvertedStartPoints.Item1.X + (myConvertedEndPoints.Item2.X - myConvertedStartPoints.Item1.X) / 2;
            }

            var bezierPath = new UIBezierPath();
            var fillPath   = new UIBezierPath();

            var currentEdgePath = new UIBezierPath();

            List <UIBezierPath> edgePaths = new List <UIBezierPath>();

            bezierPath.MoveTo(myConvertedStartPoints.Item1);
            bezierPath.AddCurveToPoint(
                myConvertedEndPoints.Item2,
                controlPoint1: (isVertical ?
                                new CGPoint(myConvertedStartPoints.Item1.X, midpoint) :
                                new CGPoint(midpoint, myConvertedStartPoints.Item1.Y)),
                controlPoint2: (isVertical ?
                                new CGPoint(myConvertedEndPoints.Item2.X, midpoint) :
                                new CGPoint(midpoint, myConvertedEndPoints.Item2.Y)));
            //bezierPath.ApplyTransform(CGAffineTransform.MakeTranslation(0, -this.underOffset)); // <<<

            currentEdgePath = new UIBezierPath();
            currentEdgePath.MoveTo(myConvertedStartPoints.Item1);
            currentEdgePath.AddCurveToPoint(
                myConvertedEndPoints.Item2,
                controlPoint1: (isVertical ?
                                new CGPoint(myConvertedStartPoints.Item1.X, midpoint) :
                                new CGPoint(midpoint, myConvertedStartPoints.Item1.Y)),
                controlPoint2: (isVertical ?
                                new CGPoint(myConvertedEndPoints.Item2.X, midpoint) :
                                new CGPoint(midpoint, myConvertedEndPoints.Item2.Y)));
            currentEdgePath.ApplyTransform(CGAffineTransform.MakeTranslation(0, -this.underOffset));
            edgePaths.Add(currentEdgePath);
            fillPath.AppendPath(currentEdgePath);

            bezierPath.AddLineTo(myConvertedEndPoints.Item1);
            bezierPath.AddCurveToPoint(
                myConvertedStartPoints.Item2,
                controlPoint1: (isVertical ?
                                new CGPoint(myConvertedEndPoints.Item1.X, midpoint) :
                                new CGPoint(midpoint, myConvertedEndPoints.Item1.Y)),
                controlPoint2: (isVertical ?
                                new CGPoint(myConvertedStartPoints.Item2.X, midpoint) :
                                new CGPoint(midpoint, myConvertedStartPoints.Item2.Y)));
            //bezierPath.ApplyTransform(CGAffineTransform.MakeTranslation(0, -this.underOffset)); // <<<
            bezierPath.AddLineTo(myConvertedStartPoints.Item1);


            currentEdgePath = new UIBezierPath();
            currentEdgePath.MoveTo(myConvertedEndPoints.Item1);
            currentEdgePath.AddCurveToPoint(
                myConvertedStartPoints.Item2,
                controlPoint1: (isVertical ?
                                new CGPoint(myConvertedEndPoints.Item1.X, midpoint) :
                                new CGPoint(midpoint, myConvertedEndPoints.Item1.Y)),
                controlPoint2: (isVertical ?
                                new CGPoint(myConvertedStartPoints.Item2.X, midpoint) :
                                new CGPoint(midpoint, myConvertedStartPoints.Item2.Y)));
            currentEdgePath.ApplyTransform(CGAffineTransform.MakeTranslation(0, -this.underOffset));
            edgePaths.Add(currentEdgePath);
            fillPath.AppendPath(currentEdgePath);

            bezierPath.AddLineTo(myConvertedStartPoints.Item1);
            //fillPath.AddLineTo(myConvertedStartPoints.Item1);

            bezierPath.ClosePath();
            nfloat delta = 0;

            bezierPath.ApplyTransform(CGAffineTransform.MakeTranslation(0, -this.underOffset + delta));
            fillPath.ClosePath();

            this.fillPath  = bezierPath;
            this.edgePaths = edgePaths.ToArray();
        }
        public override void Draw(RectangleF rect)
        {
            // Draw two appropriate corners, with cornerBackgroundColor behind them.
            if (this.CornerRadius < 0)
            {
                return;
            }

            float fMaxX = this.Bounds.GetMaxX();
            float fMaxY =this.Bounds.GetMaxY();
            UIBezierPath oPath = new UIBezierPath();
            PointF oPt = PointF.Empty;
            switch (this.CornersPosition)
            {
                case CORNERS_POSITION.LeadingVertical: // top of screen for a left/right split
                    oPath.MoveTo(oPt);
                    oPt.Y += this.CornerRadius;
                    oPath.AppendPath(UIBezierPath.FromArc(oPt, this.CornerRadius, this.Deg2Rad(90), 0f, true));
                    oPt.X += this.CornerRadius;
                    oPt.Y -= this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPath.AddLineTo(PointF.Empty);
                    oPath.ClosePath();;

                    oPt.X = fMaxX - this.CornerRadius;
                    oPt.Y = 0;
                    oPath.MoveTo(oPt);
                    oPt.Y = fMaxY;
                    oPath.AddLineTo(oPt);
                    oPt.X += this.CornerRadius;
                    oPath.AppendPath(UIBezierPath.FromArc(oPt, this.CornerRadius, this.Deg2Rad(180f), this.Deg2Rad(90), true));
                    oPt.Y -= this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X -= this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPath.ClosePath();
                    break;

                case CORNERS_POSITION.TrailingVertical: // bottom of screen for a left/right split
                    oPt.Y = fMaxY;
                    oPath.MoveTo(oPt);
                    oPt.Y -= this.CornerRadius;
                    oPath.AppendPath(UIBezierPath.FromArc(oPt, this.CornerRadius, this.Deg2Rad(270f), this.Deg2Rad(360), false));
                    oPt.X +=this.CornerRadius;
                    oPt.Y +=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPath.ClosePath();

                    oPt.X = fMaxX -this.CornerRadius;
                    oPt.Y = fMaxY;
                    oPath.MoveTo(oPt);
                    oPt.Y -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X +=this.CornerRadius;
                    oPath.AppendPath(UIBezierPath.FromArc(oPt, this.CornerRadius, this.Deg2Rad(180f), this.Deg2Rad(270f), false));
                    oPt.Y +=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPath.ClosePath();
                break;

                case CORNERS_POSITION.LeadingHorizontal: // left of screen for a top/bottom split
                    oPt.X = 0;
                    oPt.Y =this.CornerRadius;
                    oPath.MoveTo(oPt);
                    oPt.Y -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X +=this.CornerRadius;
                    oPath.AppendPath(UIBezierPath.FromArc(oPt, this.CornerRadius, this.Deg2Rad(180), this.Deg2Rad(270), false));
                    oPt.Y +=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPath.ClosePath();

                    oPt.X = 0;
                    oPt.Y = fMaxY -this.CornerRadius;
                    oPath.MoveTo(oPt);
                    oPt.Y = fMaxY;
                    oPath.AddLineTo(oPt);
                    oPt.X +=this.CornerRadius;
                    oPath.AppendPath(UIBezierPath.FromArc(oPt, this.CornerRadius, this.Deg2Rad(180f), this.Deg2Rad(90f), true));
                    oPt.Y -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPath.ClosePath();
                    break;

                case CORNERS_POSITION.TrailingHorizontal: // right of screen for a top/bottom split
                    oPt.Y =this.CornerRadius;
                    oPath.MoveTo(oPt);
                    oPt.Y -=this.CornerRadius;
                    oPath.AppendPath(UIBezierPath.FromArc(oPt, this.CornerRadius, this.Deg2Rad(270f), this.Deg2Rad(360f), false));
                    oPt.X +=this.CornerRadius;
                    oPt.Y +=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPath.ClosePath();

                    oPt.Y = fMaxY -this.CornerRadius;
                    oPath.MoveTo(oPt);
                    oPt.Y +=this.CornerRadius;
                    oPath.AppendPath(UIBezierPath.FromArc(oPt, this.CornerRadius, this.Deg2Rad(90), 0f, true));
                    oPt.X +=this.CornerRadius;
                    oPt.Y -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPt.X -=this.CornerRadius;
                    oPath.AddLineTo(oPt);
                    oPath.ClosePath();
                break;

            default:
                break;
            }

            this.CornerBackgroundColor.SetFill();
            this.CornerBackgroundColor.SetStroke();
            oPath.Fill();
        }
Esempio n. 19
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;
        }