Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --programa para la tablet
- rednet.open("back")
- local EsenciaPCID = 2
- local boton = {alto = 3, ancho = 15, fondo = colors.red, seleccionado = colors.green}
- local info = { nombre = "INFO", x = 8, y = 5, seleccionado = true}
- local llena = { nombre = "LLENA", x = 8, y = 11}
- local botones = {info, llena}
- local mensaje
- function enviaMsg(mensaje)
- rednet.send(EsenciaPCID,mensaje)
- end
- function info:action()
- botones.info = true
- info.seleccionado = true
- llena.seleccionado = false
- enviaMsg("info")
- end
- function llena:action()
- botones.info = false
- info.seleccionado = false
- llena.seleccionado = true
- enviaMsg("llena")
- end
- function enBoton(b,x,y)
- local x1 = b.x + boton.ancho
- local y1 = b.y + boton.alto
- return x >= b.x and x <= x1 and y >= b.y and y <= y1
- end
- function presionaBoton(x,y)
- for _, b in ipairs(botones) do
- if enBoton(b,x,y) then
- b.action()
- end
- end
- end
- function dibujaBoton(b)
- if b.seleccionado == true then
- term.setBackgroundColor(boton.seleccionado)
- else
- term.setBackgroundColor(boton.fondo)
- end
- term.setTextColor(colors.white)
- for n = 0, boton.alto - 1 do
- term.setCursorPos(b.x, b.y + n)
- term.write(string.rep(" ", boton.ancho - 1))
- end
- local y1 = b.y + (boton.alto - 1) / 2
- local x1 = b.x + (boton.ancho - #b.nombre) / 2
- term.setCursorPos(x1, y1)
- term.write(b.nombre)
- term.setBackgroundColor(colors.black)
- end
- while true do
- for _, b in ipairs(botones) do
- dibujaBoton(b)
- end
- local evento,ID,x,y = os.pullEvent()
- if evento == "mouse_click" then
- presionaBoton(x,y)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement