Here are some GUI functions for you to play with. Media is attached. I'll post more info in a minute.
[edit]
Ok, more info:
This is slightly different to what I used to do because:
1) It's actually made out of 3D Plains positioned at the screen (thanks CuCuMBeR)
2) All the text you see on the buttons etc is actually textured onto the objects, which means different things can be ordered easily without the text always being at the front.
3)I've never been able to make a menu bar before
, but I looked at Phaelax's code (didn't copy it though), and I just got an idea of adding menus by making a seperate function for each of them, rather than making some kind of tokenizer - thanks Phaelax.
Here are the functions:
initGUI() - Starts everything up
setBackground() - Makes the background
makeFrame() - Creates a frame
loadButton() - This will load the images for the buttons
makeButton() - Put a button somewhere
handleButtons() - Controls all the buttons
loadMenu() - Loads the images for the menus
num=addMenu() - Created a menu.. thing.. like "File" or "Edit"
num=addSubMenu() - Makes a emm.. sub menu
createMenus() - Actually makes the menus
handleMenus() - Controls the menus (not super perfect yet, but good)
getMenuSelection() - Finds what you have selected from the menu
menuSelection() - Returns 1 if selection is equal to the parameter
handleGUI() - just a quick shortcut so you can handle all things
Sprite3D() - Makes a 3d sprite (Hooray to CuCuMBeR)
showSprite3D() - Shows a sprite, only use if sprite is hidden
hideSprite3D() - vice versa
ghostSprite3D() - ghosts the sprite
unghostSprite3D() - unghosts it
freeimage() - everyone knows this one - finds a free image...
freeobject() - ...and this finds a free object.
I appologise for some objects/images and variables having to be used in this one, but I guess you could use the freeobject/image() functions to work around that.
Have fun (if you can't afford BlueGUI that is)
[edit]
Oh, and in the screenshot below, you can't see the mouse, bloody windows... ¬_¬', oh well, it's actually over File>Save As.
The menu works btw, just doesn't do anything right now, but that's cos it has nothing to do. But to prove it try clicking on file>exit and it will work fine.
Oh, and the menus don't have to be ghosted, you can choose that in the addMenu() function.
`*New GUI Functions*
`Created by: Alastair Zotos, 19th July 2006
`*Main Source File*
`init
sync on : sync rate 60
set display mode 1024,768,16
set window on : maximize window
set window title "GUI"
initGUI("tahoma",20,rgb(0,0,50))
type button
x1 as integer
x2 as integer
y1 as integer
y2 as integer
txt as string
state as integer
obj as integer
img1 as integer : img2 as integer : img3 as integer
endtype
type menu
x as integer
items as integer
obj as integer
img as integer
height as integer
txt as string
show as boolean
ghost as boolean
endtype
global button
global menu
global menuitem
loadButton("Buttons1.bmp")
loadMenu("Menu1.bmp")
`Create GUI
setBackground("Backgd1.bmp")
makeframe(10,330,130,500,"Frame1.bmp")
btn1=makebutton(20,360,120,390,"Button 1",rgb(255,255,0))
btn2=makebutton(20,400,120,430,"Button 2",rgb(255,255,0))
btn3=makebutton(20,440,120,470,"Button 3",rgb(255,255,0))
file=addMenu("File",1)
edit=addMenu("Edit",1)
view=addMenu("View",1)
fnew=addSubMenu(file,"New")
fopen=addSubMenu(file,"Open")
fsave=addSubMenu(file,"Save")
fsaveas=addSubMenu(file,"Save As")
fspace1=addSubMenu(file,"")
fexit=addSubMenu(file,"Exit")
eundo=addSubMenu(edit,"Undo")
eredo=addSubMenu(edit,"Redo")
epaste=addSubMenu(edit,"Paste")
vtbars=addSubMenu(view,"Toolbars")
createMenus()
`Main Loop
do
`Info
ink rgb(255,255,255),0
if menuSelection(file,fexit) then end
`handle GUI
handleGUI()
sync
loop
`Functions
`Setup--
function initGUI(font$,size,col)
dim imgtaken(65535) as boolean
dim spttaken(65535) as boolean
dim objtaken(65535) as boolean
dim button(0) as button
dim menu(0) as menu
set text font font$ : set text size size
global gcol=col
endfunction
`Background--
function setbackground(img$)
local i as integer : i=freeimage()
local o as integer : o=freeobject()
load image img$,i : sprite3d(o,0,0,screen width(),screen height(),i)
endfunction
`Frame--
function makeframe(x1,y1,x2,y2,img$)
local i as integer : i=freeimage()
local obj as integer : obj=freeobject()
load image img$,i
sprite3d(obj,x1,y1,(x2-x1),(y2-y1),i)
endfunction num
`Button--
function loadButton(img$)
local i as integer : i=freeimage()
global tbi1=10
create bitmap 1,100,90 : set current bitmap 1
load image img$,i : paste image i,0,0
get image tbi1,1,1,100,90
delete image i
set current bitmap 0 : delete bitmap 1
endfunction
function makebutton(x1,y1,x2,y2,txt$,col)
local num as integer
array insert at bottom button()
num=array count(button())
button(num).x1=x1 : button(num).x2=x2
button(num).y1=y1 : button(num).y2=y2
button(num).txt=txt$
button(num).state=1
button(num).obj=freeobject()
button(num).img1=freeimage() : button(num).img2=freeimage() : button(num).img3=freeimage()
create bitmap 1,100,90 : set current bitmap 1
paste image tbi1,0,0
ink col,0
center text 50,15-((text size()/2)+3),txt$
center text 50,45-((text size()/2)+3),txt$
center text 50,75-((text size()/2)+3),txt$
get image button(num).img1,0,0,100,29
get image button(num).img2,0,30,100,59
get image button(num).img3,0,60,100,89
set current bitmap 0 : delete bitmap 1
endfunction num
function handlebuttons()
local count as integer : count=array count(button())
local bi as integer
for b=1 to count
if menushow=0
if mousex()>button(b).x1 and mousex()<button(b).x2 and mousey()>button(b).y1 and mousey()<button(b).y2
button(b).state=2
else
button(b).state=1
endif
endif
if button(b).state=2 and mouseclick()
button(b).state=3
endif
if button(b).state=1 then bi=button(b).img1
if button(b).state=2 then bi=button(b).img2
if button(b).state=3 then bi=button(b).img3
Sprite3d(button(b).obj,button(b).x1,button(b).y1,button(b).x2-button(b).x1,button(b).y2-button(b).y1,bi)
next b
endfunction
`Menu--
function loadmenu(img$)
local i as integer : i=freeimage()
global mi1=20 : global mi2=21 : global mt1=22 : global mis=23
create bitmap 1,300,400 : set current bitmap 1
load image img$,i : paste image i,0,0
get image mi1,1,1,256,30
get image mi2,1,31,300,400
get image mis,256,1,266,10
delete image i
set current bitmap 0 : delete bitmap 1
global menuobj : menuobj=freeobject()
global menu_sel as string
global menushow as integer
endfunction
function addmenu(txt$,ghst)
array insert at bottom menu()
count=array count(menu())
menu(count).txt=txt$
menu(count).x=(count*50)-50
menu(count).obj=freeobject()
menu(count).img=freeimage()
if ghst>0 then menu(count).ghost=1
endfunction count
function addSubMenu(p,txt$)
count=array count(menu()) : dim mitem(count,100) as string
local i as integer
menu(p).items=menu(p).items+1
mitem(p,menu(p).items)=txt$
i=menu(p).items
endfunction i
function createmenus()
local count as integer
count=array count(menu())
for m=1 to count
create bitmap 1,screen width(),30 : set current bitmap 1
for p=1 to int(screen width()/256)+1
paste image mi1,(p*250)-250,0
next p
ink gcol,0
for mi=1 to count
text menu(mi).x+10,5,menu(mi).txt
next mi
get image mt1,0,0,screen width(),30
set current bitmap 0 : delete bitmap 1
menu(m).height=(menu(m).items*(text size()))+10
mh=menu(m).height
create bitmap 1,200,menu(m).height : set current bitmap 1
paste image mi2,0,0
for i=1 to menu(m).items
ink gcol,0
text 30,(20*i)-15,mitem(m,i)
next i
get image menu(m).img,0,0,200,menu(m).height
set current bitmap 0 : delete bitmap 1
next m
delete image mi1
delete image mi2
endfunction
function handlemenus()
count=array count(menu())
for m=1 to count
sprite3d(menuobj,0,0,screen width(),30,mt1)
if menu(m).show=1
if mousex()>menu(m).x and mousex()<menu(m).x+200 and mousey()<menu(m).height+30
menushow=m
endif
else
if mousex()>menu(m).x and mousex()<menu(m).x+50 and mousey()<30 and mouseclick()
menushow=m
endif
endif
if mousey()<30 and menushow>0
if mousex()<menu(m).x or mousex()>menu(m).x+50
menushow=0
endif
endif
if menushow>0
if mousex()<menu(m).x or mousex()>menu(m).x+200 or mousey()>menu(m).height+30
menushow=0
endif
endif
menu(m).show=0 : menu(menushow).show=1
sprite3d(menu(m).obj,menu(m).x,30,200,menu(m).height,menu(m).img)
if menu(m).ghost=1 then ghostsprite3d(menu(m).obj)
if menu(m).show=1
showsprite3d(menu(m).obj)
else
hidesprite3d(menu(m).obj)
endif
for i=1 to menu(m).items
if menushow>0
if mousey()>30+(i*text size())-10 and mousey()<30+(i*text size())
misel=i
if mouseclick() then m_sel=m : i_sel=i
else
misel=0
endif
endif
if menu(m).show=1
if misel>0 and mitem(m,misel)<>""
paste image mis,menu(m).x+8,(misel*text size())+20
endif
endif
next i
if m_sel>0 and i_sel>0 then menu(menushow).show=0
next m
menu_sel=str$(m_sel)+","+str$(i_sel)
endfunction
function getmenuselection()
local m as string : m=menu_sel
endfunction m
function menuselection(a,b)
local is as boolean
if str$(a)+","+str$(b)=menu_sel then is=1 else is=0
endfunction is
`Stuff--
function handleGUI()
handleButtons()
handleMenus()
endfunction
`Sprite--
function sprite3d(obj,x,y,sx,sy,i)
if object exist(obj)=0
make object plain obj,sx,sy
x#=0-((screen width()/2)-(sx/2))+x
y#=((screen height()/2)-(sy/2))-y
z#=(screen width()-screen height())*2.5
position object obj,x#,y#,z#
lock object on obj
disable object zwrite obj
set object ambient obj,0 : set object light obj,0
set object fog obj,0 : set object transparency obj,1
endif
if object exist(obj) then texture object obj,i
endfunction
function showsprite3d(obj)
show object obj
endfunction
function hidesprite3d(obj)
hide object obj
endfunction
function ghostsprite3d(obj)
ghost object on obj
endfunction
function unghostsprite3d(obj)
ghost object off obj
endfunction
`Free Entities--
function freeimage()
for i=1 to 65535
if image exist(i)=0 and imgtaken(i)=0
imgtaken(i)=1 : exitfunction i
endif
next i
endfunction 0
function freeobject()
for o=1 to 65535
if object exist(o)=0 and objtaken(o)=0
objtaken(o)=1 : exitfunction o
endif
next o
endfunction 0