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.

110 lines
4.3 KiB

  1. //=========== Copyright Valve Corporation, All rights reserved. ===============//
  2. //
  3. // Purpose:
  4. //=============================================================================//
  5. #ifndef PANEL2DFACTORY_H
  6. #define PANEL2DFACTORY_H
  7. #ifdef _WIN32
  8. #pragma once
  9. #endif
  10. #include "utlsymbol.h"
  11. #include "tier1/utlrbtree.h"
  12. #include "panorama/panoramasymbol.h"
  13. namespace panorama
  14. {
  15. class IUIPanel;
  16. class IUIPanelClient;
  17. class IUIEngine;
  18. class CPanel2DFactory;
  19. #ifdef DBGFLAG_VALIDATE
  20. void ValidatePanel2DFactory( CValidator &validator );
  21. #endif
  22. void RegisterPanelFactoriesWithEngine( IUIEngine *pEngine );
  23. //-----------------------------------------------------------------------------
  24. // Purpose: Used by DECLARE_PANEL2D_FACTORY macro to create a linked list of instancing functions
  25. //-----------------------------------------------------------------------------
  26. typedef panorama::IUIPanelClient *(*PANEL2DCREATEFUNC)(const char *pchName, panorama::IUIPanel *parent);
  27. typedef CPanoramaSymbol( *PANELSYMBOLFUNC )();
  28. class CPanel2DFactory
  29. {
  30. public:
  31. CPanel2DFactory( CPanoramaSymbol *pSym, char const *pchLayoutName, PANEL2DCREATEFUNC func, void *pChrisBoydBS, PANELSYMBOLFUNC symParentFunc );
  32. static bool BRegisteredLocalName( CUtlSymbol symName );
  33. CPanoramaSymbol BaseClassSymbol() { return m_funcSymParent(); }
  34. private:
  35. friend class CUIEngine;
  36. IUIPanelClient *CreatePanelInternal( const char *pchID, panorama::IUIPanel *parent );
  37. PANELSYMBOLFUNC m_funcSymParent;
  38. PANEL2DCREATEFUNC m_funcCreate;
  39. };
  40. // This is the macro which implements creation of each type of panel. It creates a function which instances an object of the specified type
  41. // It them hooks that function up to the helper list so that objects can create the elements by name, with no header file dependency, etc.
  42. // Params: className = name of class to create
  43. // layoutName = name used in the layout file
  44. #define REGISTER_PANEL2D_FACTORY( className, layoutName ) \
  45. panorama::CPanoramaSymbol className::m_symbol; \
  46. static panorama::IUIPanelClient *Create_##layoutName( const char *pchID, panorama::IUIPanel *parent ) \
  47. { \
  48. return new className( ToPanel2D(parent), pchID ); \
  49. }; \
  50. namespace panorama { className *g_##layoutName##LinkerHack = NULL; } \
  51. panorama::CPanel2DFactory g_##layoutName##_Helper( &className::m_symbol, #layoutName, Create_##layoutName, panorama::g_##layoutName##LinkerHack, &className::BaseClass::GetPanelSymbol );
  52. // Can be used to register a name so it can be used as a top level panel in XML, but can't be created through a layout file
  53. #define REGISTER_PANEL2D( className, layoutName ) \
  54. panorama::CPanoramaSymbol className::m_symbol; \
  55. namespace panorama { className *g_##layoutName##LinkerHack = NULL; } \
  56. panorama::CPanel2DFactory g_##layoutName##_Helper( &className::m_symbol, #layoutName, NULL, panorama::g_##layoutName##LinkerHack, &className::BaseClass::GetPanelSymbol );
  57. // Can be used to reserve a panel name w/o a panel class
  58. #define REGISTER_PANEL_NAME( layoutName ) \
  59. panorama::CPanoramaSymbol k_symPanel##layoutName; \
  60. panorama::CPanoramaSymbol Get_##layoutName##_Symbol() { return k_symPanel##layoutName; } \
  61. panorama::CPanel2DFactory g_##layoutName##_Helper( &k_symPanel##layoutName, #layoutName, NULL, NULL, &Get_##layoutName##_Symbol );
  62. #define DECLARE_PANEL2D( className, baseClassName ) \
  63. public: \
  64. typedef baseClassName BaseClass; \
  65. typedef className ThisClass; \
  66. static panorama::CPanoramaSymbol m_symbol; \
  67. \
  68. static panorama::CPanoramaSymbol GetPanelSymbol() { return className::m_symbol; } \
  69. virtual panorama::CPanoramaSymbol GetPanelType() const { return className::m_symbol; } \
  70. private:
  71. #define DECLARE_PANEL2D_NO_BASE( className ) \
  72. public: \
  73. typedef className ThisClass; \
  74. typedef className BaseClass; \
  75. static panorama::CPanoramaSymbol m_symbol; \
  76. \
  77. static panorama::CPanoramaSymbol GetPanelSymbol() { return className::m_symbol; } \
  78. virtual panorama::CPanoramaSymbol GetPanelType() const { return className::m_symbol; } \
  79. private:
  80. } // namespace panorama
  81. inline uint32 HashItem( const panorama::CPanoramaSymbol &item )
  82. {
  83. return ::HashItem( (UtlSymId_t)item );
  84. }
  85. #endif // PANEL2DFACTORY_H