Merge branch 'layout' of https://github.com/qfluxstudio/helium into layout
This commit is contained in:
commit
9370c1f456
@ -60,18 +60,18 @@ function atlases:assign(element)
|
|||||||
|
|
||||||
local elW = element.view.w
|
local elW = element.view.w
|
||||||
local elH = element.view.h
|
local elH = element.view.h
|
||||||
local canvas, quad, interQuad = self.atlases[canvasID]:assignElement(element)
|
local canvas, quad = self.atlases[canvasID]:assignElement(element)
|
||||||
if not canvas and self.atlases[canvasID].ideal_area < self.atlases[canvasID].taken_area*4 then
|
if not canvas and self.atlases[canvasID].ideal_area < self.atlases[canvasID].taken_area*4 then
|
||||||
--print('refragmenting ;3')
|
--print('refragmenting ;3')
|
||||||
self.atlases[canvasID]:refragment()
|
self.atlases[canvasID]:refragment()
|
||||||
canvas, quad, interQuad = self.atlases[canvasID]:assignElement(element)
|
canvas, quad = self.atlases[canvasID]:assignElement(element)
|
||||||
if not canvas then
|
if not canvas then
|
||||||
--print('ran out of space')
|
--print('ran out of space')
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
--print('wont refragment', createdAtlas.ideal_area, createdAtlas.taken_area)
|
--print('wont refragment', createdAtlas.ideal_area, createdAtlas.taken_area)
|
||||||
end
|
end
|
||||||
return canvas, quad, interQuad
|
return canvas, quad, canvasID
|
||||||
end
|
end
|
||||||
|
|
||||||
function atlases:unassign(element)
|
function atlases:unassign(element)
|
||||||
@ -145,12 +145,9 @@ function atlas:assignElement(element)
|
|||||||
if self.users[element] and self.users[element].quad and self.users[element].interQuad then
|
if self.users[element] and self.users[element].quad and self.users[element].interQuad then
|
||||||
--update by reference owo
|
--update by reference owo
|
||||||
self.users[element].quad:setViewport((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH)
|
self.users[element].quad:setViewport((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH)
|
||||||
self.users[element].interQuad:setViewport(0, 0, elW, elH)
|
|
||||||
quad = self.users[element].quad
|
quad = self.users[element].quad
|
||||||
iquad = self.users[element].interQuad
|
|
||||||
else
|
else
|
||||||
quad = love.graphics.newQuad((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH, self.w, self.h)
|
quad = love.graphics.newQuad((x-1)*BLOCK_SIZE, (y-1)*BLOCK_SIZE, elW, elH, self.w, self.h)
|
||||||
iquad = love.graphics.newQuad(0, 0, elW, elH, sw, sh)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
self.users[element] = {
|
self.users[element] = {
|
||||||
@ -165,7 +162,7 @@ function atlas:assignElement(element)
|
|||||||
self:markTiles(x, y, tileSizeX, tileSizeY)
|
self:markTiles(x, y, tileSizeX, tileSizeY)
|
||||||
self.taken_area = self.taken_area + ((tileSizeY*BLOCK_SIZE)*(tileSizeX*BLOCK_SIZE))
|
self.taken_area = self.taken_area + ((tileSizeY*BLOCK_SIZE)*(tileSizeX*BLOCK_SIZE))
|
||||||
|
|
||||||
return self.canvas, self.users[element].quad, iquad
|
return self.canvas, self.users[element].quad
|
||||||
else
|
else
|
||||||
print('failed to allocate :X')
|
print('failed to allocate :X')
|
||||||
return false
|
return false
|
||||||
|
|||||||
@ -8,6 +8,8 @@ local helium = require(path .. ".dummy")
|
|||||||
local context = require(path.. ".core.stack")
|
local context = require(path.. ".core.stack")
|
||||||
local scene = require(path.. ".core.scene")
|
local scene = require(path.. ".core.scene")
|
||||||
|
|
||||||
|
local currentCanvasID
|
||||||
|
|
||||||
---@class Element
|
---@class Element
|
||||||
local element = {}
|
local element = {}
|
||||||
element.__index = element
|
element.__index = element
|
||||||
@ -55,6 +57,8 @@ function element:new(param, immediate, w, h, flags)
|
|||||||
immediate = immediate or false,
|
immediate = immediate or false,
|
||||||
--Whether this element has a canvas assigned
|
--Whether this element has a canvas assigned
|
||||||
hasCanvas = false,
|
hasCanvas = false,
|
||||||
|
--Which canvas is it assigned to
|
||||||
|
currentCanvasIndex = nil,
|
||||||
--Current test render passes to be benchmarked
|
--Current test render passes to be benchmarked
|
||||||
testRenderPasses = 20,
|
testRenderPasses = 20,
|
||||||
--
|
--
|
||||||
@ -197,7 +201,7 @@ end
|
|||||||
local newCanvas, newQuad = love.graphics.newCanvas, love.graphics.newQuad
|
local newCanvas, newQuad = love.graphics.newCanvas, love.graphics.newQuad
|
||||||
function element:createCanvas()
|
function element:createCanvas()
|
||||||
|
|
||||||
self.canvas, self.quad = scene.activeScene.atlas:assign(self)
|
self.canvas, self.quad, self.settings.currentCanvasIndex = scene.activeScene.atlas:assign(self)
|
||||||
|
|
||||||
if not self.canvas then
|
if not self.canvas then
|
||||||
self.settings.failedCanvas = true
|
self.settings.failedCanvas = true
|
||||||
@ -291,6 +295,18 @@ function element:externalRender()
|
|||||||
self.settings.isSetup = true
|
self.settings.isSetup = true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local oldCanvasId
|
||||||
|
if self.settings.hasCanvas then
|
||||||
|
if self.settings.currentCanvasIndex == currentCanvasID then
|
||||||
|
--problem lol
|
||||||
|
self.settings.renderingParentCanvasIndex = currentCanvasID
|
||||||
|
self:reassignCanvas()
|
||||||
|
else
|
||||||
|
oldCanvasId = currentCanvasID
|
||||||
|
currentCanvasID = self.settings.currentCanvasIndex
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
if self.settings.needsRendering then
|
if self.settings.needsRendering then
|
||||||
if self.settings.hasCanvas then
|
if self.settings.hasCanvas then
|
||||||
setCanvas(self.canvas)
|
setCanvas(self.canvas)
|
||||||
@ -328,6 +344,7 @@ function element:externalRender()
|
|||||||
|
|
||||||
lg.setScissor()
|
lg.setScissor()
|
||||||
love.graphics.pop()
|
love.graphics.pop()
|
||||||
|
currentCanvasID = oldCanvasId
|
||||||
end
|
end
|
||||||
|
|
||||||
function element:externalUpdate()
|
function element:externalUpdate()
|
||||||
|
|||||||
@ -112,6 +112,9 @@ function context:getCanvasIndex(forCanvas)
|
|||||||
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
|
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
|
||||||
else
|
else
|
||||||
if forCanvas then
|
if forCanvas then
|
||||||
|
if self.element.settings.renderingParentCanvasIndex then
|
||||||
|
return self.element.settings.renderingParentCanvasIndex == 1 and 2 or 1
|
||||||
|
end
|
||||||
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
|
return self.parentCtx:getCanvasIndex() == 1 and 2 or 1
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
@ -21,22 +21,23 @@ local input = require(path.. ".core.input")
|
|||||||
return function(onClick, onRelease, onEnter, onExit, startOn, x, y, w, h)
|
return function(onClick, onRelease, onEnter, onExit, startOn, x, y, w, h)
|
||||||
local checkbox = state {
|
local checkbox = state {
|
||||||
down = false,
|
down = false,
|
||||||
toggled = not not startOn,
|
toggled = false,
|
||||||
over = false,
|
over = false,
|
||||||
}
|
}
|
||||||
|
checkbox.toggled = startOn
|
||||||
input('clicked', function(x, y, w, h)
|
input('clicked', function(x, y, w, h)
|
||||||
|
checkbox.down = true
|
||||||
|
|
||||||
if onClick then
|
if onClick then
|
||||||
onClick(x, y, w, h)
|
onClick(x, y, w, h)
|
||||||
end
|
end
|
||||||
|
|
||||||
checkbox.down = true
|
|
||||||
|
|
||||||
return function(x, y, w, h)
|
return function(x, y, w, h)
|
||||||
if onRelease then
|
|
||||||
onRelease(x, y, w, h)
|
|
||||||
end
|
|
||||||
checkbox.toggled = not checkbox.toggled
|
checkbox.toggled = not checkbox.toggled
|
||||||
checkbox.down = false
|
checkbox.down = false
|
||||||
|
|
||||||
|
if onRelease then
|
||||||
|
onRelease(checkbox.toggled, y, w, h)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user