Advertisement
Patriik

Untitled

Feb 27th, 2022
38
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.72 KB | None | 0 0
  1. local gpu = require("component").gpu
  2. local event = require("event")
  3.  
  4. local objects = {}
  5.  
  6. local function button(x,y,w,h,label,color,textColor,callback)
  7. table.insert(objects, {type="button",x=x,y=y,w=w,h=h,label=label,callback=callback,color = color,textColor = textColor, visible = true})
  8. return #objects
  9. end
  10.  
  11. local function frame(x,y,w,h,color,textColor,text)
  12. table.insert(objects, {type="frame",x=x,y=y,w=w,h=h,color = color, textColor = textColor, text = text, visible = true})
  13. return #objects
  14. end
  15.  
  16. local function draw()
  17. gpu.setBackground(0x333333)
  18. gpu.setForeground(0xFFFFFF)
  19. gpu.fill(1,1,resx,resy," ")
  20. for i,v in ipairs(objects) do
  21. local object = v
  22.  
  23. if object.type == "button" and object.visible == true then
  24. gpu.setBackground(object.color)
  25. gpu.setForeground(object.textColor)
  26. gpu.fill(object.x,object.y,object.w,object.h," ")
  27. gpu.set(object.x+math.floor(object.w/2)-math.floor(#object.label/2),object.y+math.floor(object.h/2),object.label)
  28. elseif object.type == "frame" and object.visible == true then
  29. gpu.setBackground(object.color)
  30. gpu.setForeground(object.textColor)
  31. gpu.fill(object.x,object.y,object.w,object.h," ")
  32. gpu.set(object.x+math.floor(object.w/2)-math.floor(#object.text/2),object.y+math.floor(object.h/2),object.text)
  33. end
  34. end
  35. end
  36.  
  37. event.listen("touch",function(_,_,x,y)
  38. for i,v in ipairs(objects) do
  39. if v.type == "button" then
  40. if x>=v.x and x<=v.x+v.w-1 and y>=v.y and y<=v.y+v.h-1 then
  41. v.callback()
  42. end
  43. end
  44. end
  45. end)
  46.  
  47.  
  48.  
  49. while true do
  50. os.sleep(0.1)
  51. local text = ""
  52. for i=1,#enteredPassword do
  53. text = text .. "*"
  54. end
  55.  
  56. objects[frameID].text = text
  57. draw()
  58. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement