Posted: 12th Dec 2003 21:51
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

+ Code Snippet
`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
Posted: 13th Dec 2003 6:24
Pretty cool!
Posted: 15th Dec 2003 18:53
Now has menu items. After a few more tweaks, I'll add a set for radio buttons.
Posted: 15th Dec 2003 21:07
When I start it, it gives an error on line 68:
Function declaration has unknown parameter on line 68.
What am I doing wrong?
Posted: 16th Dec 2003 5:28
Uh oh, looks like Rob K's got some competition!
Posted: 16th Dec 2003 19:31
Dude,thats pretty cool!
Posted: 16th Dec 2003 21:04
I get a syntax error at line 119. Is it because I have regular ol' DB?
Posted: 16th Dec 2003 22:13
Well, Rob K I think still has me beat. This is only for DBP. The TYPE and array list commands aren't available in DBC.

Alien, are you using DBP?
Posted: 17th Dec 2003 0:08
Well, I must admit, once you have this all done and thrown into a few handy functions where I can just say:

+ Code Snippet
MakeMenuObject(MnuTitle As String, Option1 As String [etc])


I will be more than happy to use this.
Posted: 17th Dec 2003 2:05
I wish I could do that in DB HZence.
Posted: 17th Dec 2003 3:23
Why couldn't you?
Posted: 17th Dec 2003 7:29
Because in DB, you have to state all the parameters of the function. And when the function is called, all those parameters must be passed into it.
Posted: 17th Dec 2003 7:32
I suppose I could allow something like:

MakeMenuObject(menuNumber, "File", "New-Open-Save-Exit")

And then just parse the string into seperate menu items.