Beispiel #1
0
        void DrawElement(Func <Rect> add, Pen pen = null, Brush brush = null)
        {
            if (pen == null && brush == null)
            {
                return;
            }

            var lgb = brush as LinearGradientBrush;

            if (lgb != null)
            {
                var cg = CreateGradient(lgb.Stops);
                context.SaveState();
                var frame = add();
                context.Clip();
                CGGradientDrawingOptions options = CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation;
                var size  = frame.Size;
                var start = Conversions.GetCGPoint(lgb.Absolute ? lgb.Start : frame.Position + lgb.Start * size);
                var end   = Conversions.GetCGPoint(lgb.Absolute ? lgb.End : frame.Position + lgb.End * size);
                context.DrawLinearGradient(cg, start, end, options);
                context.RestoreState();
                brush = null;
            }

            var rgb = brush as RadialGradientBrush;

            if (rgb != null)
            {
                var cg = CreateGradient(rgb.Stops);
                context.SaveState();
                var frame = add();
                context.Clip();
                CGGradientDrawingOptions options = CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation;
                var size  = frame.Size;
                var start = Conversions.GetCGPoint(rgb.GetAbsoluteCenter(frame));
                var r     = (nfloat)rgb.GetAbsoluteRadius(frame).Max;
                var end   = Conversions.GetCGPoint(rgb.GetAbsoluteFocus(frame));
                context.DrawRadialGradient(cg, start, 0, end, r, options);
                context.RestoreState();
                brush = null;
            }

            if (pen != null || brush != null)
            {
                var mode = SetPenAndBrush(pen, brush);

                add();
                context.DrawPath(mode);
            }
        }
Beispiel #2
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 #3
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();
            }
        }
Beispiel #4
0
        private static void DrawSeparator(CGContext canvas, nfloat pos, nfloat separatorWidth, nfloat startY, nfloat restY, UIColor color1)
        {
            canvas.SaveState();
            canvas.SetLineWidth(0);

            var path = new CGPath();

            //path.AddLines(points.ToArray());
            path.AddLines(new[] { new CGPoint(pos, startY), new CGPoint(pos, startY + restY), new CGPoint(pos + separatorWidth, startY + restY), new CGPoint(pos + separatorWidth, startY) });
            path.CloseSubpath();
            canvas.AddPath(path);

            //canvas.FillRect(new CGRect(pos, startY, separatorWidth, restY));
            canvas.Clip();

            using (var rgb = CGColorSpace.CreateDeviceRGB())
            {
                var gradient = new CGGradient(rgb, new[]
                {
                    new CGColor(color1.CGColor, 0.25f),
                    new CGColor(color1.CGColor, 0.5f)
                });

                canvas.DrawLinearGradient(gradient,
                                          //new CGPoint(path.BoundingBox.Left, path.BoundingBox.Top),
                                          //new CGPoint(path.BoundingBox.Right, path.BoundingBox.Bottom),
                                          new CGPoint(0, startY),
                                          new CGPoint(0, startY + restY),
                                          CGGradientDrawingOptions.DrawsBeforeStartLocation);
            }

            canvas.RestoreState();
        }
