Exemple #1
0
            public void Draw(GraphicsHandler graphics, bool stroke, FillMode fillMode, bool clip)
            {
                var outerRadius = Radius.Width;
                var yscale      = Radius.Height / Radius.Width;
                var center      = Center;
                var origin      = GradientOrigin;
                var scale       = 1f;
                var rect        = graphics.Control.GetPathBoundingBox().ToEto();

                if (stroke)
                {
                    graphics.Control.ReplacePathWithStrokedPath();
                }
                if (clip)
                {
                    graphics.Clip(fillMode);
                }

                if (wrap != GradientWrapMode.Pad)
                {
                    // use eto's transformrectangle as it'll make the rect encompass the resulting transformed area
                    var boundRect = transform.Invert().ToEto().TransformRectangle(rect);

                    // find max number of iterations we need to fill the bounding rectangle
                    scale = GradientHelper.GetRadialScale(Center, Radius, GradientOrigin, boundRect);
                }

                if (Gradient == null || scale > lastScale)
                {
                    var stops = GradientHelper.GetGradientStops(StartColor.ToCG(), EndColor.ToCG(), scale, wrap).ToList();
                    lastScale = scale;
                    Gradient  = new CGGradient(CGColorSpace.CreateDeviceRGB(), stops.Select(r => r.Item2).ToArray(), stops.Select(r => (nfloat)r.Item1).ToArray());
                }
                else
                {
                    scale = lastScale;
                }

                var scaledRect = new RectangleF(GradientOrigin - (GradientOrigin - Center + Radius) * scale, GradientOrigin + (Center + Radius - GradientOrigin) * scale);

                center       = scaledRect.Center;
                outerRadius *= scale;

                // adjust center based on ellipse scale from gradient origin
                center.Y = origin.Y - (origin.Y - center.Y) / yscale;

                // scale to draw elliptical gradient
                var t = new CGAffineTransform(1, 0f, 0f, yscale, 0, origin.Y - origin.Y * yscale);

                t.Multiply(transform);

                graphics.Control.SaveState();
                graphics.Control.ConcatCTM(t);
                graphics.Control.DrawRadialGradient(Gradient, origin.ToNS(), 0, center.ToNS(), outerRadius, CGGradientDrawingOptions.DrawsAfterEndLocation | CGGradientDrawingOptions.DrawsBeforeStartLocation);
                graphics.Control.RestoreState();
            }
        // test draw pattern
        private void DrawTexture(CGContext context)
        {
            var destRect = new CGRect(0, 0, textureImage.Width, textureImage.Height);

            //destRect = context.ConvertRectToUserSpace(destRect);

            // [top] [left] main quadrant
            context.ConcatCTM(textureImage.imageTransform);
            context.DrawImage(destRect, variation.NativeCGImage);
            context.ConcatCTM(textureImage.imageTransform.Invert());

            if (wrapMode == WrapMode.TileFlipX || wrapMode == WrapMode.TileFlipXY)
            {
                // [top] right quadrant, flipped by the x axis
                var transform = new CGAffineTransform(-1, 0, 0, 1, 2 * destRect.Width, 0);
                context.ConcatCTM(transform);
                context.ConcatCTM(textureImage.imageTransform);
                context.DrawImage(destRect, variation.NativeCGImage);
                context.ConcatCTM(textureImage.imageTransform.Invert());
                context.ConcatCTM(transform.Invert());
            }

            if (wrapMode == WrapMode.TileFlipY || wrapMode == WrapMode.TileFlipXY)
            {
                // bottom [left] quadrant, flipped by the y axis
                var transform = new CGAffineTransform(1, 0, 0, -1, 0, 2 * destRect.Height);
                context.ConcatCTM(transform);
                context.ConcatCTM(textureImage.imageTransform);
                context.DrawImage(destRect, variation.NativeCGImage);
                context.ConcatCTM(textureImage.imageTransform.Invert());
                context.ConcatCTM(transform.Invert());
            }


            if (wrapMode == WrapMode.TileFlipXY)
            {
                // bottom-right quadrant, flipped by both the y and x axis
                var transform = new CGAffineTransform(-1, 0, 0, -1, 2 * destRect.Width, 2 * destRect.Height);
                context.ConcatCTM(transform);
                context.ConcatCTM(textureImage.imageTransform);
                context.DrawImage(destRect, variation.NativeCGImage);
                context.ConcatCTM(textureImage.imageTransform.Invert());
                context.ConcatCTM(transform.Invert());
            }
        }
Exemple #3
0
 public void Invert()
 {
     transform = transform.Invert();
 }
Exemple #4
0
 public void Invert()
 {
     control = control.Invert();
 }