Пример #1
0
        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);
        }
Пример #2
0
        public ImagePanScrollBarView(RectangleF frame, UIEdgeInsets edgeInsets) : base(frame)
        {
            var scrollbarPath = UIBezierPath.Create();

            scrollbarPath.MoveTo(new PointF(edgeInsets.Left, Bounds.Height - edgeInsets.Bottom));
            scrollbarPath.AddLineTo(new PointF(Bounds.Width - edgeInsets.Right, Bounds.Height - edgeInsets.Bottom));

            var backgroundLayer = new CAShapeLayer()
            {
                Path        = scrollbarPath.CGPath,
                LineWidth   = 1,
                StrokeColor = UIColor.White.ColorWithAlpha(.1f).CGColor,
                FillColor   = UIColor.Clear.CGColor
            };


            scrollbarLayer = new CAShapeLayer()
            {
                Path        = scrollbarPath.CGPath,
                LineWidth   = 1,
                StrokeColor = UIColor.White.CGColor,
                FillColor   = UIColor.Clear.CGColor,
                Actions     = new NSDictionary("strokeStart", NSNull.Null, "strokeEnd", NSNull.Null)
            };

            Layer.AddSublayer(backgroundLayer);
            Layer.AddSublayer(scrollbarLayer);
        }
Пример #3
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            singleTapNeeded = false;
            // create a new path and set the options
            currentPath = new InkStroke(UIBezierPath.Create(), new List <CGPoint> (), StrokeColor, StrokeWidth);

            // obtain the location of the touch
            var touch         = touches.AnyObject as UITouch;
            var touchLocation = touch.LocationInView(this);

            // move the path to that position
            currentPath.Path.MoveTo(touchLocation);
            currentPath.GetPoints().Add(touchLocation);

            // update the dirty rectangle
            ResetBounds(touchLocation);

            Console.WriteLine("InkPresenter: Touches Began");

            if (touch != null)
            {
                Console.WriteLine($"InkPresenter: TapCount: {touch.TapCount}");
                if (touch.TapCount == 2)
                {
                    OnDoubleTapped();
                }
            }
        }
Пример #4
0
        public override void LayoutSublayersOfLayer(CALayer layer)
        {
            base.LayoutSublayersOfLayer(layer);

            if (layer == null || layer != this.Layer)
            {
                return;
            }

            var offset = CGPoint.Empty;
            var radius = Math.Min(Bounds.Width, Bounds.Height) / 2 - (_lineWidth / 2);

            offset.X = (nfloat)(Bounds.Width - radius * 2) / 2;
            offset.Y = (nfloat)(Bounds.Height - radius * 2) / 2;

            CATransaction.Begin();
            CATransaction.DisableActions = true;

            // Calculate frame for circle and trail circle
            var circleAndTrailFrame = new CGRect(offset.X, offset.Y, radius * 2, radius * 2);

            var circlePath = UIBezierPath.FromOval(circleAndTrailFrame);

            trailCircle.Path = circlePath.CGPath;

            circle.Transform = CATransform3D.Identity;
            circle.Frame     = this.Bounds;
            circle.Path      = UIBezierPath.FromOval(circleAndTrailFrame).CGPath;

            // Rotating circle by 212 degrees to be able to manipulate stroke end location.
            circle.Transform = CATransform3D.MakeRotation((float)(212 * Math.PI / 180), 0, 0, 1);

            var origin = new CGPoint(offset.X + radius, offset.Y + radius);

            // Calculate checkmark path
            var checkmarkPath       = UIBezierPath.Create();
            var checkmarkStartPoint = CGPoint.Empty;

            // Checkmark will start from circle's stroke end calculated above.
            checkmarkStartPoint.X = (nfloat)(origin.X + radius * ((float)(Math.Cos(212 * Math.PI / 180))));
            checkmarkStartPoint.Y = (nfloat)(origin.Y + radius * ((float)(Math.Sin(212 * Math.PI / 180))));
            checkmarkPath.MoveTo(checkmarkStartPoint);

            checkmarkSplitPoint = new CGPoint(offset.X + radius * 0.9, offset.Y + radius * 1.4);
            checkmarkPath.AddLineTo(checkmarkSplitPoint);

            var checkmarkEndPoint = CGPoint.Empty;

            // Checkmark will end 320 degrees location of the circle layer.
            checkmarkEndPoint.X = (nfloat)(origin.X + radius * (float)(Math.Cos(320 * Math.PI / 180)));
            checkmarkEndPoint.Y = (nfloat)(origin.Y + radius * (float)(Math.Sin(320 * Math.PI / 180)));
            checkmarkPath.AddLineTo(checkmarkEndPoint);

            checkmark.Frame = this.Bounds;
            checkmark.Path  = checkmarkPath.CGPath;

            CATransaction.Commit();
        }
