Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Rendering

Namespace Nexamas.UI.TextInput

    ''' <summary>
    ''' Owns renderer and painter instances used by MASInputBoxSkiaBase.
    ''' </summary>
    ''' <remarks>
    ''' Rendering resources are long-lived collaborators with disposal requirements.
    ''' Keeping them behind this aggregate prevents the public control base from
    ''' directly owning every painter/renderer object and keeps disposal centralized.
    ''' </remarks>
    Friend NotInheritable Class MASTextInputRenderResources
        Implements IDisposable

#Region "Fields"

        Private ReadOnly _surface As New MASVisualPrimitivesPainter()
        Private ReadOnly _shadow As New MASShadowPainter()
        Private ReadOnly _caret As New MASTextCaretEngine()
        Private ReadOnly _singleLineRenderer As New MASTextInputRenderer()
        Private ReadOnly _multilineRenderer As New MASTextMultilineRenderer()
        Private ReadOnly _styledRenderer As New MASTextInputStyledRenderer()
        Private ReadOnly _multilineStyledRenderer As New MASTextMultilineStyledRenderer()
        Private ReadOnly _textPaintCache As New MASTextInputOwnedPaintCache()

        Private _disposed As Boolean

#End Region

#Region "Properties"

        Friend ReadOnly Property Surface As MASVisualPrimitivesPainter
            Get
                Return _surface
            End Get
        End Property

        Friend ReadOnly Property Shadow As MASShadowPainter
            Get
                Return _shadow
            End Get
        End Property

        Friend ReadOnly Property Caret As MASTextCaretEngine
            Get
                Return _caret
            End Get
        End Property

        Friend ReadOnly Property SingleLineRenderer As MASTextInputRenderer
            Get
                Return _singleLineRenderer
            End Get
        End Property

        Friend ReadOnly Property MultilineRenderer As MASTextMultilineRenderer
            Get
                Return _multilineRenderer
            End Get
        End Property

        Friend ReadOnly Property StyledRenderer As MASTextInputStyledRenderer
            Get
                Return _styledRenderer
            End Get
        End Property

        Friend ReadOnly Property MultilineStyledRenderer As MASTextMultilineStyledRenderer
            Get
                Return _multilineStyledRenderer
            End Get
        End Property

        Friend ReadOnly Property TextPaintCache As MASTextInputOwnedPaintCache
            Get
                Return _textPaintCache
            End Get
        End Property

#End Region

#Region "Dispose"

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

            Try
                _shadow.Dispose()
            Catch masCaughtException1 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowRenderFallback(masCaughtException1)
            End Try

            Try
                _surface.Dispose()
            Catch masCaughtException2 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowRenderFallback(masCaughtException2)
            End Try

            Try
                _textPaintCache.Dispose()
            Catch masCaughtException3 As Exception
                Nexamas.UI.Diagnostics.MASExceptionSilencer.SwallowRenderFallback(masCaughtException3)
            End Try
        End Sub

#End Region

    End Class

End Namespace
