Option Strict On
Option Explicit On

Imports SkiaSharp

Namespace Nexamas.UI.Rendering

    ''' <summary>
    ''' Flat attached shell-navigation material for MASMenuBar. It is registered as a
    ''' Surface Material so MenuBar chrome can resolve through the official material gateway
    ''' while keeping its color palette owned by ThemeSystem.
    ''' </summary>
    Friend NotInheritable Class MASMenuBarFlatSurfaceMaterial
        Implements IMASSurfaceMaterial

        Public ReadOnly Property Id As String Implements IMASSurfaceMaterial.Id
            Get
                Return MASSurfaceMaterialIds.MenuBarFlat
            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.46F, 1.0F},
                    SKShaderTileMode.Clamp),
                  fill As New SKPaint With {.IsAntialias = True, .IsDither = True, .Style = SKPaintStyle.Fill, .Shader = shader}

                canvas.DrawRoundRect(rr, fill)
            End Using

            If palette.Line.Alpha > 0 Then
                Using linePaint As New SKPaint With {
                    .IsAntialias = False,
                    .Style = SKPaintStyle.Stroke,
                    .StrokeWidth = 1.0F,
                    .Color = palette.Line
                }
                    canvas.DrawLine(rectPx.Left, rectPx.Bottom - 0.5F, rectPx.Right, rectPx.Bottom - 0.5F, linePaint)
                End Using
            End If
        End Sub

    End Class

End Namespace
