Beispiel #1
0
        public override void Draw(CoreGraphics.CGRect rect)
        {
            base.Draw(rect);

            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                if (points != null)
                {
                    CGPath currentPath = new CGPath();
                    currentPath.AddLines(points);
                    g.AddPath(currentPath);
                    g.SetLineWidth(2);
                    if (invertColors)
                    {
                        g.SetStrokeColor(UIColor.FromRGB(255, 255, 255).CGColor);
                    }
                    else
                    {
                        g.SetStrokeColor(UIColor.FromRGB(0, 0, 0).CGColor);
                    }

                    g.AddLineToPoint(rect.Right, rect.Bottom);
                    g.AddLineToPoint(rect.Left, rect.Bottom);
                    g.ClosePath();

                    if (displayPoints)
                    {
                        g.SetAlpha(.7f);
                        g.SetFillColor(UIColor.FromRGB(100, 100, 100).CGColor);
                    }
                    else if (invertColors)
                    {
                        g.SetFillColor(UIColor.FromRGB(255, 255, 255).CGColor);
                    }
                    else
                    {
                        g.SetFillColor(UIColor.FromRGB(0, 0, 0).CGColor);
                    }

                    g.DrawPath(CGPathDrawingMode.FillStroke);
                    g.SetAlpha(1f);

                    if (displayPoints)
                    {
                        nfloat smallRadius = Frame.Width * .01f;
                        nfloat bigRadius   = Frame.Width * .03f;
                        foreach (CGPoint point in points)
                        {
                            g.SetFillColor(UIColor.FromRGB(0, 0, 0).CGColor);
                            g.SetAlpha(.3f);
                            g.AddArc(point.X, point.Y, bigRadius, 0.0f, (float)Math.PI * 2.0f, true);
                            g.FillPath();
                            g.SetAlpha(1f);
                            g.AddArc(point.X, point.Y, smallRadius, 0.0f, (float)Math.PI * 2.0f, true);
                            g.FillPath();
                        }
                    }
                }
            }
        }
Beispiel #2
0
        protected virtual void HandleShapeDraw(CGContext currentContext, RectangleF rect)
        {
            // Only used for circles
            var centerX    = rect.X + (rect.Width / 2);
            var centerY    = rect.Y + (rect.Height / 2);
            var radius     = rect.Width / 2;
            var startAngle = 0;
            var endAngle   = (float)(Math.PI * 2);

            switch (Element.ShapeType)
            {
            case ShapeType.Box:
                HandleStandardDraw(currentContext, rect, () => {
                    if (Element.CornerRadius > 0)
                    {
                        var path = UIBezierPath.FromRoundedRect(rect, Element.CornerRadius);
                        currentContext.AddPath(path.CGPath);
                    }
                    else
                    {
                        currentContext.AddRect(rect);
                    }
                });
                break;

            case ShapeType.Circle:
                HandleStandardDraw(currentContext, rect, () => currentContext.AddArc(centerX, centerY, radius, startAngle, endAngle, true));
                break;

            case ShapeType.CircleIndicator:
                HandleStandardDraw(currentContext, rect, () => currentContext.AddArc(centerX, centerY, radius, startAngle, endAngle, true));
                HandleStandardDraw(currentContext, rect, () => currentContext.AddArc(centerX, centerY, radius, QuarterTurnCounterClockwise, (float)(Math.PI * 2 * (Element.IndicatorPercentage / 100)) + QuarterTurnCounterClockwise, false), Element.StrokeWidth + 3);
                break;
            }
        }
Beispiel #3
0
 private void DrawCircles(CGContext ctx, int x, int y)
 {
     ctx.SetFillColor(PipColor);
     ctx.AddArc(x, y, PIP_RADIUS, 0, (float)(2 * Math.PI), true);
     ctx.DrawPath(CGPathDrawingMode.Fill);
     ctx.AddArc(x, y + 150, PIP_RADIUS, 0, (float)(2 * Math.PI), true);
     ctx.DrawPath(CGPathDrawingMode.Fill);
 }
 public void DrawArc(float cx, float cy, float radius, float startAngle, float endAngle, float w)
 {
     if (float.IsNaN(cx) || float.IsNaN(cy) || float.IsNaN(radius) || float.IsNaN(startAngle) || float.IsNaN(endAngle) || float.IsNaN(w))
     {
         System.Diagnostics.Debug.WriteLine("NaN in CoreGraphicsGraphics.DrawArc");
         return;
     }
     _c.SetLineWidth(w);
     _c.AddArc(cx, cy, radius, -startAngle, -endAngle, true);
     _c.StrokePath();
 }
Beispiel #5
0
        private void DrawArc(CGContext context, CGRect rect)
        {
            var    radius = rect.GetMaxY() * badgeCornerRoundness;
            var    puffer = new nfloat(Padding(rect));
            var    maxX   = rect.GetMaxX() - puffer;
            var    maxY   = rect.GetMaxY() - puffer;
            var    minX   = rect.GetMinX() + puffer;
            var    minY   = rect.GetMinY() + puffer;
            double pi     = Math.PI;

            context.AddArc(new nfloat(maxX - radius), new nfloat(minY + radius), new nfloat(radius), new nfloat(pi + (pi / 2)), 0, false);
            context.AddArc(new nfloat(maxX - radius), new nfloat(minY - radius), new nfloat(radius), 0, new nfloat(pi / 2), false);
        }
Beispiel #6
0
        private void FillRoundedRect(RectangleF rect, CGContext context)
        {
            float radius = 10.0f;

            context.BeginPath();
            context.SetGrayFillColor(0.0f, Opacity);
            context.MoveTo(rect.GetMinX() + radius, rect.GetMinY());
            context.AddArc(rect.GetMaxX() - radius, rect.GetMinY() + radius, radius, (float)(3 * Math.PI / 2), 0f, false);
            context.AddArc(rect.GetMaxX() - radius, rect.GetMaxY() - radius, radius, 0, (float)(Math.PI / 2), false);
            context.AddArc(rect.GetMinX() + radius, rect.GetMaxY() - radius, radius, (float)(Math.PI / 2), (float)Math.PI, false);
            context.AddArc(rect.GetMinX() + radius, rect.GetMinY() + radius, radius, (float)Math.PI, (float)(3 * Math.PI / 2), false);
            context.ClosePath();
            context.FillPath();
        }
        void FillRoundedRect(RectangleF rect, CGContext context)
        {
            float radius = 10.0f;

            context.BeginPath();
            //context.SetGrayFillColor (0.0f, this.Opacity);
            context.MoveTo(rect.GetMinX() + radius, rect.GetMinY());
            context.AddArc(rect.GetMaxX() - radius, rect.GetMinY() + radius, radius, (float)(3 * Math.PI / 2), 0f, false);
            context.AddArc(rect.GetMaxX() - radius, rect.GetMaxY() - radius, radius, 0, (float)(Math.PI / 2), false);
            context.AddArc(rect.GetMinX() + radius, rect.GetMaxY() - radius, radius, (float)(Math.PI / 2), (float)Math.PI, false);
            context.AddArc(rect.GetMinX() + radius, rect.GetMinY() + radius, radius, (float)Math.PI, (float)(3 * Math.PI / 2), false);
            context.ClosePath();
            context.SetFillColorWithColor(this.RectangleColor.CGColor);
            context.FillPath();

            context.SetStrokeColorWithColor(RectangleBorderColor.CGColor);
            context.BeginPath();
            //context.SetGrayFillColor (0.0f, this.Opacity);
            context.MoveTo(rect.GetMinX() + radius, rect.GetMinY());
            context.AddArc(rect.GetMaxX() - radius, rect.GetMinY() + radius, radius, (float)(3 * Math.PI / 2), 0f, false);
            context.AddArc(rect.GetMaxX() - radius, rect.GetMaxY() - radius, radius, 0, (float)(Math.PI / 2), false);
            context.AddArc(rect.GetMinX() + radius, rect.GetMaxY() - radius, radius, (float)(Math.PI / 2), (float)Math.PI, false);
            context.AddArc(rect.GetMinX() + radius, rect.GetMinY() + radius, radius, (float)Math.PI, (float)(3 * Math.PI / 2), false);
            context.ClosePath();

            context.StrokePath();
        }
