proper font scaling

This commit is contained in:
jill 2021-09-19 22:36:33 +03:00
parent d150205535
commit 756bbfdc99
5 changed files with 26 additions and 17 deletions

Binary file not shown.

View file

@ -4,7 +4,19 @@ for k, v in pairs(_G) do
end end
love.graphics.setDefaultFilter('nearest', 'nearest') love.graphics.setDefaultFilter('nearest', 'nearest')
interfaceFont = love.graphics.newFont('assets/fonts/Inter-Regular.otf', 20)
local fontSize = 20
interfaceFont = love.graphics.newFont('assets/fonts/Inter-Regular.otf', fontSize)
local fontCache = {}
function getFont(size, italic)
if fontCache[size] and fontCache[size][italic] then return fontCache[size][italic] end
fontCache[size] = fontCache[size] or {}
fontCache[size][italic] = love.graphics.newFont('assets/fonts/Inter-' .. (italic and 'Italic' or 'Regular') .. '.otf', math.floor(fontSize * size))
return fontCache[size][italic]
end
ease = require 'src.ease' ease = require 'src.ease'

View file

@ -281,13 +281,10 @@ function self.render()
str = str .. ' ' .. string.sub(p.name, 1, 1) str = str .. ' ' .. string.sub(p.name, 1, 1)
end end
love.graphics.push() love.graphics.setFont(getFont(0.8, true))
love.graphics.translate(x + w, y + lineWidth/2)
love.graphics.shear(-0.2, 0)
love.graphics.scale(0.8, 0.8)
love.graphics.setColor(0.8, 0.8, 1, 0.8 * a) love.graphics.setColor(0.8, 0.8, 1, 0.8 * a)
love.graphics.printf(str, -w, -lineWidth/2, w - 2, 'right') love.graphics.printf(str, x, y, w - 2, 'right')
love.graphics.pop() love.graphics.setFont(interfaceFont)
end end
::continue:: ::continue::

View file

@ -77,7 +77,7 @@ function self.createSliders()
for i,v in ipairs(param1) do for i,v in ipairs(param1) do
insertSlider(s, { insertSlider(s, {
x = outerpadding + dropdownWidth + padding, x = outerpadding + dropdownWidth + padding,
y = outerpadding + (fontHeight * 2.5 + padding) * i, y = outerpadding + (fontHeight * 3 + padding) * i - padding,
width = dropdownWidth, width = dropdownWidth,
min = v.min, min = v.min,
max = v.max, max = v.max,
@ -92,7 +92,7 @@ function self.createSliders()
for i,v in ipairs(param2) do for i,v in ipairs(param2) do
insertSlider(s, { insertSlider(s, {
x = outerpadding + dropdownWidth + padding + dropdownWidth + padding, x = outerpadding + dropdownWidth + padding + dropdownWidth + padding,
y = outerpadding + (fontHeight * 2.5 + padding) * i, y = outerpadding + (fontHeight * 3 + padding) * i - padding,
width = dropdownWidth, width = dropdownWidth,
min = v.min, min = v.min,
max = v.max, max = v.max,
@ -172,11 +172,9 @@ function self.render()
if v.topdisplayname then if v.topdisplayname then
love.graphics.setColor(0.4, 0.4, 0.55, 1) love.graphics.setColor(0.4, 0.4, 0.55, 1)
love.graphics.push() love.graphics.setFont(getFont(0.75, true))
love.graphics.translate(v.x, v.y - ssize * 1.4) love.graphics.printf(v.topdisplayname, v.x - ssize * 6, v.y - ssize * 1.45, ssize * 12, 'center')
love.graphics.scale(0.75, 0.75) love.graphics.setFont(interfaceFont)
love.graphics.printf(v.topdisplayname, -ssize * 6, 0, ssize * 12, 'center')
love.graphics.pop()
end end
if dragging then if dragging then

View file

@ -44,10 +44,10 @@ function self.render()
if tooltipwidth > 1 then if tooltipwidth > 1 then
local a = math.min((tooltipwidth - 1) / 6, 1) local a = math.min((tooltipwidth - 1) / 6, 1)
local x, y, w, h = mx + 8, my + 8, (tooltipwidth + 4 + margin), (fontHeight + margin) local x, y, w, h = mx + 8, my + 8, (tooltipwidth + 4 + margin) * 0.8, (fontHeight + margin) * 0.8
local easiness = 3 -- hehe. magic numbers local easiness = 3 -- hehe. magic numbers
local scale = 0.8 local scale = 1
local sx, sy = ((w - softlimit(mx - tooltipx, w/easiness)/easiness) / w) * scale, ((h - softlimit(my - tooltipy, h/easiness)/easiness) / h) * scale local sx, sy = ((w - softlimit(mx - tooltipx, w/easiness)/easiness) / w) * scale, ((h - softlimit(my - tooltipy, h/easiness)/easiness) / h) * scale
love.graphics.push() love.graphics.push()
@ -61,7 +61,9 @@ function self.render()
love.graphics.setScissor(0, 0, math.max(mx + (tooltipwidth + 2 + margin/2 + 16) * sx, 0), love.graphics.getHeight()) love.graphics.setScissor(0, 0, math.max(mx + (tooltipwidth + 2 + margin/2 + 16) * sx, 0), love.graphics.getHeight())
love.graphics.setColor(1, 1, 1, a) love.graphics.setColor(1, 1, 1, a)
love.graphics.print(tooltiptext, 2 + margin/2, 2 + margin/2) love.graphics.setFont(getFont(0.8, false))
love.graphics.print(tooltiptext, 2, 2)
love.graphics.setFont(interfaceFont)
love.graphics.setScissor() love.graphics.setScissor()