Need a GUI?
I'm still working on run, and actually this is for my own project, but here are the functions, do realise though that it is incomplete...
function CreateToolBar(c1,c2)
length=screen width()
box 0,0,length,20,c1,c2,c1,c2
endfunction
function CreateMenu(menu_id,text$,c1,c2,h1,h2)
PosX=menu_id*80
box PosX,0,PosX+80,20,c1,c2,c1,c2
if len(text$)>9 then text$=left$(text$,9)
ink rgb(255,255,255),0
text PosX+2,2,text$
`menu$(menu_id)=text$
if mousex()>PosX : if mousey()>PosY : if mousex()<PosX+80 : if mousey()<PosY+20
box PosX,0,PosX+80,20,h1,h2,h1,h2
ink rgb(255,255,0),0
text PosX+2,2,text$
endif : endif : endif : endif
endfunction
function ShowSubMenu(menu_id,submenu_id,text$,c1,c2,h1,h2)
PosX=menu_id*80
PosY=submenu_id*20
PosY=PosY+20
`Check for the event...
if len(text$)>9 then text$=left$(text$,9)
box PosX,PosY,PosX+80,PosY+20,c1,c2,c1,c2
ink rgb(255,255,255),0
text PosX+2,PosY+1,text$
if mousex()>PosX : if mousex()<PosX+80 : if mousey()>PosY : if mousey()<PosY+20
box PosX,PosY,PosX+80,PosY+20,h1,h2,h1,h2
ink rgb(255,255,0),0
text PosX+2,PosY+1,text$
endif : endif : endif : endif
`submenu$(menu_id,submenu_id)=text$
endfunction
function IsMenuClicked(menu_id)
PosX=menu_id*80
res=0
if mouseclick()=1
if mousex()>PosX : if mousex()<PosX+80 : if mousey()>0 : if mousey()<20
res=1
endif : endif : endif : endif
endif
endfunction res
function IsSubMenuClicked(menu_id,submenu_id)
PosX=menu_id*80
PosY=submenu_id*20
res=0
if mouseclick()=1
if mousex()>PosX : if mousex()<PosX+80 : if mousey()>PosY+20 : if mousey()<PosY+40
res=1
endif : endif : endif : endif
endif
endfunction res
function GuiButton(ButtonX,ButtonY,ButtonSizeX,ButtonSizeY,text$,c1,c2,h1,h2)
res=0
`This equasion isnt working! If anyone has a fix, please post...
`Middle=ButtonSizeX/2
`Middle=ButtonX+Middle
`This part just finds X and positions the text there, this is a fix to MIDDLE
Middle=ButtonX+2
box ButtonX,ButtonY,ButtonSizeX,ButtonSizeY,c1,c2,c1,c2
ink rgb(255,255,255),0
text Middle,ButtonY+2,text$
if mousex()>ButtonX : if mousex()<ButtonSizeX : if mousey()>ButtonY : if mousey()<ButtonSizeY
res=1
box ButtonX,ButtonY,ButtonSizeX,ButtonSizeY,h1,h2,h1,h2
ink rgb(255,255,0),0
`center text Middle,ButtonY+2,text$
text Middle,ButtonY+2,text$
if mouseclick()=1
res=2
endif
endif : endif : endif : endif
ink rgb(255,255,255),0
endfunction res
And also, there is a problem with the button, I can't seem to get the exact middle of the button with Temp=ButtonSizeX/2 : Middle=ButtonX+Temp : center text Middle,ButtonY+2,text$
Any ideas? For now, it just positions the text right in the left hand side of the button. If you guys need an example, here you go (Not sure which one this is though..)
REM Project: EasyEdit
REM Created: 7/13/2006 2:30:23 PM
REM
REM ***** Main Source File *****
REM
`dim menu$(100)
`dim submenu$(100,100)
box 0,0,256,256,rgb(rnd(255),rnd(255),rnd(255)),rgb(rnd(255),rnd(255),rnd(255)),rgb(rnd(255),rnd(255),rnd(255)),rgb(rnd(255),rnd(255),rnd(255))
get image 1,0,0,255,255
box 0,0,256,256,rgb(rnd(255),rnd(255),rnd(255)),rgb(rnd(255),rnd(255),rnd(255)),rgb(rnd(255),rnd(255),rnd(255)),rgb(rnd(255),rnd(255),rnd(255))
get image 2,0,0,255,255
make object cone 1,200
set cartoon shading on 1,1,2
set ambient light 100
color backdrop rgb(0,0,0)
`draw to front
sync on
do
`Do not use the 'cls' command!!! It will cause 3D objects to not be seen!
CreateToolBar(rgb(50,50,50),rgb(150,150,150))
CreateMenu(0,"File",rgb(50,50,50),rgb(150,150,150),rgb(10,40,50),rgb(110,140,150))
CreateMenu(1,"Edit",rgb(50,50,50),rgb(150,150,150),rgb(10,40,50),rgb(110,140,150))
CreateMenu(2,"View",rgb(50,50,50),rgb(150,150,150),rgb(10,40,50),rgb(110,140,150))
CreateMenu(3,"Help",rgb(50,50,50),rgb(150,150,150),rgb(10,40,50),rgb(110,140,150))
CreateMenu(4,"123456789",rgb(50,50,50),rgb(150,150,150),rgb(10,40,50),rgb(110,140,150))
File=IsMenuClicked(0) : Edit=IsMenuClicked(1) : View=IsMenuClicked(2) : Help=IsMenuClicked(3) : Test=IsMenuClicked(4)
if File=1 : a=1 : endif : if Edit=1 : a=2 : endif : if View=1 : a=3 : endif : if Help=1 : a=4 : endif : if Test=1 : a=5 : endif
if File=1 : repeat : until mouseclick()=0 : endif
if Edit=1 : repeat : until mouseclick()=0 : endif
if View=1 : repeat : until mouseclick()=0 : endif
if Help=1 : repeat : until mouseclick()=0 : endif
if Test=1 : repeat : until mouseclick()=0 : endif
if a=1
ShowSubMenu(0,0,"File1",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
ShowSubMenu(0,1,"File2",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
ShowSubMenu(0,2,"File3",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
if IsMenuClicked(0)=1 then a=0
endif
if a=2
ShowSubMenu(1,0,"Edit1",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
ShowSubMenu(1,1,"Edit2",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
if IsMenuClicked(1)=1 then a=0
endif
if a=3
ShowSubMenu(2,0,"View1",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
if IsMenuClicked(2)=1 then a=0
endif
if a=4
ShowSubMenu(3,0,"Help1",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
ShowSubMenu(3,1,"Help2",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
if IsMenuClicked(3)=1 then a=0
endif
if a=5
ShowSubMenu(4,0,"Test1",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
ShowSubMenu(4,1,"Test2",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
ShowSubMenu(4,2,"Test3",rgb(50,50,50),rgb(150,150,150),rgb(0,0,50),rgb(0,0,150))
if IsMenuClicked(4)=1 then a=0
endif
turn object left 1,1
sync
loop
function CreateToolBar(c1,c2)
length=screen width()
box 0,0,length,20,c1,c2,c1,c2
endfunction
function CreateMenu(menu_id,text$,c1,c2,h1,h2)
PosX=menu_id*80
box PosX,0,PosX+80,20,c1,c2,c1,c2
if len(text$)>9 then text$=left$(text$,9)
ink rgb(255,255,255),0
text PosX+2,2,text$
`menu$(menu_id)=text$
if mousex()>PosX : if mousey()>PosY : if mousex()<PosX+80 : if mousey()<PosY+20
box PosX,0,PosX+80,20,h1,h2,h1,h2
ink rgb(255,255,0),0
text PosX+2,2,text$
endif : endif : endif : endif
endfunction
function ShowSubMenu(menu_id,submenu_id,text$,c1,c2,h1,h2)
PosX=menu_id*80
PosY=submenu_id*20
PosY=PosY+20
`Check for the event...
if len(text$)>9 then text$=left$(text$,9)
box PosX,PosY,PosX+80,PosY+20,c1,c2,c1,c2
ink rgb(255,255,255),0
text PosX+2,PosY+1,text$
if mousex()>PosX : if mousex()<PosX+80 : if mousey()>PosY : if mousey()<PosY+20
box PosX,PosY,PosX+80,PosY+20,h1,h2,h1,h2
ink rgb(255,255,0),0
text PosX+2,PosY+1,text$
endif : endif : endif : endif
`submenu$(menu_id,submenu_id)=text$
endfunction
function IsMenuClicked(menu_id)
PosX=menu_id*80
res=0
if mouseclick()=1
if mousex()>PosX : if mousex()<PosX+80 : if mousey()>0 : if mousey()<20
res=1
endif : endif : endif : endif
endif
endfunction res
function IsSubMenuClicked(menu_id,submenu_id)
PosX=menu_id*80
PosY=submenu_id*20
res=0
if mouseclick()=1
if mousex()>PosX : if mousex()<PosX+80 : if mousey()>PosY+20 : if mousey()<PosY+40
res=1
endif : endif : endif : endif
endif
endfunction res
Ah, this one is for the toolbar... Good then, this one works well... And here is an untested example for how to use the button...
sync on
backdrop on
do
cls
result=GuiButton(20,20,40,40,"OK",rgb(50,50,50),rgb(150,150,150))
if result=0 then center text 320,230,"Go near the button!"
if result=1 then center text 320,230,"Click the button!"
if result=2 then center text 320,230,"The button was clicked!"
sync
loop
There you guys go! I think this is the first GUI on the forums to have a menu bar...
Oh, and the code in the first example does not permit ability to close a menu once openned, you will have to edit that yourself
Royalty-Free use, just include in credits (Naming function) - Thank you.
Uhh, That should be it, have fun with the code!
I finally have a NEW computer!!!
Windows XP Pro, AMD Athlon 64-BIT Processor, ATI Radeon Graphics, Windows Vista compatable, DirectX 9.0c, 2 Hard Drives, 6 Extra Drives, etc. etc.