Example #1
0
        LinearGradient CreateLinearGradient(LinearGradientBrush linearGradientBrush, RectF pathBounds)
        {
            if (_path == null)
            {
                return(null);
            }

            int[]   colors  = new int[linearGradientBrush.GradientStops.Count];
            float[] offsets = new float[linearGradientBrush.GradientStops.Count];

            for (int index = 0; index < linearGradientBrush.GradientStops.Count; index++)
            {
                colors[index]  = linearGradientBrush.GradientStops[index].Color.ToAndroid();
                offsets[index] = linearGradientBrush.GradientStops[index].Offset;
            }

            Shader.TileMode tilemode = Shader.TileMode.Clamp;

            using (RectF gradientBounds = new RectF(pathBounds))
            {
                return(new
                       LinearGradient(
                           (float)linearGradientBrush.StartPoint.X * gradientBounds.Width() + gradientBounds.Left,
                           (float)linearGradientBrush.StartPoint.Y * gradientBounds.Height() + gradientBounds.Top,
                           (float)linearGradientBrush.EndPoint.X * gradientBounds.Width() + gradientBounds.Left,
                           (float)linearGradientBrush.EndPoint.Y * gradientBounds.Height() + gradientBounds.Top,
                           colors,
                           offsets,
                           tilemode));
            }
        }
Example #2
0
        RadialGradient CreateRadialGradient(RadialGradientBrush radialGradientBrush, RectF pathBounds)
        {
            if (_path == null)
            {
                return(null);
            }

            int    gradientStopsCount = radialGradientBrush.GradientStops.Count;
            AColor centerColor        = gradientStopsCount > 0 ? radialGradientBrush.GradientStops[0].Color.ToAndroid() : Colors.Transparent.ToAndroid();
            AColor edgeColor          = gradientStopsCount > 0 ? radialGradientBrush.GradientStops[gradientStopsCount - 1].Color.ToAndroid() : Colors.Transparent.ToAndroid();

            float[] offsets = new float[radialGradientBrush.GradientStops.Count];

            for (int index = 0; index < radialGradientBrush.GradientStops.Count; index++)
            {
                offsets[index] = radialGradientBrush.GradientStops[index].Offset;
            }

            Shader.TileMode tilemode = Shader.TileMode.Clamp;

            using (RectF gradientBounds = new RectF(pathBounds))
            {
                return(new RadialGradient(
                           (float)radialGradientBrush.Center.X * gradientBounds.Width() + gradientBounds.Left,
                           (float)radialGradientBrush.Center.Y * gradientBounds.Height() + gradientBounds.Top,
                           (float)radialGradientBrush.Radius * Math.Max(gradientBounds.Height(), gradientBounds.Width()),
                           centerColor,
                           edgeColor,
                           tilemode));
            }
        }
Example #3
0
 public StreamItem(Context c, int resid, string line1, string line2, ImageView.ScaleType scaleType, Shader.TileMode tileMode = null)
 {
     Bitmap    = BitmapFactory.DecodeResource(c.Resources, resid);
     Line1     = line1;
     Line2     = line2;
     ScaleType = scaleType;
     TileMode  = tileMode ?? Shader.TileMode.Clamp;
 }
 internal GradientShaderFactory(int[] colors, float[] locations, Shader.TileMode tileMode,
                                GradientMode gradientMode)
 {
     _colors       = colors;
     _locations    = locations;
     _tileMode     = tileMode;
     _gradientMode = gradientMode;
 }
Example #5
0
        public Shader createShader()
        {
            if (this.mShader != null)
            {
                return(this.mShader);
            }

            if (!this.mSVGGradientStopsBuilt)
            {
                this.buildSVGGradientStopsArrays();
            }

            Shader.TileMode tileMode = this.getTileMode();
            if (this.mLinear)
            {
                float x1 = this.mSVGAttributes.getFloatAttribute(SVGConstants.ATTRIBUTE_X1, true, 0f);
                float x2 = this.mSVGAttributes.getFloatAttribute(SVGConstants.ATTRIBUTE_X2, true, 0f);
                float y1 = this.mSVGAttributes.getFloatAttribute(SVGConstants.ATTRIBUTE_Y1, true, 0f);
                float y2 = this.mSVGAttributes.getFloatAttribute(SVGConstants.ATTRIBUTE_Y2, true, 0f);

                this.mShader = new LinearGradient(x1, y1, x2, y2, this.mSVGGradientStopsColors, this.mSVGGradientStopsPositions, tileMode);
            }
            else
            {
                float centerX = this.mSVGAttributes.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_X, true, 0f);
                float centerY = this.mSVGAttributes.getFloatAttribute(SVGConstants.ATTRIBUTE_CENTER_Y, true, 0f);
                float radius  = this.mSVGAttributes.getFloatAttribute(SVGConstants.ATTRIBUTE_RADIUS, true, 0f);

                this.mShader = new RadialGradient(centerX, centerY, radius, this.mSVGGradientStopsColors, this.mSVGGradientStopsPositions, tileMode);
            }
            this.mMatrix = this.getTransform();
            if (this.mMatrix != null)
            {
                this.mShader.SetLocalMatrix(this.mMatrix);
            }

            return(this.mShader);
        }
Example #6
0
 static Shader MakeSweep(RectF r, GradData data, Shader.TileMode tile)
 {
     return(new SweepGradient(
                r.centerX(), r.centerX(), data.Colors, data.Pos));
 }
Example #7
0
 static Shader MakeRadial(RectF r, GradData data, Shader.TileMode tile)
 {
     return(new RadialGradient(
                r.centerX(), r.centerY(), r.centerX(), data.Colors, data.Pos, tile));
 }
Example #8
0
 static Shader MakeLinear(RectF r, GradData data, Shader.TileMode tile)
 {
     return(new LinearGradient(
                r.left, r.top, r.right, r.bottom, data.Colors, data.Pos, tile));
 }