


Option Strict On
Option Explicit On

Imports System
Imports Nexamas.UI.Theming
Imports SkiaSharp

Namespace Nexamas.UI.Application

    ''' <summary>
    ''' Official rendering context exposed by MASApplicationWindow.Rendering events.
    ''' It gives application code the information needed for custom drawing without exposing ThemeHost/ThemeContext as the beginner entry point.
    ''' </summary>
    <Global.System.ComponentModel.EditorBrowsable(Global.System.ComponentModel.EditorBrowsableState.Advanced)>
    Friend NotInheritable Class MASApplicationRenderContext

        Private ReadOnly _canvas As SKCanvas
        Private ReadOnly _info As SKImageInfo
        Private ReadOnly _ctx As MASThemeContext

        Friend Sub New(canvas As SKCanvas, info As SKImageInfo, ctx As MASThemeContext)
            _canvas = canvas
            _info = info
            _ctx = ctx
        End Sub

        Friend ReadOnly Property Canvas As SKCanvas
            Get
                Return _canvas
            End Get
        End Property

        Friend ReadOnly Property ImageInfo As SKImageInfo
            Get
                Return _info
            End Get
        End Property

        Friend ReadOnly Property WidthPx As Integer
            Get
                Return _info.Width
            End Get
        End Property

        Friend ReadOnly Property HeightPx As Integer
            Get
                Return _info.Height
            End Get
        End Property

        Friend ReadOnly Property BoundsPx As SKRect
            Get
                Return New SKRect(0.0F, 0.0F, CSng(Math.Max(0, _info.Width)), CSng(Math.Max(0, _info.Height)))
            End Get
        End Property

        Friend ReadOnly Property Dpi As Single
            Get
                If _ctx Is Nothing Then Return 1.0F
                Return _ctx.Dpi
            End Get
        End Property

        Friend ReadOnly Property Theme As IMASAppTheme
            Get
                If _ctx Is Nothing Then Return Nothing
                Return _ctx.Theme
            End Get
        End Property

        Friend ReadOnly Property ThemeId As String
            Get
                Dim currentTheme As IMASAppTheme = Theme
                If currentTheme Is Nothing Then Return String.Empty
                Return currentTheme.Id
            End Get
        End Property

        Friend Function HasCanvas() As Boolean
            Return _canvas IsNot Nothing
        End Function

        Friend ReadOnly Property ThemeContext As MASThemeContext
            Get
                Return _ctx
            End Get
        End Property
    End Class

End Namespace
