REM **********
REM Version 1
REM **********
dim maindir$(1)
maindir$(1)=get dir$()
dim menu$(6,10)
 
REM LABEL,X,Y,Width,Height
`200
dim fbutton$(100,4)
`300
dim wbutton$(100,4)
REM LABEL,X,Y,WIDTH,HEIGHT,menuname
`400
dim mbutton$(100,5,10)
REM X,Y,Width,Height,button data-x,y,name
`500
dim rbutton$(100,5,3)
REM X,Y,Status
`600
dim chkbx(100,3)
REM X,Y,WIDTH,HEIGHT,TEXT SIZE,TEXT NAME,message-lines
`700
dim tbox$(100,7,200)
REM X,Y,Width,Height,Message
dim ibox$(100,5)
REM X,Y,Min,Max,Width,Link
dim slider$(100,5)
menu$(0,0)="3"
REM FILE
menu$(1,0)="5"
menu$(1,1)="New"
menu$(1,2)="Load"
menu$(1,3)="Save"
menu$(1,4)="Compile"
menu$(1,5)="Close"
REM EDIT
menu$(2,0)="2"
menu$(2,1)="Undo"
menu$(2,2)="Redo"
REM ADD
menu$(3,0)="8"
menu$(3,1)="Function Button"
menu$(3,2)="Window Button"
menu$(3,3)="Menu Button"
menu$(3,4)="Radio Buttons"
menu$(3,5)="Check Box"
menu$(3,6)="Text Box"
menu$(3,7)="Input Box"
menu$(3,8)="Background image"
menu$(3,9)="Slider"
 
ink rgb(127,127,127),0
create bitmap 1,640,480
set current bitmap 0
 
 
`dropmenu(50,50,1)
`wait key
box 0,0,639,25
 
