sync on : sync rate 0
`This is for saving me some troubles
dim Mouse$(3)
Mouse$(0) = "Nothing"
Mouse$(1) = "Left mouseclick"
Mouse$(2) = "Right mouseclick"
Mouse$(3) = "Both mousebuttons are pressed"
do
cls
for i = 1 to 5
`Draw 5 buttons
ink rgb(255,255,255),0
text 5, 5 + ((i-1)*18), Mouse$(TextButton(320, 10 + ((i-1)*18), "This is button " + str$(i), rgb(0,255,0)))
next i
sync
loop
`*************
`* Functions *
`*************
`A ordinary text button
function TextButton(x, y, text$, MouseOverColor)
`Reset variables( when using more than 1 buttons )
pressed = 0
`Get text width and height
tx = text width(text$) / 2
ty = text height(text$) / 2
`Get mouseOver
if mousex() < x + tx and mousex() > x - tx
if mousey() < y + ty and mousey() > y - ty
pressed = 1
endif
endif
`Change color
if pressed > 0 then ink MouseOverColor, 0
center text x, y - ty, text$
`Reset if the user didn't click
if pressed > 0 then pressed = mouseclick()
endfunction pressed
There are alot of variations on buttons. For example, in the example-section of the help files, try opening the "record sounds"-example. (Boxed button)
Mine is an example of an ordinary text button.