mirror of
https://github.com/openmoh/openmohaa.git
synced 2025-05-09 03:58:14 +03:00
245 lines
5.9 KiB
C
245 lines
5.9 KiB
C
/*
|
|
===========================================================================
|
|
Copyright (C) 1999-2005 Id Software, Inc.
|
|
|
|
This file is part of Quake III Arena source code.
|
|
|
|
Quake III Arena 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.
|
|
|
|
Quake III Arena 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 Quake III Arena source code; if not, write to the Free Software
|
|
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"
|
|
|
|
/*
|
|
================
|
|
CG_AdjustFrom640
|
|
|
|
Adjusted for resolution and screen aspect ratio
|
|
================
|
|
*/
|
|
void CG_AdjustFrom640( float *x, float *y, float *w, float *h ) {
|
|
#if 0
|
|
// adjust for wide screens
|
|
if ( cgs.glconfig.vidWidth * 480 > cgs.glconfig.vidHeight * 640 ) {
|
|
*x += 0.5 * ( cgs.glconfig.vidWidth - ( cgs.glconfig.vidHeight * 640 / 480 ) );
|
|
}
|
|
#endif
|
|
// scale for screen sizes
|
|
*x *= cgs.screenXScale;
|
|
*y *= cgs.screenYScale;
|
|
*w *= cgs.screenXScale;
|
|
*h *= cgs.screenYScale;
|
|
}
|
|
|
|
/*
|
|
================
|
|
CG_FillRect
|
|
|
|
Coordinates are 640*480 virtual values
|
|
=================
|
|
*/
|
|
void CG_FillRect( float x, float y, float width, float height, const float *color ) {
|
|
cgi.R_SetColor( color );
|
|
|
|
CG_AdjustFrom640( &x, &y, &width, &height );
|
|
cgi.R_DrawStretchPic( x, y, width, height, 0, 0, 0, 0, cgs.media.whiteShader );
|
|
|
|
cgi.R_SetColor( NULL );
|
|
}
|
|
|
|
/*
|
|
================
|
|
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 *= cgs.screenXScale;
|
|
cgi.R_DrawStretchPic( x, y, size, h, 0, 0, 0, 0, cgs.media.whiteShader );
|
|
cgi.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 *= cgs.screenYScale;
|
|
cgi.R_DrawStretchPic( x, y, w, size, 0, 0, 0, 0, cgs.media.whiteShader );
|
|
cgi.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 ) {
|
|
cgi.R_SetColor( color );
|
|
|
|
CG_DrawTopBottom(x, y, width, height, size);
|
|
CG_DrawSides(x, y, width, height, size);
|
|
|
|
cgi.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 );
|
|
cgi.R_DrawStretchPic( x, y, width, height, 0, 0, 1, 1, hShader );
|
|
}
|
|
|
|
|
|
/*
|
|
=================
|
|
CG_DrawStrlen
|
|
|
|
Returns character count, skiping color escape codes
|
|
=================
|
|
*/
|
|
int CG_DrawStrlen( const char *str ) {
|
|
const char *s = str;
|
|
int count = 0;
|
|
|
|
// while ( *s ) {
|
|
// if ( Q_IsColorString( s ) ) {
|
|
// s += 2;
|
|
// } else {
|
|
// count++;
|
|
// s++;
|
|
// }
|
|
// }
|
|
return cgi.R_Text_Width( &cgs.media.verdana, str, -1, qtrue );
|
|
}
|
|
|
|
/*
|
|
=============
|
|
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.0;
|
|
t1 = y/64.0;
|
|
s2 = (x+w)/64.0;
|
|
t2 = (y+h)/64.0;
|
|
cgi.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 = cgs.glconfig.vidWidth;
|
|
h = cgs.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_DrawStringExt
|
|
|
|
Draws a multi-colored string with a drop shadow, optionally forcing
|
|
to a fixed color.
|
|
|
|
Coordinates are at 640 by 480 virtual resolution
|
|
==================
|
|
*/
|
|
void CG_DrawStringExt( int x, int y, const char *string, const float *setColor,
|
|
qboolean forceColor, qboolean shadow, int charWidth, int charHeight, int maxChars ) {
|
|
if(string == 0 || string[0] == 0)
|
|
return;
|
|
cgi.R_SetColor(setColor);
|
|
cgi.R_Text_Paint(&cgs.media.verdana, x, y, 1, 1, string, 0, maxChars, qfalse, qfalse);
|
|
}
|
|
void CG_DrawBigString( int x, int y, const char *s, float alpha ) {
|
|
float color[4];
|
|
|
|
color[0] = color[1] = color[2] = 1.0;
|
|
color[3] = alpha;
|
|
CG_DrawStringExt( x, y, s, color, qfalse, qtrue, BIGCHAR_WIDTH, BIGCHAR_HEIGHT, 0 );
|
|
}
|
|
|