public override void DrawInContext(CGContext context)
        {
            base.DrawInContext(context);

            // Console.WriteLine ("DrawInContext Radius: {0} Thickness: {1} Color: {2}", Radius, Thickness, Color);
            //Console.WriteLine (this.Bounds.Width+"   "+ this.Bounds.Height);

            CGPoint centerPoint = new CGPoint(this.Bounds.Width / 2, this.Bounds.Height / 2);
            CGColor glowColor   = new UIColor(Color).ColorWithAlpha(0.85f).CGColor;
            double  innerRadius = (Radius - Thickness) > 0 ? Radius - Thickness : 0;

            // Outer circle
            context.AddEllipseInRect(new CGRect(centerPoint.X - (float)Radius,
                                                centerPoint.Y - (float)Radius,
                                                (float)Radius * 2,
                                                (float)Radius * 2));
            // Inner circle
            context.AddEllipseInRect(new CGRect(centerPoint.X - (float)innerRadius,
                                                centerPoint.Y - (float)innerRadius,
                                                (float)innerRadius * 2,
                                                (float)innerRadius * 2));

            // Fill in circle
            context.SetFillColor(Color);
            context.SetShadow(CGSize.Empty, 10.0f, glowColor);
            context.EOFillPath();
        }
        public override void Draw(CoreGraphics.CGRect rect)
        {
            base.Draw(rect);

            using (CGContext g = UIGraphics.GetCurrentContext()) {
                //set up drawing attributes



                g.SetLineWidth(10);
                UIColor.Blue.SetFill();
                UIColor.Red.SetStroke();

                g.SetFillColor(UIColor.Red.CGColor);

                g.AddEllipseInRect(m_CircleJSLeft);
                g.AddEllipseInRect(m_CircleJSRight);

                //create geometry
                var path = new CGPath();

                path.AddLines(new CGPoint [] {
                    new CGPoint(100, 200),
                    new CGPoint(160, 100),
                    new CGPoint(220, 200)
                });

                path.CloseSubpath();

                //add geometry to graphics context and draw it
                g.AddPath(path);
                g.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
Beispiel #3
0
        public override void DrawInContext(CGContext context)
        {
            base.DrawInContext(context);

            context.AddEllipseInRect(Bounds);
            context.SetFillColor(ClockColor);
            context.FillPath();
        }
Beispiel #4
0
		public override void DrawInContext (CGContext context)
		{
			base.DrawInContext (context);
			
			context.AddEllipseInRect (Bounds);
			context.SetFillColor (ClockColor);
			context.FillPath ();
		}
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            cGContext = UIGraphics.GetCurrentContext();
            int size = Element.pointList.Count;

            for (int i = 0; i < size; i++)//绘制元素点图
            {
                Point item = Element.pointList.ElementAt(i);

                cGContext.SetFillColor(UIColor.Blue.CGColor);
                cGContext.AddEllipseInRect(new CGRect(item.X - Element.Circle_r, item.Y - Element.Circle_r, Element.Circle_r * 2, Element.Circle_r * 2));
                cGContext.DrawPath(CGPathDrawingMode.Fill);

                cGContext.SetStrokeColor(UIColor.Blue.CGColor);
                cGContext.SetLineWidth(2);
                cGContext.AddEllipseInRect(new CGRect(item.X - Element.Circle_R, item.Y - Element.Circle_R, Element.Circle_R * 2, Element.Circle_R * 2));
                cGContext.DrawPath(CGPathDrawingMode.Stroke);
            }
            size = Element.drawList.Count;
            for (int i = 0; i < size; i++)//绘制选中点图
            {
                Point item = Element.drawList.ElementAt(i);


                cGContext.SetFillColor(UIColor.Red.CGColor);
                cGContext.AddEllipseInRect(new CGRect(item.X - Element.Circle_r, item.Y - Element.Circle_r, Element.Circle_r * 2, Element.Circle_r * 2));
                cGContext.DrawPath(CGPathDrawingMode.Fill);
                if (i < size - 1)
                {
                    Point item2 = Element.drawList.ElementAt(i + 1);

                    cGContext.SetStrokeColor(UIColor.Red.CGColor);
                    cGContext.MoveTo((float)item.X, (float)item.Y);
                    cGContext.AddLineToPoint((float)item2.X, (float)item2.Y);
                    cGContext.DrawPath(CGPathDrawingMode.Stroke);

                    cGContext.SetStrokeColor(UIColor.Red.CGColor);
                    cGContext.SetLineWidth(2);
                    cGContext.AddEllipseInRect(new CGRect(item.X - Element.Circle_R, item.Y - Element.Circle_R, Element.Circle_R * 2, Element.Circle_R * 2));
                    cGContext.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
        }
Beispiel #6
0
 public static void DrawEllipsis(CGContext context, RectangleF rect, CGColor color, float lineWidth)
 {
     context.SaveState();
     context.SetStrokeColor(color);
     context.SetLineWidth(lineWidth);
     context.AddEllipseInRect(rect);
     context.StrokePath();
     context.RestoreState();
 }
Beispiel #7
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            float  margins  = 4;
            CGRect drawRect = new CGRect(rect.X + margins, rect.Y + margins, rect.Width - margins * 2, rect.Height - margins * 2);

            CGContext context = UIGraphics.GetCurrentContext();

            context.AddEllipseInRect(drawRect);
            context.AddEllipseInRect(drawRect.Inset(4, 4));
            context.SetFillColor(UIColor.Black.CGColor);
            context.SetStrokeColor(UIColor.White.CGColor);
            context.SetLineWidth(0.5f);
            context.ClosePath();
            context.SetShadow(new CGSize(1, 2), 4);
            context.DrawPath(CGPathDrawingMode.EOFillStroke);
        }
Beispiel #8
0
 /// <summary> 是否剪裁子控件
 /// </summary>
 /// <param name="ctx">图形上下文</param>
 /// <param name="clip">是否剪裁</param>
 void ClipSubviewsWhenConnectInContext(CGContext ctx, bool clip)
 {
     if (clip)
     {
         // 遍历所有子控件
         foreach (PCCircle circle in Subviews)
         {
             // 确定"剪裁"的形状
             ctx.AddEllipseInRect(circle.Frame);
         }
     }
 }
Beispiel #9
0
        public void Draw()
        {
            //get graphics context
            using (CGContext g = UIGraphics.GetCurrentContext())
            {
                CGRect rect = new CGRect(x, y, w, h);

                g.AddEllipseInRect(rect);
                g.Clip();
                g.ClearRect(rect);
            }
        }
Beispiel #10
0
        public void DrawEllipse(Rect frame, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            DrawElement(() => {
                context.AddEllipseInRect(Conversions.GetCGRect(frame));
                return(frame);
            }, pen, brush);
        }
Beispiel #11
0
 public void FillOval(float x, float y, float width, float height)
 {
     if (_g != null)
     {
         _c.AddEllipseInRect(new NativeRect(x, y, width, height));
         FillPath();
     }
     else
     {
         _c.FillEllipseInRect(new NativeRect(x, y, width, height));
     }
 }
Beispiel #12
0
        public override void Draw(CGRect rect)
        {
            CGRect    viewBounds   = Bounds;
            CGContext curContext   = UIGraphics.GetCurrentContext();
            var       numberString = Value.ToString(TextFormat);

            CGSize numberSize = new NSString(numberString).StringSize(Font);

            using (CGPath badgePath = NewBadgePathForTextSize(numberSize))
            {
                CGRect badgeRect = badgePath.PathBoundingBox;

                badgeRect.X    = 0;
                badgeRect.Y    = 0;
                badgeRect.Size = new SizeF((float)Math.Ceiling(badgeRect.Size.Width), (float)Math.Ceiling(badgeRect.Size.Height));

                curContext.SaveState();

                curContext.SetLineWidth(StrokeWidth);
                curContext.SetStrokeColor(StrokeColor.CGColor);
                curContext.SetFillColor(SubFillColor.CGColor);

                curContext.AddEllipseInRect(badgeRect);
                curContext.DrawPath(CGPathDrawingMode.Fill);

                curContext.SetFillColor(FillColor.CGColor);

                // Line stroke straddles the path, so we need to account for the outer portion
                badgeRect.Size = new CGSize(badgeRect.Size.Width + (float)Math.Ceiling(StrokeWidth / 2), badgeRect.Size.Height + (float)Math.Ceiling(StrokeWidth / 2));

                CGPoint ctm = new PointF(0f, 0f);

                curContext.TranslateCTM(ctm.X, ctm.Y);

                curContext.BeginPath();
                curContext.AddPath(badgePath);
                curContext.ClosePath();
                curContext.DrawPath(CGPathDrawingMode.EOFill);
                curContext.RestoreState();

                curContext.SaveState();
                curContext.SetFillColor(TextColor.CGColor);

                CGPoint textPt = new CGPoint(ctm.X + ((badgeRect.Size.Width - numberSize.Width) / 2) + AdjustOffset.X,
                                             ctm.Y + ((badgeRect.Size.Height - numberSize.Height) / 2) + AdjustOffset.Y);

                curContext.RestoreState();
            }
        }
Beispiel #13
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();
        }
Beispiel #14
0
        private void DrawPersona(CGContext context)
        {
            LearnerTemplateStyle personaStyle = this.FormsShimmer.PersonaStyle;
            float circleRadius = (float)personaStyle.CircleRadius;
            float lineSpacing  = (float)personaStyle.LineSpacing;
            float lineHeight   = (float)personaStyle.LineHeight;
            float num1         = personaStyle.Width >= 0.0 ? (float)personaStyle.Width : this.templateWidth;
            float num2         = (personaStyle.Height >= 0.0 ? (float)personaStyle.Height : this.templateHeight) / 2f;
            float num3         = (double)num2 > 0.0 ? ((double)circleRadius <= (double)num2 ? circleRadius : num2) : circleRadius;
            float num4         = this.templateX + num3 * 2f + this.columnSpacing;

            context.AddEllipseInRect(new CGRect(this.templateX, this.centerY - num3, num3 * 2f, num3 * 2f));
            context.AddRect(new CGRect((double)num4, (double)this.centerY - (double)num3 + (double)lineSpacing, ((double)num1 - (double)this.columnSpacing - (double)num3 * 2.0) * 0.8, (double)lineHeight));
            context.AddRect(new CGRect((double)num4, (double)this.centerY - (double)num3 + (double)lineSpacing + (double)lineHeight + (double)lineSpacing, ((double)num1 - (double)this.columnSpacing - (double)num3 * 2.0) * 0.5, (double)lineHeight));
        }
Beispiel #15
0
        private void DrawVideo(CGContext context)
        {
            LearnerTemplateStyle videoStyle = this.FormsShimmer.VideoStyle;
            float circleRadius = (float)videoStyle.CircleRadius;
            float lineSpacing  = (float)videoStyle.LineSpacing;
            float lineHeight   = (float)videoStyle.LineHeight;
            float width        = videoStyle.Width >= 0.0 ? (float)videoStyle.Width : this.templateWidth;
            float num1         = (videoStyle.Height >= 0.0 ? (float)videoStyle.Height : this.templateHeight) / 2f;
            float num2         = this.templateX + circleRadius * 2f + this.columnSpacing;

            context.AddRect(new CGRect(this.templateX, this.centerY - num1, width, (float)((double)num1 * 2.0 - (double)circleRadius * 2.0) - lineSpacing));
            context.AddEllipseInRect(new CGRect(this.templateX, (float)((double)this.centerY + (double)num1 - (double)circleRadius * 2.0), circleRadius * 2f, circleRadius * 2f));
            context.AddRect(new CGRect((double)num2, (double)this.centerY + (double)num1 - (double)circleRadius * 2.0 + (double)lineSpacing * 0.5, (double)width - (double)this.columnSpacing - (double)circleRadius * 2.0, (double)lineHeight));
            context.AddRect(new CGRect((double)num2, (double)this.centerY + (double)num1 - (double)circleRadius * 2.0 + (double)lineSpacing * 1.5 + (double)lineHeight, (double)width - (double)this.columnSpacing - (double)circleRadius * 2.0, (double)lineHeight));
        }
Beispiel #16
0
        private void DrawFeed(CGContext context)
        {
            LearnerTemplateStyle feedStyle = this.FormsShimmer.FeedStyle;
            float circleRadius             = (float)feedStyle.CircleRadius;
            float lineSpacing = (float)feedStyle.LineSpacing;
            float lineHeight  = (float)feedStyle.LineHeight;
            float num1        = feedStyle.Width >= 0.0 ? (float)feedStyle.Width : this.templateWidth;
            float num2        = (feedStyle.Height >= 0.0 ? (float)feedStyle.Height : this.templateHeight) / 2f;
            float num3        = this.templateX + circleRadius * 2f + this.columnSpacing;

            context.AddEllipseInRect(new CGRect(this.templateX, this.centerY - num2, circleRadius * 2f, circleRadius * 2f));
            context.AddRect(new CGRect((double)num3, (double)this.centerY - (double)num2 + (double)lineSpacing * 0.5, (double)num1 - (double)this.columnSpacing - (double)circleRadius * 2.0, (double)lineHeight));
            context.AddRect(new CGRect((double)num3, (double)this.centerY - (double)num2 + (double)lineSpacing * 1.5 + (double)lineHeight, ((double)num1 - (double)this.columnSpacing - (double)circleRadius * 2.0) * 0.5, (double)lineHeight));
            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY - (double)num2 + (double)circleRadius * 2.0 + (double)lineSpacing, (double)num1, (double)num2 * 2.0 - (double)lineHeight * 0.6 * 2.0 - (double)lineSpacing * 0.6 * 2.0 * 1.5 - (double)circleRadius * 2.0 - (double)lineSpacing));
            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY + (double)num2 - (double)lineHeight * 0.6 * 2.0 - (double)lineSpacing * 0.6, (double)num1, (double)lineHeight * 0.6));
            context.AddRect(new CGRect((double)this.templateX, (double)this.centerY + (double)num2 - (double)lineHeight * 0.6, (double)num1, (double)lineHeight * 0.6));
        }