ink rgb(255,255,255),0
box 500,3,630,22
 
 
button(0,0,1,"File",1,75,25)
button(sprite width(1)+1,0,1,"Edit",2,75,25)
button(sprite x(2)+sprite width(2)+1,0,1,"Add",3,75,25)
get image 65533,0,0,1,1
`cls
do
	if image exist(4) then paste image 4,0,26
	sprite 65533,mousex(),mousey(),65533
	col=sprite collision(65533,0)
	if col>0 and col<4 and mouseclick()=1
		current=dropmenu(sprite x(col),sprite y(col)+sprite height(col),col)
		select col
			case 1 : gosub filemenu : endcase
			case 2 : gosub editmenu : endcase
			case 3 : gosub addmenu : endcase
		endselect
	endif
	if col>4 and mouseclick()=1
		offsetx=mousex()-sprite x(col)
		offsety=mousey()-sprite y(col)
		repeat
			sprite col,mousex()-offsetx,mousey()-offsety,col
		until mouseclick()=0
		if col>200 and col<300
			fbutton$(col-200,1)=str$(sprite x(col))
			fbutton$(col-200,2)=str$(sprite y(col))
		endif
		if col>300 and col<400
			wbutton$(col-300,1)=str$(mousex()-offsetx)
			wbutton$(col-300,2)=str$(mousey()-offsety)
		endif
		if col>400 and col<500
			mbutton$(col-400,1)=str$(mousex()-offsetx)
			mbutton$(col-400,2)=str$(mousey()-offsety)
		endif
		if col>500 and col<600
			rbutton$(col-500,1)=str$(mousex()-offsetx)
			rbutton$(col-500,2)=str$(mousey()-offsety)
		endif
		if col>600 and col<700
			chkbx(col-600,1)=mousex()-offsetx
			chkbx(col-600,2)=mousey()-offsety
		endif
		if col>700 and col<800
			tbox$(col-700,1)=str$(mousex()-offsetx)
			tbox$(col-700,2)=str$(mousey()-offsety)
		endif
		if col>800 and col<900
			ibox$(col-800,1)=str$(mousex()-offsetx)
			ibox$(col-800,2)=str$(mousey()-offsety)
		endif
 
	endif
	if col>4 and mouseclick()=2
		delete sprite col
		delete image col
		delete(col)
	endif
`x=0
`text 200,200,str$(sprite x(65533))+":"+str$(sprite y(65533))
 
loop
 
end
 
filemenu:
select current
REM NEW
	case 0: print h : endcase
REM LOAD
	case 1: print h : endcase
REM Save
	case 2: mbutton$(0,0)=str$(mbuttons) : fbutton$(0,0)=str$(fbuttons) : tbox$(0,0)=str$(ctbox) : save() : endcase
REM Compile
	case 3: print h : endcase
REM Close
	case 4: print h : endcase
endselect
return
 
editmenu:
select current
REM Undo
	case 0: print h : endcase
REM Redo
	case 1: print h : endcase
endselect
return
 
addmenu:
select current
REM FUNCTION BUTTON
	case 0: inc fbuttons : makefbutton(fbuttons) : endcase
REM Window Button
	case 1: print h : endcase
REM Menu Button
	case 2: inc mbuttons : makembutton(mbuttons) : endcase
REM Radio Button
	case 3: print h : endcase
REM Check Box
	case 4: print h : endcase
REM Text box
	case 5: inc ctbox : maketextbox(ctbox) : endcase
REM Input Box
	case 6: print h : endcase
REM Background image
	case 7: bg$=openbg(200,200) : load image bg$,4 : tileimg(4) : paste image 4,0,26: endcase
REM Slider
	case 8: print h : endcase
 
endselect
return
 
 
 
 
FUNCTION Button(x,y,flag,string$,sprite,width,height)
set current bitmap 1
cls
	INK RGB(127,127,127),0
	BOX x,y,x+width,y+height
	INK RGB(255,255,255),0
	IF flag=1
		LINE x,y,x+width,y
		LINE x,y,x,y+height
		INK RGB(32,32,32),0
		LINE x,y+height,x+width,y+height
		LINE x+width,y,x+width,y+height
		INK RGB(57,57,57),0
		LINE x+1,y+height-1,x+width-1,y+height-1
		LINE x+width-1,y+1,x+width-1,y+height-1
 
	ELSE
		INK RGB(32,32,32),0
		LINE x,y,x+width,y
		LINE x,y,x,y+height-1
 
		INK RGB(255,255,255),0
		LINE x,y+height,x+width,y+height
		LINE x+width,y,x+width,y+height
 
		INK RGB(57,57,57),0
		LINE x+1,y+1,x+width-1,y+1
		LINE x+1,y+1,x+1,y+height-1
 
	ENDIF
 
	x2=x+(width)/2
	y2=y+(height/2)-(text height("|")/2)
 
	INK RGB(57,57,57),0
 
	CENTER TEXT x2,y2+2,string$
 
	INK RGB(255,255,255),0
	CENTER TEXT x2-1,y2+1,string$
 
	GET IMAGE sprite,x,y,x+width,y+height
set current bitmap 0
	SPRITE sprite,x,y,sprite
ENDFUNCTION
 
function dropmenu(x,y,menu)
	set current bitmap 1
	selections=val(menu$(menu,0))
	height=selections*(text height("|")+2)
	for i=1 to val(menu$(menu,0))
		if text width(menu$(menu,i))>width
			width=text width(menu$(menu,i))+3
		endif
	next i
	height2=text height("|")
 
 
	if bitmap exist(2)=1 then delete bitmap 2
	create bitmap 2,width+10,height+10
	ink 0,rgb(0,0,127)
	cls
	box 1,1,width-2,height2-2
	get image 65535,0,0,width,height2
 
	set current bitmap 1
	REM make the background
	ink rgb(50,50,50),0
	box x,y,x+width,y+height
	ink rgb(255,255,255),0
	box x,y,x+width-1,y+height-1
	ink rgb(127,127,127),0
	box x+1,y+1,x+width-1,y+height-1
 
	ink rgb(27,27,27),0
	for i=1 to selections
		text x+3,y+(i-1)*(text height("|")+2),menu$(menu,i)
		line x+3,y+i*(text height("|")+2),x+width-3,y+i*(text height("|")+2)
	next i
	get image 65534,x,y,x+width,y+height
	set current bitmap 0
	sprite 65534,x,y,65534
	repeat
		if (mousex()>x and mousey()>y) and (mousex()<x+width and mousey()<y+height)
			current=((mousey()-y)/(height2+2))
			if current<>(-1) then sprite 65535,x+1,y+1+(current*(height2+2)),65535	
		else
			current=-1
		endif
	until	mouseclick()=1
	if sprite exist(65535) then delete sprite 65535
`	delete sprite 65535
	if sprite exist(65534)=1 then delete sprite 65534
	set current bitmap 0
 
endfunction current
 
 
function makefbutton(button)
repeat
until mouseclick()=0
repeat
until mouseclick()=1
stx=mousex() : sty=mousey()
while mouseclick()=1
	box stx,sty,mousex(),mousey()
endwhile
endx=mousex() : endy=mousey()
if endx<stx
	tx=stx
	stx=endx
	endx=tx
endif
if endy<sty
	ty=stx
	sty=endy
	endy=ty
endif
w=(endx-stx)
h=(endy-sty)
if w>0 and h>0
rename:
ink 0,rgb(127,127,127)
box 0,26,639,479
text 500-text width("Enter Button Label")-5,5,"Enter Button Label:"
set cursor 503,5
ink 0,rgb(255,255,255)
input string$
 
for i=1 to button
	if fbutton$(i,0)=string$
		ink rgb(127,127,127),rgb(127,127,127)
		text 500-text width("Enter Button Label")-5,5,"Enter Button Label:"
		ink 0,0
		text 500-text width("Name already exists")-5,5,"Name already exists"
		wait 100
		ink rgb(127,127,127),rgb(127,127,127)
		text 500-text width("Name already exists")-5,5,"Name already exists"
		set cursor 503,5
		ink rgb(255,255,255),rgb(255,255,255)
		print string$
		goto rename
	endif
next i
fbutton$(button,0)=string$
fbutton$(button,1)=str$(stx)
fbutton$(button,2)=str$(sty)
fbutton$(button,3)=str$(w)
fbutton$(button,4)=str$(h)
button(stx,sty,1,string$,button+200,w,h)
ink rgb(127,127,127),rgb(127,127,127)
text 500-text width("Enter Button Label")-5,5,"Enter Button Label:"
set cursor 503,5
ink rgb(255,255,255),rgb(255,255,255)
print string$
endif
endfunction
 
function window(x,y,w,h)
if bitmap exist(1) then delete bitmap 1
create bitmap 1,640,480
	set current bitmap 1
	ink rgb(57,57,57),0
	cls
	box x,y,x+w,y+h
	ink rgb(255,255,255),0
	box x,y,x+w-1,y+h-1
	ink rgb(127,127,127),0
	box x+1,y+1,x+w-1,y+h-1
	get image 65532,x,y,x+w,y+h
	set current bitmap 0
	sprite 65532,x,y,65532
endfunction
 
 
Function Directory_Exist(name$)
	FIND FIRST
	filename$=Get File Name$()
	IF filename$<>name$
		REPEAT
			FIND NEXT
			filename$=Get File Name$()
		UNTIL filename$=name$ or Get File Type()=-1
	ENDIF
	IF Get File Type()=1
		value=1
	ELSE
		value=0
	ENDIF
 
ENDFUNCTION value
 
 
REM The function for an open file window. This contains everything including the loop
Function Openbg(x,y)
	SET TEXT FONT "Arial",0
REM The initial box
	INK RGB(127,127,127),0
	BOX x,y,x+14*16,y+13*14
	INK RGB(0,0,127),0
REM The top bar
	BOX x,y,x+14*16,y+14
REM Places and offsets the word "OPEN" at the top, to give a windows feel
	SET TEXT SIZE 14
	INK RGB(56,56,56),0
	TEXT x+5,y,"Open"
	INK RGB(255,255,255),0
	TEXT x+4,y-1,"Open"
	SET TEXT SIZE 12
	INK RGB(56,56,56),0
	BOX x+2,y+16,x+14*16-2,y+26
 
REM Shades the corners so that it looks windows-ish
	INK 0,0
	LINE x,y+28,x+14*16,y+28
 
	INK RGB(57,57,57),0
	BOX x+14,y+42,x+14*15,y+14*9
 
	INK RGB(255,255,255),0
	LINE x,y,x+14*16,y
	LINE x,y,x,y+13*14
 
	INK RGB(32,32,32),0
	LINE x,y+14*13,x+14*16,y+14*13
	LINE x+14*16,y,x+14*16,y+14*13
 
	INK RGB(57,57,57),0
	LINE x+1,(y+(14*13))-1,(x+(14*16))-1,(y+(14*13))-1
	LINE (x+(14*16))-1,y+1,(x+(14*16))-1,(y+(14*13))-1
 
REM Grabs the screen
	GET IMAGE 65531,0,0,640,480
REM Creates the mouse sprite
	BOX 0,0,1,1
	GET IMAGE 65530,0,0,1,1
 
	SPRITE 65530,MouseX(),MouseY(),65530
	SET SPRITE 65530,1,0
REM Creates the Buttons
	Button(x+14,y+14*10,1,"Open",65529,75,25)
	Button(x+135,y+14*10,1,"Cancel",65528,75,25)
 
	SYNC ON : SYNC RATE 0
 
REM Places the screen sprite offscreen, for pasting later
	SPRITE 65531,800,0,65531
REM Generates the file list
	CreateFiles(offset,selected)
REM Places the file list offscreen, for pasting
	SPRITE 65527,800,0,65527
 
REM Creates the text showing the directory
	location$=GET DIR$()
	limit=50
	size=LEN(location$)
	difference=size-limit
REM Checks to see if it would make it shorter to abbreviate it
	if difference>3
		location$=LEFT$(location$,(limit/2)-3)+"..."+RIGHT$(lOCATION$,(limit/2)-5)
	endif
 
	TEXT x+4,y+16,location$
REM Main Loop
	REPEAT
		SET CURRENT BITMAP 0
		IF MouseClick()=0
			oldselect=selected
		ENDIF
		IF MouseX()>x+14 and MouseY()<x+14*16 and MouseY()>y+28 and MouseY()<y+9*14
			IF MouseClick()=1
				selected=((MouseY()-(y+28))/14)
				IF selected=oldselect and oldselect>0
					changeflag=1
				ENDIF
			ENDIF
		ENDIF
		IF MouseClick()=0 and changeflag=1
			selectedname$=CreateFiles(offset,selected)
			if Directory_Exist(selectedname$)=1
				CD selectedname$
				selected=0
				offset=0
				changeflag=0
			ENDIF
		ENDIF
 
		CreateFiles(offset,selected)
		PASTE SPRITE 65531,0,0
		SPRITE 65530,MouseX(),MouseY(),65530
		IF UpKey()=1
			scroll=-1
		ENDIF
		IF DownKey()=1
			scroll=1
		ENDIF
		IF UpKey()=0 and DownKey()=0
			inc offset,scroll
			scroll=0
		ENDIF
		IF offset<0 THEN offset=0
			IF Sprite Collision(65530,65529) and MouseClick()=1
				Button(x+14,y+14*10,0,"Open",65529,75,25)
				button=1
			ELSE
				Button(x+14,y+14*10,1,"Open",65529,75,25)
			ENDIF
 
			IF Sprite Collision(65530,65528) and MouseClick()=1
				Button(x+135,y+14*10,0,"Cancel",65528,75,25)
				button=2
			ELSE
				Button(x+135,y+14*10,1,"Cancel",65528,75,25)
			ENDIF
			PASTE SPRITE 65527,x+14,y+42
 
			IF MouseClick()=0 and button<>0
			IF button=1
				selectname$=CreateFiles(offset,selected)
				IF Directory_Exist(selectname$)=1
					CD selectname$
					selected=0
				ELSE
					exitflag=1
				ENDIF
			ENDIF
 
			IF button=2
				print "cancel"
			ENDIF
			button=0
		ENDIF
 
		location$=Get Dir$()
		limit=50
		size=LEN(location$)
		difference=size-limit
		IF difference>3
			location$=LEFT$(Location$,(limit/2)-3)+"..."+RIGHT$(LOCATION$,(limit/2)-5)
		ENDIF
		TEXT x+4,y+16,location$
		SYNC
	UNTIL exitflag=1
	for i=65527 to 65531
		if image exist(i) then delete image i
		if sprite exist(i) then delete sprite i
	next i
	ink 0,0
	box 0,26,639,479
ENDFUNCTION selectname$
 
FUNCTION CreateFiles(offset,selected)
	IF Bitmap Exist(15)=1 THEN DELETE BITMAP 15
	CREATE BITMAP 15,640,480
	INK RGB(255,0,0),RGB(0,255,255)
	CLS
	INK RGB(255,0,0),RGB(0,255,255)
	BOX 0,(offset+selected-1)*14,639,(offset+selected)*14
 
	INK 0,RGB(0,255,255)
	PERFORM CHECKLIST FOR FILES
	FIND FIRST
	filecount=0
	FOR i=1 to Checklist Quantity()
		FIND NEXT
		IF Get File Name$()=".." or Right$(Get File Name$(),3)="bmp" or Right$(Get File Name$(),3)="png" or Get File Type()=1
			INC filecount
			name$=Get File Name$()
			IF Len(name$)>10
				name$=Left$(name$,6)+".."+Right$(name$,3)
			ENDIF
			string$=name$
			TEXT 0,((filecount-1)*14)+1,string$
			TEXT 196-Text Width(Get File Date$()),((filecount-1)*14)+1,Get File Date$()
			INK 0,0
			LINE 0,((filecount)*14),640,((filecount)*14)
			LINE 0,((filecount-1)*14),640,((filecount-1)*14)
			IF filecount=selected+offset then filename$=Get File Name$()
		ENDIF
	NEXT i
 
	GET IMAGE 65527,0,offset*14,196,(6*14)+(offset*14)
	SET CURRENT BITMAP 0
	INK RGB(255,255,255),0
ENDFUNCTION filename$
 
function tileimg(img)
if bitmap exist(31) then delete bitmap 31
create bitmap 31,640,480
sprite img,800,800,img
iw=sprite width(img)
ih=sprite height(img)
tw=640/sprite width(img)
th=480/sprite height(img)
delete sprite img
sync on
for x=0 to tw
	for y=0 to th
		paste image img,iw*x,ih*y
	next y
next x
sync
sync off
get image img,0,0,640,480
set current bitmap 0
delete bitmap 31
endfunction
 
 
 
function maketextbox(boxnum)
deftxt=text size()
repeat
until mouseclick()=0
repeat
until mouseclick()=1
sx=mousex()
sy=mousey()
repeat
	nx=mousex()
	ny=mousey()
	box sx,sy,nx,ny
until mouseclick()=0	
x=sx
y=sx
w=(nx-sx)
h=(ny-sy)
dim line$(200)
pt=5
ink rgb(0,0,127),0
 
box x,y,x+w,y+12
sync on : sync rate 0
cline=1
 
repeat
ink 0,0
box 0,26,639,479
ink rgb(255,255,255),0
 
`ink rgb(57,57,57),0
ink 0,0
box x,y,x+w,y+h
set cursor x+5,y+5
ink rgb(255,255,255),0
cdown=asc(inkey$())
	`59-61
	select scancode()
		case 59 : just=0 : endcase
		case 60 : just=1 : endcase
		case 61 : just=2 : endcase
	endselect
	if cdown<>0
		flag=cdown
	endif
	if flag<>0 and cdown=0
		if flag<>8 and flag<>13 and flag<>13 and flag<>43 and flag<>45
			line$(cline)=line$(cline)+chr$(flag)
			flag=0
		else
		if flag=8
			line$(cline)=left$(line$(cline),len(line$(cline))-1)
			flag=0
		endif
		if flag=13
			inc cline
			flag=0
		endif
		value=15
		if flag=43
			ts=text size()
			inc ts,value
			set text size ts
			flag=0
		endif
		if flag=45
			ts=text size()
			dec ts,value
			set text size ts
			flag=0
		endif
		endif
	endif
 
	for i=1 to cline
		if just=0
			text x+5,y+i*12,line$(i)
		endif
		if just=1
			text (x+(w/2)-(text width(line$(i))/2)),y+i*12,line$(i)
		ENDIF
		IF just=2
			text x+w-text width(line$(i)),y+i*12,line$(i)
		endif
	next i
sync
until mouseclick()=1
line$(0)=str$(cline)
for i=0 to cline
	tbox$(boxnum,7,i)=line$(i)
	if text width(line$(i))>w
		if just=1
			w=text width(line$(i))	
		endif
		if just=2
			diff=text width(line$(i))-w
			w=text width(line$(i))
			dec x,diff/2
		endif
		if just=3
			diff=text width(line$(i))-w
			w=text width(line$(i))
			dec x,diff
		endif
		w=text width(line$(i))
	endif
	if (i*text height("|"))>h then h=(i*text height("|"))
next i
sync
sync off
get image 700+boxnum,x,y,x+w,y+h
 
undim line$(200)
sprite 700+boxnum,x,y,700+boxnum
 
ink 0,0
box 0,26,639,479
ink rgb(255,255,255),0
set text size deftxt
endfunction
 
function save()
	cd maindir$(1)
	if directory_exist("$temp")=1 
		i=1
		repeat
			string$="$temp"+str$(i)
			inc i
		until directory_exist(string$)=0
			rename file "$temp",string$
			delete directory string$
	endif
	sync on
	make directory "$temp"
	if file exist("\$temp\BN2 Menu Maker.DBA")=1 then delete file "\$temp\BN2 Menu Maker.DBA"
	copy file "BN2 Menu Maker.DBA","$temp\BN2MenuMaker.DBA"
	cd get dir$()+"\$temp"
 
	save array "fbutton",fbutton$(100)
	save array "wbutton",wbutton$(100)
	save array "mbutton",mbutton$(100)
	save array "rbutton",rbutton$(100)
	save array "chkbx",chkbx(100)
	save array "tbox",tbox$(100)
	save array "ibox",ibox$(100)
	save array "slider",slider$(100)
 
	if file exist("compiled menu.dba")=1 then delete file "compiled menu.dba"
 
	open to write 1,"compiled menu.dba"
	write string 1,"#include "+chr$(34)+"BN2MenuMaker.DBA"+chr$(34)
	for i=1 to 65535
		if file exist(str$(i)+".bmp") then delete file str$(i)+".bmp"
		if image exist(i) 
			save image str$(i)+".bmp",i
			write string 1,"Load image "+chr$(34)+str$(i)+".bmp"+chr$(34)+","+str$(i)
		endif
	next i
	write string 1,"sync on : sync rate 0"
	REM These are not used, but required for the #include command to work!
	write string 1,"dim maindir$(1)"
	write string 1,"maindir$(1)=get dir$()"
	write string 1,"dim menu$(6,10)"
 
 
	write string 1,"Dim fbutton$(100,4)"
	write string 1,"Load array "+chr$(34)+"fbutton"+chr$(34)+",fbutton$(100)"
	write string 1,"Dim wbutton$(100,4)"
	write string 1,"Load array "+chr$(34)+"wbutton"+chr$(34)+",wbutton$(100)"
	write string 1,"Dim mbutton$(100,5,10)"
	write string 1,"Load array "+chr$(34)+"mbutton"+chr$(34)+",mbutton$(100)"
	write string 1,"Dim rbutton$(100,4,3)"
	write string 1,"Load array "+chr$(34)+"rbutton"+chr$(34)+",rbutton$(100)"
 
	write string 1,"Dim chkbx(100,3)"
	write string 1,"Load array "+chr$(34)+"chkbx"+chr$(34)+",chkbx(100)"
 
	write string 1,"Dim tbox$(100,7,200)"
	write string 1,"Load array "+chr$(34)+"tbox"+chr$(34)+",tbox$(100)"
 
	write string 1,"Dim ibox$(100,5)"
	write string 1,"Load array "+chr$(34)+"ibox"+chr$(34)+",ibox$(100)"
 
	write string 1,"Dim slider$(100,5)"
	write string 1,"Load array "+chr$(34)+"slider"+chr$(34)+",slider$(100)"
 
 
	write string 1,"ink rgb(127,127,127),0"
	write string 1,"box 0,0,1,1"
 
	write string 1,"get image 65533,0,0,1,1"
 
	for i=1 to val(fbutton$(0,0))
		write string 1,"sprite "+str$(i+200)+","+fbutton$(i,1)+","+fbutton$(i,2)+","+str$(i+200)
	next i
	for i=1 to val(mbutton$(0,0))
		write string 1,"sprite "+str$(i+400)+","+mbutton$(i,1)+","+mbutton$(i,2)+","+str$(i+400)
	next i
	for i=1 to val(rbutton$(0,0))
		write string 1,"sprite "+str$(i+500)+","+rbutton$(i,1)+","+rbutton$(i,2)+","+str$(i+500)
	next i
	for i=1 to val(tbox$(0,0))
		write string 1,"sprite "+str$(i+700)+","+tbox$(i,1)+","+tbox$(i,2)+",i+700"
	next i
	for i=1 to val(ibox$(0,0))
		write string 1,"sprite "+str$(i+800)+","+ibox$(i,1)+","+ibox$(i,2)+","+str$(i+800)
	next i
	for i=1 to val(wbutton$(0,0))
		write string 1,"sprite "+str$(i+300)+","+wbutton$(i,1)+","+wbutton$(i,2)+","+str$(i+300)
	next i
	for i=1 to chkbx(0,0)
		write string 1,"sprite "+str$(i+600)+","+str$(chkbx(i,1))+","+str$(chkbx(i,2))+","+str$(i+600)
	next i
 
