forked from sears2424/Source-PlusPlus
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPHandle.h
86 lines (67 loc) · 2.49 KB
/
PHandle.h
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
//========= Copyright Valve Corporation, All rights reserved. ============//
//
// Purpose:
//
// $NoKeywords: $
//=============================================================================//
#ifndef PHANDLE_H
#define PHANDLE_H
#ifdef _WIN32
#pragma once
#endif
#include <vgui/VGUI.h>
namespace vgui
{
class Panel;
//-----------------------------------------------------------------------------
// Purpose: Safe pointer class for handling Panel or derived panel classes
//-----------------------------------------------------------------------------
class PHandle
{
public:
PHandle() : m_iPanelID(INVALID_PANEL) {} //m_iSerialNumber(0), m_pListEntry(0) {}
Panel *Get();
Panel *Set( Panel *pPanel );
Panel *Set( HPanel hPanel );
operator Panel *() { return Get(); }
Panel * operator ->() { return Get(); }
Panel * operator = (Panel *pPanel) { return Set(pPanel); }
bool operator == (Panel *pPanel) { return (Get() == pPanel); }
operator bool () { return Get() != 0; }
private:
HPanel m_iPanelID;
};
//-----------------------------------------------------------------------------
// Purpose: Safe pointer class to just convert between VPANEL's and PHandle
//-----------------------------------------------------------------------------
class VPanelHandle
{
public:
VPanelHandle() : m_iPanelID(INVALID_PANEL) {}
VPANEL Get();
VPANEL Set( VPANEL pPanel );
operator VPANEL () { return Get(); }
VPANEL operator = (VPANEL pPanel) { return Set(pPanel); }
bool operator == (VPANEL pPanel) { return (Get() == pPanel); }
operator bool () { return Get() != 0; }
private:
HPanel m_iPanelID;
};
//-----------------------------------------------------------------------------
// Purpose: DHANDLE is a templated version of PHandle
//-----------------------------------------------------------------------------
template< class PanelType >
class DHANDLE : public PHandle
{
public:
PanelType *Get() { return (PanelType *)PHandle::Get(); }
PanelType *Set( PanelType *pPanel ) { return (PanelType *)PHandle::Set(pPanel); }
PanelType *Set( HPanel hPanel ) { return (PanelType *)PHandle::Set(hPanel); }
operator PanelType *() { return (PanelType *)PHandle::Get(); }
PanelType * operator ->() { return (PanelType *)PHandle::Get(); }
PanelType * operator = (PanelType *pPanel) { return (PanelType *)PHandle::Set(pPanel); }
bool operator == (Panel *pPanel) { return (PHandle::Get() == pPanel); }
operator bool () { return PHandle::Get() != NULL; }
};
};
#endif // PHANDLE_H