Skip to content

Commit

Permalink
HUD scaling via triangle API
Browse files Browse the repository at this point in the history
  • Loading branch information
Toodles2You committed Oct 8, 2024
1 parent e760b9f commit 1fa21e5
Show file tree
Hide file tree
Showing 20 changed files with 523 additions and 73 deletions.
20 changes: 10 additions & 10 deletions cl_dll/ammo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,11 +73,11 @@ void WeaponsResource::LoadWeaponSprites(WEAPON* pWeapon)
{
int i, iRes;

if (ScreenWidth > 2560 && ScreenHeight > 1600)
if (gHUD.GetWidth() > 2560 && gHUD.GetHeight() > 1600)
iRes = 2560;
else if (ScreenWidth >= 1280 && ScreenHeight > 720)
else if (gHUD.GetWidth() >= 1280 && gHUD.GetHeight() > 720)
iRes = 1280;
else if (ScreenWidth >= 640)
else if (gHUD.GetWidth() >= 640)
iRes = 640;
else
iRes = 320;
Expand Down Expand Up @@ -329,11 +329,11 @@ bool CHudAmmo::VidInit()

int nScale = 1;

if (ScreenWidth > 2560 && ScreenHeight > 1600)
if (gHUD.GetWidth() > 2560 && gHUD.GetHeight() > 1600)
nScale = 4;
else if (ScreenWidth >= 1280 && ScreenHeight > 720)
else if (gHUD.GetWidth() >= 1280 && gHUD.GetHeight() > 720)
nScale = 3;
else if (ScreenWidth >= 640)
else if (gHUD.GetWidth() >= 640)
nScale = 2;

giABWidth = 10 * nScale;
Expand Down Expand Up @@ -894,7 +894,7 @@ bool CHudAmmo::Draw(float flTime)

ScaleColors(r, g, b, a);

y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
y = gHUD.GetHeight() - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
y += (int)(gHUD.m_iFontHeight * 0.2f);

// Does weapon have any ammo at all?
Expand All @@ -906,7 +906,7 @@ bool CHudAmmo::Draw(float flTime)
{
// room for the number and the '|' and the current ammo

x = ScreenWidth - (8 * AmmoWidth) - iIconWidth;
x = gHUD.GetWidth() - (8 * AmmoWidth) - iIconWidth;
x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, pw->iClip, r, g, b);

Rect rc;
Expand All @@ -933,7 +933,7 @@ bool CHudAmmo::Draw(float flTime)
else
{
// SPR_Draw a bullets only line
x = ScreenWidth - 4 * AmmoWidth - iIconWidth;
x = gHUD.GetWidth() - 4 * AmmoWidth - iIconWidth;
x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo(pw->iAmmoType), r, g, b);
}

Expand All @@ -952,7 +952,7 @@ bool CHudAmmo::Draw(float flTime)
if ((pw->iAmmo2Type != 0) && (gWR.CountAmmo(pw->iAmmo2Type) > 0))
{
y -= gHUD.m_iFontHeight + gHUD.m_iFontHeight / 4;
x = ScreenWidth - 4 * AmmoWidth - iIconWidth;
x = gHUD.GetWidth() - 4 * AmmoWidth - iIconWidth;
x = gHUD.DrawHudNumber(x, y, iFlags | DHN_3DIGITS, gWR.CountAmmo(pw->iAmmo2Type), r, g, b);

// Draw the ammo Icon
Expand Down
4 changes: 2 additions & 2 deletions cl_dll/ammo_secondary.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,8 +68,8 @@ bool CHudAmmoSecondary::Draw(float flTime)

AmmoWidth = gHUD.GetSpriteRect(gHUD.m_HUD_number_0).right - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).left;

y = ScreenHeight - (gHUD.m_iFontHeight * 4); // this is one font height higher than the weapon ammo values
x = ScreenWidth - AmmoWidth;
y = gHUD.GetHeight() - (gHUD.m_iFontHeight * 4); // this is one font height higher than the weapon ammo values
x = gHUD.GetWidth() - AmmoWidth;

