void DrawPattern(CGContext context)
            {
                var start = new CGPoint(0, 0);
                var end   = start + sectionSize;

                context.ClipToRect(new CGRect(start, tileSize).Inset(-4, -4));

                if (Wrap == GradientWrapMode.Reflect)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        context.DrawLinearGradient(Gradient, start, end, 0);
                        context.DrawLinearGradient(InverseGradient, end, end + sectionSize, 0);
                        start = start + sectionSize + sectionSize;
                        end   = end + sectionSize + sectionSize;
                    }
                }
                else
                {
                    for (int i = 0; i < 2; i++)
                    {
                        context.DrawLinearGradient(Gradient, start, end, 0);
                        start = start + sectionSize;
                        end   = end + sectionSize;
                    }
                }
            }
        public static void Draw(this EllipticalGradient target, CGContext ctx, CGRect bounds)
        {
            target.Update();

            CGRect clippingBounds = bounds;

            if (!target.Frame.IsEmpty)
            {
                bounds = new CGRect(target.Frame.X, target.Frame.Y, target.Frame.Width, target.Frame.Height);
            }

            var gradColors   = GenerateGradientColors(target.Colors);
            var colorSpace   = CGColorSpace.CreateDeviceRGB();
            var grad         = new CGGradient(colorSpace, gradColors, ConvertToNativeArray(target.Locations));
            var gradCenter   = new CGPoint((bounds.Width * target.Center.X), (bounds.Height * target.Center.Y));
            var gradRadius   = (nfloat)Math.Min(bounds.Size.Width / 2, bounds.Size.Height / 2);
            var drawingFlags = GetGradientFlags(target);
            var scaleT       = CGAffineTransform.MakeScale(target.Scale.X, target.Scale.Y);

            ctx.SaveState();
            if (!target.Frame.IsEmpty)
            {
                ctx.ClipToRect(new CGRect(bounds.X + clippingBounds.X, bounds.Y + clippingBounds.Y, clippingBounds.Width, clippingBounds.Height));
            }

            ctx.TranslateCTM(bounds.X + gradCenter.X, bounds.Y + gradCenter.Y);
            ctx.RotateCTM((nfloat)(target.Rotation * (Math.PI / 180)));
            ctx.ScaleCTM(scaleT.xx, scaleT.yy);
            ctx.DrawRadialGradient(grad, CGPoint.Empty, 0, CGPoint.Empty, gradRadius, drawingFlags);
            ctx.RestoreState();

            grad.Dispose();
            colorSpace.Dispose();
        }
Beispiel #3
0
        public static UIImage ScaleImage(this UIImage image, int maxResolution)
        {
            CGSize newSize = new CGSize();

            newSize.Width  = (image.Size.Width > image.Size.Height) ? maxResolution : (int)(maxResolution * 1.0f / image.Size.Height * image.Size.Width);
            newSize.Height = (image.Size.Width < image.Size.Height) ? maxResolution : (int)(maxResolution * 1.0f / image.Size.Width * image.Size.Height);

            //          if (UIScreen.MainScreen.RespondsToSelector (new ObjCRuntime.Selector ("scale"))) {
            //              UIGraphics.BeginImageContextWithOptions (newSize, true, 0.0f);
            //          } else {
            UIGraphics.BeginImageContext(newSize);
            //          }

            UIImage newImage = null;
            CGRect  clipRect = new CGRect(CGPoint.Empty, newSize);

            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                context.ClipToRect(clipRect);
                image.Draw(clipRect);
                newImage = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();
            }

            return(newImage);
        }
            void DrawPattern(CGContext context)
            {
                var start = new sd.PointF(0, 0);
                var end   = start + sectionSize;

                context.ClipToRect(sd.RectangleF.Inflate(new sd.RectangleF(start, tileSize), 4, 4));

                if (Wrap == GradientWrapMode.Reflect)
                {
                    for (int i = 0; i < 2; i++)
                    {
                        context.DrawLinearGradient(Gradient, start, end, 0);
                        context.DrawLinearGradient(InverseGradient, end, end + sectionSize, 0);
                        start = start + sectionSize + sectionSize;
                        end   = end + sectionSize + sectionSize;
                    }
                }
                else
                {
                    for (int i = 0; i < 2; i++)
                    {
                        context.DrawLinearGradient(Gradient, start, end, 0);
                        start = start + sectionSize;
                        end   = end + sectionSize;
                    }
                }
            }
        public static void Draw(this LinearGradient target, CGContext ctx, CGRect bounds)
        {
            target.Update();

            CGRect clippingBounds = bounds;

            if (!target.Frame.IsEmpty)
            {
                bounds = new CGRect(target.Frame.X, target.Frame.Y, target.Frame.Width, target.Frame.Height);
            }

            var gradColors = GenerateGradientColors(target.Colors);
            var colorSpace = CGColorSpace.CreateDeviceRGB();
            var grad       = new CGGradient(colorSpace, gradColors, ConvertToNativeArray(target.Locations));

            var points       = DetermineGradientPoints(target);
            var startPoint   = new CGPoint(points[0] * bounds.Width, points[1] * bounds.Height);
            var endPoint     = new CGPoint(points[2] * bounds.Width, points[3] * bounds.Height);
            var drawingFlags = GetGradientFlags(target);

            ctx.SaveState();

            if (!target.Frame.IsEmpty)
            {
                ctx.ClipToRect(new CGRect(bounds.X + clippingBounds.X, bounds.Y + clippingBounds.Y, clippingBounds.Width, clippingBounds.Height));
            }

            ctx.DrawLinearGradient(grad, startPoint, endPoint, drawingFlags);
            ctx.RestoreState();

            grad.Dispose();
            colorSpace.Dispose();
        }
