Team Fortress 2 Source Code as on 22/4/2020
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.

86 lines
2.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose:
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef PHANDLE_H
  8. #define PHANDLE_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. #include <vgui/VGUI.h>
  13. namespace vgui
  14. {
  15. class Panel;
  16. //-----------------------------------------------------------------------------
  17. // Purpose: Safe pointer class for handling Panel or derived panel classes
  18. //-----------------------------------------------------------------------------
  19. class PHandle
  20. {
  21. public:
  22. PHandle() : m_iPanelID(INVALID_PANEL) {} //m_iSerialNumber(0), m_pListEntry(0) {}
  23. Panel *Get();
  24. Panel *Set( Panel *pPanel );
  25. Panel *Set( HPanel hPanel );
  26. operator Panel *() { return Get(); }
  27. Panel * operator ->() { return Get(); }
  28. Panel * operator = (Panel *pPanel) { return Set(pPanel); }
  29. bool operator == (Panel *pPanel) { return (Get() == pPanel); }
  30. operator bool () { return Get() != 0; }
  31. private:
  32. HPanel m_iPanelID;
  33. };
  34. //-----------------------------------------------------------------------------
  35. // Purpose: Safe pointer class to just convert between VPANEL's and PHandle
  36. //-----------------------------------------------------------------------------
  37. class VPanelHandle
  38. {
  39. public:
  40. VPanelHandle() : m_iPanelID(INVALID_PANEL) {}
  41. VPANEL Get();
  42. VPANEL Set( VPANEL pPanel );
  43. operator VPANEL () { return Get(); }
  44. VPANEL operator = (VPANEL pPanel) { return Set(pPanel); }
  45. bool operator == (VPANEL pPanel) { return (Get() == pPanel); }
  46. operator bool () { return Get() != 0; }
  47. private:
  48. HPanel m_iPanelID;
  49. };
  50. //-----------------------------------------------------------------------------
  51. // Purpose: DHANDLE is a templated version of PHandle
  52. //-----------------------------------------------------------------------------
  53. template< class PanelType >
  54. class DHANDLE : public PHandle
  55. {
  56. public:
  57. PanelType *Get() { return (PanelType *)PHandle::Get(); }
  58. PanelType *Set( PanelType *pPanel ) { return (PanelType *)PHandle::Set(pPanel); }
  59. PanelType *Set( HPanel hPanel ) { return (PanelType *)PHandle::Set(hPanel); }
  60. operator PanelType *() { return (PanelType *)PHandle::Get(); }
  61. PanelType * operator ->() { return (PanelType *)PHandle::Get(); }
  62. PanelType * operator = (PanelType *pPanel) { return (PanelType *)PHandle::Set(pPanel); }
  63. bool operator == (Panel *pPanel) { return (PHandle::Get() == pPanel); }
  64. operator bool () { return PHandle::Get() != NULL; }
  65. };
  66. };
  67. #endif // PHANDLE_H