This is a function i had been meaning to make for a long time to quickly make a main menu for a project i just started but i never got around to it, until now! You just enter the text you want the text, xpos, ypos, size and a changing variable that it passes, not really a paramater. The script changes the size of the box according to the size of the text.
Example of how to use the function -
just copy and paste into the cli, change the setting to fullscreen and run.
`make this fullscreen in the cli!!!!
set display mode 1024, 768, screen depth()
sync on : sync rate 0
main_menu:
do
cls
set cursor 0,0
set text size 20
print "FPS: ", screen fps()
print "X: ", mousex()
print "Y: ", mousey()
print "Hovering Button? ", hover_value
hover_value = menuItem("Play", 1024/2, 768/2, 50, hover_value)
`You cant put this in the function, so put it after every execution of the command
`Make sure you us a different variable every time you us the function
if hover_value = 1 and mouseclick() = 1 then gosub loading
sync
loop
return
loading:
`Predefine vars!
do
cls
set text size 60
center text 1024/2, 768/2, "Loading....."
set text size 15
center text 1024/2, 768/3*2, "(This will never load)"
sync
loop
return
`Function
function menuItem(text_value$, posx, posy, size, hover)
set text font "Comic Sans MS"
set text to bold
set text size size
set cursor posx, posy
height = text height(text_value$)
width = text width(text_value$)
left = posx - 1 - (size/2)
right = posx + width + 1 + (size/2)
top = posy + size / 5 - (size/6)
bottom = posy + height + 1 + (size/6.7)
if hover = 0
ink rgb(0,64,0),0
box left-(size/5), top-(size/6), right+(size/5), bottom+(size/7)
ink rgb(0,130,0),0
box left, top, right, bottom
ink rgb(0,50,0),0
else
ink rgb(0,64,0),0
box left-(size/5), top-(size/6), right+(size/5), bottom+(size/7)
ink rgb(0,255,0),0
box left, top, right, bottom
hover = 0
ink rgb(0,50,0),0
endif
print text_value$
ink rgb(255,15,15),0
if mousex() >= left and mousex() <= right then if mousey() >= top and mousey() <= bottom then hover = 1
endfunction hover
Just the function -
When using this function make sure you make a variable = the function and pass that variable as the value of hover. When using to make multiple button make all the variables different names.
function menuItem(text_value$, posx, posy, size, hover)
set text font "Comic Sans MS"
set text to bold
set text size size
set cursor posx, posy
height = text height(text_value$)
width = text width(text_value$)
left = posx - 1 - (size/2)
right = posx + width + 1 + (size/2)
top = posy + size / 5 - (size/6)
bottom = posy + height + 1 + (size/6.7)
if hover = 0
ink rgb(0,64,0),0
box left-(size/5), top-(size/6), right+(size/5), bottom+(size/7)
ink rgb(0,130,0),0
box left, top, right, bottom
ink rgb(0,50,0),0
else
ink rgb(0,64,0),0
box left-(size/5), top-(size/6), right+(size/5), bottom+(size/7)
ink rgb(0,255,0),0
box left, top, right, bottom
hover = 0
ink rgb(0,50,0),0
endif
print text_value$
ink rgb(255,15,15),0
if mousex() >= left and mousex() <= right then if mousey() >= top and mousey() <= bottom then hover = 1
endfunction hover
Any imporvments, suggestions or comments are welcome.