If you want to use
Screen.DrawText, you have to get the HUD scale first and divide the screen width and height by the X and Y scale factors respectively:
Code: Select all
class OverlayHandler : EventHandler
{
override void RenderOverlay(RenderEvent e)
{
let scale = StatusBar.GetHUDScale();
int w = int(Screen.GetWidth() / scale.X);
int h = int(Screen.GetHeight() / scale.Y);
Screen.DrawText(SmallFont, Font.CR_RED, 0, 0, "Screen.DrawText", DTA_KeepRatio, true, DTA_VirtualWidth, w, DTA_VirtualHeight, h);
}
}
If you want to use
StatusBar.DrawString, you have to call
StatusBar.BeginHUD() first, and also create a
HUDFont instance, which you'll need to do in
RenderOverlay as well:
Code: Select all
class OverlayHandler : EventHandler
{
private ui HUDFont _smallFont;
override void RenderOverlay(RenderEvent e)
{
if (_smallFont == null) _smallFont = HUDFont.Create(SmallFont);
StatusBar.BeginHUD();
StatusBar.DrawString(_smallFont, "StatusBar.DrawString", (0, 0), translation: Font.CR_RED);
}
}
As for which of the two methods to use, I'd probably use
StatusBar.DrawString if I wanted my text to scale along with the HUD automatically, and
Screen.DrawText otherwise. Note that it is generally not a good idea to ignore the user's scaling options except in some special cases (e.g. you want your text to occupy a part of the screen proportional to its total size).