Beispiel #8
0
		static void addPath(CGContext context, CGRect rect, float radius, RoundedCorner cornerMask)
		{
			context.MoveTo(rect.X, rect.Y + radius);
			context.AddLineToPoint(rect.X, rect.Y + rect.Height - radius);
			if (((int)cornerMask & (int)RoundedCorner.BottomLeft) != 0) {
				context.AddArc(rect.X + radius, rect.Y + rect.Height - radius, 
					radius, (nfloat)Math.PI, (nfloat)Math.PI / 2, true);
			}
			else {
				context.AddLineToPoint(rect.X, rect.Y + rect.Height);
				context.AddLineToPoint(rect.X + radius, rect.Y + rect.Height);
			}

			context.AddLineToPoint(rect.X + rect.Width - radius, 
				rect.Y + rect.Height);

			if (((int)cornerMask & (int)RoundedCorner.BottomRight) != 0) {
				context.AddArc(rect.X + rect.Width - radius, 
					rect.Y + rect.Height - radius, radius, (nfloat)Math.PI / 2, 0.0f, true);
			}
			else {
				context.AddLineToPoint(rect.X + rect.Width, rect.Y + rect.Height);
				context.AddLineToPoint(rect.X + rect.Width, rect.Y + rect.Height - radius);
			}

			context.AddLineToPoint(rect.X + rect.Width, rect.Y + radius);

			if (((int)cornerMask & (int)RoundedCorner.TopRight) != 0) {
				context.AddArc(rect.X + rect.Width - radius, rect.Y + radius, 
					radius, 0, -(nfloat)Math.PI / 2, true);
			}
			else {
				context.AddLineToPoint(rect.X + rect.Width, rect.Y);
				context.AddLineToPoint(rect.X + rect.Width - radius, rect.Y);
			}

			context.AddLineToPoint(rect.X + radius, rect.Y);

			if (((int)cornerMask & (int)RoundedCorner.TopLeft) != 0) {
				context.AddArc(rect.X + radius, rect.Y + radius, radius, 
					-(nfloat)Math.PI / 2, (nfloat)Math.PI, true);
			}
			else {
				context.AddLineToPoint(rect.X, rect.Y);
				context.AddLineToPoint(rect.X, rect.Y + radius);
			}

			context.ClosePath();
		}
Beispiel #9
0
        public static void AddBottomRoundedRect(this CGContext c, RectangleF b, float r)
        {
            c.MoveTo(b.Left, b.Top + r);
            c.AddLineToPoint(b.Left, b.Bottom - r);

            c.AddArc(b.Left + r, b.Bottom - r, r, (float)(Math.PI), (float)(Math.PI / 2), true);

            c.AddLineToPoint(b.Right - r, b.Bottom);

            c.AddArc(b.Right - r, b.Bottom - r, r, (float)(-3 * Math.PI / 2), (float)(0), true);

            c.AddLineToPoint(b.Right, b.Top);

            c.AddLineToPoint(b.Left, b.Top);
        }
 public override void Draw(CGRect rect)
 {
     using (CGContext g = UIGraphics.GetCurrentContext())
     {
         g.AddArc((nfloat)Element.X, (nfloat)Element.Y, (nfloat)Element.RX, 0, (nfloat)Element.SweepAngle, true);
     }
 }
        public override void Draw(RectangleF rect)
        {
            RectangleF allRect    = this.Bounds;
            RectangleF circleRect = new RectangleF(allRect.Location.X + 2, allRect.Location.Y + 2, allRect.Size.Width - 4, allRect.Size.Height - 4);

            CGContext context = UIGraphics.GetCurrentContext();

            // Draw background
            context.SetRGBStrokeColor(1.0f, 1.0f, 1.0f, 1.0f);
            // white
            context.SetRGBFillColor(1.0f, 1.0f, 1.0f, 0.1f);
            // translucent white
            context.SetLineWidth(2.0f);
            context.FillEllipseInRect(circleRect);
            context.StrokeEllipseInRect(circleRect);

            // Draw progress
            float x = (allRect.Size.Width / 2);
            float y = (allRect.Size.Height / 2);

            context.SetRGBFillColor(1.0f, 1.0f, 1.0f, 1.0f);
            // white
            context.MoveTo(x, y);
            context.AddArc(x, y, (allRect.Size.Width - 4) / 2, -(float)(Math.PI / 2), (float)(this.Progress * 2 * Math.PI) - (float)(Math.PI / 2), false);
            context.ClosePath();
            context.FillPath();
        }
Beispiel #12
0
        public override void Draw(CGRect rect)
        {
            // Load image
            UIImage image = new UIImage("logo.png");
            // Get drawing context
            CGContext ctx = UIGraphics.GetCurrentContext();
            // get view bounds
            CGRect bounds = this.Bounds;
            // Find the center of view
            CGPoint center = new CGPoint();

            center.X = bounds.X + bounds.Width / 2;
            center.Y = bounds.Y + bounds.Height / 2;
            // Compute the max radius of the circle
            float maxRadius = (float)Math.Sqrt(Math.Pow(bounds.Size.Width, 2) + Math.Pow(bounds.Size.Height, 2)) / 3.0f;

            ctx.SaveState();
            // draw outline circle with 1 pt black shadow
            ctx.AddArc(center.X, center.Y, maxRadius, 0, (float)(Math.PI * 2), true);
            CGSize  offset      = new CGSize(0, 1);
            CGColor shadowColor = UIColor.Black.CGColor;

            ctx.SetShadow(offset, 2, shadowColor);
            ctx.DrawPath(CGPathDrawingMode.Stroke);
            // clear shadow
            ctx.RestoreState();
            // set clipping circle
            ctx.AddArc(center.X, center.Y, maxRadius, 0, (float)(Math.PI * 2), true);
            ctx.Clip();
            // Draw the image in the circle
            image.Draw(bounds);

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();

            nfloat[] components = new nfloat[8] {
                0.8f, 0.8f, 1, 1, 0.8f, 0.8f, 1, 0
            };
            nfloat[] locations = new nfloat[2] {
                0.0f, 1
            };

            CGGradient gradient = new CGGradient(colorSpace, components, locations);

            ctx.DrawLinearGradient(gradient, new CGPoint(bounds.Width / 2, 0), new CGPoint(bounds.Width / 2, bounds.Height / 2), 0);
        }