Пример #5
0
        /* Returns a UIBezierPath object for the flat checkmark of the checkbox
         * @see BEMAnimationTypeFlat
         * @returns The path of the flat checkmark.
         */
        public UIBezierPath PathForFlatCheckMark()
        {
            UIBezierPath flatCheckMarkPath = UIBezierPath.Create();

            flatCheckMarkPath.MoveTo(new CGPoint(Size / 4, Size / 2));
            flatCheckMarkPath.AddLineTo(new CGPoint(new CGPoint(Size / 2, Size / 2)));
            flatCheckMarkPath.AddLineTo(new CGPoint(new CGPoint(Size / 1.2, Size / 2)));
            return(flatCheckMarkPath);
        }
Пример #6
0
        public ExclusionPathView(string text)
        {
            Text            = text;
            ContentInset    = new UIEdgeInsets(20, 0, 0, 0);
            BackgroundColor = UIColor.White;
            exclusionPath   = new CGPath();
            bezierPath      = UIBezierPath.Create();

            LayoutManager.AllowsNonContiguousLayout = false;
        }
Пример #7
0
        public void CreateNewPath(Stroke stroke)
        {
            CurrentPath = UIBezierPath.Create();

            CurrentPath.LineWidth     = (float)stroke.Thickness;
            CurrentPath.LineCapStyle  = CGLineCap.Round;
            CurrentPath.LineJoinStyle = CGLineJoin.Bevel;

            currentColor = stroke.StrokeColor;
        }
Пример #8
0
        //Delete the current signature.
        public void Clear()
        {
            paths       = new List <UIBezierPath> ();
            currentPath = UIBezierPath.Create();
            points      = new List <CGPoint[]> ();
            currentPoints.Clear();
            imageView.Image = null;
            btnClear.Hidden = true;

            SetNeedsDisplay();
        }
Пример #9
0
        /* Returns a UIBezierPath object for the checkmark of the checkbox
         * @returns The path of the checkmark.
         */
        public UIBezierPath PathForCheckMark()
        {
            UIBezierPath checkMarkPath = UIBezierPath.Create();

            checkMarkPath.MoveTo(new CGPoint(Size / 3.1578, Size / 2));
            checkMarkPath.AddLineTo(new CGPoint(Size / 2.0618, Size / 1.57894));
            checkMarkPath.AddLineTo(new CGPoint(Size / 1.3953, Size / 2.7272));

            if (BoxType == BemBoxType.BemBoxTypeSquare)
            {
                checkMarkPath.ApplyTransform(CGAffineTransform.MakeScale(new nfloat(1.5), new nfloat(1.5)));
                checkMarkPath.ApplyTransform(CGAffineTransform.MakeTranslation(-Size / 4, -Size / 4));
            }
            return(checkMarkPath);
        }
Пример #10
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // create a new path and set the options
            currentPath = new InkStroke(UIBezierPath.Create(), new List <CGPoint> (), StrokeColor, StrokeWidth);

            // obtain the location of the touch
            var touch         = touches.AnyObject as UITouch;
            var touchLocation = touch.LocationInView(this);

            // move the path to that position
            currentPath.Path.MoveTo(touchLocation);
            currentPath.GetPoints().Add(touchLocation);

            // update the dirty rectangle
            ResetBounds(touchLocation);
        }