Beispiel #5
0
		void DrawBorder(CGContext ctx)
		{
			if (_strokeThickness == 0)
				return;

			if (IsBorderDashed())
				ctx.SetLineDash(_strokeDashOffset * _strokeThickness, _strokeDash);

			ctx.SetLineWidth(_strokeThickness);

			ctx.SetLineCap(_strokeLineCap);
			ctx.SetLineJoin(_strokeLineJoin);
			ctx.SetMiterLimit(_strokeMiterLimit * _strokeThickness / 4);

			var clipPath = GetClipPath();

			if (clipPath! != null!)
				ctx.AddPath(clipPath);

			if (_stroke != null)
			{
				ctx.ReplacePathWithStrokedPath();
				ctx.Clip();

				DrawGradientPaint(ctx, _stroke);
			}
			else if (_strokeColor != null)
			{
				ctx.SetStrokeColor(_strokeColor.CGColor);
				ctx.DrawPath(CGPathDrawingMode.Stroke);
			}
		}
        public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect)
        {
            var       cb  = (CGContextBackend)backend;
            CGContext ctx = cb.Context;

            // Add the styles that have been globaly set to the context
            img.Styles = img.Styles.AddRange(cb.Styles);

            ctx.SaveState();
            ctx.SetAlpha((float)img.Alpha);

            double rx = destRect.Width / srcRect.Width;
            double ry = destRect.Height / srcRect.Height;

            ctx.AddRect(new CGRect((nfloat)destRect.X, (nfloat)destRect.Y, (nfloat)destRect.Width, (nfloat)destRect.Height));
            ctx.Clip();
            ctx.TranslateCTM((float)(destRect.X - (srcRect.X * rx)), (float)(destRect.Y - (srcRect.Y * ry)));
            ctx.ScaleCTM((float)rx, (float)ry);

            NSImage image = (NSImage)img.Backend;

            if (image is CustomImage)
            {
                ((CustomImage)image).DrawInContext((CGContextBackend)backend, img);
            }
            else
            {
                var size = new CGSize((nfloat)img.Size.Width, (nfloat)img.Size.Height);
                var rr   = new CGRect(0, 0, size.Width, size.Height);
                ctx.ScaleCTM(1f, -1f);
                ctx.DrawImage(new CGRect(0, -size.Height, size.Width, size.Height), image.AsCGImage(ref rr, NSGraphicsContext.CurrentContext, null));
            }

            ctx.RestoreState();
        }
