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,
pendingUpdate = true,
needsRendering = true,
active = true,
remove = false,
--Unused for now?
calculatedDimensions = true,
@ -285,8 +286,13 @@ function element:renderWrapper()
self.context:unset()
end
local lg = love.graphics
function element:externalRender()
if not self.settings.active then
return
end
local cnvs = getCanvas()
love.graphics.push('all')
@ -348,6 +354,9 @@ function element:externalRender()
end
function element:externalUpdate()
if not self.settings.active then
return
end
self.context:set()
self.context:zIndex()
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 h then self.view.h = h end
if not self.settings.active then
self:redraw()
end
local cx = context.getContext()
if cx then
if cx:childRender(self) then
@ -429,10 +442,23 @@ end
---Destroys this element
function element:destroy()
self.settings.remove = true
self.settings.inserted = false
self.settings.active = false
self.settings.firstDraw = true
self.settings.isSetup = false
self:onDestroy()
self.context:destroy()
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

View File

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

View File

@ -105,6 +105,18 @@ function context:destroy()
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)
if self.parentCtx 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()`
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
---