Imports Microsoft.VisualBasic
Imports System
Imports System.Security.Permissions
Imports Microsoft.Win32

Public Class Form1
    Public mButton As Boolean
    Dim mox As Integer
    Dim moy As Integer
    Public ScreenWidth As Integer = Screen.PrimaryScreen.WorkingArea.Width
    Public ScreenHeight As Integer = Screen.PrimaryScreen.WorkingArea.Height
    Public Shared LightColorH As System.Drawing.Color = ColorTranslator.FromOle(RGB(254, 245, 254))
    Public Shared LightColorS As System.Drawing.Color = ColorTranslator.FromOle(RGB(200, 200, 200))
    Public ShowColor(10) As System.Drawing.Color
    Public Shared DarkColorH As System.Drawing.Color = ColorTranslator.FromOle(RGB(10, 10, 100))
    Public Shared DarkColorS As System.Drawing.Color = ColorTranslator.FromOle(RGB(15, 15, 105))
    Public HideColor(10) As System.Drawing.Color
    Public TaskBarTop As Integer = Screen.PrimaryScreen.WorkingArea.Bottom
    Public OldImage(10) As System.Drawing.Image
    Public BImage As System.Drawing.Image
    Public buttontoggle(10) As Integer
    Public Stage(10) As Form2
    Public SeeStage(10) As Boolean
    Public ColorHide As System.Drawing.Color
    Public vgReg As Microsoft.Win32.RegistryKey
    Public REGSZ As String
    Public REGDword As Int32
    Public StageName As String ' Name of Stage to save or Load

    Private Sub Form1_FormClosing(sender As Object, e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        'Form2.Hide()
    End Sub

    Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
        For i = 1 To 10
            buttontoggle(i) = -1
            Stage(i) = New Form2
            Stage(i).Show()
            Stage(i).Visible = True
            SeeStage(i) = True
            ShowColor(i) = LightColorS
            HideColor(i) = LightColorH
            Stage(i).Top = i * 40
            Stage(i).Left = i * 50
            Stage(i).Width = 100
            Stage(i).Height = 4
            Stage(i).BackColor = HideColor(i)
            Stage(i).TransparencyKey = ShowColor(i)
        Next
        ColorHide = LightColorH
        mButton = False
        buttontoggle(1) = 1
        BImage = My.Resources.Chrome_ball_On
        B1.BackgroundImage = BImage
        Hsize.Maximum = ScreenWidth + 100
        Vsize.Maximum = ScreenHeight + 100
        Me.Left = ScreenWidth - Me.Width
        Me.Top = TaskBarTop - Me.Height
    End Sub

    Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
        For i = 1 To 10
            If buttontoggle(i) = 1 Then
                Stage(i).Show()
                Stage(i).Visible = True
                Stage(i).TransparencyKey = ShowColor(i)
                SeeStage(i) = True
            End If
        Next
    End Sub

    Private Sub Button2_Click(sender As System.Object, e As System.EventArgs) Handles Button2.Click
        For i = 1 To 10
            If buttontoggle(i) = 1 Then
                Stage(i).TransparencyKey = HideColor(i)
                SeeStage(i) = False
            End If
        Next
    End Sub
    Private Sub Button3_Click(sender As System.Object, e As System.EventArgs) Handles Button3.Click
        For i = 1 To 10
            If buttontoggle(i) = 1 Then
                Stage(i).Visible = False
                Stage(i).Hide()
            End If
        Next
    End Sub

    Private Sub Button5_Click(sender As System.Object, e As System.EventArgs) Handles Button5.Click
        Me.WindowState = FormWindowState.Minimized
    End Sub

    Private Sub Button6_Click(sender As System.Object, e As System.EventArgs) Handles Button6.Click
        Me.Close()
    End Sub

    Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseDown
        mButton = True
        mox = e.X
        moy = e.Y
    End Sub

    Private Sub Form1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseMove
        Dim mpx As Integer
        Dim mpy As Integer
        Dim newx As Integer
        Dim newy As Integer
        If mButton = True Then
            mpx = MousePosition.X
            mpy = MousePosition.Y
            newx = mpx - mox
            newy = mpy - moy
            'If MouseButtons = Windows.Forms.MouseButtons.Left Then
            'MsgBox(Me.Left & "   " & MousePosition.X & "    " & e.X & "     " & MousePosition.X - e.X)

            Me.Left = newx
            Me.Top = newy
            'End If
        End If
    End Sub

    Private Sub Form1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles Me.MouseUp
        mButton = False
    End Sub

    Private Sub Timer1_Tick(sender As System.Object, e As System.EventArgs) Handles Timer1.Tick
        If Me.WindowState = FormWindowState.Normal Then
            'Form2.Top = Me.Top - 10
            'Form2.Left = Me.Left - 20
        End If
    End Sub

    Private Sub Hsize_Scroll(sender As System.Object, e As System.Windows.Forms.ScrollEventArgs) Handles Hsize.Scroll
        For i = 1 To 10
            If buttontoggle(i) = 1 Then
                Stage(i).Width = Hsize.Value
            End If
        Next
    End Sub

    Private Sub Vsize_Scroll(sender As System.Object, e As System.Windows.Forms.ScrollEventArgs) Handles Vsize.Scroll
        For i = 1 To 10
            If buttontoggle(i) = 1 Then
                Stage(i).Height = Vsize.Value
            End If
        Next


    End Sub

    Private Sub NotifyIcon1_MouseDoubleClick(sender As System.Object, e As System.Windows.Forms.MouseEventArgs) Handles NotifyIcon1.MouseDoubleClick
        If Me.WindowState = FormWindowState.Minimized Then
            Me.WindowState = FormWindowState.Normal
            'Me.Left = ScreenWidth - Me.Width
            'Me.Top = TaskBarTop - Me.Height
        End If
    End Sub

    Private Sub B1_Click(sender As System.Object, e As System.EventArgs) Handles B1.Click, B7.Click, B10.Click, B5.Click, B3.Click, B2.Click, B4.Click, B6.Click, B8.Click, B9.Click
        Call BButon_Click(sender, e)
    End Sub

    Private Sub B1_MouseDown(sender As Object, e As System.Windows.Forms.MouseEventArgs) Handles B1.MouseDown, B7.MouseDown, B10.MouseDown, B5.MouseDown, B3.MouseDown, B2.MouseDown, B4.MouseDown, B6.MouseDown, B8.MouseDown, B9.MouseDown
        Call BButon_Down(sender, e)
    End Sub

    Private Sub B1_MouseEnter(sender As Object, e As System.EventArgs) Handles B1.MouseEnter, B7.MouseEnter, B10.MouseEnter, B5.MouseEnter, B3.MouseEnter, B2.MouseEnter, B4.MouseEnter, B6.MouseEnter, B8.MouseEnter, B9.MouseEnter
        Call BButon_Enter(sender, e)
    End Sub

    Private Sub B1_MouseLeave(sender As Object, e As System.EventArgs) Handles B1.MouseLeave, B7.MouseLeave, B10.MouseLeave, B5.MouseLeave, B3.MouseLeave, B2.MouseLeave, B4.MouseLeave, B6.MouseLeave, B8.MouseLeave, B9.MouseLeave
        Call BButon_Leave(sender, e)
    End Sub

    Private Sub BButon_Click(sender As Object, e As System.EventArgs)
        'MsgBox(sender.name)
        Dim b As Integer = 0
        Dim BImage As System.Drawing.Image
        Select Case sender.name
            Case "B1"
                b = 1
            Case "B2"
                b = 2
            Case "B3"
                b = 3
            Case "B4"
                b = 4
            Case "B5"
                b = 5
            Case "B6"
                b = 6
            Case "B7"
                b = 7
            Case "B8"
                b = 8
            Case "B9"
                b = 9
            Case "B10"
                b = 10
        End Select
        If buttontoggle(b) = -1 Then
            BImage = My.Resources.Chrome_ball_On
            Select Case sender.name
                Case "B1"
                    B1.BackgroundImage = BImage
                Case "B2"
                    B2.BackgroundImage = BImage
                Case "B3"
                    B3.BackgroundImage = BImage
                Case "B4"
                    B4.BackgroundImage = BImage
                Case "B5"
                    B5.BackgroundImage = BImage
                Case "B6"
                    B6.BackgroundImage = BImage
                Case "B7"
                    B7.BackgroundImage = BImage
                Case "B8"
                    B8.BackgroundImage = BImage
                Case "B9"
                    B9.BackgroundImage = BImage
                Case "B10"
                    B10.BackgroundImage = BImage
            End Select
        Else
            BImage = My.Resources.Chrome_ball_Off
            Select Case sender.name
                Case "B1"
                    B1.BackgroundImage = BImage
                Case "B2"
                    B2.BackgroundImage = BImage
                Case "B3"
                    B3.BackgroundImage = BImage
                Case "B4"
                    B4.BackgroundImage = BImage
                Case "B5"
                    B5.BackgroundImage = BImage
                Case "B6"
                    B6.BackgroundImage = BImage
                Case "B7"
                    B7.BackgroundImage = BImage
                Case "B8"
                    B8.BackgroundImage = BImage
                Case "B9"
                    B9.BackgroundImage = BImage
                Case "B10"
                    B10.BackgroundImage = BImage
            End Select
        End If
        buttontoggle(b) = buttontoggle(b) * -1
        Select Case sender.name
            Case "B1"
                OldImage(b) = B1.BackgroundImage
            Case "B2"
                OldImage(b) = B2.BackgroundImage
            Case "B3"
                OldImage(b) = B3.BackgroundImage
            Case "B4"
                OldImage(b) = B4.BackgroundImage
            Case "B5"
                OldImage(b) = B5.BackgroundImage
            Case "B6"
                OldImage(b) = B6.BackgroundImage
            Case "B7"
                OldImage(b) = B7.BackgroundImage
            Case "B8"
                OldImage(b) = B8.BackgroundImage
            Case "B9"
                OldImage(b) = B9.BackgroundImage
            Case "B10"
                OldImage(b) = B10.BackgroundImage
        End Select
    End Sub

    Private Sub BButon_Down(sender As Object, e As System.EventArgs)
        'MsgBox(sender.name)
        Dim b As Integer = 0
        Dim BImage As System.Drawing.Image
        BImage = My.Resources.Chrome_ball_Down
        Select Case sender.name
            Case "B1"
                B1.BackgroundImage = BImage
            Case "B2"
                B2.BackgroundImage = BImage
            Case "B3"
                B3.BackgroundImage = BImage
            Case "B4"
                B4.BackgroundImage = BImage
            Case "B5"
                B5.BackgroundImage = BImage
            Case "B6"
                B6.BackgroundImage = BImage
            Case "B7"
                B7.BackgroundImage = BImage
            Case "B8"
                B8.BackgroundImage = BImage
            Case "B9"
                B9.BackgroundImage = BImage
            Case "B10"
                B10.BackgroundImage = BImage
        End Select
    End Sub

    Private Sub BButon_Enter(sender As Object, e As System.EventArgs)
        'MsgBox(sender.name)
        Dim b As Integer = 0
        Dim BImage As System.Drawing.Image
        Select Case sender.name
            Case "B1"
                b = 1
            Case "B2"
                b = 2
            Case "B3"
                b = 3
            Case "B4"
                b = 4
            Case "B5"
                b = 5
            Case "B6"
                b = 6
            Case "B7"
                b = 7
            Case "B8"
                b = 8
            Case "B9"
                b = 9
            Case "B10"
                b = 10
        End Select
        Select Case sender.name
            Case "B1"
                OldImage(b) = B1.BackgroundImage
            Case "B2"
                OldImage(b) = B2.BackgroundImage
            Case "B3"
                OldImage(b) = B3.BackgroundImage
            Case "B4"
                OldImage(b) = B4.BackgroundImage
            Case "B5"
                OldImage(b) = B5.BackgroundImage
            Case "B6"
                OldImage(b) = B6.BackgroundImage
            Case "B7"
                OldImage(b) = B7.BackgroundImage
            Case "B8"
                OldImage(b) = B8.BackgroundImage
            Case "B9"
                OldImage(b) = B9.BackgroundImage
            Case "B10"
                OldImage(b) = B10.BackgroundImage
        End Select

        BImage = My.Resources.Chrome_ball_Hover
        Select Case sender.name
            Case "B1"
                B1.BackgroundImage = BImage
            Case "B2"
                B2.BackgroundImage = BImage
            Case "B3"
                B3.BackgroundImage = BImage
            Case "B4"
                B4.BackgroundImage = BImage
            Case "B5"
                B5.BackgroundImage = BImage
            Case "B6"
                B6.BackgroundImage = BImage
            Case "B7"
                B7.BackgroundImage = BImage
            Case "B8"
                B8.BackgroundImage = BImage
            Case "B9"
                B9.BackgroundImage = BImage
            Case "B10"
                B10.BackgroundImage = BImage
        End Select
        If SeeStage(b) = False Then
            Stage(b).TransparencyKey = ShowColor(b)
        End If
    End Sub

    Private Sub BButon_Leave(sender As Object, e As System.EventArgs)
        'MsgBox(sender.name)
        Dim b As Integer = 0
        Dim BImage As System.Drawing.Image
        Select Case sender.name
            Case "B1"
                b = 1
            Case "B2"
                b = 2
            Case "B3"
                b = 3
            Case "B4"
                b = 4
            Case "B5"
                b = 5
            Case "B6"
                b = 6
            Case "B7"
                b = 7
            Case "B8"
                b = 8
            Case "B9"
                b = 9
            Case "B10"
                b = 10
        End Select
        BImage = OldImage(b)
        Select Case sender.name
            Case "B1"
                B1.BackgroundImage = BImage
            Case "B2"
                B2.BackgroundImage = BImage
            Case "B3"
                B3.BackgroundImage = BImage
            Case "B4"
                B4.BackgroundImage = BImage
            Case "B5"
                B5.BackgroundImage = BImage
            Case "B6"
                B6.BackgroundImage = BImage
            Case "B7"
                B7.BackgroundImage = BImage
            Case "B8"
                B8.BackgroundImage = BImage
            Case "B9"
                B9.BackgroundImage = BImage
            Case "B10"
                B10.BackgroundImage = BImage
        End Select
        If SeeStage(b) = False Then
            Stage(b).TransparencyKey = HideColor(b)
        End If

    End Sub

    Private Sub RBLight_Click(sender As System.Object, e As System.EventArgs) Handles RBLight.Click, RBDark.Click
        ' clicking on the Light or Dark buton should also work the 2nd time it is cliked, not just when it is changed.
        RBLight_CheckedChanged(sender, e)
    End Sub

    Private Sub RBLight_CheckedChanged(sender As System.Object, e As System.EventArgs) Handles RBLight.CheckedChanged, RBDark.CheckedChanged
        ' change the stage colors to match the color that was clicked on.
        Try
            For i = 1 To 10
                If buttontoggle(i) = 1 Then
                    If RBLight.Checked = True Then
                        ShowColor(i) = LightColorS
                        HideColor(i) = LightColorH
                        ColorHide = LightColorH
                    Else
                        ShowColor(i) = DarkColorS
                        HideColor(i) = DarkColorH
                        ColorHide = DarkColorH
                    End If

                    Stage(i).BackColor = HideColor(i)
                    If SeeStage(i) = False Then
                        Stage(i).TransparencyKey = HideColor(i)
                    Else
                        Stage(i).TransparencyKey = ShowColor(i)
                    End If
                End If
            Next
        Catch
        End Try

    End Sub

    Public Sub FixSeeStage3()
        Try
            For i = 1 To 10
                If Stage(i).TransparencyKey = ColorHide Then
                    HideColor(i) = ColorHide
                    If ColorHide = LightColorH Then
                        ShowColor(i) = LightColorS
                    Else
                        ShowColor(i) = DarkColorS
                    End If
                    SeeStage(i) = False
                End If
            Next
        Catch
        End Try
    End Sub

    Public Sub FixSeeStage()
        ' after a right click to hide a stage
        ' fix the tracking variables to prevent phantom stages.
        Try
            For i = 1 To 10
                'test if set to light hidden color
                'if yes - make sure it's Hidecolor(i) and ShowColor(i) is set to Light
                'and the it's seeStage(i) is false
                If Stage(i).TransparencyKey = LightColorH Then
                    HideColor(i) = LightColorH
                    ShowColor(i) = LightColorS
                    SeeStage(i) = False
                End If
                'test if set to Dark hidden color
                'if yes - make sure it's Hidecolor(i) and ShowColor(i) is set to Dark
                'and the it's seeStage(i) is false
                If Stage(i).TransparencyKey = DarkColorH Then
                    HideColor(i) = DarkColorH
                    ShowColor(i) = DarkColorS
                    SeeStage(i) = False
                End If
                'test if set to light Show color
                'if yes - make sure it's Hidecolor(i) and ShowColor(i) is set to Light
                'and the it's seeStage(i) is True
                If Stage(i).TransparencyKey = LightColorS Then
                    HideColor(i) = LightColorH
                    ShowColor(i) = LightColorS
                    SeeStage(i) = True
                End If
                'test if set to Dark Show color
                'if yes - make sure it's Hidecolor(i) and ShowColor(i) is set to Dark
                'and the it's seeStage(i) is True
                If Stage(i).TransparencyKey = DarkColorS Then
                    HideColor(i) = DarkColorH
                    ShowColor(i) = DarkColorS
                    SeeStage(i) = True
                End If
            Next
        Catch
        End Try
    End Sub


    Private Sub Button7_Click(sender As System.Object, e As System.EventArgs) Handles Button7.Click
        '        save stage settings to the registry
        '		 Registry use
        '        Dim vgReg As Microsoft.Win32.RegistryKey
        '
        '        UserPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData)
        '        MusicFile = UserPath & "\My VGMusic\random.vgm"
        '        vgReg = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\VGMusic")
        '        vgReg.SetValue("MusicFile", MusicFile)
        '        vgReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Totem\vghd\System")
        '        modelsPath = vgReg.GetValue("ModelsPath", "Not found")
        '        dataPath = vgReg.GetValue("DataPath", "No file found")
        '        vgReg = Microsoft.Win32.Registry.CurrentUser.OpenSubKey("Software\Totem\vghd\DLM")
        '        VGusername = vgReg.GetValue("username", "Not found")
        '        VGkey = vgReg.GetValue("key", "No file found")
        '        VGinstallid = vgReg.GetValue("installid", "No file found")
        '        VGuserkey = vgReg.GetValue("userkey", "No file found")
        Try
            StageName = "hjdf $#@& -+_{}[]\|~!@#$%^&*()"
            vgReg = Microsoft.Win32.Registry.CurrentUser.CreateSubKey("Software\VirtuaStage\Stages\" & StageName)
            For i = 1 To 10
                vgReg.SetValue("StageWidth" & i, Stage(i).Width)
                vgReg.SetValue("StageHeight" & i, Stage(i).Height)
                vgReg.SetValue("StageTop" & i, Stage(i).Top)
                vgReg.SetValue("StageLeft" & i, Stage(i).Left)
                vgReg.SetValue("StageBackColor" & i, Stage(i).BackColor)
                vgReg.SetValue("StageTransparencyKey" & i, Stage(i).TransparencyKey)
                vgReg.SetValue("StageHideColor" & i, HideColor(i))
                vgReg.SetValue("StageShowColor" & i, ShowColor(i))
                vgReg.SetValue("StageIsSeen" & i, SeeStage(i))
                vgReg.SetValue("StageOpen" & i, Stage(i).Visible)

            Next
        Catch
            MsgBox("Error during save")
        End Try

    End Sub





End Class