mirror of
https://github.com/LDDestroier/CC/
synced 2025-04-27 21:13:10 +00:00
Slightly improved renderer
This commit is contained in:
parent
1cc951abaa
commit
fdad83c5c7
870
pain.lua
870
pain.lua
@ -3000,468 +3000,480 @@ local listAllMonitors = function()
|
|||||||
end
|
end
|
||||||
|
|
||||||
local getInput = function() --gotta catch them all
|
local getInput = function() --gotta catch them all
|
||||||
local button, x, y, oldmx, oldmy, origx, origy
|
|
||||||
local isDragging = false
|
local doot = function()
|
||||||
local proceed = false
|
local button, x, y, oldmx, oldmy, origx, origy
|
||||||
renderBar(barmsg)
|
local isDragging = false
|
||||||
while true do
|
local proceed = false
|
||||||
doRender = false
|
local evt, oldx, oldy = {}
|
||||||
local oldx,oldy = paint.scrollX,paint.scrollY
|
local button, points, key, dir
|
||||||
local evt = {getEvents("mouse_scroll","mouse_click", "mouse_drag","mouse_up","key","key_up",true)}
|
renderBar(barmsg)
|
||||||
if (evt[1] == "mouse_scroll") and (not viewing) then
|
while true do
|
||||||
local dir = evt[2]
|
evt = {getEvents("mouse_scroll","mouse_click", "mouse_drag","mouse_up","key","key_up",true)}
|
||||||
if dir == 1 then
|
|
||||||
if keysDown[keys.leftShift] or keysDown[keys.rightShift] then
|
--doRender = false
|
||||||
paint.t = paint.t * 2
|
oldx, oldy = paint.scrollX,paint.scrollY
|
||||||
if paint.t > 32768 then
|
|
||||||
paint.t = 32768
|
if (evt[1] == "mouse_scroll") and (not viewing) then
|
||||||
|
dir = evt[2]
|
||||||
|
if dir == 1 then
|
||||||
|
if keysDown[keys.leftShift] or keysDown[keys.rightShift] then
|
||||||
|
paint.t = paint.t * 2
|
||||||
|
if paint.t > 32768 then
|
||||||
|
paint.t = 32768
|
||||||
|
end
|
||||||
|
else
|
||||||
|
paint.b = paint.b * 2
|
||||||
|
if paint.b > 32768 then
|
||||||
|
paint.b = 32768
|
||||||
|
end
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
paint.b = paint.b * 2
|
if keysDown[keys.leftShift] or keysDown[keys.rightShift] then
|
||||||
if paint.b > 32768 then
|
paint.t = math.ceil(paint.t / 2)
|
||||||
paint.b = 32768
|
if paint.t < 1 then
|
||||||
end
|
paint.t = 1
|
||||||
end
|
|
||||||
else
|
|
||||||
if keysDown[keys.leftShift] or keysDown[keys.rightShift] then
|
|
||||||
paint.t = math.ceil(paint.t / 2)
|
|
||||||
if paint.t < 1 then
|
|
||||||
paint.t = 1
|
|
||||||
end
|
|
||||||
else
|
|
||||||
paint.b = math.ceil(paint.b / 2)
|
|
||||||
if paint.b < 1 then
|
|
||||||
paint.b = 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
renderBar(barmsg)
|
|
||||||
elseif ((evt[1] == "mouse_click") or (evt[1] == "mouse_drag")) and (not viewing) then
|
|
||||||
if evt[1] == "mouse_click" then
|
|
||||||
origx, origy = evt[3], evt[4]
|
|
||||||
end
|
|
||||||
oldmx,oldmy = x or evt[3], y or evt[4]
|
|
||||||
lastMX,lastMY = evt[3],evt[4]
|
|
||||||
button,x,y = evt[2],evt[3],evt[4]
|
|
||||||
if plc.renderBlittle then
|
|
||||||
x = 2*x
|
|
||||||
y = 3*y
|
|
||||||
lastMX = 2*lastMX
|
|
||||||
lastMY = 3*lastMY
|
|
||||||
end
|
|
||||||
linePoses = {{x=oldmx,y=oldmy},{x=x,y=y}}
|
|
||||||
miceDown[button] = true
|
|
||||||
if y <= scr_y-(plc.renderBlittle and 0 or doRenderBar) then
|
|
||||||
if (button == 3) then
|
|
||||||
putDownText(x,y)
|
|
||||||
miceDown = {}
|
|
||||||
keysDown = {}
|
|
||||||
doRender = true
|
|
||||||
elseif button == 1 then
|
|
||||||
if keysDown[keys.leftShift] and evt[1] == "mouse_click" then
|
|
||||||
isDragging = true
|
|
||||||
end
|
|
||||||
if isDragging then
|
|
||||||
if evt[1] == "mouse_click" or dontDragThisTime then
|
|
||||||
dragPoses[1] = {x=x,y=y}
|
|
||||||
end
|
end
|
||||||
dragPoses[2] = {x=x,y=y}
|
else
|
||||||
local points = getDotsInLine(dragPoses[1].x,dragPoses[1].y,dragPoses[2].x,dragPoses[2].y)
|
paint.b = math.ceil(paint.b / 2)
|
||||||
renderAllPAIN()
|
if paint.b < 1 then
|
||||||
for a = 1, #points do
|
paint.b = 1
|
||||||
term.setCursorPos(points[a].x, points[a].y)
|
|
||||||
term.blit(paint.c, CTB(paint.t), CTB(paint.b))
|
|
||||||
end
|
end
|
||||||
elseif (not dontDragThisTime) then
|
|
||||||
if evt[1] == "mouse_drag" then
|
|
||||||
local points = getDotsInLine(linePoses[1].x,linePoses[1].y,linePoses[2].x,linePoses[2].y)
|
|
||||||
for a = 1, #points do
|
|
||||||
putDotDown({x=points[a].x, y=points[a].y})
|
|
||||||
end
|
|
||||||
else
|
|
||||||
putDotDown({x=x, y=y})
|
|
||||||
end
|
|
||||||
plc.changedImage = true
|
|
||||||
doRender = true
|
|
||||||
end
|
end
|
||||||
dontDragThisTime = false
|
|
||||||
elseif button == 2 and y <= scr_y-(plc.renderBlittle and 0 or doRenderBar) then
|
|
||||||
deleteDot(x+paint.scrollX,y+paint.scrollY)
|
|
||||||
plc.changedImage = true
|
|
||||||
doRender = true
|
|
||||||
end
|
end
|
||||||
elseif origy >= scr_y-(plc.renderBlittle and 0 or doRenderBar) then
|
renderBar(barmsg)
|
||||||
miceDown = {}
|
elseif ((evt[1] == "mouse_click") or (evt[1] == "mouse_drag")) and (not viewing) then
|
||||||
keysDown = {}
|
if evt[1] == "mouse_click" then
|
||||||
isDragging = false
|
origx, origy = evt[3], evt[4]
|
||||||
local res = displayMenu()
|
|
||||||
if res == "exit" then break end
|
|
||||||
doRender = true
|
|
||||||
end
|
|
||||||
elseif (evt[1] == "mouse_up") and (not viewing) and (not plc.isCurrentlyFilling) then
|
|
||||||
origx,origy = 0,0
|
|
||||||
local button = evt[2]
|
|
||||||
miceDown[button] = false
|
|
||||||
oldmx,oldmy = nil,nil
|
|
||||||
lastMX, lastMY = nil,nil
|
|
||||||
if isDragging then
|
|
||||||
local points = getDotsInLine(dragPoses[1].x,dragPoses[1].y,dragPoses[2].x,dragPoses[2].y)
|
|
||||||
for a = 1, #points do
|
|
||||||
putDotDown({x=points[a].x, y=points[a].y})
|
|
||||||
end
|
end
|
||||||
plc.changedImage = true
|
oldmx,oldmy = x or evt[3], y or evt[4]
|
||||||
doRender = true
|
lastMX,lastMY = evt[3],evt[4]
|
||||||
end
|
button,x,y = evt[2],evt[3],evt[4]
|
||||||
saveToUndoBuffer()
|
|
||||||
isDragging = false
|
|
||||||
elseif evt[1] == "key" then
|
|
||||||
local key = evt[2]
|
|
||||||
if (isDragging or not keysDown[keys.leftShift]) and (keysDown[keys.tab]) then
|
|
||||||
if key == keys.right and (not keysDown[keys.right]) then
|
|
||||||
paint.scrollX = paint.scrollX + 1
|
|
||||||
doRender = true
|
|
||||||
elseif key == keys.left and (not keysDown[keys.left]) then
|
|
||||||
paint.scrollX = paint.scrollX - 1
|
|
||||||
doRender = true
|
|
||||||
end
|
|
||||||
if key == keys.down and (not keysDown[keys.down]) then
|
|
||||||
paint.scrollY = paint.scrollY + 1
|
|
||||||
doRender = true
|
|
||||||
elseif key == keys.up and (not keysDown[keys.up]) then
|
|
||||||
paint.scrollY = paint.scrollY - 1
|
|
||||||
doRender = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
keysDown[key] = true
|
|
||||||
if key == keys.space then
|
|
||||||
if keysDown[keys.leftShift] then
|
|
||||||
plc.evenDrawGrid = not plc.evenDrawGrid
|
|
||||||
else
|
|
||||||
doRenderBar = math.abs(doRenderBar-1)
|
|
||||||
end
|
|
||||||
doRender = true
|
|
||||||
end
|
|
||||||
if key == keys.b then
|
|
||||||
local blTerm, oldTerm = getBlittle()
|
|
||||||
plc.renderBlittle = not plc.renderBlittle
|
|
||||||
isDragging = false
|
|
||||||
term.setBackgroundColor(rendback.b)
|
|
||||||
term.clear()
|
|
||||||
if plc.renderBlittle then
|
if plc.renderBlittle then
|
||||||
term.redirect(blTerm)
|
x = 2*x
|
||||||
blTerm.setVisible(true)
|
y = 3*y
|
||||||
else
|
lastMX = 2*lastMX
|
||||||
term.redirect(oldTerm)
|
lastMY = 3*lastMY
|
||||||
blTerm.setVisible(false)
|
|
||||||
end
|
end
|
||||||
doRender = true
|
linePoses = {{x=oldmx,y=oldmy},{x=x,y=y}}
|
||||||
scr_x, scr_y = term.current().getSize()
|
miceDown[button] = true
|
||||||
end
|
if y <= scr_y-(plc.renderBlittle and 0 or doRenderBar) then
|
||||||
if keysDown[keys.leftAlt] then
|
if (button == 3) then
|
||||||
if (not plc.renderBlittle) then
|
|
||||||
if (key == keys.c) then
|
|
||||||
editFuncs.copy()
|
|
||||||
elseif (key == keys.x) then
|
|
||||||
editFuncs.cut()
|
|
||||||
elseif (key == keys.v) then
|
|
||||||
editFuncs.paste()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if (key == keys.c) and (not plc.renderBlittle) then
|
|
||||||
gotoCoords()
|
|
||||||
resetInputState()
|
|
||||||
doRender = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if (keysDown[keys.leftShift]) and (not isDragging) then
|
|
||||||
if key == keys.left then
|
|
||||||
paintEncoded[frame] = movePaintEncoded(paintEncoded[frame],-1,0)
|
|
||||||
saveToUndoBuffer()
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
elseif key == keys.right then
|
|
||||||
paintEncoded[frame] = movePaintEncoded(paintEncoded[frame],1,0)
|
|
||||||
saveToUndoBuffer()
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
elseif key == keys.up then
|
|
||||||
paintEncoded[frame] = movePaintEncoded(paintEncoded[frame],0,-1)
|
|
||||||
saveToUndoBuffer()
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
elseif key == keys.down then
|
|
||||||
paintEncoded[frame] = movePaintEncoded(paintEncoded[frame],0,1)
|
|
||||||
saveToUndoBuffer()
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if keysDown[keys.leftAlt] then
|
|
||||||
if #paintEncoded > 1 then
|
|
||||||
if key == keys.equals and paintEncoded[frame+1] then --basically plus
|
|
||||||
local first = deepCopy(paintEncoded[frame])
|
|
||||||
local next = deepCopy(paintEncoded[frame+1])
|
|
||||||
paintEncoded[frame] = next
|
|
||||||
paintEncoded[frame+1] = first
|
|
||||||
frame = frame + 1
|
|
||||||
barmsg = "Swapped prev frame."
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
saveToUndoBuffer()
|
|
||||||
end
|
|
||||||
if key == keys.minus and paintEncoded[frame-1] then
|
|
||||||
local first = deepCopy(paintEncoded[frame])
|
|
||||||
local next = deepCopy(paintEncoded[frame-1])
|
|
||||||
paintEncoded[frame] = next
|
|
||||||
paintEncoded[frame-1] = first
|
|
||||||
frame = frame - 1
|
|
||||||
barmsg = "Swapped next frame."
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
saveToUndoBuffer()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
elseif keysDown[keys.leftShift] then
|
|
||||||
if #paintEncoded > 1 then
|
|
||||||
if key == keys.equals and paintEncoded[frame+1] then --basically plus
|
|
||||||
for a = 1, #paintEncoded[frame] do
|
|
||||||
paintEncoded[frame+1][#paintEncoded[frame+1] + 1] = paintEncoded[frame][a]
|
|
||||||
end
|
|
||||||
table.remove(paintEncoded, frame)
|
|
||||||
paintEncoded = clearAllRedundant(paintEncoded)
|
|
||||||
barmsg = "Merged next frame."
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
saveToUndoBuffer()
|
|
||||||
end
|
|
||||||
if key == keys.minus and paintEncoded[frame-1] then
|
|
||||||
for a = 1, #paintEncoded[frame] do
|
|
||||||
paintEncoded[frame-1][#paintEncoded[frame-1] + 1] = paintEncoded[frame][a]
|
|
||||||
end
|
|
||||||
table.remove(paintEncoded, frame)
|
|
||||||
frame = frame - 1
|
|
||||||
paintEncoded = clearAllRedundant(paintEncoded)
|
|
||||||
barmsg = "Merged previous frame."
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
saveToUndoBuffer()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
else
|
|
||||||
if key == keys.equals then --basically 'plus'
|
|
||||||
if plc.renderBlittle then
|
|
||||||
frame = frame + 1
|
|
||||||
if frame > #paintEncoded then frame = 1 end
|
|
||||||
else
|
|
||||||
if not paintEncoded[frame+1] then
|
|
||||||
paintEncoded[frame+1] = {}
|
|
||||||
local sheet = paintEncoded[frame]
|
|
||||||
if keysDown[keys.rightShift] then
|
|
||||||
paintEncoded[frame+1] = deepCopy(sheet)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
frame = frame + 1
|
|
||||||
end
|
|
||||||
saveToUndoBuffer()
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
elseif key == keys.minus then
|
|
||||||
if plc.renderBlittle then
|
|
||||||
frame = frame - 1
|
|
||||||
if frame < 1 then frame = #paintEncoded end
|
|
||||||
else
|
|
||||||
if frame > 1 then
|
|
||||||
frame = frame - 1
|
|
||||||
end
|
|
||||||
end
|
|
||||||
saveToUndoBuffer()
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
if not plc.renderBlittle then
|
|
||||||
if key == keys.m then
|
|
||||||
local incum = bottomPrompt("Set meta: ",metaHistory)
|
|
||||||
paint.m = incum:gsub(" ","") ~= "" and incum or paint.m
|
|
||||||
if paint.m ~= metaHistory[#metaHistory] then
|
|
||||||
metaHistory[#metaHistory+1] = paint.m
|
|
||||||
end
|
|
||||||
doRender = true
|
|
||||||
isDragging = false
|
|
||||||
end
|
|
||||||
if key == keys.f7 then
|
|
||||||
plc.bepimode = not plc.bepimode
|
|
||||||
doRender = true
|
|
||||||
end
|
|
||||||
if key == keys.t then
|
|
||||||
renderBottomBar("Click to place text.")
|
|
||||||
local mevt
|
|
||||||
repeat
|
|
||||||
mevt = {os.pullEvent()}
|
|
||||||
until (mevt[1] == "key" and mevt[2] == keys.x) or (mevt[1] == "mouse_click" and mevt[2] == 1 and (mevt[4] or scr_y) <= scr_y-(plc.renderBlittle and 0 or doRenderBar))
|
|
||||||
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
|
||||||
local x,y = mevt[3],mevt[4]
|
|
||||||
if plc.renderBlittle then
|
|
||||||
x = 2*x
|
|
||||||
y = 3*y
|
|
||||||
end
|
|
||||||
putDownText(x,y)
|
putDownText(x,y)
|
||||||
miceDown = {}
|
miceDown = {}
|
||||||
keysDown = {}
|
keysDown = {}
|
||||||
end
|
doRender = true
|
||||||
doRender = true
|
elseif button == 1 then
|
||||||
plc.changedImage = true
|
if keysDown[keys.leftShift] and evt[1] == "mouse_click" then
|
||||||
isDragging = false
|
isDragging = true
|
||||||
end
|
|
||||||
if key == keys.f and not (keysDown[keys.leftShift] or keysDown[keys.rightShift]) and (not plc.isCurrentlyFilling) then
|
|
||||||
renderBottomBar("Click to fill area.")
|
|
||||||
local mevt
|
|
||||||
repeat
|
|
||||||
mevt = {os.pullEvent()}
|
|
||||||
until (mevt[1] == "key" and mevt[2] == keys.x) or (mevt[1] == "mouse_click" and mevt[2] <= 2 and (mevt[4] or scr_y) <= scr_y-(renderBlittle and 0 or doRenderBar))
|
|
||||||
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
|
||||||
local x,y = mevt[3],mevt[4]
|
|
||||||
if plc.renderBlittle then
|
|
||||||
x = 2*x
|
|
||||||
y = 3*y
|
|
||||||
end
|
end
|
||||||
miceDown = {}
|
if isDragging then
|
||||||
keysDown = {}
|
if evt[1] == "mouse_click" or dontDragThisTime then
|
||||||
os.queueEvent("filltool_async", frame, x, y, paint, mevt[2] == 2)
|
dragPoses[1] = {x=x,y=y}
|
||||||
end
|
|
||||||
doRender = true
|
|
||||||
plc.changedImage = true
|
|
||||||
isDragging = false
|
|
||||||
end
|
|
||||||
if key == keys.p then
|
|
||||||
renderBottomBar("Pick color with cursor:")
|
|
||||||
paintEncoded = clearAllRedundant(paintEncoded)
|
|
||||||
local mevt
|
|
||||||
repeat
|
|
||||||
mevt = {os.pullEvent()}
|
|
||||||
until (mevt[1] == "key" and mevt[2] == keys.x) or (mevt[2] == 1 and mevt[4] <= scr_y)
|
|
||||||
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
|
||||||
local x, y = mevt[3]+paint.scrollX, mevt[4]+paint.scrollY
|
|
||||||
if plc.renderBlittle then
|
|
||||||
x = 2*x
|
|
||||||
y = 3*y
|
|
||||||
end
|
|
||||||
local p
|
|
||||||
for a = 1, #paintEncoded[frame] do
|
|
||||||
p = paintEncoded[frame][a]
|
|
||||||
if (p.x == x) and (p.y == y) then
|
|
||||||
paint.t = p.t or paint.t
|
|
||||||
paint.b = p.b or paint.b
|
|
||||||
paint.c = p.c or paint.c
|
|
||||||
paint.m = p.m or paint.m
|
|
||||||
miceDown = {}
|
|
||||||
keysDown = {}
|
|
||||||
doRender = true
|
|
||||||
isDragging = false
|
|
||||||
break
|
|
||||||
end
|
end
|
||||||
|
dragPoses[2] = {x=x,y=y}
|
||||||
|
points = getDotsInLine(dragPoses[1].x,dragPoses[1].y,dragPoses[2].x,dragPoses[2].y)
|
||||||
|
renderAllPAIN()
|
||||||
|
for a = 1, #points do
|
||||||
|
term.setCursorPos(points[a].x, points[a].y)
|
||||||
|
term.blit(paint.c, CTB(paint.t), CTB(paint.b))
|
||||||
|
end
|
||||||
|
elseif (not dontDragThisTime) then
|
||||||
|
if evt[1] == "mouse_drag" then
|
||||||
|
points = getDotsInLine(linePoses[1].x,linePoses[1].y,linePoses[2].x,linePoses[2].y)
|
||||||
|
for a = 1, #points do
|
||||||
|
putDotDown({x=points[a].x, y=points[a].y})
|
||||||
|
end
|
||||||
|
else
|
||||||
|
putDotDown({x=x, y=y})
|
||||||
|
end
|
||||||
|
plc.changedImage = true
|
||||||
|
doRender = true
|
||||||
end
|
end
|
||||||
resetInputState()
|
dontDragThisTime = false
|
||||||
|
elseif button == 2 and y <= scr_y-(plc.renderBlittle and 0 or doRenderBar) then
|
||||||
|
deleteDot(x+paint.scrollX,y+paint.scrollY)
|
||||||
|
plc.changedImage = true
|
||||||
|
doRender = true
|
||||||
end
|
end
|
||||||
doRender = true
|
elseif origy >= scr_y-(plc.renderBlittle and 0 or doRenderBar) then
|
||||||
isDragging = false
|
miceDown = {}
|
||||||
end
|
keysDown = {}
|
||||||
if (key == keys.leftCtrl or key == keys.rightCtrl) then
|
|
||||||
keysDown = {[207] = keysDown[207]}
|
|
||||||
isDragging = false
|
isDragging = false
|
||||||
local res = displayMenu()
|
local res = displayMenu()
|
||||||
paintEncoded = clearAllRedundant(paintEncoded)
|
|
||||||
if res == "exit" then break end
|
if res == "exit" then break end
|
||||||
doRender = true
|
doRender = true
|
||||||
end
|
end
|
||||||
end
|
elseif (evt[1] == "mouse_up") and (not viewing) and (not plc.isCurrentlyFilling) then
|
||||||
if (key == keys.f and keysDown[keys.leftShift]) then
|
origx,origy = 0,0
|
||||||
local deredots = {}
|
button = evt[2]
|
||||||
plc.changedImage = true
|
miceDown[button] = false
|
||||||
for a = 1, #paintEncoded[frame] do
|
oldmx,oldmy = nil,nil
|
||||||
local dot = paintEncoded[frame][a]
|
lastMX, lastMY = nil,nil
|
||||||
if dot.x-paint.scrollX > 0 and dot.x-paint.scrollX <= scr_x then
|
if isDragging then
|
||||||
if dot.y-paint.scrollY > 0 and dot.y-paint.scrollY <= scr_y then
|
points = getDotsInLine(dragPoses[1].x,dragPoses[1].y,dragPoses[2].x,dragPoses[2].y)
|
||||||
deredots[#deredots+1] = {dot.x-paint.scrollX, dot.y-paint.scrollY}
|
for a = 1, #points do
|
||||||
end
|
putDotDown({x=points[a].x, y=points[a].y})
|
||||||
|
end
|
||||||
|
plc.changedImage = true
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
|
saveToUndoBuffer()
|
||||||
|
isDragging = false
|
||||||
|
elseif evt[1] == "key" then
|
||||||
|
key = evt[2]
|
||||||
|
if (isDragging or not keysDown[keys.leftShift]) and (keysDown[keys.tab]) then
|
||||||
|
if key == keys.right and (not keysDown[keys.right]) then
|
||||||
|
paint.scrollX = paint.scrollX + 1
|
||||||
|
doRender = true
|
||||||
|
elseif key == keys.left and (not keysDown[keys.left]) then
|
||||||
|
paint.scrollX = paint.scrollX - 1
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
|
if key == keys.down and (not keysDown[keys.down]) then
|
||||||
|
paint.scrollY = paint.scrollY + 1
|
||||||
|
doRender = true
|
||||||
|
elseif key == keys.up and (not keysDown[keys.up]) then
|
||||||
|
paint.scrollY = paint.scrollY - 1
|
||||||
|
doRender = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
for y = 1, scr_y do
|
keysDown[key] = true
|
||||||
for x = 1, scr_x do
|
if key == keys.space then
|
||||||
local good = true
|
if keysDown[keys.leftShift] then
|
||||||
for a = 1, #deredots do
|
plc.evenDrawGrid = not plc.evenDrawGrid
|
||||||
if (deredots[a][1] == x) and (deredots[a][2] == y) then
|
else
|
||||||
good = bad
|
doRenderBar = math.abs(doRenderBar-1)
|
||||||
break
|
end
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
|
if key == keys.b then
|
||||||
|
local blTerm, oldTerm = getBlittle()
|
||||||
|
plc.renderBlittle = not plc.renderBlittle
|
||||||
|
isDragging = false
|
||||||
|
term.setBackgroundColor(rendback.b)
|
||||||
|
term.clear()
|
||||||
|
if plc.renderBlittle then
|
||||||
|
term.redirect(blTerm)
|
||||||
|
blTerm.setVisible(true)
|
||||||
|
else
|
||||||
|
term.redirect(oldTerm)
|
||||||
|
blTerm.setVisible(false)
|
||||||
|
end
|
||||||
|
doRender = true
|
||||||
|
scr_x, scr_y = term.current().getSize()
|
||||||
|
end
|
||||||
|
if keysDown[keys.leftAlt] then
|
||||||
|
if (not plc.renderBlittle) then
|
||||||
|
if (key == keys.c) then
|
||||||
|
editFuncs.copy()
|
||||||
|
elseif (key == keys.x) then
|
||||||
|
editFuncs.cut()
|
||||||
|
elseif (key == keys.v) then
|
||||||
|
editFuncs.paste()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if (key == keys.c) and (not plc.renderBlittle) then
|
||||||
|
gotoCoords()
|
||||||
|
resetInputState()
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if (keysDown[keys.leftShift]) and (not isDragging) then
|
||||||
|
if key == keys.left then
|
||||||
|
paintEncoded[frame] = movePaintEncoded(paintEncoded[frame],-1,0)
|
||||||
|
saveToUndoBuffer()
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
elseif key == keys.right then
|
||||||
|
paintEncoded[frame] = movePaintEncoded(paintEncoded[frame],1,0)
|
||||||
|
saveToUndoBuffer()
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
elseif key == keys.up then
|
||||||
|
paintEncoded[frame] = movePaintEncoded(paintEncoded[frame],0,-1)
|
||||||
|
saveToUndoBuffer()
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
elseif key == keys.down then
|
||||||
|
paintEncoded[frame] = movePaintEncoded(paintEncoded[frame],0,1)
|
||||||
|
saveToUndoBuffer()
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
if keysDown[keys.leftAlt] then
|
||||||
|
if #paintEncoded > 1 then
|
||||||
|
if key == keys.equals and paintEncoded[frame+1] then --basically plus
|
||||||
|
local first = deepCopy(paintEncoded[frame])
|
||||||
|
local next = deepCopy(paintEncoded[frame+1])
|
||||||
|
paintEncoded[frame] = next
|
||||||
|
paintEncoded[frame+1] = first
|
||||||
|
frame = frame + 1
|
||||||
|
barmsg = "Swapped prev frame."
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
saveToUndoBuffer()
|
||||||
|
end
|
||||||
|
if key == keys.minus and paintEncoded[frame-1] then
|
||||||
|
local first = deepCopy(paintEncoded[frame])
|
||||||
|
local next = deepCopy(paintEncoded[frame-1])
|
||||||
|
paintEncoded[frame] = next
|
||||||
|
paintEncoded[frame-1] = first
|
||||||
|
frame = frame - 1
|
||||||
|
barmsg = "Swapped next frame."
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
saveToUndoBuffer()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif keysDown[keys.leftShift] then
|
||||||
|
if #paintEncoded > 1 then
|
||||||
|
if key == keys.equals and paintEncoded[frame+1] then --basically plus
|
||||||
|
for a = 1, #paintEncoded[frame] do
|
||||||
|
paintEncoded[frame+1][#paintEncoded[frame+1] + 1] = paintEncoded[frame][a]
|
||||||
|
end
|
||||||
|
table.remove(paintEncoded, frame)
|
||||||
|
paintEncoded = clearAllRedundant(paintEncoded)
|
||||||
|
barmsg = "Merged next frame."
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
saveToUndoBuffer()
|
||||||
|
end
|
||||||
|
if key == keys.minus and paintEncoded[frame-1] then
|
||||||
|
for a = 1, #paintEncoded[frame] do
|
||||||
|
paintEncoded[frame-1][#paintEncoded[frame-1] + 1] = paintEncoded[frame][a]
|
||||||
|
end
|
||||||
|
table.remove(paintEncoded, frame)
|
||||||
|
frame = frame - 1
|
||||||
|
paintEncoded = clearAllRedundant(paintEncoded)
|
||||||
|
barmsg = "Merged previous frame."
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
saveToUndoBuffer()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
else
|
||||||
|
if key == keys.equals then --basically 'plus'
|
||||||
|
if plc.renderBlittle then
|
||||||
|
frame = frame + 1
|
||||||
|
if frame > #paintEncoded then frame = 1 end
|
||||||
|
else
|
||||||
|
if not paintEncoded[frame+1] then
|
||||||
|
paintEncoded[frame+1] = {}
|
||||||
|
local sheet = paintEncoded[frame]
|
||||||
|
if keysDown[keys.rightShift] then
|
||||||
|
paintEncoded[frame+1] = deepCopy(sheet)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
frame = frame + 1
|
||||||
|
end
|
||||||
|
saveToUndoBuffer()
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
elseif key == keys.minus then
|
||||||
|
if plc.renderBlittle then
|
||||||
|
frame = frame - 1
|
||||||
|
if frame < 1 then frame = #paintEncoded end
|
||||||
|
else
|
||||||
|
if frame > 1 then
|
||||||
|
frame = frame - 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if good then
|
saveToUndoBuffer()
|
||||||
putDotDown({x=x, y=y})
|
doRender = true
|
||||||
end
|
plc.changedImage = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
saveToUndoBuffer()
|
if not plc.renderBlittle then
|
||||||
doRender = true
|
if key == keys.m then
|
||||||
end
|
local incum = bottomPrompt("Set meta: ",metaHistory)
|
||||||
if key == keys.g then
|
paint.m = incum:gsub(" ","") ~= "" and incum or paint.m
|
||||||
paint.doGray = not paint.doGray
|
if paint.m ~= metaHistory[#metaHistory] then
|
||||||
plc.changedImage = true
|
metaHistory[#metaHistory+1] = paint.m
|
||||||
saveToUndoBuffer()
|
end
|
||||||
doRender = true
|
doRender = true
|
||||||
end
|
isDragging = false
|
||||||
if key == keys.a then
|
end
|
||||||
paint.scrollX = 0
|
if key == keys.f7 then
|
||||||
paint.scrollY = 0
|
plc.bepimode = not plc.bepimode
|
||||||
doRender = true
|
doRender = true
|
||||||
end
|
end
|
||||||
if key == keys.n then
|
if key == keys.t then
|
||||||
if keysDown[keys.leftShift] then
|
renderBottomBar("Click to place text.")
|
||||||
paint.c = specialCharSelector()
|
local mevt
|
||||||
else
|
repeat
|
||||||
paint.c = boxCharSelector()
|
mevt = {os.pullEvent()}
|
||||||
|
until (mevt[1] == "key" and mevt[2] == keys.x) or (mevt[1] == "mouse_click" and mevt[2] == 1 and (mevt[4] or scr_y) <= scr_y-(plc.renderBlittle and 0 or doRenderBar))
|
||||||
|
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
||||||
|
local x,y = mevt[3],mevt[4]
|
||||||
|
if plc.renderBlittle then
|
||||||
|
x = 2*x
|
||||||
|
y = 3*y
|
||||||
|
end
|
||||||
|
putDownText(x,y)
|
||||||
|
miceDown = {}
|
||||||
|
keysDown = {}
|
||||||
|
end
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
isDragging = false
|
||||||
|
end
|
||||||
|
if key == keys.f and not (keysDown[keys.leftShift] or keysDown[keys.rightShift]) and (not plc.isCurrentlyFilling) then
|
||||||
|
renderBottomBar("Click to fill area.")
|
||||||
|
local mevt
|
||||||
|
repeat
|
||||||
|
mevt = {os.pullEvent()}
|
||||||
|
until (mevt[1] == "key" and mevt[2] == keys.x) or (mevt[1] == "mouse_click" and mevt[2] <= 2 and (mevt[4] or scr_y) <= scr_y-(renderBlittle and 0 or doRenderBar))
|
||||||
|
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
||||||
|
local x,y = mevt[3],mevt[4]
|
||||||
|
if plc.renderBlittle then
|
||||||
|
x = 2*x
|
||||||
|
y = 3*y
|
||||||
|
end
|
||||||
|
miceDown = {}
|
||||||
|
keysDown = {}
|
||||||
|
os.queueEvent("filltool_async", frame, x, y, paint, mevt[2] == 2)
|
||||||
|
end
|
||||||
|
doRender = true
|
||||||
|
plc.changedImage = true
|
||||||
|
isDragging = false
|
||||||
|
end
|
||||||
|
if key == keys.p then
|
||||||
|
renderBottomBar("Pick color with cursor:")
|
||||||
|
paintEncoded = clearAllRedundant(paintEncoded)
|
||||||
|
local mevt
|
||||||
|
repeat
|
||||||
|
mevt = {os.pullEvent()}
|
||||||
|
until (mevt[1] == "key" and mevt[2] == keys.x) or (mevt[2] == 1 and mevt[4] <= scr_y)
|
||||||
|
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
||||||
|
local x, y = mevt[3]+paint.scrollX, mevt[4]+paint.scrollY
|
||||||
|
if plc.renderBlittle then
|
||||||
|
x = 2*x
|
||||||
|
y = 3*y
|
||||||
|
end
|
||||||
|
local p
|
||||||
|
for a = 1, #paintEncoded[frame] do
|
||||||
|
p = paintEncoded[frame][a]
|
||||||
|
if (p.x == x) and (p.y == y) then
|
||||||
|
paint.t = p.t or paint.t
|
||||||
|
paint.b = p.b or paint.b
|
||||||
|
paint.c = p.c or paint.c
|
||||||
|
paint.m = p.m or paint.m
|
||||||
|
miceDown = {}
|
||||||
|
keysDown = {}
|
||||||
|
doRender = true
|
||||||
|
isDragging = false
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
|
resetInputState()
|
||||||
|
end
|
||||||
|
doRender = true
|
||||||
|
isDragging = false
|
||||||
|
end
|
||||||
|
if (key == keys.leftCtrl or key == keys.rightCtrl) then
|
||||||
|
keysDown = {[207] = keysDown[207]}
|
||||||
|
isDragging = false
|
||||||
|
local res = displayMenu()
|
||||||
|
paintEncoded = clearAllRedundant(paintEncoded)
|
||||||
|
if res == "exit" then break end
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
end
|
end
|
||||||
resetInputState()
|
if (key == keys.f and keysDown[keys.leftShift]) then
|
||||||
doRender = true
|
local deredots = {}
|
||||||
end
|
plc.changedImage = true
|
||||||
if key == keys.f1 then
|
for a = 1, #paintEncoded[frame] do
|
||||||
guiHelp()
|
local dot = paintEncoded[frame][a]
|
||||||
resetInputState()
|
if dot.x-paint.scrollX > 0 and dot.x-paint.scrollX <= scr_x then
|
||||||
isDragging = false
|
if dot.y-paint.scrollY > 0 and dot.y-paint.scrollY <= scr_y then
|
||||||
end
|
deredots[#deredots+1] = {dot.x-paint.scrollX, dot.y-paint.scrollY}
|
||||||
if key == keys.f3 then
|
end
|
||||||
listAllMonitors()
|
end
|
||||||
resetInputState()
|
end
|
||||||
isDragging = false
|
for y = 1, scr_y do
|
||||||
end
|
for x = 1, scr_x do
|
||||||
if key == keys.leftBracket then
|
local good = true
|
||||||
os.queueEvent("mouse_scroll",2,1,1)
|
for a = 1, #deredots do
|
||||||
elseif key == keys.rightBracket then
|
if (deredots[a][1] == x) and (deredots[a][2] == y) then
|
||||||
os.queueEvent("mouse_scroll",1,1,1)
|
good = bad
|
||||||
end
|
break
|
||||||
if key == keys.z then
|
end
|
||||||
if keysDown[keys.leftAlt] and plc.undoPos < #plc.undoBuffer then
|
end
|
||||||
doRedo()
|
if good then
|
||||||
barmsg = "Redood."
|
putDotDown({x=x, y=y})
|
||||||
doRender = true
|
end
|
||||||
elseif plc.undoPos > 1 then
|
end
|
||||||
doUndo()
|
end
|
||||||
barmsg = "Undood."
|
saveToUndoBuffer()
|
||||||
doRender = true
|
doRender = true
|
||||||
end
|
end
|
||||||
|
if key == keys.g then
|
||||||
|
paint.doGray = not paint.doGray
|
||||||
|
plc.changedImage = true
|
||||||
|
saveToUndoBuffer()
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
|
if key == keys.a then
|
||||||
|
paint.scrollX = 0
|
||||||
|
paint.scrollY = 0
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
|
if key == keys.n then
|
||||||
|
if keysDown[keys.leftShift] then
|
||||||
|
paint.c = specialCharSelector()
|
||||||
|
else
|
||||||
|
paint.c = boxCharSelector()
|
||||||
|
end
|
||||||
|
resetInputState()
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
|
if key == keys.f1 then
|
||||||
|
guiHelp()
|
||||||
|
resetInputState()
|
||||||
|
isDragging = false
|
||||||
|
end
|
||||||
|
if key == keys.f3 then
|
||||||
|
listAllMonitors()
|
||||||
|
resetInputState()
|
||||||
|
isDragging = false
|
||||||
|
end
|
||||||
|
if key == keys.leftBracket then
|
||||||
|
os.queueEvent("mouse_scroll",2,1,1)
|
||||||
|
elseif key == keys.rightBracket then
|
||||||
|
os.queueEvent("mouse_scroll",1,1,1)
|
||||||
|
end
|
||||||
|
if key == keys.z then
|
||||||
|
if keysDown[keys.leftAlt] and plc.undoPos < #plc.undoBuffer then
|
||||||
|
doRedo()
|
||||||
|
barmsg = "Redood."
|
||||||
|
doRender = true
|
||||||
|
elseif plc.undoPos > 1 then
|
||||||
|
doUndo()
|
||||||
|
barmsg = "Undood."
|
||||||
|
doRender = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
elseif evt[1] == "key_up" then
|
||||||
|
local key = evt[2]
|
||||||
|
keysDown[key] = false
|
||||||
|
end
|
||||||
|
if (oldx~=paint.scrollX) or (oldy~=paint.scrollY) then
|
||||||
|
doRender = true
|
||||||
end
|
end
|
||||||
elseif evt[1] == "key_up" then
|
|
||||||
local key = evt[2]
|
|
||||||
keysDown[key] = false
|
|
||||||
end
|
|
||||||
if (oldx~=paint.scrollX) or (oldy~=paint.scrollY) then
|
|
||||||
doRender = true
|
|
||||||
end
|
|
||||||
if doRender then
|
|
||||||
renderAllPAIN()
|
|
||||||
doRender = false
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
parallel.waitForAny(doot, function()
|
||||||
|
while true do
|
||||||
|
sleep(0.05)
|
||||||
|
if doRender then
|
||||||
|
renderAllPAIN()
|
||||||
|
doRender = false
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
runPainEditor = function(...) --needs to be cleaned up
|
runPainEditor = function(...) --needs to be cleaned up
|
||||||
|
Loading…
x
Reference in New Issue
Block a user