Beispiel #17
0
        private void DrawProfile(CGContext context)
        {
            LearnerTemplateStyle profileStyle = this.FormsShimmer.ProfileStyle;
            float  circleRadius = (float)profileStyle.CircleRadius;
            float  lineSpacing  = (float)profileStyle.LineSpacing;
            float  lineHeight   = (float)profileStyle.LineHeight;
            float  width        = profileStyle.Width >= 0.0 ? (float)profileStyle.Width : this.templateWidth;
            float  num1         = (profileStyle.Height >= 0.0 ? (float)profileStyle.Height : this.templateHeight) / 2f;
            double num2         = (double)width / 2.0;
            float  num3         = width / 2f;

            context.AddEllipseInRect(new CGRect(this.templateX + num3 - circleRadius, this.centerY - num1, circleRadius * 2f, circleRadius * 2f));
            context.AddRect(new CGRect((double)this.templateX + (double)num3 - (double)width * 0.2, (double)this.centerY + (double)lineSpacing, (double)width * 0.2 * 2.0, (double)lineHeight * 2.0));
            context.AddRect(new CGRect((double)this.templateX + (double)num3 - (double)width * 0.3, (double)this.centerY + (double)lineSpacing * 2.0 + (double)lineHeight * 2.0, (double)width * 0.3 * 2.0, (double)lineHeight * 2.0));
            context.AddRect(new CGRect(this.templateX, (float)((double)this.centerY + (double)num1 - (double)lineHeight * 2.0) - lineSpacing, width, lineHeight));
            context.AddRect(new CGRect(this.templateX, this.centerY + num1 - lineHeight, width, lineHeight));
        }
