first shell function: button
This commit is contained in:
parent
7419274205
commit
44c16b2c40
@ -178,8 +178,8 @@ end
|
||||
function element:setCalculatedSize(w, h)
|
||||
self.view.minW = w or self.view.minW
|
||||
self.view.minH = h or self.view.minH
|
||||
self.view.w = math.max(self.view.minW, self.view.w)
|
||||
self.view.h = math.max(self.view.minH, self.view.h)
|
||||
self.view.w = w or self.view.minW
|
||||
self.view.h = h or self.view.minH
|
||||
end
|
||||
|
||||
local dummy = function() end
|
||||
@ -233,7 +233,7 @@ function element:renderWrapper()
|
||||
|
||||
self.context:unset()
|
||||
end
|
||||
|
||||
local lg = love.graphics
|
||||
function element:externalRender()
|
||||
local cnvs = getCanvas()
|
||||
love.graphics.push('all')
|
||||
@ -247,33 +247,36 @@ function element:externalRender()
|
||||
if self.settings.hasCanvas then
|
||||
setCanvas(self.canvas)
|
||||
--need scissors
|
||||
love.graphics.push('all')
|
||||
love.graphics.origin()
|
||||
local ox, oy, w, h = self.quad:getViewport()
|
||||
lg.push('all')
|
||||
lg.origin()
|
||||
lg.translate(ox, oy)
|
||||
lg.setScissor(ox, oy, w, h)
|
||||
lg.clear(0,0,0,0)
|
||||
|
||||
love.graphics.translate(ox, oy)
|
||||
|
||||
love.graphics.setScissor(ox, oy, w, h)
|
||||
love.graphics.clear(0,0,0,0)
|
||||
self:renderWrapper()
|
||||
|
||||
self.settings.needsRendering = false
|
||||
love.graphics.pop()
|
||||
lg.pop()
|
||||
else
|
||||
love.graphics.translate(self.view.x, self.view.y)
|
||||
local x, y = love.graphics.transformPoint(0, 0)
|
||||
love.graphics.setScissor(x, y, self.view.w, self.view.h)
|
||||
lg.translate(self.view.x, self.view.y)
|
||||
local x, y = lg.transformPoint(0, 0)
|
||||
lg.intersectScissor(x, y, self.view.w, self.view.h)
|
||||
|
||||
self:renderWrapper()
|
||||
end
|
||||
end
|
||||
--lg.setScissor()
|
||||
|
||||
setCanvas(cnvs)
|
||||
|
||||
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)
|
||||
draw(self.canvas, self.quad, 0, 0)
|
||||
end
|
||||
|
||||
lg.setScissor()
|
||||
love.graphics.pop()
|
||||
end
|
||||
|
||||
|
||||
13
init.lua
13
init.lua
@ -27,7 +27,7 @@ setmetatable(helium, {__call = function(s, chunk)
|
||||
end,})
|
||||
end})
|
||||
|
||||
local first = true
|
||||
local skipframes = 10
|
||||
local skip = true
|
||||
|
||||
function helium.load()
|
||||
@ -41,9 +41,7 @@ end
|
||||
|
||||
|
||||
function helium.draw()
|
||||
if first and not skip then
|
||||
--love.graphics.setScissor(500, 500, 1, 1)
|
||||
|
||||
if skipframes == 0 then
|
||||
local startTime = love.timer.getTime()
|
||||
|
||||
for i = 1, 20 do
|
||||
@ -52,11 +50,8 @@ function helium.draw()
|
||||
|
||||
helium.element.setBench((love.timer.getTime()-startTime)/5)
|
||||
helium.atlas.setBench((love.timer.getTime()-startTime)/5)
|
||||
|
||||
first = false
|
||||
--love.graphics.setScissor()
|
||||
elseif first then
|
||||
skip = false
|
||||
elseif skipframes>0 then
|
||||
skipframes = skipframes - 1
|
||||
end
|
||||
|
||||
--We don't want any side effects affecting internal rendering
|
||||
|
||||
@ -3,8 +3,40 @@ local state = require(path.. ".control.state")
|
||||
local input = require(path.. ".core.input")
|
||||
|
||||
return function(onClick, onRelease, onEnter, onExit, x, y, w, h)
|
||||
local button = {}
|
||||
input('clicked')
|
||||
local button = state {
|
||||
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
|
||||
end
|
||||
Loading…
x
Reference in New Issue
Block a user