Beispiel #13
0
        public void draw(CGContext context)
        {
            double radius = Math.Sqrt(Math.Pow((this.center.X - this.point2.X) / 2, 2) + Math.Pow((this.center.Y - this.point2.Y) / 2, 2));

            context.AddArc(this.center.X, this.center.Y, (float)radius, 0.0f, (float)Math.PI * 2, true);

            _color.SetStroke();

            context.StrokePath();
        }
Beispiel #14
0
        protected virtual void HandleShapeDraw(CGContext currentContext, RectangleF rect)
        {
            var centerX    = rect.X + (rect.Width / 2);
            var centerY    = rect.Y + (rect.Height / 2);
            var radius     = rect.Width / 2;
            var startAngle = 0;
            var endAngle   = (float)(Math.PI * 2);

            HandleStandardDraw(currentContext, rect, () => currentContext.AddArc(centerX, centerY, radius, startAngle, endAngle, true));
        }
        private void DrawCurrentTouch(CGContext ctx)
        {
            if (mCurrTouch == PointF.Empty)
            {
                return;
            }

            var parentDIV       = (DrawingImageView)Superview;
            var grandParentDISV = (DrawingImageScrollView)parentDIV.Superview;
            var zoomScale       = grandParentDISV.ZoomScale;

            // circle
            try
            {
                ctx.SaveState();
                ctx.BeginPath();

                ctx.SetStrokeColorWithColor(LineColor);
                ctx.SetLineWidth(9f / zoomScale);

                var rad = CurrentTouchRadius / zoomScale;

                ctx.AddArc(mCurrTouch.X, mCurrTouch.Y, rad, 0.0f, 2.0f * (float)Math.PI, true);
            }
            finally
            {
                ctx.StrokePath();
                ctx.RestoreState();
            }

            // crosshairs
            try
            {
                ctx.SaveState();
                ctx.BeginPath();

                ctx.SetStrokeColorWithColor(LineColor);
                ctx.SetLineWidth(1f / zoomScale);

                // horizontal line
                ctx.MoveTo(0f, mCurrTouch.Y);
                ctx.AddLineToPoint(Frame.Right, mCurrTouch.Y);

                // vertical line
                ctx.MoveTo(mCurrTouch.X, 0f);
                ctx.AddLineToPoint(mCurrTouch.X, Frame.Bottom);
            }
            finally
            {
                ctx.StrokePath();
                ctx.RestoreState();
            }
        }
Beispiel #16
0
        private nfloat MakePath(CGContext context, CGRect rect)
        {
            var radius = rect.Bottom * this._cornerRoundness;
            var puffer = rect.Bottom * 0.12f;
            var maxX   = rect.Right - (puffer * 2f);
            var maxY   = rect.Bottom - puffer;
            var minX   = rect.Left + (puffer * 2f);
            var minY   = rect.Top + puffer;

            if (maxX - minX < 20f)
            {
                maxX = rect.Right - puffer;
                minX = rect.Left + puffer;
            }

            context.AddArc(maxX - radius, minY + radius, radius, (float)(Math.PI + (Math.PI / 2)), 0f, false);
            context.AddArc(maxX - radius, maxY - radius, radius, 0, (float)(Math.PI / 2), false);
            context.AddArc(minX + radius, maxY - radius, radius, (float)(Math.PI / 2), (float)Math.PI, false);
            context.AddArc(minX + radius, minY + radius, radius, (float)Math.PI, (float)(Math.PI + Math.PI / 2), false);

            return(maxY);
        }
        public static void AddRoundedRect(this CGContext c, RectangleF b, float r)
        {
            var x = b.X;
            var y = b.Y;
            var w = b.Width;
            var h = b.Height;

            if (w < 0)
            {
                x += w;
                w  = Math.Abs(w);
            }
            if (h < 0)
            {
                y += h;
                h  = Math.Abs(h);
            }

            var ri = x + w;
            var bo = y + h;

            c.MoveTo(x, y + r);
            c.AddLineToPoint(x, bo - r);

            c.AddArc(x + r, bo - r, r, (float)(Math.PI), (float)(Math.PI / 2), true);

            c.AddLineToPoint(ri - r, bo);

            c.AddArc(ri - r, bo - r, r, (float)(-3 * Math.PI / 2), (float)(0), true);

            c.AddLineToPoint(ri, y + r);

            c.AddArc(ri - r, y + r, r, (float)(0), (float)(-Math.PI / 2), true);

            c.AddLineToPoint(x + r, y);

            c.AddArc(x + r, y + r, r, (float)(-Math.PI / 2), (float)(Math.PI), true);
        }
 private void DrawCircles(CGContext ctx, int x, int y)
 {
     ctx.SetFillColor(new CGColor(ApplicationDefaults.DefaultPipColors
                                  .GetItem <NSArray <NSNumber> >((System.nuint)_pipCount - 1)
                                  .GetItem <NSNumber>(0).FloatValue,
                                  ApplicationDefaults.DefaultPipColors
                                  .GetItem <NSArray <NSNumber> >((System.nuint)_pipCount - 1)
                                  .GetItem <NSNumber>(1).FloatValue,
                                  ApplicationDefaults.DefaultPipColors
                                  .GetItem <NSArray <NSNumber> >((System.nuint)_pipCount - 1)
                                  .GetItem <NSNumber>(2).FloatValue));
     ctx.AddArc(x + 50, y + 38, PIP_RADIUS, 0, (float)(2 * Math.PI), true);
     ctx.DrawPath(CGPathDrawingMode.Fill);
 }