Beispiel #18
0
        /*public override void TouchesEnded(NSSet touches, UIEvent evt)
         * {
         *  base.TouchesEnded(touches, evt);
         *
         *  initialPoint = latestPoint;
         *
         * }*/

        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            if (!initialPoint.IsEmpty)
            {
                //get graphics context
                using (CGContext g = UIGraphics.GetCurrentContext())
                {
                    g.SetAllowsAntialiasing(true);
                    foreach (CGPoint point in touchPoints)
                    {
                        g.AddEllipseInRect(new CGRect(point, new CGSize(15, 15)));
                        g.FillEllipseInRect(new CGRect(point, new CGSize(15, 15)));
                    }
                }
            }
        }
		public override void DrawInContext (CGContext context)
		{
			base.DrawInContext (context);

			// Console.WriteLine ("DrawInContext Radius: {0} Thickness: {1} Color: {2}", Radius, Thickness, Color);
			
			PointF centerPoint = new PointF (this.Bounds.Width / 2, this.Bounds.Height / 2);
			CGColor glowColor = new UIColor (Color).ColorWithAlpha (0.85f).CGColor;
			double innerRadius = (Radius - Thickness) > 0 ? Radius - Thickness : 0;
	
			// Outer circle
			context.AddEllipseInRect (new RectangleF (centerPoint.X - (float) Radius,
			                                        centerPoint.Y - (float) Radius,
			                                        (float) Radius * 2,
			                                        (float) Radius * 2));
			// Inner circle
			context.AddEllipseInRect (new RectangleF (centerPoint.X - (float) innerRadius,
			                                        centerPoint.Y - (float) innerRadius,
			                                        (float) innerRadius * 2,
			                                        (float) innerRadius * 2));
			
			// Fill in circle
			context.SetFillColor (Color);
			context.SetShadowWithColor (SizeF.Empty, 10.0f, glowColor);
			context.EOFillPath();
		}
Beispiel #20
0
        make_arcs(CGContext graphics, float x, float y, float width, float height, float startAngle, float sweepAngle,
                  bool convert_units, bool antialiasing, bool isPieSlice)
        {
            int   i;
            float drawn = 0;
            float endAngle;
            bool  enough = false;

            // I do not think we need to convert the units so commented this out.

            /* if required deal, once and for all, with unit conversions */
            //if (convert_units && !OPTIMIZE_CONVERSION(graphics))
            //{
            //    x = gdip_unitx_convgr(graphics, x);
            //    y = gdip_unity_convgr(graphics, y);
            //    width = gdip_unitx_convgr(graphics, width);
            //    height = gdip_unity_convgr(graphics, height);
            //}

            if (Math.Abs(sweepAngle) >= 360)
            {
                graphics.AddEllipseInRect(new CGRect(x, y, width, height));
                return;
            }

            endAngle = startAngle + sweepAngle;
            /* if we end before the start then reverse positions (to keep increment positive) */
            if (endAngle < startAngle)
            {
                var temp = endAngle;
                endAngle   = startAngle;
                startAngle = temp;
            }

            if (isPieSlice)
            {
                graphics.MoveTo(x + (width / 2), y + (height / 2));
            }

            /* i is the number of sub-arcs drawn, each sub-arc can be at most 90 degrees.*/
            /* there can be no more then 4 subarcs, ie. 90 + 90 + 90 + (something less than 90) */
            for (i = 0; i < 4; i++)
            {
                float current = startAngle + drawn;
                float additional;

                if (enough)
                {
                    if (isPieSlice)
                    {
                        graphics.ClosePath();
                    }
                    return;
                }

                additional = endAngle - current;                 /* otherwise, add the remainder */
                if (additional > 90)
                {
                    additional = 90.0f;
                }
                else
                {
                    /* a near zero value will introduce bad artefact in the drawing (#78999) */
                    if ((additional >= -0.0001f) && (additional <= 0.0001f))
                    {
                        return;
                    }
                    enough = true;
                }

                make_arc(graphics, (i == 0),                    /* only move to the starting pt in the 1st iteration */
                         x, y, width, height,                   /* bounding rectangle */
                         current, current + additional, antialiasing, isPieSlice);

                drawn += additional;
            }

            if (isPieSlice)
            {
                graphics.ClosePath();
            }
        }
