Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- FILENAME: api_button.lua(API)
- AUTHOR: Donald R. Valverde (Cavious)
- VERSION: 1.0-ALPHA
- --]]
- local button = {}
- function createButton(list, id, text, fontColor, backgroundColor, xPos, yPos, funct)
- button[id] = {}
- button[id]["text"] = text
- button[id]["fontColor"] = fontColor
- button[id]["backgroundColor"] = backgroundColor
- button[id]["xPos"] = xPos
- button[id]["yPos"] = yPos
- button[id]["funct"] = funct
- table.insert(list, button[id])
- end
- function removeButton(list, id)
- table.remove(list, id)
- end
- function drawButtons(output, list)
- for i = 1, #list do
- output.setCursorPos(list[i].xPos, list[i].yPos)
- output.setTextColor(list[i].fontColor)
- output.setBackgroundColor(list[i].backgroundColor)
- output.write(list[i].text)
- end
- end
- function drawButton(output, list, i)
- output.setCursorPos(list[i].xPos, list[i].yPos)
- output.setTextColor(list[i].fontColor)
- output.setBackgroundColor(list[i].backgroundColor)
- output.write(list[i].text)
- end
- function runButtonEvent(buttonList, activeButtonColor, inactiveButtonColor, event_type)
- state = true
- while(state) do
- event, button, xPos, yPos = os.pullEvent(event_type)
- for i = 1, #buttonList do
- if(yPos == buttonList[i].yPos and xPos >= buttonList[i].xPos and xPos < (buttonList[i].text:len() + buttonList[i].xPos)) then
- buttonList[i].backgroundColor = activeButtonColor
- api_button.drawButton(term, buttonList, i)
- os.sleep(0.5)
- buttonList[i].backgroundColor = inactiveButtonColor
- api_button.drawButton(term, buttonList, i)
- os.sleep(0.5)
- buttonList[i].funct()
- state = false
- end
- end
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment