void DrawInnerGlow(CGContext context, CGPoint center, nfloat startRadius, nfloat endRadius, CGColor glowColor, nfloat glowRadius)
        {
            using (var innerGlowPath = BezierPathGenerator.Bagel(center, startRadius - glowRadius - GlowOffset, startRadius - GlowOffset, 0f, FullCircleAngle))
                using (var outerGlowPath = BezierPathGenerator.Bagel(center, endRadius + GlowOffset, endRadius + glowRadius + GlowOffset, 0f, FullCircleAngle)) {
                    context.SaveState();

#if __UNIFIED__
                    context.SetShadow(CGSize.Empty, glowRadius, glowColor);
#else
                    context.SetShadowWithColor(CGSize.Empty, glowRadius, glowColor);
#endif
                    context.SetFillColor(Color.CGColor);
                    context.AddPath(innerGlowPath.CGPath);
                    context.FillPath();
                    context.RestoreState();


                    context.SaveState();
#if __UNIFIED__
                    context.SetShadow(CGSize.Empty, glowRadius, glowColor);
#else
                    context.SetShadowWithColor(CGSize.Empty, glowRadius, glowColor);
#endif
                    context.SetFillColor(Color.CGColor);

                    context.SetFillColor(Color.CGColor);
                    context.AddPath(outerGlowPath.CGPath);
                    context.FillPath();
                    context.RestoreState();
                }
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                // Stroke settings
                context.SetLineCap(CGLineCap.Round);
                context.SetLineJoin(CGLineJoin.Round);

                // Draw the completed polylines
                foreach (FingerPaintPolyline polyline in completedPolylines)
                {
                    context.SetStrokeColor(polyline.Color);
                    context.SetLineWidth(polyline.StrokeWidth);
                    context.AddPath(polyline.Path);
                    context.DrawPath(CGPathDrawingMode.Stroke);
                }

                // Draw the in-progress polylines
                foreach (FingerPaintPolyline polyline in inProgressPolylines.Values)
                {
                    context.SetStrokeColor(polyline.Color);
                    context.SetLineWidth(polyline.StrokeWidth);
                    context.AddPath(polyline.Path);
                    context.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
        }
Beispiel #3
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);
            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                context.SetLineCap(CGLineCap.Butt);
                context.SetLineJoin(CGLineJoin.Round);

                foreach (Polyline polyline in completedPolylines)
                {
                    context.SetStrokeColor(polyline.Color);
                    context.SetLineWidth(polyline.StrokeWidth);
                    context.AddPath(polyline.Path);
                    context.DrawPath(CGPathDrawingMode.Stroke);
                }

                foreach (Polyline polyline in inProgressPolyLines.Values)
                {
                    context.SetStrokeColor(polyline.Color);
                    context.SetLineWidth(polyline.StrokeWidth);
                    context.AddPath(polyline.Path);
                    context.DrawPath(CGPathDrawingMode.Stroke);
                }
            }
        }
 /// <summary>
 /// Draws the map rectangle.
 /// </summary>
 /// <param name="mapRect">Map rectangle.</param>
 /// <param name="zoomScale">Zoom scale.</param>
 /// <param name="context"> Graphics context.</param>
 public override void DrawMapRect(MKMapRect mapRect, nfloat zoomScale, CGContext context)
 {
     base.DrawMapRect(mapRect, zoomScale, context);
     var multiPolygons = (MultiPolygon)this.polygonOverlay;
     foreach (var item in multiPolygons.Polygons)
     {
         var path = new CGPath();
         this.InvokeOnMainThread(() =>
             {
                 path = PolyPath(item.Polygon);
             });
         if (path != null)
         {
             context.SetFillColor(item.FillColor);
             context.BeginPath();
             context.AddPath(path);
             context.DrawPath(CGPathDrawingMode.EOFill);
             if (item.DrawOutlines)
             {
                 context.BeginPath();
                 context.AddPath(path);
                 context.StrokePath();
             }
         }
     }
 }
Beispiel #5
0
        public static void RenderInContext(this CGPath path,
                                           CGContext context,
                                           CGColor[] cgColors,
                                           CGColor strokeColor = null,
                                           float strokeWidth   = -1)
        {
            context.AddPath(path);
            if (cgColors.Length > 1)
            {
                context.SaveState();
                context.Clip();
                var bounds = path.BoundingBox;
                context.RenderGradientInRect(bounds, cgColors);
                context.RestoreState();
            }
            else
            {
                context.SetFillColor(cgColors[0]);
                context.FillPath();
            }

            context.AddPath(path);
            if (strokeColor != null && strokeWidth > 0.0f)
            {
                context.SetStrokeColor(strokeColor);
                context.SetLineWidth(strokeWidth);
                context.StrokePath();
            }
        }
        public static void DrawSoldOutSymbol(CGContext g, bool selected, CGRect rect)
        {
            var    path   = new CGPath();
            nfloat margin = rect.Width * 3 / 16;
            nfloat side   = (nfloat)Math.Min((double)rect.Height, (double)rect.Width) - 2 * margin;

            g.SetLineWidth(2);
            SoldOutColor(selected).SetStroke();
            var diagonalLeftTopToRightBottom = new CGPath();

            diagonalLeftTopToRightBottom.AddLines(new CGPoint[] {
                new CGPoint(margin, margin + side),
                new CGPoint(margin + side, margin)
            });
            diagonalLeftTopToRightBottom.CloseSubpath();
            g.AddPath(diagonalLeftTopToRightBottom);
            var diagonalLeftBottomToRightTop = new CGPath();

            diagonalLeftBottomToRightTop.AddLines(new CGPoint[] {
                new CGPoint(margin, margin),
                new CGPoint(margin + side, margin + side)
            });
            diagonalLeftBottomToRightTop.CloseSubpath();
            g.AddPath(diagonalLeftBottomToRightTop);
            g.DrawPath(CGPathDrawingMode.Stroke);
        }
        public override void Draw(RectangleF rect)
        {
            float     textWidth = rect.Width - TextOffset - XBorderPadding;
            CGContext ctx       = UIGraphics.GetCurrentContext();
            float     y         = rect.Y;
            float     x         = rect.X;

            TextColor.SetColor();

            DrawString(Make ?? "Unknown Make", new RectangleF(x + TextOffset, y + MakeYOffset, textWidth, AircraftMakeFontSize), AircraftMakeFont);
            DrawString(Model ?? "Unknown Model", new RectangleF(x + TextOffset, y + ModelYOffset, textWidth, AircraftModelFontSize), AircraftModelFont);
            DrawString(Remarks ?? "", new RectangleF(x + TextOffset, y + RemarksYOffset, textWidth, RemarksFontSize * 3), RemarksFont, UILineBreakMode.WordWrap);

            ctx.SaveState();

            ctx.TranslateCTM(XBorderPadding, YBorderPadding);
            ctx.AddPath(PhotoBorder);
            ctx.Clip();

            if (Photograph == null)
            {
                DefaultPhoto.Draw(PhotoRect);
            }
            else
            {
                Photograph.Draw(PhotoRect);
            }

            ctx.AddPath(PhotoBorder);
            ctx.SetStrokeColor(0.5f, 0.5f, 0.5f, 1.0f);
            ctx.SetLineWidth(0.5f);
            ctx.StrokePath();

            ctx.RestoreState();
        }
        public static void DrawOnDemandAvailabilityStatus(CGContext context, OnDemandScreening screening, nfloat side, bool selected)
        {
            // Establish some base dimensions.
            const int maxDaysInRuler = 5;
            const int margin         = 2;
            nfloat    w             = side - 2 * margin;
            nfloat    h             = side - 2 * margin;
            nfloat    x             = margin;
            nfloat    y             = margin;
            var       windowSeconds = (screening.WindowEndTime - screening.WindowStartTime).TotalSeconds;
            var       passedSeconds = (screening.StartTime - screening.WindowStartTime).TotalSeconds;
            nfloat    wPassed       = w * (nfloat)passedSeconds / (nfloat)windowSeconds;
            nfloat    wLeft         = w - wPassed;

            // Initlialize core graphics settings.
            context.SetStrokeColor(ClickPadTextColor(selected).CGColor);
            context.SetLineWidth(1);

            // Draw the passed time part of the progres bar.
            using (var passedPath = new CGPath())
            {
                context.SetFillColor(ClickPadTextColor(selected).CGColor);
                passedPath.AddRect(new CGRect(x, y + h * 1 / 16, wPassed, h * 2 / 16));
                passedPath.CloseSubpath();
                context.AddPath(passedPath);
            }
            context.DrawPath(CGPathDrawingMode.FillStroke);

            // Draw the left time part of the progress bar.
            using (var leftPath = new CGPath())
            {
                context.SetFillColor((selected ? ClickPadBackgroundColor(selected) : NSColor.White).CGColor);
                leftPath.AddRect(new CGRect(x + wPassed, y + h * 1 / 16, wLeft, h * 2 / 16));
                leftPath.CloseSubpath();
                context.AddPath(leftPath);
            }
            context.DrawPath(CGPathDrawingMode.FillStroke);

            // Draw verticle needle lines to indicate availability days.
            var    daySeconds = ViewController.DaySpan.TotalSeconds;
            nfloat days       = (nfloat)windowSeconds / (nfloat)daySeconds;
            nfloat wPeriod    = w / days;

            if (days <= maxDaysInRuler)
            {
                using (var needlePath = new CGPath())
                {
                    for (int i = 1; i < days; i++)
                    {
                        needlePath.AddLines(new CGPoint[]
                        {
                            new CGPoint(i * wPeriod, y + h * 1 / 16),
                            new CGPoint(i * wPeriod, y + h * 3 / 16)
                        });
                    }
                    context.AddPath(needlePath);
                }
            }
            context.DrawPath(CGPathDrawingMode.FillStroke);
        }
        private UIImage drawCenter()
        {
            UIGraphics.BeginImageContext(new SizeF(64, 64));

            using (CGContext cont = UIGraphics.GetCurrentContext()) {
                using (CGPath path = new CGPath()) {
                    cont.SetLineWidth(1f);
                    cont.SetRGBStrokeColor(1f, 0, 0, 1);
                    cont.SetRGBFillColor(0.5f, 0, 0, 1);
                    path.AddElipseInRect(new RectangleF(24, 24, 16, 16));
                    path.CloseSubpath();

                    cont.AddPath(path);
                    cont.DrawPath(CGPathDrawingMode.FillStroke);
                }

                using (CGPath path = new CGPath()) {
                    cont.SetRGBStrokeColor(1f, 0, 0, 1);
                    cont.SetLineWidth(3f);
//					cont.SetRGBFillColor (.5f, 0, 0, 1);
                    path.AddElipseInRect(new RectangleF(16, 16, 32, 32));
                    path.CloseSubpath();

                    cont.AddPath(path);
                    cont.DrawPath(CGPathDrawingMode.Stroke);
                }

                return(UIGraphics.GetImageFromCurrentImageContext());
            }

            UIGraphics.EndImageContext();
        }
Beispiel #10
0
        /// <summary>
        /// Draws the map rectangle.
        /// </summary>
        /// <param name="mapRect">Map rectangle.</param>
        /// <param name="zoomScale">Zoom scale.</param>
        /// <param name="context"> Graphics context.</param>
        public override void DrawMapRect(MKMapRect mapRect, nfloat zoomScale, CGContext context)
        {
            base.DrawMapRect(mapRect, zoomScale, context);
            var multiPolygons = (MultiPolygon)this.polygonOverlay;

            foreach (var item in multiPolygons.Polygons)
            {
                var path = new CGPath();
                this.InvokeOnMainThread(() =>
                {
                    path = PolyPath(item.Polygon);
                });
                if (path != null)
                {
                    context.SetFillColor(item.FillColor);
                    context.BeginPath();
                    context.AddPath(path);
                    context.DrawPath(CGPathDrawingMode.EOFill);
                    if (item.DrawOutlines)
                    {
                        context.BeginPath();
                        context.AddPath(path);
                        context.StrokePath();
                    }
                }
            }
        }
        // TODO Optimize circle drawing by removing allocation of CGPath
        // (maybe by drawing via BitmapContext, per pixel:
        // https://stackoverflow.com/questions/34987442/drawing-pixels-on-the-screen-using-coregraphics-in-swift)
        private void DrawProgressRing(CGContext g, nfloat x0, nfloat y0,
                                      nfloat progress, nfloat lineThickness, nfloat radius,
                                      UIColor backColor, UIColor frontColor)
        {
            g.SetLineWidth(lineThickness);

            // Draw background circle
            CGPath path = new CGPath();

            backColor.SetStroke();

            path.AddArc(x0, y0, radius, 0, 2.0f * (float)Math.PI, true);
            g.AddPath(path);
            g.DrawPath(CGPathDrawingMode.Stroke);

            // Draw progress circle
            var pathStatus = new CGPath();

            frontColor.SetStroke();

            var startingAngle = 1.5f * (float)Math.PI;

            pathStatus.AddArc(x0, y0, radius, startingAngle, startingAngle + progress * 2 * (float)Math.PI, false);

            g.AddPath(pathStatus);
            g.DrawPath(CGPathDrawingMode.Stroke);
        }
        public void DrawGraph(CGContext g, nfloat x0, nfloat y0, nfloat piMult)
        {
            //_g = g;
            _x0 = x0;
            _y0 = y0;

            _g.SetLineWidth(_lineWidth);
            //_piMult = piMult;

            // Draw circle
            CGPath path = new CGPath();

            UIColor.FromRGB(155, 155, 155).SetStroke();
            path.AddArc(_x0, _y0, _radius, 0.79f * (float)Math.PI, (2.21f) * (float)Math.PI, false);
            _g.AddPath(path);
            _g.DrawPath(CGPathDrawingMode.Stroke);
            //SetNeedsDisplay();

            CGPath path2 = new CGPath();

            _barColor.SetStroke();
            path2.AddArc(_x0, _y0, _radius, 0.79f * (float)Math.PI, (0.79f * (float)Math.PI + (float)(0.71 * _piMult) * (float)Math.PI), false);
            //path2.AddArc(x0, y0, _radius, -0.5f * (float)Math.PI, 0.5f * (float)Math.PI + _piMult * (float)Math.PI * 0.99, true);
            _g.AddPath(path2);
            _g.DrawPath(CGPathDrawingMode.Stroke);
            //SetNeedsDisplay();
        }
        public override void Draw(RectangleF rect)
        {
            WeatherForecastAnnotation annotation;
            CGPath path;

            base.Draw(rect);

            annotation = Annotation as WeatherForecastAnnotation;
            if (annotation == null)
            {
                return;
            }

            // Get the current graphics context
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetLineWidth(1.0f);

            // Draw the gray pointed shape:
            path = new CGPath();
            path.MoveToPoint(14.0f, 0.0f);
            path.AddLineToPoint(0.0f, 0.0f);
            path.AddLineToPoint(55.0f, 50.0f);
            context.AddPath(path);

            context.SetFillColor(UIColor.LightGray.CGColor);
            context.SetStrokeColor(UIColor.Gray.CGColor);
            context.DrawPath(CGPathDrawingMode.FillStroke);

            // Draw the cyan rounded box
            path = new CGPath();
            path.MoveToPoint(15.0f, 0.5f);
            path.AddArcToPoint(59.5f, 00.5f, 59.5f, 05.0f, 5.0f);
            path.AddArcToPoint(59.5f, 69.5f, 55.5f, 69.5f, 5.0f);
            path.AddArcToPoint(10.5f, 69.5f, 10.5f, 64.0f, 5.0f);
            path.AddArcToPoint(10.5f, 00.5f, 15.5f, 00.5f, 5.0f);
            context.AddPath(path);

            context.SetFillColor(UIColor.Cyan.CGColor);
            context.SetStrokeColor(UIColor.Blue.CGColor);
            context.DrawPath(CGPathDrawingMode.FillStroke);

            // Create the location & temperature string
            WeatherForecast forecast    = annotation.Forecast;
            NSString        temperature = new NSString(string.Format("{0}\n{1} / {2}", forecast.Place, forecast.High, forecast.Low));

            // Draw the text in black
            UIColor.Black.SetColor();
            temperature.DrawString(new RectangleF(15.0f, 5.0f, 50.0f, 40.0f), UIFont.SystemFontOfSize(11.0f));
            temperature.Dispose();

            // Draw the icon for the weather condition
            string  imageName = string.Format("WeatherMap.WeatherIcons.{0}.png", forecast.Condition);
            UIImage image     = UIImage.FromResource(typeof(WeatherAnnotationView).Assembly, imageName);

            image.Draw(new RectangleF(12.5f, 28.0f, 45.0f, 45.0f));
            image.Dispose();
        }
