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 MASShadowPainter

        Implements IDisposable

        Private _disposed As Boolean

        Private ReadOnly _buildFill As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True,
            .Style = SKPaintStyle.Fill
        }

        Private ReadOnly _haloPaint As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True,
            .Style = SKPaintStyle.Stroke,
            .StrokeJoin = SKStrokeJoin.Round,
            .StrokeCap = SKStrokeCap.Round
        }

        Private ReadOnly _tmpFill As New SKPaint With {
            .IsAntialias = True,
            .IsDither = True,
            .Style = SKPaintStyle.Fill
        }

        Private _img As SKImage = Nothing
        Private _pad As Integer = 0
        Private _offsetY As Integer = 0

        Private _lastW As Integer = -1
        Private _lastH As Integer = -1
        Private _lastDpi100 As Integer = -1
        Private _lastRadius100 As Integer = -1
        Private _lastBase As SKColor = Nothing
        Private _lastSigma100 As Integer = -1
        Private _lastOffY100 As Integer = -1
        Private _lastAlpha As Integer = -1

        Private _layerImg As SKImage = Nothing
        Private _layerPad As Integer = 0
        Private _layerOffsetY As Integer = 0

        Private _layerLastW As Integer = -1
        Private _layerLastH As Integer = -1
        Private _layerLastDpi100 As Integer = -1
        Private _layerLastRadius100 As Integer = -1
        Private _layerLastBase As SKColor = Nothing
        Private _layerLastSigA100 As Integer = -1
        Private _layerLastOffA100 As Integer = -1
        Private _layerLastAlA As Integer = -1
        Private _layerLastSigB100 As Integer = -1
        Private _layerLastOffB100 As Integer = -1
        Private _layerLastAlB As Integer = -1

        Private _cardImg As SKImage = Nothing
        Private _cardPad As Integer = 0
        Private _cardOffsetY As Integer = 0

        Private _cardLastW As Integer = -1
        Private _cardLastH As Integer = -1
        Private _cardLastDpi100 As Integer = -1
        Private _cardLastRadius100 As Integer = -1
        Private _cardLastBase As SKColor = Nothing
        Private _cardLastSigA100 As Integer = -1
        Private _cardLastOffA100 As Integer = -1
        Private _cardLastAlA As Integer = -1
        Private _cardLastSigB100 As Integer = -1
        Private _cardLastOffB100 As Integer = -1
        Private _cardLastAlB As Integer = -1

        Public Sub Dispose() Implements IDisposable.Dispose
            If _disposed Then Return
            _disposed = True

            SafeDisposeImage(_img)
            SafeDisposeImage(_layerImg)
            SafeDisposeImage(_cardImg)

            Try
                _buildFill.Dispose()
            Catch masCaughtException1 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowRenderFallback(masCaughtException1)
            End Try
            Try
                _haloPaint.Dispose()
            Catch masCaughtException2 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowRenderFallback(masCaughtException2)
            End Try
            Try
                _tmpFill.Dispose()
            Catch masCaughtException3 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowRenderFallback(masCaughtException3)
            End Try
        End Sub

    End Class

End Namespace
