diff --git a/core/element.lua b/core/element.lua index 0a3af32..39d5a64 100644 --- a/core/element.lua +++ b/core/element.lua @@ -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() - - love.graphics.translate(ox, oy) - - love.graphics.setScissor(ox, oy, w, h) - love.graphics.clear(0,0,0,0) + lg.push('all') + lg.origin() + lg.translate(ox, oy) + lg.setScissor(ox, oy, w, h) + lg.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 diff --git a/init.lua b/init.lua index 2ea75e8..6a82aac 100644 --- a/init.lua +++ b/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 diff --git a/shell/button.lua b/shell/button.lua index 6254a33..4aa1580 100644 --- a/shell/button.lua +++ b/shell/button.lua @@ -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 \ No newline at end of file