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
|
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#include "cbase.h"
#include "hud.h"
#include "iclientmode.h"
#include "hudelement.h"
//#include "view.h"
//#include "vgui_controls/Controls.h"
#include "vgui/ISurface.h"
#include "vgui/IInput.h"
#include <vgui_controls/Panel.h>
// memdbgon must be the last include file in a .cpp file!!!
#include "tier0/memdbgon.h"
using namespace vgui;
//-----------------------------------------------------------------------------
// Purpose:
//-----------------------------------------------------------------------------
class CHudVguiScreenCursor : public CHudElement, public vgui::Panel
{
DECLARE_CLASS_SIMPLE( CHudVguiScreenCursor, vgui::Panel );
public:
CHudVguiScreenCursor( const char *pElementName );
virtual bool ShouldDraw();
protected:
virtual void ApplySchemeSettings( vgui::IScheme *scheme );
virtual void Paint();
private:
// Cursor sprite and color
CHudTexture *m_pCursor;
Color m_clrCrosshair;
};
DECLARE_HUDELEMENT( CHudVguiScreenCursor );
CHudVguiScreenCursor::CHudVguiScreenCursor( const char *pElementName ) :
CHudElement( pElementName ), BaseClass( NULL, "VguiScreenCursor" )
{
vgui::Panel *pParent = g_pClientMode->GetViewport();
SetParent( pParent );
m_pCursor = 0;
m_clrCrosshair = Color( 0, 0, 0, 0 );
SetHiddenBits( HIDEHUD_PLAYERDEAD );
}
void CHudVguiScreenCursor::ApplySchemeSettings( IScheme *scheme )
{
BaseClass::ApplySchemeSettings( scheme );
m_clrCrosshair = scheme->GetColor( "VguiScreenCursor", Color( 255, 255, 255, 255 ) );
m_pCursor = gHUD.GetIcon( "arrow" );
SetPaintBackgroundEnabled( false );
SetSize( ScreenWidth(), ScreenHeight() );
}
//-----------------------------------------------------------------------------
// Purpose: Save CPU cycles by letting the HUD system early cull
// costly traversal. Called per frame, return true if thinking and
// painting need to occur.
//-----------------------------------------------------------------------------
bool CHudVguiScreenCursor::ShouldDraw( void )
{
C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return false;
if ( pPlayer->IsInViewModelVGuiInputMode() )
{
return false;
}
if ( !pPlayer->IsInVGuiInputMode() )
{
return false;
}
return CHudElement::ShouldDraw();
}
void CHudVguiScreenCursor::Paint( void )
{
if ( !m_pCursor )
return;
float x, y;
x = ScreenWidth()/2;
y = ScreenHeight()/2;
C_BasePlayer* pPlayer = C_BasePlayer::GetLocalPlayer();
if ( !pPlayer )
return;
if ( pPlayer->IsInViewModelVGuiInputMode() )
{
int iX, iY;
vgui::input()->GetCursorPos(iX, iY);
x = (float)iX;
y = (float)iY;
}
m_pCursor->DrawSelf(
x - 0.5f * m_pCursor->Width(),
y - 0.5f * m_pCursor->Height(),
m_clrCrosshair );
}
|