Skip to content

Commit

Permalink
Apply patch for Flexible HUD r2
Browse files Browse the repository at this point in the history
This didn't originally get checked into git.

ztm-flexible-hud-r2.pk3/flexible_hud_r2.diff : August 30 2014 10:17pm
  • Loading branch information
zturtleman committed Mar 31, 2024
1 parent c621589 commit b6e5bd0
Show file tree
Hide file tree
Showing 8 changed files with 361 additions and 39 deletions.
168 changes: 151 additions & 17 deletions code/cgame/cg_draw.c

Large diffs are not rendered by default.

86 changes: 84 additions & 2 deletions code/cgame/cg_drawtools.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,56 @@ Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
// cg_drawtools.c -- helper functions called by cg_draw, cg_scoreboard, cg_info, etc
#include "cg_local.h"

static screenPlacement_e cg_horizontalPlacement = PLACE_CENTER;
static screenPlacement_e cg_verticalPlacement = PLACE_CENTER;
static screenPlacement_e cg_lastHorizontalPlacement = PLACE_CENTER;
static screenPlacement_e cg_lastVerticalPlacement = PLACE_CENTER;

/*
================
CG_SetScreenPlacement
================
*/
void CG_SetScreenPlacement(screenPlacement_e hpos, screenPlacement_e vpos)
{
cg_lastHorizontalPlacement = cg_horizontalPlacement;
cg_lastVerticalPlacement = cg_verticalPlacement;

cg_horizontalPlacement = hpos;
cg_verticalPlacement = vpos;
}

/*
================
CG_PopScreenPlacement
================
*/
void CG_PopScreenPlacement(void)
{
cg_horizontalPlacement = cg_lastHorizontalPlacement;
cg_verticalPlacement = cg_lastVerticalPlacement;
}

/*
================
CG_GetScreenHorizontalPlacement
================
*/
screenPlacement_e CG_GetScreenHorizontalPlacement(void)
{
return cg_horizontalPlacement;
}

/*
================
CG_GetScreenVerticalPlacement
================
*/
screenPlacement_e CG_GetScreenVerticalPlacement(void)
{
return cg_verticalPlacement;
}

/*
================
CG_AdjustFrom640
Expand All @@ -31,6 +81,7 @@ Adjusted for resolution and screen aspect ratio
================
*/
void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
#if 0
#if 0
// adjust for wide screens
if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) {
Expand All @@ -42,6 +93,37 @@ void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
*y *= cgs.screenYScale;
*w *= cgs.screenXScale;
*h *= cgs.screenYScale;
#endif

if (cg_horizontalPlacement == PLACE_STRETCH || cg_stretch.integer) {
// scale for screen sizes (not aspect correct in wide screen)
*w *= cgs.screenXScaleStretch;
*x *= cgs.screenXScaleStretch;
} else {
// scale for screen sizes
*w *= cgs.screenXScale;
*x *= cgs.screenXScale;

if (cg_horizontalPlacement == PLACE_CENTER) {
*x += cgs.screenXBias;
} else if (cg_horizontalPlacement == PLACE_RIGHT) {
*x += cgs.screenXBias*2;
}
}

if (cg_verticalPlacement == PLACE_STRETCH || cg_stretch.integer) {
*h *= cgs.screenYScaleStretch;
*y *= cgs.screenYScaleStretch;
} else {
*h *= cgs.screenYScale;
*y *= cgs.screenYScale;

if (cg_verticalPlacement == PLACE_CENTER) {
*y += cgs.screenYBias;
} else if (cg_verticalPlacement == PLACE_BOTTOM) {
*y += cgs.screenYBias*2;
}
}
}

/*
Expand Down Expand Up @@ -604,7 +686,7 @@ static void UI_DrawBannerString2( int x, int y, const char* str, vec4_t color )
trap_R_SetColor( color );

ax = x * cgs.screenXScale + cgs.screenXBias;
ay = y * cgs.screenYScale;
ay = y * cgs.screenYScale + cgs.screenYBias;

s = str;
while ( *s )
Expand Down Expand Up @@ -714,7 +796,7 @@ static void UI_DrawProportionalString2( int x, int y, const char* str, vec4_t co
trap_R_SetColor( color );

ax = x * cgs.screenXScale + cgs.screenXBias;
ay = y * cgs.screenYScale;
ay = y * cgs.screenYScale + cgs.screenYBias;

s = str;
while ( *s )
Expand Down
2 changes: 1 addition & 1 deletion code/cgame/cg_info.c
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ void CG_DrawInformation( void ) {
levelshot = trap_R_RegisterShaderNoMip( "menu/art/unknownmap" );
}
trap_R_SetColor( NULL );
CG_DrawPic( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, levelshot );
trap_R_DrawStretchPic( 0, 0, cgs.glconfig.vidWidth, cgs.glconfig.vidHeight, 0, 0, 1, 1, levelshot );

// blend a detail texture over it
detail = trap_R_RegisterShader( "levelShotDetail" );
Expand Down
30 changes: 30 additions & 0 deletions code/cgame/cg_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ typedef struct {
// view rendering
refdef_t refdef;
vec3_t refdefViewAngles; // will be converted to refdef.viewaxis
float fov; // either range checked cg_fov or forced value

// zoom key
qboolean zoomed;
Expand Down Expand Up @@ -999,6 +1000,10 @@ typedef struct {
float screenXScale; // derived from glconfig
float screenYScale;
float screenXBias;
float screenYBias;
float screenXScaleStretch;
float screenYScaleStretch;


int serverCommandSequence; // reliable command stream counter
int processedSnapshotNum;// the number of snapshots cgame has requested
Expand Down Expand Up @@ -1106,6 +1111,14 @@ extern vmCvar_t cg_drawCrosshair;
extern vmCvar_t cg_drawCrosshairNames;
extern vmCvar_t cg_drawRewards;
extern vmCvar_t cg_drawTeamOverlay;
extern vmCvar_t cg_drawScores;
extern vmCvar_t cg_drawPickups;
extern vmCvar_t cg_drawWeaponBar;
extern vmCvar_t cg_drawStatusHead;
extern vmCvar_t cg_statusScale;
extern vmCvar_t cg_fovAspectAdjust;
extern vmCvar_t cg_fovGunAdjust;
extern vmCvar_t cg_stretch;
extern vmCvar_t cg_teamOverlayUserinfo;
extern vmCvar_t cg_crosshairX;
extern vmCvar_t cg_crosshairY;
Expand Down Expand Up @@ -1237,6 +1250,23 @@ void CG_DrawActiveFrame( int serverTime, stereoFrame_t stereoView, qboolean demo
//
// cg_drawtools.c
//
typedef enum {
PLACE_STRETCH,
PLACE_CENTER,

// horizontal only
PLACE_LEFT,
PLACE_RIGHT,

// vertical only
PLACE_TOP,
PLACE_BOTTOM
} screenPlacement_e;

void CG_SetScreenPlacement(screenPlacement_e hpos, screenPlacement_e vpos);
void CG_PopScreenPlacement(void);
screenPlacement_e CG_GetScreenHorizontalPlacement(void);
screenPlacement_e CG_GetScreenVerticalPlacement(void);
void CG_AdjustFrom640( float *x, float *y, float *w, float *h );
void CG_FillRect( float x, float y, float width, float height, const float *color );
void CG_DrawPic( float x, float y, float width, float height, qhandle_t hShader );
Expand Down
40 changes: 38 additions & 2 deletions code/cgame/cg_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,14 @@ vmCvar_t cg_drawAmmoWarning;
vmCvar_t cg_drawCrosshair;
vmCvar_t cg_drawCrosshairNames;
vmCvar_t cg_drawRewards;
vmCvar_t cg_drawScores;
vmCvar_t cg_drawPickups;
vmCvar_t cg_drawWeaponBar;
vmCvar_t cg_drawStatusHead;
vmCvar_t cg_statusScale;
vmCvar_t cg_fovAspectAdjust;
vmCvar_t cg_fovGunAdjust;
vmCvar_t cg_stretch;
vmCvar_t cg_crosshairSize;
vmCvar_t cg_crosshairX;
vmCvar_t cg_crosshairY;
Expand Down Expand Up @@ -226,6 +234,14 @@ static cvarTable_t cvarTable[] = {
{ &cg_drawCrosshair, "cg_drawCrosshair", "4", CVAR_ARCHIVE },
{ &cg_drawCrosshairNames, "cg_drawCrosshairNames", "1", CVAR_ARCHIVE },
{ &cg_drawRewards, "cg_drawRewards", "1", CVAR_ARCHIVE },
{ &cg_drawScores, "cg_drawScores", "1", CVAR_ARCHIVE },
{ &cg_drawPickups, "cg_drawPickups", "1", CVAR_ARCHIVE },
{ &cg_drawWeaponBar, "cg_drawWeaponBar", "1", CVAR_ARCHIVE },
{ &cg_drawStatusHead, "cg_drawStatusHead", "1", CVAR_ARCHIVE },
{ &cg_statusScale, "cg_statusScale", "1", CVAR_ARCHIVE },
{ &cg_fovAspectAdjust, "cg_fovAspectAdjust", "0", CVAR_ARCHIVE },
{ &cg_fovGunAdjust, "cg_fovGunAdjust", "0", CVAR_ARCHIVE },
{ &cg_stretch, "cg_stretch", "1", CVAR_ARCHIVE },
{ &cg_crosshairSize, "cg_crosshairSize", "24", CVAR_ARCHIVE },
{ &cg_crosshairHealth, "cg_crosshairHealth", "1", CVAR_ARCHIVE },
{ &cg_crosshairX, "cg_crosshairX", "0", CVAR_ARCHIVE },
Expand Down Expand Up @@ -1017,6 +1033,9 @@ static void CG_RegisterGraphics( void ) {
}
}

// can be used by HUD so always load it
CG_RegisterItemVisuals( 6 /* item_health_large */ );

