Post by johnno56 on Jan 16, 2020 4:30:48 GMT -6
This is a simple button press example to switch a light off and on.
The button is created using 'PolyFill'.
This is 'not' created by me. It is a Basic256 program that I converted.
I'm not sure how useful this will be except for the fact that it demonstrates polyfill.
I will not be offended if you choose not to use this example. Thought it may come in handy...
J
The button is created using 'PolyFill'.
This is 'not' created by me. It is a Basic256 program that I converted.
xmax = 300
ymax = 300
title$ = "Button Test"
WindowOpen(1,title$,0,0,xmax,ymax,0)
CanvasOpen(1,xmax,ymax,0,0,xmax,ymax,0)
Tahoma14 = 1
loadFont(1,"Tahoma.ttf",14)
black = rgb(0, 0, 0)
white = rgb(255, 255, 255)
grey = rgb(164, 164, 164)
darkgrey = rgb(128, 128, 128)
red = rgb(255, 0, 0)
darkred = rgb(128, 0, 0)
setColor(grey)
rectFill(0,0,299,299)
setColor(darkgrey)
circleFill(150, 60, 30)
' here, you set up and draw your button
' eg draw a button in the middle of the screen
dim x[3]
dim y[3]
b_locx=110
b_locy=140
b_width=80
b_height=30
b_text$="On/Off"
b_textsize=14
b_offsetx=20
b_offsety= 7
b_pressed=0
b_sw_pressed = 0
' *********************************
' sub routine "Draw a button"
' *********************************
sub button()
if b_pressed=0 then
setColor(rgb(200,200,200))
x[0] = b_locx: y[0] = b_locy
x[1] = b_locx+b_width: y[1] = b_locy
x[2] = b_locx: y[2] = b_locy+b_height
polyFill(3, x, y)
setColor(darkgrey)
x[0] = b_locx+b_width: y[0] = b_locy
x[1] = b_locx+b_width: y[1] = b_locy+b_height
x[2] = b_locx: y[2] = b_locy+b_height
polyFill(3, x, y)
setColor(grey)
rectFill(b_locx+b_width*0.05,b_locy+b_height*0.07, b_width-b_width*0.1, b_height-b_height*0.1)
setColor(black)
font(Tahoma14)
DrawText(b_text$,b_locx+b_offsetx,b_locy+b_offsety)
update()
else
setColor(darkgrey)
x[0] = b_locx: y[0] = b_locy
x[1] = b_locx+b_width: y[1] = b_locy
x[2] = b_locx: y[2] = b_locy+b_height
polyFill(3, x, y)
setColor(rgb(200,200,200))
x[0] = b_locx+b_width: y[0] = b_locy
x[1] = b_locx+b_width: y[1] = b_locy+b_height
x[2] = b_locx: y[2] = b_locy+b_height
polyFill(3, x, y)
setColor(grey)
rectFill(b_locx+b_width*0.05,b_locy+b_height*0.07, b_width-b_width*0.1, b_height-b_height*0.1)
setColor(black)
font(Tahoma14)
DrawText(b_text$,b_locx+(b_offsetx+2),b_locy+(b_offsety+2))
update()
end if
update()
end sub
button()
col=1
setColor(darkred)
circleFill(150,60,20)
setColor(red)
circleFill(145,55,5)
update()
' the logic to handle the button is up to you
' currently it just switches a light on and off
do
if MouseButton(0) = 1 then
if mouseX > b_locx and mouseX < b_locx+ b_width then
if mouseY > b_locy and mouseY < b_locy+b_height then
if getpixel(150,45)=darkred then
col=1
else
col=2
end if
if b_pressed=0 then
b_pressed=1
b_sw_pressed=1
end if
button()
if col=1 then
setColor(rgb(200,100,100))
circleFill(150, 60, 30)
setColor(red)
else
setColor(darkgrey)
circleFill(150, 60, 30)
setColor(darkred)
end if
circleFill(150, 60, 20)
if col=1 then
setColor(white)
else
setColor(red)
end if
circleFill(145,55,5)
wait(100)
if b_sw_pressed=1 then
b_sw_pressed=0
b_pressed=0
button()
else
end if
end if
end if
end if
update()
loop until key(k_escape) = 1
I'm not sure how useful this will be except for the fact that it demonstrates polyfill.
I will not be offended if you choose not to use this example. Thought it may come in handy...
J