`MAIN LOOP CODE
	write string 1,"do"
	write string 1,"if image exist(4) then paste image 4,0,0"
	write string 1,"sprite 65533,mousex(),mousey(),65533"
	write string 1,"col=sprite collision(65533,0)"
	write string 1,"If mouseclick()=1 then mouseflag=1"
	write string 1,"If mouseclick()=0 and mouseflag=1"
	write string 1,"select col"
	for i=1 to val(fbutton$(0,0))
		write string 1,"	case "+str$(i+200)+" : gosub fb"+fbutton$(i,0)+" : endcase"
	next i
	for i=1 to val(wbutton$(0,0))
		write string 1,"	case "+str$(i+300)+" : gosub wb"+wbutton$(i,0)+" : endcase"
	next i
	for i=1 to val(mbutton$(0,0))
		write string 1,"	case "+str$(i+400)+" : gosub mb"+mbutton$(i,0)+" : endcase"
	next i
	for i=1 to val(rbutton$(0,0))
		write string 1,"	case "+str$(i+500)+" : gosub rb"+rbutton$(i,0)+" : endcase"
	next i
	for i=1 to chkbx(0,0)
		write string 1,"	case "+str$(i+600)+" : gosub cb"+str$(chkbx(i,0))+" : endcase"
	next i
	for i=1 to val(ibox$(0,0))
		write string 1,"	case "+str$(i+800)+" : gosub ib"+ibox$(i,0)+" : endcase"
	next i
	write string 1,"endselect"
	write string 1,"mouseflag=0"
	write string 1,"endif"
	write string 1,"sync"
	write string 1,"cls"
	write string 1,"loop"
 
`	
`if col>900 and col<1000
`	gosub "slider$(col-900,0)"
`endif
write string 1,"end"
for i=1 to val(fbutton$(0,0))
	write string 1,"fb"+fbutton$(i)+":"
	write string 1,"REM CODE FOR "+fbutton$(i)+" BUTTON GOES HERE!"
	write string 1,"return"
next i
 
for i=1 to val(wbutton$(0,0))
	write string 1,"wb"+fbutton$(i,0)+":"
	write string 1,"REM CODE FOR "+wbutton$(i,0)+" BUTTON GOES HERE!"
	write string 1,"return"
next i
 
for i=1 to val(rbutton$(0,0))
	write string 1,"rb"+fbutton$(i,0)+":"
	write string 1,"REM CODE FOR "+rbutton$(i,0)+" BUTTON GOES HERE!"
	write string 1,"return"
next i
 
for i=1 to chkbx(0,0)
	write string 1,"tb"+str$(chkbx(i,0))+":"
	write string 1,"REM CODE FOR "+str$(chkbx(i,0))+" BUTTON GOES HERE!"
	write string 1,"return"
next i
 
for i=1 to val(tbox$(0,0))
	write string 1,"tb"+tbox$(i,0)+":"
	write string 1,"REM CODE FOR "+tbox$(i,0)+" BUTTON GOES HERE!"
	write string 1,"return"
next i
 
for i=1 to val(ibox$(0,0))
	write string 1,"ib"+ibox$(i,0)+":"
	write string 1,"REM CODE FOR "+ibox$(i,0)+" BUTTON GOES HERE!"
	write string 1,"return"
next i
 
for i=1 to val(mbutton$(0,0))
	write string 1,"mb"+mbutton$(i,0)+":"
	write string 1,"REM CODE FOR "+mbutton$(i,0)+" BUTTON GOES HERE!"
	write string 1,"y=val(mbutton$("+str$(i)+",2))"
	write string 1,"y=y+val(mbutton$("+str$(i)+",4))"
	write string 1,"x=val(mbutton$("+str$(i)+",1))"
	write string 1,"current=menu(x,y,1)"
	write string 1,"gosub mb"+mbutton$(i,0)+"_switch"
	write string 1,"return"
 
	write string 1,"mb"+mbutton$(i,0)+"_switch:"
	write string 1,"select current"
	for c=1 to val(mbutton$(i,5,0))
		write string 1,"	case "+str$(c)+": gosub mb"+mbutton$(i,0)+"_"+mbutton$(i,5,c)+" : endcase"
	next c
	write string 1,"endselect"
 
	for b=1 to val(mbutton$(i,5,0))
		write string 1,"mb"+mbutton$(i,0)+"_"+mbutton$(i,5,b)+":"
		write string 1,"REM CODE FOR "+mbutton$(i,0)+"->"+mbutton$(i,5,b)+" SELECTION GOES HERE"
		write string 1,"return"
	next b
next i
 
close file 1
sync
sync off
text 500-text width("done")-5,5,"done"
 
endfunction
 
function menu(x,y,menu)
if bitmap exist(1)=1 then delete bitmap 1
	create bitmap 1,700,1000
`	set current bitmap 1
	selections=val(mbutton$(menu,5,0))
	height=selections*(text height("|")+2)
	width=0
	for i=1 to val(mbutton$(menu,5,0))
		if text width(mbutton$(menu,5,i))>width
			width=text width(mbutton$(menu,5,i))+5
		endif
	next i
	height2=text height("|")
 
 
	if bitmap exist(2)=1 then delete bitmap 2
	create bitmap 2,width+10,height+10
	ink 0,rgb(0,0,127)
	cls
	box 1,1,width-2,height2-2
	get image 65535,0,0,width,height2
 
	set current bitmap 1
	REM make the background
	ink rgb(50,50,50),0
	box x,y,x+width,y+height
	ink rgb(255,255,255),0
	box x,y,x+width-1,y+height-1
	ink rgb(127,127,127),0
	box x+1,y+1,x+width-1,y+height-1
 
	ink rgb(27,27,27),0
	for i=1 to selections
		text x+3,y+(i-1)*(text height("|")+2),mbutton$(menu,5,i)
		line x+3,y+i*(text height("|")+2),x+width-3,y+i*(text height("|")+2)
	next i
	get image 65534,x,y,x+width,y+height
	set current bitmap 0
	sprite 65534,900,y,65534
	if (640-y)<sprite height(65534)
		y=val(mbutton$(menu,2))-sprite height(65534)
	endif
	sprite 65534,x,y,65534
	repeat
		if (mousex()>x and mousey()>y) and (mousex()<x+width and mousey()<y+height)
			current=((mousey()-y)/(height2+2))
			if current<>(-1) then sprite 65535,x+1,y+1+(current*(height2+2)),65535	
		else
			current=-1
		endif
		sync
	until	mouseclick()=1
	if sprite exist(65535) then delete sprite 65535
