271 lines
6.3 KiB
C
271 lines
6.3 KiB
C
/*
|
|
===========================================================================
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
Copyright (C) 2007 HermitWorks Entertainment Corporation
|
|
|
|
This file is part of the Space Trader source code.
|
|
|
|
The Space Trader source code is free software; you can redistribute it
|
|
and/or modify it under the terms of the GNU General Public License as
|
|
published by the Free Software Foundation; either version 2 of the License,
|
|
or (at your option) any later version.
|
|
|
|
The Space Trader source code is distributed in the hope that it will be
|
|
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
GNU General Public License for more details.
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
along with the Space Trader source code; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
|
===========================================================================
|
|
*/
|
|
|
|
#include "cg_local.h"
|
|
|
|
//cg_drawtools.c -- helper functions called by cg_draw, cg_scoreboard, cg_info, etc
|
|
|
|
/*
|
|
================
|
|
CG_AdjustFrom640
|
|
|
|
Adjusted for resolution and screen aspect ratio
|
|
================
|
|
*/
|
|
void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
|
|
// scale for screen sizes
|
|
*x = *x * cgDC.glconfig.xscale + cgDC.glconfig.xbias;
|
|
*y *= cgDC.glconfig.yscale;
|
|
*w *= cgDC.glconfig.xscale;
|
|
*h *= cgDC.glconfig.yscale;
|
|
}
|
|
|
|
void CG_AdjustTo640( int *x, int *y )
|
|
{
|
|
float X = (float)*x;
|
|
float Y = (float)*y;
|
|
|
|
X = (X - cgDC.glconfig.xbias) / cgDC.glconfig.xscale;
|
|
Y = Y / cgDC.glconfig.yscale;
|
|
|
|
*x = (int)X;
|
|
*y = (int)Y;
|
|
}
|
|
|
|
/*
|
|
================
|
|
CG_DrawSides
|
|
|
|
Coords are virtual 640x480
|
|
================
|
|
*/
|
|
void CG_DrawSides(float x, float y, float w, float h, float size) {
|
|
CG_AdjustFrom640( &x, &y, &w, &h );
|
|
size *= cgDC.glconfig.xscale;
|
|
trap_R_DrawStretchPic( x, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader );
|
|
trap_R_DrawStretchPic( x + w - size, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader );
|
|
}
|
|
|
|
void CG_DrawTopBottom(float x, float y, float w, float h, float size) {
|
|
CG_AdjustFrom640( &x, &y, &w, &h );
|
|
size *= cgDC.glconfig.yscale;
|
|
trap_R_DrawStretchPic( x, y, w, size, 0, 0, 0, 0, cgs.media.whiteShader );
|
|
trap_R_DrawStretchPic( x, y + h - size, w, size, 0, 0, 0, 0, cgs.media.whiteShader );
|
|
}
|
|
/*
|
|
================
|
|
UI_DrawRect
|
|
|
|
Coordinates are 640*480 virtual values
|
|
=================
|
|
*/
|
|
void CG_DrawRect( float x, float y, float width, float height, float size, const float *color ) {
|
|
trap_R_SetColor( color );
|
|
|
|
CG_DrawTopBottom(x, y, width, height, size);
|
|
CG_DrawSides(x, y, width, height, size);
|
|
|
|
trap_R_SetColor( NULL );
|
|
}
|
|
|
|
/*
|
|
================
|
|
CG_DrawPic
|
|
|
|
Coordinates are 640*480 virtual values
|
|
=================
|
|
*/
|
|
void CG_DrawPic( float x, float y, float width, float height, qhandle_t hShader ) {
|
|
CG_AdjustFrom640( &x, &y, &width, &height );
|
|
trap_R_DrawStretchPic( x, y, width, height, 0.0f, 0.0f, 1.0f, 1.0f, hShader );
|
|
}
|
|
|
|
/*
|
|
=============
|
|
CG_TileClearBox
|
|
|
|
This repeats a 64*64 tile graphic to fill the screen around a sized down
|
|
refresh window.
|
|
=============
|
|
*/
|
|
static void CG_TileClearBox( int x, int y, int w, int h, qhandle_t hShader ) {
|
|
float s1, t1, s2, t2;
|
|
|
|
s1 = x/64.0f;
|
|
t1 = y/64.0f;
|
|
s2 = (x+w)/64.0f;
|
|
t2 = (y+h)/64.0f;
|
|
trap_R_DrawStretchPic( x, y, w, h, s1, t1, s2, t2, hShader );
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
==============
|
|
CG_TileClear
|
|
|
|
Clear around a sized down screen
|
|
==============
|
|
*/
|
|
void CG_TileClear( void ) {
|
|
int top, bottom, left, right;
|
|
int w, h;
|
|
|
|
w = cgDC.glconfig.vidWidth;
|
|
h = cgDC.glconfig.vidHeight;
|
|
|
|
if ( cg.refdef.x == 0 && cg.refdef.y == 0 &&
|
|
cg.refdef.width == w && cg.refdef.height == h ) {
|
|
return; // full screen rendering
|
|
}
|
|
|
|
top = cg.refdef.y;
|
|
bottom = top + cg.refdef.height-1;
|
|
left = cg.refdef.x;
|
|
right = left + cg.refdef.width-1;
|
|
|
|
// clear above view screen
|
|
CG_TileClearBox( 0, 0, w, top, cgs.media.backTileShader );
|
|
|
|
// clear below view screen
|
|
CG_TileClearBox( 0, bottom, w, h - bottom, cgs.media.backTileShader );
|
|
|
|
// clear left of view screen
|
|
CG_TileClearBox( 0, top, left, bottom - top + 1, cgs.media.backTileShader );
|
|
|
|
// clear right of view screen
|
|
CG_TileClearBox( right, top, w - right, bottom - top + 1, cgs.media.backTileShader );
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
================
|
|
CG_FadeColor
|
|
================
|
|
*/
|
|
float *CG_FadeColor( int startMsec, int totalMsec ) {
|
|
static vec4_t color;
|
|
int t;
|
|
|
|
if ( startMsec == 0 ) {
|
|
return NULL;
|
|
}
|
|
|
|
t = cg.time - startMsec;
|
|
|
|
if ( t >= totalMsec ) {
|
|
return NULL;
|
|
}
|
|
|
|
// fade out
|
|
if ( totalMsec - t < FADE_TIME ) {
|
|
color[3] = ( totalMsec - t ) * 1.0/FADE_TIME;
|
|
} else {
|
|
color[3] = 1.0;
|
|
}
|
|
color[0] = color[1] = color[2] = 1;
|
|
|
|
return color;
|
|
}
|
|
|
|
|
|
/*
|
|
================
|
|
CG_TeamColor
|
|
================
|
|
*/
|
|
float *CG_TeamColor( int team ) {
|
|
static vec4_t red = {1, 0.2f, 0.2f, 1};
|
|
static vec4_t blue = {0.2f, 0.2f, 1, 1};
|
|
static vec4_t other = {1, 1, 1, 1};
|
|
static vec4_t spectator = {0.7f, 0.7f, 0.7f, 1};
|
|
|
|
switch ( team ) {
|
|
case TEAM_RED:
|
|
return red;
|
|
case TEAM_BLUE:
|
|
return blue;
|
|
case TEAM_SPECTATOR:
|
|
return spectator;
|
|
default:
|
|
return other;
|
|
}
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
=================
|
|
CG_GetColorForHealth
|
|
=================
|
|
*/
|
|
void CG_GetColorForHealth( int health, int armor, vec4_t hcolor ) {
|
|
int count;
|
|
int max;
|
|
|
|
// calculate the total points of damage that can
|
|
// be sustained at the current health / armor level
|
|
if ( health <= 0 ) {
|
|
VectorClear( hcolor ); // black
|
|
hcolor[3] = 1;
|
|
return;
|
|
}
|
|
count = armor;
|
|
max = health * ARMOR_PROTECTION / ( 1.0f - ARMOR_PROTECTION );
|
|
if ( max < count ) {
|
|
count = max;
|
|
}
|
|
health += count;
|
|
|
|
// set the color based on health
|
|
hcolor[0] = 1.0f;
|
|
hcolor[3] = 1.0f;
|
|
if ( health >= 100 ) {
|
|
hcolor[2] = 1.0f;
|
|
} else if ( health < 66 ) {
|
|
hcolor[2] = 0.0f;
|
|
} else {
|
|
hcolor[2] = (float)( health - 66 ) / 33.0f;
|
|
}
|
|
|
|
if ( health > 60 ) {
|
|
hcolor[1] = 1.0f;
|
|
} else if ( health < 30 ) {
|
|
hcolor[1] = 0.0f;
|
|
} else {
|
|
hcolor[1] = (float)( health - 30 ) / 30.0f;
|
|
}
|
|
}
|
|
|
|
/*
|
|
=================
|
|
CG_ColorForHealth
|
|
=================
|
|
*/
|
|
void CG_ColorForHealth( vec4_t hcolor ) {
|
|
|
|
CG_GetColorForHealth( cg.snap->ps.stats[STAT_HEALTH],
|
|
cg.snap->ps.shields, hcolor );
|
|
}
|