Beispiel #14
0
        private void DrawForwardRightBackwardLeft()
        {
            //get graphics context
            using (CGContext g = UIGraphics.GetCurrentContext()) {
                //set up drawing attributes
                g.SetLineWidth(STROKE_WIDTH);
                //g.SetFillColor (0, 0, 178, 255);
                FILL.SetFill();
                STROKE.SetStroke();

                var outline = new CGPath();
                var body    = new CGPath();

                var x0 = 0;
                var x1 = this.Frame.Width * GUTTER;
                var x2 = this.Frame.Width - x1;
                var x3 = this.Frame.Width;
                var y0 = 0;
                var y1 = this.Frame.Height * GUTTER;
                var y2 = this.Frame.Height - y1;
                var y3 = this.Frame.Height;

                var trPoints = new CGPoint[] {
                    new CGPoint(x2, y0),
                    new CGPoint(x2, y1),
                    new CGPoint(x3, y1)
                };
                var brPoints = new CGPoint[] {
                    new CGPoint(x3, y2),
                    new CGPoint(x2, y2),
                    new CGPoint(x2, y3)
                };
                var blPoints = new CGPoint[] {
                    new CGPoint(x1, y3),
                    new CGPoint(x1, y2),
                    new CGPoint(x0, y2)
                };
                var tlPoints = new CGPoint[] {
                    new CGPoint(x0, y1),
                    new CGPoint(x1, y1),
                    new CGPoint(x1, y0)
                };

                body.AddLines(trPoints.Union(brPoints).Union(blPoints).Union(tlPoints).ToArray());
                body.CloseSubpath();

                outline.AddLines(trPoints);
                outline.AddLines(brPoints);
                outline.AddLines(blPoints);
                outline.AddLines(tlPoints);

                g.AddPath(body);
                g.DrawPath(CGPathDrawingMode.Fill);

                g.AddPath(outline);
                g.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
        //
        // Helper function to generate shadow
        //
        private void GenerateShapeShadow(CGContext context, UIBezierPath shapeObject, nfloat xOffset, nfloat yOffset, nfloat blurValue, CGBlendMode blendingMode, UIColor shadowColor, nfloat borderWidth, int borderPosition, nfloat iWidth, nfloat iHeight)
        {
            CGPoint basePoint;
            CGPoint offsetPoint;
            CGSize  calculatedShadowOffset;
            nfloat  calculatedShadowBlur;
            CGPoint constPointZero;

            constPointZero = new CGPoint(0, 0);

            basePoint              = baseTransform.TransformPoint(context.PointToDeviceSpace(constPointZero));
            offsetPoint            = baseTransform.TransformPoint(context.PointToDeviceSpace(new CGPoint(xOffset, yOffset)));
            calculatedShadowOffset = new CGSize(offsetPoint.X - basePoint.X, offsetPoint.Y - basePoint.Y);
            if (blurValue == 0)
            {
                calculatedShadowBlur = 0;
            }
            else
            {
                calculatedShadowBlur = Hypot(calculatedShadowOffset.Width, calculatedShadowOffset.Height) / blurValue;
            }
            context.SetShadow(calculatedShadowOffset, calculatedShadowBlur, shadowColor.CGColor);
            context.SetBlendMode(blendingMode);

            context.BeginTransparencyLayer(null);

            UIColor.Black.SetFill();
            shapeObject.Fill();

            if (borderWidth > 0)
            {
                if (borderPosition == 0)
                {
                    context.SaveState();
                    shapeObject.LineWidth = borderWidth;
                    UIColor.Black.SetStroke();
                    shapeObject.Stroke();
                    context.RestoreState();
                }

                if (borderPosition == 1)
                {
                    context.BeginPath();
                    context.AddPath(shapeObject.CGPath);
                    context.EOClip();
                }

                if (borderPosition == 2)
                {
                    context.BeginPath();
                    context.AddPath(shapeObject.CGPath);
                    context.AddRect(RectangleFExtensions.Inset(shapeObject.Bounds, iWidth, iHeight));
                    context.EOClip();
                }
            }

            context.EndTransparencyLayer();
        }
Beispiel #16
0
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            // Get current graphics context.
            using (CGContext g = UIGraphics.GetCurrentContext()) {
                // Overall transforms to shift (0, 0) to center and scale.
                g.TranslateCTM(rect.GetMidX(), rect.GetMidY());
                nfloat scale = (nfloat)Math.Min(rect.Width, rect.Height) / 2 / 100;
                g.ScaleCTM(scale, scale);

                // Attributes for tick marks
                g.SetStrokeColor(new CGColor(0, 0, 0));
                g.SetLineCap(CGLineCap.Round);

                // Set line dash to draw tick marks for every minute.
                g.SetLineWidth(3);
                g.SetLineDash(0, new nfloat[] { 0, 3 * (nfloat)Math.PI });
                g.AddPath(tickMarks);
                g.DrawPath(CGPathDrawingMode.Stroke);

                // Set line dash to draw tick marks for every hour.
                g.SetLineWidth(6);
                g.SetLineDash(0, new nfloat[] { 0, 15 * (nfloat)Math.PI });
                g.AddPath(tickMarks);
                g.DrawPath(CGPathDrawingMode.Stroke);

                // Set common attributes for clock hands.
                g.SetStrokeColor(new CGColor(0, 0, 0));
                g.SetFillColor(new CGColor(0, 0, 1));
                g.SetLineWidth(2);
                g.SetLineDash(0, null);
                g.SetLineJoin(CGLineJoin.Round);

                // Draw hour hand.
                g.SaveState();
                g.RotateCTM(hourAngle);                  // 2 * (float)Math.PI * (dt.Hour + dt.Minute / 60.0f) / 12);
                g.AddPath(hourHand);
                g.DrawPath(CGPathDrawingMode.FillStroke);
                g.RestoreState();

                // Draw minute hand.
                g.SaveState();
                g.RotateCTM(minuteAngle);                  // 2 * (float)Math.PI * (dt.Minute + dt.Second / 60.0f) / 60);
                g.AddPath(minuteHand);
                g.DrawPath(CGPathDrawingMode.FillStroke);
                g.RestoreState();

                // Draw second hand.
                g.SaveState();
                g.RotateCTM(secondAngle);                  // 2 * (float)Math.PI * dt.Second / 60);
                g.AddPath(secondHand);
                g.DrawPath(CGPathDrawingMode.Stroke);
                g.RestoreState();
            }
        }
Beispiel #17
0
        public override void Draw(RectangleF rect)
        {
            base.Draw(rect);

            // get graphics context
            CGContext gctx = UIGraphics.GetCurrentContext();

            // set up drawing attributes
            gctx.SetLineWidth(4);
            UIColor.Yellow.SetStroke();

            // stroke with a dashed line
            gctx.SetLineDash(3, new float[] { 6, 2 });

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

            PointF origin = new PointF(Bounds.GetMidX(),
                                       Bounds.GetMinY() + 10);

            path.AddLines(new PointF[] {
                origin,
                new PointF(origin.X + 35, origin.Y + 80),
                new PointF(origin.X - 50, origin.Y + 30),
                new PointF(origin.X + 50, origin.Y + 30),
                new PointF(origin.X - 35, origin.Y + 80)
            });

            path.CloseSubpath();

            // add geometry to graphics context and draw it
            gctx.AddPath(path);

            gctx.DrawPath(CGPathDrawingMode.Stroke);

            // fill the star with a gradient
            gctx.AddPath(path);
            gctx.Clip();

            RectangleF starBoundingBox = path.BoundingBox;

            float[] locations  = { 0.0f, 1.0f };
            float[] components = { 1.0f, 0.0f, 0.0f, 1.0f,
                                   0.0f, 0.0f, 1.0f, 1.0f };

            using (var rgb = CGColorSpace.CreateDeviceRGB()) {
                CGGradient gradient = new CGGradient(rgb, components, locations);

                PointF gradientStart = new PointF(starBoundingBox.Left, starBoundingBox.Top);
                PointF gradientEnd   = new PointF(starBoundingBox.Right, starBoundingBox.Bottom);
                gctx.DrawLinearGradient(gradient, gradientStart, gradientEnd, CGGradientDrawingOptions.DrawsBeforeStartLocation);
            }
        }
Beispiel #18
0
        public void DrawPath(IPath path, float x, float y)
        {
            if (path == null || ((Path)path).NativePath == null)
            {
                return;
            }

            context.SaveState();
            context.TranslateCTM(x, y);
            context.AddPath(((Path)path).NativePath);
            context.DrawPath(CGPathDrawingMode.Stroke);
            context.RestoreState();
        }
        private void DrawPath(CGContext context, CGPath path, CGColor fillColor, double strokeWidth, CGColor strokeColor)
        {
            context.SetFillColor(fillColor);
            context.AddPath(path);
            context.FillPath();

            if (strokeWidth > 0)
            {
                context.SetLineWidth((nfloat)strokeWidth);
                context.SetStrokeColor(strokeColor);
                context.AddPath(path);
                context.StrokePath();
            }
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            //get graphics context
            using (CGContext g = UIGraphics.GetCurrentContext()) {
                //set up drawing attributes
                g.SetLineWidth(10);
                UIColor.Blue.SetFill();
                UIColor.Red.SetStroke();

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

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

                path.CloseSubpath();

                //use a dashed line
                g.SetLineDash(0, new nfloat[] { 10, 4 });

                //add geometry to graphics context and draw it
                g.AddPath(path);
                g.DrawPath(CGPathDrawingMode.FillStroke);

                // add the path back to the graphics context so that it is the current path
                g.AddPath(path);
                // set the current path to be the clipping path
                g.Clip();

                // the color space determines how Core Graphics interprets color information
                using (CGColorSpace rgb = CGColorSpace.CreateDeviceRGB()) {
                    CGGradient gradient = new CGGradient(rgb, new CGColor[] {
                        UIColor.Blue.CGColor,
                        UIColor.Yellow.CGColor
                    });

                    // draw a linear gradient
                    g.DrawLinearGradient(
                        gradient,
                        new CGPoint(path.BoundingBox.Left, path.BoundingBox.Top),
                        new CGPoint(path.BoundingBox.Right, path.BoundingBox.Bottom),
                        CGGradientDrawingOptions.DrawsBeforeStartLocation);
                }
            }
        }
Beispiel #21
0
        public void FillPath(Color color, GraphicsPath path)
        {
            StartDrawing();

            if (!Flipped)
            {
                context.ConcatCTM(new CGAffineTransform(1, 0, 0, -1, 0, ViewHeight));
            }
            context.BeginPath();
            context.AddPath(path.ControlObject as CGPath);
            context.ClosePath();
            context.SetFillColor(Generator.Convert(color));
            context.FillPath();
            EndDrawing();
        }
Beispiel #22
0
 public void DrawPolyline(MKPolyline polygon,MKMapRect mapRect, float zoomScale, CGContext context)
 {
     CGPath path = this.polyPath (polygon,mapRect,zoomScale,context);
     if (path != null)
     {
         this.ApplyFillProperties (context, zoomScale);
         context.BeginPath ();
         context.AddPath (path);
         context.DrawPath (CGPathDrawingMode.Stroke);
         this.ApplyStrokeProperties (context, zoomScale);
         context.BeginPath ();
         context.AddPath (path);
         context.StrokePath ();
     }
 }
Beispiel #23
0
        public override void AppendPath(object backend, object otherBackend)
        {
            CGContext        dest = ((CGContextBackend)backend).Context;
            CGContextBackend src  = otherBackend as CGContextBackend;

            if (src != null)
            {
                using (var path = src.Context.CopyPath())
                    dest.AddPath(path);
            }
            else
            {
                dest.AddPath((CGPath)otherBackend);
            }
        }
        protected virtual void DrawTriangle(CGContext context, CGRect rect, bool fill, bool stroke)
        {
            var trianglePath = new CGPath();

            trianglePath.MoveToPoint(rect.Width / 2, 0);
            trianglePath.AddLineToPoint(rect.Size.Width, rect.Size.Height);
            trianglePath.AddLineToPoint(0, rect.Size.Height);
            trianglePath.AddLineToPoint(rect.Width / 2, 0);

            context.AddPath(trianglePath);
            context.Clip();
            context.AddPath(trianglePath);

            DrawPath(context, fill, stroke);
        }
Beispiel #25
0
        void DrawAddPhotoButton(CGContext ctx)
        {
            UIColor    background = pressed ? HighlightedButtonColor : NormalButtonColor;
            RectangleF bounds     = PhotoRect;
            float      alpha      = 1.0f;

            ctx.SaveState();
            ctx.AddPath(PhotoBorder);
            ctx.Clip();

            using (var cs = CGColorSpace.CreateDeviceRGB()) {
                var     bottomCenter = new PointF(bounds.GetMidX(), bounds.GetMaxY());
                var     topCenter    = new PointF(bounds.GetMidX(), bounds.Y);
                float[] gradColors;
                CGPath  container;

                gradColors = new [] { 0.23f, 0.23f, 0.23f, alpha, 0.67f, 0.67f, 0.67f, alpha };
                using (var gradient = new CGGradient(cs, gradColors, new [] { 0.0f, 1.0f })) {
                    ctx.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }

                var bg = bounds.Inset(1.0f, 1.0f);
                container = GraphicsUtil.MakeRoundedRectPath(bg, 13.5f);
                ctx.AddPath(container);
                ctx.Clip();

                background.SetFill();
                ctx.FillRect(bg);

                gradColors = new [] {
                    0.0f, 0.0f, 0.0f, 0.75f,
                    0.0f, 0.0f, 0.0f, 0.65f,
                    0.0f, 0.0f, 0.0f, 0.35f,
                    0.0f, 0.0f, 0.0f, 0.05f
                };

                using (var gradient = new CGGradient(cs, gradColors, new float [] { 0.0f, 0.1f, 0.4f, 1.0f })) {
                    ctx.DrawLinearGradient(gradient, topCenter, bottomCenter, 0);
                }
            }

            //ctx.AddPath (PhotoBorder);
            //ctx.SetStrokeColor (0.5f, 0.5f, 0.5f, 1.0f);
            //ctx.SetLineWidth (0.5f);
            //ctx.StrokePath ();

            ctx.RestoreState();
        }
Beispiel #26
0
        public UIImage GetDrawlineImage()
        {
            CGRect pageRect;

            if (IsPdfBackground == true)
            {
                pageRect = PDFpageRect;
            }
            else
            {
                pageRect = imageBackgroundRect;
            }
            UIGraphics.BeginImageContext(pageRect.Size);
            CGContext context = UIGraphics.GetCurrentContext();

            context.SetLineWidth(2);
            path.AddLines(pointlist.ToArray());

            UIColor.Red.SetStroke();
            context.AddPath(path);
            context.DrawPath(CGPathDrawingMode.Stroke);
            context.SaveState();
            UIImage thm = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(thm);
        }
Beispiel #27
0
        // rect changes depending on if the whole view is being redrawn, or just a section
        public override void Draw(CGRect rect)
        {
            Console.WriteLine("Draw() Called");
            base.Draw(rect);

            using (CGContext context = UIGraphics.GetCurrentContext()) {
                // fill the background with white
                // set fill color
                UIColor.White.SetFill();
                //context.SetRGBFillColor (1, 1, 1, 1f);
                // paint
                context.FillRect(rect);

                // draw a rectangle using stroke rect
                UIColor.Blue.SetStroke();
                context.StrokeRect(new CGRect(10, 10, 200, 100));

                // draw a rectangle using a path
                context.BeginPath();
                context.MoveTo(220, 10);
                context.AddLineToPoint(420, 10);
                context.AddLineToPoint(420, 110);
                context.AddLineToPoint(220, 110);
                context.ClosePath();
                UIColor.DarkGray.SetFill();
                context.DrawPath(CGPathDrawingMode.FillStroke);

                // draw a rectangle using a path
                CGPath rectPath = new CGPath();
                rectPath.AddRect(new CGRect(new CGPoint(430, 10), new CGSize(200, 100)));
                context.AddPath(rectPath);
                context.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Beispiel #28
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 #29
0
        public override void DrawRect(CGRect dirtyRect)
        {
            CGContext ctx = NSGraphicsContext.CurrentContext.GraphicsPort;

            ctx.AddPath(HeartPath);
            ctx.StrokePath();
        }
Beispiel #30
0
            public override void Draw(CoreGraphics.CGRect rect)
            {
                base.Draw(rect);

                using (CGContext g = UIGraphics.GetCurrentContext())
                {
                    if ((xLocations != null) && (yLocations != null))
                    {
                        CGPath currentPath = new CGPath();

                        for (int i = 0; i < xLocations.Length; i++)
                        {
                            currentPath.AddLines(new CGPoint[] { new CGPoint(xLocations[i], 0), new CGPoint(xLocations[i], Frame.Height) });
                        }

                        for (int i = 0; i < yLocations.Length; i++)
                        {
                            currentPath.AddLines(new CGPoint[] { new CGPoint(0, yLocations[i]), new CGPoint(Frame.Width, yLocations[i]) });
                        }

                        g.SetLineWidth(1);
                        g.AddPath(currentPath);
                        g.SetStrokeColor(UIColor.FromRGB(0, 0, 0).CGColor);
                        g.DrawPath(CGPathDrawingMode.Stroke);
                    }
                }
            }
Beispiel #31
0
        void DrawPhoto(CGContext ctx)
        {
            ctx.SaveState();

            ctx.AddPath(PhotoBorder);
            ctx.Clip();

            Photograph.Draw(PhotoRect);

            ctx.AddPath(PhotoBorder);
            ctx.SetStrokeColor(0.5f, 0.5f, 0.5f, 1.0f);
            ctx.SetLineWidth(0.5f);
            ctx.StrokePath();

            ctx.RestoreState();
        }
Beispiel #32
0
        public override void CreateShape(CGPath path, CGContext gctx)
        {
            path.AddRect (new RectangleF (_origin, new SizeF (100, 100)));
            gctx.AddPath (path);

            gctx.DrawPath (CGPathDrawingMode.FillStroke);
        }
        public override void Draw(CGRect rect)
        {
            base.Draw(rect);

            using (CGContext g = UIGraphics.GetCurrentContext()) {
                // calc points
                float   height  = (float)rect.Height / 2;
                float   centerX = (float)rect.Width / 2;
                CGPoint p1      = new CGPoint(centerX - height / 2, height / 2 + height);
                CGPoint p2      = new CGPoint(centerX, height / 2);
                CGPoint p3      = new CGPoint(centerX + height / 2, height / 2 + height);

                //set up drawing attributes
                g.SetLineWidth(10);
                UIColor.Blue.SetFill();
                UIColor.Red.SetStroke();

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

                path.AddLines(new CGPoint[] {
                    p1,
                    p2,
                    p3
                });

                path.CloseSubpath();

                //add geometry to graphics context and draw it
                g.AddPath(path);
                g.DrawPath(CGPathDrawingMode.FillStroke);
            }
        }
        public void DrawGraph(CGContext g,nfloat x0,nfloat y0)
        {
            g.SetLineWidth (_lineWidth);

            // Draw background circle
            CGPath path = new CGPath ();
            _backColor.SetStroke ();
            path.AddArc (x0, y0, _radius, 0, 2.0f * (float)Math.PI, true);
            g.AddPath (path);
            g.DrawPath (CGPathDrawingMode.Stroke);

            // Draw overlay circle
            var pathStatus = new CGPath ();
            _frontColor.SetStroke ();
            pathStatus.AddArc(x0, y0, _radius, 0, _degrees * (float)Math.PI, false);
            g.AddPath (pathStatus);
            g.DrawPath (CGPathDrawingMode.Stroke);
        }
        public override void CreateShape(CGPath path, CGContext gctx)
        {
            path.AddLines (new PointF[] { _origin, new PointF (_origin.X + 50, _origin.Y + 100), new PointF (_origin.X - 50, _origin.Y + 100) });

            path.CloseSubpath ();

            gctx.AddPath (path);

            gctx.DrawPath (CGPathDrawingMode.FillStroke);
        }
        public override void DrawInContext(CGContext ctx)
        {
            base.DrawInContext (ctx);

            // clip
            var cornerRadius = Bounds.Height / 2.0f;
            UIBezierPath switchOutline =  UIBezierPath.FromRoundedRect( (CGRect)Bounds, (nfloat)cornerRadius);
            ctx.AddPath (switchOutline.CGPath);
            ctx.Clip ();

            // 1) fill the track
            ctx.SetFillColor (UIColor.Green.CGColor);
            ctx.AddPath(switchOutline.CGPath);
            ctx.FillPath ();

            // 2) fill the highlighed range //Skipped for demo

            // 3) add a highlight over the track
            CGRect highlight = new CGRect(cornerRadius/2, Bounds.Height/2,
                Bounds.Width - cornerRadius, Bounds.Height/2);
            UIBezierPath highlightPath = UIBezierPath.FromRoundedRect ((CGRect)highlight, (nfloat)highlight.Height / 2.0f);
            ctx.AddPath(highlightPath.CGPath);
            ctx.SetFillColor( UIColor.FromWhiteAlpha((nfloat)1.0f, (nfloat)0.4f).CGColor);
            ctx.FillPath ();

            // 4) inner shadow
            ctx.SetShadow( new CGSize(0f, 2.0f), 3.0f, UIColor.Gray.CGColor);
            ctx.AddPath (switchOutline.CGPath);
            ctx.SetStrokeColor(UIColor.Gray.CGColor);
            ctx.StrokePath ();

            // 5) outline the track
            ctx.AddPath( switchOutline.CGPath);
            ctx.SetStrokeColor(UIColor.Black.CGColor);
            ctx.SetLineWidth ((nfloat)0.5f);
            ctx.StrokePath ();

            //
            //			ctx.SetFillColor (UIColor.Blue.CGColor);
            //			ctx.FillRect (Bounds);
        }
        public override void DrawInContext(CGContext ctx)
        {
            base.DrawInContext (ctx);

            // clip
            var cornerRadius = Bounds.Height * Slider.Curvaceousness / 2.0f;
            UIBezierPath switchOutline =  UIBezierPath.FromRoundedRect( (CGRect)Bounds, (nfloat)cornerRadius);
            ctx.AddPath (switchOutline.CGPath);
            ctx.Clip ();

            // 1) fill the track
            ctx.SetFillColor (Slider.TrackColor.CGColor);
            ctx.AddPath(switchOutline.CGPath);
            ctx.FillPath ();

            // 2) fill the highlighed range
            ctx.SetFillColor(Slider.TrackHighlightColor.CGColor);
            var lower = Slider.positionForValue (Slider.LowValue);
            var higher = Slider.positionForValue(Slider.HighValue);
            ctx.FillRect((CGRect)new CGRect(lower, 0, higher - lower, Bounds.Height));

            // 3) add a highlight over the track
            CGRect highlight = new CGRect(cornerRadius/2, Bounds.Height/2,
                Bounds.Width - cornerRadius, Bounds.Height/2);
            UIBezierPath highlightPath = UIBezierPath.FromRoundedRect ((CGRect)highlight, (nfloat)highlight.Height * Slider.Curvaceousness / 2.0f);
            ctx.AddPath(highlightPath.CGPath);
            ctx.SetFillColor( UIColor.FromWhiteAlpha((nfloat)1.0f, (nfloat)0.4f).CGColor);
            ctx.FillPath ();

            // 4) inner shadow
            ctx.SetShadow( new CGSize(0f, 2.0f), 3.0f, UIColor.Gray.CGColor);
            ctx.AddPath (switchOutline.CGPath);
            ctx.SetStrokeColor(UIColor.Gray.CGColor);
            ctx.StrokePath ();

            // 5) outline the track
            ctx.AddPath( switchOutline.CGPath);
            ctx.SetStrokeColor(UIColor.Black.CGColor);
            ctx.SetLineWidth ((nfloat)0.5f);
            ctx.StrokePath ();
        }
 public override void DrawMapRect (MKMapRect mapRect, float zoomScale, CGContext context)
 {
     UIGraphics.PushContext(context);
     
     context.SetLineWidth (4000);    
     
     UIColor.Blue.SetFill();  
     CGPath path = new CGPath ();
     
     RectangleF r = this.RectForMapRect(_overlay.BoundingMapRect());
     PointF _origin = r.Location;
                          
     path.AddLines (new PointF[] { 
         _origin, 
         new PointF (_origin.X + 35000, _origin.Y + 80000),
         new PointF (_origin.X - 50000, _origin.Y + 30000),
         new PointF (_origin.X + 50000, _origin.Y + 30000),
         new PointF (_origin.X - 35000, _origin.Y + 80000) });
              
     context.AddPath (path);
     context.DrawPath (CGPathDrawingMode.Fill);
     
     UIGraphics.PopContext();
 }
        void DrawAddPhotoButton(CGContext ctx)
        {
            UIColor background = pressed ? HighlightedButtonColor : NormalButtonColor;
            RectangleF bounds = PhotoRect;
            float alpha = 1.0f;

            ctx.SaveState ();
            ctx.AddPath (PhotoBorder);
            ctx.Clip ();

            using (var cs = CGColorSpace.CreateDeviceRGB ()) {
                var bottomCenter = new PointF (bounds.GetMidX (), bounds.GetMaxY ());
                var topCenter = new PointF (bounds.GetMidX (), bounds.Y);
                float[] gradColors;
                CGPath container;

                gradColors = new [] { 0.23f, 0.23f, 0.23f, alpha, 0.67f, 0.67f, 0.67f, alpha };
                using (var gradient = new CGGradient (cs, gradColors, new [] { 0.0f, 1.0f })) {
                    ctx.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
                }

                var bg = bounds.Inset (1.0f, 1.0f);
                container = GraphicsUtil.MakeRoundedRectPath (bg, 13.5f);
                ctx.AddPath (container);
                ctx.Clip ();

                background.SetFill ();
                ctx.FillRect (bg);

                gradColors = new [] {
                    0.0f, 0.0f, 0.0f, 0.75f,
                    0.0f, 0.0f, 0.0f, 0.65f,
                    0.0f, 0.0f, 0.0f, 0.35f,
                    0.0f, 0.0f, 0.0f, 0.05f
                };

                using (var gradient = new CGGradient (cs, gradColors, new float [] { 0.0f, 0.1f, 0.4f, 1.0f })) {
                    ctx.DrawLinearGradient (gradient, topCenter, bottomCenter, 0);
                }
            }

            //ctx.AddPath (PhotoBorder);
            //ctx.SetStrokeColor (0.5f, 0.5f, 0.5f, 1.0f);
            //ctx.SetLineWidth (0.5f);
            //ctx.StrokePath ();

            ctx.RestoreState ();
        }
        public override void Draw(RectangleF bounds, CGContext context, UIView view)
        {
            var leftMargin = LeftRightPadding;

            // Superview is the container, its superview the uitableviewcell
            var uiTableViewCell = view.Superview.Superview as UITableViewCell;
            bool highlighted = uiTableViewCell != null && uiTableViewCell.Highlighted & IsTappedAssigned;
            var timeColor = highlighted ? UIColor.White : UIColor.Gray;
            var textColor = highlighted ? UIColor.White : UIColor.FromRGB(41, 41, 41);
            var nameColor = highlighted ? UIColor.White : UIColor.FromRGB(0, 64, 128);

            if (Image != null)
            {
                var imageRect = new RectangleF(LeftRightPadding, TopBottomPadding, 32f, 32f);
                UIColor.White.SetColor ();

                context.SaveState ();
                //context.TranslateCTM (imageRect.X, imageRect.Y);
                context.SetLineWidth (1);

                // On device, the shadow is painted in the opposite direction!
                context.SetShadowWithColor (new SizeF (0, 0), 3, UIColor.DarkGray.CGColor);
                context.AddPath (UIBezierPath.FromRect(imageRect).CGPath);
                context.FillPath ();
                context.RestoreState ();

                Image.Draw(imageRect);
                leftMargin += LeftRightPadding + imageRect.Width + 3f;
            }

            var contentWidth = bounds.Width - LeftRightPadding  - leftMargin;

            var daysAgo = Time.ToDaysAgo();
            timeColor.SetColor();
            var daysWidth = daysAgo.MonoStringLength(DateFont);
            RectangleF timeRect;

            timeRect = Image != null ? new RectangleF(leftMargin, TopBottomPadding + UserFont.LineHeight, daysWidth, DateFont.LineHeight) :
                                       new RectangleF(bounds.Width - LeftRightPadding - daysWidth,  TopBottomPadding + 1f, daysWidth, DateFont.LineHeight);

            view.DrawString(daysAgo, timeRect, DateFont, UILineBreakMode.TailTruncation);

            nameColor.SetColor();
            view.DrawString(Name,
                new RectangleF(leftMargin, TopBottomPadding, contentWidth, UserFont.LineHeight),
                UserFont, UILineBreakMode.TailTruncation
            );

            if (!string.IsNullOrEmpty(String))
            {
                UIColor.Black.SetColor();
                var top = TopBottomPadding + UserFont.LineHeight + 3f;
                if (Image != null)
                    top += DateFont.LineHeight;

                textColor.SetColor();

                if (Image == null)
                {
                    view.DrawString(String,
                                    new RectangleF(LeftRightPadding, top, bounds.Width - LeftRightPadding * 2, bounds.Height - TopBottomPadding - top),
                                    DescFont, UILineBreakMode.TailTruncation
                                    );
                }
                else
                {
                    view.DrawString(String,
                                    new RectangleF(leftMargin, top, contentWidth, bounds.Height - TopBottomPadding - top),
                                    DescFont, UILineBreakMode.TailTruncation
                                    );
                }
            }
        }
Beispiel #41
0
 public static void FillRoundedRect(CGContext ctx, CGRect rect, float radius)
 {
     var p = GraphicsUtil.MakeRoundedRectPath(rect, radius);
     ctx.AddPath(p);
     ctx.FillPath();
 }
Beispiel #42
0
            private void DrawRect(CGContext g, CGRect rect, Thickness borderThickness, Brush borderBrush, Brush fill, CornerRadius cornerRadius)
            {
                var center = new CGPoint(rect.Left + cornerRadius.TopLeft + borderThickness.Left / 2, rect.Top + cornerRadius.TopLeft + borderThickness.Top / 2);
                var strokeColor = borderBrush != null ? borderBrush.ToUIColor(rect.Size).CGColor : UIColor.Black.CGColor;
                g.SetStrokeColor(strokeColor);
                g.SetFillColor(strokeColor);
                List<Arc> innerArcs = new List<Arc>();
                if (cornerRadius.TopLeft != 0)
                {
                    innerArcs.Add(this.DrawArc(g, cornerRadius.TopLeft, center, borderThickness.LeftF(), borderThickness.TopF(), 180f, 270f));
                }
                else
                {
                    innerArcs.Add(new Arc() { Center = center });
                }
                g.BeginPath();
                g.SetLineWidth(borderThickness.TopF());
                g.MoveTo((nfloat)cornerRadius.TopLeft, borderThickness.TopF() / 2);
                g.AddLineToPoint(rect.Right - (nfloat)cornerRadius.TopRight - borderThickness.RightF() / 2, borderThickness.TopF() / 2);
                g.StrokePath();
                center = new CGPoint(rect.Right - cornerRadius.TopRight - borderThickness.Right / 2, rect.Top + cornerRadius.TopRight + borderThickness.Top / 2);
                if (cornerRadius.TopRight != 0)
                {
                    innerArcs.Add(this.DrawArc(g, cornerRadius.TopRight, center, borderThickness.TopF(), borderThickness.RightF(), -90f, 0f));
                }
                else
                {
                    innerArcs.Add(new Arc { Center = center });
                }
                g.BeginPath();
                g.SetLineWidth(borderThickness.RightF());
                g.MoveTo(rect.Right - borderThickness.RightF() / 2, (nfloat)cornerRadius.TopRight);
                g.AddLineToPoint(rect.Right - borderThickness.RightF() / 2, rect.Height - (nfloat)cornerRadius.BottomRight);
                g.StrokePath();
                center = new CGPoint(rect.Right - cornerRadius.BottomRight - borderThickness.Right / 2, rect.Bottom - cornerRadius.BottomRight - borderThickness.Bottom / 2);
                if (cornerRadius.BottomRight != 0)
                {
                    innerArcs.Add(this.DrawArc(g, cornerRadius.BottomRight, center, borderThickness.RightF(), borderThickness.BottomF(), 0f, 90f));
                }
                else
                {
                    innerArcs.Add(new Arc() { Center = center });
                }
                g.BeginPath();
                g.SetLineWidth(borderThickness.BottomF());
                g.MoveTo(rect.Right - (nfloat)cornerRadius.BottomRight, rect.Bottom - borderThickness.BottomF() / 2);
                g.AddLineToPoint(rect.Left + (nfloat)cornerRadius.BottomLeft, rect.Bottom - borderThickness.BottomF() / 2);
                g.StrokePath();
                center = new CGPoint((rect.Left + cornerRadius.BottomLeft + borderThickness.Left / 2), (rect.Bottom - cornerRadius.BottomLeft - borderThickness.Bottom / 2));
                if (cornerRadius.BottomLeft != 0)
                {
                    innerArcs.Add(this.DrawArc(g, cornerRadius.BottomLeft, center, borderThickness.BottomF(), borderThickness.LeftF(), 90f, 180f));
                }
                else
                {
                    innerArcs.Add(new Arc() { Center = center });
                }
                g.SetLineWidth((nfloat)borderThickness.Left);
                g.MoveTo(rect.Left + borderThickness.LeftF() / 2, rect.Bottom - (nfloat)cornerRadius.BottomLeft);
                g.AddLineToPoint(rect.Left + borderThickness.LeftF() / 2, rect.Top + (nfloat)cornerRadius.TopLeft);
                g.StrokePath();
                if (fill != null)
                {
                    var fillColor = fill.ToUIColor(rect.Size).CGColor;
                    g.SetFillColor(fillColor);
                    g.SetLineWidth(0);
                    using (CGPath path = new CGPath())
                    {
                        path.AddArc(
                            innerArcs[0].Center.X,
                            innerArcs[0].Center.Y,
                            innerArcs[0].Radius,
                            innerArcs[0].EndingAngle,
                            innerArcs[0].StartingAngle,
                            false);

                        path.AddArc(
                            innerArcs[1].Center.X,
                            innerArcs[1].Center.Y,
                            innerArcs[1].Radius,
                            innerArcs[1].EndingAngle,
                            innerArcs[1].StartingAngle,
                            false);

                        path.AddArc(
                            innerArcs[2].Center.X,
                            innerArcs[2].Center.Y,
                            innerArcs[2].Radius,
                            innerArcs[2].EndingAngle,
                            innerArcs[2].StartingAngle,
                            false);

                        path.AddArc(
                            innerArcs[3].Center.X,
                            innerArcs[3].Center.Y,
                            innerArcs[3].Radius,
                            innerArcs[3].EndingAngle,
                            innerArcs[3].StartingAngle,
                            false);

                        g.AddPath(path);
                        g.DrawPath(CGPathDrawingMode.Fill);
                    }
                }
            }
        private void DrawLinearGradient(CGContext context, RectangleF rect, CGColor startColor, CGColor  endColor)
        {
            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB ();
            float [] locations = { 0.0f, 1.0f };

            CGColor [] colors = new CGColor[] { startColor, endColor };

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

            PointF startPoint = new PointF (rect.GetMidX (), rect.GetMinY ());
            PointF endPoint = new PointF (rect.GetMidX (), rect.GetMaxY ());

            context.SaveState ();
            context.AddPath (UIBezierPath.FromRoundedRect (rect, 10).CGPath);
            context.Clip ();
            context.DrawLinearGradient (gradient, startPoint, endPoint, 0);
            context.RestoreState ();
        }
        public override void DrawInContext(CGContext ctx)
        {
            base.DrawInContext (ctx);

            var knobFrame = CGRect.Inflate(Bounds, -2.0f, -2.0f);

            UIBezierPath knobPath = UIBezierPath.FromRoundedRect((CGRect)knobFrame, (nfloat)knobFrame.Height / 2.0f);

            // 1) fill - with a subtle shadow
            ctx.SetShadow(new CGSize(0, 1), 1.0f, UIColor.Gray.CGColor);
            ctx.SetFillColor( UIColor.White.CGColor);
            ctx.AddPath( knobPath.CGPath);
            ctx.FillPath ();

            // 2) outline
            ctx.SetStrokeColor(UIColor.Gray.CGColor);
            ctx.SetLineWidth((nfloat)0.5f);
            ctx.AddPath(knobPath.CGPath);
            ctx.StrokePath ();

            // 3) inner gradient
            var rect = CGRect.Inflate(knobFrame, -2.0f, -2.0f);
            var clipPath = UIBezierPath.FromRoundedRect ((CGRect)rect, (nfloat)rect.Height / 2.0f);

            CGGradient myGradient;
            CGColorSpace myColorspace;

            nfloat[] locations = { 0.0f, 1.0f };
            nfloat[] components = { 0.0f, 0.0f, 0.0f , 0.15f,  // Start color
                0.0f, 0.0f, 0.0f, 0.05f }; // End color

            myColorspace = CGColorSpace.CreateDeviceRGB (); // CGColorSpaceCreateDeviceRGB();
            myGradient = new CGGradient( myColorspace, components, locations);

            CGPoint startPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMinY());
            CGPoint endPoint = new CGPoint((float)rect.GetMidX(), (float)rect.GetMaxY());

            ctx.SaveState ();
            ctx.AddPath( clipPath.CGPath);
            ctx.Clip ();
            ctx.DrawLinearGradient( (CGGradient)myGradient, (CGPoint)startPoint, (CGPoint)endPoint, (CGGradientDrawingOptions)0);

            myGradient.Dispose ();
            myColorspace.Dispose();
            ctx.RestoreState();

            // 4) highlight
            if (Highlighted)
            {
                // fill
                ctx.SetFillColor(UIColor.FromWhiteAlpha((nfloat)0.0f, (nfloat)0.1f).CGColor);
                ctx.AddPath( knobPath.CGPath);
                ctx.FillPath();
            }
            //
            //			if (Highlighted)
            //				ctx.SetFillColor (UIColor.Yellow.CGColor);
            //			else
            //				ctx.SetFillColor (UIColor.Red.CGColor);
            //
            //			ctx.FillRect (Bounds);
        }
		private void DrawBorder(CGContext context, CGPath path)
		{
			var separatorColor = Element.Theme.SeparatorColor ?? TableView.SeparatorColor;

		    context.SetLineWidth(1);

			context.SetStrokeColor(separatorColor.CGColor);
			context.SetShadowWithColor(new SizeF(0,0), 0f, UIColor.Clear.CGColor);
			context.AddPath(path);
			context.DrawPath(CGPathDrawingMode.Stroke);

			return;
		}
        void DrawPhoto(CGContext ctx)
        {
            ctx.SaveState ();

            ctx.AddPath (PhotoBorder);
            ctx.Clip ();

            Photograph.Draw (PhotoRect);

            ctx.AddPath (PhotoBorder);
            ctx.SetStrokeColor (0.5f, 0.5f, 0.5f, 1.0f);
            ctx.SetLineWidth (0.5f);
            ctx.StrokePath ();

            ctx.RestoreState ();
        }
 public override void DrawLayer (CALayer layer, CGContext context)
 {   
     context.SetLineWidth (4);
     var path = new CGPath ();
     path.AddLines(new PointF[]{new PointF(0,0), new PointF(100,100), new PointF(100,0)});
     path.CloseSubpath ();
     context.AddPath (path);
     context.DrawPath (CGPathDrawingMode.Stroke);            
 }
Beispiel #48
0
            private Arc DrawArc(CGContext context, double radius, CGPoint center, nfloat startingThickness, nfloat endingThickness, nfloat startingAngle, nfloat endingAngle)
            {
                using (CGPath path = new CGPath())
                {
                    context.SetLineWidth(0);
                    var deltaAngle = MathF.Abs(endingAngle - startingAngle);

                    // projectedEndingThickness is the ending thickness we would have if the two arcs
                    // subtended an angle of 180 degrees at their respective centers instead of deltaAngle
                    var projectedEndingThickness = startingThickness + (endingThickness - startingThickness) * (180.0f / deltaAngle);

                    var centerOffset = (projectedEndingThickness - startingThickness) / 4.0f;
                    var centerForInnerArc = new CGPoint(center.X + centerOffset * Math.Cos(startingAngle * Math.PI / 180.0f),
                        center.Y + centerOffset * Math.Sin(startingAngle * Math.PI / 180.0f));
                    var centerForOuterArc = new CGPoint(center.X - centerOffset * Math.Cos(startingAngle * Math.PI / 180.0f),
                        center.Y - centerOffset * Math.Sin(startingAngle * Math.PI / 180.0f));

                    var radiusForInnerArc = (nfloat)radius - (startingThickness + projectedEndingThickness) / 4;
                    var radiusForOuterArc = (nfloat)radius + (startingThickness + projectedEndingThickness) / 4;

                    path.AddArc(
                        centerForInnerArc.X,
                        centerForInnerArc.Y,
                        radiusForInnerArc,
                        endingAngle * MathF.PI / 180.0f,
                        startingAngle * MathF.PI / 180.0f,
                        true);

                    var arc = new Arc()
                    {
                        Center = centerForInnerArc,
                        Radius = radiusForInnerArc,
                        StartingAngle = endingAngle * MathF.PI / 180.0f,
                        EndingAngle = startingAngle * MathF.PI / 180.0f
                    };

                    path.AddArc(
                        centerForOuterArc.X,
                        centerForOuterArc.Y,
                        radiusForOuterArc,
                        startingAngle * MathF.PI / 180.0f,
                        endingAngle * MathF.PI / 180.0f,
                        false);

                    context.AddPath(path);

                    context.FillPath();

                    return arc;
                }
            }
Beispiel #49
0
 public static void EOFillPath(CGContext context, CGPath path, CGColor color)
 {
     context.SaveState();
     context.SetFillColor(color);
     context.AddPath(path);
     context.EOFillPath();
     context.RestoreState();
 }