summaryrefslogtreecommitdiff
path: root/src/cgame
diff options
context:
space:
mode:
authorTony J. White <tjw@tjw.org>2006-12-13 17:05:11 +0000
committerTony J. White <tjw@tjw.org>2006-12-13 17:05:11 +0000
commitf41580907488e297f2521eccb63f4f5d44aa7504 (patch)
tree8cc8cb5faa393fa88912c5efde8ea35d62de3e9d /src/cgame
parent015227d831b60b140510e48f443cfa13edbebd25 (diff)
* (bug 2944) cg_drawClock added
Diffstat (limited to 'src/cgame')
-rw-r--r--src/cgame/cg_draw.c76
-rw-r--r--src/cgame/cg_local.h2
-rw-r--r--src/cgame/cg_main.c2
3 files changed, 80 insertions, 0 deletions
diff --git a/src/cgame/cg_draw.c b/src/cgame/cg_draw.c
index ed7ba1d8..dd86371c 100644
--- a/src/cgame/cg_draw.c
+++ b/src/cgame/cg_draw.c
@@ -1945,6 +1945,79 @@ static void CG_DrawTimer( rectDef_t *rect, float text_x, float text_y,
}
/*
+=================
+CG_DrawClock
+=================
+*/
+static void CG_DrawClock( rectDef_t *rect, float text_x, float text_y,
+ float scale, vec4_t color, int align, int textStyle )
+{
+ char *s;
+ int i, tx, w, totalWidth, strLength;
+ qtime_t qt;
+ int t;
+
+ if( !cg_drawClock.integer )
+ return;
+
+ t = trap_RealTime( &qt );
+
+ if( cg_drawClock.integer == 2 )
+ {
+ s = va( "%02d%s%02d", qt.tm_hour, ( qt.tm_sec % 2 ) ? ":" : " ",
+ qt.tm_min );
+ }
+ else
+ {
+ char *pm = "am";
+ int h = qt.tm_hour;
+
+ if( h == 0 )
+ h = 12;
+ else if( h == 12 )
+ pm = "pm";
+ else if( h > 12 )
+ {
+ h -= 12;
+ pm = "pm";
+ }
+
+ s = va( "%d%s%02d%s", h, ( qt.tm_sec % 2 ) ? ":" : " ", qt.tm_min, pm );
+ }
+ w = CG_Text_Width( "0", scale, 0 );
+ strLength = CG_DrawStrlen( s );
+ totalWidth = w * strLength;
+
+ switch( align )
+ {
+ case ITEM_ALIGN_LEFT:
+ tx = rect->x;
+ break;
+
+ case ITEM_ALIGN_RIGHT:
+ tx = rect->x + rect->w - totalWidth;
+ break;
+
+ case ITEM_ALIGN_CENTER:
+ tx = rect->x + ( rect->w / 2.0f ) - ( totalWidth / 2.0f );
+ break;
+
+ default:
+ tx = 0.0f;
+ }
+
+ for( i = 0; i < strLength; i++ )
+ {
+ char c[ 2 ];
+
+ c[ 0 ] = s[ i ];
+ c[ 1 ] = '\0';
+
+ CG_Text_Paint( text_x + tx + i * w, rect->y + text_y, scale, color, c, 0, 0, textStyle );
+ }
+}
+
+/*
==================
CG_DrawSnapshot
==================
@@ -2713,6 +2786,9 @@ void CG_OwnerDraw( float x, float y, float w, float h, float text_x,
case CG_TIMER:
CG_DrawTimer( &rect, text_x, text_y, scale, color, align, textStyle );
break;
+ case CG_CLOCK:
+ CG_DrawClock( &rect, text_x, text_y, scale, color, align, textStyle );
+ break;
case CG_TIMER_MINS:
CG_DrawTimerMins( &rect, color );
break;
diff --git a/src/cgame/cg_local.h b/src/cgame/cg_local.h
index 27d89d24..f32941a8 100644
--- a/src/cgame/cg_local.h
+++ b/src/cgame/cg_local.h
@@ -1391,6 +1391,7 @@ extern vmCvar_t cg_swingSpeed;
extern vmCvar_t cg_shadows;
extern vmCvar_t cg_gibs;
extern vmCvar_t cg_drawTimer;
+extern vmCvar_t cg_drawClock;
extern vmCvar_t cg_drawFPS;
extern vmCvar_t cg_drawDemoState;
extern vmCvar_t cg_drawSnapshot;
@@ -2038,6 +2039,7 @@ void trap_CIN_DrawCinematic( int handle );
void trap_CIN_SetExtents( int handle, int x, int y, int w, int h );
void trap_SnapVector( float *v );
+int trap_RealTime( qtime_t *tm );
qboolean trap_loadCamera( const char *name );
void trap_startCamera( int time );
diff --git a/src/cgame/cg_main.c b/src/cgame/cg_main.c
index 926ccd88..db4134c0 100644
--- a/src/cgame/cg_main.c
+++ b/src/cgame/cg_main.c
@@ -120,6 +120,7 @@ vmCvar_t cg_swingSpeed;
vmCvar_t cg_shadows;
vmCvar_t cg_gibs;
vmCvar_t cg_drawTimer;
+vmCvar_t cg_drawClock;
vmCvar_t cg_drawFPS;
vmCvar_t cg_drawDemoState;
vmCvar_t cg_drawSnapshot;
@@ -263,6 +264,7 @@ static cvarTable_t cvarTable[ ] =
{ &cg_draw2D, "cg_draw2D", "1", CVAR_ARCHIVE },
{ &cg_drawStatus, "cg_drawStatus", "1", CVAR_ARCHIVE },
{ &cg_drawTimer, "cg_drawTimer", "1", CVAR_ARCHIVE },
+ { &cg_drawClock, "cg_drawClock", "0", CVAR_ARCHIVE },
{ &cg_drawFPS, "cg_drawFPS", "1", CVAR_ARCHIVE },
{ &cg_drawDemoState, "cg_drawDemoState", "1", CVAR_ARCHIVE },
{ &cg_drawSnapshot, "cg_drawSnapshot", "0", CVAR_ARCHIVE },