Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local gpu = require("component").gpu
- local event = require("event")
- local objects = {}
- local function button(x,y,w,h,label,color,textColor,callback)
- table.insert(objects, {type="button",x=x,y=y,w=w,h=h,label=label,callback=callback,color = color,textColor = textColor, visible = true})
- return #objects
- end
- local function frame(x,y,w,h,color,textColor,text)
- table.insert(objects, {type="frame",x=x,y=y,w=w,h=h,color = color, textColor = textColor, text = text, visible = true})
- return #objects
- end
- local function draw()
- gpu.setBackground(0x333333)
- gpu.setForeground(0xFFFFFF)
- gpu.fill(1,1,resx,resy," ")
- for i,v in ipairs(objects) do
- local object = v
- if object.type == "button" and object.visible == true then
- gpu.setBackground(object.color)
- gpu.setForeground(object.textColor)
- gpu.fill(object.x,object.y,object.w,object.h," ")
- gpu.set(object.x+math.floor(object.w/2)-math.floor(#object.label/2),object.y+math.floor(object.h/2),object.label)
- elseif object.type == "frame" and object.visible == true then
- gpu.setBackground(object.color)
- gpu.setForeground(object.textColor)
- gpu.fill(object.x,object.y,object.w,object.h," ")
- gpu.set(object.x+math.floor(object.w/2)-math.floor(#object.text/2),object.y+math.floor(object.h/2),object.text)
- end
- end
- end
- event.listen("touch",function(_,_,x,y)
- for i,v in ipairs(objects) do
- if v.type == "button" then
- if x>=v.x and x<=v.x+v.w-1 and y>=v.y and y<=v.y+v.h-1 then
- v.callback()
- end
- end
- end
- end)
- while true do
- os.sleep(0.1)
- local text = ""
- for i=1,#enteredPassword do
- text = text .. "*"
- end
- objects[frameID].text = text
- draw()
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement