示例#1
0
        public static void ApplyFill(this SKPaint paint, Rect bounds, DrawingStyle style)
        {
            paint.Style       = SKPaintStyle.Fill;
            paint.IsAntialias = style.EdgeMode == EdgeMode.Unspecified;

            if (style.Fill is SolidColorBrush)
            {
                paint.Color = style.Fill.ToSKColor();
            }
            else
            {
                paint.Shader = style.Fill.ToSkiaShader(bounds.Width, bounds.Height);
            }

            if (style.HasOpacity)
            {
                paint.ColorFilter = SKColorFilter.CreateBlendMode(SKColors.Transparent.WithAlpha((byte)(style.Opacity * 255d)), SKBlendMode.DstIn);
            }

            if (style.Effect != null)
            {
                if (style.Effect is DropShadowEffect)
                {
                    var fx = style.Effect as DropShadowEffect;
                    paint.ImageFilter = SKImageFilter.CreateDropShadow(fx.ShadowDepth.ToFloat(), fx.ShadowDepth.ToFloat(), fx.BlurRadius.ToFloat(), fx.BlurRadius.ToFloat(), fx.Color.ToSKColor(), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground);
                }
            }
        }
示例#2
0
        private void OnCanvasViewPaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            if (IsSelected)
            {
                SKCanvas    skCanvas = args.Surface.Canvas;
                SKImageInfo skinfo   = args.Info;
                skCanvas.Clear();

                float shadowOffset    = 6f;
                float rectangleOffset = 12f;

                SKColor       rectangleStyleFillShadowColor = new SKColor(187, 187, 187, 255);
                SKImageFilter rectangleStyleFillShadow      = SKImageFilter.CreateDropShadow(0f, 0f, shadowOffset, shadowOffset, rectangleStyleFillShadowColor, SKDropShadowImageFilterShadowMode.DrawShadowOnly, null, null);

                SKPaint rectangleStyleFillPaint = new SKPaint()
                {
                    Style       = SKPaintStyle.Fill,
                    BlendMode   = SKBlendMode.SrcOver,
                    IsAntialias = true,
                    ImageFilter = rectangleStyleFillShadow
                };

                skCanvas.DrawRect(new SKRect(rectangleOffset, rectangleOffset, skinfo.Width - rectangleOffset, skinfo.Height - rectangleOffset), rectangleStyleFillPaint);
            }
            else
            {
                args.Surface.Canvas.Clear();
            }
        }
示例#3
0
        private void SKCanvasView_OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var skCanvas = e.Surface.Canvas;
            var skinfo   = e.Info;

            skCanvas.Clear();


            var RectangleStyleFillShadowColor = new SKColor(24, 24, 24, 70);

            var RectangleStyleFillShadow = SKImageFilter.CreateDropShadow(
                (float)SliderShadowX.Value, (float)SliderShadowY.Value,
                (float)SliderSigmaX.Value, (float)SliderSigmaY.Value,
                RectangleStyleFillShadowColor,
                SKDropShadowImageFilterShadowMode.DrawShadowAndForeground,
                SKImageFilter.CreateBlur((float)SliderBlurX.Value, (float)SliderBlurY.Value), null);


            var RectangleStyleFillPaint = new SKPaint()
            {
                Style       = SKPaintStyle.Fill,
                Color       = SKColors.White,
                BlendMode   = SKBlendMode.SrcOver,
                IsAntialias = true,
                ImageFilter = RectangleStyleFillShadow
            };

            var shadowMargin = (float)SliderShadowMargin.Value;

            skCanvas.DrawRect(new SKRect(shadowMargin, shadowMargin, skinfo.Width - shadowMargin, skinfo.Height - shadowMargin), RectangleStyleFillPaint);
        }
        private void SKCanvasView_PaintSurface(object sender, SkiaSharp.Views.Forms.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)Application.Current.Resources["ButtonBackgroundColor"]).ToSKColor();

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

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

                // define where I want to draw the object
                var margin       = info.Width / 10;
                var shadowBounds = new SKRect(margin, -40, info.Width - margin, 10);
                canvas.DrawRoundRect(shadowBounds, 10, 10, paint);
            }
        }
