Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- term.redirect(term.native())
- code = debuguide ~= nil and debuguide.code or {}
- curElement = 1
- curValue = 2
- curColor = 2^curValue
- term.width, term.height = term.getSize()
- term.clear()
- toolBarActive = false
- rcm = true
- editing = false
- function findNext(sClass)
- local totals = {rectangle = 0, text = 0, line = 0, sprite = 0, fill = 0}
- if totals[sClass] == nil then
- error("sClass in function findNext is not a valid class")
- end
- for i,v in pairs(code) do
- totals[v.class] = totals[v.class] + 1
- end
- return totals[sClass] + 1
- end
- function drawBox(x,y,endX,endY,color)
- for i=y > endY and endY or y,y > endY and y or endY do
- paintutils.drawLine(x,i,endX,i,color)
- end
- end
- function fullLimitWrite(text,limit)
- term.write(#text < limit+1 and text..(string.rep(" ",limit-#text)) or string.sub(text,1,limit-3).."...")
- end
- function toColor(nColor)
- for i,v in pairs(colors) do
- if nColor == v then
- return "colors."..i
- end
- end
- end
- function dualPull(...)
- local args={...}
- repeat
- local event = {os.pullEvent()}
- for i,v in pairs(args) do
- if event[1] == v then
- return unpack(event)
- end
- end
- until false
- end
- function redraw()
- if #code > 0 then
- for i,v in pairs(code) do
- if curElement ~= i then
- if v.class == "sprite" and v.visible == true then
- for l,k in pairs(v.pixels) do
- paintutils.drawPixel(k.x,k.y,k.color)
- end
- elseif v.class == "line" and v.visible == true then
- paintutils.drawLine(v.sX,v.sY,v.eX,v.eY,v.color)
- elseif v.class == "text" and v.visible == true then
- term.setCursorPos(v.x,v.y)
- term.setTextColor(v.tColor)
- term.setBackgroundColor(v.bColor)
- term.write(v.text)
- elseif v.class == "fill" and v.visible == true then
- term.setBackgroundColor(v.color)
- term.clear()
- elseif v.class == "rectangle" and v.visible == true then
- drawBox(v.sX,v.sY,v.eX,v.eY,v.color)
- end
- elseif i == curElement then
- if v.class == "sprite" then
- for l,k in pairs(v.pixels) do
- paintutils.drawPixel(k.x,k.y,k.color)
- end
- elseif v.class == "line" then
- paintutils.drawLine(v.sX,v.sY,v.eX,v.eY,v.color ~= colors.blue and colors.blue or colors.lightBlue)
- elseif v.class == "text" then
- term.setCursorPos(v.x,v.y)
- term.setTextColor(v.tColor ~= colors.lightBlue and colors.lightBlue or colors.blue)
- term.setBackgroundColor(v.bColor ~= blue and colors.blue or colors.lightBlue)
- term.write(v.text)
- elseif v.class == "fill" then
- term.setBackgroundColor(v.color ~= colors.blue and colors.blue or colors.lightBlue)
- term.clear()
- elseif v.class == "rectangle" then
- drawBox(v.sX,v.sY,v.eX,v.eY,v.color ~= colors.blue and colors.blue or colors.lightBlue)
- end
- end
- end
- end
- if toolBarActive == true and editing == false then
- drawBox(term.width-12,1,term.width,term.height,colors.white)
- term.setCursorPos(term.width-11,1)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(term.width-12,1)
- fullLimitWrite("Toolbar",13)
- term.setCursorPos(term.width-12,7)
- term.setTextColor(colors.lightBlue)
- term.setBackgroundColor(colors.lightGray)
- fullLimitWrite("Edit",13)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- term.setCursorPos(term.width,1)
- term.write("X")
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- for i=-2,2 do
- term.setCursorPos(term.width-12,4+i)
- if code[curElement + i] ~= nil then
- if code[curElement + i] == code[curElement] then
- term.setTextColor(colors.lightBlue)
- fullLimitWrite(code[curElement].name,13)
- term.setTextColor(colors.black)
- else
- fullLimitWrite(code[curElement + i].name,13)
- end
- else
- fullLimitWrite(" ",13)
- end
- end
- end
- end
- function line(toX,toY,fromX,fromY,color,key,name)
- term.setBackgroundColor(colors.black)
- term.clear()
- redraw()
- if toX == nil and toY == nil and fromX == nil and fromY == nil then
- event, button, fromX, fromY = os.pullEvent("mouse_click")
- event, button, toX, toY = os.pullEvent("mouse_click")
- end
- if not color then
- color = colors.red
- end
- local curPoint = "to"
- while true do
- redraw()
- paintutils.drawLine(fromX,fromY,toX,toY,color)
- paintutils.drawPixel(curPoint == "to" and toX or fromX,curPoint == "to" and toY or fromY,color ~= colors.lightBlue and colors.lightBlue or colors.blue)
- local event, button, x, y = dualPull("mouse_click","mouse_drag")
- if event == "mouse_drag" then
- paintutils.drawLine(fromX,fromY,toX,toY,colors.black)
- toX = curPoint == "to" and x or toX
- toY = curPoint == "to" and y or toY
- fromX = curPoint == "from" and x or fromX
- fromY = curPoint == "from" and y or fromY
- redraw()
- paintutils.drawLine(fromX,fromY,toX,toY,color)
- elseif event == "mouse_click" then
- if x == fromX and y == fromY and curPoint ~= "from" then
- curPoint = "from"
- elseif x == toX and y == toY and curPoint ~= "to" then
- curPoint = "to"
- elseif x == toX and y == toY and curPoint == "to" then
- break
- elseif x == fromX and y == fromY and curPoint == "from" then
- break
- end
- end
- end
- local template = {
- class = "line",
- sX = fromX,
- sY = fromY,
- eX = toX,
- eY = toY,
- visible = true,
- color = color,
- name = name or "line"..findNext("line")}
- if key then
- code[key] = template
- else
- table.insert(code,template)
- end
- redraw()
- end
- function text(x,y,sText,bColor,tColor,key,name)
- term.setBackgroundColor(colors.black)
- term.clear()
- redraw()
- if not bColor and not tColor then
- tColor = colors.black
- bColor = colors.green
- end
- local tText = {}
- if sText then
- for i=1,#sText do
- local letter = string.sub(sText,i,i)
- table.insert(tText,letter)
- end
- end
- local selected = #tText
- if not x and not y then
- event, button, x, y = os.pullEvent("mouse_click")
- end
- repeat
- redraw()
- term.setCursorPos(x,y)
- term.setTextColor(tColor)
- term.setBackgroundColor(bColor)
- term.write(table.concat(tText))
- local event, key = dualPull("key","char")
- if event == "char" then
- table.insert(tText,selected + 1,key)
- selected = selected + 1
- elseif event == "key" then
- if key == keys.left and selected > 0 then
- selected = selected - 1
- elseif key == keys.right and selected < #tText then
- selected = selected + 1
- elseif key == keys.backspace and selected > 0 then
- local oldSel = selected
- selected = selected - 1
- table.remove(tText,oldSel)
- paintutils.drawPixel(x + #tText,y,colors.black)
- end
- end
- until key == keys.enter
- if #tText > 0 then
- local template = {
- class = "text",
- text = table.concat(tText),
- x = x,
- y = y,
- tColor = tColor,
- visible = true,
- bColor = bColor,
- name = name or "text"..findNext("text")}
- if key then
- code[key] = template
- else
- table.insert(code,template)
- end
- end
- redraw()
- end
- function sprite(pixels,key,name)
- term.setBackgroundColor(colors.black)
- term.clear()
- redraw()
- local pTbl = pixels or {}
- while true do
- curColor = 2^curValue
- redraw()
- for i,v in pairs(pTbl) do
- paintutils.drawPixel(v.x,v.y,v.color)
- end
- local event, button, x, y = dualPull("mouse_click","key","mouse_scroll","mouse_drag")
- if event == "mouse_click" or event == "mouse_drag" then
- local found = false
- for i,v in pairs(pTbl) do
- if v.x == x and v.y == y then
- v.color = curColor
- found = true
- end
- end
- if found == false then
- table.insert(pTbl,{x = x, y = y, color = curColor})
- end
- elseif event == "key" then
- if button == keys.enter then
- break
- elseif button == 14 and #pTbl > 0 then
- paintutils.drawPixel(pTbl[#pTbl].x,pTbl[#pTbl].y,colors.black)
- table.remove(pTbl)
- redraw()
- elseif button == keys.up then
- curValue = curValue < 15 and curValue + 1 or 0
- elseif button == keys.down then
- curValue = curValue > 0 and curValue - 1 or 15
- end
- end
- end
- local template = {
- class = "sprite",
- pixels = pTbl,
- visible = true,
- name = name or "Pxls"..findNext("sprite")}
- if key and #pTbl > 0 then
- code[key] = template
- elseif #pTbl > 0 then
- table.insert(code,template)
- end
- redraw()
- end
- function rectangle(fromX,fromY,toX,toY,color,key,name)
- term.setBackgroundColor(colors.black)
- term.clear()
- redraw()
- if not fromX and not fromY and not toX and not toY then
- local event, button, fX, fY = os.pullEvent("mouse_click")
- fromX = fX
- fromY = fY
- local event, button, tX, tY = os.pullEvent("mouse_click")
- toX = tX
- toY = fY
- end
- if not color then
- color = colors.red
- end
- local curPoint = "to"
- while true do
- redraw()
- drawBox(fromX,fromY,toX,toY,color)
- paintutils.drawPixel(curPoint == "to" and toX or fromX, curPoint == "to" and toY or fromY, color ~= colors.lightBlue and colors.lightBlue or colors.blue)
- local event, button, x, y = dualPull("mouse_click","mouse_drag")
- if event == "mouse_drag" then
- if curPoint == "to" then
- drawBox(fromX,fromY,toX,toY,colors.black)
- toX = x
- toY = y
- elseif curPoint == "from" then
- drawBox(fromX,fromY,toX,toY,colors.black)
- fromX = x
- fromY = y
- end
- elseif event == "mouse_click" then
- if x == fromX and y == fromY and curPoint ~= "from" then
- curPoint = "from"
- elseif x == toX and y == toY and curPoint ~= "to" then
- curPoint = "to"
- elseif x == toX and y == toY and curPoint == "to" then
- break
- elseif x == fromX and y == fromY and curPoint == "from" then
- break
- end
- end
- end
- local template = {
- class = "rectangle",
- sX = fromX < toX and fromX or toX,
- sY = fromY < toY and fromY or toY,
- eX = fromX > toX and fromX or toX,
- eY = fromY > toY and fromY or toY,
- visible = true,
- color = color,
- name = name or "rect"..findNext("rectangle")}
- if key then
- code[key] = template
- else
- table.insert(code,template)
- end
- redraw()
- end
- function delete(nKey)
- if code[nKey] ~= nil then
- local item = code[nKey]
- if item.class == "line" then
- paintutils.drawLine(item.sX,item.sY,item.eX,item.eY,colors.black)
- table.remove(code, nKey)
- redraw()
- elseif item.class == "text" then
- paintutils.drawLine(item.x,item.y,item.x + #item.text, item.y, colors.black)
- table.remove(code, nKey)
- redraw()
- elseif item.class == "sprite" then
- for i,v in pairs(item.pixels) do
- paintutils.drawPixel(v.x,v.y,colors.black)
- end
- table.remove(code, nKey)
- redraw()
- elseif item.class == "rectangle" then
- drawBox(item.sX, item.sY, item.eX, item.eY, colors.black)
- table.remove(code, nKey)
- redraw()
- end
- end
- end
- function edit(key)
- local item = code[key]
- item.visible = false
- if item.class == "line" then
- line(item.sX,item.sY,item.eX,item.eY,item.color,key,item.name)
- elseif item.class == "text" then
- text(item.x,item.y,item.text,item.tColor,item.bColor,key,item.name)
- elseif item.class == "sprite" then
- sprite(item.pixels,key,item.name)
- elseif item.class == "rectangle" then
- rectangle(item.sX,item.sY,item.eX,item.eY,item.color,key,item.name)
- end
- end
- function rightClickMenu(x,y)
- if x == nil or y == nil then
- event,button,x,y = os.pullEvent("mouse_click")
- end
- local width, height = term.getSize()
- redraw()
- if toolBarActive == true then
- width = width - 13
- end
- local browser
- while rcm == true do
- if y + 5 > height then
- y = y - 5
- end
- if x + 8 > width then
- x = x - (8 - (width-x))
- end
- drawBox(x,y,x+8,y+5,colors.white)
- term.setTextColor(colors.black)
- term.setCursorPos(x,y)
- term.write("Line")
- term.setCursorPos(x,y+1)
- term.write("Text")
- term.setCursorPos(x,y+2)
- term.write("Box")
- term.setCursorPos(x,y+3)
- term.write("Sprite")
- term.setCursorPos(x,y+4)
- term.write("Delete")
- term.setCursorPos(x,y+5)
- term.write("Browser")
- local event, button, clickX, clickY = os.pullEvent("mouse_click")
- if button == 2 and (clickX > x+8 or clickX < x or clickY > y+5 or clickY < y) then
- drawBox(x,y,x+8,y+5,colors.black)
- redraw()
- x = clickX
- y = clickY
- if y + 5 > height then
- y = y - 5
- end
- if x + 8 > width then
- x = x - (8 - (width-x))
- end
- elseif button == 1 then
- if clickX >= x and clickX < x + 9 and clickY == y then
- drawBox(x,y,x+8,y+5,colors.black)
- redraw()
- line()
- end
- if clickX >= x and clickX < x + 9 and clickY == y+1 then
- drawBox(x,y,x+8,y+5,colors.black)
- redraw()
- text()
- end
- if clickX >= x and clickX < x + 9 and clickY == y+2 then
- drawBox(x,y,x+8,y+5,colors.black)
- redraw()
- rectangle()
- end
- if clickX >= x and clickX < x + 9 and clickY == y+3 then
- drawBox(x,y,x+8,y+5,colors.black)
- redraw()
- sprite()
- end
- if clickX >= x and clickX < x + 9 and clickY == y+4 then
- drawBox(x,y,x+8,y+5,colors.black)
- delete(#code)
- redraw()
- end
- if clickX >= x and clickX < x + 9 and clickY == y+5 then
- drawBox(x,y,x+8,y+5,colors.black)
- redraw()
- browser = true
- break
- end
- if clickX > x+8 or clickX < x then
- drawBox(x,y,x+8,y+5,colors.black)
- break
- end
- if clickY > y+5 or clickY < y then
- drawBox(x,y,x+8,y+5,colors.black)
- redraw()
- break
- end
- end
- end
- if browser then
- elementBrowser()
- browser = false
- end
- end
- function elementBrowser()
- while true do
- drawBox(term.width-12,1,term.width,term.height,colors.white)
- term.setCursorPos(term.width-11,1)
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.lightGray)
- term.setCursorPos(term.width-12,1)
- fullLimitWrite("Toolbar",13)
- term.setCursorPos(term.width-12,7)
- term.setTextColor(colors.lightBlue)
- term.setBackgroundColor(colors.lightGray)
- fullLimitWrite("Edit",13)
- term.setTextColor(colors.white)
- term.setBackgroundColor(colors.red)
- term.setCursorPos(term.width,1)
- term.write("X")
- term.setTextColor(colors.black)
- term.setBackgroundColor(colors.white)
- for i=-2,2 do
- term.setCursorPos(term.width-12,4+i)
- if code[curElement + i] ~= nil then
- if code[curElement + i] == code[curElement] then
- term.setTextColor(colors.lightBlue)
- fullLimitWrite(code[curElement].name,13)
- term.setTextColor(colors.black)
- else
- fullLimitWrite(code[curElement + i].name,13)
- end
- else
- fullLimitWrite(" ",13)
- end
- end
- local event, button, x, y = dualPull("mouse_click","mouse_scroll","key")
- if event == "mouse_scroll" then
- if button == -1 then
- curElement = curElement > 1 and curElement - 1 or #code
- sleep(0.01)
- redraw()
- elseif button == 1 then
- curElement = curElement < #code and curElement + 1 or 1
- sleep(0.01)
- redraw()
- end
- elseif event == "key" then
- if button == 211 or button == 14 then
- delete(curElement)
- curElement = (code[curElement] == nil and #code > 0) and curElement - 1 or curElement
- elseif button == keys.up then
- curElement = curElement > 1 and curElement - 1 or #code
- elseif button == keys.down then
- curElement = curElement < #code and curElement + 1 or 1
- end
- elseif event == "mouse_click" then
- if x > term.width-12 and 7 > y then
- for i=-2,2 do
- if y == 4 + i and curElement + i > 0 and curElement + i < #code + 1 then
- curElement = curElement + i
- redraw()
- end
- end
- elseif x > term.width-12 and y == 7 then
- term.setBackgroundColor(colors.black)
- term.clear()
- redraw()
- local svcur = curElement
- curElement = 0
- editing = true
- edit(svcur)
- curElement = svcur
- term.setBackgroundColor(colors.black)
- term.clear()
- redraw()
- elseif (y == 1 and x == term.width) then
- drawBox(term.width-12,1,term.width,term.height,colors.black)
- redraw()
- toolBarActive = false
- rcm = false
- break
- elseif term.width > x and button == 2 then
- toolBarActive = true
- rightClickMenu(x,y,true)
- end
- end
- end
- end
- function save()
- local file = fs.open("test","a")
- local rect = false
- local currentBColor
- local currentTColor
- file.writeLine("function drawGUI()")
- for i,v in pairs(code) do
- if v.class == "rectangle" then
- if not paintutils.drawFilledBox and not rect then
- file.writeLine([[
- local function drawBox(x,y,endX,endY,color)
- for i=y > endY and endY or y,y > endY and y or endY do
- paintutils.drawLine(x,i,endX,i,color)
- end
- end]])
- rect = true
- end
- file.writeLine(rect and " drawBox("..v.sX..","..v.sY..","..v.eX..","..v.eY..","..toColor(v.color)..")" or " paintutils.drawFilledBox("..v.sX..","..v.sY..","..v.eX..","..v.eY..","..toColor(v.color)..")")
- currentTColor = v.color
- currentBColor = v.color
- elseif v.class == "line" then
- file.writeLine(" paintutils.drawLine("..v.sX..","..v.sY..","..v.eX..","..v.eY..","..toColor(v.color)..")")
- currentTColor = v.color
- currentBColor = v.color
- elseif v.class == "text" then
- file.writeLine(" term.setCursorPos("..v.x..","..v.y..")")
- if currentTColor ~= v.tColor then
- file.writeLine(" term.setTextColor("..toColor(v.tColor)..")")
- currentTColor = v.tColor
- end
- if currentBColor ~= v.bColor then
- file.writeLine(" term.setBackgroundColor("..toColor(v.bColor)..")")
- currentBColor = v.bColor
- end
- file.writeLine(' term.write("'..v.text..'")')
- elseif v.class == "sprite" then
- file.writeLine(" ")
- for l,k in pairs(v.pixels) do
- file.writeLine(" paintutils.drawPixel("..k.x..","..k.y..","..k.color..")")
- end
- currentTColor = v.color
- currentBColor = v.color
- end
- end
- file.writeLine("end")
- file.close()
- end
- rightClickMenu()
Advertisement
Add Comment
Please, Sign In to add comment