if (0 != m_HUD_ammoicon)
{
Expand Down
14 changes: 7 additions & 7 deletions cl_dll/ammohistory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ HistoryResource gHR;

#define AMMO_PICKUP_GAP (gHR.iHistoryGap + 5)
#define AMMO_PICKUP_PICK_HEIGHT (32 + (gHR.iHistoryGap * 2))
#define AMMO_PICKUP_HEIGHT_MAX (ScreenHeight - 100)
#define AMMO_PICKUP_HEIGHT_MAX (gHUD.GetHeight() - 100)

#define MAX_ITEM_NAME 32
int HISTORY_DRAW_TIME = 5;
Expand Down Expand Up @@ -129,8 +129,8 @@ bool HistoryResource::DrawAmmoHistory(float flTime)
ScaleColors(r, g, b, V_min(scale, 255));

// Draw the pic
int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i));
int xpos = ScreenWidth - (rcPic.right - rcPic.left) - 4;
int ypos = gHUD.GetHeight() - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i));
int xpos = gHUD.GetWidth() - (rcPic.right - rcPic.left) - 4;
if (spr && 0 != *spr) // weapon isn't loaded yet so just don't draw the pic
{ // the dll has to make sure it has sent info the weapons you need
SPR_Set(*spr, r, g, b);
Expand All @@ -156,8 +156,8 @@ bool HistoryResource::DrawAmmoHistory(float flTime)
float scale = (rgAmmoHistory[i].DisplayTime - flTime) * 80;
ScaleColors(r, g, b, V_min(scale, 255));

int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i));
int xpos = ScreenWidth - (weap->rcInactive.right - weap->rcInactive.left);
int ypos = gHUD.GetHeight() - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i));
int xpos = gHUD.GetWidth() - (weap->rcInactive.right - weap->rcInactive.left);
SPR_Set(weap->hInactive, r, g, b);
SPR_DrawAdditive(0, xpos, ypos, &weap->rcInactive);
}
Expand All @@ -174,8 +174,8 @@ bool HistoryResource::DrawAmmoHistory(float flTime)
float scale = (rgAmmoHistory[i].DisplayTime - flTime) * 80;
ScaleColors(r, g, b, V_min(scale, 255));

int ypos = ScreenHeight - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i));
int xpos = ScreenWidth - (rect.right - rect.left) - 10;
int ypos = gHUD.GetHeight() - (AMMO_PICKUP_PICK_HEIGHT + (AMMO_PICKUP_GAP * i));
int xpos = gHUD.GetWidth() - (rect.right - rect.left) - 10;

SPR_Set(gHUD.GetSprite(rgAmmoHistory[i].iId), r, g, b);
SPR_DrawAdditive(0, xpos, ypos, &rect);
Expand Down
4 changes: 2 additions & 2 deletions cl_dll/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ bool CHudBattery::Draw(float flTime)

int iOffset = (m_prc1->bottom - m_prc1->top) / 6;

y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
y = gHUD.GetHeight() - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;

int width = (m_prc1->right - m_prc1->left);

// this used to just be ScreenWidth/5 (4 on Updated) but that caused real issues at higher resolutions. Instead, base it on the width of this sprite.
// this used to just be gHUD.GetWidth()/5 (4 on Updated) but that caused real issues at higher resolutions. Instead, base it on the width of this sprite.
x = 3 * width;

// make sure we have the right sprite handles
Expand Down
4 changes: 4 additions & 0 deletions cl_dll/cdll_int.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@ void InitInput();
void EV_HookEvents();
void IN_Commands();

void CL_DrawCrosshair();

