Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local w,h = term.getSize()
- local inMenu = false
- local animated = false
- local column = {}
- local lSel,rSel = colours.white,nil
- local sx,sy = 0,0
- --Change this to change default canvas colour
- local alphaC = colours.cyan
- local sFrame = 1
- local frames = { }
- local buffer = nil
- local selectrect = nil
- local rectblink = 0
- local frameCount = 1
- local state = "paint"
- local brushsize = 3
- local record = false
- local animtime = 0.3
- local hexnums = {[10] = "a", [11] = "b", [12] = "c", [13] = "d", [14] = "e" , [15] = "f"}
- local logo = {
- "fcc 3 339";
- " fcc 9333 33";
- " fcc 933 333 33";
- " fcc 933 33 33";
- " fcc 933 33 33";
- " c88 333 93333";
- " 888 333 9333";
- " 333 3 333 939";
- }
- local mChoices = {"Save","Exit"}
- local helpTopics = {
- [1] = {
- name = "Paint Mode",
- key = nil,
- animonly = false,
- message = "The default mode for NPaintPro, for painting pixels."
- .." Controls here that are not overridden will apply for all other modes. Leaving a mode by selecting that mode "
- .." again will always send the user back to paint mode.",
- controls = {
- { "Arrow keys", "Scroll the canvas" },
- { "Left Click", "Paint/select left colour" },
- { "Right Click", "Paint/select right colour" },
- { "X Key", "Clear image on screen" },
- { "Tab Key", "Hide selection rectangle if visible" },
- { "Q Key", "Set alpha mask to left colour" },
- { "W Key", "Set alpha mask to right colour" },
- { "Number Keys", "Swich between frames 1-9" },
- { "</> keys", "Move to the next/last frame" },
- { "R Key", "Removes every frame after the current frame"}
- }
- },
- [2] = {
- name = "Brush Mode",
- key = "b",
- animonly = false,
- message = "Brush mode allows painting a circular area of variable diameter rather than a single pixel, working in "..
- "the exact same way as paint mode in all other regards.",
- controls = {
- { "Left Click", "Paints a brush blob with the left colour" },
- { "Right Click", "Paints a brush blob with the right colour" },
- { "Number Keys", "Changes the radius of the brush blob from 2-9" }
- }
- },
- [3] = {
- name = "Pippette Mode",
- key = "p",
- animonly = false,
- message = "Pippette mode allows the user to click the canvas and set the colour clicked to the left or right "..
- "selected colour, for later painting.",
- controls = {
- { "Left Click", "Sets clicked colour to the left selected colour" },
- { "Right Click", "Sets clicked colour to the right selected colour" }
- }
- },
- [4] = {
- name = "Move Mode",
- key = "m",
- animonly = false,
- message = "Mode mode allows the moving of the entire image on the screen. This is especially useful for justifying"..
- " the image to the top-left for animations or game assets.",
- controls = {
- { "Left/Right Click", "Moves top-left corner of image to selected square" },
- { "Arrow keys", "Moves image one pixel in any direction" }
- }
- },
- [5] = {
- name = "Flood Mode (NYI)",
- key = "f",
- animonly = false,
- message = "Flood mode allows the changing of an area of a given colour to that of the selected colour. "..
- "The tool uses a flood4 algorithm and will not fill diagonally. Transparency cannot be flood filled.",
- controls = {
- { "Left Click", "Flood fills selected area to left colour" },
- { "Right Click", "Flood fills selected area to right colour" }
- }
- },
- [6] = {
- name = "Select Mode",
- key = "s",
- animonly = false,
- message = "Select mode allows the creation and use of the selection rectangle, to highlight specific areas on "..
- "the screen and perform operations on the selected area of the image. The selection rectangle can contain an "..
- "image on the clipboard- if it does, the image will flash inside the rectangle, and the rectangle edges will "..
- "be light grey instead of dark grey.",
- controls = {
- { "C Key", "Copy: Moves selection into the clipboard" },
- { "X Key", "Cut: Clears canvas under the rectangle, and moves it into the clipboard" },
- { "V Key", "Paste: Copys clipboard to the canvas" },
- { "Z Key", "Empties clipboard" },
- { "Left/Right Click", "Moves top-left corner of rectangle to selected pixel" },
- { "Arrow Keys", "Moves rectangle one pixel in any direction" }
- }
- },
- [7] = {
- name = "Corner Select Mode",
- key = nil,
- animonly = false,
- message = "If a selection rectangle isn't visible, this mode is selected automatically. It allows the "..
- "defining of the corners of the rectangle- one the top-left and bottom-right corners have been defined, "..
- "NPaintPro switches to selection mode. Note rectangle must be at least 2 pixels wide and high.",
- controls = {
- { "Left/Right Click", "Defines a corner of the selection rectangle" }
- }
- },
- [8] = {
- name = "Play Mode",
- key = "space",
- animonly = true,
- message = "Play mode will loop through each frame in your animation at a constant rate. Editing tools are "..
- "locked in this mode, and the coordinate display will turn green to indicate it is on.",
- controls = {
- { "</> Keys", "Increases/Decreases speed of the animation" },
- { "Space Bar", "Returns to paint mode" }
- }
- },
- [9] = {
- name = "Record Mode",
- key = "\\",
- animonly = true,
- message = "Record mode is not a true mode, but influences how other modes work. Changes made that modify the "..
- "canvas in record mode will affect ALL frames in the animation. The coordinates will turn red to indicate that "..
- "record mode is on.",
- controls = {
- { "", "Affects:" },
- { "- Paint Mode", "" },
- { "- Brush Mode", "" },
- { "- Cut and Paste in Select Mode", ""},
- { "- Move Mode", ""}
- }
- },
- [10] = {
- name = "File Mode",
- keys = "ctrl",
- animonly = false,
- message = "Allows you to save changes or leave the program.",
- controls = { }
- }
- }
- local selectedHelp = nil
- local toplim,botlim,leflim,riglim = nil,nil,nil,nil
- local sPath = nil
- --[[ Helpers ]]--
- local function getHexOf(colour)
- if not colour then return " " end
- local val = math.log(colour)/math.log(2)
- if val > 9 then val = hexnums[val] end
- return val
- end
- local function getColourOf(hex)
- if hex == " " then return nil end
- local val = tonumber(hex)
- if not val then
- for k,v in pairs(hexnums) do
- if v == hex then val = math.pow(2,k) end
- end
- else
- val = math.pow(2,val)
- end
- return val
- end
- local function updateImageLims()
- toplim,botlim,leflim,riglim = nil,nil,nil,nil
- for y,_ in pairs(frames[sFrame]) do
- for x,_ in pairs(frames[sFrame][y]) do
- if frames[sFrame][y][x] ~= nil then
- if leflim == nil or x < leflim then leflim = x end
- if toplim == nil or y < toplim then toplim = y end
- if riglim == nil or x > riglim then riglim = x end
- if botlim == nil or y > botlim then botlim = y end
- end
- end
- end
- end
- local function updateTimer()
- os.startTimer(0.5)
- rectblink = (rectblink % 2) + 1
- end
- --[[ Loading ]]--
- local function loadNFP(path)
- sFrame = 1
- frames[sFrame] = { }
- if fs.exists(path) then
- local file = io.open(path, "r" )
- local sLine = file:read()
- local num = 1
- while sLine do
- table.insert(frames[sFrame], num, {})
- for i=1,#sLine do
- frames[sFrame][num][i] = getColourOf(string.sub(sLine,i,i))
- end
- num = num+1
- sLine = file:read()
- end
- file:close()
- end
- end
- local function saveNFP(path)
- local file = io.open(path, "w")
- updateImageLims()
- if not toplim then
- file:close()
- return
- end
- for y=1,botlim do
- local line = ""
- if frames[sFrame][y] then
- for x=1,riglim do
- line = line..getHexOf(frames[sFrame][y][x])
- end
- end
- file:write(line.."\n")
- end
- file:close()
- end
- local function loadNFA(path)
- frames[sFrame] = { }
- if fs.exists(path) then
- local file = io.open(path, "r" )
- local sLine = file:read()
- local num = 1
- while sLine do
- table.insert(frames[sFrame], num, {})
- if sLine == "~" then
- sFrame = sFrame + 1
- frames[sFrame] = { }
- num = 1
- else
- for i=1,#sLine do
- frames[sFrame][num][i] = getColourOf(string.sub(sLine,i,i))
- end
- num = num+1
- end
- sLine = file:read()
- end
- file:close()
- end
- framecount = sFrame
- sFrame = 1
- end
- local function saveNFA(path)
- local file = io.open(path, "w")
- updateImageLims()
- if not toplim then
- file:close()
- return
- end
- for i=1,#frames do
- for y=1,botlim do
- local line = ""
- if frames[i][y] then
- for x=1,riglim do
- line = line..getHexOf(frames[i][y][x])
- end
- end
- file:write(line.."\n")
- end
- if i < #frames then file:write("~\n") end
- end
- file:close()
- end
- local function init()
- if animated then loadNFA(sPath)
- else loadNFP(sPath) end
- for i=0,15 do
- table.insert(column, math.pow(2,i))
- end
- end
- --[[ Drawing ]]--
- local function drawLogo()
- term.setBackgroundColour(colours.white)
- term.clear()
- for y=1,#logo do
- for x=1,#logo[y] do
- term.setCursorPos(w/2 - #logo[y]/2 + x, h/2 - #logo/2 + y)
- local col = getColourOf(string.sub(logo[y], x, x))
- if not col then col = 1 end
- term.setBackgroundColour(col)
- term.write(" ")
- end
- end
- sleep(1)
- term.setBackgroundColour(colours.white)
- term.setTextColour(colours.black)
- local msg = "NPaintPro"
- term.setCursorPos(w/2 - #msg/2, h-3)
- term.write(msg)
- msg = "By NitrogenFingers"
- term.setCursorPos(w/2 - #msg/2, h-2)
- term.write(msg)
- os.pullEvent()
- end
- local function drawCanvas()
- term.setBackgroundColor(alphaC)
- --term.clear()
- --Picture first
- for y=sy+1,sy+h-1 do
- if frames[sFrame][y] then
- for x=sx+1,sx+w-2 do
- if frames[sFrame][y][x] then
- term.setBackgroundColour(frames[sFrame][y][x])
- else
- term.setBackgroundColour(alphaC)
- end
- term.setCursorPos(x-sx,y-sy)
- term.write(" ")
- end
- else
- for x=sx+1,sx+w-2 do
- term.setBackgroundColour(alphaC)
- term.setCursorPos(x-sx,y-sy)
- term.write(" ")
- end
- end
- end
- --Then the buffer
- if selectrect then
- if buffer and rectblink == 1 then
- for y=selectrect.y1, math.min(selectrect.y2, selectrect.y1 + buffer.height-1) do
- for x=selectrect.x1, math.min(selectrect.x2, selectrect.x1 + buffer.width-1) do
- if buffer.contents[y-selectrect.y1+1][x-selectrect.x1+1] then
- term.setCursorPos(x+sx,y+sy)
- term.setBackgroundColour(buffer.contents[y-selectrect.y1+1][x-selectrect.x1+1])
- term.write(" ")
- end
- end
- end
- end
- --This draws the "selection" box
- local add = nil
- if buffer then
- term.setBackgroundColour(colours.lightGrey)
- else
- term.setBackgroundColour(colours.grey)
- end
- for i=selectrect.x1, selectrect.x2 do
- add = (i + selectrect.y1 + rectblink) % 2 == 0
- term.setCursorPos(i-sx,selectrect.y1-sy)
- if add then term.write(" ") end
- add = (i + selectrect.y2 + rectblink) % 2 == 0
- term.setCursorPos(i-sx,selectrect.y2-sy)
- if add then term.write(" ") end
- end
- for i=selectrect.y1 + 1, selectrect.y2 - 1 do
- add = (i + selectrect.x1 + rectblink) % 2 == 0
- term.setCursorPos(selectrect.x1-sx,i-sy)
- if add then term.write(" ") end
- add = (i + selectrect.x2 + rectblink) % 2 == 0
- term.setCursorPos(selectrect.x2-sx,i-sy)
- if add then term.write(" ") end
- end
- end
- end
- local function drawInterface()
- --Picker
- for i=1,#column do
- term.setCursorPos(w-1, i)
- term.setBackgroundColour(column[i])
- term.write(" ")
- end
- term.setCursorPos(w-1,#column+1)
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.red)
- term.write("XX")
- --Pallette
- term.setCursorPos(w-1,h-1)
- if not lSel then
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.red)
- term.write("X")
- else
- term.setBackgroundColour(lSel)
- term.setTextColour(lSel)
- term.write(" ")
- end
- if not rSel then
- term.setBackgroundColour(colours.black)
- term.setTextColour(colours.red)
- term.write("X")
- else
- term.setBackgroundColour(rSel)
- term.setTextColour(rSel)
- term.write(" ")
- end
- --Footer
- if inMenu then return end
- term.setCursorPos(1, h)
- term.setBackgroundColour(colours.lightGrey)
- term.setTextColour(colours.grey)
- term.clearLine()
- term.write(string.upper(string.sub(state, 1, 1))..string.sub(state, 2, #state).." mode")
- if state == "brush" then term.write(", size="..brushsize) end
- term.write(" (H for help)")
- local coords="X:"..sx.." Y:"..sy
- if animated then coords = coords.." Frame:"..sFrame.."/"..framecount.." " end
- term.setCursorPos(w-#coords+1,h)
- if state == "play" then term.setBackgroundColour(colours.lime)
- elseif record then term.setBackgroundColour(colours.red) end
- term.write(coords)
- if animated then
- term.setCursorPos(w-1,h)
- term.setBackgroundColour(colours.grey)
- term.setTextColour(colours.lightGrey)
- term.write("<>")
- end
- end
- local function drawHelpScreen()
- while true do
- term.setBackgroundColour(colours.lightGrey)
- term.clear()
- if not selectedHelp then
- term.setCursorPos(4, 1)
- term.setTextColour(colours.brown)
- term.write("Available modes (click for info):")
- for i=1,#helpTopics do
- term.setCursorPos(2, 2 + i)
- term.setTextColour(colours.black)
- term.write(helpTopics[i].name)
- if helpTopics[i].key then
- term.setTextColour(colours.red)
- term.write(" ("..helpTopics[i].key..")")
- end
- end
- term.setCursorPos(4,h)
- term.setTextColour(colours.black)
- term.write("Press any key to exit")
- else
- term.setCursorPos(4,1)
- term.setTextColour(colours.brown)
- term.write(helpTopics[selectedHelp].name)
- if helpTopics[selectedHelp].key then
- term.setTextColour(colours.red)
- term.write(" ("..helpTopics[selectedHelp].key..")")
- end
- term.setCursorPos(1,3)
- term.setTextColour(colours.black)
- print(helpTopics[selectedHelp].message.."\n")
- for i=1,#helpTopics[selectedHelp].controls do
- term.setTextColour(colours.brown)
- term.write(helpTopics[selectedHelp].controls[i][1].." ")
- term.setTextColour(colours.black)
- print(helpTopics[selectedHelp].controls[i][2])
- end
- end
- local id,p1,p2 = os.pullEvent()
- if id == "timer" then updateTimer()
- elseif id == "key" then
- if selectedHelp then selectedHelp = nil
- else break end
- elseif id == "click" then
- if not selectedHelp then
- if p2 >=3 and p2 <= 2+#helpTopics then
- selectedHelp = p2-2
- else break end
- else
- selectedHelp = nil
- end
- end
- end
- end
- local function drawMessage(message)
- term.setCursorPos(1,h)
- term.setBackgroundColour(colours.lightGrey)
- term.setTextColour(colours.grey)
- term.clearLine()
- term.write(message)
- end
- --[[ Image tools ]]--
- local function copyToBuffer(removeImage)
- buffer = { width = selectrect.x2 - selectrect.x1 + 1, height = selectrect.y2 - selectrect.y1 + 1, contents = { } }
- local containsSomething = false
- for y=1,buffer.height do
- buffer.contents[y] = { }
- local f,l = sFrame,sFrame
- if record then f,l = 1, framecount end
- for fra = f,l do
- if frames[fra][selectrect.y1 + y - 1] then
- for x=1,buffer.width do
- buffer.contents[y][x] = frames[sFrame][selectrect.y1 + y - 1][selectrect.x1 + x - 1]
- if removeImage then frames[fra][selectrect.y1 + y - 1][selectrect.x1 + x - 1] = nil end
- if buffer.contents[y][x] then containsSomething = true end
- end
- end
- end
- end
- --I don't classify an empty buffer as a real buffer- confusing to the user.
- if not containsSomething then buffer = nil end
- end
- local function copyFromBuffer(removeBuffer)
- if not buffer then return end
- for y=1,buffer.height do
- local f,l = sFrame, sFrame
- if record then f,l = 1, framecount end
- for fra = f,l do
- if not frames[fra][selectrect.y1+y-1] then frames[fra][selectrect.y1+y-1] = { } end
- for x=1,buffer.width do
- frames[fra][selectrect.y1+y-1][selectrect.x1+x-1] = buffer.contents[y][x]
- end
- end
- end
- if removeBuffer then buffer = nil end
- end
- local function moveImage(newx,newy)
- updateImageLims()
- if not leflim or not toplim then return end
- if newx <=0 or newy <=0 then return end
- --And superimpose each pixel to new coordinates
- local newlines = { }
- local f,l = sFrame,sFrame
- if record then f,l = 1,framecount end
- for i=f,l do
- for y,line in pairs(frames[i]) do
- newlines[y-toplim+newy] = { }
- for x,char in pairs(line) do
- newlines[y-toplim+newy][x-leflim+newx] = char
- end
- end
- frames[i] = newlines
- end
- end
- local function clearImage()
- inMenu = true
- if not animated then
- drawMessage("Clear image? Y/N: ")
- elseif record then
- drawMessage("Clear ALL frames? Y/N: ")
- else
- drawMessage("Clear current frame? Y/N :")
- end
- if string.find(string.upper(readInput(1)), "Y") then
- local f,l = sFrame,sFrame
- if record then f,l = 1,framecount end
- for i=f,l do
- frames[i] = { }
- end
- end
- inMenu = false
- end
- --[[ Animation Tools ]]--
- local function playAnimation()
- state = "play"
- selectedrect = nil
- os.pullEvent("timer")
- os.startTimer(animtime)
- repeat
- drawCanvas()
- drawInterface()
- local id,key = os.pullEvent()
- if id=="timer" then
- os.startTimer(animtime)
- sFrame = (sFrame % framecount) + 1
- elseif id=="key" then
- if key == keys.comma and animtime > 0.1 then animtime = animtime - 0.05
- elseif key == keys.period and animtime < 0.5 then animtime = animtime + 0.05
- elseif key == keys.space then state = "paint" end
- end
- until state ~= "play"
- os.startTimer(0.5)
- end
- local function changeFrame(newframe)
- inMenu = true
- if not tonumber(newframe) then
- term.setCursorPos(1,h)
- term.setBackgroundColour(colours.lightGrey)
- term.setTextColour(colours.grey)
- term.clearLine()
- term.write("Go to frame: ")
- sleep(0.1)
- newframe = tonumber(readInput(1))
- if not newframe or newframe <= 0 then return end
- elseif newframe <= 0 then return end
- if newframe > framecount then
- for i=framecount+1,newframe do
- frames[i] = {}
- for y,line in pairs(frames[sFrame]) do
- frames[i][y] = { }
- for x,v in pairs(line) do
- frames[i][y][x] = v
- end
- end
- end
- framecount = newframe
- end
- sFrame = newframe
- inMenu = false
- end
- local function removeFramesAfter(frame)
- inMenu = true
- if frame==framecount then return end
- term.setCursorPos(1,h)
- term.setBackgroundColour(colours.lightGrey)
- term.setTextColour(colours.grey)
- term.clearLine()
- term.write("Delete frames "..(frame+1).."-"..framecount.."? Y/N: ")
- sleep(0.1)
- local answer = string.upper(readInput(1))
- if string.find(answer, "Y") ~= 1 then return end
- for i=frame+1, framecount do
- frames[i] = nil
- end
- framecount = frame
- inMenu = false
- end
- --[[ Interface ]]--
- local function accessMenu()
- local selection = 1
- term.setCursorPos(1,h)
- term.setBackgroundColour(colours.lightGrey)
- term.clearLine()
- while true do
- term.setCursorPos(1,h)
- term.setBackgroundColour(colours.lightGrey)
- term.clearLine()
- term.setTextColour(colours.black)
- for k,v in pairs(mChoices) do
- if selection==k then
- term.setTextColour(colours.red)
- local ox,_ = term.getCursorPos()
- term.write("["..string.rep(" ",#v).."]")
- term.setCursorPos(ox+1,h)
- term.setTextColour(colours.black)
- term.write(v)
- term.setCursorPos(term.getCursorPos()+1,h)
- else
- term.write(" "..v.." ")
- end
- end
- local id,key = os.pullEvent()
- if id == "key" then
- if key == keys.right and selection < #mChoices then
- selection = selection + 1
- elseif key == keys.left and selection > 1 then
- selection = selection - 1
- elseif key == keys.enter then
- if mChoices[selection]=="Save" then
- if animated then saveNFA(sPath)
- else saveNFP(sPath) end
- return false
- elseif mChoices[selection]=="Exit" then return true
- end
- elseif key == keys.leftCtrl then return false end
- elseif id == "timer" then updateTimer() drawCanvas() drawInterface()end
- end
- end
- function readInput(lim)
- sleep(0.01)
- term.setCursorBlink(true)
- local inputString = ""
- local ox,oy = term.getCursorPos()
- term.write(" ")
- term.setCursorPos(ox, oy)
- if not lim or type(lim) ~= "number" or lim < 1 then lim = w - ox end
- while true do
- local id,key = os.pullEvent()
- if id == "key" and key == 14 and #inputString > 0 then
- inputString = string.sub(inputString, 1, #inputString-1)
- term.setCursorPos(ox + #inputString,oy)
- term.write(" ")
- elseif id == "key" and key == 28 and inputString ~= string.rep(" ", #inputString) then
- break
- elseif id == "char" and #inputString < lim then
- inputString = inputString..key
- elseif id == "timer" then
- updateTimer()
- drawCanvas()
- drawInterface()
- end
- term.setCursorPos(ox,oy)
- term.write(inputString)
- term.setCursorPos(ox + #inputString, oy)
- end
- while string.sub(inputString, 1, 1) == " " do
- inputString = string.sub(inputString, 2, #inputString)
- end
- while string.sub(inputString, #inputString, #inputString) == " " do
- inputString = string.sub(inputString, 1, #inputString-1)
- end
- term.setCursorBlink(false)
- return inputString
- end
- local function handleEvents()
- os.startTimer(0.5)
- while true do
- drawCanvas()
- drawInterface()
- local id,p1,p2,p3 = os.pullEvent()
- if id=="timer" then
- updateTimer()
- elseif id=="click" then
- if p1 >=w-1 and p2 < #column+1 then
- if p3==1 then lSel = column[p2]
- else rSel = column[p2] end
- elseif p1 >=w-1 and p2==#column+1 then
- if p3==1 then lSel = nil
- else rSel = nil end
- elseif p1==w-1 and p2==h and animated then
- changeFrame(sFrame-1)
- elseif p1==w and p2==h and animated then
- changeFrame(sFrame+1)
- elseif p1 < w-1 and p2 <= h-1 then
- if state=="pippette" then
- if p3==1 then
- if frames[sFrame][p2+sy] and frames[sFrame][p2+sy][p1+sx] then
- lSel = frames[sFrame][p2+sy][p1+sx]
- end
- elseif p3==2 then
- if frames[sFrame][p2+sy] and frames[sFrame][p2+sy][p1+sx] then
- rSel = frames[sFrame][p2+sy][p1+sx]
- end
- end
- elseif state=="move" then
- moveImage(p1,p2)
- elseif state=="corner select" then
- if not selectrect then
- selectrect = { x1=p1, x2=p1, y1=p2, y2=p2 }
- elseif selectrect.x1 ~= p1 and selectrect.y1 ~= p2 then
- if p1<selectrect.x1 then selectrect.x1 = p1
- else selectrect.x2 = p1 end
- if p2<selectrect.y1 then selectrect.y1 = p2
- else selectrect.y2 = p2 end
- state = "select"
- end
- elseif state=="select" then
- local swidth = selectrect.x2 - selectrect.x1
- local sheight = selectrect.y2 - selectrect.y1
- selectrect.x1 = p1
- selectrect.y1 = p2
- selectrect.x2 = p1 + swidth
- selectrect.y2 = p2 + sheight
- else
- local f,l = sFrame,sFrame
- if record then f,l = 1,framecount end
- local bwidth = 0
- if state == "brush" then bwidth = brushsize-1 end
- for i=f,l do
- for x = math.max(1,p1+sx-bwidth),p1+sx+bwidth do
- for y = math.max(1,p2+sy-bwidth), p2+sy+bwidth do
- if math.abs(x - (p1+sx)) + math.abs(y - (p2+sy)) <= bwidth then
- if not frames[i][y] then frames[i][y] = {} end
- if p3==1 then frames[i][y][x] = lSel
- else frames[i][y][x] = rSel end
- end
- end
- end
- end
- end
- end
- elseif id=="key" then
- if p1==keys.leftCtrl then
- if accessMenu() then break end
- elseif p1==keys.h then drawHelpScreen()
- elseif p1==keys.x then
- --Cut feature
- if state=="select" then
- copyToBuffer(true)
- else
- clearImage()
- end
- elseif p1==keys.c and state=="select" then
- copyToBuffer(false)
- elseif p1==keys.v then
- if state~="select" then
- selectrect = { x1=1,x2=buffer.width,y1=1,y2=buffer.height }
- else
- copyFromBuffer(false)
- end
- elseif p1==keys.z and state=="select" then
- buffer = nil
- elseif p1==keys.s then
- if state=="corner select" or state=="select" then
- state = "paint"
- elseif selectrect and selectrect.x1 ~= selectrect.x2 then
- state = "select"
- else
- state = "corner select"
- end
- elseif p1==keys.tab then
- selectrect = nil
- if state == "select" then state = "corner select" end
- elseif p1==keys.q then
- if lSel then alphaC = lSel end
- elseif p1==keys.w then
- if rSel then alphaC = rSel end
- elseif p1==keys.b then
- if state=="brush" then state = "paint"
- else state = "brush" end
- elseif p1==keys.m then
- if state=="move" then state = "paint"
- else state = "move" end
- elseif p1==keys.backslash and animated then
- record = not record
- elseif p1==keys.p then
- if state=="pippette" then state = "paint"
- else state = "pippette" end
- elseif p1==keys.g and animated then
- changeFrame()
- elseif p1==keys.period and animated then
- changeFrame(sFrame+1)
- elseif p1==keys.comma and animated then
- changeFrame(sFrame-1)
- elseif p1==keys.r and animated then
- removeFramesAfter(sFrame)
- elseif p1==keys.space and animated then
- playAnimation()
- elseif p1==keys.left then
- if state == "move" then
- updateImageLims()
- moveImage(leflim-1,toplim)
- elseif state=="select" and selectrect.x1 > 1 then
- selectrect.x1 = selectrect.x1-1
- selectrect.x2 = selectrect.x2-1
- elseif sx > 0 then sx=sx-1 end
- elseif p1==keys.right then
- if state == "move" then
- updateImageLims()
- moveImage(leflim+1,toplim)
- elseif state=="select" then
- selectrect.x1 = selectrect.x1+1
- selectrect.x2 = selectrect.x2+1
- else sx=sx+1 end
- elseif p1==keys.up then
- if state == "move" then
- updateImageLims()
- moveImage(leflim,toplim-1)
- elseif state=="select" and selectrect.y1 > 1 then
- selectrect.y1 = selectrect.y1-1
- selectrect.y2 = selectrect.y2-1
- elseif sy > 0 then sy=sy-1 end
- elseif p1==keys.down then
- if state == "move" then
- updateImageLims()
- moveImage(leflim,toplim+1)
- elseif state=="select" then
- selectrect.y1 = selectrect.y1+1
- selectrect.y2 = selectrect.y2+1
- else sy=sy+1 end
- end
- elseif id=="char" and tonumber(p1) then
- if state=="brush" and tonumber(p1) > 1 then
- brushsize = tonumber(p1)
- elseif tonumber(p1) > 0 then
- changeFrame(tonumber(p1))
- end
- end
- end
- end
- --[[ Main ]]--
- --Taken almost directly from edit (for consistency)
- local tArgs = {...}
- local ca = 1
- if tArgs[ca] == "-a" then
- animated = true
- ca = ca + 1
- end
- if #tArgs < ca then
- print("Usage: npaintpro [-a] <path>")
- return
- end
- sPath = shell.resolve(tArgs[ca])
- local bReadOnly = fs.isReadOnly(sPath)
- if fs.exists(sPath) then
- if fs.isDir(sPath) then
- print("Cannot edit a directory.")
- return
- elseif string.find(sPath, ".nfp") ~= #sPath-3 and string.find(sPath, ".nfa") ~= #sPath-3 then
- print("Can only edit .nfp and nfa files:",string.find(sPath, ".nfp"),#sPath-3)
- return
- end
- if string.find(sPath, ".nfa") == #sPath-3 then
- animated = true
- end
- if string.find(sPath, ".nfp") == #sPath-3 and animated then
- print("Convert to nfa? Y/N")
- if string.find(string.lower(io.read()), "y") then
- local nsPath = string.sub(sPath, 1, #sPath-1).."a"
- fs.move(sPath, nsPath)
- sPath = nsPath
- else
- animated = false
- end
- end
- else
- if not animated and string.find(sPath, ".nfp") ~= #sPath-3 then
- sPath = sPath..".nfp"
- elseif animated and string.find(sPath, ".nfa") ~= #sPath-3 then
- sPath = sPath..".nfa"
- end
- end
- if not term.isColour() then
- print("For colour computers only")
- return
- end
- drawLogo()
- init()
- handleEvents()
- term.setBackgroundColour(colours.black)
- shell.run("clear")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement