This is a function for creating a windows style main menu, its not finished - i only created it as a temperary measure until i either buy BlueGUI or recreate a menu using types.
Theres plenty of bugs such as not allowing you to have more than one sub menu called the same or having a 2nd sub menu but its a start. You also cant currenly use the keyboard to select the menu, just the mouse.
sync on
set display mode 1024,768,32
set window on
mainmenu_formatMenu()
mainmenu_addDrop("File")
mainmenu_addDrop("Edit")
mainmenu_addDrop("Help")
mainmenu_addSub(1,"Open")
mainmenu_addSub(1,"Exit")
mainmenu_addSub(2,"Undo")
`mainmenu_addSub(3,"About")
`Create then hide a object to make display 3D
make object cube 1,1
hide object 1
do
menuAction$ = mainmenu_drawMenu("XPstyle")
if menuAction$ = "Exit" then end
sync
loop
function mainmenu_formatMenu()
dim countDrop(10,4)
dim nameDrop$(10)
dim nameSub$(10,10)
dim mouseSTATEDrop$(10)
dim subMenu_draw(10)
` countDrop(0,0) = Drop Count
` countDrop(1,0) = 1st Drop Sub Count
` countDrop(1,1) = 1st Drop x1
` countDrop(1,2) = 1st Drop y1
` countDrop(1,3) = 1st Drop x2
` countDrop(1,4) = 1st Drop y2
` countDrop(2,0) = 2nd Drop Sub Count
set text font "tahoma"
set text size 14
endfunction
function mainmenu_addDrop(Name$)
countDrop(0,0)=countDrop(0,0)+1
nameDrop$(countDrop(0,0))=Name$
endfunction
function mainmenu_addSub(sub,Name$)
countDrop(sub,0)=countDrop(sub,0)+1
nameSub$(sub,countDrop(sub,0))=Name$
endfunction
function mainmenu_drawMenu(type$)
`================================VARIABLE================================
`gap is the space either side of a Drop name
if type$ = "Grey" then gap = 5
if type$ = "Highlight" then gap = 5
if type$ = "XPstyle" then gap = 7
shimL = gap `shimLEFT (used in positioning of Drops)
shimT = 0
temp_boxWidth = 0 `to position SubMenu box
boxWidth = 0 `to position SubMenu box
boxHeight = 0 `to position SubMenu box
openSUBMenu = 0 `Decide weather sub menu stays open
mX = mouseX() `Mouse X position
mY = mouseY() `Mouse Y position
`========================================================================
`================================MENU BAR================================
colour("clBTNFACE") : box 0,0,screen width(),18 :`MenuBar
colour("clMENUTEXT")
`========================================================================
`================================TOP MENU================================
`Drawing Drop and remembering its position
if countDrop(0,0) > 0
for i = 1 to countDrop(0,0)
countDrop(i,2) = 0
countDrop(i,4) = 18
next i
for i = 1 to countDrop(0,0)
colour("clMENUTEXT") : text shimL+gap,countDrop(i,2)+1,nameDrop$(i)
countDrop(i,1) = shimL
shimL=shimL+text width(nameDrop$(i))+(gap*2)
countDrop(i,3) = shimL-1
next i
endif
`Calcalating state of the mouse, taking req action
if countDrop(0,0) > 0
for i = 1 to countDrop(0,0)
if mX>countDrop(i,1) and mX<countDrop(i,3) and mY>countDrop(i,2) and mY<countDrop(i,4)
mouseSTATEDrop$(i) = "onOver"
if mouseClick() = 1 then mouseSTATEDrop$(i) = "onClick"
else mouseSTATEDrop$(i) = ""
endif
next i
`onEvent actions depending on Menu Style selected
for i = 1 to countDrop(0,0)
if type$="Grey"
if mouseSTATEDrop$(i)="onOver"
colour("clBTNHIGHLIGHT") : line countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,2)
colour("clBTNHIGHLIGHT") : line countDrop(i,1),countDrop(i,2),countDrop(i,1),countDrop(i,4)-1 :`Outline Raised
colour("clBTNSHADOW") : line countDrop(i,3),countDrop(i,2),countDrop(i,3),countDrop(i,4)-1
colour("clBTNSHADOW") : line countDrop(i,1),countDrop(i,4)-1,countDrop(i,3),countDrop(i,4)-1 :`Outline Raised
endif
if mouseSTATEDrop$(i)="onClick"
colour("clBTNHIGHLIGHT") : line countDrop(i,3),countDrop(i,2),countDrop(i,3),countDrop(i,4)-1
colour("clBTNHIGHLIGHT") : line countDrop(i,1),countDrop(i,4)-1,countDrop(i,3),countDrop(i,4)-1 :`Outline Lowered
colour("clBTNSHADOW") : line countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,2)
colour("clBTNSHADOW") : line countDrop(i,1),countDrop(i,2),countDrop(i,1),countDrop(i,4)-1 :`Outline Lowered
`Draw sub menu
for x = 1 to countDrop(0,0)
if subMenu_draw(x) = 1 then subMenu_draw(x) = 0
if countDrop(x,0) > 0 then subMenu_draw(i) = 1
next x
endif
endif
if type$="Highlight"
if mouseSTATEDrop$(i) = "onOver"
`onOVER effect goes here
colour("clHIGHLIGHT") : box countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,4) :`Highlight
colour("clHIGHLIGHTTEXT") : text (countDrop(i,1)+gap),1,nameDrop$(i) :`Highlight Text
endif
if mouseSTATEDrop$(i) = "onClick"
`onCLICK effect goes here as well as telling computer that sub menu will open
colour("clHIGHLIGHT") : box countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,4) :`Highlight
colour("clHIGHLIGHTTEXT") : text (countDrop(i,1)+gap),1,nameDrop$(i) :`Highlight Text
`Draw sub menu
for x = 1 to countDrop(0,0)
if subMenu_draw(x) = 1 then subMenu_draw(x) = 0
if countDrop(x,0) > 0 then subMenu_draw(i) = 1
next x
endif
endif
if type$="XPstyle"
if mouseSTATEDrop$(i) = "onOver"
ink rgb(49,106,197),0 : line countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,2)
ink rgb(49,106,197),0 : line countDrop(i,1),countDrop(i,2),countDrop(i,1),countDrop(i,4)-1 :`Outline Border
ink rgb(49,106,197),0 : line countDrop(i,3),countDrop(i,2),countDrop(i,3),countDrop(i,4)
ink rgb(49,106,197),0 : line countDrop(i,1),countDrop(i,4)-1,countDrop(i,3),countDrop(i,4)-1 :`Outline Border
ink rgb(189,205,236),0 : box countDrop(i,1)+1,countDrop(i,2)+1,countDrop(i,3),countDrop(i,4)-1 :`Highlight
ink rgb(176,175,156),0 : box countDrop(i,3)+1,countDrop(i,2)+4,countDrop(i,3)+5,countDrop(i,4) :`Shadow 2
ink rgb(136,135,116),0 : box countDrop(i,3)+1,countDrop(i,2)+6,countDrop(i,3)+3,countDrop(i,4) :`Shadow 1
colour("clMENUTEXT") : text countDrop(i,1)+gap,1,nameDrop$(i)
endif
if mouseSTATEDrop$(i) = "onClick"
ink rgb(138,134,122),0 : line countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,2)
ink rgb(138,134,122),0 : line countDrop(i,1),countDrop(i,2),countDrop(i,1),countDrop(i,4)-1 :`Outline Border
ink rgb(138,134,122),0 : line countDrop(i,3),countDrop(i,2),countDrop(i,3),countDrop(i,4)
ink rgb(138,134,122),0 : line countDrop(i,1),countDrop(i,4)-1,countDrop(i,3),countDrop(i,4)-1 :`Outline Border
ink rgb(239,237,222),0 : box countDrop(i,1)+1,countDrop(i,2)+1,countDrop(i,3),countDrop(i,4)-1 :`Highlight
ink rgb(176,175,156),0 : box countDrop(i,3)+1,countDrop(i,2)+4,countDrop(i,3)+5,countDrop(i,4) :`Shadow 2
ink rgb(136,135,116),0 : box countDrop(i,3)+1,countDrop(i,2)+6,countDrop(i,3)+3,countDrop(i,4) :`Shadow 1
colour("clMENUTEXT") : text countDrop(i,1)+gap,1,nameDrop$(i)
for x = 1 to countDrop(0,0)
if subMenu_draw(x) = 1 then subMenu_draw(x) = 0
if countDrop(x,0) > 0 then subMenu_draw(i) = 1
next x
endif
endif
next i
endif
`========================================================================
`================================SUB MENU================================
for i = 1 to countDrop(0,0)
if subMenu_Draw(i) = 1
`Draw sub box/sub names here
boxHeight = countDrop(i,4)+gap+2
for x = 1 to countDrop(i,0)
temp_boxWidth = (gap*4) + text width(nameSub$(i,x))
if temp_boxWidth > boxWidth then boxWidth = temp_boxWidth
boxHeight = boxHeight + text height(nameSub$(i,x)) + gap
next x
`Draw sub box/sub names here
shimT = countDrop(i,4)+gap+1
if type$="Grey"
`Show highlighted Drop
colour("clBTNHIGHLIGHT") : line countDrop(i,3),countDrop(i,2),countDrop(i,3),countDrop(i,4)-1
: line countDrop(i,1),countDrop(i,4)-1,countDrop(i,3),countDrop(i,4)-1 :`Outline Lowered
colour("clBTNSHADOW") : line countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,2)
: line countDrop(i,1),countDrop(i,2),countDrop(i,1),countDrop(i,4)-1 :`Outline Lowered
`Draw SubMenu
colourNum(21) : box countDrop(i,1)+1,countDrop(i,4),(countDrop(i,1)+1)+boxWidth,boxHeight+1 :`Dropdown Border
colour("clBTNFACE") : box countDrop(i,1)+2,countDrop(i,4)+1,countDrop(i,1)+boxWidth,boxHeight :`Dropdown Box
`Draw SubNames
for x = 1 to countDrop(i,0)
shimB = shimT + text height(nameSub$(i,x)) + gap
`Not Highlighted
colour("clMENUTEXT") : text countDrop(i,1)+2+(gap*2),shimT,nameSub$(i,x) :`Text
`Highlighted
if mX>countDrop(i,1) and (mX<(countDrop(i,1)+1)+boxWidth) and mY>shimT and mY<shimB
colour("clBTNSHADOW") : box countDrop(i,1)+4,shimT-2,countDrop(i,1)+boxWidth-2,shimB-2 :`Highlight
colour("clHIGHLIGHTTEXT") : text countDrop(i,1)+2+(gap*2),shimT,nameSub$(i,x) :`Highlight Text
if mouseClick() = 1
subMenu_Draw(i) = 0
exitFunction nameSub$(i,x)
endif
endif
shimT = shimB
next x
endif
if type$="Highlight"
`Show highlighted Drop
colour("clHIGHLIGHT") : box countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,4) :`Highlight
colour("clHIGHLIGHTTEXT") : text (countDrop(i,1)+gap),1,nameDrop$(i) :`Highlight Text
`Draw SubMenu
colourNum(21) : box countDrop(i,1)+1,countDrop(i,4),(countDrop(i,1)+1)+boxWidth,boxHeight+1 :`Dropdown Border
ink rgb(255,255,255),0 : box countDrop(i,1)+2,countDrop(i,4)+1,countDrop(i,1)+boxWidth,boxHeight :`Dropdown Box
`Draw SubNames
for x = 1 to countDrop(i,0)
shimB = shimT + text height(nameSub$(i,x)) + gap
`Not Highlighted
colour("clMENUTEXT") : text countDrop(i,1)+2+(gap*2),shimT,nameSub$(i,x) :`Text
`Highlighted
if mX>countDrop(i,1) and (mX<(countDrop(i,1)+1)+boxWidth) and mY>shimT and mY<shimB
colour("clHIGHLIGHT") : box countDrop(i,1)+4,shimT-2,countDrop(i,1)+boxWidth-2,shimB-2 :`Highlight
colour("clHIGHLIGHTTEXT") : text countDrop(i,1)+2+(gap*2),shimT,nameSub$(i,x) :`Highlight Text
if mouseClick() = 1
subMenu_Draw(i) = 0
exitFunction nameSub$(i,x)
endif
endif
shimT = shimB
next x
endif
if type$="XPstyle"
boxWidth = boxWidth + (gap*3)
shimL=countDrop(i,1) + (gap*4)
`Show highlighted Drop
ink rgb(138,134,122),0 : line countDrop(i,1),countDrop(i,2),countDrop(i,3),countDrop(i,2) :`Outline Border
ink rgb(138,134,122),0 : line countDrop(i,1),countDrop(i,2),countDrop(i,1),countDrop(i,4) :`Outline Border
ink rgb(138,134,122),0 : line countDrop(i,3),countDrop(i,2),countDrop(i,3),countDrop(i,4) :`Outline Border
ink rgb(255,255,255),0 : line countDrop(i,1)+1,countDrop(i,4)-1,countDrop(i,3),countDrop(i,4)-1 :`Joining Border
ink rgb(239,237,222),0 : box countDrop(i,1)+1,countDrop(i,2)+1,countDrop(i,3),countDrop(i,4) :`Highlight
ink rgb(176,175,156),0 : box countDrop(i,3)+1,countDrop(i,2)+4,countDrop(i,3)+5,countDrop(i,4) :`Shadow 2
ink rgb(136,135,116),0 : box countDrop(i,3)+1,countDrop(i,2)+6,countDrop(i,3)+3,countDrop(i,4) :`Shadow 1
colour("clMENUTEXT") : text countDrop(i,1)+gap,1,nameDrop$(i)
`Draw SubMenu
`REDO SUB MENU FOR XPSTYLE¬
` - ADD LEFT HAND SIDE BAR
ink rgb(138,134,122),0 : box countDrop(i,1),countDrop(i,4),(countDrop(i,1)+1)+boxWidth,boxHeight+1 :`Dropdown Border
ink rgb(255,255,255),0 : line countDrop(i,1)+1,countDrop(i,4),countDrop(i,3),countDrop(i,4) :`Joining Border
ink rgb(255,255,255),0 : box countDrop(i,1)+1,countDrop(i,4)+1,countDrop(i,1)+boxWidth,boxHeight :`Dropdown Box
ink rgb(239,237,222),0 : box countDrop(i,1)+3,countDrop(i,4)+2,countDrop(i,1)+(gap*4),boxHeight-1 :`Side Box
`Draw SubNames
for x = 1 to countDrop(i,0)
shimB = shimT + text height(nameSub$(i,x)) + gap
`Not Highlighted
colour("clMENUTEXT") : text shimL+2+gap,shimT,nameSub$(i,x) :`Text
`Highlighted
if mX>countDrop(i,1) and (mX<(countDrop(i,1)+1)+boxWidth) and mY>shimT and mY<shimB
ink rgb(49,106,197),0 : line countDrop(i,1)+4,shimT-2,countDrop(i,1)+boxWidth-2,shimT-2 :`Outline Border
ink rgb(49,106,197),0 : line countDrop(i,1)+4,shimT-2,countDrop(i,1)+4,shimB-2 :`Outline Border
ink rgb(49,106,197),0 : line countDrop(i,1)+boxWidth-3,shimT-2,countDrop(i,1)+boxWidth-3,shimB-2 :`Outline Border
ink rgb(49,106,197),0 : line countDrop(i,1)+4,shimB-3,countDrop(i,1)+boxWidth-2,shimB-3 :`Outline Border
ink rgb(189,205,236),0 : box countDrop(i,1)+5,shimT-1,countDrop(i,1)+boxWidth-3,shimB-3 :`Highlight
colour("clMENUTEXT") : text shimL+2+gap,shimT,nameSub$(i,x) :`Highlight Text
if mouseClick() = 1
subMenu_Draw(i) = 0
exitFunction nameSub$(i,x)
endif
endif
shimT = shimB
next x
endif
endif
`if mouse onOver another drop, redraw sub menu
for a = 1 to countDrop(0,0)
if subMenu_Draw(a) = 1
if (mX>countDrop(i,1) and mX<countDrop(i,3) and mY>countDrop(i,2) and mY<countDrop(i,4)) and (subMenu_Draw(i) = 0)
for x = 1 to countDrop(0,0)
if subMenu_draw(x) = 1 then subMenu_draw(x) = 0
if countDrop(x,0) > 0 then subMenu_draw(i) = 1
next x
endif
endif
next a
`if Drop reClicked or mouse clicked outside of SubMenu
if (mX>countDrop(i,1) and (mX<(countDrop(i,1)+1)+boxWidth) and mY>countDrop(i,2) and mY<(countDrop(i,4)+boxHeight))
else
if mouseClick() = 1 then subMenu_draw(i) = 0
endif
next i
`========================================================================
`we endfunction with "" as no subMenu selected (once clicked, exitfunction called)
endfunction ""
function colour(Col$)
if Col$ = "clACTIVEBORDER" then ink getColour(10),0
if Col$ = "clACTIVECAPTION" then ink getColour(2),0
if Col$ = "clAPPWORKSPACE" then ink getColour(12),0
if Col$ = "clBACKGROUND" then ink getColour(1),0
if Col$ = "clBTNFACE" then ink getColour(15),0
if Col$ = "clBTNHIGHLIGHT" then ink getColour(20),0
if Col$ = "clBTNSHADOW" then ink getColour(16),0
if Col$ = "clBTNTEXT" then ink getColour(18),0
if Col$ = "clCAPTIONTEXT" then ink getColour(9),0
if Col$ = "clGRAYTEXT" then ink getColour(17),0
if Col$ = "clHIGHLIGHT" then ink getColour(13),0
if Col$ = "clHIGHLIGHTTEXT" then ink getColour(14),0
if Col$ = "clINACTIVEBORDER" then ink getColour(11),0
if Col$ = "clINACTIVECAPTION" then ink getColour(3),0
if Col$ = "clINACTIVECAPTIONTEXT" then ink getColour(19),0
if Col$ = "clMENU" then ink getColour(4),0
if Col$ = "clMENUTEXT" then ink getColour(7),0
if Col$ = "clSCROLLBAR" then ink getColour(0),0
if Col$ = "clWINDOW" then ink getColour(5),0
if Col$ = "clWINDOWFRAME" then ink getColour(6),0
if Col$ = "clWINDOWTEXT" then ink getColour(8),0
endfunction
function colourNum(Col)
ink getColour(Col),0
endfunction
function getColour(num)
local col as dword
load dll "user32.dll",1
col = call dll(1,"GetSysColor", num)
delete dll 1
col = rgb(rgbb(col), rgbg(col), rgbr(col))
endfunction col
mainmenu_addDrop("FILE") will add a menu item called FILE
mainmenu_addSub(x,"Open") will add a sub menu called OPEN to the x drop.
menuAction$ = mainmenu_drawMenu("XPstyle") will determain the type of menu - Highlight, XPstyle or Grey
James Morgan