Modified source engine (2017) developed by valve and leaked in 2020. Not for commercial purporses
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

91 lines
2.6 KiB

//========= 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() const;
Panel *Set( Panel *pPanel );
Panel *Set( HPanel hPanel );
operator Panel *() const { return Get(); }
Panel * operator ->() { return Get(); }
Panel * operator = (Panel *pPanel) { return Set(pPanel); }
//bool operator == (Panel *pPanel) { return (Get() == pPanel); }
operator bool () const { return Get() != 0; }
friend bool operator == ( const PHandle &p1, const PHandle &p2 )
{
return p1.m_iPanelID == p2.m_iPanelID;
}
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