Пример #11
0
        private void DrawGrid()
        {
            var size = new CGRect()
            {
                Width  = ContentSize.Width > Frame.Width ? Frame.Width : ContentSize.Width,
                Height = ContentSize.Height > Frame.Width ? Frame.Width : ContentSize.Height,
                X      = ContentOffset.X < 0 ? 0 : ContentOffset.X,
                Y      = ContentOffset.Y < 0 ? 0 : ContentOffset.Y,
            };

            var gridHeight = size.Height / (_linesCount + 1);
            var gridWidth  = size.Width / (_linesCount + 1);

            _path           = UIBezierPath.Create();
            _path.LineWidth = 1;

            for (int i = 1; i < _linesCount + 1; i++)
            {
                var start = new CGPoint(x: i * gridWidth + size.X, y: size.Y);
                var end   = new CGPoint(x: i * gridWidth + size.X, y: size.Height + size.Y);
                _path.MoveTo(start);
                _path.AddLineTo(end);
            }

            for (int i = 1; i < _linesCount + 1; i++)
            {
                var start = new CGPoint(x: size.X, y: i * gridHeight + size.Y);
                var end   = new CGPoint(x: size.Width + size.X, y: i * gridHeight + size.Y);
                _path.MoveTo(start);
                _path.AddLineTo(end);
            }
            _shapeLayer.RemoveAllAnimations();
            _shapeLayer.StrokeColor = _strokeColor.ColorWithAlpha(0.15f).CGColor;

            var animation = CABasicAnimation.FromKeyPath("strokeColor");

            animation.BeginTime = CAAnimation.CurrentMediaTime() + 0.2; //delay
            animation.Duration  = 0.2;
            animation.SetTo(_strokeColor.ColorWithAlpha(0).CGColor);
            animation.RemovedOnCompletion = false;
            animation.FillMode            = CAFillMode.Forwards;

            _shapeLayer.AddAnimation(animation, "flashStrokeColor");
            _shapeLayer.Path = _path.CGPath;
            _path.ClosePath();
        }
Пример #12
0
        //Draw the paths to the UIImage view
        private void drawPath()
        {
            UIGraphics.BeginImageContextWithOptions(Frame.Size, false, UIScreen.MainScreen.Scale);            //Support Retina when drawing
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetLineCap(CGLineCap.Round);            //TODO decide to make this an abstract (requires support on Android and WP)
            context.SetLineJoin(CGLineJoin.Round);          //TODO decide to make this an abstract (requires support on Android and WP)

            foreach (var stroke in Strokes)
            {
                if (stroke.Points.Count == 0)
                {
                    continue;
                }

                context.SetLineWidth((float)stroke.Thickness);
                context.SetStrokeColor(new UIColor((float)stroke.StrokeColor.R, (float)stroke.StrokeColor.G, (float)stroke.StrokeColor.B, (float)stroke.StrokeColor.A).CGColor);

                var p = UIBezierPath.Create();
                p.MoveTo(new CGPoint(stroke.Points[0].X, stroke.Points[0].Y));
                for (int i = 1; i < stroke.Points.Count; i++)
                {
                    p.AddLineTo(new CGPoint(stroke.Points[i].X, stroke.Points[i].Y));
                }

                if (stroke.ClosePath)
                {
                    p.AddLineTo(new CGPoint(stroke.Points[0].X, stroke.Points[0].Y));
                }

                context.AddPath(p.CGPath);
                context.StrokePath();
            }

            //Get the image
            UIImage image = UIGraphics.GetImageFromCurrentImageContext();

            //End the CGContext
            UIGraphics.EndImageContext();

            //Display the image
            ImageView.Image = image;
        }
Пример #13
0
        /// <summary>
        /// Delete the current signature.
        /// </summary>
        public void Clear()
        {
            paths       = new List <UIBezierPath>();
            currentPath = UIBezierPath.Create();
            points      = new List <CGPoint[]>();
            currentPoints.Clear();

            if (UseBitmapBuffer)
            {
                if (imageView.Image != null)
                {
                    imageView.Image.Dispose();
                }

                imageView.Image = null;
            }

            SetNeedsDisplay();
            NotifyIsBlankChanged();
        }
Пример #14
0
        public override void TouchesBegan(NSSet touches, UIEvent evt)
        {
            // create a new path and set the options
            currentPath = new InkStroke(UIBezierPath.Create(), new List <InkPoint> (), StrokeColor, StrokeWidth, InkSource.Touch, DateTime.UtcNow);

            // obtain the location of the touch
            var touch         = touches.AnyObject as UITouch;
            var touchLocation = touch.LocationInView(this);

            // move the path to that position
            currentPath.Path.MoveTo(touchLocation);
            currentPath.GetPoints().Add(new InkPoint(
                                            touchLocation,
                                            (float)touch.Force,
                                            null,
                                            TimeSpan.FromSeconds(touch.Timestamp)));

            // update the dirty rectangle
            ResetBounds(touchLocation);
        }
Пример #15
0
        public override void TouchesBegan(Foundation.NSSet touches, UIEvent evt)
        {
            //Create a new path and set the options.
            currentPath               = UIBezierPath.Create();
            currentPath.LineWidth     = StrokeWidth;
            currentPath.LineJoinStyle = CGLineJoin.Round;

            currentPoints.Clear();

            UITouch touch = touches.AnyObject as UITouch;

            //Obtain the location of the touch, move the path to that position and add it to the
            //current_points array.
            CGPoint touchLocation = touch.LocationInView(this);

            currentPath.MoveTo(touchLocation);
            currentPoints.Add(touchLocation);

            resetBounds(touchLocation);

            btnClear.Hidden = false;
        }
Пример #16
0
        /* Returns a UIBezierPath object for an extra long checkmark which is in contact with the box.
         * @returns The path of the checkmark.
         */
        public UIBezierPath PathForLongCheckMark()
        {
            UIBezierPath checkMarkPath = UIBezierPath.Create();

            checkMarkPath.MoveTo(new CGPoint(Size / 3.1578, Size / 2));
            checkMarkPath.AddLineTo(new CGPoint(Size / 2.0618, Size / 1.57894));


            if (BoxType == BemBoxType.BemBoxTypeSquare)
            {
                // If we use a square box, the check mark should be a little bit bigger
                checkMarkPath.AddLineTo(new CGPoint(new CGPoint(Size / 1.2053, Size / 4.5272)));
                checkMarkPath.ApplyTransform(CGAffineTransform.MakeScale(new nfloat(1.5), new nfloat(1.5)));
                checkMarkPath.ApplyTransform(CGAffineTransform.MakeTranslation(-Size / 4, -Size / 4));
            }
            else
            {
                checkMarkPath.AddLineTo(new CGPoint(new CGPoint(Size / 1.1553, Size / 5.9272)));
            }

            return(checkMarkPath);
        }
Пример #17
0
        /// <summary>
        /// Begin touches.
        /// </summary>
        /// <param name="touches">Touches to use.</param>
        /// <param name="evt">Event to use.</param>
        public override void TouchesBegan(Foundation.NSSet touches, UIEvent evt)
        {
            if (currentPath != null)
            {
                // Obtain the smoothed path and the points array for that path.
                currentPath = SmoothedPathWithGranularity(0, out currentPoints);

                // Add the smoothed path and points array to their Lists.
                paths.Add(currentPath);
                points.Add(currentPoints.ToArray());

                LoadNewImage();
                SetNeedsDisplay();
                NotifyIsBlankChanged();

                currentPath = null;
                currentPoints.Clear();
            }

            // Create a new path and set the options.
            currentPath               = UIBezierPath.Create();
            currentPath.LineWidth     = StrokeWidth;
            currentPath.LineJoinStyle = CGLineJoin.Round;

            currentPoints.Clear();

            UITouch touch = touches.AnyObject as UITouch;

            // Obtain the location of the touch, move the path to that position and add it to the
            // current_points array.
            CGPoint touchLocation = touch.LocationInView(this);

            currentPath.MoveTo(touchLocation);
            currentPoints.Add(touchLocation);

            ResetBounds(touchLocation);
        }