示例#5
0
        void makeShadow(SKImageInfo info, SKCanvas canvas, TypeShadow typeShadow, float x, float y, Color color, Color backgroundColor)
        {
            SKPaint skPaint = new SKPaint()
            {
                Style = SKPaintStyle.Fill,
                Color = backgroundColor.ToSKColor(),
                //StrokeWidth = 1,
                IsAntialias = true,


                ImageFilter = SKImageFilter.CreateDropShadow(
                    x,
                    y,
                    SizeStroker,
                    SizeStroker,
                    color.ToSKColor().WithAlpha((byte)(0xFF * OpacityShadow)),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
            };
            var    auxSize     = SizeShadow;
            SKRect skRectangle = new SKRect();

            skRectangle.Size = new SKSize(info.Width - (auxSize * 2), info.Height - (auxSize * 2));

            skRectangle.Location = new SKPoint(auxSize, auxSize);



            canvas.DrawRoundRect(skRectangle, BorderRadius, BorderRadius, skPaint);
        }
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs args)
        {
            base.OnPaintSurface(args);

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

            canvas.Clear();
            canvas.Save();

            using (SKPaint paint = new SKPaint())
            {
                // Set SKPaint properties
                paint.Color       = SKColors.White;
                paint.ImageFilter = SKImageFilter.CreateDropShadow(
                    OffsetX,
                    OffsetY,
                    BlurX,
                    BlurY,
                    ShadowColor.ToSKColor(),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground);

                canvas.DrawRoundRect(new SKRect(20f, 20f, info.Width - 20, info.Height - 20), Radius, Radius, paint);

                canvas.Restore();
            }
        }
示例#7
0
        private void NavShadow_PaintSurface(object sender, SKPaintSurfaceEventArgs args)
        {
            var info    = args.Info;
            var surface = args.Surface;
            var canvas  = surface.Canvas;

            canvas.Clear(SKColor.Empty);

            using (var path = new SKPath())
            {
                path.MoveTo(0, -6);
                path.LineTo(info.Width, -6);
                var shadowPaint = new SKPaint
                {
                    Style       = SKPaintStyle.Stroke,
                    StrokeWidth = 6,
                    Color       = SKColor.Parse("#FFFFFF"),
                    ImageFilter = SKImageFilter.CreateDropShadow(
                        0,
                        6,
                        0,
                        6,
                        SKColor.Parse("#444444"),
                        SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
                };
                canvas.DrawPath(path, shadowPaint);
            }
        }
示例#8
0
        public static void DrawDisplayName(SKCanvas c, BaseIcon icon)
        {
            string text = icon.DisplayName;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            int x = 5;
            int y = STARTER_POSITION + NAME_TEXT_SIZE;

            using (var shadow = SKImageFilter.CreateDropShadow(0, 0, 5, 5, SKColors.Black))
                using (var paint = new SKPaint {
                    FilterQuality = SKFilterQuality.High, IsAntialias = true, Typeface = ChicTypefaces.BurbankBigCondensedBold, TextSize = NAME_TEXT_SIZE, ImageFilter = shadow, Color = SKColors.White
                })
                {
                    while (paint.TextSize > icon.Width - x * 5)
                    {
                        paint.TextSize--;
                    }

                    c.DrawText(text, x, y, paint);
                }
        }
示例#9
0
        private new void DrawBackground(SKCanvas c)
        {
            c.DrawRect(new SKRect(Margin, Margin, Width - Margin, Height - Margin),
                       new SKPaint
            {
                IsAntialias = true, FilterQuality = SKFilterQuality.High,
                Shader      = SKShader.CreateRadialGradient(new SKPoint(Width / 2, Height / 2), Width / 5 * 2,
                                                            new[] { Background[0], Background[1] },
                                                            SKShaderTileMode.Clamp)
            });

            for (var i = 0; i < _backgroundOverlay.Width; i++)
            {
                for (var j = 0; j < _backgroundOverlay.Height; j++)
                {
                    if (_backgroundOverlay.GetPixel(i, j) == SKColors.Black)
                    {
                        _backgroundOverlay.SetPixel(i, j, SKColors.Transparent);
                    }
                }
            }

            c.DrawBitmap(_backgroundOverlay, new SKRect(Margin, Margin, Width - Margin, Height - Margin), new SKPaint
            {
                IsAntialias = true,
                ColorFilter = SKColorFilter.CreateBlendMode(SKColors.Black.WithAlpha(150), SKBlendMode.DstIn),
                ImageFilter = SKImageFilter.CreateDropShadow(2, 2, 4, 4, new SKColor(0, 0, 0))
            });
            c.DrawColor(SKColors.Black.WithAlpha(125), SKBlendMode.DstIn);
        }
示例#10
0
        void makeInnerShadow(SKImageInfo info, SKCanvas canvas, TypeShadow typeShadow, float x, float y, Color color, Color backgroundColor)
        {
            SKPaint skPaint = new SKPaint()
            {
                Style       = SKPaintStyle.Stroke,
                Color       = color.ToSKColor().WithAlpha((byte)(0xFF * OpacityShadow)),
                StrokeWidth = SizeStroker,
                IsAntialias = true,
                ImageFilter = SKImageFilter.CreateDropShadow(
                    x,
                    y,
                    SizeStroker,
                    SizeStroker,
                    color.ToSKColor().WithAlpha((byte)(0xFF * OpacityShadow)),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground)
            };

            SKRect skRectangle = new SKRect();

            if (!ShowOut)
            {
                skRectangle.Size     = new SKSize(info.Width, info.Height);
                skRectangle.Location = new SKPoint(0, 0);
            }
            else
            {
                skRectangle.Size     = new SKSize(info.Width - (SizeShadow * 2), info.Height - (SizeShadow * 2));
                skRectangle.Location = new SKPoint(SizeShadow, SizeShadow);
            }



            skRectangle.Inflate(SizeStroker, SizeStroker);
            canvas.DrawRoundRect(skRectangle, BorderRadius, BorderRadius, skPaint);
        }
示例#11
0
        public static void DrawBackground(SKCanvas c, BaseIcon icon)
        {
            using (var path = new SKPath {
                FillType = SKPathFillType.EvenOdd
            })
            {
                path.MoveTo(0, icon.Height);
                path.LineTo(0, icon.Height - 75);
                path.LineTo(icon.Width, icon.Height - 85);
                path.LineTo(icon.Width, icon.Height);
                path.Close();

                using (var shadow = SKImageFilter.CreateDropShadow(0, -3, 5, 5, SKColors.Black))
                    using (var paint = new SKPaint {
                        FilterQuality = SKFilterQuality.High, IsAntialias = true, Color = icon.RarityColors[0], ImageFilter = shadow
                    })
                        c.DrawPath(path, paint);
            }

            using (var path = new SKPath {
                FillType = SKPathFillType.EvenOdd
            })
            {
                path.MoveTo(0, icon.Height);
                path.LineTo(0, icon.Height - 65);
                path.LineTo(icon.Width, icon.Height - 75);
                path.LineTo(icon.Width, icon.Height);
                path.Close();

                using (var paint = new SKPaint {
                    FilterQuality = SKFilterQuality.High, IsAntialias = true, Color = new SKColor(30, 30, 30)
                })
                    c.DrawPath(path, paint);
            }
        }
示例#12
0
 public static SKImageFilter ToSKDropShadow(this Color shadowColor, float distance) =>
 SKImageFilter.CreateDropShadow(
     distance,
     distance,
     DEFAULT_SIGMA,
     DEFAULT_SIGMA,
     shadowColor.ToSKColor(),         //0.75 of opacity. Taken form UWP renderer
     SKDropShadowImageFilterShadowMode.DrawShadowOnly);
示例#13
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs eventArgs)
        {
            var givenCanvas = eventArgs.Surface.Canvas;

            givenCanvas.Clear();
            int canvasWidth  = eventArgs.Info.Width;
            int canvasHeight = eventArgs.Info.Height;

            this.roundRectButton = new SKRoundRect(new SKRect(0, 0, canvasWidth, canvasHeight - 20), ButtonRadius, ButtonRadius);

            this.paintButton = new SKPaint()
            {
                Color       = this.ColorPrimary.ToSKColor(),
                IsAntialias = true
            };

            if (HasShadow)
            {
                paintButton.ImageFilter = SKImageFilter.CreateDropShadow(
                    0,
                    8,
                    0,
                    5,
                    Color.FromRgba(0, 0, 0, 0.4).ToSKColor(),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground
                    );
            }

            if (this.IsGradient)
            {
                paintButton.Shader = SKShader.CreateLinearGradient(
                    new SKPoint(this.roundRectButton.Rect.Left, this.roundRectButton.Rect.Top),
                    new SKPoint(this.roundRectButton.Rect.Right, this.roundRectButton.Rect.Bottom),
                    new SKColor[] {
                    this.ColorPrimary.ToSKColor(),
                    this.ColorSecondary.ToSKColor()
                },
                    new float[] {
                    this.buttonGradientOffset,
                    1
                },
                    SKShaderTileMode.Repeat
                    );
            }

            givenCanvas.DrawRoundRect(this.roundRectButton, this.paintButton);

            SKPaint paintButtonTitle = new SKPaint()
            {
                TextSize    = FontSize * coreSettings.ScalingFactor,
                IsAntialias = true,
                Color       = this.ColorText.ToSKColor(),
                TextAlign   = TextAlign,
                Typeface    = TextFont
            };

            givenCanvas.DrawText(this.ButtonTitle, canvasWidth / 2, ((canvasHeight - 30) / 2 + 25), paintButtonTitle);
        }
示例#14
0
        public static void DrawCompletionRewards(SKCanvas c, BaseBundle icon)
        {
            using SKPaint paint = new SKPaint
                  {
                      IsAntialias   = true,
                      FilterQuality = SKFilterQuality.High,
                      TextSize      = 35,
                      Color         = SKColors.White,
                      TextAlign     = SKTextAlign.Left,
                      Typeface      = Text.TypeFaces.BundleDisplayNameTypeface
                  };

            int y = icon.HeaderHeight + (50 * 2) + (95 * icon.Quests.Count);

            foreach (CompletionReward r in icon.CompletionRewards)
            {
                DrawQuestBackground(c, icon, y, false);

                paint.TextSize    = 35;
                paint.ImageFilter = null;
                paint.Color       = SKColors.White;
                paint.TextAlign   = SKTextAlign.Left;
                paint.Typeface    = Text.TypeFaces.BundleDisplayNameTypeface;
                while (paint.MeasureText(r.CompletionText) > icon.Width - 65 - 165)
                {
                    paint.TextSize -= 1;
                }
                c.DrawText(r.CompletionText, new SKPoint(65, y + paint.TextSize + 15), paint);

                if (r.Reward?.RewardIcon != null)
                {
                    if (r.Reward.IsCountShifted)
                    {
                        int l = r.Reward.RewardQuantity.ToString().Length;
                        paint.TextSize    = l >= 5 ? 30 : 35;
                        paint.TextAlign   = SKTextAlign.Right;
                        paint.Color       = SKColor.Parse(r.Reward.RewardFillColor);
                        paint.Typeface    = Text.TypeFaces.BundleDefaultTypeface;
                        paint.ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 5, 5, SKColor.Parse(r.Reward.RewardBorderColor).WithAlpha(200));
                        c.DrawText(r.Reward.RewardQuantity.ToString(), new SKPoint(icon.Width - 85, y + 47.5F), paint);
                        c.DrawBitmap(r.Reward.RewardIcon, new SKPoint(icon.Width - 30 - r.Reward.RewardIcon.Width, y + 12.5F),
                                     new SKPaint {
                            IsAntialias = true, FilterQuality = SKFilterQuality.High
                        });
                    }
                    else
                    {
                        c.DrawBitmap(r.Reward.RewardIcon, new SKPoint(icon.Width - 125, y + 5),
                                     new SKPaint {
                            IsAntialias = true, FilterQuality = SKFilterQuality.High
                        });
                    }
                }

                y += 95;
            }
        }
示例#15
0
 internal static SKImageFilter ToSKDropShadow(this Color shadowColor, float distance, float?sigma = null)
 {
     return(SKImageFilter.CreateDropShadow(
                distance,
                distance,
                sigma ?? DEFAULT_SIGMA,
                sigma ?? DEFAULT_SIGMA,
                shadowColor.ToSKColor()));
 }
示例#16
0
        void OnPaint(object sender, SKPaintSurfaceEventArgs e)
        {
            SKImageInfo info    = e.Info;
            SKSurface   surface = e.Surface;
            SKCanvas    canvas  = surface.Canvas;

            canvas.Clear();

            if (CanvasWidth != info.Width || CanvasHeight != info.Height)
            {
                CanvasWidth  = info.Width;
                CanvasHeight = info.Height;
                UpdateCoordinate();
            }

            using (var primaryPaint = new SKPaint
            {
                IsAntialias = true,
                Style = SKPaintStyle.Stroke,
                StrokeCap = SKStrokeCap.Round,
                StrokeWidth = Thickness,
            })
                using (var shadowPaint = new SKPaint
                {
                    IsAntialias = true,
                    Style = SKPaintStyle.Stroke,
                    ImageFilter = SKImageFilter.CreateDropShadow(0, 0, 3, 3, SKColor.Parse("#222222"), SKDropShadowImageFilterShadowMode.DrawShadowOnly),
                    StrokeCap = SKStrokeCap.Round,
                    StrokeWidth = Thickness,
                })
                {
                    // DrawRightBGPart
                    primaryPaint.Color = _rightItemBGColor;
                    DrawRightBGPart(canvas, primaryPaint, shadowPaint);
                    primaryPaint.Color = _rightItemColor;
                    DrawRightProgressPart(canvas, primaryPaint, shadowPaint);

                    // DrawLeftBGPart
                    primaryPaint.Color = _leftItemBGColor;
                    DrawLeftBGPart(canvas, primaryPaint, shadowPaint);
                    primaryPaint.Color = _leftItemColor;
                    DrawLeftProgressPart(canvas, primaryPaint, shadowPaint);

                    // DrawBottomBGPart
                    primaryPaint.Color = _bottomItemBGColor;
                    DrawBottomBGPart(canvas, primaryPaint, shadowPaint);
                    primaryPaint.Color = _bottomItemColor;
                    DrawBottomProgressPart(canvas, primaryPaint, shadowPaint);

                    // Right End point
                    primaryPaint.Color = _rightItemBGColor;
                    DrawRightBGEndPart(canvas, primaryPaint, shadowPaint);
                    primaryPaint.Color = _rightItemColor;
                    DrawRightProgressEndPart(canvas, primaryPaint, shadowPaint);
                }
        }
示例#17
0
 internal static SKImageFilter ToSKDropShadow(this Color shadowColor, float distance)
 {
     return(SKImageFilter.CreateDropShadow(
                distance,
                distance,
                DEFAULT_SIGMA,
                DEFAULT_SIGMA,
                shadowColor.ToSKColor(),
                SKDropShadowImageFilterShadowMode.DrawShadowOnly));
 }
示例#18
0
        public static void DrawPreviewImage(SKCanvas c, BaseIcon icon)
        {
            int x = (icon.Width - icon.Height) / 2;
            int y = 0;

            using (var shadow = SKImageFilter.CreateDropShadow(0, 0, 5, 5, SKColors.Black))
                using (var paint = new SKPaint {
                    FilterQuality = SKFilterQuality.High, IsAntialias = true, ImageFilter = shadow
                })
                    c.DrawBitmap(icon.IconImage, new SKRect(x, y, x + icon.Height, y + icon.Height), paint);
        }
示例#19
0
        public void PaintTextGL(object sender, SKSurface surface, GRBackendRenderTarget backendRenderTarget)
        {
            float dx     = -10;
            float dy     = 10;
            float sigmaX = 3;
            float sigmaY = 3;

            var    Bind = sender as Xamarin.Forms.View;
            string text = (string)Bind.BindingContext;

            var canvas = surface.Canvas;

            canvas.Clear();

            using (SKPaint textPaintFill = new SKPaint
            {
                Style = SKPaintStyle.Fill,
                IsAntialias = true,
                Color = SKColor.Parse("#E7D014")
            })
            {
                using (SKPaint textPaint = new SKPaint
                {
                    Style = SKPaintStyle.Stroke,
                    StrokeWidth = 4,
                    IsAntialias = true,
                    Color = SKColor.Parse("#000")
                })
                {
                    textPaintFill.Typeface = GetTypeface("AmericanCaptain.ttf");
                    textPaint.Typeface     = textPaintFill.Typeface;
                    float textWidth = textPaintFill.MeasureText(text);
                    textPaintFill.TextSize = 0.85f * backendRenderTarget.Width * textPaintFill.TextSize / textWidth;
                    textPaint.TextSize     = 0.85f * backendRenderTarget.Width * textPaint.TextSize / textWidth;
                    SKRect textBounds = new SKRect();
                    textPaint.MeasureText(text, ref textBounds);
                    textPaintFill.ImageFilter = SKImageFilter.CreateDropShadow(
                        dx,
                        dy,
                        sigmaX,
                        sigmaY,
                        SKColor.Parse("#55000000"));
                    textPaintFill.MeasureText(text, ref textBounds);



                    float xText = backendRenderTarget.Width / 2 - textBounds.MidX;
                    float yText = backendRenderTarget.Height / 2 - textBounds.MidY;

                    canvas.DrawText(text, xText, yText, textPaint);
                    canvas.DrawText(text, xText, yText, textPaintFill);
                }
            }
        }
 public Icon(IEmission emission, SKPoint cakeCenter, float radius, float offset, SKPoint center)
 {
     Radius     = radius;
     Offset     = offset;
     Center     = center;
     SVG        = CakeUtil.GetSVGPath(emission);
     Color      = CakeUtil.GetColor(emission);
     DropShadow = SKImageFilter.CreateDropShadow(-(Center.X - cakeCenter.X) / 12, -(Center.Y - cakeCenter.Y) / 12, 9, 9, SKColors.Black.WithAlpha(50), SKDropShadowImageFilterShadowMode.DrawShadowAndForeground);
     ScaleSVGPath();
     CenterSVGPath();
 }
示例#21
0
 public override void PostProcess(SKCanvas canvas, SKImageInfo canvasInfo, SKPath renderBounds, SKPaint paint)
 {
     paint.ImageFilter = SKImageFilter.CreateDropShadow(
         Properties.GlowOffset.CurrentValue.X,
         Properties.GlowOffset.CurrentValue.Y,
         Properties.GlowBlurAmount.CurrentValue.Width,
         Properties.GlowBlurAmount.CurrentValue.Height, Properties.GlowColor,
         SKDropShadowImageFilterShadowMode.DrawShadowAndForeground,
         paint.ImageFilter
         );
 }
示例#22
0
 public override void PostProcess(SKCanvas canvas, SKRect bounds, SKPaint paint)
 {
     paint.ImageFilter = SKImageFilter.CreateDropShadow(
         Properties.GlowOffset.CurrentValue.X,
         Properties.GlowOffset.CurrentValue.Y,
         Properties.GlowBlurAmount.CurrentValue.Width,
         Properties.GlowBlurAmount.CurrentValue.Height,
         Properties.GlowColor,
         paint.ImageFilter
         );
 }