Beispiel #19
0
        public override void DrawInContext(CGContext ctx)
        {
            base.DrawInContext(ctx);

            var bounds = Bounds;
            var c      = new PointF(bounds.GetMidX(), bounds.GetMidY());

            ctx.BeginPath();
            ctx.MoveTo(c.X, c.Y);
            ctx.AddLineToPoint(bounds.Right, c.Y);
            ctx.AddArc(c.X, c.Y, bounds.Width / 2, (float)0, (float)Angle, false);
            ctx.AddLineToPoint(c.X, c.Y);
            ctx.SetFillColor(otherColor);
            ctx.FillPath();

            ctx.BeginPath();
            ctx.MoveTo(c.X, c.Y);
            ctx.AddLineToPoint(bounds.Right, c.Y);
            ctx.AddArc(c.X, c.Y, bounds.Width / 2, (float)0, (float)(1e-7 + Angle), true);
            ctx.AddLineToPoint(c.X, c.Y);
            ctx.SetFillColor(color);
            ctx.FillPath();
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                _circleColor.SetFill();
                context.FillEllipseInRect(_circleRect);

                _arcColor.SetFill();
                context.AddArc(_centerX, _centerY, _radius, _startAngle, _endAngle, true);
                context.AddLineToPoint(_centerX, _centerY);
                context.FillPath();
            }
        }
Beispiel #21
0
        private void _chart_OnDrawCircle(object sender, Charting.Controls.Chart.DrawEventArgs <Events.SingleDrawingData> e)
        {
            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                g.SetLineWidth(2);
                Colors[e.Data.SeriesNo].SetFill();
                Colors[e.Data.SeriesNo].SetStroke();

                float startAngle = -((float)Math.PI / 2);
                float endAngle   = ((2 * (float)Math.PI) + startAngle);
                g.AddArc((float)e.Data.X, (float)e.Data.Y, (float)e.Data.Size, startAngle, endAngle, true);

                g.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Beispiel #22
0
        public override void DrawLayer(CALayer layer, CGContext context)
        {
            var   radius = (float)FormsButton.WidthRequest / 2;
            var   offset = BorderThickness / 2;
            float angle  = (FormsButton.Completion + .75f) * 2 * (float)Math.PI;

            context.AddEllipseInRect(CGRect.FromLTRB(offset, offset, (float)FormsButton.WidthRequest - offset, (float)FormsButton.HeightRequest - offset));
            context.SetStrokeColor(UIColor.White.CGColor);
            context.SetLineWidth(BorderThickness);
            context.StrokePath();

            context.SetStrokeColor(UIColor.Red.CGColor);
            context.AddArc(radius, radius, radius - offset, 1.5f * (float)Math.PI, angle, false);
            context.StrokePath();
        }
        public static void drawUnfilledArcInContext(CGContext ctx, CGPoint center, nfloat radius, nfloat lineWidth, nfloat fromAngleFromNorth, nfloat toAngleFromNorth)
        {
            var cartesianFromAngle = (nfloat)CompassToCartesian(ConvertToRadians(fromAngleFromNorth));
            var cartesianToAngle   = (nfloat)CompassToCartesian(ConvertToRadians(toAngleFromNorth));

            ctx.AddArc(center.X,   // arc start point x
                       center.Y,   // arc start point y
                       radius,     // arc radius from center
                       cartesianFromAngle, cartesianToAngle,
                       false);     // iOS flips the y coordinate so anti-clockwise (specified here by 0) becomes clockwise (desired)!

            ctx.SetLineWidth(lineWidth);
            ctx.SetLineCap(CGLineCap.Butt);
            ctx.DrawPath(CGPathDrawingMode.Stroke);
        }
Beispiel #24
0
		public override void DrawInContext (CGContext ctx)
		{
			base.DrawInContext (ctx);
			
			var bounds = Bounds;
			var c = new PointF (bounds.GetMidX (), bounds.GetMidY ());
			
			ctx.BeginPath ();
			ctx.MoveTo (c.X, c.Y);
			ctx.AddLineToPoint (bounds.Right, c.Y);
			ctx.AddArc (c.X, c.Y, bounds.Width/2, (float)0, (float)Angle, false);
			ctx.AddLineToPoint (c.X, c.Y);
			ctx.SetFillColor (otherColor);
			ctx.FillPath ();
			
			ctx.BeginPath ();
			ctx.MoveTo (c.X, c.Y);
			ctx.AddLineToPoint (bounds.Right, c.Y);
			ctx.AddArc (c.X, c.Y, bounds.Width/2, (float)0, (float)(1e-7 + Angle), true);
			ctx.AddLineToPoint (c.X, c.Y);
			ctx.SetFillColor (color);
			ctx.FillPath ();
			
		}
Beispiel #25
0
        public static void RoundRectPath(CGContext cr, CGRect rect, float[] cornerRadii)
        {
            if (cornerRadii == null || cornerRadii.Length != 4)
            {
                throw new ArgumentOutOfRangeException("cornerRadii", "cornerRadii count must be 4.");
            }

            cr.BeginPath();
            float radius = cornerRadii[0];

            cr.AddArc(rect.X + radius, rect.Y + radius, radius, (float)Math.PI, (float)(3.0f * Math.PI / 2.0f), false);

            radius = cornerRadii[1];
            cr.AddArc(rect.X + rect.Width - radius, rect.Y + radius, radius, (float)(3.0f * Math.PI / 2.0f), 2.0f * (float)Math.PI, false);

            radius = cornerRadii[2];
            cr.AddArc(rect.X + rect.Width - radius, rect.Y + rect.Height - radius, radius, (float)(2 * Math.PI), 5.0f * ((float)Math.PI / 2.0f), false);

            radius = cornerRadii[3];
            cr.AddArc(rect.X + radius, rect.Y + rect.Height - radius, radius, (float)(5.0f * Math.PI / 2.0f), (float)(3.0f * Math.PI), false);


            cr.ClosePath();
        }
Beispiel #26
0
        private void _chart_OnDrawPie(object sender, Charting.Controls.Chart.DrawEventArgs <Events.PieDrawingData> e)
        {
            double totalDegrees = 0;

            for (int i = 0; i < e.Data.Percentages.Length; i++)
            {
                double degrees = e.Data.Percentages[i];
                using (CGContext g = UIGraphics.GetCurrentContext())
                {
                    g.SetLineWidth(2);
                    Colors[i].SetFill();
                    Colors[i].SetStroke();

                    g.AddArc((float)e.Data.X, (float)e.Data.Y, (float)e.Data.Size, (float)(Math.PI / 180 * totalDegrees), (float)(Math.PI / 180 * degrees), true);

                    g.DrawPath(CGPathDrawingMode.FillStroke);
                }
                totalDegrees += degrees;
            }
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            CGContext context = UIGraphics.GetCurrentContext();

            CGRect  bounds = rect;
            CGPoint center = new CGPoint();

            center.X = (nfloat)(bounds.Size.Width / 2.0);
            center.Y = (nfloat)(bounds.Size.Height / 2.0);

            context.SaveState();
            context.SetFillColor(UIColor.Blue.CGColor);

            context.AddArc(center.X, center.Y, _radius, 0, GetRadians(300), false);
            context.AddLineToPoint(center.X, center.Y);
            context.AddLineToPoint(rect.Width, center.Y);

            context.DrawPath(CGPathDrawingMode.Fill);
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            using (CGContext g = UIGraphics.GetCurrentContext()) {
                g.SetFillColor((UIColor.FromPatternImage(UIImage.FromBundle(ImageFileName)).CGColor));

                if (ScratchViewShape == Shape.Rectangle)
                {
                    g.FillRect(rect);
                }
                else
                {
                    g.AddArc(rect.Width / 2, rect.Height / 2, rect.Width / 2, 0, (float)Math.PI * 2.0f, true);
                    g.FillPath();
                }

                if (!initialPoint.IsEmpty)
                {
                    g.SetLineWidth(20);
                    g.SetBlendMode(CGBlendMode.Clear);
                    UIColor.Clear.SetColor();

                    if (path.IsEmpty || startNewPath)
                    {
                        path.AddLines(new CGPoint[] { initialPoint, latestPoint });
                        startNewPath = false;
                    }
                    else
                    {
                        path.AddLineToPoint(latestPoint);
                    }

                    g.SetLineCap(CGLineCap.Round);
                    g.AddPath(path);
                    g.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
        }
Beispiel #29
0
 private void drawArc(CGContext context, CGRect rect)
 {
     var radius = rect.GetMaxY() * badgeCornerRoundness;
     var puffer = new nfloat(Padding(rect));
     var maxX = rect.GetMaxX() - puffer;
     var maxY = rect.GetMaxY() - puffer;
     var minX = rect.GetMinX() + puffer;
     var minY = rect.GetMinY() + puffer;
     double pi = Math.PI;
     context.AddArc(new nfloat(maxX - radius), new nfloat(minY + radius), new nfloat(radius), new nfloat(pi + (pi / 2)), 0, false);
     context.AddArc(new nfloat(maxX - radius), new nfloat(minY - radius), new nfloat(radius), 0, new nfloat(pi / 2), false);
 }
Beispiel #30
0
        public override void Draw(RectangleF rect)
        {
            float x     = 105;
            float y     = 105;
            float r     = 100;
            float twopi = (2f * (float)Math.PI) * -1f;

            CGContext ctx = UIGraphics.GetCurrentContext();

            //base circle
            UIColor.FromRGB(137, 136, 133).SetColor();
            ctx.AddArc(x, y, r + 3, 0, twopi, true);
            ctx.FillPath();

            //border circle
            UIColor.FromRGB(231, 231, 231).SetColor();
            ctx.AddArc(x, y, r, 0, twopi, true);
            ctx.FillPath();

            //Center circle
            UIColor.White.SetColor();
            ctx.AddArc(x, y, r / 1.2f, 0, twopi, true);
            ctx.FillPath();

            UIColor.Black.SetFill();
            //Slow
            SizeF stringSize = StringSize("Fast", font10);

            DrawString("Fast", new PointF(105 - r + 7, 105 + r / 2 - 28), stringSize.Width, font10, UILineBreakMode.TailTruncation);

            //fast
            stringSize = StringSize("Slow", font10);
            DrawString("Slow", new PointF(105 + r - 25, 105 - r / 2 + 20), stringSize.Width, font10, UILineBreakMode.TailTruncation);

            //pubnub
            UIColor.Red.SetFill();
            stringSize = StringSize("PubNub", font18b);
            DrawString("PubNub", new PointF((r * 2 - stringSize.Width) / 2 + 5, y - r / 2f), stringSize.Width, font18b, UILineBreakMode.TailTruncation);


            //needle
            //double percentFromMaxValue = max / 100.0d;
            max = 1000;
            double percentFromMaxValue = max / 100.0d;

            if (lag > max)
            {
                lag = max;
            }

            //angle
            double invertLag = ((max - min) / 2 - lag) * 2 + lag;
            //Debug.WriteLine("lag: "+ lag.ToString() + " invlag:" + invLag.ToString());
            double angle = 360 - Math.Round((double)invertLag / percentFromMaxValue * (90 / 100.0f)) * Math.PI / 180.0;
            //double angle2  = 360 - Math.Round((double)lag / percentFromMaxValue* (90 / 100.0f)) * Math.PI / 180.0;;
            //Debug.WriteLine("lagangle: "+ angle.ToString() + " invLagangle" + angle2.ToString());
            //double angle = WrapValue(lag, max);

            float  distance = 80;
            PointF p        = new PointF(distance * (float)Math.Cos(angle), distance * (float)Math.Sin(angle));

            UIColor.Brown.SetStroke();
            CGPath path1 = new CGPath();

            ctx.SetLineWidth(3);

            PointF newPoint = new PointF(105 - p.X, 105 - p.Y);

            PointF[] linePoints = new PointF[] {
                newPoint,
                new PointF(105, 105)
            };

            path1.AddLines(linePoints);
            path1.CloseSubpath();

            ctx.AddPath(path1);
            ctx.DrawPath(CGPathDrawingMode.FillStroke);

            //caliberate
            UIColor.Brown.SetColor();
            double theta = 0.0;

            for (int i = 0; i < 360; i++)

            {
                float bx4 = (float)(x - 4 + (r - 10) * (Math.Cos(theta * Math.PI / 180)));
                float by4 = (float)(y - 15 + (r - 10) * (Math.Sin(theta * Math.PI / 180)));

                if ((theta > 160) && (theta < 350))
                {
                    UIColor.Black.SetColor();
                    DrawString(".", new PointF(bx4, by4), StringSize(".", font18b).Width, font18b, UILineBreakMode.TailTruncation);
                }
                else if (((theta >= 0) && (theta < 40)) || ((theta >= 350) && (theta <= 360)))
                {
                    //redline
                    UIColor.Red.SetColor();
                    DrawString(".", new PointF(bx4, by4), StringSize(".", font18b).Width, font18b, UILineBreakMode.TailTruncation);
                }
                theta += 10.0;
            }

            //small circle
            UIColor.FromRGB(220, 214, 194).SetColor();
            //ctx.AddArc (x, y+y*.33f, r/1.5f, 0, twopi, true );
            ctx.AddArc(x, y + r / 2f, r / 2f, 0, twopi, true);
            ctx.FillPath();

            //speed in small circle
            UIColor.Black.SetFill();
            stringSize = StringSize(Convert.ToInt32(lag).ToString(), font18b);
            DrawString(Convert.ToInt32(lag).ToString(), new PointF((r * 2 - stringSize.Width) / 2 + 4, y + r / 2f - 15), stringSize.Width, font18b, UILineBreakMode.TailTruncation);

            //ms
            UIColor.Black.SetFill();
            stringSize = StringSize("MS", font18b);
            DrawString("MS", new PointF((r - stringSize.Width) / 2 + 55, y + r / 2f + 10), stringSize.Width, font18b, UILineBreakMode.TailTruncation);
        }
		void FillRoundedRect (RectangleF rect, CGContext context)
		{
			float radius = 10.0f;
			context.BeginPath ();
			context.SetGrayFillColor (0.0f, this.Opacity);
			context.MoveTo (rect.GetMinX () + radius, rect.GetMinY ());
			context.AddArc (rect.GetMaxX () - radius, rect.GetMinY () + radius, radius, (float)(3 * Math.PI / 2), 0f, false);
			context.AddArc (rect.GetMaxX () - radius, rect.GetMaxY () - radius, radius, 0, (float)(Math.PI / 2), false);
			context.AddArc (rect.GetMinX () + radius, rect.GetMaxY () - radius, radius, (float)(Math.PI / 2), (float)Math.PI, false);
			context.AddArc (rect.GetMinX () + radius, rect.GetMinY () + radius, radius, (float)Math.PI, (float)(3 * Math.PI / 2), false);
			context.ClosePath ();
			context.FillPath ();
		}
        public static void drawUnfilledArcInContext(CGContext ctx, CGPoint center, nfloat radius, nfloat lineWidth, nfloat fromAngleFromNorth, nfloat toAngleFromNorth)
        {
            var cartesianFromAngle = (nfloat)CompassToCartesian(ConvertToRadians(fromAngleFromNorth));
            var cartesianToAngle = (nfloat)CompassToCartesian(ConvertToRadians(toAngleFromNorth));
            
            ctx.AddArc(center.X,   // arc start point x
                            center.Y,   // arc start point y
                            radius,     // arc radius from center
                            cartesianFromAngle, cartesianToAngle,
                            false); // iOS flips the y coordinate so anti-clockwise (specified here by 0) becomes clockwise (desired)!

            ctx.SetLineWidth(lineWidth);
            ctx.SetLineCap(CGLineCap.Butt);
            ctx.DrawPath(CGPathDrawingMode.Stroke);
        }
Beispiel #33
0
        public void draw(CGContext context)
        {
            double radius = Math.Sqrt(Math.Pow((this.center.X - this.point2.X)/2, 2) + Math.Pow((this.center.Y - this.point2.Y)/2, 2));

            context.AddArc(this.center.X, this.center.Y, (float)radius, 0.0f, (float)Math.PI * 2, true);

            _color.SetStroke();

            context.StrokePath();
        }
Beispiel #34
0
        public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            DrawElement(() => {
                var bb = new BoundingBoxBuilder();

                foreach (var op in ops)
                {
                    var mt = op as MoveTo;
                    if (mt != null)
                    {
                        var p = mt.Point;
                        if (!IsValid(p.X) || !IsValid(p.Y))
                        {
                            continue;
                        }
                        context.MoveTo((nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var lt = op as LineTo;
                    if (lt != null)
                    {
                        var p = lt.Point;
                        if (!IsValid(p.X) || !IsValid(p.Y))
                        {
                            continue;
                        }
                        context.AddLineToPoint((nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        continue;
                    }
                    var at = op as ArcTo;
                    if (at != null)
                    {
                        var p = at.Point;
                        if (!IsValid(p.X) || !IsValid(p.Y))
                        {
                            continue;
                        }
                        var pp = Conversions.GetPoint(context.GetPathCurrentPoint());
                        if (pp == p)
                        {
                            continue;
                        }
                        Point c1, c2;
                        at.GetCircles(pp, out c1, out c2);

                        var circleCenter = (at.LargeArc ^ at.SweepClockwise) ? c1 : c2;

                        var startAngle = (float)Math.Atan2(pp.Y - circleCenter.Y, pp.X - circleCenter.X);
                        var endAngle   = (float)Math.Atan2(p.Y - circleCenter.Y, p.X - circleCenter.X);

                        if (!IsValid(circleCenter.X) || !IsValid(circleCenter.Y) || !IsValid(startAngle) || !IsValid(endAngle))
                        {
                            context.MoveTo((nfloat)p.X, (nfloat)p.Y);
                            continue;
                        }

                        var clockwise = !at.SweepClockwise;

                        context.AddArc((nfloat)circleCenter.X, (nfloat)circleCenter.Y, (nfloat)at.Radius.Min, startAngle, endAngle, clockwise);

                        bb.Add(p);
                        continue;
                    }
                    var ct = op as CurveTo;
                    if (ct != null)
                    {
                        var p = ct.Point;
                        if (!IsValid(p.X) || !IsValid(p.Y))
                        {
                            continue;
                        }
                        var c1 = ct.Control1;
                        var c2 = ct.Control2;
                        if (!IsValid(c1.X) || !IsValid(c1.Y) || !IsValid(c2.X) || !IsValid(c2.Y))
                        {
                            context.MoveTo((nfloat)p.X, (nfloat)p.Y);
                            continue;
                        }
                        context.AddCurveToPoint((nfloat)c1.X, (nfloat)c1.Y, (nfloat)c2.X, (nfloat)c2.Y, (nfloat)p.X, (nfloat)p.Y);
                        bb.Add(p);
                        bb.Add(c1);
                        bb.Add(c2);
                        continue;
                    }
                    var cp = op as ClosePath;
                    if (cp != null)
                    {
                        context.ClosePath();
                        continue;
                    }

                    throw new NotSupportedException("Path Op " + op);
                }

                return(bb.BoundingBox);
            }, pen, brush);
        }
	public override void DrawInContext (CGContext context)
	{
		// Drawing with a white stroke color
		context.SetStrokeColor (1, 1, 1, 1);
		// And draw with a blue fill color
		context.SetFillColor (0, 0, 1, 1);
		// Draw them with a 2 stroke width so they are a bit more visible.
		context.SetLineWidth (2);

		// Add an ellipse circumscribed in the given rect to the current path, then stroke it
		context.AddEllipseInRect (new CGRect (30, 30, 60, 60));
		context.StrokePath ();

		// Stroke ellipse convenience that is equivalent to AddEllipseInRect(); StrokePath();
		context.StrokeEllipseInRect (new CGRect (30, 120, 60, 60));

		// Fill rect convenience equivalent to AddEllipseInRect(); FillPath();
		context.FillEllipseInRect (new CGRect (30, 210, 60, 60));

		// Stroke 2 seperate arcs
		context.AddArc (150, 60, 30, 0, (float)Math.PI / 2, false);
		context.StrokePath ();
		context.AddArc (150, 60, 30, (float)(3 * Math.PI / 2), (float)Math.PI, true);
		context.StrokePath ();

		// Stroke 2 arcs together going opposite directions.
		context.AddArc (150, 150, 30, 0, (float)Math.PI / 2, false);
		context.AddArc (150, 150, 30, (float)(3 * Math.PI / 2), (float)Math.PI, true);
		context.StrokePath ();

		// Stroke 2 arcs together going the same direction..
		context.AddArc (150, 240, 30, 0, (float)(Math.PI / 2), false);
		context.AddArc (150, 240, 30, (float)Math.PI, (float)(3 * Math.PI / 2), false);
		context.StrokePath ();

		// Stroke an arc using AddArcToPoint
		CGPoint[] p = {
			new CGPoint (210, 30),
			new CGPoint (210, 60),
			new CGPoint (240, 60),
		};
		context.MoveTo (p [0].X, p [0].Y);
		context.AddArcToPoint (p [1].X, p [1].Y, p [2].X, p [2].Y, 30);
		context.StrokePath ();

		// Show the two segments that are used to determine the tangent lines to draw the arc.
		context.SetStrokeColor (1, 0, 0, 1);
		context.AddLines (p);
		context.StrokePath ();

		// As a bonus, we'll combine arcs to create a round rectangle!

		// Drawing with a white stroke color
		context.SetStrokeColor (1, 1, 1, 1);

		// If you were making this as a routine, you would probably accept a rectangle
		// that defines its bounds, and a radius reflecting the "rounded-ness" of the rectangle.
		var rrect = new CGRect (210, 90, 60, 60);
		var radius = 10;
		// NOTE: At this point you may want to verify that your radius is no more than half
		// the width and height of your rectangle, as this technique degenerates for those cases.

		// In order to draw a rounded rectangle, we will take advantage of the fact that
		// context.AddArcToPoint will draw straight lines past the start and end of the arc
		// in order to create the path from the current position and the destination position.

		// In order to create the 4 arcs correctly, we need to know the min, mid and max positions
		// on the x and y lengths of the given rectangle.
		nfloat minx = rrect.X, midx = rrect.X + rrect.Width / 2, maxx = rrect.X + rrect.Width;
		nfloat miny = rrect.Y, midy = rrect.Y + rrect.Height / 2, maxy = rrect.Y + rrect.Height;

		// Next, we will go around the rectangle in the order given by the figure below.
		//       minx    midx    maxx
		// miny    2       3       4
		// midy   1 9              5
		// maxy    8       7       6
		// Which gives us a coincident start and end point, which is incidental to this technique, but still doesn't
		// form a closed path, so we still need to close the path to connect the ends correctly.
		// Thus we start by moving to point 1, then adding arcs through each pair of points that follows.
		// You could use a similar tecgnique to create any shape with rounded corners.

		// Start at 1
		context.MoveTo (minx, midy);
		// Add an arc through 2 to 3
		context.AddArcToPoint (minx, miny, midx, miny, radius);
		// Add an arc through 4 to 5
		context.AddArcToPoint (maxx, miny, maxx, midy, radius);
		// Add an arc through 6 to 7
		context.AddArcToPoint (maxx, maxy, midx, maxy, radius);
		// Add an arc through 8 to 9
		context.AddArcToPoint (minx, maxy, minx, midy, radius);
		// Close the path
		context.ClosePath ();
		// Fill & stroke the path
		context.DrawPath (CGPathDrawingMode.FillStroke);
	}
 void DrawArcInContext(CGContext context, PointF center, float radius, float startAngle, float endAngle, CGColor color, bool cgClockwise)
 {
     context.BeginPath();
     context.MoveTo(center.X, center.Y);
     context.AddArc(center.X, center.Y, radius, startAngle, endAngle, cgClockwise);
     context.SetFillColor(color);
     context.FillPath();
 }
Beispiel #37
0
        public override void ArcNegative(object backend, double xc, double yc, double radius, double angle1, double angle2)
        {
            CGContext ctx = ((CGContextBackend)backend).Context;

            ctx.AddArc((float)xc, (float)yc, (float)radius, (float)(angle1 * degrees), (float)(angle2 * degrees), true);
        }
        public override void DrawRect(CGRect dirtyRect)
        {
            // Don't draw if we don't have a font or a title.
            if (Font == null || Title == string.Empty)
            {
                return;
            }

            // Initialize the text matrix to a known value
            CGContext context = NSGraphicsContext.CurrentContext.GraphicsPort;

            context.TextMatrix = CGAffineTransform.MakeIdentity();

            // Draw a white background
            NSColor.White.Set();
            context.FillRect(dirtyRect);
            CTLine line = new CTLine(AttributedString);

            int glyphCount = (int)line.GlyphCount;

            if (glyphCount == 0)
            {
                return;
            }

            GlyphArcInfo[] glyphArcInfo = new GlyphArcInfo[glyphCount];
            PrepareGlyphArcInfo(line, glyphCount, glyphArcInfo);

            // Move the origin from the lower left of the view nearer to its center.
            context.SaveState();
            context.TranslateCTM(dirtyRect.GetMidX(), dirtyRect.GetMidY() - Radius / 2);

            // Stroke the arc in red for verification.
            context.BeginPath();
            context.AddArc(0, 0, Radius, (float)Math.PI, 0, true);
            context.SetStrokeColor(1, 0, 0, 1);
            context.StrokePath();

            // Rotate the context 90 degrees counterclockwise.
            context.RotateCTM((float)PI_2);

            /*
             *      Now for the actual drawing. The angle offset for each glyph relative to the previous
             *      glyph has already been calculated; with that information in hand, draw those glyphs
             *      overstruck and centered over one another, making sure to rotate the context after each
             *      glyph so the glyphs are spread along a semicircular path.
             */
            CGPoint textPosition = new CGPoint(0, Radius);

            context.TextPosition = textPosition;
            var runArray = line.GetGlyphRuns();
            var runCount = runArray.Count();

            var glyphOffset = 0;
            var runIndex    = 0;

            for (; runIndex < runCount; runIndex++)
            {
                var    run           = runArray [runIndex];
                var    runGlyphCount = run.GlyphCount;
                bool   drawSubstitutedGlyphsManually = false;
                CTFont runFont = run.GetAttributes().Font;

                // Determine if we need to draw substituted glyphs manually. Do so if the runFont is not
                //      the same as the overall font.
                var    description = NSFontDescriptor.FromNameSize(runFont.FamilyName, runFont.Size);
                NSFont rrunFont    = NSFont.FromDescription(description, runFont.Size);
                // used for comparison
                if (DimsSubstitutedGlyphs && Font != rrunFont)
                {
                    drawSubstitutedGlyphsManually = true;
                }

                var runGlyphIndex = 0;
                for (; runGlyphIndex < runGlyphCount; runGlyphIndex++)
                {
                    var glyphRange = new NSRange(runGlyphIndex, 1);
                    context.RotateCTM(-(glyphArcInfo [runGlyphIndex + glyphOffset].angle));

                    // Center this glyph by moving left by half its width.
                    var glyphWidth           = glyphArcInfo [runGlyphIndex + glyphOffset].width;
                    var halfGlyphWidth       = glyphWidth / 2.0;
                    var positionForThisGlyph = new CGPoint(textPosition.X - (float)halfGlyphWidth, textPosition.Y);

                    // Glyphs are positioned relative to the text position for the line, so offset text position leftwards by this glyph's
                    //      width in preparation for the next glyph.
                    textPosition.X -= glyphWidth;

                    CGAffineTransform textMatrix = run.TextMatrix;
                    textMatrix.x0      = positionForThisGlyph.X;
                    textMatrix.y0      = positionForThisGlyph.Y;
                    context.TextMatrix = textMatrix;

                    if (!drawSubstitutedGlyphsManually)
                    {
                        run.Draw(context, glyphRange);
                    }
                    else
                    {
                        // We need to draw the glyphs manually in this case because we are effectively applying a graphics operation by
                        //      setting the context fill color. Normally we would use kCTForegroundColorAttributeName, but this does not apply
                        // as we don't know the ranges for the colors in advance, and we wanted demonstrate how to manually draw.
                        var cgFont   = runFont.ToCGFont();
                        var glyph    = run.GetGlyphs(glyphRange);
                        var position = run.GetPositions(glyphRange);
                        context.SetFont(cgFont);
                        context.SetFontSize(runFont.Size);
                        context.SetFillColor(0.25f, 0.25f, 0.25f, 1);
                        context.ShowGlyphsAtPositions(glyph, position, 1);
                    }

                    // Draw the glyph bounds
                    if (ShowsGlyphBounds)
                    {
                        var glyphBounds = run.GetImageBounds(context, glyphRange);
                        context.SetStrokeColor(0, 0, 1, 1);
                        context.StrokeRect(glyphBounds);
                    }

                    // Draw the bounding boxes defined by the line metrics
                    if (ShowsLineMetrics)
                    {
                        var    lineMetrics = new CGRect();
                        nfloat ascent      = 0;
                        nfloat descent     = 0;
                        nfloat leading     = 0;

                        run.GetTypographicBounds(glyphRange, out ascent, out descent, out leading);

                        // The glyph is centered around the y-axis
                        lineMetrics.Location = new CGPoint(-(float)halfGlyphWidth, positionForThisGlyph.Y - descent);
                        lineMetrics.Size     = new CGSize(glyphWidth, ascent + descent);
                        context.SetStrokeColor(0, 1, 0, 1);
                        context.StrokeRect(lineMetrics);
                    }
                }

                glyphOffset += (int)runGlyphCount;
            }

            context.RestoreState();
        }
        void drawSlicesSeparators(CGContext contextRef, SizeF viewSize, PointF center)
        {
            int outerDiameter = (int)Math.Min(viewSize.Width, viewSize.Height);

            double outerRadius = outerDiameter / 2.0 - internalPadding;
            int innerDiameter = (int)(outerDiameter - Theme.Thickness);
            double innerRadius = innerDiameter / 2.0;
            int sliceCount = (int)ProgressTotal;
            double sliceAngle = (2 * M_PI) / sliceCount;

            contextRef.SetLineWidth(Theme.SliceDividerThickness);
            contextRef.SetStrokeColor(Theme.SliceDividerColor.CGColor);
            contextRef.MoveTo(center.X, center.Y);

            for (int i = 0; i < sliceCount; i++) {
                contextRef.BeginPath();

                double startAngle = sliceAngle * i - M_PI_2;
                double endAngle = sliceAngle * (i + 1) - M_PI_2;

                contextRef.AddArc(center.X, center.Y, (float)outerRadius, (float)startAngle, (float)endAngle, false);
                contextRef.AddArc(center.X, center.Y, (float)innerRadius, (float)endAngle, (float)startAngle, true);
                contextRef.StrokePath();
            }
        }
        void drawSlicesWithRadius(float radius, PointF center, CGContext contextRef)
        {
            bool cgClockwise = !Clockwise;

            uint startingSlice = StartingSlice - 1;

            if (ProgressCounter == 0 && Theme.DrawIncompleteArcIfNoProgress)
            {
                DrawArcInContext(contextRef, center, radius, 0, M_PI * 2, Theme.IncompletedColor.CGColor, cgClockwise);
                return;
            }

            if (!Theme.SliceDividerHidden && Theme.SliceDividerThickness > 0)
            {
                float sliceAngle = (2 * M_PI) / ProgressTotal;

                for (int i =0; i < ProgressTotal; i++) {
                    float startValue = (sliceAngle * i) + sliceAngle * startingSlice;
                    float startAngle, endAngle;
                    if (Clockwise)
                    {
                        startAngle = -M_PI_2 + startValue;
                        endAngle = startAngle + sliceAngle;
                    }
                    else
                    {
                        startAngle = -M_PI_2 - startValue;
                        endAngle = startAngle - sliceAngle;
                    }

                    contextRef.BeginPath();
                    contextRef.MoveTo(center.X, center.Y);
                    contextRef.AddArc(center.X, center.Y, radius, startAngle, endAngle, cgClockwise);

                    CGColor color = Theme.IncompletedColor.CGColor;

                    if (i < ProgressCounter)
                    {
                        color = Theme.CompletedColor.CGColor;
                    }

                    contextRef.SetFillColor(color);
                    contextRef.FillPath();
                }
            }
            else
            {
                double originAngle, endAngle;
                double sliceAngle = (2 * M_PI) / ProgressTotal;
                double startingAngle = sliceAngle * startingSlice;
                double progressAngle = sliceAngle * ProgressCounter;

                if (Clockwise) {
                    originAngle = - M_PI_2 + startingAngle;
                    endAngle = originAngle + progressAngle;
                } else {
                    originAngle = - M_PI_2 - startingAngle;
                    endAngle = originAngle - progressAngle;
                }

                DrawArcInContext(contextRef, center, radius, (float)originAngle, (float)endAngle, Theme.CompletedColor.CGColor, cgClockwise);

                if (ProgressCounter < ProgressTotal)
                {
                    DrawArcInContext(contextRef, center, radius, (float)endAngle, (float)originAngle, Theme.IncompletedColor.CGColor, cgClockwise);
                }
            }
        }
Beispiel #41
0
        private float MakePath(CGContext context, RectangleF rect)
        {
            var radius = rect.Bottom * this.cornerRoundness;
            var puffer = rect.Bottom * 0.12f;
            var maxX = rect.Right - (puffer * 2f);
            var maxY = rect.Bottom - puffer;
            var minX = rect.Left + (puffer * 2f);
            var minY = rect.Top + puffer;
            if (maxX - minX < 20f) {
                maxX = rect.Right - puffer;
                minX = rect.Left + puffer;
            }

            context.AddArc (maxX - radius, minY + radius, radius, (float)(Math.PI + (Math.PI / 2)), 0f, false);
            context.AddArc (maxX - radius, maxY - radius, radius, 0, (float)(Math.PI / 2), false);
            context.AddArc (minX + radius, maxY - radius, radius, (float)(Math.PI / 2), (float)Math.PI, false);
            context.AddArc (minX + radius, minY + radius, radius, (float)Math.PI, (float)(Math.PI + Math.PI / 2), false);

            return maxY;
        }