'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'          Menu Selection Program (C) Shockwave.
'          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
'  Fully customisable!! The selection is returned in the
'  variable "CHOICE". Known problems with this are if you
'  use a prgram that contains variables that clash with
'  this one it may cause unexplained errors/effects. 
'  This program can run out of processor time when used
'  in conjunction with a large program using lots of 
'  vaiables.. If this happens, reduce the amount of
'  graphic bars, or remove them by setting "MENUBARS" to 0
'  when the program runs out of processor time you will
'  know as the menus will not be drawn correctly.
'
'  This program allows up to 10 choices on the menu and
'  up to 20 sime bars, It has LIMITED variable validation
'Coded in August 2001 by Nick Simpson (Shockwave/Fanatix).
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

open window 400,400

      red=0 : rem Set to 1 if you want a red component.
      grn=0 : rem Set to 1 if you want a green component.
      blu=1 : rem Set to 1 if you want a blue component.
    delay=3 : rem Delay in frames of selector speed!
 ystart=175 : Rem Y start pos of menus.
menubars=20 : Rem number of graphic bars (0 to turn off)
mchoices=10 : Rem number of possible selections.
dim mtext$(mchoices)

'You MUST have one of the following for each menu choice
'Delete unnescessary choices or you'll get an out of
'range error.. eg if MCHOICES=5 then you should only have
'5 mtext$ definitions.

  mtext$(1)="         SELECTION NUMBER ONE"
  mtext$(2)="         SELECTION NUMBER TWO"
  mtext$(3)="        SELECTION NUMBER THREE"
  mtext$(4)="        SELECTION NUMBER FOUR!"
  mtext$(5)="        SELECTION NUMBER FIVE!"
  mtext$(6)="         SELECTION NUMBER SIX"
  mtext$(7)="        SELECTION NUMBER SEVEN"
  mtext$(8)="        SELECTION NUMBER EIGHT"
  mtext$(9)="        SELECTION NUMBER NINE!"
 mtext$(10)="         SELECTION NUMBER TEN"

'the title bar:

   mtbar$="                  PROGRAM TITLE!!"

'Validation etc:

   dw=0
   choice=1
   if menubars>20 menubars=20
   if delay<1 delay=1
   if red=1 red=255
   if grn=1 grn=255
   if blu=1 blu=255
   if ystart<175 ystart=175
   if ystart>200 ystart=200
   if mchoices>10 mchoices=10
   portflag=0

repeat
  setdispbuf dw
  dw=0-dw
  setdrawbuf dw
  clear window
     gosub drawmenu
until (j=16384)

'put your calls here..
'eg: if choice=1 goto game
'etc..

end

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'              Here's the menu program.
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

label drawmenu

'background colour gradient:

    setrgb 1,0,0,0
    setrgb 2,red-230,grn-230,blu-230
    setrgb 3,red-230,grn-230,blu-230
    gtriangle 0,0 to 640,510 to 0,510
    setrgb 2,0,0,0
    gtriangle 0,0 to 640,0 to 640,510

'Draw Title Bar!

    setrgb 1,red/10,grn/10,blu/10
    fill rectangle 60,50 to 600,80
    setrgb 1,red-150,grn-150,blu-150
    fill rectangle 50,40 to 590,70
    setrgb 1,0,0,0
    text 62,60,mtbar$
    setrgb 1,255,255,255
    text 61,57,mtbar$

'Instructions:

    setrgb 1,55,55,55
    text 134,135,"USE JOYPAD UP, DOWN AND (X) TO SELECT!"

'Jump to background bars sub:

    if menubars>0 gosub menbr

'Draw selections boxes:

    yp=ystart

for menua=1 to mchoices

    setrgb 1,0,0,0

    if menua=choice setrgb 1,red/10,grn/10,blu/10
    fill rectangle 125,yp+5 to 540,yp+25
    setrgb 1,red-200,grn-200,blu-200
    if choice=menua setrgb 1,red-150,grn-150,blu-150 

    fill rectangle 120,yp to 535,yp+20
    setrgb 1,0,0,0
    text 130,yp+17,mtext$(menua)
    setrgb 1,255,255,255
    text 130,yp+14,mtext$(menua)
    yp=yp+30

next menua

'Detect joypad and change selection:

  j=0
  portflag=portflag+1
    if portflag>delay portflag=0
    if portflag=0 j=peek("port1")
    if j=16 choice=choice-1
    if j=64 choice=choice+1
    if choice>mchoices choice=mchoices
    if choice<1 choice=1

return

'****************************************
'*** Draw the sine bars at the bottom ***
'****************************************

label menbr

'sine pointers

    mbrsin=mbrsin+.2
    mbrsin2=mbrsin2+.4

'do each bar in turn

    for menubrs=1 to menubars 
       setrgb 1,0,0,0
       setrgb 2,0,0,0
       setrgb 3,red,grn,blu
         x=40*sin((menubrs+mbrsin2)/3)+300
         x=x+240*sin((menubrs+mbrsin)/12)
        gtriangle x,400+menubrs to x,510 to x+32,510
        gtriangle x+64,510 to x+64,400+menubrs to x+32,510
       setrgb 2,red,grn,blu
   gtriangle x,400+menubrs to x+32,510 to x+32,400+menubrs
   gtriangle x+64,400+menubrs to x+32,400+menubrs to x+32,510
      next menubrs

return