示例#23
0
        protected override void OnPaintSurface(SKPaintSurfaceEventArgs eventArgs)
        {
            var givenCanvas = eventArgs.Surface.Canvas;

            givenCanvas.Clear();

            this.canvasWidth  = eventArgs.Info.Width;
            this.canvasHeight = eventArgs.Info.Height;

            if (!this.HasShadow)
            {
                this.shadowPadding = 0;
            }

            // Draw the Checkbox container
            SKRoundRect roundRectCheckbox = new SKRoundRect(new SKRect(this.shadowPadding, 0, this.canvasWidth - this.shadowPadding, this.canvasHeight - (this.shadowPadding * 2)), ((this.canvasHeight - (this.shadowPadding * 2)) / 6), ((this.canvasHeight - (this.shadowPadding * 2)) / 6));
            SKPaint     paintCheckbox     = new SKPaint()
            {
                Color       = this.colorCurrent.ToSKColor(),
                Style       = SKPaintStyle.Fill,
                IsAntialias = true
            };

            if (this.HasShadow)
            {
                paintCheckbox.ImageFilter = SKImageFilter.CreateDropShadow(
                    0,
                    8,
                    0,
                    5,
                    Color.FromRgba(0, 0, 0, 0.4).ToSKColor(),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground
                    );
            }

            givenCanvas.DrawRoundRect(roundRectCheckbox, paintCheckbox);

            if (this.IsChecked)
            {
                SKPaint paintIcon = new SKPaint()
                {
                    TextSize    = 48f,
                    IsAntialias = true,
                    Color       = this.ColorIcon.ToSKColor(),
                    TextAlign   = SKTextAlign.Center,
                    Typeface    = this.GetTypeface("fa-solid-900.ttf")
                };
                SKRect rectIcon = new SKRect();
                paintIcon.MeasureText("\uf00d", ref rectIcon);

                givenCanvas.DrawText("\uf00d", this.canvasWidth / 2, this.canvasHeight / 2 - rectIcon.MidY - this.shadowPadding, paintIcon);
            }
        }
        void OnPaintSurface(object sender, SKPaintSurfaceEventArgs e)
        {
            var geometry = ContentNativeView == null ? NativeView.Geometry : ContentNativeView.Geometry;
            var canvas   = e.Surface.Canvas;

            canvas.Clear();

            var path         = new SKPath();
            var left         = geometry.Left - _canvasView.Geometry.Left;
            var top          = geometry.Top - _canvasView.Geometry.Top;
            var rect         = new SKRect(left, top, left + geometry.Width, top + geometry.Height);
            var scaledRadius = Forms.ConvertToScaledPixel(ShadowsElement.CornerRadius) * 2;
            var topLeft      = new SKRect(rect.Left, rect.Top, rect.Left + scaledRadius, rect.Top + scaledRadius);
            var topRight     = new SKRect(rect.Right - scaledRadius, rect.Top, rect.Right, rect.Top + scaledRadius);
            var bottomLeft   = new SKRect(rect.Left, rect.Bottom - scaledRadius, rect.Left + scaledRadius, rect.Bottom);
            var bottomRight  = new SKRect(rect.Right - scaledRadius, rect.Bottom - scaledRadius, rect.Right, rect.Bottom);

            path.ArcTo(topLeft, 180, 90, false);
            path.ArcTo(topRight, 270, 90, false);
            path.ArcTo(bottomRight, 0, 90, false);
            path.ArcTo(bottomLeft, 90, 90, false);
            path.Close();

            using (var paint = new SKPaint())
            {
                paint.IsAntialias = true;
                paint.Style       = SKPaintStyle.StrokeAndFill;
                foreach (var shade in _shadesSource)
                {
                    var scaledOffsetX    = Forms.ConvertToScaledPixel(shade.Offset.X);
                    var scaledOffsetY    = Forms.ConvertToScaledPixel(shade.Offset.Y);
                    var scaledBlurRadius = Forms.ConvertToScaledPixel(shade.BlurRadius);

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Difference, true);
                    paint.ImageFilter = SKImageFilter.CreateDropShadow(
                        scaledOffsetX,
                        scaledOffsetY,
                        scaledBlurRadius,
                        scaledBlurRadius,
                        shade.Color.MultiplyAlpha(shade.Opacity).ToSK(),
                        SKDropShadowImageFilterShadowMode.DrawShadowOnly);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Intersect, true);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();
                }
            }
        }
