Exemplo n.º 1
0
 public void setShader()
 {
     if (!parameters.Directional)
     {
         shader.SetTechnique("Billboard");
     }
     else
     {
         shader.SetTechnique("DirectionalBillboard");
         shader.Effect.GetVariableByName("startPosition").AsVector().Set(parameters.position);
     }
     shader.Effect.GetVariableByName("world").AsMatrix().SetMatrix(Matrix.Identity);
     shader.Effect.GetVariableByName("viewProjection").AsMatrix().SetMatrix(Matrix.Identity);
     shader.Effect.GetVariableByName("viewInverse").AsMatrix().SetMatrix(Matrix.Identity);
     shader.Effect.GetVariableByName("txDiffuse").AsResource().SetResource(texturePool.LoadTexture(parameters.texture));
     shader.Effect.GetVariableByName("size").AsScalar().Set(parameters.size);
     //effect parameter
     shader.Effect.GetVariableByName("timeTexture").AsResource().SetResource(timeTextureRSV);
     shader.Effect.GetVariableByName("width").AsScalar().Set(parameters.particleWidth);
     shader.Effect.GetVariableByName("height").AsScalar().Set(parameters.particleHeight);
     shader.Effect.GetVariableByName("widthEnd").AsScalar().Set(parameters.particleWidthEnd);
     shader.Effect.GetVariableByName("heightEnd").AsScalar().Set(parameters.particleHeightEnd);
     shader.Effect.GetVariableByName("startColor").AsVector().Set(new Color4(StartColor.ToVector3() * parameters.darkScale));
     shader.Effect.GetVariableByName("endColor").AsVector().Set(new Color4(EndColor.ToVector3() * parameters.darkScale));
     shader.Effect.GetVariableByName("oneOverTotalLifeTime").AsScalar().Set(1 / (parameters.MaxLifeTime));
     shader.Effect.GetVariableByName("uvStart").AsVector().Set(parameters.UvStart);
     shader.Effect.GetVariableByName("uvSize").AsVector().Set(parameters.UvSize);
     shader.Apply();
 }
Exemplo n.º 2
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);

            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            if (StartColor != Color.Transparent || EndColor != Color.Transparent)
            {
                var     colors     = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() };
                SKPoint startPoint = new SKPoint(0, 0);
                SKPoint endPoint   = Horizontal ? new SKPoint(info.Width, 0) : new SKPoint(0, info.Height);

                var shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp);

                SKPaint paint = new SKPaint
                {
                    Style  = SKPaintStyle.Fill,
                    Shader = shader
                };

                canvas.DrawRect(new SKRect(0, 0, info.Width, info.Height), paint);
            }
        }
 protected override SKShader CreateGradientShader(SKImageInfo info)
 {
     return(SKShader.CreateLinearGradient(
                new SKPoint(0, info.Height / 2),
                new SKPoint(info.Width / 2, info.Height / 2),
                new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() },
                new float[] { 0, 0.5f },
                SKShaderTileMode.Mirror));
 }
