Finds visual height of a character(-s). May be very helpful when positioning text by height. Supports newlines.
local font = 'DermaLarge'
local char = 'a'
local visH, emptySpace = surface.GetVisualCharacterHeight( char, font )
hook.Add( 'HUDPaint', '', function()
surface.SetFont( font )
local w, h = surface.GetTextSize( char )
local x = ScrW() * 0.5 - w * 0.5 - 5
local y = ScrH() * 0.5
surface.SetDrawColor( 255, 180, 180 )
surface.DrawRect( x, y, w, h )
draw.SimpleText( char, font, x, y, color_black )
x = ScrW() * 0.5 + 5 + w * 0.5
surface.SetDrawColor( 180, 255, 180 )
surface.DrawRect( x, y, w, visH )
y = y - emptySpace
draw.SimpleText( char, font, x, y, color_black )
end )
Also, works with newlines
local font = 'DermaLarge'
local char = 'a\nb'
local visH, emptySpace = surface.GetVisualCharacterHeight( char, font )
hook.Add( 'HUDPaint', '', function()
surface.SetFont( font )
local w, h = surface.GetTextSize( char )
local x = ScrW() * 0.5 - w * 0.5 - 5
local y = ScrH() * 0.5
surface.SetDrawColor( 255, 180, 180 )
surface.DrawRect( x, y, w, h )
draw.DrawText( char, font, x, y, color_black )
x = ScrW() * 0.5 + 5 + w * 0.5
surface.SetDrawColor( 180, 255, 180 )
surface.DrawRect( x, y, w, visH )
y = y - emptySpace
draw.DrawText( char, font, x, y, color_black )
end )