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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//
//=============================================================================//
#include "cbase.h"
#include "c_baseentity.h"
#include "hud.h"
#include "hudelement.h"
#include "clientmode.h"
#include <vgui_controls/Panel.h>
#include <vgui/IScheme.h>
#include <vgui/ISurface.h>
#include <vgui/ILocalize.h>
#include <vgui_controls/AnimationController.h>
#include "materialsystem/imaterialsystemhardwareconfig.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CHudHDRDemo : public CHudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHudHDRDemo, vgui::Panel );
public:
CHudHDRDemo( const char *name );
// vgui overrides
virtual void ApplySchemeSettings(vgui::IScheme *pScheme );
virtual void Paint( void );
virtual bool ShouldDraw( void );
void SetHDRDemoActive( bool bActive );
private:
bool m_bHDRDemoActive;
// Painting
//CPanelAnimationVar( float, m_flAlphaOverride, "Alpha", "0" );
CPanelAnimationVar( Color, m_BorderColor, "BorderColor", "0 0 0 255" );
CPanelAnimationVar( Color, m_TextColor, "TextColor", "255 255 255 255" );
CPanelAnimationVarAliasType( int, m_iBorderLeft, "BorderLeft", "8", "proportional_int" );
CPanelAnimationVarAliasType( int, m_iBorderRight, "BorderRight", "8", "proportional_int" );
CPanelAnimationVarAliasType( int, m_iBorderTop, "BorderTop", "8", "proportional_int" );
CPanelAnimationVarAliasType( int, m_iBorderBottom, "BorderBottom", "8", "proportional_int" );
CPanelAnimationVarAliasType( int, m_iBorderCenter, "BorderCenter", "8", "proportional_int" );
CPanelAnimationVarAliasType( int, m_iLeftY, "LeftTitleY", "8", "proportional_int" );
CPanelAnimationVarAliasType( int, m_iRightY, "RightTitleY", "8", "proportional_int" );
};
DECLARE_HUDELEMENT( CHudHDRDemo );
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CHudHDRDemo::CHudHDRDemo( const char *name ) : vgui::Panel( NULL, "HudHDRDemo" ), CHudElement( name )
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
SetPaintBorderEnabled( false );
SetPaintBackgroundEnabled( false );
m_bHDRDemoActive = false;
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudHDRDemo::ApplySchemeSettings( vgui::IScheme *pScheme )
{
BaseClass::ApplySchemeSettings(pScheme);
SetSize( ScreenWidth(), ScreenHeight() );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
void CHudHDRDemo::Paint()
{
int x, y, wide, tall;
GetBounds( x, y, wide, tall );
// Draw the borders
vgui::surface()->DrawSetColor( m_BorderColor );
vgui::surface()->DrawFilledRect( 0, 0, m_iBorderLeft, tall ); // Left
vgui::surface()->DrawFilledRect( wide-m_iBorderRight, 0, wide, tall ); // Right
vgui::surface()->DrawFilledRect( m_iBorderLeft, 0, wide-m_iBorderRight, m_iBorderTop ); // Top
vgui::surface()->DrawFilledRect( m_iBorderLeft, tall-m_iBorderBottom, wide-m_iBorderRight, tall ); // Bottom
vgui::surface()->DrawFilledRect( ((wide-m_iBorderCenter)/2), m_iBorderTop, ((wide+m_iBorderCenter)/2), tall-m_iBorderBottom ); // Center
// Get our scheme and font information
vgui::HScheme scheme = vgui::scheme()->GetScheme( "ClientScheme" );
vgui::HFont hFont = vgui::scheme()->GetIScheme(scheme)->GetFont( "HDRDemoText" );
vgui::surface()->DrawSetTextFont( hFont );
vgui::surface()->DrawSetTextColor( m_TextColor );
// Left Title
wchar_t *tempString = g_pVGuiLocalize->Find("#Valve_HDRDEMO_LeftTitle");
if (tempString)
{
int iLength = 0;
for ( wchar_t *wch = tempString; *wch != 0; wch++ )
{
iLength += vgui::surface()->GetCharacterWidth( hFont, *wch );
}
vgui::surface()->DrawSetTextPos( floor(wide * 0.25) - (iLength / 2), m_iLeftY );
vgui::surface()->DrawPrintText(tempString, wcslen(tempString));
}
// Right Title
tempString = g_pVGuiLocalize->Find("#Valve_HDRDEMO_RightTitle");
if (tempString)
{
int iLength = 0;
for ( wchar_t *wch = tempString; *wch != 0; wch++ )
{
iLength += vgui::surface()->GetCharacterWidth( hFont, *wch );
}
vgui::surface()->DrawSetTextPos( ceil(wide * 0.75) - (iLength / 2), m_iRightY );
vgui::surface()->DrawPrintText(tempString, wcslen(tempString));
}
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
bool CHudHDRDemo::ShouldDraw()
{
return (
// no split screen hud if not hdr
(g_pMaterialSystemHardwareConfig->GetHDRType() != HDR_TYPE_NONE) &&
m_bHDRDemoActive
); //&& m_flAlphaOverride > 0 );
}
//-----------------------------------------------------------------------------
// Purpose:
// Input : bActive -
//-----------------------------------------------------------------------------
void CHudHDRDemo::SetHDRDemoActive( bool bActive )
{
if ( bActive && !m_bHDRDemoActive )
{
ConVarRef pHideHud( "hidehud" );
pHideHud.SetValue( 15 );
}
else if ( !bActive && m_bHDRDemoActive )
{
ConVarRef pHideHud( "hidehud" );
pHideHud.SetValue( 0 );
}
m_bHDRDemoActive = bActive;
}
//=======================================================================================================
// CONVAR to toggle this hud element
void mat_show_ab_hdr_hudelement_changed( IConVar *pConVar, const char *pOldString, float flOldValue )
{
CHudHDRDemo *pHudDemo = (CHudHDRDemo*)GET_HUDELEMENT( CHudHDRDemo );
if ( pHudDemo )
{
ConVarRef var( pConVar );
pHudDemo->SetHDRDemoActive( var.GetBool() );
}
}
ConVar mat_show_ab_hdr_hudelement( "mat_show_ab_hdr_hudelement", "0", FCVAR_CHEAT, "HDR Demo HUD Element toggle.", mat_show_ab_hdr_hudelement_changed );
|