Beispiel #6
0
        public static UIImage SquareImageAndScaleToSize(this UIImage image, float newSize)
        {
            double  ratio;
            double  delta;
            CGPoint offset;

            //make a new square size, that is the resized imaged width
            CGSize size = new CGSize(newSize, newSize);

            //figure out if the picture is landscape or portrait, then
            //calculate scale factor and offset
            if (image.Size.Width > image.Size.Height)
            {
                ratio  = newSize / image.Size.Width;
                delta  = (ratio * image.Size.Width - ratio * image.Size.Height);
                offset = new CGPoint(delta / 2, 0);
            }
            else
            {
                ratio  = newSize / image.Size.Height;
                delta  = (ratio * image.Size.Height - ratio * image.Size.Width);
                offset = new CGPoint(0, delta / 2);
            }

            //make the final clipping rect based on the calculated values
            //          CGRect clipRect = new CGRect (-offset.X, -offset.Y/8 , (ratio * image.Size.Width) + delta, (ratio * image.Size.Height) + delta * 1.5   );
            CGRect clipRect = new CGRect(-offset.X, 0, (ratio * image.Size.Width) + delta, (ratio * image.Size.Height) + delta * 1.5);

            //start a new context, with scale factor 0.0 so retina displays get
            //high quality image
            //          if (UIScreen.MainScreen.RespondsToSelector (new ObjCRuntime.Selector ("scale"))) {
            //              UIGraphics.BeginImageContextWithOptions (size, true, 0.0f);
            //          } else {
            UIGraphics.BeginImageContext(size);
            //          }

            UIImage newImage = null;

            using (CGContext context = UIGraphics.GetCurrentContext())
            {
                context.ClipToRect(clipRect);
                image.Draw(clipRect);
                newImage = UIGraphics.GetImageFromCurrentImageContext();
                UIGraphics.EndImageContext();
            }

            return(newImage);
        }
Beispiel #7
0
        protected virtual void Draw(CGContext context, IEnumerable <IPointEntry> entries, IEnumerable <IPointEntry> highlightedEntries, IViewPort viewPort, IXAxis xAxis, IYAxis yAxis, PointRenderStyle renderStyle)
        {
            var points = entries
                         ?.Select(t => new
            {
                Point       = GetDrawPosition(t.X, t.Y, viewPort, xAxis, yAxis),
                IsHighlight = highlightedEntries?.Contains(t) ?? false,
                Entry       = t
            })
                         .ToList();

            if (points != null)
            {
                context.SaveState();

                context.ClipToRect(viewPort.ViewPortRect);

                if (renderStyle.LineStyle.ShouldDraw)
                {
                    DrawLine(context, points.Select(t => t.Point).ToList(), renderStyle);
                }

                if (renderStyle.MarkerStyle.ShouldDraw)
                {
                    DrawNotHighlightedMarkers(context, points.Where(t => !t.IsHighlight).Select(t => t.Point).ToList(), renderStyle.MarkerStyle);
                }

                if (renderStyle.HighlightMarkerStyle.ShouldDraw)
                {
                    DrawHighlightedMarkers(context, points.Where(t => t.IsHighlight).Select(t => t.Point).ToList(), renderStyle.HighlightMarkerStyle);
                }

                foreach (var point in points)
                {
                    if (ShouldDraw(point.IsHighlight, renderStyle.TextStyle, renderStyle.HighlightTextStyle))
                    {
                        DrawEntryValue(context, point.Entry, point.Point, point.IsHighlight ? renderStyle.HighlightTextStyle : renderStyle.TextStyle);
                    }
                }

                context.RestoreState();
            }
        }
