Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- load libraries
- os.loadAPI("drawLib")
- local buttons = {}
- -- create
- function addButton(x,y,w,h,name,colorOn,colorOff,state,textOn,textOff,textX,textY,header)
- buttons[name] = {
- ["x"] = x,
- ["y"] = y,
- ["width"] = w,
- ["height"] = h,
- ["colorOn"] = colorOn,
- ["colorOff"] = colorOff,
- ["state"] = state,
- ["textOn"] = textOn,
- ["textOff"] = textOff,
- ["textX"] = textX,
- ["textY"] = textY,
- ["header"] = header
- }
- end
- -- read
- function getButton(buttonname)
- return buttons[buttonname]
- end
- function getAllButtons()
- return buttons
- end
- function isWithinBoundingBox(x,y,buttonname)
- return x >= buttons[buttonname].x and x < buttons[buttonname].x + buttons[buttonname].width and
- y >= buttons[buttonname].y and y < buttons[buttonname].y + buttons[buttonname].height
- end
- -- update
- function setButtonState(buttonname, state)
- buttons[buttonname].state = state
- end
- --draw
- function drawButton(button,monitor)
- local color = colors.red
- local text = ""
- if buttons[button].state==true then color = buttons[button].colorOn else color = buttons[button].colorOff end
- if buttons[button].state==true then text = buttons[button].textOn else text = buttons[button].textOff end
- drawLib.drawLine(buttons[button].x, buttons[button].y, buttons[button].width, buttons[button].height, color, monitor)
- if buttons[button].header == "" then else
- drawLib.drawTitle(buttons[button].x, buttons[button].y - 1, buttons[button].header, colors.white, colors.black, monitor) end
- drawLib.drawTitle(buttons[button].textX, buttons[button].textY, text, colors.white, color, monitor)
- end
Add Comment
Please, Sign In to add comment