mirror of
https://github.com/LDDestroier/CC/
synced 2024-06-25 22:53:18 +00:00
Put fill tool on separate coroutine
This commit is contained in:
parent
1dc2d1c235
commit
f51b635153
44
pain.lua
44
pain.lua
|
@ -72,6 +72,7 @@ local firstTerm, blittleTerm = term.current()
|
||||||
local firstBG = term.getBackgroundColor()
|
local firstBG = term.getBackgroundColor()
|
||||||
local firstTX = term.getTextColor()
|
local firstTX = term.getTextColor()
|
||||||
local changedImage = false
|
local changedImage = false
|
||||||
|
local isCurrentlyFilling = false
|
||||||
|
|
||||||
local _
|
local _
|
||||||
local tableconcat = table.concat
|
local tableconcat = table.concat
|
||||||
|
@ -1447,10 +1448,10 @@ local convertToGrayscale = function(pe)
|
||||||
return output
|
return output
|
||||||
end
|
end
|
||||||
|
|
||||||
local reRenderPAIN = function()
|
local reRenderPAIN = function(overrideRenderBar)
|
||||||
local _reallyDoRenderBar = doRenderBar
|
local _reallyDoRenderBar = doRenderBar
|
||||||
doRenderBar = 1
|
doRenderBar = 1
|
||||||
renderPAIN(paintEncoded[frame],paint.scrollX,paint.scrollY,true,true)
|
renderPAIN(paintEncoded[frame],paint.scrollX,paint.scrollY,true,overrideRenderBar)
|
||||||
doRenderBar = _reallyDoRenderBar
|
doRenderBar = _reallyDoRenderBar
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1523,15 +1524,17 @@ local fillTool = function(_frame,cx,cy,dot) -- "_frame" is the frame NUMBER
|
||||||
end
|
end
|
||||||
local doBreak
|
local doBreak
|
||||||
local step = 0
|
local step = 0
|
||||||
|
local currentlyOnScreen
|
||||||
while true do
|
while true do
|
||||||
doBreak = true
|
doBreak = true
|
||||||
for chY, v in pairs(check) do
|
for chY, v in pairs(check) do
|
||||||
for chX, isTrue in pairs(v) do
|
for chX, isTrue in pairs(v) do
|
||||||
|
currentlyOnScreen = (chX-paint.scrollX >= 1 and chX-paint.scrollX <= scr_x and chY-paint.scrollY >= 1 and chY-paint.scrollY <= scr_y)
|
||||||
if isTrue and (not touched[chY][chX]) then
|
if isTrue and (not touched[chY][chX]) then
|
||||||
step = step + 1
|
step = step + 1
|
||||||
if doFillAnimation and (step % 2 == 0) then
|
if doFillAnimation then
|
||||||
if (chX-paint.scrollX >= 1 and chX-paint.scrollX <= scr_x and chY-paint.scrollY >= 1 and chY-paint.scrollY <= scr_y) then
|
if currentlyOnScreen then
|
||||||
reRenderPAIN()
|
reRenderPAIN(true)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
frame[#frame+1] = {
|
frame[#frame+1] = {
|
||||||
|
@ -1584,7 +1587,7 @@ local fillTool = function(_frame,cx,cy,dot) -- "_frame" is the frame NUMBER
|
||||||
doBreak = false
|
doBreak = false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if step % (doFillAnimation and 256 or 1024) == 0 then -- tries to prevent crash
|
if step % ((doFillAnimation and currentlyOnScreen) and 4 or 1024) == 0 then -- tries to prevent crash
|
||||||
sleep(0)
|
sleep(0)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -2111,7 +2114,7 @@ I recommend using NFT if you don't need multiple frames, NFP if you don't need t
|
||||||
elseif output == false then
|
elseif output == false then
|
||||||
return "nobreak"
|
return "nobreak"
|
||||||
end
|
end
|
||||||
reRenderPAIN()
|
reRenderPAIN(true)
|
||||||
end
|
end
|
||||||
end,
|
end,
|
||||||
[2] = function() --Edit
|
[2] = function() --Edit
|
||||||
|
@ -2244,7 +2247,7 @@ I recommend using NFT if you don't need multiple frames, NFP if you don't need t
|
||||||
if res == "exit" then
|
if res == "exit" then
|
||||||
return "exit"
|
return "exit"
|
||||||
elseif res == "nobreak" then
|
elseif res == "nobreak" then
|
||||||
reRenderPAIN()
|
reRenderPAIN(true)
|
||||||
else
|
else
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
@ -2623,7 +2626,7 @@ local getInput = function() --gotta catch them all
|
||||||
local mevt
|
local mevt
|
||||||
repeat
|
repeat
|
||||||
mevt = {os.pullEvent()}
|
mevt = {os.pullEvent()}
|
||||||
until (mevt[1] == "key" and mevt[2] == keys.x) or (mevt[2] == 1 and (mevt[4] or scr_y) < scr_y-(renderBlittle and 0 or doRenderBar))
|
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-(renderBlittle and 0 or doRenderBar))
|
||||||
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
||||||
local x,y = mevt[3],mevt[4]
|
local x,y = mevt[3],mevt[4]
|
||||||
if renderBlittle then
|
if renderBlittle then
|
||||||
|
@ -2638,27 +2641,25 @@ local getInput = function() --gotta catch them all
|
||||||
changedImage = true
|
changedImage = true
|
||||||
isDragging = false
|
isDragging = false
|
||||||
end
|
end
|
||||||
if key == keys.f and not (keysDown[keys.leftShift] or keysDown[keys.rightShift]) then
|
if key == keys.f and not (keysDown[keys.leftShift] or keysDown[keys.rightShift]) and (not isCurrentlyFilling) then
|
||||||
renderBottomBar("Click to fill area.")
|
renderBottomBar("Click to fill area.")
|
||||||
local mevt
|
local mevt
|
||||||
repeat
|
repeat
|
||||||
mevt = {os.pullEvent()}
|
mevt = {os.pullEvent()}
|
||||||
until (mevt[1] == "key" and mevt[2] == keys.x) or (mevt[2] == 1 and (mevt[4] or scr_y) < scr_y-(renderBlittle and 0 or doRenderBar))
|
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-(renderBlittle and 0 or doRenderBar))
|
||||||
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
if not (mevt[1] == "key" and mevt[2] == keys.x) then
|
||||||
local x,y = mevt[3],mevt[4]
|
local x,y = mevt[3],mevt[4]
|
||||||
if renderBlittle then
|
if renderBlittle then
|
||||||
x = 2*x
|
x = 2*x
|
||||||
y = 3*y
|
y = 3*y
|
||||||
end
|
end
|
||||||
renderBottomBar("Filling area...")
|
os.queueEvent("filltool_async", frame, x, y, paint)
|
||||||
fillTool(frame, x, y, paint)
|
|
||||||
miceDown = {}
|
miceDown = {}
|
||||||
keysDown = {}
|
keysDown = {}
|
||||||
end
|
end
|
||||||
doRender = true
|
doRender = true
|
||||||
changedImage = true
|
changedImage = true
|
||||||
isDragging = false
|
isDragging = false
|
||||||
renderBottomBar("Click to fill region.")
|
|
||||||
end
|
end
|
||||||
if key == keys.p then
|
if key == keys.p then
|
||||||
renderBottomBar("Pick color with cursor:")
|
renderBottomBar("Pick color with cursor:")
|
||||||
|
@ -2905,6 +2906,19 @@ runPainEditor = function(...) --needs to be cleaned up
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local asyncFillTool = function()
|
||||||
|
local event, frameNo, x, y, dot
|
||||||
|
isCurrentlyFilling = false
|
||||||
|
while true do
|
||||||
|
event, frameNo, x, y, dot = os.pullEvent("filltool_async")
|
||||||
|
isCurrentlyFilling = true
|
||||||
|
renderBottomBar("Filling area...")
|
||||||
|
fillTool(frameNo, x, y, dot)
|
||||||
|
isCurrentlyFilling = false
|
||||||
|
reRenderPAIN(false)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if not paintEncoded[frame] then paintEncoded = {paintEncoded} end
|
if not paintEncoded[frame] then paintEncoded = {paintEncoded} end
|
||||||
if pMode == 1 then
|
if pMode == 1 then
|
||||||
doRenderBar = 0
|
doRenderBar = 0
|
||||||
|
@ -2916,7 +2930,7 @@ runPainEditor = function(...) --needs to be cleaned up
|
||||||
end
|
end
|
||||||
lastPaintEncoded = deepCopy(paintEncoded)
|
lastPaintEncoded = deepCopy(paintEncoded)
|
||||||
undoBuffer = {deepCopy(paintEncoded)}
|
undoBuffer = {deepCopy(paintEncoded)}
|
||||||
parallel.waitForAny(getInput,doNonEventDrivenMovement)
|
parallel.waitForAny(getInput, doNonEventDrivenMovement, asyncFillTool)
|
||||||
|
|
||||||
term.setCursorPos(1,scr_y)
|
term.setCursorPos(1,scr_y)
|
||||||
term.setBackgroundColor(colors.black)
|
term.setBackgroundColor(colors.black)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user