Hi all.
I got an idea for a menu system that is both usable and easy to use. I scratched the code together in about five to ten minutes, and its not a very exiting program, but it demostrates how you can create a easy modable menu system. The system is based on an array. You input the values into the array, and the function will create the menu and will use all the components of the array. I hope someone findes the code usefull.
Updated for the second time
rem Set the resolution
set display mode 1024,768,32
rem Define the types
type types
txt as string
button as boolean
endtype
rem Create the array taht will contain all the info about the menu
dim menuArray(7) as types
rem This part is a headline, not a button
menuArray(0).txt="MENU SYSTEM TEST: "
menuArray(0).button=0
rem The buttons
menuArray(1).txt="red box"
menuArray(2).txt="green box"
menuArray(3).txt="blue box"
menuArray(4).txt="white box"
menuArray(5).txt="grey box"
menuArray(6).txt="no box"
menuArray(7).txt="EXIT"
rem Make so they are buttons
for n=1 to 7
menuArray(n).button=1
next n
rem Set the colors
red=rgb(255,0,0)
green=rgb(0,255,0)
blue=rgb(0,0,255)
white=rgb(255,255,255)
grey=rgb(100,100,100)
do
cls
switch1=menu(10,10)
if switch1<>0 then switch=switch1
rem What happens?
select switch
case 1 : box 100,100,200,200,red,red,red,red : endcase
case 2 : box 100,100,200,200,green,green,green,green : endcase
case 3 : box 100,100,200,200,blue,blue,blue,blue : endcase
case 4 : box 100,100,200,200,white,white,white,white : endcase
case 5 : box 100,100,200,200,grey,grey,grey,grey : endcase
case 7 : end : endcase
endselect
loop
rem The function that creates the menu
function menu(startx as integer,starty as integer)
for n=0 to array count(menuArray())
if menuArray(n).button=1
if mousex()>=startx and mousex()<=startx+text width(menuArray(n).txt) and mousey()>=starty+(text height("I")*(n-1)+15)+5 and mousey()<=starty+(text height("I")*(n-1)+15)+2+text height(menuArray(n).txt)
ink rgb(155,55,255),0
if mouseclick()=1 then buttonPressed=n
endif
endif
text startx,starty+(text height("I")*(n-1)+15)+5,menuArray(n).txt
ink rgb(255,255,255),0
next n
endfunction buttonPressed