': This program uses
': InForm - GUI library for QB64 - v1.2
': Fellippe Heitor, 2016-2020 - fellippe@qb64.org - @fellippeheitor
': https://github.com/FellippeHeitor/InForm
'-----------------------------------------------------------

': Controls' IDs: ------------------------------------------------------------------
DIM SHARED IQTest AS LONG
DIM SHARED ClickOnTheSTOPButtonBeforeTimeILB AS LONG
DIM SHARED STOPClickMeBT AS LONG
DIM SHARED ProgressBar1 AS LONG
DIM SHARED ProgressBar2 AS LONG
DIM SHARED PartialTimeLB AS LONG
DIM SHARED TotalTimeLB AS LONG
DIM SHARED tStatus AS INTEGER
': External modules: ---------------------------------------------------------------
'$INCLUDE:'InForm\InForm.ui'
'$INCLUDE:'InForm\xp.uitheme'
'$INCLUDE:'IQTest.frm'

': Event procedures: ---------------------------------------------------------------
SUB tt
    BEEP
    IF Control(ProgressBar2).Value >= 10 THEN
        BEEP
        Control(ProgressBar1).Value = Control(ProgressBar1).Value + 10
        Control(ProgressBar2).Value = 0
    ELSE
        Control(ProgressBar2).Value = Control(ProgressBar2).Value + 1
    END IF
    IF Control(ProgressBar1).Value >= 100 THEN
        _TITLE "BOOM!"
        Caption(STOPClickMeBT) = "TOO LATE!"
        TIMER OFF
        tStatus = False
    END IF
END SUB

SUB MoveButton
    Control(STOPClickMeBT).Left = __UI_MouseLeft + (RND * 100) + 50
    IF Control(STOPClickMeBT).Left > Control(IQTest).Width - Control(STOPClickMeBT).Width THEN Control(STOPClickMeBT).Left = 10
    Control(STOPClickMeBT).Top = __UI_MouseTop + (RND * 100) + 50
    IF Control(STOPClickMeBT).Top >= Control(IQTest).Height - Control(STOPClickMeBT).Height - 60 THEN Control(STOPClickMeBT).Top = 10
END SUB

SUB __UI_BeforeInit

END SUB

SUB __UI_OnLoad
    ON TIMER(1) tt
    TIMER ON
    tStatus = True
END SUB

SUB __UI_BeforeUpdateDisplay
    'This event occurs at approximately 30 frames per second.
    'You can change the update frequency by calling SetFrameRate DesiredRate%
    IF tStatus THEN
        IF _MOUSEINPUT THEN
            IF (__UI_MouseLeft < (Control(STOPClickMeBT).Left - 50)) OR (__UI_MouseLeft > (Control(STOPClickMeBT).Left + Control(STOPClickMeBT).Width + 50)) THEN
                IF (__UI_MouseTop > (Control(STOPClickMeBT).Top - 50)) OR (__UI_MouseTop < (Control(STOPClickMeBT).Top + Control(stopmeclickbt).Height + 50)) THEN
                    __UI_MouseEnter STOPClickMeBT 'MoveButton
                END IF
            END IF
        END IF
    END IF
END SUB

SUB __UI_BeforeUnload
    'If you set __UI_UnloadSignal = False here you can
    'cancel the user's request to close.

END SUB

SUB __UI_Click (id AS LONG)
    SELECT CASE id
        CASE IQTest

        CASE ClickOnTheSTOPButtonBeforeTimeILB

        CASE STOPClickMeBT
            IF Caption(STOPClickMeBT) = "TOO LATE!" THEN EXIT SUB
            ' the user wins
            _TITLE "YOU WIN!"
            TIMER OFF
            Caption(STOPClickMeBT) = "You GOT IT"
            tStatus = False
        CASE ProgressBar1

        CASE ProgressBar2

        CASE PartialTimeLB

        CASE TotalTimeLB

    END SELECT
END SUB

SUB __UI_MouseEnter (id AS LONG)
    SELECT CASE id
        CASE IQTest

        CASE ClickOnTheSTOPButtonBeforeTimeILB

        CASE STOPClickMeBT
            IF tStatus THEN MoveButton
        CASE ProgressBar1

        CASE ProgressBar2

        CASE PartialTimeLB

        CASE TotalTimeLB

    END SELECT
END SUB

SUB __UI_MouseLeave (id AS LONG)
    SELECT CASE id
        CASE IQTest

        CASE ClickOnTheSTOPButtonBeforeTimeILB

        CASE STOPClickMeBT

        CASE ProgressBar1

        CASE ProgressBar2

        CASE PartialTimeLB

        CASE TotalTimeLB

    END SELECT
END SUB

SUB __UI_FocusIn (id AS LONG)
    SELECT CASE id
        CASE STOPClickMeBT

    END SELECT
END SUB

SUB __UI_FocusOut (id AS LONG)
    'This event occurs right before a control loses focus.
    'To prevent a control from losing focus, set __UI_KeepFocus = True below.
    SELECT CASE id
        CASE STOPClickMeBT

    END SELECT
END SUB

SUB __UI_MouseDown (id AS LONG)
    SELECT CASE id
        CASE IQTest

        CASE ClickOnTheSTOPButtonBeforeTimeILB

        CASE STOPClickMeBT

        CASE ProgressBar1

        CASE ProgressBar2

        CASE PartialTimeLB

        CASE TotalTimeLB

    END SELECT
END SUB

SUB __UI_MouseUp (id AS LONG)
    SELECT CASE id
        CASE IQTest

        CASE ClickOnTheSTOPButtonBeforeTimeILB

        CASE STOPClickMeBT

        CASE ProgressBar1

        CASE ProgressBar2

        CASE PartialTimeLB

        CASE TotalTimeLB

    END SELECT
END SUB

SUB __UI_KeyPress (id AS LONG)
    'When this event is fired, __UI_KeyHit will contain the code of the key hit.
    'You can change it and even cancel it by making it = 0
    SELECT CASE id
        CASE STOPClickMeBT

    END SELECT
END SUB

SUB __UI_TextChanged (id AS LONG)
    SELECT CASE id
    END SELECT
END SUB

SUB __UI_ValueChanged (id AS LONG)
    SELECT CASE id
    END SELECT
END SUB

SUB __UI_FormResized

END SUB

