Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- require("ui_api")
- -- GLOBALS
- local colorButtons = {}
- local curColor = colors.white
- local showOptions = false
- local cWidth = termWidth - 4
- local cHeight = termWidth - 1
- local curDrawing = {}
- local running = true
- for i = 1, cWidth, 1 do
- curDrawing[i] = {}
- for j = 1, cHeight, 1 do
- curDrawing[i][j] = colors.white
- end
- end
- term.clear()
- term.setCursorPos(1, 1)
- -- Functions & Stuff
- function setColor(color)
- curColor = color
- end
- function toggleOptions()
- if showOptions == true then showOptions = false elseif showOptions == false then showOptions = true end
- end
- function quitApp()
- term.clear()
- term.setCursorPos(1,1)
- running = false
- end
- function drawOptions()
- --drawRectangle(1, 2, 7, 10, colors.blue)
- saveButton:draw()
- end
- function draw()
- while running do
- term.clear()
- -- Draw main shapes, topbar, sidebar.
- drawRectangle(1, 1, termWidth, 1, colors.green, "Paint Program by gravitowl", colors.white)
- drawRectangle(termWidth - 3, 2, 4, termHeight, colors.gray)
- -- Draw canvas
- for i = 1, cWidth, 1 do
- for j = 1, cHeight, 1 do
- drawRectangle(i, j + 1, 1, 1, curDrawing[i][j])
- end
- end
- -- Show currently selected color.
- drawRectangle(termWidth-2, 12, 2, 1, curColor)
- if showOptions then
- for key, ob in pairs(optionsMenu) do
- ob:draw()
- end
- end
- -- Draw buttons
- for key, cb in pairs(colorButtons) do
- cb:draw()
- end
- optionsButton:draw()
- os.sleep(0.1)
- end
- end
- function click()
- while running do
- local e, a, x, y = os.pullEvent("mouse_click")
- for key, cb in pairs(colorButtons) do
- cb:isClicked(x, y)
- end
- optionsButton:isClicked(x, y)
- if showOptions then
- for key, ob in pairs(optionsMenu) do
- ob:isClicked(x, y)
- end
- end
- if x >= 1 and x <= cWidth and y > 1 and y < cHeight then
- curDrawing[x][y - 1] = curColor
- end
- end
- end
- -- Buttons
- local CBY = 3
- colorButtons = {
- white = Button:new(nil, termWidth-2, CBY, 0, 0, "", colors.white, colors.white, {setColor, colors.white}),
- orange = Button:new(nil, termWidth-2, CBY + 1, 0, 0, "", colors.white, colors.orange, {setColor, colors.orange}),
- magenta = Button:new(nil, termWidth-2, CBY + 2, 0, 0, "", colors.white, colors.magenta, {setColor, colors.magenta}),
- lightBlue = Button:new(nil, termWidth-2, CBY + 3, 0, 0, "", colors.white, colors.lightBlue, {setColor, colors.lightBlue}),
- yellow = Button:new(nil, termWidth-2, CBY + 4, 0, 0, "", colors.white, colors.yellow, {setColor, colors.yellow}),
- lime = Button:new(nil, termWidth-2, CBY + 5, 0, 0, "", colors.white, colors.lime, {setColor, colors.lime}),
- pink = Button:new(nil, termWidth-2, CBY + 6, 0, 0, "", colors.white, colors.pink, {setColor, colors.pink}),
- gray = Button:new(nil, termWidth-2, CBY + 7, 0, 0, "", colors.white, colors.gray, {setColor, colors.gray}),
- lightGray = Button:new(nil, termWidth-1, CBY, 0, 0, "", colors.white, colors.lightGray, {setColor, colors.lightGray}),
- blue = Button:new(nil, termWidth-1, CBY + 1, 0, 0, "", colors.white, colors.blue, {setColor, colors.blue}),
- purple = Button:new(nil, termWidth-1, CBY + 2, 0, 0, "", colors.white, colors.purple, {setColor, colors.purple}),
- cyan = Button:new(nil, termWidth-1, CBY + 3, 0, 0, "", colors.white, colors.cyan, {setColor, colors.cyan}),
- brown = Button:new(nil, termWidth-1, CBY + 4, 0, 0, "", colors.white, colors.brown, {setColor, colors.brown}),
- green = Button:new(nil, termWidth-1, CBY + 5, 0, 0, "", colors.white, colors.green, {setColor, colors.green}),
- red = Button:new(nil, termWidth-1, CBY + 6, 0, 0, "", colors.white, colors.red, {setColor, colors.red}),
- black = Button:new(nil, termWidth-1, CBY + 7, 0, 0, "", colors.white, colors.black, {setColor, colors.black}),
- }
- optionsButton = Button:new(nil, 1, 1, 7, 1, "OPTIONS", colors.black, colors.lime, toggleOptions)
- optionsMenu = {
- saveButton = Button:new(nil, 1, 2, 7, 1, "SAVE", colors.black, colors.blue, "return"),
- newButton = Button:new(nil, 1, 3, 7, 1, "NEW", colors.black, colors.blue, "return"),
- quitButton = Button:new(nil, 1, 4, 7, 1, "QUIT", colors.black, colors.blue, quitApp)
- }
- parallel.waitForAll(draw, click)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement