JC-MP

JC2-MP => Feedback => Bug reports => Topic started by: DaAlpha on November 08, 2020, 09:04:12 pm

Title: Render.GetTextSize is not accurate when using scale
Post by: DaAlpha on November 08, 2020, 09:04:12 pm
Steps to reproduce:

Code: Lua
  1. print(Render:GetTextSize("This should be the same", 16, 1.5))
  2. print(Render:GetTextSize("This should be the same", 16) * 1.5)

Output:
Code: [Select]
20:57:25 | [info ] | [_test] 267.000000, 24.000000
20:57:25 | [info ] | [_test] 259.500000, 24.000000

My global text scale is set to 1.0.

Additional information:

It seems to jump around in steps, as can be seen using this code:

Code: Lua
  1. local scale = 1
  2. local down  = false
  3.  
  4. Events:Subscribe("Render", function(args)
  5.   local delta = args.delta * 0.1
  6.   if down then
  7.     delta = -delta
  8.   end
  9.  
  10.   scale = scale + delta
  11.   if scale <= 0.5 or scale >= 2 then
  12.     down = not down
  13.   end
  14.  
  15.   local fontSize  = 16
  16.   local text      = "Sample Text"
  17.   local textSize1 = Render:GetTextSize(text, fontSize) * scale
  18.   local textSize2 = Render:GetTextSize(text, fontSize, scale)
  19.   local textPos   = Vector2(Render.Width * 0.5, Render.Height * 0.25)
  20.  
  21.   Render:FillArea(textPos, textSize1, Color.White)
  22.   Render:FillArea(textPos, textSize2, Color.Red)
  23.   Render:DrawText(textPos, text, Color.Black, fontSize, scale)
  24.  
  25.   Render:DrawText(textPos - Vector2(0, 18), string.format("Scale: %.3f", scale), Color.White)
  26. end)

(https://alphie.de/temp/r9QRQSu2wk.gif)