aboutsummaryrefslogtreecommitdiff
path: root/mp/src/game/client/hud_numericdisplay.cpp
diff options
context:
space:
mode:
authorJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
committerJoe Ludwig <[email protected]>2013-06-26 15:22:04 -0700
commit39ed87570bdb2f86969d4be821c94b722dc71179 (patch)
treeabc53757f75f40c80278e87650ea92808274aa59 /mp/src/game/client/hud_numericdisplay.cpp
downloadsource-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.tar.xz
source-sdk-2013-39ed87570bdb2f86969d4be821c94b722dc71179.zip
First version of the SOurce SDK 2013
Diffstat (limited to 'mp/src/game/client/hud_numericdisplay.cpp')
-rw-r--r--mp/src/game/client/hud_numericdisplay.cpp199
1 files changed, 199 insertions, 0 deletions
diff --git a/mp/src/game/client/hud_numericdisplay.cpp b/mp/src/game/client/hud_numericdisplay.cpp
new file mode 100644
index 00000000..3e84614f
--- /dev/null
+++ b/mp/src/game/client/hud_numericdisplay.cpp
@@ -0,0 +1,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();
+}
+
+
+