Counter Strike : Global Offensive Source Code
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.

134 lines
4.8 KiB

  1. //========= Copyright 1996-2005, Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: Helper for the CHudElement class to add themselves to the list of hud elements
  4. //
  5. // $NoKeywords: $
  6. //=============================================================================//
  7. #ifndef HUD_ELEMENT_HELPER_H
  8. #define HUD_ELEMENT_HELPER_H
  9. #ifdef _WIN32
  10. #pragma once
  11. #endif
  12. class CHudElement;
  13. #define HUDELEMENT_DEFAULT 0 // default, hud elements present in all split contexts
  14. #define HUDELEMENT_SS_FULLSCREEN_ONLY 1 // hud element only created in fullscreen context
  15. //-----------------------------------------------------------------------------
  16. // Purpose: Used by DECLARE_HUDELEMENT macro to create a linked list of
  17. // instancing functions
  18. //-----------------------------------------------------------------------------
  19. class CHudElementHelper
  20. {
  21. public:
  22. // Static list of helpers
  23. static CHudElementHelper *m_sHelpers;
  24. // Create all the hud elements
  25. static void CreateAllElements( void );
  26. public:
  27. // Construction
  28. CHudElementHelper( CHudElement *( *pfnCreate )( void ), int depth, int flags = HUDELEMENT_DEFAULT );
  29. // Accessors
  30. CHudElementHelper *GetNext( void );
  31. private:
  32. // Next factory in list
  33. CHudElementHelper *m_pNext;
  34. // Creation function to use for this technology
  35. CHudElement *( *m_pfnCreate )( void );
  36. //Depth used to determine hud panel ordering
  37. int m_iDepth;
  38. // Flags for visibility of hud elements in splitscreen
  39. int m_iFlags;
  40. };
  41. // This is the macro which implements creation of each hud element
  42. // It creates a function which instances an object of the specified type
  43. // It them hooks that function up to the helper list so that the CHud objects can create
  44. // the elements by name, with no header file dependency, etc.
  45. #define DECLARE_HUDELEMENT( className ) \
  46. static CHudElement *Create_##className( void ) \
  47. { \
  48. return new className( #className ); \
  49. }; \
  50. static CHudElementHelper g_##className##_Helper( Create_##className, 50 );
  51. #define DECLARE_HUDELEMENT_DEPTH( className, depth ) \
  52. static CHudElement *Create_##className( void ) \
  53. { \
  54. return new className( #className ); \
  55. }; \
  56. static CHudElementHelper g_##className##_Helper( Create_##className, depth );
  57. #define DECLARE_NAMED_HUDELEMENT( className, panelName ) \
  58. static CHudElement *Create_##panelName( void ) \
  59. { \
  60. return new className( #panelName ); \
  61. }; \
  62. static CHudElementHelper g_##panelName##_Helper( Create_##panelName, 50 );
  63. // Versions with flags
  64. #define DECLARE_HUDELEMENT_FLAGS( className, flags ) \
  65. static CHudElement *Create_##className( void ) \
  66. { \
  67. return new className( #className ); \
  68. }; \
  69. static CHudElementHelper g_##className##_Helper( Create_##className, 50, flags );
  70. #define DECLARE_HUDELEMENT_DEPTH_FLAGS( className, depth, flags ) \
  71. static CHudElement *Create_##className( void ) \
  72. { \
  73. return new className( #className ); \
  74. }; \
  75. static CHudElementHelper g_##className##_Helper( Create_##className, depth );
  76. #define DECLARE_NAMED_HUDELEMENT_FLAGS( className, panelName, flags ) \
  77. static CHudElement *Create_##panelName( void ) \
  78. { \
  79. return new className( #panelName ); \
  80. }; \
  81. static CHudElementHelper g_##panelName##_Helper( Create_##panelName, 50 );
  82. // This macro can be used to get a pointer to a specific hud element
  83. #define GET_HUDELEMENT( className ) \
  84. (className*)GetHud().FindElement( #className )
  85. #define GET_NAMED_HUDELEMENT( className, panelName ) \
  86. (className*)GetHud().FindElement( #panelName )
  87. #define GET_FULLSCREEN_HUDELEMENT( className ) \
  88. ((className*)GetHud( 0 ).FindElement( #className ))
  89. // Things that inherit from vgui::Panel, too, will have ambiguous new operators
  90. // so this should disambiguate them
  91. #define DECLARE_MULTIPLY_INHERITED() \
  92. void *operator new( size_t stAllocateBlock ) \
  93. { \
  94. return CHudElement::operator new ( stAllocateBlock ); \
  95. } \
  96. void* operator new( size_t stAllocateBlock, int nBlockUse, const char *pFileName, int nLine ) \
  97. { \
  98. return CHudElement::operator new ( stAllocateBlock, nBlockUse, pFileName, nLine ); \
  99. } \
  100. void operator delete( void *pMem ) \
  101. { \
  102. CHudElement::operator delete ( pMem ); \
  103. } \
  104. void operator delete( void *pMem, int nBlockUse, const char *pFileName, int nLine ) \
  105. { \
  106. CHudElement::operator delete ( pMem, nBlockUse, pFileName, nLine ); \
  107. }
  108. // Alias for base hud element
  109. #define IMPLEMENT_OPERATORS_NEW_AND_DELETE DECLARE_MULTIPLY_INHERITED
  110. #endif // HUD_ELEMENT_HELPER_H