Пример #18
0
        /*
         * Obtain a smoothed path with the specified granularity from the current path using Catmull-Rom spline.
         * Implemented using a modified version of the code in the solution at
         * http://stackoverflow.com/questions/8702696/drawing-smooth-curves-methods-needed.
         * Also outputs a List of the points corresponding to the smoothed path.
         */
        UIBezierPath smoothedPathWithGranularity(int granularity, out List <CGPoint> smoothedPoints)
        {
            List <CGPoint> pointsArray = currentPoints;

            smoothedPoints = new List <CGPoint> ();

            //Not enough points to smooth effectively, so return the original path and points.
            if (pointsArray.Count < 4)
            {
                smoothedPoints = pointsArray;
                return(currentPath);
            }

            //Create a new bezier path to hold the smoothed path.
            UIBezierPath smoothedPath = UIBezierPath.Create();

            smoothedPath.LineWidth     = StrokeWidth;
            smoothedPath.LineJoinStyle = CGLineJoin.Round;

            //Duplicate the first and last points as control points.
            pointsArray.Insert(0, pointsArray [0]);
            pointsArray.Add(pointsArray [pointsArray.Count - 1]);

            //Add the first point
            smoothedPath.MoveTo(pointsArray [0]);
            smoothedPoints.Add(pointsArray [0]);

            for (var index = 1; index < pointsArray.Count - 2; index++)
            {
                CGPoint p0 = pointsArray [index - 1];
                CGPoint p1 = pointsArray [index];
                CGPoint p2 = pointsArray [index + 1];
                CGPoint p3 = pointsArray [index + 2];

                //Add n points starting at p1 + dx/dy up until p2 using Catmull-Rom splines
                for (var i = 1; i < granularity; i++)
                {
                    float t   = (float)i * (1f / (float)granularity);
                    float tt  = t * t;
                    float ttt = tt * t;

                    //Intermediate point
                    CGPoint mid = default(CGPoint);
                    mid.X = 0.5f * (2f * p1.X + (p2.X - p0.X) * t +
                                    (2f * p0.X - 5f * p1.X + 4f * p2.X - p3.X) * tt +
                                    (3f * p1.X - p0.X - 3f * p2.X + p3.X) * ttt);
                    mid.Y = 0.5f * (2 * p1.Y + (p2.Y - p0.Y) * t +
                                    (2 * p0.Y - 5 * p1.Y + 4 * p2.Y - p3.Y) * tt +
                                    (3 * p1.Y - p0.Y - 3 * p2.Y + p3.Y) * ttt);

                    smoothedPath.AddLineTo(mid);
                    smoothedPoints.Add(mid);
                }

                //Add p2
                smoothedPath.AddLineTo(p2);
                smoothedPoints.Add(p2);
            }

            //Add the last point
            smoothedPath.AddLineTo(pointsArray [pointsArray.Count - 1]);
            smoothedPoints.Add(pointsArray [pointsArray.Count - 1]);

            return(smoothedPath);
        }
