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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
//=============================================================================//
#include "cbase.h"
#include "hud_numericdisplay.h"
#include "iclientmode.h"
#include <Color.h>
#include <KeyValues.h>
#include <vgui/ISurface.h>
#include <vgui/ISystem.h>
#include <vgui/IVGui.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose: Constructor
//-----------------------------------------------------------------------------
CHudNumericDisplay::CHudNumericDisplay(vgui::Panel *parent, const char *name) : BaseClass(parent, name)
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
m_iValue = 0;
m_LabelText[0] = 0;
m_iSecondaryValue = 0;
m_bDisplayValue = true;
m_bDisplaySecondaryValue = false;
m_bIndent = false;
m_bIsTime = false;
}
//-----------------------------------------------------------------------------
// Purpose: Resets values on restore/new map
//-----------------------------------------------------------------------------
void CHudNumericDisplay::Reset()
{
m_flBlur = 0.0f;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CHudNumericDisplay::SetDisplayValue(int value)
{
m_iValue = value;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CHudNumericDisplay::SetSecondaryValue(int value)
{
m_iSecondaryValue = value;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CHudNumericDisplay::SetShouldDisplayValue(bool state)
{
m_bDisplayValue = state;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CHudNumericDisplay::SetShouldDisplaySecondaryValue(bool state)
{
m_bDisplaySecondaryValue = state;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CHudNumericDisplay::SetLabelText(const wchar_t *text)
{
wcsncpy(m_LabelText, text, sizeof(m_LabelText) / sizeof(wchar_t));
m_LabelText[(sizeof(m_LabelText) / sizeof(wchar_t)) - 1] = 0;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CHudNumericDisplay::SetIndent(bool state)
{
m_bIndent = state;
}
//-----------------------------------------------------------------------------
// Purpose: data accessor
//-----------------------------------------------------------------------------
void CHudNumericDisplay::SetIsTime(bool state)
{
m_bIsTime = state;
}
//-----------------------------------------------------------------------------
// Purpose: paints a number at the specified position
//-----------------------------------------------------------------------------
void CHudNumericDisplay::PaintNumbers(HFont font, int xpos, int ypos, int value)
{
surface()->DrawSetTextFont(font);
wchar_t unicode[6];
if ( !m_bIsTime )
{
V_snwprintf(unicode, ARRAYSIZE(unicode), L"%d", value);
}
else
{
int iMinutes = value / 60;
int iSeconds = value - iMinutes * 60;
#ifdef PORTAL
// portal uses a normal font for numbers so we need the seperate to be a renderable ':' char
if ( iSeconds < 10 )
V_snwprintf( unicode, ARRAYSIZE(unicode), L"%d:0%d", iMinutes, iSeconds );
else
V_snwprintf( unicode, ARRAYSIZE(unicode), L"%d:%d", iMinutes, iSeconds );
#else
if ( iSeconds < 10 )
V_snwprintf( unicode, ARRAYSIZE(unicode), L"%d`0%d", iMinutes, iSeconds );
else
V_snwprintf( unicode, ARRAYSIZE(unicode), L"%d`%d", iMinutes, iSeconds );
#endif
}
// adjust the position to take into account 3 characters
int charWidth = surface()->GetCharacterWidth(font, '0');
if (value < 100 && m_bIndent)
{
xpos += charWidth;
}
if (value < 10 && m_bIndent)
{
xpos += charWidth;
}
surface()->DrawSetTextPos(xpos, ypos);
surface()->DrawUnicodeString( unicode );
}
//-----------------------------------------------------------------------------
// Purpose: draws the text
//-----------------------------------------------------------------------------
void CHudNumericDisplay::PaintLabel( void )
{
surface()->DrawSetTextFont(m_hTextFont);
surface()->DrawSetTextColor(GetFgColor());
surface()->DrawSetTextPos(text_xpos, text_ypos);
surface()->DrawUnicodeString( m_LabelText );
}
//-----------------------------------------------------------------------------
// Purpose: renders the vgui panel
//-----------------------------------------------------------------------------
void CHudNumericDisplay::Paint()
{
if (m_bDisplayValue)
{
// draw our numbers
surface()->DrawSetTextColor(GetFgColor());
PaintNumbers(m_hNumberFont, digit_xpos, digit_ypos, m_iValue);
// draw the overbright blur
for (float fl = m_flBlur; fl > 0.0f; fl -= 1.0f)
{
if (fl >= 1.0f)
{
PaintNumbers(m_hNumberGlowFont, digit_xpos, digit_ypos, m_iValue);
}
else
{
// draw a percentage of the last one
Color col = GetFgColor();
col[3] *= fl;
surface()->DrawSetTextColor(col);
PaintNumbers(m_hNumberGlowFont, digit_xpos, digit_ypos, m_iValue);
}
}
}
// total ammo
if (m_bDisplaySecondaryValue)
{
surface()->DrawSetTextColor(GetFgColor());
PaintNumbers(m_hSmallNumberFont, digit2_xpos, digit2_ypos, m_iSecondaryValue);
}
PaintLabel();
}
|