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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $Workfile: $
// $Date: $
// $NoKeywords: $
//=============================================================================//
#include "client_pch.h"
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
ConVar vgui_nav_lock( "vgui_nav_lock", "0", FCVAR_DEVELOPMENTONLY );
ConVar vgui_nav_lock_default_button( "vgui_nav_lock_default_button", "0", FCVAR_DEVELOPMENTONLY );
//-----------------------------------------------------------------------------
// Purpose: Determine length of text string
// Input : *font -
// *fmt -
// ... -
// Output :
//-----------------------------------------------------------------------------
int DrawTextLen( vgui::HFont font, const wchar_t *text )
{
int len = wcslen( text );
int x = 0;
vgui::surface()->DrawSetTextFont( font );
for ( int i = 0 ; i < len; i++ )
{
int a, b, c;
vgui::surface()->GetCharABCwide( font, text[i], a, b, c );
// Ignore a
if ( i != 0 )
x += a;
x += b;
if ( i != len - 1 )
x += c;
}
return x;
}
//-----------------------------------------------------------------------------
// Purpose: Draws colored text to a vgui panel
// Input : *font - font to use
// x - position of text
// y -
// r - color of text
// g -
// b -
// a - alpha ( 0 = opaque, 255 = transparent )
// *fmt - va_* text string
// ... -
// Output : int - horizontal # of pixels drawn
//-----------------------------------------------------------------------------
int DrawColoredText( vgui::HFont font, int x, int y, int r, int g, int b, int a, const wchar_t *text )
{
int len = wcslen( text );
if ( len <= 0 )
return x;
MatSysQueueMark( g_pMaterialSystem, "DrawColoredText\n" );
vgui::surface()->DrawSetTextFont( font );
vgui::surface()->DrawSetTextPos( x, y );
vgui::surface()->DrawSetTextColor( r, g, b, a );
int pixels = DrawTextLen( font, text );
vgui::surface()->DrawPrintText( text, len );
MatSysQueueMark( g_pMaterialSystem, "END DrawColoredText\n" );
return x + pixels;
}
int DrawColoredText( vgui::HFont font, int x, int y, Color clr, const wchar_t *text )
{
int r, g, b, a;
clr.GetColor( r, g, b, a );
return ::DrawColoredText( font, x, y, r, g, b, a, text);
}
int DrawCenteredColoredText( vgui::HFont font, int left, int top, int right, int bottom, Color clr, const wchar_t *text )
{
int textHeight = vgui::surface()->GetFontTall( font );
int textWidth = DrawTextLen( font, text );
return DrawColoredText( font, (right + left) / 2 - textWidth / 2, (bottom + top) / 2 - textHeight / 2, clr, text );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBasePanel::CBasePanel( vgui::Panel *parent, char const *panelName )
: vgui::Panel( parent, panelName )
{
vgui::ivgui()->AddTickSignal( GetVPanel() );
}
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
CBasePanel::~CBasePanel( void )
{
}
void CBasePanel::OnTick()
{
if ( vgui_nav_lock.GetInt() > 0 )
{
vgui_nav_lock.SetValue( vgui_nav_lock.GetInt() - 1 );
}
if ( vgui_nav_lock_default_button.GetInt() > 0 )
{
vgui_nav_lock_default_button.SetValue( vgui_nav_lock_default_button.GetInt() - 1 );
}
SetVisible( ShouldDraw() );
}
|