Exemplo n.º 4
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)
        {
            global::Android.Graphics.LinearGradient gradient;

            var colors = new int[]
            {
                StartColor.ToAndroid().ToArgb(),
                EndColor.ToAndroid().ToArgb()
            };

            switch (Direction)
            {
            default:
            case GradientDirection.ToRight:
                gradient = new global::Android.Graphics.LinearGradient(0, 0, Width, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToLeft:
                gradient = new global::Android.Graphics.LinearGradient(Width, 0, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToTop:
                gradient = new global::Android.Graphics.LinearGradient(0, Height, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToBottom:
                gradient = new global::Android.Graphics.LinearGradient(0, 0, 0, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToTopLeft:
                gradient = new global::Android.Graphics.LinearGradient(Width, Height, 0, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToTopRight:
                gradient = new global::Android.Graphics.LinearGradient(0, Height, Width, 0, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToBottomLeft:
                gradient = new global::Android.Graphics.LinearGradient(Width, 0, 0, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;

            case GradientDirection.ToBottomRight:
                gradient = new global::Android.Graphics.LinearGradient(0, 0, Width, Height, colors, null, global::Android.Graphics.Shader.TileMode.Mirror);
                break;
            }

            var paint = new global::Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);

            base.DispatchDraw(canvas);
        }
Exemplo n.º 5
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();
            }
Exemplo n.º 6
0
 /// <summary>
 /// Gets a hash-code for this object based on current values.
 /// </summary>
 public override int GetHashCode()
 {
     return
         ((StartColor != null ? StartColor.GetHashCode() : 0) ^
          (EndColor != null ? EndColor.GetHashCode() : 0) ^
          (Texture != null ? Texture.GetHashCode() : 0) ^
          Angle.GetHashCode() ^
          Scale.GetHashCode() ^
          WrapMode.GetHashCode() ^
          BrushType.GetHashCode());
 }
Exemplo n.º 7
0
        protected override MutableObject Mutate(MutableObject mutable)
        {
            var newGradient = new ColorGradient(2);

            newGradient.ColorKeys[0] = new GradientColorKey(StartColor.GetFirstValue(mutable), 0);
            newGradient.ColorKeys[1] = new GradientColorKey(EndColor.GetFirstValue(mutable), 1);

            GradientTarget.SetValue(newGradient, mutable);

            return(mutable);
        }
Exemplo n.º 8
0
        public override void StartKinetic(VisualPayload payload, Func <float, float> translateTime)
        {
            var startColor = StartColor.GetFirstValue(payload.Data);
            var endColor   = EndColor.GetFirstValue(payload.Data);

            var transitionTimeInverse = 1f / TransitionTime.GetFirstValue(payload.Data);
            var startTime             = Time.time;


            var colorSatellite =
                payload.VisualData.Bound.gameObject.AddComponent <BoundMovementSatellite>();

            var newPayload = new VisualPayload(payload.Data, new VisualDescription(payload.VisualData.Bound));

            var materialsList =
                payload.VisualData.Bound.GetComponentsInChildren <Renderer>().Select(rend => rend.material).ToList();

            colorSatellite.MovementFunc = (trans) =>
            {
                float proportion = (Time.time - startTime) * transitionTimeInverse;

                if (proportion >= 1f)
                {
                    foreach (var mat in materialsList)
                    {
                        mat.color = endColor;
                    }

                    colorSatellite.Cleanup();
                    return;
                }

                proportion = translateTime(proportion);

                var toColor = Color.Lerp(startColor, endColor, proportion);

                foreach (var mat in materialsList)
                {
                    mat.color = toColor;
                }
            };

            colorSatellite.CleanupFunc = (trans) =>
            {
                JobManager.Instance.StartJob(
                    Finished.Transmit(newPayload), jobName: "Kinetic Finished", startImmediately: true,
                    maxExecutionsPerFrame: 1);
            };

            // execute first step immediately to set initial position
            colorSatellite.MovementFunc(colorSatellite.transform);
        }
Exemplo n.º 9
0
 protected override void DumpBody(XmlWriter writer, SwfTagCode shapeType)
 {
     if (SwfShape.IsMorph(shapeType))
     {
         writer.WriteAttributeString("begin-color", Color.ToHtmlHex());
         writer.WriteAttributeString("end-color", EndColor.ToHtmlHex());
     }
     else
     {
         bool hasAlpha = SwfShape.HasAlpha(shapeType);
         writer.WriteAttributeString("color", Color.ToHtmlHex(hasAlpha));
     }
 }
Exemplo n.º 10
0
        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            var gradient = new Android.Graphics.LinearGradient(0, 0, 0, Height,
                                                               StartColor.ToAndroid(),
                                                               EndColor.ToAndroid(),
                                                               Android.Graphics.Shader.TileMode.Mirror);

            var paint = new Android.Graphics.Paint()
            {
                Dither = true,
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Exemplo n.º 11
0
        public void Dump(XmlWriter writer, SwfTagCode shapeType)
        {
            writer.WriteStartElement("line-style");
            writer.WriteAttributeString("width", Width.ToString());
            if (shapeType == SwfTagCode.DefineMorphShape)
            {
                writer.WriteAttributeString("end-width", EndWidth.ToString());
                writer.WriteAttributeString("color", Color.ToHtmlHex());
                writer.WriteAttributeString("end-color", EndColor.ToHtmlHex());
            }
            else if (shapeType == SwfTagCode.DefineShape4 || shapeType == SwfTagCode.DefineMorphShape2)
            {
                bool isMorph = shapeType == SwfTagCode.DefineMorphShape2;
                if (isMorph)
                {
                    writer.WriteAttributeString("end-width", EndWidth.ToString());
                }

                writer.WriteAttributeString("start-cap", StartCapStyle.ToString());
                writer.WriteAttributeString("end-cap", EndCapStyle.ToString());
                writer.WriteAttributeString("flags", Flags.ToString());

                if (JoinStyle == SwfJoinStyle.Miter)
                {
                    writer.WriteAttributeString("miter-limit", MiterLimit.ToString());
                }

                if (Fill != null)
                {
                    Fill.Dump(writer, shapeType);
                }
                else
                {
                    writer.WriteAttributeString("color", Color.ToHtmlHex());
                    if (isMorph)
                    {
                        writer.WriteAttributeString("end-color", EndColor.ToHtmlHex());
                    }
                }
            }
            else
            {
                writer.WriteAttributeString("color", Color.ToHtmlHex(shapeType == SwfTagCode.DefineShape3));
            }
            writer.WriteEndElement();
        }
Exemplo n.º 12
0
            public sd2.PathGradientBrush GetBrush(RectangleF rect)
            {
                var scale  = 1f;
                var bounds = rect;

                if (Matrix != null)
                {
                    bounds = Matrix.Inverse().TransformRectangle(bounds);
                }

                scale = GradientHelper.GetRadialScale(Center, Radius, GradientOrigin, bounds);

                if (brush == null || lastScale != scale)
                {
                    lastScale = scale;

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

                    var path = new sd2.GraphicsPath();
                    path.AddEllipse(scaledRect.ToSD());

                    brush                = new sd2.PathGradientBrush(path);
                    brush.CenterColor    = StartColor.ToSD();
                    brush.CenterPoint    = GradientOrigin.ToSD();
                    brush.WrapMode       = wrapMode.ToSD();
                    brush.SurroundColors = new[] { EndColor.ToSD() };

                    if (Matrix != null)
                    {
                        brush.MultiplyTransform(Matrix.ToSD());
                    }

                    if (scale > 1f)
                    {
                        var paths = GradientHelper.GetGradientStops(StartColor.ToSD(), EndColor.ToSD(), scale, wrapMode);

                        brush.InterpolationColors = new sd2.ColorBlend
                        {
                            Positions = paths.Reverse().Select(r => 1f - r.Item1).ToArray(),
                            Colors    = paths.Reverse().Select(r => r.Item2).ToArray()
                        };
                    }
                }

                return(brush);
            }
Exemplo n.º 13
0
        protected override void DispatchDraw(global::Android.Graphics.Canvas canvas)

        {
            #region for Horizontal Gradient

            LinearGradient gradient = new Android.Graphics.LinearGradient(0, 0, Width, 0,

                                                                          #endregion



                                                                          StartColor.ToAndroid(),

                                                                          EndColor.ToAndroid(),

                                                                          Android.Graphics.Shader.TileMode.Mirror);



            Paint paint = new Android.Graphics.Paint()

            {
                Dither = true,
            };

            float rx = _context.ToPixels(_cornerRadius);

            float ry = _context.ToPixels(_cornerRadius);

            RectF rect = new RectF(0, 0, Width, Height);

            Path path = new Path();

            path.AddRoundRect(rect, rx, ry, Path.Direction.Cw);



            paint.StrokeWidth = 5f;  //set outline stroke

            paint.SetShader(gradient);

            canvas.DrawPath(path, paint);

            base.DispatchDraw(canvas);
        }
 void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
 {
     SKImageInfo info = args.Info;
     SKSurface surface = args.Surface;
     SKCanvas canvas = surface.Canvas;
     canvas.Clear();
     var colors = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor()};
     SKPoint startPoint = new SKPoint(0,0);
     SKPoint endPoint = Horizontal ? new SKPoint(info.Width, 0) : new SKPoint(0, info.Height);
     var shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp);
     SKPaint paint = new SKPaint
     {
         Style = SKPaintStyle.Fill,
         Shader = shader
     };
     
     canvas.DrawRect(new SKRect(0, 0, info.Width, info.Height), paint);
 }
Exemplo n.º 15
0
        void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            var colors = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() };

            using (SKPaint paint = new SKPaint())
            {
                // Createrectangle
                SKRect rect = new SKRect(0, 0, info.Width, info.Height);


                paint.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(rect.Left, rect.Top),
                    new SKPoint(rect.Right, rect.Bottom),
                    colors,
                    null,
                    SKShaderTileMode.Clamp);

                // Draw the gradient on the rectangle
                canvas.DrawRect(rect, paint);
            }


            // Create linear gradient from upper-left to lower-right


            /*SKPoint startPoint = new SKPoint(0, 0);
             * SKPoint endPoint = Horizontal ? new SKPoint(info.Width, 0) : new SKPoint(0, info.Height);
             *
             * var shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp);
             *
             * SKPaint paint = new SKPaint
             * {
             *  Style = SKPaintStyle.Fill,
             *  Shader = shader
             * };
             *
             * canvas.DrawRect(new SKRect(0, 0, info.Width, info.Height), paint);*/
        }
Exemplo n.º 16
0
 protected override sd.Brush Create(sd.RenderTarget target)
 {
     return(new sd.LinearGradientBrush(
                target,
                new sd.LinearGradientBrushProperties
     {
         StartPoint = StartPoint.ToDx(),
         EndPoint = EndPoint.ToDx()
     },
                new sd.GradientStopCollection(GraphicsHandler.CurrentRenderTarget, new[] {
         new sd.GradientStop {
             Color = StartColor.ToDx(), Position = 0f
         },
         new sd.GradientStop {
             Color = EndColor.ToDx(), Position = 1f
         }
     }, WrapMode.ToDx())
                ));
 }
Exemplo n.º 17
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            try
            {
                SKImageInfo info    = args.Info;
                SKSurface   surface = args.Surface;
                SKCanvas    canvas  = surface.Canvas;

                canvas.Clear();

                var startPoint = new SKPoint(0, 0);
                var endPoint   = new SKPoint(info.Width, info.Height);

                SKColor[] colors;
                SKShader  shader;

                if (HasGradientStartInset)
                {
                    colors = new SKColor[] { StartColor.ToSKColor(), StartColor.ToSKColor(), EndColor.ToSKColor() };
                    shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, new float[] { 0, GradientStartInsetPercent, 1 }, SKShaderTileMode.Clamp);
                }
                else
                {
                    colors = new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() };
                    shader = SKShader.CreateLinearGradient(startPoint, endPoint, colors, null, SKShaderTileMode.Clamp);
                }

                var mainPaint = new SKPaint
                {
                    Style  = SKPaintStyle.Fill,
                    Shader = shader
                };

                canvas.DrawRect(new SKRect(startPoint.X, startPoint.Y, endPoint.X, endPoint.Y), mainPaint);
            }
            catch (Exception ex)
            {
                // Don't crash for a pretty effect
                System.Diagnostics.Debug.WriteLine(ex);
            }
        }
Exemplo n.º 18
0
 protected override sd.Brush Create(sd.RenderTarget target)
 {
     return(new sd.RadialGradientBrush(
                target,
                new sd.RadialGradientBrushProperties
     {
         Center = Center.ToDx(),
         GradientOriginOffset = (GradientOrigin - Center).ToDx(),
         RadiusX = Radius.Width,
         RadiusY = Radius.Height
     },
                new sd.GradientStopCollection(GraphicsHandler.CurrentRenderTarget, new[] {
         new sd.GradientStop {
             Color = StartColor.ToDx(), Position = 0f
         },
         new sd.GradientStop {
             Color = EndColor.ToDx(), Position = 1f
         }
     }, WrapMode.ToDx())
                ));
 }
        protected override void DispatchDraw(Canvas canvas)
        {
            var gradient = GradientOrientation == GradientOrientation.Horizontal ?
                           new LinearGradient(0, 0, 0, Height,
                                              StartColor.ToAndroid(),
                                              EndColor.ToAndroid(),
                                              Shader.TileMode.Mirror)
                :
                           new LinearGradient(0, 0, Width, 0,
                                              StartColor.ToAndroid(),
                                              EndColor.ToAndroid(),
                                              Shader.TileMode.Mirror);

            var paint = new Paint
            {
                Dither = true
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }
Exemplo n.º 20
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs e)
        {
            base.OnPaintSurface(e);
            var canvas = e.Surface.Canvas;

            canvas.Clear();

            int width  = e.Info.Width;
            int height = e.Info.Height;

            SKPaint backPaint = new SKPaint
            {
                Style = SKPaintStyle.Fill,
                Color = SKColors.WhiteSmoke,
            };

            canvas.DrawRect(new SKRect(0, 0, width, height), backPaint);

            canvas.Save();

            canvas.Translate(width / 2, height / 2);
            canvas.Scale(Math.Min(width / 210f, height / 520f));

            var rect = new SKRect(-100, -100, 100, 100);

            // Add a buffer for the rectangle
            rect.Inflate(-10, -10);

            var bgColorPaint = new SKPaint
            {
                Color       = BGColor.ToSKColor(),
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                StrokeWidth = 0
            };


            var barColorPaint = new SKPaint
            {
                Color       = BarColor.ToSKColor(),
                IsAntialias = true,
                Style       = SKPaintStyle.Fill,
                StrokeWidth = 0
            };

            var frameColorPaint = new SKPaint
            {
                Color       = FrameColor.ToSKColor(),
                IsAntialias = true,
                Style       = SKPaintStyle.Stroke,
                StrokeWidth = 2
            };

            var skrect      = new SKRect(0, 0, PGWidth, PGHeight);
            var skRoundRect = new SKRoundRect(skrect, PGHeight / 2, PGHeight / 2);

            canvas.DrawRoundRect(0, 0, PGWidth, PGHeight, PGHeight / 2, PGHeight / 2, bgColorPaint);
            canvas.DrawRoundRect(skRoundRect, frameColorPaint);
            canvas.ClipRoundRect(skRoundRect, SKClipOperation.Intersect);

            if (StartColor != Color.Default && EndColor != Color.Default)
            {
                barColorPaint.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(skrect.Left, skrect.Bottom),
                    new SKPoint(skrect.Right, skrect.Top),
                    new SKColor[] { StartColor.ToSKColor(), EndColor.ToSKColor() },
                    new float[] { 0, 1 },
                    SKShaderTileMode.Repeat);
            }
            canvas.DrawRoundRect(0, 0, PGWidth * Progress / 100, PGHeight, PGWidth / 2, 0, barColorPaint);

            canvas.Restore();
        }
Exemplo n.º 21
0
 /// <inheritdoc/>
 public override int GetHashCode()
 {
     return(StartColor.GetHashCode() ^ (EndColor.GetHashCode() << 1) ^
            ((Angle.GetHashCode() + 1) << 2) ^ ((Focus.GetHashCode() + 1) << 10) ^ ((Contrast.GetHashCode() + 1) << 20));
 }
Exemplo n.º 22
0
        public GradientButton()
        {
            HeightRequest = 44;
            WidthRequest  = 100;

            _label = new Label
            {
                Text                    = Text,
                TextColor               = TextColor,
                FontSize                = 17,
                BackgroundColor         = Color.Transparent,
                HorizontalTextAlignment = TextAlignment.Center,
                VerticalTextAlignment   = TextAlignment.Center
            };

            _background = new NControlView
            {
                DrawingFunction = (canvas, rect) =>
                {
                    var brush = new LinearGradientBrush(
                        Point.Zero,
                        Point.OneX,
                        StartColor.ToNColor(),
                        EndColor.ToNColor());

                    var curveSize = BorderRadius;
                    var width     = rect.Width;
                    var height    = rect.Height;

                    canvas.DrawPath(new PathOp[] {
                        new MoveTo(curveSize, 0),
                        // Top Right corner
                        new LineTo(width - curveSize, 0),
                        new CurveTo(
                            new Point(width - curveSize, 0),
                            new Point(width, 0),
                            new Point(width, curveSize)
                            ),
                        new LineTo(width, height - curveSize),
                        // Bottom right corner
                        new CurveTo(
                            new Point(width, height - curveSize),
                            new Point(width, height),
                            new Point(width - curveSize, height)
                            ),
                        new LineTo(curveSize, height),
                        // Bottom left corner
                        new CurveTo(
                            new Point(curveSize, height),
                            new Point(0, height),
                            new Point(0, height - curveSize)
                            ),
                        new LineTo(0, curveSize),
                        new CurveTo(
                            new Point(0, curveSize),
                            new Point(0, 0),
                            new Point(curveSize, 0)
                            ),
                        new ClosePath()
                    }, null, brush);
                }
            };

            Content = new Grid
            {
                Children =
                {
                    _background,
                    _label
                }
            };
        }
        protected override void DispatchDraw(Android.Graphics.Canvas canvas)
        {
            var gradient =
                Direction == GredientBoxViewDirection.TopToBottom ?
                new Android.Graphics.LinearGradient(0, 0, 0, Height, StartColor.ToAndroid(), EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror) :
                Direction == GredientBoxViewDirection.LeftToRight ?
                new Android.Graphics.LinearGradient(0, 0, Width, 0, StartColor.ToAndroid(), EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror) :
                Direction == GredientBoxViewDirection.TopLeftToBottomRight ?
                new Android.Graphics.LinearGradient(0, 0, Width, Height, StartColor.ToAndroid(), EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror) :
                Direction == GredientBoxViewDirection.TopRightToBottomLeft ?
                new Android.Graphics.LinearGradient(0, Width, 0, Height, StartColor.ToAndroid(), EndColor.ToAndroid(), Android.Graphics.Shader.TileMode.Mirror) :
                null;
            var paint = new Android.Graphics.Paint {
                Dither = true
            };

            paint.SetShader(gradient);
            canvas.DrawPaint(paint);
            base.DispatchDraw(canvas);
        }