Public Class Form1

    Public Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Integer) As Integer
    Shared Sub Main(ByVal CmdArgs() As String)
        'MsgBox(CInt(2.6).ToString + vbNewLine + CInt(Math.Round(2.6, 0)).ToString)
        'End
        'Try
        Dim draw As New XDMD.Device(True, True)
        Application.DoEvents()
        'c2.Dispose()
        'Return
        'If Not IO.File.Exists(Application.StartupPath + "\uac.swf") Then End

        draw.PlayFlash(Application.StartupPath + "\uac.swf")

        Dim SurfArcade As New XDMD.Surface(Application.StartupPath + "\pinballx.png", draw)
        'Dim b As New Bitmap(128, CInt(32))
        'Dim g As Graphics = Graphics.FromImage(b)
        'g.Clear(Color.White)
        'g.Dispose()
        'Dim b2 As New Bitmap(b)
        'b2.Save(Application.StartupPath + "\white.png")
        'Dim SurfB As New XDMD.Surface(b, draw)
        'If Not b Is Nothing Then
        '    b.Dispose()
        '    b = Nothing
        'End If

        'SurfArcade.Draw(0, 0)
        'SurfArcade.Draw(-20, 12)
        'draw.Render()
        'draw.
        'Dim SurfScroll As New XDMD.Surface(70, 13, draw)
        'draw.PlayVideo(Application.StartupPath + "\test2.m4v", True, True, New Rectangle(0, -10, 128, 62), False)
        Dim TranLoop As Integer = -1

        Static col As Integer
        Static ColDbl As Double
        'draw.Clear(15)
        Dim f As New XDMD.Font(Application.StartupPath + "\Fonts\f7by13.gif", draw)
        'draw.TransitionDisplay(XDMD.Device.AnimationType.FillFadeIn, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_06)
        Dim x As Integer = 128
        'Dim
        Dim ColDir As Integer
        'draw.ManualRender = True
        'draw.ManualRender = True
        'draw.ManualRender = False

        ' MsgBox((-20 + 0.3).ToString)
        Dim score As Integer = 0
        Dim SurfVideo As XDMD.Surface = Nothing
        Do While 1 = 1
            'draw.DrawVideoFrame()
            'draw.DrawFlashFrame(New Rectangle(0, 0, 128, 32), 15)
            If GetAsyncKeyState(Keys.Escape) <> 0 Then
                Exit Do

            End If

            'If x > -550 Then
            '    x -= 1
            '    'draw.DrawVideoFrame()
            '    'SurfArcade.draw(-60, -60)
            '    'SurfScroll.Clear(16)
            '    'f.Draw(0, 0, 1, draw.TimeToDrawFrame.ToString)
            '    f.Draw(SurfScroll, x, 0, CInt(ColDbl), "Test TomTest Tom. The Quick Brown Fox Jumped over something")
            '    'SurfScroll.draw(New Rectangle(0, 0, CInt(SurfScroll.Width * 2), CInt(32)), New Rectangle(0, -3, CInt(SurfScroll.Width), CInt(22)))
            '    'f.Draw(0, 0, 32, 32, 15, draw.TimeToDrawFrame.ToString)
            'Else
            '    x -= 1
            '    '
            '    x = 128
            '    If x < -500 Then
            '        'x = 128
            '    End If
            'End If
            'SurfArcade.draw(New Rectangle(0, 0, 128, 32))
            If ColDir = 0 Then
                ColDbl += 1
                If CInt(ColDbl) > 15 Then
                    ColDir = 1
                    ColDbl = 15
                Else
                End If


            Else
                ColDbl -= 1
                If CInt(ColDbl) < 1 Then
                    ColDbl = 0
                    ColDir = 0
                End If
            End If
            'SurfB.draw(0, 0, CInt(ColDbl))
            'f.Draw(4, 6, 15, "Test TomTest Tom")
            If Not SurfVideo Is Nothing Then
                draw.DrawVideoFrame(SurfVideo, New Rectangle(0, 0, SurfVideo.Width, SurfVideo.Height))
            End If
            If draw.SurfaceFontTransitionState = XDMD.Device.PlayState.Ready Then
                '
                'draw.TransitionSurface(SurfArcade, New Rectangle(0, 0, 128, 32), XDMD.Device.AnimationType.FadeIn, XDMD.Device.AnimationType.ScrollOnLeft, XDMD.Device.AnimationSpeed.Speed_09, 160, XDMD.Device.AnimationType.None, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02)

                'draw.TransitionSurface(SurfArcade, New Rectangle(0, 0, 128, 32), XDMD.Device.AnimationType.FadeIn, XDMD.Device.AnimationType.ScrollOnDown, XDMD.Device.AnimationSpeed.Speed_03, 160, XDMD.Device.AnimationType.FadeOut, XDMD.Device.AnimationType.ZoomOut, XDMD.Device.AnimationSpeed.Speed_08)
                'draw.TransitionFont(f, "Test TomTest Tom. The Quick Brown Fox Jumped over something", 10, 7, XDMD.Device.AnimationType.FadeIn, XDMD.Device.AnimationType.ScrollOnLeft, XDMD.Device.AnimationSpeed.Speed_02, 0, XDMD.Device.AnimationType.ScrollOffLeft, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02)
                TranLoop += 1
                Select Case TranLoop
                    Case Is = 0
                        draw.TransitionSurface(SurfArcade, New Rectangle(0, 0, 128, 32), XDMD.Device.AnimationType.FadeIn, XDMD.Device.AnimationType.ScrollOnUp, XDMD.Device.AnimationSpeed.Speed_02, 0, XDMD.Device.AnimationType.None, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_03)
                        draw.TransitionSurface(SurfArcade, New Rectangle(0, 0, 128, 32), XDMD.Device.AnimationType.FadeIn, XDMD.Device.AnimationType.ScrollOnDown, XDMD.Device.AnimationSpeed.Speed_02, 120, XDMD.Device.AnimationType.ZoomOut, XDMD.Device.AnimationType.FadeOut, XDMD.Device.AnimationSpeed.Speed_03)
                        'draw.TransitionSurface(SurfArcade, New Rectangle(0, 0, 128, 32), XDMD.Device.AnimationType.FadeIn, XDMD.Device.AnimationType.ScrollOnDown, XDMD.Device.AnimationSpeed.Speed_09, 160, XDMD.Device.AnimationType.None, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02)
                        'draw.TransitionDisplay(XDMD.Device.AnimationType.ScrollOnDown, XDMD.Device.AnimationType.ScrollOnLeft, XDMD.Device.AnimationSpeed.Speed_01)
                        '    draw.TransitionSurface(SurfArcade, 30, 10, XDMD.Device.AnimationType.ScrollOnUp, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)
                        'draw.TransitionSurface(SurfB, 0, 0, XDMD.Device.AnimationType.ZoomIn, XDMD.Device.AnimationType.FadeIn, XDMD.Device.AnimationSpeed.Speed_01)
                        'draw.TransitionSurface(SurfArcade, -60, -60, XDMD.Device.AnimationType.ScrollOnDown, XDMD.Device.AnimationType.ScrollOnLeft, XDMD.Device.AnimationSpeed.Speed_01)
                    Case Is = 1
                        draw.TransitionFont(f, "Welcome to the XDMD Demo.", 10, 10, XDMD.Device.AnimationType.ScrollOnLeft, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02, 0, XDMD.Device.AnimationType.ScrollOffLeft, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02)
                        'draw.TransitionDisplay(XDMD.Device.AnimationType.FillFadeIn, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_08)
                        ' draw.TransitionSurface(SurfB, 0, 0, XDMD.Device.AnimationType.ZoomOut, XDMD.Device.AnimationType.ZoomOut, XDMD.Device.AnimationSpeed.Speed_01)
                        'draw.TransitionSurface(SurfArcade, 0, 0, XDMD.Device.AnimationType.FillFadeIn, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_09)
                    Case Is = 2
                        draw.PlayVideo(Application.StartupPath + "\invaders.mp4", True, False, New Rectangle(0, -10, 128, 62), False)
                        SurfVideo = New XDMD.Surface(128, CInt((128 / draw.VideoWidth) * (draw.VideoHeight)), draw)
                        draw.TransitionSurface(SurfVideo, New Rectangle(0, 0, 128, SurfVideo.Height), XDMD.Device.AnimationType.ScrollOnUp, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02, 0, XDMD.Device.AnimationType.ScrollOffUp, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02)
                        '
                    Case Is = 3
                      
                        draw.TransitionSurface(SurfVideo, New Rectangle(0, 0, 128, SurfVideo.Height), XDMD.Device.AnimationType.ScrollOnDown, XDMD.Device.AnimationType.ScrollOnLeft, XDMD.Device.AnimationSpeed.Speed_02, 0, XDMD.Device.AnimationType.FadeOut, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02)
                    Case Is = 4
                        draw.StopVideo()
                        SurfVideo.Dispose()
                        SurfVideo = Nothing
                        'draw.TransitionSurface(SurfArcade, 0, 0, XDMD.Device.AnimationType.FadeOut, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_09)
                        '# draw.TransitionDisplay(XDMD.Device.AnimationType.FillFadeOut, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)
                        'draw.TransitionSurface(SurfArcade, 0, 0, XDMD.Device.AnimationType.FillFadeOut, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)
                        '    draw.TransitionSurface(SurfArcade, 30, 10, XDMD.Device.AnimationType.ScrollOffUp, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)
                        'Case Is = 2
                        '    draw.TransitionSurface(SurfArcade, 30, 10, XDMD.Device.AnimationType.ScrollOnRight, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)
                        'Case Is = 3
                        '    draw.TransitionSurface(SurfArcade, 30, 10, XDMD.Device.AnimationType.ScrollOffRight, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)

                        'Case Is = 4
                        '    draw.TransitionSurface(SurfArcade, 30, 10, XDMD.Device.AnimationType.ScrollOnDown, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)

                        'Case Is = 5
                        '    draw.TransitionSurface(SurfArcade, 30, 10, XDMD.Device.AnimationType.ScrollOffDown, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)
                        'Case Is = 6
                        '    draw.TransitionSurface(SurfArcade, 30, 10, XDMD.Device.AnimationType.ScrollOnLeft, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)
                    Case Is = 5
                        draw.TransitionFont(f, "Text Fade.", 10, 10, XDMD.Device.AnimationType.FadeIn, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02, 0, XDMD.Device.AnimationType.FadeOut, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02)
                    Case Is = 6
                        draw.TransitionFont(f, "Zoom.", -18, 0, 32, 32, XDMD.Device.AnimationType.ZoomIn, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_02, 0, XDMD.Device.AnimationType.ZoomOut, XDMD.Device.AnimationType.FadeOut, XDMD.Device.AnimationSpeed.Speed_02)
                    Case Is = 7
                        score += 1
                        f.Draw(10, 10, 15, "Score: " + Microsoft.VisualBasic.Right("0000000000" + score.ToString, 6))
                        If score < 500 Then
                            TranLoop -= 1
                        Else
                            ColDbl = 0
                            ColDir = 0
                            score = 0
                        End If
                    Case Is = 8
                        Dim c As Integer = 15
                        score += 1
                        'If CInt(score / 2) = score / 2 Then
                        '    c = 14
                        '    'End
                        'End If
                        f.Draw(50, 10, CInt(ColDbl), "XDMD")
                        If score < 300 Then
                            TranLoop -= 1
                        Else
                            score = 0
                        End If
                    Case Else
                        score = 0
                        'draw.TransitionSurface(SurfArcade, 30, 10, XDMD.Device.AnimationType.ScrollOffLeft, XDMD.Device.AnimationType.None, XDMD.Device.AnimationSpeed.Speed_01)
                        TranLoop = -1
                End Select
            End If
            '
            'Threading.Thread.Sleep(3)
            'draw.NeedToRender = True
            'Threading.Thread.Sleep(9)
            'Do While draw.NeedToRender
            '    Threading.Thread.Sleep(1)
            '    'Application.DoEvents()

            'Loop

            draw.RenderWait()

            'draw.RenderWait(True)
            'Application.DoEvents()
         
            Application.DoEvents()
        Loop
        draw.Dispose()
        'MsgBox("")
        'Catch ex As Exception
        '    MsgBox(ex.Message)
        'End Try

    End Sub

    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

        'Me.Show()
        Me.Visible = False
        Return
        'Dim c As New XDMD.Video
        'c.SlowConvertBitmapTo4bppGray(New Bitmap(Application.StartupPath + "\star trek.png")).Save("gray2.png")
        'c.ConvertBitmaps(Application.StartupPath + "\test.png", System.Windows.Media.PixelFormats.Gray4).Save("Gray.png",Imaging.ImageFormat.)
        'Me.Show()
        'Me.Visible = False
        'Dim c2 As New XDMD.Device(True)
        'Return
        'If c.OpenVideo(Application.StartupPath + "\test.m4v", True) Then
        '    c.StartVideo()
        '    'c.Seek(500000)
        '    'Threading.Thread.Sleep(9000)
        '    Dim l As Integer
        '    Dim bmp As Bitmap = Nothing
        '    Dim cnt As Integer = 0
        '    Do While Me.Created
        '        Dim tstart As Integer = Environment.TickCount
        '        c.GrabFrame()
        '        Threading.Thread.Sleep(10)
        '        cnt += 1
        '        If cnt > 300 Then
        '            MsgBox(Environment.TickCount - tstart)
        '            cnt = 0
        '        End If
        '        'If Not bmp Is Nothing Then
        '        '    bmp.Dispose()
        '        'End If
        '        'bmp = New Bitmap(c.VidSize.width, c.VidSize.height)
        '        'Dim b3 As Integer
        '        'For y As Integer = 0 To c.VidSize.height - 1
        '        '    'Dim xx As Integer = 0
        '        '    For x As Integer = 0 To c.VidSize.width - 1
        '        '        l = (((c.VidSize.width * 3) * y) + (x * 3))
        '        '        '        If rgbValues(l) > 0 Then
        '        '        'b3 = CInt(((CInt(c.Buffer24Bit(l)) + +CInt(c.Buffer24Bit(l + 1)) + CInt(c.Buffer24Bit(l + 2))) / 3) / 1)
        '        '        b3 = c.Buffer(x + (y * c.VidSize.width))
        '        '        '            'If b3 > 255 Then b3 = 255
        '        '        Dim dc As System.Drawing.Color = System.Drawing.Color.FromArgb(255, b3, b3, b3)
        '        '        bmp.SetPixel(x, y, dc)
        '        '        'arr(x + (y * w)) = b3
        '        '        '        End If
        '        '        '        'xx += 4
        '        '    Next

        '        'Next

        '        'If Not Me.BackgroundImage Is Nothing Then
        '        '    BackgroundImage.Dispose()
        '        'End If
        '        'BackgroundImage = bmp

        '        Application.DoEvents()
        '    Loop




        'End If

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    End Sub

    Public Sub New()

        ' This call is required by the designer.
        InitializeComponent()

        ' Add any initialization after the InitializeComponent() call.
        'Dim c2 As New XDMD.XDMD(False, True)
        'Me.Visible = False
        'Dim c2 As New XDMD.XDMD(True)
        Return
    End Sub
End Class
