home *** CD-ROM | disk | FTP | other *** search
/ START Magazine / START VOL 3 NO 5.st / MENUBILD.ARC / MENUBILD.LST next >
Encoding:
File List  |  1988-09-12  |  20.3 KB  |  673 lines

  1. '
  2. ' Menu builder by David Plotkin
  3. '
  4. ' Copyright 1988 Antic Publishing Inc.
  5. '
  6. Rez=Xbios(4) !check resolution
  7. ' Rez=1 for med res (640x200), 2 for hi res (640x400)
  8. If Rez=0
  9.   A$="Menu Builder |   must be  | run in Med. or Hi Rez"
  10.   Alert 1,A$,1," OK ",Dum
  11.   Edit
  12. Endif
  13. '
  14. ' Menu_bar$ holds menu string
  15. ' Menutitle$ holds text of menu titles (max 10)
  16. ' Submenu$ holds text of submenu items (max 10 for each title)
  17. ' Dxpos is x position of dialog box, Dypos is y position
  18. ' Dwidth is width of dialog box, Dheight is the height
  19. ' Temp$ is temporary string for storing the screen
  20. ' Nummenus% is the number of menu titles (total)
  21. ' Numsubmenus% is the number of submenus under each menu title
  22. '
  23. Max_menu%=150
  24. Dim Menu_bar$(Max_menu%),Menutitles$(10),Submenus$(10,10)
  25. Dim Temp$(32000),Numsubmenus%(10)
  26. Gosub Initialize
  27. Gosub Menusetup
  28. Menu Menu_bar$()
  29. On Menu  Gosub Menu_handler
  30. On Menu Button 1,1,1 Gosub Menubutton
  31. On Menu Message Gosub Respondmsg
  32. Titlew 1,"GFA Menu Builder"
  33. Openw 1
  34. Aftererror:
  35. Do
  36.   On Menu
  37. Loop
  38. Procedure Menubutton
  39.   ' respond to press of the mouse button
  40.   Xmouse=Menu(10)  !x coordinate of mouse
  41.   Ymouse=Menu(11)  !y coordinate of mouse
  42.   Found%=0
  43.   A%=1+(Rez-1)
  44.   If Xmouse>450 And Xmouse<480 And Ymouse>8*A%+Yoff1% And Ymouse<18*A%+Yoff1%
  45.     ' over the UP arrow in the number of menus section
  46.     Graphmode 3  !XOR mode
  47.     Pbox 450,8*A%,480,18*A%
  48.     If Nummenus%<6
  49.       Nummenus%=Nummenus%+1
  50.       Menutitles$(Nummenus%)="Menu"+Str$(Nummenus%)
  51.       Numsubmenus%(Nummenus%)=4
  52.       For Lp2%=1 To 4
  53.         Submenus$(Nummenus%,Lp2%)="Item"+Str$(Lp2%)
  54.       Next Lp2%
  55.       Menu Kill
  56.       Gosub Menusetup
  57.       Menu Menu_bar$()
  58.     Else
  59.       A$="Only six menus | are allowed!"
  60.       Alert 3,A$,1,"Sorry",Dum
  61.     Endif
  62.     Pbox 450,8*A%,480,18*A%
  63.     Graphmode 1  !back to REPLACE mode
  64.     Gosub Drawnummenus
  65.     Gosub Drawtitles
  66.     Gosub Drawnumsubmenus
  67.     On Menu  Gosub Menu_handler
  68.     On Menu Button 1,1,1 Gosub Menubutton
  69.     On Menu Message Gosub Respondmsg
  70.     Found%=1
  71.   Endif
  72.   If Xmouse>510 And Xmouse<540 And Ymouse>8*A%+Yoff1% And Ymouse<18*A%+Yoff1% And Found%=0
  73.     ' over the DOWN arrow in the number of menus section
  74.     Graphmode 3  !XOR mode
  75.     Pbox 510,8*A%,540,18*A%
  76.     If Nummenus%>1
  77.       Nummenus%=Nummenus%-1
  78.       Menu Kill
  79.       Gosub Menusetup
  80.       Menu Menu_bar$()
  81.     Else
  82.       A$="Must have at | least one menu!"
  83.       Alert 3,A$,1,"Sorry",Dum
  84.     Endif
  85.     Pbox 510,8*A%,540,18*A%
  86.     Graphmode 1
  87.     Clearw 1
  88.     Gosub Drwwindow1
  89.     On Menu  Gosub Menu_handler
  90.     On Menu Button 1,1,1 Gosub Menubutton
  91.     On Menu Message Gosub Respondmsg
  92.     Found%=1
  93.   Endif
  94.   For Ln%=1 To Nummenus%
  95.     If Found%=0  ! not found yet, so check for title box
  96.       Upbound%=(Ln%*10)*A%+30*A%
  97.       Lowbound%=Upbound%+10*A%
  98.       If Xmouse>10 And Xmouse<300 And Ymouse>Upbound%+Yoff1% And Ymouse<Lowbound%+Yoff1%
  99.         ' over a menu title box
  100.         L%=Ln%  !store found variable
  101.         Graphmode 3
  102.         Pbox 10,Upbound%,300,Lowbound%
  103.         Gosub Drag_box(12,Upbound%+1+A%,300,Lowbound%-A%) !drag a box
  104.         Ct%=0
  105.         Fnd%=0  !found flag
  106.         While Ct%<Nummenus% And Fnd%=0
  107.           Ct%=Ct%+1  !increment the counter
  108.           Up%=(Ct%*10)*A%+30*A%
  109.           Low%=Up%+10*A%
  110.           If Eex>=10 And Eex=<300 And Eey>=Up%+Yoff1% And Eey<=Low%+Yoff1%
  111.             Fnd%=1
  112.           Endif
  113.         Wend
  114.         If Ct%=L%  !still in the same place, so change the title
  115.           Gosub Getnewtitle
  116.         Else  !otherwise
  117.           If Fnd%=1  ! found something
  118.             Swap Menutitles$(Ct%),Menutitles$(L%)
  119.             Swap Numsubmenus%(Ct%),Numsubmenus%(L%)
  120.             Hold%=Numsubmenus%(Ct%)  ! and the # of items in the destination
  121.             If Numsubmenus%(L%)>Numsubmenus%(Ct%) !use larger value
  122.               Hold%=Numsubmenus%(L%)
  123.             Endif
  124.             For Lp3%=1 To Hold%  !for each submenu in the destination
  125.               Swap Submenus$(Ct%,Lp3%),Submenus$(L%,Lp3%)
  126.             Next Lp3%
  127.           Endif
  128.         Endif
  129.         Menu Kill
  130.         Gosub Menusetup
  131.         Menu Menu_bar$()
  132.         Pbox 10,Upbound%,300,Lowbound%
  133.         Graphmode 1
  134.         Clearw 1
  135.         Gosub Drwwindow1
  136.         On Menu  Gosub Menu_handler
  137.         On Menu Button 1,1,1 Gosub Menubutton
  138.         On Menu Message Gosub Respondmsg
  139.         Found%=1 !trigger the "found" flag
  140.       Endif
  141.       If Xmouse>350 And Xmouse<410 And Ymouse>Upbound%+Yoff1% And Ymouse<Lowbound%+Yoff1%
  142.         ' Over the "DELETE" button
  143.         Graphmode 3
  144.         Pbox 350,Upbound%,410,Lowbound%
  145.         If Nummenus%>1 !can't get rid of the last menu
  146.           If Ln%<Nummenus%  !don't need to manipulate menus if del. last one
  147.             For Lq%=Ln% To Nummenus%-1
  148.               Menutitles$(Lq%)=Menutitles$(Lq%+1)
  149.               For Llq%=1 To Numsubmenus%(Lq%+1) !move submenu items
  150.                 Submenus$(Lq%,Llq%)=Submenus$(Lq%+1,Llq%)
  151.               Next Llq%
  152.               Numsubmenus%(Lq%)=Numsubmenus%(Lq%+1)
  153.             Next Lq%
  154.           Endif
  155.           Nummenus%=Nummenus%-1  !reduce the number of menus
  156.           Menu Kill
  157.           Gosub Menusetup
  158.           Menu Menu_bar$()
  159.           Pbox 350,Upbound%,410,Lowbound%
  160.           Graphmode 1
  161.           Clearw 1
  162.           Gosub Drwwindow1
  163.           On Menu  Gosub Menu_handler
  164.           On Menu Button 1,1,1 Gosub Menubutton
  165.           On Menu Message Gosub Respondmsg
  166.           Found%=1 !trigger the "found" flag
  167.         Else
  168.           A$="Must have at | least one menu!"
  169.           Alert 3,A$,1,"Sorry",Dum
  170.           Pbox 350,Upbound%,410,Lowbound%
  171.           Found%=1
  172.         Endif
  173.       Endif
  174.       If Xmouse>450 And Xmouse<480 And Ymouse>Upbound%+Yoff1% And Ymouse<Lowbound%+Yoff1%
  175.         ' over the up arrow for number of submenus
  176.         Graphmode 3
  177.         Pbox 450,Upbound%,480,Lowbound%
  178.         If Numsubmenus%(Ln%)<10
  179.           Numsubmenus%(Ln%)=Numsubmenus%(Ln%)+1
  180.           Submenus$(Ln%,Numsubmenus%(Ln%))="Item"+Str$(Numsubmenus%(Ln%))
  181.           Menu Kill
  182.           Gosub Menusetup
  183.           Menu Menu_bar$()
  184.           Pbox 450,Upbound%,480,Lowbound%
  185.           Graphmode 1
  186.           Clearw 1
  187.           Gosub Drwwindow1
  188.           On Menu  Gosub Menu_handler
  189.           On Menu Button 1,1,1 Gosub Menubutton
  190.           On Menu Message Gosub Respondmsg
  191.           Found%=1 !trigger the "found" flag
  192.         Else
  193.           A$="No more than | 10 items per menu!"
  194.           Alert 3,A$,1,"Sorry",Dum
  195.           Pbox 450,Upbound%,480,Lowbound%
  196.           Found%=1
  197.         Endif
  198.       Endif
  199.       If Xmouse>510 And Xmouse<540 And Ymouse>Upbound%+Yoff1% And Ymouse<Lowbound%+Yoff1%
  200.         ' over the down arrow for number of submenus
  201.         Graphmode 3
  202.         Pbox 510,Upbound%,540,Lowbound%
  203.         If Numsubmenus%(Ln%)>1
  204.           Numsubmenus%(Ln%)=Numsubmenus%(Ln%)-1
  205.           Menu Kill
  206.           Gosub Menusetup
  207.           Menu Menu_bar$()
  208.           Pbox 510,Upbound%,540,Lowbound%
  209.           Graphmode 1
  210.           Clearw 1
  211.           Gosub Drwwindow1
  212.           On Menu  Gosub Menu_handler
  213.           On Menu Button 1,1,1 Gosub Menubutton
  214.           On Menu Message Gosub Respondmsg
  215.           Found%=1 !trigger the "found" flag
  216.         Else
  217.           A$="Must have at least | 1 item per menu!"
  218.           Alert 3,A$,1,"Sorry",Dum
  219.           Pbox 510,Upbound%,540,Lowbound%
  220.           Found%=1
  221.         Endif
  222.       Endif ! xmouse and ymouse within bounds
  223.     Endif ! found%=0
  224.   Next Ln%
  225.   If Found%=0 ! still haven't found it, so try Desk menu item
  226.     If Xmouse>10 And Xmouse<300 And Ymouse>Dupbound%+Yoff1% And Ymouse<Dlowbound%+Yoff1%
  227.       ' over the Desk menu item
  228.       Graphmode 3
  229.       Pbox 10,Dupbound%,300,Dlowbound%  ! fill in the box
  230.       Gosub Getnewdeskitem
  231.       Pbox 10,Dupbound%,300,Dlowbound%
  232.       Graphmode 1
  233.       Clearw 1
  234.       Gosub Drwwindow1
  235.       Found%=1 ! trigger the "found" flag
  236.     Endif
  237.   Endif
  238.   If Found%=0 ! still haven't found it, so try the buttons at the bottom
  239.     Upb%=A%*165
  240.     Lowb%=Upb%+10*A%
  241.     If Xmouse>120 And Xmouse<180 And Ymouse>Upb%+Yoff1% And Ymouse<Lowb%+Yoff1%
  242.       ' over the QUIT button
  243.       Graphmode 3
  244.       Pbox 120,Upb%,180,Lowb%
  245.       A$="Want to quit? | (Saved your work?)"
  246.       Alert 2,A$,1," Yes | No ",Dum%
  247.       If Dum%=1 ! all done
  248.         End
  249.       Endif
  250.       Pbox 120,Upb%,180,Lowb%
  251.       Graphmode 1
  252.       Found%=1
  253.     Endif ! xmouse and ymouse within bounds
  254.     If Xmouse>200 And Xmouse<250 And Ymouse>Upb%+Yoff1% And Ymouse<Lowb%+Yoff1%
  255.       ' over the SAVE button
  256.       Graphmode 3
  257.       Pbox 200,Upb%,250,Lowb%
  258.       Graphmode 1
  259.       On Error Gosub Errorroutine
  260.       Nm$=""
  261.       Fileselect Path$,Nm$,Nm2$
  262.       If Nm2$<>"" And Right$(Nm2$,1)<>"\"
  263.         Defmouse 2
  264.         Open "o",#1,Nm2$
  265.         Write #1,Desk$
  266.         Write #1,Nummenus%
  267.         For Llz%=1 To Nummenus%
  268.           Write #1,Menutitles$(Llz%)
  269.           Write #1,Numsubmenus%(Llz%)
  270.           For Llz2%=1 To Numsubmenus%(Llz%)
  271.             Write #1,Submenus$(Llz%,Llz2%)
  272.           Next Llz2%
  273.         Next Llz%
  274.         Close #1
  275.         Gosub Gtnewpath(Nm2$)
  276.         Defmouse 0
  277.       Endif
  278.       On Error
  279.     Endif
  280.     If Xmouse>270 And Xmouse<320 And Ymouse>Upb%+Yoff1% And Ymouse<Lowb%+Yoff1%
  281.       ' over the LOAD button
  282.       Graphmode 3
  283.       Pbox 270,Upb%,320,Lowb%
  284.       Graphmode 1
  285.       On Error Gosub Errorroutine
  286.       Fileselect Path$,Nm$,Nm2$
  287.       If Nm2$<>"" And Right$(Nm2$,1)<>"\"
  288.         Defmouse 2
  289.         Open "i",#1,Nm2$
  290.         Input #1,Desk$
  291.         Input #1,Nummenus%
  292.         For Llz%=1 To Nummenus%
  293.           Input #1,Menutitles$(Llz%)
  294.           Input #1,Numsubmenus%(Llz%)
  295.           For Llz2%=1 To Numsubmenus%(Llz%)
  296.             Input #1,Submenus$(Llz%,Llz2%)
  297.           Next Llz2%
  298.         Next Llz%
  299.         Close #1
  300.         Gosub Gtnewpath(Nm2$)
  301.         Defmouse 0
  302.         Menu Kill
  303.         Gosub Menusetup
  304.         Menu Menu_bar$()
  305.         On Menu  Gosub Menu_handler
  306.         On Menu Button 1,1,1 Gosub Menubutton
  307.         On Menu Message Gosub Respondmsg
  308.         Found%=1 !trigger the "found" flag
  309.       Endif
  310.       On Error
  311.     Endif
  312.     If Xmouse>10 And Xmouse<100 And Ymouse>Upb%+Yoff1% And Ymouse<Lowb%+Yoff1%
  313.       ' over the WRITE CODE button
  314.       Graphmode 3
  315.       Pbox 10,Upb%,100,Lowb%
  316.       Graphmode 1
  317.       On Error Gosub Errorroutine
  318.       Nm$=""
  319.       Fileselect Path2$,Nm$,Nm2$
  320.       If Nm2$<>"" And Right$(Nm2$,1)<>"\"
  321.         Defmouse 2
  322.         Open "o",#2,Nm2$
  323.         Gosub Writecode
  324.         Close #2
  325.         Gosub Gtnewpath2(Nm2$)
  326.         Defmouse 0
  327.       Endif
  328.       On Error
  329.     Endif
  330.   Endif ! Found%=0
  331. Return
  332. Procedure Writecode
  333.   Print #2,"Gosub Build_menu_bar"
  334.   Print #2,"On Menu Gosub Menu_handler"
  335.   Print #2,"Do"
  336.   Print #2," On Menu"
  337.   Print #2,"Loop"
  338.   Print #2,"Procedure Menu_handler"
  339.   Print #2,"  'Procedure to respond to menu items"
  340.   Print #2,"  Menu_option$=Menu_bar$(Menu(0))"
  341.   Print #2,"  If Menu_option$=";Chr$(34);Desk$;Chr$(34)
  342.   Print #2,"    'put your code to handle Desk menu item here"
  343.   Print #2,"  Endif"
  344.   For Lp%=1 To Nummenus%
  345.     For Lp2%=1 To Numsubmenus%(Lp%)
  346.       Print #2,"  If Menu_option$=";Chr$(34);Submenus$(Lp%,Lp2%);Chr$(34)
  347.       Print #2,"    'put your code for ";Submenus$(Lp%,Lp2%);" here"
  348.       Print #2,"  Endif"
  349.     Next Lp2%
  350.   Next Lp%
  351.   Print #2,"Menu Off"
  352.   Print #2,"Return"
  353.   Print #2,"Procedure Build_menu_bar"
  354.   Print #2,"   ' Menu definition procedure"
  355.   Print #2,"   Menu Kill"
  356.   Print #2,"   Restore Main_list_menu_data"
  357.   Print #2,"   Dim Menu_bar$(150)"
  358.   Print #2,"   For I%=0 To 150"
  359.   Print #2,"      Read Menu_bar$(I%)"
  360.   Print #2,"      Exit If Menu_bar$(I%)=";Chr$(34);"***";Chr$(34)
  361.   Print #2,"   Next I%"
  362.   Print #2,"   Menu_bar$(I%)=";Chr$(34);Chr$(34)
  363.   Print #2,"   Main_list_menu_data:"
  364.   Print #2,"   Data Desk,";Chr$(34);Desk$;Chr$(34)
  365.   Print #2,"   Data -------------------"
  366.   Print #2,"   Data 1,2,3,4,5,6,";Chr$(34);Chr$(34)
  367.   For Lllp%=1 To Nummenus%
  368.     Print #2,"   Data ";Menutitles$(Lllp%);",";
  369.     For Lllp2%=1 To Numsubmenus%(Lllp%)
  370.       Print #2,Submenus$(Lllp%,Lllp2%);
  371.       If Lllp2%<Numsubmenus%(Lllp%)
  372.         Print #2,",";
  373.       Endif
  374.     Next Lllp2%
  375.     Print #2,",";Chr$(34);Chr$(34)
  376.   Next Lllp%
  377.   Print #2
  378.   Print #2,"   Data ***"
  379.   Print #2," Menu Menu_bar$()"
  380.   Print #2,"Return"
  381. Return
  382. Procedure Gtnewpath(Pt$)
  383.   L=Len(Pt$)
  384.   Tp$=""
  385.   While (Tp$<>"\" And Tp$<>":" And Tp$<>"/" And L>0)
  386.     Tp$=Mid$(Pt$,L,1)
  387.     L=L-1
  388.   Wend
  389.   If L>0
  390.     Path$=Left$(Pt$,L+1)+"*.MBX"
  391.   Else
  392.     Path$="*.MBX"
  393.   Endif
  394. Return
  395. Procedure Gtnewpath2(Pt$)
  396.   L=Len(Pt$)
  397.   Tp$=""
  398.   While (Tp$<>"\" And Tp$<>":" And Tp$<>"/" And L>0)
  399.     Tp$=Mid$(Pt$,L,1)
  400.     L=L-1
  401.   Wend
  402.   If L>0
  403.     Path2$=Left$(Pt$,L+1)+"*.LST"
  404.   Else
  405.     Path2$="*.LST"
  406.   Endif
  407. Return
  408. Procedure Errorroutine
  409.   Currenterror=Err
  410.   A$="Error accessing|the disk"
  411.   Alert 1,A$,1," OK ",Dum
  412.   Defmouse 0
  413.   Resume Aftererror
  414. Return
  415. Procedure Getnewtitle
  416.   ' get new title to replace title number Lp%
  417.   Graphmode 1
  418.   Sget Temp$  !store the screen
  419.   Pbox 100,50*A%,500,100*A%
  420.   Box 100,50*A%,500,100*A%
  421.   Box 110,60*A%,490,95*A%
  422.   Text 200,60*A%-2*A%,"Enter new menu title:"
  423.   Print At(16,10);
  424.   Input Ttle$
  425.   If Ttle$<>""
  426.     Menutitles$(Ln%)=Left$(Ttle$,9) !longest is 9 characters
  427.   Endif
  428.   Sput Temp$  ! restore the screen
  429.   Graphmode 3
  430. Return
  431. Procedure Drag_box(Xst%,Yst%,Xend%,Yend%)
  432.   Dpoke Gintin,Xend%-Xst%  !width of the box being dragged
  433.   Dpoke Gintin+2,Yend%-Yst%  !height of the box
  434.   Dpoke Gintin+4,Xst%  !starting x coordinate
  435.   Dpoke Gintin+6,Yst%+Yoff1% !starting y coordinate
  436.   Dpoke Gintin+8,0  !x coordinate of the bounding rectangle
  437.   Dpoke Gintin+10,Yoff1%  !y coordinate of bounding rectangle
  438.   Dpoke Gintin+12,639  !width of bounding rectangle
  439.   Dpoke Gintin+14,399+200*(Rez=1)-Yoff1%  !height of bounding rectangle
  440.   Gemsys (71)  !do it
  441.   Eex=Dpeek(Gintout+2)  !x coordinate when button released
  442.   Eey=Dpeek(Gintout+4)  !y coordinate when button released
  443. Return
  444. Procedure Drwwindow1
  445.   ' draw the contents of window 1
  446.   Gosub Drawnummenus
  447.   Gosub Drawtitles
  448.   Gosub Drawnumsubmenus
  449.   Gosub Drawbuttons
  450. Return
  451. Procedure Drawbuttons
  452.   Upbound%=165*(1+(Rez-1))
  453.   Lowbound%=Upbound%+10*(1+(Rez-1))
  454.   Box 10,Upbound%,100,Lowbound%
  455.   Text 15,Lowbound%-2*(1+(Rez-1)),"Write Code"
  456.   Box 120,Upbound%,180,Lowbound%
  457.   Text 125,Lowbound%-2*(1+(Rez-1)),"Quit"
  458.   Box 200,Upbound%,250,Lowbound%
  459.   Text 205,Lowbound%-2*(1+(Rez-1)),"Save"
  460.   Box 270,Upbound%,320,Lowbound%
  461.   Text 275,Lowbound%-2*(1+(Rez-1)),"Load"
  462. Return
  463. Procedure Drawnummenus
  464.   ' draw the number of menus box
  465.   Color 1
  466.   Print At(40,2);"Number of menus: "
  467.   Box 450,8*(1+(Rez-1)),480,18*(1+(Rez-1))
  468.   Box 480,8*(1+(Rez-1)),510,18*(1+(Rez-1))
  469.   Box 510,8*(1+(Rez-1)),540,18*(1+(Rez-1))
  470.   Text 490,15*(1+(Rez-1)),Str$(Nummenus%)
  471.   Text 460,15*(1+(Rez-1)),Up$
  472.   Text 520,15*(1+(Rez-1)),Down$
  473. Return
  474. Procedure Drawtitles
  475.   ' draw the menu titles on the screen
  476.   Print At(7,4);"Menu titles:"
  477.   For Lp%=1 To Nummenus%
  478.     Upbound%=(Lp%*10)*(1+(Rez-1))+30*(1+(Rez-1))
  479.     Lowbound%=Upbound%+10*(1+(Rez-1))
  480.     Box 10,Upbound%,300,Lowbound%
  481.     Text 15,Lowbound%-2*(1+(Rez-1)),Menutitles$(Lp%)
  482.     Box 350,Upbound%,410,Lowbound%
  483.     Text 355,Lowbound%-2*(1+(Rez-1)),"Delete"
  484.   Next Lp%
  485.   ' now handle the desk "about" menu
  486.   Print At(7,15);"Information under Desk menu:"
  487.   Dupbound%=100*(1+(Rez-1))+30*(1+(Rez-1))
  488.   Dlowbound%=Dupbound%+10*(1+(Rez-1))
  489.   Box 10,Dupbound%,300,Dlowbound%
  490.   Text 15,Dlowbound%-2*(1+(Rez-1)),Desk$
  491. Return
  492. Procedure Drawnumsubmenus
  493.   ' draw the number of submenus boxes on the screen
  494.   Print At(55,4);"Number of items:"
  495.   For Lp%=1 To Nummenus%
  496.     Upbound%=(Lp%*10)*(1+(Rez-1))+30*(1+(Rez-1))
  497.     Lowbound%=Upbound%+10*(1+(Rez-1))
  498.     Box 450,Upbound%,480,Lowbound%
  499.     Box 480,Upbound%,510,Lowbound%
  500.     Box 510,Upbound%,540,Lowbound%
  501.     Text 490,Lowbound%-2*(1+(Rez-1)),Numsubmenus%(Lp%)
  502.     Text 460,Lowbound%-2*(1+(Rez-1)),Up$
  503.     Text 520,Lowbound%-2*(1+(Rez-1)),Down$
  504.   Next Lp%
  505. Return
  506. Procedure Menu_handler
  507.   ' respond to menu selection
  508.   Menu_option$=Menu_bar$(Menu(0)) ! text of item number that was clicked on
  509.   Hold%=Menu(0) ! item number that was clicked
  510.   If Menu_option$=" Menu builder " ! credit for me!
  511.     A$="     Menu builder |   by David Plotkin|"+Chr$(189)+" 1988 Antic Publishing"
  512.     Alert 1,A$,1," OK ",Dum
  513.     Menu Off
  514.   Else
  515.     ' figure out what was clicked on
  516.     Cnt%=0 ! index into submenus$()
  517.     Cnt2%=10  ! index into menu string (Menu_bar$())
  518.     Fnd%=0 ! found flag
  519.     Llq%=0 ! counter for number of menu items per title
  520.     Llp%=1 ! counter for menu title
  521.     While Fnd%=0
  522.       Cnt%=Cnt%+1 ! increment submenus$() index
  523.       Llq%=Llq%+1 ! increment current title item number
  524.       Cnt2%=Cnt2%+1 ! increment index into menu string
  525.       If Cnt2%=Hold% ! found it!
  526.         Fnd%=1
  527.       Endif
  528.       If Llq%=Numsubmenus%(Llp%) And Fnd%=0 ! reached the end of current title items
  529.         Llp%=Llp%+1 ! increment menu title number
  530.         Llq%=0 ! reset the counter for item number
  531.         Cnt2%=Cnt2%+2 ! adjust menu string index
  532.         Cnt%=0 ! reset the index into submenus$()
  533.       Endif
  534.     Wend
  535.     Gosub Getnewitem
  536.     Menu Off
  537.     Menu Kill
  538.     Gosub Menusetup
  539.     Menu Menu_bar$()
  540.     On Menu  Gosub Menu_handler
  541.     On Menu Button 1,1,1 Gosub Menubutton
  542.     On Menu Message Gosub Respondmsg
  543.   Endif
  544. Return
  545. Procedure Getnewitem
  546.   ' get new item to replace item number Llp%,Cnt%
  547.   Sget Temp$  !store the screen
  548.   Pbox 100,50*A%,500,100*A%
  549.   Box 100,50*A%,500,100*A%
  550.   Box 110,60*A%,490,95*A%
  551.   Text 200,60*A%-2*A%,"Enter new menu item:"
  552.   Print At(22,9);"Current item is: ";Submenus$(Llp%,Cnt%)
  553.   Print At(16,10);
  554.   Input Ttle$
  555.   If Ttle$<>""
  556.     Submenus$(Llp%,Cnt%)=Left$(Ttle$,15) !longest is 15 characters
  557.   Endif
  558.   Sput Temp$  ! restore the screen
  559. Return
  560. Procedure Getnewdeskitem
  561.   ' get new item to replace desk item
  562.   Graphmode 1
  563.   Sget Temp$  !store the screen
  564.   Pbox 100,50*A%,500,100*A%
  565.   Box 100,50*A%,500,100*A%
  566.   Box 110,60*A%,490,95*A%
  567.   Text 200,60*A%-2*A%,"Enter new Desk menu item:"
  568.   Print At(22,9);"Current item is: ";Desk$
  569.   Print At(16,10);
  570.   Input Ttle$
  571.   If Ttle$<>""
  572.     Desk$=Left$(Ttle$,15) !longest is 15 characters
  573.   Endif
  574.   Sput Temp$  ! restore the screen
  575.   Graphmode 3
  576. Return
  577. Procedure Menusetup
  578.   ' set up initial menu string
  579.   Restore Strt
  580.   For I%=0 To 9
  581.     Read Menu_bar$(I%)
  582.   Next I%
  583.   Strt:
  584.   Data Desk," Menu builder "
  585.   Data -------------------
  586.   Data 1,2,3,4,5,6,""
  587.   Cnt%=0
  588.   For Lp%=1 To Nummenus%
  589.     Cnt%=Cnt%+1
  590.     Menu_bar$(Cnt%+9)=Menutitles$(Lp%)
  591.     For Lp2%=1 To Numsubmenus%(Lp%)
  592.       Cnt%=Cnt%+1
  593.       Menu_bar$(Cnt%+9)=Submenus$(Lp%,Lp2%)
  594.     Next Lp2%
  595.     Cnt%=Cnt%+1
  596.     Menu_bar$(Cnt%+9)=""
  597.   Next Lp%
  598.   Menu_bar$(Cnt%+10)=""
  599.   Menu_bar$(Cnt%+11)=""
  600. Return
  601. Procedure Initialize
  602.   ' set up file name and pathname
  603.   Desk$="My Program"
  604.   Path$="\*.MBX"
  605.   Path2$="\*.LST"
  606.   Nm$=""
  607.   ' set up size of dialog box (window 4)
  608.   Dxpos=160
  609.   Dwidth=340
  610.   If Rez=1
  611.     Dypos=100
  612.     Dheight=75
  613.   Else
  614.     Dypos=100
  615.     Dheight=150
  616.   Endif
  617.   Hndl1=Windtab
  618.   Attr=Windtab+2
  619.   Xpos=Windtab+4
  620.   Ypos=Windtab+6
  621.   Width=Windtab+8
  622.   Height=Windtab+10
  623.   ' use window 4 for dialog box
  624.   Hndl4=Windtab+36
  625.   Attr4=Windtab+38
  626.   Xpos4=Windtab+40
  627.   Ypos4=Windtab+42
  628.   Width4=Windtab+44
  629.   Height4=Windtab+46
  630.   ' use full screen titled window for work space
  631.   Dpoke Attr,&H1
  632.   Dpoke Xpos,0
  633.   ' Ypos offset from menu bar
  634.   Dpoke Ypos,19+10*(Rez=1)
  635.   Dpoke Width,639
  636.   Dpoke Height,399+19*(Rez=2)+200*(Rez=1)+10*(Rez=1)
  637.   ' Initialize window 4 with title bar only
  638.   Dpoke Attr4,&H1
  639.   Dpoke Xpos4,Dxpos
  640.   Dpoke Ypos4,Dypos
  641.   Dpoke Width4,Dwidth
  642.   Dpoke Height4,Dheight
  643.   Deffill 0,1,0
  644.   If Rez=1
  645.     Yoff1%=19 !offset for mouse corrd to top of window 1
  646.     Yoff4%=10 !offset for window 4 title bar (0,0 is top left corner of title bar)
  647.   Else
  648.     Yoff1%=38
  649.     Yoff4%=19
  650.   Endif
  651.   ' set up initial menu string in Menutitle$ and Submenus$
  652.   Nummenus%=4
  653.   For Lp%=1 To 4
  654.     Menutitles$(Lp%)="Menu"+Str$(Lp%)
  655.     For Lp2%=1 To 4
  656.       Submenus$(Lp%,Lp2%)="Item"+Str$(Lp2%)
  657.     Next Lp2%
  658.   Next Lp%
  659.   For Lp%=1 To 10
  660.     Numsubmenus%(Lp%)=4
  661.   Next Lp%
  662.   Up$=Chr$(1)
  663.   Down$=Chr$(2)
  664.   A%=1+(Rez-1)
  665. Return
  666. Procedure Respondmsg
  667.   ' respond to GEM messages
  668.   If Menu(1)=20  !redraw of window 1 (only one used)
  669.     Clearw 1
  670.     Gosub Drwwindow1
  671.   Endif
  672. Return
  673.