Process POPUP.MENU
''
'' COPYRIGHT (C) 1996, CACI Products Company.
'' AUTHOR: Steve Bailey
'' DATE: 12-9-96
'' DESCRIPTION:
''     This process controls an asyncronous mouse.  This process will be 
''     suspended inside the READLOC.R (style 16) call.  The process wakes up
''     when the mouse is clicked inside a window.  At this time the popup menu
''     can be brought up.  The specific popup menu is determined by where
''     the mouse was clicked.
''

define X, Y as double variables
define VXFORM as an integer variable
define POPUP.ITEMS as a 1-dim text array

let X = X    let Y = Y    let VXFORM = VXFORM

reserve POPUP.ITEMS(*) as 3

'' keep returning to READLOC
while SIMULATION.DONE eq 0
do
    call READLOC.R(0.0, 0.0, 16) yielding X, Y, VXFORM
    '' we return here after the user clicks the mouse

    '' if the background was selected, bring up the "air resistance" menu.
    '' After a mouseclick, G.4 contains the segment id of the selected icon
    if (G.4 eq 0) and (Y gt 0.0)
        reserve POPUP.ITEMS(*) as 3
        let POPUP.ITEMS(1) = "High Air Resistance"
        let POPUP.ITEMS(2) = "Low Air Resistance"
        let POPUP.ITEMS(3) = "No Air Resistance"
    
        select case POPUP.F(POPUP.ITEMS(*))
          case "High Air Resistance"   let EVRN.AIRRES = .AIRRES.HIGH
          case "Low Air Resistance"    let EVRN.AIRRES = .AIRRES.MEDIUM
          case "No Air Resistance"     let EVRN.AIRRES = .AIRRES.LOW
          default
        endselect

        release POPUP.ITEMS(*)
    always
    
    '' if the background was selected BELOW THE FLOOR, bring up the "gravity" 
    '' menu.  
    if (G.4 eq 0) and (Y le 0.0)
        reserve POPUP.ITEMS(*) as 3
        let POPUP.ITEMS(1) = "Jupiter Gravity"
        let POPUP.ITEMS(2) = "Earth Gravity"
        let POPUP.ITEMS(3) = "Moon Gravity"
    
        select case POPUP.F(POPUP.ITEMS(*))
          case "Jupiter Gravity"  let EVRN.GRAVITY = .GRAVITY.HIGH
          case "Earth Gravity"    let EVRN.GRAVITY = .GRAVITY.MEDIUM
          case "Moon Gravity"     let EVRN.GRAVITY = .GRAVITY.LOW
          default
        endselect

        release POPUP.ITEMS(*)
    always
    
    '' if the floor was selected, bring up the floor "stiffness" menu
    '' After a mouseclick, G.4 contains the segment id of the selected icon
    if G.4 eq SEGID.A(FLOOR)
        reserve POPUP.ITEMS(*) as 3
        let POPUP.ITEMS(1) = "High Stiffness"
        let POPUP.ITEMS(2) = "Medium Stiffness"
        let POPUP.ITEMS(3) = "Low Stiffness"
    
        select case POPUP.F(POPUP.ITEMS(*))
          case "High Stiffness"   let EVRN.FLOOR = .FLOOR.HIGH
          case "Medium Stiffness" let EVRN.FLOOR = .FLOOR.MEDIUM
          case "Low Stiffness"    let EVRN.FLOOR = .FLOOR.LOW
          default
        endselect

        release POPUP.ITEMS(*)
    always
    
    '' if a ball was selected, display a menu allowing you to set the mass
    for each BALL in BALL.SET, with G.4 eq SEGID.A(BALL)
    do
        reserve POPUP.ITEMS(*) as 4
        let POPUP.ITEMS(1) = "Remove"
        let POPUP.ITEMS(2) = "Stop"
        let POPUP.ITEMS(3) = "Double Mass"
        let POPUP.ITEMS(4) = "Half Mass"
    
        select case POPUP.F(POPUP.ITEMS(*))
          case "Remove"   
              let DONE.FLAG(BALL) = 1

          case "Stop"   
              let VX(BALL) = 0
              let VY(BALL) = 0

          case "Double Mass"    
              let MASS(BALL) = MASS(BALL) * 2.0

          case "Half Mass"    
              let MASS(BALL) = MASS(BALL) / 2.0

          default
        endselect

        release POPUP.ITEMS(*)
    loop
loop
    
End