Beispiel #8
0
 public GraphicsHandler(NSView view)
 {
     this.view      = view;
     this.needsLock = true;
     this.Control   = NSGraphicsContext.FromWindow(view.Window);
     this.context   = this.Control.GraphicsPort;
     context.SaveState();
     context.ClipToRect(view.ConvertRectToView(view.VisibleRect(), null));
     AddObserver(NSView.NSViewFrameDidChangeNotification, delegate(ObserverActionArgs e) {
         var handler      = e.Widget.Handler as GraphicsHandler;
         var innerview    = handler.view;
         var innercontext = handler.Control.GraphicsPort;
         innercontext.RestoreState();
         innercontext.ClipToRect(innerview.ConvertRectToView(innerview.VisibleRect(), null));
         innercontext.SaveState();
     }, view);
     this.Flipped = view.IsFlipped;
     context.InterpolationQuality = CGInterpolationQuality.High;
     context.SetAllowsSubpixelPositioning(false);
 }
Beispiel #9
0
    public override void DrawInContext(CGContext context)
    {
        var imageRect = new CGRect(8, 8, 64, 64);

        // Note: The images are actually drawn upside down because Quartz image drawing expects
        // the coordinate system to have the origin in the lower-left corner, but a UIView
        // puts the origin in the upper-left corner. For the sake of brevity (and because
        // it likely would go unnoticed for the image used) this is not addressed here.
        // For the demonstration of PDF drawing however, it is addressed, as it would definately
        // be noticed, and one method of addressing it is shown there.

        // Draw the image in the upper left corner (0,0) with size 64x64
        context.DrawImage(imageRect, image);

        // Tile the same image across the bottom of the view
        // CGContextDrawTiledImage() will fill the entire clipping area with the image, so to avoid
        // filling the entire view, we'll clip the view to the rect below. This rect extends
        // past the region of the view, but since the view's rectangle has already been applied as a clip
        // to our drawing area, it will be intersected with this rect to form the final clipping area
        context.ClipToRect(new CGRect(0, 80, Bounds.Width, Bounds.Height));

        // The origin of the image rect works similarly to the phase parameter for SetLineDash and
        // SetPatternPhase and specifies where in the coordinate system the "first" image is drawn.
        // The size (previously set to 64x64) specifies the size the image is scaled to before being tiled.
        imageRect.X = 32;
        imageRect.Y = 112;
        context.DrawTiledImage(imageRect, image);

        // Highlight the "first" image from the DrawTiledImage call.
        context.SetFillColor(1, 0, 0, 0.5f);
        context.FillRect(imageRect);

        // And stroke the clipped area
        context.SetLineWidth(3);
        context.SetStrokeColor(1, 0, 0, 1);
        context.StrokeRect(context.GetClipBoundingBox());
    }
	public override void DrawInContext (CGContext context)
	{
		var imageRect = new RectangleF (8, 8, 64, 64);
		
		// Note: The images are actually drawn upside down because Quartz image drawing expects
		// the coordinate system to have the origin in the lower-left corner, but a UIView
		// puts the origin in the upper-left corner. For the sake of brevity (and because
		// it likely would go unnoticed for the image used) this is not addressed here.
		// For the demonstration of PDF drawing however, it is addressed, as it would definately
		// be noticed, and one method of addressing it is shown there.
	
		// Draw the image in the upper left corner (0,0) with size 64x64
		context.DrawImage (imageRect, image);
		
		// Tile the same image across the bottom of the view
		// CGContextDrawTiledImage() will fill the entire clipping area with the image, so to avoid
		// filling the entire view, we'll clip the view to the rect below. This rect extends
		// past the region of the view, but since the view's rectangle has already been applied as a clip
		// to our drawing area, it will be intersected with this rect to form the final clipping area
		context.ClipToRect(new RectangleF (0, 80, Bounds.Width, Bounds.Height));
		
		// The origin of the image rect works similarly to the phase parameter for SetLineDash and
		// SetPatternPhase and specifies where in the coordinate system the "first" image is drawn.
		// The size (previously set to 64x64) specifies the size the image is scaled to before being tiled.
		imageRect.X = 32;
		imageRect.Y = 112;
		context.DrawTiledImage (imageRect, image);
		
		// Highlight the "first" image from the DrawTiledImage call.
		context.SetRGBFillColor (1, 0, 0, 0.5f);
		context.FillRect (imageRect);
		
		// And stroke the clipped area
		context.SetLineWidth (3);
		context.SetRGBStrokeColor (1, 0, 0, 1);
		context.StrokeRect (context.GetClipBoundingBox ());
	}
    public override void DrawInContext(CGContext context)
    {
        // The clipping rects we plan to use, which also defines the location and span of each gradient
        var clips = new RectangleF []
        {
            new RectangleF(10, 30, 60, 90),
            new RectangleF(90, 30, 60, 90),
            new RectangleF(170, 30, 60, 90),
            new RectangleF(250, 30, 60, 90),
            new RectangleF(30, 140, 120, 120),
            new RectangleF(170, 140, 120, 120),
            new RectangleF(30, 280, 120, 120),
            new RectangleF(170, 280, 120, 120),
        };

        // Linear Gradients
        PointF start, end;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[0]);

        // A linear gradient requires only a starting & ending point.
        // The colors of the gradient are linearly interpolated along the line segment connecting these two points
        // A gradient location of 0 means that color is expressed fully at the 'start' point
        // a location of 1 means that color is expressed fully at the 'end' point.
        // The gradient fills outwards perpendicular to the line segment connectiong start & end points
        // (which is why we need to clip the context, or the gradient would fill beyond where we want it to).
        // The gradient options (last) parameter determines what how to fill the clip area that is "before" and "after"
        // the line segment connecting start & end.
        start = demoLGStart(clips[0]);
        end = demoLGEnd(clips[0]);
        context.DrawLinearGradient(gradient, start, end, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[1]);
        start = demoLGStart(clips[1]);
        end = demoLGEnd(clips[1]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[2]);
        start = demoLGStart(clips[2]);
        end = demoLGEnd(clips[2]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[3]);
        start = demoLGStart(clips[3]);
        end = demoLGEnd(clips[3]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Radial Gradients

        float startRadius, endRadius;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[4]);

        // A radial gradient requires a start & end point as well as a start & end radius.
        // Logically a radial gradient is created by linearly interpolating the center, radius and color of each
        // circle using the start and end point for the center, start and end radius for the radius, and the color ramp
        // inherant to the gradient to create a set of stroked circles that fill the area completely.
        // The gradient options specify if this interpolation continues past the start or end points as it does with
        // linear gradients.
        start = end = demoRGCenter(clips[4]);
        startRadius = demoRGInnerRadius(clips[4]);
        endRadius = demoRGOuterRadius(clips[4]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[5]);
        start = end = demoRGCenter(clips[5]);
        startRadius = demoRGInnerRadius(clips[5]);
        endRadius = demoRGOuterRadius(clips[5]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[6]);
        start = end = demoRGCenter(clips[6]);
        startRadius = demoRGInnerRadius(clips[6]);
        endRadius = demoRGOuterRadius(clips[6]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[7]);
        start = end = demoRGCenter(clips[7]);
        startRadius = demoRGInnerRadius(clips[7]);
        endRadius = demoRGOuterRadius(clips[7]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Show the clipping areas
        context.SetLineWidth(2);
        context.SetRGBStrokeColor(1, 0, 0, 1);
        context.AddRects(clips);
        context.StrokePath();
    }
 public void SetClippingRect(float x, float y, float width, float height)
 {
     _c.ClipToRect(new RectangleF(x, y, width, height));
 }
