Code: Select all
''
Switches by rbytes, October 2017
each one is a button that toggles to an alternate image when touched
#.button is a button. Pressing a button registers an action. Group elements are:
backcolor(r,g,b,a) - function to set button color with red, green, blue and alpha r,g,b,a components, alpha component is optional;
fontcolor(r,g,b,a) - function to set font color with red, green, blue and alpha r,g,b,a components, alpha component is optional;
fontname - font name;
fontsize - font size;
height - button height;
image - path to button background image;
text - text on button;
width - button width;
x - offset from left screen border;
y - offset from top screen border.
''
bs,cs,ds,es,fs = 0 ' flags for switches
' light bulbs off
j = #.image
j.source = "bulb-off.png"
j.width = 60
j.height = 100
j.y = 100
k,l,m,n = j
j.x = 270
k.x = 420
l.x = 570
m.x = 720
n.x = 870
#.show(j,k,l,m,n)
' light bulbs on
j2 = #.image
j2.source = "bulb-on.png"
j2.width = 60
j2.height = 100
j2.y = 100
k2,l2,m2,n2 = j2
j2.x = 270
k2.x = 420
l2.x = 570
m2.x = 720
n2.x = 870
b = #.button
b.width = 100
b.height = 40
b.y = 300
b.text = ""
b.image = "sw-off.png"
c,d,e,f = b
b.x = 250
c.x = 400
d.x = 550
e.x = 700
f.x = 850
#.show(b,c,d,e,f)
>
? #.act(b)
bs = 1 - bs
? bs
b.image = "sw-on.png"
#.show(j2)
!
b.image = "sw-off.png"
#.hide(j2)
.
.
? #.act(c)
cs = 1 - cs
? cs
c.image = "sw-on.png"
#.show(k2)
!
c.image = "sw-off.png"
#.hide(k2)
.
.
? #.act(d)
ds = 1 - ds
? ds
d.image = "sw-on.png"
#.show(l2)
!
d.image = "sw-off.png"
#.hide(l2)
.
.
? #.act(e)
es = 1 - es
? es
e.image = "sw-on.png"
#.show(m2)
!
e.image = "sw-off.png"
#.hide(m2)
.
.
? #.act(f)
fs = 1 - fs
? fs
f.image = "sw-on.png"
#.show(n2)
!
f.image = "sw-off.png"
#.hide(n2)
.
.
#.relax()
<