Here is a toolbar for building your applications with. It is modular so it should be able to be dropped into any existent programs without conflict minus the possibility of variable name conflicts. No known bugs glitches or errors currently.
How to use? put code below into your program than copy the bulky second code into a bank agc file and save it as toolbar.agc put it in your program directory beside your main and your good to go. toolbar will scale if window size changes.
#include "toolbar.agc"
put this outside of your main loop it only needs to run once
code is optomised so it only draws each element one time. sprites are deleted when not in use but images are stored. loop only checks 5 sprite hits per loop. only time elements are redrawn is if the window size changes
gosub LoadVariables:
#Constant ParentNums=5
BuildMainToolbar()
put RunMenu() somewhere inside your do <-> loop
copy into toolbar.agc
LoadVariables:
Type MainParentType
x_offset as integer
localoffset as integer
parent_string as string
Parent_width as string
parent_height as string
Offset as integer
Child as MainParentChild[10]
SpriteID as integer
ImageID as integer
Hover as integer
ChildSpriteID as integer
ChildimageID as integer
entrys as integer
endtype
global Main as mainparenttype [ParentNums]
Type MainParentChild
Data as string
Action as string
endtype
global screen_width as integer:screen_width=getwindowwidth()
global screen_height as integer:screen_height=getwindowheight()
global oldheight as integer:oldheight=screen_height
global oldwidth as integer:oldwidth=screen_width
global fontsize as integer:fontsize=18
global black_col as integer:black_col=makecolor(0,0,0)
global Dgray_col as integer:Dgray_col=makecolor(80,80,80)
global Lgray_col as integer:Lgray_col=makecolor(100,100,100)
global White_col as integer:White_col= makecolor(255,255,255)
global HighlighterIID
global HighlighterSID
global clicked as integer//can replace with whatever u want to for clicked funtion
global backgroundSID as integer
global backgroundIID as integer
global ActiveChild as integer
global textheight as integer
global textwidth as integer
global size=1
BuildHighlighter()
return
function resolution()
screen_height=GetWindowHeight()
screen_width=GetWindowWidth()
if screen_height <>oldHeight or screen_width<>oldwidth
oldHeight=screen_height=GetWindowheight()
oldwidth=screen_width=GetWindowwidth()
SetVirtualResolution(screen_width,screen_height)
DrawToolbarBackground()
endif
endfunction
function BuildMainToolbar()
main[1].x_offset=10
main[1].parent_string="File"
main[2].parent_string="Edit"
main[3].parent_string="Tools"
main[4].parent_string="Options"
main[5].parent_string="Help"
main[1].Child[1].Data="Open"
main[1].Child[2].Data="Open Recent"
main[1].Child[3].Data="New"
main[1].Child[4].Data="Save"
main[1].Child[5].Data="Save as"
main[1].Child[6].Data="Exit"
main[2].Child[1].Data="Cut"
main[2].Child[2].Data="Copy"
main[2].Child[3].Data="Paste"
main[3].Child[1].Data="Tool1"
main[3].Child[2].Data="Tool2"
main[3].Child[3].Data="Tool3"
main[3].Child[4].Data="Tool4"
main[4].Child[1].Data="Option1"
main[4].Child[2].Data="Option2"
main[4].Child[3].Data="Option3"
main[4].Child[4].Data="Option4"
main[4].Child[5].Data="Option5"
main[4].Child[6].Data="Option6"
main[4].Child[7].Data="Option7"
main[4].Child[8].Data="Option8"
main[4].Child[9].Data="Option9"
main[4].Child[10].Data="Option10"
main[5].Child[1].Data="Help Files"
main[5].Child[2].Data="Key Reference"
main[5].Child[3].Data="Contact"
main[5].Child[4].Data="About"
text=toolbar_parents()
DrawToolbarBackground()
buildChildren(text)
//fill children entrys
for i = 1 to parentnums
for b= 1 to 10
if len(main[i].child[b].data)>=1
main[i].entrys=main[i].entrys+1
endif
next
next
endfunction
function DrawToolbarBackground()
clearscreen()
size=26
drawbox(0,0,screen_Width-1,size+1,black_col,black_col,black_col,black_col,1)
drawbox(0+1,0+1,screen_Width-2,size/2,Dgray_col,dgray_col,lgray_col,lgray_col,1)//splitbox top
drawbox(0+1,(size/2)+1,screen_Width-2,size,lgray_col,lgray_col,dgray_col,dgray_col,1)//splitbox top
render()
if backgroundSID>0
deletesprite(BackgroundSID)
deleteimage(BackgroundIID)
endif
image=GetImage(0,0,screen_Width-1,28):BackgroundIID=image
sprite=createsprite(image):backgroundSID=sprite
setspritedepth(sprite,10)
endfunction
function toolbar_parents()
SetClearcolor(145,145,145)
text=createtext("")
settextvisible(text,0)
settextsize(text,fontsize)
settextstring(text,"a")
textheight=gettexttotalheight(text)
textwidth=gettexttotalwidth(text)
settextstring(text,"")
clearscreen()
#constant ToolBarBackgroundID=GetImage(0,0,MaxWidth,42)
#constant ToolBarSpriteID=createsprite(ToolBarBackgroundID)
for i = 1 to ParentNums
settextvisible(text,1)
settextstring(text,main[i].parent_string)
width=GetTextTotalWidth(text)+20
size=26//even number only
drawbox(0,2,width,size/2,Dgray_col,dgray_col,lgray_col,lgray_col,1)//splitbox top
drawbox(0,(size/2)+1,width,size-1,lgray_col,lgray_col,dgray_col,dgray_col,1)//splitbox top
settextposition(text,10,size/2-fontsize/2)
render()
drawtext(text)
settextstring(text,"")
settextvisible(text,0)
image=getimage(0,0,width,size)
sprite=createsprite(image)
main[i].spriteID=sprite
main[i].ImageID=image
setspritedepth(sprite,2)
xoffset=main[1].x_offset
setspriteposition(sprite,xoffset,0)
main[i].localoffset=xoffset
main[1].x_offset=main[1].x_offset+width+10
clearscreen()
next
endfunction text
function buildChildren(text)
child=0
for parent=1 to ParentNums
for i=1 to 10 //get data of children determin longest lenght
if len(main[Parent].child[i].data)>=1
inc child,1
endif
settextstring(text,main[Parent].child[i].Data)
lenght1=GetTextTotalWidth(text)
if lenght <lenght1
lenght=lenght1
endif
settextstring(text,"")
next
padding=8
rows=child*textheight
drawbox(0,0,lenght+60,rows+1,black_col,black_col,black_col,black_col,1)
drawbox(0+1,0+1,lenght+60-2,rows,Dgray_col,dgray_col,lgray_col,lgray_col,1)//splitbox top
drawline(20,3,20,rows-2,128,128,128)
drawline(21,3,21,rows-2,140,140,140)
for i= 1 to child
drawline(23,((i-1)*textheight)+padding-(textheight/2),lenght+50,((i-1)*textheight)+padding-(textheight/2),110,110,110)
next
render()
settextvisible(text,1)
for i= 1 to child
SetTextPosition(text,25,((i-1)*textheight)+padding-(textheight/2) )
settextstring(text,main[Parent].child[i].Data)
DrawText(text)
next
child=0
settextvisible(text,0)
image=getimage(0,0,lenght+60,rows+2)
main[Parent].ChildImageID=image
clearscreen()
next
endfunction
Function RunMenu()
resolution()
HitID=getspritehit(getrawmousex(),getrawmousey())
for i = 1 to Parentnums //get the number for array not id
if main[i].SpriteID=HitID
Highlightparent(i,HitID)
endif
if main[i].SpriteID<>HitID
UnHighlightParent(i,HitID)
endif
next
mouseclick()
DeleteChild()
RunChildren()
SelectSubroutine()
Endfunction
function mouseclick()
if clicked=0
if GetRawMouseLeftPressed()=1
for i = 1 to ParentNums
if main[i].hover=1
CreateChild(i)
clicked=1
endif
next
endif
endif
if clicked=1 and GetRawMouseLeftPressed()=0
clicked=0
endif
endfunction
function highlightparent(parent,HitID)
if main[parent].Hover=0
parentid=main[parent].SpriteID
setspritecolor(ParentID,355,355,355,355)
main[parent].Hover=1
endif
endfunction
function UnhighlightParent(i,HitID)
if main[i].hover=1 and main[i].SpriteID<>HitID
if HitID<>main[i].SpriteID
main[i].hover=0
setspritecolor(main[i].SpriteID,255,255,255,255)
endif
endif
endfunction
Function createChild(i)
if main[i].ChildSpriteID=0
sprite=CreateSprite(main[i].ChildimageID)
setspriteposition(sprite,main[i].localoffset,27)
main[i].ChildSpriteID=sprite
activechild=i
endif
endfunction
function DeleteChild()
for b = 1 to parentnums
Target=getspritehit(getrawmousex(),getrawmousey())
if main[b].SpriteID<>target and main[b].ChildSpriteID<>target and target<>highlighterSID
if GetSpriteExists(main[b].ChildSpriteID)=1
Deletesprite(main[b].ChildSpriteID)
main[b].ChildSpriteID=0
deletesprite(highlighterSID)
highlighterSID=0
activechild=0
endif
endif
next
Endfunction
function RunChildren()
if activechild>0
If highlighterSID <1
sprite=createsprite(HighlighterIID) //keep from looping
SetSpriteDepth(sprite,1)
highlighterSID=sprite
endif
if getspriteexists(main[activechild].ChildSpriteID)>0
x=getspritex(main[activechild].ChildSpriteID)
y=getspritey(main[activechild].ChildSpriteID)
mousey=ceil(getrawmousey())
size= (mousey-y+textheight)/textheight
if size> main[ActiveChild].entrys
size=main[ActiveChild].entrys
endif
if size<1
setspritevisible(highlightersID,0)
endif
if size>0
setspritevisible(highlightersID,1)
endif
boarderoffset=22
SetSpritePosition(highlighterSID,main[activechild].localoffset+boarderoffset+2,size*textheight+10)
text=createtext(main[ActiveChild].child[size].Data)
settextsize(text,fontsize)
width=gettexttotalwidth(text)+4
deletetext(text)
setspritesize(highlighterSID,width,textheight-3)
endif
endif
endfunction
function BuildHighlighter()
blah$="label1"
clearscreen()
gray=makecolor(200,200,200,128)
drawbox(0,0,1,1,gray,gray,gray,gray,1)
render()
HighlighterIID=getimage(0,0,1,1)
endfunction
//below are examples for launching functions whith a click
function SelectSubroutine()
if activechild>0 and clicked=0
if getrawmouseleftpressed()=1 and len(main[activechild].child[size].Data)>1
if main[activechild].child[size].Data="Open"
File()
endif
if main[activechild].child[size].Data="Open Recent"
File()
endif
if main[activechild].child[size].Data="New"
`New()
endif
if main[activechild].child[size].Data="Save"
`File()
endif
if main[activechild].child[size].Data="Exit"
`File()
endif
//cleanup
for b= 1 to parentnums
if GetSpriteExists(main[b].ChildSpriteID)=1
Deletesprite(main[b].ChildSpriteID)
main[b].ChildSpriteID=0
deletesprite(highlighterSID)
highlighterSID=0
activechild=0
endif
next
endif
endif
endfunction
//////////////////////////FUNCTION EXAMPLE
function File()
file$=ChooseRawFile(".txt" )
endfunction
#constant Parentnums determines how many parent you can build adding more parent items to the menu this number must be increased. any question just ask
Enjoy
or can just download atttached file