fix: ensure that bar width can't be negative

This commit is contained in:
Kazhnuz 2019-08-15 14:06:20 +02:00
parent 8787eb99e6
commit b58f3d262a

View file

@ -6,7 +6,7 @@ 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[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)
@ -41,12 +41,15 @@ function gui.newBorder(width, height, middlePosition)
end
function gui.drawBar(x, y, width, height)
local height = height or 7
love.graphics.setScissor(x, y, width, height)
love.graphics.draw(barborder, x, y)
love.graphics.rectangle("fill", x+7, y, width-14, height)
love.graphics.draw(barborder, x+width-7, y, 0, -1, -1, 7, 7)
love.graphics.setScissor( )
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