added undraw

This commit is contained in:
qeffects 2021-07-21 22:40:20 +03:00
parent 0f99994ae3
commit 2144c5ab21
4 changed files with 58 additions and 14 deletions

View File

@ -46,6 +46,7 @@ function element:new(param, immediate, w, h, flags)
isSetup = false, isSetup = false,
pendingUpdate = true, pendingUpdate = true,
needsRendering = true, needsRendering = true,
active = true,
remove = false, remove = false,
--Unused for now? --Unused for now?
calculatedDimensions = true, calculatedDimensions = true,
@ -285,8 +286,13 @@ function element:renderWrapper()
self.context:unset() self.context:unset()
end end
local lg = love.graphics local lg = love.graphics
function element:externalRender() function element:externalRender()
if not self.settings.active then
return
end
local cnvs = getCanvas() local cnvs = getCanvas()
love.graphics.push('all') love.graphics.push('all')
@ -348,6 +354,9 @@ function element:externalRender()
end end
function element:externalUpdate() function element:externalUpdate()
if not self.settings.active then
return
end
self.context:set() self.context:set()
self.context:zIndex() self.context:zIndex()
if ((not self.settings.failedCanvas if ((not self.settings.failedCanvas
@ -402,6 +411,10 @@ function element:draw(x, y, w, h)
if w then self.view.w = w end if w then self.view.w = w end
if h then self.view.h = h end if h then self.view.h = h end
if not self.settings.active then
self:redraw()
end
local cx = context.getContext() local cx = context.getContext()
if cx then if cx then
if cx:childRender(self) then if cx:childRender(self) then
@ -429,10 +442,23 @@ end
---Destroys this element ---Destroys this element
function element:destroy() function element:destroy()
self.settings.remove = true self.settings.remove = true
self.settings.inserted = false
self.settings.active = false
self.settings.firstDraw = true self.settings.firstDraw = true
self.settings.isSetup = false self.settings.isSetup = false
self:onDestroy() self:onDestroy()
self.context:destroy() self.context:destroy()
end end
function element:redraw()
self.settings.active = true
self.context:redraw()
end
---Stops rendering, updates and draw
function element:undraw()
self.settings.active = false
self.context:undraw()
end
return element return element

View File

@ -207,7 +207,7 @@ function input.eventHandlers.mousereleased(x, y, btn)
local captured = false local captured = false
if input.subscriptions.clicked then if input.subscriptions.clicked then
for index, sub in ipairs(input.subscriptions.clicked) do for index, sub in ipairs(input.subscriptions.clicked) do
if sub.currentEvent then if sub.currentEvent and sub.active and sub.stack.element.settings.active then
sub.currentEvent = false sub.currentEvent = false
captured = true captured = true
if sub.cleanUp then if sub.cleanUp then
@ -219,7 +219,7 @@ function input.eventHandlers.mousereleased(x, y, btn)
if input.subscriptions.dragged then if input.subscriptions.dragged then
for index, sub in ipairs(input.subscriptions.dragged) do for index, sub in ipairs(input.subscriptions.dragged) do
if sub.currentEvent then if sub.currentEvent and sub.active and sub.stack.element.settings.active then
sub.currentEvent = false sub.currentEvent = false
captured = true captured = true
if sub.cleanUp then if sub.cleanUp then
@ -231,7 +231,7 @@ function input.eventHandlers.mousereleased(x, y, btn)
if input.subscriptions.mousereleased then if input.subscriptions.mousereleased then
for index, sub in ipairs(input.subscriptions.mousereleased) do for index, sub in ipairs(input.subscriptions.mousereleased) do
if sub.active and sub:checkInside(x, y) then if sub.active and sub.stack.element.settings.active and sub:checkInside(x, y) then
sub:emit(x-sub.x, y-sub.y, btn) sub:emit(x-sub.x, y-sub.y, btn)
captured = true captured = true
end end
@ -241,7 +241,7 @@ function input.eventHandlers.mousereleased(x, y, btn)
if input.subscriptions.mousereleased_outside then if input.subscriptions.mousereleased_outside then
for index, sub in ipairs(input.subscriptions.mousereleased_outside) do for index, sub in ipairs(input.subscriptions.mousereleased_outside) do
if sub.active and sub:checkOutside(x, y) then if sub.active and sub.stack.element.settings.active and sub:checkOutside(x, y) then
sub:emit(x-sub.x, y-sub.y, btn) sub:emit(x-sub.x, y-sub.y, btn)
captured = true captured = true
end end
@ -259,7 +259,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
for index, sub in ipairs(input.subscriptions.clicked) do for index, sub in ipairs(input.subscriptions.clicked) do
local succ = sub:checkInside(x, y) local succ = sub:checkInside(x, y)
if succ and sub.active then if succ and sub.active and sub.stack.element.settings.active then
sub.cleanUp = sub:emit(x-sub.x, y-sub.y, btn) or dummyfunc sub.cleanUp = sub:emit(x-sub.x, y-sub.y, btn) or dummyfunc
sub.currentEvent = true sub.currentEvent = true
return true return true
@ -270,7 +270,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
if input.subscriptions.dragged then if input.subscriptions.dragged then
for index, sub in ipairs(input.subscriptions.dragged) do for index, sub in ipairs(input.subscriptions.dragged) do
if sub.active and sub:checkInside(x, y) then if sub.active and sub.stack.element.settings.active and sub:checkInside(x, y) then
sub.currentEvent = true sub.currentEvent = true
return true return true
end end
@ -280,7 +280,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
if input.subscriptions.mousepressed then if input.subscriptions.mousepressed then
for index, sub in ipairs(input.subscriptions.mousepressed) do for index, sub in ipairs(input.subscriptions.mousepressed) do
if sub.active and sub:checkInside(x, y) then if sub.active and sub.stack.element.settings.active and sub:checkInside(x, y) then
sub:emit(x-sub.x, y-sub.y, btn) sub:emit(x-sub.x, y-sub.y, btn)
return true return true
end end
@ -290,7 +290,7 @@ function input.eventHandlers.mousepressed(x, y, btn)
if input.subscriptions.mousepressed_outside then if input.subscriptions.mousepressed_outside then
for index, sub in ipairs(input.subscriptions.mousepressed_outside) do for index, sub in ipairs(input.subscriptions.mousepressed_outside) do
if sub.active and sub:checkOutside(x, y) then if sub.active and sub.stack.element.settings.active and sub:checkOutside(x, y) then
sub:emit(x-sub.x, y-sub.y, btn) sub:emit(x-sub.x, y-sub.y, btn)
return true return true
end end
@ -304,7 +304,7 @@ function input.eventHandlers.keypressed(btn, btncode)
local captured = false local captured = false
if input.subscriptions.keypressed then if input.subscriptions.keypressed then
for index, sub in ipairs(input.subscriptions.keypressed) do for index, sub in ipairs(input.subscriptions.keypressed) do
if sub.active then if sub.active and sub.stack.element.settings.active then
sub:emit(btn, btncode) sub:emit(btn, btncode)
captured = true captured = true
end end
@ -319,7 +319,7 @@ function input.eventHandlers.keyreleased(btn, btncode)
local captured = false local captured = false
if input.subscriptions.keyreleased then if input.subscriptions.keyreleased then
for index, sub in ipairs(input.subscriptions.keyreleased) do for index, sub in ipairs(input.subscriptions.keyreleased) do
if sub.active then if sub.active and sub.stack.element.settings.active then
sub:emit(btn, btncode) sub:emit(btn, btncode)
captured = true captured = true
end end
@ -333,7 +333,7 @@ function input.eventHandlers.textinput(text)
local captured = false local captured = false
if input.subscriptions.textinput then if input.subscriptions.textinput then
for index, sub in ipairs(input.subscriptions.textinput) do for index, sub in ipairs(input.subscriptions.textinput) do
if sub.active then if sub.active and sub.stack.element.settings.active then
sub:emit(text) sub:emit(text)
captured = true captured = true
end end
@ -350,7 +350,7 @@ function input.eventHandlers.mousemoved(x, y, dx, dy)
for index, sub in ipairs(input.subscriptions.hover) do for index, sub in ipairs(input.subscriptions.hover) do
local succ = sub:checkInside(x, y) local succ = sub:checkInside(x, y)
if sub.active and not sub.currentEvent and succ then if sub.active and sub.stack.element.settings.active and not sub.currentEvent and succ then
sub.cleanUp = sub:emit(x-sub.x, y-sub.y, dx, dy) or dummyfunc sub.cleanUp = sub:emit(x-sub.x, y-sub.y, dx, dy) or dummyfunc
sub.currentEvent = true sub.currentEvent = true
return true return true
@ -367,7 +367,7 @@ function input.eventHandlers.mousemoved(x, y, dx, dy)
if input.subscriptions.dragged then if input.subscriptions.dragged then
for index, sub in ipairs(input.subscriptions.dragged) do for index, sub in ipairs(input.subscriptions.dragged) do
if sub.active and sub.currentEvent then if sub.active and sub.stack.element.settings.active and sub.currentEvent then
if not sub.cleanUp then if not sub.cleanUp then
sub.cleanUp = sub:emit(x-sub.x, y-sub.y, dx, dy) or dummyfunc sub.cleanUp = sub:emit(x-sub.x, y-sub.y, dx, dy) or dummyfunc
else else

View File

@ -105,6 +105,18 @@ function context:destroy()
end end
end end
function context:undraw()
for i = 1, #self.childrenContexts do
self.childrenContexts[i].element:undraw()
end
end
function context:redraw()
for i = 1, #self.childrenContexts do
self.childrenContexts[i].element:redraw()
end
end
function context:getCanvasIndex(forCanvas) function context:getCanvasIndex(forCanvas)
if self.parentCtx then if self.parentCtx then
if self.element.settings.hasCanvas then if self.element.settings.hasCanvas then

View File

@ -105,7 +105,13 @@ Inside it renders immediately, so you can put it inbetween other graphics operat
`Element:destroy()` `Element:destroy()`
Use destroy to remove this element from the scene Use destroy to completely and irreversibly remove this element from the scene
---
`Element:undraw()`
Use undraw to hide this element for now with the intention of re-drawing it sometime later, to do that just :draw() it again
--- ---