Hi All,
Got this menu thingy going after some time, see what you think, tried to rem it as much as I can without bogging it down.
if you know of a better why of doing some of the code, mod it and paste back here.
Its has one problem which I am working on is if one submenu is open you can not aways click another menu without clicking twice.
Rem Project: topdropdownmenu
Rem Created: 4/13/2005 6:44:50 PM
Rem ***** Main Source File *****
rem Standard Setup Code
rem Order of running
rem setup screen font and size
rem create an array to put menu names in.
rem make variables global
rem get menu names and store them in menu$
rem make some quick variables for screen size
rem start do loop
rem call frame_title() function
rem show menu titles
rem show mouse cords
rem check if mouse is in menu bar if it is gosub titles.
rem Now check if mouse is clicked when over a menu title then call menuchoice() function.
rem a gosub to dosomething
rem a gosub to dosomething2
rem make menu titles and subtitles, you put your menu names here
rem Function menuchoice(menumber,xpos)this take menu number and how far in from the left of screen and draws a box to put submenus in.
rem Function dosomething(menu_choice,choice) checks which menu title press and which submenu then gose to gosub of function.
rem Function whatdidIpressed(menu_choice,choice) shoes you on screen what you pressed.
rem Function bevelbox(_left,_top,_right,_bottom,_bevwidth,_maincolor,_secondcolor,_bevshade,_toback,_fill)
rem bevelbox is a function to make a color fade down to a darker color
rem _left,_top is first cords like 0,0
rem _right,_bottom second cords like 100,100
rem _bevwidth is how much it fades by.
rem _maincolor the color of the paper.
rem _secondcolor is the paper color.
rem _bevshade is shade color of bevel.
rem _toback if this is set to 1 will draw to front else draw to back.
rem _fill set to 1 fills paper else its open jusrt the boarder.
rem Function frame_title(title$) draw the main frame title.
rem Function Menu_titles(number_of_titles) draws how many menu tiles to screen set by number_of_titles.
sync on : sync rate 0 :
color backdrop rgb(0,0,128)
rem hide mouse
set text font "arial" : set text size 12
set text transparent
dim menu$(8,20)
dim ts$(8)
global th sw sh th ts$ click menuchoice
rem get menu titles and subtitles
gosub menutitles
rem quick variables
sw=screen width()
sh=screen height()
th=text height("1")
tw=text width("1")
sp=(screen width()/8)/tw
mw=text width(menu$(0,0))
click=0
rem number of titles in bar
Menu_titles(8)
do
cls
rem make top frame bar with title
frame_title(menu$(0,1))
rem show menu titles
text tw,th+2,ts$
rem show mouse cords
set cursor 0,60
print "mouse cords=x "+str$(mousex())+" y "+str$(mousey())
rem go to choice if in bar
if mousey()>11 and mousey()<26
gosub Over_Menu_titles_X
endif
rem reset text
set text transparent
rem submenu do choice
if mcc=1 and click=1
click=1-click
rem call menu function 1
menuchoice(1,tw)
click=1-click
endif
rem sub2
if mcc=2 and click=1
click=1-click
menuchoice(2,tw*3+mw)
click=1-click
endif
rem sub3
if mcc=3 and click=1
click=1-click
menuchoice(3,tw*4+mw*2)
click=1-click
endif
rem sub4
if mcc=4 and click=1
click=1-click
menuchoice(4,mw*4)
click=1-click
endif
rem sub5
if mcc=5 and click=1
click=1-click
menuchoice(5,tw*2+mw*5)
click=1-click
endif
rem sub6
if mcc=6 and click=1
click=1-click
menuchoice(6,tw*4+mw*6)
click=1-click
endif
rem sub7
if mcc=7 and click=1
click=1-click
menuchoice(7,tw*5+mw*7)
click=1-click
endif
rem sub8
if mcc=8 and click=1
click=1-click
menuchoice(8,tw*8+mw*8)
click=1-click
endif
sync
loop
Over_Menu_titles_X:
rem if the mouse is over title then invert color
if mousey()>11 and mousey()<26
if mousex()>tw and mousex()<tw+text width(menu$(1,0))
set text opaque
text tw,th+2, menu$(1,0)
choice=1
endif
rem this is menu two.
if mousex()>tw+text width(menu$(1,0)) and mousex()<tw+text width(menu$(1,0)+menu$(2,0))
set text opaque
text tw+text width(menu$(1,0)),th+2, menu$(2,0)
choice=2
endif
if mousex()>tw+text width(menu$(1,0)+menu$(2,0)) and mousex()<tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0))
set text opaque
text tw+text width(menu$(1,0)+menu$(2,0)),th+2, menu$(3,0)
choice=3
endif
if mousex()>tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)) and mousex()<tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0))
set text opaque
text tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)),th+2, menu$(4,0)
choice=4
endif
if mousex()>tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)) and mousex()<tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0))
set text opaque
text tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)),th+2, menu$(5,0)
choice=5
endif
if mousex()>tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)) and mousex()<tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)+menu$(6,0))
set text opaque
text tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)),th+2, menu$(6,0)
choice=6
endif
if mousex()>tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)+menu$(6,0)) and mousex()<tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)+menu$(6,0)+menu$(7,0))
set text opaque
text tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)+menu$(6,0)),th+2, menu$(7,0)
choice=7
endif
if mousex()>tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)+menu$(6,0)+menu$(7,0)) and mousex()<tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)+menu$(6,0)+menu$(7,0)+menu$(8,0))
set text opaque
text tw+text width(menu$(1,0)+menu$(2,0)+menu$(3,0)+menu$(4,0)+menu$(5,0)+menu$(6,0)+menu$(7,0)),th+2, menu$(8,0)
choice=8
endif
rem if mouse is click put choice into mcc
if mouseclick()
click=1-click
mcc=choice
repeat
until mouseclick()=0
endif
else
mcc=0
set text transparent
endif
return
something:
rem put your action code in here
return
something2:
text sw/2,sh/2,"you clicked menu title two first"
sync
wait 5000
return
menutitles:
rem menu titles and subtitles
menu$(0,0)=" " :rem text spacer
menu$(0,1)="Frame Title"
rem menu 1 list
menu$(1,0)="File " :rem title
menu$(1,1)="New File " :rem sub items
menu$(1,2)="Save file"
menu$(1,3)="Save As.."
menu$(1,4)="Exit "
rem menu 2 list
menu$(2,0)="Edit "
menu$(2,1)="Undo "
menu$(2,2)="Cut "
menu$(2,3)="Copy "
rem menu 3 list
menu$(3,0)="Search "
menu$(3,1)="Find.. "
rem menu 4
menu$(4,0)="View "
menu$(4,1)="Reset "
rem menu 5
menu$(5,0)="Options "
rem menu 6
menu$(6,0)="Tools "
rem menu 7
menu$(7,0)="Window "
rem menu 8
menu$(8,0)="Help "
menu$(8,1)="About.. "
return
rem ===============================
function menuchoice(menumber,xpos)
depth=30 :rem depth of text
while click=0
set text transparent
rem draw out side bar and fill in box
bevelbox(xpos-tw-6,26,xpos+text width(menu$(0,0))+th+th,150,3,RGB(0,135,225),RGB(202,202,202),RGB(0,0,255),0,1)
rem set text color
ink RGB(255,255,255),0
rem show number of sub menus
text xpos,depth, menu$(menumber,1)
text xpos,depth+th, menu$(menumber,2)
text xpos,depth+th*2,menu$(menumber,3)
text xpos,depth+th*3,menu$(menumber,4)
text xpos,depth+th*4,menu$(menumber,5)
rem check if mouse pointer is over it and change to invers color
if mousex()>xpos and mousex()<xpos+depth+text width(menu$(menumber,1))
if mousey()>depth and mousey()<depth+th
set text opaque
text xpos,depth, menu$(menumber,1)
rem make schoice equal one
schoice=1
endif
rem reapeat as above for sub menu 2
if mousey()>depth+th and mousey()<depth+th*2
set text opaque
text xpos,depth+th, menu$(menumber,2)
schoice=2
endif
if mousey()>depth+th*2 and mousey()<depth+th*3
set text opaque
text xpos,depth+th*2, menu$(menumber,3)
schoice=3
endif
if mousey()>depth+th*3 and mousey()<depth+th*4
set text opaque
text xpos,depth+th*3, menu$(menumber,4)
schoice=4
endif
if mousey()>depth+th*4 and mousey()<depth+th*5
set text opaque
text xpos,depth+th*4, menu$(menumber,5)
schoice=5
endif
endif
sync
rem set click and put your choice into smcc fot checking
if mouseclick()
click=1-click
smcc=schoice
endif
rem waits till you let go of mouse button.
repeat
until mouseclick()=0
endwhile
rem take smcc to function
dosomething(menumber,smcc)
endfunction value
function dosomething(menu_choice,choice)
rem which menu then which choice knock out this line when you use it
whatdidIpressed(menu_choice,choice)
if menu_choice=1
if choice=2 then gosub something
rem if you have Ion or BlueGUI
rem if smcc=3 then saveBox(title$,filter$)
rem if smcc=5 then printbox(title$,filter$)
rem if smcc=6 then end
endif
if menu_choice=2
if choice=1 then gosub something2
endif
endfunction
rem knock this out when working
function whatdidIpressed(menu_choice,choice)
center text sw/2,sh/2," You clicked on menu Title "+str$(menu_choice)+" and Submenu "+str$(choice)
sync
wait 2000
endfunction
rem bevelbox(screen width()/screen width(),screen height()/screen height(),screen width(),screen height(),6,RGB(255,255,0),RGB(0,255,0),0,0)
function bevelbox(_left,_top,_right,_bottom,_bevwidth,_maincolor,_secondcolor,_bevshade,_toback,_fill)
rem make paper
if _toback=1
draw to front
else
draw to back
endif
rem find color numbers
rcol=rgbr(_secondcolor) : gcol=rgbg(_secondcolor) : bcol=rgbb(_secondcolor)
rem make boarders
if _fill<>0 then box _left,_top,_right,_bottom,_maincolor,_maincolor,_secondcolor,_secondcolor
for _bev = 0 to _bevwidth
rem fade color
gcol=gcol-_bev
rcol=rcol-_bev
bcol=bcol-_bev
ink rgb(rcol,gcol,bcol),_foundcol
rem draw a black line to end beveal
if _bev=_bevwidth then ink RGB(0,0,0) ,_foundcol
line _left+_bev, _top+_bev, _right-_bev, _top+_bev
line _left+_bev, _bottom-_bev, _right-_bev, _bottom-_bev
line _left+_bev, _top+_bev, _left+_bev, _bottom-_bev
line _right-_bev, _top+_bev, _right-_bev, _bottom-_bev+1
next _bev
rem reset drawing
draw to back
rem end above
endfunction
function frame_title(title$)
rem draws frame title bars and puts name there
box 0,0,sw,th+4,RGB(0,0,255),RGB(0,0,255),RGB(255,255,255),RGB(255,255,255)
text tw,0,title$
rem draws menu title bar
box 0,th,sw,th*2+4,RGB(0,135,225),RGB(0,135,235),RGB(0,135,255),RGB(0,135,255)
endfunction
function Menu_titles(number_of_titles)
rem draws menus titles
ink RGB(255,255,255),0
for t=1 to number_of_titles
ts$(t)=menu$(t,0)+space$(sp-len(menu$(0,0)))
ts$=ts$+ts$(t)
next t
endfunction
Ps. this for DBPro 5.8 if its work's in DBC lets us know.
I'm not getting you down am I, Ho Look! another fancy Door?