Пример #1
0
        private void SKCanvasView_PaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            SKImageInfo info    = args.Info;
            SKSurface   surface = args.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            using (SKPaint paint = new SKPaint())
            {
                // define the color for the shadow
                SKColor shadowColor = Color.FromHex("#000000").ToSKColor();

                paint.IsDither    = true;
                paint.IsAntialias = true;
                paint.Color       = shadowColor;

                // create filter for drop shadow
                paint.ImageFilter = SKImageFilter.CreateDropShadowOnly(
                    dx: 0, dy: 0,
                    sigmaX: 40, sigmaY: 40,
                    color: shadowColor);

                // define where I want to draw the object
                var corner       = info.Width / 2;
                var shadowBounds = new SKRect(65, 65, 460, 460);
                canvas.DrawRoundRect(shadowBounds, corner, corner, paint);
            }
        }
Пример #2
0
        protected override void OnBackgroundPaint(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;
            var bound  = e.Info.Rect;

            canvas.Clear();
            var bgColor     = Element.BackgroundColor.IsDefault() ? s_defaultColor : SKColor.Parse(Element.BackgroundColor.ToHex());
            var borderColor = Element.BorderColor.IsDefault() ? s_defaultColor : SKColor.Parse(Element.BorderColor.ToHex());
            var roundRect   = CreateRoundRect(bound);

            using (var paint = new SKPaint
            {
                IsAntialias = true,
            })
            {
                if (Element.HasShadow)
                {
                    paint.Color = SKColors.White;
                    paint.Style = SKPaintStyle.Stroke;
                    // Draw shadow
                    paint.ImageFilter = SKImageFilter.CreateDropShadowOnly(
                        Forms.ConvertToScaledPixel(0),
                        Forms.ConvertToScaledPixel(0),
                        Forms.ConvertToScaledPixel(s_borderWidth * 2),
                        Forms.ConvertToScaledPixel(s_borderWidth * 2),
                        SKColors.Black);
                    canvas.DrawRoundRect(roundRect, paint);
                }

                paint.ImageFilter = null;
                paint.Style       = SKPaintStyle.Fill;
                paint.Color       = bgColor;

                // Draw background color
                canvas.DrawRoundRect(roundRect, paint);

                paint.Style       = SKPaintStyle.Stroke;
                paint.StrokeWidth = Forms.ConvertToScaledPixel(s_borderWidth);
                paint.Color       = borderColor;

                // Draw Background (Brush)
                using (var brushPaint = Element.GetBackgroundPaint(bound))
                {
                    if (brushPaint != null)
                    {
                        canvas.DrawRoundRect(roundRect, brushPaint);
                    }
                }

                // Draw border
                canvas.DrawRoundRect(roundRect, paint);
            }
        }
Пример #3
0
        protected virtual void OnShadowPaint(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;
            var bound  = e.Info.Rect;

            canvas.Clear();

            // Draw shadow
            if (ShadowElement.HasShadow)
            {
                using (var paint = new SKPaint
                {
                    IsAntialias = true,
                    Style = SKPaintStyle.StrokeAndFill
                })
                {
                    using (var path = CreateShadowPath())
                    {
                        var scaledOffsetX    = Forms.ConvertToScaledPixel(ShadowElement.ShadowOffsetX);
                        var scaledOffsetY    = Forms.ConvertToScaledPixel(ShadowElement.ShadowOffsetY);
                        var scaledBlurRadius = Forms.ConvertToScaledPixel(ShadowElement.ShadowBlurRadius);

                        canvas.Save();
                        canvas.ClipPath(path, SKClipOperation.Difference, true);
                        paint.ImageFilter = SKImageFilter.CreateDropShadowOnly(
                            scaledOffsetX,
                            scaledOffsetY,
                            scaledBlurRadius,
                            scaledBlurRadius,
                            ShadowElement.ShadowColor.MultiplyAlpha(ShadowElement.ShadowOpacity).ToSK());
                        canvas.DrawPath(path, paint);
                        canvas.Restore();

                        canvas.Save();
                        canvas.ClipPath(path, SKClipOperation.Intersect, true);
                        canvas.DrawPath(path, paint);
                        canvas.Restore();
                    }
                }
            }
        }
        protected override void OnBackgroundPaint(object sender, SKPaintSurfaceEventArgs e)
        {
            var canvas = e.Surface.Canvas;
            var bound  = e.Info.Rect;

            canvas.Clear();
            var bgColor     = Element.BackgroundColor == Color.Default ? s_defaultColor : SKColor.Parse(Element.BackgroundColor.ToHex());
            var borderColor = ShadowElement.BorderColor == Color.Default ? s_defaultColor : SKColor.Parse(ShadowElement.BorderColor.ToHex());

            using (var paint = new SKPaint
            {
                IsAntialias = true,
            })
            {
                using (var path = GetRoundRectPath(false))
                {
                    // Draw shadow here only if you choose useShadowClip = true. (this means no use of shadow canvas)
                    if (UseShadowClipping && ShadowElement.HasShadow)
                    {
                        using (var path2 = GetRoundRectPath(true))
                        {
                            paint.Style = SKPaintStyle.StrokeAndFill;
                            var scaledOffsetX    = Forms.ConvertToScaledPixel(ShadowElement.ShadowOffsetX);
                            var scaledOffsetY    = Forms.ConvertToScaledPixel(ShadowElement.ShadowOffsetY);
                            var scaledBlurRadius = Forms.ConvertToScaledPixel(ShadowElement.ShadowBlurRadius);

                            canvas.Save();
                            canvas.ClipPath(path2, SKClipOperation.Difference, true);
                            paint.ImageFilter = SKImageFilter.CreateDropShadowOnly(
                                scaledOffsetX,
                                scaledOffsetY,
                                scaledBlurRadius,
                                scaledBlurRadius,
                                ShadowElement.ShadowColor.MultiplyAlpha(ShadowElement.ShadowOpacity).ToSK());
                            canvas.DrawPath(path2, paint);
                            canvas.Restore();

                            canvas.Save();
                            canvas.ClipPath(path2, SKClipOperation.Intersect, true);
                            canvas.DrawPath(path2, paint);
                            canvas.Restore();
                        }
                    }

                    // Draw background color
                    paint.ImageFilter = null;
                    paint.Style       = SKPaintStyle.Fill;
                    paint.Color       = bgColor;
                    canvas.DrawPath(path, paint);

                    // Draw Background (Brush)
                    using (var brushPaint = Element.GetBackgroundPaint(bound))
                    {
                        if (brushPaint != null)
                        {
                            canvas.DrawPath(path, brushPaint);
                        }
                    }

                    // Draw border
                    if (ShadowElement.BorderWidth != 0)
                    {
                        paint.IsAntialias = true;
                        paint.Style       = SKPaintStyle.Stroke;
                        paint.StrokeWidth = Forms.ConvertToScaledPixel(ShadowElement.BorderWidth);
                        paint.Color       = borderColor;
                        canvas.DrawPath(path, paint);
                    }
                }
            }
        }