示例#25
0
        private void DrawShadow(SKCanvas canvas, SKTypeface font, string text = "Xamarin", int x = 0, int y    = 0, int fontsize = 200, int strokewidth = 2,
                                string shadowcolor = "#AAffff00", string shadowg1 = "#ff0000", string shadowg2 = "#cccccc")
        {
            using (SKPaint measurepaint = new SKPaint())
            {
                measurepaint.Style       = SKPaintStyle.Fill;
                measurepaint.IsAntialias = true;
                measurepaint.Typeface    = font;
                measurepaint.TextSize    = (float)fontsize;

                using (SKPath textPath = measurepaint.GetTextPath(text, (float)x, (float)y + (float)fontsize))
                {
                    using (SKPaint paint2 = new SKPaint())
                    {
                        paint2.IsAntialias = true;
                        paint2.StrokeMiter = 1000;
                        paint2.StrokeCap   = SKStrokeCap.Round;
                        paint2.StrokeJoin  = SKStrokeJoin.Round;
                        paint2.Style       = SKPaintStyle.StrokeAndFill;
                        paint2.StrokeWidth = (float)strokewidth;


                        if (Gradient)
                        {
                            paint2.Color = FromString(shadowcolor);
                        }
                        else
                        {
                            paint2.Color = FromString(shadowg1);
                        }

                        paint2.Typeface = font;
                        paint2.TextSize = (float)fontsize;

                        SKRect textBounds = textPath.Bounds;
                        if (Gradient)
                        {
                            paint2.Shader = SKShader.CreateLinearGradient(
                                new SKPoint(textBounds.Left + textBounds.Width * 0.5f, textBounds.Top),
                                new SKPoint(textBounds.Left + textBounds.Width * 0.5f, textBounds.Bottom),
                                new SKColor[] { FromString(shadowg1), FromString(shadowg2) }, null,
                                SKShaderTileMode.Clamp);
                        }

                        paint2.ImageFilter = SKImageFilter.CreateDropShadow(8, 8, 4, 4, FromString(shadowcolor), SKDropShadowImageFilterShadowMode.DrawShadowOnly);

                        canvas.DrawPath(textPath, paint2);
                    }
                }
            }
        }
        private void DrawShadow(SKCanvas canvas)
        {
            var pancake = Element as PancakeView;

            if (pancake.Shadow != null)
            {
                SKPath path;
                if (pancake.Sides != 4)
                {
                    path = DrawingExtensions.CreatePolygonPath(Control.Geometry.Width, Control.Geometry.Height,
                                                               pancake.Sides, pancake.CornerRadius.TopLeft, pancake.OffsetAngle);
                }
                else
                {
                    var left = Control.Geometry.Left - _skCanvasView.Geometry.Left;
                    var top  = Control.Geometry.Top - _skCanvasView.Geometry.Top;
                    path = DrawingExtensions.CreateRoundedRectPath(left, top, left + Control.Geometry.Width, top + Control.Geometry.Height, pancake.CornerRadius);
                }

                using (var paint = new SKPaint())
                {
                    paint.IsAntialias = true;
                    paint.Style       = SKPaintStyle.StrokeAndFill;

                    var shadow           = pancake.Shadow;
                    var scaledOffsetX    = Forms.ConvertToScaledPixel(shadow.Offset.X);
                    var scaledOffsetY    = Forms.ConvertToScaledPixel(shadow.Offset.Y);
                    var scaledBlurRadius = Forms.ConvertToScaledPixel(shadow.BlurRadius);

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Difference, true);
                    paint.ImageFilter = SKImageFilter.CreateDropShadow(
                        scaledOffsetX,
                        scaledOffsetY,
                        scaledBlurRadius,
                        scaledBlurRadius,
                        shadow.Color.MultiplyAlpha(shadow.Opacity).ToNative().ToSKColor(),
                        SKDropShadowImageFilterShadowMode.DrawShadowOnly);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();

                    canvas.Save();
                    canvas.ClipPath(path, SKClipOperation.Intersect, true);
                    canvas.DrawPath(path, paint);
                    canvas.Restore();
                }
            }
        }
