Code: Select all
'' bluatigro 19 dec 2017
'' button
screen 20 , 32
dim shared as integer mousex , mousey , winx , winy , mousebutton
screeninfo winx , winy
type tbutton
public :
dim as integer x , y , w , h
dim as ulong kl , hover , push
declare function hit( a as integer , b as integer ) as integer
declare sub show
end type
function tbutton.hit( a as integer , b as integer ) as integer
if a < x then return 0
if a > x + w then return 0
if b < y then return 0
if b > y + h then return 0
return 1
end function
sub tbutton.show
if hit( mousex , mousey ) then
if mousebutton then
line ( x , y ) - step ( w , h ) , push , bf
else
line ( x , y ) - step ( w , h ) , hover , bf
end if
else
line ( x , y ) - step ( w , h ) , kl , bf
end if
end sub
dim as tbutton button( 20 )
dim as integer i
for i = 0 to ubound( button )
button(i).x = i * 50
button(i).y = winy / 2 - 20
button(i).w = 40
button(i).h = 40
button(i).kl = rgb( 0 , 255 , 0 )
button(i).hover = rgb( 0 , 0 , 255 )
button(i).push = rgb( 255 , 0 , 0 )
next i
do
cls
if not getmouse( mousex , mousey , , mousebutton ) then
end if
for i = 0 to ubound( button )
button(i).show
next i
sleep 100
loop until inkey = chr( 27 )