
Trouble with scalable HUDs and preserve aspect ratio option
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!)
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!)
-
Nash
-

- Posts: 17505
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Trouble with scalable HUDs and preserve aspect ratio option
I'm trying to make a status bar that respects the HUD option menu scale settings, it seems what I'm looking for was found in BaseStatusBar :: DrawMyPos so I copied that code and incorporated it into my drawing routines, however there's a problem. When I toggle the "preserve aspect ratio" option, it seems to cut off the graphics, and it doesn't even squash the graphics appopriately as expected. What am I doing wrong?


You do not have the required permissions to view the files attached to this post.
-
Nash
-

- Posts: 17505
- Joined: Mon Oct 27, 2003 12:07 am
- Location: Kuala Lumpur, Malaysia
Re: Trouble with scalable HUDs and preserve aspect ratio opt
No one downloaded the file so here's the relevant part
Really need help with this because I don't see what I'm doing wrong
Code: Select all
class LADHUD : BaseStatusBar
{
HUDFont mHUDFont;
const HUD_WIDTH = 320;
const HUD_HEIGHT = 200;
// how high to offset the compass position
const HUD_COMPASS_POS_Y_ADJUST = 8;
// used to calculate the clipping rectangle
// (+1 to account for shadow)
const HUD_COMPASS_CLIP_WIDTH = 80 + 1;
const HUD_COMPASS_CLIP_HEIGHT = 6;
const barHeight = 0;
bool fullautomap;
override void Init()
{
Super.Init();
SetSize(barHeight, HUD_WIDTH, HUD_HEIGHT);
Font fnt = "SmallFont";
mHUDFont = HUDFont.Create(fnt, fnt.GetCharWidth("0"), true, 1, 1);
}
override void NewGame()
{
if (CPlayer)
{
AttachToPlayer(CPlayer);
}
}
override void Draw(int state, double TicFrac)
{
Super.Draw(state, TicFrac);
if (CPlayer && (state == HUD_StatusBar || state == HUD_Fullscreen))
{
BeginHUD();
// starting clip rectangle
Screen.SetClipRect(0, 0, Screen.GetWidth(), Screen.GetHeight());
DrawCompass();
}
}
}
extend class LADHUD
{
void DrawCompass(void)
{
if (CPlayer && CPlayer.mo)
{
// record old clipping values
int ocx, ocy, ocw, och;
[ocx, ocy, ocw, och] = Screen.GetClipRect();
// setup clipping rectangle
int clipFlags = DI_SCREEN_HCENTER | DI_SCREEN_BOTTOM,
ncx = -(HUD_COMPASS_CLIP_WIDTH / 2),
ncy = -HUD_COMPASS_POS_Y_ADJUST - HUD_COMPASS_CLIP_HEIGHT,
ncw = HUD_COMPASS_CLIP_WIDTH,
nch = HUD_COMPASS_CLIP_HEIGHT;
//Console.Printf("%d/%d/%d/%d", ncx, ncy, ncw, nch);
SetClipRect(ncx, ncy, ncw, nch, clipFlags);
// borrowed from BaseStatusBar :: DrawMyPos
int height = SmallFont.GetHeight();
int vwidth;
int vheight;
int xpos;
int ypos;
let scalevec = GetHUDScale();
double scale = scalevec.X;
vwidth = Screen.GetWidth() / scale;
vheight = Screen.GetHeight() / scale;
xpos = vwidth / 2;
ypos = GetTopOfStatusBar() / scale - (height * 2);
// draw background
double backgroundAlpha = 0.35;
let backgroundTex = TexMan.CheckForTexture("graphics/hud/compass/background.png", TexMan.Type_Any);
if (backgroundTex.IsValid())
{
Screen.DrawTexture(backgroundTex, false, xpos - (HUD_COMPASS_CLIP_WIDTH / 2), ypos,
DTA_VirtualWidth, vwidth,
DTA_VirtualHeight, vheight,
DTA_KeepRatio, true,
DTA_Alpha, backgroundAlpha);
}
// draw center marker on background
LADUI.DrawUITexture(xpos, ypos, "graphics/hud/compass/background-center.png", CPlayer, true, vwidth, vheight, shadowx: 1, shadowy: 0, alpha: backgroundAlpha, textureShadow: true);
// draw foreground
LADUI.DrawUITexture(xpos - (HUD_COMPASS_CLIP_WIDTH / 2), ypos, "graphics/hud/compass/foreground.png", CPlayer, true, vwidth, vheight, shadowx: 1, shadowy: 0, textureShadow: true);
// done with compass, restore old clipping rectangle
Screen.SetClipRect(ocx, ocy, ocw, och);
}
}
}
-
Graf Zahl
- Lead GZDoom+Raze Developer

- Posts: 49252
- Joined: Sat Jul 19, 2003 10:19 am
- Location: Germany
Re: Trouble with scalable HUDs and preserve aspect ratio opt
You really shouldn't mix DrawTexture calls with the status bar drawers. For that one you have to be very careful to match things.
But from the looks of it, it's your clip rect causing the problem. You set that before doing all the coordinate voodoo and it's all constants
But from the looks of it, it's your clip rect causing the problem. You set that before doing all the coordinate voodoo and it's all constants