Beispiel #7
0
        private void DrawBorder(CGContext ctx)
        {
            if (!HasBorder())
            {
                return;
            }

            if (IsBorderDashed())
            {
                ctx.SetLineDash(0, new [] { (nfloat)_dashWidth, (nfloat)_dashGap });
            }

            // Stroke is inner, the outer will be clipped. So double the value to get the real one!
            ctx.SetLineWidth(2 * _strokeWidth);
            ctx.AddPath(GetRoundCornersPath(Bounds).CGPath);

            if (HasBorderGradient())
            {
                ctx.ReplacePathWithStrokedPath();
                ctx.Clip();

                var startPoint = new CGPoint(_strokePositions[0] * Bounds.Width, _strokePositions[1] * Bounds.Height);
                var endPoint   = new CGPoint(_strokePositions[2] * Bounds.Width, _strokePositions[3] * Bounds.Height);

                var gradient = new CGGradient(CGColorSpace.CreateDeviceRGB(), _strokeColors, _strokeColorPositions);

                ctx.DrawLinearGradient(gradient, startPoint, endPoint, CGGradientDrawingOptions.None);
            }
            else if (_strokeColor != null)
            {
                ctx.SetStrokeColor(_strokeColor.CGColor);
                ctx.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Beispiel #8
0
        public override void DrawImage(object backend, ImageDescription img, Rectangle srcRect, Rectangle destRect)
        {
            CGContext ctx   = ((CGContextBackend)backend).Context;
            NSImage   image = img.ToNSImage();

            ctx.SaveState();
            ctx.SetAlpha((float)img.Alpha);

            double rx = destRect.Width / srcRect.Width;
            double ry = destRect.Height / srcRect.Height;

            ctx.AddRect(new RectangleF((float)destRect.X, (float)destRect.Y, (float)destRect.Width, (float)destRect.Height));
            ctx.Clip();
            ctx.TranslateCTM((float)(destRect.X - (srcRect.X * rx)), (float)(destRect.Y - (srcRect.Y * ry)));
            ctx.ScaleCTM((float)rx, (float)ry);

            if (image is CustomImage)
            {
                ((CustomImage)image).DrawInContext((CGContextBackend)backend);
            }
            else
            {
                RectangleF rr = new RectangleF(0, 0, (float)image.Size.Width, image.Size.Height);
                ctx.ScaleCTM(1f, -1f);
                ctx.DrawImage(new RectangleF(0, -image.Size.Height, image.Size.Width, image.Size.Height), image.AsCGImage(ref rr, NSGraphicsContext.CurrentContext, null));
            }

            ctx.RestoreState();
        }
        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();
        }
Beispiel #10
0
        private void DrawBorder(CGContext ctx)
        {
            if (!HasBorder())
            {
                return;
            }

            if (IsBorderDashed())
            {
                ctx.SetLineDash(0, new [] { (nfloat)_dashWidth, (nfloat)_dashGap });
            }

            // Stroke is inner, the outer will be clipped. So double the value to get the real one!
            ctx.SetLineWidth(2 * _strokeWidth);
            ctx.AddPath(GetClipPath());

            if (_strokeGradientProvider != null && _strokeGradientProvider.HasGradient)
            {
                ctx.ReplacePathWithStrokedPath();
                ctx.Clip();

                _strokeGradientProvider.DrawGradient(ctx, Bounds);
            }
            else if (_strokeColor != null)
            {
                ctx.SetStrokeColor(_strokeColor.CGColor);
                ctx.DrawPath(CGPathDrawingMode.Stroke);
            }
        }
Beispiel #11
0
        void FillPathWithGradient()
        {
            var gr = new CGGradient(CGColorSpace.CreateDeviceRGB(), _g.Colors.Select(c => c.GetCGColor()).ToArray(), _g.Locations.Select(g => (NativeValue)g).ToArray());

            _c.SaveState();
            _c.Clip();
            _c.DrawLinearGradient(gr, _g.Start.ToPointF(), _g.End.ToPointF(), CGGradientDrawingOptions.DrawsAfterEndLocation | CGGradientDrawingOptions.DrawsBeforeStartLocation);
            _c.RestoreState();
        }
Beispiel #12
0
        public override void ClipPreserve(object backend)
        {
            CGContext ctx = ((CGContextBackend)backend).Context;

            using (CGPath oldPath = ctx.CopyPath()) {
                ctx.Clip();
                ctx.AddPath(oldPath);
            }
        }
Beispiel #13
0
 public static void FillRect(CGContext context, RectangleF rect, CGColor color)
 {
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     context.SetFillColor(color);
     context.FillRect(rect);
     context.RestoreState();
 }
Beispiel #14
0
        public override void DrawInContext(CGContext context)
        {
            var progressAngle = CalculateProgressAngle(Percentage);

            using (var path = BezierPathGenerator.Bagel(CenterPoint, startRadius, endRadius, 0f, progressAngle)) {
                context.AddPath(path.CGPath);
                context.Clip();
                context.DrawImage(Bounds, fullProgressImage.CGImage);
            }
        }
Beispiel #15
0
        public override void DrawInContext(CGContext ctx)
        {
            base.DrawInContext(ctx);

            ctx.AddPath(GetRoundCornersPath(Bounds).CGPath);
            ctx.Clip();

            DrawGradient(ctx);
            DrawBorder(ctx);
        }
Beispiel #16
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 #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 static UIImage ScaleToSize(UIImage image, int width, int height)
        {
            UIGraphics.BeginImageContext(new SizeF(width, height));
            CGContext ctx   = UIGraphics.GetCurrentContext();
            float     ratio = (float)width / (float)height;

            ctx.AddRect(new RectangleF(0.0f, 0.0f, width, height));
            ctx.Clip();

            var   cg = image.CGImage;
            float h  = cg.Height;
            float w  = cg.Width;
            float ar = w / h;

            if (ar != ratio)
            {
                // Image's aspect ratio is wrong so we'll need to crop
                float  scaleY = height / h;
                float  scaleX = width / w;
                PointF offset;
                SizeF  crop;
                float  size;

                if (scaleX >= scaleY)
                {
                    size   = h * (w / width);
                    offset = new PointF(0.0f, h / 2.0f - size / 2.0f);
                    crop   = new SizeF(w, size);
                }
                else
                {
                    size   = w * (h / height);
                    offset = new PointF(w / 2.0f - size / 2.0f, 0.0f);
                    crop   = new SizeF(size, h);
                }

                ctx.ScaleCTM(1.0f, -1.0f);
                using (var copy = cg.WithImageInRect(new RectangleF(offset, crop))) {
                    ctx.DrawImage(new RectangleF(0.0f, 0.0f, width, -height), copy);
                }
            }
            else
            {
                image.Draw(new RectangleF(0.0f, 0.0f, width, height));
            }

            UIImage scaled = UIGraphics.GetImageFromCurrentImageContext();

            UIGraphics.EndImageContext();

            return(scaled);
        }
Beispiel #19
0
        public override void DrawInteriorWithFrame(CGRect cellFrame, NSView inView)
        {
            CGContext ctx = NSGraphicsContext.CurrentContext.GraphicsPort;

            ctx.SaveState();
            ctx.AddRect(cellFrame);
            ctx.Clip();
            foreach (CellPos cp in GetCells(cellFrame))
            {
                cp.Cell.DrawInteriorWithFrame(cp.Frame, inView);
            }
            ctx.RestoreState();
        }
Beispiel #20
0
		public override void DrawInContext(CGContext ctx)
		{
			base.DrawInContext(ctx);

			var clipPath = GetClipPath();

			if (clipPath! != null!)
				ctx.AddPath(clipPath);

			ctx.Clip();

			DrawBackground(ctx);
			DrawBorder(ctx);
		}
        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 #22
0
        public override void DrawInContext(CGContext ctx)
        {
            base.DrawInContext(ctx);

            _shadowLayer.ShadowPath = GetClipPath();

            ctx.AddPath(GetClipPath());
            ctx.Clip();

            DrawGradient(ctx);
            DrawBorder(ctx);

            _dirty = false;
        }
        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 #24
0
            public override void Draw(CGRect rect)
            {
                base.Draw(rect);

                using (CGContext context = UIGraphics.GetCurrentContext())
                {
                    context.AddRect(new CGRect(0, 0, Frame.Width, 1));
                    context.Clip();

                    UIColor color = Rock.Mobile.UI.Util.GetUIColor(0x777777FF);

                    // probably should change this to not being a gradient
                    CGGradient gradiant = new CGGradient(CGColorSpace.CreateDeviceRGB(), new CGColor[] { color.CGColor, color.CGColor });
                    context.DrawLinearGradient(gradiant, new CGPoint(0, 0), new CGPoint(Frame.Width, 0), CGGradientDrawingOptions.DrawsBeforeStartLocation);
                }
            }
Beispiel #25
0
        public static void DrawRoundRect(this CGContext cr, CGGradient gradient, CGRect rect, float[] cornerRadii, float angle = (float)-Math.PI / 2.0f)
        {
            cr.SaveState();

            RoundRectPath(cr, rect, cornerRadii);

            cr.Clip();
            CGPoint startg = RectIntersect(angle, rect);
            CGPoint endg   = RectIntersect(angle + (float)Math.PI, rect);

            cr.DrawLinearGradient(gradient, startg, endg, 0);
            gradient.Dispose();


            cr.RestoreState();
        }
Beispiel #26
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 #27
0
 internal static void Draw(CGContext ctx, GradientInfo gradient)
 {
     ctx.SaveState();
     ctx.Clip();
     using (var cg = new CGGradient(Util.DeviceRGBColorSpace, gradient.Colors.ToArray(), gradient.Stops.ToArray())) {
         if (gradient.Linear)
         {
             ctx.DrawLinearGradient(cg, gradient.Start, gradient.End, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
         }
         else
         {
             ctx.DrawRadialGradient(cg, gradient.Start, gradient.StartRadius, gradient.End, gradient.EndRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
         }
     }
     ctx.RestoreState();
 }
Beispiel #28
0
        public void DrawContentView()
        {
            if (!Highlighted)
            {
                var borderRect = Bounds;

                var innerRect = CalculateInnerRect();

                CGPath path = null;

                var backgroundColor = TableView.BackgroundColor;

                CGContext context = UIGraphics.GetCurrentContext();
                context.SaveState();


                context.SetFillColorWithColor(backgroundColor.CGColor);

                if (TableView.Style == UITableViewStyle.Grouped)
                {
                    borderRect = CalculateInnerRect();
                    path       = GetCellBorderPath(borderRect);
                }
                else
                {
                    path = new CGPath();
                    path.AddRect(borderRect);
                }

                context.AddPath(path);
                context.Clip();

                ShouldDrawBorder = false;

                if (Element.Theme.DrawContentViewAction != null)
                {
                    Element.Theme.DrawContentViewAction(innerRect, context, this);
                }

                context.RestoreState();

                if (ShouldDrawBorder)
                {
                    DrawBorder(context, path);
                }
            }
        }
        public override void DrawInContext(CGContext ctx)
        {
            nfloat       cornerRadius  = Bounds.Height * Slider.Curvaceousness / 2;
            UIBezierPath switchOutline = UIBezierPath.FromRoundedRect(Bounds, cornerRadius);

            ctx.AddPath(switchOutline.CGPath);
            ctx.Clip();

            ctx.SetFillColor(Slider.TrackColor.CGColor);
            ctx.AddPath(switchOutline.CGPath);
            ctx.FillPath();

            ctx.AddPath(switchOutline.CGPath);
            ctx.SetStrokeColor(UIColor.Gray.CGColor);
            ctx.SetLineWidth(0.5f);
            ctx.StrokePath();
        }
Beispiel #30
0
        public override void Draw(CGRect rect)
        {
            // Load image
            UIImage image = new UIImage("logo.png");
            // Get drawing context
            CGContext ctx = UIGraphics.GetCurrentContext();
            // get view bounds
            CGRect bounds = this.Bounds;
            // Find the center of view
            CGPoint center = new CGPoint();

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

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

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

            CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();

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

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

            ctx.DrawLinearGradient(gradient, new CGPoint(bounds.Width / 2, 0), new CGPoint(bounds.Width / 2, bounds.Height / 2), 0);
        }
        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 / 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 ();
        }
        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 ();
        }
        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 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 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 ();
        }
Beispiel #38
0
 public static void FillGradient(CGContext context, RectangleF rect, CGColor color1, CGColor color2)
 {
     CGGradient gradientBackground;
     CGColorSpace colorSpace = CGColorSpace.CreateDeviceRGB();
     
     float[] locationListBackground = new float[] { 1.0f, 0.0f };
     List<float> colorListBackground = new List<float>();
     colorListBackground.AddRange(color1.Components);
     colorListBackground.AddRange(color2.Components);
     gradientBackground = new CGGradient(colorSpace, colorListBackground.ToArray(), locationListBackground);
     
     context.SaveState();
     context.AddRect(rect);
     context.Clip();
     //context.ScaleCTM(1, -1);
     context.DrawLinearGradient(gradientBackground, new PointF(rect.X, rect.Y), new PointF(rect.X + rect.Width, rect.Y + rect.Height), CGGradientDrawingOptions.DrawsBeforeStartLocation);
     context.RestoreState();
 }       
        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 #40
0
        private void DrawShine(CGContext context, RectangleF rect)
        {
            context.SaveState ();

            context.BeginPath ();
            var maxY = MakePath (context, rect);
            context.Clip ();

            /*var locations = new float[] { 0.0f, 0.5f };
            var components = new float[] { 0.92f, 0.92f, 0.92f, 1.0f, 0.82f, 0.82f, 0.82f, 0.4f };*/

            var locations = new float[] { 0f, 0.4f, 0.5f, 0.5f, 0.6f, 1.0f };
            var colors = new UIColor[] {
                UIColor.FromWhiteAlpha (1.0f, 0.885f),
                UIColor.FromWhiteAlpha (1.0f, 0.45f),
                UIColor.FromWhiteAlpha (1.0f, 0.23f),
                UIColor.FromWhiteAlpha (1.0f, 0.10f),
                UIColor.FromRGBA (0f, 0f, 0f, 0.13f),
                UIColor.FromRGBA (0f, 0f, 0f, 0.13f)
            };
            var components = GetComponents (colors);

            var darkLoc = new float[] { 0.5f, 1.0f };
            var darkComp = new float[] { 0.08f, 0.08f, 0.08f, 0.6f, 0.18f, 0.18f, 0.18f, 0.2f };

            using (var cspace = CGColorSpace.CreateDeviceRGB ())
            using (var darkGrad = new CGGradient (cspace, darkComp, darkLoc))
            using (var gradient = new CGGradient (cspace, components, locations)) {

                PointF sPoint = new PointF (0f, 0f),
                    ePoint = new PointF (0f, maxY);
                context.DrawLinearGradient (gradient, sPoint, ePoint, 0);
            }

            context.RestoreState ();
        }