`	delete sprite 65535
	if sprite exist(65534)=1 then delete sprite 65534
	set current bitmap 0
 
endfunction current
 
 
function makembutton(button)
repeat
until mouseclick()=0
repeat
until mouseclick()=1
stx=mousex() : sty=mousey()
while mouseclick()=1
	box stx,sty,mousex(),mousey()
endwhile
endx=mousex() : endy=mousey()
if endx<stx
	tx=stx
	stx=endx
	endx=tx
endif
if endy<sty
	ty=stx
	sty=endy
	endy=ty
endif
w=(endx-stx)
h=(endy-sty)
if w>0 and h>0
rename:
ink 0,rgb(127,127,127)
box 0,26,639,479
text 500-text width("Enter Button Label")-5,5,"Enter Button Label:"
set cursor 503,5
ink 0,rgb(255,255,255)
input string$
 
for i=1 to button
	if fbutton$(i,0)=string$
		ink rgb(127,127,127),rgb(127,127,127)
		text 500-text width("Enter Button Label")-5,5,"Enter Button Label:"
		ink 0,0
		text 500-text width("Name already exists")-5,5,"Name already exists"
		wait 100
		ink rgb(127,127,127),rgb(127,127,127)
		text 500-text width("Name already exists")-5,5,"Name already exists"
		set cursor 503,5
		ink rgb(255,255,255),rgb(255,255,255)
		print string$
		goto rename
	endif
next i
ink rgb(127,127,127),rgb(127,127,127)
text 500-text width("Enter Button Label")-5,5,"Enter Button Label:"
 
ink rgb(255,255,255),0
box 500,3,630,22
ink 0,rgb(127,127,127)
text 500-text width("Enter Number Of Items:")-5,5,"Enter Number Of Items:"
set cursor 503,5
ink 0,rgb(255,255,255)
input number
	ink rgb(127,127,127),0
	box 0,0,500,25
 
for i=1 to number
	ink rgb(255,255,255),0
	box 500,3,630,22
	ink 0,rgb(127,127,127)
	text 500-text width("Enter Item "+str$(i)+":")-5,5,"Enter Items "+str$(i)+":"
	set cursor 503,5
	ink 0,rgb(255,255,255)
	input item$
	mbutton$(button,5,i)=item$
	ink rgb(127,127,127),0
	box 0,0,500,25
 
next i
	ink rgb(255,255,255),0
	box 500,3,630,22
	ink rgb(127,127,127),0
	box 0,0,500,25
 
mbutton$(button,0)=string$
mbutton$(button,1)=str$(stx)
mbutton$(button,2)=str$(sty)
mbutton$(button,3)=str$(w)
mbutton$(button,4)=str$(h)
mbutton$(button,5)=str$(number)
button(stx,sty,1,string$,button+400,w,h)
set cursor 503,5
ink rgb(255,255,255),rgb(255,255,255)
print string$
endif
endfunction
 
 
function delete(item)
	cat=item/100
	sub=cat*100
	item=item-sub
	select cat
		case 2
			ttl=val(fbutton$(0,0))
			fbutton$(0,0)=str$(val(fbutton$(0,0))-1)
			for i=item to ttl
				for b=0 to 4
					fbutton$(i,b)=fbutton$(i+1,b)
				next b
			next i
		endcase
 
		case 3
			ttl=val(wbutton$(0,0))
			wbutton$(0,0)=str$(val(wbutton$(0,0))-1)
			for i=item to ttl
				for b=0 to 4
					wbutton$(i,b)=wbutton$(i+1,b)
				next b
			next i
		endcase
 
		case 4
			ttl=val(mbutton$(0,0))
			mbutton$(0,0)=str$(val(mbutton$(0,0))-1)
			for i=item to ttl
				for b=0 to 5
					for c=0 to 10
						mbutton$(i,b,c)=mbutton$(i+1,b,c)
					next c
				next b
			next i
		endcase
 
		case 5
			ttl=val(rbutton$(0,0))
			rbutton$(0,0)=str$(val(rbutton$(0,0))-1)
			for a=item to ttl
				for b=0 to 5
					for c=0 to 3
						rbutton$(a,b,c)=rbutton$(a+1,b,c)
					next c
				next b
			next a
		endcase
 
		case 6
			ttl=chkbx(0,0)
			chkbx(0,0)=chkbx(0,0)-1
			for a=item to ttl
				for b=0 to 3
					chkbx(a,b)=chkbx(a+1,b)
				next b
			next a
		endcase
 
		case 7
			ttl=val(tbox$(0,0))
			tbox$(0,0)=str$(val(tbox$(0,0))-1)
			for a=item to ttl
				for b=0 to 7
					for c=0 to 200
						tbox$(a,b,c)=tbox$(a+1,b,c)
					next c
				next b
			next a
		endcase
 
		case 8
			ttl=val(ibox$(0,0))
			ibox$(0,0)=str$(val(ibox$(0,0))-1)
			for a=item to ttl
				for b=0 to 5
					ibox$(a,b)=ibox$(a+1,b)
				next b
			next a
		endcase
	endselect
endfunction