From 447f46c1710f507622306a338cc8c82b1ce3aa5c Mon Sep 17 00:00:00 2001 From: ubq323 Date: Mon, 20 Feb 2023 15:51:29 +0000 Subject: center some ui elements better --- client/util.lua | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) (limited to 'client/util.lua') diff --git a/client/util.lua b/client/util.lua index 8a18b96..efeac31 100644 --- a/client/util.lua +++ b/client/util.lua @@ -1,17 +1,18 @@ local font = love.graphics.getFont() local text = love.graphics.newText(font) -local function print_good(lines,x,y) - if type(lines) ~= "table" then lines = {lines} end - for _,line in ipairs(lines) do - text:set(line) - local w,h = text:getDimensions() - love.graphics.setColor(0,0,0,0.8) - love.graphics.rectangle("fill",x,y,w,h) - love.graphics.setColor(1,1,1) - love.graphics.draw(text,x,y) - y = y + h - end +local function print_good(str,x,y) + text:set(str) + local w,h = text:getDimensions() + local W,H = love.graphics.getDimensions() + if x == "center" then x = (W/2)-(w/2) end + if y == "center" then y = (H/2)-(h/2) end + if x < 0 then x = W-w-(-x)+1 end + if y < 0 then y = H-h-(-y)+1 end + love.graphics.setColor(0,0,0,0.8) + love.graphics.rectangle("fill",x,y,w,h) + love.graphics.setColor(1,1,1) + love.graphics.draw(text,x,y) end return { -- cgit v1.2.3