Beispiel #13
0
 partial void IntersectClipImp(RectangleF r)
 {
     context.ClipToRect(r.ToCGRect());
 }
Beispiel #14
0
        /// <summary>
        /// resize and crop to a specific location
        /// </summary>
        public UIImage CropResize(float width, float height, CropPosition position)
        {
            SizeF ImgSize = modifiedImage.Size;

            //
            if (ImgSize.Width < width)
            {
                width = ImgSize.Width;
            }
            if (ImgSize.Height < height)
            {
                height = ImgSize.Height;
            }
            //
            float crop_x = 0;
            float crop_y = 0;

            if (ImgSize.Width / width < ImgSize.Height / height)
            {
                //scad din width
                RatioResizeToWidth(width);
                ImgSize = modifiedImage.Size;
                //compute crop_y
                if (position == CropPosition.Center)
                {
                    crop_y = (ImgSize.Height / 2) - (height / 2);
                }
                if (position == CropPosition.End)
                {
                    crop_y = ImgSize.Height - height;
                }
            }
            else
            {
                //change height
                RatioResizeToHeight(height);
                ImgSize = modifiedImage.Size;
                //calculeaza crop_x
                if (position == CropPosition.Center)
                {
                    crop_x = (ImgSize.Width / 2) - (width / 2);
                }
                if (position == CropPosition.End)
                {
                    crop_x = ImgSize.Width - width;
                }
            }
            //create new contect
            UIGraphics.BeginImageContext(new SizeF(width, height));
            CGContext context = UIGraphics.GetCurrentContext();
            //crops the new context to the desired height and width
            RectangleF clippedRect = new RectangleF(0, 0, width, height);

            context.ClipToRect(clippedRect);
            //draw my image on the context
            RectangleF drawRect = new RectangleF(-crop_x, -crop_y, ImgSize.Width, ImgSize.Height);

            modifiedImage.Draw(drawRect);
            //save the context in modifiedImage
            modifiedImage = UIGraphics.GetImageFromCurrentImageContext();
            //close the context
            UIGraphics.EndImageContext();

            return(modifiedImage);
        }
Beispiel #15
0
        public static UIImage CropResize(UIImage image, float width, float height, CropPosition position)
        {
            UIImage modifiedImage = image;

            SizeF ImgSize = modifiedImage.Size;

            if (ImgSize.Width < width)
            {
                width = ImgSize.Width;
            }

            if (ImgSize.Height < height)
            {
                height = ImgSize.Height;
            }

            float crop_x = 0;
            float crop_y = 0;

            if (ImgSize.Width / width < ImgSize.Height / height)
            {
                var cur_width = modifiedImage.Size.Width;
                if (cur_width > width)
                {
                    var ratio   = width / cur_width;
                    var height2 = modifiedImage.Size.Height * ratio;

                    var beforeResizeWidth = modifiedImage;
                    UIGraphics.BeginImageContext(new SizeF(width, height2));
                    modifiedImage.Draw(new RectangleF(0, 0, width, height2));
                    modifiedImage = UIGraphics.GetImageFromCurrentImageContext();
                    UIGraphics.EndImageContext();
                    beforeResizeWidth.Dispose();
                }

                ImgSize = modifiedImage.Size;

                if (position == CropPosition.Center)
                {
                    crop_y = (ImgSize.Height / 2) - (height / 2);
                }
                if (position == CropPosition.End)
                {
                    crop_y = ImgSize.Height - height;
                }
            }
            else
            {
                var cur_height = modifiedImage.Size.Height;
                if (cur_height > height)
                {
                    var ratio  = height / cur_height;
                    var width2 = modifiedImage.Size.Width * ratio;

                    var beforeResizeHeight = modifiedImage;
                    UIGraphics.BeginImageContext(new SizeF(width2, height));
                    modifiedImage.Draw(new RectangleF(0, 0, width2, height));
                    modifiedImage = UIGraphics.GetImageFromCurrentImageContext();
                    UIGraphics.EndImageContext();
                    beforeResizeHeight.Dispose();
                }

                ImgSize = modifiedImage.Size;

                if (position == CropPosition.Center)
                {
                    crop_x = (ImgSize.Width / 2) - (width / 2);
                }
                if (position == CropPosition.End)
                {
                    crop_x = ImgSize.Width - width;
                }
            }

            var beforeFinal = modifiedImage;

            UIGraphics.BeginImageContext(new SizeF(width, height));
            CGContext  context     = UIGraphics.GetCurrentContext();
            RectangleF clippedRect = new RectangleF(0, 0, width, height);

            context.ClipToRect(clippedRect);
            RectangleF drawRect = new RectangleF(-crop_x, -crop_y, ImgSize.Width, ImgSize.Height);

            modifiedImage.Draw(drawRect);
            modifiedImage = UIGraphics.GetImageFromCurrentImageContext();
            UIGraphics.EndImageContext();
            context.Dispose();
            beforeFinal.Dispose();
            return(modifiedImage);
        }
    public override void DrawInContext(CGContext context)
    {
        // The clipping rects we plan to use, which also defines the location and span of each gradient
        var clips = new RectangleF []
        {
            new RectangleF(10, 30, 60, 90),
            new RectangleF(90, 30, 60, 90),
            new RectangleF(170, 30, 60, 90),
            new RectangleF(250, 30, 60, 90),
            new RectangleF(30, 140, 120, 120),
            new RectangleF(170, 140, 120, 120),
            new RectangleF(30, 280, 120, 120),
            new RectangleF(170, 280, 120, 120),
        };

        // Linear Gradients
        PointF start, end;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[0]);

        // A linear gradient requires only a starting & ending point.
        // The colors of the gradient are linearly interpolated along the line segment connecting these two points
        // A gradient location of 0 means that color is expressed fully at the 'start' point
        // a location of 1 means that color is expressed fully at the 'end' point.
        // The gradient fills outwards perpendicular to the line segment connectiong start & end points
        // (which is why we need to clip the context, or the gradient would fill beyond where we want it to).
        // The gradient options (last) parameter determines what how to fill the clip area that is "before" and "after"
        // the line segment connecting start & end.
        start = demoLGStart(clips[0]);
        end   = demoLGEnd(clips[0]);
        context.DrawLinearGradient(gradient, start, end, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[1]);
        start = demoLGStart(clips[1]);
        end   = demoLGEnd(clips[1]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[2]);
        start = demoLGStart(clips[2]);
        end   = demoLGEnd(clips[2]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[3]);
        start = demoLGStart(clips[3]);
        end   = demoLGEnd(clips[3]);
        context.DrawLinearGradient(gradient, start, end, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Radial Gradients

        float startRadius, endRadius;

        // Clip to area to draw the gradient, and draw it. Since we are clipping, we save the graphics state
        // so that we can revert to the previous larger area.
        context.SaveState();
        context.ClipToRect(clips[4]);

        // A radial gradient requires a start & end point as well as a start & end radius.
        // Logically a radial gradient is created by linearly interpolating the center, radius and color of each
        // circle using the start and end point for the center, start and end radius for the radius, and the color ramp
        // inherant to the gradient to create a set of stroked circles that fill the area completely.
        // The gradient options specify if this interpolation continues past the start or end points as it does with
        // linear gradients.
        start       = end = demoRGCenter(clips[4]);
        startRadius = demoRGInnerRadius(clips[4]);
        endRadius   = demoRGOuterRadius(clips[4]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, 0);
        context.RestoreState();

        // Same as above for each combination of CGGradientDrawingOptions.DrawsBeforeStartLocation & CGGradientDrawingOptions.DrawsAfterEndLocation

        context.SaveState();
        context.ClipToRect(clips[5]);
        start       = end = demoRGCenter(clips[5]);
        startRadius = demoRGInnerRadius(clips[5]);
        endRadius   = demoRGOuterRadius(clips[5]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[6]);
        start       = end = demoRGCenter(clips[6]);
        startRadius = demoRGInnerRadius(clips[6]);
        endRadius   = demoRGOuterRadius(clips[6]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        context.SaveState();
        context.ClipToRect(clips[7]);
        start       = end = demoRGCenter(clips[7]);
        startRadius = demoRGInnerRadius(clips[7]);
        endRadius   = demoRGOuterRadius(clips[7]);
        context.DrawRadialGradient(gradient, start, startRadius, end, endRadius, CGGradientDrawingOptions.DrawsBeforeStartLocation | CGGradientDrawingOptions.DrawsAfterEndLocation);
        context.RestoreState();

        // Show the clipping areas
        context.SetLineWidth(2);
        context.SetRGBStrokeColor(1, 0, 0, 1);
        context.AddRects(clips);
        context.StrokePath();
    }
Beispiel #17
0
 public void SetClippingRect(float x, float y, float width, float height)
 {
     _c.ClipToRect(new NativeRect(x, y, width, height));
 }