A work in progress. The drop-down menu items list isn't written yet, so the menu titles act more like buttons. Still, I think it's an effective way to create and handle multiple buttons for your apps.
UPDATE: Look Below
`bool menuItemClicked(int menu_number, int item_number)
sync on
Global m_numberOfMenus as integer
`type menuItemObject
` int number
` string title
`endtype
type dropDownMenuObject
number as integer
title as string
numberOfItems as integer
`dim item(0) as string
x1 as integer
y1 as integer
x2 as integer
y2 as integer
endtype
dim dropDownMenu(0) as dropDownMenuObject
makeDropDownMenu(1, "File") : positionDropDownMenu(1, 100, 100)
makeDropDownMenu(2, "Edit") : positionDropDownMenu(2, 135, 200)
makeDropDownMenu(3, "Search") : positionDropDownMenu(3, 135, 200)
makeDropDownMenu(4, "View") : positionDropDownMenu(4, 135, 200)
makeDropDownMenu(5, "Compile"): positionDropDownMenu(5, 135, 200)
makeDropDownMenu(6, "Tools") : positionDropDownMenu(6, 135, 200)
alignDropDownMenus(1,1)
thing$ = "Click a menu"
do
cls
drawDropDownMenu(1)
drawDropDownMenu(2)
drawDropDownMenu(3)
drawDropDownMenu(4)
drawDropDownMenu(5)
drawDropDownMenu(6)
`if dropDownMenuListener() = 1 then thing$ = "File"
`if dropDownMenuListener() = 2 then thing$ = "Edit"
menu = dropDownMenuListener()
if menu > 0 then thing$ = getDropDownMenuName(menu)
set cursor 0,80
ink rgb(255,255,255),0
print thing$
sync
loop
REM public function
REM Creates a new drop-down menu object
function makeDropdownMenu(menu_number as integer, menu_title$ as string)
array insert at bottom dropDownMenu(0)
inc m_numberOfMenus
dropDownMenu(m_numberOfMenus).title = menu_title$
dropDownMenu(m_numberOfMenus).number = menu_number
endfunction
REM public function
REM Adds an item to a drop-down menu
function dropDownMenuAddItem(menu_number as integer, item_name$ as string)
index = getArrayElement(menu_number)
`array insert at bottom dropDownMenu(index).item(0)
dropDownMenu(index).numberOfItems = dropDownMenu(index).numberOfItems + 1
`dropDownMenu(index).item(dropDownMenu(index).numberOfItems ) = item_name$
endfunction
REM public function
REM Defines location of a drop-down menu
function positionDropDownMenu(menu_number as integer, x as integer, y as integer)
index = getArrayElement(menu_number)
dropDownMenu(index).x1 = x
dropDownMenu(index).y1 = y
dropDownMenu(index).x2 = x + (len(dropDownMenu(index).title) * 8 + 3)
dropDownMenu(index).y2 = y+14
endfunction
REM public function
REM Draws a drop-down menu object
function drawDropDownMenu(menu_number as integer)
index = getArrayElement(menu_number)
x1 = dropDownMenu(index).x1
y1 = dropDownMenu(index).y1
x2 = dropDownMenu(index).x2
y2 = dropDownMenu(index).y2
ink rgb(200,200,200),0
box x1, y1, x2, y2
ink 0,0
text x1+1, y1, dropDownMenu(index).title
endfunction
REM public function
REM If a drop-down menu is clicked, returns that menu number
function dropDownMenuListener()
index = 0
dropDownMenuNumbe = 0
if mouseclick()
while (index <= m_numberOfMenus)
inc index
x1 = dropDownMenu(index).x1
y1 = dropDownMenu(index).y1
x2 = dropDownMenu(index).x2
y2 = dropDownMenu(index).y2
if mouseWithIn(x1, y1, x2, y2)
dropDownMenuNumber = dropDownMenu(index).number
exit
endif
endwhile
endif
endfunction dropDownMenuNumber
REM public function
REM Aligns all drop-down menus on the given y-coordinate, and starting
REM at the given x-coordinate placing them one after another to the right
function alignDropDownMenus(x as integer, y as integer)
index = 0
y2 = y + 14
while (index <= m_numberOfMenus)
inc index
dropDownMenu(index).x1 = x
dropDownMenu(index).y1 = y
x = x + (len(dropDownMenu(index).title) * 8 + 3)
dropDownMenu(index).x2 = x
dropDownMenu(index).y2 = y2
inc x
endwhile
endfunction
REM public function
REM Same thing as alignDropDownMenus(), but centers the row of menus at the
REM x-coordinate given
function centerDropDownMenus(x as integer, y as integer)
endfunction
REM public function
REM Returns the given menu number's title as a string
function getDropDownMenuName(menu_number as integer)
index = getArrayElement(menu_number)
name$ = dropDownMenu(index).title
endfunction name$
REM private function
REM Returns the proper index number associated with the given menu number
function getArrayElement(menu_number as integer)
i = 0
menu_index = 0
while (i <= m_numberOfMenus)
if dropDownMenu(i).number = menu_number
menu_index = i
i = m_numberOfMenus+1
else
inc i
endif
endwhile
endfunction menu_index
REM private function
REM Returns true if mouse is within the defined area
function mouseWithIn(x1 as integer, y1 as integer,x2 as integer, y2 as integer)
if mousex() > x1 and mousex() < x2 and mousey() > y1 and mousey() < y2 then exitfunction 1
endfunction 0