// wall marks
cgs.media.bulletMarkShader = trap_R_RegisterShader( "gfx/damage/bullet_mrk" );
cgs.media.burnMarkShader = trap_R_RegisterShader( "gfx/damage/burn_med_mrk" );
Expand Down Expand Up @@ -1877,8 +1896,25 @@ void CG_Init( int serverMessageNum, int serverCommandSequence, int clientNum ) {

// get the rendering configuration from the client system
trap_GetGlconfig( &cgs.glconfig );
cgs.screenXScale = cgs.glconfig.vidWidth / 640.0;
cgs.screenYScale = cgs.glconfig.vidHeight / 480.0;
cgs.screenXScaleStretch = cgs.glconfig.vidWidth * (1.0/640.0);
cgs.screenYScaleStretch = cgs.glconfig.vidHeight * (1.0/480.0);
if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) {
cgs.screenXScale = cgs.glconfig.vidWidth * (1.0/640.0);
cgs.screenYScale = cgs.glconfig.vidHeight * (1.0/480.0);
// wide screen
cgs.screenXBias = 0.5 * ( cgs.glconfig.vidWidth - ( cgs.glconfig.vidHeight * (640.0/480.0) ) );
cgs.screenXScale = cgs.screenYScale;
// no narrow screen
cgs.screenYBias = 0;
} else {
cgs.screenXScale = cgs.glconfig.vidWidth * (1.0/640.0);
cgs.screenYScale = cgs.glconfig.vidHeight * (1.0/480.0);
// narrow screen
cgs.screenYBias = 0.5 * ( cgs.glconfig.vidHeight - ( cgs.glconfig.vidWidth * (480.0/640.0) ) );
cgs.screenYScale = cgs.screenXScale;
// no wide screen
cgs.screenXBias = 0;
}

// get the gamestate from the client system
trap_GetGameState( &cgs.gameState );
Expand Down
6 changes: 6 additions & 0 deletions code/cgame/cg_scoreboard.c
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,8 @@ qboolean CG_DrawOldScoreboard( void ) {
int lineHeight;
int topBorderSize, bottomBorderSize;

CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);

// don't draw amuthing if the menu or console is up
if ( cg_paused.integer ) {
cg.deferredPlayerLoading = 0;
Expand Down Expand Up @@ -457,6 +459,8 @@ void CG_DrawOldTourneyScoreboard( void ) {
int y;
int i;

CG_SetScreenPlacement(PLACE_CENTER, PLACE_CENTER);

// request more scores regularly
if ( cg.scoresRequestTime + 2000 < cg.time ) {
cg.scoresRequestTime = cg.time;
Expand All @@ -466,7 +470,9 @@ void CG_DrawOldTourneyScoreboard( void ) {
// draw the dialog background
color[0] = color[1] = color[2] = 0;
color[3] = 1;
CG_SetScreenPlacement(PLACE_STRETCH, PLACE_STRETCH);
CG_FillRect( 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT, color );
CG_PopScreenPlacement();

color[0] = 1;
color[1] = 1;
Expand Down
14 changes: 13 additions & 1 deletion code/cgame/cg_view.c
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,7 @@ static int CG_CalcFov( void ) {

if ( cg.predictedPlayerState.pm_type == PM_INTERMISSION ) {
// if in intermission, use a fixed value
fov_x = 90;
cg.fov = fov_x = 90;
} else {
// user selectable
if ( cgs.dmflags & DF_FIXED_FOV ) {
Expand All @@ -489,6 +489,8 @@ static int CG_CalcFov( void ) {
}
}

cg.fov = fov_x;

// account for zooms
zoomFov = cg_zoomFov.value;
if ( zoomFov < 1 ) {
Expand All @@ -512,6 +514,16 @@ static int CG_CalcFov( void ) {
}
}

if ( cg_fovAspectAdjust.integer ) {
// Based on LordHavoc's code for Darkplaces
// http://www.quakeworld.nu/forum/topic/53/what-does-your-qw-look-like/page/30
const float baseAspect = 0.75f; // 3/4
const float aspect = (float)cg.refdef.width/(float)cg.refdef.height;
const float desiredFov = fov_x;

fov_x = atan2( tan( desiredFov*M_PI / 360.0f ) * baseAspect*aspect, 1 )*360.0f / M_PI;
}

x = cg.refdef.width / tan( fov_x / 360 * M_PI );
fov_y = atan2( cg.refdef.height, x );
fov_y = fov_y * 360 / M_PI;
Expand Down
Loading

0 comments on commit b6e5bd0

Please sign in to comment.