villares 2020-04-19 20:42:20 -03:00
rodzic f584b245f9
commit 8c4339aca2
3 zmienionych plików z 143 dodań i 0 usunięć

Wyświetl plik

@ -0,0 +1,59 @@
estado_inicial = True
def setup():
global b1, b2
size(400, 400)
b1 = Botao(100, 150, 200, 50, "clique aqui")
b2 = Botao(100, 200, 200, 50, "de novo!")
def draw():
if estado_inicial:
background(200)
else:
background(10)
global estado_inicial
resultado1 = b1.display()
resultado2 = b2.display()
if resultado1 or resultado2:
print('clique')
estado_inicial = not estado_inicial
class Botao():
def __init__(self, x, y, w, h, t):
self.x, self.y = x, y
self.w, self.h = w, h
self.t = t
self.pressed = False
def mouse_over(self):
return (self.x < mouseX < self.x + self.w and
self.y < mouseY < self.y + self.h)
def display(self):
mouse_over = self.mouse_over()
if mouse_over:
fill(140)
else:
fill(240)
rectMode(CORNER)
rect(self.x, self.y, self.w, self.h, 5)
fill(0)
textAlign(CENTER, CENTER)
text(self.t,
self.x + self.w / 2,
self.y + self.h / 2)
if mouse_over and self.pressed and not mousePressed:
self.pressed = False
return True
if mouse_over and mousePressed:
self.pressed = True
else:
self.pressed = False
return False

Wyświetl plik

@ -0,0 +1,45 @@
estado_inicial = True
def setup():
size(400, 400)
def draw():
global estado_inicial
if estado_inicial:
background(200)
else:
background(10)
resultado1 = botao(100, 125, 200, 50, "clique aqui")
resultado2 = botao(100, 225, 200, 50, "de novo!")
if resultado1 or resultado2:
print('clique')
estado_inicial = not estado_inicial
def botao(x, y, w, h, _text):
global estado_botoes
try:
estado_botoes
except NameError:
estado_botoes = dict()
mouse_over = (x < mouseX < x + w and
y < mouseY < y + h)
if mouse_over:
fill(140)
else:
fill(240)
rect(x, y, w, h, 5)
fill(0)
textAlign(CENTER, CENTER)
text(_text, x + w / 2, y + h / 2)
if mouse_over:
if mousePressed:
estado_botoes[(x, y)] = True
return False
elif estado_botoes.get((x, y)):
estado_botoes[(x, y)] = False
return True
estado_botoes[(x, y)] = False
return False

Wyświetl plik

@ -0,0 +1,39 @@
estado_inicial = True
def setup():
size(400, 400)
def draw():
global estado_inicial
if estado_inicial:
background(200)
else:
background(10)
resultado1 = botao(100, 125, 200, 50, "clique aqui")
resultado2 = botao(100, 225, 200, 50, "de novo!")
if resultado1 or resultado2:
print('clique')
estado_inicial = not estado_inicial
def botao(x, y, w, h, _text):
mouse_over = (x < mouseX < x + w and
y < mouseY < y + h)
if mouse_over:
fill(140)
else:
fill(240)
rect(x, y, w, h, 5)
fill(0)
textAlign(CENTER, CENTER)
text(_text, x + w / 2, y + h / 2)
if mouse_over:
if mousePressed:
botao.__dict__[(x, y)] = True
return False
elif botao.__dict__.get((x, y)):
botao.__dict__[(x, y)] = False
return True
botao.__dict__[(x, y)] = False
return False