Пример #19
0
        //Allow the user to import an array of points to be used to draw a signature in the view, with new
        //lines indicated by a CGPoint.Empty in the array.
        public void LoadPoints(CGPoint[] loadedPoints)
        {
            if (loadedPoints == null || loadedPoints.Count() == 0)
            {
                return;
            }

            var startIndex = 0;
            var emptyIndex = loadedPoints.ToList().IndexOf(CGPoint.Empty);

            if (emptyIndex == -1)
            {
                emptyIndex = loadedPoints.Count();
            }

            //Clear any existing paths or points.
            paths  = new List <UIBezierPath> ();
            points = new List <CGPoint[]> ();

            do
            {
                //Create a new path and set the line options
                currentPath               = UIBezierPath.Create();
                currentPath.LineWidth     = StrokeWidth;
                currentPath.LineJoinStyle = CGLineJoin.Round;

                currentPoints = new List <CGPoint> ();

                //Move to the first point and add that point to the current_points array.
                currentPath.MoveTo(loadedPoints [startIndex]);
                currentPoints.Add(loadedPoints [startIndex]);

                //Iterate through the array until an empty point (or the end of the array) is reached,
                //adding each point to the current_path and to the current_points array.
                for (var i = startIndex + 1; i < emptyIndex; i++)
                {
                    currentPath.AddLineTo(loadedPoints [i]);
                    currentPoints.Add(loadedPoints [i]);
                }

                //Add the current_path and current_points list to their respective Lists before
                //starting on the next line to be drawn.
                paths.Add(currentPath);
                points.Add(currentPoints.ToArray());

                //Obtain the indices for the next line to be drawn.
                startIndex = emptyIndex + 1;
                if (startIndex < loadedPoints.Count() - 1)
                {
                    emptyIndex = loadedPoints.ToList().IndexOf(CGPoint.Empty, startIndex);

                    if (emptyIndex == -1)
                    {
                        emptyIndex = loadedPoints.Count();
                    }
                }
                else
                {
                    emptyIndex = startIndex;
                }
            } while (startIndex < emptyIndex);

            //Obtain the image for the imported signature and display it in the image view.
            imageView.Image = GetImage(false);
            //Display the clear button.
            btnClear.Hidden = false;
            SetNeedsDisplay();
        }
Пример #20
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();
            }
        }
Пример #21
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            // 半透明区域
            UIColor.FromWhiteAlpha(0, 0.7f).SetFill();
            UIGraphics.RectFill(rect);

            //// 透明区域
            CGRect scanner_rect = new CGRect(Scanner_X, Scanner_Y, Scanner_Width, Scanner_Width);

            UIColor.Clear.SetFill();
            UIGraphics.RectFill(scanner_rect);

            // 边框
            UIBezierPath borderPath = UIBezierPath.FromRect(new CGRect(Scanner_X, Scanner_Y, Scanner_Width, Scanner_Width));

            borderPath.LineCapStyle = CGLineCap.Round;
            borderPath.LineWidth    = Scanner_BorderWidth;
            UIColor.White.SetColor();
            borderPath.Stroke();

            for (int index = 0; index < 4; ++index)
            {
                UIBezierPath tempPath = UIBezierPath.Create();
                tempPath.LineWidth = Scanner_CornerWidth;
                _lineColor.SetColor();

                switch (index)
                {
                // 左上角棱角
                case 0:
                {
                    tempPath.MoveTo(new CGPoint(Scanner_X + Scanner_CornerLength, Scanner_Y));
                    tempPath.AddLineTo(new CGPoint(Scanner_X, Scanner_Y));
                    tempPath.AddLineTo(new CGPoint(Scanner_X, Scanner_Y + Scanner_CornerLength));
                }
                break;

                // 右上角
                case 1:
                {
                    tempPath.MoveTo(new CGPoint(Scanner_X + Scanner_Width - Scanner_CornerLength, Scanner_Y));
                    tempPath.AddLineTo(new CGPoint(Scanner_X + Scanner_Width, Scanner_Y));
                    tempPath.AddLineTo(new CGPoint(Scanner_X + Scanner_Width, Scanner_Y + Scanner_CornerLength));
                }
                break;

                // 左下角
                case 2:
                {
                    tempPath.MoveTo(new CGPoint(Scanner_X, Scanner_Y + Scanner_Width - Scanner_CornerLength));
                    tempPath.AddLineTo(new CGPoint(Scanner_X, Scanner_Y + Scanner_Width));
                    tempPath.AddLineTo(new CGPoint(Scanner_X + Scanner_CornerLength, Scanner_Y + Scanner_Width));
                }
                break;

                // 右下角
                case 3:
                {
                    tempPath.MoveTo(new CGPoint(Scanner_X + Scanner_Width - Scanner_CornerLength, Scanner_Y + Scanner_Width));
                    tempPath.AddLineTo(new CGPoint(Scanner_X + Scanner_Width, Scanner_Y + Scanner_Width));
                    tempPath.AddLineTo(new CGPoint(Scanner_X + Scanner_Width, Scanner_Y + Scanner_Width - Scanner_CornerLength));
                }
                break;

                default:
                    break;
                }
                tempPath.Stroke();
            }
        }