/*
================================
HUD_GetHullBounds
Expand Down Expand Up @@ -208,6 +210,8 @@ int DLLEXPORT HUD_Redraw(float time, int intermission)
{
// RecClHudRedraw(time, intermission);

CL_DrawCrosshair();

gHUD.Redraw(time, 0 != intermission);

return 1;
Expand Down
26 changes: 11 additions & 15 deletions cl_dll/cl_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,24 +44,23 @@ inline const char* CVAR_GET_STRING(const char* x) { return gEngfuncs.pfnGetCvarS
inline struct cvar_s* CVAR_CREATE(const char* cv, const char* val, const int flags) { return gEngfuncs.pfnRegisterVariable((char*)cv, (char*)val, flags); }

#define SPR_Load (*gEngfuncs.pfnSPR_Load)
#define SPR_Set (*gEngfuncs.pfnSPR_Set)
void SPR_Set(HSPRITE hPic, int r, int g, int b);
#define SPR_Frames (*gEngfuncs.pfnSPR_Frames)
#define SPR_GetList (*gEngfuncs.pfnSPR_GetList)

// SPR_Draw draws a the current sprite as solid
#define SPR_Draw (*gEngfuncs.pfnSPR_Draw)
void SPR_Draw(int frame, int x, int y, const Rect* prc);
// SPR_DrawHoles draws the current sprites, with color index255 not drawn (transparent)
#define SPR_DrawHoles (*gEngfuncs.pfnSPR_DrawHoles)
void SPR_DrawHoles(int frame, int x, int y, const Rect* prc);
// SPR_DrawAdditive adds the sprites RGB values to the background (additive transulency)
#define SPR_DrawAdditive (*gEngfuncs.pfnSPR_DrawAdditive)
void SPR_DrawAdditive(int frame, int x, int y, const Rect* prc);

// SPR_EnableScissor sets a clipping rect for HUD sprites. (0,0) is the top-left hand corner of the screen.
#define SPR_EnableScissor (*gEngfuncs.pfnSPR_EnableScissor)
// SPR_DisableScissor disables the clipping rect
#define SPR_DisableScissor (*gEngfuncs.pfnSPR_DisableScissor)
//
#define FillRGBA (*gEngfuncs.pfnFillRGBA)

void FillRGBA(int x, int y, int width, int height, int r, int g, int b, int a);

// ScreenHeight returns the height of the screen, in pixels
#define ScreenHeight (gHUD.m_scrinfo.iHeight)
Expand All @@ -83,7 +82,7 @@ inline struct cvar_s* CVAR_CREATE(const char* cv, const char* val, const int fla
#define ServerCmd (*gEngfuncs.pfnServerCmd)
#define EngineClientCmd (*gEngfuncs.pfnClientCmd)
#define EngineFilteredClientCmd (*gEngfuncs.pfnFilteredClientCmd)
#define SetCrosshair (*gEngfuncs.pfnSetCrosshair)
void SetCrosshair(HSPRITE hspr, Rect rc, int r, int g, int b);
#define AngleVectors (*gEngfuncs.pfnAngleVectors)


Expand All @@ -97,15 +96,9 @@ inline int TextMessageDrawChar(int x, int y, int number, int r, int g, int b)
return gEngfuncs.pfnDrawCharacter(x, y, number, r, g, b);
}

inline int DrawConsoleString(int x, int y, const char* string)
{
return gEngfuncs.pfnDrawConsoleString(x, y, (char*)string);
}
int DrawConsoleString(int x, int y, const char* string);

inline void GetConsoleStringSize(const char* string, int* width, int* height)
{
gEngfuncs.pfnDrawConsoleStringLen(string, width, height);
}
void GetConsoleStringSize(const char* string, int* width, int* height);

inline int ConsoleStringLen(const char* string)
{
Expand All @@ -124,6 +117,9 @@ inline void CenterPrint(const char* string)
gEngfuncs.pfnCenterPrint(string);
}

int DrawString(int x, int y, const char* str, int r, int g, int b);

int DrawStringReverse(int x, int y, const char* str, int r, int g, int b);

inline char* safe_strcpy(char* dst, const char* src, int len_dst)
{
Expand Down
2 changes: 1 addition & 1 deletion cl_dll/death.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ bool CHudDeathNotice::Draw(float flTime)
texty = y + 4;

int id = (rgDeathNoticeList[i].iId == -1) ? m_HUD_d_skull : rgDeathNoticeList[i].iId;
x = ScreenWidth - ConsoleStringLen(rgDeathNoticeList[i].szVictim) - (gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left) - 4;
x = gHUD.GetWidth() - ConsoleStringLen(rgDeathNoticeList[i].szVictim) - (gHUD.GetSpriteRect(id).right - gHUD.GetSpriteRect(id).left) - 4;

if (!rgDeathNoticeList[i].iSuicide)
{
Expand Down
6 changes: 3 additions & 3 deletions cl_dll/flashlight.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -118,22 +118,22 @@ bool CHudFlashlight::Draw(float flTime)
ScaleColors(r, g, b, a);

y = (m_prc1->bottom - m_prc2->top) / 2;
x = ScreenWidth - m_iWidth - m_iWidth / 2;
x = gHUD.GetWidth() - m_iWidth - m_iWidth / 2;

// Draw the flashlight casing
SPR_Set(m_hSprite1, r, g, b);
SPR_DrawAdditive(0, x, y, m_prc1);

if (m_fOn)
{ // draw the flashlight beam
x = ScreenWidth - m_iWidth / 2;
x = gHUD.GetWidth() - m_iWidth / 2;

SPR_Set(m_hBeam, r, g, b);
SPR_DrawAdditive(0, x, y, m_prcBeam);
}

// draw the flashlight energy level
x = ScreenWidth - m_iWidth - m_iWidth / 2;
x = gHUD.GetWidth() - m_iWidth - m_iWidth / 2;
int iOffset = m_iWidth * (1.0 - m_flBat);
if (iOffset < m_iWidth)
{
Expand Down
20 changes: 10 additions & 10 deletions cl_dll/health.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ bool CHudHealth::Draw(float flTime)
HealthWidth = gHUD.GetSpriteRect(gHUD.m_HUD_number_0).right - gHUD.GetSpriteRect(gHUD.m_HUD_number_0).left;
int CrossWidth = gHUD.GetSpriteRect(m_HUD_cross).right - gHUD.GetSpriteRect(m_HUD_cross).left;

y = ScreenHeight - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
y = gHUD.GetHeight() - gHUD.m_iFontHeight - gHUD.m_iFontHeight / 2;
x = CrossWidth / 2;

SPR_Set(gHUD.GetSprite(m_HUD_cross), r, g, b);
Expand Down Expand Up @@ -315,8 +315,8 @@ bool CHudHealth::DrawPain(float flTime)
ScaleColors(r, g, b, shade);
SPR_Set(m_hSprite, r, g, b);

x = ScreenWidth / 2 - SPR_Width(m_hSprite, 0) / 2;
y = ScreenHeight / 2 - SPR_Height(m_hSprite, 0) * 3;
x = gHUD.GetWidth() / 2 - SPR_Width(m_hSprite, 0) / 2;
y = gHUD.GetHeight() / 2 - SPR_Height(m_hSprite, 0) * 3;
SPR_DrawAdditive(0, x, y, NULL);
m_fAttackFront = V_max(0.0f, m_fAttackFront - fFade);
}
Expand All @@ -330,8 +330,8 @@ bool CHudHealth::DrawPain(float flTime)
ScaleColors(r, g, b, shade);
SPR_Set(m_hSprite, r, g, b);

x = ScreenWidth / 2 + SPR_Width(m_hSprite, 1) * 2;
y = ScreenHeight / 2 - SPR_Height(m_hSprite, 1) / 2;
x = gHUD.GetWidth() / 2 + SPR_Width(m_hSprite, 1) * 2;
y = gHUD.GetHeight() / 2 - SPR_Height(m_hSprite, 1) / 2;
SPR_DrawAdditive(1, x, y, NULL);
m_fAttackRight = V_max(0.0f, m_fAttackRight - fFade);
}
Expand All @@ -345,8 +345,8 @@ bool CHudHealth::DrawPain(float flTime)
ScaleColors(r, g, b, shade);
SPR_Set(m_hSprite, r, g, b);

x = ScreenWidth / 2 - SPR_Width(m_hSprite, 2) / 2;
y = ScreenHeight / 2 + SPR_Height(m_hSprite, 2) * 2;
x = gHUD.GetWidth() / 2 - SPR_Width(m_hSprite, 2) / 2;
y = gHUD.GetHeight() / 2 + SPR_Height(m_hSprite, 2) * 2;
SPR_DrawAdditive(2, x, y, NULL);
m_fAttackRear = V_max(0.0f, m_fAttackRear - fFade);
}
Expand All @@ -360,8 +360,8 @@ bool CHudHealth::DrawPain(float flTime)
ScaleColors(r, g, b, shade);
SPR_Set(m_hSprite, r, g, b);

x = ScreenWidth / 2 - SPR_Width(m_hSprite, 3) * 3;
y = ScreenHeight / 2 - SPR_Height(m_hSprite, 3) / 2;
x = gHUD.GetWidth() / 2 - SPR_Width(m_hSprite, 3) * 3;
y = gHUD.GetHeight() / 2 - SPR_Height(m_hSprite, 3) / 2;
SPR_DrawAdditive(3, x, y, NULL);

m_fAttackLeft = V_max(0.0f, m_fAttackLeft - fFade);
Expand Down Expand Up @@ -457,7 +457,7 @@ void CHudHealth::UpdateTiles(float flTime, long bitsDamage)
{
// put this one at the bottom
pdmg->x = giDmgWidth / 8;
pdmg->y = ScreenHeight - giDmgHeight * 2;
pdmg->y = gHUD.GetHeight() - giDmgHeight * 2;
pdmg->fExpire = flTime + DMG_IMAGE_LIFE;

// move everyone else up
Expand Down
Loading

0 comments on commit 1fa21e5

Please sign in to comment.