Portable Half-Life SDK. GoldSource and Xash3D. Crossplatform.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

394 lines
9.0 KiB

9 years ago
/***
*
* Copyright (c) 1996-2002, Valve LLC. All rights reserved.
*
* This product contains software technology licensed from Id
* Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
* All Rights Reserved.
*
* Use, distribution, and modification of this source code and/or resulting
* object code is restricted to non-commercial enhancements to products from
* Valve LLC. All other use, distribution, or modification is prohibited
* without written permission from Valve LLC.
*
****/
//
// hud_redraw.cpp
//
#include <math.h>
#include "hud.h"
#include "cl_util.h"
//#include "triangleapi.h"
#define MAX_LOGO_FRAMES 56
9 years ago
int grgLogoFrame[MAX_LOGO_FRAMES] =
9 years ago
{
1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 13, 13, 13, 13, 13, 12, 11, 10, 9, 8, 14, 15,
16, 17, 18, 19, 20, 20, 20, 20, 20, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29,
29, 29, 29, 29, 29, 28, 27, 26, 25, 24, 30, 31
};
extern int g_iVisibleMouse;
float HUD_GetFOV( void );
extern cvar_t *sensitivity;
// Think
9 years ago
void CHud::Think( void )
9 years ago
{
int newfov;
HUDLIST *pList = m_pHudList;
9 years ago
while( pList )
9 years ago
{
9 years ago
if( pList->p->m_iFlags & HUD_ACTIVE )
9 years ago
pList->p->Think();
pList = pList->pNext;
}
newfov = HUD_GetFOV();
9 years ago
if( newfov == 0 )
9 years ago
{
m_iFOV = default_fov->value;
}
else
{
m_iFOV = newfov;
}
// the clients fov is actually set in the client data update section of the hud
// Set a new sensitivity
9 years ago
if( m_iFOV == default_fov->value )
{
9 years ago
// reset to saved sensitivity
m_flMouseSensitivity = 0;
}
else
9 years ago
{
9 years ago
// set a new sensitivity that is proportional to the change from the FOV default
m_flMouseSensitivity = sensitivity->value * ((float)newfov / (float)default_fov->value) * CVAR_GET_FLOAT("zoom_sensitivity_ratio");
}
// think about default fov
9 years ago
if( m_iFOV == 0 )
{
// only let players adjust up in fov, and only if they are not overriden by something else
9 years ago
m_iFOV = max( default_fov->value, 90 );
}
}
// Redraw
// step through the local data, placing the appropriate graphics & text as appropriate
// returns 1 if they've changed, 0 otherwise
9 years ago
int CHud::Redraw( float flTime, int intermission )
9 years ago
{
m_fOldTime = m_flTime; // save time of previous redraw
m_flTime = flTime;
m_flTimeDelta = (double)m_flTime - m_fOldTime;
static float m_flShotTime = 0;
9 years ago
9 years ago
// Clock was reset, reset delta
9 years ago
if( m_flTimeDelta < 0 )
9 years ago
m_flTimeDelta = 0;
if( !m_iIntermission && intermission )
{
// Take a screenshot if the client's got the cvar set
if( CVAR_GET_FLOAT( "hud_takesshots" ) != 0 )
m_flShotTime = flTime + 1.0; // Take a screenshot in a second
}
9 years ago
if( m_flShotTime && m_flShotTime < flTime )
9 years ago
{
9 years ago
gEngfuncs.pfnClientCmd( "snapshot\n" );
9 years ago
m_flShotTime = 0;
}
m_iIntermission = intermission;
// if no redrawing is necessary
// return 0;
9 years ago
if( m_pCvarDraw->value )
9 years ago
{
HUDLIST *pList = m_pHudList;
9 years ago
while( pList )
9 years ago
{
9 years ago
if( !intermission )
9 years ago
{
9 years ago
if ( ( pList->p->m_iFlags & HUD_ACTIVE ) && !( m_iHideHUDDisplay & HIDEHUD_ALL ) )
pList->p->Draw( flTime );
9 years ago
}
else
9 years ago
{
// it's an intermission, so only draw hud elements that are set to draw during intermissions
if( pList->p->m_iFlags & HUD_INTERMISSION )
9 years ago
pList->p->Draw( flTime );
}
pList = pList->pNext;
}
}
// are we in demo mode? do we need to draw the logo in the top corner?
9 years ago
if( m_iLogo )
9 years ago
{
int x, y, i;
9 years ago
if( m_hsprLogo == 0 )
m_hsprLogo = LoadSprite( "sprites/%d_logo.spr" );
SPR_Set( m_hsprLogo, 250, 250, 250 );
9 years ago
9 years ago
x = SPR_Width( m_hsprLogo, 0 );
9 years ago
x = ScreenWidth - x;
9 years ago
y = SPR_Height( m_hsprLogo, 0 ) / 2;
9 years ago
// Draw the logo at 20 fps
9 years ago
int iFrame = (int)( flTime * 20 ) % MAX_LOGO_FRAMES;
9 years ago
i = grgLogoFrame[iFrame] - 1;
9 years ago
SPR_DrawAdditive( i, x, y, NULL );
9 years ago
}
/*
9 years ago
if( g_iVisibleMouse )
9 years ago
{
void IN_GetMousePos( int *mx, int *my );
int mx, my;
IN_GetMousePos( &mx, &my );
9 years ago
if( m_hsprCursor == 0 )
9 years ago
{
char sz[256];
sprintf( sz, "sprites/cursor.spr" );
m_hsprCursor = SPR_Load( sz );
}
9 years ago
SPR_Set( m_hsprCursor, 250, 250, 250 );
9 years ago
// Draw the logo at 20 fps
SPR_DrawAdditive( 0, mx, my, NULL );
}
*/
return 1;
}
void ScaleColors( int &r, int &g, int &b, int a )
{
float x = (float)a / 255;
9 years ago
r = (int)( r * x );
g = (int)( g * x );
b = (int)( b * x );
9 years ago
}
const unsigned char colors[8][3] =
{
{127, 127, 127}, // additive cannot be black
{255, 0, 0},
{ 0, 255, 0},
{255, 255, 0},
{ 0, 0, 255},
{ 0, 255, 255},
{255, 0, 255},
{240, 180, 24}
};
9 years ago
int CHud::DrawHudString( int xpos, int ypos, int iMaxX, char *szIt, int r, int g, int b )
9 years ago
{
if( hud_textmode->value == 2 )
{
9 years ago
gEngfuncs.pfnDrawSetTextColor( r / 255.0, g / 255.0, b / 255.0 );
9 years ago
return gEngfuncs.pfnDrawConsoleString( xpos, ypos, (char*) szIt );
}
// xash3d: reset unicode state
TextMessageDrawChar( 0, 0, 0, 0, 0, 0 );
// draw the string until we hit the null character or a newline character
9 years ago
for( ; *szIt != 0 && *szIt != '\n'; szIt++ )
9 years ago
{
9 years ago
int w = gHUD.m_scrinfo.charWidths['M'];
if( xpos + w > iMaxX )
9 years ago
return xpos;
9 years ago
if( ( *szIt == '^' ) && ( *( szIt + 1 ) >= '0') && ( *( szIt + 1 ) <= '7') )
9 years ago
{
szIt++;
9 years ago
r = colors[*szIt - '0'][0];
g = colors[*szIt - '0'][1];
b = colors[*szIt - '0'][2];
if( !*(++szIt) )
9 years ago
return xpos;
}
int c = (unsigned int)(unsigned char)*szIt;
xpos += TextMessageDrawChar( xpos, ypos, c, r, g, b );
}
return xpos;
}
int DrawUtfString( int xpos, int ypos, int iMaxX, char *szIt, int r, int g, int b )
{
// xash3d: reset unicode state
gEngfuncs.pfnVGUI2DrawCharacterAdditive( 0, 0, 0, 0, 0, 0, 0 );
// draw the string until we hit the null character or a newline character
for( ; *szIt != 0 && *szIt != '\n'; szIt++ )
{
int w = gHUD.m_scrinfo.charWidths['M'];
if( xpos + w > iMaxX )
return xpos;
if( ( *szIt == '^' ) && ( *( szIt + 1 ) >= '0') && ( *( szIt + 1 ) <= '7') )
{
szIt++;
r = colors[*szIt - '0'][0];
g = colors[*szIt - '0'][1];
b = colors[*szIt - '0'][2];
if( !*(++szIt) )
return xpos;
}
int c = (unsigned int)(unsigned char)*szIt;
xpos += gEngfuncs.pfnVGUI2DrawCharacterAdditive( xpos, ypos, c, r, g, b, 0 );
}
9 years ago
return xpos;
}
9 years ago
int CHud::DrawHudStringLen( char *szIt )
9 years ago
{
int l = 0;
9 years ago
for( ; *szIt != 0 && *szIt != '\n'; szIt++ )
9 years ago
{
9 years ago
l += gHUD.m_scrinfo.charWidths[(unsigned char)*szIt];
9 years ago
}
return l;
}
9 years ago
int CHud::DrawHudNumberString( int xpos, int ypos, int iMinX, int iNumber, int r, int g, int b )
9 years ago
{
char szString[32];
sprintf( szString, "%d", iNumber );
return DrawHudStringReverse( xpos, ypos, iMinX, szString, r, g, b );
}
// draws a string from right to left (right-aligned)
9 years ago
int CHud::DrawHudStringReverse( int xpos, int ypos, int iMinX, char *szString, int r, int g, int b )
9 years ago
{
// find the end of the string
for( char *szIt = szString; *szIt != 0; szIt++ )
9 years ago
xpos -= gHUD.m_scrinfo.charWidths[(unsigned char)*szIt];
9 years ago
if( xpos < iMinX )
xpos = iMinX;
DrawHudString( xpos, ypos, gHUD.m_scrinfo.iWidth, szString, r, g, b );
return xpos;
}
9 years ago
int CHud::DrawHudNumber( int x, int y, int iFlags, int iNumber, int r, int g, int b )
9 years ago
{
9 years ago
int iWidth = GetSpriteRect( m_HUD_number_0 ).right - GetSpriteRect( m_HUD_number_0 ).left;
9 years ago
int k;
9 years ago
if( iNumber > 0 )
9 years ago
{
// SPR_Draw 100's
9 years ago
if( iNumber >= 100 )
9 years ago
{
9 years ago
k = iNumber / 100;
SPR_Set( GetSprite( m_HUD_number_0 + k ), 255, 255, 255 );
SPR_DrawHoles( 0, x, y, &GetSpriteRect( m_HUD_number_0 + k ) );
9 years ago
x += iWidth;
}
9 years ago
else if( iFlags & ( DHN_3DIGITS ) )
9 years ago
{
//SPR_DrawAdditive( 0, x, y, &rc );
x += iWidth;
}
// SPR_Draw 10's
9 years ago
if( iNumber >= 10 )
9 years ago
{
9 years ago
k = ( iNumber % 100 ) / 10;
SPR_Set( GetSprite( m_HUD_number_0 + k ), 255, 255, 255 );
SPR_DrawHoles( 0, x, y, &GetSpriteRect( m_HUD_number_0 + k ) );
9 years ago
x += iWidth;
}
9 years ago
else if( iFlags & ( DHN_3DIGITS | DHN_2DIGITS ) )
9 years ago
{
//SPR_DrawAdditive( 0, x, y, &rc );
x += iWidth;
}
// SPR_Draw ones
k = iNumber % 10;
SPR_Set( GetSprite( m_HUD_number_0 + k ), 255, 255, 255 );
SPR_DrawHoles( 0, x, y, &GetSpriteRect( m_HUD_number_0 + k ) );
9 years ago
x += iWidth;
9 years ago
}
else if( iFlags & DHN_DRAWZERO )
9 years ago
{
SPR_Set( GetSprite( m_HUD_number_0 ), 255, 255, 255 );
9 years ago
// SPR_Draw 100's
9 years ago
if( iFlags & ( DHN_3DIGITS ) )
9 years ago
{
//SPR_DrawAdditive( 0, x, y, &rc );
x += iWidth;
}
9 years ago
if( iFlags & ( DHN_3DIGITS | DHN_2DIGITS ) )
9 years ago
{
//SPR_DrawAdditive( 0, x, y, &rc );
x += iWidth;
}
// SPR_Draw ones
SPR_DrawHoles( 0, x, y, &GetSpriteRect( m_HUD_number_0 ) );
9 years ago
x += iWidth;
}
return x;
}
int CHud::GetNumWidth( int iNumber, int iFlags )
{
9 years ago
if( iFlags & ( DHN_3DIGITS ) )
9 years ago
return 3;
9 years ago
if( iFlags & ( DHN_2DIGITS ) )
9 years ago
return 2;
9 years ago
if( iNumber <= 0 )
9 years ago
{
9 years ago
if( iFlags & ( DHN_DRAWZERO ) )
9 years ago
return 1;
else
return 0;
}
9 years ago
if( iNumber < 10 )
9 years ago
return 1;
9 years ago
if( iNumber < 100 )
9 years ago
return 2;
return 3;
}
void CHud::DrawDarkRectangle( int x, int y, int wide, int tall )
{
//gEngfuncs.pTriAPI->RenderMode( kRenderTransTexture );
gEngfuncs.pfnFillRGBABlend( x, y, wide, tall, 0, 0, 0, 255 * 0.6 );
9 years ago
FillRGBA( x + 1, y, wide - 1, 1, 255, 140, 0, 255 );
FillRGBA( x, y, 1, tall - 1, 255, 140, 0, 255 );
FillRGBA( x + wide - 1, y + 1, 1, tall - 1, 255, 140, 0, 255 );
FillRGBA( x, y + tall - 1, wide - 1, 1, 255, 140, 0, 255 );
9 years ago
}