Page 1 of 1

Help request with zscript hud scaling

Posted: Fri Jul 23, 2021 4:38 pm
by kevansevans
I'm having scaling issues across various monitors trying to make my HUD look nice. There's not enough documentation for me to solve this, especially on the wiki page itself https://zdoom.org/wiki/Classes:BaseStatusBar

What I would like is some sort of function that can correctly set my HUD's scale so that on every resolution, or whatever scale settings a player has, they should look as similar as possible.

Example of the current problem, this is how my hud looks on my screen: https://imgur.com/a/0SaC7h6
And this is how it looks on someone else's screen: https://imgur.com/a/MRGasD2

Re: Help request with zscript hud scaling

Posted: Tue Aug 10, 2021 8:40 am
by Player701
As far as I'm aware, accounting for the HUD scale works this way: call GetHUDScale() and divide Screen.GetWidth() by the x-component and Screen.GetHeight() by the y-component of the returned value. The resulting values should be assumed as the width and height of the entire screen for HUD drawing purposes. E.g. if you have a 1920x1080 resolution and a HUD scale of 2, then you will assume a size of 960x540. This will make sure your HUD scales correctly when you use absolute values to draw its contents, e.g. a rectangle the size of 10x10 pixels will actually become 20x20 with a HUD scale of 2.

On the other hand, if you want your HUD to always have the same size regardless of the scale, you should use values proportional to the calculated screen size. So if you want a HUD element to fill exactly 10% of the screen's total width, divide the calculated screen height by 10. With a 1920x1080 screen and a HUD scale of 1, the result will be 1920/10 = 192, and with a HUD scale of 2 it will be 960/10 = 96. Both will translate to 192 actual pixels after HUD scaling is applied. You can also forgo the BaseStatusBar drawing methods and use Screen methods directly (so then you can use the screen's actual size via GetWidth() / GetHeight() as the reference size to calculate proportional values).

Note, however, that it may annoy some players when they find out that their HUD does not scale properly, so I wouldn't recommend implementing your HUD that way.