summaryrefslogtreecommitdiff
path: root/game/client/hl1/hl1_hud_numbers.cpp
blob: 1abcabccffb9b6960acab3a1dd57431490cffab1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose: 
//
//=============================================================================//

#include "cbase.h"
#include "hud.h"
#include "hudelement.h"
#include "hud_macros.h"
#include "iclientmode.h"
#include "hl1_hud_numbers.h"


// This is a bad way to implement HL1 style sprite fonts, but it will work for now

CHL1HudNumbers::CHL1HudNumbers( vgui::Panel *parent, const char *name ) : BaseClass( parent, name )
{
	vgui::Panel *pParent = g_pClientMode->GetViewport();
	SetParent( pParent );
}


void CHL1HudNumbers::VidInit( void )
{
	for ( int i = 0; i < 10; i++ )
	{
		char szNumString[ 10 ];

		sprintf( szNumString, "number_%d", i );
		icon_digits[ i ] = gHUD.GetIcon( szNumString );
	}
}


int CHL1HudNumbers::GetNumberFontHeight( void )
{
	if ( icon_digits[ 0 ] )
	{
		return icon_digits[ 0 ]->Height();
	}
	else
	{
		return 0;
	}
}


int CHL1HudNumbers::GetNumberFontWidth( void )
{
	if ( icon_digits[ 0 ] )
	{
		return icon_digits[ 0 ]->Width();
	}
	else
	{
		return 0;
	}
}


int CHL1HudNumbers::DrawHudNumber( int x, int y, int iNumber, Color &clrDraw )
{
	int iWidth = GetNumberFontWidth();
	int k;
	
	if ( iNumber > 0 )
	{
		// SPR_Draw 100's
		if ( iNumber >= 100 )
		{
			k = iNumber / 100;
			icon_digits[ k ]->DrawSelf( x, y, clrDraw );
			x += iWidth;
		}
		else
		{
			x += iWidth;
		}

		// SPR_Draw 10's
		if ( iNumber >= 10 )
		{
			k = ( iNumber % 100 ) / 10;
			icon_digits[ k ]->DrawSelf( x, y, clrDraw );
			x += iWidth;
		}
		else
		{
			x += iWidth;
		}

		// SPR_Draw ones
		k = iNumber % 10;
		icon_digits[ k ]->DrawSelf( x, y, clrDraw );
		x += iWidth;
	} 
	else
	{
		// SPR_Draw 100's
		x += iWidth;

		// SPR_Draw 10's
		x += iWidth;

		// SPR_Draw ones
		k = 0;
		icon_digits[ k ]->DrawSelf( x, y, clrDraw );
		x += iWidth;
	}

	return x;
}