Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- version = "1.03"
- buttons = {}
- function newButton(name,xmin,xmax,ymin,ymax,tfunc,bColor,bName)
- if name and xmin and xmax and ymin and ymax then
- else
- return false
- end
- if bColor and bName then
- buttons[name] = {xmin,xmax,ymin,ymax,tfunc,bColor,bName}
- else
- buttons[name] = {xmin,xmax,ymin,ymax,tfunc}
- end
- return true
- end
- function deleteButton(name)
- buttons[name] = nil
- return true
- end
- function checkButtons(posx,posy)
- for k,v in pairs(buttons) do
- if posx >= buttons[k][1] and posx <= buttons[k][2] and posy >= buttons[k][3] and posy <= buttons[k][4] then
- return buttons[k][5]()
- end
- sleep(0)
- end
- end
- function deleteAllButtons()
- buttons = {}
- return true
- end
- function displayButtons()
- for k,v in pairs(buttons) do
- if buttons[k][6] then
- drawBox(buttons[k][1],buttons[k][3],buttons[k][2],buttons[k][4],buttons[k][6])
- buttonCX = buttons[k][2] - buttons[k][1]
- buttonCX = buttons[k][2] - math.floor(buttonCX / 2)
- buttonCY = buttons[k][4] - buttons[k][3]
- buttonCY = buttons[k][4] - math.floor(buttonCY / 2)
- if buttons[k][7] then
- cBText = #buttons[k][7] /2
- toPosX = buttonCX - cBText
- term.setCursorPos(toPosX,buttonCY)
- write(buttons[k][7])
- end
- end
- end
- end
- function clicked()
- return true
- end
- cn = 0
- colnum = 0
- cm = false
- pos1x,pos1y,pos2x,pos2y = 1,1,1,1
- text = ""
- nButtons = 0
- term.setBackgroundColor(colors.white)
- term.clear()
- TID = os.startTimer(0.1)
- while true do
- e,wc,cx,cy = os.pullEvent()
- term.clear()
- displayButtons()
- term.setBackgroundColor(colors.white)
- term.setCursorPos(1,1)
- term.setTextColor(2^colnum)
- write("Color")
- scrx,scry = term.getSize()
- term.setCursorPos(1,scry)
- term.setTextColor(colors.black)
- write(text)
- term.setCursorPos(pos1x,pos1y)
- term.setTextColor(colors.orange)
- write("+")
- term.setCursorPos(pos2x,pos2y)
- write("+")
- term.setTextColor(colors.black)
- if e == "timer" and wc == TID then
- TID = os.statTimer(0.1)
- end
- if e == "mouse_click" then
- if wc == 1 then
- cn = cn +1
- if cn == 3 then
- cn = 1
- end
- if cn == 1 then
- pos1x,pos1y = cx,cy
- elseif cn == 2 then
- pos2x, pos2y = cx, cy
- end
- elseif wc == 2 then
- if checkButtons(cx,cy) then
- selected = k
- end
- end
- end
- if e == "char" and cm then
- text = text .. wc
- end
- if e == "key" then
- if wc == keys.up then
- if colnum < 15 then
- colnum = colnum +1
- else
- colnum = 0
- end
- elseif wc == keys.down then
- if colnum > 0 then
- colnum = colnum -1
- else
- colnum = 15
- end
- elseif wc == keys.enter then
- nButtons = nButtons +1
- if pos1x >= pos2x then
- txm = pos1x
- txb = pos2x
- else
- txm = pos2x
- txb = pos1x
- end
- if pos1y >= pos2y then
- tym = pos1y
- tyb = pos2y
- else
- tym = pos2y
- tyb = pos1y
- end
- term.clear()
- newButton(tostring(nButtons),txb,txm,tyb,tym,clicked,2^colnum,text)
- displayButtons()
- term.setBackgroundColor(colors.white)
- text = ""
- elseif wc == keys.rightShift then
- if cm then
- cm = false
- else
- cm = true
- end
- elseif wc == keys.backspace then
- if selected then
- deleteButton(k)
- selected = false
- elseif cm then
- text = string.sub(text,1,#text-1)
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment