Help request with zscript hud scaling

Ask about ACS, DECORATE, ZScript, or any other scripting questions here!

Moderator: GZDoom Developers

Forum rules
Before asking on how to use a ZDoom feature, read the ZDoom wiki first. If you still don't understand how to use a feature, then ask here.

Please bear in mind that the people helping you do not automatically know how much you know. You may be asked to upload your project file to look at. Don't be afraid to ask questions about what things mean, but also please be patient with the people trying to help you. (And helpers, please be patient with the person you're trying to help!)
Post Reply
User avatar
kevansevans
Spotlight Team
Posts: 420
Joined: Tue Oct 05, 2010 12:04 am
Graphics Processor: nVidia with Vulkan support
Contact:

Help request with zscript hud scaling

Post 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
User avatar
Player701
 
 
Posts: 1640
Joined: Wed May 13, 2009 3:15 am
Graphics Processor: nVidia with Vulkan support
Contact:

Re: Help request with zscript hud scaling

Post 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.
Post Reply

Return to “Scripting”