Beispiel #21
0
    public override void DrawInContext(CGContext context)
    {
        // Drawing with a white stroke color
        context.SetRGBStrokeColor(1, 1, 1, 1);
        // And draw with a blue fill color
        context.SetRGBFillColor(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 RectangleF(30, 30, 60, 60));
        context.StrokePath();

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

        // Fill rect convenience equivalent to AddEllipseInRect(); FillPath();
        context.FillEllipseInRect(new RectangleF(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
        PointF [] p =
        {
            new PointF(210, 30),
            new PointF(210, 60),
            new PointF(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.SetRGBStrokeColor(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.SetRGBStrokeColor(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 RectangleF(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.
        float minx = rrect.X, midx = rrect.X + rrect.Width / 2, maxx = rrect.X + rrect.Width;
        float 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);
    }
Beispiel #22
0
            UIImage DrawShape(ShapeType shapeType, CGSize size, UIColor strokeColor, UIColor fillColor)
            {
                float   width  = (float)size.Width;
                float   height = (float)size.Height;
                var     stroke = 1;
                var     scale  = (width / 2) - (stroke * 2);
                var     center = new Vector2(width / 2, height / 2);
                UIImage starImage;

                UIGraphics.BeginImageContext(new CGSize(width, height));
                using (CGContext g = UIGraphics.GetCurrentContext())
                {
                    g.SetLineWidth(stroke);
                    FillColor.ToUIColor().SetFill();
                    StrokeColor.ToUIColor().SetStroke();
                    var shapePoints = new Vector2[0];
                    switch (shapeType)
                    {
                    case ShapeType.Oval:
                        var radiusX = (width / 3) - stroke;
                        var radiusY = (height / 2) - stroke;
                        g.AddEllipseInRect(new CGRect(0, 0, radiusX * 2, radiusY * 2));
                        break;

                    case ShapeType.Circle:
                        var radius = Math.Min(width, height) / 2 - stroke;
                        g.AddEllipseInRect(new CGRect(0, 0, radius * 2, radius * 2));
                        break;

                    case ShapeType.Line:
                        shapePoints = CreateLineGeometry(scale, center);
                        break;

                    case ShapeType.Hexagon:
                        shapePoints = CreateHexagonGeometry(scale, center);
                        break;

                    case ShapeType.Rectangle:
                        shapePoints = CreateRectangleGeometry(scale, center);
                        break;

                    case ShapeType.Square:
                        shapePoints = CreateSquareGeometry(scale, center);
                        break;

                    case ShapeType.Trapezoid:
                        shapePoints = CreateTrapezoidGeometry(scale, center);
                        break;

                    case ShapeType.Triangle:
                        shapePoints = CreateTriangleGeometry(scale, center);
                        break;

                    case ShapeType.Star:
                        shapePoints = CreateStarGeometry(scale, center);
                        break;

                    default:

                        break;
                    }
                    if (shapePoints.Count() > 0)
                    {
                        var points = new List <CGPoint>();

                        foreach (var item in shapePoints)
                        {
                            points.Add(new CGPoint(item.X, item.Y));
                        }

                        var path = new CGPath();

                        path.AddLines(points.ToArray());

                        path.CloseSubpath();

                        g.AddPath(path);
                    }
                    g.DrawPath(CGPathDrawingMode.FillStroke);
                    starImage = UIGraphics.GetImageFromCurrentImageContext();
                }

                return(starImage);
            }
	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);
	}
Beispiel #24
0
 protected virtual void DrawOval(CGContext context, float x, float y, float width, float height, bool fill, bool stroke)
 {
     context.AddEllipseInRect(new RectangleF(x, y, width, height));
     this.DrawPath(context, fill, stroke);
 }
Beispiel #25
0
 void AddEllipsePath(float x1, float y1, float x2, float y2)
 {
     context.AddEllipseInRect(new CGRect(x1, y1, x2 - x1, y2 - y1));
 }
        public void DrawPad(CGContext canvas, SKPoint center, float radius, SKPaint strokePaint, float strokePaintStrokeWidth, SKPaint fillPaint, SKPaint holePaint, SKPaint strokeAccentPaint, float strokeAccentPaintStrokeWidth, SKPaint holeAccentPaint, Swipe swipe)
        {
            float step       = radius / 7.0f;
            float holeRadius = radius / 7.0f;
            float orthShift  = (strokePaintStrokeWidth + strokeAccentPaintStrokeWidth) / 2.0f;
            float diagShift  = orthShift / 1.41f;

            var path = new CGPath();

            path.MoveToPoint(CG.Point(swipe % new SKPoint(center.X - radius, center.Y - radius)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius, center.Y - radius + 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 1 * step, center.Y - radius + 2 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius - 1 * step, center.Y - radius + 4 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 1 * step, center.Y - radius + 6 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius - 1 * step, center.Y - radius + 8 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 1 * step, center.Y - radius + 10 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius - 1 * step, center.Y - radius + 12 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius, center.Y - radius + 13 * step)));

            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius, center.Y + radius)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 1 * step, center.Y + radius)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 2 * step, center.Y + radius - 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 4 * step, center.Y + radius + 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 6 * step, center.Y + radius - 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 8 * step, center.Y + radius + 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 10 * step, center.Y + radius - 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 12 * step, center.Y + radius + 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + 13 * step, center.Y + radius)));

            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius, center.Y + radius)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius, center.Y + radius - 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 1 * step, center.Y + radius - 2 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + 1 * step, center.Y + radius - 4 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 1 * step, center.Y + radius - 6 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + 1 * step, center.Y + radius - 8 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 1 * step, center.Y + radius - 10 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + 1 * step, center.Y + radius - 12 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius, center.Y + radius - 13 * step)));

            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius, center.Y - radius)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 1 * step, center.Y - radius)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 2 * step, center.Y - radius + 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 4 * step, center.Y - radius - 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 6 * step, center.Y - radius + 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 8 * step, center.Y - radius - 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 10 * step, center.Y - radius + 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 12 * step, center.Y - radius - 1 * step)));
            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius - 13 * step, center.Y - radius)));

            path.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius, center.Y - radius)));
            path.CloseSubpath();

            var accPathLft = new CGPath();

            accPathLft.MoveToPoint(CG.Point(swipe % new SKPoint(center.X - radius + orthShift, center.Y - radius + orthShift)));
            accPathLft.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + orthShift, center.Y - radius + orthShift + 1 * step)));
            accPathLft.MoveToPoint(CG.Point(swipe % new SKPoint(center.X - radius + diagShift + 1 * step, center.Y - radius + diagShift + 2 * step)));
            accPathLft.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + diagShift - 1 * step, center.Y - radius + diagShift + 4 * step)));
            accPathLft.MoveToPoint(CG.Point(swipe % new SKPoint(center.X - radius + diagShift + 1 * step, center.Y - radius + diagShift + 6 * step)));
            accPathLft.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + diagShift - 1 * step, center.Y - radius + diagShift + 8 * step)));
            accPathLft.MoveToPoint(CG.Point(swipe % new SKPoint(center.X - radius + diagShift + 1 * step, center.Y - radius + diagShift + 10 * step)));
            accPathLft.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + diagShift - 1 * step, center.Y - radius + diagShift + 12 * step)));
            accPathLft.MoveToPoint(CG.Point(swipe % new SKPoint(center.X - radius + orthShift, center.Y - radius + 13 * step)));
            accPathLft.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X - radius + orthShift, center.Y - radius + 14 * step)));

            var accPathTop = new CGPath();

            accPathTop.MoveToPoint(CG.Point(swipe % new SKPoint(center.X + radius, center.Y - radius + orthShift)));
            accPathTop.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + diagShift / 2 - 1 * step, center.Y - radius + orthShift)));
            accPathTop.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + diagShift - 2 * step, center.Y - radius + diagShift + 1 * step)));
            accPathTop.MoveToPoint(CG.Point(swipe % new SKPoint(center.X + radius + diagShift - 4 * step, center.Y - radius + diagShift - 1 * step)));
            accPathTop.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + diagShift - 6 * step, center.Y - radius + diagShift + 1 * step)));
            accPathTop.MoveToPoint(CG.Point(swipe % new SKPoint(center.X + radius + diagShift - 8 * step, center.Y - radius + diagShift - 1 * step)));
            accPathTop.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + diagShift - 10 * step, center.Y - radius + diagShift + 1 * step)));
            accPathTop.MoveToPoint(CG.Point(swipe % new SKPoint(center.X + radius + diagShift - 12 * step, center.Y - radius + diagShift - 1 * step)));
            accPathTop.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + diagShift / 2 - 13 * step, center.Y - radius + orthShift)));
            accPathTop.AddLineToPoint(CG.Point(swipe % new SKPoint(center.X + radius + orthShift - 14 * step, center.Y - radius + orthShift)));

            canvas.AddPath(path);
            canvas.SetFillColor(CG.Color(fillPaint.Color));
            canvas.FillPath();

            canvas.AddPath(accPathLft);
            canvas.SetStrokeColor(CG.Color(strokeAccentPaint.Color));
            canvas.SetLineWidth(strokeAccentPaint.StrokeWidth);
            canvas.SetLineJoin(CG.LineJoin(strokeAccentPaint.StrokeJoin));
            canvas.SetLineCap(CG.LineCap(strokeAccentPaint.StrokeCap));
            canvas.StrokePath();

            canvas.AddPath(accPathTop);
            canvas.SetStrokeColor(CG.Color(strokeAccentPaint.Color));
            canvas.SetLineWidth(strokeAccentPaint.StrokeWidth);
            canvas.SetLineJoin(CG.LineJoin(strokeAccentPaint.StrokeJoin));
            canvas.SetLineCap(CG.LineCap(strokeAccentPaint.StrokeCap));
            canvas.StrokePath();

            canvas.AddPath(path);
            canvas.SetStrokeColor(CG.Color(strokePaint.Color));
            canvas.SetLineWidth(strokePaint.StrokeWidth);
            canvas.SetLineJoin(CG.LineJoin(strokePaint.StrokeJoin));
            canvas.SetLineCap(CG.LineCap(strokePaint.StrokeCap));
            canvas.StrokePath();

            canvas.AddEllipseInRect(CG.RectFromCircle(swipe % new SKPoint(center.X + diagShift / 2, center.Y + diagShift / 2), swipe % (holeRadius + diagShift / 2)));
            canvas.SetFillColor(CG.Color(holeAccentPaint.Color));
            canvas.FillPath();
            canvas.AddEllipseInRect(CG.RectFromCircle(swipe % center, swipe % holeRadius));
            canvas.SetFillColor(CG.Color(holePaint.Color));
            canvas.FillPath();
        }
        void drawCenter(CGContext contextRef, SizeF viewSize, PointF center)
        {
            int innerDiameter = (int)(Math.Min(viewSize.Width, viewSize.Height) - Theme.Thickness);
            double innerRadius = innerDiameter / 2.0;

            contextRef.SetLineWidth(Theme.Thickness);

            RectangleF innerCircle = new RectangleF((float)(center.X - innerRadius), (float)(center.Y - innerRadius), (float)innerDiameter, (float)innerDiameter);

            contextRef.AddEllipseInRect(innerCircle);
            contextRef.Clip();
            contextRef.ClearRect(innerCircle);
            contextRef.SetFillColor(Theme.CenterColor.CGColor);
            contextRef.FillRect(innerCircle);
        }
Beispiel #28
0
        public override void DrawInContext(CGContext ctx)
        {
            var rect = Bounds;

            var centerPoint = new CGPoint(rect.Width / 2, rect.Height / 2);

            var radius = NMath.Min(rect.Height, rect.Width) / 2;


            var progress = NMath.Min(Progress, 1 - nfloat.Epsilon);

            nfloat radians = 0;

            if (ClockwiseProgress)
            {
                radians = (progress * 2 * NMath.PI) - (NMath.PI / 2);
            }
            else
            {
                radians = (3 * (NMath.PI / 2)) - (progress * 2 * NMath.PI);
            }


            // fill track tint

            if (TrackTintColor != null)
            {
                ctx.SetFillColor(TrackTintColor.CGColor);

                using (var trackPath = new CGPath())
                {
                    trackPath.MoveToPoint(centerPoint);
                    trackPath.AddArc(centerPoint.X, centerPoint.Y, radius, 2 * NMath.PI, 0, true);
                    trackPath.CloseSubpath();
                    ctx.AddPath(trackPath);
                    ctx.FillPath();
                }
            }


            // fill progress if necessary

            if (progress > 0)
            {
                // fill progress

                ctx.SetFillColor(ProgressTintColor.CGColor);

                using (var progressPath = new CGPath())
                {
                    progressPath.MoveToPoint(centerPoint);
                    progressPath.AddArc(centerPoint.X, centerPoint.Y, radius, (3 * (NMath.PI / 2)), radians, !ClockwiseProgress);
                    progressPath.CloseSubpath();
                    ctx.AddPath(progressPath);
                    ctx.FillPath();
                }


                // round corners (if necessary)

                if (RoundedCorners)
                {
                    var pathWidth = radius * ThicknessRadio;

                    var xOffset = radius * (1 + ((1 - (ThicknessRadio / 2)) * NMath.Cos(radians)));
                    var yOffset = radius * (1 + ((1 - (ThicknessRadio / 2)) * NMath.Sin(radians)));

                    var endPoint = new CGPoint(xOffset, yOffset);

                    var startEllipseRect = new CGRect(centerPoint.X - pathWidth / 2, 0, pathWidth, pathWidth);

                    ctx.AddEllipseInRect(startEllipseRect);
                    ctx.FillPath();

                    var endEllipseRect = new CGRect(endPoint.X - pathWidth / 2, endPoint.Y - pathWidth / 2, pathWidth, pathWidth);

                    ctx.AddEllipseInRect(endEllipseRect);
                    ctx.FillPath();
                }
            }


            // notch center circle

            ctx.SetBlendMode(CGBlendMode.Clear);

            var innerRadius = radius * (1 - ThicknessRadio);

            var clearRect = new CGRect(centerPoint.X - innerRadius, centerPoint.Y - innerRadius, innerRadius * 2, innerRadius * 2);

            ctx.AddEllipseInRect(clearRect);
            ctx.FillPath();


            // fill inner tint (if necessary)

            if (InnerTintColor != null)
            {
                ctx.SetBlendMode(CGBlendMode.Normal);
                ctx.SetFillColor(InnerTintColor.CGColor);
                ctx.AddEllipseInRect(clearRect);
                ctx.FillPath();
            }
        }
        static void make_arcs(CGContext graphics, float x, float y, float width, float height, float startAngle, float sweepAngle,
			          bool convert_units, bool antialiasing, bool isPieSlice)
        {
            int i;
            float drawn = 0;
            float endAngle;
            bool enough = false;

            // I do not think we need to convert the units so commented this out.

            /* if required deal, once and for all, with unit conversions */
            //if (convert_units && !OPTIMIZE_CONVERSION(graphics))
            //{
            //    x = gdip_unitx_convgr(graphics, x);
            //    y = gdip_unity_convgr(graphics, y);
            //    width = gdip_unitx_convgr(graphics, width);
            //    height = gdip_unity_convgr(graphics, height);
            //}

            if (Math.Abs(sweepAngle) >= 360)
            {
                graphics.AddEllipseInRect (new CGRect (x,y,width,height));
                return;
            }

            endAngle = startAngle + sweepAngle;
            /* if we end before the start then reverse positions (to keep increment positive) */
            if (endAngle < startAngle)
            {
                var temp = endAngle;
                endAngle = startAngle;
                startAngle = temp;
            }

            if (isPieSlice) {
                graphics.MoveTo(x + (width / 2), y + (height / 2));
            }

            /* i is the number of sub-arcs drawn, each sub-arc can be at most 90 degrees.*/
            /* there can be no more then 4 subarcs, ie. 90 + 90 + 90 + (something less than 90) */
            for (i = 0; i < 4; i++)
            {
                float current = startAngle + drawn;
                float additional;

                if (enough)
                {
                    if (isPieSlice)
                    {
                        graphics.ClosePath();
                    }
                    return;
                }

                additional = endAngle - current; /* otherwise, add the remainder */
                if (additional > 90)
                {
                    additional = 90.0f;
                }
                else
                {
                    /* a near zero value will introduce bad artefact in the drawing (#78999) */
                    if (( additional >= -0.0001f) && (additional <= 0.0001f))
                        return;
                    enough = true;
                }

                make_arc(graphics, (i == 0),	/* only move to the starting pt in the 1st iteration */
                         x, y, width, height,	/* bounding rectangle */
                         current, current + additional, antialiasing, isPieSlice);

                drawn += additional;

            }

            if (isPieSlice) {
                graphics.ClosePath();
            }
        }