first shell function: button

This commit is contained in:
Elmārs Āboliņš 2020-10-19 02:21:04 +03:00
parent 7419274205
commit 44c16b2c40
3 changed files with 56 additions and 26 deletions

View File

@ -178,8 +178,8 @@ end
function element:setCalculatedSize(w, h) function element:setCalculatedSize(w, h)
self.view.minW = w or self.view.minW self.view.minW = w or self.view.minW
self.view.minH = h or self.view.minH self.view.minH = h or self.view.minH
self.view.w = math.max(self.view.minW, self.view.w) self.view.w = w or self.view.minW
self.view.h = math.max(self.view.minH, self.view.h) self.view.h = h or self.view.minH
end end
local dummy = function() end local dummy = function() end
@ -233,7 +233,7 @@ function element:renderWrapper()
self.context:unset() self.context:unset()
end end
local lg = love.graphics
function element:externalRender() function element:externalRender()
local cnvs = getCanvas() local cnvs = getCanvas()
love.graphics.push('all') love.graphics.push('all')
@ -247,33 +247,36 @@ function element:externalRender()
if self.settings.hasCanvas then if self.settings.hasCanvas then
setCanvas(self.canvas) setCanvas(self.canvas)
--need scissors --need scissors
love.graphics.push('all')
love.graphics.origin()
local ox, oy, w, h = self.quad:getViewport() local ox, oy, w, h = self.quad:getViewport()
lg.push('all')
love.graphics.translate(ox, oy) lg.origin()
lg.translate(ox, oy)
love.graphics.setScissor(ox, oy, w, h) lg.setScissor(ox, oy, w, h)
love.graphics.clear(0,0,0,0) lg.clear(0,0,0,0)
self:renderWrapper() self:renderWrapper()
self.settings.needsRendering = false self.settings.needsRendering = false
love.graphics.pop() lg.pop()
else else
love.graphics.translate(self.view.x, self.view.y) lg.translate(self.view.x, self.view.y)
local x, y = love.graphics.transformPoint(0, 0) local x, y = lg.transformPoint(0, 0)
love.graphics.setScissor(x, y, self.view.w, self.view.h) lg.intersectScissor(x, y, self.view.w, self.view.h)
self:renderWrapper() self:renderWrapper()
end end
end end
--lg.setScissor()
setCanvas(cnvs) setCanvas(cnvs)
if self.settings.hasCanvas then if self.settings.hasCanvas then
love.graphics.translate(self.view.x, self.view.y) lg.translate(self.view.x, self.view.y)
setColor(1, 1, 1, 1) setColor(1, 1, 1, 1)
draw(self.canvas, self.quad, 0, 0) draw(self.canvas, self.quad, 0, 0)
end end
lg.setScissor()
love.graphics.pop() love.graphics.pop()
end end

View File

@ -27,7 +27,7 @@ setmetatable(helium, {__call = function(s, chunk)
end,}) end,})
end}) end})
local first = true local skipframes = 10
local skip = true local skip = true
function helium.load() function helium.load()
@ -41,9 +41,7 @@ end
function helium.draw() function helium.draw()
if first and not skip then if skipframes == 0 then
--love.graphics.setScissor(500, 500, 1, 1)
local startTime = love.timer.getTime() local startTime = love.timer.getTime()
for i = 1, 20 do for i = 1, 20 do
@ -52,11 +50,8 @@ function helium.draw()
helium.element.setBench((love.timer.getTime()-startTime)/5) helium.element.setBench((love.timer.getTime()-startTime)/5)
helium.atlas.setBench((love.timer.getTime()-startTime)/5) helium.atlas.setBench((love.timer.getTime()-startTime)/5)
elseif skipframes>0 then
first = false skipframes = skipframes - 1
--love.graphics.setScissor()
elseif first then
skip = false
end end
--We don't want any side effects affecting internal rendering --We don't want any side effects affecting internal rendering

View File

@ -3,8 +3,40 @@ local state = require(path.. ".control.state")
local input = require(path.. ".core.input") local input = require(path.. ".core.input")
return function(onClick, onRelease, onEnter, onExit, x, y, w, h) return function(onClick, onRelease, onEnter, onExit, x, y, w, h)
local button = {} local button = state {
input('clicked') down = false,
over = false,
}
input('clicked', function(x, y, w, h)
if onClick then
onClick(x, y, w, h)
end
button.down = true
return function(x, y, w, h)
if onRelease then
onRelease(x, y, w, h)
end
button.down = false
end
end)
input('hover', function(x, y, w, h)
if onEnter then
onEnter(x, y, w, h)
end
button.over = true
return function(x, y, w, h)
if onExit then
onExit(x, y, w, h)
end
button.over = false
end
end)
return button return button
end end