': This program uses
': InForm - GUI library for QB64 - Beta version 7
': Fellippe Heitor, 2016-2018 - fellippe@qb64.org - @fellippeheitor
': https://github.com/FellippeHeitor/InForm
'-----------------------------------------------------------
 
': Controls' IDs: ------------------------------------------------------------------
REM NOTICE: THIS FORM HAS BEEN RECENTLY EDITED
 '>> The controls in the list below may have been added or renamed,
'>> and previously existing controls may have been deleted since
'>> this program's structure was first generated.
'>> Make sure to check your code in the events SUBs so that
'>> you can take your recent edits into consideration.
': ---------------------------------------------------------------------------------
 
': External modules: ---------------------------------------------------------------
'$INCLUDE:'InForm\InForm.ui'
'$INCLUDE:'InForm\xp.uitheme'
'$INCLUDE:'GravitationSimulation.frm'
 
': Event procedures: ---------------------------------------------------------------
 
 
 
    '!!! Ought to be able to set these in UIEditor
    Control(BodyDataFR).Disabled = True
    Control(GravitationalCollapseFR).Disabled = True
    DispCalc` = True
    SetFrameRate Thirty%%
 
SUB __UI_BeforeUpdateDisplay
     'This event occurs at approximately 30 frames per second.
    'You can change the update frequency by calling SetFrameRate DesiredRate%
 
 
        '!!! Temp
        NoBodiesLess1% = 11
        DIM GlobalArray#
(NoBodiesLess1%
, 3)         GlobalArray#(0, 3) = 1
        GlobalArray#(1, 3) = 2
        GlobalArray#(0, 0) = 5
 
        'Use local array from global to display only >0 mass bodies in z-dimension order
        DIM LocalArray!
(NoBodiesLess1%
, 2)  
        NoVisible% = 0
        FOR N% 
= 0 TO NoBodiesLess1%
             IF GlobalArray#
(N%
, 3) <> 0 THEN                     LocalArray!(NoVisible%, M%%) = GlobalArray#(N%, M%%) '!!! Or whatever index value is correct
                NoVisible% = NoVisible% + 1
 
        'FOR N% = 0 TO NoVisible% - 1
        '    PRINT #1, N%, LocalArray!(N%, 0)
        'NEXT N%
        'PRINT #1, ""
 
 
            'Now order visible bodies
            'To order based upon z-dimension
            '!!! NB Here, x- is out of screen, y- is left to right, z_ is botton to top (old coordinate system)
            ' dblA#() is the array used here, not in the calculations routine
            Jump% = 1 'fio To order based upon x-distance: this doesn't seem to slowdown calculation too much.
            WHILE Jump% 
<= NoVisible% 
- 1: Jump% 
= Jump% 
* 2: 
WEND             'Have to do this every time as collisions change NoBodiesLess1%
                Jump% = (Jump% - 1) \ 2
                Finis` = False
                    Finis` = True
                    FOR Upper% 
= 0 TO NoVisible% 
- 1 - Jump%
                         Lower% = Upper% + Jump%
                        'IF dblA#(intKeep%(Upper%, 3), 1) > dblA#(intKeep%(Lower%, 3), 1) THEN
                        '    SWAP intKeep%(Upper%, 3), intKeep%(Lower%, 3)
                        '    Finis` = False
                        'END IF
                        IF LocalArray!
