' SSOT-V2 Signature: This class/file follows the SSOT-V2 architecture.
Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Architecture
Imports Nexamas.UI.General
Imports Nexamas.UI.Theming
Imports Nexamas.UI.Values
Imports SkiaSharp

Namespace Nexamas.UI.Rendering

    Partial Friend NotInheritable Class MASVisualPrimitivesPainter

#Region "Combo/Input Helpers: Chevron"

        Friend Shared Function ComputeChevronDownGlyphRect(rBase As SKRect,
                                                           dpi As Single) As SKRect

            dpi = PixelSnap.SafeDpi(dpi)

            Dim arrowW As Single = (InputTokens.IconSize + InputTokens.IconGap) * dpi
            Dim arrowR As New SKRect(rBase.Right - arrowW, rBase.Top, rBase.Right, rBase.Bottom)

            Dim g As Single = InputTokens.IconSize * dpi

            Return New SKRect(
                arrowR.MidX - g / 2.0F,
                arrowR.MidY - g / 2.0F,
                arrowR.MidX + g / 2.0F,
                arrowR.MidY + g / 2.0F)

        End Function

        Friend Sub DrawChevronDown_Nice(canvas As SKCanvas,
                                        ctx As MASThemeContext,
                                        glyphRect As SKRect,
                                        dpi As Single,
                                        isDisabled As Boolean)

            If _disposed Then Return
            If canvas Is Nothing OrElse ctx Is Nothing Then Return
            If glyphRect.Width <= 1 OrElse glyphRect.Height <= 1 Then Return

            dpi = PixelSnap.SafeDpi(dpi)

            Dim th As IMASInputTheme = ctx.InputTheme
            If th Is Nothing Then Return

            Dim col As SKColor = If(isDisabled, th.Text.Disabled, th.Text.Normal)
            If Not isDisabled AndAlso col.Alpha > 220 Then col = col.WithAlpha(220)

            Dim insetX As Single = InputTokens.IconGap * dpi * 0.6F
            Dim insetY As Single = InputTokens.IconGap * dpi * 0.7F

            Dim xL As Single = glyphRect.Left + insetX
            Dim xR As Single = glyphRect.Right - insetX
            Dim xM As Single = glyphRect.MidX

            Dim yTop As Single = glyphRect.Top + insetY
            Dim yBot As Single = glyphRect.Bottom - insetY * 0.85F

            Dim stroke As Single = Math.Max(InputTokens.ChevronStroke * dpi, 1.0F)

            Using p As New SKPaint With {
                .IsAntialias = True,
                .IsDither = True,
                .Style = SKPaintStyle.Stroke,
                .StrokeCap = SKStrokeCap.Round,
                .StrokeJoin = SKStrokeJoin.Round,
                .StrokeWidth = stroke,
                .Color = col
            }
                Using path As New SKPath()
                    path.MoveTo(xL, yTop)
                    path.LineTo(xM, yBot)
                    path.LineTo(xR, yTop)
                    canvas.DrawPath(path, p)
                End Using
            End Using

        End Sub

#End Region



    End Class

End Namespace
