Option Strict On
Option Explicit On

Imports SkiaSharp

Namespace Nexamas.UI.Rendering

    Friend NotInheritable Class MASSoftMistSurfaceMaterial
        Implements IMASSurfaceMaterial

        Public ReadOnly Property Id As String Implements IMASSurfaceMaterial.Id
            Get
                Return MASSurfaceMaterialIds.SoftMist
            End Get
        End Property

        Friend Sub Draw(canvas As SKCanvas,
                        context As MASSurfaceMaterialContext) Implements IMASSurfaceMaterial.Draw

            If canvas Is Nothing OrElse context Is Nothing Then Return

            Dim rectPx As SKRect = context.BoundsPx
            Dim radiusPx As Single = context.CornerRadiusPx
            If rectPx.Width <= 0.5F OrElse rectPx.Height <= 0.5F Then Return

            Dim palette As MASSurfaceMaterialPalette =
                MASSurfaceMaterialThemeResolver.Resolve(Me.Id, context)

            Dim rr As SKRoundRect = MASSurfaceMaterialPaintUtils.RoundRect(rectPx, radiusPx)

            Using shader As SKShader = SKShader.CreateLinearGradient(
                    New SKPoint(rectPx.Left, rectPx.Top),
                    New SKPoint(rectPx.Left, rectPx.Bottom),
                    New SKColor() {palette.Top, palette.Mid, palette.Bottom},
                    New Single() {0.0F, 0.58F, 1.0F},
                    SKShaderTileMode.Clamp),
                  p As New SKPaint With {.IsAntialias = True, .IsDither = True, .Style = SKPaintStyle.Fill, .Shader = shader}

                canvas.DrawRoundRect(rr, p)
            End Using

            Using washShader As SKShader = SKShader.CreateRadialGradient(
                    New SKPoint(rectPx.Left + rectPx.Width * 0.18F, rectPx.Top + rectPx.Height * 0.05F),
                    Math.Max(rectPx.Width, rectPx.Height) * 0.78F,
                    New SKColor() {palette.Glow, MASSurfaceMaterialPaintUtils.WithAlpha(palette.Glow, 0)},
                    New Single() {0.0F, 1.0F},
                    SKShaderTileMode.Clamp),
                  wash As New SKPaint With {.IsAntialias = True, .IsDither = True, .Style = SKPaintStyle.Fill, .Shader = washShader}

                canvas.DrawRoundRect(rr, wash)
            End Using
        End Sub

    End Class

End Namespace