示例#27
0
        public static void DrawBanner(SKCanvas c, BaseIcon icon)
        {
            var f  = (int)(ChicRatios.Get1024(50) * icon.Height);
            var tf = (int)(ChicRatios.Get1024(25) * icon.Height);
            var tt = (int)(ChicRatios.Get1024(23) * icon.Height);
            var t  = (int)(ChicRatios.Get1024(20) * icon.Height);
            var et = (int)(ChicRatios.Get1024(18) * icon.Height);
            var ft = (int)(ChicRatios.Get1024(15) * icon.Height);
            var tw = (int)(ChicRatios.Get1024(12) * icon.Height);
            var n  = (int)(ChicRatios.Get1024(9) * icon.Height);
            var s  = (int)(ChicRatios.Get1024(7) * icon.Height);

            using (var textPaint = new SKPaint
            {
                IsAntialias = true,
                FilterQuality = SKFilterQuality.High,
                Color = SKColors.White,
                Typeface = ChicTypefaces.BurbankBigRegularBlack,
                TextAlign = SKTextAlign.Left,
                TextSize = f
            })
            {
                int width = (int)textPaint.MeasureText(icon.Banner);

                using (var path = new SKPath())
                {
                    path.FillType = SKPathFillType.EvenOdd;

                    path.MoveTo(ft, ft);
                    path.LineTo(width + f, tw);
                    path.LineTo(width + tf, textPaint.TextSize + tt);
                    path.LineTo(t, textPaint.TextSize + et);
                    path.Close();

                    using (var filter = SKImageFilter.CreateDropShadow(0, 0, s, s, SKColors.Black))
                        c.DrawPath(path,
                                   new SKPaint
                        {
                            IsAntialias   = true,
                            FilterQuality = SKFilterQuality.High,
                            Color         = SKColor.Parse("#f5112c"),
                            ImageFilter   = filter
                        });
                }

                c.DrawText(icon.Banner, tf, textPaint.TextSize + n, textPaint);
            }
        }
示例#28
0
        public static void DrawDisplayName(SKCanvas c, BaseIcon icon)
        {
            string text = icon.DisplayName;

            if (string.IsNullOrEmpty(text))
            {
                return;
            }

            int x = (int)(icon.Height * ChicRatios.Get(5));
            int y = (int)(icon.Height * STARTER_POSITION_RATIO + icon.Height * NAME_TEXT_SIZE_RATIO);

            using (var namePaint = new SKPaint
            {
                IsAntialias = true,
                FilterQuality = SKFilterQuality.High,
                Typeface = ChicTypefaces.BurbankBigCondensedBold,
                TextSize = icon.Height * NAME_TEXT_SIZE_RATIO,
                Color = SKColors.White,
                //TextAlign = SKTextAlign.Left,
                ImageFilter = SKImageFilter.CreateDropShadow(0, 0, icon.Height * 0.009765625f, icon.Height * 0.009765625f, SKColors.Black)
            })
            {
                using (var paint = new SKPaint
                {
                    IsAntialias = true,
                    FilterQuality = SKFilterQuality.High,
                    Typeface = ChicTypefaces.BurbankBigCondensedBold,
                    TextSize = icon.Height * ChicRatios.Get(23),
                    Color = SKColors.White,
                    ImageFilter = SKImageFilter.CreateDropShadow(0, 0, icon.Height * ChicRatios.Get(5), icon.Height * ChicRatios.Get(5), SKColors.Black)
                })
                {
                    while (namePaint.MeasureText(icon.DisplayName) + paint.MeasureText(icon.BundleInfo) > icon.Width - x * 5)
                    {
                        namePaint.TextSize--;
                        if (paint.TextSize > icon.Height * ChicRatios.Get(20))
                        {
                            paint.TextSize--;
                        }
                    }
                }

                c.DrawText(text, x, y, namePaint);
            }
        }
示例#29
0
        public static void DrawChicFace(SKCanvas c, SKColor color, int x, int size = 128)
        {
            using (var path = SKPath.ParseSvgPathData(ChicData.ChicHeadPath))
                using (var b = new SKBitmap(320, 320))
                {
                    using (var ca = new SKCanvas(b))
                        using (var paint = new SKPaint {
                            FilterQuality = SKFilterQuality.High, IsAntialias = true, Color = color
                        })
                            ca.DrawPath(path, paint);

                    using (var shadow = SKImageFilter.CreateDropShadow(0, 0, 5, 5, SKColors.Black))
                        using (var paint = new SKPaint {
                            FilterQuality = SKFilterQuality.High, IsAntialias = true, ImageFilter = shadow
                        })
                            c.DrawBitmap(b, new SKRect(x, 0, size, size));
                }
        }
示例#30
0
        public static void DrawBackground(this SKCanvas canvas, SKRect rect, bool inset, double offsetX, double offsetY, double blurRadius, double spreadRadius, Xamarin.Forms.Color color)
        {
            Console.WriteLine($"shadow rect = {rect}, {offsetX}, {offsetY}");

            using (var paint = new SKPaint())
            {
                paint.Color       = SKColors.Blue;
                paint.ImageFilter = SKImageFilter.CreateDropShadow(
                    (float)offsetX,
                    (float)offsetY,
                    (float)blurRadius,
                    (float)blurRadius,
                    color.ToSK(),
                    SKDropShadowImageFilterShadowMode.DrawShadowAndForeground);

                rect.Inflate((float)spreadRadius, (float)spreadRadius);
                canvas.DrawRect(rect, paint);
            }
        }