55 lines
1.6 KiB
Lua
55 lines
1.6 KiB
Lua
local gui = {}
|
|
|
|
local barborder = love.graphics.newImage("assets/gui/barborder.png")
|
|
|
|
function gui.newBorder(width, height, middlePosition)
|
|
local tileset = love.graphics.newImage("assets/gui/borders.png")
|
|
local tilequad = {}
|
|
local w, h = tileset:getDimensions()
|
|
tilequad[1] = love.graphics.newQuad(0, 0, 20, 20, w, h)
|
|
tilequad[2] = love.graphics.newQuad(20, 0, 20, 20, w, h)
|
|
tilequad[3] = love.graphics.newQuad(40, 0, 20, 20, w, h)
|
|
tilequad[4] = love.graphics.newQuad(60, 0, 20, 20, w, h)
|
|
|
|
local Texture = love.graphics.newCanvas(width, height)
|
|
|
|
love.graphics.setCanvas(Texture)
|
|
utils.graphics.resetColor()
|
|
|
|
local height = math.ceil(height / 20)
|
|
local width = math.ceil(width / 20)
|
|
|
|
for i=1, width do
|
|
if i < middlePosition then
|
|
love.graphics.draw(tileset, tilequad[1], (i-1) * 20, 0)
|
|
elseif (i == middlePosition) then
|
|
love.graphics.draw(tileset, tilequad[2], (i-1) * 20, 0)
|
|
else
|
|
love.graphics.draw(tileset, tilequad[3], (i-1) * 20, 0)
|
|
end
|
|
|
|
if height > 1 then
|
|
for j = 2, height do
|
|
love.graphics.draw(tileset, tilequad[4], (i-1) * 20, (j-1) * 20)
|
|
end
|
|
end
|
|
end
|
|
|
|
love.graphics.setCanvas( )
|
|
|
|
return Texture
|
|
end
|
|
|
|
function gui.drawBar(x, y, width, height)
|
|
if (width > 0) then
|
|
local height = height or 7
|
|
love.graphics.setScissor(x, y, width, height)
|
|
love.graphics.draw(barborder, x, y)
|
|
local barwidth = math.max(width-14, 0)
|
|
love.graphics.rectangle("fill", x+7, y, barwidth, height)
|
|
love.graphics.draw(barborder, x+width-7, y, 0, -1, -1, 7, 7)
|
|
love.graphics.setScissor( )
|
|
end
|
|
end
|
|
|
|
return gui
|