(Upper%
, 1) > LocalArray!
(Lower%
, 1) THEN                             SWAP LocalArray!
(Upper%
, 1), LocalArray!
(Lower%
, 1)                             Finis` = False
 
            BeginDraw PictureBox1 'Replace PictureBox1 with the actual ID of the desired PictureBox
            'Drawing code goes here
 
            CLS '!!! Need this if image is (software)  
            '_DISPLAYORDER _HARDWARE '!!! This doesn't work
 
            IF Caption
(CauseBT
) = "Cause" THEN                 '_MAPTRIANGLE (0, 0)-(260, 0)-(0, 253), Earth& TO(200, 200, -400)-(460, 0, -400)-(200, 453, -400) '261x254
                '!!! _MAPTRIANGLE(3D) doesn't work in InForm
            EndDraw PictureBox1
 
            '!!! Not enough bodies to carry on
            '!!! Or do we do this assessment elsewhere?
 
 
 
    'If you set __UI_UnloadSignal = False here you can
    'cancel the user's request to close.
 
 
        CASE GravitationSimulation
  
 
 
            IF Caption
(CauseBT
) = "Cause" THEN                 Caption(CauseBT) = "Effect"
                Control(SimulationTypeFR).Hidden = False
                Control(SimulationTypeFR).Disabled = False
                Caption(CauseBT) = "Cause"
 
 
            Control(SimulationTypeFR).Hidden = True
            Control(SimulationTypeFR).Disabled = True
            '!!! And other Frames
 
            DoCalc` = True
                A# = 2E24 * (3.6 ^ 5)
 
 
            'PRINT #1, Control(SolarSystemRB).Value
            'PRINT #1, Control(BodyManualRB).Value
            'PRINT #1, Control(GravitationalCollapseRB).Value
            'PRINT #1, Control(LoadFromFileRB).Value
            'PRINT #1, Control(DemonstrationRB).Value
 
            'Hidden/NotHidden 11-Body, GravitationalCollapse Input Forms
            IF Control
(BodyManualRB
).Value 
= True 
THEN                 Control(BodyDataFR).Hidden = False
                Control(BodyDataFR).Disabled = False
                Control(BodyDataFR).Hidden = True
                Control(BodyDataFR).Disabled = True
            IF Control
(GravitationalCollapseRB
).Value 
= True 
THEN                 Control(GravitationalCollapseFR).Hidden = False
                Control(GravitationalCollapseFR).Disabled = False
                Control(GravitationalCollapseFR).Hidden = True
                Control(GravitationalCollapseFR).Disabled = True
 
 
            IF Control
(BodyManualRB
).Value 
= True 
THEN                 Control(BodyDataFR).Hidden = False
                Control(BodyDataFR).Disabled = False
                Control(BodyDataFR).Hidden = True
                Control(BodyDataFR).Disabled = True
            IF Control
(GravitationalCollapseRB
).Value 
= True 
THEN                 Control(GravitationalCollapseFR).Hidden = False
                Control(GravitationalCollapseFR).Disabled = False
                Control(GravitationalCollapseFR).Hidden = True
                Control(GravitationalCollapseFR).Disabled = True
 
        CASE GravitationalCollapseRB
  
            IF Control
(BodyManualRB
).Value 
= True 
THEN                 Control(BodyDataFR).Hidden = False
                Control(BodyDataFR).Disabled = False
                Control(BodyDataFR).Hidden = True
                Control(BodyDataFR).Disabled = True
            IF Control
(GravitationalCollapseRB
).Value 
= True 
THEN                 Control(GravitationalCollapseFR).Hidden = False
                Control(GravitationalCollapseFR).Disabled = False
                Control(GravitationalCollapseFR).Hidden = True
                Control(GravitationalCollapseFR).Disabled = True
 
 
            IF Control
(BodyManualRB
).Value 
= True 
THEN                 Control(BodyDataFR).Hidden = False
                Control(BodyDataFR).Disabled = False
                Control(BodyDataFR).Hidden = True
                Control(BodyDataFR).Disabled = True
            IF Control
(GravitationalCollapseRB
).Value 
= True 
THEN                 Control(GravitationalCollapseFR).Hidden = False
                Control(GravitationalCollapseFR).Disabled = False
                Control(GravitationalCollapseFR).Hidden = True
                Control(GravitationalCollapseFR).Disabled = True
 
 
            IF Control
(BodyManualRB
).Value 
= True 
THEN                 Control(BodyDataFR).Hidden = False
                Control(BodyDataFR).Disabled = False
                Control(BodyDataFR).Hidden = True
                Control(BodyDataFR).Disabled = True
            IF Control
(GravitationalCollapseRB
).Value 
= True 
THEN                 Control(GravitationalCollapseFR).Hidden = False
                Control(GravitationalCollapseFR).Disabled = False
                Control(GravitationalCollapseFR).Hidden = True
                Control(GravitationalCollapseFR).Disabled = True
 
 
 
        CASE GravitationSimulation
  
 
        CASE GravitationSimulation
  
 
 
    'This event occurs right before a control loses focus.
    'To prevent a control from losing focus, set __UI_KeepFocus = True below.
 
        CASE GravitationSimulation
  
 
        CASE GravitationSimulation
  
 
    '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
 
 
 
 
        CASE GravitationalCollapseRB