' Menu V2 Coded by Shockwave of fanatix (C) August 2001
'A less Demo-Like menu for all you budding Yabasic coders
'  This one also only needs one call.. Just Gosub Menu!
'    It needs the graphics screen to be open though!
'
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
open window 400,400
gosub menu
setdrawbuf mdb
clear window

text 150,150,"USER CHOSE:"+str$(choice)
setdispbuf mdb
pause 2
end

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
' Self Contained Menu Subroutine.. The selection Number
' Is returned in the variable CHOICE
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
label menu
choice=1

'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'               Variable initialisation:
'%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


mtitle$="    THIS IS THE HEADING BAR!!"
mxchoice=15 : rem amount of choices possible
delay=2 : rem delay in reading port in frames
ystart=80 : rem position to draw menu from
dim choice$(mxchoice)

'     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
'     %% ARRAY DEFINITIONS FOR MENU CHOICES: %%
'     %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

choice$(1)="          SELECTION ONE"
choice$(2)="          SELECTION TWO"
choice$(3)="         SELECTION THREE"
choice$(4)="         SELECTION FOUR"
choice$(5)="         SELECTION FIVE"
choice$(6)="          SELECTION SIX"
choice$(7)="         SELECTION SEVEN"
choice$(8)="         SELECTION EIGHT"
choice$(9)="         SELECTION NINE"
choice$(10)="         SELECTION TEN"
choice$(11)="        SELECTION ELEVEN"
choice$(12)="        SELECTION TWELVE"
choice$(13)="       SELECTION THIRTEEN"
choice$(14)="       SELECTION FOURTEEN"
choice$(15)="        SELECTION FIFTEEN"

mdb=0
repeat

'Double buffer!

    setdispbuf mdb
    mdb=1-mdb
    setdrawbuf mdb
    clear window

'       %%%%%%%%%%%%%%%%%%%%%
'       %% Draw Background %%
'       %%%%%%%%%%%%%%%%%%%%%

    setrgb 1,10,10,55 
    fill rectangle 0,0 to 640,512
    for meb=1 to 510 step 40
    for mea=0 to 640 step 40
    setrgb 1,15,15,60+(meb/4)

  fill rectangle mea,meb to mea+20,meb+20 
  fill rectangle mea+20,meb+20 to mea+40,meb+40 

next mea
next meb

'            %%%%%%%%%%%%%%%
'            %% title bar %%
'            %%%%%%%%%%%%%%%

   setrgb 1,0,0,0
   fill rectangle 160,40 to 510,70
   setrgb 1,50,50,100
   fill rectangle 150,30 to 500,60
   setrgb 1,0,0,0
   text 162,54,mtitle$
   setrgb 1,255,255,255
   text 160,49,mtitle$

'        %%%%%%%%%%%%%%%%%%%%%
'        %% DRAW SELECTIONS %%
'        %%%%%%%%%%%%%%%%%%%%%
myy=ystart
for mea=1 to mxchoice
  setrgb 1,0,0,0
  fill rectangle 160,myy+10 to 510,myy+25
  setrgb 1,50,50,100
  if choice=mea setrgb 1,80,80,130
  fill rectangle 150,myy to 500,myy+15
  setrgb 1,155,155,255
  if choice=mea setrgb 1,255,255,255
  text 150,myy+11,choice$(mea)
  myy=myy+28
next mea

'Instructions

setrgb 1,255,255,255
text 147,510,"USE JOYPAD UP DOWN AND (X) TO SELECT"

'Read D-pad

  menjpad=0
  portflag=portflag+1
  if portflag>delay portflag=1
  if portflag=1 menjpad=peek("port1")
  if menjpad=16 choice=choice-1
  if menjpad=64 choice=choice+1
  if choice<1 choice=mxchoice
  if choice>mxchoice choice=1
until (menjpad=16384)

return
